[gdk-pixbuf] test-common: If image data differs, output first coords that fail



commit f1837aaf08cac2b3d0635452a00f318131fddc55
Author: Benjamin Otte <otte redhat com>
Date:   Sun Oct 4 02:20:29 2015 +0200

    test-common: If image data differs, output first coords that fail

 tests/pixbuf-slow-load.c                           |   72 ++++++++++++++-----
 tests/test-common.c                                |   31 +++++++-
 .../test-images/tga/gtk-logo-32bpp-bottom-left.tga |  Bin 9260 -> 9260 bytes
 .../tga/gtk-logo-32bpp-bottom-right.tga            |  Bin 9260 -> 9260 bytes
 tests/test-images/tga/gtk-logo-32bpp-top-left.tga  |  Bin 9260 -> 9260 bytes
 tests/test-images/tga/gtk-logo-32bpp-top-right.tga |  Bin 9260 -> 9260 bytes
 .../tga/gtk-logo-cmap-8bpp-bottom-left.tga         |  Bin 3196 -> 3116 bytes
 .../tga/gtk-logo-cmap-8bpp-bottom-right.tga        |  Bin 3196 -> 3116 bytes
 .../tga/gtk-logo-cmap-8bpp-top-left.tga            |  Bin 3196 -> 3116 bytes
 .../tga/gtk-logo-cmap-8bpp-top-right.tga           |  Bin 3196 -> 3116 bytes
 .../tga/gtk-logo-cmap-rle-8bpp-bottom-left.tga     |  Bin 1797 -> 1767 bytes
 .../tga/gtk-logo-cmap-rle-8bpp-bottom-right.tga    |  Bin 1797 -> 1767 bytes
 .../tga/gtk-logo-cmap-rle-8bpp-top-left.tga        |  Bin 1797 -> 1767 bytes
 .../tga/gtk-logo-cmap-rle-8bpp-top-right.tga       |  Bin 1797 -> 1767 bytes
 .../tga/gtk-logo-gray-8bpp-bottom-left.tga         |  Bin 2348 -> 6956 bytes
 .../tga/gtk-logo-gray-8bpp-bottom-right.tga        |  Bin 2348 -> 6956 bytes
 .../tga/gtk-logo-gray-8bpp-top-left.tga            |  Bin 2348 -> 6956 bytes
 .../tga/gtk-logo-gray-8bpp-top-right.tga           |  Bin 2348 -> 6956 bytes
 .../tga/gtk-logo-gray-rle-8bpp-bottom-left.tga     |  Bin 999 -> 2287 bytes
 .../tga/gtk-logo-gray-rle-8bpp-bottom-right.tga    |  Bin 999 -> 2287 bytes
 .../tga/gtk-logo-gray-rle-8bpp-top-left.tga        |  Bin 999 -> 2287 bytes
 .../tga/gtk-logo-gray-rle-8bpp-top-right.tga       |  Bin 999 -> 2287 bytes
 .../tga/gtk-logo-rle-32bpp-bottom-left.tga         |  Bin 4078 -> 4078 bytes
 .../tga/gtk-logo-rle-32bpp-bottom-right.tga        |  Bin 4078 -> 4078 bytes
 .../tga/gtk-logo-rle-32bpp-top-left.tga            |  Bin 4078 -> 4078 bytes
 .../tga/gtk-logo-rle-32bpp-top-right.tga           |  Bin 4078 -> 4078 bytes
 26 files changed, 80 insertions(+), 23 deletions(-)
