Improve GAppInfo test coverage

This commit is contained in:
Matthias Clasen 2012-08-19 02:23:32 -04:00
parent 35bf77445b
commit f89e9deaec
3 changed files with 83 additions and 6 deletions

View File

@ -1,13 +1,17 @@
[Desktop Entry] [Desktop Entry]
Type=Application Type=Application
GenericName=generic-appinfo-test
Name=appinfo-test Name=appinfo-test
Name[de]=appinfo-test-de Name[de]=appinfo-test-de
X-GNOME-FullName=example X-GNOME-FullName=example
X-GNOME-FullName[de]=Beispiel X-GNOME-FullName[de]=Beispiel
Comment=GAppInfo example Comment=GAppInfo example
Comment[de]=GAppInfo Beispiel Comment[de]=GAppInfo Beispiel
Exec=./appinfo-test --option Exec=./appinfo-test --option %U %i --name %c --filename %k %m %%
Icon=testicon Icon=testicon.svg
Terminal=true
StartupNotify=true StartupNotify=true
StartupWMClass=appinfo-class StartupWMClass=appinfo-class
MimeType=image/png;image/jpeg; MimeType=image/png;image/jpeg;
Keywords=keyword1;test keyword;
Categories=GNOME;GTK;

View File

@ -9,6 +9,8 @@ test_launch (void)
{ {
GAppInfo *appinfo; GAppInfo *appinfo;
GError *error; GError *error;
GFile *file;
GList *l;
appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test.desktop"); appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test.desktop");
g_assert (appinfo != NULL); g_assert (appinfo != NULL);
@ -19,6 +21,23 @@ test_launch (void)
g_assert (g_app_info_launch_uris (appinfo, NULL, NULL, &error)); g_assert (g_app_info_launch_uris (appinfo, NULL, NULL, &error));
g_assert_no_error (error); g_assert_no_error (error);
file = g_file_new_for_path (SRCDIR "/appinfo-test.desktop");
l = NULL;
l = g_list_append (l, file);
g_assert (g_app_info_launch (appinfo, l, NULL, &error));
g_assert_no_error (error);
g_list_free (l);
g_object_unref (file);
l = NULL;
l = g_list_append (l, "file://" SRCDIR "/appinfo-test.desktop");
l = g_list_append (l, "file:///etc/group#adm");
g_assert (g_app_info_launch_uris (appinfo, l, NULL, &error));
g_assert_no_error (error);
g_list_free (l);
} }
static void static void
@ -78,7 +97,6 @@ test_basic (void)
g_assert (g_app_info_get_id (appinfo) == NULL); g_assert (g_app_info_get_id (appinfo) == NULL);
g_assert_cmpstr (g_app_info_get_executable (appinfo), ==, "./appinfo-test"); g_assert_cmpstr (g_app_info_get_executable (appinfo), ==, "./appinfo-test");
g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, "./appinfo-test --option");
icon = g_app_info_get_icon (appinfo); icon = g_app_info_get_icon (appinfo);
g_assert (G_IS_THEMED_ICON (icon)); g_assert (G_IS_THEMED_ICON (icon));
@ -317,6 +335,45 @@ test_supported_types (void)
g_object_unref (appinfo); g_object_unref (appinfo);
} }
static void
test_from_keyfile (void)
{
GDesktopAppInfo *info;
GKeyFile *kf;
GError *error = NULL;
const gchar *categories;
gchar **keywords;
const gchar *file;
const gchar *name;
kf = g_key_file_new ();
g_key_file_load_from_file (kf,
SRCDIR "/appinfo-test.desktop",
G_KEY_FILE_NONE,
&error);
g_assert_no_error (error);
info = g_desktop_app_info_new_from_keyfile (kf);
g_key_file_free (kf);
g_assert (info != NULL);
g_object_get (info, "filename", &file, NULL);
g_assert (file == NULL);
file = g_desktop_app_info_get_filename (info);
g_assert (file == NULL);
categories = g_desktop_app_info_get_categories (info);
g_assert_cmpstr (categories, ==, "GNOME;GTK;");
keywords = (gchar **)g_desktop_app_info_get_keywords (info);
g_assert_cmpint (g_strv_length (keywords), ==, 2);
g_assert_cmpstr (keywords[0], ==, "keyword1");
g_assert_cmpstr (keywords[1], ==, "test keyword");
name = g_desktop_app_info_get_generic_name (info);
g_assert_cmpstr (name, ==, "generic-appinfo-test");
g_assert (!g_desktop_app_info_get_nodisplay (info));
g_object_unref (info);
}
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
@ -334,6 +391,7 @@ main (int argc, char *argv[])
g_test_add_func ("/appinfo/environment", test_environment); g_test_add_func ("/appinfo/environment", test_environment);
g_test_add_func ("/appinfo/startup-wm-class", test_startup_wm_class); g_test_add_func ("/appinfo/startup-wm-class", test_startup_wm_class);
g_test_add_func ("/appinfo/supported-types", test_supported_types); g_test_add_func ("/appinfo/supported-types", test_supported_types);
g_test_add_func ("/appinfo/from-keyfile", test_from_keyfile);
return g_test_run (); return g_test_run ();
} }

View File

@ -73,12 +73,13 @@ const gchar *myapp5_data =
"Type=Application\n" "Type=Application\n"
"Exec=my_app5 %f\n" "Exec=my_app5 %f\n"
"Name=my app 5\n" "Name=my app 5\n"
"MimeType=image/bmp;"; "MimeType=image/bmp;x-scheme-handler/ftp;";
const gchar *defaults_data = const gchar *defaults_data =
"[Default Applications]\n" "[Default Applications]\n"
"image/bmp=myapp4.desktop;\n" "image/bmp=myapp4.desktop;\n"
"image/png=myapp3.desktop;\n"; "image/png=myapp3.desktop;\n"
"x-scheme-handler/ftp=myapp5.desktop;\n";
const gchar *mimecache_data = const gchar *mimecache_data =
"[MIME Cache]\n" "[MIME Cache]\n"
@ -562,6 +563,19 @@ test_mime_default_last_used (void)
g_object_unref (appinfo5); g_object_unref (appinfo5);
} }
static void
test_scheme_handler (void)
{
GAppInfo *info, *info5;
info5 = (GAppInfo*)g_desktop_app_info_new ("myapp5.desktop");
info = g_app_info_get_default_for_uri_scheme ("ftp");
g_assert (g_app_info_equal (info, info5));
g_object_unref (info);
g_object_unref (info5);
}
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
@ -573,7 +587,8 @@ main (int argc, char *argv[])
g_test_add_func ("/appinfo/mime/api", test_mime_api); g_test_add_func ("/appinfo/mime/api", test_mime_api);
g_test_add_func ("/appinfo/mime/default", test_mime_default); g_test_add_func ("/appinfo/mime/default", test_mime_default);
g_test_add_func ("/appinfo/mime/file", test_mime_file); g_test_add_func ("/appinfo/mime/file", test_mime_file);
g_test_add_func ("/appinfo/mime/default_last_used", test_mime_default_last_used); g_test_add_func ("/appinfo/mime/scheme-handler", test_scheme_handler);
g_test_add_func ("/appinfo/mime/default-last-used", test_mime_default_last_used);
return g_test_run (); return g_test_run ();
} }