[gdk-pixbuf] tests: Allow passing a filter function when adding all files



commit 11b59a0db87f666a82b04a4cd455e6d935ece0a4
Author: Benjamin Otte <otte redhat com>
Date:   Tue Oct 6 04:16:12 2015 +0200

    tests: Allow passing a filter function when adding all files
    
    ... and use it to not add reference images.

 tests/pixbuf-randomly-modified.c |    2 +-
 tests/pixbuf-slow-load.c         |    9 +++------
 tests/test-common.c              |   14 +++++++++-----
 tests/test-common.h              |    5 ++++-
 4 files changed, 17 insertions(+), 13 deletions(-)
---
diff --git a/tests/pixbuf-randomly-modified.c b/tests/pixbuf-randomly-modified.c
index 60f8428..f45f53c 100644
--- a/tests/pixbuf-randomly-modified.c
+++ b/tests/pixbuf-randomly-modified.c
@@ -104,7 +104,7 @@ main (int argc, char **argv)
   g_test_init (&argc, &argv, NULL);
 
   test_images_dir = g_build_filename (g_test_get_dir (G_TEST_DIST), "test-images/randomly-modified", NULL);
-  add_test_for_all_images ("/pixbuf/randomly-modified", test_images_dir, test_randomly_modified);
+  add_test_for_all_images ("/pixbuf/randomly-modified", test_images_dir, test_randomly_modified, NULL);
   g_free (test_images_dir);
 
   g_test_message ("Modified image is written to pixbuf-randomly-modified-image");
diff --git a/tests/pixbuf-slow-load.c b/tests/pixbuf-slow-load.c
index 6ccc6ce..9633ef0 100644
--- a/tests/pixbuf-slow-load.c
+++ b/tests/pixbuf-slow-load.c
@@ -78,9 +78,9 @@ make_ref_filename (const char *filename)
 }
 
 static gboolean
-is_ref_filename (const char *filename)
+is_not_ref_image (const char *filename)
 {
-  return g_str_has_suffix (filename, ".ref.png");
+  return !g_str_has_suffix (filename, ".ref.png");
 }
 
 static void
@@ -97,9 +97,6 @@ test_reftest_success (gconstpointer file)
   gboolean success;
 
   filename = file;
-  if (is_ref_filename (filename))
-    return;
-
   ref_filename = make_ref_filename (filename);
   reference = gdk_pixbuf_new_from_file (ref_filename, &error);
   g_assert_no_error (error);
@@ -154,7 +151,7 @@ main (int argc, char **argv)
   g_test_init (&argc, &argv, NULL);
 
   tga_test_images = g_build_filename (g_test_get_dir (G_TEST_DIST), "test-images/tga", NULL);
-  add_test_for_all_images ("/pixbuf/reftest/success", tga_test_images, test_reftest_success);
+  add_test_for_all_images ("/pixbuf/reftest/success", tga_test_images, test_reftest_success, 
is_not_ref_image);
   g_free (tga_test_images);
 
   return g_test_run ();
diff --git a/tests/test-common.c b/tests/test-common.c
index 9498301..fef9d94 100644
--- a/tests/test-common.c
+++ b/tests/test-common.c
@@ -175,7 +175,8 @@ pixdata_equal (GdkPixbuf  *test,
 void
 add_test_for_all_images (const gchar   *prefix,
                          const gchar   *path,
-                         GTestDataFunc  test_func)
+                         GTestDataFunc  test_func,
+                         AddTestFunc    add_test_func)
 {
   GDir *dir;
   const gchar *name;
@@ -188,10 +189,13 @@ add_test_for_all_images (const gchar   *prefix,
 
       test_path = g_strconcat (prefix, "/", name, NULL);
       dir_path = g_strconcat (path, "/", name, NULL);
-      if (g_file_test (dir_path, G_FILE_TEST_IS_DIR))
-        add_test_for_all_images (test_path, dir_path, test_func);
-      else
-        g_test_add_data_func_full (test_path, g_strdup (dir_path), test_func, g_free);
+      if (add_test_func == NULL || add_test_func (dir_path))
+        {
+          if (g_file_test (dir_path, G_FILE_TEST_IS_DIR))
+            add_test_for_all_images (test_path, dir_path, test_func, add_test_func);
+          else
+            g_test_add_data_func_full (test_path, g_strdup (dir_path), test_func, g_free);
+        }
       g_free (test_path);
       g_free (dir_path);
     }
diff --git a/tests/test-common.h b/tests/test-common.h
index 4273f71..6b53242 100644
--- a/tests/test-common.h
+++ b/tests/test-common.h
@@ -27,12 +27,15 @@
 
 G_BEGIN_DECLS
 
+typedef gboolean (* AddTestFunc) (const gchar *filename);
+
 gboolean format_supported (const gchar *filename);
 gboolean skip_if_insufficient_memory (GError **err);
 gboolean pixdata_equal (GdkPixbuf *test, GdkPixbuf *ref, GError **error);
 void add_test_for_all_images (const gchar   *prefix,
                               const gchar   *dir,
-                              GTestDataFunc  test_func);
+                              GTestDataFunc  test_func,
+                              AddTestFunc    add_test_func);
 
 
 G_END_DECLS


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