tests: move common test code in libadgtest
[adg.git] / src / adg / tests / test-table-style.c
blob95fdbba672882b701fb895c286cf4c956b5f19fb
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.
21 #include <adg-test.h>
22 #include <adg.h>
25 static void
26 _adg_cell_padding(void)
28 AdgTableStyle *table_style;
29 CpmlPair null_padding, identity_padding;
30 const CpmlPair *padding;
31 CpmlPair *padding_dup;
33 table_style = adg_table_style_new();
34 null_padding.x = 0;
35 null_padding.y = 0;
36 identity_padding.x = 1;
37 identity_padding.y = 1;
39 /* Using the public APIs */
40 adg_table_style_set_cell_padding(table_style, &identity_padding);
41 padding = adg_table_style_get_cell_padding(table_style);
42 g_assert(cpml_pair_equal(padding, &identity_padding));
44 adg_table_style_set_cell_padding(table_style, &null_padding);
45 padding = adg_table_style_get_cell_padding(table_style);
46 g_assert(cpml_pair_equal(padding, &null_padding));
48 adg_table_style_set_cell_padding(table_style, NULL);
49 padding = adg_table_style_get_cell_padding(table_style);
50 g_assert(cpml_pair_equal(padding, &null_padding));
52 /* Using GObject property methods */
53 g_object_set(table_style, "cell-padding", &identity_padding, NULL);
54 g_object_get(table_style, "cell-padding", &padding_dup, NULL);
55 g_assert(cpml_pair_equal(padding_dup, &identity_padding));
56 g_free(padding_dup);
58 g_object_set(table_style, "cell-padding", NULL, NULL);
59 g_object_get(table_style, "cell-padding", &padding_dup, NULL);
60 g_assert(cpml_pair_equal(padding_dup, &identity_padding));
61 g_free(padding_dup);
63 g_object_set(table_style, "cell-padding", &null_padding, NULL);
64 g_object_get(table_style, "cell-padding", &padding_dup, NULL);
65 g_assert(cpml_pair_equal(padding_dup, &null_padding));
66 g_free(padding_dup);
68 g_object_unref(table_style);
71 static void
72 _adg_cell_spacing(void)
74 AdgTableStyle *table_style;
75 CpmlPair null_spacing, identity_spacing;
76 const CpmlPair *spacing;
77 CpmlPair *spacing_dup;
79 table_style = adg_table_style_new();
80 null_spacing.x = 0;
81 null_spacing.y = 0;
82 identity_spacing.x = 1;
83 identity_spacing.y = 1;
85 /* Using the public APIs */
86 adg_table_style_set_cell_spacing(table_style, &identity_spacing);
87 spacing = adg_table_style_get_cell_spacing(table_style);
88 g_assert(cpml_pair_equal(spacing, &identity_spacing));
90 adg_table_style_set_cell_spacing(table_style, &null_spacing);
91 spacing = adg_table_style_get_cell_spacing(table_style);
92 g_assert(cpml_pair_equal(spacing, &null_spacing));
94 adg_table_style_set_cell_spacing(table_style, NULL);
95 spacing = adg_table_style_get_cell_spacing(table_style);
96 g_assert(cpml_pair_equal(spacing, &null_spacing));
98 /* Using GObject property methods */
99 g_object_set(table_style, "cell-spacing", &identity_spacing, NULL);
100 g_object_get(table_style, "cell-spacing", &spacing_dup, NULL);
101 g_assert(cpml_pair_equal(spacing_dup, &identity_spacing));
102 g_free(spacing_dup);
104 g_object_set(table_style, "cell-spacing", NULL, NULL);
105 g_object_get(table_style, "cell-spacing", &spacing_dup, NULL);
106 g_assert(cpml_pair_equal(spacing_dup, &identity_spacing));
107 g_free(spacing_dup);
109 g_object_set(table_style, "cell-spacing", &null_spacing, NULL);
110 g_object_get(table_style, "cell-spacing", &spacing_dup, NULL);
111 g_assert(cpml_pair_equal(spacing_dup, &null_spacing));
112 g_free(spacing_dup);
114 g_object_unref(table_style);
117 static void
118 _adg_color_dress(void)
120 AdgTableStyle *table_style;
121 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
122 AdgDress color_dress;
124 table_style = adg_table_style_new();
125 valid_dress_1 = ADG_DRESS_COLOR;
126 valid_dress_2 = ADG_DRESS_COLOR_STROKE;
127 incompatible_dress = ADG_DRESS_FILL;
129 /* Using the public APIs */
130 adg_table_style_set_color_dress(table_style, valid_dress_1);
131 color_dress = adg_table_style_get_color_dress(table_style);
132 g_assert_cmpint(color_dress, ==, valid_dress_1);
134 adg_table_style_set_color_dress(table_style, incompatible_dress);
135 color_dress = adg_table_style_get_color_dress(table_style);
136 g_assert_cmpint(color_dress, ==, valid_dress_1);
138 adg_table_style_set_color_dress(table_style, valid_dress_2);
139 color_dress = adg_table_style_get_color_dress(table_style);
140 g_assert_cmpint(color_dress, ==, valid_dress_2);
142 /* Using GObject property methods */
143 g_object_set(table_style, "color-dress", valid_dress_1, NULL);
144 g_object_get(table_style, "color-dress", &color_dress, NULL);
145 g_assert_cmpint(color_dress, ==, valid_dress_1);
147 g_object_set(table_style, "color-dress", incompatible_dress, NULL);
148 g_object_get(table_style, "color-dress", &color_dress, NULL);
149 g_assert_cmpint(color_dress, ==, valid_dress_1);
151 g_object_set(table_style, "color-dress", valid_dress_2, NULL);
152 g_object_get(table_style, "color-dress", &color_dress, NULL);
153 g_assert_cmpint(color_dress, ==, valid_dress_2);
155 g_object_unref(table_style);
158 static void
159 _adg_frame_dress(void)
161 AdgTableStyle *table_style;
162 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
163 AdgDress frame_dress;
165 table_style = adg_table_style_new();
166 valid_dress_1 = ADG_DRESS_LINE_DIMENSION;
167 valid_dress_2 = ADG_DRESS_LINE_STROKE;
168 incompatible_dress = ADG_DRESS_FONT;
170 /* Using the public APIs */
171 adg_table_style_set_frame_dress(table_style, valid_dress_1);
172 frame_dress = adg_table_style_get_frame_dress(table_style);
173 g_assert_cmpint(frame_dress, ==, valid_dress_1);
175 adg_table_style_set_frame_dress(table_style, incompatible_dress);
176 frame_dress = adg_table_style_get_frame_dress(table_style);
177 g_assert_cmpint(frame_dress, ==, valid_dress_1);
179 adg_table_style_set_frame_dress(table_style, valid_dress_2);
180 frame_dress = adg_table_style_get_frame_dress(table_style);
181 g_assert_cmpint(frame_dress, ==, valid_dress_2);
183 /* Using GObject property methods */
184 g_object_set(table_style, "frame-dress", valid_dress_1, NULL);
185 g_object_get(table_style, "frame-dress", &frame_dress, NULL);
186 g_assert_cmpint(frame_dress, ==, valid_dress_1);
188 g_object_set(table_style, "frame-dress", incompatible_dress, NULL);
189 g_object_get(table_style, "frame-dress", &frame_dress, NULL);
190 g_assert_cmpint(frame_dress, ==, valid_dress_1);
192 g_object_set(table_style, "frame-dress", valid_dress_2, NULL);
193 g_object_get(table_style, "frame-dress", &frame_dress, NULL);
194 g_assert_cmpint(frame_dress, ==, valid_dress_2);
196 g_object_unref(table_style);
199 static void
200 _adg_grid_dress(void)
202 AdgTableStyle *table_style;
203 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
204 AdgDress grid_dress;
206 table_style = adg_table_style_new();
207 valid_dress_1 = ADG_DRESS_LINE;
208 valid_dress_2 = ADG_DRESS_LINE_DIMENSION;
209 incompatible_dress = ADG_DRESS_FONT;
211 /* Using the public APIs */
212 adg_table_style_set_grid_dress(table_style, valid_dress_1);
213 grid_dress = adg_table_style_get_grid_dress(table_style);
214 g_assert_cmpint(grid_dress, ==, valid_dress_1);
216 adg_table_style_set_grid_dress(table_style, incompatible_dress);
217 grid_dress = adg_table_style_get_grid_dress(table_style);
218 g_assert_cmpint(grid_dress, ==, valid_dress_1);
220 adg_table_style_set_grid_dress(table_style, valid_dress_2);
221 grid_dress = adg_table_style_get_grid_dress(table_style);
222 g_assert_cmpint(grid_dress, ==, valid_dress_2);
224 /* Using GObject property methods */
225 g_object_set(table_style, "grid-dress", valid_dress_1, NULL);
226 g_object_get(table_style, "grid-dress", &grid_dress, NULL);
227 g_assert_cmpint(grid_dress, ==, valid_dress_1);
229 g_object_set(table_style, "grid-dress", incompatible_dress, NULL);
230 g_object_get(table_style, "grid-dress", &grid_dress, NULL);
231 g_assert_cmpint(grid_dress, ==, valid_dress_1);
233 g_object_set(table_style, "grid-dress", valid_dress_2, NULL);
234 g_object_get(table_style, "grid-dress", &grid_dress, NULL);
235 g_assert_cmpint(grid_dress, ==, valid_dress_2);
237 g_object_unref(table_style);
240 static void
241 _adg_row_height(void)
243 AdgTableStyle *table_style;
244 gdouble valid_row_height_1, valid_row_height_2, invalid_row_height;
245 gdouble row_height;
247 table_style = adg_table_style_new();
248 valid_row_height_1 = 0;
249 valid_row_height_2 = 999;
250 invalid_row_height = -1;
252 /* Using the public APIs */
253 adg_table_style_set_row_height(table_style, valid_row_height_1);
254 row_height = adg_table_style_get_row_height(table_style);
255 g_assert_cmpfloat(row_height, ==, valid_row_height_1);
257 adg_table_style_set_row_height(table_style, invalid_row_height);
258 row_height = adg_table_style_get_row_height(table_style);
259 g_assert_cmpfloat(row_height, ==, valid_row_height_1);
261 adg_table_style_set_row_height(table_style, valid_row_height_2);
262 row_height = adg_table_style_get_row_height(table_style);
263 g_assert_cmpfloat(row_height, ==, valid_row_height_2);
265 /* Using GObject property methods */
266 g_object_set(table_style, "row-height", valid_row_height_1, NULL);
267 g_object_get(table_style, "row-height", &row_height, NULL);
268 g_assert_cmpfloat(row_height, ==, valid_row_height_1);
270 g_object_set(table_style, "row-height", invalid_row_height, NULL);
271 g_object_get(table_style, "row-height", &row_height, NULL);
272 g_assert_cmpfloat(row_height, ==, valid_row_height_1);
274 g_object_set(table_style, "row-height", valid_row_height_2, NULL);
275 g_object_get(table_style, "row-height", &row_height, NULL);
276 g_assert_cmpfloat(row_height, ==, valid_row_height_2);
278 g_object_unref(table_style);
281 static void
282 _adg_title_dress(void)
284 AdgTableStyle *table_style;
285 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
286 AdgDress title_dress;
288 table_style = adg_table_style_new();
289 valid_dress_1 = ADG_DRESS_FONT_QUOTE_TEXT;
290 valid_dress_2 = ADG_DRESS_FONT_TEXT;
291 incompatible_dress = ADG_DRESS_LINE_FILL;
293 /* Using the public APIs */
294 adg_table_style_set_title_dress(table_style, valid_dress_1);
295 title_dress = adg_table_style_get_title_dress(table_style);
296 g_assert_cmpint(title_dress, ==, valid_dress_1);
298 adg_table_style_set_title_dress(table_style, incompatible_dress);
299 title_dress = adg_table_style_get_title_dress(table_style);
300 g_assert_cmpint(title_dress, ==, valid_dress_1);
302 adg_table_style_set_title_dress(table_style, valid_dress_2);
303 title_dress = adg_table_style_get_title_dress(table_style);
304 g_assert_cmpint(title_dress, ==, valid_dress_2);
306 /* Using GObject property methods */
307 g_object_set(table_style, "title-dress", valid_dress_1, NULL);
308 g_object_get(table_style, "title-dress", &title_dress, NULL);
309 g_assert_cmpint(title_dress, ==, valid_dress_1);
311 g_object_set(table_style, "title-dress", incompatible_dress, NULL);
312 g_object_get(table_style, "title-dress", &title_dress, NULL);
313 g_assert_cmpint(title_dress, ==, valid_dress_1);
315 g_object_set(table_style, "title-dress", valid_dress_2, NULL);
316 g_object_get(table_style, "title-dress", &title_dress, NULL);
317 g_assert_cmpint(title_dress, ==, valid_dress_2);
319 g_object_unref(table_style);
322 static void
323 _adg_value_dress(void)
325 AdgTableStyle *table_style;
326 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
327 AdgDress value_dress;
329 table_style = adg_table_style_new();
330 valid_dress_1 = ADG_DRESS_FONT_TEXT;
331 valid_dress_2 = ADG_DRESS_FONT_QUOTE_ANNOTATION;
332 incompatible_dress = ADG_DRESS_LINE;
334 /* Using the public APIs */
335 adg_table_style_set_value_dress(table_style, valid_dress_1);
336 value_dress = adg_table_style_get_value_dress(table_style);
337 g_assert_cmpint(value_dress, ==, valid_dress_1);
339 adg_table_style_set_value_dress(table_style, incompatible_dress);
340 value_dress = adg_table_style_get_value_dress(table_style);
341 g_assert_cmpint(value_dress, ==, valid_dress_1);
343 adg_table_style_set_value_dress(table_style, valid_dress_2);
344 value_dress = adg_table_style_get_value_dress(table_style);
345 g_assert_cmpint(value_dress, ==, valid_dress_2);
347 /* Using GObject property methods */
348 g_object_set(table_style, "value-dress", valid_dress_1, NULL);
349 g_object_get(table_style, "value-dress", &value_dress, NULL);
350 g_assert_cmpint(value_dress, ==, valid_dress_1);
352 g_object_set(table_style, "value-dress", incompatible_dress, NULL);
353 g_object_get(table_style, "value-dress", &value_dress, NULL);
354 g_assert_cmpint(value_dress, ==, valid_dress_1);
356 g_object_set(table_style, "value-dress", valid_dress_2, NULL);
357 g_object_get(table_style, "value-dress", &value_dress, NULL);
358 g_assert_cmpint(value_dress, ==, valid_dress_2);
360 g_object_unref(table_style);
365 main(int argc, char *argv[])
367 adg_test_init(&argc, &argv);
369 adg_test_add_func("/adg/table-style/cell-padding", _adg_cell_padding);
370 adg_test_add_func("/adg/table-style/cell-spacing", _adg_cell_spacing);
371 adg_test_add_func("/adg/table-style/color-dress", _adg_color_dress);
372 adg_test_add_func("/adg/table-style/frame-dress", _adg_frame_dress);
373 adg_test_add_func("/adg/table-style/grid-dress", _adg_grid_dress);
374 adg_test_add_func("/adg/table-style/row-height", _adg_row_height);
375 adg_test_add_func("/adg/table-style/title-dress", _adg_title_dress);
376 adg_test_add_func("/adg/table-style/value-dress", _adg_value_dress);
378 return g_test_run();