---
diff --git a/tests/pixbuf-slow-load.c b/tests/pixbuf-slow-load.c
index 308e503..47e2523 100644
--- a/tests/pixbuf-slow-load.c
+++ b/tests/pixbuf-slow-load.c
@@ -33,7 +33,26 @@ loader_size_prepared (GdkPixbufLoader  *loader,
 {
   g_assert (*pixbuf == NULL);
 
-  *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w, h);
+  *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, w, h);
+  g_assert (*pixbuf != NULL);
+}
+
+static void
+loader_area_prepared (GdkPixbufLoader  *loader,
+                      int               w,
+                      int               h,
+                      GdkPixbuf       **pixbuf)
+{
+  g_assert (*pixbuf != NULL);
+
+  if (gdk_pixbuf_get_has_alpha (gdk_pixbuf_loader_get_pixbuf (loader)))
+    {
+      GdkPixbuf *alpha = gdk_pixbuf_add_alpha (*pixbuf, FALSE, 0, 0, 0);
+
+      g_object_unref (*pixbuf);
+      *pixbuf = alpha;
+    }
+
   g_assert (*pixbuf != NULL);
 }
 
@@ -52,56 +71,71 @@ loader_area_updated (GdkPixbufLoader  *loader,
                         x, y);
 }
 
+static char *
+make_ref_filename (const char *filename)
+{
+  return g_strconcat (filename, ".ref.png", NULL);
+}
+
+static gboolean
+is_ref_filename (const char *filename)
+{
+  return g_str_has_suffix (filename, ".ref.png");
+}
+
 static void
-test_slow_load (gconstpointer file)
+test_reftest_success (gconstpointer file)
 {
   GdkPixbufLoader *loader;
   GdkPixbuf *reference, *loaded = NULL;
   GError *error = NULL;
   const char *filename;
+  char *ref_filename;
   guchar *contents;
   gsize i, contents_length;
+  gboolean success;
 
   filename = file;
-  reference = gdk_pixbuf_new_from_file (filename, &error);
+  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);
   g_assert (reference != NULL);
-  if (!gdk_pixbuf_get_has_alpha (reference))
-    {
-      GdkPixbuf *tmp = gdk_pixbuf_add_alpha (reference, FALSE, 0, 0, 0);
-      g_object_unref (reference);
-      reference = tmp;
-    }
 
-  loader = gdk_pixbuf_loader_new_with_mime_type ("image/x-tga", &error);
-  g_assert_no_error (error);
+  loader = gdk_pixbuf_loader_new ();
   g_assert (loader != NULL);
   g_signal_connect (loader, "size-prepared", G_CALLBACK (loader_size_prepared), &loaded);
+  g_signal_connect (loader, "area-prepared", G_CALLBACK (loader_area_prepared), &loaded);
   g_signal_connect (loader, "area-updated", G_CALLBACK (loader_area_updated), &loaded);
 
-  if (!g_file_get_contents (filename, (gchar **) &contents, &contents_length, &error))
-    g_assert_not_reached ();
+  success = g_file_get_contents (filename, (gchar **) &contents, &contents_length, &error);
   g_assert_no_error (error);
+  g_assert (success);
 
   for (i = 0; i < contents_length; i++)
     {
-      if (!gdk_pixbuf_loader_write (loader, &contents[i], 1, &error))
-        g_assert_not_reached();
+      success = gdk_pixbuf_loader_write (loader, &contents[i], 1, &error);
       g_assert_no_error (error);
+      g_assert (success);
     }
   
-  if (!gdk_pixbuf_loader_close (loader, &error))
-    g_assert_not_reached ();
+  success = gdk_pixbuf_loader_close (loader, &error);
   g_assert_no_error (error);
+  g_assert (success);
+
   g_assert (loaded != NULL);
 
-  g_assert (pixdata_equal (reference, loaded, &error));
+  success = pixdata_equal (reference, loaded, &error);
   g_assert_no_error (error);
+  g_assert (success);
 
   g_free (contents);
   g_object_unref (loaded);
   g_object_unref (loader);
   g_object_unref (reference);
+  g_free (ref_filename);
 }
 
 int
@@ -112,7 +146,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/slow-load", tga_test_images, test_slow_load);
+  add_test_for_all_images ("/pixbuf/reftest/success", tga_test_images, test_reftest_success);
   g_free (tga_test_images);
 
   return g_test_run ();
