[gtk/matthiasc/color-profile-rebased: 51/51] Add a test for color conversion
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/color-profile-rebased: 51/51] Add a test for color conversion
- Date: Sat, 1 Oct 2022 01:36:44 +0000 (UTC)
commit 6cb33000093e9afb520bbde80a376f081080ef01
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Sep 30 20:57:52 2022 -0400
Add a test for color conversion
testsuite/gdk/color.c | 43 +++++++++++++++++++++++++++++++++++++++++++
testsuite/gdk/meson.build | 1 +
2 files changed, 44 insertions(+)
---
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]