Merge branch 'test-improvements' into 'main'

tests: A couple of test isolation improvements

See merge request GNOME/glib!3837
This commit is contained in:
Marco Trevisan 2024-01-18 16:27:12 +00:00
commit 7cd819126a
3 changed files with 36 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 *

View File

@ -55,6 +55,9 @@ test_fail (void)
static void
test_error (void)
{
/* We expect this test to abort, so try to avoid that creating a coredump */
g_test_disable_crash_reporting ();
g_error ("This should error out\nBecause it's just\nwrong!");
}