5 #include <gio/gdesktopappinfo.h>
13 appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test.desktop");
14 g_assert (appinfo != NULL);
17 g_assert (g_app_info_launch (appinfo, NULL, NULL, &error));
18 g_assert_no_error (error);
20 g_assert (g_app_info_launch_uris (appinfo, NULL, NULL, &error));
21 g_assert_no_error (error);
25 test_locale (const char *locale)
30 orig = setlocale (LC_ALL, NULL);
31 g_setenv ("LANGUAGE", locale, TRUE);
32 setlocale (LC_ALL, "");
34 appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test.desktop");
36 if (g_strcmp0 (locale, "C") == 0)
38 g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "appinfo-test");
39 g_assert_cmpstr (g_app_info_get_description (appinfo), ==, "GAppInfo example");
40 g_assert_cmpstr (g_app_info_get_display_name (appinfo), ==, "example");
42 else if (g_str_has_prefix (locale, "en"))
44 g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "appinfo-test");
45 g_assert_cmpstr (g_app_info_get_description (appinfo), ==, "GAppInfo example");
46 g_assert_cmpstr (g_app_info_get_display_name (appinfo), ==, "example");
48 else if (g_str_has_prefix (locale, "de"))
50 g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "appinfo-test-de");
51 g_assert_cmpstr (g_app_info_get_description (appinfo), ==, "GAppInfo Beispiel");
52 g_assert_cmpstr (g_app_info_get_display_name (appinfo), ==, "Beispiel");
55 g_object_unref (appinfo);
57 g_setenv ("LANGUAGE", orig, TRUE);
58 setlocale (LC_ALL, "");
65 test_locale ("en_US");
67 test_locale ("de_DE.UTF-8");
77 appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test.desktop");
79 g_assert (g_app_info_get_id (appinfo) == NULL);
80 g_assert_cmpstr (g_app_info_get_executable (appinfo), ==, "./appinfo-test");
81 g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, "./appinfo-test --option");
83 icon = g_app_info_get_icon (appinfo);
84 g_assert (G_IS_THEMED_ICON (icon));
85 icon2 = g_themed_icon_new ("testicon");
86 g_assert (g_icon_equal (icon, icon2));
87 g_object_unref (icon2);
89 appinfo2 = g_app_info_dup (appinfo);
90 g_assert (g_app_info_get_id (appinfo) == g_app_info_get_id (appinfo2));
91 g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, g_app_info_get_commandline (appinfo2));
93 g_object_unref (appinfo);
94 g_object_unref (appinfo2);
102 g_desktop_app_info_set_desktop_env ("GNOME");
104 appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test.desktop");
105 g_assert (g_app_info_should_show (appinfo));
106 g_object_unref (appinfo);
108 appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test-gnome.desktop");
109 g_assert (g_app_info_should_show (appinfo));
110 g_object_unref (appinfo);
112 appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test-notgnome.desktop");
113 g_assert (!g_app_info_should_show (appinfo));
114 g_object_unref (appinfo);
118 test_commandline (void)
124 appinfo = g_app_info_create_from_commandline ("./appinfo-test --option",
126 G_APP_INFO_CREATE_SUPPORTS_URIS,
128 g_assert (appinfo != NULL);
129 g_assert_no_error (error);
130 g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "cmdline-app-test");
131 g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, "./appinfo-test --option %u");
132 g_assert (g_app_info_supports_uris (appinfo));
133 g_assert (!g_app_info_supports_files (appinfo));
135 g_object_unref (appinfo);
138 appinfo = g_app_info_create_from_commandline ("./appinfo-test --option",
140 G_APP_INFO_CREATE_NONE,
142 g_assert (appinfo != NULL);
143 g_assert_no_error (error);
144 g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "cmdline-app-test");
145 g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, "./appinfo-test --option %f");
146 g_assert (!g_app_info_supports_uris (appinfo));
147 g_assert (g_app_info_supports_files (appinfo));
149 g_object_unref (appinfo);
153 test_launch_context (void)
155 GAppLaunchContext *context;
159 context = g_app_launch_context_new ();
160 appinfo = g_app_info_create_from_commandline ("./appinfo-test --option",
162 G_APP_INFO_CREATE_SUPPORTS_URIS,
165 str = g_app_launch_context_get_display (context, appinfo, NULL);
166 g_assert (str == NULL);
168 str = g_app_launch_context_get_startup_notify_id (context, appinfo, NULL);
169 g_assert (str == NULL);
171 g_object_unref (appinfo);
172 g_object_unref (context);
180 appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test2.desktop");
182 g_assert (appinfo == NULL);
185 /* Test that we can set an appinfo as default for a mime type or
186 * file extension, and also add and remove handled mime types.
189 test_associations (void)
197 appinfo = g_app_info_create_from_commandline ("./appinfo-test --option",
199 G_APP_INFO_CREATE_SUPPORTS_URIS,
203 result = g_app_info_set_as_default_for_type (appinfo, "application/x-glib-test", &error);
206 g_assert_no_error (error);
208 appinfo2 = g_app_info_get_default_for_type ("application/x-glib-test", FALSE);
211 g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, g_app_info_get_commandline (appinfo2));
213 g_object_unref (appinfo2);
215 result = g_app_info_set_as_default_for_extension (appinfo, "gio-tests", &error);
217 g_assert_no_error (error);
219 appinfo2 = g_app_info_get_default_for_type ("application/x-extension-gio-tests", FALSE);
222 g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, g_app_info_get_commandline (appinfo2));
224 g_object_unref (appinfo2);
226 result = g_app_info_add_supports_type (appinfo, "application/x-gio-test", &error);
228 g_assert_no_error (error);
230 list = g_app_info_get_all_for_type ("application/x-gio-test");
231 g_assert_cmpint (g_list_length (list), ==, 1);
232 appinfo2 = list->data;
233 g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, g_app_info_get_commandline (appinfo2));
234 g_object_unref (appinfo2);
237 g_assert (g_app_info_can_remove_supports_type (appinfo));
238 g_assert (g_app_info_remove_supports_type (appinfo, "application/x-gio-test", &error));
239 g_assert_no_error (error);
241 g_assert (g_app_info_can_delete (appinfo));
242 g_assert (g_app_info_delete (appinfo));
243 g_object_unref (appinfo);
247 test_environment (void)
249 GAppLaunchContext *ctx;
252 ctx = g_app_launch_context_new ();
253 g_app_launch_context_setenv (ctx, "FOO", "bar");
254 g_app_launch_context_setenv (ctx, "BLA", "bla");
256 env = g_app_launch_context_get_environment (ctx);
258 g_assert_cmpstr (g_environ_getenv (env, "FOO"), ==, "bar");
259 g_assert_cmpstr (g_environ_getenv (env, "BLA"), ==, "bla");
263 g_app_launch_context_setenv (ctx, "FOO", "baz");
264 g_app_launch_context_unsetenv (ctx, "BLA");
266 env = g_app_launch_context_get_environment (ctx);
268 g_assert_cmpstr (g_environ_getenv (env, "FOO"), ==, "baz");
269 g_assert (g_environ_getenv (env, "BLA") == NULL);
273 g_object_unref (ctx);
277 main (int argc, char *argv[])
280 g_test_init (&argc, &argv, NULL);
282 g_test_add_func ("/appinfo/basic", test_basic);
283 g_test_add_func ("/appinfo/text", test_text);
284 g_test_add_func ("/appinfo/launch", test_launch);
285 g_test_add_func ("/appinfo/show-in", test_show_in);
286 g_test_add_func ("/appinfo/commandline", test_commandline);
287 g_test_add_func ("/appinfo/launch-context", test_launch_context);
288 g_test_add_func ("/appinfo/tryexec", test_tryexec);
289 g_test_add_func ("/appinfo/associations", test_associations);
290 g_test_add_func ("/appinfo/environment", test_environment);
292 return g_test_run ();