1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2010 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_antialias(void)
27 AdgLineStyle
*line_style
;
28 cairo_antialias_t valid_antialias_1
, valid_antialias_2
, antialias
;
30 line_style
= adg_line_style_new();
31 valid_antialias_1
= CAIRO_ANTIALIAS_SUBPIXEL
;
32 valid_antialias_2
= CAIRO_ANTIALIAS_DEFAULT
;
34 /* Using the public APIs */
35 adg_line_style_set_antialias(line_style
, valid_antialias_1
);
36 antialias
= adg_line_style_get_antialias(line_style
);
37 g_assert_cmpint(antialias
, ==, valid_antialias_1
);
39 adg_line_style_set_antialias(line_style
, valid_antialias_2
);
40 antialias
= adg_line_style_get_antialias(line_style
);
41 g_assert_cmpint(antialias
, ==, valid_antialias_2
);
43 /* Using GObject property methods */
44 g_object_set(line_style
, "antialias", valid_antialias_1
, NULL
);
45 g_object_get(line_style
, "antialias", &antialias
, NULL
);
46 g_assert_cmpint(antialias
, ==, valid_antialias_1
);
48 g_object_set(line_style
, "antialias", valid_antialias_2
, NULL
);
49 g_object_get(line_style
, "antialias", &antialias
, NULL
);
50 g_assert_cmpint(antialias
, ==, valid_antialias_2
);
52 g_object_unref(line_style
);
58 AdgLineStyle
*line_style
;
59 cairo_line_cap_t valid_cap_1
, valid_cap_2
, cap
;
61 line_style
= adg_line_style_new();
62 valid_cap_1
= CAIRO_LINE_CAP_SQUARE
;
63 valid_cap_2
= CAIRO_LINE_CAP_BUTT
;
65 /* Using the public APIs */
66 adg_line_style_set_cap(line_style
, valid_cap_1
);
67 cap
= adg_line_style_get_cap(line_style
);
68 g_assert_cmpint(cap
, ==, valid_cap_1
);
70 adg_line_style_set_cap(line_style
, valid_cap_2
);
71 cap
= adg_line_style_get_cap(line_style
);
72 g_assert_cmpint(cap
, ==, valid_cap_2
);
74 /* Using GObject property methods */
75 g_object_set(line_style
, "cap", valid_cap_1
, NULL
);
76 g_object_get(line_style
, "cap", &cap
, NULL
);
77 g_assert_cmpint(cap
, ==, valid_cap_1
);
79 g_object_set(line_style
, "cap", valid_cap_2
, NULL
);
80 g_object_get(line_style
, "cap", &cap
, NULL
);
81 g_assert_cmpint(cap
, ==, valid_cap_2
);
83 g_object_unref(line_style
);
87 _adg_test_color_dress(void)
89 AdgLineStyle
*line_style
;
90 AdgDress valid_dress_1
, valid_dress_2
, incompatible_dress
;
93 line_style
= adg_line_style_new();
94 valid_dress_1
= ADG_DRESS_COLOR_DIMENSION
;
95 valid_dress_2
= ADG_DRESS_COLOR_HATCH
;
96 incompatible_dress
= ADG_DRESS_TEXT_LIMIT
;
98 /* Using the public APIs */
99 adg_line_style_set_color_dress(line_style
, valid_dress_1
);
100 color_dress
= adg_line_style_get_color_dress(line_style
);
101 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
103 adg_line_style_set_color_dress(line_style
, incompatible_dress
);
104 color_dress
= adg_line_style_get_color_dress(line_style
);
105 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
107 adg_line_style_set_color_dress(line_style
, valid_dress_2
);
108 color_dress
= adg_line_style_get_color_dress(line_style
);
109 g_assert_cmpint(color_dress
, ==, valid_dress_2
);
111 /* Using GObject property methods */
112 g_object_set(line_style
, "color-dress", valid_dress_1
, NULL
);
113 g_object_get(line_style
, "color-dress", &color_dress
, NULL
);
114 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
116 g_object_set(line_style
, "color-dress", incompatible_dress
, NULL
);
117 g_object_get(line_style
, "color-dress", &color_dress
, NULL
);
118 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
120 g_object_set(line_style
, "color-dress", valid_dress_2
, NULL
);
121 g_object_get(line_style
, "color-dress", &color_dress
, NULL
);
122 g_assert_cmpint(color_dress
, ==, valid_dress_2
);
124 g_object_unref(line_style
);
130 AdgLineStyle
*line_style
;
131 cairo_line_join_t valid_join_1
, valid_join_2
, join
;
133 line_style
= adg_line_style_new();
134 valid_join_1
= CAIRO_LINE_JOIN_BEVEL
;
135 valid_join_2
= CAIRO_LINE_JOIN_MITER
;
137 /* Using the public APIs */
138 adg_line_style_set_join(line_style
, valid_join_1
);
139 join
= adg_line_style_get_join(line_style
);
140 g_assert_cmpint(join
, ==, valid_join_1
);
142 adg_line_style_set_join(line_style
, valid_join_2
);
143 join
= adg_line_style_get_join(line_style
);
144 g_assert_cmpint(join
, ==, valid_join_2
);
146 /* Using GObject property methods */
147 g_object_set(line_style
, "join", valid_join_1
, NULL
);
148 g_object_get(line_style
, "join", &join
, NULL
);
149 g_assert_cmpint(join
, ==, valid_join_1
);
151 g_object_set(line_style
, "join", valid_join_2
, NULL
);
152 g_object_get(line_style
, "join", &join
, NULL
);
153 g_assert_cmpint(join
, ==, valid_join_2
);
155 g_object_unref(line_style
);
159 _adg_test_miter_limit(void)
161 AdgLineStyle
*line_style
;
162 gdouble valid_miter_limit_1
, valid_miter_limit_2
, invalid_miter_limit
;
165 line_style
= adg_line_style_new();
166 valid_miter_limit_1
= 0;
167 valid_miter_limit_2
= 1000;
168 invalid_miter_limit
= -1;
170 /* Using the public APIs */
171 adg_line_style_set_miter_limit(line_style
, valid_miter_limit_1
);
172 miter_limit
= adg_line_style_get_miter_limit(line_style
);
173 g_assert_cmpfloat(miter_limit
, ==, valid_miter_limit_1
);
175 adg_line_style_set_miter_limit(line_style
, invalid_miter_limit
);
176 miter_limit
= adg_line_style_get_miter_limit(line_style
);
177 g_assert_cmpfloat(miter_limit
, ==, valid_miter_limit_1
);
179 adg_line_style_set_miter_limit(line_style
, valid_miter_limit_2
);
180 miter_limit
= adg_line_style_get_miter_limit(line_style
);
181 g_assert_cmpfloat(miter_limit
, ==, valid_miter_limit_2
);
183 /* Using GObject property methods */
184 g_object_set(line_style
, "miter-limit", valid_miter_limit_1
, NULL
);
185 g_object_get(line_style
, "miter-limit", &miter_limit
, NULL
);
186 g_assert_cmpfloat(miter_limit
, ==, valid_miter_limit_1
);
188 g_object_set(line_style
, "miter-limit", invalid_miter_limit
, NULL
);
189 g_object_get(line_style
, "miter-limit", &miter_limit
, NULL
);
190 g_assert_cmpfloat(miter_limit
, ==, valid_miter_limit_1
);
192 g_object_set(line_style
, "miter-limit", valid_miter_limit_2
, NULL
);
193 g_object_get(line_style
, "miter-limit", &miter_limit
, NULL
);
194 g_assert_cmpfloat(miter_limit
, ==, valid_miter_limit_2
);
196 g_object_unref(line_style
);
200 _adg_test_width(void)
202 AdgLineStyle
*line_style
;
203 gdouble valid_width_1
, valid_width_2
, invalid_width
;
206 line_style
= adg_line_style_new();
211 /* Using the public APIs */
212 adg_line_style_set_width(line_style
, valid_width_1
);
213 width
= adg_line_style_get_width(line_style
);
214 g_assert_cmpfloat(width
, ==, valid_width_1
);
216 adg_line_style_set_width(line_style
, invalid_width
);
217 width
= adg_line_style_get_width(line_style
);
218 g_assert_cmpfloat(width
, ==, valid_width_1
);
220 adg_line_style_set_width(line_style
, valid_width_2
);
221 width
= adg_line_style_get_width(line_style
);
222 g_assert_cmpfloat(width
, ==, valid_width_2
);
224 /* Using GObject property methods */
225 g_object_set(line_style
, "width", valid_width_1
, NULL
);
226 g_object_get(line_style
, "width", &width
, NULL
);
227 g_assert_cmpfloat(width
, ==, valid_width_1
);
229 g_object_set(line_style
, "width", invalid_width
, NULL
);
230 g_object_get(line_style
, "width", &width
, NULL
);
231 g_assert_cmpfloat(width
, ==, valid_width_1
);
233 g_object_set(line_style
, "width", valid_width_2
, NULL
);
234 g_object_get(line_style
, "width", &width
, NULL
);
235 g_assert_cmpfloat(width
, ==, valid_width_2
);
237 g_object_unref(line_style
);
242 main(int argc
, char *argv
[])
244 adg_test_init(&argc
, &argv
);
246 adg_test_add_func("/adg/line-style/antialias", _adg_test_antialias
);
247 adg_test_add_func("/adg/line-style/cap", _adg_test_cap
);
248 adg_test_add_func("/adg/line-style/color-dress", _adg_test_color_dress
);
249 adg_test_add_func("/adg/line-style/join", _adg_test_join
);
250 adg_test_add_func("/adg/line-style/miter-limit", _adg_test_miter_limit
);
251 adg_test_add_func("/adg/line-style/width", _adg_test_width
);