doc: update copyright line for 2021
[adg.git] / src / adg / tests / test-title-block.c
blob9020a0b407d21743e4b85ad452d490a1e0d2bc0e
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_local_mix(void)
28 AdgTitleBlock *title_block;
29 AdgEntity *entity;
31 /* Ensure the title block behaves exaclty like an AdgTable */
33 title_block = adg_title_block_new();
34 entity = (AdgEntity *) title_block;
35 g_assert_cmpint(adg_entity_get_local_mix(entity), ==, ADG_MIX_DISABLED);
36 adg_entity_destroy(entity);
38 /* Check local mix method overriding */
39 title_block = g_object_new(ADG_TYPE_TITLE_BLOCK, "local-mix", ADG_MIX_ANCESTORS_NORMALIZED, NULL);
40 entity = (AdgEntity *) title_block;
41 g_assert_cmpint(adg_entity_get_local_mix(entity), ==, ADG_MIX_ANCESTORS_NORMALIZED);
42 adg_entity_destroy(entity);
44 /* Check default mix using GObject methods */
45 title_block = g_object_new(ADG_TYPE_TITLE_BLOCK, NULL);
46 entity = (AdgEntity *) title_block;
47 g_assert_cmpint(adg_entity_get_local_mix(entity), ==, ADG_MIX_DISABLED);
48 adg_entity_destroy(entity);
51 static void
52 _adg_property_author(void)
54 AdgTitleBlock *title_block;
55 const gchar *valid_text, *latin1_text;
56 const gchar *author;
57 gchar *author_dup;
59 title_block = adg_title_block_new();
60 valid_text = "This is some text...";
61 latin1_text = "This is some àèìòù Latin1 text...";
63 /* Using the public APIs */
64 adg_title_block_set_author(title_block, valid_text);
65 author = adg_title_block_get_author(title_block);
66 g_assert_cmpstr(author, ==, valid_text);
68 adg_title_block_set_author(title_block, latin1_text);
69 author = adg_title_block_get_author(title_block);
70 g_assert_cmpstr(author, ==, latin1_text);
72 adg_title_block_set_author(title_block, NULL);
73 author = adg_title_block_get_author(title_block);
74 g_assert_null(author);
76 /* Using GObject property methods */
77 g_object_set(title_block, "author", valid_text, NULL);
78 g_object_get(title_block, "author", &author_dup, NULL);
79 g_assert_cmpstr(author_dup, ==, valid_text);
80 g_free(author_dup);
82 g_object_set(title_block, "author", latin1_text, NULL);
83 g_object_get(title_block, "author", &author_dup, NULL);
84 g_assert_cmpstr(author_dup, ==, latin1_text);
85 g_free(author_dup);
87 g_object_set(title_block, "author", NULL, NULL);
88 g_object_get(title_block, "author", &author_dup, NULL);
89 g_assert_null(author_dup);
91 adg_entity_destroy(ADG_ENTITY(title_block));
94 static void
95 _adg_property_date(void)
97 AdgTitleBlock *title_block;
98 const gchar *valid_text, *latin1_text;
99 const gchar *date;
100 gchar *date_dup;
102 title_block = adg_title_block_new();
103 valid_text = "This is some text...";
104 latin1_text = "This is some àèìòù Latin1 text...";
106 /* Using the public APIs */
107 adg_title_block_set_date(title_block, valid_text);
108 date = adg_title_block_get_date(title_block);
109 g_assert_cmpstr(date, ==, valid_text);
111 adg_title_block_set_date(title_block, latin1_text);
112 date = adg_title_block_get_date(title_block);
113 g_assert_cmpstr(date, ==, latin1_text);
115 adg_title_block_set_date(title_block, NULL);
116 date = adg_title_block_get_date(title_block);
117 g_assert_nonnull(date);
119 /* Using GObject property methods */
120 g_object_set(title_block, "date", valid_text, NULL);
121 g_object_get(title_block, "date", &date_dup, NULL);
122 g_assert_cmpstr(date_dup, ==, valid_text);
123 g_free(date_dup);
125 g_object_set(title_block, "date", latin1_text, NULL);
126 g_object_get(title_block, "date", &date_dup, NULL);
127 g_assert_cmpstr(date_dup, ==, latin1_text);
128 g_free(date_dup);
130 g_object_set(title_block, "date", NULL, NULL);
131 g_object_get(title_block, "date", &date_dup, NULL);
132 g_assert_nonnull(date_dup);
133 g_free(date_dup);
135 adg_entity_destroy(ADG_ENTITY(title_block));
138 static void
139 _adg_property_drawing(void)
141 AdgTitleBlock *title_block;
142 const gchar *valid_text, *latin1_text;
143 const gchar *drawing;
144 gchar *drawing_dup;
146 title_block = adg_title_block_new();
147 valid_text = "This is some text...";
148 latin1_text = "This is some àèìòù Latin1 text...";
150 /* Using the public APIs */
151 adg_title_block_set_drawing(title_block, valid_text);
152 drawing = adg_title_block_get_drawing(title_block);
153 g_assert_cmpstr(drawing, ==, valid_text);
155 adg_title_block_set_drawing(title_block, latin1_text);
156 drawing = adg_title_block_get_drawing(title_block);
157 g_assert_cmpstr(drawing, ==, latin1_text);
159 adg_title_block_set_drawing(title_block, NULL);
160 drawing = adg_title_block_get_drawing(title_block);
161 g_assert_null(drawing);
163 /* Using GObject property methods */
164 g_object_set(title_block, "drawing", valid_text, NULL);
165 g_object_get(title_block, "drawing", &drawing_dup, NULL);
166 g_assert_cmpstr(drawing_dup, ==, valid_text);
167 g_free(drawing_dup);
169 g_object_set(title_block, "drawing", latin1_text, NULL);
170 g_object_get(title_block, "drawing", &drawing_dup, NULL);
171 g_assert_cmpstr(drawing_dup, ==, latin1_text);
172 g_free(drawing_dup);
174 g_object_set(title_block, "drawing", NULL, NULL);
175 g_object_get(title_block, "drawing", &drawing_dup, NULL);
176 g_assert_null(drawing_dup);
178 adg_entity_destroy(ADG_ENTITY(title_block));
181 static void
182 _adg_property_logo(void)
184 AdgTitleBlock *title_block;
185 AdgEntity *valid_entity, *invalid_entity, *logo;
187 title_block = adg_title_block_new();
188 valid_entity = ADG_ENTITY(adg_hatch_new(NULL));
189 invalid_entity = adg_test_invalid_pointer();
191 /* Prevent valid_entity from being destroyed
192 * the first time AdgTitleBlock:logo is set to NULL */
193 g_object_ref(valid_entity);
195 /* Using the public APIs */
196 adg_title_block_set_logo(title_block, valid_entity);
197 logo = adg_title_block_logo(title_block);
198 g_assert_true(logo == valid_entity);
200 adg_title_block_set_logo(title_block, invalid_entity);
201 logo = adg_title_block_logo(title_block);
202 g_assert_true(logo == valid_entity);
204 adg_title_block_set_logo(title_block, valid_entity);
205 logo = adg_title_block_logo(title_block);
206 g_assert_true(logo == valid_entity);
208 adg_title_block_set_logo(title_block, NULL);
209 logo = adg_title_block_logo(title_block);
210 g_assert_null(logo);
212 /* Using GObject property methods */
213 g_object_set(title_block, "logo", valid_entity, NULL);
214 g_object_get(title_block, "logo", &logo, NULL);
215 g_assert_true(logo == valid_entity);
216 adg_entity_destroy(logo);
218 g_object_set(title_block, "logo", invalid_entity, NULL);
219 g_object_get(title_block, "logo", &logo, NULL);
220 g_assert_true(logo == valid_entity);
221 adg_entity_destroy(logo);
223 g_object_set(title_block, "logo", valid_entity, NULL);
224 g_object_get(title_block, "logo", &logo, NULL);
225 g_assert_true(logo == valid_entity);
226 adg_entity_destroy(logo);
228 g_object_set(title_block, "logo", NULL, NULL);
229 g_object_get(title_block, "logo", &logo, NULL);
230 g_assert_null(logo);
232 adg_entity_destroy(ADG_ENTITY(title_block));
233 g_object_unref(valid_entity);
236 static void
237 _adg_property_projection(void)
239 AdgTitleBlock *title_block;
240 AdgEntity *valid_entity, *invalid_entity, *projection;
242 title_block = adg_title_block_new();
243 valid_entity = ADG_ENTITY(adg_hatch_new(NULL));
244 invalid_entity = adg_test_invalid_pointer();
246 /* Prevent valid_entity from being destroyed
247 * the first time AdgTitleBlock:projection is set to NULL */
248 g_object_ref(valid_entity);
250 /* Using the public APIs */
251 adg_title_block_set_projection(title_block, valid_entity);
252 projection = adg_title_block_projection(title_block);
253 g_assert_true(projection == valid_entity);
255 adg_title_block_set_projection(title_block, invalid_entity);
256 projection = adg_title_block_projection(title_block);
257 g_assert_true(projection == valid_entity);
259 adg_title_block_set_projection(title_block, NULL);
260 projection = adg_title_block_projection(title_block);
261 g_assert_null(projection);
263 /* Using GObject property methods */
264 g_object_set(title_block, "projection", valid_entity, NULL);
265 g_object_get(title_block, "projection", &projection, NULL);
266 g_assert_true(projection == valid_entity);
267 adg_entity_destroy(projection);
269 g_object_set(title_block, "projection", invalid_entity, NULL);
270 g_object_get(title_block, "projection", &projection, NULL);
271 g_assert_true(projection == valid_entity);
272 adg_entity_destroy(projection);
274 g_object_set(title_block, "projection", NULL, NULL);
275 g_object_get(title_block, "projection", &projection, NULL);
276 g_assert_null(projection);
278 adg_entity_destroy(ADG_ENTITY(title_block));
279 g_object_unref(valid_entity);
282 static void
283 _adg_property_scale(void)
285 AdgTitleBlock *title_block;
286 const gchar *valid_text, *latin1_text;
287 const gchar *scale;
288 gchar *scale_dup;
290 title_block = adg_title_block_new();
291 valid_text = "This is some text...";
292 latin1_text = "This is some àèìòù Latin1 text...";
294 /* Using the public APIs */
295 adg_title_block_set_scale(title_block, valid_text);
296 scale = adg_title_block_get_scale(title_block);
297 g_assert_cmpstr(scale, ==, valid_text);
299 adg_title_block_set_scale(title_block, latin1_text);
300 scale = adg_title_block_get_scale(title_block);
301 g_assert_cmpstr(scale, ==, latin1_text);
303 adg_title_block_set_scale(title_block, NULL);
304 scale = adg_title_block_get_scale(title_block);
305 g_assert_null(scale);
307 /* Using GObject property methods */
308 g_object_set(title_block, "scale", valid_text, NULL);
309 g_object_get(title_block, "scale", &scale_dup, NULL);
310 g_assert_cmpstr(scale_dup, ==, valid_text);
311 g_free(scale_dup);
313 g_object_set(title_block, "scale", latin1_text, NULL);
314 g_object_get(title_block, "scale", &scale_dup, NULL);
315 g_assert_cmpstr(scale_dup, ==, latin1_text);
316 g_free(scale_dup);
318 g_object_set(title_block, "scale", NULL, NULL);
319 g_object_get(title_block, "scale", &scale_dup, NULL);
320 g_assert_null(scale_dup);
322 adg_entity_destroy(ADG_ENTITY(title_block));
325 static void
326 _adg_property_size(void)
328 AdgTitleBlock *title_block;
329 const gchar *valid_text, *latin1_text;
330 const gchar *size;
331 gchar *size_dup;
333 title_block = adg_title_block_new();
334 valid_text = "This is some text...";
335 latin1_text = "This is some àèìòù Latin1 text...";
337 /* Using the public APIs */
338 adg_title_block_set_size(title_block, valid_text);
339 size = adg_title_block_get_size(title_block);
340 g_assert_cmpstr(size, ==, valid_text);
342 adg_title_block_set_size(title_block, latin1_text);
343 size = adg_title_block_get_size(title_block);
344 g_assert_cmpstr(size, ==, latin1_text);
346 adg_title_block_set_size(title_block, NULL);
347 size = adg_title_block_get_size(title_block);
348 g_assert_null(size);
350 /* Using GObject property methods */
351 g_object_set(title_block, "size", valid_text, NULL);
352 g_object_get(title_block, "size", &size_dup, NULL);
353 g_assert_cmpstr(size_dup, ==, valid_text);
354 g_free(size_dup);
356 g_object_set(title_block, "size", latin1_text, NULL);
357 g_object_get(title_block, "size", &size_dup, NULL);
358 g_assert_cmpstr(size_dup, ==, latin1_text);
359 g_free(size_dup);
361 g_object_set(title_block, "size", NULL, NULL);
362 g_object_get(title_block, "size", &size_dup, NULL);
363 g_assert_null(size_dup);
365 adg_entity_destroy(ADG_ENTITY(title_block));
368 static void
369 _adg_property_title(void)
371 AdgTitleBlock *title_block;
372 const gchar *valid_text, *latin1_text;
373 const gchar *title;
374 gchar *title_dup;
376 title_block = adg_title_block_new();
377 valid_text = "This is some text...";
378 latin1_text = "This is some àèìòù Latin1 text...";
380 /* Using the public APIs */
381 adg_title_block_set_title(title_block, valid_text);
382 title = adg_title_block_get_title(title_block);
383 g_assert_cmpstr(title, ==, valid_text);
385 adg_title_block_set_title(title_block, latin1_text);
386 title = adg_title_block_get_title(title_block);
387 g_assert_cmpstr(title, ==, latin1_text);
389 adg_title_block_set_title(title_block, NULL);
390 title = adg_title_block_get_title(title_block);
391 g_assert_null(title);
393 /* Using GObject property methods */
394 g_object_set(title_block, "title", valid_text, NULL);
395 g_object_get(title_block, "title", &title_dup, NULL);
396 g_assert_cmpstr(title_dup, ==, valid_text);
397 g_free(title_dup);
399 g_object_set(title_block, "title", latin1_text, NULL);
400 g_object_get(title_block, "title", &title_dup, NULL);
401 g_assert_cmpstr(title_dup, ==, latin1_text);
402 g_free(title_dup);
404 g_object_set(title_block, "title", NULL, NULL);
405 g_object_get(title_block, "title", &title_dup, NULL);
406 g_assert_null(title_dup);
408 adg_entity_destroy(ADG_ENTITY(title_block));
413 main(int argc, char *argv[])
415 adg_test_init(&argc, &argv);
417 adg_test_add_object_checks("/adg/title-block/type/object", ADG_TYPE_TITLE_BLOCK);
418 adg_test_add_entity_checks("/adg/title-block/type/entity", ADG_TYPE_TITLE_BLOCK);
420 adg_test_add_global_space_checks("/adg/title-block/behavior/global-space", adg_title_block_new());
422 g_test_add_func("/adg/title-block/property/local-mix", _adg_property_local_mix);
423 g_test_add_func("/adg/title-block/property/author", _adg_property_author);
424 g_test_add_func("/adg/title-block/property/date", _adg_property_date);
425 g_test_add_func("/adg/title-block/property/drawing", _adg_property_drawing);
426 g_test_add_func("/adg/title-block/property/logo", _adg_property_logo);
427 g_test_add_func("/adg/title-block/property/projection", _adg_property_projection);
428 g_test_add_func("/adg/title-block/property/scale", _adg_property_scale);
429 g_test_add_func("/adg/title-block/property/size", _adg_property_size);
430 g_test_add_func("/adg/title-block/property/title", _adg_property_title);
432 return g_test_run();