From 9a8a26270cb37d2448b4d219b6ab058dec106ea3 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Mon, 21 Jan 2013 18:43:24 +0000 Subject: [PATCH] test-write-texture-formats: Add fuzziness to the pixel comparisons The rounding used when storing 10-bit per component data into an 8-bit per component texture seems to have changed in recent versions of Mesa which was causing this test to fail. I've also noticed this failing on the NVidia binary driver. This patch adds some fuzziness to the comparison so that it will pass. There is a new test_utils function called test_utils_compare_pixel_and_alpha which is the same as test_utils_compare_pixel except that it also compares the alpha component. Reviewed-by: Robert Bragg (cherry picked from commit ce626fb3939b0f200d85ccdf32809608b879212d) --- tests/conform/test-utils.c | 23 ++++++++++++++++++++++ tests/conform/test-utils.h | 13 ++++++++++++ tests/conform/test-write-texture-formats.c | 14 +++---------- 3 files changed, 39 insertions(+), 11 deletions(-) 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