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>
This commit is contained in:
Robert Bragg 2011-10-31 14:55:20 +00:00
parent e0344468d8
commit c3035c231d
2 changed files with 56 additions and 0 deletions

View File

@ -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)); 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);
}

View File

@ -69,4 +69,23 @@ test_utils_check_pixel (int x, int y, guint32 expected_pixel);
void void
test_utils_check_pixel_rgb (int x, int y, int r, int g, int b); 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_ */ #endif /* _TEST_UTILS_H_ */