3 #include <glib-object.h>
5 #define G_TYPE_TEST (my_test_get_type ())
6 #define MY_TEST(test) (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest))
7 #define MY_IS_TEST(test) (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST))
8 #define MY_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass))
9 #define MY_IS_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
10 #define MY_TEST_GET_CLASS(test) (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
17 typedef struct _GTest GTest;
18 typedef struct _GTestClass GTestClass;
29 GObjectClass parent_class;
32 static GType my_test_get_type (void);
34 static void my_test_class_init (GTestClass * klass);
35 static void my_test_init (GTest * test);
36 static void my_test_dispose (GObject * object);
37 static void my_test_get_property (GObject *object,
41 static void my_test_set_property (GObject *object,
46 static GObjectClass *parent_class = NULL;
49 my_test_get_type (void)
51 static GType test_type = 0;
54 const GTypeInfo test_info = {
58 (GClassInitFunc) my_test_class_init,
63 (GInstanceInitFunc) my_test_init,
67 test_type = g_type_register_static (G_TYPE_OBJECT, "GTest",
74 my_test_class_init (GTestClass * klass)
76 GObjectClass *gobject_class;
78 gobject_class = (GObjectClass *) klass;
80 parent_class = g_type_class_ref (G_TYPE_OBJECT);
82 gobject_class->dispose = my_test_dispose;
83 gobject_class->get_property = my_test_get_property;
84 gobject_class->set_property = my_test_set_property;
86 g_object_class_install_property (gobject_class,
88 g_param_spec_int ("dummy",
96 my_test_init (GTest * test)
98 g_print ("init %p\n", test);
102 my_test_dispose (GObject * object)
106 test = MY_TEST (object);
108 g_print ("dispose %p!\n", test);
110 G_OBJECT_CLASS (parent_class)->dispose (object);
114 my_test_get_property (GObject *object,
121 test = MY_TEST (object);
126 g_value_set_int (value, test->dummy);
129 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
135 my_test_set_property (GObject *object,
142 test = MY_TEST (object);
147 test->dummy = g_value_get_int (value);
150 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
155 static gint count = 0;
158 dummy_notify (GObject *object,
162 if (count % 10000 == 0)
167 my_test_do_property (GTest * test)
171 g_object_get (test, "dummy", &dummy, NULL);
172 g_object_set (test, "dummy", dummy + 1, NULL);
176 main (int argc, char **argv)
181 g_thread_init (NULL);
182 g_print ("START: %s\n", argv[0]);
183 g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
186 test = g_object_new (G_TYPE_TEST, NULL);
188 g_signal_connect (test, "notify::dummy", G_CALLBACK (dummy_notify), NULL);
190 g_assert (count == test->dummy);
192 for (i=0; i<1000000; i++) {
193 my_test_do_property (test);
196 g_assert (count == test->dummy);