build: depends on cairo-gobject if introspection is enabled
[adg.git] / src / adg / tests / test-table-style.c
blobb676f4b432f3daa3b3105eac930afaa865e35c9e
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011,2012,2013 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"
24 static void
25 _adg_cell_padding(void)
27 AdgTableStyle *table_style;
28 CpmlPair null_padding, identity_padding;
29 const CpmlPair *padding;
30 CpmlPair *padding_dup;
32 table_style = adg_table_style_new();
33 null_padding.x = 0;
34 null_padding.y = 0;
35 identity_padding.x = 1;
36 identity_padding.y = 1;
38 /* Using the public APIs */
39 adg_table_style_set_cell_padding(table_style, &identity_padding);
40 padding = adg_table_style_get_cell_padding(table_style);
41 g_assert(cpml_pair_equal(padding, &identity_padding));
43 adg_table_style_set_cell_padding(table_style, &null_padding);
44 padding = adg_table_style_get_cell_padding(table_style);
45 g_assert(cpml_pair_equal(padding, &null_padding));
47 adg_table_style_set_cell_padding(table_style, NULL);
48 padding = adg_table_style_get_cell_padding(table_style);
49 g_assert(cpml_pair_equal(padding, &null_padding));
51 /* Using GObject property methods */
52 g_object_set(table_style, "cell-padding", &identity_padding, NULL);
53 g_object_get(table_style, "cell-padding", &padding_dup, NULL);
54 g_assert(cpml_pair_equal(padding_dup, &identity_padding));
55 g_free(padding_dup);
57 g_object_set(table_style, "cell-padding", NULL, NULL);
58 g_object_get(table_style, "cell-padding", &padding_dup, NULL);
59 g_assert(cpml_pair_equal(padding_dup, &identity_padding));
60 g_free(padding_dup);
62 g_object_set(table_style, "cell-padding", &null_padding, NULL);
63 g_object_get(table_style, "cell-padding", &padding_dup, NULL);
64 g_assert(cpml_pair_equal(padding_dup, &null_padding));
65 g_free(padding_dup);
67 g_object_unref(table_style);
70 static void
71 _adg_cell_spacing(void)
73 AdgTableStyle *table_style;
74 CpmlPair null_spacing, identity_spacing;
75 const CpmlPair *spacing;
76 CpmlPair *spacing_dup;
78 table_style = adg_table_style_new();
79 null_spacing.x = 0;
80 null_spacing.y = 0;
81 identity_spacing.x = 1;
82 identity_spacing.y = 1;
84 /* Using the public APIs */
85 adg_table_style_set_cell_spacing(table_style, &identity_spacing);
86 spacing = adg_table_style_get_cell_spacing(table_style);
87 g_assert(cpml_pair_equal(spacing, &identity_spacing));
89 adg_table_style_set_cell_spacing(table_style, &null_spacing);
90 spacing = adg_table_style_get_cell_spacing(table_style);
91 g_assert(cpml_pair_equal(spacing, &null_spacing));
93 adg_table_style_set_cell_spacing(table_style, NULL);
94 spacing = adg_table_style_get_cell_spacing(table_style);
95 g_assert(cpml_pair_equal(spacing, &null_spacing));
97 /* Using GObject property methods */
98 g_object_set(table_style, "cell-spacing", &identity_spacing, NULL);
99 g_object_get(table_style, "cell-spacing", &spacing_dup, NULL);
100 g_assert(cpml_pair_equal(spacing_dup, &identity_spacing));
101 g_free(spacing_dup);
103 g_object_set(table_style, "cell-spacing", NULL, NULL);
104 g_object_get(table_style, "cell-spacing", &spacing_dup, NULL);
105 g_assert(cpml_pair_equal(spacing_dup, &identity_spacing));
106 g_free(spacing_dup);
108 g_object_set(table_style, "cell-spacing", &null_spacing, NULL);
109 g_object_get(table_style, "cell-spacing", &spacing_dup, NULL);
110 g_assert(cpml_pair_equal(spacing_dup, &null_spacing));
111 g_free(spacing_dup);
113 g_object_unref(table_style);
116 static void
117 _adg_color_dress(void)
119 AdgTableStyle *table_style;
120 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
121 AdgDress color_dress;
123 table_style = adg_table_style_new();
124 valid_dress_1 = ADG_DRESS_COLOR;
125 valid_dress_2 = ADG_DRESS_COLOR_STROKE;
126 incompatible_dress = ADG_DRESS_FILL;
128 /* Using the public APIs */
129 adg_table_style_set_color_dress(table_style, valid_dress_1);
130 color_dress = adg_table_style_get_color_dress(table_style);
131 g_assert_cmpint(color_dress, ==, valid_dress_1);
133 adg_table_style_set_color_dress(table_style, incompatible_dress);
134 color_dress = adg_table_style_get_color_dress(table_style);
135 g_assert_cmpint(color_dress, ==, valid_dress_1);
137 adg_table_style_set_color_dress(table_style, valid_dress_2);
138 color_dress = adg_table_style_get_color_dress(table_style);
139 g_assert_cmpint(color_dress, ==, valid_dress_2);
141 /* Using GObject property methods */
142 g_object_set(table_style, "color-dress", valid_dress_1, NULL);
143 g_object_get(table_style, "color-dress", &color_dress, NULL);
144 g_assert_cmpint(color_dress, ==, valid_dress_1);
146 g_object_set(table_style, "color-dress", incompatible_dress, NULL);
147 g_object_get(table_style, "color-dress", &color_dress, NULL);
148 g_assert_cmpint(color_dress, ==, valid_dress_1);
150 g_object_set(table_style, "color-dress", valid_dress_2, NULL);
151 g_object_get(table_style, "color-dress", &color_dress, NULL);
152 g_assert_cmpint(color_dress, ==, valid_dress_2);
154 g_object_unref(table_style);
157 static void
158 _adg_frame_dress(void)
160 AdgTableStyle *table_style;
161 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
162 AdgDress frame_dress;
164 table_style = adg_table_style_new();
165 valid_dress_1 = ADG_DRESS_LINE_DIMENSION;
166 valid_dress_2 = ADG_DRESS_LINE_STROKE;
167 incompatible_dress = ADG_DRESS_FONT;
169 /* Using the public APIs */
170 adg_table_style_set_frame_dress(table_style, valid_dress_1);
171 frame_dress = adg_table_style_get_frame_dress(table_style);
172 g_assert_cmpint(frame_dress, ==, valid_dress_1);
174 adg_table_style_set_frame_dress(table_style, incompatible_dress);
175 frame_dress = adg_table_style_get_frame_dress(table_style);
176 g_assert_cmpint(frame_dress, ==, valid_dress_1);
178 adg_table_style_set_frame_dress(table_style, valid_dress_2);
179 frame_dress = adg_table_style_get_frame_dress(table_style);
180 g_assert_cmpint(frame_dress, ==, valid_dress_2);
182 /* Using GObject property methods */
183 g_object_set(table_style, "frame-dress", valid_dress_1, NULL);
184 g_object_get(table_style, "frame-dress", &frame_dress, NULL);
185 g_assert_cmpint(frame_dress, ==, valid_dress_1);
187 g_object_set(table_style, "frame-dress", incompatible_dress, NULL);
188 g_object_get(table_style, "frame-dress", &frame_dress, NULL);
189 g_assert_cmpint(frame_dress, ==, valid_dress_1);
191 g_object_set(table_style, "frame-dress", valid_dress_2, NULL);
192 g_object_get(table_style, "frame-dress", &frame_dress, NULL);
193 g_assert_cmpint(frame_dress, ==, valid_dress_2);
195 g_object_unref(table_style);
198 static void
199 _adg_grid_dress(void)
201 AdgTableStyle *table_style;
202 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
203 AdgDress grid_dress;
205 table_style = adg_table_style_new();
206 valid_dress_1 = ADG_DRESS_LINE;
207 valid_dress_2 = ADG_DRESS_LINE_DIMENSION;
208 incompatible_dress = ADG_DRESS_FONT;
210 /* Using the public APIs */
211 adg_table_style_set_grid_dress(table_style, valid_dress_1);
212 grid_dress = adg_table_style_get_grid_dress(table_style);
213 g_assert_cmpint(grid_dress, ==, valid_dress_1);
215 adg_table_style_set_grid_dress(table_style, incompatible_dress);
216 grid_dress = adg_table_style_get_grid_dress(table_style);
217 g_assert_cmpint(grid_dress, ==, valid_dress_1);
219 adg_table_style_set_grid_dress(table_style, valid_dress_2);
220 grid_dress = adg_table_style_get_grid_dress(table_style);
221 g_assert_cmpint(grid_dress, ==, valid_dress_2);
223 /* Using GObject property methods */
224 g_object_set(table_style, "grid-dress", valid_dress_1, NULL);
225 g_object_get(table_style, "grid-dress", &grid_dress, NULL);
226 g_assert_cmpint(grid_dress, ==, valid_dress_1);
228 g_object_set(table_style, "grid-dress", incompatible_dress, NULL);
229 g_object_get(table_style, "grid-dress", &grid_dress, NULL);
230 g_assert_cmpint(grid_dress, ==, valid_dress_1);
232 g_object_set(table_style, "grid-dress", valid_dress_2, NULL);
233 g_object_get(table_style, "grid-dress", &grid_dress, NULL);
234 g_assert_cmpint(grid_dress, ==, valid_dress_2);
236 g_object_unref(table_style);
239 static void
240 _adg_row_height(void)
242 AdgTableStyle *table_style;
243 gdouble valid_row_height_1, valid_row_height_2, invalid_row_height;
244 gdouble row_height;
246 table_style = adg_table_style_new();
247 valid_row_height_1 = 0;
248 valid_row_height_2 = 999;
249 invalid_row_height = -1;
251 /* Using the public APIs */
252 adg_table_style_set_row_height(table_style, valid_row_height_1);
253 row_height = adg_table_style_get_row_height(table_style);
254 g_assert_cmpfloat(row_height, ==, valid_row_height_1);
256 adg_table_style_set_row_height(table_style, invalid_row_height);
257 row_height = adg_table_style_get_row_height(table_style);
258 g_assert_cmpfloat(row_height, ==, valid_row_height_1);
260 adg_table_style_set_row_height(table_style, valid_row_height_2);
261 row_height = adg_table_style_get_row_height(table_style);
262 g_assert_cmpfloat(row_height, ==, valid_row_height_2);
264 /* Using GObject property methods */
265 g_object_set(table_style, "row-height", valid_row_height_1, NULL);
266 g_object_get(table_style, "row-height", &row_height, NULL);
267 g_assert_cmpfloat(row_height, ==, valid_row_height_1);
269 g_object_set(table_style, "row-height", invalid_row_height, NULL);
270 g_object_get(table_style, "row-height", &row_height, NULL);
271 g_assert_cmpfloat(row_height, ==, valid_row_height_1);
273 g_object_set(table_style, "row-height", valid_row_height_2, NULL);
274 g_object_get(table_style, "row-height", &row_height, NULL);
275 g_assert_cmpfloat(row_height, ==, valid_row_height_2);
277 g_object_unref(table_style);
280 static void
281 _adg_title_dress(void)
283 AdgTableStyle *table_style;
284 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
285 AdgDress title_dress;
287 table_style = adg_table_style_new();
288 valid_dress_1 = ADG_DRESS_FONT_QUOTE_TEXT;
289 valid_dress_2 = ADG_DRESS_FONT_TEXT;
290 incompatible_dress = ADG_DRESS_LINE_FILL;
292 /* Using the public APIs */
293 adg_table_style_set_title_dress(table_style, valid_dress_1);
294 title_dress = adg_table_style_get_title_dress(table_style);
295 g_assert_cmpint(title_dress, ==, valid_dress_1);
297 adg_table_style_set_title_dress(table_style, incompatible_dress);
298 title_dress = adg_table_style_get_title_dress(table_style);
299 g_assert_cmpint(title_dress, ==, valid_dress_1);
301 adg_table_style_set_title_dress(table_style, valid_dress_2);
302 title_dress = adg_table_style_get_title_dress(table_style);
303 g_assert_cmpint(title_dress, ==, valid_dress_2);
305 /* Using GObject property methods */
306 g_object_set(table_style, "title-dress", valid_dress_1, NULL);
307 g_object_get(table_style, "title-dress", &title_dress, NULL);
308 g_assert_cmpint(title_dress, ==, valid_dress_1);
310 g_object_set(table_style, "title-dress", incompatible_dress, NULL);
311 g_object_get(table_style, "title-dress", &title_dress, NULL);
312 g_assert_cmpint(title_dress, ==, valid_dress_1);
314 g_object_set(table_style, "title-dress", valid_dress_2, NULL);
315 g_object_get(table_style, "title-dress", &title_dress, NULL);
316 g_assert_cmpint(title_dress, ==, valid_dress_2);
318 g_object_unref(table_style);
321 static void
322 _adg_value_dress(void)
324 AdgTableStyle *table_style;
325 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
326 AdgDress value_dress;
328 table_style = adg_table_style_new();
329 valid_dress_1 = ADG_DRESS_FONT_TEXT;
330 valid_dress_2 = ADG_DRESS_FONT_QUOTE_ANNOTATION;
331 incompatible_dress = ADG_DRESS_LINE;
333 /* Using the public APIs */
334 adg_table_style_set_value_dress(table_style, valid_dress_1);
335 value_dress = adg_table_style_get_value_dress(table_style);
336 g_assert_cmpint(value_dress, ==, valid_dress_1);
338 adg_table_style_set_value_dress(table_style, incompatible_dress);
339 value_dress = adg_table_style_get_value_dress(table_style);
340 g_assert_cmpint(value_dress, ==, valid_dress_1);
342 adg_table_style_set_value_dress(table_style, valid_dress_2);
343 value_dress = adg_table_style_get_value_dress(table_style);
344 g_assert_cmpint(value_dress, ==, valid_dress_2);
346 /* Using GObject property methods */
347 g_object_set(table_style, "value-dress", valid_dress_1, NULL);
348 g_object_get(table_style, "value-dress", &value_dress, NULL);
349 g_assert_cmpint(value_dress, ==, valid_dress_1);
351 g_object_set(table_style, "value-dress", incompatible_dress, NULL);
352 g_object_get(table_style, "value-dress", &value_dress, NULL);
353 g_assert_cmpint(value_dress, ==, valid_dress_1);
355 g_object_set(table_style, "value-dress", valid_dress_2, NULL);
356 g_object_get(table_style, "value-dress", &value_dress, NULL);
357 g_assert_cmpint(value_dress, ==, valid_dress_2);
359 g_object_unref(table_style);
364 main(int argc, char *argv[])
366 adg_test_init(&argc, &argv);
368 adg_test_add_func("/adg/table-style/cell-padding", _adg_cell_padding);
369 adg_test_add_func("/adg/table-style/cell-spacing", _adg_cell_spacing);
370 adg_test_add_func("/adg/table-style/color-dress", _adg_color_dress);
371 adg_test_add_func("/adg/table-style/frame-dress", _adg_frame_dress);
372 adg_test_add_func("/adg/table-style/grid-dress", _adg_grid_dress);
373 adg_test_add_func("/adg/table-style/row-height", _adg_row_height);
374 adg_test_add_func("/adg/table-style/title-dress", _adg_title_dress);
375 adg_test_add_func("/adg/table-style/value-dress", _adg_value_dress);
377 return g_test_run();