tests: Tidy up test naming in glib/tests/once.c

Make it a little clearer. This introduces no functional changes.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1323
This commit is contained in:
Philip Withnall 2020-02-13 14:45:33 +00:00
parent 536e32c5a8
commit 596fa49aa0

View File

@ -34,11 +34,13 @@ do_once (gpointer data)
} }
static void static void
test_once1 (void) test_once_single_threaded (void)
{ {
GOnce once = G_ONCE_INIT; GOnce once = G_ONCE_INIT;
gpointer res; gpointer res;
g_test_summary ("Test g_once() usage from a single thread");
g_assert (once.status == G_ONCE_STATUS_NOTCALLED); g_assert (once.status == G_ONCE_STATUS_NOTCALLED);
res = g_once (&once, do_once, NULL); res = g_once (&once, do_once, NULL);
@ -51,10 +53,12 @@ test_once1 (void)
} }
static void static void
test_once2 (void) test_once_init_single_threaded (void)
{ {
static gsize init = 0; static gsize init = 0;
g_test_summary ("Test g_once_init_{enter,leave}() usage from a single thread");
if (g_once_init_enter (&init)) if (g_once_init_enter (&init))
{ {
g_assert (TRUE); g_assert (TRUE);
@ -96,15 +100,17 @@ thread_func (gpointer data)
} }
static void static void
test_once3 (void) test_once_init_multi_threaded (void)
{ {
gint i; gint i;
GThread *threads[THREADS]; GThread *threads[THREADS];
g_test_summary ("Test g_once_init_{enter,leave}() usage from multiple threads");
shared = 0; shared = 0;
for (i = 0; i < THREADS; i++) for (i = 0; i < THREADS; i++)
threads[i] = g_thread_new ("once3", thread_func, NULL); threads[i] = g_thread_new ("once-init-multi-threaded", thread_func, NULL);
for (i = 0; i < THREADS; i++) for (i = 0; i < THREADS; i++)
g_thread_join (threads[i]); g_thread_join (threads[i]);
@ -113,10 +119,12 @@ test_once3 (void)
} }
static void static void
test_once4 (void) test_once_init_string (void)
{ {
static const gchar *val; static const gchar *val;
g_test_summary ("Test g_once_init_{enter,leave}() usage with a string");
if (g_once_init_enter (&val)) if (g_once_init_enter (&val))
g_once_init_leave (&val, "foo"); g_once_init_leave (&val, "foo");
@ -128,10 +136,10 @@ main (int argc, char *argv[])
{ {
g_test_init (&argc, &argv, NULL); g_test_init (&argc, &argv, NULL);
g_test_add_func ("/thread/once1", test_once1); g_test_add_func ("/once/single-threaded", test_once_single_threaded);
g_test_add_func ("/thread/once2", test_once2); g_test_add_func ("/once-init/single-threaded", test_once_init_single_threaded);
g_test_add_func ("/thread/once3", test_once3); g_test_add_func ("/once-init/multi-threaded", test_once_init_multi_threaded);
g_test_add_func ("/thread/once4", test_once4); g_test_add_func ("/once-init/string", test_once_init_string);
return g_test_run (); return g_test_run ();
} }