From 525e3953efe2c08be6480d9c97df331ef04f54ad Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 11 Sep 2022 15:11:34 -0400 Subject: [PATCH] tests: Add a test for g_task_set_static_name() The test checks that the original string is returned by g_task_get_name(). --- gio/tests/task.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/gio/tests/task.c b/gio/tests/task.c index f5043547f..15dc25723 100644 --- a/gio/tests/task.c +++ b/gio/tests/task.c @@ -656,6 +656,44 @@ name_callback (GObject *object, g_main_loop_quit (loop); } +static void static_name_callback (GObject *object, + GAsyncResult *result, + gpointer user_data); + +static void +test_static_name (void) +{ + GTask *t1 = NULL; + char *name1 = NULL; + char *orig = "some task"; + + t1 = g_task_new (NULL, NULL, static_name_callback, &name1); + g_task_set_static_name (t1, orig); + g_task_return_boolean (t1, TRUE); + g_object_unref (t1); + + g_main_loop_run (loop); + + g_assert_true (name1 == orig); +} + +static void +static_name_callback (GObject *object, + GAsyncResult *result, + gpointer user_data) +{ + const char **name_out = user_data; + GError *local_error = NULL; + + g_assert_null (*name_out); + *name_out = g_task_get_name (G_TASK (result)); + + g_task_propagate_boolean (G_TASK (result), &local_error); + g_assert_no_error (local_error); + + g_main_loop_quit (loop); +} + /* test_asynchronous_cancellation: cancelled tasks are returned * asynchronously, i.e. not from inside the GCancellable::cancelled * handler. @@ -2412,6 +2450,7 @@ main (int argc, char **argv) g_test_add_func ("/gtask/report-error", test_report_error); g_test_add_func ("/gtask/priority", test_priority); g_test_add_func ("/gtask/name", test_name); + g_test_add_func ("/gtask/static-name", test_static_name); g_test_add_func ("/gtask/asynchronous-cancellation", test_asynchronous_cancellation); g_test_add_func ("/gtask/check-cancellable", test_check_cancellable); g_test_add_func ("/gtask/return-if-cancelled", test_return_if_cancelled);