[gtk/debug-envvars-cleanup] tests: Rewrite the icontheme tests



commit 805736cf34cafcd0b2a4155503b3ece2ac1d861b
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Sep 23 13:12:41 2022 -0400

    tests: Rewrite the icontheme tests
    
    The lookup order tests were relying on out
    debug spew using g_log, so they can redirect
    the output by setting a log writer function.
    
    Rewrite this to use g_test_subprocess() and
    parse stderr.

 testsuite/gtk/icontheme.c | 372 +++++++++++++++++++++-------------------------
 1 file changed, 172 insertions(+), 200 deletions(-)
---
diff --git a/testsuite/gtk/icontheme.c b/testsuite/gtk/icontheme.c
index fb5bf189f4..0a546ce79a 100644
--- a/testsuite/gtk/icontheme.c
+++ b/testsuite/gtk/icontheme.c
@@ -135,59 +135,22 @@ assert_icon_lookup_fails (const char         *icon_name,
   g_assert_cmpstr (gtk_icon_paintable_get_icon_name (info), ==, "image-missing");
 }
 
-static GList *lookups = NULL;
-static gboolean collecting_lookups = FALSE;
-
-static GLogWriterOutput
-log_writer (GLogLevelFlags   log_level,
-            const GLogField *fields,
-            gsize            n_fields,
-            gpointer         user_data)
-{
-  const char *domain = NULL;
-  const char *msg = NULL;
-  int i;
-
-  if (!collecting_lookups)
-    return g_log_writer_default (log_level, fields, n_fields, user_data);
-
-  for (i = 0; i < n_fields; i++)
-    {
-      if (strcmp (fields[i].key, "GLIB_DOMAIN") == 0)
-        domain = fields[i].value;
-      if (strcmp (fields[i].key, "MESSAGE") == 0)
-        msg = fields[i].value;
-    }
-
-  if (log_level != G_LOG_LEVEL_MESSAGE || g_strcmp0 (domain, "Gtk") != 0)
-    return g_log_writer_default (log_level, fields, n_fields, user_data);
-
-  if (g_str_has_prefix (msg, "\tlookup name: "))
-    {
-      char *s;
-      s = g_strchomp (g_strdup (msg + strlen ("\tlookup name: ")));
-      lookups = g_list_append (lookups, s);
-    }
-
-  return G_LOG_WRITER_HANDLED;
-}
+#ifdef G_ENABLE_DEBUG
+#define require_debug()
+#else
+#define require_debug() \
+  g_test_skip ("requires G_ENABLE_DEBUG"); \
+  return;
+#endif
 
 static void
