diff options
author | Dan Winship <danw@gnome.org> | 2012-11-24 16:34:13 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2012-12-19 14:35:10 -0500 |
commit | ea06ec80634ff8f22882f3bc92effb10ac294e41 (patch) | |
tree | 936f2a046818149587cf1f20eae6f6c2d8f2fc4a /gio/tests/gdbus-exit-on-close.c | |
parent | e3a29184d56b3a65664eb8859e61afbc804497c8 (diff) |
tests: port from g_test_trap_subprocess() to g_test_trap_fork()
(or, in a few cases, to g_test_expect_message())
https://bugzilla.gnome.org/show_bug.cgi?id=679683
Diffstat (limited to 'gio/tests/gdbus-exit-on-close.c')
-rw-r--r-- | gio/tests/gdbus-exit-on-close.c | 133 |
1 files changed, 72 insertions, 61 deletions
diff --git a/gio/tests/gdbus-exit-on-close.c b/gio/tests/gdbus-exit-on-close.c index 08338c492..02bb50251 100644 --- a/gio/tests/gdbus-exit-on-close.c +++ b/gio/tests/gdbus-exit-on-close.c @@ -109,14 +109,74 @@ close_async_cb (GObject *source G_GNUC_UNUSED, } static void -test_exit_on_close (gconstpointer test_data) +test_exit_on_close_child (gconstpointer test_data) { const TestData *td = test_data; - GTestTrapFlags silence; + GDBusConnection *c; - /* all the tests rely on a shared main loop */ loop = g_main_loop_new (NULL, FALSE); + session_bus_up (); + c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); + + g_assert (c != NULL); + + /* the default is meant to be TRUE */ + if (td->exit_on_close != IMPLICITLY_TRUE) + g_dbus_connection_set_exit_on_close (c, td->exit_on_close); + + g_assert_cmpint (g_dbus_connection_get_exit_on_close (c), ==, + (td->exit_on_close != EXPLICITLY_FALSE)); + g_assert (!g_dbus_connection_is_closed (c)); + + g_timeout_add (50, quit_later_cb, NULL); + g_main_loop_run (loop); + + g_signal_connect (c, "closed", G_CALLBACK (closed_cb), (gpointer) td); + + if (td->who_closes == LOCAL) + { + GVariant *v; + GError *error = NULL; + + v = g_dbus_connection_call_sync (c, "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + "ListNames", + NULL, + G_VARIANT_TYPE ("(as)"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + g_assert_no_error (error); + g_assert (v != NULL); + g_variant_unref (v); + + g_dbus_connection_close (c, NULL, close_async_cb, NULL); + } + else + { + session_bus_stop (); + } + + g_main_loop_run (loop); + /* this is only reached when we turn off exit-on-close */ + g_main_loop_unref (loop); + g_object_unref (c); + + session_bus_down (); + + exit (0); +} + +static void +test_exit_on_close (gconstpointer test_data) +{ + const TestData *td = test_data; + GTestTrapFlags silence; + char *child_name; + g_test_dbus_unset (); if (g_test_verbose ()) @@ -124,63 +184,9 @@ test_exit_on_close (gconstpointer test_data) else silence = G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR; - if (g_test_trap_fork (0, silence)) - { - GDBusConnection *c; - - session_bus_up (); - c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); - - g_assert (c != NULL); - - /* the default is meant to be TRUE */ - if (td->exit_on_close != IMPLICITLY_TRUE) - g_dbus_connection_set_exit_on_close (c, td->exit_on_close); - - g_assert_cmpint (g_dbus_connection_get_exit_on_close (c), ==, - (td->exit_on_close != EXPLICITLY_FALSE)); - g_assert (!g_dbus_connection_is_closed (c)); - - g_timeout_add (50, quit_later_cb, NULL); - g_main_loop_run (loop); - - g_signal_connect (c, "closed", G_CALLBACK (closed_cb), (gpointer) td); - - if (td->who_closes == LOCAL) - { - GVariant *v; - GError *error = NULL; - - v = g_dbus_connection_call_sync (c, "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus", - "ListNames", - NULL, - G_VARIANT_TYPE ("(as)"), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - &error); - g_assert_no_error (error); - g_assert (v != NULL); - g_variant_unref (v); - - g_dbus_connection_close (c, NULL, close_async_cb, NULL); - } - else - { - session_bus_stop (); - } - - g_main_loop_run (loop); - /* this is only reached when we turn off exit-on-close */ - g_main_loop_unref (loop); - g_object_unref (c); - - session_bus_down (); - - exit (0); - } + child_name = g_strdup_printf ("/gdbus/exit-on-close/%s:child", td->name); + g_test_trap_subprocess (child_name, 0, silence); + g_free (child_name); if (td->exit_on_close == EXPLICITLY_FALSE || td->who_closes == LOCAL) @@ -207,10 +213,15 @@ main (int argc, for (i = 0; cases[i].name != NULL; i++) { - gchar *name = g_strdup_printf ("/gdbus/exit-on-close/%s", cases[i].name); + gchar *name; + name = g_strdup_printf ("/gdbus/exit-on-close/%s", cases[i].name); g_test_add_data_func (name, &cases[i], test_exit_on_close); g_free (name); + + name = g_strdup_printf ("/gdbus/exit-on-close/%s:child", cases[i].name); + g_test_add_data_func (name, &cases[i], test_exit_on_close_child); + g_free (name); } return g_test_run(); |