summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2017-11-27 19:26:03 +0000
committerSimon McVittie <smcv@collabora.com>2017-12-04 11:52:52 +0000
commitf59b4f9226c0134f91fc1eefebef6e7a816f85cd (patch)
treebeda5c6503d7bb010ee42abf15ea9a23466140a8
parent38ff6bd20d58b57a5dd0eab1b1c09c5c43b61d26 (diff)
test-utils: Separate failable and non-failable functions
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>
-rw-r--r--test/dbus-daemon.c3
-rw-r--r--test/internals/refs.c6
-rw-r--r--test/name-test/test-privserver.c5
-rw-r--r--test/name-test/test-shutdown.c3
-rw-r--r--test/test-names.c3
-rw-r--r--test/test-service.c5
-rw-r--r--test/test-shell-service.c5
-rw-r--r--test/test-utils-glib.c2
-rw-r--r--test/test-utils.c35
-rw-r--r--test/test-utils.h13
10 files changed, 54 insertions, 26 deletions
diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c
index 2c0d2b061..b3039c410 100644
--- a/test/dbus-daemon.c
+++ b/test/dbus-daemon.c
@@ -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
{
diff --git a/test/internals/refs.c b/test/internals/refs.c
index 3c6b438da..15178772f 100644
--- a/test/internals/refs.c
+++ b/test/internals/refs.c
@@ -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);
diff --git a/test/name-test/test-privserver.c b/test/name-test/test-privserver.c
index c6de73484..04f9cfa08 100644
--- a/test/name-test/test-privserver.c
+++ b/test/name-test/test-privserver.c
@@ -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);
diff --git a/test/name-test/test-shutdown.c b/test/name-test/test-shutdown.c
index e70bfd39e..dbbe52546 100644
--- a/test/name-test/test-shutdown.c
+++ b/test/name-test/test-shutdown.c
@@ -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);
diff --git a/test/test-names.c b/test/test-names.c
index 95e428651..eac79ee13 100644
--- a/test/test-names.c
+++ b/test/test-names.c
@@ -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);
diff --git a/test/test-service.c b/test/test-service.c
index f71e3e039..52ea38330 100644
--- a/test/test-service.c
+++ b/test/test-service.c
@@ -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))
diff --git a/test/test-shell-service.c b/test/test-shell-service.c
index 2eaccc1dc..b9de92b61 100644
--- a/test/test-shell-service.c
+++ b/test/test-shell-service.c
@@ -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))
diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c
index 5394ca4e9..4920e250e 100644
--- a/test/test-utils-glib.c
+++ b/test/test-utils-glib.c
@@ -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;
diff --git a/test/test-utils.c b/test/test-utils.c
index 53ad4a4ea..995605238 100644
--- a/test/test-utils.c
+++ b/test/test-utils.c
@@ -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;
@@ -166,6 +166,14 @@ die (const char *message)
}
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;
@@ -312,6 +320,14 @@ test_server_setup (TestMainContext *ctx,
}
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)
{
@@ -333,6 +349,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 ();
}
diff --git a/test/test-utils.h b/test/test-utils.h
index 39fae77b1..860ee216e 100644
--- a/test/test-utils.h
+++ b/test/test-utils.h
@@ -10,18 +10,27 @@
#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);