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
;
34 GObjectClass parent_class
;
37 static GType
my_test_get_type (void);
38 static volatile gboolean stopping
;
40 static void my_test_class_init (GTestClass
* klass
);
41 static void my_test_init (GTest
* test
);
42 static void my_test_dispose (GObject
* object
);
43 static void my_test_get_property (GObject
*object
,
47 static void my_test_set_property (GObject
*object
,
52 static GObjectClass
*parent_class
= NULL
;
55 my_test_get_type (void)
57 static GType test_type
= 0;
60 const GTypeInfo test_info
= {
64 (GClassInitFunc
) my_test_class_init
,
69 (GInstanceInitFunc
) my_test_init
,
73 test_type
= g_type_register_static (G_TYPE_OBJECT
, "GTest", &test_info
, 0);
79 my_test_class_init (GTestClass
* klass
)
81 GObjectClass
*gobject_class
;
83 gobject_class
= (GObjectClass
*) klass
;
85 parent_class
= g_type_class_ref (G_TYPE_OBJECT
);
87 gobject_class
->dispose
= my_test_dispose
;
88 gobject_class
->get_property
= my_test_get_property
;
89 gobject_class
->set_property
= my_test_set_property
;
91 g_object_class_install_property (gobject_class
,
93 g_param_spec_int ("dummy",
101 my_test_init (GTest
* test
)
103 static guint static_id
= 1;
104 test
->id
= static_id
++;
108 my_test_dispose (GObject
* object
)
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
);
156 dummy_notify (GObject
*object
,
161 test
= MY_TEST (object
);
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 run_thread (GTest
* test
)
181 my_test_do_property (test
);
182 if ((i
++ % 10000) == 0)
184 g_print (".%c", 'a' + test
->id
);
185 g_thread_yield(); /* force context switch */
193 main (int argc
, char **argv
)
196 GThread
*test_threads
[N_THREADS
];
197 GTest
*test_objects
[N_THREADS
];
200 g_print ("START: %s\n", argv
[0]);
201 g_log_set_always_fatal (G_LOG_LEVEL_WARNING
| G_LOG_LEVEL_CRITICAL
| g_log_set_always_fatal (G_LOG_FATAL_MASK
));
203 for (i
= 0; i
< N_THREADS
; i
++) {
206 test
= g_object_new (G_TYPE_TEST
, NULL
);
207 test_objects
[i
] = test
;
209 g_assert (test
->count
== test
->dummy
);
210 g_signal_connect (test
, "notify::dummy", G_CALLBACK (dummy_notify
), NULL
);
215 for (i
= 0; i
< N_THREADS
; i
++)
216 test_threads
[i
] = g_thread_create ((GThreadFunc
) run_thread
, test_objects
[i
], TRUE
, NULL
);
221 g_print ("\nstopping\n");
223 /* join all threads */
224 for (i
= 0; i
< N_THREADS
; i
++)
225 g_thread_join (test_threads
[i
]);
227 g_print ("stopped\n");
229 for (i
= 0; i
< N_THREADS
; i
++) {
230 GTest
*test
= test_objects
[i
];
232 g_assert (test
->count
== test
->dummy
);
233 g_object_unref (test
);