Add some more cases to the app-id unit tests
[glib.git] / gio / tests / desktop-app-info.c
blob5f34ed1a0123a2e16b2a6ad87b29824515682550
1 /*
2 * Copyright (C) 2008 Red Hat, Inc
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 * Author: Matthias Clasen
20 #include <glib/glib.h>
21 #include <gio/gio.h>
22 #include <gio/gdesktopappinfo.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
27 static char *basedir;
29 static GAppInfo *
30 create_app_info (const char *name)
32 GError *error;
33 GAppInfo *info;
35 error = NULL;
36 info = g_app_info_create_from_commandline ("true blah",
37 name,
38 G_APP_INFO_CREATE_NONE,
39 &error);
40 g_assert (error == NULL);
42 /* this is necessary to ensure that the info is saved */
43 g_app_info_set_as_default_for_type (info, "application/x-blah", &error);
44 g_assert (error == NULL);
45 g_app_info_remove_supports_type (info, "application/x-blah", &error);
46 g_assert (error == NULL);
47 g_app_info_reset_type_associations ("application/x-blah");
49 return info;
52 static void
53 test_delete (void)
55 GAppInfo *info;
57 const char *id;
58 char *filename;
59 gboolean res;
61 info = create_app_info ("Blah");
63 id = g_app_info_get_id (info);
64 g_assert (id != NULL);
66 filename = g_build_filename (basedir, "applications", id, NULL);
68 res = g_file_test (filename, G_FILE_TEST_EXISTS);
69 g_assert (res);
71 res = g_app_info_can_delete (info);
72 g_assert (res);
74 res = g_app_info_delete (info);
75 g_assert (res);
77 res = g_file_test (filename, G_FILE_TEST_EXISTS);
78 g_assert (!res);
80 g_object_unref (info);
82 if (g_file_test ("/usr/share/applications/gedit.desktop", G_FILE_TEST_EXISTS))
84 info = (GAppInfo*)g_desktop_app_info_new_from_filename ("/usr/share/applications/gedit.desktop");
85 g_assert (info);
87 res = g_app_info_can_delete (info);
88 g_assert (!res);
90 res = g_app_info_delete (info);
91 g_assert (!res);
95 static void
96 test_default (void)
98 GAppInfo *info, *info1, *info2, *info3;
99 GList *list;
100 GError *error = NULL;
102 info1 = create_app_info ("Blah1");
103 info2 = create_app_info ("Blah2");
104 info3 = create_app_info ("Blah3");
106 g_app_info_set_as_default_for_type (info1, "application/x-test", &error);
107 g_assert (error == NULL);
109 g_app_info_set_as_default_for_type (info2, "application/x-test", &error);
110 g_assert (error == NULL);
112 info = g_app_info_get_default_for_type ("application/x-test", FALSE);
113 g_assert (info != NULL);
114 g_assert_cmpstr (g_app_info_get_id (info), ==, g_app_info_get_id (info2));
116 /* now try adding something, but not setting as default */
117 g_app_info_add_supports_type (info3, "application/x-test", &error);
118 g_assert (error == NULL);
120 /* check that info2 is still default */
121 info = g_app_info_get_default_for_type ("application/x-test", FALSE);
122 g_assert (info != NULL);
123 g_assert_cmpstr (g_app_info_get_id (info), ==, g_app_info_get_id (info2));
125 /* now remove info1 again */
126 g_app_info_remove_supports_type (info1, "application/x-test", &error);
127 g_assert (error == NULL);
129 /* and make sure info2 is still default */
130 info = g_app_info_get_default_for_type ("application/x-test", FALSE);
131 g_assert (info != NULL);
132 g_assert_cmpstr (g_app_info_get_id (info), ==, g_app_info_get_id (info2));
134 /* now clean it all up */
135 g_app_info_reset_type_associations ("application/x-test");
137 list = g_app_info_get_all_for_type ("application/x-test");
138 g_assert (list == NULL);
140 g_app_info_delete (info1);
141 g_app_info_delete (info2);
142 g_app_info_delete (info3);
144 g_object_unref (info1);
145 g_object_unref (info2);
148 static void
149 test_fallback (void)
151 GAppInfo *info1, *info2, *app;
152 GList *apps, *recomm, *fallback, *list, *l, *m;
153 GError *error = NULL;
154 gint old_length;
156 info1 = create_app_info ("Test1");
157 info2 = create_app_info ("Test2");
159 g_assert (g_content_type_is_a ("text/x-python", "text/plain"));
161 apps = g_app_info_get_all_for_type ("text/x-python");
162 old_length = g_list_length (apps);
163 g_list_free_full (apps, g_object_unref);
165 g_app_info_add_supports_type (info1, "text/x-python", &error);
166 g_assert (error == NULL);
168 g_app_info_add_supports_type (info2, "text/plain", &error);
169 g_assert (error == NULL);
171 /* check that both apps are registered */
172 apps = g_app_info_get_all_for_type ("text/x-python");
173 g_assert_cmpint (g_list_length (apps), ==, old_length + 2);
175 /* check that Test1 is among the recommended apps */
176 recomm = g_app_info_get_recommended_for_type ("text/x-python");
177 g_assert (recomm != NULL);
178 for (l = recomm; l; l = l->next)
180 app = l->data;
181 if (g_app_info_equal (info1, app))
182 break;
184 g_assert (g_app_info_equal (info1, app));
186 /* and that Test2 is among the fallback apps */
187 fallback = g_app_info_get_fallback_for_type ("text/x-python");
188 g_assert (fallback != NULL);
189 for (l = fallback; l; l = l->next)
191 app = l->data;
192 if (g_app_info_equal (info2, app))
193 break;
195 g_assert_cmpstr (g_app_info_get_name (app), ==, "Test2");
197 /* check that recomm + fallback = all applications */
198 list = g_list_concat (g_list_copy (recomm), g_list_copy (fallback));
199 g_assert (g_list_length (list) == g_list_length (apps));
201 for (l = list, m = apps; l != NULL && m != NULL; l = l->next, m = m->next)
203 g_assert (g_app_info_equal (l->data, m->data));
206 g_list_free (list);
208 g_list_free_full (apps, g_object_unref);
209 g_list_free_full (recomm, g_object_unref);
210 g_list_free_full (fallback, g_object_unref);
212 g_app_info_reset_type_associations ("text/x-python");
213 g_app_info_reset_type_associations ("text/plain");
215 g_app_info_delete (info1);
216 g_app_info_delete (info2);
218 g_object_unref (info1);
219 g_object_unref (info2);
222 static void
223 test_last_used (void)
225 GList *applications;
226 GAppInfo *info1, *info2, *default_app;
227 GError *error = NULL;
229 info1 = create_app_info ("Test1");
230 info2 = create_app_info ("Test2");
232 g_app_info_set_as_default_for_type (info1, "application/x-test", &error);
233 g_assert (error == NULL);
235 g_app_info_add_supports_type (info2, "application/x-test", &error);
236 g_assert (error == NULL);
238 applications = g_app_info_get_recommended_for_type ("application/x-test");
239 g_assert (g_list_length (applications) == 2);
241 /* the first should be the default app now */
242 g_assert (g_app_info_equal (g_list_nth_data (applications, 0), info1));
243 g_assert (g_app_info_equal (g_list_nth_data (applications, 1), info2));
245 g_list_free_full (applications, g_object_unref);
247 g_app_info_set_as_last_used_for_type (info2, "application/x-test", &error);
248 g_assert (error == NULL);
250 applications = g_app_info_get_recommended_for_type ("application/x-test");
251 g_assert (g_list_length (applications) == 2);
253 default_app = g_app_info_get_default_for_type ("application/x-test", FALSE);
254 g_assert (g_app_info_equal (default_app, info1));
256 /* the first should be the other app now */
257 g_assert (g_app_info_equal (g_list_nth_data (applications, 0), info2));
258 g_assert (g_app_info_equal (g_list_nth_data (applications, 1), info1));
260 g_list_free_full (applications, g_object_unref);
262 g_app_info_reset_type_associations ("application/x-test");
264 g_app_info_delete (info1);
265 g_app_info_delete (info2);
267 g_object_unref (info1);
268 g_object_unref (info2);
269 g_object_unref (default_app);
272 static gboolean
273 cleanup_dir_recurse (GFile *parent,
274 GFile *root,
275 GError **error)
277 gboolean ret = FALSE;
278 GFileEnumerator *enumerator;
279 GError *local_error = NULL;
281 g_assert (root != NULL);
283 enumerator =
284 g_file_enumerate_children (parent, "*",
285 G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL,
286 &local_error);
287 if (!enumerator)
289 if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
291 g_clear_error (&local_error);
292 ret = TRUE;
294 goto out;
297 while (TRUE)
299 GFile *child;
300 GFileInfo *finfo;
301 char *relative_path;
303 if (!g_file_enumerator_iterate (enumerator, &finfo, &child, NULL, error))
304 goto out;
305 if (!finfo)
306 break;
308 relative_path = g_file_get_relative_path (root, child);
309 g_assert (relative_path != NULL);
310 g_free (relative_path);
312 if (g_file_info_get_file_type (finfo) == G_FILE_TYPE_DIRECTORY)
314 if (!cleanup_dir_recurse (child, root, error))
315 goto out;
318 if (!g_file_delete (child, NULL, error))
319 goto out;
322 ret = TRUE;
323 out:
324 return ret;
327 static void
328 cleanup_subdirs (const char *base_dir)
330 GFile *base, *file;
331 GError *error = NULL;
333 base = g_file_new_for_path (base_dir);
334 file = g_file_get_child (base, "applications");
335 (void) cleanup_dir_recurse (file, file, &error);
336 g_assert_no_error (error);
337 g_object_unref (file);
338 file = g_file_get_child (base, "mime");
339 (void) cleanup_dir_recurse (file, file, &error);
340 g_assert_no_error (error);
341 g_object_unref (file);
344 static void
345 test_extra_getters (void)
347 GDesktopAppInfo *appinfo;
348 gchar *s;
349 gboolean b;
351 appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL));
352 g_assert (appinfo != NULL);
354 g_assert (g_desktop_app_info_has_key (appinfo, "Terminal"));
355 g_assert (!g_desktop_app_info_has_key (appinfo, "Bratwurst"));
357 s = g_desktop_app_info_get_string (appinfo, "StartupWMClass");
358 g_assert_cmpstr (s, ==, "appinfo-class");
359 g_free (s);
361 b = g_desktop_app_info_get_boolean (appinfo, "Terminal");
362 g_assert (b);
364 g_object_unref (appinfo);
367 static void
368 wait_for_file (const gchar *want_this,
369 const gchar *but_not_this,
370 const gchar *or_this)
372 gint retries = 600;
374 /* I hate time-based conditions in tests, but this will wait up to one
375 * whole minute for "touch file" to finish running. I think it should
376 * be OK.
378 * 600 * 100ms = 60 seconds.
380 while (access (want_this, F_OK) != 0)
382 g_usleep (100000); /* 100ms */
383 g_assert (retries);
384 retries--;
387 g_assert (access (but_not_this, F_OK) != 0);
388 g_assert (access (or_this, F_OK) != 0);
390 unlink (want_this);
391 unlink (but_not_this);
392 unlink (or_this);
395 static void
396 test_actions (void)
398 const gchar * const *actions;
399 GDesktopAppInfo *appinfo;
400 gchar *name;
402 appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_DIST, "appinfo-test-actions.desktop", NULL));
403 g_assert (appinfo != NULL);
405 actions = g_desktop_app_info_list_actions (appinfo);
406 g_assert_cmpstr (actions[0], ==, "frob");
407 g_assert_cmpstr (actions[1], ==, "tweak");
408 g_assert_cmpstr (actions[2], ==, "twiddle");
409 g_assert_cmpstr (actions[3], ==, "broken");
410 g_assert_cmpstr (actions[4], ==, NULL);
412 name = g_desktop_app_info_get_action_name (appinfo, "frob");
413 g_assert_cmpstr (name, ==, "Frobnicate");
414 g_free (name);
416 name = g_desktop_app_info_get_action_name (appinfo, "tweak");
417 g_assert_cmpstr (name, ==, "Tweak");
418 g_free (name);
420 name = g_desktop_app_info_get_action_name (appinfo, "twiddle");
421 g_assert_cmpstr (name, ==, "Twiddle");
422 g_free (name);
424 name = g_desktop_app_info_get_action_name (appinfo, "broken");
425 g_assert (name != NULL);
426 g_assert (g_utf8_validate (name, -1, NULL));
427 g_free (name);
429 unlink ("frob"); unlink ("tweak"); unlink ("twiddle");
431 g_desktop_app_info_launch_action (appinfo, "frob", NULL);
432 wait_for_file ("frob", "tweak", "twiddle");
434 g_desktop_app_info_launch_action (appinfo, "tweak", NULL);
435 wait_for_file ("tweak", "frob", "twiddle");
437 g_desktop_app_info_launch_action (appinfo, "twiddle", NULL);
438 wait_for_file ("twiddle", "frob", "tweak");
440 g_object_unref (appinfo);
443 static gchar *
444 run_apps (const gchar *command,
445 const gchar *arg,
446 gboolean with_usr,
447 gboolean with_home,
448 const gchar *locale_name,
449 const gchar *language,
450 const gchar *xdg_current_desktop)
452 gboolean success;
453 gchar **envp;
454 gchar **argv;
455 gint status;
456 gchar *out;
458 argv = g_new (gchar *, 4);
459 argv[0] = g_test_build_filename (G_TEST_BUILT, "apps", NULL);
460 argv[1] = g_strdup (command);
461 argv[2] = g_strdup (arg);
462 argv[3] = NULL;
464 envp = g_get_environ ();
466 if (with_usr)
468 gchar *tmp = g_test_build_filename (G_TEST_DIST, "desktop-files", "usr", NULL);
469 envp = g_environ_setenv (envp, "XDG_DATA_DIRS", tmp, TRUE);
470 g_free (tmp);
472 else
473 envp = g_environ_setenv (envp, "XDG_DATA_DIRS", "/does-not-exist", TRUE);
475 if (with_home)
477 gchar *tmp = g_test_build_filename (G_TEST_DIST, "desktop-files", "home", NULL);
478 envp = g_environ_setenv (envp, "XDG_DATA_HOME", tmp, TRUE);
479 g_free (tmp);
481 else
482 envp = g_environ_setenv (envp, "XDG_DATA_HOME", "/does-not-exist", TRUE);
484 if (locale_name)
485 envp = g_environ_setenv (envp, "LC_ALL", locale_name, TRUE);
486 else
487 envp = g_environ_setenv (envp, "LC_ALL", "C", TRUE);
489 if (language)
490 envp = g_environ_setenv (envp, "LANGUAGE", language, TRUE);
491 else
492 envp = g_environ_unsetenv (envp, "LANGUAGE");
494 if (xdg_current_desktop)
495 envp = g_environ_setenv (envp, "XDG_CURRENT_DESKTOP", xdg_current_desktop, TRUE);
496 else
497 envp = g_environ_unsetenv (envp, "XDG_CURRENT_DESKTOP");
499 success = g_spawn_sync (NULL, argv, envp, 0, NULL, NULL, &out, NULL, &status, NULL);
500 g_assert (success);
501 g_assert (status == 0);
503 g_strfreev (envp);
504 g_strfreev (argv);
506 return out;
509 static void
510 assert_strings_equivalent (const gchar *expected,
511 const gchar *result)
513 gchar **expected_words;
514 gchar **result_words;
515 gint i, j;
517 expected_words = g_strsplit (expected, " ", 0);
518 result_words = g_strsplit_set (result, " \n", 0);
520 for (i = 0; expected_words[i]; i++)
522 for (j = 0; result_words[j]; j++)
523 if (g_str_equal (expected_words[i], result_words[j]))
524 goto got_it;
526 g_test_message ("Unable to find expected string '%s' in result '%s'", expected_words[i], result);
527 g_test_fail ();
529 got_it:
530 continue;
533 g_assert_cmpint (g_strv_length (expected_words), ==, g_strv_length (result_words));
534 g_strfreev (expected_words);
535 g_strfreev (result_words);
538 static void
539 assert_list (const gchar *expected,
540 gboolean with_usr,
541 gboolean with_home,
542 const gchar *locale_name,
543 const gchar *language)
545 gchar *result;
547 result = run_apps ("list", NULL, with_usr, with_home, locale_name, language, NULL);
548 g_strchomp (result);
549 assert_strings_equivalent (expected, result);
550 g_free (result);
553 static void
554 assert_info (const gchar *desktop_id,
555 const gchar *expected,
556 gboolean with_usr,
557 gboolean with_home,
558 const gchar *locale_name,
559 const gchar *language)
561 gchar *result;
563 result = run_apps ("show-info", desktop_id, with_usr, with_home, locale_name, language, NULL);
564 g_assert_cmpstr (result, ==, expected);
565 g_free (result);
568 static void
569 assert_search (const gchar *search_string,
570 const gchar *expected,
571 gboolean with_usr,
572 gboolean with_home,
573 const gchar *locale_name,
574 const gchar *language)
576 gchar **expected_lines;
577 gchar **result_lines;
578 gchar *result;
579 gint i;
581 expected_lines = g_strsplit (expected, "\n", -1);
582 result = run_apps ("search", search_string, with_usr, with_home, locale_name, language, NULL);
583 result_lines = g_strsplit (result, "\n", -1);
584 g_assert_cmpint (g_strv_length (expected_lines), ==, g_strv_length (result_lines));
585 for (i = 0; expected_lines[i]; i++)
586 assert_strings_equivalent (expected_lines[i], result_lines[i]);
587 g_strfreev (expected_lines);
588 g_strfreev (result_lines);
589 g_free (result);
592 static void
593 assert_implementations (const gchar *interface,
594 const gchar *expected,
595 gboolean with_usr,
596 gboolean with_home)
598 gchar *result;
600 result = run_apps ("implementations", interface, with_usr, with_home, NULL, NULL, NULL);
601 g_strchomp (result);
602 assert_strings_equivalent (expected, result);
603 g_free (result);
606 #define ALL_USR_APPS "evince-previewer.desktop nautilus-classic.desktop gnome-font-viewer.desktop " \
607 "baobab.desktop yelp.desktop eog.desktop cheese.desktop gnome-clocks.desktop " \
608 "gnome-contacts.desktop kde4-kate.desktop gcr-prompter.desktop totem.desktop " \
609 "gnome-terminal.desktop nautilus-autorun-software.desktop gcr-viewer.desktop " \
610 "nautilus-connect-server.desktop kde4-dolphin.desktop gnome-music.desktop " \
611 "kde4-konqbrowser.desktop gucharmap.desktop kde4-okular.desktop nautilus.desktop " \
612 "gedit.desktop evince.desktop file-roller.desktop dconf-editor.desktop glade.desktop"
613 #define HOME_APPS "epiphany-weather-for-toronto-island-9c6a4e022b17686306243dada811d550d25eb1fb.desktop"
614 #define ALL_HOME_APPS HOME_APPS " eog.desktop"
616 static void
617 test_search (void)
619 assert_list ("", FALSE, FALSE, NULL, NULL);
620 assert_list (ALL_USR_APPS, TRUE, FALSE, NULL, NULL);
621 assert_list (ALL_HOME_APPS, FALSE, TRUE, NULL, NULL);
622 assert_list (ALL_USR_APPS " " HOME_APPS, TRUE, TRUE, NULL, NULL);
624 /* The user has "installed" their own version of eog.desktop which
625 * calls it "Eye of GNOME". Do some testing based on that.
627 * We should always find "Pictures" keyword no matter where we look.
629 assert_search ("Picture", "eog.desktop\n", TRUE, TRUE, NULL, NULL);
630 assert_search ("Picture", "eog.desktop\n", TRUE, FALSE, NULL, NULL);
631 assert_search ("Picture", "eog.desktop\n", FALSE, TRUE, NULL, NULL);
632 assert_search ("Picture", "", FALSE, FALSE, NULL, NULL);
634 /* We should only find it called "eye of gnome" when using the user's
635 * directory.
637 assert_search ("eye gnome", "", TRUE, FALSE, NULL, NULL);
638 assert_search ("eye gnome", "eog.desktop\n", FALSE, TRUE, NULL, NULL);
639 assert_search ("eye gnome", "eog.desktop\n", TRUE, TRUE, NULL, NULL);
641 /* We should only find it called "image viewer" when _not_ using the
642 * user's directory.
644 assert_search ("image viewer", "eog.desktop\n", TRUE, FALSE, NULL, NULL);
645 assert_search ("image viewer", "", FALSE, TRUE, NULL, NULL);
646 assert_search ("image viewer", "", TRUE, TRUE, NULL, NULL);
648 /* Obvious multi-word search */
649 assert_search ("gno hel", "yelp.desktop\n", TRUE, TRUE, NULL, NULL);
651 /* Repeated search terms should do nothing... */
652 assert_search ("files file fil fi f", "nautilus.desktop\n"
653 "gedit.desktop\n", TRUE, TRUE, NULL, NULL);
655 /* "con" will match "connect" and "contacts" on name but dconf only on
656 * the "config" keyword
658 assert_search ("con", "nautilus-connect-server.desktop gnome-contacts.desktop\n"
659 "dconf-editor.desktop\n", TRUE, TRUE, NULL, NULL);
661 /* "gnome" will match "eye of gnome" from the user's directory, plus
662 * matching "GNOME Clocks" X-GNOME-FullName. It's only a comment on
663 * yelp and gnome-contacts, though.
665 assert_search ("gnome", "eog.desktop\n"
666 "gnome-clocks.desktop\n"
667 "yelp.desktop gnome-contacts.desktop\n", TRUE, TRUE, NULL, NULL);
669 /* eog has exec name 'false' in usr only */
670 assert_search ("false", "eog.desktop\n", TRUE, FALSE, NULL, NULL);
671 assert_search ("false", "", FALSE, TRUE, NULL, NULL);
672 assert_search ("false", "", TRUE, TRUE, NULL, NULL);
673 assert_search ("false", "", FALSE, FALSE, NULL, NULL);
675 /* make sure we only search the first component */
676 assert_search ("nonsearchable", "", TRUE, FALSE, NULL, NULL);
678 /* "gnome con" will match only gnome contacts; via the name for
679 * "contacts" and the comment for "gnome"
681 assert_search ("gnome con", "gnome-contacts.desktop\n", TRUE, TRUE, NULL, NULL);
683 /* make sure we get the correct kde4- prefix on the application IDs
684 * from subdirectories
686 assert_search ("konq", "kde4-konqbrowser.desktop\n", TRUE, TRUE, NULL, NULL);
687 assert_search ("kate", "kde4-kate.desktop\n", TRUE, TRUE, NULL, NULL);
689 /* make sure we can lookup apps by name properly */
690 assert_info ("kde4-kate.desktop",
691 "kde4-kate.desktop\n"
692 "Kate\n"
693 "Kate\n"
694 "nil\n", TRUE, TRUE, NULL, NULL);
696 assert_info ("nautilus.desktop",
697 "nautilus.desktop\n"
698 "Files\n"
699 "Files\n"
700 "Access and organize files\n", TRUE, TRUE, NULL, NULL);
702 /* make sure localised searching works properly */
703 assert_search ("foliumi", "nautilus.desktop\n"
704 "kde4-konqbrowser.desktop\n"
705 "eog.desktop\n", TRUE, FALSE, "en_US.UTF-8", "eo");
706 /* the user's eog.desktop has no translations... */
707 assert_search ("foliumi", "nautilus.desktop\n"
708 "kde4-konqbrowser.desktop\n", TRUE, TRUE, "en_US.UTF-8", "eo");
711 static void
712 test_implements (void)
714 /* Make sure we can find our search providers... */
715 assert_implementations ("org.gnome.Shell.SearchProvider2",
716 "gnome-music.desktop gnome-contacts.desktop eog.desktop",
717 TRUE, FALSE);
719 /* And our image acquisition possibilities... */
720 assert_implementations ("org.freedesktop.ImageProvider",
721 "cheese.desktop",
722 TRUE, FALSE);
724 /* Make sure the user's eog is properly masking the system one */
725 assert_implementations ("org.gnome.Shell.SearchProvider2",
726 "gnome-music.desktop gnome-contacts.desktop",
727 TRUE, TRUE);
729 /* Make sure we get nothing if we have nothing */
730 assert_implementations ("org.gnome.Shell.SearchProvider2", "", FALSE, FALSE);
733 static void
734 assert_shown (const gchar *desktop_id,
735 gboolean expected,
736 const gchar *xdg_current_desktop)
738 gchar *result;
740 result = run_apps ("should-show", desktop_id, TRUE, TRUE, NULL, NULL, xdg_current_desktop);
741 g_assert_cmpstr (result, ==, expected ? "true\n" : "false\n");
742 g_free (result);
745 static void
746 test_show_in (void)
748 assert_shown ("gcr-prompter.desktop", FALSE, NULL);
749 assert_shown ("gcr-prompter.desktop", FALSE, "GNOME");
750 assert_shown ("gcr-prompter.desktop", FALSE, "KDE");
751 assert_shown ("gcr-prompter.desktop", FALSE, "GNOME:GNOME-Classic");
752 assert_shown ("gcr-prompter.desktop", TRUE, "GNOME-Classic:GNOME");
753 assert_shown ("gcr-prompter.desktop", TRUE, "GNOME-Classic");
754 assert_shown ("gcr-prompter.desktop", TRUE, "GNOME-Classic:KDE");
755 assert_shown ("gcr-prompter.desktop", TRUE, "KDE:GNOME-Classic");
759 main (int argc,
760 char *argv[])
762 gint result;
764 g_test_init (&argc, &argv, NULL);
766 basedir = g_get_current_dir ();
767 g_setenv ("XDG_DATA_HOME", basedir, TRUE);
768 cleanup_subdirs (basedir);
770 g_test_add_func ("/desktop-app-info/delete", test_delete);
771 g_test_add_func ("/desktop-app-info/default", test_default);
772 g_test_add_func ("/desktop-app-info/fallback", test_fallback);
773 g_test_add_func ("/desktop-app-info/lastused", test_last_used);
774 g_test_add_func ("/desktop-app-info/extra-getters", test_extra_getters);
775 g_test_add_func ("/desktop-app-info/actions", test_actions);
776 g_test_add_func ("/desktop-app-info/search", test_search);
777 g_test_add_func ("/desktop-app-info/implements", test_implements);
778 g_test_add_func ("/desktop-app-info/show-in", test_show_in);
780 result = g_test_run ();
782 cleanup_subdirs (basedir);
784 return result;