[kdbus] KDBUS_ITEM_PAYLOAD_OFF items are (once again) relative to msg header
[platform/upstream/glib.git] / gio / tests / desktop-app-info.c
1 /* 
2  * Copyright (C) 2008 Red Hat, Inc
3  *
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.
8  *
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.
13  *
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/>.
16  * 
17  * Author: Matthias Clasen
18  */
19
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>
26
27 static char *basedir;
28
29 static GAppInfo * 
30 create_app_info (const char *name)
31 {
32   GError *error;
33   GAppInfo *info;
34
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);
41
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");
48   
49   return info;
50 }
51
52 static void
53 test_delete (void)
54 {
55   GAppInfo *info;
56
57   const char *id;
58   char *filename;
59   gboolean res;
60
61   info = create_app_info ("Blah");
62  
63   id = g_app_info_get_id (info);
64   g_assert (id != NULL);
65
66   filename = g_build_filename (basedir, "applications", id, NULL);
67
68   res = g_file_test (filename, G_FILE_TEST_EXISTS);
69   g_assert (res);
70
71   res = g_app_info_can_delete (info);
72   g_assert (res);
73
74   res = g_app_info_delete (info);
75   g_assert (res);
76
77   res = g_file_test (filename, G_FILE_TEST_EXISTS);
78   g_assert (!res);
79
80   g_object_unref (info);
81
82   if (g_file_test ("/usr/share/applications/gedit.desktop", G_FILE_TEST_EXISTS))
83     {
84       info = (GAppInfo*)g_desktop_app_info_new_from_filename ("/usr/share/applications/gedit.desktop");
85       g_assert (info);
86      
87       res = g_app_info_can_delete (info);
88       g_assert (!res);
89  
90       res = g_app_info_delete (info);
91       g_assert (!res);
92     }
93 }
94
95 static void
96 test_default (void)
97 {
98   GAppInfo *info, *info1, *info2, *info3;
99   GList *list;
100   GError *error = NULL;  
101
102   info1 = create_app_info ("Blah1");
103   info2 = create_app_info ("Blah2");
104   info3 = create_app_info ("Blah3");
105
106   g_app_info_set_as_default_for_type (info1, "application/x-test", &error);
107   g_assert (error == NULL);
108
109   g_app_info_set_as_default_for_type (info2, "application/x-test", &error);
110   g_assert (error == NULL);
111
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));
115
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);
119
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));
124
125   /* now remove info1 again */
126   g_app_info_remove_supports_type (info1, "application/x-test", &error);
127   g_assert (error == NULL);
128
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));
133
134   /* now clean it all up */
135   g_app_info_reset_type_associations ("application/x-test");
136
137   list = g_app_info_get_all_for_type ("application/x-test");
138   g_assert (list == NULL);
139
140   g_app_info_delete (info1);
141   g_app_info_delete (info2);
142   g_app_info_delete (info3);
143
144   g_object_unref (info1);
145   g_object_unref (info2);
146 }
147
148 static void
149 test_fallback (void)
150 {
151   GAppInfo *info1, *info2, *app;
152   GList *apps, *recomm, *fallback, *list, *l, *m;
153   GError *error = NULL;
154   gint old_length;
155
156   info1 = create_app_info ("Test1");
157   info2 = create_app_info ("Test2");
158
159   g_assert (g_content_type_is_a ("text/x-python", "text/plain"));
160
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);
164
165   g_app_info_add_supports_type (info1, "text/x-python", &error);
166   g_assert (error == NULL);
167
168   g_app_info_add_supports_type (info2, "text/plain", &error);
169   g_assert (error == NULL);
170
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);
174
175   /* check the ordering */
176   app = g_list_nth_data (apps, 0);
177   g_assert (g_app_info_equal (info1, app));
178
179   /* check that Test1 is the first recommended app */
180   recomm = g_app_info_get_recommended_for_type ("text/x-python");
181   g_assert (recomm != NULL);
182   app = g_list_nth_data (recomm, 0);
183   g_assert (g_app_info_equal (info1, app));
184
185   /* and that Test2 is among the fallback apps */
186   fallback = g_app_info_get_fallback_for_type ("text/x-python");
187   g_assert (fallback != NULL);
188   for (l = fallback; l; l = l->next)
189     {
190       app = l->data;
191       if (g_app_info_equal (info2, app))
192         break;
193     }
194   g_assert_cmpstr (g_app_info_get_name (app), ==, "Test2");
195
196   /* check that recomm + fallback = all applications */
197   list = g_list_concat (g_list_copy (recomm), g_list_copy (fallback));
198   g_assert (g_list_length (list) == g_list_length (apps));
199
200   for (l = list, m = apps; l != NULL && m != NULL; l = l->next, m = m->next)
201     {
202       g_assert (g_app_info_equal (l->data, m->data));
203     }
204
205   g_list_free (list);
206
207   g_list_free_full (apps, g_object_unref);
208   g_list_free_full (recomm, g_object_unref);
209   g_list_free_full (fallback, g_object_unref);
210
211   g_app_info_reset_type_associations ("text/x-python");
212   g_app_info_reset_type_associations ("text/plain");
213
214   g_app_info_delete (info1);
215   g_app_info_delete (info2);
216
217   g_object_unref (info1);
218   g_object_unref (info2);
219 }
220
221 static void
222 test_last_used (void)
223 {
224   GList *applications;
225   GAppInfo *info1, *info2, *default_app;
226   GError *error = NULL;
227
228   info1 = create_app_info ("Test1");
229   info2 = create_app_info ("Test2");
230
231   g_app_info_set_as_default_for_type (info1, "application/x-test", &error);
232   g_assert (error == NULL);
233
234   g_app_info_add_supports_type (info2, "application/x-test", &error);
235   g_assert (error == NULL);
236
237   applications = g_app_info_get_recommended_for_type ("application/x-test");
238   g_assert (g_list_length (applications) == 2);
239
240   /* the first should be the default app now */
241   g_assert (g_app_info_equal (g_list_nth_data (applications, 0), info1));
242   g_assert (g_app_info_equal (g_list_nth_data (applications, 1), info2));
243
244   g_list_free_full (applications, g_object_unref);
245
246   g_app_info_set_as_last_used_for_type (info2, "application/x-test", &error);
247   g_assert (error == NULL);
248
249   applications = g_app_info_get_recommended_for_type ("application/x-test");
250   g_assert (g_list_length (applications) == 2);
251
252   default_app = g_app_info_get_default_for_type ("application/x-test", FALSE);
253   g_assert (g_app_info_equal (default_app, info1));
254
255   /* the first should be the other app now */
256   g_assert (g_app_info_equal (g_list_nth_data (applications, 0), info2));
257   g_assert (g_app_info_equal (g_list_nth_data (applications, 1), info1));
258
259   g_list_free_full (applications, g_object_unref);
260
261   g_app_info_reset_type_associations ("application/x-test");
262
263   g_app_info_delete (info1);
264   g_app_info_delete (info2);
265
266   g_object_unref (info1);
267   g_object_unref (info2);
268   g_object_unref (default_app);
269 }
270
271 static void
272 cleanup_dir_recurse (GFile *parent, GFile *root)
273 {
274   gboolean res;
275   GError *error;
276   GFileEnumerator *enumerator;
277   GFileInfo *info;
278   GFile *descend;
279   char *relative_path;
280
281   g_assert (root != NULL);
282
283   error = NULL;
284   enumerator =
285     g_file_enumerate_children (parent, "*",
286                                G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL,
287                                &error);
288   if (! enumerator)
289           return;
290   error = NULL;
291   info = g_file_enumerator_next_file (enumerator, NULL, &error);
292   while ((info) && (!error))
293     {
294       descend = g_file_get_child (parent, g_file_info_get_name (info));
295       g_assert (descend != NULL);
296       relative_path = g_file_get_relative_path (root, descend);
297       g_assert (relative_path != NULL);
298
299       if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
300           cleanup_dir_recurse (descend, root);
301
302       error = NULL;
303       res = g_file_delete (descend, NULL, &error);
304       g_assert_cmpint (res, ==, TRUE);
305
306       g_object_unref (descend);
307       error = NULL;
308       info = g_file_enumerator_next_file (enumerator, NULL, &error);
309     }
310   g_assert (error == NULL);
311
312   error = NULL;
313   res = g_file_enumerator_close (enumerator, NULL, &error);
314   g_assert_cmpint (res, ==, TRUE);
315   g_assert (error == NULL);
316 }
317
318 static void
319 cleanup_subdirs (const char *base_dir)
320 {
321   GFile *base, *file;
322  
323   base = g_file_new_for_path (base_dir);  
324   file = g_file_get_child (base, "applications");
325   cleanup_dir_recurse (file, file);
326   g_object_unref (file);
327   file = g_file_get_child (base, "mime");
328   cleanup_dir_recurse (file, file);
329   g_object_unref (file);
330 }
331
332 static void
333 test_extra_getters (void)
334 {
335   GDesktopAppInfo *appinfo;
336   gchar *s;
337   gboolean b;
338
339   appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_DIST, "appinfo-test.desktop", NULL));
340   g_assert (appinfo != NULL);
341
342   g_assert (g_desktop_app_info_has_key (appinfo, "Terminal"));
343   g_assert (!g_desktop_app_info_has_key (appinfo, "Bratwurst"));
344
345   s = g_desktop_app_info_get_string (appinfo, "StartupWMClass");
346   g_assert_cmpstr (s, ==, "appinfo-class");
347   g_free (s);
348
349   b = g_desktop_app_info_get_boolean (appinfo, "Terminal");
350   g_assert (b);
351
352   g_object_unref (appinfo);
353 }
354
355 static void
356 wait_for_file (const gchar *want_this,
357                const gchar *but_not_this,
358                const gchar *or_this)
359 {
360   gint retries = 600;
361
362   /* I hate time-based conditions in tests, but this will wait up to one
363    * whole minute for "touch file" to finish running.  I think it should
364    * be OK.
365    *
366    * 600 * 100ms = 60 seconds.
367    */
368   while (access (want_this, F_OK) != 0)
369     {
370       g_usleep (100000); /* 100ms */
371       g_assert (retries);
372       retries--;
373     }
374
375   g_assert (access (but_not_this, F_OK) != 0);
376   g_assert (access (or_this, F_OK) != 0);
377
378   unlink (want_this);
379   unlink (but_not_this);
380   unlink (or_this);
381 }
382
383 static void
384 test_actions (void)
385 {
386   const gchar * const *actions;
387   GDesktopAppInfo *appinfo;
388   gchar *name;
389
390   appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_DIST, "appinfo-test-actions.desktop", NULL));
391   g_assert (appinfo != NULL);
392
393   actions = g_desktop_app_info_list_actions (appinfo);
394   g_assert_cmpstr (actions[0], ==, "frob");
395   g_assert_cmpstr (actions[1], ==, "tweak");
396   g_assert_cmpstr (actions[2], ==, "twiddle");
397   g_assert_cmpstr (actions[3], ==, "broken");
398   g_assert_cmpstr (actions[4], ==, NULL);
399
400   name = g_desktop_app_info_get_action_name (appinfo, "frob");
401   g_assert_cmpstr (name, ==, "Frobnicate");
402   g_free (name);
403
404   name = g_desktop_app_info_get_action_name (appinfo, "tweak");
405   g_assert_cmpstr (name, ==, "Tweak");
406   g_free (name);
407
408   name = g_desktop_app_info_get_action_name (appinfo, "twiddle");
409   g_assert_cmpstr (name, ==, "Twiddle");
410   g_free (name);
411
412   name = g_desktop_app_info_get_action_name (appinfo, "broken");
413   g_assert (name != NULL);
414   g_assert (g_utf8_validate (name, -1, NULL));
415   g_free (name);
416
417   unlink ("frob"); unlink ("tweak"); unlink ("twiddle");
418
419   g_desktop_app_info_launch_action (appinfo, "frob", NULL);
420   wait_for_file ("frob", "tweak", "twiddle");
421
422   g_desktop_app_info_launch_action (appinfo, "tweak", NULL);
423   wait_for_file ("tweak", "frob", "twiddle");
424
425   g_desktop_app_info_launch_action (appinfo, "twiddle", NULL);
426   wait_for_file ("twiddle", "frob", "tweak");
427
428   g_object_unref (appinfo);
429 }
430
431 static gchar *
432 run_apps (const gchar *command,
433           const gchar *arg,
434           gboolean     with_usr,
435           gboolean     with_home,
436           const gchar *locale_name,
437           const gchar *language,
438           const gchar *xdg_current_desktop)
439 {
440   gboolean success;
441   gchar **envp;
442   gchar **argv;
443   gint status;
444   gchar *out;
445
446   argv = g_new (gchar *, 4);
447   argv[0] = g_test_build_filename (G_TEST_BUILT, "apps", NULL);
448   argv[1] = g_strdup (command);
449   argv[2] = g_strdup (arg);
450   argv[3] = NULL;
451
452   envp = g_get_environ ();
453
454   if (with_usr)
455     {
456       gchar *tmp = g_test_build_filename (G_TEST_DIST, "desktop-files", "usr", NULL);
457       envp = g_environ_setenv (envp, "XDG_DATA_DIRS", tmp, TRUE);
458       g_free (tmp);
459     }
460   else
461     envp = g_environ_setenv (envp, "XDG_DATA_DIRS", "/does-not-exist", TRUE);
462
463   if (with_home)
464     {
465       gchar *tmp = g_test_build_filename (G_TEST_DIST, "desktop-files", "home", NULL);
466       envp = g_environ_setenv (envp, "XDG_DATA_HOME", tmp, TRUE);
467       g_free (tmp);
468     }
469   else
470     envp = g_environ_setenv (envp, "XDG_DATA_HOME", "/does-not-exist", TRUE);
471
472   if (locale_name)
473     envp = g_environ_setenv (envp, "LC_ALL", locale_name, TRUE);
474   else
475     envp = g_environ_setenv (envp, "LC_ALL", "C", TRUE);
476
477   if (language)
478     envp = g_environ_setenv (envp, "LANGUAGE", language, TRUE);
479   else
480     envp = g_environ_unsetenv (envp, "LANGUAGE");
481
482   if (xdg_current_desktop)
483     envp = g_environ_setenv (envp, "XDG_CURRENT_DESKTOP", xdg_current_desktop, TRUE);
484   else
485     envp = g_environ_unsetenv (envp, "XDG_CURRENT_DESKTOP");
486
487   success = g_spawn_sync (NULL, argv, envp, 0, NULL, NULL, &out, NULL, &status, NULL);
488   g_assert (success);
489   g_assert (status == 0);
490
491   g_strfreev (envp);
492   g_strfreev (argv);
493
494   return out;
495 }
496
497 static void
498 assert_strings_equivalent (const gchar *expected,
499                            const gchar *result)
500 {
501   gchar **expected_words;
502   gchar **result_words;
503   gint i, j;
504
505   expected_words = g_strsplit (expected, " ", 0);
506   result_words = g_strsplit_set (result, " \n", 0);
507
508   for (i = 0; expected_words[i]; i++)
509     {
510       for (j = 0; result_words[j]; j++)
511         if (g_str_equal (expected_words[i], result_words[j]))
512           goto got_it;
513
514       g_test_message ("Unable to find expected string '%s' in result '%s'", expected_words[i], result);
515       g_test_fail ();
516
517 got_it:
518       continue;
519     }
520
521   g_assert_cmpint (g_strv_length (expected_words), ==, g_strv_length (result_words));
522   g_strfreev (expected_words);
523   g_strfreev (result_words);
524 }
525
526 static void
527 assert_list (const gchar *expected,
528              gboolean     with_usr,
529              gboolean     with_home,
530              const gchar *locale_name,
531              const gchar *language)
532 {
533   gchar *result;
534
535   result = run_apps ("list", NULL, with_usr, with_home, locale_name, language, NULL);
536   g_strchomp (result);
537   assert_strings_equivalent (expected, result);
538   g_free (result);
539 }
540
541 static void
542 assert_info (const gchar *desktop_id,
543              const gchar *expected,
544              gboolean     with_usr,
545              gboolean     with_home,
546              const gchar *locale_name,
547              const gchar *language)
548 {
549   gchar *result;
550
551   result = run_apps ("show-info", desktop_id, with_usr, with_home, locale_name, language, NULL);
552   g_assert_cmpstr (result, ==, expected);
553   g_free (result);
554 }
555
556 static void
557 assert_search (const gchar *search_string,
558                const gchar *expected,
559                gboolean     with_usr,
560                gboolean     with_home,
561                const gchar *locale_name,
562                const gchar *language)
563 {
564   gchar **expected_lines;
565   gchar **result_lines;
566   gchar *result;
567   gint i;
568
569   expected_lines = g_strsplit (expected, "\n", -1);
570   result = run_apps ("search", search_string, with_usr, with_home, locale_name, language, NULL);
571   result_lines = g_strsplit (result, "\n", -1);
572   g_assert_cmpint (g_strv_length (expected_lines), ==, g_strv_length (result_lines));
573   for (i = 0; expected_lines[i]; i++)
574     assert_strings_equivalent (expected_lines[i], result_lines[i]);
575   g_strfreev (expected_lines);
576   g_strfreev (result_lines);
577   g_free (result);
578 }
579
580 static void
581 assert_implementations (const gchar *interface,
582                         const gchar *expected,
583                         gboolean     with_usr,
584                         gboolean     with_home)
585 {
586   gchar *result;
587
588   result = run_apps ("implementations", interface, with_usr, with_home, NULL, NULL, NULL);
589   g_strchomp (result);
590   assert_strings_equivalent (expected, result);
591   g_free (result);
592 }
593
594 #define ALL_USR_APPS  "evince-previewer.desktop nautilus-classic.desktop gnome-font-viewer.desktop "         \
595                       "baobab.desktop yelp.desktop eog.desktop cheese.desktop gnome-clocks.desktop "         \
596                       "gnome-contacts.desktop kde4-kate.desktop gcr-prompter.desktop totem.desktop "         \
597                       "gnome-terminal.desktop nautilus-autorun-software.desktop gcr-viewer.desktop "         \
598                       "nautilus-connect-server.desktop kde4-dolphin.desktop gnome-music.desktop "            \
599                       "kde4-konqbrowser.desktop gucharmap.desktop kde4-okular.desktop nautilus.desktop "     \
600                       "gedit.desktop evince.desktop file-roller.desktop dconf-editor.desktop glade.desktop"
601 #define HOME_APPS     "epiphany-weather-for-toronto-island-9c6a4e022b17686306243dada811d550d25eb1fb.desktop"
602 #define ALL_HOME_APPS HOME_APPS " eog.desktop"
603
604 static void
605 test_search (void)
606 {
607   assert_list ("", FALSE, FALSE, NULL, NULL);
608   assert_list (ALL_USR_APPS, TRUE, FALSE, NULL, NULL);
609   assert_list (ALL_HOME_APPS, FALSE, TRUE, NULL, NULL);
610   assert_list (ALL_USR_APPS " " HOME_APPS, TRUE, TRUE, NULL, NULL);
611
612   /* The user has "installed" their own version of eog.desktop which
613    * calls it "Eye of GNOME".  Do some testing based on that.
614    *
615    * We should always find "Pictures" keyword no matter where we look.
616    */
617   assert_search ("Picture", "eog.desktop\n", TRUE, TRUE, NULL, NULL);
618   assert_search ("Picture", "eog.desktop\n", TRUE, FALSE, NULL, NULL);
619   assert_search ("Picture", "eog.desktop\n", FALSE, TRUE, NULL, NULL);
620   assert_search ("Picture", "", FALSE, FALSE, NULL, NULL);
621
622   /* We should only find it called "eye of gnome" when using the user's
623    * directory.
624    */
625   assert_search ("eye gnome", "", TRUE, FALSE, NULL, NULL);
626   assert_search ("eye gnome", "eog.desktop\n", FALSE, TRUE, NULL, NULL);
627   assert_search ("eye gnome", "eog.desktop\n", TRUE, TRUE, NULL, NULL);
628
629   /* We should only find it called "image viewer" when _not_ using the
630    * user's directory.
631    */
632   assert_search ("image viewer", "eog.desktop\n", TRUE, FALSE, NULL, NULL);
633   assert_search ("image viewer", "", FALSE, TRUE, NULL, NULL);
634   assert_search ("image viewer", "", TRUE, TRUE, NULL, NULL);
635
636   /* Obvious multi-word search */
637   assert_search ("gno hel", "yelp.desktop\n", TRUE, TRUE, NULL, NULL);
638
639   /* Repeated search terms should do nothing... */
640   assert_search ("files file fil fi f", "nautilus.desktop\n"
641                                         "gedit.desktop\n", TRUE, TRUE, NULL, NULL);
642
643   /* "con" will match "connect" and "contacts" on name but dconf only on
644    * the "config" keyword
645    */
646   assert_search ("con", "nautilus-connect-server.desktop gnome-contacts.desktop\n"
647                         "dconf-editor.desktop\n", TRUE, TRUE, NULL, NULL);
648
649   /* "gnome" will match "eye of gnome" from the user's directory, plus
650    * matching "GNOME Clocks" X-GNOME-FullName.  It's only a comment on
651    * yelp and gnome-contacts, though.
652    */
653   assert_search ("gnome", "eog.desktop\n"
654                           "gnome-clocks.desktop\n"
655                           "yelp.desktop gnome-contacts.desktop\n", TRUE, TRUE, NULL, NULL);
656
657   /* eog has exec name 'false' in usr only */
658   assert_search ("false", "eog.desktop\n", TRUE, FALSE, NULL, NULL);
659   assert_search ("false", "", FALSE, TRUE, NULL, NULL);
660   assert_search ("false", "", TRUE, TRUE, NULL, NULL);
661   assert_search ("false", "", FALSE, FALSE, NULL, NULL);
662
663   /* make sure we only search the first component */
664   assert_search ("nonsearchable", "", TRUE, FALSE, NULL, NULL);
665
666   /* "gnome con" will match only gnome contacts; via the name for
667    * "contacts" and the comment for "gnome"
668    */
669   assert_search ("gnome con", "gnome-contacts.desktop\n", TRUE, TRUE, NULL, NULL);
670
671   /* make sure we get the correct kde4- prefix on the application IDs
672    * from subdirectories
673    */
674   assert_search ("konq", "kde4-konqbrowser.desktop\n", TRUE, TRUE, NULL, NULL);
675   assert_search ("kate", "kde4-kate.desktop\n", TRUE, TRUE, NULL, NULL);
676
677   /* make sure we can lookup apps by name properly */
678   assert_info ("kde4-kate.desktop",
679                "kde4-kate.desktop\n"
680                "Kate\n"
681                "Kate\n"
682                "nil\n", TRUE, TRUE, NULL, NULL);
683
684   assert_info ("nautilus.desktop",
685                "nautilus.desktop\n"
686                "Files\n"
687                "Files\n"
688                "Access and organize files\n", TRUE, TRUE, NULL, NULL);
689
690   /* make sure localised searching works properly */
691   assert_search ("foliumi", "nautilus.desktop\n"
692                             "kde4-konqbrowser.desktop\n"
693                             "eog.desktop\n", TRUE, FALSE, "en_US.UTF-8", "eo");
694   /* the user's eog.desktop has no translations... */
695   assert_search ("foliumi", "nautilus.desktop\n"
696                             "kde4-konqbrowser.desktop\n", TRUE, TRUE, "en_US.UTF-8", "eo");
697 }
698
699 static void
700 test_implements (void)
701 {
702   /* Make sure we can find our search providers... */
703   assert_implementations ("org.gnome.Shell.SearchProvider2",
704                        "gnome-music.desktop gnome-contacts.desktop eog.desktop",
705                        TRUE, FALSE);
706
707   /* And our image acquisition possibilities... */
708   assert_implementations ("org.freedesktop.ImageProvider",
709                        "cheese.desktop",
710                        TRUE, FALSE);
711
712   /* Make sure the user's eog is properly masking the system one */
713   assert_implementations ("org.gnome.Shell.SearchProvider2",
714                        "gnome-music.desktop gnome-contacts.desktop",
715                        TRUE, TRUE);
716
717   /* Make sure we get nothing if we have nothing */
718   assert_implementations ("org.gnome.Shell.SearchProvider2", "", FALSE, FALSE);
719 }
720
721 static void
722 assert_shown (const gchar *desktop_id,
723               gboolean     expected,
724               const gchar *xdg_current_desktop)
725 {
726   gchar *result;
727
728   result = run_apps ("should-show", desktop_id, TRUE, TRUE, NULL, NULL, xdg_current_desktop);
729   g_assert_cmpstr (result, ==, expected ? "true\n" : "false\n");
730   g_free (result);
731 }
732
733 static void
734 test_show_in (void)
735 {
736   assert_shown ("gcr-prompter.desktop", FALSE, NULL);
737   assert_shown ("gcr-prompter.desktop", FALSE, "GNOME");
738   assert_shown ("gcr-prompter.desktop", FALSE, "KDE");
739   assert_shown ("gcr-prompter.desktop", FALSE, "GNOME:GNOME-Classic");
740   assert_shown ("gcr-prompter.desktop", TRUE, "GNOME-Classic:GNOME");
741   assert_shown ("gcr-prompter.desktop", TRUE, "GNOME-Classic");
742   assert_shown ("gcr-prompter.desktop", TRUE, "GNOME-Classic:KDE");
743   assert_shown ("gcr-prompter.desktop", TRUE, "KDE:GNOME-Classic");
744 }
745
746 int
747 main (int   argc,
748       char *argv[])
749 {
750   gint result;
751
752   g_test_init (&argc, &argv, NULL);
753
754   basedir = g_get_current_dir ();
755   g_setenv ("XDG_DATA_HOME", basedir, TRUE);
756   cleanup_subdirs (basedir);
757
758   g_test_add_func ("/desktop-app-info/delete", test_delete);
759   g_test_add_func ("/desktop-app-info/default", test_default);
760   g_test_add_func ("/desktop-app-info/fallback", test_fallback);
761   g_test_add_func ("/desktop-app-info/lastused", test_last_used);
762   g_test_add_func ("/desktop-app-info/extra-getters", test_extra_getters);
763   g_test_add_func ("/desktop-app-info/actions", test_actions);
764   g_test_add_func ("/desktop-app-info/search", test_search);
765   g_test_add_func ("/desktop-app-info/implements", test_implements);
766   g_test_add_func ("/desktop-app-info/show-in", test_show_in);
767
768   result = g_test_run ();
769
770   cleanup_subdirs (basedir);
771
772   return result;
773 }