1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2017 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.
27 _adg_behavior_geometry(void)
29 AdgDim
*dim
= ADG_DIM(adg_ldim_new());
32 g_assert_false(adg_dim_has_geometry(NULL
));
33 adg_dim_switch_geometry(NULL
, FALSE
);
34 g_assert_null(adg_dim_get_geometry_notice(NULL
));
35 adg_dim_set_geometry_notice(NULL
, NULL
);
36 g_assert_false(adg_dim_compute_geometry(NULL
));
38 /* Check geometry computed flag */
39 g_assert_false(adg_dim_has_geometry(dim
));
40 adg_dim_switch_geometry(dim
, TRUE
);
41 g_assert_true(adg_dim_has_geometry(dim
));
42 adg_dim_switch_geometry(dim
, FALSE
);
43 g_assert_false(adg_dim_has_geometry(dim
));
45 /* Check geometry notice */
46 g_assert_null(adg_dim_get_geometry_notice(dim
));
47 adg_dim_set_geometry_notice(dim
, "test");
48 g_assert_nonnull(adg_dim_get_geometry_notice(dim
));
49 g_assert_cmpstr(adg_dim_get_geometry_notice(dim
), ==, "test");
50 adg_dim_set_geometry_notice(dim
, NULL
);
51 g_assert_null(adg_dim_get_geometry_notice(dim
));
53 /* Check that compute-geometry call is cached */
54 g_assert_false(adg_dim_compute_geometry(dim
));
55 adg_dim_switch_geometry(dim
, TRUE
);
56 g_assert_true(adg_dim_compute_geometry(dim
));
58 adg_entity_destroy(ADG_ENTITY(dim
));
62 _adg_property_detached(void)
65 AdgThreeState valid_three_state_1
, valid_three_state_2
, invalid_three_state
;
66 AdgThreeState detached
;
68 dim
= ADG_DIM(adg_ldim_new());
69 valid_three_state_1
= ADG_THREE_STATE_UNKNOWN
;
70 valid_three_state_2
= ADG_THREE_STATE_OFF
;
71 invalid_three_state
= 1234;
73 /* Using the public APIs */
74 adg_dim_set_detached(dim
, valid_three_state_1
);
75 detached
= adg_dim_get_detached(dim
);
76 g_assert_cmpint(detached
, ==, valid_three_state_1
);
78 adg_dim_set_detached(dim
, invalid_three_state
);
79 detached
= adg_dim_get_detached(dim
);
80 g_assert_cmpint(detached
, ==, valid_three_state_1
);
82 adg_dim_set_detached(dim
, valid_three_state_2
);
83 detached
= adg_dim_get_detached(dim
);
84 g_assert_cmpint(detached
, ==, valid_three_state_2
);
86 /* Using GObject property methods */
87 g_object_set(dim
, "detached", valid_three_state_1
, NULL
);
88 g_object_get(dim
, "detached", &detached
, NULL
);
89 g_assert_cmpint(detached
, ==, valid_three_state_1
);
91 g_object_set(dim
, "detached", invalid_three_state
, NULL
);
92 g_object_get(dim
, "detached", &detached
, NULL
);
93 g_assert_cmpint(detached
, ==, valid_three_state_1
);
95 g_object_set(dim
, "detached", valid_three_state_2
, NULL
);
96 g_object_get(dim
, "detached", &detached
, NULL
);
97 g_assert_cmpint(detached
, ==, valid_three_state_2
);
99 adg_entity_destroy(ADG_ENTITY(dim
));
103 _adg_property_dim_dress(void)
106 AdgDress valid_dress
, incompatible_dress
;
109 dim
= ADG_DIM(adg_ldim_new());
110 valid_dress
= ADG_DRESS_DIMENSION
;
111 incompatible_dress
= ADG_DRESS_LINE
;
113 /* Using the public APIs */
114 adg_dim_set_dim_dress(dim
, valid_dress
);
115 dim_dress
= adg_dim_get_dim_dress(dim
);
116 g_assert_cmpint(dim_dress
, ==, valid_dress
);
118 adg_dim_set_dim_dress(dim
, incompatible_dress
);
119 dim_dress
= adg_dim_get_dim_dress(dim
);
120 g_assert_cmpint(dim_dress
, ==, valid_dress
);
122 /* Using GObject property methods */
123 g_object_set(dim
, "dim-dress", valid_dress
, NULL
);
124 g_object_get(dim
, "dim-dress", &dim_dress
, NULL
);
125 g_assert_cmpint(dim_dress
, ==, valid_dress
);
127 g_object_set(dim
, "dim-dress", incompatible_dress
, NULL
);
128 g_object_get(dim
, "dim-dress", &dim_dress
, NULL
);
129 g_assert_cmpint(dim_dress
, ==, valid_dress
);
131 adg_entity_destroy(ADG_ENTITY(dim
));
135 _adg_property_level(void)
138 gdouble valid_value_1
, valid_value_2
;
141 dim
= ADG_DIM(adg_ldim_new());
142 valid_value_1
= 4321;
143 valid_value_2
= 1234;
145 /* Using the public APIs */
146 adg_dim_set_level(dim
, valid_value_1
);
147 level
= adg_dim_get_level(dim
);
148 adg_assert_isapprox(level
, valid_value_1
);
150 adg_dim_set_level(dim
, valid_value_2
);
151 level
= adg_dim_get_level(dim
);
152 adg_assert_isapprox(level
, valid_value_2
);
154 /* Using GObject property methods */
155 g_object_set(dim
, "level", valid_value_1
, NULL
);
156 g_object_get(dim
, "level", &level
, NULL
);
157 adg_assert_isapprox(level
, valid_value_1
);
159 g_object_set(dim
, "level", valid_value_2
, NULL
);
160 g_object_get(dim
, "level", &level
, NULL
);
161 adg_assert_isapprox(level
, valid_value_2
);
163 adg_entity_destroy(ADG_ENTITY(dim
));
167 _adg_property_max(void)
170 const gchar
*valid_text
, *latin1_text
;
174 dim
= ADG_DIM(adg_ldim_new());
175 valid_text
= "This is some text...";
176 latin1_text
= "This is some àèìòù Latin1 text...";
178 /* Using the public APIs */
179 adg_dim_set_max(dim
, valid_text
);
180 max
= adg_dim_get_max(dim
);
181 g_assert_cmpstr(max
, ==, valid_text
);
183 adg_dim_set_max(dim
, latin1_text
);
184 max
= adg_dim_get_max(dim
);
185 g_assert_cmpstr(max
, ==, latin1_text
);
187 adg_dim_set_max(dim
, NULL
);
188 max
= adg_dim_get_max(dim
);
191 /* Using GObject property methods */
192 g_object_set(dim
, "max", valid_text
, NULL
);
193 g_object_get(dim
, "max", &max_dup
, NULL
);
194 g_assert_cmpstr(max_dup
, ==, valid_text
);
197 g_object_set(dim
, "max", latin1_text
, NULL
);
198 g_object_get(dim
, "max", &max_dup
, NULL
);
199 g_assert_cmpstr(max_dup
, ==, latin1_text
);
202 g_object_set(dim
, "max", NULL
, NULL
);
203 g_object_get(dim
, "max", &max_dup
, NULL
);
204 g_assert_null(max_dup
);
206 adg_entity_destroy(ADG_ENTITY(dim
));
210 _adg_property_min(void)
213 const gchar
*valid_text
, *latin1_text
;
217 dim
= ADG_DIM(adg_ldim_new());
218 valid_text
= "This is some text...";
219 latin1_text
= "This is some àèìòù Latin1 text...";
221 /* Using the public APIs */
222 adg_dim_set_min(dim
, valid_text
);
223 min
= adg_dim_get_min(dim
);
224 g_assert_cmpstr(min
, ==, valid_text
);
226 adg_dim_set_min(dim
, latin1_text
);
227 min
= adg_dim_get_min(dim
);
228 g_assert_cmpstr(min
, ==, latin1_text
);
230 adg_dim_set_min(dim
, NULL
);
231 min
= adg_dim_get_min(dim
);
234 /* Using GObject property methods */
235 g_object_set(dim
, "min", valid_text
, NULL
);
236 g_object_get(dim
, "min", &min_dup
, NULL
);
237 g_assert_cmpstr(min_dup
, ==, valid_text
);
240 g_object_set(dim
, "min", latin1_text
, NULL
);
241 g_object_get(dim
, "min", &min_dup
, NULL
);
242 g_assert_cmpstr(min_dup
, ==, latin1_text
);
245 g_object_set(dim
, "min", NULL
, NULL
);
246 g_object_get(dim
, "min", &min_dup
, NULL
);
247 g_assert_null(min_dup
);
249 adg_entity_destroy(ADG_ENTITY(dim
));
253 _adg_property_outside(void)
256 AdgThreeState valid_three_state_1
, valid_three_state_2
, invalid_three_state
;
257 AdgThreeState outside
;
259 dim
= ADG_DIM(adg_rdim_new());
260 valid_three_state_1
= ADG_THREE_STATE_UNKNOWN
;
261 valid_three_state_2
= ADG_THREE_STATE_OFF
;
262 invalid_three_state
= 1234;
264 /* Using the public APIs */
265 adg_dim_set_outside(dim
, valid_three_state_1
);
266 outside
= adg_dim_get_outside(dim
);
267 g_assert_cmpint(outside
, ==, valid_three_state_1
);
269 adg_dim_set_outside(dim
, invalid_three_state
);
270 outside
= adg_dim_get_outside(dim
);
271 g_assert_cmpint(outside
, ==, valid_three_state_1
);
273 adg_dim_set_outside(dim
, valid_three_state_2
);
274 outside
= adg_dim_get_outside(dim
);
275 g_assert_cmpint(outside
, ==, valid_three_state_2
);
277 /* Using GObject property methods */
278 g_object_set(dim
, "outside", valid_three_state_1
, NULL
);
279 g_object_get(dim
, "outside", &outside
, NULL
);
280 g_assert_cmpint(outside
, ==, valid_three_state_1
);
282 g_object_set(dim
, "outside", invalid_three_state
, NULL
);
283 g_object_get(dim
, "outside", &outside
, NULL
);
284 g_assert_cmpint(outside
, ==, valid_three_state_1
);
286 g_object_set(dim
, "outside", valid_three_state_2
, NULL
);
287 g_object_get(dim
, "outside", &outside
, NULL
);
288 g_assert_cmpint(outside
, ==, valid_three_state_2
);
290 adg_entity_destroy(ADG_ENTITY(dim
));
294 _adg_property_pos(void)
298 AdgPoint
*origin
, *explicit_point
, *model_point
;
301 dim
= ADG_DIM(adg_rdim_new());
302 model
= ADG_MODEL(adg_path_new());
303 origin
= adg_point_new();
304 explicit_point
= adg_point_new();
305 model_point
= adg_point_new();
307 adg_point_set_pair_explicit(origin
, 0, 0);
308 adg_point_set_pair_explicit(explicit_point
, 123, 321);
309 adg_model_set_named_pair(model
, "named-pair", (CpmlPair
*) explicit_point
);
310 adg_point_set_pair_from_model(model_point
, model
, "named-pair");
312 /* Ensure ADG does not consider an explicit point equals to
313 * a point bound to a named pair with the same coordinates */
314 g_assert_false(adg_point_equal(explicit_point
, model_point
));
316 pos
= adg_dim_get_pos(dim
);
319 /* Using the public APIs */
320 adg_dim_set_pos_explicit(dim
, 0, 0);
321 pos
= adg_dim_get_pos(dim
);
322 g_assert_true(adg_point_equal(pos
, origin
));
324 adg_dim_set_pos(dim
, NULL
);
325 pos
= adg_dim_get_pos(dim
);
328 adg_dim_set_pos(dim
, explicit_point
);
329 pos
= adg_dim_get_pos(dim
);
330 g_assert_true(adg_point_equal(pos
, explicit_point
));
332 adg_dim_set_pos_from_model(dim
, model
, "dummy");
333 pos
= adg_dim_get_pos(dim
);
334 g_assert_nonnull(pos
);
336 adg_dim_set_pos_from_model(dim
, model
, "named-pair");
337 pos
= adg_dim_get_pos(dim
);
338 g_assert_true(adg_point_equal(pos
, model_point
));
340 /* Using GObject property methods */
341 g_object_set(dim
, "pos", origin
, NULL
);
342 g_object_get(dim
, "pos", &pos
, NULL
);
343 g_assert_true(adg_point_equal(pos
, origin
));
344 adg_point_destroy(pos
);
346 g_object_set(dim
, "pos", NULL
, NULL
);
347 g_object_get(dim
, "pos", &pos
, NULL
);
350 g_object_set(dim
, "pos", explicit_point
, NULL
);
351 g_object_get(dim
, "pos", &pos
, NULL
);
352 g_assert_true(adg_point_equal(pos
, explicit_point
));
353 adg_point_destroy(pos
);
355 adg_dim_set_pos_from_model(dim
, model
, "dummy");
356 g_object_get(dim
, "pos", &pos
, NULL
);
357 g_assert_nonnull(pos
);
358 adg_point_destroy(pos
);
360 g_object_set(dim
, "pos", model_point
, NULL
);
361 g_object_get(dim
, "pos", &pos
, NULL
);
362 g_assert_true(adg_point_equal(pos
, model_point
));
363 adg_point_destroy(pos
);
365 adg_point_destroy(origin
);
366 adg_point_destroy(explicit_point
);
367 adg_point_destroy(model_point
);
368 adg_entity_destroy(ADG_ENTITY(dim
));
369 g_object_unref(model
);
373 _adg_property_ref1(void)
377 AdgPoint
*origin
, *explicit_point
, *model_point
;
380 dim
= ADG_DIM(adg_rdim_new());
381 model
= ADG_MODEL(adg_path_new());
382 origin
= adg_point_new();
383 explicit_point
= adg_point_new();
384 model_point
= adg_point_new();
386 adg_point_set_pair_explicit(origin
, 0, 0);
387 adg_point_set_pair_explicit(explicit_point
, 123, 321);
388 adg_model_set_named_pair(model
, "named-pair", (CpmlPair
*) explicit_point
);
389 adg_point_set_pair_from_model(model_point
, model
, "named-pair");
391 /* Ensure ADG does not consider an explicit point equals to
392 * a point bound to a named pair with the same coordinates */
393 g_assert_false(adg_point_equal(explicit_point
, model_point
));
395 ref1
= adg_dim_get_ref1(dim
);
398 /* Using the public APIs */
399 adg_dim_set_ref1_explicit(dim
, 0, 0);
400 ref1
= adg_dim_get_ref1(dim
);
401 g_assert_true(adg_point_equal(ref1
, origin
));
403 adg_dim_set_ref1(dim
, NULL
);
404 ref1
= adg_dim_get_ref1(dim
);
407 adg_dim_set_ref1(dim
, explicit_point
);
408 ref1
= adg_dim_get_ref1(dim
);
409 g_assert_true(adg_point_equal(ref1
, explicit_point
));
411 adg_dim_set_ref1_from_model(dim
, model
, "dummy");
412 ref1
= adg_dim_get_ref1(dim
);
413 g_assert_nonnull(ref1
);
415 adg_dim_set_ref1_from_model(dim
, model
, "named-pair");
416 ref1
= adg_dim_get_ref1(dim
);
417 g_assert_true(adg_point_equal(ref1
, model_point
));
419 /* Using GObject property methods */
420 g_object_set(dim
, "ref1", origin
, NULL
);
421 g_object_get(dim
, "ref1", &ref1
, NULL
);
422 g_assert_true(adg_point_equal(ref1
, origin
));
423 adg_point_destroy(ref1
);
425 g_object_set(dim
, "ref1", NULL
, NULL
);
426 g_object_get(dim
, "ref1", &ref1
, NULL
);
429 g_object_set(dim
, "ref1", explicit_point
, NULL
);
430 g_object_get(dim
, "ref1", &ref1
, NULL
);
431 g_assert_true(adg_point_equal(ref1
, explicit_point
));
432 adg_point_destroy(ref1
);
434 adg_dim_set_ref1_from_model(dim
, model
, "dummy");
435 g_object_get(dim
, "ref1", &ref1
, NULL
);
436 g_assert_nonnull(ref1
);
437 adg_point_destroy(ref1
);
439 g_object_set(dim
, "ref1", model_point
, NULL
);
440 g_object_get(dim
, "ref1", &ref1
, NULL
);
441 g_assert_true(adg_point_equal(ref1
, model_point
));
442 adg_point_destroy(ref1
);
444 adg_point_destroy(origin
);
445 adg_point_destroy(explicit_point
);
446 adg_point_destroy(model_point
);
447 adg_entity_destroy(ADG_ENTITY(dim
));
448 g_object_unref(model
);
452 _adg_property_ref2(void)
456 AdgPoint
*origin
, *explicit_point
, *model_point
;
459 dim
= ADG_DIM(adg_rdim_new());
460 model
= ADG_MODEL(adg_path_new());
461 origin
= adg_point_new();
462 explicit_point
= adg_point_new();
463 model_point
= adg_point_new();
465 adg_point_set_pair_explicit(origin
, 0, 0);
466 adg_point_set_pair_explicit(explicit_point
, 123, 321);
467 adg_model_set_named_pair(model
, "named-pair", (CpmlPair
*) explicit_point
);
468 adg_point_set_pair_from_model(model_point
, model
, "named-pair");
470 /* Ensure ADG does not consider an explicit point equals to
471 * a point bound to a named pair with the same coordinates */
472 g_assert_false(adg_point_equal(explicit_point
, model_point
));
474 ref2
= adg_dim_get_ref2(dim
);
477 /* Using the public APIs */
478 adg_dim_set_ref2_explicit(dim
, 0, 0);
479 ref2
= adg_dim_get_ref2(dim
);
480 g_assert_true(adg_point_equal(ref2
, origin
));
482 adg_dim_set_ref2(dim
, NULL
);
483 ref2
= adg_dim_get_ref2(dim
);
486 adg_dim_set_ref2(dim
, explicit_point
);
487 ref2
= adg_dim_get_ref2(dim
);
488 g_assert_true(adg_point_equal(ref2
, explicit_point
));
490 adg_dim_set_ref2_from_model(dim
, model
, "dummy");
491 ref2
= adg_dim_get_ref2(dim
);
492 g_assert_nonnull(ref2
);
494 adg_dim_set_ref2_from_model(dim
, model
, "named-pair");
495 ref2
= adg_dim_get_ref2(dim
);
496 g_assert_true(adg_point_equal(ref2
, model_point
));
498 /* Using GObject property methods */
499 g_object_set(dim
, "ref2", origin
, NULL
);
500 g_object_get(dim
, "ref2", &ref2
, NULL
);
501 g_assert_true(adg_point_equal(ref2
, origin
));
502 adg_point_destroy(ref2
);
504 g_object_set(dim
, "ref2", NULL
, NULL
);
505 g_object_get(dim
, "ref2", &ref2
, NULL
);
508 g_object_set(dim
, "ref2", explicit_point
, NULL
);
509 g_object_get(dim
, "ref2", &ref2
, NULL
);
510 g_assert_true(adg_point_equal(ref2
, explicit_point
));
511 adg_point_destroy(ref2
);
513 adg_dim_set_ref2_from_model(dim
, model
, "dummy");
514 g_object_get(dim
, "ref2", &ref2
, NULL
);
515 g_assert_nonnull(ref2
);
516 adg_point_destroy(ref2
);
518 g_object_set(dim
, "ref2", model_point
, NULL
);
519 g_object_get(dim
, "ref2", &ref2
, NULL
);
520 g_assert_true(adg_point_equal(ref2
, model_point
));
521 adg_point_destroy(ref2
);
523 adg_point_destroy(origin
);
524 adg_point_destroy(explicit_point
);
525 adg_point_destroy(model_point
);
526 adg_entity_destroy(ADG_ENTITY(dim
));
527 g_object_unref(model
);
531 _adg_property_value(void)
534 const gchar
*valid_text
, *latin1_text
;
538 dim
= ADG_DIM(adg_ldim_new());
539 valid_text
= "This is some text...";
540 latin1_text
= "This is some àèìòù Latin1 text...";
542 /* Using the public APIs */
543 adg_dim_set_value(dim
, valid_text
);
544 value
= adg_dim_get_value(dim
);
545 g_assert_cmpstr(value
, ==, valid_text
);
547 adg_dim_set_value(dim
, latin1_text
);
548 value
= adg_dim_get_value(dim
);
549 g_assert_cmpstr(value
, ==, latin1_text
);
551 adg_dim_set_value(dim
, NULL
);
552 value
= adg_dim_get_value(dim
);
553 g_assert_null(value
);
555 /* Using GObject property methods */
556 g_object_set(dim
, "value", valid_text
, NULL
);
557 g_object_get(dim
, "value", &value_dup
, NULL
);
558 g_assert_cmpstr(value_dup
, ==, valid_text
);
561 g_object_set(dim
, "value", latin1_text
, NULL
);
562 g_object_get(dim
, "value", &value_dup
, NULL
);
563 g_assert_cmpstr(value_dup
, ==, latin1_text
);
566 g_object_set(dim
, "value", NULL
, NULL
);
567 g_object_get(dim
, "value", &value_dup
, NULL
);
568 g_assert_null(value_dup
);
570 adg_entity_destroy(ADG_ENTITY(dim
));
574 _adg_method_get_text(void)
577 AdgDimStyle
*dim_style
;
580 dim
= ADG_DIM(adg_ldim_new());
581 dim_style
= ADG_DIM_STYLE(adg_entity_style(ADG_ENTITY(dim
), ADG_DRESS_DIMENSION
));
583 /* Checking predefined dresses */
585 /* Default dress: ADG_DRESS_DIMENSION */
586 text
= adg_dim_get_text(dim
, 7.891);
587 g_assert_cmpstr(text
, ==, "7.89");
590 /* Restore the default dress */
591 adg_dim_set_dim_dress(dim
, ADG_DRESS_DIMENSION
);
592 text
= adg_dim_get_text(dim
, 3.456);
593 g_assert_cmpstr(text
, ==, "3.46");
596 /* Decrease the decimals */
597 adg_dim_style_set_decimals(dim_style
, 1);
598 text
= adg_dim_get_text(dim
, 7.891);
599 g_assert_cmpstr(text
, ==, "7.9");
602 /* Change the argument type */
603 adg_dim_style_set_number_arguments(dim_style
, "a");
604 text
= adg_dim_get_text(dim
, 7.891);
605 g_assert_cmpstr(text
, ==, "7.891");
608 adg_dim_style_set_number_arguments(dim_style
, "D");
609 text
= adg_dim_get_text(dim
, 7.891);
610 g_assert_cmpstr(text
, ==, "7");
613 adg_dim_style_set_number_arguments(dim_style
, "d");
614 text
= adg_dim_get_text(dim
, 7.891);
615 g_assert_cmpstr(text
, ==, "7.9");
618 /* Change the number format */
619 adg_dim_style_set_number_format(dim_style
, "%.3f");
620 text
= adg_dim_get_text(dim
, 7.891);
621 g_assert_cmpstr(text
, ==, "7.900");
624 /* Trying a complex formatting with multiple fields */
625 adg_dim_style_set_decimals(dim_style
, 2);
626 adg_dim_style_set_number_arguments(dim_style
, "aieDMSdms");
627 adg_dim_style_set_number_format(dim_style
, "%%Raw: \\(%g, %g, %g\\); Truncated: \\(%g, %g, %g\\); Rounded: \\(%g, %g, %g\\)");
628 text
= adg_dim_get_text(dim
, 7.891);
629 g_assert_cmpstr(text
, ==, "%Raw: (7.891, 53.46, 27.6); Truncated: (7, 53, 27); Rounded: (7.89, 53.46, 27.6)");
632 text
= adg_dim_get_text(dim
, 5.432);
633 g_assert_cmpstr(text
, ==, "%Raw: (5.432, 25.92, 55.2); Truncated: (5, 25, 55); Rounded: (5.43, 25.92, 55.2)");
636 /* Testing simple disappearing of unvalorized values */
637 adg_dim_style_set_number_arguments(dim_style
, "a");
638 adg_dim_style_set_number_format(dim_style
, "(%g)");
640 text
= adg_dim_get_text(dim
, 123);
641 g_assert_cmpstr(text
, ==, "123");
644 text
= adg_dim_get_text(dim
, 0);
645 g_assert_cmpstr(text
, ==, "");
648 adg_dim_style_set_number_arguments(dim_style
, "aD");
649 adg_dim_style_set_number_format(dim_style
, ">(%g)--(%g)<");
651 text
= adg_dim_get_text(dim
, 0);
652 g_assert_cmpstr(text
, ==, ">--<");
655 text
= adg_dim_get_text(dim
, 0.42);
656 g_assert_cmpstr(text
, ==, ">0.42--<");
659 text
= adg_dim_get_text(dim
, 2.34);
660 g_assert_cmpstr(text
, ==, ">2.34--2<");
663 /* Testing nested parenthesis */
664 adg_dim_style_set_number_arguments(dim_style
, "DMs");
665 adg_dim_style_set_number_format(dim_style
, "%g°(%g'(%g\"))");
667 text
= adg_dim_get_text(dim
, 0);
668 g_assert_cmpstr(text
, ==, "0°");
671 text
= adg_dim_get_text(dim
, 1.5);
672 g_assert_cmpstr(text
, ==, "1°30'");
675 text
= adg_dim_get_text(dim
, 2.002777);
676 g_assert_cmpstr(text
, ==, "2°0'10\"");
679 /* Test errors on unmatched parenthesis */
680 adg_dim_style_set_number_format(dim_style
, "%g°(%g'(%g\")");
681 g_assert_null(adg_dim_get_text(dim
, 0));
683 adg_dim_style_set_number_format(dim_style
, "%g°%g'(%g\"))");
684 g_assert_null(adg_dim_get_text(dim
, 0));
686 adg_entity_destroy(ADG_ENTITY(dim
));
690 _adg_method_set_limits(void)
694 dim
= ADG_DIM(adg_ldim_new());
697 adg_dim_set_limits(NULL
, "", "");
698 adg_dim_set_limits(dim
, NULL
, "");
699 adg_dim_set_limits(dim
, "", NULL
);
701 adg_dim_set_limits(dim
, "min", "max");
702 g_assert_cmpstr(adg_dim_get_min(dim
), ==, "min");
703 g_assert_cmpstr(adg_dim_get_max(dim
), ==, "max");
705 adg_entity_destroy(ADG_ENTITY(dim
));
709 _adg_method_geometry_missing(void)
714 dim
= ADG_DIM(adg_ldim_new());
717 adg_dim_geometry_missing(NULL
, "");
718 adg_dim_geometry_missing(dim
, NULL
);
720 /* Ensure there is no previous notice */
721 notice
= adg_dim_get_geometry_notice(dim
);
722 g_assert_null(notice
);
724 /* The results cannot be compared for equality because the message is
725 * localization dependent, so just check if the provided argument
726 * is present in the result */
727 adg_dim_geometry_missing(dim
, "test123");
728 notice
= adg_dim_get_geometry_notice(dim
);
729 g_assert_nonnull(notice
);
730 g_assert_nonnull(strstr(notice
, "test123"));
732 adg_entity_destroy(ADG_ENTITY(dim
));
736 _adg_method_geometry_coincident(void)
742 dim
= ADG_DIM(adg_ldim_new());
747 adg_dim_geometry_coincident(NULL
, "", "", &pair
);
748 adg_dim_geometry_coincident(dim
, NULL
, "", &pair
);
749 adg_dim_geometry_coincident(dim
, "", NULL
, &pair
);
750 adg_dim_geometry_coincident(dim
, "", "", NULL
);
752 /* Ensure there is no previous notice */
753 notice
= adg_dim_get_geometry_notice(dim
);
754 g_assert_null(notice
);
756 /* The results cannot be compared for equality because the message is
757 * localization dependent, so just check if the provided arguments
758 * are presents in the result */
759 adg_dim_geometry_coincident(dim
, "first", "second", &pair
);
760 notice
= adg_dim_get_geometry_notice(dim
);
761 g_assert_nonnull(notice
);
762 g_assert_nonnull(strstr(notice
, "first"));
763 g_assert_nonnull(strstr(notice
, "second"));
764 g_assert_nonnull(strstr(notice
, "1.2"));
765 g_assert_nonnull(strstr(notice
, "3.4"));
767 adg_entity_destroy(ADG_ENTITY(dim
));
772 main(int argc
, char *argv
[])
774 adg_test_init(&argc
, &argv
);
776 adg_test_add_object_checks("/adg/dim/type/object", ADG_TYPE_DIM
);
777 adg_test_add_entity_checks("/adg/dim/type/entity", ADG_TYPE_DIM
);
779 g_test_add_func("/adg/dim/behavior/geometry", _adg_behavior_geometry
);
781 g_test_add_func("/adg/dim/property/detached", _adg_property_detached
);
782 g_test_add_func("/adg/dim/property/dim-dress", _adg_property_dim_dress
);
783 g_test_add_func("/adg/dim/property/level", _adg_property_level
);
784 g_test_add_func("/adg/dim/property/max", _adg_property_max
);
785 g_test_add_func("/adg/dim/property/min", _adg_property_min
);
786 g_test_add_func("/adg/dim/property/outside", _adg_property_outside
);
787 g_test_add_func("/adg/dim/property/pos", _adg_property_pos
);
788 g_test_add_func("/adg/dim/property/ref1", _adg_property_ref1
);
789 g_test_add_func("/adg/dim/property/ref2", _adg_property_ref2
);
790 g_test_add_func("/adg/dim/property/value", _adg_property_value
);
792 g_test_add_func("/adg/dim/method/get_text", _adg_method_get_text
);
793 g_test_add_func("/adg/dim/method/set_limits", _adg_method_set_limits
);
794 g_test_add_func("/adg/dim/method/geometry_missing", _adg_method_geometry_missing
);
795 g_test_add_func("/adg/dim/method/geometry_coincident", _adg_method_geometry_coincident
);