From e9f4047251be9252afa1e74104df13cfd99e380b Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Fri, 27 Nov 2020 07:12:03 +0100 Subject: [PATCH] testsuite: Add a test for get_point() --- testsuite/gsk/path.c | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/testsuite/gsk/path.c b/testsuite/gsk/path.c index c61e0da6ad..0df31023c9 100644 --- a/testsuite/gsk/path.c +++ b/testsuite/gsk/path.c @@ -455,6 +455,55 @@ test_segment (void) } } +static void +test_get_point (void) +{ + static const guint max_contours = 5; + static const float tolerance = 0.5; + GskPath *path; + GskPathMeasure *measure; + guint n_discontinuities; + float length, offset, last_offset; + graphene_point_t point, last_point; + guint i, j; + + for (i = 0; i < 10; i++) + { + path = create_random_path (max_contours); + measure = gsk_path_measure_new_with_tolerance (path, tolerance); + length = gsk_path_measure_get_length (measure); + n_discontinuities = 0; + + gsk_path_measure_get_point (measure, + 0, + &last_point, + NULL); + /* FIXME: anything we can test with tangents here? */ + last_offset = 0; + + for (j = 1; j <= 1024; j++) + { + offset = length * j / 1024; + gsk_path_measure_get_point (measure, + offset, + &point, + NULL); + + if (graphene_point_distance (&last_point, &point, NULL, NULL) > offset - last_offset + tolerance) + { + n_discontinuities++; + g_assert_cmpint (n_discontinuities, <, max_contours); + } + + last_offset = offset; + last_point = point; + } + + gsk_path_measure_unref (measure); + gsk_path_unref (path); + } +} + static void test_closest_point (void) { @@ -551,6 +600,7 @@ main (int argc, g_test_add_func ("/path/segment_end", test_segment_end); g_test_add_func ("/path/segment_chunk", test_segment_chunk); g_test_add_func ("/path/segment", test_segment); + g_test_add_func ("/path/get_point", test_get_point); g_test_add_func ("/path/closest_point", test_closest_point); return g_test_run ();