diff --git a/tests/test-common.c b/tests/test-common.c
index 01a0c38..1bca8da 100644
--- a/tests/test-common.c
+++ b/tests/test-common.c
@@ -105,11 +105,34 @@ pixdata_equal (GdkPixbuf *p1, GdkPixbuf *p2, GError **error)
     g_set_error_literal (error, GDK_PIXBUF_ERROR, 0, "Rowstrides differ");
     return FALSE;
   }
+
   if (memcmp (gdk_pixbuf_get_pixels (p1), gdk_pixbuf_get_pixels (p2),
-          gdk_pixbuf_get_byte_length (p1)) != 0) {
-    g_set_error_literal (error, GDK_PIXBUF_ERROR, 0, "Data differ");
-    return FALSE;
-  }
+          gdk_pixbuf_get_byte_length (p1)) != 0)
+    {
+      guint x, y, width, height, n_channels, rowstride;
+      const guchar *pixels1, *pixels2;
+
+      rowstride = gdk_pixbuf_get_rowstride (p1);
+      n_channels = gdk_pixbuf_get_n_channels (p1);
+      width = gdk_pixbuf_get_width (p1);
+      height = gdk_pixbuf_get_height (p1);
+      pixels1 = gdk_pixbuf_get_pixels (p1);
+      pixels2 = gdk_pixbuf_get_pixels (p2);
+
+      for (y = 0; y < height; y++)
+        {
+          for (x = 0; x < width; x++)
+            {
+              if (memcmp (&pixels1[x * n_channels], &pixels2[x * n_channels], n_channels) != 0)
+                {
+                  g_set_error (error, GDK_PIXBUF_ERROR, 0, "Data differ at %ux%u", x, y);
+                  return FALSE;
+                }
+            }
+          pixels1 += rowstride;
+          pixels2 += rowstride;
+        }
+    }
 
   return TRUE;
 }
