Branch data Line data Source code
1 : :
2 : : #include <locale.h>
3 : : #include <string.h>
4 : :
5 : : #include <glib/gstdio.h>
6 : : #include <gio/gio.h>
7 : : #include <gio/gdesktopappinfo.h>
8 : :
9 : : /* Should be called inside a #GTestDBus environment. */
10 : : static void
11 : 3 : test_launch_for_app_info (GAppInfo *appinfo)
12 : : {
13 : 3 : GError *error = NULL;
14 : : gboolean success;
15 : : GFile *file;
16 : : GList *l;
17 : : const gchar *path;
18 : : gchar *uri;
19 : :
20 : 3 : success = g_app_info_launch (appinfo, NULL, NULL, &error);
21 : 3 : g_assert_no_error (error);
22 : 3 : g_assert_true (success);
23 : :
24 : 3 : success = g_app_info_launch_uris (appinfo, NULL, NULL, &error);
25 : 3 : g_assert_no_error (error);
26 : 3 : g_assert_true (success);
27 : :
28 : 3 : path = g_test_get_filename (G_TEST_BUILT, "appinfo-test.desktop", NULL);
29 : 3 : file = g_file_new_for_path (path);
30 : 3 : l = NULL;
31 : 3 : l = g_list_append (l, file);
32 : :
33 : 3 : success = g_app_info_launch (appinfo, l, NULL, &error);
34 : 3 : g_assert_no_error (error);
35 : 3 : g_assert_true (success);
36 : 3 : g_list_free (l);
37 : 3 : g_object_unref (file);
38 : :
39 : 3 : l = NULL;
40 : 3 : uri = g_strconcat ("file://", g_test_get_dir (G_TEST_BUILT), "/appinfo-test.desktop", NULL);
41 : 3 : l = g_list_append (l, uri);
42 : 3 : l = g_list_append (l, "file:///etc/group#adm");
43 : :
44 : 3 : success = g_app_info_launch_uris (appinfo, l, NULL, &error);
45 : 3 : g_assert_no_error (error);
46 : 3 : g_assert_true (success);
47 : :
48 : 3 : g_list_free (l);
49 : 3 : g_free (uri);
50 : 3 : }
51 : :
52 : : static void
53 : 1 : test_launch (void)
54 : : {
55 : 1 : GTestDBus *bus = NULL;
56 : : GAppInfo *appinfo;
57 : : const gchar *path;
58 : :
59 : : /* Set up a test session bus to keep D-Bus traffic off the real session bus. */
60 : 1 : bus = g_test_dbus_new (G_TEST_DBUS_NONE);
61 : 1 : g_test_dbus_up (bus);
62 : :
63 : 1 : path = g_test_get_filename (G_TEST_BUILT, "appinfo-test.desktop", NULL);
64 : 1 : appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
65 : 1 : g_assert_true (G_IS_APP_INFO (appinfo));
66 : :
67 : 1 : test_launch_for_app_info (appinfo);
68 : 1 : g_object_unref (appinfo);
69 : :
70 : 1 : g_test_dbus_down (bus);
71 : 1 : g_clear_object (&bus);
72 : 1 : }
73 : :
74 : : static void
75 : 1 : test_launch_no_app_id (void)
76 : : {
77 : 1 : const gchar desktop_file_base_contents[] =
78 : : "[Desktop Entry]\n"
79 : : "Type=Application\n"
80 : : "GenericName=generic-appinfo-test\n"
81 : : "Name=appinfo-test\n"
82 : : "Name[de]=appinfo-test-de\n"
83 : : "X-GNOME-FullName=example\n"
84 : : "X-GNOME-FullName[de]=Beispiel\n"
85 : : "Comment=GAppInfo example\n"
86 : : "Comment[de]=GAppInfo Beispiel\n"
87 : : "Icon=testicon.svg\n"
88 : : "Terminal=false\n"
89 : : "StartupNotify=true\n"
90 : : "StartupWMClass=appinfo-class\n"
91 : : "MimeType=image/png;image/jpeg;\n"
92 : : "Keywords=keyword1;test keyword;\n"
93 : : "Categories=GNOME;GTK;\n";
94 : :
95 : 1 : GTestDBus *bus = NULL;
96 : : gchar *exec_line_variants[2];
97 : : gsize i;
98 : :
99 : 1 : exec_line_variants[0] = g_strdup_printf (
100 : : "Exec=%s/appinfo-test --option %%U %%i --name %%c --filename %%k %%m %%%%",
101 : : g_test_get_dir (G_TEST_BUILT));
102 : 1 : exec_line_variants[1] = g_strdup_printf (
103 : : "Exec=%s/appinfo-test --option %%u %%i --name %%c --filename %%k %%m %%%%",
104 : : g_test_get_dir (G_TEST_BUILT));
105 : :
106 : 1 : g_test_bug ("https://bugzilla.gnome.org/show_bug.cgi?id=791337");
107 : :
108 : : /* Set up a test session bus to keep D-Bus traffic off the real session bus. */
109 : 1 : bus = g_test_dbus_new (G_TEST_DBUS_NONE);
110 : 1 : g_test_dbus_up (bus);
111 : :
112 [ + + ]: 3 : for (i = 0; i < G_N_ELEMENTS (exec_line_variants); i++)
113 : : {
114 : : gchar *desktop_file_contents;
115 : : GKeyFile *fake_desktop_file;
116 : : GAppInfo *appinfo;
117 : : gboolean loaded;
118 : :
119 : 2 : g_test_message ("Exec line variant #%" G_GSIZE_FORMAT, i);
120 : :
121 : 2 : desktop_file_contents = g_strdup_printf ("%s\n%s",
122 : : desktop_file_base_contents,
123 : : exec_line_variants[i]);
124 : :
125 : : /* We load a desktop file from memory to force the app not
126 : : * to have an app ID, which would check different codepaths.
127 : : */
128 : 2 : fake_desktop_file = g_key_file_new ();
129 : 2 : loaded = g_key_file_load_from_data (fake_desktop_file, desktop_file_contents, -1, G_KEY_FILE_NONE, NULL);
130 : 2 : g_assert_true (loaded);
131 : :
132 : 2 : appinfo = (GAppInfo*)g_desktop_app_info_new_from_keyfile (fake_desktop_file);
133 : 2 : g_assert_nonnull (appinfo);
134 : :
135 : 2 : test_launch_for_app_info (appinfo);
136 : :
137 : 2 : g_free (desktop_file_contents);
138 : 2 : g_object_unref (appinfo);
139 : 2 : g_key_file_unref (fake_desktop_file);
140 : : }
141 : :
142 : 1 : g_test_dbus_down (bus);
143 : 1 : g_clear_object (&bus);
144 : :
145 : 1 : g_free (exec_line_variants[1]);
146 : 1 : g_free (exec_line_variants[0]);
147 : 1 : }
148 : :
149 : : static void
150 : 4 : test_locale (const char *locale)
151 : : {
152 : : GAppInfo *appinfo;
153 : 4 : gchar *orig = NULL;
154 : : const gchar *path;
155 : :
156 : 4 : orig = g_strdup (setlocale (LC_ALL, NULL));
157 : 4 : g_setenv ("LANGUAGE", locale, TRUE);
158 : 4 : setlocale (LC_ALL, "");
159 : :
160 : 4 : path = g_test_get_filename (G_TEST_DIST, "appinfo-test-static.desktop", NULL);
161 : 4 : appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
162 : :
163 [ + + ]: 4 : if (g_strcmp0 (locale, "C") == 0)
164 : : {
165 : 1 : g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "appinfo-test");
166 : 1 : g_assert_cmpstr (g_app_info_get_description (appinfo), ==, "GAppInfo example");
167 : 1 : g_assert_cmpstr (g_app_info_get_display_name (appinfo), ==, "example");
168 : : }
169 [ + - - + : 3 : else if (g_str_has_prefix (locale, "en"))
+ - + + ]
170 : : {
171 : 1 : g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "appinfo-test");
172 : 1 : g_assert_cmpstr (g_app_info_get_description (appinfo), ==, "GAppInfo example");
173 : 1 : g_assert_cmpstr (g_app_info_get_display_name (appinfo), ==, "example");
174 : : }
175 [ + - - + : 2 : else if (g_str_has_prefix (locale, "de"))
+ - + - ]
176 : : {
177 : 2 : g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "appinfo-test-de");
178 : 2 : g_assert_cmpstr (g_app_info_get_description (appinfo), ==, "GAppInfo Beispiel");
179 : 2 : g_assert_cmpstr (g_app_info_get_display_name (appinfo), ==, "Beispiel");
180 : : }
181 : :
182 : 4 : g_object_unref (appinfo);
183 : :
184 : 4 : g_setenv ("LANGUAGE", orig, TRUE);
185 : 4 : setlocale (LC_ALL, "");
186 : 4 : g_free (orig);
187 : 4 : }
188 : :
189 : : static void
190 : 1 : test_text (void)
191 : : {
192 : 1 : test_locale ("C");
193 : 1 : test_locale ("en_US");
194 : 1 : test_locale ("de");
195 : 1 : test_locale ("de_DE.UTF-8");
196 : 1 : }
197 : :
198 : : static void
199 : 1 : test_basic (void)
200 : : {
201 : : GAppInfo *appinfo;
202 : : GAppInfo *appinfo2;
203 : : GIcon *icon, *icon2;
204 : : const gchar *path;
205 : :
206 : 1 : path = g_test_get_filename (G_TEST_DIST, "appinfo-test-static.desktop", NULL);
207 : 1 : appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
208 : 1 : g_assert_nonnull (appinfo);
209 : :
210 : 1 : g_assert_cmpstr (g_app_info_get_id (appinfo), ==, "appinfo-test-static.desktop");
211 : 1 : g_assert_nonnull (strstr (g_app_info_get_executable (appinfo), "true"));
212 : :
213 : 1 : icon = g_app_info_get_icon (appinfo);
214 : 1 : g_assert_true (G_IS_THEMED_ICON (icon));
215 : 1 : icon2 = g_themed_icon_new ("testicon");
216 : 1 : g_assert_true (g_icon_equal (icon, icon2));
217 : 1 : g_object_unref (icon2);
218 : :
219 : 1 : appinfo2 = g_app_info_dup (appinfo);
220 : 1 : g_assert_cmpstr (g_app_info_get_id (appinfo), ==, g_app_info_get_id (appinfo2));
221 : 1 : g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, g_app_info_get_commandline (appinfo2));
222 : :
223 : 1 : g_object_unref (appinfo);
224 : 1 : g_object_unref (appinfo2);
225 : 1 : }
226 : :
227 : : static void
228 : 1 : test_show_in (void)
229 : : {
230 : : GAppInfo *appinfo;
231 : : const gchar *path;
232 : :
233 : 1 : path = g_test_get_filename (G_TEST_BUILT, "appinfo-test.desktop", NULL);
234 : 1 : appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
235 : 1 : g_assert_true (G_IS_APP_INFO (appinfo));
236 : :
237 : 1 : g_assert_true (g_app_info_should_show (appinfo));
238 : 1 : g_object_unref (appinfo);
239 : :
240 : 1 : path = g_test_get_filename (G_TEST_BUILT, "appinfo-test-gnome.desktop", NULL);
241 : 1 : appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
242 : 1 : g_assert_true (g_app_info_should_show (appinfo));
243 : 1 : g_object_unref (appinfo);
244 : :
245 : 1 : path = g_test_get_filename (G_TEST_BUILT, "appinfo-test-notgnome.desktop", NULL);
246 : 1 : appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
247 : 1 : g_assert_false (g_app_info_should_show (appinfo));
248 : 1 : g_object_unref (appinfo);
249 : 1 : }
250 : :
251 : : static void
252 : 1 : test_commandline (void)
253 : : {
254 : : GAppInfo *appinfo;
255 : : GError *error;
256 : : gchar *cmdline;
257 : : gchar *cmdline_out;
258 : :
259 : 1 : cmdline = g_strconcat (g_test_get_dir (G_TEST_BUILT), "/appinfo-test --option", NULL);
260 : 1 : cmdline_out = g_strconcat (cmdline, " %u", NULL);
261 : :
262 : 1 : error = NULL;
263 : 1 : appinfo = g_app_info_create_from_commandline (cmdline,
264 : : "cmdline-app-test",
265 : : G_APP_INFO_CREATE_SUPPORTS_URIS,
266 : : &error);
267 : 1 : g_assert_no_error (error);
268 : 1 : g_assert_nonnull (appinfo);
269 : 1 : g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "cmdline-app-test");
270 : 1 : g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, cmdline_out);
271 : 1 : g_assert_true (g_app_info_supports_uris (appinfo));
272 : 1 : g_assert_false (g_app_info_supports_files (appinfo));
273 : :
274 : 1 : g_object_unref (appinfo);
275 : :
276 : 1 : g_free (cmdline_out);
277 : 1 : cmdline_out = g_strconcat (cmdline, " %f", NULL);
278 : :
279 : 1 : error = NULL;
280 : 1 : appinfo = g_app_info_create_from_commandline (cmdline,
281 : : "cmdline-app-test",
282 : : G_APP_INFO_CREATE_NONE,
283 : : &error);
284 : 1 : g_assert_no_error (error);
285 : 1 : g_assert_nonnull (appinfo);
286 : 1 : g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "cmdline-app-test");
287 : 1 : g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, cmdline_out);
288 : 1 : g_assert_false (g_app_info_supports_uris (appinfo));
289 : 1 : g_assert_true (g_app_info_supports_files (appinfo));
290 : :
291 : 1 : g_object_unref (appinfo);
292 : :
293 : 1 : g_free (cmdline);
294 : 1 : g_free (cmdline_out);
295 : 1 : }
296 : :
297 : : static void
298 : 1 : test_launch_context (void)
299 : : {
300 : : GAppLaunchContext *context;
301 : : GAppInfo *appinfo;
302 : : gchar *str;
303 : : gchar *cmdline;
304 : :
305 : 1 : cmdline = g_strconcat (g_test_get_dir (G_TEST_BUILT), "/appinfo-test --option", NULL);
306 : :
307 : 1 : context = g_app_launch_context_new ();
308 : 1 : appinfo = g_app_info_create_from_commandline (cmdline,
309 : : "cmdline-app-test",
310 : : G_APP_INFO_CREATE_SUPPORTS_URIS,
311 : : NULL);
312 : :
313 : 1 : str = g_app_launch_context_get_display (context, appinfo, NULL);
314 : 1 : g_assert_null (str);
315 : :
316 : 1 : str = g_app_launch_context_get_startup_notify_id (context, appinfo, NULL);
317 : 1 : g_assert_null (str);
318 : :
319 : 1 : g_object_unref (appinfo);
320 : 1 : g_object_unref (context);
321 : :
322 : 1 : g_free (cmdline);
323 : 1 : }
324 : :
325 : : static gboolean launched_reached;
326 : :
327 : : static void
328 : 1 : launched (GAppLaunchContext *context,
329 : : GAppInfo *info,
330 : : GVariant *platform_data,
331 : : gpointer user_data)
332 : : {
333 : : gint pid;
334 : :
335 : 1 : pid = 0;
336 : 1 : g_assert_true (g_variant_lookup (platform_data, "pid", "i", &pid));
337 : 1 : g_assert_cmpint (pid, !=, 0);
338 : :
339 : 1 : launched_reached = TRUE;
340 : 1 : }
341 : :
342 : : static void
343 : 0 : launch_failed (GAppLaunchContext *context,
344 : : const gchar *startup_notify_id)
345 : : {
346 : : g_assert_not_reached ();
347 : : }
348 : :
349 : : static void
350 : 1 : test_launch_context_signals (void)
351 : : {
352 : 1 : GTestDBus *bus = NULL;
353 : : GAppLaunchContext *context;
354 : : GAppInfo *appinfo;
355 : 1 : GError *error = NULL;
356 : : gboolean success;
357 : : gchar *cmdline;
358 : :
359 : : /* Set up a test session bus to keep D-Bus traffic off the real session bus. */
360 : 1 : bus = g_test_dbus_new (G_TEST_DBUS_NONE);
361 : 1 : g_test_dbus_up (bus);
362 : :
363 : 1 : cmdline = g_strconcat (g_test_get_dir (G_TEST_BUILT), "/appinfo-test --option", NULL);
364 : :
365 : 1 : context = g_app_launch_context_new ();
366 : 1 : g_signal_connect (context, "launched", G_CALLBACK (launched), NULL);
367 : 1 : g_signal_connect (context, "launch_failed", G_CALLBACK (launch_failed), NULL);
368 : 1 : appinfo = g_app_info_create_from_commandline (cmdline,
369 : : "cmdline-app-test",
370 : : G_APP_INFO_CREATE_SUPPORTS_URIS,
371 : : NULL);
372 : :
373 : 1 : success = g_app_info_launch (appinfo, NULL, context, &error);
374 : 1 : g_assert_no_error (error);
375 : 1 : g_assert_true (success);
376 : :
377 : 1 : g_assert_true (launched_reached);
378 : :
379 : 1 : g_object_unref (appinfo);
380 : 1 : g_object_unref (context);
381 : :
382 : 1 : g_free (cmdline);
383 : :
384 : 1 : g_test_dbus_down (bus);
385 : 1 : g_clear_object (&bus);
386 : 1 : }
387 : :
388 : : static void
389 : 1 : test_tryexec (void)
390 : : {
391 : : GAppInfo *appinfo;
392 : : const gchar *path;
393 : :
394 : 1 : path = g_test_get_filename (G_TEST_BUILT, "appinfo-test2.desktop", NULL);
395 : 1 : appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path);
396 : :
397 : 1 : g_assert_null (appinfo);
398 : 1 : }
399 : :
400 : : /* Test that we can set an appinfo as default for a mime type or
401 : : * file extension, and also add and remove handled mime types.
402 : : */
403 : : static void
404 : 1 : test_associations (void)
405 : : {
406 : : GAppInfo *appinfo;
407 : : GAppInfo *appinfo2;
408 : 1 : GError *error = NULL;
409 : : gboolean result;
410 : : GList *list;
411 : : gchar *cmdline;
412 : 1 : gchar *update_desktop_database = NULL, *update_mime_database = NULL;
413 : :
414 : 1 : update_desktop_database = g_find_program_in_path ("update-desktop-database");
415 : 1 : update_mime_database = g_find_program_in_path ("update-mime-database");
416 : :
417 [ + - - + ]: 1 : if (update_desktop_database == NULL || update_mime_database == NULL)
418 : : {
419 : 0 : g_test_skip ("update-desktop-database and update-mime-database are needed to change file associations");
420 : 0 : g_free (update_desktop_database);
421 : 0 : g_free (update_mime_database);
422 : 0 : return;
423 : : }
424 : :
425 : 1 : g_free (update_desktop_database);
426 : 1 : g_free (update_mime_database);
427 : :
428 : 1 : cmdline = g_strconcat (g_test_get_dir (G_TEST_BUILT), "/appinfo-test --option", NULL);
429 : 1 : appinfo = g_app_info_create_from_commandline (cmdline,
430 : : "cmdline-app-test",
431 : : G_APP_INFO_CREATE_SUPPORTS_URIS,
432 : : NULL);
433 : 1 : g_free (cmdline);
434 : :
435 : 1 : result = g_app_info_set_as_default_for_type (appinfo, "application/x-glib-test", &error);
436 : 1 : g_assert_no_error (error);
437 : 1 : g_assert_true (result);
438 : :
439 : 1 : appinfo2 = g_app_info_get_default_for_type ("application/x-glib-test", FALSE);
440 : :
441 : 1 : g_assert_nonnull (appinfo2);
442 : 1 : g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, g_app_info_get_commandline (appinfo2));
443 : :
444 : 1 : g_object_unref (appinfo2);
445 : :
446 : 1 : result = g_app_info_set_as_default_for_extension (appinfo, "gio-tests", &error);
447 : 1 : g_assert_no_error (error);
448 : 1 : g_assert_true (result);
449 : :
450 : 1 : appinfo2 = g_app_info_get_default_for_type ("application/x-extension-gio-tests", FALSE);
451 : :
452 : 1 : g_assert_nonnull (appinfo2);
453 : 1 : g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, g_app_info_get_commandline (appinfo2));
454 : :
455 : 1 : g_object_unref (appinfo2);
456 : :
457 : 1 : result = g_app_info_add_supports_type (appinfo, "application/x-gio-test", &error);
458 : 1 : g_assert_no_error (error);
459 : 1 : g_assert_true (result);
460 : :
461 : 1 : list = g_app_info_get_all_for_type ("application/x-gio-test");
462 : 1 : g_assert_cmpint (g_list_length (list), ==, 1);
463 : 1 : appinfo2 = list->data;
464 : 1 : g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, g_app_info_get_commandline (appinfo2));
465 : 1 : g_object_unref (appinfo2);
466 : 1 : g_list_free (list);
467 : :
468 : 1 : g_assert_true (g_app_info_can_remove_supports_type (appinfo));
469 : 1 : result = g_app_info_remove_supports_type (appinfo, "application/x-gio-test", &error);
470 : 1 : g_assert_no_error (error);
471 : 1 : g_assert_true (result);
472 : :
473 : 1 : g_assert_true (g_app_info_can_delete (appinfo));
474 : 1 : g_assert_true (g_app_info_delete (appinfo));
475 : 1 : g_object_unref (appinfo);
476 : : }
477 : :
478 : : static void
479 : 1 : test_environment (void)
480 : : {
481 : : GAppLaunchContext *ctx;
482 : : gchar **env;
483 : : const gchar *path;
484 : :
485 : 1 : g_unsetenv ("FOO");
486 : 1 : g_unsetenv ("BLA");
487 : 1 : path = g_getenv ("PATH");
488 : :
489 : 1 : ctx = g_app_launch_context_new ();
490 : :
491 : 1 : env = g_app_launch_context_get_environment (ctx);
492 : :
493 : 1 : g_assert_null (g_environ_getenv (env, "FOO"));
494 : 1 : g_assert_null (g_environ_getenv (env, "BLA"));
495 : 1 : g_assert_cmpstr (g_environ_getenv (env, "PATH"), ==, path);
496 : :
497 : 1 : g_strfreev (env);
498 : :
499 : 1 : g_app_launch_context_setenv (ctx, "FOO", "bar");
500 : 1 : g_app_launch_context_setenv (ctx, "BLA", "bla");
501 : :
502 : 1 : env = g_app_launch_context_get_environment (ctx);
503 : :
504 : 1 : g_assert_cmpstr (g_environ_getenv (env, "FOO"), ==, "bar");
505 : 1 : g_assert_cmpstr (g_environ_getenv (env, "BLA"), ==, "bla");
506 : 1 : g_assert_cmpstr (g_environ_getenv (env, "PATH"), ==, path);
507 : :
508 : 1 : g_strfreev (env);
509 : :
510 : 1 : g_app_launch_context_setenv (ctx, "FOO", "baz");
511 : 1 : g_app_launch_context_unsetenv (ctx, "BLA");
512 : :
513 : 1 : env = g_app_launch_context_get_environment (ctx);
514 : :
515 : 1 : g_assert_cmpstr (g_environ_getenv (env, "FOO"), ==, "baz");
516 : 1 : g_assert_null (g_environ_getenv (env, "BLA"));
517 : :
518 : 1 : g_strfreev (env);
519 : :
520 : 1 : g_object_unref (ctx);
521 : 1 : }
522 : :
523 : : static void
524 : 1 : test_startup_wm_class (void)
525 : : {
526 : : GDesktopAppInfo *appinfo;
527 : : const char *wm_class;
528 : : const gchar *path;
529 : :
530 : 1 : path = g_test_get_filename (G_TEST_DIST, "appinfo-test-static.desktop", NULL);
531 : 1 : appinfo = g_desktop_app_info_new_from_filename (path);
532 : 1 : wm_class = g_desktop_app_info_get_startup_wm_class (appinfo);
533 : :
534 : 1 : g_assert_cmpstr (wm_class, ==, "appinfo-class");
535 : :
536 : 1 : g_object_unref (appinfo);
537 : 1 : }
538 : :
539 : : static void
540 : 1 : test_supported_types (void)
541 : : {
542 : : GAppInfo *appinfo;
543 : : const char * const *content_types;
544 : : const gchar *path;
545 : :
546 : 1 : path = g_test_get_filename (G_TEST_DIST, "appinfo-test-static.desktop", NULL);
547 : 1 : appinfo = G_APP_INFO (g_desktop_app_info_new_from_filename (path));
548 : 1 : content_types = g_app_info_get_supported_types (appinfo);
549 : :
550 : 1 : g_assert_cmpint (g_strv_length ((char**)content_types), ==, 2);
551 : 1 : g_assert_cmpstr (content_types[0], ==, "image/png");
552 : :
553 : 1 : g_object_unref (appinfo);
554 : 1 : }
555 : :
556 : : static void
557 : 1 : test_from_keyfile (void)
558 : : {
559 : : GDesktopAppInfo *info;
560 : : GKeyFile *kf;
561 : 1 : GError *error = NULL;
562 : : const gchar *categories;
563 : : gchar **categories_list;
564 : : gsize categories_count;
565 : : gchar **keywords;
566 : : const gchar *file;
567 : : const gchar *name;
568 : : const gchar *path;
569 : :
570 : 1 : path = g_test_get_filename (G_TEST_DIST, "appinfo-test-static.desktop", NULL);
571 : 1 : kf = g_key_file_new ();
572 : 1 : g_key_file_load_from_file (kf, path, G_KEY_FILE_NONE, &error);
573 : 1 : g_assert_no_error (error);
574 : 1 : info = g_desktop_app_info_new_from_keyfile (kf);
575 : 1 : g_key_file_unref (kf);
576 : 1 : g_assert_nonnull (info);
577 : :
578 : 1 : g_object_get (info, "filename", &file, NULL);
579 : 1 : g_assert_null (file);
580 : :
581 : 1 : file = g_desktop_app_info_get_filename (info);
582 : 1 : g_assert_null (file);
583 : 1 : categories = g_desktop_app_info_get_categories (info);
584 : 1 : g_assert_cmpstr (categories, ==, "GNOME;GTK;");
585 : 1 : categories_list = g_desktop_app_info_get_string_list (info, "Categories", &categories_count);
586 : 1 : g_assert_cmpint (categories_count, ==, 2);
587 : 1 : g_assert_cmpint (g_strv_length (categories_list), ==, 2);
588 : 1 : g_assert_cmpstr (categories_list[0], ==, "GNOME");
589 : 1 : g_assert_cmpstr (categories_list[1], ==, "GTK");
590 : 1 : keywords = (gchar **)g_desktop_app_info_get_keywords (info);
591 : 1 : g_assert_cmpint (g_strv_length (keywords), ==, 2);
592 : 1 : g_assert_cmpstr (keywords[0], ==, "keyword1");
593 : 1 : g_assert_cmpstr (keywords[1], ==, "test keyword");
594 : 1 : name = g_desktop_app_info_get_generic_name (info);
595 : 1 : g_assert_cmpstr (name, ==, "generic-appinfo-test");
596 : 1 : g_assert_false (g_desktop_app_info_get_nodisplay (info));
597 : :
598 : 1 : g_strfreev (categories_list);
599 : 1 : g_object_unref (info);
600 : 1 : }
601 : :
602 : : int
603 : 1 : main (int argc, char *argv[])
604 : : {
605 : 1 : g_setenv ("XDG_CURRENT_DESKTOP", "GNOME", TRUE);
606 : :
607 : 1 : g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
608 : :
609 : 1 : g_test_add_func ("/appinfo/basic", test_basic);
610 : 1 : g_test_add_func ("/appinfo/text", test_text);
611 : 1 : g_test_add_func ("/appinfo/launch", test_launch);
612 : 1 : g_test_add_func ("/appinfo/launch/no-appid", test_launch_no_app_id);
613 : 1 : g_test_add_func ("/appinfo/show-in", test_show_in);
614 : 1 : g_test_add_func ("/appinfo/commandline", test_commandline);
615 : 1 : g_test_add_func ("/appinfo/launch-context", test_launch_context);
616 : 1 : g_test_add_func ("/appinfo/launch-context-signals", test_launch_context_signals);
617 : 1 : g_test_add_func ("/appinfo/tryexec", test_tryexec);
618 : 1 : g_test_add_func ("/appinfo/associations", test_associations);
619 : 1 : g_test_add_func ("/appinfo/environment", test_environment);
620 : 1 : g_test_add_func ("/appinfo/startup-wm-class", test_startup_wm_class);
621 : 1 : g_test_add_func ("/appinfo/supported-types", test_supported_types);
622 : 1 : g_test_add_func ("/appinfo/from-keyfile", test_from_keyfile);
623 : :
624 : 1 : return g_test_run ();
625 : : }
|