[gdk-pixbuf] test-common: Improve error mesages in pixdata_equal()



commit aab38f5803d2fdad5ba5f46119543c6b75992f79
Author: Benjamin Otte <otte redhat com>
Date:   Mon Oct 5 20:26:15 2015 +0200

    test-common: Improve error mesages in pixdata_equal()
    
    When something differs, display the actual values

 tests/test-common.c |   48 +++++++++++++++++++++++++++++++++++-------------
 1 files changed, 35 insertions(+), 13 deletions(-)
---
diff --git a/tests/test-common.c b/tests/test-common.c
index 738153d..9498301 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;
                 }
             }


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