diff --git a/tests/test-images/tga/gtk-logo-32bpp-bottom-left.tga 
b/tests/test-images/tga/gtk-logo-32bpp-bottom-left.tga
index 79986c6..46b1db1 100644
Binary files a/tests/test-images/tga/gtk-logo-32bpp-bottom-left.tga and 
b/tests/test-images/tga/gtk-logo-32bpp-bottom-left.tga differ
diff --git a/tests/test-images/tga/gtk-logo-32bpp-bottom-right.tga 
b/tests/test-images/tga/gtk-logo-32bpp-bottom-right.tga
index fefe92e..b2b916e 100644
Binary files a/tests/test-images/tga/gtk-logo-32bpp-bottom-right.tga and 
b/tests/test-images/tga/gtk-logo-32bpp-bottom-right.tga differ
diff --git a/tests/test-images/tga/gtk-logo-32bpp-top-left.tga 
b/tests/test-images/tga/gtk-logo-32bpp-top-left.tga
index 3ba4683..212b447 100644
Binary files a/tests/test-images/tga/gtk-logo-32bpp-top-left.tga and 
b/tests/test-images/tga/gtk-logo-32bpp-top-left.tga differ
diff --git a/tests/test-images/tga/gtk-logo-32bpp-top-right.tga 
b/tests/test-images/tga/gtk-logo-32bpp-top-right.tga
index afbe0e9..e76fcd4 100644
Binary files a/tests/test-images/tga/gtk-logo-32bpp-top-right.tga and 
b/tests/test-images/tga/gtk-logo-32bpp-top-right.tga differ
diff --git a/tests/test-images/tga/gtk-logo-cmap-8bpp-bottom-left.tga 
b/tests/test-images/tga/gtk-logo-cmap-8bpp-bottom-left.tga
index 0de138f..8a364c7 100644
Binary files a/tests/test-images/tga/gtk-logo-cmap-8bpp-bottom-left.tga and 
b/tests/test-images/tga/gtk-logo-cmap-8bpp-bottom-left.tga differ
diff --git a/tests/test-images/tga/gtk-logo-cmap-8bpp-bottom-right.tga 
b/tests/test-images/tga/gtk-logo-cmap-8bpp-bottom-right.tga
index cbbda19..a530d46 100644
Binary files a/tests/test-images/tga/gtk-logo-cmap-8bpp-bottom-right.tga and 
b/tests/test-images/tga/gtk-logo-cmap-8bpp-bottom-right.tga differ
diff --git a/tests/test-images/tga/gtk-logo-cmap-8bpp-top-left.tga 
b/tests/test-images/tga/gtk-logo-cmap-8bpp-top-left.tga
index 04e3a50..4b69b5b 100644
Binary files a/tests/test-images/tga/gtk-logo-cmap-8bpp-top-left.tga and 
b/tests/test-images/tga/gtk-logo-cmap-8bpp-top-left.tga differ
diff --git a/tests/test-images/tga/gtk-logo-cmap-8bpp-top-right.tga 
b/tests/test-images/tga/gtk-logo-cmap-8bpp-top-right.tga
index 5bdda53..baaabf4 100644
Binary files a/tests/test-images/tga/gtk-logo-cmap-8bpp-top-right.tga and 
b/tests/test-images/tga/gtk-logo-cmap-8bpp-top-right.tga differ
diff --git a/tests/test-images/tga/gtk-logo-cmap-rle-8bpp-bottom-left.tga 
b/tests/test-images/tga/gtk-logo-cmap-rle-8bpp-bottom-left.tga
index e5df6d5..6d0770e 100644
Binary files a/tests/test-images/tga/gtk-logo-cmap-rle-8bpp-bottom-left.tga and 
b/tests/test-images/tga/gtk-logo-cmap-rle-8bpp-bottom-left.tga differ
diff --git a/tests/test-images/tga/gtk-logo-cmap-rle-8bpp-bottom-right.tga 
b/tests/test-images/tga/gtk-logo-cmap-rle-8bpp-bottom-right.tga
index de3e417..a2ed973 100644
Binary files a/tests/test-images/tga/gtk-logo-cmap-rle-8bpp-bottom-right.tga and 
b/tests/test-images/tga/gtk-logo-cmap-rle-8bpp-bottom-right.tga differ
diff --git a/tests/test-images/tga/gtk-logo-cmap-rle-8bpp-top-left.tga 
b/tests/test-images/tga/gtk-logo-cmap-rle-8bpp-top-left.tga
index aa75ab3..1204059 100644
Binary files a/tests/test-images/tga/gtk-logo-cmap-rle-8bpp-top-left.tga and 
b/tests/test-images/tga/gtk-logo-cmap-rle-8bpp-top-left.tga differ
diff --git a/tests/test-images/tga/gtk-logo-cmap-rle-8bpp-top-right.tga 
b/tests/test-images/tga/gtk-logo-cmap-rle-8bpp-top-right.tga
index fbde5d6..d0f41a5 100644
Binary files a/tests/test-images/tga/gtk-logo-cmap-rle-8bpp-top-right.tga and 
b/tests/test-images/tga/gtk-logo-cmap-rle-8bpp-top-right.tga differ
diff --git a/tests/test-images/tga/gtk-logo-gray-8bpp-bottom-left.tga 
b/tests/test-images/tga/gtk-logo-gray-8bpp-bottom-left.tga
index 428aa93..956940e 100644
Binary files a/tests/test-images/tga/gtk-logo-gray-8bpp-bottom-left.tga and 
b/tests/test-images/tga/gtk-logo-gray-8bpp-bottom-left.tga differ
diff --git a/tests/test-images/tga/gtk-logo-gray-8bpp-bottom-right.tga 
b/tests/test-images/tga/gtk-logo-gray-8bpp-bottom-right.tga
index 58c9250..3258220 100644
Binary files a/tests/test-images/tga/gtk-logo-gray-8bpp-bottom-right.tga and 
b/tests/test-images/tga/gtk-logo-gray-8bpp-bottom-right.tga differ
diff --git a/tests/test-images/tga/gtk-logo-gray-8bpp-top-left.tga 
b/tests/test-images/tga/gtk-logo-gray-8bpp-top-left.tga
index 80c1a0e..a35e8b8 100644
Binary files a/tests/test-images/tga/gtk-logo-gray-8bpp-top-left.tga and 
b/tests/test-images/tga/gtk-logo-gray-8bpp-top-left.tga differ
diff --git a/tests/test-images/tga/gtk-logo-gray-8bpp-top-right.tga 
b/tests/test-images/tga/gtk-logo-gray-8bpp-top-right.tga
index e846052..93f9c45 100644
Binary files a/tests/test-images/tga/gtk-logo-gray-8bpp-top-right.tga and 
b/tests/test-images/tga/gtk-logo-gray-8bpp-top-right.tga differ
diff --git a/tests/test-images/tga/gtk-logo-gray-rle-8bpp-bottom-left.tga 
b/tests/test-images/tga/gtk-logo-gray-rle-8bpp-bottom-left.tga
index 3a1fe6d..1bafb18 100644
Binary files a/tests/test-images/tga/gtk-logo-gray-rle-8bpp-bottom-left.tga and 
b/tests/test-images/tga/gtk-logo-gray-rle-8bpp-bottom-left.tga differ
diff --git a/tests/test-images/tga/gtk-logo-gray-rle-8bpp-bottom-right.tga 
b/tests/test-images/tga/gtk-logo-gray-rle-8bpp-bottom-right.tga
index 0d8ec83..8a1fa6d 100644
Binary files a/tests/test-images/tga/gtk-logo-gray-rle-8bpp-bottom-right.tga and 
b/tests/test-images/tga/gtk-logo-gray-rle-8bpp-bottom-right.tga differ
diff --git a/tests/test-images/tga/gtk-logo-gray-rle-8bpp-top-left.tga 
b/tests/test-images/tga/gtk-logo-gray-rle-8bpp-top-left.tga
index 5370ede..0cc8d1d 100644
Binary files a/tests/test-images/tga/gtk-logo-gray-rle-8bpp-top-left.tga and 
b/tests/test-images/tga/gtk-logo-gray-rle-8bpp-top-left.tga differ
diff --git a/tests/test-images/tga/gtk-logo-gray-rle-8bpp-top-right.tga 
b/tests/test-images/tga/gtk-logo-gray-rle-8bpp-top-right.tga
index 354f6f5..a78d6a1 100644
Binary files a/tests/test-images/tga/gtk-logo-gray-rle-8bpp-top-right.tga and 
b/tests/test-images/tga/gtk-logo-gray-rle-8bpp-top-right.tga differ
diff --git a/tests/test-images/tga/gtk-logo-rle-32bpp-bottom-left.tga 
b/tests/test-images/tga/gtk-logo-rle-32bpp-bottom-left.tga
index 9f5e8fe..59851c1 100644
Binary files a/tests/test-images/tga/gtk-logo-rle-32bpp-bottom-left.tga and 
b/tests/test-images/tga/gtk-logo-rle-32bpp-bottom-left.tga differ
diff --git a/tests/test-images/tga/gtk-logo-rle-32bpp-bottom-right.tga 
b/tests/test-images/tga/gtk-logo-rle-32bpp-bottom-right.tga
index 6b42d4d..73b2705 100644
Binary files a/tests/test-images/tga/gtk-logo-rle-32bpp-bottom-right.tga and 
b/tests/test-images/tga/gtk-logo-rle-32bpp-bottom-right.tga differ
diff --git a/tests/test-images/tga/gtk-logo-rle-32bpp-top-left.tga 
b/tests/test-images/tga/gtk-logo-rle-32bpp-top-left.tga
index bc8421e..ba9d473 100644
Binary files a/tests/test-images/tga/gtk-logo-rle-32bpp-top-left.tga and 
b/tests/test-images/tga/gtk-logo-rle-32bpp-top-left.tga differ
diff --git a/tests/test-images/tga/gtk-logo-rle-32bpp-top-right.tga 
b/tests/test-images/tga/gtk-logo-rle-32bpp-top-right.tga
index baec40d..415df40 100644
Binary files a/tests/test-images/tga/gtk-logo-rle-32bpp-top-right.tga and 
b/tests/test-images/tga/gtk-logo-rle-32bpp-top-right.tga differ


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