doc: update copyright line for 2021
[adg.git] / src / adg / tests / test-dim-style.c
blob34e0ee05da5e57e4f85f6846b93700935a451140
1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007-2021 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 <adg-test.h>
22 #include <adg.h>
25 static void
26 _adg_property_baseline_spacing(void)
28 AdgDimStyle *dim_style;
29 gdouble valid_baseline_spacing_1, valid_baseline_spacing_2, invalid_baseline_spacing;
30 gdouble baseline_spacing;
32 dim_style = adg_dim_style_new();
33 valid_baseline_spacing_1 = 0;
34 valid_baseline_spacing_2 = 999;
35 invalid_baseline_spacing = -1;
37 /* Using the public APIs */
38 adg_dim_style_set_baseline_spacing(dim_style, valid_baseline_spacing_1);
39 baseline_spacing = adg_dim_style_get_baseline_spacing(dim_style);
40 adg_assert_isapprox(baseline_spacing, valid_baseline_spacing_1);
42 adg_dim_style_set_baseline_spacing(dim_style, invalid_baseline_spacing);
43 baseline_spacing = adg_dim_style_get_baseline_spacing(dim_style);
44 adg_assert_isapprox(baseline_spacing, valid_baseline_spacing_1);
46 adg_dim_style_set_baseline_spacing(dim_style, valid_baseline_spacing_2);
47 baseline_spacing = adg_dim_style_get_baseline_spacing(dim_style);
48 adg_assert_isapprox(baseline_spacing, valid_baseline_spacing_2);
50 /* Using GObject property methods */
51 g_object_set(dim_style, "baseline-spacing", valid_baseline_spacing_1, NULL);
52 g_object_get(dim_style, "baseline-spacing", &baseline_spacing, NULL);
53 adg_assert_isapprox(baseline_spacing, valid_baseline_spacing_1);
55 g_object_set(dim_style, "baseline-spacing", invalid_baseline_spacing, NULL);
56 g_object_get(dim_style, "baseline-spacing", &baseline_spacing, NULL);
57 adg_assert_isapprox(baseline_spacing, valid_baseline_spacing_1);
59 g_object_set(dim_style, "baseline-spacing", valid_baseline_spacing_2, NULL);
60 g_object_get(dim_style, "baseline-spacing", &baseline_spacing, NULL);
61 adg_assert_isapprox(baseline_spacing, valid_baseline_spacing_2);
63 g_object_unref(dim_style);
66 static void
67 _adg_property_beyond(void)
69 AdgDimStyle *dim_style;
70 gdouble valid_beyond_1, valid_beyond_2, invalid_beyond;
71 gdouble beyond;
73 dim_style = adg_dim_style_new();
74 valid_beyond_1 = 0;
75 valid_beyond_2 = 999;
76 invalid_beyond = -1;
78 /* Using the public APIs */
79 adg_dim_style_set_beyond(dim_style, valid_beyond_1);
80 beyond = adg_dim_style_get_beyond(dim_style);
81 adg_assert_isapprox(beyond, valid_beyond_1);
83 adg_dim_style_set_beyond(dim_style, invalid_beyond);
84 beyond = adg_dim_style_get_beyond(dim_style);
85 adg_assert_isapprox(beyond, valid_beyond_1);
87 adg_dim_style_set_beyond(dim_style, valid_beyond_2);
88 beyond = adg_dim_style_get_beyond(dim_style);
89 adg_assert_isapprox(beyond, valid_beyond_2);
91 /* Using GObject property methods */
92 g_object_set(dim_style, "beyond", valid_beyond_1, NULL);
93 g_object_get(dim_style, "beyond", &beyond, NULL);
94 adg_assert_isapprox(beyond, valid_beyond_1);
96 g_object_set(dim_style, "beyond", invalid_beyond, NULL);
97 g_object_get(dim_style, "beyond", &beyond, NULL);
98 adg_assert_isapprox(beyond, valid_beyond_1);
100 g_object_set(dim_style, "beyond", valid_beyond_2, NULL);
101 g_object_get(dim_style, "beyond", &beyond, NULL);
102 adg_assert_isapprox(beyond, valid_beyond_2);
104 g_object_unref(dim_style);
107 static void
108 _adg_property_color_dress(void)
110 AdgDimStyle *dim_style;
111 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
112 AdgDress color_dress;
114 dim_style = adg_dim_style_new();
115 valid_dress_1 = ADG_DRESS_COLOR_ANNOTATION;
116 valid_dress_2 = ADG_DRESS_COLOR;
117 incompatible_dress = ADG_DRESS_FONT;
119 /* Using the public APIs */
120 adg_dim_style_set_color_dress(dim_style, valid_dress_1);
121 color_dress = adg_dim_style_get_color_dress(dim_style);
122 g_assert_cmpint(color_dress, ==, valid_dress_1);
124 adg_dim_style_set_color_dress(dim_style, incompatible_dress);
125 color_dress = adg_dim_style_get_color_dress(dim_style);
126 g_assert_cmpint(color_dress, ==, valid_dress_1);
128 adg_dim_style_set_color_dress(dim_style, valid_dress_2);
129 color_dress = adg_dim_style_get_color_dress(dim_style);
130 g_assert_cmpint(color_dress, ==, valid_dress_2);
132 /* Using GObject property methods */
133 g_object_set(dim_style, "color-dress", valid_dress_1, NULL);
134 g_object_get(dim_style, "color-dress", &color_dress, NULL);
135 g_assert_cmpint(color_dress, ==, valid_dress_1);
137 g_object_set(dim_style, "color-dress", incompatible_dress, NULL);
138 g_object_get(dim_style, "color-dress", &color_dress, NULL);
139 g_assert_cmpint(color_dress, ==, valid_dress_1);
141 g_object_set(dim_style, "color-dress", valid_dress_2, NULL);
142 g_object_get(dim_style, "color-dress", &color_dress, NULL);
143 g_assert_cmpint(color_dress, ==, valid_dress_2);
145 g_object_unref(dim_style);
148 static void
149 _adg_property_from_offset(void)
151 AdgDimStyle *dim_style;
152 gdouble valid_from_offset_1, valid_from_offset_2, invalid_from_offset;
153 gdouble from_offset;
155 dim_style = adg_dim_style_new();
156 valid_from_offset_1 = 0;
157 valid_from_offset_2 = 999;
158 invalid_from_offset = -1;
160 /* Using the public APIs */
161 adg_dim_style_set_from_offset(dim_style, valid_from_offset_1);
162 from_offset = adg_dim_style_get_from_offset(dim_style);
163 adg_assert_isapprox(from_offset, valid_from_offset_1);
165 adg_dim_style_set_from_offset(dim_style, invalid_from_offset);
166 from_offset = adg_dim_style_get_from_offset(dim_style);
167 adg_assert_isapprox(from_offset, valid_from_offset_1);
169 adg_dim_style_set_from_offset(dim_style, valid_from_offset_2);
170 from_offset = adg_dim_style_get_from_offset(dim_style);
171 adg_assert_isapprox(from_offset, valid_from_offset_2);
173 /* Using GObject property methods */
174 g_object_set(dim_style, "from-offset", valid_from_offset_1, NULL);
175 g_object_get(dim_style, "from-offset", &from_offset, NULL);
176 adg_assert_isapprox(from_offset, valid_from_offset_1);
178 g_object_set(dim_style, "from-offset", invalid_from_offset, NULL);
179 g_object_get(dim_style, "from-offset", &from_offset, NULL);
180 adg_assert_isapprox(from_offset, valid_from_offset_1);
182 g_object_set(dim_style, "from-offset", valid_from_offset_2, NULL);
183 g_object_get(dim_style, "from-offset", &from_offset, NULL);
184 adg_assert_isapprox(from_offset, valid_from_offset_2);
186 g_object_unref(dim_style);
189 static void
190 _adg_property_limits_shift(void)
192 AdgDimStyle *dim_style;
193 CpmlPair null_shift, identity_shift;
194 const CpmlPair *shift;
195 CpmlPair *shift_dup;
197 dim_style = adg_dim_style_new();
198 null_shift.x = 0;
199 null_shift.y = 0;
200 identity_shift.x = 1;
201 identity_shift.y = 1;
203 /* Using the public APIs */
204 adg_dim_style_set_limits_shift(dim_style, &identity_shift);
205 shift = adg_dim_style_get_limits_shift(dim_style);
206 g_assert_true(cpml_pair_equal(shift, &identity_shift));
208 adg_dim_style_set_limits_shift(dim_style, &null_shift);
209 shift = adg_dim_style_get_limits_shift(dim_style);
210 g_assert_true(cpml_pair_equal(shift, &null_shift));
212 adg_dim_style_set_limits_shift(dim_style, NULL);
213 shift = adg_dim_style_get_limits_shift(dim_style);
214 g_assert_true(cpml_pair_equal(shift, &null_shift));
216 /* Using GObject property methods */
217 g_object_set(dim_style, "limits-shift", &identity_shift, NULL);
218 g_object_get(dim_style, "limits-shift", &shift_dup, NULL);
219 g_assert_true(cpml_pair_equal(shift_dup, &identity_shift));
220 g_free(shift_dup);
222 g_object_set(dim_style, "limits-shift", NULL, NULL);
223 g_object_get(dim_style, "limits-shift", &shift_dup, NULL);
224 g_assert_true(cpml_pair_equal(shift_dup, &identity_shift));
225 g_free(shift_dup);
227 g_object_set(dim_style, "limits-shift", &null_shift, NULL);
228 g_object_get(dim_style, "limits-shift", &shift_dup, NULL);
229 g_assert_true(cpml_pair_equal(shift_dup, &null_shift));
230 g_free(shift_dup);
232 g_object_unref(dim_style);
235 static void
236 _adg_property_limits_spacing(void)
238 AdgDimStyle *dim_style;
239 gdouble limits_spacing;
241 dim_style = adg_dim_style_new();
243 /* Using the public APIs */
244 adg_dim_style_set_limits_spacing(dim_style, 999.);
245 limits_spacing = adg_dim_style_get_limits_spacing(dim_style);
246 adg_assert_isapprox(limits_spacing, 999.);
248 /* Negative spacing is allowed */
249 adg_dim_style_set_limits_spacing(dim_style, -1.);
250 limits_spacing = adg_dim_style_get_limits_spacing(dim_style);
251 adg_assert_isapprox(limits_spacing, -1.);
253 adg_dim_style_set_limits_spacing(dim_style, 0.);
254 limits_spacing = adg_dim_style_get_limits_spacing(dim_style);
255 adg_assert_isapprox(limits_spacing, 0.);
257 /* Using GObject property methods */
258 g_object_set(dim_style, "limits-spacing", 999., NULL);
259 g_object_get(dim_style, "limits-spacing", &limits_spacing, NULL);
260 adg_assert_isapprox(limits_spacing, 999.);
262 g_object_set(dim_style, "limits-spacing", -1., NULL);
263 g_object_get(dim_style, "limits-spacing", &limits_spacing, NULL);
264 adg_assert_isapprox(limits_spacing, -1.);
266 g_object_set(dim_style, "limits-spacing", 0., NULL);
267 g_object_get(dim_style, "limits-spacing", &limits_spacing, NULL);
268 adg_assert_isapprox(limits_spacing, 0.);
270 g_object_unref(dim_style);
273 static void
274 _adg_property_line_dress(void)
276 AdgDimStyle *dim_style;
277 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
278 AdgDress line_dress;
280 dim_style = adg_dim_style_new();
281 valid_dress_1 = ADG_DRESS_LINE_FILL;
282 valid_dress_2 = ADG_DRESS_LINE;
283 incompatible_dress = ADG_DRESS_COLOR;
285 /* Using the public APIs */
286 adg_dim_style_set_line_dress(dim_style, valid_dress_1);
287 line_dress = adg_dim_style_get_line_dress(dim_style);
288 g_assert_cmpint(line_dress, ==, valid_dress_1);
290 adg_dim_style_set_line_dress(dim_style, incompatible_dress);
291 line_dress = adg_dim_style_get_line_dress(dim_style);
292 g_assert_cmpint(line_dress, ==, valid_dress_1);
294 adg_dim_style_set_line_dress(dim_style, valid_dress_2);
295 line_dress = adg_dim_style_get_line_dress(dim_style);
296 g_assert_cmpint(line_dress, ==, valid_dress_2);
298 /* Using GObject property methods */
299 g_object_set(dim_style, "line-dress", valid_dress_1, NULL);
300 g_object_get(dim_style, "line-dress", &line_dress, NULL);
301 g_assert_cmpint(line_dress, ==, valid_dress_1);
303 g_object_set(dim_style, "line-dress", incompatible_dress, NULL);
304 g_object_get(dim_style, "line-dress", &line_dress, NULL);
305 g_assert_cmpint(line_dress, ==, valid_dress_1);
307 g_object_set(dim_style, "line-dress", valid_dress_2, NULL);
308 g_object_get(dim_style, "line-dress", &line_dress, NULL);
309 g_assert_cmpint(line_dress, ==, valid_dress_2);
311 g_object_unref(dim_style);
314 static void
315 _adg_property_marker1(void)
317 AdgDimStyle *dim_style;
318 AdgMarker *valid_marker, *invalid_marker, *marker;
320 dim_style = adg_dim_style_new();
321 valid_marker = ADG_MARKER(adg_arrow_new());
322 invalid_marker = adg_test_invalid_pointer();
324 /* Using the public APIs */
325 adg_dim_style_set_marker1(dim_style, valid_marker);
326 marker = adg_dim_style_marker1_new(dim_style);
327 g_assert_nonnull(marker);
328 adg_entity_destroy(ADG_ENTITY(marker));
330 adg_dim_style_set_marker1(dim_style, invalid_marker);
331 marker = adg_dim_style_marker1_new(dim_style);
332 g_assert_nonnull(marker);
333 adg_entity_destroy(ADG_ENTITY(marker));
335 adg_dim_style_set_marker1(dim_style, NULL);
336 marker = adg_dim_style_marker1_new(dim_style);
337 g_assert_null(marker);
339 /* Using GObject property methods */
340 g_object_set(dim_style, "marker1", valid_marker, NULL);
341 marker = adg_dim_style_marker1_new(dim_style);
342 g_assert_nonnull(marker);
343 adg_entity_destroy(ADG_ENTITY(marker));
345 g_object_set(dim_style, "marker1", invalid_marker, NULL);
346 marker = adg_dim_style_marker1_new(dim_style);
347 g_assert_nonnull(marker);
348 adg_entity_destroy(ADG_ENTITY(marker));
350 g_object_set(dim_style, "marker1", NULL, NULL);
351 marker = adg_dim_style_marker1_new(dim_style);
352 g_assert_null(marker);
354 g_object_unref(dim_style);
355 adg_entity_destroy(ADG_ENTITY(valid_marker));
358 static void
359 _adg_property_marker2(void)
361 AdgDimStyle *dim_style;
362 AdgMarker *valid_marker, *invalid_marker, *marker;
364 dim_style = adg_dim_style_new();
365 valid_marker = ADG_MARKER(adg_arrow_new());
366 invalid_marker = adg_test_invalid_pointer();
368 /* Using the public APIs */
369 adg_dim_style_set_marker2(dim_style, valid_marker);
370 marker = adg_dim_style_marker2_new(dim_style);
371 g_assert_nonnull(marker);
372 adg_entity_destroy(ADG_ENTITY(marker));
374 adg_dim_style_set_marker2(dim_style, invalid_marker);
375 marker = adg_dim_style_marker2_new(dim_style);
376 g_assert_nonnull(marker);
377 adg_entity_destroy(ADG_ENTITY(marker));
379 adg_dim_style_set_marker2(dim_style, NULL);
380 marker = adg_dim_style_marker2_new(dim_style);
381 g_assert_null(marker);
383 /* Using GObject property methods */
384 g_object_set(dim_style, "marker2", valid_marker, NULL);
385 marker = adg_dim_style_marker2_new(dim_style);
386 g_assert_nonnull(marker);
387 adg_entity_destroy(ADG_ENTITY(marker));
389 g_object_set(dim_style, "marker2", invalid_marker, NULL);
390 marker = adg_dim_style_marker2_new(dim_style);
391 g_assert_nonnull(marker);
392 adg_entity_destroy(ADG_ENTITY(marker));
394 g_object_set(dim_style, "marker2", NULL, NULL);
395 marker = adg_dim_style_marker2_new(dim_style);
396 g_assert_null(marker);
398 g_object_unref(dim_style);
399 adg_entity_destroy(ADG_ENTITY(valid_marker));
402 static void
403 _adg_property_max_dress(void)
405 AdgDimStyle *dim_style;
406 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
407 AdgDress max_dress;
409 dim_style = adg_dim_style_new();
410 valid_dress_1 = ADG_DRESS_FONT_QUOTE_ANNOTATION;
411 valid_dress_2 = ADG_DRESS_FONT_ANNOTATION;
412 incompatible_dress = ADG_DRESS_FILL_HATCH;
414 /* Using the public APIs */
415 adg_dim_style_set_max_dress(dim_style, valid_dress_1);
416 max_dress = adg_dim_style_get_max_dress(dim_style);
417 g_assert_cmpint(max_dress, ==, valid_dress_1);
419 adg_dim_style_set_max_dress(dim_style, incompatible_dress);
420 max_dress = adg_dim_style_get_max_dress(dim_style);
421 g_assert_cmpint(max_dress, ==, valid_dress_1);
423 adg_dim_style_set_max_dress(dim_style, valid_dress_2);
424 max_dress = adg_dim_style_get_max_dress(dim_style);
425 g_assert_cmpint(max_dress, ==, valid_dress_2);
427 /* Using GObject property methods */
428 g_object_set(dim_style, "max-dress", valid_dress_1, NULL);
429 g_object_get(dim_style, "max-dress", &max_dress, NULL);
430 g_assert_cmpint(max_dress, ==, valid_dress_1);
432 g_object_set(dim_style, "max-dress", incompatible_dress, NULL);
433 g_object_get(dim_style, "max-dress", &max_dress, NULL);
434 g_assert_cmpint(max_dress, ==, valid_dress_1);
436 g_object_set(dim_style, "max-dress", valid_dress_2, NULL);
437 g_object_get(dim_style, "max-dress", &max_dress, NULL);
438 g_assert_cmpint(max_dress, ==, valid_dress_2);
440 g_object_unref(dim_style);
443 static void
444 _adg_property_min_dress(void)
446 AdgDimStyle *dim_style;
447 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
448 AdgDress min_dress;
450 dim_style = adg_dim_style_new();
451 valid_dress_1 = ADG_DRESS_FONT_QUOTE_TEXT;
452 valid_dress_2 = ADG_DRESS_FONT_QUOTE_ANNOTATION;
453 incompatible_dress = ADG_DRESS_FILL_HATCH;
455 /* Using the public APIs */
456 adg_dim_style_set_min_dress(dim_style, valid_dress_1);
457 min_dress = adg_dim_style_get_min_dress(dim_style);
458 g_assert_cmpint(min_dress, ==, valid_dress_1);
460 adg_dim_style_set_min_dress(dim_style, incompatible_dress);
461 min_dress = adg_dim_style_get_min_dress(dim_style);
462 g_assert_cmpint(min_dress, ==, valid_dress_1);
464 adg_dim_style_set_min_dress(dim_style, valid_dress_2);
465 min_dress = adg_dim_style_get_min_dress(dim_style);
466 g_assert_cmpint(min_dress, ==, valid_dress_2);
468 /* Using GObject property methods */
469 g_object_set(dim_style, "min-dress", valid_dress_1, NULL);
470 g_object_get(dim_style, "min-dress", &min_dress, NULL);
471 g_assert_cmpint(min_dress, ==, valid_dress_1);
473 g_object_set(dim_style, "min-dress", incompatible_dress, NULL);
474 g_object_get(dim_style, "min-dress", &min_dress, NULL);
475 g_assert_cmpint(min_dress, ==, valid_dress_1);
477 g_object_set(dim_style, "min-dress", valid_dress_2, NULL);
478 g_object_get(dim_style, "min-dress", &min_dress, NULL);
479 g_assert_cmpint(min_dress, ==, valid_dress_2);
481 g_object_unref(dim_style);
484 static void
485 _adg_property_number_format(void)
487 AdgDimStyle *dim_style;
488 const gchar *valid_text_1, *valid_text_2;
489 const gchar *number_format;
490 gchar *number_format_dup;
492 dim_style = adg_dim_style_new();
493 valid_text_1 = "%lf";
494 valid_text_2 = "%abc%";
496 /* Check default value */
497 number_format = adg_dim_style_get_number_format(dim_style);
498 g_assert_cmpstr(number_format, ==, "%-.7g");
500 /* Using the public APIs */
501 adg_dim_style_set_number_format(dim_style, valid_text_1);
502 number_format = adg_dim_style_get_number_format(dim_style);
503 g_assert_cmpstr(number_format, ==, valid_text_1);
505 adg_dim_style_set_number_format(dim_style, valid_text_2);
506 number_format = adg_dim_style_get_number_format(dim_style);
507 g_assert_cmpstr(number_format, ==, valid_text_2);
509 adg_dim_style_set_number_format(dim_style, NULL);
510 number_format = adg_dim_style_get_number_format(dim_style);
511 g_assert_null(number_format);
513 /* Using GObject property methods */
514 g_object_set(dim_style, "number-format", valid_text_1, NULL);
515 g_object_get(dim_style, "number-format", &number_format_dup, NULL);
516 g_assert_cmpstr(number_format_dup, ==, valid_text_1);
517 g_free(number_format_dup);
519 g_object_set(dim_style, "number-format", valid_text_2, NULL);
520 g_object_get(dim_style, "number-format", &number_format_dup, NULL);
521 g_assert_cmpstr(number_format_dup, ==, valid_text_2);
522 g_free(number_format_dup);
524 g_object_set(dim_style, "number-format", NULL, NULL);
525 g_object_get(dim_style, "number-format", &number_format_dup, NULL);
526 g_assert_null(number_format_dup);
528 g_object_unref(dim_style);
531 static void
532 _adg_property_number_arguments(void)
534 AdgDimStyle *dim_style;
535 const gchar *valid_text_1, *valid_text_2;
536 const gchar *number_arguments;
537 gchar *number_arguments_dup;
539 dim_style = adg_dim_style_new();
540 valid_text_1 = "aieDdMmSs";
541 valid_text_2 = "";
543 /* Check default value */
544 number_arguments = adg_dim_style_get_number_arguments(dim_style);
545 g_assert_cmpstr(number_arguments, ==, "d");
547 /* Using the public APIs */
548 adg_dim_style_set_number_arguments(dim_style, valid_text_1);
549 number_arguments = adg_dim_style_get_number_arguments(dim_style);
550 g_assert_cmpstr(number_arguments, ==, valid_text_1);
552 adg_dim_style_set_number_arguments(dim_style, "invalid");
553 number_arguments = adg_dim_style_get_number_arguments(dim_style);
554 g_assert_cmpstr(number_arguments, ==, valid_text_1);
556 adg_dim_style_set_number_arguments(dim_style, " ");
557 number_arguments = adg_dim_style_get_number_arguments(dim_style);
558 g_assert_cmpstr(number_arguments, ==, valid_text_1);
560 adg_dim_style_set_number_arguments(dim_style, valid_text_2);
561 number_arguments = adg_dim_style_get_number_arguments(dim_style);
562 g_assert_cmpstr(number_arguments, ==, valid_text_2);
564 adg_dim_style_set_number_arguments(dim_style, NULL);
565 number_arguments = adg_dim_style_get_number_arguments(dim_style);
566 g_assert_null(number_arguments);
568 /* Using GObject property methods */
569 g_object_set(dim_style, "number-arguments", valid_text_1, NULL);
570 g_object_get(dim_style, "number-arguments", &number_arguments_dup, NULL);
571 g_assert_cmpstr(number_arguments_dup, ==, valid_text_1);
572 g_free(number_arguments_dup);
574 g_object_set(dim_style, "number-arguments", "invalid", NULL);
575 g_object_get(dim_style, "number-arguments", &number_arguments_dup, NULL);
576 g_assert_cmpstr(number_arguments_dup, ==, valid_text_1);
577 g_free(number_arguments_dup);
579 g_object_set(dim_style, "number-arguments", " ", NULL);
580 g_object_get(dim_style, "number-arguments", &number_arguments_dup, NULL);
581 g_assert_cmpstr(number_arguments_dup, ==, valid_text_1);
582 g_free(number_arguments_dup);
584 g_object_set(dim_style, "number-arguments", valid_text_2, NULL);
585 g_object_get(dim_style, "number-arguments", &number_arguments_dup, NULL);
586 g_assert_cmpstr(number_arguments_dup, ==, valid_text_2);
587 g_free(number_arguments_dup);
589 g_object_set(dim_style, "number-arguments", NULL, NULL);
590 g_object_get(dim_style, "number-arguments", &number_arguments_dup, NULL);
591 g_assert_null(number_arguments_dup);
593 g_object_unref(dim_style);
596 static void
597 _adg_property_number_tag(void)
599 AdgDimStyle *dim_style;
600 const gchar *valid_text_1, *valid_text_2;
601 const gchar *number_tag;
602 gchar *number_tag_dup;
604 dim_style = adg_dim_style_new();
605 valid_text_1 = "";
606 valid_text_2 = "<è>";
608 /* Check default value */
609 number_tag = adg_dim_style_get_number_tag(dim_style);
610 g_assert_cmpstr(number_tag, ==, "<>");
612 /* Using the public APIs */
613 adg_dim_style_set_number_tag(dim_style, valid_text_1);
614 number_tag = adg_dim_style_get_number_tag(dim_style);
615 g_assert_cmpstr(number_tag, ==, valid_text_1);
617 adg_dim_style_set_number_tag(dim_style, valid_text_2);
618 number_tag = adg_dim_style_get_number_tag(dim_style);
619 g_assert_cmpstr(number_tag, ==, valid_text_2);
621 adg_dim_style_set_number_tag(dim_style, NULL);
622 number_tag = adg_dim_style_get_number_tag(dim_style);
623 g_assert_null(number_tag);
625 /* Using GObject property methods */
626 g_object_set(dim_style, "number-tag", valid_text_1, NULL);
627 g_object_get(dim_style, "number-tag", &number_tag_dup, NULL);
628 g_assert_cmpstr(number_tag_dup, ==, valid_text_1);
629 g_free(number_tag_dup);
631 g_object_set(dim_style, "number-tag", valid_text_2, NULL);
632 g_object_get(dim_style, "number-tag", &number_tag_dup, NULL);
633 g_assert_cmpstr(number_tag_dup, ==, valid_text_2);
634 g_free(number_tag_dup);
636 g_object_set(dim_style, "number-tag", NULL, NULL);
637 g_object_get(dim_style, "number-tag", &number_tag_dup, NULL);
638 g_assert_null(number_tag_dup);
640 g_object_unref(dim_style);
643 static void
644 _adg_property_decimals(void)
646 AdgDimStyle *dim_style;
647 gint decimals;
649 dim_style = adg_dim_style_new();
651 /* Check default value */
652 decimals = adg_dim_style_get_decimals(dim_style);
653 g_assert_cmpint(decimals, ==, 2);
655 /* Using the public APIs */
656 adg_dim_style_set_decimals(dim_style, 4);
657 decimals = adg_dim_style_get_decimals(dim_style);
658 g_assert_cmpint(decimals, ==, 4);
660 adg_dim_style_set_decimals(dim_style, -2);
661 decimals = adg_dim_style_get_decimals(dim_style);
662 g_assert_cmpint(decimals, ==, 4);
664 decimals = adg_dim_style_get_decimals(NULL);
665 g_assert_cmpint(decimals, ==, -2);
667 adg_dim_style_set_decimals(dim_style, -1);
668 decimals = adg_dim_style_get_decimals(dim_style);
669 g_assert_cmpint(decimals, ==, -1);
671 /* Using GObject property methods */
672 g_object_set(dim_style, "decimals", 2, NULL);
673 g_object_get(dim_style, "decimals", &decimals, NULL);
674 g_assert_cmpint(decimals, ==, 2);
676 g_object_set(dim_style, "decimals", -2, NULL);
677 g_object_get(dim_style, "decimals", &decimals, NULL);
678 g_assert_cmpint(decimals, ==, 2);
680 g_object_set(dim_style, "decimals", -1, NULL);
681 g_object_get(dim_style, "decimals", &decimals, NULL);
682 g_assert_cmpint(decimals, ==, -1);
684 g_object_unref(dim_style);
687 static void
688 _adg_property_rounding(void)
690 AdgDimStyle *dim_style;
691 gint rounding;
693 dim_style = adg_dim_style_new();
695 /* Check default value */
696 rounding = adg_dim_style_get_rounding(dim_style);
697 g_assert_cmpint(rounding, ==, 6);
699 /* Using the public APIs */
700 adg_dim_style_set_rounding(dim_style, 4);
701 rounding = adg_dim_style_get_rounding(dim_style);
702 g_assert_cmpint(rounding, ==, 4);
704 adg_dim_style_set_rounding(dim_style, -2);
705 rounding = adg_dim_style_get_rounding(dim_style);
706 g_assert_cmpint(rounding, ==, 4);
708 rounding = adg_dim_style_get_rounding(NULL);
709 g_assert_cmpint(rounding, ==, -2);
711 adg_dim_style_set_rounding(dim_style, -1);
712 rounding = adg_dim_style_get_rounding(dim_style);
713 g_assert_cmpint(rounding, ==, -1);
715 /* Using GObject property methods */
716 g_object_set(dim_style, "rounding", 2, NULL);
717 g_object_get(dim_style, "rounding", &rounding, NULL);
718 g_assert_cmpint(rounding, ==, 2);
720 g_object_set(dim_style, "rounding", -2, NULL);
721 g_object_get(dim_style, "rounding", &rounding, NULL);
722 g_assert_cmpint(rounding, ==, 2);
724 g_object_set(dim_style, "rounding", -1, NULL);
725 g_object_get(dim_style, "rounding", &rounding, NULL);
726 g_assert_cmpint(rounding, ==, -1);
728 g_object_unref(dim_style);
731 static void
732 _adg_property_quote_shift(void)
734 AdgDimStyle *dim_style;
735 CpmlPair null_shift, identity_shift;
736 const CpmlPair *shift;
737 CpmlPair *shift_dup;
739 dim_style = adg_dim_style_new();
740 null_shift.x = 0;
741 null_shift.y = 0;
742 identity_shift.x = 1;
743 identity_shift.y = 1;
745 /* Using the public APIs */
746 adg_dim_style_set_quote_shift(dim_style, &identity_shift);
747 shift = adg_dim_style_get_quote_shift(dim_style);
748 g_assert_true(cpml_pair_equal(shift, &identity_shift));
750 adg_dim_style_set_quote_shift(dim_style, &null_shift);
751 shift = adg_dim_style_get_quote_shift(dim_style);
752 g_assert_true(cpml_pair_equal(shift, &null_shift));
754 adg_dim_style_set_quote_shift(dim_style, NULL);
755 shift = adg_dim_style_get_quote_shift(dim_style);
756 g_assert_true(cpml_pair_equal(shift, &null_shift));
758 /* Using GObject property methods */
759 g_object_set(dim_style, "quote-shift", &identity_shift, NULL);
760 g_object_get(dim_style, "quote-shift", &shift_dup, NULL);
761 g_assert_true(cpml_pair_equal(shift_dup, &identity_shift));
762 g_free(shift_dup);
764 g_object_set(dim_style, "quote-shift", NULL, NULL);
765 g_object_get(dim_style, "quote-shift", &shift_dup, NULL);
766 g_assert_true(cpml_pair_equal(shift_dup, &identity_shift));
767 g_free(shift_dup);
769 g_object_set(dim_style, "quote-shift", &null_shift, NULL);
770 g_object_get(dim_style, "quote-shift", &shift_dup, NULL);
771 g_assert_true(cpml_pair_equal(shift_dup, &null_shift));
772 g_free(shift_dup);
774 g_object_unref(dim_style);
777 static void
778 _adg_property_to_offset(void)
780 AdgDimStyle *dim_style;
781 gdouble valid_to_offset_1, valid_to_offset_2, invalid_to_offset;
782 gdouble to_offset;
784 dim_style = adg_dim_style_new();
785 valid_to_offset_1 = 0;
786 valid_to_offset_2 = 999;
787 invalid_to_offset = -1;
789 /* Using the public APIs */
790 adg_dim_style_set_to_offset(dim_style, valid_to_offset_1);
791 to_offset = adg_dim_style_get_to_offset(dim_style);
792 adg_assert_isapprox(to_offset, valid_to_offset_1);
794 adg_dim_style_set_to_offset(dim_style, invalid_to_offset);
795 to_offset = adg_dim_style_get_to_offset(dim_style);
796 adg_assert_isapprox(to_offset, valid_to_offset_1);
798 adg_dim_style_set_to_offset(dim_style, valid_to_offset_2);
799 to_offset = adg_dim_style_get_to_offset(dim_style);
800 adg_assert_isapprox(to_offset, valid_to_offset_2);
802 /* Using GObject property methods */
803 g_object_set(dim_style, "to-offset", valid_to_offset_1, NULL);
804 g_object_get(dim_style, "to-offset", &to_offset, NULL);
805 adg_assert_isapprox(to_offset, valid_to_offset_1);
807 g_object_set(dim_style, "to-offset", invalid_to_offset, NULL);
808 g_object_get(dim_style, "to-offset", &to_offset, NULL);
809 adg_assert_isapprox(to_offset, valid_to_offset_1);
811 g_object_set(dim_style, "to-offset", valid_to_offset_2, NULL);
812 g_object_get(dim_style, "to-offset", &to_offset, NULL);
813 adg_assert_isapprox(to_offset, valid_to_offset_2);
815 g_object_unref(dim_style);
818 static void
819 _adg_property_value_dress(void)
821 AdgDimStyle *dim_style;
822 AdgDress valid_dress_1, valid_dress_2, incompatible_dress;
823 AdgDress value_dress;
825 dim_style = adg_dim_style_new();
826 valid_dress_1 = ADG_DRESS_FONT;
827 valid_dress_2 = ADG_DRESS_FONT_QUOTE_ANNOTATION;
828 incompatible_dress = ADG_DRESS_FILL_HATCH;
830 /* Using the public APIs */
831 adg_dim_style_set_value_dress(dim_style, valid_dress_1);
832 value_dress = adg_dim_style_get_value_dress(dim_style);
833 g_assert_cmpint(value_dress, ==, valid_dress_1);
835 adg_dim_style_set_value_dress(dim_style, incompatible_dress);
836 value_dress = adg_dim_style_get_value_dress(dim_style);
837 g_assert_cmpint(value_dress, ==, valid_dress_1);
839 adg_dim_style_set_value_dress(dim_style, valid_dress_2);
840 value_dress = adg_dim_style_get_value_dress(dim_style);
841 g_assert_cmpint(value_dress, ==, valid_dress_2);
843 /* Using GObject property methods */
844 g_object_set(dim_style, "value-dress", valid_dress_1, NULL);
845 g_object_get(dim_style, "value-dress", &value_dress, NULL);
846 g_assert_cmpint(value_dress, ==, valid_dress_1);
848 g_object_set(dim_style, "value-dress", incompatible_dress, NULL);
849 g_object_get(dim_style, "value-dress", &value_dress, NULL);
850 g_assert_cmpint(value_dress, ==, valid_dress_1);
852 g_object_set(dim_style, "value-dress", valid_dress_2, NULL);
853 g_object_get(dim_style, "value-dress", &value_dress, NULL);
854 g_assert_cmpint(value_dress, ==, valid_dress_2);
856 g_object_unref(dim_style);
859 static void
860 _adg_method_convert(void)
862 AdgDimStyle *dim_style;
863 gdouble value;
865 dim_style = adg_dim_style_new();
866 adg_dim_style_set_decimals(dim_style, 0);
868 /* Sanity check */
869 g_assert_false(adg_dim_style_convert(NULL, &value, 'a'));
870 g_assert_false(adg_dim_style_convert(dim_style, NULL, 'a'));
871 g_assert_false(adg_dim_style_convert(NULL, NULL, 'a'));
873 /* Checking the various conversions. For reference:
874 * - 'a': the raw @value, i.e. no conversion is performed;
875 * - 'i': the raw number of minutes, i.e. the fractional part of @value x 60
876 * - 'e': the raw number of seconds, i.e. the fractional part of the raw
877 * number of minutes x 60
878 * - 'D': the truncated value of the raw value ('a');
879 * - 'd': the rounded value of the raw value ('a');
880 * - 'M': the truncated value of the raw number of minutes ('i');
881 * - 'm': the rounded value of the raw number of minutes ('i');
882 * - 'S': the truncated value of the raw number of seconds ('e');
883 * - 's': the rounded value of the raw number of seconds ('e');
885 value = 5.678;
886 g_assert_true(adg_dim_style_convert(dim_style, &value, 'a'));
887 adg_assert_isapprox(value, 5.678);
889 value = 5.678;
890 g_assert_true(adg_dim_style_convert(dim_style, &value, 'i'));
891 adg_assert_isapprox(value, 40.68);
893 value = 5.678;
894 g_assert_true(adg_dim_style_convert(dim_style, &value, 'e'));
895 adg_assert_isapprox(value, 40.8);
897 value = 5.678;
898 g_assert_true(adg_dim_style_convert(dim_style, &value, 'D'));
899 adg_assert_isapprox(value, 5);
901 value = 5.678;
902 g_assert_true(adg_dim_style_convert(dim_style, &value, 'd'));
903 adg_assert_isapprox(value, 6);
905 value = 5.678;
906 g_assert_true(adg_dim_style_convert(dim_style, &value, 'M'));
907 adg_assert_isapprox(value, 40);
909 value = 5.678;
910 g_assert_true(adg_dim_style_convert(dim_style, &value, 'm'));
911 adg_assert_isapprox(value, 41);
913 value = 5.678;
914 g_assert_true(adg_dim_style_convert(dim_style, &value, 'S'));
915 adg_assert_isapprox(value, 40);
917 value = 5.678;
918 g_assert_true(adg_dim_style_convert(dim_style, &value, 's'));
919 adg_assert_isapprox(value, 41);
921 /* Checking that the round property rounds */
922 value = 59.999;
923 g_assert_true(adg_dim_style_convert(dim_style, &value, 'D'));
924 adg_assert_isapprox(value, 59);
926 adg_dim_style_set_rounding(dim_style, 3);
928 value = 59.999;
929 g_assert_true(adg_dim_style_convert(dim_style, &value, 'D'));
930 adg_assert_isapprox(value, 59);
932 adg_dim_style_set_rounding(dim_style, 2);
934 value = 59.999;
935 g_assert_true(adg_dim_style_convert(dim_style, &value, 'D'));
936 adg_assert_isapprox(value, 60);
937 g_object_unref(dim_style);
940 static void
941 _adg_method_clone(void)
943 AdgDimStyle *dim_style, *clone;
944 AdgMarker *org, *dup;
946 dim_style = adg_dim_style_new();
947 clone = ADG_DIM_STYLE(adg_style_clone(ADG_STYLE(dim_style)));
950 /* Check that first markers are complatible */
951 org = adg_dim_style_marker1_new(dim_style);
952 dup = adg_dim_style_marker1_new(clone);
953 g_assert_cmpuint(adg_marker_get_n_segment(org), ==, adg_marker_get_n_segment(org));
954 adg_assert_isapprox(adg_marker_get_pos(org), adg_marker_get_pos(dup));
955 adg_assert_isapprox(adg_marker_get_size(org), adg_marker_get_size(dup));
956 g_object_unref(org);
957 g_object_unref(dup);
960 /* Check that second markers are complatible */
961 org = adg_dim_style_marker2_new(dim_style);
962 dup = adg_dim_style_marker2_new(clone);
963 g_assert_cmpuint(adg_marker_get_n_segment(org), ==, adg_marker_get_n_segment(org));
964 adg_assert_isapprox(adg_marker_get_pos(org), adg_marker_get_pos(dup));
965 adg_assert_isapprox(adg_marker_get_size(org), adg_marker_get_size(dup));
966 g_object_unref(org);
967 g_object_unref(dup);
970 g_object_unref(dim_style);
971 g_object_unref(clone);
976 main(int argc, char *argv[])
978 adg_test_init(&argc, &argv);
980 adg_test_add_object_checks("/adg/dim-style/type/object", ADG_TYPE_DIM_STYLE);
982 g_test_add_func("/adg/dim-style/property/baseline-spacing", _adg_property_baseline_spacing);
983 g_test_add_func("/adg/dim-style/property/beyond", _adg_property_beyond);
984 g_test_add_func("/adg/dim-style/property/color-dress", _adg_property_color_dress);
985 g_test_add_func("/adg/dim-style/property/from-offset", _adg_property_from_offset);
986 g_test_add_func("/adg/dim-style/property/limits-shift", _adg_property_limits_shift);
987 g_test_add_func("/adg/dim-style/property/limits-spacing", _adg_property_limits_spacing);
988 g_test_add_func("/adg/dim-style/property/line-dress", _adg_property_line_dress);
989 g_test_add_func("/adg/dim-style/property/marker1", _adg_property_marker1);
990 g_test_add_func("/adg/dim-style/property/marker2", _adg_property_marker2);
991 g_test_add_func("/adg/dim-style/property/max-dress", _adg_property_max_dress);
992 g_test_add_func("/adg/dim-style/property/min-dress", _adg_property_min_dress);
993 g_test_add_func("/adg/dim-style/property/number-format", _adg_property_number_format);
994 g_test_add_func("/adg/dim-style/property/number-arguments", _adg_property_number_arguments);
995 g_test_add_func("/adg/dim-style/property/number-tag", _adg_property_number_tag);
996 g_test_add_func("/adg/dim-style/property/decimals", _adg_property_decimals);
997 g_test_add_func("/adg/dim-style/property/rounding", _adg_property_rounding);
998 g_test_add_func("/adg/dim-style/property/quote-shift", _adg_property_quote_shift);
999 g_test_add_func("/adg/dim-style/property/to-offset", _adg_property_to_offset);
1000 g_test_add_func("/adg/dim-style/property/value-dress", _adg_property_value_dress);
1002 g_test_add_func("/adg/dim-style/method/convert", _adg_method_convert);
1003 g_test_add_func("/adg/dim-style/method/clone", _adg_method_clone);
1005 return g_test_run();