24031e13b732a01cb3a48937510530384506647b
[adg.git] / src / cpml / tests / test-segment.c
blob24031e13b732a01cb3a48937510530384506647b
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 CpmlPath path = {
89 CAIRO_STATUS_SUCCESS,
90 data,
91 G_N_ELEMENTS(data)
94 CpmlPath 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, empty;
105 CpmlSegment segment, segment_copy;
107 /* Checking APIs */
108 empty = cpml_path_is_empty(NULL);
109 g_assert(empty);
110 empty = cpml_path_is_empty(&noop_path);
111 g_assert(! empty);
112 found = cpml_segment_from_cairo(&segment, &noop_path);
113 g_assert(! found);
114 empty = cpml_path_is_empty(&path);
115 g_assert(! empty);
117 /* CPML entry point */
118 found = cpml_segment_from_cairo(&segment, &path);
119 g_assert(found);
121 /* First segment */
122 g_assert_cmpint(segment.data[0].header.type, ==, CPML_MOVE);
123 g_assert_cmpint(segment.data[2].header.type, ==, CPML_LINE);
125 /* Second 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_CURVE);
131 /* Third 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_ARC);
137 /* Forth segment */
138 found = cpml_segment_next(&segment);
139 g_assert(found);
140 g_assert_cmpint(segment.data[0].header.type, ==, CPML_MOVE);
141 g_assert_cmpint(segment.data[2].header.type, ==, CPML_CLOSE);
143 /* Copy and boundaries check */
144 cpml_segment_copy(&segment_copy, &segment);
145 found = cpml_segment_next(&segment);
146 g_assert(! found);
147 found = cpml_segment_next(&segment_copy);
148 g_assert(! found);
149 cpml_segment_reset(&segment_copy);
150 g_assert_cmpint(segment_copy.data[0].header.type, ==, CPML_MOVE);
151 g_assert_cmpint(segment_copy.data[2].header.type, ==, CPML_LINE);
156 main(int argc, char *argv[])
158 cpml_test_init(&argc, &argv);
160 cpml_test_add_func("/cpml/segment/basic", _cpml_test_basic);
162 return g_test_run();