[gtk+] testsuite: Add more icontheme tests



commit 5f794773aa61ce16d8d4ccae91cf2219081f99c8
Author: Benjamin Otte <otte redhat com>
Date:   Tue May 13 03:17:15 2014 +0200

    testsuite: Add more icontheme tests
    
    Check that the lookup order works properly when forcing either symbolic
    or regular icons.

 testsuite/gtk/Makefile.am                          |    4 +
 testsuite/gtk/icons/index.theme                    |    8 +-
 .../gtk/icons/scalable/everything-justregular.svg  |   11 ++
 .../scalable/everything-justsymbolic-symbolic.svg  |   11 ++
 .../gtk/icons/scalable/everything-symbolic.svg     |    5 +
 testsuite/gtk/icons/scalable/everything.svg        |    5 +
 testsuite/gtk/icontheme.c                          |  132 +++++++++++++++++++-
 7 files changed, 174 insertions(+), 2 deletions(-)
---
diff --git a/testsuite/gtk/Makefile.am b/testsuite/gtk/Makefile.am
index 9774a15..927241c 100644
--- a/testsuite/gtk/Makefile.am
+++ b/testsuite/gtk/Makefile.am
@@ -128,6 +128,10 @@ keyhash_SOURCES    =                                       \
 test_icontheme =                                       \
        icons/16x16/simple.png                          \
        icons/index.theme                               \
+       icons/scalable/everything-justregular.svg       \
+       icons/scalable/everything-justsymbolic-symbolic.svg     \
+       icons/scalable/everything.svg                   \
+       icons/scalable/everything-symbolic.svg          \
        $(NULL)
 
 EXTRA_DIST +=                          \
diff --git a/testsuite/gtk/icons/index.theme b/testsuite/gtk/icons/index.theme
index 79ecb17..28e544a 100644
--- a/testsuite/gtk/icons/index.theme
+++ b/testsuite/gtk/icons/index.theme
@@ -3,10 +3,16 @@ Name=Icons
 Comment=Testing of the Icon theme code
 Example=16x16/simple.png
 
-Directories=16x16
+Directories=16x16,scalable
 
 [16x16]
 Context=16x16 icons
 Size=16
 Type=Fixed
 
