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 AdgFontStyle
*font_style
;
28 cairo_antialias_t valid_antialias_1
, valid_antialias_2
, antialias
;
30 font_style
= adg_font_style_new();
31 valid_antialias_1
= CAIRO_ANTIALIAS_SUBPIXEL
;
32 valid_antialias_2
= CAIRO_ANTIALIAS_DEFAULT
;
34 /* Using the public APIs */
35 adg_font_style_set_antialias(font_style
, valid_antialias_1
);
36 antialias
= adg_font_style_get_antialias(font_style
);
37 g_assert_cmpint(antialias
, ==, valid_antialias_1
);
39 adg_font_style_set_antialias(font_style
, valid_antialias_2
);
40 antialias
= adg_font_style_get_antialias(font_style
);
41 g_assert_cmpint(antialias
, ==, valid_antialias_2
);
43 /* Using GObject property methods */
44 g_object_set(font_style
, "antialias", valid_antialias_1
, NULL
);
45 g_object_get(font_style
, "antialias", &antialias
, NULL
);
46 g_assert_cmpint(antialias
, ==, valid_antialias_1
);
48 g_object_set(font_style
, "antialias", valid_antialias_2
, NULL
);
49 g_object_get(font_style
, "antialias", &antialias
, NULL
);
50 g_assert_cmpint(antialias
, ==, valid_antialias_2
);
52 g_object_unref(font_style
);
56 _adg_test_color_dress(void)
58 AdgFontStyle
*font_style
;
59 AdgDress valid_dress_1
, valid_dress_2
, incompatible_dress
;
62 font_style
= adg_font_style_new();
63 valid_dress_1
= ADG_DRESS_COLOR_DIMENSION
;
64 valid_dress_2
= ADG_DRESS_COLOR_HATCH
;
65 incompatible_dress
= ADG_DRESS_TEXT_LIMIT
;
67 /* Using the public APIs */
68 adg_font_style_set_color_dress(font_style
, valid_dress_1
);
69 color_dress
= adg_font_style_get_color_dress(font_style
);
70 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
72 adg_font_style_set_color_dress(font_style
, incompatible_dress
);
73 color_dress
= adg_font_style_get_color_dress(font_style
);
74 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
76 adg_font_style_set_color_dress(font_style
, valid_dress_2
);
77 color_dress
= adg_font_style_get_color_dress(font_style
);
78 g_assert_cmpint(color_dress
, ==, valid_dress_2
);
80 /* Using GObject property methods */
81 g_object_set(font_style
, "color-dress", valid_dress_1
, NULL
);
82 g_object_get(font_style
, "color-dress", &color_dress
, NULL
);
83 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
85 g_object_set(font_style
, "color-dress", incompatible_dress
, NULL
);
86 g_object_get(font_style
, "color-dress", &color_dress
, NULL
);
87 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
89 g_object_set(font_style
, "color-dress", valid_dress_2
, NULL
);
90 g_object_get(font_style
, "color-dress", &color_dress
, NULL
);
91 g_assert_cmpint(color_dress
, ==, valid_dress_2
);
93 g_object_unref(font_style
);
97 _adg_test_family(void)
99 AdgFontStyle
*font_style
;
100 const gchar
*valid_text_1
, *valid_text_2
;
104 font_style
= adg_font_style_new();
105 valid_text_1
= "Sans serif 10, bold";
108 /* Using the public APIs */
109 adg_font_style_set_family(font_style
, valid_text_1
);
110 family
= adg_font_style_get_family(font_style
);
111 g_assert_cmpstr(family
, ==, valid_text_1
);
113 adg_font_style_set_family(font_style
, valid_text_2
);
114 family
= adg_font_style_get_family(font_style
);
115 g_assert_cmpstr(family
, ==, valid_text_2
);
117 adg_font_style_set_family(font_style
, NULL
);
118 family
= adg_font_style_get_family(font_style
);
119 g_assert(family
== NULL
);
121 /* Using GObject property methods */
122 g_object_set(font_style
, "family", valid_text_1
, NULL
);
123 g_object_get(font_style
, "family", &family_dup
, NULL
);
124 g_assert_cmpstr(family_dup
, ==, valid_text_1
);
127 g_object_set(font_style
, "family", valid_text_2
, NULL
);
128 g_object_get(font_style
, "family", &family_dup
, NULL
);
129 g_assert_cmpstr(family_dup
, ==, valid_text_2
);
132 g_object_set(font_style
, "family", NULL
, NULL
);
133 g_object_get(font_style
, "family", &family_dup
, NULL
);
134 g_assert(family_dup
== NULL
);
136 g_object_unref(font_style
);
140 _adg_test_hint_metrics(void)
142 AdgFontStyle
*font_style
;
143 cairo_hint_metrics_t valid_hint_metrics_1
, valid_hint_metrics_2
;
144 cairo_hint_metrics_t hint_metrics
;
146 font_style
= adg_font_style_new();
147 valid_hint_metrics_1
= CAIRO_HINT_METRICS_DEFAULT
;
148 valid_hint_metrics_2
= CAIRO_HINT_METRICS_ON
;
150 /* Using the public APIs */
151 adg_font_style_set_hint_metrics(font_style
, valid_hint_metrics_1
);
152 hint_metrics
= adg_font_style_get_hint_metrics(font_style
);
153 g_assert_cmpint(hint_metrics
, ==, valid_hint_metrics_1
);
155 adg_font_style_set_hint_metrics(font_style
, valid_hint_metrics_2
);
156 hint_metrics
= adg_font_style_get_hint_metrics(font_style
);
157 g_assert_cmpint(hint_metrics
, ==, valid_hint_metrics_2
);
159 /* Using GObject property methods */
160 g_object_set(font_style
, "hint-metrics", valid_hint_metrics_1
, NULL
);
161 g_object_get(font_style
, "hint-metrics", &hint_metrics
, NULL
);
162 g_assert_cmpint(hint_metrics
, ==, valid_hint_metrics_1
);
164 g_object_set(font_style
, "hint-metrics", valid_hint_metrics_2
, NULL
);
165 g_object_get(font_style
, "hint-metrics", &hint_metrics
, NULL
);
166 g_assert_cmpint(hint_metrics
, ==, valid_hint_metrics_2
);
168 g_object_unref(font_style
);
172 _adg_test_hint_style(void)
174 AdgFontStyle
*font_style
;
175 cairo_hint_style_t valid_hint_style_1
, valid_hint_style_2
;
176 cairo_hint_style_t hint_style
;
178 font_style
= adg_font_style_new();
179 valid_hint_style_1
= CAIRO_HINT_STYLE_MEDIUM
;
180 valid_hint_style_2
= CAIRO_HINT_STYLE_SLIGHT
;
182 /* Using the public APIs */
183 adg_font_style_set_hint_style(font_style
, valid_hint_style_1
);
184 hint_style
= adg_font_style_get_hint_style(font_style
);
185 g_assert_cmpint(hint_style
, ==, valid_hint_style_1
);
187 adg_font_style_set_hint_style(font_style
, valid_hint_style_2
);
188 hint_style
= adg_font_style_get_hint_style(font_style
);
189 g_assert_cmpint(hint_style
, ==, valid_hint_style_2
);
191 /* Using GObject property methods */
192 g_object_set(font_style
, "hint-style", valid_hint_style_1
, NULL
);
193 g_object_get(font_style
, "hint-style", &hint_style
, NULL
);
194 g_assert_cmpint(hint_style
, ==, valid_hint_style_1
);
196 g_object_set(font_style
, "hint-style", valid_hint_style_2
, NULL
);
197 g_object_get(font_style
, "hint-style", &hint_style
, NULL
);
198 g_assert_cmpint(hint_style
, ==, valid_hint_style_2
);
200 g_object_unref(font_style
);
206 AdgFontStyle
*font_style
;
207 gdouble valid_size_1
, valid_size_2
, invalid_size
;
210 font_style
= adg_font_style_new();
215 /* Using the public APIs */
216 adg_font_style_set_size(font_style
, valid_size_1
);
217 size
= adg_font_style_get_size(font_style
);
218 g_assert_cmpfloat(size
, ==, valid_size_1
);
220 adg_font_style_set_size(font_style
, invalid_size
);
221 size
= adg_font_style_get_size(font_style
);
222 g_assert_cmpfloat(size
, ==, valid_size_1
);
224 adg_font_style_set_size(font_style
, valid_size_2
);
225 size
= adg_font_style_get_size(font_style
);
226 g_assert_cmpfloat(size
, ==, valid_size_2
);
228 /* Using GObject property methods */
229 g_object_set(font_style
, "size", valid_size_1
, NULL
);
230 g_object_get(font_style
, "size", &size
, NULL
);
231 g_assert_cmpfloat(size
, ==, valid_size_1
);
233 g_object_set(font_style
, "size", invalid_size
, NULL
);
234 g_object_get(font_style
, "size", &size
, NULL
);
235 g_assert_cmpfloat(size
, ==, valid_size_1
);
237 g_object_set(font_style
, "size", valid_size_2
, NULL
);
238 g_object_get(font_style
, "size", &size
, NULL
);
239 g_assert_cmpfloat(size
, ==, valid_size_2
);
241 g_object_unref(font_style
);
245 _adg_test_slant(void)
247 AdgFontStyle
*font_style
;
248 cairo_font_slant_t valid_slant_1
, valid_slant_2
;
249 cairo_font_slant_t slant
;
251 font_style
= adg_font_style_new();
252 valid_slant_1
= CAIRO_FONT_WEIGHT_NORMAL
;
253 valid_slant_2
= CAIRO_FONT_WEIGHT_BOLD
;
255 /* Using the public APIs */
256 adg_font_style_set_slant(font_style
, valid_slant_1
);
257 slant
= adg_font_style_get_slant(font_style
);
258 g_assert_cmpint(slant
, ==, valid_slant_1
);
260 adg_font_style_set_slant(font_style
, valid_slant_2
);
261 slant
= adg_font_style_get_slant(font_style
);
262 g_assert_cmpint(slant
, ==, valid_slant_2
);
264 /* Using GObject property methods */
265 g_object_set(font_style
, "slant", valid_slant_1
, NULL
);
266 g_object_get(font_style
, "slant", &slant
, NULL
);
267 g_assert_cmpint(slant
, ==, valid_slant_1
);
269 g_object_set(font_style
, "slant", valid_slant_2
, NULL
);
270 g_object_get(font_style
, "slant", &slant
, NULL
);
271 g_assert_cmpint(slant
, ==, valid_slant_2
);
273 g_object_unref(font_style
);
277 _adg_test_subpixel_order(void)
279 AdgFontStyle
*font_style
;
280 cairo_subpixel_order_t valid_subpixel_order_1
, valid_subpixel_order_2
;
281 cairo_subpixel_order_t subpixel_order
;
283 font_style
= adg_font_style_new();
284 valid_subpixel_order_1
= CAIRO_SUBPIXEL_ORDER_RGB
;
285 valid_subpixel_order_2
= CAIRO_SUBPIXEL_ORDER_BGR
;
287 /* Using the public APIs */
288 adg_font_style_set_subpixel_order(font_style
, valid_subpixel_order_1
);
289 subpixel_order
= adg_font_style_get_subpixel_order(font_style
);
290 g_assert_cmpint(subpixel_order
, ==, valid_subpixel_order_1
);
292 adg_font_style_set_subpixel_order(font_style
, valid_subpixel_order_2
);
293 subpixel_order
= adg_font_style_get_subpixel_order(font_style
);
294 g_assert_cmpint(subpixel_order
, ==, valid_subpixel_order_2
);
296 /* Using GObject property methods */
297 g_object_set(font_style
, "subpixel-order", valid_subpixel_order_1
, NULL
);
298 g_object_get(font_style
, "subpixel-order", &subpixel_order
, NULL
);
299 g_assert_cmpint(subpixel_order
, ==, valid_subpixel_order_1
);
301 g_object_set(font_style
, "subpixel-order", valid_subpixel_order_2
, NULL
);
302 g_object_get(font_style
, "subpixel-order", &subpixel_order
, NULL
);
303 g_assert_cmpint(subpixel_order
, ==, valid_subpixel_order_2
);
305 g_object_unref(font_style
);
309 _adg_test_weight(void)
311 AdgFontStyle
*font_style
;
312 cairo_font_weight_t valid_weight_1
, valid_weight_2
;
313 cairo_font_weight_t weight
;
315 font_style
= adg_font_style_new();
316 valid_weight_1
= CAIRO_FONT_WEIGHT_NORMAL
;
317 valid_weight_2
= CAIRO_FONT_WEIGHT_BOLD
;
319 /* Using the public APIs */
320 adg_font_style_set_weight(font_style
, valid_weight_1
);
321 weight
= adg_font_style_get_weight(font_style
);
322 g_assert_cmpint(weight
, ==, valid_weight_1
);
324 adg_font_style_set_weight(font_style
, valid_weight_2
);
325 weight
= adg_font_style_get_weight(font_style
);
326 g_assert_cmpint(weight
, ==, valid_weight_2
);
328 /* Using GObject property methods */
329 g_object_set(font_style
, "weight", valid_weight_1
, NULL
);
330 g_object_get(font_style
, "weight", &weight
, NULL
);
331 g_assert_cmpint(weight
, ==, valid_weight_1
);
333 g_object_set(font_style
, "weight", valid_weight_2
, NULL
);
334 g_object_get(font_style
, "weight", &weight
, NULL
);
335 g_assert_cmpint(weight
, ==, valid_weight_2
);
337 g_object_unref(font_style
);
342 main(int argc
, char *argv
[])
344 adg_test_init(&argc
, &argv
);
346 adg_test_add_func("/adg/font-style/antialias", _adg_test_antialias
);
347 adg_test_add_func("/adg/font-style/color-dress", _adg_test_color_dress
);
348 adg_test_add_func("/adg/font-style/family", _adg_test_family
);
349 adg_test_add_func("/adg/font-style/hint-metrics", _adg_test_hint_metrics
);
350 adg_test_add_func("/adg/font-style/hint-style", _adg_test_hint_style
);
351 adg_test_add_func("/adg/font-style/size", _adg_test_size
);
352 adg_test_add_func("/adg/font-style/slant", _adg_test_slant
);
353 adg_test_add_func("/adg/font-style/subpixel-order", _adg_test_subpixel_order
);
354 adg_test_add_func("/adg/font-style/weight", _adg_test_weight
);