1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2021 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.
26 _adg_property_color_dress(void)
28 AdgLineStyle
*line_style
;
29 AdgDress valid_dress_1
, valid_dress_2
, incompatible_dress
;
32 line_style
= adg_line_style_new();
33 valid_dress_1
= ADG_DRESS_COLOR_DIMENSION
;
34 valid_dress_2
= ADG_DRESS_COLOR_FILL
;
35 incompatible_dress
= ADG_DRESS_FONT_QUOTE_ANNOTATION
;
37 /* Using the public APIs */
38 adg_line_style_set_color_dress(line_style
, valid_dress_1
);
39 color_dress
= adg_line_style_get_color_dress(line_style
);
40 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
42 adg_line_style_set_color_dress(line_style
, incompatible_dress
);
43 color_dress
= adg_line_style_get_color_dress(line_style
);
44 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
46 adg_line_style_set_color_dress(line_style
, valid_dress_2
);
47 color_dress
= adg_line_style_get_color_dress(line_style
);
48 g_assert_cmpint(color_dress
, ==, valid_dress_2
);
50 /* Using GObject property methods */
51 g_object_set(line_style
, "color-dress", valid_dress_1
, NULL
);
52 g_object_get(line_style
, "color-dress", &color_dress
, NULL
);
53 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
55 g_object_set(line_style
, "color-dress", incompatible_dress
, NULL
);
56 g_object_get(line_style
, "color-dress", &color_dress
, NULL
);
57 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
59 g_object_set(line_style
, "color-dress", valid_dress_2
, NULL
);
60 g_object_get(line_style
, "color-dress", &color_dress
, NULL
);
61 g_assert_cmpint(color_dress
, ==, valid_dress_2
);
63 g_object_unref(line_style
);
67 _adg_property_width(void)
69 AdgLineStyle
*line_style
;
70 gdouble valid_width_1
, valid_width_2
, invalid_width
;
73 line_style
= adg_line_style_new();
78 /* Using the public APIs */
79 adg_line_style_set_width(line_style
, valid_width_1
);
80 width
= adg_line_style_get_width(line_style
);
81 adg_assert_isapprox(width
, valid_width_1
);
83 adg_line_style_set_width(line_style
, invalid_width
);
84 width
= adg_line_style_get_width(line_style
);
85 adg_assert_isapprox(width
, valid_width_1
);
87 adg_line_style_set_width(line_style
, valid_width_2
);
88 width
= adg_line_style_get_width(line_style
);
89 adg_assert_isapprox(width
, valid_width_2
);
91 /* Using GObject property methods */
92 g_object_set(line_style
, "width", valid_width_1
, NULL
);
93 g_object_get(line_style
, "width", &width
, NULL
);
94 adg_assert_isapprox(width
, valid_width_1
);
96 g_object_set(line_style
, "width", invalid_width
, NULL
);
97 g_object_get(line_style
, "width", &width
, NULL
);
98 adg_assert_isapprox(width
, valid_width_1
);
100 g_object_set(line_style
, "width", valid_width_2
, NULL
);
101 g_object_get(line_style
, "width", &width
, NULL
);
102 adg_assert_isapprox(width
, valid_width_2
);
104 g_object_unref(line_style
);
108 _adg_property_cap(void)
110 AdgLineStyle
*line_style
;
111 cairo_line_cap_t valid_cap_1
, valid_cap_2
, cap
;
113 line_style
= adg_line_style_new();
114 valid_cap_1
= CAIRO_LINE_CAP_SQUARE
;
115 valid_cap_2
= CAIRO_LINE_CAP_BUTT
;
117 /* Using the public APIs */
118 adg_line_style_set_cap(line_style
, valid_cap_1
);
119 cap
= adg_line_style_get_cap(line_style
);
120 g_assert_cmpint(cap
, ==, valid_cap_1
);
122 adg_line_style_set_cap(line_style
, valid_cap_2
);
123 cap
= adg_line_style_get_cap(line_style
);
124 g_assert_cmpint(cap
, ==, valid_cap_2
);
126 /* Using GObject property methods */
127 g_object_set(line_style
, "cap", valid_cap_1
, NULL
);
128 g_object_get(line_style
, "cap", &cap
, NULL
);
129 g_assert_cmpint(cap
, ==, valid_cap_1
);
131 g_object_set(line_style
, "cap", valid_cap_2
, NULL
);
132 g_object_get(line_style
, "cap", &cap
, NULL
);
133 g_assert_cmpint(cap
, ==, valid_cap_2
);
135 g_object_unref(line_style
);
139 _adg_property_join(void)
141 AdgLineStyle
*line_style
;
142 cairo_line_join_t valid_join_1
, valid_join_2
, join
;
144 line_style
= adg_line_style_new();
145 valid_join_1
= CAIRO_LINE_JOIN_BEVEL
;
146 valid_join_2
= CAIRO_LINE_JOIN_MITER
;
148 /* Using the public APIs */
149 adg_line_style_set_join(line_style
, valid_join_1
);
150 join
= adg_line_style_get_join(line_style
);
151 g_assert_cmpint(join
, ==, valid_join_1
);
153 adg_line_style_set_join(line_style
, valid_join_2
);
154 join
= adg_line_style_get_join(line_style
);
155 g_assert_cmpint(join
, ==, valid_join_2
);
157 /* Using GObject property methods */
158 g_object_set(line_style
, "join", valid_join_1
, NULL
);
159 g_object_get(line_style
, "join", &join
, NULL
);
160 g_assert_cmpint(join
, ==, valid_join_1
);
162 g_object_set(line_style
, "join", valid_join_2
, NULL
);
163 g_object_get(line_style
, "join", &join
, NULL
);
164 g_assert_cmpint(join
, ==, valid_join_2
);
166 g_object_unref(line_style
);
170 _adg_property_miter_limit(void)
172 AdgLineStyle
*line_style
;
173 gdouble valid_miter_limit_1
, valid_miter_limit_2
, invalid_miter_limit
;
176 line_style
= adg_line_style_new();
177 valid_miter_limit_1
= 0;
178 valid_miter_limit_2
= 1000;
179 invalid_miter_limit
= -1;
181 /* Using the public APIs */
182 adg_line_style_set_miter_limit(line_style
, valid_miter_limit_1
);
183 miter_limit
= adg_line_style_get_miter_limit(line_style
);
184 adg_assert_isapprox(miter_limit
, valid_miter_limit_1
);
186 adg_line_style_set_miter_limit(line_style
, invalid_miter_limit
);
187 miter_limit
= adg_line_style_get_miter_limit(line_style
);
188 adg_assert_isapprox(miter_limit
, valid_miter_limit_1
);
190 adg_line_style_set_miter_limit(line_style
, valid_miter_limit_2
);
191 miter_limit
= adg_line_style_get_miter_limit(line_style
);
192 adg_assert_isapprox(miter_limit
, valid_miter_limit_2
);
194 /* Using GObject property methods */
195 g_object_set(line_style
, "miter-limit", valid_miter_limit_1
, NULL
);
196 g_object_get(line_style
, "miter-limit", &miter_limit
, NULL
);
197 adg_assert_isapprox(miter_limit
, valid_miter_limit_1
);
199 g_object_set(line_style
, "miter-limit", invalid_miter_limit
, NULL
);
200 g_object_get(line_style
, "miter-limit", &miter_limit
, NULL
);
201 adg_assert_isapprox(miter_limit
, valid_miter_limit_1
);
203 g_object_set(line_style
, "miter-limit", valid_miter_limit_2
, NULL
);
204 g_object_get(line_style
, "miter-limit", &miter_limit
, NULL
);
205 adg_assert_isapprox(miter_limit
, valid_miter_limit_2
);
207 g_object_unref(line_style
);
211 _adg_property_antialias(void)
213 AdgLineStyle
*line_style
;
214 cairo_antialias_t valid_antialias_1
, valid_antialias_2
, antialias
;
216 line_style
= adg_line_style_new();
217 valid_antialias_1
= CAIRO_ANTIALIAS_SUBPIXEL
;
218 valid_antialias_2
= CAIRO_ANTIALIAS_DEFAULT
;
220 /* Using the public APIs */
221 adg_line_style_set_antialias(line_style
, valid_antialias_1
);
222 antialias
= adg_line_style_get_antialias(line_style
);
223 g_assert_cmpint(antialias
, ==, valid_antialias_1
);
225 adg_line_style_set_antialias(line_style
, valid_antialias_2
);
226 antialias
= adg_line_style_get_antialias(line_style
);
227 g_assert_cmpint(antialias
, ==, valid_antialias_2
);
229 /* Using GObject property methods */
230 g_object_set(line_style
, "antialias", valid_antialias_1
, NULL
);
231 g_object_get(line_style
, "antialias", &antialias
, NULL
);
232 g_assert_cmpint(antialias
, ==, valid_antialias_1
);
234 g_object_set(line_style
, "antialias", valid_antialias_2
, NULL
);
235 g_object_get(line_style
, "antialias", &antialias
, NULL
);
236 g_assert_cmpint(antialias
, ==, valid_antialias_2
);
238 g_object_unref(line_style
);
242 _adg_property_dash(void)
244 AdgLineStyle
*line_style
;
247 gint num_dashes
, new_num_dashes
;
248 const gdouble
*dashes
, *new_dashes
;
250 line_style
= adg_line_style_new();
252 /* Checking default value */
253 dash
= adg_line_style_get_dash(line_style
);
255 dash
= (AdgDash
*) 0xdead;
256 g_object_get(line_style
, "dash", &dash
, NULL
);
259 /* Using the public APIs */
260 new_dash
= adg_dash_new_with_dashes(3, 1, 2, 3);
261 new_dashes
= adg_dash_get_dashes(new_dash
);
262 new_num_dashes
= adg_dash_get_num_dashes(new_dash
);
263 adg_line_style_set_dash(line_style
, new_dash
);
264 dash
= adg_line_style_get_dash(line_style
);
265 dashes
= adg_dash_get_dashes(dash
);
266 num_dashes
= adg_dash_get_num_dashes(dash
);
267 g_assert_cmpint(new_num_dashes
, ==, num_dashes
);
268 adg_assert_isapprox(new_dashes
[0], dashes
[0]);
269 adg_assert_isapprox(new_dashes
[1], dashes
[1]);
270 adg_assert_isapprox(new_dashes
[2], dashes
[2]);
271 adg_dash_destroy(new_dash
);
273 /* Using GObject property methods */
274 new_dash
= adg_dash_new_with_dashes(2, 4, 5);
275 new_dashes
= adg_dash_get_dashes(new_dash
);
276 new_num_dashes
= adg_dash_get_num_dashes(new_dash
);
277 g_object_set(line_style
, "dash", new_dash
, NULL
);
278 g_object_get(line_style
, "dash", &dash
, NULL
);
279 dashes
= adg_dash_get_dashes(dash
);
280 num_dashes
= adg_dash_get_num_dashes(dash
);
281 g_assert_cmpint(new_num_dashes
, ==, num_dashes
);
282 adg_assert_isapprox(new_dashes
[0], dashes
[0]);
283 adg_assert_isapprox(new_dashes
[1], dashes
[1]);
284 adg_dash_destroy(new_dash
);
286 /* Checking the unset of dash */
287 adg_line_style_set_dash(line_style
, NULL
);
288 dash
= adg_line_style_get_dash(line_style
);
291 g_object_unref(line_style
);
296 main(int argc
, char *argv
[])
298 adg_test_init(&argc
, &argv
);
300 adg_test_add_object_checks("/adg/line-style/type/object", ADG_TYPE_LINE_STYLE
);
302 g_test_add_func("/adg/line-style/property/color-dress", _adg_property_color_dress
);
303 g_test_add_func("/adg/line-style/property/width", _adg_property_width
);
304 g_test_add_func("/adg/line-style/property/cap", _adg_property_cap
);
305 g_test_add_func("/adg/line-style/property/join", _adg_property_join
);
306 g_test_add_func("/adg/line-style/property/miter-limit", _adg_property_miter_limit
);
307 g_test_add_func("/adg/line-style/property/antialias", _adg_property_antialias
);
308 g_test_add_func("/adg/line-style/property/dash", _adg_property_dash
);