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