tests: Add a test for the RGB <-> HSL functions
Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 32d67c2bf40641b2d1d30fa2d994013c3e6ce5bc)
This commit is contained in:
parent
5858cac873
commit
1c3cd74211
@ -29,6 +29,7 @@ test_sources = \
|
||||
test-blend-strings.c \
|
||||
test-blend.c \
|
||||
test-depth-test.c \
|
||||
test-color-hsl.c \
|
||||
test-color-mask.c \
|
||||
test-backface-culling.c \
|
||||
test-just-vertex-shader.c \
|
||||
|
45
tests/conform/test-color-hsl.c
Normal file
45
tests/conform/test-color-hsl.c
Normal file
@ -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);
|
||||
|
||||
g_assert_cmpint (color.red, ==, 108);
|
||||
g_assert_cmpint (color.green, ==, 198);
|
||||
g_assert_cmpint (color.blue, ==, 78);
|
||||
g_assert_cmpint (color.alpha, ==, 255);
|
||||
|
||||
memset(&color, 0, sizeof (CoglColor));
|
||||
cogl_color_init_from_hsl(&color, hue, 0, luminance);
|
||||
|
||||
cogl_assert_float(color.red / 255.0f, luminance);
|
||||
cogl_assert_float(color.green / 255.0f, luminance);
|
||||
cogl_assert_float(color.blue / 255.0f, luminance);
|
||||
cogl_assert_float(color.alpha / 255.0f, 1.0f);
|
||||
|
||||
if (cogl_test_verbose ())
|
||||
g_print ("OK\n");
|
||||
}
|
@ -135,6 +135,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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user