Add some more appinfo tests
authorMatthias Clasen <mclasen@redhat.com>
Sat, 3 Jul 2010 16:49:46 +0000 (12:49 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 5 Jul 2010 00:51:06 +0000 (20:51 -0400)
gio/tests/appinfo-test-gnome.desktop [new file with mode: 0644]
gio/tests/appinfo-test-notgnome.desktop [new file with mode: 0644]
gio/tests/appinfo-test.desktop
gio/tests/appinfo.c

diff --git a/gio/tests/appinfo-test-gnome.desktop b/gio/tests/appinfo-test-gnome.desktop
new file mode 100644 (file)
index 0000000..9e3b428
--- /dev/null
@@ -0,0 +1,6 @@
+[Desktop Entry]
+Type=Application
+Name=appinfo-test
+Exec=./appinfo-test --option
+OnlyShowIn=GNOME;KDE;
+NotShowIn=ROX;
diff --git a/gio/tests/appinfo-test-notgnome.desktop b/gio/tests/appinfo-test-notgnome.desktop
new file mode 100644 (file)
index 0000000..2f7c11d
--- /dev/null
@@ -0,0 +1,6 @@
+[Desktop Entry]
+Type=Application
+Name=appinfo-test
+Exec=./appinfo-test --option
+OnlyShowIn=KDE;
+NotShowIn=GNOME;
index becc1c4..0a64cfb 100644 (file)
@@ -1,4 +1,10 @@
 [Desktop Entry]
 Type=Application
 Name=appinfo-test
-Exec=./appinfo-test
+Name[de]=appinfo-test-de
+X-GNOME-FullName=example
+X-GNOME-FullName[de]=Beispiel
+Comment=GAppInfo example
+Comment[de]=GAppInfo Beispiel
+Exec=./appinfo-test --option
+Icon=testicon
index 099068a..3c89eba 100644 (file)
@@ -1,3 +1,6 @@
+
+#include <locale.h>
+
 #include <gio/gio.h>
 #include <gio/gdesktopappinfo.h>
 
@@ -12,13 +15,139 @@ test_launch (void)
   g_assert (g_app_info_launch (appinfo, NULL, NULL, NULL));
 }
 
+static void
+test_locale (const char *locale)
+{
+  GAppInfo *appinfo;
+  const gchar *orig;
+
+  orig = setlocale (LC_ALL, NULL);
+  g_setenv ("LANGUAGE", locale, TRUE);
+  setlocale (LC_ALL, "");
+
+  appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test.desktop");
+
+  if (g_strcmp0 (locale, "C") == 0)
+    {
+      g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "appinfo-test");
+      g_assert_cmpstr (g_app_info_get_description (appinfo), ==, "GAppInfo example");
+      g_assert_cmpstr (g_app_info_get_display_name (appinfo), ==, "example");
+    }
+  else if (g_str_has_prefix (locale, "en"))
+    {
+      g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "appinfo-test");
+      g_assert_cmpstr (g_app_info_get_description (appinfo), ==, "GAppInfo example");
+      g_assert_cmpstr (g_app_info_get_display_name (appinfo), ==, "example");
+    }
+  else if (g_str_has_prefix (locale, "de"))
+    {
+      g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "appinfo-test-de");
+      g_assert_cmpstr (g_app_info_get_description (appinfo), ==, "GAppInfo Beispiel");
+      g_assert_cmpstr (g_app_info_get_display_name (appinfo), ==, "Beispiel");
+    }
+
+  g_object_unref (appinfo);
+
+  g_setenv ("LANGUAGE", orig, TRUE);
+  setlocale (LC_ALL, "");
+}
+
+static void
+test_text (void)
+{
+  test_locale ("C");
+  test_locale ("en_US");
+  test_locale ("de");
+  test_locale ("de_DE.UTF-8");
+}
+
+static void
+test_basic (void)
+{
+  GAppInfo *appinfo;
+  GIcon *icon, *icon2;
+
+  appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test.desktop");
+
+  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_commandline (appinfo), ==, "./appinfo-test --option");
+
+  icon = g_app_info_get_icon (appinfo);
+  g_assert (G_IS_THEMED_ICON (icon));
+  icon2 = g_themed_icon_new ("testicon");
+  g_assert (g_icon_equal (icon, icon2));
+  g_object_unref (icon2);
+
+  g_object_unref (appinfo);
+}
+
+static void
+test_show_in (void)
+{
+  GAppInfo *appinfo;
+
+  g_desktop_app_info_set_desktop_env ("GNOME");
+
+  appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test.desktop");
+  g_assert (g_app_info_should_show (appinfo));
+  g_object_unref (appinfo);
+
+  appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test-gnome.desktop");
+  g_assert (g_app_info_should_show (appinfo));
+  g_object_unref (appinfo);
+
+  appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (SRCDIR "/appinfo-test-notgnome.desktop");
+  g_assert (!g_app_info_should_show (appinfo));
+  g_object_unref (appinfo);
+}
+
+static void
+test_commandline (void)
+{
+  GAppInfo *appinfo;
+  GError *error;
+
+  error = NULL;
+  appinfo = g_app_info_create_from_commandline ("./appinfo-test --option",
+                                                "cmdline-app-test",
+                                                G_APP_INFO_CREATE_SUPPORTS_URIS,
+                                                &error);
+  g_assert (appinfo != NULL);
+  g_assert_no_error (error);
+  g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "cmdline-app-test");
+  g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, "./appinfo-test --option %u");
+  g_assert (g_app_info_supports_uris (appinfo));
+  g_assert (!g_app_info_supports_files (appinfo));
+
+  g_object_unref (appinfo);
+
+  error = NULL;
+  appinfo = g_app_info_create_from_commandline ("./appinfo-test --option",
+                                                "cmdline-app-test",
+                                                G_APP_INFO_CREATE_NONE,
+                                                &error);
+  g_assert (appinfo != NULL);
+  g_assert_no_error (error);
+  g_assert_cmpstr (g_app_info_get_name (appinfo), ==, "cmdline-app-test");
+  g_assert_cmpstr (g_app_info_get_commandline (appinfo), ==, "./appinfo-test --option %f");
+  g_assert (!g_app_info_supports_uris (appinfo));
+  g_assert (g_app_info_supports_files (appinfo));
+
+  g_object_unref (appinfo);
+}
+
 int
 main (int argc, char *argv[])
 {
   g_type_init ();
   g_test_init (&argc, &argv, NULL);
 
+  g_test_add_func ("/appinfo/basic", test_basic);
+  g_test_add_func ("/appinfo/text", test_text);
   g_test_add_func ("/appinfo/launch", test_launch);
+  g_test_add_func ("/appinfo/show-in", test_show_in);
+  g_test_add_func ("/appinfo/commandline", test_commandline);
 
   return g_test_run ();
 }