diff --git a/gio/tests/appinfo.c b/gio/tests/appinfo.c index 6a2ae697b..d9c53c853 100644 --- a/gio/tests/appinfo.c +++ b/gio/tests/appinfo.c @@ -6,6 +6,7 @@ #include #include +/* Should be called inside a #GTestDBus environment. */ static void test_launch_for_app_info (GAppInfo *appinfo) { @@ -51,15 +52,23 @@ test_launch_for_app_info (GAppInfo *appinfo) static void test_launch (void) { + GTestDBus *bus = NULL; GAppInfo *appinfo; const gchar *path; + /* Set up a test session bus to keep D-Bus traffic off the real session bus. */ + bus = g_test_dbus_new (G_TEST_DBUS_NONE); + g_test_dbus_up (bus); + path = g_test_get_filename (G_TEST_BUILT, "appinfo-test.desktop", NULL); appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path); g_assert_true (G_IS_APP_INFO (appinfo)); test_launch_for_app_info (appinfo); g_object_unref (appinfo); + + g_test_dbus_down (bus); + g_clear_object (&bus); } static void @@ -83,6 +92,7 @@ test_launch_no_app_id (void) "Keywords=keyword1;test keyword;\n" "Categories=GNOME;GTK;\n"; + GTestDBus *bus = NULL; gchar *exec_line_variants[2]; gsize i; @@ -95,6 +105,10 @@ test_launch_no_app_id (void) g_test_bug ("https://bugzilla.gnome.org/show_bug.cgi?id=791337"); + /* Set up a test session bus to keep D-Bus traffic off the real session bus. */ + bus = g_test_dbus_new (G_TEST_DBUS_NONE); + g_test_dbus_up (bus); + for (i = 0; i < G_N_ELEMENTS (exec_line_variants); i++) { gchar *desktop_file_contents; @@ -125,6 +139,9 @@ test_launch_no_app_id (void) g_key_file_unref (fake_desktop_file); } + g_test_dbus_down (bus); + g_clear_object (&bus); + g_free (exec_line_variants[1]); g_free (exec_line_variants[0]); } @@ -332,12 +349,17 @@ launch_failed (GAppLaunchContext *context, static void test_launch_context_signals (void) { + GTestDBus *bus = NULL; GAppLaunchContext *context; GAppInfo *appinfo; GError *error = NULL; gboolean success; gchar *cmdline; + /* Set up a test session bus to keep D-Bus traffic off the real session bus. */ + bus = g_test_dbus_new (G_TEST_DBUS_NONE); + g_test_dbus_up (bus); + cmdline = g_strconcat (g_test_get_dir (G_TEST_BUILT), "/appinfo-test --option", NULL); context = g_app_launch_context_new (); @@ -358,6 +380,9 @@ test_launch_context_signals (void) g_object_unref (context); g_free (cmdline); + + g_test_dbus_down (bus); + g_clear_object (&bus); } static void diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c index bd28f940e..e82e2dd31 100644 --- a/gio/tests/desktop-app-info.c +++ b/gio/tests/desktop-app-info.c @@ -596,6 +596,7 @@ wait_for_file (const gchar *want_this, static void test_actions (void) { + GTestDBus *bus = NULL; const char *expected[] = { "frob", "tweak", "twiddle", "broken", NULL }; const gchar * const *actions; GDesktopAppInfo *appinfo; @@ -605,6 +606,10 @@ test_actions (void) gchar *tweak_path; gchar *twiddle_path; + /* Set up a test session bus to keep D-Bus traffic off the real session bus. */ + bus = g_test_dbus_new (G_TEST_DBUS_NONE); + g_test_dbus_up (bus); + appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_DIST, "appinfo-test-actions.desktop", NULL)); g_assert_nonnull (appinfo); @@ -651,6 +656,9 @@ test_actions (void) g_free (tweak_path); g_free (twiddle_path); g_object_unref (appinfo); + + g_test_dbus_down (bus); + g_clear_object (&bus); } static gchar *