From 54d678498353d5a01686db7d6068e38b770193a9 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 16 Apr 2018 19:39:04 +0100 Subject: [PATCH 03/39] tests: Add a GAsyncReadyCallback that stores the GAsyncResult It seems I eventually introduce this into every project where I've added GLib-based unit tests. Today it's dbus' turn. Signed-off-by: Simon McVittie --- test/test-utils-glib.c | 16 ++++++++++++++++ test/test-utils-glib.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c index a9bbbb26..cfdbb38e 100644 --- a/test/test-utils-glib.c +++ b/test/test-utils-glib.c @@ -762,3 +762,19 @@ test_main_context_call_and_wait (TestMainContext *ctx, dbus_clear_pending_call (&pc); return g_steal_pointer (&reply); } + +/* + * Store the result of an async operation. @user_data is a pointer to a + * variable that can store @result, initialized to %NULL. + */ +void +test_store_result_cb (GObject *source_object G_GNUC_UNUSED, + GAsyncResult *result, + gpointer user_data) +{ + GAsyncResult **result_p = user_data; + + g_assert_nonnull (result_p); + g_assert_null (*result_p); + *result_p = g_object_ref (result); +} diff --git a/test/test-utils-glib.h b/test/test-utils-glib.h index 755e8c7c..7e65b629 100644 --- a/test/test-utils-glib.h +++ b/test/test-utils-glib.h @@ -121,4 +121,8 @@ backported_g_steal_pointer (gpointer pointer_to_pointer) } #endif +void test_store_result_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data); + #endif -- 2.17.0