1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2010,2011,2012 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_author(void)
27 AdgTitleBlock
*title_block
;
28 const gchar
*valid_text
, *latin1_text
;
32 title_block
= adg_title_block_new();
33 valid_text
= "This is some text...";
34 latin1_text
= "This is some àèìòù Latin1 text...";
36 /* Using the public APIs */
37 adg_title_block_set_author(title_block
, valid_text
);
38 author
= adg_title_block_get_author(title_block
);
39 g_assert_cmpstr(author
, ==, valid_text
);
41 adg_title_block_set_author(title_block
, latin1_text
);
42 author
= adg_title_block_get_author(title_block
);
43 g_assert_cmpstr(author
, ==, latin1_text
);
45 adg_title_block_set_author(title_block
, NULL
);
46 author
= adg_title_block_get_author(title_block
);
47 g_assert(author
== NULL
);
49 /* Using GObject property methods */
50 g_object_set(title_block
, "author", valid_text
, NULL
);
51 g_object_get(title_block
, "author", &author_dup
, NULL
);
52 g_assert_cmpstr(author_dup
, ==, valid_text
);
55 g_object_set(title_block
, "author", latin1_text
, NULL
);
56 g_object_get(title_block
, "author", &author_dup
, NULL
);
57 g_assert_cmpstr(author_dup
, ==, latin1_text
);
60 g_object_set(title_block
, "author", NULL
, NULL
);
61 g_object_get(title_block
, "author", &author_dup
, NULL
);
62 g_assert(author_dup
== NULL
);
64 adg_entity_destroy(ADG_ENTITY(title_block
));
70 AdgTitleBlock
*title_block
;
71 const gchar
*valid_text
, *latin1_text
;
75 title_block
= adg_title_block_new();
76 valid_text
= "This is some text...";
77 latin1_text
= "This is some àèìòù Latin1 text...";
79 /* Using the public APIs */
80 adg_title_block_set_date(title_block
, valid_text
);
81 date
= adg_title_block_get_date(title_block
);
82 g_assert_cmpstr(date
, ==, valid_text
);
84 adg_title_block_set_date(title_block
, latin1_text
);
85 date
= adg_title_block_get_date(title_block
);
86 g_assert_cmpstr(date
, ==, latin1_text
);
88 adg_title_block_set_date(title_block
, NULL
);
89 date
= adg_title_block_get_date(title_block
);
90 g_assert(date
!= NULL
);
92 /* Using GObject property methods */
93 g_object_set(title_block
, "date", valid_text
, NULL
);
94 g_object_get(title_block
, "date", &date_dup
, NULL
);
95 g_assert_cmpstr(date_dup
, ==, valid_text
);
98 g_object_set(title_block
, "date", latin1_text
, NULL
);
99 g_object_get(title_block
, "date", &date_dup
, NULL
);
100 g_assert_cmpstr(date_dup
, ==, latin1_text
);
103 g_object_set(title_block
, "date", NULL
, NULL
);
104 g_object_get(title_block
, "date", &date_dup
, NULL
);
105 g_assert(date_dup
!= NULL
);
108 adg_entity_destroy(ADG_ENTITY(title_block
));
112 _adg_test_drawing(void)
114 AdgTitleBlock
*title_block
;
115 const gchar
*valid_text
, *latin1_text
;
116 const gchar
*drawing
;
119 title_block
= adg_title_block_new();
120 valid_text
= "This is some text...";
121 latin1_text
= "This is some àèìòù Latin1 text...";
123 /* Using the public APIs */
124 adg_title_block_set_drawing(title_block
, valid_text
);
125 drawing
= adg_title_block_get_drawing(title_block
);
126 g_assert_cmpstr(drawing
, ==, valid_text
);
128 adg_title_block_set_drawing(title_block
, latin1_text
);
129 drawing
= adg_title_block_get_drawing(title_block
);
130 g_assert_cmpstr(drawing
, ==, latin1_text
);
132 adg_title_block_set_drawing(title_block
, NULL
);
133 drawing
= adg_title_block_get_drawing(title_block
);
134 g_assert(drawing
== NULL
);
136 /* Using GObject property methods */
137 g_object_set(title_block
, "drawing", valid_text
, NULL
);
138 g_object_get(title_block
, "drawing", &drawing_dup
, NULL
);
139 g_assert_cmpstr(drawing_dup
, ==, valid_text
);
142 g_object_set(title_block
, "drawing", latin1_text
, NULL
);
143 g_object_get(title_block
, "drawing", &drawing_dup
, NULL
);
144 g_assert_cmpstr(drawing_dup
, ==, latin1_text
);
147 g_object_set(title_block
, "drawing", NULL
, NULL
);
148 g_object_get(title_block
, "drawing", &drawing_dup
, NULL
);
149 g_assert(drawing_dup
== NULL
);
151 adg_entity_destroy(ADG_ENTITY(title_block
));
157 AdgTitleBlock
*title_block
;
158 AdgEntity
*valid_entity
, *invalid_entity
, *logo
;
160 title_block
= adg_title_block_new();
161 valid_entity
= ADG_ENTITY(adg_hatch_new(NULL
));
162 invalid_entity
= adg_test_invalid_pointer();
164 /* Prevent valid_entity from being destroyed
165 * the first time AdgTitleBlock:logo is set to NULL */
166 g_object_ref(valid_entity
);
168 /* Using the public APIs */
169 adg_title_block_set_logo(title_block
, valid_entity
);
170 logo
= adg_title_block_logo(title_block
);
171 g_assert(logo
== valid_entity
);
173 adg_title_block_set_logo(title_block
, invalid_entity
);
174 logo
= adg_title_block_logo(title_block
);
175 g_assert(logo
== valid_entity
);
177 adg_title_block_set_logo(title_block
, valid_entity
);
178 logo
= adg_title_block_logo(title_block
);
179 g_assert(logo
== valid_entity
);
181 adg_title_block_set_logo(title_block
, NULL
);
182 logo
= adg_title_block_logo(title_block
);
183 g_assert(logo
== NULL
);
185 /* Using GObject property methods */
186 g_object_set(title_block
, "logo", valid_entity
, NULL
);
187 g_object_get(title_block
, "logo", &logo
, NULL
);
188 g_assert(logo
== valid_entity
);
189 adg_entity_destroy(logo
);
191 g_object_set(title_block
, "logo", invalid_entity
, NULL
);
192 g_object_get(title_block
, "logo", &logo
, NULL
);
193 g_assert(logo
== valid_entity
);
194 adg_entity_destroy(logo
);
196 g_object_set(title_block
, "logo", valid_entity
, NULL
);
197 g_object_get(title_block
, "logo", &logo
, NULL
);
198 g_assert(logo
== valid_entity
);
199 adg_entity_destroy(logo
);
201 g_object_set(title_block
, "logo", NULL
, NULL
);
202 g_object_get(title_block
, "logo", &logo
, NULL
);
203 g_assert(logo
== NULL
);
205 adg_entity_destroy(ADG_ENTITY(title_block
));
206 g_object_unref(valid_entity
);
210 _adg_test_projection(void)
212 AdgTitleBlock
*title_block
;
213 AdgEntity
*valid_entity
, *invalid_entity
, *projection
;
215 title_block
= adg_title_block_new();
216 valid_entity
= ADG_ENTITY(adg_hatch_new(NULL
));
217 invalid_entity
= adg_test_invalid_pointer();
219 /* Prevent valid_entity from being destroyed
220 * the first time AdgTitleBlock:projection is set to NULL */
221 g_object_ref(valid_entity
);
223 /* Using the public APIs */
224 adg_title_block_set_projection(title_block
, valid_entity
);
225 projection
= adg_title_block_projection(title_block
);
226 g_assert(projection
== valid_entity
);
228 adg_title_block_set_projection(title_block
, invalid_entity
);
229 projection
= adg_title_block_projection(title_block
);
230 g_assert(projection
== valid_entity
);
232 adg_title_block_set_projection(title_block
, NULL
);
233 projection
= adg_title_block_projection(title_block
);
234 g_assert(projection
== NULL
);
236 /* Using GObject property methods */
237 g_object_set(title_block
, "projection", valid_entity
, NULL
);
238 g_object_get(title_block
, "projection", &projection
, NULL
);
239 g_assert(projection
== valid_entity
);
240 adg_entity_destroy(projection
);
242 g_object_set(title_block
, "projection", invalid_entity
, NULL
);
243 g_object_get(title_block
, "projection", &projection
, NULL
);
244 g_assert(projection
== valid_entity
);
245 adg_entity_destroy(projection
);
247 g_object_set(title_block
, "projection", NULL
, NULL
);
248 g_object_get(title_block
, "projection", &projection
, NULL
);
249 g_assert(projection
== NULL
);
251 adg_entity_destroy(ADG_ENTITY(title_block
));
252 g_object_unref(valid_entity
);
256 _adg_test_scale(void)
258 AdgTitleBlock
*title_block
;
259 const gchar
*valid_text
, *latin1_text
;
263 title_block
= adg_title_block_new();
264 valid_text
= "This is some text...";
265 latin1_text
= "This is some àèìòù Latin1 text...";
267 /* Using the public APIs */
268 adg_title_block_set_scale(title_block
, valid_text
);
269 scale
= adg_title_block_get_scale(title_block
);
270 g_assert_cmpstr(scale
, ==, valid_text
);
272 adg_title_block_set_scale(title_block
, latin1_text
);
273 scale
= adg_title_block_get_scale(title_block
);
274 g_assert_cmpstr(scale
, ==, latin1_text
);
276 adg_title_block_set_scale(title_block
, NULL
);
277 scale
= adg_title_block_get_scale(title_block
);
278 g_assert(scale
== NULL
);
280 /* Using GObject property methods */
281 g_object_set(title_block
, "scale", valid_text
, NULL
);
282 g_object_get(title_block
, "scale", &scale_dup
, NULL
);
283 g_assert_cmpstr(scale_dup
, ==, valid_text
);
286 g_object_set(title_block
, "scale", latin1_text
, NULL
);
287 g_object_get(title_block
, "scale", &scale_dup
, NULL
);
288 g_assert_cmpstr(scale_dup
, ==, latin1_text
);
291 g_object_set(title_block
, "scale", NULL
, NULL
);
292 g_object_get(title_block
, "scale", &scale_dup
, NULL
);
293 g_assert(scale_dup
== NULL
);
295 adg_entity_destroy(ADG_ENTITY(title_block
));
301 AdgTitleBlock
*title_block
;
302 const gchar
*valid_text
, *latin1_text
;
306 title_block
= adg_title_block_new();
307 valid_text
= "This is some text...";
308 latin1_text
= "This is some àèìòù Latin1 text...";
310 /* Using the public APIs */
311 adg_title_block_set_size(title_block
, valid_text
);
312 size
= adg_title_block_get_size(title_block
);
313 g_assert_cmpstr(size
, ==, valid_text
);
315 adg_title_block_set_size(title_block
, latin1_text
);
316 size
= adg_title_block_get_size(title_block
);
317 g_assert_cmpstr(size
, ==, latin1_text
);
319 adg_title_block_set_size(title_block
, NULL
);
320 size
= adg_title_block_get_size(title_block
);
321 g_assert(size
== NULL
);
323 /* Using GObject property methods */
324 g_object_set(title_block
, "size", valid_text
, NULL
);
325 g_object_get(title_block
, "size", &size_dup
, NULL
);
326 g_assert_cmpstr(size_dup
, ==, valid_text
);
329 g_object_set(title_block
, "size", latin1_text
, NULL
);
330 g_object_get(title_block
, "size", &size_dup
, NULL
);
331 g_assert_cmpstr(size_dup
, ==, latin1_text
);
334 g_object_set(title_block
, "size", NULL
, NULL
);
335 g_object_get(title_block
, "size", &size_dup
, NULL
);
336 g_assert(size_dup
== NULL
);
338 adg_entity_destroy(ADG_ENTITY(title_block
));
342 _adg_test_title(void)
344 AdgTitleBlock
*title_block
;
345 const gchar
*valid_text
, *latin1_text
;
349 title_block
= adg_title_block_new();
350 valid_text
= "This is some text...";
351 latin1_text
= "This is some àèìòù Latin1 text...";
353 /* Using the public APIs */
354 adg_title_block_set_title(title_block
, valid_text
);
355 title
= adg_title_block_get_title(title_block
);
356 g_assert_cmpstr(title
, ==, valid_text
);
358 adg_title_block_set_title(title_block
, latin1_text
);
359 title
= adg_title_block_get_title(title_block
);
360 g_assert_cmpstr(title
, ==, latin1_text
);
362 adg_title_block_set_title(title_block
, NULL
);
363 title
= adg_title_block_get_title(title_block
);
364 g_assert(title
== NULL
);
366 /* Using GObject property methods */
367 g_object_set(title_block
, "title", valid_text
, NULL
);
368 g_object_get(title_block
, "title", &title_dup
, NULL
);
369 g_assert_cmpstr(title_dup
, ==, valid_text
);
372 g_object_set(title_block
, "title", latin1_text
, NULL
);
373 g_object_get(title_block
, "title", &title_dup
, NULL
);
374 g_assert_cmpstr(title_dup
, ==, latin1_text
);
377 g_object_set(title_block
, "title", NULL
, NULL
);
378 g_object_get(title_block
, "title", &title_dup
, NULL
);
379 g_assert(title_dup
== NULL
);
381 adg_entity_destroy(ADG_ENTITY(title_block
));
386 main(int argc
, char *argv
[])
388 adg_test_init(&argc
, &argv
);
390 adg_test_add_func("/adg/title-block/author", _adg_test_author
);
391 adg_test_add_func("/adg/title-block/date", _adg_test_date
);
392 adg_test_add_func("/adg/title-block/drawing", _adg_test_drawing
);
393 adg_test_add_func("/adg/title-block/logo", _adg_test_logo
);
394 adg_test_add_func("/adg/title-block/projection", _adg_test_projection
);
395 adg_test_add_func("/adg/title-block/scale", _adg_test_scale
);
396 adg_test_add_func("/adg/title-block/size", _adg_test_size
);
397 adg_test_add_func("/adg/title-block/title", _adg_test_title
);