tests: Run more appinfo tests under a GTestDBus environment

I ran Bustle/dbus-monitor on the session bus while running the full GLib
test suite, and noticed that these tests were causing `Launched` signal
emissions on the main session bus. That suggested they weren’t isolated
properly, which at best causes noise on the bus and at worst could cause
spurious test failures.

Fix that by running those tests in a `GTestDBus` environment, as some of
the other appinfo tests already are.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall 2024-01-18 15:22:30 +00:00
parent 217e25ac67
commit 5c05dfad97
2 changed files with 33 additions and 0 deletions

View File

@ -6,6 +6,7 @@
#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
/* 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

View File

@ -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 *