Convert tests/refcount/properties.c to glib test framework

This commit is contained in:
Emmanuel Fleury 2022-03-16 09:27:23 +01:00 committed by Philip Withnall
parent 715ff4ea29
commit 76fccc78c0

View File

@ -181,7 +181,7 @@ run_thread (GTest * test)
my_test_do_property (test); my_test_do_property (test);
if ((i++ % 10000) == 0) if ((i++ % 10000) == 0)
{ {
g_print (".%c", 'a' + test->id); g_test_message (".%c", 'a' + test->id);
g_thread_yield(); /* force context switch */ g_thread_yield(); /* force context switch */
} }
} }
@ -189,24 +189,21 @@ run_thread (GTest * test)
return NULL; return NULL;
} }
int static void
main (int argc, char **argv) test_refcount_properties_1 (void)
{ {
#define N_THREADS 5 #define N_THREADS 5
GThread *test_threads[N_THREADS]; GThread *test_threads[N_THREADS];
GTest *test_objects[N_THREADS]; GTest *test_objects[N_THREADS];
gint i; gint i;
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));
for (i = 0; i < N_THREADS; i++) { for (i = 0; i < N_THREADS; i++) {
GTest *test; GTest *test;
test = g_object_new (G_TYPE_TEST, NULL); test = g_object_new (G_TYPE_TEST, NULL);
test_objects[i] = test; test_objects[i] = test;
g_assert (test->count == test->dummy); g_assert_cmpint (test->count, ==, test->dummy);
g_signal_connect (test, "notify::dummy", G_CALLBACK (dummy_notify), NULL); g_signal_connect (test, "notify::dummy", G_CALLBACK (dummy_notify), NULL);
} }
@ -218,20 +215,29 @@ main (int argc, char **argv)
g_usleep (3000000); g_usleep (3000000);
g_atomic_int_set (&stopping, TRUE); g_atomic_int_set (&stopping, TRUE);
g_print ("\nstopping\n");
/* join all threads */ /* join all threads */
for (i = 0; i < N_THREADS; i++) for (i = 0; i < N_THREADS; i++)
g_thread_join (test_threads[i]); g_thread_join (test_threads[i]);
g_print ("stopped\n");
for (i = 0; i < N_THREADS; i++) { for (i = 0; i < N_THREADS; i++) {
GTest *test = test_objects[i]; GTest *test = test_objects[i];
g_assert (test->count == test->dummy); g_assert_cmpint (test->count, ==, test->dummy);
g_object_unref (test); g_object_unref (test);
} }
}
return 0;
int
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/properties-1", test_refcount_properties_1);
return g_test_run ();
} }