[gtk/curve-ops: 4/17] Add curve eval tests
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/curve-ops: 4/17] Add curve eval tests
- Date: Tue, 8 Dec 2020 19:18:17 +0000 (UTC)
commit b09bebb9eed19b49305aa8d8c4572bb3d1d43562
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Dec 7 10:41:35 2020 -0500
Add curve eval tests
Add a few tests for gsk_curve_eval.
Since GskCurve is not public api, we add gskcurve.c
as source to the test binary.
testsuite/gsk/curve.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++
testsuite/gsk/meson.build | 1 +
2 files changed, 81 insertions(+)
---
diff --git a/testsuite/gsk/curve.c b/testsuite/gsk/curve.c
new file mode 100644
index 0000000000..3afaad9a60
--- /dev/null
+++ b/testsuite/gsk/curve.c
@@ -0,0 +1,80 @@
+#include <gtk/gtk.h>
+#include "gsk/gskcurveprivate.h"
+
+static void
+init_random_point (graphene_point_t *p)
+{
+ p->x = g_test_rand_double_range (0, 1000);
+ p->y = g_test_rand_double_range (0, 1000);
+}
+
+static void
+init_random_curve (GskCurve *curve)
+{
+ switch (g_test_rand_int_range (GSK_PATH_LINE, GSK_PATH_CONIC + 1))
+ {
+ case GSK_PATH_LINE:
+ {
+ graphene_point_t p[2];
+
+ init_random_point (&p[0]);
+ init_random_point (&p[1]);
+ gsk_curve_init (curve, gsk_pathop_encode (GSK_PATH_LINE, p));
+ }
+ break;
+
+ case GSK_PATH_CURVE:
+ {
+ graphene_point_t p[4];
+
+ init_random_point (&p[0]);
+ init_random_point (&p[1]);
+ init_random_point (&p[2]);
+ init_random_point (&p[3]);
+ gsk_curve_init (curve, gsk_pathop_encode (GSK_PATH_CURVE, p));
+ }
+ break;
+
+ case GSK_PATH_CONIC:
+ {
+ graphene_point_t p[4];
+
+ init_random_point (&p[0]);
+ init_random_point (&p[1]);
+ p[2] = GRAPHENE_POINT_INIT (g_test_rand_double_range (0, 20), 0);
+ init_random_point (&p[3]);
+ gsk_curve_init (curve, gsk_pathop_encode (GSK_PATH_CONIC, p));
+ }
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+}
+
+static void
+test_curve_points (void)
+{
+ for (int i = 0; i < 100; i++)
+ {
+ GskCurve c;
+ graphene_point_t p;
+
+ init_random_curve (&c);
+
+ gsk_curve_eval (&c, 0, &p, NULL);
+ g_assert_true (graphene_point_near (gsk_curve_get_start_point (&c), &p, 0.01));
+ gsk_curve_eval (&c, 1, &p, NULL);
+ g_assert_true (graphene_point_near (gsk_curve_get_end_point (&c), &p, 0.01));
+ }
+}
+
+int
+main (int argc, char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/curve/points", test_curve_points);
+
+ return g_test_run ();
+}
diff --git a/testsuite/gsk/meson.build b/testsuite/gsk/meson.build
index b6930d07fc..f46a89f14f 100644
--- a/testsuite/gsk/meson.build
+++ b/testsuite/gsk/meson.build
@@ -188,6 +188,7 @@ foreach test : node_parser_tests
endforeach
tests = [
+ ['curve', ['../../gsk/gskcurve.c'], ['-DGTK_COMPILATION']],
['path'],
['path-special-cases'],
['rounded-rect'],
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]