[gtk/path-work-rebased: 38/149] testsuite: Add path tests




commit adb0877a6bea2ccb1b57a6eafab839e0d038d307
Author: Benjamin Otte <otte redhat com>
Date:   Mon Nov 16 00:38:15 2020 +0100

    testsuite: Add path tests

 testsuite/gsk/meson.build |   1 +
 testsuite/gsk/path.c      | 129 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 130 insertions(+)
---
diff --git a/testsuite/gsk/meson.build b/testsuite/gsk/meson.build
index 2fb02087d3..d6e6113b41 100644
--- a/testsuite/gsk/meson.build
+++ b/testsuite/gsk/meson.build
@@ -204,6 +204,7 @@ foreach test : node_parser_tests
 endforeach
 
 tests = [
+  ['path'],
   ['rounded-rect'],
   ['transform'],
   ['shader'],
diff --git a/testsuite/gsk/path.c b/testsuite/gsk/path.c
new file mode 100644
index 0000000000..6bedd22311
--- /dev/null
+++ b/testsuite/gsk/path.c
@@ -0,0 +1,129 @@
+/*
+ * Copyright © 2020 Benjamin Otte
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+#include <gtk/gtk.h>
+
+static GskPath *
+create_random_path (void)
+{
+  GskPathBuilder *builder;
+  guint i, n;
+
+  builder = gsk_path_builder_new ();
+  n = g_test_rand_int_range (0, 20);
+
+  for (i = 0; i < n; i++)
+    {
+      switch (g_test_rand_int_range (0, 11))
+      {
+        case 0:
+          gsk_path_builder_move_to (builder,
+                                    g_test_rand_double_range (-1000, 1000),
+                                    g_test_rand_double_range (-1000, 1000));
+          break;
+
+        case 1:
+          gsk_path_builder_close (builder);
+          break;
+
+        case 2:
+        case 3:
+        case 4:
+        case 5:
+          gsk_path_builder_line_to (builder,
+                                    g_test_rand_double_range (-1000, 1000),
+                                    g_test_rand_double_range (-1000, 1000));
+          break;
+
+        case 6:
+        case 7:
+        case 8:
+        case 9:
+          gsk_path_builder_curve_to (builder,
+                                     g_test_rand_double_range (-1000, 1000),
+                                     g_test_rand_double_range (-1000, 1000),
+                                     g_test_rand_double_range (-1000, 1000),
+                                     g_test_rand_double_range (-1000, 1000),
+                                     g_test_rand_double_range (-1000, 1000),
+                                     g_test_rand_double_range (-1000, 1000));
+          break;
+
+        case 10:
+          gsk_path_builder_add_rect (builder,
+                                     &GRAPHENE_RECT_INIT (g_test_rand_double_range (-1000, 1000),
+                                                          g_test_rand_double_range (-1000, 1000),
+                                                          g_test_rand_double_range (-1000, 1000),
+                                                          g_test_rand_double_range (-1000, 1000)));
+          break;
+
+        default:
+          g_assert_not_reached();
+          break;
+      }
+    }
+
+  return gsk_path_builder_free_to_path (builder);
+}
+
+static void
+test_create (void)
+{
+  GskPath *path1, *path2, *built;
+  GskPathBuilder *builder;
+  guint i;
+  char *s;
+  GString *str;
+
+  for (i = 0; i < 1000; i++)
+    {
+      builder = gsk_path_builder_new ();
+      path1 = create_random_path ();
+      gsk_path_builder_add_path (builder, path1);
+      path2 = create_random_path ();
+      gsk_path_builder_add_path (builder, path2);
+      built = gsk_path_builder_free_to_path (builder);
+
+      str = g_string_new (NULL);
+      gsk_path_print (path1, str);
+      if (!gsk_path_is_empty (path1) && !gsk_path_is_empty (path2))
+        g_string_append_c (str, ' ');
+      gsk_path_print (path2, str);
+
+      s = gsk_path_to_string (built);
+
+      g_assert_cmpstr (s, ==, str->str);
+      g_string_free (str, TRUE);
+      g_free (s);
+
+      gsk_path_unref (built);
+      gsk_path_unref (path2);
+      gsk_path_unref (path1);
+    }
+}
+
+int
+main (int   argc,
+      char *argv[])
+{
+  gtk_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/path/create", test_create);
+
+  return g_test_run ();
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]