[gdk-pixbuf] tests: Add error reporting to pixdata_equal()



commit 34530f299665c2563614ee2c66470d7b3cf2b1a5
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Nov 3 19:30:42 2014 +0100

    tests: Add error reporting to pixdata_equal()

 tests/pixbuf-resource.c |    4 ++--
 tests/pixbuf-save.c     |    2 +-
 tests/test-common.c     |   30 ++++++++++++++++++++++--------
 tests/test-common.h     |    2 +-
 4 files changed, 26 insertions(+), 12 deletions(-)
---
diff --git a/tests/pixbuf-resource.c b/tests/pixbuf-resource.c
index 9b53ab7..8791d1d 100644
--- a/tests/pixbuf-resource.c
+++ b/tests/pixbuf-resource.c
@@ -30,7 +30,7 @@
 static gboolean
 pixbuf_equal (GdkPixbuf *p1, GdkPixbuf *p2)
 {
-  if (!pixdata_equal (p1, p2))
+  if (!pixdata_equal (p1, p2, NULL))
     return FALSE;
   if (compare_option (p1, p2, "Title") != 0)
     return FALSE;
@@ -72,7 +72,7 @@ test_resource (void)
   
   pixbuf = gdk_pixbuf_new_from_resource ("/test/resource/icc-profile.pixdata", &error);
   g_assert_no_error (error);
-  g_assert (pixdata_equal (pixbuf, ref));
+  g_assert (pixdata_equal (pixbuf, ref, NULL));
   g_object_unref (pixbuf);
 
   pixbuf = gdk_pixbuf_new_from_resource ("/no/such/resource", &error);
diff --git a/tests/pixbuf-save.c b/tests/pixbuf-save.c
index 4afa514..0191417 100644
--- a/tests/pixbuf-save.c
+++ b/tests/pixbuf-save.c
@@ -29,7 +29,7 @@
 static gboolean
 pixbuf_equal (GdkPixbuf *p1, GdkPixbuf *p2)
 {
-  if (!pixdata_equal (p1, p2))
+  if (!pixdata_equal (p1, p2, NULL))
     return FALSE;
   if (compare_option (p1, p2, "Title") != 0)
     return FALSE;
diff --git a/tests/test-common.c b/tests/test-common.c
index 1cbf974..7071d4c 100644
--- a/tests/test-common.c
+++ b/tests/test-common.c
@@ -65,23 +65,37 @@ format_supported (const gchar *filename)
 }
 
 gboolean
-pixdata_equal (GdkPixbuf *p1, GdkPixbuf *p2)
+pixdata_equal (GdkPixbuf *p1, GdkPixbuf *p2, GError **error)
 {
-  if (gdk_pixbuf_get_colorspace (p1) != gdk_pixbuf_get_colorspace (p2))
+  if (gdk_pixbuf_get_colorspace (p1) != gdk_pixbuf_get_colorspace (p2)) {
+    g_set_error_literal (error, GDK_PIXBUF_ERROR, 0, "Colorspaces differ");
     return FALSE;
-  if (gdk_pixbuf_get_n_channels (p1) != gdk_pixbuf_get_n_channels (p2))
+  }
+  if (gdk_pixbuf_get_n_channels (p1) != gdk_pixbuf_get_n_channels (p2)) {
+    g_set_error_literal (error, GDK_PIXBUF_ERROR, 0, "Channels differ");
     return FALSE;
-  if (gdk_pixbuf_get_bits_per_sample (p1) != gdk_pixbuf_get_bits_per_sample (p2))
+  }
+  if (gdk_pixbuf_get_bits_per_sample (p1) != gdk_pixbuf_get_bits_per_sample (p2)) {
+    g_set_error_literal (error, GDK_PIXBUF_ERROR, 0, "BPP differ");
     return FALSE;
-  if (gdk_pixbuf_get_width (p1) != gdk_pixbuf_get_width (p2))
+  }
+  if (gdk_pixbuf_get_width (p1) != gdk_pixbuf_get_width (p2)) {
+    g_set_error_literal (error, GDK_PIXBUF_ERROR, 0, "Widths differ");
     return FALSE;
-  if (gdk_pixbuf_get_height (p1) != gdk_pixbuf_get_height (p2))
+  }
+  if (gdk_pixbuf_get_height (p1) != gdk_pixbuf_get_height (p2)) {
+    g_set_error_literal (error, GDK_PIXBUF_ERROR, 0, "Heights differ");
     return FALSE;
-  if (gdk_pixbuf_get_rowstride (p1) != gdk_pixbuf_get_rowstride (p2))
+  }
+  if (gdk_pixbuf_get_rowstride (p1) != gdk_pixbuf_get_rowstride (p2)) {
+    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)
+          gdk_pixbuf_get_byte_length (p1)) != 0) {
+    g_set_error_literal (error, GDK_PIXBUF_ERROR, 0, "Data differ");
     return FALSE;
+  }
 
   return TRUE;
 }
diff --git a/tests/test-common.h b/tests/test-common.h
index 179d5cb..56e4418 100644
--- a/tests/test-common.h
+++ b/tests/test-common.h
@@ -28,7 +28,7 @@
 G_BEGIN_DECLS
 
 gboolean format_supported (const gchar *filename);
-gboolean pixdata_equal (GdkPixbuf *p1, GdkPixbuf *p2);
+gboolean pixdata_equal (GdkPixbuf *p1, GdkPixbuf *p2, GError **error);
 
 G_END_DECLS
 


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