Exemplo n.º 1
0
int
main (int   argc,
      char *argv[])
{
  TestIfaceClass *iface;
  GObject *object;
  char *string1 = "A";
  char *string2 = "B";

  g_type_init ();
  
  /* Basic check of interfaces added before class_init time
   */
  g_type_add_interface_check (string1, check_func);

  object = g_object_new (TEST_TYPE_OBJECT1, NULL);
  iface = TEST_IFACE_GET_CLASS (object);
    g_assert (strcmp (iface->history->str, "A") == 0);
  g_object_unref (object);

  /* Add a second check function
   */
  g_type_add_interface_check (string2, check_func);

  object = g_object_new (TEST_TYPE_OBJECT2, NULL);
  iface = TEST_IFACE_GET_CLASS (object);
  g_assert (strcmp (iface->history->str, "AB") == 0);
  g_object_unref (object);

  /* Remove the first check function
   */
  g_type_remove_interface_check (string1, check_func);

  object = g_object_new (TEST_TYPE_OBJECT3, NULL);
  iface = TEST_IFACE_GET_CLASS (object);
  g_assert (strcmp (iface->history->str, "B") == 0);
  g_object_unref (object);

  /* Test interfaces added after class_init time
   */
  g_type_class_ref (TEST_TYPE_OBJECT4);
  {
    GInterfaceInfo const iface = {
      NULL, NULL, NULL
    };
    
    g_type_add_interface_static (TEST_TYPE_OBJECT4, TEST_TYPE_IFACE, &iface);
  }
  
  object = g_object_new (TEST_TYPE_OBJECT4, NULL);
  iface = TEST_IFACE_GET_CLASS (object);
  g_assert (strcmp (iface->history->str, "B") == 0);
  g_object_unref (object);
    
  return 0;
}
Exemplo n.º 2
0
static void
soup_proxy_resolver_interface_init (GTypeInterface *interface)
{
	/* Add an interface_check where we can kludgily add the
	 * SoupProxyURIResolver interface to all SoupProxyResolvers.
	 * (SoupProxyResolver can't just implement
	 * SoupProxyURIResolver itself because interface types can't
	 * implement other interfaces.) This is an ugly hack, but it
	 * only gets used if someone actually creates a
	 * SoupProxyResolver...
	 */
	g_type_add_interface_check (NULL, proxy_resolver_interface_check);
}