tests: add testcase for {Only,Not}ShowIn

https://bugzilla.gnome.org/show_bug.cgi?id=729813
This commit is contained in:
Ryan Lortie 2014-05-08 16:16:35 -04:00
parent 5a5e16e93c
commit 079d20f012
4 changed files with 53 additions and 8 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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 ();

View File

@ -15,4 +15,5 @@ Icon=security-medium
Exec=true
Terminal=false
Type=Application
NoDisplay=true
OnlyShowIn=GNOME-Classic
NotShowIn=GNOME