+[scalable]
+Context=scalable icons
+Type=Scalable
+Size=128
+Min-Size=1
+Max-Size=256
diff --git a/testsuite/gtk/icons/scalable/everything-justregular.svg 
b/testsuite/gtk/icons/scalable/everything-justregular.svg
new file mode 100644
index 0000000..dfbda60
--- /dev/null
+++ b/testsuite/gtk/icons/scalable/everything-justregular.svg
@@ -0,0 +1,11 @@
+<?xml version="1.0" standalone="no"?>
+<svg width="128" height="128" version="1.1" xmlns="http://www.w3.org/2000/svg";>
+  <rect x="0" y="0" width="32" height="32" fill="black"/>
+  <rect x="32" y="32" width="32" height="32" fill="black"/>
+  <rect x="64" y="0" width="32" height="32" fill="black"/>
+  <rect x="96" y="32" width="32" height="32" fill="black"/>
+  <rect x="0" y="64" width="32" height="32" fill="black"/>
+  <rect x="32" y="96" width="32" height="32" fill="black"/>
+  <rect x="64" y="64" width="32" height="32" fill="black"/>
+  <rect x="96" y="96" width="32" height="32" fill="black"/>
+</svg>
diff --git a/testsuite/gtk/icons/scalable/everything-justsymbolic-symbolic.svg 
b/testsuite/gtk/icons/scalable/everything-justsymbolic-symbolic.svg
new file mode 100644
index 0000000..dfbda60
--- /dev/null
+++ b/testsuite/gtk/icons/scalable/everything-justsymbolic-symbolic.svg
@@ -0,0 +1,11 @@
+<?xml version="1.0" standalone="no"?>
+<svg width="128" height="128" version="1.1" xmlns="http://www.w3.org/2000/svg";>
+  <rect x="0" y="0" width="32" height="32" fill="black"/>
+  <rect x="32" y="32" width="32" height="32" fill="black"/>
+  <rect x="64" y="0" width="32" height="32" fill="black"/>
+  <rect x="96" y="32" width="32" height="32" fill="black"/>
+  <rect x="0" y="64" width="32" height="32" fill="black"/>
+  <rect x="32" y="96" width="32" height="32" fill="black"/>
+  <rect x="64" y="64" width="32" height="32" fill="black"/>
+  <rect x="96" y="96" width="32" height="32" fill="black"/>
+</svg>
diff --git a/testsuite/gtk/icons/scalable/everything-symbolic.svg 
b/testsuite/gtk/icons/scalable/everything-symbolic.svg
new file mode 100644
index 0000000..eefa1e5
--- /dev/null
+++ b/testsuite/gtk/icons/scalable/everything-symbolic.svg
@@ -0,0 +1,5 @@
+<?xml version="1.0" standalone="no"?>
+<svg width="128" height="128" version="1.1" xmlns="http://www.w3.org/2000/svg";>
+  <rect x="0" y="0" width="64" height="64" fill="black"/>
+  <rect x="64" y="64" width="64" height="64" fill="black"/>
+</svg>
diff --git a/testsuite/gtk/icons/scalable/everything.svg b/testsuite/gtk/icons/scalable/everything.svg
new file mode 100644
index 0000000..eefa1e5
--- /dev/null
+++ b/testsuite/gtk/icons/scalable/everything.svg
@@ -0,0 +1,5 @@
+<?xml version="1.0" standalone="no"?>
+<svg width="128" height="128" version="1.1" xmlns="http://www.w3.org/2000/svg";>
+  <rect x="0" y="0" width="64" height="64" fill="black"/>
+  <rect x="64" y="64" width="64" height="64" fill="black"/>
+</svg>
diff --git a/testsuite/gtk/icontheme.c b/testsuite/gtk/icontheme.c
index 2f84616..ff69715 100644
--- a/testsuite/gtk/icontheme.c
+++ b/testsuite/gtk/icontheme.c
@@ -2,6 +2,8 @@
 
 #include <string.h>
 
