From b9d8973c2f0daddc42bea739ef73694b459924b5 Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Wed, 4 Feb 2015 23:53:34 +0100 Subject: [PATCH] tests: move common path data in libadgtest Adapted tests to use the common path data instead of providing their own every time. --- src/cpml/tests/test-primitive.c | 344 ++++++++++++++++------------------------ src/cpml/tests/test-segment.c | 324 +++++++++++++++---------------------- src/tests/adg-test.c | 79 +++++++++ src/tests/adg-test.h | 2 + 4 files changed, 347 insertions(+), 402 deletions(-) diff --git a/src/cpml/tests/test-primitive.c b/src/cpml/tests/test-primitive.c index 28bfcbda..588227fb 100644 --- a/src/cpml/tests/test-primitive.c +++ b/src/cpml/tests/test-primitive.c @@ -23,59 +23,29 @@ #include -static cairo_path_data_t data[] = { - { .header = { CPML_MOVE, 2 }}, - { .point = { 0, 1 }}, - - /* Line */ - { .header = { CPML_LINE, 2 }}, - { .point = { 2, 3 }}, - - /* Arc */ - { .header = { CPML_ARC, 3 }}, - { .point = { 4, 5 }}, - { .point = { 6, 7 }}, - - /* Curve */ - { .header = { CPML_CURVE, 4 }}, - { .point = { 8, 9 }}, - { .point = { 10, 11 }}, - { .point = { 12, 13 }}, - - /* Closing primive */ - { .header = { CPML_CLOSE, 1 }} -}; - -cairo_path_t path = { - CAIRO_STATUS_SUCCESS, - data, - G_N_ELEMENTS(data) -}; - - static void _cpml_test_browsing(void) { CpmlSegment segment; CpmlPrimitive primitive, primitive_copy; - cpml_segment_from_cairo(&segment, &path); + cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); cpml_primitive_from_segment(&primitive, &segment); g_assert_cmpfloat((primitive.org)->point.x, ==, 0); g_assert_cmpfloat((primitive.org)->point.y, ==, 1); g_assert_cmpint((primitive.data)->header.type, ==, CPML_LINE); g_assert_true(cpml_primitive_next(&primitive)); - g_assert_cmpfloat((primitive.org)->point.x, ==, 2); - g_assert_cmpfloat((primitive.org)->point.y, ==, 3); + g_assert_cmpfloat((primitive.org)->point.x, ==, 3); + g_assert_cmpfloat((primitive.org)->point.y, ==, 1); g_assert_cmpint((primitive.data)->header.type, ==, CPML_ARC); g_assert_true(cpml_primitive_next(&primitive)); g_assert_cmpfloat((primitive.org)->point.x, ==, 6); g_assert_cmpfloat((primitive.org)->point.y, ==, 7); g_assert_cmpint((primitive.data)->header.type, ==, CPML_CURVE); g_assert_true(cpml_primitive_next(&primitive)); - g_assert_cmpfloat((primitive.org)->point.x, ==, 12); - g_assert_cmpfloat((primitive.org)->point.y, ==, 13); + g_assert_cmpfloat((primitive.org)->point.x, ==, -2); + g_assert_cmpfloat((primitive.org)->point.y, ==, 2); g_assert_cmpint((primitive.data)->header.type, ==, CPML_CLOSE); g_assert_false(cpml_primitive_next(&primitive)); @@ -135,7 +105,7 @@ _cpml_test_sanity_put_point(gint i) CpmlPrimitive primitive; CpmlPair pair; - cpml_segment_from_cairo(&segment, &path); + cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); cpml_primitive_from_segment(&primitive, &segment); switch (i) { @@ -264,7 +234,7 @@ _cpml_test_from_segment(void) CpmlSegment segment; CpmlPrimitive primitive; - g_assert_true(cpml_segment_from_cairo(&segment, &path)); + g_assert_true(cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path())); cpml_primitive_from_segment(&primitive, &segment); g_assert_nonnull(primitive.segment); @@ -300,7 +270,7 @@ _cpml_test_get_n_points(void) CpmlPrimitive primitive; size_t n_points; - cpml_segment_from_cairo(&segment, &path); + cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); /* Line */ cpml_primitive_from_segment(&primitive, &segment); @@ -327,61 +297,56 @@ _cpml_test_get_n_points(void) static void _cpml_test_set_point(void) { - gsize size; - cairo_path_data_t data_copy[G_N_ELEMENTS(data)]; - cairo_path_t path_copy = { - CAIRO_STATUS_SUCCESS, - data_copy, - G_N_ELEMENTS(data) - }; - CpmlSegment segment; + gsize data_size; + CpmlSegment original, *segment; CpmlPrimitive primitive; CpmlPair pair, pair2; int equality; - size = sizeof(data_copy); - memcpy(data_copy, data, size); - - cpml_segment_from_cairo(&segment, &path_copy); + /* Work on a copy to not modify the original path data */ + cpml_segment_from_cairo(&original, (cairo_path_t *) adg_test_path()); + data_size = original.num_data * sizeof(cairo_path_data_t); + segment = cpml_segment_deep_dup(&original); /* Line */ - cpml_primitive_from_segment(&primitive, &segment); + cpml_primitive_from_segment(&primitive, segment); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, ==, 0); cpml_primitive_put_point(&primitive, 0, &pair); pair.x += 1; cpml_primitive_set_point(&primitive, 0, &pair); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, !=, 0); pair.x -= 1; cpml_primitive_set_point(&primitive, 0, &pair); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, ==, 0); cpml_primitive_put_point(&primitive, 1, &pair); pair.y += 1; cpml_primitive_set_point(&primitive, 1, &pair); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, !=, 0); /* On a CPML_LINE primitives, -1 and 1 indices are equals */ cpml_primitive_put_point(&primitive, -1, &pair2); g_assert_cmpfloat(pair.x, ==, pair2.x); g_assert_cmpfloat(pair.y, ==, pair2.y); - memcpy(data_copy, data, size); - equality = memcmp(data_copy, data, size); + memcpy(segment->data, original.data, data_size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, ==, 0); cpml_primitive_put_point(&primitive, 2, &pair); pair.x += 1; pair.y += 1; /* This should be a NOP without segfaults */ cpml_primitive_set_point(&primitive, 2, &pair); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, ==, 0); - /* From now on, memcpy() is assumed to force equality (as yet + /* From now on, memcpy() is assumed to force equality (as already * proved by the previous assertions) and pair2 is used as a * different-from-everything pair, that is setting pair2 on any - * point will break the equality between data and data_copy + * point will break the equality between segment->data and + * original.data */ pair2.x = 12345; pair2.y = 54321; @@ -390,58 +355,60 @@ _cpml_test_set_point(void) cpml_primitive_next(&primitive); cpml_primitive_set_point(&primitive, 0, &pair2); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, !=, 0); - memcpy(data_copy, data, size); + memcpy(segment->data, original.data, data_size); cpml_primitive_set_point(&primitive, 1, &pair2); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, !=, 0); - memcpy(data_copy, data, size); + memcpy(segment->data, original.data, data_size); cpml_primitive_set_point(&primitive, 2, &pair2); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, !=, 0); - memcpy(data_copy, data, size); + memcpy(segment->data, original.data, data_size); cpml_primitive_set_point(&primitive, 3, &pair2); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, ==, 0); /* Curve */ cpml_primitive_next(&primitive); cpml_primitive_set_point(&primitive, 0, &pair2); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, !=, 0); - memcpy(data_copy, data, size); + memcpy(segment->data, original.data, data_size); cpml_primitive_set_point(&primitive, 1, &pair2); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, !=, 0); - memcpy(data_copy, data, size); + memcpy(segment->data, original.data, data_size); cpml_primitive_set_point(&primitive, 2, &pair2); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, !=, 0); - memcpy(data_copy, data, size); + memcpy(segment->data, original.data, data_size); cpml_primitive_set_point(&primitive, 3, &pair2); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, !=, 0); - memcpy(data_copy, data, size); + memcpy(segment->data, original.data, data_size); cpml_primitive_set_point(&primitive, 4, &pair2); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, ==, 0); /* Close */ cpml_primitive_next(&primitive); cpml_primitive_set_point(&primitive, 0, &pair2); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, !=, 0); - memcpy(data_copy, data, size); + memcpy(segment->data, original.data, data_size); cpml_primitive_set_point(&primitive, 1, &pair2); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, !=, 0); - memcpy(data_copy, data, size); + memcpy(segment->data, original.data, data_size); cpml_primitive_set_point(&primitive, 2, &pair2); - equality = memcmp(data_copy, data, size); + equality = memcmp(original.data, segment->data, data_size); g_assert_cmpint(equality, ==, 0); + + g_free(segment); } static void @@ -451,7 +418,7 @@ _cpml_test_put_point(void) CpmlPrimitive primitive; CpmlPair pair; - cpml_segment_from_cairo(&segment, &path); + cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); /* Line */ cpml_primitive_from_segment(&primitive, &segment); @@ -460,15 +427,15 @@ _cpml_test_put_point(void) g_assert_cmpfloat(pair.x, ==, 0); g_assert_cmpfloat(pair.y, ==, 1); cpml_primitive_put_point(&primitive, 1, &pair); - g_assert_cmpfloat(pair.x, ==, 2); - g_assert_cmpfloat(pair.y, ==, 3); + g_assert_cmpfloat(pair.x, ==, 3); + g_assert_cmpfloat(pair.y, ==, 1); cpml_primitive_put_point(&primitive, 2, &pair); - g_assert_cmpfloat(pair.x, ==, 2); - g_assert_cmpfloat(pair.y, ==, 3); + g_assert_cmpfloat(pair.x, ==, 3); + g_assert_cmpfloat(pair.y, ==, 1); /* The negative indices are checked only against CPML_LINE */ cpml_primitive_put_point(&primitive, -1, &pair); - g_assert_cmpfloat(pair.x, ==, 2); - g_assert_cmpfloat(pair.y, ==, 3); + g_assert_cmpfloat(pair.x, ==, 3); + g_assert_cmpfloat(pair.y, ==, 1); cpml_primitive_put_point(&primitive, -2, &pair); g_assert_cmpfloat(pair.x, ==, 0); g_assert_cmpfloat(pair.y, ==, 1); @@ -480,8 +447,8 @@ _cpml_test_put_point(void) cpml_primitive_next(&primitive); cpml_primitive_put_point(&primitive, 0, &pair); - g_assert_cmpfloat(pair.x, ==, 2); - g_assert_cmpfloat(pair.y, ==, 3); + g_assert_cmpfloat(pair.x, ==, 3); + g_assert_cmpfloat(pair.y, ==, 1); cpml_primitive_put_point(&primitive, 1, &pair); g_assert_cmpfloat(pair.x, ==, 4); g_assert_cmpfloat(pair.y, ==, 5); @@ -505,18 +472,18 @@ _cpml_test_put_point(void) g_assert_cmpfloat(pair.x, ==, 10); g_assert_cmpfloat(pair.y, ==, 11); cpml_primitive_put_point(&primitive, 3, &pair); - g_assert_cmpfloat(pair.x, ==, 12); - g_assert_cmpfloat(pair.y, ==, 13); + g_assert_cmpfloat(pair.x, ==, -2); + g_assert_cmpfloat(pair.y, ==, 2); cpml_primitive_put_point(&primitive, 4, &pair); - g_assert_cmpfloat(pair.x, ==, 12); - g_assert_cmpfloat(pair.y, ==, 13); + g_assert_cmpfloat(pair.x, ==, -2); + g_assert_cmpfloat(pair.y, ==, 2); /* Close */ cpml_primitive_next(&primitive); cpml_primitive_put_point(&primitive, 0, &pair); - g_assert_cmpfloat(pair.x, ==, 12); - g_assert_cmpfloat(pair.y, ==, 13); + g_assert_cmpfloat(pair.x, ==, -2); + g_assert_cmpfloat(pair.y, ==, 2); cpml_primitive_put_point(&primitive, 1, &pair); g_assert_cmpfloat(pair.x, ==, 0); g_assert_cmpfloat(pair.y, ==, 1); @@ -528,153 +495,111 @@ _cpml_test_put_point(void) static void _cpml_test_get_length(void) { - cairo_path_data_t rectangle_data[] = { - { .header = { CPML_MOVE, 2 }}, - { .point = { 0, 0 }}, - - { .header = { CPML_LINE, 2 }}, - { .point = { 2, 0 }}, - - { .header = { CPML_LINE, 2 }}, - { .point = { 2, 1 }}, - - { .header = { CPML_LINE, 2 }}, - { .point = { 0, 1 }}, - - { .header = { CPML_CLOSE, 1 }} - }; - cairo_path_t rectangle = { - CAIRO_STATUS_SUCCESS, - rectangle_data, - G_N_ELEMENTS(rectangle_data) - }; CpmlSegment segment; CpmlPrimitive primitive; - cpml_segment_from_cairo(&segment, &rectangle); - + cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); + cpml_segment_next(&segment); cpml_primitive_from_segment(&primitive, &segment); - g_assert_cmpfloat(cpml_primitive_get_length(&primitive), ==, 2); - cpml_primitive_next(&primitive); g_assert_cmpfloat(cpml_primitive_get_length(&primitive), ==, 1); cpml_primitive_next(&primitive); g_assert_cmpfloat(cpml_primitive_get_length(&primitive), ==, 2); - - cpml_primitive_next(&primitive); - g_assert_cmpfloat(cpml_primitive_get_length(&primitive), ==, 1); } static void _cpml_test_put_intersections(void) { - cairo_path_data_t path1_data[] = { - { .header = { CPML_MOVE, 2 }}, - { .point = { 98, 1 }}, - - { .header = { CPML_LINE, 2 }}, - { .point = { 102, 1 }}, - - { .header = { CPML_LINE, 2 }}, - { .point = { 102, 0 }}, - - { .header = { CPML_LINE, 2 }}, - { .point = { 98, 0 }} - }, path2_data[] = { - { .header = { CPML_MOVE, 2 }}, - { .point = { 100, -1 }}, - - { .header = { CPML_LINE, 2 }}, - { .point = { 100, 2 }} - }; - cairo_path_t path1 = { - CAIRO_STATUS_SUCCESS, - path1_data, - G_N_ELEMENTS(path1_data) - }, path2 = { - CAIRO_STATUS_SUCCESS, - path2_data, - G_N_ELEMENTS(path2_data) - }; CpmlSegment segment; - CpmlPrimitive primitive, primitive2; + CpmlPrimitive primitive1, primitive2; CpmlPair pair[2]; - cpml_segment_from_cairo(&segment, &path2); - cpml_primitive_from_segment(&primitive, &segment); + /* Set primitive1 to 1.1 (first segment, first primitive) */ + cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); + cpml_primitive_from_segment(&primitive1, &segment); - cpml_segment_from_cairo(&segment, &path1); + /* Set primitive2 to 2.1 (second segment, first primitive) */ + cpml_segment_next(&segment); cpml_primitive_from_segment(&primitive2, &segment); - g_assert_cmpuint(cpml_primitive_put_intersections(&primitive, &primitive2, 0, pair), ==, 0); + /* primitive1 (1.1) does not intersect primitive2 (2.1) */ + g_assert_cmpuint(cpml_primitive_put_intersections(&primitive1, &primitive2, 2, pair), ==, 0); - /* The first primitive of path1 intersects (really) path2 in (0, 1) */ - g_assert_cmpuint(cpml_primitive_put_intersections(&primitive, &primitive2, 2, pair), ==, 1); - g_assert_cmpfloat(pair[0].x, ==, 100); - g_assert_cmpfloat(pair[0].y, ==, 1); - g_assert_cmpint(cpml_primitive_is_inside(&primitive, pair), ==, 1); - g_assert_cmpint(cpml_primitive_is_inside(&primitive2, pair), ==, 1); - g_assert_cmpuint(cpml_primitive_put_intersections(&primitive2, &primitive, 2, pair), ==, 1); - g_assert_cmpfloat(pair[0].x, ==, 100); + cpml_primitive_next(&primitive2); + + /* primitive1 (1.1) intersects primitive2 (2.2) in (1, 1) */ + g_assert_cmpuint(cpml_primitive_put_intersections(&primitive1, &primitive2, 2, pair), ==, 1); + g_assert_cmpfloat(pair[0].x, ==, 1); g_assert_cmpfloat(pair[0].y, ==, 1); + g_assert_cmpint(cpml_primitive_is_inside(&primitive1, pair), ==, 1); g_assert_cmpint(cpml_primitive_is_inside(&primitive2, pair), ==, 1); - g_assert_cmpint(cpml_primitive_is_inside(&primitive, pair), ==, 1); - /* The second primitive does not intersect */ - cpml_primitive_next(&primitive2); - g_assert_cmpuint(cpml_primitive_put_intersections(&primitive, &primitive2, 2, pair), ==, 0); - g_assert_cmpuint(cpml_primitive_put_intersections(&primitive2, &primitive, 2, pair), ==, 0); + /* Check the intersection is not returned when not requested */ + g_assert_cmpuint(cpml_primitive_put_intersections(&primitive1, &primitive2, 0, pair), ==, 0); - /* The third primitive intersects in (0, 0) */ - cpml_primitive_next(&primitive2); - g_assert_cmpuint(cpml_primitive_put_intersections(&primitive, &primitive2, 2, pair), ==, 1); - g_assert_cmpfloat(pair[0].x, ==, 100); - g_assert_cmpfloat(pair[0].y, ==, 0); - g_assert_cmpuint(cpml_primitive_put_intersections(&primitive2, &primitive, 2, pair), ==, 1); - g_assert_cmpfloat(pair[0].x, ==, 100); - g_assert_cmpfloat(pair[0].y, ==, 0); + cpml_primitive_next(&primitive1); - g_assert_cmpuint(cpml_primitive_put_intersections_with_segment(&primitive, &segment, 0, pair), ==, 0); + /* primitive1 (1.2) does not intersect primitive2 (2.2) */ + g_assert_cmpuint(cpml_primitive_put_intersections(&primitive1, &primitive2, 2, pair), ==, 0); - /* path2 intesects the whole path1 in two points */ - g_assert_cmpuint(cpml_primitive_put_intersections_with_segment(&primitive, &segment, 2, pair), ==, 2); - g_assert_cmpfloat(pair[0].x, ==, 100); - g_assert_cmpfloat(pair[0].y, ==, 1); - g_assert_cmpfloat(pair[1].x, ==, 100); - g_assert_cmpfloat(pair[1].y, ==, 0); + cpml_primitive_next(&primitive1); - cpml_segment_from_cairo(&segment, &path); - cpml_primitive_from_segment(&primitive2, &segment); + /* primitive1 (1.3) does not intersect primitive2 (2.2) */ + g_assert_cmpuint(cpml_primitive_put_intersections(&primitive1, &primitive2, 2, pair), ==, 0); - /* Check line-line intesection */ - g_assert_cmpuint(cpml_primitive_put_intersections(&primitive2, &primitive, 2, pair), ==, 1); - g_assert_cmpuint(cpml_primitive_put_intersections(&primitive, &primitive2, 2, pair), ==, 1); + cpml_primitive_next(&primitive1); - /* Check the returned intersection is an hypothetical intersection */ + /* primitive1 (1.4) intersects primitive2 (2.2), but outside their boundaries */ + g_assert_cmpuint(cpml_primitive_put_intersections(&primitive1, &primitive2, 2, pair), ==, 1); + g_assert_cmpfloat(pair[0].x, ==, 1); + g_assert_cmpfloat(pair[0].y, ==, -1); + g_assert_cmpint(cpml_primitive_is_inside(&primitive1, pair), ==, 0); g_assert_cmpint(cpml_primitive_is_inside(&primitive2, pair), ==, 0); - g_assert_cmpint(cpml_primitive_is_inside(&primitive, pair), ==, 0); +} - /* Check line-arc intesection */ - cpml_primitive_next(&primitive2); - g_assert_cmpuint(cpml_primitive_put_intersections(&primitive2, &primitive, 2, pair), ==, 0); - g_assert_cmpuint(cpml_primitive_put_intersections(&primitive, &primitive2, 2, pair), ==, 0); +static void +_cpml_test_put_intersections_with_segment(void) +{ + CpmlSegment segment; + CpmlPrimitive primitive; + CpmlPair pair[4]; - /* Check line-curve intesection */ - cpml_primitive_next(&primitive2); - g_assert_cmpuint(cpml_primitive_put_intersections(&primitive2, &primitive, 2, pair), ==, 0); - g_assert_cmpuint(cpml_primitive_put_intersections(&primitive, &primitive2, 2, pair), ==, 0); + /* Set primitive to first segment, first primitive */ + cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); + cpml_primitive_from_segment(&primitive, &segment); - /* Check line-close intesection */ - cpml_primitive_next(&primitive2); - g_assert_cmpuint(cpml_primitive_put_intersections(&primitive2, &primitive, 2, pair), ==, 1); - g_assert_cmpuint(cpml_primitive_put_intersections(&primitive, &primitive2, 2, pair), ==, 1); + /* Set segment to the second segment */ + cpml_segment_next(&segment); - /* Check the returned intersection is an hypothetical intersection */ - g_assert_cmpint(cpml_primitive_is_inside(&primitive2, pair), ==, 0); - g_assert_cmpint(cpml_primitive_is_inside(&primitive, pair), ==, 0); + /* primitive (1.1) intersects segment (2) in (1, 1) */ + g_assert_cmpuint(cpml_primitive_put_intersections_with_segment(&primitive, &segment, 4, pair), ==, 1); + g_assert_cmpfloat(pair[0].x, ==, 1); + g_assert_cmpfloat(pair[0].y, ==, 1); - g_assert_false(cpml_primitive_next(&primitive2)); + cpml_primitive_next(&primitive); + + /* primitive (1.1) does not intersect segment (2) */ + g_assert_cmpuint(cpml_primitive_put_intersections_with_segment(&primitive, &segment, 4, pair), ==, 0); + + /* Set primitive to second segment, first primitive */ + cpml_primitive_from_segment(&primitive, &segment); + + /* Set segment to the first segment */ + cpml_segment_reset(&segment); + + /* primitive (2.1) intersects segment (1) in extrapolation. + * TODO: change this behavior! They must not intersect. */ + g_assert_cmpuint(cpml_primitive_put_intersections_with_segment(&primitive, &segment, 4, pair), ==, 1); + g_assert_cmpfloat(pair[0].x, ==, 2); + g_assert_cmpfloat(pair[0].y, ==, 0); + + cpml_primitive_next(&primitive); + + /* primitive (2.2) wrongly intersects segment (1) */ + g_assert_cmpuint(cpml_primitive_put_intersections_with_segment(&primitive, &segment, 4, pair), ==, 1); + g_assert_cmpfloat(pair[0].x, ==, 2); + g_assert_cmpfloat(pair[0].y, ==, 0); } static void @@ -735,7 +660,7 @@ _cpml_test_to_cairo(void) int length, last_length; cr = adg_test_cairo_context(); - cpml_segment_from_cairo(&segment, &path); + cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); cpml_primitive_from_segment(&primitive, &segment); g_assert_cmpint(adg_test_cairo_num_data(cr), ==, 0); @@ -759,7 +684,7 @@ _cpml_test_dump(gint i) switch (i) { case 1: - cpml_segment_from_cairo(&segment, &path); + cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); cpml_primitive_from_segment(&primitive, &segment); cpml_primitive_dump(&primitive, 1); @@ -800,6 +725,7 @@ main(int argc, char *argv[]) g_test_add_func("/cpml/primitive/method/put-point", _cpml_test_put_point); g_test_add_func("/cpml/primitive/method/get-length", _cpml_test_get_length); g_test_add_func("/cpml/primitive/method/put-intersections", _cpml_test_put_intersections); + g_test_add_func("/cpml/primitive/method/put-intersections-with-segment", _cpml_test_put_intersections_with_segment); g_test_add_func("/cpml/primitive/method/join", _cpml_test_join); g_test_add_func("/cpml/primitive/method/to-cairo", _cpml_test_to_cairo); adg_test_add_traps("/cpml/primitive/method/dump", _cpml_test_dump, 1); diff --git a/src/cpml/tests/test-segment.c b/src/cpml/tests/test-segment.c index ef553284..f44f1172 100644 --- a/src/cpml/tests/test-segment.c +++ b/src/cpml/tests/test-segment.c @@ -22,123 +22,40 @@ #include -static cairo_path_data_t data[] = { - /* Useless heading CPML_MOVE */ - { .header = { CPML_MOVE, 2 }}, - { .point = { 0, 0 }}, - - /* First segment: a couple of lines of length 2 */ - { .header = { CPML_MOVE, 2 }}, - { .point = { 0, 0 }}, - { .header = { CPML_LINE, 2 }}, - { .point = { 2, 0 }}, - { .header = { CPML_LINE, 2 }}, - { .point = { 2, 2 }}, - - /* Another useless CPML_MOVE with useless embedded data */ - { .header = { CPML_MOVE, 3 }}, - { .point = { 0, 0 }}, - { .point = { 0, 0 }}, - - /* Second segment: a Bézier curve with a trailing CPML_CLOSE */ - { .header = { CPML_MOVE, 2 }}, - { .point = { 10, 13 }}, - { .header = { CPML_CURVE, 4 }}, - { .point = { 8, 9 }}, - { .point = { 10, 11 }}, - { .point = { 12, 13 }}, - { .header = { CPML_CLOSE, 1 }}, - - /* A valid cairo segment considered invalid by CPML - * because does not have a leading CPML_MOVE */ - { .header = { CPML_LINE, 2 }}, - { .point = { 10, 0 }}, - { .header = { CPML_CLOSE, 1 }}, - - /* Another valid cairo segment invalid in CPML */ - { .header = { CPML_CLOSE, 1 }}, - - /* Third segment: a couple of arcs */ - { .header = { CPML_MOVE, 2 }}, - { .point = { 14, 15 }}, - { .header = { CPML_ARC, 3 }}, - { .point = { 16, 17 }}, - { .point = { 18, 19 }}, - { .header = { CPML_ARC, 3 }}, - { .point = { 20, 21 }}, - { .point = { 22, 23 }}, - - /* Forth segment: a floating CPML_CLOSE */ - { .header = { CPML_MOVE, 2 }}, - { .point = { 24, 25 }}, - { .header = { CPML_CLOSE, 1 }} -}; - -static cairo_path_data_t noop_data[] = { - /* Useless heading CPML_MOVE */ - { .header = { CPML_MOVE, 2 }}, - { .point = { 0, 1 }}, - { .header = { CPML_MOVE, 4 }}, - { .point = { 2, 3 }}, - { .point = { 4, 5 }}, - { .point = { 6, 7 }}, - { .header = { CPML_MOVE, 2 }}, - { .point = { 8, 9 }} -}; - -static cairo_path_data_t y1_data[] = { - { .header = { CPML_MOVE, 2 }}, - { .point = { 0, 1 }}, - { .header = { CPML_LINE, 2 }}, - { .point = { 5, 1 }} -}; - -cairo_path_t path = { - CAIRO_STATUS_SUCCESS, - data, - G_N_ELEMENTS(data) -}; - -cairo_path_t noop_path = { - CAIRO_STATUS_SUCCESS, - noop_data, - G_N_ELEMENTS(noop_data) -}; - -cairo_path_t y1_path = { - CAIRO_STATUS_SUCCESS, - y1_data, - G_N_ELEMENTS(y1_data) -}; - - static void _cpml_test_browsing(void) { CpmlSegment segment; - cpml_segment_from_cairo(&segment, &path); + cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); /* First segment */ g_assert_cmpint(segment.data[0].header.type, ==, CPML_MOVE); g_assert_cmpint(segment.data[2].header.type, ==, CPML_LINE); cpml_segment_reset(&segment); + cpml_segment_reset(&segment); g_assert_cmpint(segment.data[0].header.type, ==, CPML_MOVE); g_assert_cmpint(segment.data[2].header.type, ==, CPML_LINE); /* Second segment */ g_assert_cmpint(cpml_segment_next(&segment), ==, 1); g_assert_cmpint(segment.data[0].header.type, ==, CPML_MOVE); - g_assert_cmpint(segment.data[2].header.type, ==, CPML_CURVE); + g_assert_cmpint(segment.data[2].header.type, ==, CPML_LINE); + g_assert_cmpint(segment.data[4].header.type, ==, CPML_LINE); /* Third segment */ g_assert_cmpint(cpml_segment_next(&segment), ==, 1); g_assert_cmpint(segment.data[0].header.type, ==, CPML_MOVE); - g_assert_cmpint(segment.data[2].header.type, ==, CPML_ARC); + g_assert_cmpint(segment.data[2].header.type, ==, CPML_CURVE); /* Forth segment */ g_assert_cmpint(cpml_segment_next(&segment), ==, 1); g_assert_cmpint(segment.data[0].header.type, ==, CPML_MOVE); + g_assert_cmpint(segment.data[2].header.type, ==, CPML_ARC); + + /* Fifth segment */ + g_assert_cmpint(cpml_segment_next(&segment), ==, 1); + g_assert_cmpint(segment.data[0].header.type, ==, CPML_MOVE); g_assert_cmpint(segment.data[2].header.type, ==, CPML_CLOSE); g_assert_cmpint(cpml_segment_next(&segment), ==, 0); @@ -151,11 +68,14 @@ _cpml_test_browsing(void) static void _cpml_test_sanity_from_cairo(gint i) { + cairo_path_t *path = (cairo_path_t *) adg_test_path(); CpmlSegment segment; + cpml_segment_from_cairo(&segment, path); + switch (i) { case 1: - cpml_segment_from_cairo(NULL, &path); + cpml_segment_from_cairo(NULL, path); break; case 2: cpml_segment_from_cairo(&segment, NULL); @@ -185,7 +105,7 @@ _cpml_test_sanity_put_intersections(gint i) CpmlSegment segment; CpmlPair pair; - cpml_segment_from_cairo(&segment, &path); + cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); switch (i) { case 1: @@ -222,6 +142,9 @@ _cpml_test_sanity_transform(gint i) CpmlSegment segment; cairo_matrix_t matrix; + cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); + cairo_matrix_init_identity(&matrix); + switch (i) { case 1: cpml_segment_transform(NULL, &matrix); @@ -253,6 +176,8 @@ _cpml_test_sanity_to_cairo(gint i) { CpmlSegment segment; + cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); + switch (i) { case 1: cpml_segment_to_cairo(NULL, adg_test_cairo_context()); @@ -282,32 +207,63 @@ static void _cpml_test_from_cairo(void) { CpmlSegment segment; + cairo_path_data_t noop_data[] = { + /* Useless heading primitives */ + { .header = { CPML_MOVE, 2 }}, + { .point = { 0, 1 }}, + { .header = { CPML_MOVE, 4 }}, + { .point = { 2, 3 }}, + { .point = { 4, 5 }}, + { .point = { 6, 7 }}, + { .header = { CPML_MOVE, 2 }}, + { .point = { 8, 9 }} + }; + cairo_path_t noop_path = { + CAIRO_STATUS_SUCCESS, + noop_data, + G_N_ELEMENTS(noop_data) + }; + cairo_path_t empty_path = { + CAIRO_STATUS_SUCCESS, + noop_data, + 0 + }; + g_assert_cmpint(cpml_segment_from_cairo(&segment, &noop_path), ==, 0); - g_assert_cmpint(cpml_segment_from_cairo(&segment, &path), ==, 1); + g_assert_cmpint(cpml_segment_from_cairo(&segment, &empty_path), ==, 0); + g_assert_cmpint(cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()), ==, 1); } static void _cpml_test_get_length(void) { CpmlSegment segment; - cpml_segment_from_cairo(&segment, &path); + cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); - /* First segment */ - g_assert_cmpfloat(cpml_segment_get_length(&segment), ==, 4); - g_assert_cmpfloat(cpml_segment_get_length(&segment), ==, 4); + /* First segment: not a round number so avoiding == */ + g_assert_cmpfloat(cpml_segment_get_length(&segment), >, 0); + + cpml_segment_next(&segment); /* Second segment */ + g_assert_cmpfloat(cpml_segment_get_length(&segment), ==, 3); + g_assert_cmpfloat(cpml_segment_get_length(&segment), ==, 3); + cpml_segment_next(&segment); - /* TODO: Bézier curve length not yet implemented - * g_assert_cmpfloat(cpml_segment_get_length(&segment), ==, ???); */ /* Third segment */ + /* TODO: Bézier curve length not yet implemented + * g_assert_cmpfloat(cpml_segment_get_length(&segment), >, 0); */ + cpml_segment_next(&segment); - g_assert_cmpfloat(cpml_segment_get_length(&segment), ==, 0); /* Forth segment */ + g_assert_cmpfloat(cpml_segment_get_length(&segment), ==, 0); + cpml_segment_next(&segment); + + /* Fifth segment */ g_assert_cmpfloat(cpml_segment_get_length(&segment), ==, 0); } @@ -315,22 +271,27 @@ static void _cpml_test_put_intersections(void) { CpmlSegment segment1, segment2; - CpmlPair pair[2]; + CpmlPair pair[10]; - cpml_segment_from_cairo(&segment1, &path); - cpml_segment_from_cairo(&segment2, &y1_path); + cpml_segment_from_cairo(&segment1, (cairo_path_t *) adg_test_path()); + cpml_segment_copy(&segment2, &segment1); - g_assert_cmpuint(cpml_segment_put_intersections(&segment1, &segment2, 0, pair), ==, 0); + cpml_segment_next(&segment2); - /* The first segment of path intersects y1_path in (2, 1) */ - g_assert_cmpuint(cpml_segment_put_intersections(&segment1, &segment2, 2, pair), ==, 1); - g_assert_cmpfloat(pair[0].x, ==, 2); + /* The first segment intersects the second segment in (1, 1). + * TODO: avoid extrapolated intersections! Check + * cpml_primitive_put_intersections */ + g_assert_cmpuint(cpml_segment_put_intersections(&segment1, &segment2, 10, pair), ==, 3); + g_assert_cmpfloat(pair[0].x, ==, 1); g_assert_cmpfloat(pair[0].y, ==, 1); + g_assert_cmpfloat(pair[1].x, ==, 2); + g_assert_cmpfloat(pair[1].y, ==, 0); + + cpml_segment_next(&segment2); - /* The third segment of path does not intersect y1_path */ - cpml_segment_next(&segment1); - cpml_segment_next(&segment1); - g_assert_cmpuint(cpml_segment_put_intersections(&segment1, &segment2, 2, pair), ==, 0); + /* The third segment intersects the first segment 5 times. + * TODO: check if this is true */ + g_assert_cmpuint(cpml_segment_put_intersections(&segment1, &segment2, 10, pair), ==, 5); } static void @@ -338,9 +299,15 @@ _cpml_test_offset(void) { CpmlSegment original, *segment; - cpml_segment_from_cairo(&original, &path); + /* Work on a copy to avoid modifying adg_test_path() data */ + cpml_segment_from_cairo(&original, (cairo_path_t *) adg_test_path()); + segment = cpml_segment_deep_dup(&original); + + /* TODO: provide tests for arcs and curves */ + cpml_segment_offset(segment, 1); + g_free(segment); - /* Working on a duplicate of the first segment to avoid modifying path */ + cpml_segment_next(&original); segment = cpml_segment_deep_dup(&original); cpml_segment_offset(segment, 1); @@ -349,15 +316,13 @@ _cpml_test_offset(void) g_assert_cmpfloat(segment->data[1].point.y, ==, 1); g_assert_cmpint(segment->data[2].header.type, ==, CPML_LINE); - g_assert_cmpfloat(segment->data[3].point.x, ==, 1); + g_assert_cmpfloat(segment->data[3].point.x, ==, 0); g_assert_cmpfloat(segment->data[3].point.y, ==, 1); g_assert_cmpint(segment->data[4].header.type, ==, CPML_LINE); - g_assert_cmpfloat(segment->data[5].point.x, ==, 1); + g_assert_cmpfloat(segment->data[5].point.x, ==, 0); g_assert_cmpfloat(segment->data[5].point.y, ==, 2); - /* TODO: provide tests for arcs and curves */ - g_free(segment); } @@ -367,9 +332,8 @@ _cpml_test_transform(void) CpmlSegment original, *segment; cairo_matrix_t matrix; - cpml_segment_from_cairo(&original, &path); - - /* Working on a duplicate of the first segment to avoid modifying path */ + /* Work on a copy to avoid modifying adg_test_path() data */ + cpml_segment_from_cairo(&original, (cairo_path_t *) adg_test_path()); segment = cpml_segment_deep_dup(&original); cairo_matrix_init_translate(&matrix, 1, 2); @@ -377,90 +341,69 @@ _cpml_test_transform(void) g_assert_cmpint(segment->data[0].header.type, ==, CPML_MOVE); g_assert_cmpfloat(segment->data[1].point.x, ==, 1); - g_assert_cmpfloat(segment->data[1].point.y, ==, 2); + g_assert_cmpfloat(segment->data[1].point.y, ==, 3); g_assert_cmpint(segment->data[2].header.type, ==, CPML_LINE); - g_assert_cmpfloat(segment->data[3].point.x, ==, 3); - g_assert_cmpfloat(segment->data[3].point.y, ==, 2); + g_assert_cmpfloat(segment->data[3].point.x, ==, 4); + g_assert_cmpfloat(segment->data[3].point.y, ==, 3); - g_assert_cmpint(segment->data[4].header.type, ==, CPML_LINE); - g_assert_cmpfloat(segment->data[5].point.x, ==, 3); - g_assert_cmpfloat(segment->data[5].point.y, ==, 4); + g_assert_cmpint(segment->data[4].header.type, ==, CPML_ARC); + g_assert_cmpfloat(segment->data[5].point.x, ==, 5); + g_assert_cmpfloat(segment->data[5].point.y, ==, 7); + g_assert_cmpfloat(segment->data[6].point.x, ==, 7); + g_assert_cmpfloat(segment->data[6].point.y, ==, 9); + + g_assert_cmpint(segment->data[7].header.type, ==, CPML_CURVE); + g_assert_cmpfloat(segment->data[8].point.x, ==, 9); + g_assert_cmpfloat(segment->data[8].point.y, ==, 11); + g_assert_cmpfloat(segment->data[9].point.x, ==, 11); + g_assert_cmpfloat(segment->data[9].point.y, ==, 13); + g_assert_cmpfloat(segment->data[10].point.x, ==, -1); + g_assert_cmpfloat(segment->data[10].point.y, ==, 4); + + g_assert_cmpint(segment->data[11].header.type, ==, CPML_CLOSE); g_free(segment); } +#include static void _cpml_test_reverse(void) { CpmlSegment original, *segment; - cpml_segment_from_cairo(&original, &path); - - /* First segment: work on a duplicate to avoid modifying path */ + /* Work on a copy to avoid modifying adg_test_path() data */ + cpml_segment_from_cairo(&original, (cairo_path_t *) adg_test_path()); segment = cpml_segment_deep_dup(&original); - cpml_segment_reverse(segment); - - g_assert_cmpint(segment->num_data, ==, 6); - - g_assert_cmpint(segment->data[0].header.type, ==, CPML_MOVE); - g_assert_cmpfloat(segment->data[1].point.x, ==, 2); - g_assert_cmpfloat(segment->data[1].point.y, ==, 2); - - g_assert_cmpint(segment->data[2].header.type, ==, CPML_LINE); - g_assert_cmpfloat(segment->data[3].point.x, ==, 2); - g_assert_cmpfloat(segment->data[3].point.y, ==, 0); - - g_assert_cmpint(segment->data[4].header.type, ==, CPML_LINE); - g_assert_cmpfloat(segment->data[5].point.x, ==, 0); - g_assert_cmpfloat(segment->data[5].point.y, ==, 0); - - g_free(segment); - /* TODO: the second segment is an invalid CPML segment because - * it is followed by a segment without a leading move_to. - * Find a decent reverse algorithm and document it. - * I'm just skipping that segment for now. - */ - cpml_segment_next(&original); - - /* Third segment */ - cpml_segment_next(&original); - segment = cpml_segment_deep_dup(&original); + /* First segment */ cpml_segment_reverse(segment); - g_assert_cmpint(segment->num_data, ==, 8); + g_assert_cmpint(segment->num_data, ==, 12); g_assert_cmpint(segment->data[0].header.type, ==, CPML_MOVE); - g_assert_cmpfloat(segment->data[1].point.x, ==, 22); - g_assert_cmpfloat(segment->data[1].point.y, ==, 23); - - g_assert_cmpint(segment->data[2].header.type, ==, CPML_ARC); - g_assert_cmpfloat(segment->data[3].point.x, ==, 20); - g_assert_cmpfloat(segment->data[3].point.y, ==, 21); - g_assert_cmpfloat(segment->data[4].point.x, ==, 18); - g_assert_cmpfloat(segment->data[4].point.y, ==, 19); - - g_assert_cmpint(segment->data[5].header.type, ==, CPML_ARC); - g_assert_cmpfloat(segment->data[6].point.x, ==, 16); - g_assert_cmpfloat(segment->data[6].point.y, ==, 17); - g_assert_cmpfloat(segment->data[7].point.x, ==, 14); - g_assert_cmpfloat(segment->data[7].point.y, ==, 15); - - g_free(segment); + g_assert_cmpfloat(segment->data[1].point.x, ==, -2); + g_assert_cmpfloat(segment->data[1].point.y, ==, 2); - /* Forth segment */ - cpml_segment_next(&original); - segment = cpml_segment_deep_dup(&original); - cpml_segment_reverse(segment); + g_assert_cmpint(segment->data[2].header.type, ==, CPML_CURVE); + g_assert_cmpfloat(segment->data[3].point.x, ==, 10); + g_assert_cmpfloat(segment->data[3].point.y, ==, 11); + g_assert_cmpfloat(segment->data[4].point.x, ==, 8); + g_assert_cmpfloat(segment->data[4].point.y, ==, 9); + g_assert_cmpfloat(segment->data[5].point.x, ==, 6); + g_assert_cmpfloat(segment->data[5].point.y, ==, 7); - g_assert_cmpint(segment->num_data, ==, 3); + g_assert_cmpint(segment->data[6].header.type, ==, CPML_ARC); + g_assert_cmpfloat(segment->data[7].point.x, ==, 4); + g_assert_cmpfloat(segment->data[7].point.y, ==, 5); + g_assert_cmpfloat(segment->data[8].point.x, ==, 3); + g_assert_cmpfloat(segment->data[8].point.y, ==, 1); - g_assert_cmpint(segment->data[0].header.type, ==, CPML_MOVE); - g_assert_cmpfloat(segment->data[1].point.x, ==, 24); - g_assert_cmpfloat(segment->data[1].point.y, ==, 25); + g_assert_cmpint(segment->data[9].header.type, ==, CPML_LINE); + g_assert_cmpfloat(segment->data[10].point.x, ==, 0); + g_assert_cmpfloat(segment->data[10].point.y, ==, 1); - g_assert_cmpint(segment->data[2].header.type, ==, CPML_CLOSE); + g_assert_cmpint(segment->data[11].header.type, ==, CPML_CLOSE); g_free(segment); } @@ -473,7 +416,7 @@ _cpml_test_to_cairo(void) int length, last_length; cr = adg_test_cairo_context(); - cpml_segment_from_cairo(&segment, &path); + cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); g_assert_cmpint(adg_test_cairo_num_data(cr), ==, 0); @@ -495,18 +438,13 @@ _cpml_test_dump(gint i) switch (i) { case 1: - cpml_segment_from_cairo(&segment, &path); - cpml_segment_dump(&segment); - cpml_segment_next(&segment); + cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); cpml_segment_dump(&segment); break; default: g_test_trap_assert_passed(); g_test_trap_assert_stderr_unmatched("?"); - g_test_trap_assert_stdout("*move*"); - g_test_trap_assert_stdout("*line*"); - g_test_trap_assert_stdout("*curve*"); - g_test_trap_assert_stdout_unmatched("*arc*"); + g_test_trap_assert_stdout("*move*line*arc*curve*close*"); break; } } diff --git a/src/tests/adg-test.c b/src/tests/adg-test.c index ef84b990..f87c9274 100644 --- a/src/tests/adg-test.c +++ b/src/tests/adg-test.c @@ -93,6 +93,85 @@ adg_test_cairo_num_data(cairo_t *cr) return length; } +const cairo_path_t * +adg_test_path(void) +{ + static cairo_path_data_t data[] = { + + /* First segment: a valid segment with all primitive types */ + { .header = { CPML_MOVE, 2 }}, + { .point = { 0, 1 }}, + { .header = { CPML_LINE, 2 }}, + { .point = { 3, 1 }}, + { .header = { CPML_ARC, 3 }}, + { .point = { 4, 5 }}, + { .point = { 6, 7 }}, + { .header = { CPML_CURVE, 4 }}, + { .point = { 8, 9 }}, + { .point = { 10, 11 }}, + { .point = { -2, 2 }}, + { .header = { CPML_CLOSE, 1 }}, + + /* Useless CPML_MOVE */ + { .header = { CPML_MOVE, 2 }}, + { .point = { 0, 0 }}, + + /* Second segment: a couple of lines of length 1 and 2; + * line 2 intersects line 1 of the first segment in (1, 1) */ + { .header = { CPML_MOVE, 2 }}, + { .point = { 0, 0 }}, + { .header = { CPML_LINE, 2 }}, + { .point = { 1, 0 }}, + { .header = { CPML_LINE, 2 }}, + { .point = { 1, 2 }}, + + /* Another useless CPML_MOVE with useless embedded data */ + { .header = { CPML_MOVE, 4 }}, + { .point = { 1, 2 }}, + { .point = { 3, 4 }}, + { .point = { 5, 6 }}, + + /* Third segment: a Bézier curve with a trailing CPML_CLOSE */ + { .header = { CPML_MOVE, 2 }}, + { .point = { 10, 13 }}, + { .header = { CPML_CURVE, 4 }}, + { .point = { 8, 9 }}, + { .point = { 10, 11 }}, + { .point = { 12, 13 }}, + { .header = { CPML_CLOSE, 1 }}, + + /* A valid cairo segment considered invalid by CPML + * because does not have a leading CPML_MOVE */ + { .header = { CPML_LINE, 2 }}, + { .point = { 10, 0 }}, + { .header = { CPML_CLOSE, 1 }}, + + /* Another valid cairo segment invalid in CPML */ + { .header = { CPML_CLOSE, 1 }}, + + /* Forth segment: a couple of arcs */ + { .header = { CPML_MOVE, 2 }}, + { .point = { 14, 15 }}, + { .header = { CPML_ARC, 3 }}, + { .point = { 16, 17 }}, + { .point = { 18, 19 }}, + { .header = { CPML_ARC, 3 }}, + { .point = { 20, 21 }}, + { .point = { 22, 23 }}, + + /* Fifth segment: a floating CPML_CLOSE */ + { .header = { CPML_MOVE, 2 }}, + { .point = { 24, 25 }}, + { .header = { CPML_CLOSE, 1 }} + }; + static cairo_path_t path = { + CAIRO_STATUS_SUCCESS, + data, + G_N_ELEMENTS(data) + }; + return &path; +} + static void _adg_enum_checks(gconstpointer user_data) { diff --git a/src/tests/adg-test.h b/src/tests/adg-test.h index 8998560b..95cb254e 100644 --- a/src/tests/adg-test.h +++ b/src/tests/adg-test.h @@ -92,6 +92,8 @@ void adg_test_init (int *p_argc, const gpointer adg_test_invalid_pointer (void); cairo_t * adg_test_cairo_context (void); int adg_test_cairo_num_data (cairo_t *cr); +const cairo_path_t * + adg_test_path (void); void adg_test_add_enum_checks (const gchar *testpath, GType type); void adg_test_add_boxed_checks (const gchar *testpath, -- 2.11.4.GIT