1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2015 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_test_antialias(void)
28 AdgFontStyle
*font_style
;
29 cairo_antialias_t valid_antialias_1
, valid_antialias_2
, antialias
;
31 font_style
= adg_font_style_new();
32 valid_antialias_1
= CAIRO_ANTIALIAS_SUBPIXEL
;
33 valid_antialias_2
= CAIRO_ANTIALIAS_DEFAULT
;
35 /* Using the public APIs */
36 adg_font_style_set_antialias(font_style
, valid_antialias_1
);
37 antialias
= adg_font_style_get_antialias(font_style
);
38 g_assert_cmpint(antialias
, ==, valid_antialias_1
);
40 adg_font_style_set_antialias(font_style
, valid_antialias_2
);
41 antialias
= adg_font_style_get_antialias(font_style
);
42 g_assert_cmpint(antialias
, ==, valid_antialias_2
);
44 /* Using GObject property methods */
45 g_object_set(font_style
, "antialias", valid_antialias_1
, NULL
);
46 g_object_get(font_style
, "antialias", &antialias
, NULL
);
47 g_assert_cmpint(antialias
, ==, valid_antialias_1
);
49 g_object_set(font_style
, "antialias", valid_antialias_2
, NULL
);
50 g_object_get(font_style
, "antialias", &antialias
, NULL
);
51 g_assert_cmpint(antialias
, ==, valid_antialias_2
);
53 g_object_unref(font_style
);
57 _adg_test_color_dress(void)
59 AdgFontStyle
*font_style
;
60 AdgDress valid_dress_1
, valid_dress_2
, incompatible_dress
;
63 font_style
= adg_font_style_new();
64 valid_dress_1
= ADG_DRESS_COLOR_DIMENSION
;
65 valid_dress_2
= ADG_DRESS_COLOR_FILL
;
66 incompatible_dress
= ADG_DRESS_FONT_QUOTE_TEXT
;
68 /* Using the public APIs */
69 adg_font_style_set_color_dress(font_style
, valid_dress_1
);
70 color_dress
= adg_font_style_get_color_dress(font_style
);
71 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
73 adg_font_style_set_color_dress(font_style
, incompatible_dress
);
74 color_dress
= adg_font_style_get_color_dress(font_style
);
75 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
77 adg_font_style_set_color_dress(font_style
, valid_dress_2
);
78 color_dress
= adg_font_style_get_color_dress(font_style
);
79 g_assert_cmpint(color_dress
, ==, valid_dress_2
);
81 /* Using GObject property methods */
82 g_object_set(font_style
, "color-dress", valid_dress_1
, NULL
);
83 g_object_get(font_style
, "color-dress", &color_dress
, NULL
);
84 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
86 g_object_set(font_style
, "color-dress", incompatible_dress
, NULL
);
87 g_object_get(font_style
, "color-dress", &color_dress
, NULL
);
88 g_assert_cmpint(color_dress
, ==, valid_dress_1
);
90 g_object_set(font_style
, "color-dress", valid_dress_2
, NULL
);
91 g_object_get(font_style
, "color-dress", &color_dress
, NULL
);
92 g_assert_cmpint(color_dress
, ==, valid_dress_2
);
94 g_object_unref(font_style
);
98 _adg_test_family(void)
100 AdgFontStyle
*font_style
;
101 const gchar
*valid_text_1
, *valid_text_2
;
105 font_style
= adg_font_style_new();
106 valid_text_1
= "Sans serif 10, bold";
109 /* Using the public APIs */
110 adg_font_style_set_family(font_style
, valid_text_1
);
111 family
= adg_font_style_get_family(font_style
);
112 g_assert_cmpstr(family
, ==, valid_text_1
);
114 adg_font_style_set_family(font_style
, valid_text_2
);
115 family
= adg_font_style_get_family(font_style
);
116 g_assert_cmpstr(family
, ==, valid_text_2
);
118 adg_font_style_set_family(font_style
, NULL
);
119 family
= adg_font_style_get_family(font_style
);
120 g_assert(family
== NULL
);
122 /* Using GObject property methods */
123 g_object_set(font_style
, "family", valid_text_1
, NULL
);
124 g_object_get(font_style
, "family", &family_dup
, NULL
);
125 g_assert_cmpstr(family_dup
, ==, valid_text_1
);
128 g_object_set(font_style
, "family", valid_text_2
, NULL
);
129 g_object_get(font_style
, "family", &family_dup
, NULL
);
130 g_assert_cmpstr(family_dup
, ==, valid_text_2
);
133 g_object_set(font_style
, "family", NULL
, NULL
);
134 g_object_get(font_style
, "family", &family_dup
, NULL
);
135 g_assert(family_dup
== NULL
);
137 g_object_unref(font_style
);
141 _adg_test_hint_metrics(void)
143 AdgFontStyle
*font_style
;
144 cairo_hint_metrics_t valid_hint_metrics_1
, valid_hint_metrics_2
;
145 cairo_hint_metrics_t hint_metrics
;
147 font_style
= adg_font_style_new();
148 valid_hint_metrics_1
= CAIRO_HINT_METRICS_DEFAULT
;
149 valid_hint_metrics_2
= CAIRO_HINT_METRICS_ON
;
151 /* Using the public APIs */
152 adg_font_style_set_hint_metrics(font_style
, valid_hint_metrics_1
);
153 hint_metrics
= adg_font_style_get_hint_metrics(font_style
);
154 g_assert_cmpint(hint_metrics
, ==, valid_hint_metrics_1
);
156 adg_font_style_set_hint_metrics(font_style
, valid_hint_metrics_2
);
157 hint_metrics
= adg_font_style_get_hint_metrics(font_style
);
158 g_assert_cmpint(hint_metrics
, ==, valid_hint_metrics_2
);
160 /* Using GObject property methods */
161 g_object_set(font_style
, "hint-metrics", valid_hint_metrics_1
, NULL
);
162 g_object_get(font_style
, "hint-metrics", &hint_metrics
, NULL
);
163 g_assert_cmpint(hint_metrics
, ==, valid_hint_metrics_1
);
165 g_object_set(font_style
, "hint-metrics", valid_hint_metrics_2
, NULL
);
166 g_object_get(font_style
, "hint-metrics", &hint_metrics
, NULL
);
167 g_assert_cmpint(hint_metrics
, ==, valid_hint_metrics_2
);
169 g_object_unref(font_style
);
173 _adg_test_hint_style(void)
175 AdgFontStyle
*font_style
;
176 cairo_hint_style_t valid_hint_style_1
, valid_hint_style_2
;
177 cairo_hint_style_t hint_style
;
179 font_style
= adg_font_style_new();
180 valid_hint_style_1
= CAIRO_HINT_STYLE_MEDIUM
;
181 valid_hint_style_2
= CAIRO_HINT_STYLE_SLIGHT
;
183 /* Using the public APIs */
184 adg_font_style_set_hint_style(font_style
, valid_hint_style_1
);
185 hint_style
= adg_font_style_get_hint_style(font_style
);
186 g_assert_cmpint(hint_style
, ==, valid_hint_style_1
);
188 adg_font_style_set_hint_style(font_style
, valid_hint_style_2
);
189 hint_style
= adg_font_style_get_hint_style(font_style
);
190 g_assert_cmpint(hint_style
, ==, valid_hint_style_2
);
192 /* Using GObject property methods */
193 g_object_set(font_style
, "hint-style", valid_hint_style_1
, NULL
);
194 g_object_get(font_style
, "hint-style", &hint_style
, NULL
);
195 g_assert_cmpint(hint_style
, ==, valid_hint_style_1
);
197 g_object_set(font_style
, "hint-style", valid_hint_style_2
, NULL
);
198 g_object_get(font_style
, "hint-style", &hint_style
, NULL
);
199 g_assert_cmpint(hint_style
, ==, valid_hint_style_2
);
201 g_object_unref(font_style
);
207 AdgFontStyle
*font_style
;
208 gdouble valid_size_1
, valid_size_2
, invalid_size
;
211 font_style
= adg_font_style_new();
216 /* Using the public APIs */
217 adg_font_style_set_size(font_style
, valid_size_1
);
218 size
= adg_font_style_get_size(font_style
);
219 g_assert_cmpfloat(size
, ==, valid_size_1
);
221 adg_font_style_set_size(font_style
, invalid_size
);
222 size
= adg_font_style_get_size(font_style
);
223 g_assert_cmpfloat(size
, ==, valid_size_1
);
225 adg_font_style_set_size(font_style
, valid_size_2
);
226 size
= adg_font_style_get_size(font_style
);
227 g_assert_cmpfloat(size
, ==, valid_size_2
);
229 /* Using GObject property methods */
230 g_object_set(font_style
, "size", valid_size_1
, NULL
);
231 g_object_get(font_style
, "size", &size
, NULL
);
232 g_assert_cmpfloat(size
, ==, valid_size_1
);
234 g_object_set(font_style
, "size", invalid_size
, NULL
);
235 g_object_get(font_style
, "size", &size
, NULL
);
236 g_assert_cmpfloat(size
, ==, valid_size_1
);
238 g_object_set(font_style
, "size", valid_size_2
, NULL
);
239 g_object_get(font_style
, "size", &size
, NULL
);
240 g_assert_cmpfloat(size
, ==, valid_size_2
);
242 g_object_unref(font_style
);
246 _adg_test_slant(void)
248 AdgFontStyle
*font_style
;
249 cairo_font_slant_t valid_slant_1
, valid_slant_2
;
250 cairo_font_slant_t slant
;
252 font_style
= adg_font_style_new();
253 valid_slant_1
= CAIRO_FONT_SLANT_NORMAL
;
254 valid_slant_2
= CAIRO_FONT_SLANT_OBLIQUE
;
256 /* Using the public APIs */
257 adg_font_style_set_slant(font_style
, valid_slant_1
);
258 slant
= adg_font_style_get_slant(font_style
);
259 g_assert_cmpint(slant
, ==, valid_slant_1
);
261 adg_font_style_set_slant(font_style
, valid_slant_2
);
262 slant
= adg_font_style_get_slant(font_style
);
263 g_assert_cmpint(slant
, ==, valid_slant_2
);
265 /* Using GObject property methods */
266 g_object_set(font_style
, "slant", valid_slant_1
, NULL
);
267 g_object_get(font_style
, "slant", &slant
, NULL
);
268 g_assert_cmpint(slant
, ==, valid_slant_1
);
270 g_object_set(font_style
, "slant", valid_slant_2
, NULL
);
271 g_object_get(font_style
, "slant", &slant
, NULL
);
272 g_assert_cmpint(slant
, ==, valid_slant_2
);
274 g_object_unref(font_style
);
278 _adg_test_subpixel_order(void)
280 AdgFontStyle
*font_style
;
281 cairo_subpixel_order_t valid_subpixel_order_1
, valid_subpixel_order_2
;
282 cairo_subpixel_order_t subpixel_order
;
284 font_style
= adg_font_style_new();
285 valid_subpixel_order_1
= CAIRO_SUBPIXEL_ORDER_RGB
;
286 valid_subpixel_order_2
= CAIRO_SUBPIXEL_ORDER_BGR
;
288 /* Using the public APIs */
289 adg_font_style_set_subpixel_order(font_style
, valid_subpixel_order_1
);
290 subpixel_order
= adg_font_style_get_subpixel_order(font_style
);
291 g_assert_cmpint(subpixel_order
, ==, valid_subpixel_order_1
);
293 adg_font_style_set_subpixel_order(font_style
, valid_subpixel_order_2
);
294 subpixel_order
= adg_font_style_get_subpixel_order(font_style
);
295 g_assert_cmpint(subpixel_order
, ==, valid_subpixel_order_2
);
297 /* Using GObject property methods */
298 g_object_set(font_style
, "subpixel-order", valid_subpixel_order_1
, NULL
);
299 g_object_get(font_style
, "subpixel-order", &subpixel_order
, NULL
);
300 g_assert_cmpint(subpixel_order
, ==, valid_subpixel_order_1
);
302 g_object_set(font_style
, "subpixel-order", valid_subpixel_order_2
, NULL
);
303 g_object_get(font_style
, "subpixel-order", &subpixel_order
, NULL
);
304 g_assert_cmpint(subpixel_order
, ==, valid_subpixel_order_2
);
306 g_object_unref(font_style
);
310 _adg_test_weight(void)
312 AdgFontStyle
*font_style
;
313 cairo_font_weight_t valid_weight_1
, valid_weight_2
;
314 cairo_font_weight_t weight
;
316 font_style
= adg_font_style_new();
317 valid_weight_1
= CAIRO_FONT_WEIGHT_NORMAL
;
318 valid_weight_2
= CAIRO_FONT_WEIGHT_BOLD
;
320 /* Using the public APIs */
321 adg_font_style_set_weight(font_style
, valid_weight_1
);
322 weight
= adg_font_style_get_weight(font_style
);
323 g_assert_cmpint(weight
, ==, valid_weight_1
);
325 adg_font_style_set_weight(font_style
, valid_weight_2
);
326 weight
= adg_font_style_get_weight(font_style
);
327 g_assert_cmpint(weight
, ==, valid_weight_2
);
329 /* Using GObject property methods */
330 g_object_set(font_style
, "weight", valid_weight_1
, NULL
);
331 g_object_get(font_style
, "weight", &weight
, NULL
);
332 g_assert_cmpint(weight
, ==, valid_weight_1
);
334 g_object_set(font_style
, "weight", valid_weight_2
, NULL
);
335 g_object_get(font_style
, "weight", &weight
, NULL
);
336 g_assert_cmpint(weight
, ==, valid_weight_2
);
338 g_object_unref(font_style
);
343 main(int argc
, char *argv
[])
345 adg_test_init(&argc
, &argv
);
347 adg_test_add_func("/adg/font-style/antialias", _adg_test_antialias
);
348 adg_test_add_func("/adg/font-style/color-dress", _adg_test_color_dress
);
349 adg_test_add_func("/adg/font-style/family", _adg_test_family
);
350 adg_test_add_func("/adg/font-style/hint-metrics", _adg_test_hint_metrics
);
351 adg_test_add_func("/adg/font-style/hint-style", _adg_test_hint_style
);
352 adg_test_add_func("/adg/font-style/size", _adg_test_size
);
353 adg_test_add_func("/adg/font-style/slant", _adg_test_slant
);
354 adg_test_add_func("/adg/font-style/subpixel-order", _adg_test_subpixel_order
);
355 adg_test_add_func("/adg/font-style/weight", _adg_test_weight
);