test: updated test units
[adg.git] / src / cpml / tests / test-segment.c
blob21751c5ccbddc2024df15b50b2ae16425e0afe5e
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011,2012,2013 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.
21 #include "test-internal.h"
24 static cairo_path_data_t data[] = {
25 /* Useless heading CPML_MOVE */
26 { .header = { CPML_MOVE, 2 }},
27 { .point = { 0, 0 }},
29 /* First segment: a couple of lines */
30 { .header = { CPML_MOVE, 2 }},
31 { .point = { 0, 1 }},
32 { .header = { CPML_LINE, 2 }},
33 { .point = { 2, 3 }},
34 { .header = { CPML_LINE, 2 }},
35 { .point = { 4, 5 }},
37 /* Another useless CPML_MOVE with useless embedded data */
38 { .header = { CPML_MOVE, 3 }},
39 { .point = { 0, 0 }},
40 { .point = { 0, 0 }},
42 /* Second segment: a Bézier curve with a trailing CPML_CLOSE */
43 { .header = { CPML_MOVE, 2 }},
44 { .point = { 6, 7 }},
45 { .header = { CPML_CURVE, 4 }},
46 { .point = { 8, 9 }},
47 { .point = { 10, 11 }},
48 { .point = { 12, 13 }},
49 { .header = { CPML_CLOSE, 1 }},
51 /* A valid cairo segment considered invalid by CPML
52 * because does not have a heading CPML_MOVE */
53 { .header = { CPML_LINE, 2 }},
54 { .point = { 0, 0 }},
55 { .header = { CPML_CLOSE, 1 }},
57 /* Another valid cairo segment invalid in CPML */
58 { .header = { CPML_CLOSE, 1 }},
60 /* Third segment: a couple of arcs */
61 { .header = { CPML_MOVE, 2 }},
62 { .point = { 14, 15 }},
63 { .header = { CPML_ARC, 3 }},
64 { .point = { 16, 17 }},
65 { .point = { 18, 19 }},
66 { .header = { CPML_ARC, 3 }},
67 { .point = { 20, 21 }},
68 { .point = { 22, 23 }},
70 /* Forth segment: a floating CPML_CLOSE */
71 { .header = { CPML_MOVE, 2 }},
72 { .point = { 24, 25 }},
73 { .header = { CPML_CLOSE, 1 }}
76 static cairo_path_data_t noop_data[] = {
77 /* Useless heading CPML_MOVE */
78 { .header = { CPML_MOVE, 2 }},
79 { .point = { 0, 1 }},
80 { .header = { CPML_MOVE, 4 }},
81 { .point = { 2, 3 }},
82 { .point = { 4, 5 }},
83 { .point = { 6, 7 }},
84 { .header = { CPML_MOVE, 2 }},
85 { .point = { 8, 9 }}
88 cairo_path_t path = {
89 CAIRO_STATUS_SUCCESS,
90 data,
91 G_N_ELEMENTS(data)
94 cairo_path_t noop_path = {
95 CAIRO_STATUS_SUCCESS,
96 noop_data,
97 G_N_ELEMENTS(noop_data)
101 static void
102 _cpml_test_basic(void)
104 cairo_bool_t found;
105 CpmlSegment segment, segment_copy;
107 /* Checking APIs */
108 found = cpml_segment_from_cairo(&segment, &noop_path);
109 g_assert(! found);
111 /* CPML entry point */
112 found = cpml_segment_from_cairo(&segment, &path);
113 g_assert(found);
115 /* First segment */
116 g_assert_cmpint(segment.data[0].header.type, ==, CPML_MOVE);
117 g_assert_cmpint(segment.data[2].header.type, ==, CPML_LINE);
119 /* Second segment */
120 found = cpml_segment_next(&segment);
121 g_assert(found);
122 g_assert_cmpint(segment.data[0].header.type, ==, CPML_MOVE);
123 g_assert_cmpint(segment.data[2].header.type, ==, CPML_CURVE);
125 /* Third segment */
126 found = cpml_segment_next(&segment);
127 g_assert(found);
128 g_assert_cmpint(segment.data[0].header.type, ==, CPML_MOVE);
129 g_assert_cmpint(segment.data[2].header.type, ==, CPML_ARC);
131 /* Forth segment */
132 found = cpml_segment_next(&segment);
133 g_assert(found);
134 g_assert_cmpint(segment.data[0].header.type, ==, CPML_MOVE);
135 g_assert_cmpint(segment.data[2].header.type, ==, CPML_CLOSE);
137 /* Copy and boundaries check */
138 cpml_segment_copy(&segment_copy, &segment);
139 found = cpml_segment_next(&segment);
140 g_assert(! found);
141 found = cpml_segment_next(&segment_copy);
142 g_assert(! found);
143 cpml_segment_reset(&segment_copy);
144 g_assert_cmpint(segment_copy.data[0].header.type, ==, CPML_MOVE);
145 g_assert_cmpint(segment_copy.data[2].header.type, ==, CPML_LINE);
150 main(int argc, char *argv[])
152 cpml_test_init(&argc, &argv);
154 cpml_test_add_func("/cpml/segment/basic", _cpml_test_basic);
156 return g_test_run();