Update German translation
[glib.git] / gobject / tests / type.c
blob1abe4823da02ad74b662a2e6242e614400e8c7f4
1 #include <glib-object.h>
3 static void
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);
16 typedef struct {
17 GTypeInterface g_iface;
18 } BarInterface;
20 GType bar_get_type (void);
22 G_DEFINE_INTERFACE (Bar, bar, G_TYPE_OBJECT)
24 static void
25 bar_default_init (BarInterface *iface)
29 typedef struct {
30 GTypeInterface g_iface;
31 } FooInterface;
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 ());)
38 static void
39 foo_default_init (FooInterface *iface)
43 static void
44 test_interface_prerequisite (void)
46 GType *prereqs;
47 guint n_prereqs;
48 gpointer iface;
49 gpointer parent;
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);
61 g_free (prereqs);
64 typedef struct {
65 GTypeInterface g_iface;
66 } BazInterface;
68 GType baz_get_type (void);
70 G_DEFINE_INTERFACE (Baz, baz, G_TYPE_OBJECT)
72 static void
73 baz_default_init (BazInterface *iface)
77 typedef struct {
78 GObject parent;
79 } Bazo;
81 typedef struct {
82 GObjectClass parent_class;
83 } BazoClass;
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 (),
90 bazo_iface_init);)
92 static void
93 bazo_init (Bazo *b)
97 static void
98 bazo_class_init (BazoClass *c)
102 static void
103 bazo_iface_init (BazInterface *i)
107 static gint check_called;
109 static void
110 check_func (gpointer check_data,
111 gpointer g_iface)
113 g_assert (check_data == &check_called);
115 check_called++;
118 static void
119 test_interface_check (void)
121 GObject *o;
123 check_called = 0;
124 g_type_add_interface_check (&check_called, check_func);
125 o = g_object_new (bazo_get_type (), NULL);
126 g_object_unref (o);
127 g_assert_cmpint (check_called, ==, 1);
128 g_type_remove_interface_check (&check_called, check_func);
131 static void
132 test_next_base (void)
134 GType type;
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 ();