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 "test-internal.h"
25 _adg_test_detached(void)
28 AdgThreeState valid_three_state_1
, valid_three_state_2
, invalid_three_state
;
29 AdgThreeState detached
;
31 dim
= ADG_DIM(adg_adim_new());
32 valid_three_state_1
= ADG_THREE_STATE_UNKNOWN
;
33 valid_three_state_2
= ADG_THREE_STATE_OFF
;
34 invalid_three_state
= 1234;
36 /* Using the public APIs */
37 adg_dim_set_detached(dim
, valid_three_state_1
);
38 detached
= adg_dim_get_detached(dim
);
39 g_assert_cmpint(detached
, ==, valid_three_state_1
);
41 adg_dim_set_detached(dim
, invalid_three_state
);
42 detached
= adg_dim_get_detached(dim
);
43 g_assert_cmpint(detached
, ==, valid_three_state_1
);
45 adg_dim_set_detached(dim
, valid_three_state_2
);
46 detached
= adg_dim_get_detached(dim
);
47 g_assert_cmpint(detached
, ==, valid_three_state_2
);
49 /* Using GObject property methods */
50 g_object_set(dim
, "detached", valid_three_state_1
, NULL
);
51 g_object_get(dim
, "detached", &detached
, NULL
);
52 g_assert_cmpint(detached
, ==, valid_three_state_1
);
54 g_object_set(dim
, "detached", invalid_three_state
, NULL
);
55 g_object_get(dim
, "detached", &detached
, NULL
);
56 g_assert_cmpint(detached
, ==, valid_three_state_1
);
58 g_object_set(dim
, "detached", valid_three_state_2
, NULL
);
59 g_object_get(dim
, "detached", &detached
, NULL
);
60 g_assert_cmpint(detached
, ==, valid_three_state_2
);
62 adg_entity_destroy(ADG_ENTITY(dim
));
66 _adg_test_dim_dress(void)
69 AdgDress valid_dress
, incompatible_dress
;
72 dim
= ADG_DIM(adg_adim_new());
73 valid_dress
= ADG_DRESS_DIMENSION
;
74 incompatible_dress
= ADG_DRESS_LINE
;
76 /* Using the public APIs */
77 adg_dim_set_dim_dress(dim
, valid_dress
);
78 dim_dress
= adg_dim_get_dim_dress(dim
);
79 g_assert_cmpint(dim_dress
, ==, valid_dress
);
81 adg_dim_set_dim_dress(dim
, incompatible_dress
);
82 dim_dress
= adg_dim_get_dim_dress(dim
);
83 g_assert_cmpint(dim_dress
, ==, valid_dress
);
85 /* Using GObject property methods */
86 g_object_set(dim
, "dim-dress", valid_dress
, NULL
);
87 g_object_get(dim
, "dim-dress", &dim_dress
, NULL
);
88 g_assert_cmpint(dim_dress
, ==, valid_dress
);
90 g_object_set(dim
, "dim-dress", incompatible_dress
, NULL
);
91 g_object_get(dim
, "dim-dress", &dim_dress
, NULL
);
92 g_assert_cmpint(dim_dress
, ==, valid_dress
);
94 adg_entity_destroy(ADG_ENTITY(dim
));
101 gdouble valid_value_1
, valid_value_2
;
104 dim
= ADG_DIM(adg_ldim_new());
105 valid_value_1
= 4321;
106 valid_value_2
= 1234;
108 /* Using the public APIs */
109 adg_dim_set_level(dim
, valid_value_1
);
110 level
= adg_dim_get_level(dim
);
111 g_assert_cmpfloat(level
, ==, valid_value_1
);
113 adg_dim_set_level(dim
, valid_value_2
);
114 level
= adg_dim_get_level(dim
);
115 g_assert_cmpfloat(level
, ==, valid_value_2
);
117 /* Using GObject property methods */
118 g_object_set(dim
, "level", valid_value_1
, NULL
);
119 g_object_get(dim
, "level", &level
, NULL
);
120 g_assert_cmpfloat(level
, ==, valid_value_1
);
122 g_object_set(dim
, "level", valid_value_2
, NULL
);
123 g_object_get(dim
, "level", &level
, NULL
);
124 g_assert_cmpfloat(level
, ==, valid_value_2
);
126 adg_entity_destroy(ADG_ENTITY(dim
));
133 const gchar
*valid_text
, *latin1_text
;
137 dim
= ADG_DIM(adg_ldim_new());
138 valid_text
= "This is some text...";
139 latin1_text
= "This is some àèìòù Latin1 text...";
141 /* Using the public APIs */
142 adg_dim_set_max(dim
, valid_text
);
143 max
= adg_dim_get_max(dim
);
144 g_assert_cmpstr(max
, ==, valid_text
);
146 adg_dim_set_max(dim
, latin1_text
);
147 max
= adg_dim_get_max(dim
);
148 g_assert_cmpstr(max
, ==, latin1_text
);
150 adg_dim_set_max(dim
, NULL
);
151 max
= adg_dim_get_max(dim
);
152 g_assert(max
== NULL
);
154 /* Using GObject property methods */
155 g_object_set(dim
, "max", valid_text
, NULL
);
156 g_object_get(dim
, "max", &max_dup
, NULL
);
157 g_assert_cmpstr(max_dup
, ==, valid_text
);
160 g_object_set(dim
, "max", latin1_text
, NULL
);
161 g_object_get(dim
, "max", &max_dup
, NULL
);
162 g_assert_cmpstr(max_dup
, ==, latin1_text
);
165 g_object_set(dim
, "max", NULL
, NULL
);
166 g_object_get(dim
, "max", &max_dup
, NULL
);
167 g_assert(max_dup
== NULL
);
169 adg_entity_destroy(ADG_ENTITY(dim
));
176 const gchar
*valid_text
, *latin1_text
;
180 dim
= ADG_DIM(adg_ldim_new());
181 valid_text
= "This is some text...";
182 latin1_text
= "This is some àèìòù Latin1 text...";
184 /* Using the public APIs */
185 adg_dim_set_min(dim
, valid_text
);
186 min
= adg_dim_get_min(dim
);
187 g_assert_cmpstr(min
, ==, valid_text
);
189 adg_dim_set_min(dim
, latin1_text
);
190 min
= adg_dim_get_min(dim
);
191 g_assert_cmpstr(min
, ==, latin1_text
);
193 adg_dim_set_min(dim
, NULL
);
194 min
= adg_dim_get_min(dim
);
195 g_assert(min
== NULL
);
197 /* Using GObject property methods */
198 g_object_set(dim
, "min", valid_text
, NULL
);
199 g_object_get(dim
, "min", &min_dup
, NULL
);
200 g_assert_cmpstr(min_dup
, ==, valid_text
);
203 g_object_set(dim
, "min", latin1_text
, NULL
);
204 g_object_get(dim
, "min", &min_dup
, NULL
);
205 g_assert_cmpstr(min_dup
, ==, latin1_text
);
208 g_object_set(dim
, "min", NULL
, NULL
);
209 g_object_get(dim
, "min", &min_dup
, NULL
);
210 g_assert(min_dup
== NULL
);
212 adg_entity_destroy(ADG_ENTITY(dim
));
216 _adg_test_outside(void)
219 AdgThreeState valid_three_state_1
, valid_three_state_2
, invalid_three_state
;
220 AdgThreeState outside
;
222 dim
= ADG_DIM(adg_rdim_new());
223 valid_three_state_1
= ADG_THREE_STATE_UNKNOWN
;
224 valid_three_state_2
= ADG_THREE_STATE_OFF
;
225 invalid_three_state
= 1234;
227 /* Using the public APIs */
228 adg_dim_set_outside(dim
, valid_three_state_1
);
229 outside
= adg_dim_get_outside(dim
);
230 g_assert_cmpint(outside
, ==, valid_three_state_1
);
232 adg_dim_set_outside(dim
, invalid_three_state
);
233 outside
= adg_dim_get_outside(dim
);
234 g_assert_cmpint(outside
, ==, valid_three_state_1
);
236 adg_dim_set_outside(dim
, valid_three_state_2
);
237 outside
= adg_dim_get_outside(dim
);
238 g_assert_cmpint(outside
, ==, valid_three_state_2
);
240 /* Using GObject property methods */
241 g_object_set(dim
, "outside", valid_three_state_1
, NULL
);
242 g_object_get(dim
, "outside", &outside
, NULL
);
243 g_assert_cmpint(outside
, ==, valid_three_state_1
);
245 g_object_set(dim
, "outside", invalid_three_state
, NULL
);
246 g_object_get(dim
, "outside", &outside
, NULL
);
247 g_assert_cmpint(outside
, ==, valid_three_state_1
);
249 g_object_set(dim
, "outside", valid_three_state_2
, NULL
);
250 g_object_get(dim
, "outside", &outside
, NULL
);
251 g_assert_cmpint(outside
, ==, valid_three_state_2
);
253 adg_entity_destroy(ADG_ENTITY(dim
));
261 AdgPoint
*origin
, *explicit_point
, *model_point
;
264 dim
= ADG_DIM(adg_rdim_new());
265 model
= ADG_MODEL(adg_path_new());
266 origin
= adg_point_new();
267 explicit_point
= adg_point_new();
268 model_point
= adg_point_new();
270 adg_point_set_pair_explicit(origin
, 0, 0);
271 adg_point_set_pair_explicit(explicit_point
, 123, 321);
272 adg_model_set_named_pair(model
, "named-pair", (CpmlPair
*) explicit_point
);
273 adg_point_set_pair_from_model(model_point
, model
, "named-pair");
275 /* Ensure ADG does not consider an explicit point equals to
276 * a point bound to a named pair with the same coordinates */
277 g_assert(!adg_point_equal(explicit_point
, model_point
));
279 pos
= adg_dim_get_pos(dim
);
280 g_assert(pos
== NULL
);
282 /* Using the public APIs */
283 adg_dim_set_pos_explicit(dim
, 0, 0);
284 pos
= adg_dim_get_pos(dim
);
285 g_assert(adg_point_equal(pos
, origin
));
287 adg_dim_set_pos(dim
, NULL
);
288 pos
= adg_dim_get_pos(dim
);
289 g_assert(pos
== NULL
);
291 adg_dim_set_pos(dim
, explicit_point
);
292 pos
= adg_dim_get_pos(dim
);
293 g_assert(adg_point_equal(pos
, explicit_point
));
295 adg_dim_set_pos_from_model(dim
, model
, "dummy");
296 pos
= adg_dim_get_pos(dim
);
297 g_assert(pos
!= NULL
);
299 adg_dim_set_pos_from_model(dim
, model
, "named-pair");
300 pos
= adg_dim_get_pos(dim
);
301 g_assert(adg_point_equal(pos
, model_point
));
303 /* Using GObject property methods */
304 g_object_set(dim
, "pos", origin
, NULL
);
305 g_object_get(dim
, "pos", &pos
, NULL
);
306 g_assert(adg_point_equal(pos
, origin
));
307 adg_point_destroy(pos
);
309 g_object_set(dim
, "pos", NULL
, NULL
);
310 g_object_get(dim
, "pos", &pos
, NULL
);
311 g_assert(pos
== NULL
);
313 g_object_set(dim
, "pos", explicit_point
, NULL
);
314 g_object_get(dim
, "pos", &pos
, NULL
);
315 g_assert(adg_point_equal(pos
, explicit_point
));
316 adg_point_destroy(pos
);
318 adg_dim_set_pos_from_model(dim
, model
, "dummy");
319 g_object_get(dim
, "pos", &pos
, NULL
);
320 g_assert(pos
!= NULL
);
321 adg_point_destroy(pos
);
323 g_object_set(dim
, "pos", model_point
, NULL
);
324 g_object_get(dim
, "pos", &pos
, NULL
);
325 g_assert(adg_point_equal(pos
, model_point
));
326 adg_point_destroy(pos
);
328 adg_point_destroy(origin
);
329 adg_point_destroy(explicit_point
);
330 adg_point_destroy(model_point
);
331 adg_entity_destroy(ADG_ENTITY(dim
));
332 g_object_unref(model
);
340 AdgPoint
*origin
, *explicit_point
, *model_point
;
343 dim
= ADG_DIM(adg_rdim_new());
344 model
= ADG_MODEL(adg_path_new());
345 origin
= adg_point_new();
346 explicit_point
= adg_point_new();
347 model_point
= adg_point_new();
349 adg_point_set_pair_explicit(origin
, 0, 0);
350 adg_point_set_pair_explicit(explicit_point
, 123, 321);
351 adg_model_set_named_pair(model
, "named-pair", (CpmlPair
*) explicit_point
);
352 adg_point_set_pair_from_model(model_point
, model
, "named-pair");
354 /* Ensure ADG does not consider an explicit point equals to
355 * a point bound to a named pair with the same coordinates */
356 g_assert(!adg_point_equal(explicit_point
, model_point
));
358 ref1
= adg_dim_get_ref1(dim
);
359 g_assert(ref1
== NULL
);
361 /* Using the public APIs */
362 adg_dim_set_ref1_explicit(dim
, 0, 0);
363 ref1
= adg_dim_get_ref1(dim
);
364 g_assert(adg_point_equal(ref1
, origin
));
366 adg_dim_set_ref1(dim
, NULL
);
367 ref1
= adg_dim_get_ref1(dim
);
368 g_assert(ref1
== NULL
);
370 adg_dim_set_ref1(dim
, explicit_point
);
371 ref1
= adg_dim_get_ref1(dim
);
372 g_assert(adg_point_equal(ref1
, explicit_point
));
374 adg_dim_set_ref1_from_model(dim
, model
, "dummy");
375 ref1
= adg_dim_get_ref1(dim
);
376 g_assert(ref1
!= NULL
);
378 adg_dim_set_ref1_from_model(dim
, model
, "named-pair");
379 ref1
= adg_dim_get_ref1(dim
);
380 g_assert(adg_point_equal(ref1
, model_point
));
382 /* Using GObject property methods */
383 g_object_set(dim
, "ref1", origin
, NULL
);
384 g_object_get(dim
, "ref1", &ref1
, NULL
);
385 g_assert(adg_point_equal(ref1
, origin
));
386 adg_point_destroy(ref1
);
388 g_object_set(dim
, "ref1", NULL
, NULL
);
389 g_object_get(dim
, "ref1", &ref1
, NULL
);
390 g_assert(ref1
== NULL
);
392 g_object_set(dim
, "ref1", explicit_point
, NULL
);
393 g_object_get(dim
, "ref1", &ref1
, NULL
);
394 g_assert(adg_point_equal(ref1
, explicit_point
));
395 adg_point_destroy(ref1
);
397 adg_dim_set_ref1_from_model(dim
, model
, "dummy");
398 g_object_get(dim
, "ref1", &ref1
, NULL
);
399 g_assert(ref1
!= NULL
);
400 adg_point_destroy(ref1
);
402 g_object_set(dim
, "ref1", model_point
, NULL
);
403 g_object_get(dim
, "ref1", &ref1
, NULL
);
404 g_assert(adg_point_equal(ref1
, model_point
));
405 adg_point_destroy(ref1
);
407 adg_point_destroy(origin
);
408 adg_point_destroy(explicit_point
);
409 adg_point_destroy(model_point
);
410 adg_entity_destroy(ADG_ENTITY(dim
));
411 g_object_unref(model
);
419 AdgPoint
*origin
, *explicit_point
, *model_point
;
422 dim
= ADG_DIM(adg_rdim_new());
423 model
= ADG_MODEL(adg_path_new());
424 origin
= adg_point_new();
425 explicit_point
= adg_point_new();
426 model_point
= adg_point_new();
428 adg_point_set_pair_explicit(origin
, 0, 0);
429 adg_point_set_pair_explicit(explicit_point
, 123, 321);
430 adg_model_set_named_pair(model
, "named-pair", (CpmlPair
*) explicit_point
);
431 adg_point_set_pair_from_model(model_point
, model
, "named-pair");
433 /* Ensure ADG does not consider an explicit point equals to
434 * a point bound to a named pair with the same coordinates */
435 g_assert(!adg_point_equal(explicit_point
, model_point
));
437 ref2
= adg_dim_get_ref2(dim
);
438 g_assert(ref2
== NULL
);
440 /* Using the public APIs */
441 adg_dim_set_ref2_explicit(dim
, 0, 0);
442 ref2
= adg_dim_get_ref2(dim
);
443 g_assert(adg_point_equal(ref2
, origin
));
445 adg_dim_set_ref2(dim
, NULL
);
446 ref2
= adg_dim_get_ref2(dim
);
447 g_assert(ref2
== NULL
);
449 adg_dim_set_ref2(dim
, explicit_point
);
450 ref2
= adg_dim_get_ref2(dim
);
451 g_assert(adg_point_equal(ref2
, explicit_point
));
453 adg_dim_set_ref2_from_model(dim
, model
, "dummy");
454 ref2
= adg_dim_get_ref2(dim
);
455 g_assert(ref2
!= NULL
);
457 adg_dim_set_ref2_from_model(dim
, model
, "named-pair");
458 ref2
= adg_dim_get_ref2(dim
);
459 g_assert(adg_point_equal(ref2
, model_point
));
461 /* Using GObject property methods */
462 g_object_set(dim
, "ref2", origin
, NULL
);
463 g_object_get(dim
, "ref2", &ref2
, NULL
);
464 g_assert(adg_point_equal(ref2
, origin
));
465 adg_point_destroy(ref2
);
467 g_object_set(dim
, "ref2", NULL
, NULL
);
468 g_object_get(dim
, "ref2", &ref2
, NULL
);
469 g_assert(ref2
== NULL
);
471 g_object_set(dim
, "ref2", explicit_point
, NULL
);
472 g_object_get(dim
, "ref2", &ref2
, NULL
);
473 g_assert(adg_point_equal(ref2
, explicit_point
));
474 adg_point_destroy(ref2
);
476 adg_dim_set_ref2_from_model(dim
, model
, "dummy");
477 g_object_get(dim
, "ref2", &ref2
, NULL
);
478 g_assert(ref2
!= NULL
);
479 adg_point_destroy(ref2
);
481 g_object_set(dim
, "ref2", model_point
, NULL
);
482 g_object_get(dim
, "ref2", &ref2
, NULL
);
483 g_assert(adg_point_equal(ref2
, model_point
));
484 adg_point_destroy(ref2
);
486 adg_point_destroy(origin
);
487 adg_point_destroy(explicit_point
);
488 adg_point_destroy(model_point
);
489 adg_entity_destroy(ADG_ENTITY(dim
));
490 g_object_unref(model
);
494 _adg_test_value(void)
497 const gchar
*valid_text
, *latin1_text
;
501 dim
= ADG_DIM(adg_ldim_new());
502 valid_text
= "This is some text...";
503 latin1_text
= "This is some àèìòù Latin1 text...";
505 /* Using the public APIs */
506 adg_dim_set_value(dim
, valid_text
);
507 value
= adg_dim_get_value(dim
);
508 g_assert_cmpstr(value
, ==, valid_text
);
510 adg_dim_set_value(dim
, latin1_text
);
511 value
= adg_dim_get_value(dim
);
512 g_assert_cmpstr(value
, ==, latin1_text
);
514 adg_dim_set_value(dim
, NULL
);
515 value
= adg_dim_get_value(dim
);
516 g_assert(value
== NULL
);
518 /* Using GObject property methods */
519 g_object_set(dim
, "value", valid_text
, NULL
);
520 g_object_get(dim
, "value", &value_dup
, NULL
);
521 g_assert_cmpstr(value_dup
, ==, valid_text
);
524 g_object_set(dim
, "value", latin1_text
, NULL
);
525 g_object_get(dim
, "value", &value_dup
, NULL
);
526 g_assert_cmpstr(value_dup
, ==, latin1_text
);
529 g_object_set(dim
, "value", NULL
, NULL
);
530 g_object_get(dim
, "value", &value_dup
, NULL
);
531 g_assert(value_dup
== NULL
);
533 adg_entity_destroy(ADG_ENTITY(dim
));
538 main(int argc
, char *argv
[])
540 adg_test_init(&argc
, &argv
);
542 adg_test_add_func("/adg/dim/detached", _adg_test_detached
);
543 adg_test_add_func("/adg/dim/dim-dress", _adg_test_dim_dress
);
544 adg_test_add_func("/adg/dim/level", _adg_test_level
);
545 adg_test_add_func("/adg/dim/max", _adg_test_max
);
546 adg_test_add_func("/adg/dim/min", _adg_test_min
);
547 adg_test_add_func("/adg/dim/outside", _adg_test_outside
);
548 adg_test_add_func("/adg/dim/pos", _adg_test_pos
);
549 adg_test_add_func("/adg/dim/ref1", _adg_test_ref1
);
550 adg_test_add_func("/adg/dim/ref2", _adg_test_ref2
);
551 adg_test_add_func("/adg/dim/value", _adg_test_value
);