-assert_lookup_order (const char         *icon_name,
-                     int                 size,
-                     GtkTextDirection    direction,
-                     GtkIconLookupFlags  flags,
-                     gboolean            fallbacks,
-                     const char         *first,
-                     ...)
+do_icon_lookup (const char         *icon_name,
+                int                 size,
+                GtkTextDirection    direction,
+                GtkIconLookupFlags  flags,
+                gboolean            fallbacks)
 {
-  va_list args;
-  const char *s;
-  GtkIconPaintable *info;
-  GList *l;
-
-  g_assert_null (lookups);
-  collecting_lookups = TRUE;
+  GtkIconPaintable *info = NULL;
 
   if (fallbacks)
     {
@@ -203,165 +166,164 @@ assert_lookup_order (const char         *icon_name,
 
   if (info)
     g_object_unref (info);
+}
 
-  collecting_lookups = FALSE;
+static char *
+make_lookup_pattern (const char *first_name,
+                     ...)
+{
+  GString *s;
+  va_list args;
+  char *name;
 
-  va_start (args, first);
-  s = first;
-  l = lookups;
-  while (s != NULL)
-    {
-      g_assert_nonnull (l);
-      g_assert_cmpstr (s, ==, l->data);
-      s = va_arg (args, char *);
-      l = l->next;
-    }
-  g_assert_null (l);
-  va_end (args);
+  s = g_string_new ("");
+  g_string_append_printf (s, "*lookup name: %s", first_name);
 
-  g_list_free_full (lookups, g_free);
-  lookups = NULL;
-}
+  va_start (args, first_name);
 
-#ifdef G_ENABLE_DEBUG
-#define require_debug()
-#else
-#define require_debug() \
-  g_test_skip ("requires G_ENABLE_DEBUG"); \
-  return;
-#endif
+  while ((name = va_arg (args, char *)) != NULL)
+    g_string_append_printf (s, "*lookup name: %s", name);
 
-static void
-test_lookup_order (void)
-{
-  require_debug ();
+  va_end (args);
 
-  if (g_test_subprocess ())
-    {
-      guint debug_flags;
-
-      debug_flags = gtk_get_debug_flags ();
-      gtk_set_debug_flags (debug_flags | GTK_DEBUG_ICONTHEME);
-
-      g_log_set_writer_func (log_writer, NULL, NULL);
-
-      assert_lookup_order ("foo-bar-baz", 16, GTK_TEXT_DIR_NONE, 0, TRUE,
-                           "foo-bar-baz",
-                           "foo-bar",
-                           "foo",
-                           "foo-bar-baz-symbolic",
-                           "foo-bar-symbolic",
-                           "foo-symbolic",
-                           NULL);
-      assert_lookup_order ("foo-bar-baz", 16, GTK_TEXT_DIR_RTL, 0, TRUE,
-                           "foo-bar-baz-rtl",
-                           "foo-bar-baz",
-                           "foo-bar-rtl",
-                           "foo-bar",
-                           "foo-rtl",
-                           "foo",
-                           "foo-bar-baz-symbolic-rtl",
-                           "foo-bar-baz-symbolic",
-                           "foo-bar-symbolic-rtl",
-                           "foo-bar-symbolic",
-                           "foo-symbolic-rtl",
-                           "foo-symbolic",
-                           NULL);
-      assert_lookup_order ("foo-bar-baz", 16, GTK_TEXT_DIR_RTL, 0, FALSE,
-                           "foo-bar-baz-rtl",
-                           "foo-bar-baz",
-                           NULL);
-      assert_lookup_order ("foo-bar-baz-symbolic", 16, GTK_TEXT_DIR_NONE, 0, TRUE,
-                           "foo-bar-baz-symbolic",
-                           "foo-bar-symbolic",
-                           "foo-symbolic",
-                           "foo-bar-baz",
-                           "foo-bar",
-                           "foo",
-                           NULL);
-
-      assert_lookup_order ("bla-bla", 16, GTK_TEXT_DIR_NONE, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
-                           "bla-bla-symbolic",
-                           "bla-symbolic",
-                           "bla-bla-symbolic", /* awkward */
-                           "bla-symbolic", /* awkward */
-                           "bla-bla",
-                           "bla",
-                           NULL);
-      assert_lookup_order ("bla-bla-symbolic", 16, GTK_TEXT_DIR_NONE, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
-                           "bla-bla-symbolic",
-                           "bla-symbolic",
-                           "bla-bla-symbolic", /* awkward */
-                           "bla-symbolic", /* awkward */
-                           "bla-bla",
-                           "bla",
-                           NULL);
-
-      assert_lookup_order ("bar-baz", 16, GTK_TEXT_DIR_RTL, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
-                           "bar-baz-symbolic-rtl",
-                           "bar-baz-symbolic",
-                           "bar-symbolic-rtl",
-                           "bar-symbolic",
-                           "bar-baz-symbolic-rtl", /* awkward */
-                           "bar-baz-symbolic", /* awkward */
-                           "bar-symbolic-rtl", /* awkward */
-                           "bar-symbolic", /* awkward */
-                           "bar-baz-rtl",
-                           "bar-baz",
-                           "bar-rtl",
-                           "bar",
-                           NULL);
-      assert_lookup_order ("bar-baz-symbolic", 16, GTK_TEXT_DIR_RTL, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
-                           "bar-baz-symbolic-rtl",
-                           "bar-baz-symbolic",
-                           "bar-symbolic-rtl",
-                           "bar-symbolic",
-                           "bar-baz-symbolic-rtl", /* awkward */
-                           "bar-baz-symbolic", /* awkward */
-                           "bar-symbolic-rtl", /* awkward */
-                           "bar-symbolic", /* awkward */
-                           "bar-baz-rtl",
-                           "bar-baz",
-                           "bar-rtl",
-                           "bar",
-                           NULL);
-
-      assert_lookup_order ("bar-baz", 16, GTK_TEXT_DIR_LTR, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
-                           "bar-baz-symbolic-ltr",
-                           "bar-baz-symbolic",
-                           "bar-symbolic-ltr",
-                           "bar-symbolic",
-                           "bar-baz-symbolic-ltr", /* awkward */
-                           "bar-baz-symbolic", /* awkward */
-                           "bar-symbolic-ltr", /* awkward */
-                           "bar-symbolic", /* awkward */
-                           "bar-baz-ltr",
-                           "bar-baz",
-                           "bar-ltr",
-                           "bar",
-                           NULL);
-      assert_lookup_order ("bar-baz-symbolic", 16, GTK_TEXT_DIR_LTR, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
-                           "bar-baz-symbolic-ltr",
-                           "bar-baz-symbolic",
-                           "bar-symbolic-ltr",
-                           "bar-symbolic",
-                           "bar-baz-symbolic-ltr", /* awkward */
-                           "bar-baz-symbolic", /* awkward */
-                           "bar-symbolic-ltr", /* awkward */
-                           "bar-symbolic", /* awkward */
-                           "bar-baz-ltr",
-                           "bar-baz",
-                           "bar-ltr",
-                           "bar",
-                           NULL);
+  g_string_append (s, "*");
 
-      return;
-    }
+  return g_string_free (s, FALSE);
+}
 
-  g_test_trap_subprocess (NULL, 0, 0);
-  g_test_trap_assert_passed ();
+#define CONCAT_EXPANDED(a,b) CONCAT_EXPANDED2(a,b)
+#define CONCAT_EXPANDED2(a,b) a##b
+
+#define LOOKUP_ORDER_TEST(icon_name,size,direction,flags,fallback,...)           \
+  
LOOKUP_ORDER_TEST1(CONCAT_EXPANDED(test_lookup_order,__COUNTER__),icon_name,size,direction,flags,fallback,__VA_ARGS__)
+
+#define LOOKUP_ORDER_TEST1(func,icon_name,size,direction,flags,fallback,...)           \
+static void                                                                       \
+func (void)                                           \
+{                                                                                 \
+  char *pattern;                                                                  \
+  require_debug ();                                                               \
+  if (g_test_subprocess ())                                                       \
+    {                                                                             \
+      guint debug_flags = gtk_get_debug_flags ();                                 \
+      gtk_set_debug_flags (debug_flags | GTK_DEBUG_ICONTHEME);                    \
+      do_icon_lookup (icon_name, size, direction, flags, fallback);               \
+      return;                                                                     \
+    }                                                                             \
+  g_test_trap_subprocess (NULL, 0, 0);                                            \
+  g_test_trap_assert_passed ();                                                   \
+  pattern = make_lookup_pattern (__VA_ARGS__, NULL);                              \
+  g_test_trap_assert_stderr (pattern);                                            \
+  g_free (pattern);                                                               \
 }
 
+
+LOOKUP_ORDER_TEST ("foo-bar-baz", 16, GTK_TEXT_DIR_NONE, 0, TRUE,
+                   "foo-bar-baz",
+                   "foo-bar",
+                   "foo",
+                   "foo-bar-baz-symbolic",
+                   "foo-bar-symbolic",
+                   "foo-symbolic")
+
+LOOKUP_ORDER_TEST ("foo-bar-baz", 16, GTK_TEXT_DIR_RTL, 0, TRUE,
+                   "foo-bar-baz-rtl",
+                   "foo-bar-baz",
+                   "foo-bar-rtl",
+                   "foo-bar",
+                   "foo-rtl",
+                   "foo",
+                   "foo-bar-baz-symbolic-rtl",
+                   "foo-bar-baz-symbolic",
+                   "foo-bar-symbolic-rtl",
+                   "foo-bar-symbolic",
+                   "foo-symbolic-rtl",
+                   "foo-symbolic")
+
+LOOKUP_ORDER_TEST ("foo-bar-baz", 16, GTK_TEXT_DIR_RTL, 0, FALSE,
+                   "foo-bar-baz-rtl",
+                   "foo-bar-baz")
+
+LOOKUP_ORDER_TEST ("foo-bar-baz-symbolic", 16, GTK_TEXT_DIR_NONE, 0, TRUE,
+                   "foo-bar-baz-symbolic",
+                   "foo-bar-symbolic",
+                   "foo-symbolic",
+                   "foo-bar-baz",
+                   "foo-bar",
+                   "foo")
+
+LOOKUP_ORDER_TEST ("bla-bla", 16, GTK_TEXT_DIR_NONE, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
+                   "bla-bla-symbolic",
+                   "bla-symbolic",
+                   "bla-bla-symbolic", /* awkward */
+                   "bla-symbolic", /* awkward */
+                   "bla-bla",
+                   "bla")
+
+LOOKUP_ORDER_TEST ("bla-bla-symbolic", 16, GTK_TEXT_DIR_NONE, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
+                   "bla-bla-symbolic",
+                   "bla-symbolic",
+                   "bla-bla-symbolic", /* awkward */
+                   "bla-symbolic", /* awkward */
+                   "bla-bla",
+                   "bla")
+
+LOOKUP_ORDER_TEST ("bar-baz", 16, GTK_TEXT_DIR_RTL, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
+                   "bar-baz-symbolic-rtl",
+                   "bar-baz-symbolic",
+                   "bar-symbolic-rtl",
+                   "bar-symbolic",
+                   "bar-baz-symbolic-rtl", /* awkward */
+                   "bar-baz-symbolic", /* awkward */
+                   "bar-symbolic-rtl", /* awkward */
+                   "bar-symbolic", /* awkward */
+                   "bar-baz-rtl",
+                   "bar-baz",
+                   "bar-rtl",
+                   "bar")
+
+LOOKUP_ORDER_TEST ("bar-baz-symbolic", 16, GTK_TEXT_DIR_RTL, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
+                   "bar-baz-symbolic-rtl",
+                   "bar-baz-symbolic",
+                   "bar-symbolic-rtl",
+                   "bar-symbolic",
+                   "bar-baz-symbolic-rtl", /* awkward */
+                   "bar-baz-symbolic", /* awkward */
+                   "bar-symbolic-rtl", /* awkward */
+                   "bar-symbolic", /* awkward */
+                   "bar-baz-rtl",
+                   "bar-baz",
+                   "bar-rtl",
+                   "bar")
+
+LOOKUP_ORDER_TEST ("bar-baz", 16, GTK_TEXT_DIR_LTR, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
+                   "bar-baz-symbolic-ltr",
+                   "bar-baz-symbolic",
+                   "bar-symbolic-ltr",
+                   "bar-symbolic",
+                   "bar-baz-symbolic-ltr", /* awkward */
+                   "bar-baz-symbolic", /* awkward */
+                   "bar-symbolic-ltr", /* awkward */
+                   "bar-symbolic", /* awkward */
+                   "bar-baz-ltr",
+                   "bar-baz",
+                   "bar-ltr",
+                   "bar")
+
+LOOKUP_ORDER_TEST ("bar-baz-symbolic", 16, GTK_TEXT_DIR_LTR, GTK_ICON_LOOKUP_FORCE_SYMBOLIC, TRUE,
+                   "bar-baz-symbolic-ltr",
+                   "bar-baz-symbolic",
+                   "bar-symbolic-ltr",
+                   "bar-symbolic",
+                   "bar-baz-symbolic-ltr", /* awkward */
+                   "bar-baz-symbolic", /* awkward */
+                   "bar-symbolic-ltr", /* awkward */
+                   "bar-symbolic", /* awkward */
+                   "bar-baz-ltr",
+                   "bar-baz",
+                   "bar-ltr",
+                   "bar")
+
 static void
 test_basics (void)
 {
@@ -822,7 +784,17 @@ main (int argc, char *argv[])
   g_test_add_func ("/icontheme/list", test_list);
   g_test_add_func ("/icontheme/inherit", test_inherit);
   g_test_add_func ("/icontheme/nonsquare-symbolic", test_nonsquare_symbolic);
-  g_test_add_func ("/icontheme/lookup-order", test_lookup_order);
+  //g_test_add_func ("/icontheme/lookup-order", test_lookup_order);
+  g_test_add_func ("/icontheme/lookup_order1", test_lookup_order1);
+  g_test_add_func ("/icontheme/lookup_order2", test_lookup_order2);
+  g_test_add_func ("/icontheme/lookup_order3", test_lookup_order3);
+  g_test_add_func ("/icontheme/lookup_order4", test_lookup_order4);
+  g_test_add_func ("/icontheme/lookup_order5", test_lookup_order5);
+  g_test_add_func ("/icontheme/lookup_order6", test_lookup_order6);
+  g_test_add_func ("/icontheme/lookup_order7", test_lookup_order7);
+  g_test_add_func ("/icontheme/lookup_order8", test_lookup_order8);
+  g_test_add_func ("/icontheme/lookup_order9", test_lookup_order9);
+  g_test_add_func ("/icontheme/lookup_order10", test_lookup_order10);
 
   return g_test_run();
 }


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