doc: update copyright line for 2021
[adg.git] / src / adg / tests / test-font-style.c
blob335eb20b1f8e1d2162743549efe9a7d73a3216b7
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.
21 #include <adg-test.h>
22 #include <adg.h>
25 static void
26 _adg_property_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);
56 static void
57 _adg_property_color_dress(void)
59 AdgFontStyle *font_style;
60 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
61 AdgDress color_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);
97 static void
98 _adg_property_family(void)
100 AdgFontStyle *font_style;
101 const gchar *valid_text_1, *valid_text_2;
102 const gchar *family;
103 gchar *family_dup;
105 font_style = adg_font_style_new();
106 valid_text_1 = "Sans serif 10, bold";
107 valid_text_2 = "";
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_null(family);
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);
126 g_free(family_dup);
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);
131 g_free(family_dup);
133 g_object_set(font_style, "family", NULL, NULL);
134 g_object_get(font_style, "family", &family_dup, NULL);
135 g_assert_null(family_dup);
137 g_object_unref(font_style);
140 static void
141 _adg_property_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);
172 static void
173 _adg_property_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);
204 static void
205 _adg_property_size(void)
207 AdgFontStyle *font_style;
208 gdouble valid_size_1, valid_size_2, invalid_size;
209 gdouble size;
211 font_style = adg_font_style_new();
212 valid_size_1 = 0;
213 valid_size_2 = 999;
214 invalid_size = -1;
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 adg_assert_isapprox(size, valid_size_1);
221 adg_font_style_set_size(font_style, invalid_size);
222 size = adg_font_style_get_size(font_style);
223 adg_assert_isapprox(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 adg_assert_isapprox(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 adg_assert_isapprox(size, valid_size_1);
234 g_object_set(font_style, "size", invalid_size, NULL);
235 g_object_get(font_style, "size", &size, NULL);
236 adg_assert_isapprox(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 adg_assert_isapprox(size, valid_size_2);
242 g_object_unref(font_style);
245 static void
246 _adg_property_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);
277 static void
278 _adg_property_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);
309 static void
310 _adg_property_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_object_checks("/adg/font-style/type/object", ADG_TYPE_FONT_STYLE);
349 g_test_add_func("/adg/font-style/property/antialias", _adg_property_antialias);
350 g_test_add_func("/adg/font-style/property/color-dress", _adg_property_color_dress);
351 g_test_add_func("/adg/font-style/property/family", _adg_property_family);
352 g_test_add_func("/adg/font-style/property/hint-metrics", _adg_property_hint_metrics);
353 g_test_add_func("/adg/font-style/property/hint-style", _adg_property_hint_style);
354 g_test_add_func("/adg/font-style/property/size", _adg_property_size);
355 g_test_add_func("/adg/font-style/property/slant", _adg_property_slant);
356 g_test_add_func("/adg/font-style/property/subpixel-order", _adg_property_subpixel_order);
357 g_test_add_func("/adg/font-style/property/weight", _adg_property_weight);
359 return g_test_run();