Add some more cases to the app-id unit tests
[glib.git] / gio / tests / apps.c
blob191edd4aad68f3e90731391357b2023a86b632e6
1 #include <gio/gio.h>
2 #include <gio/gdesktopappinfo.h>
3 #include <locale.h>
4 #include <stdlib.h>
6 static void
7 print (const gchar *str)
9 g_print ("%s\n", str ? str : "nil");
12 static void
13 print_app_list (GList *list)
15 while (list)
17 GAppInfo *info = list->data;
18 print (g_app_info_get_id (info));
19 list = g_list_delete_link (list, list);
20 g_object_unref (info);
24 static void
25 quit (gpointer user_data)
27 g_print ("appinfo database changed.\n");
28 exit (0);
31 int
32 main (int argc, char **argv)
34 setlocale (LC_ALL, "");
36 if (argv[1] == NULL)
38 else if (g_str_equal (argv[1], "list"))
40 GList *all, *i;
42 all = g_app_info_get_all ();
43 for (i = all; i; i = i->next)
44 g_print ("%s%s", g_app_info_get_id (i->data), i->next ? " " : "\n");
45 g_list_free_full (all, g_object_unref);
47 else if (g_str_equal (argv[1], "search"))
49 gchar ***results;
50 gint i, j;
52 results = g_desktop_app_info_search (argv[2]);
53 for (i = 0; results[i]; i++)
55 for (j = 0; results[i][j]; j++)
56 g_print ("%s%s", j ? " " : "", results[i][j]);
57 g_print ("\n");
58 g_strfreev (results[i]);
60 g_free (results);
62 else if (g_str_equal (argv[1], "implementations"))
64 GList *results;
66 results = g_desktop_app_info_get_implementations (argv[2]);
67 print_app_list (results);
69 else if (g_str_equal (argv[1], "show-info"))
71 GAppInfo *info;
73 info = (GAppInfo *) g_desktop_app_info_new (argv[2]);
74 if (info)
76 print (g_app_info_get_id (info));
77 print (g_app_info_get_name (info));
78 print (g_app_info_get_display_name (info));
79 print (g_app_info_get_description (info));
80 g_object_unref (info);
83 else if (g_str_equal (argv[1], "default-for-type"))
85 GAppInfo *info;
87 info = g_app_info_get_default_for_type (argv[2], FALSE);
89 if (info)
91 print (g_app_info_get_id (info));
92 g_object_unref (info);
95 else if (g_str_equal (argv[1], "recommended-for-type"))
97 GList *list;
99 list = g_app_info_get_recommended_for_type (argv[2]);
100 print_app_list (list);
102 else if (g_str_equal (argv[1], "all-for-type"))
104 GList *list;
106 list = g_app_info_get_all_for_type (argv[2]);
107 print_app_list (list);
110 else if (g_str_equal (argv[1], "fallback-for-type"))
112 GList *list;
114 list = g_app_info_get_fallback_for_type (argv[2]);
115 print_app_list (list);
118 else if (g_str_equal (argv[1], "should-show"))
120 GAppInfo *info;
122 info = (GAppInfo *) g_desktop_app_info_new (argv[2]);
123 if (info)
125 g_print ("%s\n", g_app_info_should_show (info) ? "true" : "false");
126 g_object_unref (info);
130 else if (g_str_equal (argv[1], "monitor"))
132 GAppInfoMonitor *monitor;
133 GAppInfo *info;
135 monitor = g_app_info_monitor_get ();
137 info = (GAppInfo *) g_desktop_app_info_new ("this-desktop-file-does-not-exist");
138 g_assert (!info);
140 g_signal_connect (monitor, "changed", G_CALLBACK (quit), NULL);
142 while (1)
143 g_main_context_iteration (NULL, TRUE);
146 return 0;