mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2025-12-20 08:00:11 +01:00
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>
This commit is contained in:
parent
38ff6bd20d
commit
f59b4f9226
10 changed files with 54 additions and 26 deletions
|
|
@ -196,8 +196,7 @@ setup (Fixture *f,
|
||||||
f->right_conn = dbus_bus_get_private (DBUS_BUS_SESSION, &f->e);
|
f->right_conn = dbus_bus_get_private (DBUS_BUS_SESSION, &f->e);
|
||||||
test_assert_no_error (&f->e);
|
test_assert_no_error (&f->e);
|
||||||
|
|
||||||
if (!test_connection_setup (f->ctx, f->right_conn))
|
test_connection_setup (f->ctx, f->right_conn);
|
||||||
g_error ("OOM");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -251,8 +251,7 @@ setup_connection (Fixture *f,
|
||||||
dbus_server_set_new_connection_function (f->server,
|
dbus_server_set_new_connection_function (f->server,
|
||||||
new_conn_cb, f, NULL);
|
new_conn_cb, f, NULL);
|
||||||
|
|
||||||
if (!test_server_setup (f->loop, f->server))
|
test_server_setup (f->loop, f->server);
|
||||||
g_error ("failed to set up server");
|
|
||||||
|
|
||||||
address = dbus_server_get_address (f->server);
|
address = dbus_server_get_address (f->server);
|
||||||
g_assert (address != NULL);
|
g_assert (address != NULL);
|
||||||
|
|
@ -261,8 +260,7 @@ setup_connection (Fixture *f,
|
||||||
g_assert (f->connection != NULL);
|
g_assert (f->connection != NULL);
|
||||||
dbus_free (address);
|
dbus_free (address);
|
||||||
|
|
||||||
if (!test_connection_setup (f->loop, f->connection))
|
test_connection_setup (f->loop, f->connection);
|
||||||
g_error ("failed to set up connection");
|
|
||||||
|
|
||||||
while (f->server_connection == NULL)
|
while (f->server_connection == NULL)
|
||||||
_dbus_loop_iterate (f->loop, TRUE);
|
_dbus_loop_iterate (f->loop, TRUE);
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ new_connection_callback (DBusServer *server,
|
||||||
{
|
{
|
||||||
TestServiceData *testdata = data;
|
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);
|
dbus_connection_close (new_connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,8 +114,7 @@ main (int argc, char *argv[])
|
||||||
dbus_server_set_new_connection_function (server, new_connection_callback,
|
dbus_server_set_new_connection_function (server, new_connection_callback,
|
||||||
testdata, NULL);
|
testdata, NULL);
|
||||||
|
|
||||||
if (!test_server_setup (loop, server))
|
test_server_setup (loop, server);
|
||||||
die ("server setup failed");
|
|
||||||
|
|
||||||
fprintf (stderr, "server running mainloop\n");
|
fprintf (stderr, "server running mainloop\n");
|
||||||
_dbus_loop_run (loop);
|
_dbus_loop_run (loop);
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,7 @@ open_destroy_shared_session_bus_connection (void)
|
||||||
if (loop == NULL)
|
if (loop == NULL)
|
||||||
die ("No memory\n");
|
die ("No memory\n");
|
||||||
|
|
||||||
if (!test_connection_setup (loop, connection))
|
test_connection_setup (loop, connection);
|
||||||
die ("No memory\n");
|
|
||||||
|
|
||||||
test_connection_shutdown (loop, connection);
|
test_connection_shutdown (loop, connection);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,8 +64,7 @@ main (int argc,
|
||||||
if (loop == NULL)
|
if (loop == NULL)
|
||||||
die ("No memory\n");
|
die ("No memory\n");
|
||||||
|
|
||||||
if (!test_connection_setup (loop, connection))
|
test_connection_setup (loop, connection);
|
||||||
die ("No memory\n");
|
|
||||||
|
|
||||||
TestName(connection, "org.freedesktop.DBus.Test", TRUE);
|
TestName(connection, "org.freedesktop.DBus.Test", TRUE);
|
||||||
TestName(connection, "org.freedesktop.DBus.Test-2", TRUE);
|
TestName(connection, "org.freedesktop.DBus.Test-2", TRUE);
|
||||||
|
|
|
||||||
|
|
@ -452,9 +452,8 @@ main (int argc,
|
||||||
loop = _dbus_loop_new ();
|
loop = _dbus_loop_new ();
|
||||||
if (loop == NULL)
|
if (loop == NULL)
|
||||||
die ("No memory\n");
|
die ("No memory\n");
|
||||||
|
|
||||||
if (!test_connection_setup (loop, connection))
|
test_connection_setup (loop, connection);
|
||||||
die ("No memory\n");
|
|
||||||
|
|
||||||
if (!dbus_connection_add_filter (connection,
|
if (!dbus_connection_add_filter (connection,
|
||||||
filter_func, NULL, NULL))
|
filter_func, NULL, NULL))
|
||||||
|
|
|
||||||
|
|
@ -145,9 +145,8 @@ main (int argc,
|
||||||
loop = _dbus_loop_new ();
|
loop = _dbus_loop_new ();
|
||||||
if (loop == NULL)
|
if (loop == NULL)
|
||||||
die ("No memory\n");
|
die ("No memory\n");
|
||||||
|
|
||||||
if (!test_connection_setup (loop, connection))
|
test_connection_setup (loop, connection);
|
||||||
die ("No memory\n");
|
|
||||||
|
|
||||||
if (!dbus_connection_add_filter (connection,
|
if (!dbus_connection_add_filter (connection,
|
||||||
filter_func, NULL, NULL))
|
filter_func, NULL, NULL))
|
||||||
|
|
|
||||||
|
|
@ -346,7 +346,7 @@ test_try_connect_to_bus (TestMainContext *ctx,
|
||||||
|
|
||||||
g_assert (dbus_bus_get_unique_name (conn) != NULL);
|
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);
|
_DBUS_SET_OOM (&error);
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
|
||||||
|
|
@ -98,8 +98,8 @@ cdata_new (DBusLoop *loop,
|
||||||
}
|
}
|
||||||
|
|
||||||
dbus_bool_t
|
dbus_bool_t
|
||||||
test_connection_setup (TestMainContext *ctx,
|
test_connection_try_setup (TestMainContext *ctx,
|
||||||
DBusConnection *connection)
|
DBusConnection *connection)
|
||||||
{
|
{
|
||||||
DBusLoop *loop = ctx;
|
DBusLoop *loop = ctx;
|
||||||
CData *cd;
|
CData *cd;
|
||||||
|
|
@ -165,6 +165,14 @@ die (const char *message)
|
||||||
exit (1);
|
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
|
void
|
||||||
test_connection_shutdown (TestMainContext *ctx,
|
test_connection_shutdown (TestMainContext *ctx,
|
||||||
DBusConnection *connection)
|
DBusConnection *connection)
|
||||||
|
|
@ -268,8 +276,8 @@ remove_server_timeout (DBusTimeout *timeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
dbus_bool_t
|
dbus_bool_t
|
||||||
test_server_setup (TestMainContext *ctx,
|
test_server_try_setup (TestMainContext *ctx,
|
||||||
DBusServer *server)
|
DBusServer *server)
|
||||||
{
|
{
|
||||||
DBusLoop *loop = ctx;
|
DBusLoop *loop = ctx;
|
||||||
ServerData *sd;
|
ServerData *sd;
|
||||||
|
|
@ -311,6 +319,14 @@ test_server_setup (TestMainContext *ctx,
|
||||||
return FALSE;
|
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
|
void
|
||||||
test_server_shutdown (TestMainContext *ctx,
|
test_server_shutdown (TestMainContext *ctx,
|
||||||
DBusServer *server)
|
DBusServer *server)
|
||||||
|
|
@ -332,6 +348,17 @@ test_server_shutdown (TestMainContext *ctx,
|
||||||
|
|
||||||
TestMainContext *
|
TestMainContext *
|
||||||
test_main_context_get (void)
|
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 ();
|
return _dbus_loop_new ();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,18 +10,27 @@
|
||||||
#include <dbus/dbus-internals.h>
|
#include <dbus/dbus-internals.h>
|
||||||
typedef DBusLoop TestMainContext;
|
typedef DBusLoop TestMainContext;
|
||||||
|
|
||||||
|
_DBUS_GNUC_WARN_UNUSED_RESULT
|
||||||
TestMainContext *test_main_context_get (void);
|
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);
|
TestMainContext *test_main_context_ref (TestMainContext *ctx);
|
||||||
void test_main_context_unref (TestMainContext *ctx);
|
void test_main_context_unref (TestMainContext *ctx);
|
||||||
void test_main_context_iterate (TestMainContext *ctx,
|
void test_main_context_iterate (TestMainContext *ctx,
|
||||||
dbus_bool_t may_block);
|
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);
|
DBusConnection *connection);
|
||||||
void test_connection_shutdown (TestMainContext *ctx,
|
void test_connection_shutdown (TestMainContext *ctx,
|
||||||
DBusConnection *connection);
|
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);
|
DBusServer *server);
|
||||||
void test_server_shutdown (TestMainContext *ctx,
|
void test_server_shutdown (TestMainContext *ctx,
|
||||||
DBusServer *server);
|
DBusServer *server);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue