[gdk-pixbuf/wip/otte/tga: 21/24] Add a helper to run tests over directories



commit 98c63e553970e19cfaa42ea72c994a9d480b32cf
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Sep 23 22:55:26 2015 -0400

    Add a helper to run tests over directories
    
    This helper function recursively runs over a directory
    and adds a test function for each file in the tree.

 tests/test-common.c |   26 ++++++++++++++++++++++++++
 tests/test-common.h |    4 ++++
 2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/tests/test-common.c b/tests/test-common.c
index 0f70a8b..01a0c38 100644
--- a/tests/test-common.c
+++ b/tests/test-common.c
@@ -113,3 +113,29 @@ pixdata_equal (GdkPixbuf *p1, GdkPixbuf *p2, GError **error)
 
   return TRUE;
 }
+
+void
+add_test_for_all_images (const gchar   *prefix,
+                         const gchar   *path,
+                         GTestDataFunc  test_func)
+{
+  GDir *dir;
+  const gchar *name;
+
+  dir = g_dir_open (path, 0, NULL);
+  while ((name = g_dir_read_name (dir)) != NULL)
+    {
+      gchar *test_path;
+      gchar *dir_path;
+
+      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);
+      g_free (test_path);
+      g_free (dir_path);
+    }
+  g_dir_close (dir);
+}
diff --git a/tests/test-common.h b/tests/test-common.h
index 0514cd7..5c8e3e7 100644
--- a/tests/test-common.h
+++ b/tests/test-common.h
@@ -30,6 +30,10 @@ G_BEGIN_DECLS
 gboolean format_supported (const gchar *filename);
 gboolean skip_if_insufficient_memory (GError **err);
 gboolean pixdata_equal (GdkPixbuf *p1, GdkPixbuf *p2, GError **error);
+void add_test_for_all_images (const gchar   *prefix,
+                              const gchar   *dir,
+                              GTestDataFunc  test_func);
+
 
 G_END_DECLS
 


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