diff options
author | Damien Lespiau <damien.lespiau@intel.com> | 2013-05-14 21:26:30 +0100 |
---|---|---|
committer | Damien Lespiau <damien.lespiau@intel.com> | 2013-05-29 21:42:20 +0100 |
commit | 32d67c2bf40641b2d1d30fa2d994013c3e6ce5bc (patch) | |
tree | 79254d794c52655ca73a734448d8d5385cf5fe8f /tests | |
parent | edcbeaf3c941f7a2335fbec47d5248cd9b0e8088 (diff) | |
download | cogl-32d67c2bf40641b2d1d30fa2d994013c3e6ce5bc.tar.gz |
tests: Add a test for the RGB <-> HSL functions
Reviewed-by: Robert Bragg <robert@linux.intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/conform/Makefile.am | 1 | ||||
-rw-r--r-- | tests/conform/test-color-hsl.c | 45 | ||||
-rw-r--r-- | tests/conform/test-conform-main.c | 1 |
3 files changed, 47 insertions, 0 deletions
diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am index 4bb732d0..8b73c53f 100644 --- a/tests/conform/Makefile.am +++ b/tests/conform/Makefile.am @@ -29,6 +29,7 @@ test_sources = \ test-atlas-migration.c \ test-blend-strings.c \ test-depth-test.c \ + test-color-hsl.c \ test-color-mask.c \ test-backface-culling.c \ test-just-vertex-shader.c \ diff --git a/tests/conform/test-color-hsl.c b/tests/conform/test-color-hsl.c new file mode 100644 index 00000000..8c51cd9e --- /dev/null +++ b/tests/conform/test-color-hsl.c @@ -0,0 +1,45 @@ +#include <math.h> +#include <string.h> + +#include <cogl/cogl.h> + +#include "test-utils.h" + +#define cogl_assert_float(a, b) \ + do { \ + if (fabsf ((a) - (b)) >= 0.0001f) \ + g_assert_cmpfloat ((a), ==, (b)); \ + } while (0) + +void +test_color_hsl (void) +{ + CoglColor color; + float hue, saturation, luminance; + + cogl_color_init_from_4ub(&color, 108, 198, 78, 255); + cogl_color_to_hsl(&color, &hue, &saturation, &luminance); + + cogl_assert_float(hue, 105.f); + cogl_assert_float(saturation, 0.512821); + cogl_assert_float(luminance, 0.541176); + + memset(&color, 0, sizeof (CoglColor)); + cogl_color_init_from_hsl(&color, hue, saturation, luminance); + + cogl_assert_float(color.red, 108.0f / 255.0f); + cogl_assert_float(color.green, 198.0f / 255.0f); + cogl_assert_float(color.blue, 78.0f / 255.0f); + cogl_assert_float(color.alpha, 1.0f); + + memset(&color, 0, sizeof (CoglColor)); + cogl_color_init_from_hsl(&color, hue, 0, luminance); + + cogl_assert_float(color.red, luminance); + cogl_assert_float(color.green, luminance); + cogl_assert_float(color.blue, luminance); + cogl_assert_float(color.alpha, 1.0f); + + if (cogl_test_verbose ()) + g_print ("OK\n"); +} diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c index 569985f0..671d0b24 100644 --- a/tests/conform/test-conform-main.c +++ b/tests/conform/test-conform-main.c @@ -133,6 +133,7 @@ main (int argc, char **argv) 0); ADD_TEST (test_euler_quaternion, 0, 0); + ADD_TEST (test_color_hsl, 0, 0); ADD_TEST (test_fence, TEST_REQUIREMENT_FENCE, 0); |