[gtk+/wip/css-icons] testsuite: Add a basic icontheme test



commit 3531dac152b64bda471022114f65c55835f806fe
Author: Benjamin Otte <otte redhat com>
Date:   Mon May 12 18:19:47 2014 +0200

    testsuite: Add a basic icontheme test
    
    Most of the work here is creating the infrastructure to have a custom
    icon theme to add icons to and run tests against.

 testsuite/gtk/Makefile.am            |    7 +++
 testsuite/gtk/icons/16x16/simple.png |  Bin 0 -> 174 bytes
 testsuite/gtk/icons/index.theme      |   12 +++++
 testsuite/gtk/icontheme.c            |   86 ++++++++++++++++++++++++++++++++++
 4 files changed, 105 insertions(+), 0 deletions(-)
---
diff --git a/testsuite/gtk/Makefile.am b/testsuite/gtk/Makefile.am
index d5a1bcb..9774a15 100644
--- a/testsuite/gtk/Makefile.am
+++ b/testsuite/gtk/Makefile.am
@@ -40,6 +40,7 @@ TEST_PROGS +=                         \
        floating                \
        grid                    \
        gtkmenu                 \
+       icontheme               \
        keyhash                 \
        listbox                 \
        no-gtk-init             \
@@ -124,10 +125,15 @@ keyhash_SOURCES   =                                       \
        $(NULL)
 
 
+test_icontheme =                                       \
+       icons/16x16/simple.png                          \
+       icons/index.theme                               \
+       $(NULL)
 
 EXTRA_DIST +=                          \
        file-chooser-test-dir/empty     \
        file-chooser-test-dir/text.txt  \
+       $(test_icontheme)               \
        $(NULL)
 
 GTK_GSETTINGS_SCHEMAS = \
@@ -149,6 +155,7 @@ all-am: gschemas.compiled
 if BUILDOPT_INSTALL_TESTS
 insttestdir = $(pkglibexecdir)/installed-tests
 insttest_PROGRAMS = $(TEST_PROGS)
+insttest_DATA = $(test_icontheme)
 
 %.test: %$(EXEEXT) Makefile
        $(AM_V_GEN) (echo '[Test]' > $  tmp; \
diff --git a/testsuite/gtk/icons/16x16/simple.png b/testsuite/gtk/icons/16x16/simple.png
new file mode 100644
index 0000000..91824f9
Binary files /dev/null and b/testsuite/gtk/icons/16x16/simple.png differ
diff --git a/testsuite/gtk/icons/index.theme b/testsuite/gtk/icons/index.theme
new file mode 100644
index 0000000..79ecb17
--- /dev/null
+++ b/testsuite/gtk/icons/index.theme
@@ -0,0 +1,12 @@
+[Icon Theme]
+Name=Icons
+Comment=Testing of the Icon theme code
+Example=16x16/simple.png
+
+Directories=16x16
+
+[16x16]
+Context=16x16 icons
+Size=16
+Type=Fixed
+
diff --git a/testsuite/gtk/icontheme.c b/testsuite/gtk/icontheme.c
new file mode 100644
index 0000000..2f84616
--- /dev/null
+++ b/testsuite/gtk/icontheme.c
@@ -0,0 +1,86 @@
+#include <gtk/gtk.h>
+
+#include <string.h>
+
+static GtkIconTheme *
+get_test_icontheme (void)
+{
+  static GtkIconTheme *icon_theme = NULL;
+  const char *current_dir;
+
+  if (icon_theme)
+    return icon_theme;
+
+  icon_theme = gtk_icon_theme_new ();
+  gtk_icon_theme_set_custom_theme (icon_theme, "icons");
+  current_dir = g_get_current_dir ();
+  gtk_icon_theme_set_search_path (icon_theme, &current_dir, 1);
+
+  return icon_theme;
+}
+
+static char *
+lookup_flags_to_string (GtkIconLookupFlags flags)
+{
+  GValue flags_value = { 0, }, string_value = { 0, };
+  char *result;
+
+  g_value_init (&flags_value, GTK_TYPE_ICON_LOOKUP_FLAGS);
+  g_value_init (&string_value, G_TYPE_STRING);
+
+  g_value_set_flags (&flags_value, flags);
+  if (!g_value_transform (&flags_value, &string_value))
+    {
+      g_assert_not_reached ();
+    }
+
+  result = g_value_dup_string (&string_value);
+
+  g_value_unset (&flags_value);
+  g_value_unset (&string_value);
+
+  return result;
+}
+
+static void
+assert_icon_lookup (const char         *icon_name,
+                    gint                size,
+                    GtkIconLookupFlags  flags,
+                    const char         *filename)
+{
+  GtkIconInfo *info;
+
+  info = gtk_icon_theme_lookup_icon (get_test_icontheme (), icon_name, size, flags);
+  if (info == NULL)
+    {
+      g_error ("Could not look up an icon for \"%s\" with flags %s at size %d",
+               icon_name, lookup_flags_to_string (flags), size);
+      return;
+    }
+
+  if (!g_str_has_suffix (gtk_icon_info_get_filename (info), filename))
+    {
+      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));
+      return;
+    }
+
+  g_object_unref (info);
+}
+
+static void
+test_basics (void)
+{
+  assert_icon_lookup ("simple", 16, 0, "/icons/16x16/simple.png");
+}
+
+int
+main (int argc, char *argv[])
+{
+  gtk_test_init (&argc, &argv);
+
+  g_test_add_func ("/icontheme/basics", test_basics);
+
+  return g_test_run();
+}


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