First public contribution.
2 * Portions copyright (c) 2006-2009 Nokia Corporation. All rights reserved.
6 #include <glib-object.h>
9 #include <glib_global.h>
10 #include "mrt2_glib2_test.h"
11 #endif /*__SYMBIAN32__*/
12 #define G_TYPE_TEST (my_test_get_type ())
13 #define MY_TEST(test) (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest))
14 #define MY_IS_TEST(test) (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST))
15 #define MY_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass))
16 #define MY_IS_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
17 #define MY_TEST_GET_CLASS(test) (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
24 typedef struct _GTest GTest;
25 typedef struct _GTestClass GTestClass;
38 GObjectClass parent_class;
41 static GType my_test_get_type (void);
42 static volatile gboolean stopping;
44 static void my_test_class_init (GTestClass * klass);
45 static void my_test_init (GTest * test);
46 static void my_test_dispose (GObject * object);
47 static void my_test_get_property (GObject *object,
51 static void my_test_set_property (GObject *object,
56 static GObjectClass *parent_class = NULL;
59 my_test_get_type (void)
61 static GType test_type = 0;
64 static const GTypeInfo test_info = {
68 (GClassInitFunc) my_test_class_init,
73 (GInstanceInitFunc) my_test_init,
77 test_type = g_type_register_static (G_TYPE_OBJECT, "GTest", &test_info, 0);
83 my_test_class_init (GTestClass * klass)
85 GObjectClass *gobject_class;
87 gobject_class = (GObjectClass *) klass;
89 parent_class = g_type_class_ref (G_TYPE_OBJECT);
91 gobject_class->dispose = my_test_dispose;
92 gobject_class->get_property = my_test_get_property;
93 gobject_class->set_property = my_test_set_property;
95 g_object_class_install_property (gobject_class,
97 g_param_spec_int ("dummy",
105 my_test_init (GTest * test)
107 static guint static_id = 1;
108 test->id = static_id++;
112 my_test_dispose (GObject * object)
116 test = MY_TEST (object);
118 G_OBJECT_CLASS (parent_class)->dispose (object);
122 my_test_get_property (GObject *object,
129 test = MY_TEST (object);
134 g_value_set_int (value, test->dummy);
137 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
143 my_test_set_property (GObject *object,
150 test = MY_TEST (object);
155 test->dummy = g_value_get_int (value);
158 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
164 dummy_notify (GObject *object,
169 test = MY_TEST (object);
175 my_test_do_property (GTest * test)
179 g_object_get (test, "dummy", &dummy, NULL);
180 g_object_set (test, "dummy", dummy + 1, NULL);
184 run_thread (GTest * test)
189 my_test_do_property (test);
190 if ((i++ % 10000) == 0)
192 g_print (".%c", 'a' + test->id);
193 g_thread_yield(); /* force context switch */
201 main (int argc, char **argv)
204 GArray *test_objects;
205 GArray *test_threads;
206 const gint n_threads = 5;
210 g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
211 g_set_print_handler(mrtPrintHandler);
212 #endif /*__SYMBIAN32__*/
213 g_thread_init (NULL);
214 g_print ("START: %s\n", argv[0]);
215 g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
218 test_objects = g_array_new (FALSE, FALSE, sizeof (GTest *));
220 for (i = 0; i < n_threads; i++) {
223 test = g_object_new (G_TYPE_TEST, NULL);
224 g_array_append_val (test_objects, test);
226 g_assert (test->count == test->dummy);
227 g_signal_connect (test, "notify::dummy", G_CALLBACK (dummy_notify), NULL);
230 test_threads = g_array_new (FALSE, FALSE, sizeof (GThread *));
234 for (i = 0; i < n_threads; i++) {
238 test = g_array_index (test_objects, GTest *, i);
240 thread = g_thread_create ((GThreadFunc) run_thread, test, TRUE, NULL);
241 g_array_append_val (test_threads, thread);
246 g_print ("\nstopping\n");
248 /* join all threads */
249 for (i = 0; i < n_threads; i++) {
252 thread = g_array_index (test_threads, GThread *, i);
253 g_thread_join (thread);
256 g_print ("stopped\n");
258 for (i = 0; i < n_threads; i++) {
261 test = g_array_index (test_objects, GTest *, i);
263 g_assert (test->count == test->dummy);
266 testResultXml("properties");
267 #endif /* EMULATOR */