Ejemplo 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;
}
Ejemplo n.º 2
0
static void
iface_print_string (TestIface   *tiobj,
		    const gchar *string)
{
  TestIfaceClass *iface;

  g_return_if_fail (TEST_IS_IFACE (tiobj));
  g_return_if_fail (G_IS_OBJECT (tiobj)); /* ensured through prerequisite */

  iface = TEST_IFACE_GET_CLASS (tiobj);
  g_object_ref (tiobj);
  iface->print_string (tiobj, string);
  g_object_unref (tiobj);
}