Update contrib.
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))
19 typedef struct _GTest GTest;
20 typedef struct _GTestClass GTestClass;
29 GObjectClass parent_class;
32 static GType my_test_get_type (void);
33 static volatile gboolean stopping;
35 static void my_test_class_init (GTestClass * klass);
36 static void my_test_init (GTest * test);
37 static void my_test_dispose (GObject * object);
39 static GObjectClass *parent_class = NULL;
42 my_test_get_type (void)
44 static GType test_type = 0;
47 static const GTypeInfo test_info = {
51 (GClassInitFunc) my_test_class_init,
56 (GInstanceInitFunc) my_test_init,
60 test_type = g_type_register_static (G_TYPE_OBJECT, "GTest",
67 my_test_class_init (GTestClass * klass)
69 GObjectClass *gobject_class;
71 gobject_class = (GObjectClass *) klass;
73 parent_class = g_type_class_ref (G_TYPE_OBJECT);
75 gobject_class->dispose = my_test_dispose;
79 my_test_init (GTest * test)
81 g_print ("init %p\n", test);
85 my_test_dispose (GObject * object)
89 test = MY_TEST (object);
91 g_print ("dispose %p!\n", object);
93 G_OBJECT_CLASS (parent_class)->dispose (object);
97 my_test_do_refcount (GTest * test)
100 g_object_unref (test);
104 run_thread (GTest * test)
109 my_test_do_refcount (test);
110 if ((i++ % 10000) == 0) {
112 g_thread_yield(); /* force context switch */
120 main (int argc, char **argv)
123 GTest *test1, *test2;
124 GArray *test_threads;
125 const guint n_threads = 5;
129 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);
130 g_set_print_handler(mrtPrintHandler);
131 #endif /*__SYMBIAN32__*/
132 g_thread_init (NULL);
133 g_print ("START: %s\n", argv[0]);
134 g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
137 test1 = g_object_new (G_TYPE_TEST, NULL);
138 test2 = g_object_new (G_TYPE_TEST, NULL);
140 test_threads = g_array_new (FALSE, FALSE, sizeof (GThread *));
144 for (i = 0; i < n_threads; i++) {
147 thread = g_thread_create ((GThreadFunc) run_thread, test1, TRUE, NULL);
148 g_array_append_val (test_threads, thread);
150 thread = g_thread_create ((GThreadFunc) run_thread, test2, TRUE, NULL);
151 g_array_append_val (test_threads, thread);
157 g_print ("\nstopping\n");
159 /* join all threads */
160 for (i = 0; i < 2 * n_threads; i++) {
163 thread = g_array_index (test_threads, GThread *, i);
164 g_thread_join (thread);
167 g_print ("stopped\n");
169 testResultXml("objects");
170 #endif /* EMULATOR */