mutter/tests/conform/test-utils.h
Neil Roberts e69e41b2c7 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>
2011-10-26 18:57:33 +01:00

73 lines
2.3 KiB
C

#ifndef _TEST_UTILS_H_
#define _TEST_UTILS_H_
/* This fixture structure is allocated by glib, and before running
* each test we get a callback to initialize it.
*
* Actually we don't use this currently, we instead manage our own
* TestUtilsSharedState structure which also gets passed as a private
* data argument to the same initialization callback. The advantage of
* allocating our own shared state structure is that we can put data
* in it before we start running anything.
*/
typedef struct _TestUtilsGTestFixture
{
/**/
int dummy;
} TestUtilsGTestFixture;
/* Stuff you put in here is setup once in main() and gets passed around to
* all test functions and fixture setup/teardown functions in the data
* argument */
typedef struct _TestUtilsSharedState
{
int *argc_addr;
char ***argv_addr;
void (* todo_func) (TestUtilsGTestFixture *, void *data);
CoglContext *ctx;
CoglFramebuffer *fb;
} TestUtilsSharedState;
void
test_utils_init (TestUtilsGTestFixture *fixture,
const void *data);
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_ */