1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2010,2011 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",
273 adg_point_get_pair(explicit_point
));
274 adg_point_set_pair_from_model(model_point
, model
, "named-pair");
276 /* Ensure ADG does not consider an explicit point equals to
277 * a point bound to a named pair with the same coordinates */
278 g_assert(!adg_point_equal(explicit_point
, model_point
));
280 pos
= adg_dim_get_pos(dim
);
281 g_assert(pos
== NULL
);
283 /* Using the public APIs */
284 adg_dim_set_pos_explicit(dim
, 0, 0);
285 pos
= adg_dim_get_pos(dim
);
286 g_assert(adg_point_equal(pos
, origin
));
288 adg_dim_set_pos(dim
, NULL
);
289 pos
= adg_dim_get_pos(dim
);
290 g_assert(pos
== NULL
);
292 adg_dim_set_pos(dim
, explicit_point
);
293 pos
= adg_dim_get_pos(dim
);
294 g_assert(adg_point_equal(pos
, explicit_point
));
296 /* Checking the lazy assignment feature */
297 adg_dim_set_pos_from_model(dim
, model
, "dummy");
298 pos
= adg_dim_get_pos(dim
);
299 g_assert(pos
!= NULL
);
300 g_assert(adg_point_get_pair(pos
) == NULL
);
302 adg_dim_set_pos_from_model(dim
, model
, "named-pair");
303 pos
= adg_dim_get_pos(dim
);
304 g_assert(adg_point_equal(pos
, model_point
));
306 /* Using GObject property methods */
307 g_object_set(dim
, "pos", origin
, NULL
);
308 g_object_get(dim
, "pos", &pos
, NULL
);
309 g_assert(adg_point_equal(pos
, origin
));
310 adg_point_destroy(pos
);
312 g_object_set(dim
, "pos", NULL
, NULL
);
313 g_object_get(dim
, "pos", &pos
, NULL
);
314 g_assert(pos
== NULL
);
316 g_object_set(dim
, "pos", explicit_point
, NULL
);
317 g_object_get(dim
, "pos", &pos
, NULL
);
318 g_assert(adg_point_equal(pos
, explicit_point
));
319 adg_point_destroy(pos
);
321 /* Checking the lazy assignment feature */
322 adg_dim_set_pos_from_model(dim
, model
, "dummy");
323 g_object_get(dim
, "pos", &pos
, NULL
);
324 g_assert(pos
!= NULL
);
325 g_assert(adg_point_get_pair(pos
) == NULL
);
326 adg_point_destroy(pos
);
328 g_object_set(dim
, "pos", model_point
, NULL
);
329 g_object_get(dim
, "pos", &pos
, NULL
);
330 g_assert(adg_point_equal(pos
, model_point
));
331 adg_point_destroy(pos
);
333 adg_point_destroy(origin
);
334 adg_point_destroy(explicit_point
);
335 adg_point_destroy(model_point
);
336 adg_entity_destroy(ADG_ENTITY(dim
));
337 g_object_unref(model
);
345 AdgPoint
*origin
, *explicit_point
, *model_point
;
348 dim
= ADG_DIM(adg_rdim_new());
349 model
= ADG_MODEL(adg_path_new());
350 origin
= adg_point_new();
351 explicit_point
= adg_point_new();
352 model_point
= adg_point_new();
354 adg_point_set_pair_explicit(origin
, 0, 0);
355 adg_point_set_pair_explicit(explicit_point
, 123, 321);
356 adg_model_set_named_pair(model
, "named-pair",
357 adg_point_get_pair(explicit_point
));
358 adg_point_set_pair_from_model(model_point
, model
, "named-pair");
360 /* Ensure ADG does not consider an explicit point equals to
361 * a point bound to a named pair with the same coordinates */
362 g_assert(!adg_point_equal(explicit_point
, model_point
));
364 ref1
= adg_dim_get_ref1(dim
);
365 g_assert(ref1
== NULL
);
367 /* Using the public APIs */
368 adg_dim_set_ref1_explicit(dim
, 0, 0);
369 ref1
= adg_dim_get_ref1(dim
);
370 g_assert(adg_point_equal(ref1
, origin
));
372 adg_dim_set_ref1(dim
, NULL
);
373 ref1
= adg_dim_get_ref1(dim
);
374 g_assert(ref1
== NULL
);
376 adg_dim_set_ref1(dim
, explicit_point
);
377 ref1
= adg_dim_get_ref1(dim
);
378 g_assert(adg_point_equal(ref1
, explicit_point
));
380 /* Checking the lazy assignment feature */
381 adg_dim_set_ref1_from_model(dim
, model
, "dummy");
382 ref1
= adg_dim_get_ref1(dim
);
383 g_assert(ref1
!= NULL
);
384 g_assert(adg_point_get_pair(ref1
) == NULL
);
386 adg_dim_set_ref1_from_model(dim
, model
, "named-pair");
387 ref1
= adg_dim_get_ref1(dim
);
388 g_assert(adg_point_equal(ref1
, model_point
));
390 /* Using GObject property methods */
391 g_object_set(dim
, "ref1", origin
, NULL
);
392 g_object_get(dim
, "ref1", &ref1
, NULL
);
393 g_assert(adg_point_equal(ref1
, origin
));
394 adg_point_destroy(ref1
);
396 g_object_set(dim
, "ref1", NULL
, NULL
);
397 g_object_get(dim
, "ref1", &ref1
, NULL
);
398 g_assert(ref1
== NULL
);
400 g_object_set(dim
, "ref1", explicit_point
, NULL
);
401 g_object_get(dim
, "ref1", &ref1
, NULL
);
402 g_assert(adg_point_equal(ref1
, explicit_point
));
403 adg_point_destroy(ref1
);
405 /* Checking the lazy assignment feature */
406 adg_dim_set_ref1_from_model(dim
, model
, "dummy");
407 g_object_get(dim
, "ref1", &ref1
, NULL
);
408 g_assert(ref1
!= NULL
);
409 g_assert(adg_point_get_pair(ref1
) == NULL
);
410 adg_point_destroy(ref1
);
412 g_object_set(dim
, "ref1", model_point
, NULL
);
413 g_object_get(dim
, "ref1", &ref1
, NULL
);
414 g_assert(adg_point_equal(ref1
, model_point
));
415 adg_point_destroy(ref1
);
417 adg_point_destroy(origin
);
418 adg_point_destroy(explicit_point
);
419 adg_point_destroy(model_point
);
420 adg_entity_destroy(ADG_ENTITY(dim
));
421 g_object_unref(model
);
429 AdgPoint
*origin
, *explicit_point
, *model_point
;
432 dim
= ADG_DIM(adg_rdim_new());
433 model
= ADG_MODEL(adg_path_new());
434 origin
= adg_point_new();
435 explicit_point
= adg_point_new();
436 model_point
= adg_point_new();
438 adg_point_set_pair_explicit(origin
, 0, 0);
439 adg_point_set_pair_explicit(explicit_point
, 123, 321);
440 adg_model_set_named_pair(model
, "named-pair",
441 adg_point_get_pair(explicit_point
));
442 adg_point_set_pair_from_model(model_point
, model
, "named-pair");
444 /* Ensure ADG does not consider an explicit point equals to
445 * a point bound to a named pair with the same coordinates */
446 g_assert(!adg_point_equal(explicit_point
, model_point
));
448 ref2
= adg_dim_get_ref2(dim
);
449 g_assert(ref2
== NULL
);
451 /* Using the public APIs */
452 adg_dim_set_ref2_explicit(dim
, 0, 0);
453 ref2
= adg_dim_get_ref2(dim
);
454 g_assert(adg_point_equal(ref2
, origin
));
456 adg_dim_set_ref2(dim
, NULL
);
457 ref2
= adg_dim_get_ref2(dim
);
458 g_assert(ref2
== NULL
);
460 adg_dim_set_ref2(dim
, explicit_point
);
461 ref2
= adg_dim_get_ref2(dim
);
462 g_assert(adg_point_equal(ref2
, explicit_point
));
464 /* Checking the lazy assignment feature */
465 adg_dim_set_ref2_from_model(dim
, model
, "dummy");
466 ref2
= adg_dim_get_ref2(dim
);
467 g_assert(ref2
!= NULL
);
468 g_assert(adg_point_get_pair(ref2
) == NULL
);
470 adg_dim_set_ref2_from_model(dim
, model
, "named-pair");
471 ref2
= adg_dim_get_ref2(dim
);
472 g_assert(adg_point_equal(ref2
, model_point
));
474 /* Using GObject property methods */
475 g_object_set(dim
, "ref2", origin
, NULL
);
476 g_object_get(dim
, "ref2", &ref2
, NULL
);
477 g_assert(adg_point_equal(ref2
, origin
));
478 adg_point_destroy(ref2
);
480 g_object_set(dim
, "ref2", NULL
, NULL
);
481 g_object_get(dim
, "ref2", &ref2
, NULL
);
482 g_assert(ref2
== NULL
);
484 g_object_set(dim
, "ref2", explicit_point
, NULL
);
485 g_object_get(dim
, "ref2", &ref2
, NULL
);
486 g_assert(adg_point_equal(ref2
, explicit_point
));
487 adg_point_destroy(ref2
);
489 /* Checking the lazy assignment feature */
490 adg_dim_set_ref2_from_model(dim
, model
, "dummy");
491 g_object_get(dim
, "ref2", &ref2
, NULL
);
492 g_assert(ref2
!= NULL
);
493 g_assert(adg_point_get_pair(ref2
) == NULL
);
494 adg_point_destroy(ref2
);
496 g_object_set(dim
, "ref2", model_point
, NULL
);
497 g_object_get(dim
, "ref2", &ref2
, NULL
);
498 g_assert(adg_point_equal(ref2
, model_point
));
499 adg_point_destroy(ref2
);
501 adg_point_destroy(origin
);
502 adg_point_destroy(explicit_point
);
503 adg_point_destroy(model_point
);
504 adg_entity_destroy(ADG_ENTITY(dim
));
505 g_object_unref(model
);
509 _adg_test_value(void)
512 const gchar
*valid_text
, *latin1_text
;
516 dim
= ADG_DIM(adg_ldim_new());
517 valid_text
= "This is some text...";
518 latin1_text
= "This is some àèìòù Latin1 text...";
520 /* Using the public APIs */
521 adg_dim_set_value(dim
, valid_text
);
522 value
= adg_dim_get_value(dim
);
523 g_assert_cmpstr(value
, ==, valid_text
);
525 adg_dim_set_value(dim
, latin1_text
);
526 value
= adg_dim_get_value(dim
);
527 g_assert_cmpstr(value
, ==, latin1_text
);
529 adg_dim_set_value(dim
, NULL
);
530 value
= adg_dim_get_value(dim
);
531 g_assert(value
== NULL
);
533 /* Using GObject property methods */
534 g_object_set(dim
, "value", valid_text
, NULL
);
535 g_object_get(dim
, "value", &value_dup
, NULL
);
536 g_assert_cmpstr(value_dup
, ==, valid_text
);
539 g_object_set(dim
, "value", latin1_text
, NULL
);
540 g_object_get(dim
, "value", &value_dup
, NULL
);
541 g_assert_cmpstr(value_dup
, ==, latin1_text
);
544 g_object_set(dim
, "value", NULL
, NULL
);
545 g_object_get(dim
, "value", &value_dup
, NULL
);
546 g_assert(value_dup
== NULL
);
548 adg_entity_destroy(ADG_ENTITY(dim
));
553 main(int argc
, char *argv
[])
555 adg_test_init(&argc
, &argv
);
557 adg_test_add_func("/adg/dim/detached", _adg_test_detached
);
558 adg_test_add_func("/adg/dim/dim-dress", _adg_test_dim_dress
);
559 adg_test_add_func("/adg/dim/level", _adg_test_level
);
560 adg_test_add_func("/adg/dim/max", _adg_test_max
);
561 adg_test_add_func("/adg/dim/min", _adg_test_min
);
562 adg_test_add_func("/adg/dim/outside", _adg_test_outside
);
563 adg_test_add_func("/adg/dim/pos", _adg_test_pos
);
564 adg_test_add_func("/adg/dim/ref1", _adg_test_ref1
);
565 adg_test_add_func("/adg/dim/ref2", _adg_test_ref2
);
566 adg_test_add_func("/adg/dim/value", _adg_test_value
);