mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-04 10:16:17 +01:00
tests: Isolate directories in appinfo test
This is essentially a reversion of commit
a39b847ddf
, plus the addition of the new
G_TEST_OPTIONS_ISOLATE_XDG_DIRS option.
Signed-off-by: Philip Withnall <withnall@endlessm.com>
https://gitlab.gnome.org/GNOME/glib/issues/1601
This commit is contained in:
parent
99bc33b632
commit
797a8b0930
@ -6,111 +6,6 @@
|
||||
#include <gio/gio.h>
|
||||
#include <gio/gdesktopappinfo.h>
|
||||
|
||||
static gboolean
|
||||
cleanup_dir_recurse (GFile *parent,
|
||||
GFile *root,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
GFileEnumerator *enumerator;
|
||||
GError *local_error = NULL;
|
||||
|
||||
g_assert (root != NULL);
|
||||
|
||||
enumerator =
|
||||
g_file_enumerate_children (parent, "*",
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL,
|
||||
&local_error);
|
||||
if (!enumerator)
|
||||
{
|
||||
if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
|
||||
{
|
||||
g_clear_error (&local_error);
|
||||
ret = TRUE;
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
GFile *child;
|
||||
GFileInfo *finfo;
|
||||
char *relative_path;
|
||||
|
||||
if (!g_file_enumerator_iterate (enumerator, &finfo, &child, NULL, error))
|
||||
goto out;
|
||||
if (!finfo)
|
||||
break;
|
||||
|
||||
relative_path = g_file_get_relative_path (root, child);
|
||||
g_assert (relative_path != NULL);
|
||||
g_free (relative_path);
|
||||
|
||||
if (g_file_info_get_file_type (finfo) == G_FILE_TYPE_DIRECTORY)
|
||||
{
|
||||
if (!cleanup_dir_recurse (child, root, error))
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!g_file_delete (child, NULL, error))
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
g_clear_object (&enumerator);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gchar *tmp_dir;
|
||||
gchar *config_dir;
|
||||
gchar *data_dir;
|
||||
} Fixture;
|
||||
|
||||
static void
|
||||
setup (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
{
|
||||
GError *local_error = NULL;
|
||||
|
||||
fixture->tmp_dir = g_dir_make_tmp ("gio-test-appinfo_XXXXXX", &local_error);
|
||||
g_assert_no_error (local_error);
|
||||
|
||||
fixture->config_dir = g_build_filename (fixture->tmp_dir, "config", NULL);
|
||||
g_assert_cmpint (g_mkdir (fixture->config_dir, 0755), ==, 0);
|
||||
|
||||
fixture->data_dir = g_build_filename (fixture->tmp_dir, "data", NULL);
|
||||
g_assert_cmpint (g_mkdir (fixture->data_dir, 0755), ==, 0);
|
||||
|
||||
g_setenv ("XDG_CONFIG_HOME", fixture->config_dir, TRUE);
|
||||
g_setenv ("XDG_DATA_HOME", fixture->data_dir, TRUE);
|
||||
|
||||
g_setenv ("XDG_DATA_DIRS", "/dev/null", TRUE);
|
||||
g_setenv ("XDG_CONFIG_DIRS", "/dev/null", TRUE);
|
||||
g_setenv ("XDG_CACHE_HOME", "/dev/null", TRUE);
|
||||
g_setenv ("XDG_RUNTIME_DIR", "/dev/null", TRUE);
|
||||
|
||||
g_test_message ("Using tmp directory: %s", fixture->tmp_dir);
|
||||
}
|
||||
|
||||
static void
|
||||
teardown (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
{
|
||||
GFile *tmp_dir = g_file_new_for_path (fixture->tmp_dir);
|
||||
GError *local_error = NULL;
|
||||
|
||||
cleanup_dir_recurse (tmp_dir, tmp_dir, &local_error);
|
||||
g_assert_no_error (local_error);
|
||||
|
||||
g_clear_pointer (&fixture->config_dir, g_free);
|
||||
g_clear_pointer (&fixture->data_dir, g_free);
|
||||
g_clear_pointer (&fixture->tmp_dir, g_free);
|
||||
}
|
||||
|
||||
static void
|
||||
test_launch_for_app_info (GAppInfo *appinfo)
|
||||
{
|
||||
@ -155,8 +50,7 @@ test_launch_for_app_info (GAppInfo *appinfo)
|
||||
}
|
||||
|
||||
static void
|
||||
test_launch (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
test_launch (void)
|
||||
{
|
||||
GAppInfo *appinfo;
|
||||
const gchar *path;
|
||||
@ -170,8 +64,7 @@ test_launch (Fixture *fixture,
|
||||
}
|
||||
|
||||
static void
|
||||
test_launch_no_app_id (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
test_launch_no_app_id (void)
|
||||
{
|
||||
const gchar desktop_file_base_contents[] =
|
||||
"[Desktop Entry]\n"
|
||||
@ -278,8 +171,7 @@ test_locale (const char *locale)
|
||||
}
|
||||
|
||||
static void
|
||||
test_text (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
test_text (void)
|
||||
{
|
||||
test_locale ("C");
|
||||
test_locale ("en_US");
|
||||
@ -288,8 +180,7 @@ test_text (Fixture *fixture,
|
||||
}
|
||||
|
||||
static void
|
||||
test_basic (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
test_basic (void)
|
||||
{
|
||||
GAppInfo *appinfo;
|
||||
GAppInfo *appinfo2;
|
||||
@ -317,8 +208,7 @@ test_basic (Fixture *fixture,
|
||||
}
|
||||
|
||||
static void
|
||||
test_show_in (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
test_show_in (void)
|
||||
{
|
||||
GAppInfo *appinfo;
|
||||
const gchar *path;
|
||||
@ -340,8 +230,7 @@ test_show_in (Fixture *fixture,
|
||||
}
|
||||
|
||||
static void
|
||||
test_commandline (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
test_commandline (void)
|
||||
{
|
||||
GAppInfo *appinfo;
|
||||
GError *error;
|
||||
@ -387,8 +276,7 @@ test_commandline (Fixture *fixture,
|
||||
}
|
||||
|
||||
static void
|
||||
test_launch_context (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
test_launch_context (void)
|
||||
{
|
||||
GAppLaunchContext *context;
|
||||
GAppInfo *appinfo;
|
||||
@ -440,8 +328,7 @@ launch_failed (GAppLaunchContext *context,
|
||||
}
|
||||
|
||||
static void
|
||||
test_launch_context_signals (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
test_launch_context_signals (void)
|
||||
{
|
||||
GAppLaunchContext *context;
|
||||
GAppInfo *appinfo;
|
||||
@ -471,8 +358,7 @@ test_launch_context_signals (Fixture *fixture,
|
||||
}
|
||||
|
||||
static void
|
||||
test_tryexec (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
test_tryexec (void)
|
||||
{
|
||||
GAppInfo *appinfo;
|
||||
const gchar *path;
|
||||
@ -487,8 +373,7 @@ test_tryexec (Fixture *fixture,
|
||||
* file extension, and also add and remove handled mime types.
|
||||
*/
|
||||
static void
|
||||
test_associations (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
test_associations (void)
|
||||
{
|
||||
GAppInfo *appinfo;
|
||||
GAppInfo *appinfo2;
|
||||
@ -549,8 +434,7 @@ test_associations (Fixture *fixture,
|
||||
}
|
||||
|
||||
static void
|
||||
test_environment (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
test_environment (void)
|
||||
{
|
||||
GAppLaunchContext *ctx;
|
||||
gchar **env;
|
||||
@ -595,8 +479,7 @@ test_environment (Fixture *fixture,
|
||||
}
|
||||
|
||||
static void
|
||||
test_startup_wm_class (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
test_startup_wm_class (void)
|
||||
{
|
||||
GDesktopAppInfo *appinfo;
|
||||
const char *wm_class;
|
||||
@ -612,8 +495,7 @@ test_startup_wm_class (Fixture *fixture,
|
||||
}
|
||||
|
||||
static void
|
||||
test_supported_types (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
test_supported_types (void)
|
||||
{
|
||||
GAppInfo *appinfo;
|
||||
const char * const *content_types;
|
||||
@ -630,8 +512,7 @@ test_supported_types (Fixture *fixture,
|
||||
}
|
||||
|
||||
static void
|
||||
test_from_keyfile (Fixture *fixture,
|
||||
gconstpointer user_data)
|
||||
test_from_keyfile (void)
|
||||
{
|
||||
GDesktopAppInfo *info;
|
||||
GKeyFile *kf;
|
||||
@ -681,23 +562,23 @@ main (int argc, char *argv[])
|
||||
{
|
||||
g_setenv ("XDG_CURRENT_DESKTOP", "GNOME", TRUE);
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
|
||||
g_test_bug_base ("https://bugzilla.gnome.org/show_bug.cgi?id=");
|
||||
|
||||
g_test_add ("/appinfo/basic", Fixture, NULL, setup, test_basic, teardown);
|
||||
g_test_add ("/appinfo/text", Fixture, NULL, setup, test_text, teardown);
|
||||
g_test_add ("/appinfo/launch", Fixture, NULL, setup, test_launch, teardown);
|
||||
g_test_add ("/appinfo/launch/no-appid", Fixture, NULL, setup, test_launch_no_app_id, teardown);
|
||||
g_test_add ("/appinfo/show-in", Fixture, NULL, setup, test_show_in, teardown);
|
||||
g_test_add ("/appinfo/commandline", Fixture, NULL, setup, test_commandline, teardown);
|
||||
g_test_add ("/appinfo/launch-context", Fixture, NULL, setup, test_launch_context, teardown);
|
||||
g_test_add ("/appinfo/launch-context-signals", Fixture, NULL, setup, test_launch_context_signals, teardown);
|
||||
g_test_add ("/appinfo/tryexec", Fixture, NULL, setup, test_tryexec, teardown);
|
||||
g_test_add ("/appinfo/associations", Fixture, NULL, setup, test_associations, teardown);
|
||||
g_test_add ("/appinfo/environment", Fixture, NULL, setup, test_environment, teardown);
|
||||
g_test_add ("/appinfo/startup-wm-class", Fixture, NULL, setup, test_startup_wm_class, teardown);
|
||||
g_test_add ("/appinfo/supported-types", Fixture, NULL, setup, test_supported_types, teardown);
|
||||
g_test_add ("/appinfo/from-keyfile", Fixture, NULL, setup, test_from_keyfile, teardown);
|
||||
g_test_add_func ("/appinfo/basic", test_basic);
|
||||
g_test_add_func ("/appinfo/text", test_text);
|
||||
g_test_add_func ("/appinfo/launch", test_launch);
|
||||
g_test_add_func ("/appinfo/launch/no-appid", test_launch_no_app_id);
|
||||
g_test_add_func ("/appinfo/show-in", test_show_in);
|
||||
g_test_add_func ("/appinfo/commandline", test_commandline);
|
||||
g_test_add_func ("/appinfo/launch-context", test_launch_context);
|
||||
g_test_add_func ("/appinfo/launch-context-signals", test_launch_context_signals);
|
||||
g_test_add_func ("/appinfo/tryexec", test_tryexec);
|
||||
g_test_add_func ("/appinfo/associations", test_associations);
|
||||
g_test_add_func ("/appinfo/environment", test_environment);
|
||||
g_test_add_func ("/appinfo/startup-wm-class", test_startup_wm_class);
|
||||
g_test_add_func ("/appinfo/supported-types", test_supported_types);
|
||||
g_test_add_func ("/appinfo/from-keyfile", test_from_keyfile);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user