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"
25 _adg_test_color_dress(void)
27 AdgLineStyle
*line_style
;
28 AdgDress valid_dress_1
, valid_dress_2
, incompatible_dress
;
31 line_style
= adg_line_style_new();
32 valid_dress_1
= ADG_DRESS_COLOR_DIMENSION
;
33 valid_dress_2
= ADG_DRESS_COLOR_FILL
;
34 incompatible_dress
= ADG_DRESS_FONT_QUOTE_ANNOTATION
;
36 /* Using the public APIs */
37 adg_line_style_set_color_dress(line_style
, valid_dress_1
);
38 color_dress
= adg_line_style_get_color_dress(line_style
);
39 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
41 adg_line_style_set_color_dress(line_style
, incompatible_dress
);
42 color_dress
= adg_line_style_get_color_dress(line_style
);
43 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
45 adg_line_style_set_color_dress(line_style
, valid_dress_2
);
46 color_dress
= adg_line_style_get_color_dress(line_style
);
47 g_assert_cmpint(color_dress
, ==, valid_dress_2
);
49 /* Using GObject property methods */
50 g_object_set(line_style
, "color-dress", valid_dress_1
, NULL
);
51 g_object_get(line_style
, "color-dress", &color_dress
, NULL
);
52 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
54 g_object_set(line_style
, "color-dress", incompatible_dress
, NULL
);
55 g_object_get(line_style
, "color-dress", &color_dress
, NULL
);
56 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
58 g_object_set(line_style
, "color-dress", valid_dress_2
, NULL
);
59 g_object_get(line_style
, "color-dress", &color_dress
, NULL
);
60 g_assert_cmpint(color_dress
, ==, valid_dress_2
);
62 g_object_unref(line_style
);
68 AdgLineStyle
*line_style
;
69 gdouble valid_width_1
, valid_width_2
, invalid_width
;
72 line_style
= adg_line_style_new();
77 /* Using the public APIs */
78 adg_line_style_set_width(line_style
, valid_width_1
);
79 width
= adg_line_style_get_width(line_style
);
80 g_assert_cmpfloat(width
, ==, valid_width_1
);
82 adg_line_style_set_width(line_style
, invalid_width
);
83 width
= adg_line_style_get_width(line_style
);
84 g_assert_cmpfloat(width
, ==, valid_width_1
);
86 adg_line_style_set_width(line_style
, valid_width_2
);
87 width
= adg_line_style_get_width(line_style
);
88 g_assert_cmpfloat(width
, ==, valid_width_2
);
90 /* Using GObject property methods */
91 g_object_set(line_style
, "width", valid_width_1
, NULL
);
92 g_object_get(line_style
, "width", &width
, NULL
);
93 g_assert_cmpfloat(width
, ==, valid_width_1
);
95 g_object_set(line_style
, "width", invalid_width
, NULL
);
96 g_object_get(line_style
, "width", &width
, NULL
);
97 g_assert_cmpfloat(width
, ==, valid_width_1
);
99 g_object_set(line_style
, "width", valid_width_2
, NULL
);
100 g_object_get(line_style
, "width", &width
, NULL
);
101 g_assert_cmpfloat(width
, ==, valid_width_2
);
103 g_object_unref(line_style
);
109 AdgLineStyle
*line_style
;
110 cairo_line_cap_t valid_cap_1
, valid_cap_2
, cap
;
112 line_style
= adg_line_style_new();
113 valid_cap_1
= CAIRO_LINE_CAP_SQUARE
;
114 valid_cap_2
= CAIRO_LINE_CAP_BUTT
;
116 /* Using the public APIs */
117 adg_line_style_set_cap(line_style
, valid_cap_1
);
118 cap
= adg_line_style_get_cap(line_style
);
119 g_assert_cmpint(cap
, ==, valid_cap_1
);
121 adg_line_style_set_cap(line_style
, valid_cap_2
);
122 cap
= adg_line_style_get_cap(line_style
);
123 g_assert_cmpint(cap
, ==, valid_cap_2
);
125 /* Using GObject property methods */
126 g_object_set(line_style
, "cap", valid_cap_1
, NULL
);
127 g_object_get(line_style
, "cap", &cap
, NULL
);
128 g_assert_cmpint(cap
, ==, valid_cap_1
);
130 g_object_set(line_style
, "cap", valid_cap_2
, NULL
);
131 g_object_get(line_style
, "cap", &cap
, NULL
);
132 g_assert_cmpint(cap
, ==, valid_cap_2
);
134 g_object_unref(line_style
);
140 AdgLineStyle
*line_style
;
141 cairo_line_join_t valid_join_1
, valid_join_2
, join
;
143 line_style
= adg_line_style_new();
144 valid_join_1
= CAIRO_LINE_JOIN_BEVEL
;
145 valid_join_2
= CAIRO_LINE_JOIN_MITER
;
147 /* Using the public APIs */
148 adg_line_style_set_join(line_style
, valid_join_1
);
149 join
= adg_line_style_get_join(line_style
);
150 g_assert_cmpint(join
, ==, valid_join_1
);
152 adg_line_style_set_join(line_style
, valid_join_2
);
153 join
= adg_line_style_get_join(line_style
);
154 g_assert_cmpint(join
, ==, valid_join_2
);
156 /* Using GObject property methods */
157 g_object_set(line_style
, "join", valid_join_1
, NULL
);
158 g_object_get(line_style
, "join", &join
, NULL
);
159 g_assert_cmpint(join
, ==, valid_join_1
);
161 g_object_set(line_style
, "join", valid_join_2
, NULL
);
162 g_object_get(line_style
, "join", &join
, NULL
);
163 g_assert_cmpint(join
, ==, valid_join_2
);
165 g_object_unref(line_style
);
169 _adg_test_miter_limit(void)
171 AdgLineStyle
*line_style
;
172 gdouble valid_miter_limit_1
, valid_miter_limit_2
, invalid_miter_limit
;
175 line_style
= adg_line_style_new();
176 valid_miter_limit_1
= 0;
177 valid_miter_limit_2
= 1000;
178 invalid_miter_limit
= -1;
180 /* Using the public APIs */
181 adg_line_style_set_miter_limit(line_style
, valid_miter_limit_1
);
182 miter_limit
= adg_line_style_get_miter_limit(line_style
);
183 g_assert_cmpfloat(miter_limit
, ==, valid_miter_limit_1
);
185 adg_line_style_set_miter_limit(line_style
, invalid_miter_limit
);
186 miter_limit
= adg_line_style_get_miter_limit(line_style
);
187 g_assert_cmpfloat(miter_limit
, ==, valid_miter_limit_1
);
189 adg_line_style_set_miter_limit(line_style
, valid_miter_limit_2
);
190 miter_limit
= adg_line_style_get_miter_limit(line_style
);
191 g_assert_cmpfloat(miter_limit
, ==, valid_miter_limit_2
);
193 /* Using GObject property methods */
194 g_object_set(line_style
, "miter-limit", valid_miter_limit_1
, NULL
);
195 g_object_get(line_style
, "miter-limit", &miter_limit
, NULL
);
196 g_assert_cmpfloat(miter_limit
, ==, valid_miter_limit_1
);
198 g_object_set(line_style
, "miter-limit", invalid_miter_limit
, NULL
);
199 g_object_get(line_style
, "miter-limit", &miter_limit
, NULL
);
200 g_assert_cmpfloat(miter_limit
, ==, valid_miter_limit_1
);
202 g_object_set(line_style
, "miter-limit", valid_miter_limit_2
, NULL
);
203 g_object_get(line_style
, "miter-limit", &miter_limit
, NULL
);
204 g_assert_cmpfloat(miter_limit
, ==, valid_miter_limit_2
);
206 g_object_unref(line_style
);
210 _adg_test_antialias(void)
212 AdgLineStyle
*line_style
;
213 cairo_antialias_t valid_antialias_1
, valid_antialias_2
, antialias
;
215 line_style
= adg_line_style_new();
216 valid_antialias_1
= CAIRO_ANTIALIAS_SUBPIXEL
;
217 valid_antialias_2
= CAIRO_ANTIALIAS_DEFAULT
;
219 /* Using the public APIs */
220 adg_line_style_set_antialias(line_style
, valid_antialias_1
);
221 antialias
= adg_line_style_get_antialias(line_style
);
222 g_assert_cmpint(antialias
, ==, valid_antialias_1
);
224 adg_line_style_set_antialias(line_style
, valid_antialias_2
);
225 antialias
= adg_line_style_get_antialias(line_style
);
226 g_assert_cmpint(antialias
, ==, valid_antialias_2
);
228 /* Using GObject property methods */
229 g_object_set(line_style
, "antialias", valid_antialias_1
, NULL
);
230 g_object_get(line_style
, "antialias", &antialias
, NULL
);
231 g_assert_cmpint(antialias
, ==, valid_antialias_1
);
233 g_object_set(line_style
, "antialias", valid_antialias_2
, NULL
);
234 g_object_get(line_style
, "antialias", &antialias
, NULL
);
235 g_assert_cmpint(antialias
, ==, valid_antialias_2
);
237 g_object_unref(line_style
);
243 AdgLineStyle
*line_style
;
246 gint num_dashes
, new_num_dashes
;
247 const gdouble
*dashes
, *new_dashes
;
249 line_style
= adg_line_style_new();
251 /* Checking default value */
252 dash
= adg_line_style_get_dash(line_style
);
253 g_assert(dash
== NULL
);
254 dash
= (AdgDash
*) 0xdead;
255 g_object_get(line_style
, "dash", &dash
, NULL
);
256 g_assert(dash
== NULL
);
258 /* Using the public APIs */
259 new_dash
= adg_dash_new_with_dashes(3, 1, 2, 3);
260 new_dashes
= adg_dash_get_dashes(new_dash
);
261 new_num_dashes
= adg_dash_get_num_dashes(new_dash
);
262 adg_line_style_set_dash(line_style
, new_dash
);
263 dash
= adg_line_style_get_dash(line_style
);
264 dashes
= adg_dash_get_dashes(dash
);
265 num_dashes
= adg_dash_get_num_dashes(dash
);
266 g_assert_cmpint(new_num_dashes
, ==, num_dashes
);
267 g_assert_cmpfloat(new_dashes
[0], ==, dashes
[0]);
268 g_assert_cmpfloat(new_dashes
[1], ==, dashes
[1]);
269 g_assert_cmpfloat(new_dashes
[2], ==, dashes
[2]);
270 adg_dash_destroy(new_dash
);
272 /* Using GObject property methods */
273 new_dash
= adg_dash_new_with_dashes(2, 4, 5);
274 new_dashes
= adg_dash_get_dashes(new_dash
);
275 new_num_dashes
= adg_dash_get_num_dashes(new_dash
);
276 g_object_set(line_style
, "dash", new_dash
, NULL
);
277 g_object_get(line_style
, "dash", &dash
, NULL
);
278 dashes
= adg_dash_get_dashes(dash
);
279 num_dashes
= adg_dash_get_num_dashes(dash
);
280 g_assert_cmpint(new_num_dashes
, ==, num_dashes
);
281 g_assert_cmpfloat(new_dashes
[0], ==, dashes
[0]);
282 g_assert_cmpfloat(new_dashes
[1], ==, dashes
[1]);
283 adg_dash_destroy(new_dash
);
285 /* Checking the unset of dash */
286 adg_line_style_set_dash(line_style
, NULL
);
287 dash
= adg_line_style_get_dash(line_style
);
288 g_assert(dash
== NULL
);
290 g_object_unref(line_style
);
295 main(int argc
, char *argv
[])
297 adg_test_init(&argc
, &argv
);
299 adg_test_add_func("/adg/line-style/color-dress", _adg_test_color_dress
);
300 adg_test_add_func("/adg/line-style/width", _adg_test_width
);
301 adg_test_add_func("/adg/line-style/cap", _adg_test_cap
);
302 adg_test_add_func("/adg/line-style/join", _adg_test_join
);
303 adg_test_add_func("/adg/line-style/miter-limit", _adg_test_miter_limit
);
304 adg_test_add_func("/adg/line-style/antialias", _adg_test_antialias
);
305 adg_test_add_func("/adg/line-style/dash", _adg_test_dash
);