2 #include <glib-object.h>
8 #define G_TYPE_TEST (my_test_get_type ())
9 #define MY_TEST(test) (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest))
10 #define MY_IS_TEST(test) (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST))
11 #define MY_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass))
12 #define MY_IS_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
13 #define MY_TEST_GET_CLASS(test) (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
20 typedef struct _GTest GTest
;
21 typedef struct _GTestClass GTestClass
;
32 GObjectClass parent_class
;
35 static GType
my_test_get_type (void);
37 static void my_test_class_init (GTestClass
* klass
);
38 static void my_test_init (GTest
* test
);
39 static void my_test_dispose (GObject
* object
);
40 static void my_test_get_property (GObject
*object
,
44 static void my_test_set_property (GObject
*object
,
49 static GObjectClass
*parent_class
= NULL
;
52 my_test_get_type (void)
54 static GType test_type
= 0;
57 const GTypeInfo test_info
= {
61 (GClassInitFunc
) my_test_class_init
,
66 (GInstanceInitFunc
) my_test_init
,
70 test_type
= g_type_register_static (G_TYPE_OBJECT
, "GTest",
77 my_test_class_init (GTestClass
* klass
)
79 GObjectClass
*gobject_class
;
81 gobject_class
= (GObjectClass
*) klass
;
83 parent_class
= g_type_class_ref (G_TYPE_OBJECT
);
85 gobject_class
->dispose
= my_test_dispose
;
86 gobject_class
->get_property
= my_test_get_property
;
87 gobject_class
->set_property
= my_test_set_property
;
89 g_object_class_install_property (gobject_class
,
91 g_param_spec_int ("dummy",
99 my_test_init (GTest
* test
)
101 g_print ("init %p\n", test
);
105 my_test_dispose (GObject
* object
)
109 test
= MY_TEST (object
);
111 g_print ("dispose %p!\n", test
);
113 G_OBJECT_CLASS (parent_class
)->dispose (object
);
117 my_test_get_property (GObject
*object
,
124 test
= MY_TEST (object
);
129 g_value_set_int (value
, test
->dummy
);
132 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
138 my_test_set_property (GObject
*object
,
145 test
= MY_TEST (object
);
150 test
->dummy
= g_value_get_int (value
);
153 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
158 static gint count
= 0;
161 dummy_notify (GObject
*object
,
165 if (count
% 10000 == 0)
170 my_test_do_property (GTest
* test
)
174 g_object_get (test
, "dummy", &dummy
, NULL
);
175 g_object_set (test
, "dummy", dummy
+ 1, NULL
);
179 main (int argc
, char **argv
)
184 g_print ("START: %s\n", argv
[0]);
185 g_log_set_always_fatal (G_LOG_LEVEL_WARNING
| G_LOG_LEVEL_CRITICAL
| g_log_set_always_fatal (G_LOG_FATAL_MASK
));
187 test
= g_object_new (G_TYPE_TEST
, NULL
);
189 g_signal_connect (test
, "notify::dummy", G_CALLBACK (dummy_notify
), NULL
);
191 g_assert (count
== test
->dummy
);
193 for (i
=0; i
<1000000; i
++) {
194 my_test_do_property (test
);
197 g_assert (count
== test
->dummy
);
199 g_object_unref (test
);