+#define SCALABLE_IMAGE_SIZE (128)
+
 static GtkIconTheme *
 get_test_icontheme (void)
 {
@@ -62,7 +64,7 @@ assert_icon_lookup (const char         *icon_name,
     {
       g_error ("Icon for \"%s\" with flags %s at size %d should be \"...%s\" but is \"...%s\"",
                icon_name, lookup_flags_to_string (flags), size,
-               filename, gtk_icon_info_get_filename (info) + strlen (gtk_icon_info_get_filename (info)) - 
strlen (filename));
+               filename, gtk_icon_info_get_filename (info) + strlen (g_get_current_dir ()));
       return;
     }
 
@@ -70,17 +72,145 @@ assert_icon_lookup (const char         *icon_name,
 }
 
 static void
+assert_icon_lookup_fails (const char         *icon_name,
+                          gint                size,
+                          GtkIconLookupFlags  flags)
+{
+  static gboolean seen_could_not_find_message = FALSE;
+  GtkIconInfo *info;
+
+  if (!seen_could_not_find_message)
+    g_test_expect_message ("Gtk", G_LOG_LEVEL_WARNING, "Could not find the icon*");
+  info = gtk_icon_theme_lookup_icon (get_test_icontheme (), icon_name, size, flags);
+  if (!seen_could_not_find_message)
+    {
+      g_test_assert_expected_messages ();
+      seen_could_not_find_message = TRUE;
+    }
+  if (info != NULL)
+    {
+      g_error ("Should not find an icon for \"%s\" with flags %s at size %d, but found \"%s\"",
+               icon_name, lookup_flags_to_string (flags), size, gtk_icon_info_get_filename (info) + strlen 
(g_get_current_dir ()));
+      g_object_unref (info);
+      return;
+    }
+}
+
+
+static void
 test_basics (void)
 {
   assert_icon_lookup ("simple", 16, 0, "/icons/16x16/simple.png");
 }
 
+static void
+test_force_symbolic (void)
+{
+  /* check forcing symbolic works */
+  assert_icon_lookup ("everything",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
+                      "/icons/scalable/everything-symbolic.svg");
+  /* check forcing symbolic also works for symbolic icons (d'oh) */
+  assert_icon_lookup ("everything-symbolic",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
+                      "/icons/scalable/everything-symbolic.svg");
+
+  /* check all the combos for fallbacks on an icon that only exists as symbolic */
+  assert_icon_lookup ("everything-justsymbolic",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
+                      "/icons/scalable/everything-justsymbolic-symbolic.svg");
+  assert_icon_lookup ("everything-justsymbolic",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
+                      "/icons/scalable/everything-justsymbolic-symbolic.svg");
+  assert_icon_lookup ("everything-justsymbolic-symbolic",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
+                      "/icons/scalable/everything-justsymbolic-symbolic.svg");
+  assert_icon_lookup ("everything-justsymbolic-symbolic",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
+                      "/icons/scalable/everything-justsymbolic-symbolic.svg");
+
+  /* check all the combos for fallbacks, this time for an icon that only exists as regular */
+  assert_icon_lookup ("everything-justregular",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
+                      "/icons/scalable/everything-justregular.svg");
+  assert_icon_lookup ("everything-justregular",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
+                      "/icons/scalable/everything-symbolic.svg");
+  assert_icon_lookup_fails ("everything-justregular-symbolic",
+                            SCALABLE_IMAGE_SIZE,
+                            GTK_ICON_LOOKUP_FORCE_SYMBOLIC);
+  assert_icon_lookup ("everything-justregular-symbolic",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_SYMBOLIC,
+                      "/icons/scalable/everything-symbolic.svg");
+}
+
+static void
+test_force_regular (void)
+{
+  /* check forcing regular works (d'oh) */
+  assert_icon_lookup ("everything",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_FORCE_REGULAR,
+                      "/icons/scalable/everything.svg");
+  /* check forcing regular also works for symbolic icons ) */
+  assert_icon_lookup ("everything-symbolic",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_FORCE_REGULAR,
+                      "/icons/scalable/everything.svg");
+
+  /* check all the combos for fallbacks on an icon that only exists as regular */
+  assert_icon_lookup ("everything-justregular",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_FORCE_REGULAR,
+                      "/icons/scalable/everything-justregular.svg");
+  assert_icon_lookup ("everything-justregular",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_REGULAR,
+                      "/icons/scalable/everything-justregular.svg");
+  assert_icon_lookup ("everything-justregular-symbolic",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_FORCE_REGULAR,
+                      "/icons/scalable/everything-justregular.svg");
+  assert_icon_lookup ("everything-justregular-symbolic",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_REGULAR,
+                      "/icons/scalable/everything-justregular.svg");
+
+  /* check all the combos for fallbacks, this time for an icon that only exists as symbolic */
+  assert_icon_lookup_fails ("everything-justsymbolic",
+                            SCALABLE_IMAGE_SIZE,
+                            GTK_ICON_LOOKUP_FORCE_REGULAR);
+  assert_icon_lookup ("everything-justsymbolic",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_REGULAR,
+                      "/icons/scalable/everything.svg");
+  assert_icon_lookup ("everything-justsymbolic-symbolic",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_FORCE_REGULAR,
+                      "/icons/scalable/everything-justsymbolic-symbolic.svg");
+  assert_icon_lookup ("everything-justsymbolic-symbolic",
+                      SCALABLE_IMAGE_SIZE,
+                      GTK_ICON_LOOKUP_GENERIC_FALLBACK | GTK_ICON_LOOKUP_FORCE_REGULAR,
+                      "/icons/scalable/everything.svg");
+}
+
 int
 main (int argc, char *argv[])
 {
   gtk_test_init (&argc, &argv);
 
   g_test_add_func ("/icontheme/basics", test_basics);
+  g_test_add_func ("/icontheme/force-symbolic", test_force_symbolic);
+  g_test_add_func ("/icontheme/force-regular", test_force_regular);
 
   return g_test_run();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]