diff options
author | Matthias Clasen <mclasen@redhat.com> | 2022-09-30 20:57:52 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-09-30 20:57:52 -0400 |
commit | 6cb33000093e9afb520bbde80a376f081080ef01 (patch) | |
tree | 12b97d809915b3571b11c2752b0eb4eb380126af | |
parent | fde2fefbcd74f7f463a0274987c2698cc07f26f3 (diff) | |
download | gtk+-matthiasc/color-profile-rebased.tar.gz |
Add a test for color conversionmatthiasc/color-profile-rebased
-rw-r--r-- | testsuite/gdk/color.c | 43 | ||||
-rw-r--r-- | testsuite/gdk/meson.build | 1 |
2 files changed, 44 insertions, 0 deletions
diff --git a/testsuite/gdk/color.c b/testsuite/gdk/color.c new file mode 100644 index 0000000000..48b70a3ceb --- /dev/null +++ b/testsuite/gdk/color.c @@ -0,0 +1,43 @@ +#include <gdk/gdk.h> +#include <gdk/gdkcolorprivate.h> +#include <gdk/gdkcolorspaceprivate.h> + +static void +test_roundtrip_srgb (void) +{ + GdkColorSpace *srgb = gdk_color_space_get_srgb (); + GdkColorSpace *srgb_linear = gdk_color_space_get_srgb_linear (); + GdkColor orig; + GdkColor linear; + GdkColor back; + GdkRGBA rgba; + + for (int i = 0; i < 1000; i++) + { + rgba.red = g_test_rand_double_range (0., 1.); + rgba.green = g_test_rand_double_range (0., 1.); + rgba.blue = g_test_rand_double_range (0., 1.); + rgba.alpha = g_test_rand_double_range (0., 1.); + + gdk_color_init_from_rgba (&orig, &rgba); + + gdk_color_convert (&linear, srgb_linear, &orig); + gdk_color_convert (&back, srgb, &linear); + + g_assert_true (gdk_color_space_equal (gdk_color_get_color_space (&orig), gdk_color_get_color_space (&back))); + g_assert_cmpfloat_with_epsilon (gdk_color_get_alpha (&orig), gdk_color_get_alpha (&back), 0.0001); + g_assert_cmpfloat_with_epsilon (gdk_color_get_components (&orig)[0], gdk_color_get_components (&back)[0], 0.0001); + g_assert_cmpfloat_with_epsilon (gdk_color_get_components (&orig)[1], gdk_color_get_components (&back)[1], 0.0001); + g_assert_cmpfloat_with_epsilon (gdk_color_get_components (&orig)[2], gdk_color_get_components (&back)[2], 0.0001); + } +} + +int +main (int argc, char *argv[]) +{ + (g_test_init) (&argc, &argv, NULL); + + g_test_add_func ("/color/roundtrip-srgb", test_roundtrip_srgb); + + return g_test_run (); +} diff --git a/testsuite/gdk/meson.build b/testsuite/gdk/meson.build index e8bc9c88f9..59e860e43c 100644 --- a/testsuite/gdk/meson.build +++ b/testsuite/gdk/meson.build @@ -56,6 +56,7 @@ endforeach internal_tests = [ 'image', 'texture', + 'color' ] foreach t : internal_tests |