]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
test-utils: Separate failable and non-failable functions
authorSimon McVittie <smcv@collabora.com>
Mon, 27 Nov 2017 19:26:03 +0000 (19:26 +0000)
committerSimon McVittie <smcv@collabora.com>
Mon, 4 Dec 2017 11:52:52 +0000 (11:52 +0000)
test_object_try_whatever() now has libdbus-like OOM handling,
while test_object_whatever() has GLib-like OOM handling. This is
because an overwhelming majority of the callers of these functions
either didn't check for OOM anyway, or checked for it but then
aborted. In the uncommon case where we do care, we can use the _try_
version.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=100317
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
test/dbus-daemon.c
test/internals/refs.c
test/name-test/test-privserver.c
test/name-test/test-shutdown.c
test/test-names.c
test/test-service.c
test/test-shell-service.c
test/test-utils-glib.c
test/test-utils.c
test/test-utils.h

index 2c0d2b06142fbec2a4215705c19f90aa036abaf3..b3039c41053f2aa39f0c84f3bd9b03612edc1cb4 100644 (file)
@@ -196,8 +196,7 @@ setup (Fixture *f,
       f->right_conn = dbus_bus_get_private (DBUS_BUS_SESSION, &f->e);
       test_assert_no_error (&f->e);
 
-      if (!test_connection_setup (f->ctx, f->right_conn))
-        g_error ("OOM");
+      test_connection_setup (f->ctx, f->right_conn);
     }
   else
     {
index 3c6b438da529c59a5195a2ca6ca1a3fbac3e2657..15178772f4ff9fd8e1687facd264862c17975821 100644 (file)
@@ -251,8 +251,7 @@ setup_connection (Fixture *f,
   dbus_server_set_new_connection_function (f->server,
       new_conn_cb, f, NULL);
 
-  if (!test_server_setup (f->loop, f->server))
-    g_error ("failed to set up server");
+  test_server_setup (f->loop, f->server);
 
   address = dbus_server_get_address (f->server);
   g_assert (address != NULL);
@@ -261,8 +260,7 @@ setup_connection (Fixture *f,
   g_assert (f->connection != NULL);
   dbus_free (address);
 
-  if (!test_connection_setup (f->loop, f->connection))
-    g_error ("failed to set up connection");
+  test_connection_setup (f->loop, f->connection);
 
   while (f->server_connection == NULL)
     _dbus_loop_iterate (f->loop, TRUE);
index c6de7348478085104b8c253efb1e1f12da48abf4..04f9cfa0841dfd2cf08d5831f1ea519e30e992e6 100644 (file)
@@ -29,7 +29,7 @@ new_connection_callback (DBusServer     *server,
 {
   TestServiceData *testdata = data;
 
-  if (!test_connection_setup (testdata->loop, new_connection))
+  if (!test_connection_try_setup (testdata->loop, new_connection))
     dbus_connection_close (new_connection);
 }
 
@@ -114,8 +114,7 @@ main (int argc, char *argv[])
   dbus_server_set_new_connection_function (server, new_connection_callback,
                                            testdata, NULL);
 
-  if (!test_server_setup (loop, server))
-    die ("server setup failed");
+  test_server_setup (loop, server);
 
   fprintf (stderr, "server running mainloop\n");
   _dbus_loop_run (loop);
index e70bfd39ef95f66bb614076f119d7a3c358adda5..dbbe52546a91f2f74429beaf3f4c271f26875dad 100644 (file)
@@ -38,8 +38,7 @@ open_destroy_shared_session_bus_connection (void)
   if (loop == NULL)
     die ("No memory\n");
   
-  if (!test_connection_setup (loop, connection))
-    die ("No memory\n");
+  test_connection_setup (loop, connection);
 
   test_connection_shutdown (loop, connection);
  
index 95e428651491b0ca2bf6e02ce3015328841881e6..eac79ee137b33344e6f4b638b093adc36bedc352 100644 (file)
@@ -64,8 +64,7 @@ main (int    argc,
   if (loop == NULL)
     die ("No memory\n");
   
-  if (!test_connection_setup (loop, connection))
-    die ("No memory\n");
+  test_connection_setup (loop, connection);
 
   TestName(connection, "org.freedesktop.DBus.Test", TRUE);
   TestName(connection, "org.freedesktop.DBus.Test-2", TRUE);
index f71e3e039bece83513b53edcd1bb043461ca44e0..52ea38330ca5bae23b931f9532b668000f06e335 100644 (file)
@@ -452,9 +452,8 @@ main (int    argc,
   loop = _dbus_loop_new ();
   if (loop == NULL)
     die ("No memory\n");
-  
-  if (!test_connection_setup (loop, connection))
-    die ("No memory\n");
+
+  test_connection_setup (loop, connection);
 
   if (!dbus_connection_add_filter (connection,
                                    filter_func, NULL, NULL))
index 2eaccc1dc4296fa559e4ba18f5d5eb30f64884c6..b9de92b615590460923e860f1aeb4551ab50ab2d 100644 (file)
@@ -145,9 +145,8 @@ main (int    argc,
   loop = _dbus_loop_new ();
   if (loop == NULL)
     die ("No memory\n");
-  
-  if (!test_connection_setup (loop, connection))
-    die ("No memory\n");
+
+  test_connection_setup (loop, connection);
 
   if (!dbus_connection_add_filter (connection,
                                    filter_func, NULL, NULL))
index 5394ca4e9bc6aec6f71b2f5e257dc83208be7131..4920e250e3a5cbbbd08c21a16947290b2323fab1 100644 (file)
@@ -346,7 +346,7 @@ test_try_connect_to_bus (TestMainContext *ctx,
 
   g_assert (dbus_bus_get_unique_name (conn) != NULL);
 
-  if (!test_connection_setup (ctx, conn))
+  if (!test_connection_try_setup (ctx, conn))
     {
       _DBUS_SET_OOM (&error);
       goto fail;
index 53ad4a4ea6e4cc8eda3aac705902a1c59e8f5698..99560523863dd55099a66633a3bfc84ca4c88129 100644 (file)
@@ -98,8 +98,8 @@ cdata_new (DBusLoop       *loop,
 }
 
 dbus_bool_t
-test_connection_setup (TestMainContext *ctx,
-                       DBusConnection *connection)
+test_connection_try_setup (TestMainContext *ctx,
+                           DBusConnection  *connection)
 {
   DBusLoop *loop = ctx;
   CData *cd;
@@ -165,6 +165,14 @@ die (const char *message)
   exit (1);
 }
 
+void
+test_connection_setup (TestMainContext *ctx,
+                       DBusConnection  *connection)
+{
+  if (!test_connection_try_setup (ctx, connection))
+    die ("Not enough memory to set up connection");
+}
+
 void
 test_connection_shutdown (TestMainContext *ctx,
                           DBusConnection *connection)
@@ -268,8 +276,8 @@ remove_server_timeout (DBusTimeout *timeout,
 }
 
 dbus_bool_t
-test_server_setup (TestMainContext *ctx,
-                   DBusServer    *server)
+test_server_try_setup (TestMainContext *ctx,
+                       DBusServer      *server)
 {
   DBusLoop *loop = ctx;
   ServerData *sd;
@@ -311,6 +319,14 @@ test_server_setup (TestMainContext *ctx,
   return FALSE;
 }
 
+void
+test_server_setup (TestMainContext *ctx,
+                   DBusServer      *server)
+{
+  if (!test_server_try_setup (ctx, server))
+    die ("Not enough memory to set up server");
+}
+
 void
 test_server_shutdown (TestMainContext  *ctx,
                       DBusServer       *server)
@@ -332,6 +348,17 @@ test_server_shutdown (TestMainContext  *ctx,
 
 TestMainContext *
 test_main_context_get (void)
+{
+  TestMainContext *ret = _dbus_loop_new ();
+
+  if (ret == NULL)
+    die ("Out of memory");
+
+  return ret;
+}
+
+TestMainContext *
+test_main_context_try_get (void)
 {
   return _dbus_loop_new ();
 }
index 39fae77b119493b67bb9fa9a3c4f4dbd42281c75..860ee216ef38e40215045482eebaa7c6fc96311e 100644 (file)
 #include <dbus/dbus-internals.h>
 typedef DBusLoop TestMainContext;
 
+_DBUS_GNUC_WARN_UNUSED_RESULT
 TestMainContext *test_main_context_get            (void);
+_DBUS_GNUC_WARN_UNUSED_RESULT
+TestMainContext *test_main_context_try_get        (void);
 TestMainContext *test_main_context_ref            (TestMainContext *ctx);
 void             test_main_context_unref          (TestMainContext *ctx);
 void             test_main_context_iterate        (TestMainContext *ctx,
                                                    dbus_bool_t      may_block);
 
-dbus_bool_t test_connection_setup                 (TestMainContext *ctx,
+_DBUS_GNUC_WARN_UNUSED_RESULT
+dbus_bool_t test_connection_try_setup             (TestMainContext *ctx,
+                                                   DBusConnection *connection);
+void        test_connection_setup                 (TestMainContext *ctx,
                                                    DBusConnection *connection);
 void        test_connection_shutdown              (TestMainContext *ctx,
                                                    DBusConnection *connection);
 
-dbus_bool_t test_server_setup                     (TestMainContext *ctx,
+_DBUS_GNUC_WARN_UNUSED_RESULT
+dbus_bool_t test_server_try_setup                 (TestMainContext *ctx,
+                                                   DBusServer    *server);
+void        test_server_setup                     (TestMainContext *ctx,
                                                    DBusServer    *server);
 void        test_server_shutdown                  (TestMainContext *ctx,
                                                    DBusServer    *server);