[gtk/wip/otte/lottie: 9/11] testuite: Add tests for gsk_curve_get_point()




commit 6cf9b2a328fae9f631b2c75ea2bd1bfe7f5afe93
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Dec 7 10:41:35 2020 -0500

    testuite: Add tests for gsk_curve_get_point()
    
    Add a few tests for gsk_curve_get_point().
    
    Since GskCurve is not public api, we add gskcurve.c
    as source to the test binary.

 testsuite/gsk/curve.c     | 89 +++++++++++++++++++++++++++++++++++++++++++++++
 testsuite/gsk/meson.build |  1 +
 2 files changed, 90 insertions(+)
---
diff --git a/testsuite/gsk/curve.c b/testsuite/gsk/curve.c
new file mode 100644
index 0000000000..5e83a1b806
--- /dev/null
+++ b/testsuite/gsk/curve.c
@@ -0,0 +1,89 @@
+#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 float
+random_weight (void)
+{
+  if (g_test_rand_bit ())
+    return g_test_rand_double_range (0, 100);
+  else
+    return 1.0 / g_test_rand_double_range (1, 100);
+}
+
+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 (random_weight(), 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]