diff options
author | Simon McVittie <smcv@collabora.com> | 2017-11-21 12:15:04 +0000 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2017-11-24 12:19:15 +0000 |
commit | 05c04704f9801b732d7372e5ef14e181019257bc (patch) | |
tree | 2fbdfed82216c5b8b7a5f187a2fc5b1528bc0041 /test/test-utils-glib.c | |
parent | d96da8149a105b2bd037c11991138a677035859a (diff) | |
download | dbus-05c04704f9801b732d7372e5ef14e181019257bc.tar.gz |
test_main_context_call_and_wait: Add
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103600
Diffstat (limited to 'test/test-utils-glib.c')
-rw-r--r-- | test/test-utils-glib.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c index ccf87699..a539c5c8 100644 --- a/test/test-utils-glib.c +++ b/test/test-utils-glib.c @@ -714,3 +714,39 @@ test_mkdir (const gchar *path, g_strerror (saved_errno)); } } + +void +test_oom (void) +{ + g_error ("Out of memory"); +} + +/* + * Send the given method call and wait for a reply, spinning the main + * context as necessary. + */ +DBusMessage * +test_main_context_call_and_wait (TestMainContext *ctx, + DBusConnection *connection, + DBusMessage *call, + int timeout) +{ + DBusPendingCall *pc = NULL; + DBusMessage *reply = NULL; + + if (!dbus_connection_send_with_reply (connection, call, &pc, timeout) || + pc == NULL) + test_oom (); + + if (dbus_pending_call_get_completed (pc)) + test_pending_call_store_reply (pc, &reply); + else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply, + &reply, NULL)) + test_oom (); + + while (reply == NULL) + test_main_context_iterate (ctx, TRUE); + + dbus_clear_pending_call (&pc); + return g_steal_pointer (&reply); +} |