mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 06:56:14 +01:00
Convert tests/refcount/objects.c to glib test framework
This commit is contained in:
parent
ce585ba4d2
commit
62b5fe5991
@ -65,7 +65,6 @@ my_test_class_init (GTestClass * klass)
|
|||||||
GObjectClass *gobject_class;
|
GObjectClass *gobject_class;
|
||||||
|
|
||||||
gobject_class = (GObjectClass *) klass;
|
gobject_class = (GObjectClass *) klass;
|
||||||
|
|
||||||
parent_class = g_type_class_ref (G_TYPE_OBJECT);
|
parent_class = g_type_class_ref (G_TYPE_OBJECT);
|
||||||
|
|
||||||
gobject_class->dispose = my_test_dispose;
|
gobject_class->dispose = my_test_dispose;
|
||||||
@ -74,7 +73,7 @@ my_test_class_init (GTestClass * klass)
|
|||||||
static void
|
static void
|
||||||
my_test_init (GTest * test)
|
my_test_init (GTest * test)
|
||||||
{
|
{
|
||||||
g_print ("init %p\n", test);
|
g_test_message ("init %p\n", test);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -84,7 +83,7 @@ my_test_dispose (GObject * object)
|
|||||||
|
|
||||||
test = MY_TEST (object);
|
test = MY_TEST (object);
|
||||||
|
|
||||||
g_print ("dispose %p!\n", test);
|
g_test_message ("dispose %p!\n", test);
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
@ -104,7 +103,7 @@ run_thread (GTest * test)
|
|||||||
while (!g_atomic_int_get (&stopping)) {
|
while (!g_atomic_int_get (&stopping)) {
|
||||||
my_test_do_refcount (test);
|
my_test_do_refcount (test);
|
||||||
if ((i++ % 10000) == 0) {
|
if ((i++ % 10000) == 0) {
|
||||||
g_print (".");
|
g_test_message (".");
|
||||||
g_thread_yield (); /* force context switch */
|
g_thread_yield (); /* force context switch */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,17 +111,14 @@ run_thread (GTest * test)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static void
|
||||||
main (int argc, char **argv)
|
test_refcount_object_basics (void)
|
||||||
{
|
{
|
||||||
guint i;
|
guint i;
|
||||||
GTest *test1, *test2;
|
GTest *test1, *test2;
|
||||||
GArray *test_threads;
|
GArray *test_threads;
|
||||||
const guint n_threads = 5;
|
const guint n_threads = 5;
|
||||||
|
|
||||||
g_print ("START: %s\n", argv[0]);
|
|
||||||
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
|
|
||||||
|
|
||||||
test1 = g_object_new (G_TYPE_TEST, NULL);
|
test1 = g_object_new (G_TYPE_TEST, NULL);
|
||||||
test2 = g_object_new (G_TYPE_TEST, NULL);
|
test2 = g_object_new (G_TYPE_TEST, NULL);
|
||||||
|
|
||||||
@ -139,12 +135,10 @@ main (int argc, char **argv)
|
|||||||
thread = g_thread_create ((GThreadFunc) run_thread, test2, TRUE, NULL);
|
thread = g_thread_create ((GThreadFunc) run_thread, test2, TRUE, NULL);
|
||||||
g_array_append_val (test_threads, thread);
|
g_array_append_val (test_threads, thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_usleep (5000000);
|
g_usleep (5000000);
|
||||||
|
|
||||||
g_atomic_int_set (&stopping, 1);
|
g_atomic_int_set (&stopping, 1);
|
||||||
|
|
||||||
g_print ("\nstopping\n");
|
|
||||||
|
|
||||||
/* join all threads */
|
/* join all threads */
|
||||||
for (i = 0; i < 2 * n_threads; i++) {
|
for (i = 0; i < 2 * n_threads; i++) {
|
||||||
GThread *thread;
|
GThread *thread;
|
||||||
@ -156,8 +150,18 @@ main (int argc, char **argv)
|
|||||||
g_object_unref (test1);
|
g_object_unref (test1);
|
||||||
g_object_unref (test2);
|
g_object_unref (test2);
|
||||||
g_array_unref (test_threads);
|
g_array_unref (test_threads);
|
||||||
|
}
|
||||||
g_print ("stopped\n");
|
|
||||||
|
int
|
||||||
return 0;
|
main (int argc, gchar *argv[])
|
||||||
|
{
|
||||||
|
g_log_set_always_fatal (G_LOG_LEVEL_WARNING |
|
||||||
|
G_LOG_LEVEL_CRITICAL |
|
||||||
|
g_log_set_always_fatal (G_LOG_FATAL_MASK));
|
||||||
|
|
||||||
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
|
||||||
|
g_test_add_func ("/gobject/refcount/object-basics", test_refcount_object_basics);
|
||||||
|
|
||||||
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user