summaryrefslogtreecommitdiff
path: root/tests/test-common.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2015-10-05 20:26:15 +0200
committerBenjamin Otte <otte@redhat.com>2015-10-13 02:56:47 +0200
commitaab38f5803d2fdad5ba5f46119543c6b75992f79 (patch)
treec94f7048d60bde091c4286a3614657e6cfce9abf /tests/test-common.c
parentdc073ef7096afcde6e0e146884d472dc8486dcc3 (diff)
downloadgdk-pixbuf-aab38f5803d2fdad5ba5f46119543c6b75992f79.tar.gz
test-common: Improve error mesages in pixdata_equal()
When something differs, display the actual values
Diffstat (limited to 'tests/test-common.c')
-rw-r--r--tests/test-common.c48
1 files changed, 35 insertions, 13 deletions
diff --git a/tests/test-common.c b/tests/test-common.c
index 738153d15..94983013b 100644
--- a/tests/test-common.c
+++ b/tests/test-common.c
@@ -85,37 +85,42 @@ pixdata_equal (GdkPixbuf *test,
{
if (gdk_pixbuf_get_colorspace (test) != gdk_pixbuf_get_colorspace (ref))
{
- g_set_error_literal (error, GDK_PIXBUF_ERROR, 0, "Colorspaces differ");
+ g_set_error (error, GDK_PIXBUF_ERROR, 0, "Image colorspace is %d but should be %d",
+ gdk_pixbuf_get_colorspace (test), gdk_pixbuf_get_colorspace (ref));
return FALSE;
}
if (gdk_pixbuf_get_n_channels (test) != gdk_pixbuf_get_n_channels (ref))
{
- g_set_error_literal (error, GDK_PIXBUF_ERROR, 0, "Channels differ");
+ g_set_error (error, GDK_PIXBUF_ERROR, 0,
+ "has %u channels but should have %u",
+ gdk_pixbuf_get_n_channels (test), gdk_pixbuf_get_n_channels (ref));
return FALSE;
}
if (gdk_pixbuf_get_bits_per_sample (test) != gdk_pixbuf_get_bits_per_sample (ref))
{
- g_set_error_literal (error, GDK_PIXBUF_ERROR, 0, "BPP differ");
+ g_set_error (error, GDK_PIXBUF_ERROR, 0,
+ "Image is %u bits per sample but should be %u bits per sample",
+ gdk_pixbuf_get_bits_per_sample (test), gdk_pixbuf_get_bits_per_sample (ref));
return FALSE;
}
- if (gdk_pixbuf_get_width (test) != gdk_pixbuf_get_width (ref))
+ if (gdk_pixbuf_get_width (test) != gdk_pixbuf_get_width (ref) ||
+ gdk_pixbuf_get_height (test) != gdk_pixbuf_get_height (ref))
{
- g_set_error_literal (error, GDK_PIXBUF_ERROR, 0, "Widths differ");
- return FALSE;
- }
-
- if (gdk_pixbuf_get_height (test) != gdk_pixbuf_get_height (ref))
- {
- g_set_error_literal (error, GDK_PIXBUF_ERROR, 0, "Heights differ");
+ g_set_error (error, GDK_PIXBUF_ERROR, 0,
+ "Image size is %dx%d but should be %dx%d",
+ gdk_pixbuf_get_width (test), gdk_pixbuf_get_height (test),
+ gdk_pixbuf_get_width (ref), gdk_pixbuf_get_height (ref));
return FALSE;
}
if (gdk_pixbuf_get_rowstride (test) != gdk_pixbuf_get_rowstride (ref))
{
- g_set_error_literal (error, GDK_PIXBUF_ERROR, 0, "Rowstrides differ");
+ g_set_error (error, GDK_PIXBUF_ERROR, 0,
+ "Image rowstrides is %u bytes but should be %u bytes",
+ gdk_pixbuf_get_rowstride (test), gdk_pixbuf_get_rowstride (ref));
return FALSE;
}
@@ -138,7 +143,24 @@ pixdata_equal (GdkPixbuf *test,
{
if (memcmp (&test_pixels[x * n_channels], &ref_pixels[x * n_channels], n_channels) != 0)
{
- g_set_error (error, GDK_PIXBUF_ERROR, 0, "Data differ at %ux%u", x, y);
+ if (n_channels == 4)
+ {
+ g_set_error (error, GDK_PIXBUF_ERROR, 0, "Image data at %ux%u is #%02X%02X%02X%02X, but should be #%02X%02X%02X%02X",
+ x, y,
+ test_pixels[0], test_pixels[1], test_pixels[2], test_pixels[3],
+ ref_pixels[0], ref_pixels[1], ref_pixels[2], ref_pixels[3]);
+ }
+ else if (n_channels == 3)
+ {
+ g_set_error (error, GDK_PIXBUF_ERROR, 0, "Image data at %ux%u is #%02X%02X%02X, but should be #%02X%02X%02X",
+ x, y,
+ test_pixels[0], test_pixels[1], test_pixels[2],
+ ref_pixels[0], ref_pixels[1], ref_pixels[2]);
+ }
+ else
+ {
+ g_set_error (error, GDK_PIXBUF_ERROR, 0, "Image data differ at %ux%u", x, y);
+ }
return FALSE;
}
}