diff --git a/tests/conform/test-utils.c b/tests/conform/test-utils.c index b39dd1136..99d692613 100644 --- a/tests/conform/test-utils.c +++ b/tests/conform/test-utils.c @@ -173,6 +173,29 @@ compare_component (int a, int b) return ABS (a - b) <= 1; } +void +test_utils_compare_pixel_and_alpha (const uint8_t *screen_pixel, + uint32_t expected_pixel) +{ + /* Compare each component with a small fuzz factor */ + if (!compare_component (screen_pixel[0], expected_pixel >> 24) || + !compare_component (screen_pixel[1], (expected_pixel >> 16) & 0xff) || + !compare_component (screen_pixel[2], (expected_pixel >> 8) & 0xff) || + !compare_component (screen_pixel[3], (expected_pixel >> 0) & 0xff)) + { + uint32_t screen_pixel_num = GUINT32_FROM_BE (*(uint32_t *) screen_pixel); + char *screen_pixel_string = + g_strdup_printf ("#%08x", screen_pixel_num); + char *expected_pixel_string = + g_strdup_printf ("#%08x", expected_pixel); + + g_assert_cmpstr (screen_pixel_string, ==, expected_pixel_string); + + g_free (screen_pixel_string); + g_free (expected_pixel_string); + } +} + void test_utils_compare_pixel (const uint8_t *screen_pixel, uint32_t expected_pixel) { diff --git a/tests/conform/test-utils.h b/tests/conform/test-utils.h index e698f3248..3f9cdc6ae 100644 --- a/tests/conform/test-utils.h +++ b/tests/conform/test-utils.h @@ -102,6 +102,19 @@ test_utils_check_region (CoglFramebuffer *framebuffer, void test_utils_compare_pixel (const uint8_t *screen_pixel, uint32_t expected_pixel); +/* + * test_utils_compare_pixel_and_alpha: + * @screen_pixel: A pixel stored in memory + * @expected_pixel: The expected RGBA value + * + * Compares a pixel from a buffer to an expected value. This is + * similar to test_utils_compare_pixel() except that it doesn't ignore + * the alpha component. + */ +void +test_utils_compare_pixel_and_alpha (const uint8_t *screen_pixel, + uint32_t expected_pixel); + /* * test_utils_create_color_texture: * @context: A #CoglContext diff --git a/tests/conform/test-write-texture-formats.c b/tests/conform/test-write-texture-formats.c index 03d8a88fa..859f4b4b8 100644 --- a/tests/conform/test-write-texture-formats.c +++ b/tests/conform/test-write-texture-formats.c @@ -12,22 +12,14 @@ static void test_color (CoglTexture *texture, uint32_t expected_pixel) { - uint32_t received_pixel; - char *received_value_str; - char *expected_value_str; + uint8_t received_pixel[4]; cogl_texture_get_data (texture, COGL_PIXEL_FORMAT_RGBA_8888_PRE, 4, /* rowstride */ - (uint8_t *) &received_pixel); + received_pixel); - received_pixel = GUINT32_FROM_BE (received_pixel); - - received_value_str = g_strdup_printf ("0x%08x", received_pixel); - expected_value_str = g_strdup_printf ("0x%08x", expected_pixel); - g_assert_cmpstr (received_value_str, ==, expected_value_str); - g_free (received_value_str); - g_free (expected_value_str); + test_utils_compare_pixel_and_alpha (received_pixel, expected_pixel); } static void