[cogl] tests: Adds test_utils_check_region() utility api



commit c3035c231de51aab1604b2d85a15be96d4afd377
Author: Robert Bragg <robert linux intel com>
Date:   Mon Oct 31 14:55:20 2011 +0000

    tests: Adds test_utils_check_region() utility api
    
    For conformance tests that want to read back a region of pixels and
    check they all have the same color we now have a test_utils_check_region
    utility function for that.
    
    Reviewed-by: Neil Roberts <neil linux intel com>

 tests/conform/test-utils.c |   37 +++++++++++++++++++++++++++++++++++++
 tests/conform/test-utils.h |   19 +++++++++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/tests/conform/test-utils.c b/tests/conform/test-utils.c
index b9d706f..1c0d5b5 100644
--- a/tests/conform/test-utils.c
+++ b/tests/conform/test-utils.c
@@ -104,3 +104,40 @@ test_utils_check_pixel_rgb (int x, int y, int r, int g, int b)
 {
   test_utils_check_pixel (x, y, (r << 24) | (g << 16) | (b << 8));
 }
+
+void
+test_utils_check_region (int x, int y,
+                         int width, int height,
+                         guint32 expected_rgba)
+{
+  guint32 reference = expected_rgba >> 8;
+  guint8 *pixels, *p;
+
+  pixels = p = g_malloc (width * height * 4);
+  cogl_read_pixels (x,
+                    y,
+                    width,
+                    height,
+                    COGL_READ_PIXELS_COLOR_BUFFER,
+                    COGL_PIXEL_FORMAT_RGBA_8888,
+                    p);
+
+  /* Check whether the center of each division is the right color */
+  for (y = 0; y < height; y++)
+    for (x = 0; x < width; x++)
+      {
+        guint32 current = GUINT32_FROM_BE (*((guint32 *)p)) >> 8;
+        if (current != reference)
+          {
+            /* Ensure we have a meaningful error message... */
+            char *screen_pixel = g_strdup_printf ("#%06x", current);
+            char *intended_pixel = g_strdup_printf ("#%06x", reference);
+            g_assert_cmpstr (screen_pixel, == ,intended_pixel);
+          }
+        p += 4;
+      }
+
+  g_free (pixels);
+}
+
+
diff --git a/tests/conform/test-utils.h b/tests/conform/test-utils.h
index 225c793..a82766c 100644
--- a/tests/conform/test-utils.h
+++ b/tests/conform/test-utils.h
@@ -69,4 +69,23 @@ test_utils_check_pixel (int x, int y, guint32 expected_pixel);
 void
 test_utils_check_pixel_rgb (int x, int y, int r, int g, int b);
 
+/*
+ * test_utils_check_region:
+ * @x: x co-ordinate of the region to test
+ * @y: y co-ordinate of the region to test
+ * @width: width of the region to test
+ * @height: height of the region to test
+ * @pixel: An integer of the form 0xrrggbb representing the expected region color
+ *
+ * Performs a read pixel on the specified region of the current cogl
+ * framebuffer and asserts that it matches the given color. The alpha
+ * channel of the color is ignored. The pixels are converted to a
+ * string and compared with g_assert_cmpstr so that if the comparison
+ * fails then the assert will display a meaningful message
+ */
+void
+test_utils_check_region (int x, int y,
+                         int width, int height,
+                         guint32 expected_rgba);
+
 #endif /* _TEST_UTILS_H_ */



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