mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-05 10:38:08 +01:00
Merge branch 'test-improvements' into 'main'
tests: A couple of test isolation improvements See merge request GNOME/glib!3837
This commit is contained in:
commit
7cd819126a
@ -6,6 +6,7 @@
|
|||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
#include <gio/gdesktopappinfo.h>
|
#include <gio/gdesktopappinfo.h>
|
||||||
|
|
||||||
|
/* Should be called inside a #GTestDBus environment. */
|
||||||
static void
|
static void
|
||||||
test_launch_for_app_info (GAppInfo *appinfo)
|
test_launch_for_app_info (GAppInfo *appinfo)
|
||||||
{
|
{
|
||||||
@ -51,15 +52,23 @@ test_launch_for_app_info (GAppInfo *appinfo)
|
|||||||
static void
|
static void
|
||||||
test_launch (void)
|
test_launch (void)
|
||||||
{
|
{
|
||||||
|
GTestDBus *bus = NULL;
|
||||||
GAppInfo *appinfo;
|
GAppInfo *appinfo;
|
||||||
const gchar *path;
|
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);
|
path = g_test_get_filename (G_TEST_BUILT, "appinfo-test.desktop", NULL);
|
||||||
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
|
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
|
||||||
g_assert_true (G_IS_APP_INFO (appinfo));
|
g_assert_true (G_IS_APP_INFO (appinfo));
|
||||||
|
|
||||||
test_launch_for_app_info (appinfo);
|
test_launch_for_app_info (appinfo);
|
||||||
g_object_unref (appinfo);
|
g_object_unref (appinfo);
|
||||||
|
|
||||||
|
g_test_dbus_down (bus);
|
||||||
|
g_clear_object (&bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -83,6 +92,7 @@ test_launch_no_app_id (void)
|
|||||||
"Keywords=keyword1;test keyword;\n"
|
"Keywords=keyword1;test keyword;\n"
|
||||||
"Categories=GNOME;GTK;\n";
|
"Categories=GNOME;GTK;\n";
|
||||||
|
|
||||||
|
GTestDBus *bus = NULL;
|
||||||
gchar *exec_line_variants[2];
|
gchar *exec_line_variants[2];
|
||||||
gsize i;
|
gsize i;
|
||||||
|
|
||||||
@ -95,6 +105,10 @@ test_launch_no_app_id (void)
|
|||||||
|
|
||||||
g_test_bug ("https://bugzilla.gnome.org/show_bug.cgi?id=791337");
|
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++)
|
for (i = 0; i < G_N_ELEMENTS (exec_line_variants); i++)
|
||||||
{
|
{
|
||||||
gchar *desktop_file_contents;
|
gchar *desktop_file_contents;
|
||||||
@ -125,6 +139,9 @@ test_launch_no_app_id (void)
|
|||||||
g_key_file_unref (fake_desktop_file);
|
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[1]);
|
||||||
g_free (exec_line_variants[0]);
|
g_free (exec_line_variants[0]);
|
||||||
}
|
}
|
||||||
@ -332,12 +349,17 @@ launch_failed (GAppLaunchContext *context,
|
|||||||
static void
|
static void
|
||||||
test_launch_context_signals (void)
|
test_launch_context_signals (void)
|
||||||
{
|
{
|
||||||
|
GTestDBus *bus = NULL;
|
||||||
GAppLaunchContext *context;
|
GAppLaunchContext *context;
|
||||||
GAppInfo *appinfo;
|
GAppInfo *appinfo;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gboolean success;
|
gboolean success;
|
||||||
gchar *cmdline;
|
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);
|
cmdline = g_strconcat (g_test_get_dir (G_TEST_BUILT), "/appinfo-test --option", NULL);
|
||||||
|
|
||||||
context = g_app_launch_context_new ();
|
context = g_app_launch_context_new ();
|
||||||
@ -358,6 +380,9 @@ test_launch_context_signals (void)
|
|||||||
g_object_unref (context);
|
g_object_unref (context);
|
||||||
|
|
||||||
g_free (cmdline);
|
g_free (cmdline);
|
||||||
|
|
||||||
|
g_test_dbus_down (bus);
|
||||||
|
g_clear_object (&bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -596,6 +596,7 @@ wait_for_file (const gchar *want_this,
|
|||||||
static void
|
static void
|
||||||
test_actions (void)
|
test_actions (void)
|
||||||
{
|
{
|
||||||
|
GTestDBus *bus = NULL;
|
||||||
const char *expected[] = { "frob", "tweak", "twiddle", "broken", NULL };
|
const char *expected[] = { "frob", "tweak", "twiddle", "broken", NULL };
|
||||||
const gchar * const *actions;
|
const gchar * const *actions;
|
||||||
GDesktopAppInfo *appinfo;
|
GDesktopAppInfo *appinfo;
|
||||||
@ -605,6 +606,10 @@ test_actions (void)
|
|||||||
gchar *tweak_path;
|
gchar *tweak_path;
|
||||||
gchar *twiddle_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));
|
appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_DIST, "appinfo-test-actions.desktop", NULL));
|
||||||
g_assert_nonnull (appinfo);
|
g_assert_nonnull (appinfo);
|
||||||
|
|
||||||
@ -651,6 +656,9 @@ test_actions (void)
|
|||||||
g_free (tweak_path);
|
g_free (tweak_path);
|
||||||
g_free (twiddle_path);
|
g_free (twiddle_path);
|
||||||
g_object_unref (appinfo);
|
g_object_unref (appinfo);
|
||||||
|
|
||||||
|
g_test_dbus_down (bus);
|
||||||
|
g_clear_object (&bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar *
|
static gchar *
|
||||||
|
@ -55,6 +55,9 @@ test_fail (void)
|
|||||||
static void
|
static void
|
||||||
test_error (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!");
|
g_error ("This should error out\nBecause it's just\nwrong!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user