[Cogl] [PATCH 2/2] tests: Add a test for the RGB <-> HSL functions

Robert Bragg robert at sixbynine.org
Tue May 28 06:46:06 PDT 2013


It looks like this doesn't catch that the alpha component isn't
currently initialized by _init_from_hsl() because the first test of
_to_hsl inadvertently ends up initializing the alpha component before
the next test.

Maybe we should explicitly initialize the color with zeros before
testing _init_from_hsl().

Apart from that, the test looks good to land to me:

Reviewed-by: Robert Bragg <robert at linux.intel.com>

thanks,
- robert

On Thu, May 23, 2013 at 3:45 PM, Damien Lespiau
<damien.lespiau at intel.com> wrote:
> ---
>  tests/conform/Makefile.am         |  1 +
>  tests/conform/test-color-hsl.c    | 35 +++++++++++++++++++++++++++++++++++
>  tests/conform/test-conform-main.c |  1 +
>  3 files changed, 37 insertions(+)
>  create mode 100644 tests/conform/test-color-hsl.c
>
> diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
> index d5c25db..009a43a 100644
> --- a/tests/conform/Makefile.am
> +++ b/tests/conform/Makefile.am
> @@ -30,6 +30,7 @@ test_sources = \
>         test-bitmask.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 0000000..b20742e
> --- /dev/null
> +++ b/tests/conform/test-color-hsl.c
> @@ -0,0 +1,35 @@
> +#include <math.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);
> +
> +  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);
> +
> +  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 9345065..1cb0094 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);
>
>    g_printerr ("Unknown test name \"%s\"\n", argv[1]);
>
> --
> 1.8.1.4
>
> _______________________________________________
> Cogl mailing list
> Cogl at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/cogl


More information about the Cogl mailing list