[gtk/wip/otte/lottie: 9/17] testsuite: Add path tests
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/lottie: 9/17] testsuite: Add path tests
- Date: Thu, 19 Nov 2020 21:41:49 +0000 (UTC)
commit 6f009aa6d72605c45dfa8ccb32c925b44d960a2a
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 0fe09619c8..2cce6a5e9a 100644
--- a/testsuite/gsk/meson.build
+++ b/testsuite/gsk/meson.build
@@ -188,6 +188,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..fc2397e98d
--- /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,
+ 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]