1 #include <glib-object.h>
4 test_registration_serial (void)
6 gint serial1
, serial2
, serial3
;
8 serial1
= g_type_get_type_registration_serial ();
9 g_pointer_type_register_static ("my+pointer");
10 serial2
= g_type_get_type_registration_serial ();
11 g_assert (serial1
!= serial2
);
12 serial3
= g_type_get_type_registration_serial ();
13 g_assert (serial2
== serial3
);
17 GTypeInterface g_iface
;
20 GType
bar_get_type (void);
22 G_DEFINE_INTERFACE (Bar
, bar
, G_TYPE_OBJECT
)
25 bar_default_init (BarInterface
*iface
)
30 GTypeInterface g_iface
;
33 GType
foo_get_type (void);
35 G_DEFINE_INTERFACE_WITH_CODE (Foo
, foo
, G_TYPE_OBJECT
,
36 g_type_interface_add_prerequisite (g_define_type_id
, bar_get_type ());)
39 foo_default_init (FooInterface
*iface
)
44 test_interface_prerequisite (void)
51 prereqs
= g_type_interface_prerequisites (foo_get_type (), &n_prereqs
);
52 g_assert_cmpint (n_prereqs
, ==, 2);
53 g_assert (prereqs
[0] == bar_get_type ());
54 g_assert (prereqs
[1] == G_TYPE_OBJECT
);
56 iface
= g_type_default_interface_ref (foo_get_type ());
57 parent
= g_type_interface_peek_parent (iface
);
58 g_assert (parent
== NULL
);
59 g_type_default_interface_unref (iface
);
65 GTypeInterface g_iface
;
68 GType
baz_get_type (void);
70 G_DEFINE_INTERFACE (Baz
, baz
, G_TYPE_OBJECT
)
73 baz_default_init (BazInterface
*iface
)
82 GObjectClass parent_class
;
85 GType
bazo_get_type (void);
86 static void bazo_iface_init (BazInterface
*i
);
88 G_DEFINE_TYPE_WITH_CODE (Bazo
, bazo
, G_TYPE_INITIALLY_UNOWNED
,
89 G_IMPLEMENT_INTERFACE (baz_get_type (),
98 bazo_class_init (BazoClass
*c
)
103 bazo_iface_init (BazInterface
*i
)
107 static gint check_called
;
110 check_func (gpointer check_data
,
113 g_assert (check_data
== &check_called
);
119 test_interface_check (void)
124 g_type_add_interface_check (&check_called
, check_func
);
125 o
= g_object_new (bazo_get_type (), NULL
);
127 g_assert_cmpint (check_called
, ==, 1);
128 g_type_remove_interface_check (&check_called
, check_func
);
132 test_next_base (void)
136 type
= g_type_next_base (bazo_get_type (), G_TYPE_OBJECT
);
138 g_assert (type
== G_TYPE_INITIALLY_UNOWNED
);
142 main (int argc
, char *argv
[])
144 g_test_init (&argc
, &argv
, NULL
);
146 g_test_add_func ("/type/registration-serial", test_registration_serial
);
147 g_test_add_func ("/type/interface-prerequisite", test_interface_prerequisite
);
148 g_test_add_func ("/type/interface-check", test_interface_check
);
149 g_test_add_func ("/type/next-base", test_next_base
);
151 return g_test_run ();