[cogl] tests: Add a utility function for reading a pixel
- From: Neil Roberts <nroberts src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl] tests: Add a utility function for reading a pixel
- Date: Wed, 26 Oct 2011 18:04:16 +0000 (UTC)
commit e69e41b2c743c6b12f5d2d95f3b613223b105beb
Author: Neil Roberts <neil linux intel com>
Date: Wed Oct 26 14:15:14 2011 +0100
tests: Add a utility function for reading a pixel
Most of the conformance tests read a pixel value and assert that it
matches a known value. However they were all doing this with slightly
different methods. This adds a common test_utils_check_pixel function
which they now all use. The function takes an x and y coordinate and a
32-bit value representing the color. It is assumed that writing a
known color is most convenient as an 8 digit hex sequence which this
function allows. There is also a test_utils_check_pixel_rgb function
wrapper which takes the components as separate arguments. This is more
convenient when the expected color is also calculated by the test.
Reviewed-by: Robert Bragg <robert linux intel com>
tests/conform/test-blend-strings.c | 26 ++---------------
tests/conform/test-color-mask.c | 30 +++-----------------
tests/conform/test-depth-test.c | 39 ++------------------------
tests/conform/test-just-vertex-shader.c | 24 +---------------
tests/conform/test-materials.c | 46 +++++--------------------------
tests/conform/test-premult.c | 41 +---------------------------
tests/conform/test-utils.c | 26 +++++++++++++++++
tests/conform/test-utils.h | 31 +++++++++++++++++++++
8 files changed, 78 insertions(+), 185 deletions(-)
---
diff --git a/tests/conform/test-blend-strings.c b/tests/conform/test-blend-strings.c
index e722934..d410727 100644
--- a/tests/conform/test-blend-strings.c
+++ b/tests/conform/test-blend-strings.c
@@ -26,26 +26,6 @@ typedef struct _TestState
static void
-check_pixel (int x, int y, guint32 expected_pixel)
-{
- guint32 pixel;
- char *screen_pixel;
- char *intended_pixel;
-
- cogl_read_pixels (x, y, 1, 1, COGL_READ_PIXELS_COLOR_BUFFER,
- COGL_PIXEL_FORMAT_RGBA_8888_PRE,
- (guint8 *) &pixel);
-
- screen_pixel = g_strdup_printf ("#%06x", GUINT32_FROM_BE (pixel) >> 8);
- intended_pixel = g_strdup_printf ("#%06x", expected_pixel >> 8);
-
- g_assert_cmpstr (screen_pixel, ==, intended_pixel);
-
- g_free (screen_pixel);
- g_free (intended_pixel);
-}
-
-static void
test_blend (TestState *state,
int x,
int y,
@@ -138,7 +118,7 @@ test_blend (TestState *state,
g_print (" blend constant = UNUSED\n");
}
- check_pixel (x_off, y_off, expected_result);
+ test_utils_check_pixel (x_off, y_off, expected_result);
/*
@@ -191,7 +171,7 @@ test_blend (TestState *state,
/* See what we got... */
- check_pixel (x_off, y_off, expected_result);
+ test_utils_check_pixel (x_off, y_off, expected_result);
}
static CoglHandle
@@ -308,7 +288,7 @@ test_tex_combine (TestState *state,
g_print (" combine constant = UNUSED\n");
}
- check_pixel (x_off, y_off, expected_result);
+ test_utils_check_pixel (x_off, y_off, expected_result);
}
static void
diff --git a/tests/conform/test-color-mask.c b/tests/conform/test-color-mask.c
index 389a41d..75c8a05 100644
--- a/tests/conform/test-color-mask.c
+++ b/tests/conform/test-color-mask.c
@@ -16,26 +16,6 @@ typedef struct _TestState
} TestState;
static void
-check_pixel (int x, int y, guint8 r, guint8 g, guint8 b)
-{
- guint32 pixel;
- char *screen_pixel;
- char *intended_pixel;
-
- cogl_read_pixels (x, y, 1, 1, COGL_READ_PIXELS_COLOR_BUFFER,
- COGL_PIXEL_FORMAT_RGBA_8888_PRE,
- (guint8 *) &pixel);
-
- screen_pixel = g_strdup_printf ("#%06x", GUINT32_FROM_BE (pixel) >> 8);
- intended_pixel = g_strdup_printf ("#%02x%02x%02x", r, g, b);
-
- g_assert_cmpstr (screen_pixel, ==, intended_pixel);
-
- g_free (screen_pixel);
- g_free (intended_pixel);
-}
-
-static void
paint (TestState *state)
{
CoglColor bg;
@@ -78,11 +58,11 @@ paint (TestState *state)
{ 0x00, 0xff, 0x00, 0xff },
{ 0x00, 0x00, 0xff, 0xff } };
- check_pixel (state->width * (i + 0.5f) / NUM_FBOS,
- state->height / 2,
- expected_colors[i][0],
- expected_colors[i][1],
- expected_colors[i][2]);
+ test_utils_check_pixel_rgb (state->width * (i + 0.5f) / NUM_FBOS,
+ state->height / 2,
+ expected_colors[i][0],
+ expected_colors[i][1],
+ expected_colors[i][2]);
}
}
diff --git a/tests/conform/test-depth-test.c b/tests/conform/test-depth-test.c
index 006cedb..d42571f 100644
--- a/tests/conform/test-depth-test.c
+++ b/tests/conform/test-depth-test.c
@@ -32,28 +32,6 @@ typedef struct
float range_far;
} TestDepthState;
-static void
-check_pixel (GLubyte *pixel, guint32 color)
-{
- guint8 r = MASK_RED (color);
- guint8 g = MASK_GREEN (color);
- guint8 b = MASK_BLUE (color);
- guint8 a = MASK_ALPHA (color);
-
- if (g_test_verbose ())
- g_print (" expected = %x, %x, %x, %x\n",
- r, g, b, a);
- /* FIXME - allow for hardware in-precision */
- g_assert_cmpint (pixel[RED], ==, r);
- g_assert_cmpint (pixel[GREEN], ==, g);
- g_assert_cmpint (pixel[BLUE], ==, b);
-
- /* FIXME
- * We ignore the alpha, since we don't know if our render target is
- * RGB or RGBA */
- /* g_assert (pixel[ALPHA] == a); */
-}
-
static gboolean
draw_rectangle (TestState *state,
int x,
@@ -108,9 +86,6 @@ test_depth (TestState *state,
TestDepthState *rect2_state,
guint32 expected_result)
{
- GLubyte pixel[4];
- int y_off;
- int x_off;
gboolean missing_feature = FALSE;
if (rect0_state)
@@ -125,17 +100,9 @@ test_depth (TestState *state,
if (missing_feature)
return;
- /* See what we got... */
-
- y_off = y * QUAD_WIDTH + (QUAD_WIDTH / 2);
- x_off = x * QUAD_WIDTH + (QUAD_WIDTH / 2);
-
- cogl_read_pixels (x_off, y_off, 1, 1,
- COGL_READ_PIXELS_COLOR_BUFFER,
- COGL_PIXEL_FORMAT_RGBA_8888_PRE,
- pixel);
-
- check_pixel (pixel, expected_result);
+ test_utils_check_pixel (x * QUAD_WIDTH + (QUAD_WIDTH / 2),
+ y * QUAD_WIDTH + (QUAD_WIDTH / 2),
+ expected_result);
}
static void
diff --git a/tests/conform/test-just-vertex-shader.c b/tests/conform/test-just-vertex-shader.c
index 7b809cd..ead7d6c 100644
--- a/tests/conform/test-just-vertex-shader.c
+++ b/tests/conform/test-just-vertex-shader.c
@@ -145,32 +145,12 @@ paint (TestState *state)
}
static void
-check_pixel (int x, int y, guint8 r, guint8 g, guint8 b)
-{
- guint32 pixel;
- char *screen_pixel;
- char *intended_pixel;
-
- cogl_read_pixels (x, y, 1, 1, COGL_READ_PIXELS_COLOR_BUFFER,
- COGL_PIXEL_FORMAT_RGBA_8888_PRE,
- (guint8 *) &pixel);
-
- screen_pixel = g_strdup_printf ("#%06x", GUINT32_FROM_BE (pixel) >> 8);
- intended_pixel = g_strdup_printf ("#%02x%02x%02x", r, g, b);
-
- g_assert_cmpstr (screen_pixel, ==, intended_pixel);
-
- g_free (screen_pixel);
- g_free (intended_pixel);
-}
-
-static void
validate_result (void)
{
/* Non-shader version */
- check_pixel (25, 25, 0, 0xff, 0);
+ test_utils_check_pixel (25, 25, 0x00ff0000);
/* Shader version */
- check_pixel (75, 25, 0, 0xff, 0);
+ test_utils_check_pixel (75, 25, 0x00ff0000);
}
void
diff --git a/tests/conform/test-materials.c b/tests/conform/test-materials.c
index 5dbb30c..058238d 100644
--- a/tests/conform/test-materials.c
+++ b/tests/conform/test-materials.c
@@ -25,44 +25,12 @@ typedef struct _TestState
ClutterGeometry stage_geom;
} TestState;
-
static void
-check_pixel (TestState *state, int x, int y, guint32 color)
+check_quad (int quad_x, int quad_y, guint32 color)
{
- GLint y_off;
- GLint x_off;
- GLubyte pixel[4];
- guint8 r = MASK_RED (color);
- guint8 g = MASK_GREEN (color);
- guint8 b = MASK_BLUE (color);
- guint8 a = MASK_ALPHA (color);
-
- /* See what we got... */
-
- /* NB: glReadPixels is done in GL screen space so y = 0 is at the bottom */
- y_off = y * QUAD_WIDTH + (QUAD_WIDTH / 2);
- x_off = x * QUAD_WIDTH + (QUAD_WIDTH / 2);
-
- cogl_read_pixels (x_off, y_off, 1, 1,
- COGL_READ_PIXELS_COLOR_BUFFER,
- COGL_PIXEL_FORMAT_RGBA_8888_PRE,
- pixel);
- if (g_test_verbose ())
- g_print (" result = %02x, %02x, %02x, %02x\n",
- pixel[RED], pixel[GREEN], pixel[BLUE], pixel[ALPHA]);
-
- if (g_test_verbose ())
- g_print (" expected = %x, %x, %x, %x\n",
- r, g, b, a);
- /* FIXME - allow for hardware in-precision */
- g_assert (pixel[RED] == r);
- g_assert (pixel[GREEN] == g);
- g_assert (pixel[BLUE] == b);
-
- /* FIXME
- * We ignore the alpha, since we don't know if our render target is
- * RGB or RGBA */
- /* g_assert (pixel[ALPHA] == a); */
+ test_utils_check_pixel (x * QUAD_WIDTH + (QUAD_WIDTH / 2),
+ y * QUAD_WIDTH + (QUAD_WIDTH / 2),
+ color);
}
static void
@@ -104,9 +72,9 @@ test_material_with_primitives (TestState *state,
cogl_pop_matrix ();
- check_pixel (state, x, y, color);
- check_pixel (state, x, y+1, color);
- check_pixel (state, x, y+2, color);
+ check_quad (x, y, color);
+ check_quad (x, y+1, color);
+ check_quad (x, y+2, color);
}
static void
diff --git a/tests/conform/test-premult.c b/tests/conform/test-premult.c
index 6b73aca..8c3c929 100644
--- a/tests/conform/test-premult.c
+++ b/tests/conform/test-premult.c
@@ -25,29 +25,6 @@ typedef struct _TestState
CoglHandle passthrough_material;
} TestState;
-
-static void
-check_pixel (GLubyte *pixel, guint32 color)
-{
- guint8 r = MASK_RED (color);
- guint8 g = MASK_GREEN (color);
- guint8 b = MASK_BLUE (color);
- guint8 a = MASK_ALPHA (color);
-
- if (g_test_verbose ())
- g_print (" expected = %x, %x, %x, %x\n",
- r, g, b, a);
- /* FIXME - allow for hardware in-precision */
- g_assert (pixel[RED] == r);
- g_assert (pixel[GREEN] == g);
- g_assert (pixel[BLUE] == b);
-
- /* FIXME
- * We ignore the alpha, since we don't know if our render target is
- * RGB or RGBA */
- /* g_assert (pixel[ALPHA] == a); */
-}
-
static guchar *
gen_tex_data (guint32 color)
{
@@ -110,23 +87,7 @@ check_texture (TestState *state,
x * QUAD_WIDTH + QUAD_WIDTH,
y * QUAD_WIDTH + QUAD_WIDTH);
- /* See what we got... */
-
- y_off = y * QUAD_WIDTH + (QUAD_WIDTH / 2);
- x_off = x * QUAD_WIDTH + (QUAD_WIDTH / 2);
-
- cogl_read_pixels (x_off, y_off, 1, 1,
- COGL_READ_PIXELS_COLOR_BUFFER,
- COGL_PIXEL_FORMAT_RGBA_8888_PRE,
- pixel);
- if (g_test_verbose ())
- {
- g_print ("check texture (%d, %d):\n", x, y);
- g_print (" result = %02x, %02x, %02x, %02x\n",
- pixel[RED], pixel[GREEN], pixel[BLUE], pixel[ALPHA]);
- }
-
- check_pixel (pixel, expected_result);
+ test_utils_check_pixel (x_off, y_off, expected_result);
}
static void
diff --git a/tests/conform/test-utils.c b/tests/conform/test-utils.c
index 87c0437..b9d706f 100644
--- a/tests/conform/test-utils.c
+++ b/tests/conform/test-utils.c
@@ -78,3 +78,29 @@ test_utils_fini (TestUtilsGTestFixture *fixture,
if (state->ctx)
cogl_object_unref (state->ctx);
}
+
+void
+test_utils_check_pixel (int x, int y, guint32 expected_pixel)
+{
+ guint32 pixel;
+ char *screen_pixel;
+ char *intended_pixel;
+
+ cogl_read_pixels (x, y, 1, 1, COGL_READ_PIXELS_COLOR_BUFFER,
+ COGL_PIXEL_FORMAT_RGBA_8888_PRE,
+ (guint8 *) &pixel);
+
+ screen_pixel = g_strdup_printf ("#%06x", GUINT32_FROM_BE (pixel) >> 8);
+ intended_pixel = g_strdup_printf ("#%06x", expected_pixel >> 8);
+
+ g_assert_cmpstr (screen_pixel, ==, intended_pixel);
+
+ g_free (screen_pixel);
+ g_free (intended_pixel);
+}
+
+void
+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));
+}
diff --git a/tests/conform/test-utils.h b/tests/conform/test-utils.h
index 9325051..225c793 100644
--- a/tests/conform/test-utils.h
+++ b/tests/conform/test-utils.h
@@ -38,4 +38,35 @@ void
test_utils_fini (TestUtilsGTestFixture *fixture,
const void *data);
+/*
+ * test_utils_check_pixel:
+ * @x: x co-ordinate of the pixel to test
+ * @y: y co-ordinate of the pixel to test
+ * @pixel: An integer of the form 0xRRGGBBAA representing the expected
+ * pixel value
+ *
+ * This performs reads a pixel on 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_pixel (int x, int y, guint32 expected_pixel);
+
+/*
+ * test_utils_check_pixel:
+ * @x: x co-ordinate of the pixel to test
+ * @y: y co-ordinate of the pixel to test
+ * @pixel: An integer of the form 0xrrggbb representing the expected pixel value
+ *
+ * This performs reads a pixel on 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_pixel_rgb (int x, int y, int r, int g, int b);
+
#endif /* _TEST_UTILS_H_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]