mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-05-02 22:27:59 +02:00
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
This commit is contained in:
parent
d96da8149a
commit
05c04704f9
3 changed files with 45 additions and 2 deletions
|
|
@ -554,7 +554,7 @@ test_simple (void)
|
|||
}
|
||||
|
||||
static void
|
||||
test_oom (void)
|
||||
test_oom_handling (void)
|
||||
{
|
||||
if (!_dbus_test_oom_handling ("DBusVariant", test_once, NULL))
|
||||
g_error ("Test failed");
|
||||
|
|
@ -567,7 +567,7 @@ main (int argc,
|
|||
test_init (&argc, &argv);
|
||||
|
||||
g_test_add_func ("/variant/simple", test_simple);
|
||||
g_test_add_func ("/variant/oom", test_oom);
|
||||
g_test_add_func ("/variant/oom", test_oom_handling);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,6 +99,13 @@ void test_mkdir (const gchar *path, gint mode);
|
|||
|
||||
void test_timeout_reset (void);
|
||||
|
||||
void test_oom (void) _DBUS_GNUC_NORETURN;
|
||||
|
||||
DBusMessage *test_main_context_call_and_wait (TestMainContext *ctx,
|
||||
DBusConnection *connection,
|
||||
DBusMessage *call,
|
||||
int timeout);
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2, 44, 0)
|
||||
#define g_steal_pointer(x) backported_g_steal_pointer (x)
|
||||
/* A simplified version of g_steal_pointer without type-safety. */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue