[gdk-pixbuf/wip/otte/tga] pixbuf-randomly-modified: Use the new helper



commit d1351d9eec556e87d59bdb621c00319e779d330d
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Sep 23 22:56:32 2015 -0400

    pixbuf-randomly-modified: Use the new helper
    
    Use the new helper function. This fixes the problem
    that the test previously had with subdirectories in
    test-images. The helper function will recurse into
    any subdirectory it finds.

 tests/Makefile.am                |    8 +++++++-
 tests/pixbuf-randomly-modified.c |   18 ++++--------------
 2 files changed, 11 insertions(+), 15 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2772f7a..00df505 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -62,9 +62,15 @@ dist_installed_test_data =           \
        cve-2015-4491.bmp               \
        large.png                       \
        large.jpg                       \
-       $(wildcard $(srcdir)/test-images/*) \
+       $(filter-out tga,$(wildcard $(srcdir)/test-images/*)) \
        $(wildcard $(srcdir)/test-images/tga/*)
 
+pixbuf_randomly_modified_SOURCES =     \
+       pixbuf-randomly-modified.c      \
+       test-common.c                   \
+       test-common.h                   \
+       $(NULL)
+
 cve_2015_4491_SOURCES =                        \
        cve-2015-4491.c                 \
        resources.h                     \
diff --git a/tests/pixbuf-randomly-modified.c b/tests/pixbuf-randomly-modified.c
index 5540187..69c90c4 100644
--- a/tests/pixbuf-randomly-modified.c
+++ b/tests/pixbuf-randomly-modified.c
@@ -29,6 +29,8 @@
 #include <sys/resource.h>
 #endif
 
+#include "test-common.h"
+
 static void
 randomly_modify (const gchar *image, guint size)
 {
@@ -64,15 +66,13 @@ static void
 test_randomly_modified (gconstpointer data)
 {
   const gchar *file = data;
-  const gchar *path;
   gchar *buffer;
   gsize size;
   gint iterations;
   gint i;
   GError *error = NULL;
 
-  path = g_test_get_filename (G_TEST_DIST, "test-images", file, NULL);
-  g_file_get_contents (path, &buffer, &size, &error);
+  g_file_get_contents (file, &buffer, &size, &error);
   g_assert_no_error (error);
 
   if (g_test_thorough ())
@@ -89,10 +89,7 @@ test_randomly_modified (gconstpointer data)
 int
 main (int argc, char **argv)
 {
-  const gchar *name;
   gchar *test_images_dir;
-  gchar *path;
-  GDir *dir;
 #ifdef HAVE_SETRLIMIT
   struct rlimit max_mem_size;
 
@@ -107,14 +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", NULL);
-  dir = g_dir_open (test_images_dir, 0, NULL);
-  while ((name = g_dir_read_name (dir)) != NULL)
-    {
-      path = g_strconcat ("/pixbuf/randomly-modified/", name, NULL);
-      g_test_add_data_func_full (path, g_strdup (name), test_randomly_modified, g_free);
-      g_free (path);
-    }
-  g_dir_close (dir);
+  add_test_for_all_images ("/pixbuf/randomly-modified", test_images_dir, test_randomly_modified);
   g_free (test_images_dir);
 
   g_test_message ("Modified image is written to pixbuf-randomly-modified-image");


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