diff options
author | Philip Withnall <withnall@endlessm.com> | 2018-08-14 16:03:03 +0100 |
---|---|---|
committer | Philip Withnall <withnall@endlessm.com> | 2018-08-16 18:58:27 +0100 |
commit | a8dcd4f0decf78afdd22caaaad4ac746e075c3b0 (patch) | |
tree | 5f26bd3238f330f280d15ed9421bf88b7258d1e5 /tests/dbus.c | |
parent | ea8c09f14da4b931cdadbabe2be315f6747ac7b7 (diff) | |
download | dconf-a8dcd4f0decf78afdd22caaaad4ac746e075c3b0.tar.gz |
tests: Stop using deprecated g_test_trap_fork() API
Use g_test_subprocess() and g_test_trap_subprocess() instead. This
requires splitting up some of the unit tests, since subprocesses are
handled at a per-test level, and you can’t trivially fork multiple
different subprocesses from a single test (like you could with fork()).
While fork was safe to use on POSIX (and dconf only targets POSIX), the
fact that we had to redefine GLIB_VERSION_MIN_REQUIRED to hide the
deprecation errors was not doing wonders for the maintainability of the
tests.
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Diffstat (limited to 'tests/dbus.c')
-rw-r--r-- | tests/dbus.c | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/tests/dbus.c b/tests/dbus.c index 980d2b0..032cb04 100644 --- a/tests/dbus.c +++ b/tests/dbus.c @@ -1,5 +1,3 @@ -#define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_36 /* Suppress deprecation warnings */ - #include <string.h> #include <glib.h> #include <stdlib.h> @@ -147,7 +145,7 @@ dconf_engine_handle_dbus_signal (GBusType bus_type, } static void -test_creation_error (void) +test_creation_error_sync_with_error (void) { if (g_getenv ("DISPLAY") == NULL || g_strcmp0 (g_getenv ("DISPLAY"), "") == 0) { @@ -156,7 +154,7 @@ test_creation_error (void) } /* Sync with 'error' */ - if (g_test_trap_fork (0, 0)) + if (g_test_subprocess ()) { GError *error = NULL; GVariant *reply; @@ -170,13 +168,24 @@ test_creation_error (void) g_assert (reply == NULL); g_assert (error != NULL); g_assert (strstr (error->message, "some nonsense")); - exit (0); + return; } + g_test_trap_subprocess (NULL, 0, 0); g_test_trap_assert_passed (); +} + +static void +test_creation_error_sync_without_error (void) +{ + if (g_getenv ("DISPLAY") == NULL || g_strcmp0 (g_getenv ("DISPLAY"), "") == 0) + { + g_test_skip ("FIXME: D-Bus tests do not work on CI at the moment"); + return; + } /* Sync without 'error' */ - if (g_test_trap_fork (0, 0)) + if (g_test_subprocess ()) { GVariant *reply; @@ -187,13 +196,24 @@ test_creation_error (void) g_variant_new ("()"), G_VARIANT_TYPE ("(as)"), NULL); g_assert (reply == NULL); - exit (0); + return; } + g_test_trap_subprocess (NULL, 0, 0); g_test_trap_assert_passed (); +} + +static void +test_creation_error_async (void) +{ + if (g_getenv ("DISPLAY") == NULL || g_strcmp0 (g_getenv ("DISPLAY"), "") == 0) + { + g_test_skip ("FIXME: D-Bus tests do not work on CI at the moment"); + return; + } /* Async */ - if (g_test_trap_fork (0, 0)) + if (g_test_subprocess ()) { DConfEngineCallHandle *handle; GError *error = NULL; @@ -222,9 +242,10 @@ test_creation_error (void) else g_assert (error != NULL); - exit (0); + return; } + g_test_trap_subprocess (NULL, 0, 0); g_test_trap_assert_passed (); } @@ -506,7 +527,11 @@ main (int argc, char **argv) /* test_creation_error absolutely must come first */ if (!g_str_equal (DBUS_BACKEND, "/libdbus-1")) - g_test_add_func (DBUS_BACKEND "/creation/error", test_creation_error); + { + g_test_add_func (DBUS_BACKEND "/creation/error/sync-with-error", test_creation_error_sync_with_error); + g_test_add_func (DBUS_BACKEND "/creation/error/sync-without-error", test_creation_error_sync_without_error); + g_test_add_func (DBUS_BACKEND "/creation/error/async", test_creation_error_async); + } g_test_add_func (DBUS_BACKEND "/sync-call/success", test_sync_call_success); g_test_add_func (DBUS_BACKEND "/sync-call/error", test_sync_call_error); |