mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-03 06:32:10 +01:00
tests: Avoid chdir() call at the start of appinfo tests
By encoding the path to the appinfo-test binary in the .desktop files, we can avoid a chdir() call in the tests, which was a bit ugly. Signed-off-by: Philip Withnall <withnall@endlessm.com> https://gitlab.gnome.org/GNOME/glib/issues/538
This commit is contained in:
parent
aee897bd89
commit
46f47641c5
@ -339,10 +339,6 @@ dist_test_data += \
|
||||
|
||||
dist_test_data += \
|
||||
appinfo-test-actions.desktop \
|
||||
appinfo-test-gnome.desktop \
|
||||
appinfo-test-notgnome.desktop \
|
||||
appinfo-test.desktop \
|
||||
appinfo-test2.desktop \
|
||||
file.c \
|
||||
org.gtk.test.dbusappinfo.desktop \
|
||||
x-content/image-dcf/DCIM/Camera/20130831_203925.jpg \
|
||||
@ -367,6 +363,35 @@ clean-mimeapps:
|
||||
rm -rf xdgdatadir xdgdatahome xdgconfighome
|
||||
endif
|
||||
|
||||
appinfo-test-gnome.desktop: appinfo-test-gnome.desktop.in Makefile
|
||||
$(AM_V_GEN)$(SED) \
|
||||
-e 's|[@]installed_tests_dir[@]|$(installed_testdir)|g' \
|
||||
$< > $@
|
||||
appinfo-test-notgnome.desktop: appinfo-test-notgnome.desktop.in Makefile
|
||||
$(AM_V_GEN)$(SED) \
|
||||
-e 's|[@]installed_tests_dir[@]|$(installed_testdir)|g' \
|
||||
$< > $@
|
||||
appinfo-test.desktop: appinfo-test.desktop.in Makefile
|
||||
$(AM_V_GEN)$(SED) \
|
||||
-e 's|[@]installed_tests_dir[@]|$(installed_testdir)|g' \
|
||||
$< > $@
|
||||
appinfo-test2.desktop: appinfo-test2.desktop.in Makefile
|
||||
$(AM_V_GEN)$(SED) \
|
||||
-e 's|[@]installed_tests_dir[@]|$(installed_testdir)|g' \
|
||||
$< > $@
|
||||
|
||||
appinfo_desktop_templates = \
|
||||
appinfo-test-gnome.desktop.in \
|
||||
appinfo-test-notgnome.desktop.in \
|
||||
appinfo-test.desktop.in \
|
||||
appinfo-test2.desktop.in \
|
||||
$(NULL)
|
||||
appinfo_desktop_files = $(appinfo_desktop_templates:.in=)
|
||||
|
||||
EXTRA_DIST += $(appinfo_desktop_templates)
|
||||
CLEANFILES += $(appinfo_desktop_files)
|
||||
test_data += $(appinfo_desktop_files)
|
||||
|
||||
uninstalled_test_programs += gsettings gschema-compile
|
||||
gsettings_DEPENDENCIES = test.mo
|
||||
CLEANFILES += test.mo de/LC_MESSAGES/test.mo keyfile/gsettings.store
|
||||
|
@ -1,6 +1,6 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=appinfo-test
|
||||
Exec=./appinfo-test --option
|
||||
Exec=@installed_tests_dir@/appinfo-test --option
|
||||
OnlyShowIn=GNOME;KDE;
|
||||
NotShowIn=ROX;
|
@ -1,6 +1,6 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=appinfo-test
|
||||
Exec=./appinfo-test --option
|
||||
Exec=@installed_tests_dir@/appinfo-test --option
|
||||
OnlyShowIn=KDE;
|
||||
NotShowIn=GNOME;
|
@ -14,7 +14,7 @@ main (int argc, char *argv[])
|
||||
gchar *expected;
|
||||
gint pid_from_env;
|
||||
|
||||
expected = g_test_build_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
|
||||
expected = g_test_build_filename (G_TEST_BUILT, "appinfo-test.desktop", NULL);
|
||||
g_assert_cmpstr (envvar, ==, expected);
|
||||
g_free (expected);
|
||||
|
||||
|
@ -7,7 +7,7 @@ X-GNOME-FullName=example
|
||||
X-GNOME-FullName[de]=Beispiel
|
||||
Comment=GAppInfo example
|
||||
Comment[de]=GAppInfo Beispiel
|
||||
Exec=./appinfo-test --option %U %i --name %c --filename %k %m %%
|
||||
Exec=@installed_tests_dir@/appinfo-test --option %U %i --name %c --filename %k %m %%
|
||||
Icon=testicon.svg
|
||||
Terminal=true
|
||||
StartupNotify=true
|
@ -6,6 +6,6 @@ X-GNOME-FullName=example
|
||||
X-GNOME-FullName[de]=Beispiel
|
||||
Comment=GAppInfo example
|
||||
Comment[de]=GAppInfo Beispiel
|
||||
Exec=./appinfo-test --option
|
||||
Exec=@installed_tests_dir@/appinfo-test --option
|
||||
TryExec=does-not-exist
|
||||
Icon=testicon
|
@ -133,7 +133,7 @@ test_launch_for_app_info (GAppInfo *appinfo)
|
||||
g_assert (g_app_info_launch_uris (appinfo, NULL, NULL, &error));
|
||||
g_assert_no_error (error);
|
||||
|
||||
path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
|
||||
path = g_test_get_filename (G_TEST_BUILT, "appinfo-test.desktop", NULL);
|
||||
file = g_file_new_for_path (path);
|
||||
l = NULL;
|
||||
l = g_list_append (l, file);
|
||||
@ -144,7 +144,7 @@ test_launch_for_app_info (GAppInfo *appinfo)
|
||||
g_object_unref (file);
|
||||
|
||||
l = NULL;
|
||||
uri = g_strconcat ("file://", g_test_get_dir (G_TEST_DIST), "/appinfo-test.desktop", NULL);
|
||||
uri = g_strconcat ("file://", g_test_get_dir (G_TEST_BUILT), "/appinfo-test.desktop", NULL);
|
||||
l = g_list_append (l, uri);
|
||||
l = g_list_append (l, "file:///etc/group#adm");
|
||||
|
||||
@ -161,7 +161,7 @@ test_launch (Fixture *fixture,
|
||||
GAppInfo *appinfo;
|
||||
const gchar *path;
|
||||
|
||||
path = g_test_get_filename (G_TEST_DIST, "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);
|
||||
g_assert (appinfo != NULL);
|
||||
|
||||
@ -191,13 +191,16 @@ test_launch_no_app_id (Fixture *fixture,
|
||||
"Keywords=keyword1;test keyword;\n"
|
||||
"Categories=GNOME;GTK;\n";
|
||||
|
||||
const char *exec_line_variants[] = {
|
||||
"Exec=./appinfo-test --option %U %i --name %c --filename %k %m %%",
|
||||
"Exec=./appinfo-test --option %u %i --name %c --filename %k %m %%"
|
||||
};
|
||||
|
||||
gchar *exec_line_variants[2];
|
||||
gsize i;
|
||||
|
||||
exec_line_variants[0] = g_strdup_printf (
|
||||
"Exec=%s/appinfo-test --option %%U %%i --name %%c --filename %%k %%m %%%%",
|
||||
g_test_get_dir (G_TEST_BUILT));
|
||||
exec_line_variants[1] = g_strdup_printf (
|
||||
"Exec=%s/appinfo-test --option %%u %%i --name %%c --filename %%k %%m %%%%",
|
||||
g_test_get_dir (G_TEST_BUILT));
|
||||
|
||||
g_test_bug ("791337");
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (exec_line_variants); i++)
|
||||
@ -229,6 +232,9 @@ test_launch_no_app_id (Fixture *fixture,
|
||||
g_object_unref (appinfo);
|
||||
g_key_file_unref (fake_desktop_file);
|
||||
}
|
||||
|
||||
g_free (exec_line_variants[1]);
|
||||
g_free (exec_line_variants[0]);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -242,7 +248,7 @@ test_locale (const char *locale)
|
||||
g_setenv ("LANGUAGE", locale, TRUE);
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
path = g_test_get_filename (G_TEST_DIST, "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);
|
||||
|
||||
if (g_strcmp0 (locale, "C") == 0)
|
||||
@ -290,7 +296,7 @@ test_basic (Fixture *fixture,
|
||||
GIcon *icon, *icon2;
|
||||
const gchar *path;
|
||||
|
||||
path = g_test_get_filename (G_TEST_DIST, "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);
|
||||
|
||||
g_assert_cmpstr (g_app_info_get_id (appinfo), ==, "appinfo-test.desktop");
|
||||
@ -317,17 +323,17 @@ test_show_in (Fixture *fixture,
|
||||
GAppInfo *appinfo;
|
||||
const gchar *path;
|
||||
|
||||
path = g_test_get_filename (G_TEST_DIST, "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);
|
||||
g_assert (g_app_info_should_show (appinfo));
|
||||
g_object_unref (appinfo);
|
||||
|
||||
path = g_test_get_filename (G_TEST_DIST, "appinfo-test-gnome.desktop", NULL);
|
||||
path = g_test_get_filename (G_TEST_BUILT, "appinfo-test-gnome.desktop", NULL);
|
||||
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
|
||||
g_assert (g_app_info_should_show (appinfo));
|
||||
g_object_unref (appinfo);
|
||||
|
||||
path = g_test_get_filename (G_TEST_DIST, "appinfo-test-notgnome.desktop", NULL);
|
||||
path = g_test_get_filename (G_TEST_BUILT, "appinfo-test-notgnome.desktop", NULL);
|
||||
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
|
||||
g_assert (!g_app_info_should_show (appinfo));
|
||||
g_object_unref (appinfo);
|
||||
@ -471,7 +477,7 @@ test_tryexec (Fixture *fixture,
|
||||
GAppInfo *appinfo;
|
||||
const gchar *path;
|
||||
|
||||
path = g_test_get_filename (G_TEST_DIST, "appinfo-test2.desktop", NULL);
|
||||
path = g_test_get_filename (G_TEST_BUILT, "appinfo-test2.desktop", NULL);
|
||||
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
|
||||
|
||||
g_assert (appinfo == NULL);
|
||||
@ -596,7 +602,7 @@ test_startup_wm_class (Fixture *fixture,
|
||||
const char *wm_class;
|
||||
const gchar *path;
|
||||
|
||||
path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
|
||||
path = g_test_get_filename (G_TEST_BUILT, "appinfo-test.desktop", NULL);
|
||||
appinfo = g_desktop_app_info_new_from_filename (path);
|
||||
wm_class = g_desktop_app_info_get_startup_wm_class (appinfo);
|
||||
|
||||
@ -613,7 +619,7 @@ test_supported_types (Fixture *fixture,
|
||||
const char * const *content_types;
|
||||
const gchar *path;
|
||||
|
||||
path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
|
||||
path = g_test_get_filename (G_TEST_BUILT, "appinfo-test.desktop", NULL);
|
||||
appinfo = G_APP_INFO (g_desktop_app_info_new_from_filename (path));
|
||||
content_types = g_app_info_get_supported_types (appinfo);
|
||||
|
||||
@ -638,7 +644,7 @@ test_from_keyfile (Fixture *fixture,
|
||||
const gchar *name;
|
||||
const gchar *path;
|
||||
|
||||
path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
|
||||
path = g_test_get_filename (G_TEST_BUILT, "appinfo-test.desktop", NULL);
|
||||
kf = g_key_file_new ();
|
||||
g_key_file_load_from_file (kf, path, G_KEY_FILE_NONE, &error);
|
||||
g_assert_no_error (error);
|
||||
@ -673,19 +679,11 @@ test_from_keyfile (Fixture *fixture,
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
const gchar *build_dir;
|
||||
|
||||
g_setenv ("XDG_CURRENT_DESKTOP", "GNOME", TRUE);
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
g_test_bug_base ("https://bugzilla.gnome.org/show_bug.cgi?id=");
|
||||
|
||||
/* With Meson build we need to change into right directory, so that the
|
||||
* appinfo-test binary can be found. */
|
||||
build_dir = g_getenv ("G_TEST_BUILDDIR");
|
||||
if (build_dir)
|
||||
g_chdir (build_dir);
|
||||
|
||||
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);
|
||||
|
@ -365,7 +365,7 @@ test_extra_getters (void)
|
||||
g_setenv ("LANGUAGE", "de_DE.UTF8", TRUE);
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL));
|
||||
appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_BUILT, "appinfo-test.desktop", NULL));
|
||||
g_assert (appinfo != NULL);
|
||||
|
||||
g_assert (g_desktop_app_info_has_key (appinfo, "Terminal"));
|
||||
@ -814,7 +814,7 @@ test_launch_as_manager (void)
|
||||
return;
|
||||
}
|
||||
|
||||
path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
|
||||
path = g_test_get_filename (G_TEST_BUILT, "appinfo-test.desktop", NULL);
|
||||
appinfo = g_desktop_app_info_new_from_filename (path);
|
||||
g_assert_nonnull (appinfo);
|
||||
|
||||
@ -841,15 +841,8 @@ int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
{
|
||||
const gchar *build_dir;
|
||||
gint result;
|
||||
|
||||
/* With Meson build we need to change into right directory, so that the
|
||||
* appinfo-test binary can be found. */
|
||||
build_dir = g_getenv ("G_TEST_BUILDDIR");
|
||||
if (build_dir)
|
||||
g_chdir (build_dir);
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
basedir = g_get_current_dir ();
|
||||
|
@ -395,15 +395,35 @@ if host_machine.system() != 'windows'
|
||||
}
|
||||
endif
|
||||
|
||||
appinfo_test_desktop_files = [
|
||||
'appinfo-test-gnome.desktop',
|
||||
'appinfo-test-notgnome.desktop',
|
||||
'appinfo-test.desktop',
|
||||
'appinfo-test2.desktop',
|
||||
]
|
||||
|
||||
cdata = configuration_data()
|
||||
if installed_tests_enabled
|
||||
cdata.set('installed_tests_dir', installed_tests_execdir)
|
||||
else
|
||||
cdata.set('installed_tests_dir', meson.current_build_dir())
|
||||
endif
|
||||
|
||||
foreach appinfo_test_desktop_file : appinfo_test_desktop_files
|
||||
configure_file(
|
||||
input: appinfo_test_desktop_file + '.in',
|
||||
output: appinfo_test_desktop_file,
|
||||
install_dir: installed_tests_execdir,
|
||||
install: installed_tests_enabled,
|
||||
configuration: cdata,
|
||||
)
|
||||
endforeach
|
||||
|
||||
if installed_tests_enabled
|
||||
install_data(
|
||||
'contexts.c',
|
||||
'g-icon.c',
|
||||
'appinfo-test-actions.desktop',
|
||||
'appinfo-test-gnome.desktop',
|
||||
'appinfo-test-notgnome.desktop',
|
||||
'appinfo-test.desktop',
|
||||
'appinfo-test2.desktop',
|
||||
'file.c',
|
||||
'org.gtk.test.dbusappinfo.desktop',
|
||||
install_dir : installed_tests_execdir,
|
||||
|
Loading…
x
Reference in New Issue
Block a user