tests: Move color conform tests from clutter
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3544>
This commit is contained in:
parent
93ded65b7d
commit
e93fe16241
@ -32,7 +32,6 @@ clutter_conform_tests_classes_tests = [
|
||||
|
||||
clutter_conform_tests_general_tests = [
|
||||
'binding-pool',
|
||||
'color',
|
||||
'event-delivery',
|
||||
'frame-clock',
|
||||
'frame-clock-timeline',
|
||||
|
@ -3,7 +3,7 @@ cogl_tests = [
|
||||
[ 'test-blend-strings', [] ],
|
||||
[ 'test-blend', [] ],
|
||||
[ 'test-depth-test', [] ],
|
||||
[ 'test-color-hsl', [] ],
|
||||
[ 'test-color', [] ],
|
||||
[ 'test-backface-culling', [] ],
|
||||
[ 'test-just-vertex-shader', [] ],
|
||||
[ 'test-pipeline-user-matrix', [] ],
|
||||
|
@ -1,53 +0,0 @@
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <cogl/cogl.h>
|
||||
|
||||
#include "tests/cogl-test-utils.h"
|
||||
|
||||
#define TEST_CASE_EPSILON 0.0001
|
||||
|
||||
static void
|
||||
test_color_hsl (void)
|
||||
{
|
||||
CoglColor color;
|
||||
float hue, saturation, luminance;
|
||||
|
||||
cogl_color_init_from_4f (&color, 108.0 / 255.0, 198 / 255.0, 78.0 / 255.0, 1.0);
|
||||
cogl_color_to_hsl(&color, &hue, &saturation, &luminance);
|
||||
|
||||
g_assert_cmpfloat_with_epsilon (hue, 105.f, TEST_CASE_EPSILON);
|
||||
g_assert_cmpfloat_with_epsilon (saturation, 0.512821, TEST_CASE_EPSILON);
|
||||
g_assert_cmpfloat_with_epsilon (luminance, 0.541176, TEST_CASE_EPSILON);
|
||||
|
||||
memset(&color, 0, sizeof (CoglColor));
|
||||
cogl_color_init_from_hsl (&color, hue, saturation, luminance);
|
||||
|
||||
g_assert_cmpfloat_with_epsilon (cogl_color_get_red (&color), 108.0 / 255.0,
|
||||
TEST_CASE_EPSILON);
|
||||
g_assert_cmpfloat_with_epsilon (cogl_color_get_green (&color), 198.0 / 255.0,
|
||||
TEST_CASE_EPSILON);
|
||||
g_assert_cmpfloat_with_epsilon (cogl_color_get_blue (&color), 78.0 / 255.0,
|
||||
TEST_CASE_EPSILON);
|
||||
g_assert_cmpfloat_with_epsilon (cogl_color_get_alpha (&color), 1.0,
|
||||
TEST_CASE_EPSILON);
|
||||
|
||||
memset(&color, 0, sizeof (CoglColor));
|
||||
cogl_color_init_from_hsl (&color, hue, 0, luminance);
|
||||
|
||||
g_assert_cmpfloat_with_epsilon (cogl_color_get_red (&color), luminance,
|
||||
TEST_CASE_EPSILON);
|
||||
g_assert_cmpfloat_with_epsilon (cogl_color_get_green (&color), luminance,
|
||||
TEST_CASE_EPSILON);
|
||||
g_assert_cmpfloat_with_epsilon (cogl_color_get_blue (&color), luminance,
|
||||
TEST_CASE_EPSILON);
|
||||
g_assert_cmpfloat_with_epsilon (cogl_color_get_alpha (&color), 1.0,
|
||||
TEST_CASE_EPSILON);
|
||||
|
||||
if (cogl_test_verbose ())
|
||||
g_print ("OK\n");
|
||||
}
|
||||
|
||||
COGL_TEST_SUITE (
|
||||
g_test_add_func ("/color/hsl", test_color_hsl);
|
||||
)
|
@ -1,20 +1,66 @@
|
||||
#include <clutter/clutter.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tests/clutter-test-utils.h"
|
||||
#include <cogl/cogl.h>
|
||||
|
||||
#include "tests/cogl-test-utils.h"
|
||||
|
||||
#define TEST_CASE_EPSILON 0.0001
|
||||
|
||||
static void
|
||||
test_color_hsl (void)
|
||||
{
|
||||
CoglColor color;
|
||||
float hue, saturation, luminance;
|
||||
|
||||
cogl_color_init_from_4f (&color, 108.0 / 255.0, 198 / 255.0, 78.0 / 255.0, 1.0);
|
||||
cogl_color_to_hsl (&color, &hue, &saturation, &luminance);
|
||||
|
||||
g_assert_cmpfloat_with_epsilon (hue, 105.f, TEST_CASE_EPSILON);
|
||||
g_assert_cmpfloat_with_epsilon (saturation, 0.512821, TEST_CASE_EPSILON);
|
||||
g_assert_cmpfloat_with_epsilon (luminance, 0.541176, TEST_CASE_EPSILON);
|
||||
|
||||
memset (&color, 0, sizeof (CoglColor));
|
||||
cogl_color_init_from_hsl (&color, hue, saturation, luminance);
|
||||
|
||||
g_assert_cmpfloat_with_epsilon (cogl_color_get_red (&color), 108.0 / 255.0,
|
||||
TEST_CASE_EPSILON);
|
||||
g_assert_cmpfloat_with_epsilon (cogl_color_get_green (&color), 198.0 / 255.0,
|
||||
TEST_CASE_EPSILON);
|
||||
g_assert_cmpfloat_with_epsilon (cogl_color_get_blue (&color), 78.0 / 255.0,
|
||||
TEST_CASE_EPSILON);
|
||||
g_assert_cmpfloat_with_epsilon (cogl_color_get_alpha (&color), 1.0,
|
||||
TEST_CASE_EPSILON);
|
||||
|
||||
memset (&color, 0, sizeof (CoglColor));
|
||||
cogl_color_init_from_hsl (&color, hue, 0, luminance);
|
||||
|
||||
g_assert_cmpfloat_with_epsilon (cogl_color_get_red (&color), luminance,
|
||||
TEST_CASE_EPSILON);
|
||||
g_assert_cmpfloat_with_epsilon (cogl_color_get_green (&color), luminance,
|
||||
TEST_CASE_EPSILON);
|
||||
g_assert_cmpfloat_with_epsilon (cogl_color_get_blue (&color), luminance,
|
||||
TEST_CASE_EPSILON);
|
||||
g_assert_cmpfloat_with_epsilon (cogl_color_get_alpha (&color), 1.0,
|
||||
TEST_CASE_EPSILON);
|
||||
|
||||
if (cogl_test_verbose ())
|
||||
g_print ("OK\n");
|
||||
}
|
||||
|
||||
static void
|
||||
color_hls_roundtrip (void)
|
||||
{
|
||||
ClutterColor color;
|
||||
CoglColor color;
|
||||
gfloat hue, luminance, saturation;
|
||||
|
||||
/* test luminance only */
|
||||
clutter_color_from_string (&color, "#7f7f7f");
|
||||
cogl_color_from_string (&color, "#7f7f7f");
|
||||
g_assert_cmpuint (color.red, ==, 0x7f);
|
||||
g_assert_cmpuint (color.green, ==, 0x7f);
|
||||
g_assert_cmpuint (color.blue, ==, 0x7f);
|
||||
|
||||
clutter_color_to_hls (&color, &hue, &luminance, &saturation);
|
||||
cogl_color_to_hsl (&color, &hue, &saturation, &luminance);
|
||||
g_assert_cmpfloat (hue, ==, 0.0);
|
||||
g_assert (luminance >= 0.0 && luminance <= 1.0);
|
||||
g_assert_cmpfloat (saturation, ==, 0.0);
|
||||
@ -30,21 +76,21 @@ color_hls_roundtrip (void)
|
||||
}
|
||||
|
||||
color.red = color.green = color.blue = 0;
|
||||
clutter_color_from_hls (&color, hue, luminance, saturation);
|
||||
cogl_color_init_from_hsl (&color, hue, saturation, luminance);
|
||||
|
||||
g_assert_cmpuint (color.red, ==, 0x7f);
|
||||
g_assert_cmpuint (color.green, ==, 0x7f);
|
||||
g_assert_cmpuint (color.blue, ==, 0x7f);
|
||||
|
||||
/* full conversion */
|
||||
clutter_color_from_string (&color, "#7f8f7f");
|
||||
cogl_color_from_string (&color, "#7f8f7f");
|
||||
color.alpha = 255;
|
||||
|
||||
g_assert_cmpuint (color.red, ==, 0x7f);
|
||||
g_assert_cmpuint (color.green, ==, 0x8f);
|
||||
g_assert_cmpuint (color.blue, ==, 0x7f);
|
||||
|
||||
clutter_color_to_hls (&color, &hue, &luminance, &saturation);
|
||||
cogl_color_to_hsl (&color, &hue, &saturation, &luminance);
|
||||
g_assert (hue >= 0.0 && hue < 360.0);
|
||||
g_assert (luminance >= 0.0 && luminance <= 1.0);
|
||||
g_assert (saturation >= 0.0 && saturation <= 1.0);
|
||||
@ -60,7 +106,7 @@ color_hls_roundtrip (void)
|
||||
}
|
||||
|
||||
color.red = color.green = color.blue = 0;
|
||||
clutter_color_from_hls (&color, hue, luminance, saturation);
|
||||
cogl_color_init_from_hsl (&color, hue, saturation, luminance);
|
||||
|
||||
g_assert_cmpuint (color.red, ==, 0x7f);
|
||||
g_assert_cmpuint (color.green, ==, 0x8f);
|
||||
@ -73,25 +119,25 @@ color_hls_roundtrip (void)
|
||||
static void
|
||||
color_from_string_invalid (void)
|
||||
{
|
||||
ClutterColor color;
|
||||
CoglColor color;
|
||||
|
||||
g_assert (!clutter_color_from_string (&color, "ff0000ff"));
|
||||
g_assert (!clutter_color_from_string (&color, "#decaffbad"));
|
||||
g_assert (!clutter_color_from_string (&color, "ponies"));
|
||||
g_assert (!clutter_color_from_string (&color, "rgb(255, 0, 0, 0)"));
|
||||
g_assert (!clutter_color_from_string (&color, "rgba(1.0, 0, 0)"));
|
||||
g_assert (!clutter_color_from_string (&color, "hsl(100, 0, 0)"));
|
||||
g_assert (!clutter_color_from_string (&color, "hsla(10%, 0%, 50%)"));
|
||||
g_assert (!clutter_color_from_string (&color, "hsla(100%, 0%, 50%, 20%)"));
|
||||
g_assert (!clutter_color_from_string (&color, "hsla(0.5, 0.9, 0.2, 0.4)"));
|
||||
g_assert (!cogl_color_from_string (&color, "ff0000ff"));
|
||||
g_assert (!cogl_color_from_string (&color, "#decaffbad"));
|
||||
g_assert (!cogl_color_from_string (&color, "ponies"));
|
||||
g_assert (!cogl_color_from_string (&color, "rgb(255, 0, 0, 0)"));
|
||||
g_assert (!cogl_color_from_string (&color, "rgba(1.0, 0, 0)"));
|
||||
g_assert (!cogl_color_from_string (&color, "hsl(100, 0, 0)"));
|
||||
g_assert (!cogl_color_from_string (&color, "hsla(10%, 0%, 50%)"));
|
||||
g_assert (!cogl_color_from_string (&color, "hsla(100%, 0%, 50%, 20%)"));
|
||||
g_assert (!cogl_color_from_string (&color, "hsla(0.5, 0.9, 0.2, 0.4)"));
|
||||
}
|
||||
|
||||
static void
|
||||
color_from_string_valid (void)
|
||||
{
|
||||
ClutterColor color;
|
||||
CoglColor color;
|
||||
|
||||
g_assert (clutter_color_from_string (&color, "#ff0000ff"));
|
||||
g_assert (cogl_color_from_string (&color, "#ff0000ff"));
|
||||
if (!g_test_quiet ())
|
||||
{
|
||||
g_print ("color = { %x, %x, %x, %x }, expected = { 0xff, 0, 0, 0xff }\n",
|
||||
@ -105,7 +151,7 @@ color_from_string_valid (void)
|
||||
g_assert_cmpuint (color.blue, ==, 0);
|
||||
g_assert_cmpuint (color.alpha, ==, 0xff);
|
||||
|
||||
g_assert (clutter_color_from_string (&color, "#0f0f"));
|
||||
g_assert (cogl_color_from_string (&color, "#0f0f"));
|
||||
if (!g_test_quiet ())
|
||||
{
|
||||
g_print ("color = { %x, %x, %x, %x }, expected = { 0, 0xff, 0, 0xff }\n",
|
||||
@ -119,7 +165,7 @@ color_from_string_valid (void)
|
||||
g_assert_cmpuint (color.blue, ==, 0);
|
||||
g_assert_cmpuint (color.alpha, ==, 0xff);
|
||||
|
||||
g_assert (clutter_color_from_string (&color, "#0000ff"));
|
||||
g_assert (cogl_color_from_string (&color, "#0000ff"));
|
||||
if (!g_test_quiet ())
|
||||
{
|
||||
g_print ("color = { %x, %x, %x, %x }, expected = { 0, 0, 0xff, 0xff }\n",
|
||||
@ -133,7 +179,7 @@ color_from_string_valid (void)
|
||||
g_assert_cmpuint (color.blue, ==, 0xff);
|
||||
g_assert_cmpuint (color.alpha, ==, 0xff);
|
||||
|
||||
g_assert (clutter_color_from_string (&color, "#abc"));
|
||||
g_assert (cogl_color_from_string (&color, "#abc"));
|
||||
if (!g_test_quiet ())
|
||||
{
|
||||
g_print ("color = { %x, %x, %x, %x }, expected = { 0xaa, 0xbb, 0xcc, 0xff }\n",
|
||||
@ -147,7 +193,7 @@ color_from_string_valid (void)
|
||||
g_assert_cmpuint (color.blue, ==, 0xcc);
|
||||
g_assert_cmpuint (color.alpha, ==, 0xff);
|
||||
|
||||
g_assert (clutter_color_from_string (&color, "#123abc"));
|
||||
g_assert (cogl_color_from_string (&color, "#123abc"));
|
||||
if (!g_test_quiet ())
|
||||
{
|
||||
g_print ("color = { %x, %x, %x, %x }, expected = { 0x12, 0x3a, 0xbc, 0xff }\n",
|
||||
@ -161,7 +207,7 @@ color_from_string_valid (void)
|
||||
g_assert (color.blue == 0xbc);
|
||||
g_assert (color.alpha == 0xff);
|
||||
|
||||
g_assert (clutter_color_from_string (&color, "rgb(255, 128, 64)"));
|
||||
g_assert (cogl_color_from_string (&color, "rgb(255, 128, 64)"));
|
||||
if (!g_test_quiet ())
|
||||
{
|
||||
g_print ("color = { %x, %x, %x, %x }, expected = { 255, 128, 64, 255 }\n",
|
||||
@ -175,7 +221,7 @@ color_from_string_valid (void)
|
||||
g_assert_cmpuint (color.blue, ==, 64);
|
||||
g_assert_cmpuint (color.alpha, ==, 255);
|
||||
|
||||
g_assert (clutter_color_from_string (&color, "rgba ( 30%, 0, 25%, 0.5 ) "));
|
||||
g_assert (cogl_color_from_string (&color, "rgba ( 30%, 0, 25%, 0.5 ) "));
|
||||
if (!g_test_quiet ())
|
||||
{
|
||||
g_print ("color = { %x, %x, %x, %x }, expected = { %.1f, 0, %.1f, 128 }\n",
|
||||
@ -191,7 +237,7 @@ color_from_string_valid (void)
|
||||
g_assert_cmpuint (color.blue, ==, (255.0 / 100.0 * 25.0));
|
||||
g_assert_cmpuint (color.alpha, ==, 127);
|
||||
|
||||
g_assert (clutter_color_from_string (&color, "rgb( 50%, -50%, 150% )"));
|
||||
g_assert (cogl_color_from_string (&color, "rgb( 50%, -50%, 150% )"));
|
||||
if (!g_test_quiet ())
|
||||
{
|
||||
g_print ("color = { %x, %x, %x, %x }, expected = { 127, 0, 255, 255 }\n",
|
||||
@ -205,7 +251,7 @@ color_from_string_valid (void)
|
||||
g_assert_cmpuint (color.blue, ==, 255);
|
||||
g_assert_cmpuint (color.alpha, ==, 255);
|
||||
|
||||
g_assert (clutter_color_from_string (&color, "hsl( 0, 100%, 50% )"));
|
||||
g_assert (cogl_color_from_string (&color, "hsl( 0, 100%, 50% )"));
|
||||
if (!g_test_quiet ())
|
||||
{
|
||||
g_print ("color = { %x, %x, %x, %x }, expected = { 255, 0, 0, 255 }\n",
|
||||
@ -219,9 +265,9 @@ color_from_string_valid (void)
|
||||
g_assert_cmpuint (color.blue, ==, 0);
|
||||
g_assert_cmpuint (color.alpha, ==, 255);
|
||||
|
||||
g_assert (clutter_color_from_string (&color, "hsl( 0, 100%, 50% )"));
|
||||
g_assert (cogl_color_from_string (&color, "hsl( 0, 100%, 50% )"));
|
||||
|
||||
g_assert (clutter_color_from_string (&color, "hsla( 0, 100%, 50%, 0.5 )"));
|
||||
g_assert (cogl_color_from_string (&color, "hsla( 0, 100%, 50%, 0.5 )"));
|
||||
if (!g_test_quiet ())
|
||||
{
|
||||
g_print ("color = { %x, %x, %x, %x }, expected = { 255, 0, 0, 127 }\n",
|
||||
@ -236,13 +282,13 @@ color_from_string_valid (void)
|
||||
g_assert_cmpuint (color.alpha, ==, 127);
|
||||
|
||||
g_test_bug ("662818");
|
||||
g_assert (clutter_color_from_string (&color, "hsla(0,100%,50% , 0.5)"));
|
||||
g_assert (cogl_color_from_string (&color, "hsla(0,100%,50% , 0.5)"));
|
||||
}
|
||||
|
||||
static void
|
||||
color_to_string (void)
|
||||
{
|
||||
ClutterColor color;
|
||||
CoglColor color;
|
||||
gchar *str;
|
||||
|
||||
color.red = 0xcc;
|
||||
@ -250,16 +296,16 @@ color_to_string (void)
|
||||
color.blue = 0xcc;
|
||||
color.alpha = 0x22;
|
||||
|
||||
str = clutter_color_to_string (&color);
|
||||
str = cogl_color_to_string (&color);
|
||||
g_assert_cmpstr (str, ==, "#cccccc22");
|
||||
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
|
||||
CLUTTER_TEST_SUITE (
|
||||
CLUTTER_TEST_UNIT ("/color/hls-roundtrip", color_hls_roundtrip)
|
||||
CLUTTER_TEST_UNIT ("/color/from-string/invalid", color_from_string_invalid)
|
||||
CLUTTER_TEST_UNIT ("/color/from-string/valid", color_from_string_valid)
|
||||
CLUTTER_TEST_UNIT ("/color/to-string", color_to_string)
|
||||
COGL_TEST_SUITE (
|
||||
g_test_add_func ("/color/hsl", test_color_hsl);
|
||||
g_test_add_func ("/color/hls-roundtrip", color_hls_roundtrip);
|
||||
g_test_add_func ("/color/from-string/invalid", color_from_string_invalid);
|
||||
g_test_add_func ("/color/from-string/valid", color_from_string_valid);
|
||||
g_test_add_func ("/color/to-string", color_to_string);
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user