diff options
author | Neil Roberts <neil@linux.intel.com> | 2013-01-21 18:43:24 +0000 |
---|---|---|
committer | Robert Bragg <robert@linux.intel.com> | 2013-01-22 18:00:11 +0000 |
commit | 9a8a26270cb37d2448b4d219b6ab058dec106ea3 (patch) | |
tree | 709ea69e53fc51addaa5612f30bfbcefc1aa78a7 | |
parent | 364f2325079e7cc453a3b923b8e41da28fb0276d (diff) | |
download | cogl-9a8a26270cb37d2448b4d219b6ab058dec106ea3.tar.gz |
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 <robert@linux.intel.com>
(cherry picked from commit ce626fb3939b0f200d85ccdf32809608b879212d)
-rw-r--r-- | tests/conform/test-utils.c | 23 | ||||
-rw-r--r-- | tests/conform/test-utils.h | 13 | ||||
-rw-r--r-- | 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 b39dd113..99d69261 100644 --- a/tests/conform/test-utils.c +++ b/tests/conform/test-utils.c @@ -174,6 +174,29 @@ compare_component (int a, int b) } 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) { /* Compare each component with a small fuzz factor */ diff --git a/tests/conform/test-utils.h b/tests/conform/test-utils.h index e698f324..3f9cdc6a 100644 --- a/tests/conform/test-utils.h +++ b/tests/conform/test-utils.h @@ -103,6 +103,19 @@ 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 * @color: A color to put in the texture diff --git a/tests/conform/test-write-texture-formats.c b/tests/conform/test-write-texture-formats.c index 03d8a88f..859f4b4b 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 |