1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2015 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
27 _cpml_test_browsing(void)
30 CpmlPrimitive primitive
, primitive_copy
;
32 cpml_segment_from_cairo(&segment
, (cairo_path_t
*) adg_test_path());
34 cpml_primitive_from_segment(&primitive
, &segment
);
35 g_assert_cmpfloat((primitive
.org
)->point
.x
, ==, 0);
36 g_assert_cmpfloat((primitive
.org
)->point
.y
, ==, 1);
37 g_assert_cmpint((primitive
.data
)->header
.type
, ==, CPML_LINE
);
38 g_assert_true(cpml_primitive_next(&primitive
));
39 g_assert_cmpfloat((primitive
.org
)->point
.x
, ==, 3);
40 g_assert_cmpfloat((primitive
.org
)->point
.y
, ==, 1);
41 g_assert_cmpint((primitive
.data
)->header
.type
, ==, CPML_ARC
);
42 g_assert_true(cpml_primitive_next(&primitive
));
43 g_assert_cmpfloat((primitive
.org
)->point
.x
, ==, 6);
44 g_assert_cmpfloat((primitive
.org
)->point
.y
, ==, 7);
45 g_assert_cmpint((primitive
.data
)->header
.type
, ==, CPML_CURVE
);
46 g_assert_true(cpml_primitive_next(&primitive
));
47 g_assert_cmpfloat((primitive
.org
)->point
.x
, ==, -2);
48 g_assert_cmpfloat((primitive
.org
)->point
.y
, ==, 2);
49 g_assert_cmpint((primitive
.data
)->header
.type
, ==, CPML_CLOSE
);
50 g_assert_false(cpml_primitive_next(&primitive
));
52 cpml_primitive_reset(&primitive
);
53 g_assert_true(cpml_primitive_next(&primitive
));
54 cpml_primitive_reset(&primitive
);
55 cpml_primitive_reset(&primitive
);
56 g_assert_true(cpml_primitive_next(&primitive
));
57 g_assert_true(cpml_primitive_next(&primitive
));
58 g_assert_true(cpml_primitive_next(&primitive
));
59 g_assert_false(cpml_primitive_next(&primitive
));
61 cpml_primitive_copy(&primitive_copy
, &primitive
);
62 g_assert_false(cpml_primitive_next(&primitive_copy
));
63 cpml_primitive_reset(&primitive
);
64 g_assert_false(cpml_primitive_next(&primitive_copy
));
65 cpml_primitive_reset(&primitive_copy
);
66 g_assert_true(cpml_primitive_next(&primitive_copy
));
70 _cpml_test_sanity_from_segment(gint i
)
72 CpmlPrimitive primitive
;
77 cpml_primitive_from_segment(NULL
, &segment
);
80 cpml_primitive_from_segment(&primitive
, NULL
);
83 g_test_trap_assert_failed();
89 _cpml_test_sanity_get_n_points(gint i
)
93 cpml_primitive_get_n_points(NULL
);
96 g_test_trap_assert_failed();
102 _cpml_test_sanity_put_point(gint i
)
105 CpmlPrimitive primitive
;
108 cpml_segment_from_cairo(&segment
, (cairo_path_t
*) adg_test_path());
109 cpml_primitive_from_segment(&primitive
, &segment
);
113 cpml_primitive_put_point(NULL
, 0, &pair
);
116 cpml_primitive_put_point(&primitive
, 0, NULL
);
119 g_test_trap_assert_failed();
125 _cpml_test_sanity_get_length(gint i
)
129 cpml_primitive_get_length(NULL
);
132 g_test_trap_assert_failed();
138 _cpml_test_sanity_put_intersections(gint i
)
140 CpmlPrimitive primitive
;
145 cpml_primitive_put_intersections(NULL
, &primitive
, 2, &pair
);
148 cpml_primitive_put_intersections(&primitive
, NULL
, 2, &pair
);
151 cpml_primitive_put_intersections(&primitive
, &primitive
, 2, NULL
);
154 g_test_trap_assert_failed();
160 _cpml_test_sanity_put_intersections_with_segment(gint i
)
162 CpmlPrimitive primitive
;
168 cpml_primitive_put_intersections_with_segment(NULL
, &segment
, 2, &pair
);
171 cpml_primitive_put_intersections_with_segment(&primitive
, NULL
, 2, &pair
);
174 cpml_primitive_put_intersections_with_segment(&primitive
, &segment
, 2, NULL
);
177 g_test_trap_assert_failed();
183 _cpml_test_sanity_join(gint i
)
185 CpmlPrimitive primitive
;
189 cpml_primitive_join(NULL
, &primitive
);
192 cpml_primitive_join(&primitive
, NULL
);
195 g_test_trap_assert_failed();
201 _cpml_test_sanity_dump(gint i
)
205 cpml_segment_dump(NULL
);
208 g_test_trap_assert_failed();
214 _cpml_test_sanity_to_cairo(gint i
)
216 CpmlPrimitive primitive
;
220 cpml_primitive_to_cairo(NULL
, adg_test_cairo_context());
223 cpml_primitive_to_cairo(&primitive
, NULL
);
226 g_test_trap_assert_failed();
232 _cpml_test_from_segment(void)
235 CpmlPrimitive primitive
;
237 g_assert_true(cpml_segment_from_cairo(&segment
, (cairo_path_t
*) adg_test_path()));
239 cpml_primitive_from_segment(&primitive
, &segment
);
240 g_assert_nonnull(primitive
.segment
);
241 g_assert_nonnull(primitive
.org
);
242 g_assert_nonnull(primitive
.data
);
246 _cpml_test_type_get_n_points(void)
250 n_points
= cpml_primitive_type_get_n_points(CPML_MOVE
);
251 g_assert_cmpuint(n_points
, ==, 0);
253 n_points
= cpml_primitive_type_get_n_points(CPML_LINE
);
254 g_assert_cmpuint(n_points
, ==, 2);
256 n_points
= cpml_primitive_type_get_n_points(CPML_ARC
);
257 g_assert_cmpuint(n_points
, ==, 3);
259 n_points
= cpml_primitive_type_get_n_points(CPML_CURVE
);
260 g_assert_cmpuint(n_points
, ==, 4);
262 n_points
= cpml_primitive_type_get_n_points(CPML_CLOSE
);
263 g_assert_cmpuint(n_points
, ==, 2);
267 _cpml_test_get_n_points(void)
270 CpmlPrimitive primitive
;
273 cpml_segment_from_cairo(&segment
, (cairo_path_t
*) adg_test_path());
276 cpml_primitive_from_segment(&primitive
, &segment
);
277 n_points
= cpml_primitive_get_n_points(&primitive
);
278 g_assert_cmpuint(n_points
, ==, 2);
281 cpml_primitive_next(&primitive
);
282 n_points
= cpml_primitive_get_n_points(&primitive
);
283 g_assert_cmpuint(n_points
, ==, 3);
286 cpml_primitive_next(&primitive
);
287 n_points
= cpml_primitive_get_n_points(&primitive
);
288 g_assert_cmpuint(n_points
, ==, 4);
290 /* Close: although the end point is not needed, the CPML API
291 * returns 2 points to treat this primitive as a CPML_LINE */
292 cpml_primitive_next(&primitive
);
293 n_points
= cpml_primitive_get_n_points(&primitive
);
294 g_assert_cmpuint(n_points
, ==, 2);
298 _cpml_test_set_point(void)
301 CpmlSegment original
, *segment
;
302 CpmlPrimitive primitive
;
303 CpmlPair pair
, pair2
;
306 /* Work on a copy to not modify the original path data */
307 cpml_segment_from_cairo(&original
, (cairo_path_t
*) adg_test_path());
308 data_size
= original
.num_data
* sizeof(cairo_path_data_t
);
309 segment
= cpml_segment_deep_dup(&original
);
312 cpml_primitive_from_segment(&primitive
, segment
);
314 equality
= memcmp(original
.data
, segment
->data
, data_size
);
315 g_assert_cmpint(equality
, ==, 0);
316 cpml_primitive_put_point(&primitive
, 0, &pair
);
318 cpml_primitive_set_point(&primitive
, 0, &pair
);
319 equality
= memcmp(original
.data
, segment
->data
, data_size
);
320 g_assert_cmpint(equality
, !=, 0);
322 cpml_primitive_set_point(&primitive
, 0, &pair
);
323 equality
= memcmp(original
.data
, segment
->data
, data_size
);
324 g_assert_cmpint(equality
, ==, 0);
325 cpml_primitive_put_point(&primitive
, 1, &pair
);
327 cpml_primitive_set_point(&primitive
, 1, &pair
);
328 equality
= memcmp(original
.data
, segment
->data
, data_size
);
329 g_assert_cmpint(equality
, !=, 0);
330 /* On a CPML_LINE primitives, -1 and 1 indices are equals */
331 cpml_primitive_put_point(&primitive
, -1, &pair2
);
332 g_assert_cmpfloat(pair
.x
, ==, pair2
.x
);
333 g_assert_cmpfloat(pair
.y
, ==, pair2
.y
);
334 memcpy(segment
->data
, original
.data
, data_size
);
335 equality
= memcmp(original
.data
, segment
->data
, data_size
);
336 g_assert_cmpint(equality
, ==, 0);
337 cpml_primitive_put_point(&primitive
, 2, &pair
);
340 /* This should be a NOP without segfaults */
341 cpml_primitive_set_point(&primitive
, 2, &pair
);
342 equality
= memcmp(original
.data
, segment
->data
, data_size
);
343 g_assert_cmpint(equality
, ==, 0);
345 /* From now on, memcpy() is assumed to force equality (as already
346 * proved by the previous assertions) and pair2 is used as a
347 * different-from-everything pair, that is setting pair2 on any
348 * point will break the equality between segment->data and
355 cpml_primitive_next(&primitive
);
357 cpml_primitive_set_point(&primitive
, 0, &pair2
);
358 equality
= memcmp(original
.data
, segment
->data
, data_size
);
359 g_assert_cmpint(equality
, !=, 0);
360 memcpy(segment
->data
, original
.data
, data_size
);
361 cpml_primitive_set_point(&primitive
, 1, &pair2
);
362 equality
= memcmp(original
.data
, segment
->data
, data_size
);
363 g_assert_cmpint(equality
, !=, 0);
364 memcpy(segment
->data
, original
.data
, data_size
);
365 cpml_primitive_set_point(&primitive
, 2, &pair2
);
366 equality
= memcmp(original
.data
, segment
->data
, data_size
);
367 g_assert_cmpint(equality
, !=, 0);
368 memcpy(segment
->data
, original
.data
, data_size
);
369 cpml_primitive_set_point(&primitive
, 3, &pair2
);
370 equality
= memcmp(original
.data
, segment
->data
, data_size
);
371 g_assert_cmpint(equality
, ==, 0);
374 cpml_primitive_next(&primitive
);
376 cpml_primitive_set_point(&primitive
, 0, &pair2
);
377 equality
= memcmp(original
.data
, segment
->data
, data_size
);
378 g_assert_cmpint(equality
, !=, 0);
379 memcpy(segment
->data
, original
.data
, data_size
);
380 cpml_primitive_set_point(&primitive
, 1, &pair2
);
381 equality
= memcmp(original
.data
, segment
->data
, data_size
);
382 g_assert_cmpint(equality
, !=, 0);
383 memcpy(segment
->data
, original
.data
, data_size
);
384 cpml_primitive_set_point(&primitive
, 2, &pair2
);
385 equality
= memcmp(original
.data
, segment
->data
, data_size
);
386 g_assert_cmpint(equality
, !=, 0);
387 memcpy(segment
->data
, original
.data
, data_size
);
388 cpml_primitive_set_point(&primitive
, 3, &pair2
);
389 equality
= memcmp(original
.data
, segment
->data
, data_size
);
390 g_assert_cmpint(equality
, !=, 0);
391 memcpy(segment
->data
, original
.data
, data_size
);
392 cpml_primitive_set_point(&primitive
, 4, &pair2
);
393 equality
= memcmp(original
.data
, segment
->data
, data_size
);
394 g_assert_cmpint(equality
, ==, 0);
397 cpml_primitive_next(&primitive
);
399 cpml_primitive_set_point(&primitive
, 0, &pair2
);
400 equality
= memcmp(original
.data
, segment
->data
, data_size
);
401 g_assert_cmpint(equality
, !=, 0);
402 memcpy(segment
->data
, original
.data
, data_size
);
403 cpml_primitive_set_point(&primitive
, 1, &pair2
);
404 equality
= memcmp(original
.data
, segment
->data
, data_size
);
405 g_assert_cmpint(equality
, !=, 0);
406 memcpy(segment
->data
, original
.data
, data_size
);
407 cpml_primitive_set_point(&primitive
, 2, &pair2
);
408 equality
= memcmp(original
.data
, segment
->data
, data_size
);
409 g_assert_cmpint(equality
, ==, 0);
415 _cpml_test_put_point(void)
418 CpmlPrimitive primitive
;
421 cpml_segment_from_cairo(&segment
, (cairo_path_t
*) adg_test_path());
424 cpml_primitive_from_segment(&primitive
, &segment
);
426 cpml_primitive_put_point(&primitive
, 0, &pair
);
427 g_assert_cmpfloat(pair
.x
, ==, 0);
428 g_assert_cmpfloat(pair
.y
, ==, 1);
429 cpml_primitive_put_point(&primitive
, 1, &pair
);
430 g_assert_cmpfloat(pair
.x
, ==, 3);
431 g_assert_cmpfloat(pair
.y
, ==, 1);
432 cpml_primitive_put_point(&primitive
, 2, &pair
);
433 g_assert_cmpfloat(pair
.x
, ==, 3);
434 g_assert_cmpfloat(pair
.y
, ==, 1);
435 /* The negative indices are checked only against CPML_LINE */
436 cpml_primitive_put_point(&primitive
, -1, &pair
);
437 g_assert_cmpfloat(pair
.x
, ==, 3);
438 g_assert_cmpfloat(pair
.y
, ==, 1);
439 cpml_primitive_put_point(&primitive
, -2, &pair
);
440 g_assert_cmpfloat(pair
.x
, ==, 0);
441 g_assert_cmpfloat(pair
.y
, ==, 1);
442 cpml_primitive_put_point(&primitive
, -3, &pair
);
443 g_assert_cmpfloat(pair
.x
, ==, 0);
444 g_assert_cmpfloat(pair
.y
, ==, 1);
447 cpml_primitive_next(&primitive
);
449 cpml_primitive_put_point(&primitive
, 0, &pair
);
450 g_assert_cmpfloat(pair
.x
, ==, 3);
451 g_assert_cmpfloat(pair
.y
, ==, 1);
452 cpml_primitive_put_point(&primitive
, 1, &pair
);
453 g_assert_cmpfloat(pair
.x
, ==, 4);
454 g_assert_cmpfloat(pair
.y
, ==, 5);
455 cpml_primitive_put_point(&primitive
, 2, &pair
);
456 g_assert_cmpfloat(pair
.x
, ==, 6);
457 g_assert_cmpfloat(pair
.y
, ==, 7);
458 cpml_primitive_put_point(&primitive
, 3, &pair
);
459 g_assert_cmpfloat(pair
.x
, ==, 6);
460 g_assert_cmpfloat(pair
.y
, ==, 7);
463 cpml_primitive_next(&primitive
);
465 cpml_primitive_put_point(&primitive
, 0, &pair
);
466 g_assert_cmpfloat(pair
.x
, ==, 6);
467 g_assert_cmpfloat(pair
.y
, ==, 7);
468 cpml_primitive_put_point(&primitive
, 1, &pair
);
469 g_assert_cmpfloat(pair
.x
, ==, 8);
470 g_assert_cmpfloat(pair
.y
, ==, 9);
471 cpml_primitive_put_point(&primitive
, 2, &pair
);
472 g_assert_cmpfloat(pair
.x
, ==, 10);
473 g_assert_cmpfloat(pair
.y
, ==, 11);
474 cpml_primitive_put_point(&primitive
, 3, &pair
);
475 g_assert_cmpfloat(pair
.x
, ==, -2);
476 g_assert_cmpfloat(pair
.y
, ==, 2);
477 cpml_primitive_put_point(&primitive
, 4, &pair
);
478 g_assert_cmpfloat(pair
.x
, ==, -2);
479 g_assert_cmpfloat(pair
.y
, ==, 2);
482 cpml_primitive_next(&primitive
);
484 cpml_primitive_put_point(&primitive
, 0, &pair
);
485 g_assert_cmpfloat(pair
.x
, ==, -2);
486 g_assert_cmpfloat(pair
.y
, ==, 2);
487 cpml_primitive_put_point(&primitive
, 1, &pair
);
488 g_assert_cmpfloat(pair
.x
, ==, 0);
489 g_assert_cmpfloat(pair
.y
, ==, 1);
490 cpml_primitive_put_point(&primitive
, 2, &pair
);
491 g_assert_cmpfloat(pair
.x
, ==, 0);
492 g_assert_cmpfloat(pair
.y
, ==, 1);
496 _cpml_test_get_length(void)
499 CpmlPrimitive primitive
;
501 cpml_segment_from_cairo(&segment
, (cairo_path_t
*) adg_test_path());
502 cpml_segment_next(&segment
);
503 cpml_primitive_from_segment(&primitive
, &segment
);
505 g_assert_cmpfloat(cpml_primitive_get_length(&primitive
), ==, 1);
507 cpml_primitive_next(&primitive
);
508 g_assert_cmpfloat(cpml_primitive_get_length(&primitive
), ==, 2);
512 _cpml_test_put_intersections(void)
515 CpmlPrimitive primitive1
, primitive2
;
518 /* Set primitive1 to 1.1 (first segment, first primitive) */
519 cpml_segment_from_cairo(&segment
, (cairo_path_t
*) adg_test_path());
520 cpml_primitive_from_segment(&primitive1
, &segment
);
522 /* Set primitive2 to 2.1 (second segment, first primitive) */
523 cpml_segment_next(&segment
);
524 cpml_primitive_from_segment(&primitive2
, &segment
);
526 /* primitive1 (1.1) does not intersect primitive2 (2.1) */
527 g_assert_cmpuint(cpml_primitive_put_intersections(&primitive1
, &primitive2
, 2, pair
), ==, 0);
529 cpml_primitive_next(&primitive2
);
531 /* primitive1 (1.1) intersects primitive2 (2.2) in (1, 1) */
532 g_assert_cmpuint(cpml_primitive_put_intersections(&primitive1
, &primitive2
, 2, pair
), ==, 1);
533 g_assert_cmpfloat(pair
[0].x
, ==, 1);
534 g_assert_cmpfloat(pair
[0].y
, ==, 1);
535 g_assert_cmpint(cpml_primitive_is_inside(&primitive1
, pair
), ==, 1);
536 g_assert_cmpint(cpml_primitive_is_inside(&primitive2
, pair
), ==, 1);
538 /* Check the intersection is not returned when not requested */
539 g_assert_cmpuint(cpml_primitive_put_intersections(&primitive1
, &primitive2
, 0, pair
), ==, 0);
541 cpml_primitive_next(&primitive1
);
543 /* primitive1 (1.2) does not intersect primitive2 (2.2) */
544 g_assert_cmpuint(cpml_primitive_put_intersections(&primitive1
, &primitive2
, 2, pair
), ==, 0);
546 cpml_primitive_next(&primitive1
);
548 /* primitive1 (1.3) does not intersect primitive2 (2.2) */
549 g_assert_cmpuint(cpml_primitive_put_intersections(&primitive1
, &primitive2
, 2, pair
), ==, 0);
551 cpml_primitive_next(&primitive1
);
553 /* primitive1 (1.4) intersects primitive2 (2.2), but outside their boundaries */
554 g_assert_cmpuint(cpml_primitive_put_intersections(&primitive1
, &primitive2
, 2, pair
), ==, 1);
555 g_assert_cmpfloat(pair
[0].x
, ==, 1);
556 g_assert_cmpfloat(pair
[0].y
, ==, -1);
557 g_assert_cmpint(cpml_primitive_is_inside(&primitive1
, pair
), ==, 0);
558 g_assert_cmpint(cpml_primitive_is_inside(&primitive2
, pair
), ==, 0);
562 _cpml_test_put_intersections_with_segment(void)
565 CpmlPrimitive primitive
;
568 /* Set primitive to first segment, first primitive */
569 cpml_segment_from_cairo(&segment
, (cairo_path_t
*) adg_test_path());
570 cpml_primitive_from_segment(&primitive
, &segment
);
572 /* Set segment to the second segment */
573 cpml_segment_next(&segment
);
575 /* primitive (1.1) intersects segment (2) in (1, 1) */
576 g_assert_cmpuint(cpml_primitive_put_intersections_with_segment(&primitive
, &segment
, 4, pair
), ==, 1);
577 g_assert_cmpfloat(pair
[0].x
, ==, 1);
578 g_assert_cmpfloat(pair
[0].y
, ==, 1);
580 cpml_primitive_next(&primitive
);
582 /* primitive (1.1) does not intersect segment (2) */
583 g_assert_cmpuint(cpml_primitive_put_intersections_with_segment(&primitive
, &segment
, 4, pair
), ==, 0);
585 /* Set primitive to second segment, first primitive */
586 cpml_primitive_from_segment(&primitive
, &segment
);
588 /* Set segment to the first segment */
589 cpml_segment_reset(&segment
);
591 /* primitive (2.1) intersects segment (1) in extrapolation.
592 * TODO: change this behavior! They must not intersect. */
593 g_assert_cmpuint(cpml_primitive_put_intersections_with_segment(&primitive
, &segment
, 4, pair
), ==, 1);
594 g_assert_cmpfloat(pair
[0].x
, ==, 2);
595 g_assert_cmpfloat(pair
[0].y
, ==, 0);
597 cpml_primitive_next(&primitive
);
599 /* primitive (2.2) wrongly intersects segment (1) */
600 g_assert_cmpuint(cpml_primitive_put_intersections_with_segment(&primitive
, &segment
, 4, pair
), ==, 1);
601 g_assert_cmpfloat(pair
[0].x
, ==, 2);
602 g_assert_cmpfloat(pair
[0].y
, ==, 0);
606 _cpml_test_join(void)
608 cairo_path_data_t path_data
[] = {
609 { .header
= { CPML_MOVE
, 2 }},
610 { .point
= { 0, 0 }},
612 { .header
= { CPML_LINE
, 2 }},
613 { .point
= { 2, 0 }},
615 { .header
= { CPML_LINE
, 2 }},
616 { .point
= { 2, 2 }},
618 { .header
= { CPML_LINE
, 2 }},
619 { .point
= { 1, 2 }},
621 { .header
= { CPML_LINE
, 2 }},
622 { .point
= { 1, -2 }}
624 cairo_path_t path
= {
625 CAIRO_STATUS_SUCCESS
,
627 G_N_ELEMENTS(path_data
)
630 CpmlPrimitive primitive1
, primitive2
;
632 cpml_segment_from_cairo(&segment
, &path
);
634 cpml_primitive_from_segment(&primitive1
, &segment
);
635 cpml_primitive_copy(&primitive2
, &primitive1
);
636 cpml_primitive_next(&primitive2
);
638 /* primitive1 and primitive2 are already joint */
639 g_assert_cmpint(cpml_primitive_join(&primitive1
, &primitive2
), ==, 1);
640 g_assert_cmpfloat((primitive2
.org
)->point
.x
, ==, 2);
641 g_assert_cmpfloat((primitive2
.org
)->point
.y
, ==, 0);
643 cpml_primitive_next(&primitive2
);
644 /* Now primitive1 and primitive2 are divergent,
645 * hence cannot be joined */
646 g_assert_cmpint(cpml_primitive_join(&primitive1
, &primitive2
), ==, 0);
648 cpml_primitive_next(&primitive2
);
649 g_assert_cmpint(cpml_primitive_join(&primitive1
, &primitive2
), ==, 1);
650 g_assert_cmpfloat((primitive2
.org
)->point
.x
, ==, 1);
651 g_assert_cmpfloat((primitive2
.org
)->point
.y
, ==, 0);
655 _cpml_test_to_cairo(void)
659 CpmlPrimitive primitive
;
660 int length
, last_length
;
662 cr
= adg_test_cairo_context();
663 cpml_segment_from_cairo(&segment
, (cairo_path_t
*) adg_test_path());
664 cpml_primitive_from_segment(&primitive
, &segment
);
666 g_assert_cmpint(adg_test_cairo_num_data(cr
), ==, 0);
670 last_length
= length
;
671 cpml_primitive_to_cairo(&primitive
, cr
);
672 length
= adg_test_cairo_num_data(cr
);
673 g_assert_cmpint(length
, >, last_length
);
674 } while (cpml_primitive_next(&primitive
));
680 _cpml_test_dump(gint i
)
683 CpmlPrimitive primitive
;
687 cpml_segment_from_cairo(&segment
, (cairo_path_t
*) adg_test_path());
688 cpml_primitive_from_segment(&primitive
, &segment
);
689 cpml_primitive_dump(&primitive
, 1);
691 cpml_primitive_next(&primitive
);
692 cpml_primitive_dump(&primitive
, 1);
695 g_test_trap_assert_passed();
696 g_test_trap_assert_stderr_unmatched("?");
697 g_test_trap_assert_stdout("*NULL*");
698 g_test_trap_assert_stdout("*move*");
699 g_test_trap_assert_stdout("*line*");
705 main(int argc
, char *argv
[])
707 adg_test_init(&argc
, &argv
);
709 g_test_add_func("/cpml/primitive/behavior/browsing", _cpml_test_browsing
);
711 adg_test_add_traps("/cpml/primitive/sanity/from-segment", _cpml_test_sanity_from_segment
, 1);
712 adg_test_add_traps("/cpml/primitive/sanity/get-n-points", _cpml_test_sanity_get_n_points
, 1);
713 adg_test_add_traps("/cpml/primitive/sanity/put-point", _cpml_test_sanity_put_point
, 2);
714 adg_test_add_traps("/cpml/primitive/sanity/get-length", _cpml_test_sanity_get_length
, 1);
715 adg_test_add_traps("/cpml/primitive/sanity/put-intersections", _cpml_test_sanity_put_intersections
, 3);
716 adg_test_add_traps("/cpml/primitive/sanity/put-intersections-with-segment", _cpml_test_sanity_put_intersections_with_segment
, 3);
717 adg_test_add_traps("/cpml/primitive/sanity/join", _cpml_test_sanity_join
, 2);
718 adg_test_add_traps("/cpml/primitive/sanity/to-cairo", _cpml_test_sanity_to_cairo
, 2);
719 adg_test_add_traps("/cpml/primitive/sanity/dump", _cpml_test_sanity_dump
, 1);
721 g_test_add_func("/cpml/primitive/method/from-segment", _cpml_test_from_segment
);
722 g_test_add_func("/cpml/primitive/method/type-get-n-points", _cpml_test_type_get_n_points
);
723 g_test_add_func("/cpml/primitive/method/get-n-points", _cpml_test_get_n_points
);
724 g_test_add_func("/cpml/primitive/method/set-point", _cpml_test_set_point
);
725 g_test_add_func("/cpml/primitive/method/put-point", _cpml_test_put_point
);
726 g_test_add_func("/cpml/primitive/method/get-length", _cpml_test_get_length
);
727 g_test_add_func("/cpml/primitive/method/put-intersections", _cpml_test_put_intersections
);
728 g_test_add_func("/cpml/primitive/method/put-intersections-with-segment", _cpml_test_put_intersections_with_segment
);
729 g_test_add_func("/cpml/primitive/method/join", _cpml_test_join
);
730 g_test_add_func("/cpml/primitive/method/to-cairo", _cpml_test_to_cairo
);
731 adg_test_add_traps("/cpml/primitive/method/dump", _cpml_test_dump
, 1);