diff options
author | Benjamin Otte <otte@redhat.com> | 2015-10-04 02:20:29 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2015-10-13 02:56:47 +0200 |
commit | f1837aaf08cac2b3d0635452a00f318131fddc55 (patch) | |
tree | 71a0bb457c4819c25ce8d261d92bb9feed3f8b80 | |
parent | cfb0de7a421fb93e6b415f666494824722a26739 (diff) | |
download | gdk-pixbuf-f1837aaf08cac2b3d0635452a00f318131fddc55.tar.gz |
test-common: If image data differs, output first coords that fail
26 files changed, 80 insertions, 23 deletions
diff --git a/tests/pixbuf-slow-load.c b/tests/pixbuf-slow-load.c index 308e50315..47e252315 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 01a0c3877..1bca8da19 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 Binary files differindex 79986c644..46b1db128 100644 --- a/tests/test-images/tga/gtk-logo-32bpp-bottom-left.tga +++ b/tests/test-images/tga/gtk-logo-32bpp-bottom-left.tga diff --git a/tests/test-images/tga/gtk-logo-32bpp-bottom-right.tga b/tests/test-images/tga/gtk-logo-32bpp-bottom-right.tga Binary files differindex fefe92e62..b2b916ecc 100644 --- a/tests/test-images/tga/gtk-logo-32bpp-bottom-right.tga +++ b/tests/test-images/tga/gtk-logo-32bpp-bottom-right.tga diff --git a/tests/test-images/tga/gtk-logo-32bpp-top-left.tga b/tests/test-images/tga/gtk-logo-32bpp-top-left.tga Binary files differindex 3ba468305..212b447b9 100644 --- a/tests/test-images/tga/gtk-logo-32bpp-top-left.tga +++ b/tests/test-images/tga/gtk-logo-32bpp-top-left.tga diff --git a/tests/test-images/tga/gtk-logo-32bpp-top-right.tga b/tests/test-images/tga/gtk-logo-32bpp-top-right.tga Binary files differindex afbe0e905..e76fcd483 100644 --- a/tests/test-images/tga/gtk-logo-32bpp-top-right.tga +++ b/tests/test-images/tga/gtk-logo-32bpp-top-right.tga 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 Binary files differindex 0de138fa4..8a364c727 100644 --- a/tests/test-images/tga/gtk-logo-cmap-8bpp-bottom-left.tga +++ b/tests/test-images/tga/gtk-logo-cmap-8bpp-bottom-left.tga 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 Binary files differindex cbbda1905..a530d46c1 100644 --- a/tests/test-images/tga/gtk-logo-cmap-8bpp-bottom-right.tga +++ b/tests/test-images/tga/gtk-logo-cmap-8bpp-bottom-right.tga 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 Binary files differindex 04e3a50b8..4b69b5b42 100644 --- a/tests/test-images/tga/gtk-logo-cmap-8bpp-top-left.tga +++ b/tests/test-images/tga/gtk-logo-cmap-8bpp-top-left.tga 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 Binary files differindex 5bdda53af..baaabf4e0 100644 --- a/tests/test-images/tga/gtk-logo-cmap-8bpp-top-right.tga +++ b/tests/test-images/tga/gtk-logo-cmap-8bpp-top-right.tga 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 Binary files differindex e5df6d5a6..6d0770ee1 100644 --- 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 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 Binary files differindex de3e4178d..a2ed97320 100644 --- 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 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 Binary files differindex aa75ab39e..1204059c6 100644 --- 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 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 Binary files differindex fbde5d656..d0f41a504 100644 --- 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 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 Binary files differindex 428aa9377..956940e5a 100644 --- a/tests/test-images/tga/gtk-logo-gray-8bpp-bottom-left.tga +++ b/tests/test-images/tga/gtk-logo-gray-8bpp-bottom-left.tga 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 Binary files differindex 58c925067..32582203e 100644 --- a/tests/test-images/tga/gtk-logo-gray-8bpp-bottom-right.tga +++ b/tests/test-images/tga/gtk-logo-gray-8bpp-bottom-right.tga 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 Binary files differindex 80c1a0ec6..a35e8b878 100644 --- a/tests/test-images/tga/gtk-logo-gray-8bpp-top-left.tga +++ b/tests/test-images/tga/gtk-logo-gray-8bpp-top-left.tga 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 Binary files differindex e846052f0..93f9c4585 100644 --- a/tests/test-images/tga/gtk-logo-gray-8bpp-top-right.tga +++ b/tests/test-images/tga/gtk-logo-gray-8bpp-top-right.tga 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 Binary files differindex 3a1fe6d0d..1bafb18f8 100644 --- 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 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 Binary files differindex 0d8ec83c2..8a1fa6de8 100644 --- 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 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 Binary files differindex 5370ede36..0cc8d1d27 100644 --- 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 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 Binary files differindex 354f6f582..a78d6a157 100644 --- 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 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 Binary files differindex 9f5e8fed9..59851c167 100644 --- a/tests/test-images/tga/gtk-logo-rle-32bpp-bottom-left.tga +++ b/tests/test-images/tga/gtk-logo-rle-32bpp-bottom-left.tga 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 Binary files differindex 6b42d4da5..73b27053d 100644 --- a/tests/test-images/tga/gtk-logo-rle-32bpp-bottom-right.tga +++ b/tests/test-images/tga/gtk-logo-rle-32bpp-bottom-right.tga 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 Binary files differindex bc8421e29..ba9d47338 100644 --- a/tests/test-images/tga/gtk-logo-rle-32bpp-top-left.tga +++ b/tests/test-images/tga/gtk-logo-rle-32bpp-top-left.tga 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 Binary files differindex baec40d6d..415df40b8 100644 --- a/tests/test-images/tga/gtk-logo-rle-32bpp-top-right.tga +++ b/tests/test-images/tga/gtk-logo-rle-32bpp-top-right.tga |