]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
test_main_context_call_and_wait: Add
authorSimon McVittie <smcv@collabora.com>
Tue, 21 Nov 2017 12:15:04 +0000 (12:15 +0000)
committerSimon McVittie <smcv@collabora.com>
Fri, 24 Nov 2017 12:19:15 +0000 (12:19 +0000)
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

test/internals/variant.c
test/test-utils-glib.c
test/test-utils-glib.h

index b8249fd1976ce73e756d38f616ec3fec48b9cb8e..69954e7abee86a761abc368e56ccc080c1ad7de0 100644 (file)
@@ -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 ();
 }
index ccf8769962f22ec80da2ff5414776e0e5c5b6a6f..a539c5c84e3bf1c1904c35d5166d59f4c60f2198 100644 (file)
@@ -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);
+}
index 9822a36d8d065799c071acb9deb64f571fa3d953..2c0f9d699285f203d8d7f335a88bf6f4a954ff48 100644 (file)
@@ -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. */