[glib] tests: add testcase for {Only,Not}ShowIn
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] tests: add testcase for {Only,Not}ShowIn
- Date: Thu, 8 May 2014 20:33:11 +0000 (UTC)
commit 079d20f012127873335fccd174b104b60d9d7f4f
Author: Ryan Lortie <desrt desrt ca>
Date: Thu May 8 16:16:35 2014 -0400
tests: add testcase for {Only,Not}ShowIn
https://bugzilla.gnome.org/show_bug.cgi?id=729813
gio/tests/appinfo.c | 4 +-
gio/tests/apps.c | 12 ++++++
gio/tests/desktop-app-info.c | 42 +++++++++++++++++--
.../usr/applications/gcr-prompter.desktop | 3 +-
4 files changed, 53 insertions(+), 8 deletions(-)
---
diff --git a/gio/tests/appinfo.c b/gio/tests/appinfo.c
index e04071a..b1a60f0 100644
--- a/gio/tests/appinfo.c
+++ b/gio/tests/appinfo.c
@@ -136,8 +136,6 @@ test_show_in (void)
GAppInfo *appinfo;
const gchar *path;
- g_desktop_app_info_set_desktop_env ("GNOME");
-
path = g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL);
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
g_assert (g_app_info_should_show (appinfo));
@@ -476,6 +474,8 @@ test_from_keyfile (void)
int
main (int argc, char *argv[])
{
+ g_setenv ("XDG_CURRENT_DESKTOP", "GNOME", TRUE);
+
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/appinfo/basic", test_basic);
diff --git a/gio/tests/apps.c b/gio/tests/apps.c
index 6a4b04f..dedd719 100644
--- a/gio/tests/apps.c
+++ b/gio/tests/apps.c
@@ -107,5 +107,17 @@ main (int argc, char **argv)
print_app_list (list);
}
+ else if (g_str_equal (argv[1], "should-show"))
+ {
+ GAppInfo *info;
+
+ info = (GAppInfo *) g_desktop_app_info_new (argv[2]);
+ if (info)
+ {
+ g_print ("%s\n", g_app_info_should_show (info) ? "true" : "false");
+ g_object_unref (info);
+ }
+ }
+
return 0;
}
diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c
index 69fe587..22dd4b7 100644
--- a/gio/tests/desktop-app-info.c
+++ b/gio/tests/desktop-app-info.c
@@ -429,7 +429,8 @@ run_apps (const gchar *command,
gboolean with_usr,
gboolean with_home,
const gchar *locale_name,
- const gchar *language)
+ const gchar *language,
+ const gchar *xdg_current_desktop)
{
gboolean success;
gchar **envp;
@@ -473,6 +474,11 @@ run_apps (const gchar *command,
else
envp = g_environ_unsetenv (envp, "LANGUAGE");
+ if (xdg_current_desktop)
+ envp = g_environ_setenv (envp, "XDG_CURRENT_DESKTOP", xdg_current_desktop, TRUE);
+ else
+ envp = g_environ_unsetenv (envp, "XDG_CURRENT_DESKTOP");
+
success = g_spawn_sync (NULL, argv, envp, 0, NULL, NULL, &out, NULL, &status, NULL);
g_assert (success);
g_assert (status == 0);
@@ -521,7 +527,7 @@ assert_list (const gchar *expected,
{
gchar *result;
- result = run_apps ("list", NULL, with_usr, with_home, locale_name, language);
+ result = run_apps ("list", NULL, with_usr, with_home, locale_name, language, NULL);
g_strchomp (result);
assert_strings_equivalent (expected, result);
g_free (result);
@@ -537,7 +543,7 @@ assert_info (const gchar *desktop_id,
{
gchar *result;
- result = run_apps ("show-info", desktop_id, with_usr, with_home, locale_name, language);
+ result = run_apps ("show-info", desktop_id, with_usr, with_home, locale_name, language, NULL);
g_assert_cmpstr (result, ==, expected);
g_free (result);
}
@@ -556,7 +562,7 @@ assert_search (const gchar *search_string,
gint i;
expected_lines = g_strsplit (expected, "\n", -1);
- result = run_apps ("search", search_string, with_usr, with_home, locale_name, language);
+ result = run_apps ("search", search_string, with_usr, with_home, locale_name, language, NULL);
result_lines = g_strsplit (result, "\n", -1);
g_assert_cmpint (g_strv_length (expected_lines), ==, g_strv_length (result_lines));
for (i = 0; expected_lines[i]; i++)
@@ -574,7 +580,7 @@ assert_implementations (const gchar *interface,
{
gchar *result;
- result = run_apps ("implementations", interface, with_usr, with_home, NULL, NULL);
+ result = run_apps ("implementations", interface, with_usr, with_home, NULL, NULL, NULL);
g_strchomp (result);
assert_strings_equivalent (expected, result);
g_free (result);
@@ -707,6 +713,31 @@ test_implements (void)
assert_implementations ("org.gnome.Shell.SearchProvider2", "", FALSE, FALSE);
}
+static void
+assert_shown (const gchar *desktop_id,
+ gboolean expected,
+ const gchar *xdg_current_desktop)
+{
+ gchar *result;
+
+ result = run_apps ("should-show", desktop_id, TRUE, TRUE, NULL, NULL, xdg_current_desktop);
+ g_assert_cmpstr (result, ==, expected ? "true\n" : "false\n");
+ g_free (result);
+}
+
+static void
+test_show_in (void)
+{
+ assert_shown ("gcr-prompter.desktop", FALSE, NULL);
+ assert_shown ("gcr-prompter.desktop", FALSE, "GNOME");
+ assert_shown ("gcr-prompter.desktop", FALSE, "KDE");
+ assert_shown ("gcr-prompter.desktop", FALSE, "GNOME:GNOME-Classic");
+ assert_shown ("gcr-prompter.desktop", TRUE, "GNOME-Classic:GNOME");
+ assert_shown ("gcr-prompter.desktop", TRUE, "GNOME-Classic");
+ assert_shown ("gcr-prompter.desktop", TRUE, "GNOME-Classic:KDE");
+ assert_shown ("gcr-prompter.desktop", TRUE, "KDE:GNOME-Classic");
+}
+
int
main (int argc,
char *argv[])
@@ -727,6 +758,7 @@ main (int argc,
g_test_add_func ("/desktop-app-info/actions", test_actions);
g_test_add_func ("/desktop-app-info/search", test_search);
g_test_add_func ("/desktop-app-info/implements", test_implements);
+ g_test_add_func ("/desktop-app-info/show-in", test_show_in);
result = g_test_run ();
diff --git a/gio/tests/desktop-files/usr/applications/gcr-prompter.desktop
b/gio/tests/desktop-files/usr/applications/gcr-prompter.desktop
index 0a91ff6..15273b0 100644
--- a/gio/tests/desktop-files/usr/applications/gcr-prompter.desktop
+++ b/gio/tests/desktop-files/usr/applications/gcr-prompter.desktop
@@ -15,4 +15,5 @@ Icon=security-medium
Exec=true
Terminal=false
Type=Application
-NoDisplay=true
+OnlyShowIn=GNOME-Classic
+NotShowIn=GNOME
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]