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"
25 _adg_test_local_mix(void)
27 AdgTitleBlock
*title_block
;
30 /* Ensure the title block behaves exaclty like an AdgTable */
32 title_block
= adg_title_block_new();
33 entity
= (AdgEntity
*) title_block
;
34 g_assert_cmpint(adg_entity_get_local_mix(entity
), ==, ADG_MIX_DISABLED
);
35 adg_entity_destroy(entity
);
37 /* Check local mix method overriding */
38 title_block
= g_object_new(ADG_TYPE_TITLE_BLOCK
, "local-mix", ADG_MIX_ANCESTORS_NORMALIZED
, NULL
);
39 entity
= (AdgEntity
*) title_block
;
40 g_assert_cmpint(adg_entity_get_local_mix(entity
), ==, ADG_MIX_ANCESTORS_NORMALIZED
);
41 adg_entity_destroy(entity
);
43 /* Check default mix using GObject methods */
44 title_block
= g_object_new(ADG_TYPE_TITLE_BLOCK
, NULL
);
45 entity
= (AdgEntity
*) title_block
;
46 g_assert_cmpint(adg_entity_get_local_mix(entity
), ==, ADG_MIX_DISABLED
);
47 adg_entity_destroy(entity
);
51 _adg_test_author(void)
53 AdgTitleBlock
*title_block
;
54 const gchar
*valid_text
, *latin1_text
;
58 title_block
= adg_title_block_new();
59 valid_text
= "This is some text...";
60 latin1_text
= "This is some àèìòù Latin1 text...";
62 /* Using the public APIs */
63 adg_title_block_set_author(title_block
, valid_text
);
64 author
= adg_title_block_get_author(title_block
);
65 g_assert_cmpstr(author
, ==, valid_text
);
67 adg_title_block_set_author(title_block
, latin1_text
);
68 author
= adg_title_block_get_author(title_block
);
69 g_assert_cmpstr(author
, ==, latin1_text
);
71 adg_title_block_set_author(title_block
, NULL
);
72 author
= adg_title_block_get_author(title_block
);
73 g_assert(author
== NULL
);
75 /* Using GObject property methods */
76 g_object_set(title_block
, "author", valid_text
, NULL
);
77 g_object_get(title_block
, "author", &author_dup
, NULL
);
78 g_assert_cmpstr(author_dup
, ==, valid_text
);
81 g_object_set(title_block
, "author", latin1_text
, NULL
);
82 g_object_get(title_block
, "author", &author_dup
, NULL
);
83 g_assert_cmpstr(author_dup
, ==, latin1_text
);
86 g_object_set(title_block
, "author", NULL
, NULL
);
87 g_object_get(title_block
, "author", &author_dup
, NULL
);
88 g_assert(author_dup
== NULL
);
90 adg_entity_destroy(ADG_ENTITY(title_block
));
96 AdgTitleBlock
*title_block
;
97 const gchar
*valid_text
, *latin1_text
;
101 title_block
= adg_title_block_new();
102 valid_text
= "This is some text...";
103 latin1_text
= "This is some àèìòù Latin1 text...";
105 /* Using the public APIs */
106 adg_title_block_set_date(title_block
, valid_text
);
107 date
= adg_title_block_get_date(title_block
);
108 g_assert_cmpstr(date
, ==, valid_text
);
110 adg_title_block_set_date(title_block
, latin1_text
);
111 date
= adg_title_block_get_date(title_block
);
112 g_assert_cmpstr(date
, ==, latin1_text
);
114 adg_title_block_set_date(title_block
, NULL
);
115 date
= adg_title_block_get_date(title_block
);
116 g_assert(date
!= NULL
);
118 /* Using GObject property methods */
119 g_object_set(title_block
, "date", valid_text
, NULL
);
120 g_object_get(title_block
, "date", &date_dup
, NULL
);
121 g_assert_cmpstr(date_dup
, ==, valid_text
);
124 g_object_set(title_block
, "date", latin1_text
, NULL
);
125 g_object_get(title_block
, "date", &date_dup
, NULL
);
126 g_assert_cmpstr(date_dup
, ==, latin1_text
);
129 g_object_set(title_block
, "date", NULL
, NULL
);
130 g_object_get(title_block
, "date", &date_dup
, NULL
);
131 g_assert(date_dup
!= NULL
);
134 adg_entity_destroy(ADG_ENTITY(title_block
));
138 _adg_test_drawing(void)
140 AdgTitleBlock
*title_block
;
141 const gchar
*valid_text
, *latin1_text
;
142 const gchar
*drawing
;
145 title_block
= adg_title_block_new();
146 valid_text
= "This is some text...";
147 latin1_text
= "This is some àèìòù Latin1 text...";
149 /* Using the public APIs */
150 adg_title_block_set_drawing(title_block
, valid_text
);
151 drawing
= adg_title_block_get_drawing(title_block
);
152 g_assert_cmpstr(drawing
, ==, valid_text
);
154 adg_title_block_set_drawing(title_block
, latin1_text
);
155 drawing
= adg_title_block_get_drawing(title_block
);
156 g_assert_cmpstr(drawing
, ==, latin1_text
);
158 adg_title_block_set_drawing(title_block
, NULL
);
159 drawing
= adg_title_block_get_drawing(title_block
);
160 g_assert(drawing
== NULL
);
162 /* Using GObject property methods */
163 g_object_set(title_block
, "drawing", valid_text
, NULL
);
164 g_object_get(title_block
, "drawing", &drawing_dup
, NULL
);
165 g_assert_cmpstr(drawing_dup
, ==, valid_text
);
168 g_object_set(title_block
, "drawing", latin1_text
, NULL
);
169 g_object_get(title_block
, "drawing", &drawing_dup
, NULL
);
170 g_assert_cmpstr(drawing_dup
, ==, latin1_text
);
173 g_object_set(title_block
, "drawing", NULL
, NULL
);
174 g_object_get(title_block
, "drawing", &drawing_dup
, NULL
);
175 g_assert(drawing_dup
== NULL
);
177 adg_entity_destroy(ADG_ENTITY(title_block
));
183 AdgTitleBlock
*title_block
;
184 AdgEntity
*valid_entity
, *invalid_entity
, *logo
;
186 title_block
= adg_title_block_new();
187 valid_entity
= ADG_ENTITY(adg_hatch_new(NULL
));
188 invalid_entity
= adg_test_invalid_pointer();
190 /* Prevent valid_entity from being destroyed
191 * the first time AdgTitleBlock:logo is set to NULL */
192 g_object_ref(valid_entity
);
194 /* Using the public APIs */
195 adg_title_block_set_logo(title_block
, valid_entity
);
196 logo
= adg_title_block_logo(title_block
);
197 g_assert(logo
== valid_entity
);
199 adg_title_block_set_logo(title_block
, invalid_entity
);
200 logo
= adg_title_block_logo(title_block
);
201 g_assert(logo
== valid_entity
);
203 adg_title_block_set_logo(title_block
, valid_entity
);
204 logo
= adg_title_block_logo(title_block
);
205 g_assert(logo
== valid_entity
);
207 adg_title_block_set_logo(title_block
, NULL
);
208 logo
= adg_title_block_logo(title_block
);
209 g_assert(logo
== NULL
);
211 /* Using GObject property methods */
212 g_object_set(title_block
, "logo", valid_entity
, NULL
);
213 g_object_get(title_block
, "logo", &logo
, NULL
);
214 g_assert(logo
== valid_entity
);
215 adg_entity_destroy(logo
);
217 g_object_set(title_block
, "logo", invalid_entity
, NULL
);
218 g_object_get(title_block
, "logo", &logo
, NULL
);
219 g_assert(logo
== valid_entity
);
220 adg_entity_destroy(logo
);
222 g_object_set(title_block
, "logo", valid_entity
, NULL
);
223 g_object_get(title_block
, "logo", &logo
, NULL
);
224 g_assert(logo
== valid_entity
);
225 adg_entity_destroy(logo
);
227 g_object_set(title_block
, "logo", NULL
, NULL
);
228 g_object_get(title_block
, "logo", &logo
, NULL
);
229 g_assert(logo
== NULL
);
231 adg_entity_destroy(ADG_ENTITY(title_block
));
232 g_object_unref(valid_entity
);
236 _adg_test_projection(void)
238 AdgTitleBlock
*title_block
;
239 AdgEntity
*valid_entity
, *invalid_entity
, *projection
;
241 title_block
= adg_title_block_new();
242 valid_entity
= ADG_ENTITY(adg_hatch_new(NULL
));
243 invalid_entity
= adg_test_invalid_pointer();
245 /* Prevent valid_entity from being destroyed
246 * the first time AdgTitleBlock:projection is set to NULL */
247 g_object_ref(valid_entity
);
249 /* Using the public APIs */
250 adg_title_block_set_projection(title_block
, valid_entity
);
251 projection
= adg_title_block_projection(title_block
);
252 g_assert(projection
== valid_entity
);
254 adg_title_block_set_projection(title_block
, invalid_entity
);
255 projection
= adg_title_block_projection(title_block
);
256 g_assert(projection
== valid_entity
);
258 adg_title_block_set_projection(title_block
, NULL
);
259 projection
= adg_title_block_projection(title_block
);
260 g_assert(projection
== NULL
);
262 /* Using GObject property methods */
263 g_object_set(title_block
, "projection", valid_entity
, NULL
);
264 g_object_get(title_block
, "projection", &projection
, NULL
);
265 g_assert(projection
== valid_entity
);
266 adg_entity_destroy(projection
);
268 g_object_set(title_block
, "projection", invalid_entity
, NULL
);
269 g_object_get(title_block
, "projection", &projection
, NULL
);
270 g_assert(projection
== valid_entity
);
271 adg_entity_destroy(projection
);
273 g_object_set(title_block
, "projection", NULL
, NULL
);
274 g_object_get(title_block
, "projection", &projection
, NULL
);
275 g_assert(projection
== NULL
);
277 adg_entity_destroy(ADG_ENTITY(title_block
));
278 g_object_unref(valid_entity
);
282 _adg_test_scale(void)
284 AdgTitleBlock
*title_block
;
285 const gchar
*valid_text
, *latin1_text
;
289 title_block
= adg_title_block_new();
290 valid_text
= "This is some text...";
291 latin1_text
= "This is some àèìòù Latin1 text...";
293 /* Using the public APIs */
294 adg_title_block_set_scale(title_block
, valid_text
);
295 scale
= adg_title_block_get_scale(title_block
);
296 g_assert_cmpstr(scale
, ==, valid_text
);
298 adg_title_block_set_scale(title_block
, latin1_text
);
299 scale
= adg_title_block_get_scale(title_block
);
300 g_assert_cmpstr(scale
, ==, latin1_text
);
302 adg_title_block_set_scale(title_block
, NULL
);
303 scale
= adg_title_block_get_scale(title_block
);
304 g_assert(scale
== NULL
);
306 /* Using GObject property methods */
307 g_object_set(title_block
, "scale", valid_text
, NULL
);
308 g_object_get(title_block
, "scale", &scale_dup
, NULL
);
309 g_assert_cmpstr(scale_dup
, ==, valid_text
);
312 g_object_set(title_block
, "scale", latin1_text
, NULL
);
313 g_object_get(title_block
, "scale", &scale_dup
, NULL
);
314 g_assert_cmpstr(scale_dup
, ==, latin1_text
);
317 g_object_set(title_block
, "scale", NULL
, NULL
);
318 g_object_get(title_block
, "scale", &scale_dup
, NULL
);
319 g_assert(scale_dup
== NULL
);
321 adg_entity_destroy(ADG_ENTITY(title_block
));
327 AdgTitleBlock
*title_block
;
328 const gchar
*valid_text
, *latin1_text
;
332 title_block
= adg_title_block_new();
333 valid_text
= "This is some text...";
334 latin1_text
= "This is some àèìòù Latin1 text...";
336 /* Using the public APIs */
337 adg_title_block_set_size(title_block
, valid_text
);
338 size
= adg_title_block_get_size(title_block
);
339 g_assert_cmpstr(size
, ==, valid_text
);
341 adg_title_block_set_size(title_block
, latin1_text
);
342 size
= adg_title_block_get_size(title_block
);
343 g_assert_cmpstr(size
, ==, latin1_text
);
345 adg_title_block_set_size(title_block
, NULL
);
346 size
= adg_title_block_get_size(title_block
);
347 g_assert(size
== NULL
);
349 /* Using GObject property methods */
350 g_object_set(title_block
, "size", valid_text
, NULL
);
351 g_object_get(title_block
, "size", &size_dup
, NULL
);
352 g_assert_cmpstr(size_dup
, ==, valid_text
);
355 g_object_set(title_block
, "size", latin1_text
, NULL
);
356 g_object_get(title_block
, "size", &size_dup
, NULL
);
357 g_assert_cmpstr(size_dup
, ==, latin1_text
);
360 g_object_set(title_block
, "size", NULL
, NULL
);
361 g_object_get(title_block
, "size", &size_dup
, NULL
);
362 g_assert(size_dup
== NULL
);
364 adg_entity_destroy(ADG_ENTITY(title_block
));
368 _adg_test_title(void)
370 AdgTitleBlock
*title_block
;
371 const gchar
*valid_text
, *latin1_text
;
375 title_block
= adg_title_block_new();
376 valid_text
= "This is some text...";
377 latin1_text
= "This is some àèìòù Latin1 text...";
379 /* Using the public APIs */
380 adg_title_block_set_title(title_block
, valid_text
);
381 title
= adg_title_block_get_title(title_block
);
382 g_assert_cmpstr(title
, ==, valid_text
);
384 adg_title_block_set_title(title_block
, latin1_text
);
385 title
= adg_title_block_get_title(title_block
);
386 g_assert_cmpstr(title
, ==, latin1_text
);
388 adg_title_block_set_title(title_block
, NULL
);
389 title
= adg_title_block_get_title(title_block
);
390 g_assert(title
== NULL
);
392 /* Using GObject property methods */
393 g_object_set(title_block
, "title", valid_text
, NULL
);
394 g_object_get(title_block
, "title", &title_dup
, NULL
);
395 g_assert_cmpstr(title_dup
, ==, valid_text
);
398 g_object_set(title_block
, "title", latin1_text
, NULL
);
399 g_object_get(title_block
, "title", &title_dup
, NULL
);
400 g_assert_cmpstr(title_dup
, ==, latin1_text
);
403 g_object_set(title_block
, "title", NULL
, NULL
);
404 g_object_get(title_block
, "title", &title_dup
, NULL
);
405 g_assert(title_dup
== NULL
);
407 adg_entity_destroy(ADG_ENTITY(title_block
));
412 main(int argc
, char *argv
[])
414 adg_test_init(&argc
, &argv
);
416 adg_test_add_func("/adg/title-block/local-mix", _adg_test_local_mix
);
417 adg_test_add_func("/adg/title-block/author", _adg_test_author
);
418 adg_test_add_func("/adg/title-block/date", _adg_test_date
);
419 adg_test_add_func("/adg/title-block/drawing", _adg_test_drawing
);
420 adg_test_add_func("/adg/title-block/logo", _adg_test_logo
);
421 adg_test_add_func("/adg/title-block/projection", _adg_test_projection
);
422 adg_test_add_func("/adg/title-block/scale", _adg_test_scale
);
423 adg_test_add_func("/adg/title-block/size", _adg_test_size
);
424 adg_test_add_func("/adg/title-block/title", _adg_test_title
);