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.
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
);
67 _adg_property_beyond(void)
69 AdgDimStyle
*dim_style
;
70 gdouble valid_beyond_1
, valid_beyond_2
, invalid_beyond
;
73 dim_style
= adg_dim_style_new();
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
);
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
);
149 _adg_property_from_offset(void)
151 AdgDimStyle
*dim_style
;
152 gdouble valid_from_offset_1
, valid_from_offset_2
, invalid_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
);
190 _adg_property_limits_shift(void)
192 AdgDimStyle
*dim_style
;
193 CpmlPair null_shift
, identity_shift
;
194 const CpmlPair
*shift
;
197 dim_style
= adg_dim_style_new();
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
));
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
));
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
));
232 g_object_unref(dim_style
);
236 _adg_property_limits_spacing(void)
238 AdgDimStyle
*dim_style
;
239 gdouble valid_limits_spacing_1
, valid_limits_spacing_2
, invalid_limits_spacing
;
240 gdouble limits_spacing
;
242 dim_style
= adg_dim_style_new();
243 valid_limits_spacing_1
= 0;
244 valid_limits_spacing_2
= 999;
245 invalid_limits_spacing
= -1;
247 /* Using the public APIs */
248 adg_dim_style_set_limits_spacing(dim_style
, valid_limits_spacing_1
);
249 limits_spacing
= adg_dim_style_get_limits_spacing(dim_style
);
250 adg_assert_isapprox(limits_spacing
, valid_limits_spacing_1
);
252 adg_dim_style_set_limits_spacing(dim_style
, invalid_limits_spacing
);
253 limits_spacing
= adg_dim_style_get_limits_spacing(dim_style
);
254 adg_assert_isapprox(limits_spacing
, valid_limits_spacing_1
);
256 adg_dim_style_set_limits_spacing(dim_style
, valid_limits_spacing_2
);
257 limits_spacing
= adg_dim_style_get_limits_spacing(dim_style
);
258 adg_assert_isapprox(limits_spacing
, valid_limits_spacing_2
);
260 /* Using GObject property methods */
261 g_object_set(dim_style
, "limits-spacing", valid_limits_spacing_1
, NULL
);
262 g_object_get(dim_style
, "limits-spacing", &limits_spacing
, NULL
);
263 adg_assert_isapprox(limits_spacing
, valid_limits_spacing_1
);
265 g_object_set(dim_style
, "limits-spacing", invalid_limits_spacing
, NULL
);
266 g_object_get(dim_style
, "limits-spacing", &limits_spacing
, NULL
);
267 adg_assert_isapprox(limits_spacing
, valid_limits_spacing_1
);
269 g_object_set(dim_style
, "limits-spacing", valid_limits_spacing_2
, NULL
);
270 g_object_get(dim_style
, "limits-spacing", &limits_spacing
, NULL
);
271 adg_assert_isapprox(limits_spacing
, valid_limits_spacing_2
);
273 g_object_unref(dim_style
);
277 _adg_property_line_dress(void)
279 AdgDimStyle
*dim_style
;
280 AdgDress valid_dress_1
, valid_dress_2
, incompatible_dress
;
283 dim_style
= adg_dim_style_new();
284 valid_dress_1
= ADG_DRESS_LINE_FILL
;
285 valid_dress_2
= ADG_DRESS_LINE
;
286 incompatible_dress
= ADG_DRESS_COLOR
;
288 /* Using the public APIs */
289 adg_dim_style_set_line_dress(dim_style
, valid_dress_1
);
290 line_dress
= adg_dim_style_get_line_dress(dim_style
);
291 g_assert_cmpint(line_dress
, ==, valid_dress_1
);
293 adg_dim_style_set_line_dress(dim_style
, incompatible_dress
);
294 line_dress
= adg_dim_style_get_line_dress(dim_style
);
295 g_assert_cmpint(line_dress
, ==, valid_dress_1
);
297 adg_dim_style_set_line_dress(dim_style
, valid_dress_2
);
298 line_dress
= adg_dim_style_get_line_dress(dim_style
);
299 g_assert_cmpint(line_dress
, ==, valid_dress_2
);
301 /* Using GObject property methods */
302 g_object_set(dim_style
, "line-dress", valid_dress_1
, NULL
);
303 g_object_get(dim_style
, "line-dress", &line_dress
, NULL
);
304 g_assert_cmpint(line_dress
, ==, valid_dress_1
);
306 g_object_set(dim_style
, "line-dress", incompatible_dress
, NULL
);
307 g_object_get(dim_style
, "line-dress", &line_dress
, NULL
);
308 g_assert_cmpint(line_dress
, ==, valid_dress_1
);
310 g_object_set(dim_style
, "line-dress", valid_dress_2
, NULL
);
311 g_object_get(dim_style
, "line-dress", &line_dress
, NULL
);
312 g_assert_cmpint(line_dress
, ==, valid_dress_2
);
314 g_object_unref(dim_style
);
318 _adg_property_marker1(void)
320 AdgDimStyle
*dim_style
;
321 AdgMarker
*valid_marker
, *invalid_marker
, *marker
;
323 dim_style
= adg_dim_style_new();
324 valid_marker
= ADG_MARKER(adg_arrow_new());
325 invalid_marker
= adg_test_invalid_pointer();
327 /* Using the public APIs */
328 adg_dim_style_set_marker1(dim_style
, valid_marker
);
329 marker
= adg_dim_style_marker1_new(dim_style
);
330 g_assert_nonnull(marker
);
331 adg_entity_destroy(ADG_ENTITY(marker
));
333 adg_dim_style_set_marker1(dim_style
, invalid_marker
);
334 marker
= adg_dim_style_marker1_new(dim_style
);
335 g_assert_nonnull(marker
);
336 adg_entity_destroy(ADG_ENTITY(marker
));
338 adg_dim_style_set_marker1(dim_style
, NULL
);
339 marker
= adg_dim_style_marker1_new(dim_style
);
340 g_assert_null(marker
);
342 /* Using GObject property methods */
343 g_object_set(dim_style
, "marker1", valid_marker
, NULL
);
344 marker
= adg_dim_style_marker1_new(dim_style
);
345 g_assert_nonnull(marker
);
346 adg_entity_destroy(ADG_ENTITY(marker
));
348 g_object_set(dim_style
, "marker1", invalid_marker
, NULL
);
349 marker
= adg_dim_style_marker1_new(dim_style
);
350 g_assert_nonnull(marker
);
351 adg_entity_destroy(ADG_ENTITY(marker
));
353 g_object_set(dim_style
, "marker1", NULL
, NULL
);
354 marker
= adg_dim_style_marker1_new(dim_style
);
355 g_assert_null(marker
);
357 g_object_unref(dim_style
);
358 adg_entity_destroy(ADG_ENTITY(valid_marker
));
362 _adg_property_marker2(void)
364 AdgDimStyle
*dim_style
;
365 AdgMarker
*valid_marker
, *invalid_marker
, *marker
;
367 dim_style
= adg_dim_style_new();
368 valid_marker
= ADG_MARKER(adg_arrow_new());
369 invalid_marker
= adg_test_invalid_pointer();
371 /* Using the public APIs */
372 adg_dim_style_set_marker2(dim_style
, valid_marker
);
373 marker
= adg_dim_style_marker2_new(dim_style
);
374 g_assert_nonnull(marker
);
375 adg_entity_destroy(ADG_ENTITY(marker
));
377 adg_dim_style_set_marker2(dim_style
, invalid_marker
);
378 marker
= adg_dim_style_marker2_new(dim_style
);
379 g_assert_nonnull(marker
);
380 adg_entity_destroy(ADG_ENTITY(marker
));
382 adg_dim_style_set_marker2(dim_style
, NULL
);
383 marker
= adg_dim_style_marker2_new(dim_style
);
384 g_assert_null(marker
);
386 /* Using GObject property methods */
387 g_object_set(dim_style
, "marker2", valid_marker
, NULL
);
388 marker
= adg_dim_style_marker2_new(dim_style
);
389 g_assert_nonnull(marker
);
390 adg_entity_destroy(ADG_ENTITY(marker
));
392 g_object_set(dim_style
, "marker2", invalid_marker
, NULL
);
393 marker
= adg_dim_style_marker2_new(dim_style
);
394 g_assert_nonnull(marker
);
395 adg_entity_destroy(ADG_ENTITY(marker
));
397 g_object_set(dim_style
, "marker2", NULL
, NULL
);
398 marker
= adg_dim_style_marker2_new(dim_style
);
399 g_assert_null(marker
);
401 g_object_unref(dim_style
);
402 adg_entity_destroy(ADG_ENTITY(valid_marker
));
406 _adg_property_max_dress(void)
408 AdgDimStyle
*dim_style
;
409 AdgDress valid_dress_1
, valid_dress_2
, incompatible_dress
;
412 dim_style
= adg_dim_style_new();
413 valid_dress_1
= ADG_DRESS_FONT_QUOTE_ANNOTATION
;
414 valid_dress_2
= ADG_DRESS_FONT_ANNOTATION
;
415 incompatible_dress
= ADG_DRESS_FILL_HATCH
;
417 /* Using the public APIs */
418 adg_dim_style_set_max_dress(dim_style
, valid_dress_1
);
419 max_dress
= adg_dim_style_get_max_dress(dim_style
);
420 g_assert_cmpint(max_dress
, ==, valid_dress_1
);
422 adg_dim_style_set_max_dress(dim_style
, incompatible_dress
);
423 max_dress
= adg_dim_style_get_max_dress(dim_style
);
424 g_assert_cmpint(max_dress
, ==, valid_dress_1
);
426 adg_dim_style_set_max_dress(dim_style
, valid_dress_2
);
427 max_dress
= adg_dim_style_get_max_dress(dim_style
);
428 g_assert_cmpint(max_dress
, ==, valid_dress_2
);
430 /* Using GObject property methods */
431 g_object_set(dim_style
, "max-dress", valid_dress_1
, NULL
);
432 g_object_get(dim_style
, "max-dress", &max_dress
, NULL
);
433 g_assert_cmpint(max_dress
, ==, valid_dress_1
);
435 g_object_set(dim_style
, "max-dress", incompatible_dress
, NULL
);
436 g_object_get(dim_style
, "max-dress", &max_dress
, NULL
);
437 g_assert_cmpint(max_dress
, ==, valid_dress_1
);
439 g_object_set(dim_style
, "max-dress", valid_dress_2
, NULL
);
440 g_object_get(dim_style
, "max-dress", &max_dress
, NULL
);
441 g_assert_cmpint(max_dress
, ==, valid_dress_2
);
443 g_object_unref(dim_style
);
447 _adg_property_min_dress(void)
449 AdgDimStyle
*dim_style
;
450 AdgDress valid_dress_1
, valid_dress_2
, incompatible_dress
;
453 dim_style
= adg_dim_style_new();
454 valid_dress_1
= ADG_DRESS_FONT_QUOTE_TEXT
;
455 valid_dress_2
= ADG_DRESS_FONT_QUOTE_ANNOTATION
;
456 incompatible_dress
= ADG_DRESS_FILL_HATCH
;
458 /* Using the public APIs */
459 adg_dim_style_set_min_dress(dim_style
, valid_dress_1
);
460 min_dress
= adg_dim_style_get_min_dress(dim_style
);
461 g_assert_cmpint(min_dress
, ==, valid_dress_1
);
463 adg_dim_style_set_min_dress(dim_style
, incompatible_dress
);
464 min_dress
= adg_dim_style_get_min_dress(dim_style
);
465 g_assert_cmpint(min_dress
, ==, valid_dress_1
);
467 adg_dim_style_set_min_dress(dim_style
, valid_dress_2
);
468 min_dress
= adg_dim_style_get_min_dress(dim_style
);
469 g_assert_cmpint(min_dress
, ==, valid_dress_2
);
471 /* Using GObject property methods */
472 g_object_set(dim_style
, "min-dress", valid_dress_1
, NULL
);
473 g_object_get(dim_style
, "min-dress", &min_dress
, NULL
);
474 g_assert_cmpint(min_dress
, ==, valid_dress_1
);
476 g_object_set(dim_style
, "min-dress", incompatible_dress
, NULL
);
477 g_object_get(dim_style
, "min-dress", &min_dress
, NULL
);
478 g_assert_cmpint(min_dress
, ==, valid_dress_1
);
480 g_object_set(dim_style
, "min-dress", valid_dress_2
, NULL
);
481 g_object_get(dim_style
, "min-dress", &min_dress
, NULL
);
482 g_assert_cmpint(min_dress
, ==, valid_dress_2
);
484 g_object_unref(dim_style
);
488 _adg_property_number_format(void)
490 AdgDimStyle
*dim_style
;
491 const gchar
*valid_text_1
, *valid_text_2
;
492 const gchar
*number_format
;
493 gchar
*number_format_dup
;
495 dim_style
= adg_dim_style_new();
496 valid_text_1
= "%lf";
497 valid_text_2
= "%abc%";
499 /* Check default value */
500 number_format
= adg_dim_style_get_number_format(dim_style
);
501 g_assert_cmpstr(number_format
, ==, "%-.7g");
503 /* Using the public APIs */
504 adg_dim_style_set_number_format(dim_style
, valid_text_1
);
505 number_format
= adg_dim_style_get_number_format(dim_style
);
506 g_assert_cmpstr(number_format
, ==, valid_text_1
);
508 adg_dim_style_set_number_format(dim_style
, valid_text_2
);
509 number_format
= adg_dim_style_get_number_format(dim_style
);
510 g_assert_cmpstr(number_format
, ==, valid_text_2
);
512 adg_dim_style_set_number_format(dim_style
, NULL
);
513 number_format
= adg_dim_style_get_number_format(dim_style
);
514 g_assert_null(number_format
);
516 /* Using GObject property methods */
517 g_object_set(dim_style
, "number-format", valid_text_1
, NULL
);
518 g_object_get(dim_style
, "number-format", &number_format_dup
, NULL
);
519 g_assert_cmpstr(number_format_dup
, ==, valid_text_1
);
520 g_free(number_format_dup
);
522 g_object_set(dim_style
, "number-format", valid_text_2
, NULL
);
523 g_object_get(dim_style
, "number-format", &number_format_dup
, NULL
);
524 g_assert_cmpstr(number_format_dup
, ==, valid_text_2
);
525 g_free(number_format_dup
);
527 g_object_set(dim_style
, "number-format", NULL
, NULL
);
528 g_object_get(dim_style
, "number-format", &number_format_dup
, NULL
);
529 g_assert_null(number_format_dup
);
531 g_object_unref(dim_style
);
535 _adg_property_number_arguments(void)
537 AdgDimStyle
*dim_style
;
538 const gchar
*valid_text_1
, *valid_text_2
;
539 const gchar
*number_arguments
;
540 gchar
*number_arguments_dup
;
542 dim_style
= adg_dim_style_new();
543 valid_text_1
= "aieDdMmSs";
546 /* Check default value */
547 number_arguments
= adg_dim_style_get_number_arguments(dim_style
);
548 g_assert_cmpstr(number_arguments
, ==, "d");
550 /* Using the public APIs */
551 adg_dim_style_set_number_arguments(dim_style
, valid_text_1
);
552 number_arguments
= adg_dim_style_get_number_arguments(dim_style
);
553 g_assert_cmpstr(number_arguments
, ==, valid_text_1
);
555 adg_dim_style_set_number_arguments(dim_style
, "invalid");
556 number_arguments
= adg_dim_style_get_number_arguments(dim_style
);
557 g_assert_cmpstr(number_arguments
, ==, valid_text_1
);
559 adg_dim_style_set_number_arguments(dim_style
, " ");
560 number_arguments
= adg_dim_style_get_number_arguments(dim_style
);
561 g_assert_cmpstr(number_arguments
, ==, valid_text_1
);
563 adg_dim_style_set_number_arguments(dim_style
, valid_text_2
);
564 number_arguments
= adg_dim_style_get_number_arguments(dim_style
);
565 g_assert_cmpstr(number_arguments
, ==, valid_text_2
);
567 adg_dim_style_set_number_arguments(dim_style
, NULL
);
568 number_arguments
= adg_dim_style_get_number_arguments(dim_style
);
569 g_assert_null(number_arguments
);
571 /* Using GObject property methods */
572 g_object_set(dim_style
, "number-arguments", valid_text_1
, NULL
);
573 g_object_get(dim_style
, "number-arguments", &number_arguments_dup
, NULL
);
574 g_assert_cmpstr(number_arguments_dup
, ==, valid_text_1
);
575 g_free(number_arguments_dup
);
577 g_object_set(dim_style
, "number-arguments", "invalid", NULL
);
578 g_object_get(dim_style
, "number-arguments", &number_arguments_dup
, NULL
);
579 g_assert_cmpstr(number_arguments_dup
, ==, valid_text_1
);
580 g_free(number_arguments_dup
);
582 g_object_set(dim_style
, "number-arguments", " ", NULL
);
583 g_object_get(dim_style
, "number-arguments", &number_arguments_dup
, NULL
);
584 g_assert_cmpstr(number_arguments_dup
, ==, valid_text_1
);
585 g_free(number_arguments_dup
);
587 g_object_set(dim_style
, "number-arguments", valid_text_2
, NULL
);
588 g_object_get(dim_style
, "number-arguments", &number_arguments_dup
, NULL
);
589 g_assert_cmpstr(number_arguments_dup
, ==, valid_text_2
);
590 g_free(number_arguments_dup
);
592 g_object_set(dim_style
, "number-arguments", NULL
, NULL
);
593 g_object_get(dim_style
, "number-arguments", &number_arguments_dup
, NULL
);
594 g_assert_null(number_arguments_dup
);
596 g_object_unref(dim_style
);
600 _adg_property_number_tag(void)
602 AdgDimStyle
*dim_style
;
603 const gchar
*valid_text_1
, *valid_text_2
;
604 const gchar
*number_tag
;
605 gchar
*number_tag_dup
;
607 dim_style
= adg_dim_style_new();
609 valid_text_2
= "<è>";
611 /* Check default value */
612 number_tag
= adg_dim_style_get_number_tag(dim_style
);
613 g_assert_cmpstr(number_tag
, ==, "<>");
615 /* Using the public APIs */
616 adg_dim_style_set_number_tag(dim_style
, valid_text_1
);
617 number_tag
= adg_dim_style_get_number_tag(dim_style
);
618 g_assert_cmpstr(number_tag
, ==, valid_text_1
);
620 adg_dim_style_set_number_tag(dim_style
, valid_text_2
);
621 number_tag
= adg_dim_style_get_number_tag(dim_style
);
622 g_assert_cmpstr(number_tag
, ==, valid_text_2
);
624 adg_dim_style_set_number_tag(dim_style
, NULL
);
625 number_tag
= adg_dim_style_get_number_tag(dim_style
);
626 g_assert_null(number_tag
);
628 /* Using GObject property methods */
629 g_object_set(dim_style
, "number-tag", valid_text_1
, NULL
);
630 g_object_get(dim_style
, "number-tag", &number_tag_dup
, NULL
);
631 g_assert_cmpstr(number_tag_dup
, ==, valid_text_1
);
632 g_free(number_tag_dup
);
634 g_object_set(dim_style
, "number-tag", valid_text_2
, NULL
);
635 g_object_get(dim_style
, "number-tag", &number_tag_dup
, NULL
);
636 g_assert_cmpstr(number_tag_dup
, ==, valid_text_2
);
637 g_free(number_tag_dup
);
639 g_object_set(dim_style
, "number-tag", NULL
, NULL
);
640 g_object_get(dim_style
, "number-tag", &number_tag_dup
, NULL
);
641 g_assert_null(number_tag_dup
);
643 g_object_unref(dim_style
);
647 _adg_property_decimals(void)
649 AdgDimStyle
*dim_style
;
652 dim_style
= adg_dim_style_new();
654 /* Check default value */
655 decimals
= adg_dim_style_get_decimals(dim_style
);
656 g_assert_cmpint(decimals
, ==, 2);
658 /* Using the public APIs */
659 adg_dim_style_set_decimals(dim_style
, 4);
660 decimals
= adg_dim_style_get_decimals(dim_style
);
661 g_assert_cmpint(decimals
, ==, 4);
663 adg_dim_style_set_decimals(dim_style
, -2);
664 decimals
= adg_dim_style_get_decimals(dim_style
);
665 g_assert_cmpint(decimals
, ==, 4);
667 decimals
= adg_dim_style_get_decimals(NULL
);
668 g_assert_cmpint(decimals
, ==, -2);
670 adg_dim_style_set_decimals(dim_style
, -1);
671 decimals
= adg_dim_style_get_decimals(dim_style
);
672 g_assert_cmpint(decimals
, ==, -1);
674 /* Using GObject property methods */
675 g_object_set(dim_style
, "decimals", 2, NULL
);
676 g_object_get(dim_style
, "decimals", &decimals
, NULL
);
677 g_assert_cmpint(decimals
, ==, 2);
679 g_object_set(dim_style
, "decimals", -2, NULL
);
680 g_object_get(dim_style
, "decimals", &decimals
, NULL
);
681 g_assert_cmpint(decimals
, ==, 2);
683 g_object_set(dim_style
, "decimals", -1, NULL
);
684 g_object_get(dim_style
, "decimals", &decimals
, NULL
);
685 g_assert_cmpint(decimals
, ==, -1);
687 g_object_unref(dim_style
);
691 _adg_property_quote_shift(void)
693 AdgDimStyle
*dim_style
;
694 CpmlPair null_shift
, identity_shift
;
695 const CpmlPair
*shift
;
698 dim_style
= adg_dim_style_new();
701 identity_shift
.x
= 1;
702 identity_shift
.y
= 1;
704 /* Using the public APIs */
705 adg_dim_style_set_quote_shift(dim_style
, &identity_shift
);
706 shift
= adg_dim_style_get_quote_shift(dim_style
);
707 g_assert_true(cpml_pair_equal(shift
, &identity_shift
));
709 adg_dim_style_set_quote_shift(dim_style
, &null_shift
);
710 shift
= adg_dim_style_get_quote_shift(dim_style
);
711 g_assert_true(cpml_pair_equal(shift
, &null_shift
));
713 adg_dim_style_set_quote_shift(dim_style
, NULL
);
714 shift
= adg_dim_style_get_quote_shift(dim_style
);
715 g_assert_true(cpml_pair_equal(shift
, &null_shift
));
717 /* Using GObject property methods */
718 g_object_set(dim_style
, "quote-shift", &identity_shift
, NULL
);
719 g_object_get(dim_style
, "quote-shift", &shift_dup
, NULL
);
720 g_assert_true(cpml_pair_equal(shift_dup
, &identity_shift
));
723 g_object_set(dim_style
, "quote-shift", NULL
, NULL
);
724 g_object_get(dim_style
, "quote-shift", &shift_dup
, NULL
);
725 g_assert_true(cpml_pair_equal(shift_dup
, &identity_shift
));
728 g_object_set(dim_style
, "quote-shift", &null_shift
, NULL
);
729 g_object_get(dim_style
, "quote-shift", &shift_dup
, NULL
);
730 g_assert_true(cpml_pair_equal(shift_dup
, &null_shift
));
733 g_object_unref(dim_style
);
737 _adg_property_to_offset(void)
739 AdgDimStyle
*dim_style
;
740 gdouble valid_to_offset_1
, valid_to_offset_2
, invalid_to_offset
;
743 dim_style
= adg_dim_style_new();
744 valid_to_offset_1
= 0;
745 valid_to_offset_2
= 999;
746 invalid_to_offset
= -1;
748 /* Using the public APIs */
749 adg_dim_style_set_to_offset(dim_style
, valid_to_offset_1
);
750 to_offset
= adg_dim_style_get_to_offset(dim_style
);
751 adg_assert_isapprox(to_offset
, valid_to_offset_1
);
753 adg_dim_style_set_to_offset(dim_style
, invalid_to_offset
);
754 to_offset
= adg_dim_style_get_to_offset(dim_style
);
755 adg_assert_isapprox(to_offset
, valid_to_offset_1
);
757 adg_dim_style_set_to_offset(dim_style
, valid_to_offset_2
);
758 to_offset
= adg_dim_style_get_to_offset(dim_style
);
759 adg_assert_isapprox(to_offset
, valid_to_offset_2
);
761 /* Using GObject property methods */
762 g_object_set(dim_style
, "to-offset", valid_to_offset_1
, NULL
);
763 g_object_get(dim_style
, "to-offset", &to_offset
, NULL
);
764 adg_assert_isapprox(to_offset
, valid_to_offset_1
);
766 g_object_set(dim_style
, "to-offset", invalid_to_offset
, NULL
);
767 g_object_get(dim_style
, "to-offset", &to_offset
, NULL
);
768 adg_assert_isapprox(to_offset
, valid_to_offset_1
);
770 g_object_set(dim_style
, "to-offset", valid_to_offset_2
, NULL
);
771 g_object_get(dim_style
, "to-offset", &to_offset
, NULL
);
772 adg_assert_isapprox(to_offset
, valid_to_offset_2
);
774 g_object_unref(dim_style
);
778 _adg_property_value_dress(void)
780 AdgDimStyle
*dim_style
;
781 AdgDress valid_dress_1
, valid_dress_2
, incompatible_dress
;
782 AdgDress value_dress
;
784 dim_style
= adg_dim_style_new();
785 valid_dress_1
= ADG_DRESS_FONT
;
786 valid_dress_2
= ADG_DRESS_FONT_QUOTE_ANNOTATION
;
787 incompatible_dress
= ADG_DRESS_FILL_HATCH
;
789 /* Using the public APIs */
790 adg_dim_style_set_value_dress(dim_style
, valid_dress_1
);
791 value_dress
= adg_dim_style_get_value_dress(dim_style
);
792 g_assert_cmpint(value_dress
, ==, valid_dress_1
);
794 adg_dim_style_set_value_dress(dim_style
, incompatible_dress
);
795 value_dress
= adg_dim_style_get_value_dress(dim_style
);
796 g_assert_cmpint(value_dress
, ==, valid_dress_1
);
798 adg_dim_style_set_value_dress(dim_style
, valid_dress_2
);
799 value_dress
= adg_dim_style_get_value_dress(dim_style
);
800 g_assert_cmpint(value_dress
, ==, valid_dress_2
);
802 /* Using GObject property methods */
803 g_object_set(dim_style
, "value-dress", valid_dress_1
, NULL
);
804 g_object_get(dim_style
, "value-dress", &value_dress
, NULL
);
805 g_assert_cmpint(value_dress
, ==, valid_dress_1
);
807 g_object_set(dim_style
, "value-dress", incompatible_dress
, NULL
);
808 g_object_get(dim_style
, "value-dress", &value_dress
, NULL
);
809 g_assert_cmpint(value_dress
, ==, valid_dress_1
);
811 g_object_set(dim_style
, "value-dress", valid_dress_2
, NULL
);
812 g_object_get(dim_style
, "value-dress", &value_dress
, NULL
);
813 g_assert_cmpint(value_dress
, ==, valid_dress_2
);
815 g_object_unref(dim_style
);
819 _adg_method_convert(void)
821 AdgDimStyle
*dim_style
;
824 dim_style
= adg_dim_style_new();
825 adg_dim_style_set_decimals(dim_style
, 0);
828 g_assert_false(adg_dim_style_convert(NULL
, &value
, 'a'));
829 g_assert_false(adg_dim_style_convert(dim_style
, NULL
, 'a'));
830 g_assert_false(adg_dim_style_convert(NULL
, NULL
, 'a'));
832 /* Checking the various conversions. For reference:
833 * - 'a': the raw @value, i.e. no conversion is performed;
834 * - 'i': the raw number of minutes, i.e. the fractional part of @value x 60
835 * - 'e': the raw number of seconds, i.e. the fractional part of the raw
836 * number of minutes x 60
837 * - 'D': the truncated value of the raw value ('a');
838 * - 'd': the rounded value of the raw value ('a');
839 * - 'M': the truncated value of the raw number of minutes ('i');
840 * - 'm': the rounded value of the raw number of minutes ('i');
841 * - 'S': the truncated value of the raw number of seconds ('e');
842 * - 's': the rounded value of the raw number of seconds ('e');
845 g_assert_true(adg_dim_style_convert(dim_style
, &value
, 'a'));
846 adg_assert_isapprox(value
, 5.678);
849 g_assert_true(adg_dim_style_convert(dim_style
, &value
, 'i'));
850 adg_assert_isapprox(value
, 40.68);
853 g_assert_true(adg_dim_style_convert(dim_style
, &value
, 'e'));
854 adg_assert_isapprox(value
, 40.8);
857 g_assert_true(adg_dim_style_convert(dim_style
, &value
, 'D'));
858 adg_assert_isapprox(value
, 5);
861 g_assert_true(adg_dim_style_convert(dim_style
, &value
, 'd'));
862 adg_assert_isapprox(value
, 6);
865 g_assert_true(adg_dim_style_convert(dim_style
, &value
, 'M'));
866 adg_assert_isapprox(value
, 40);
869 g_assert_true(adg_dim_style_convert(dim_style
, &value
, 'm'));
870 adg_assert_isapprox(value
, 41);
873 g_assert_true(adg_dim_style_convert(dim_style
, &value
, 'S'));
874 adg_assert_isapprox(value
, 40);
877 g_assert_true(adg_dim_style_convert(dim_style
, &value
, 's'));
878 adg_assert_isapprox(value
, 41);
880 g_object_unref(dim_style
);
885 main(int argc
, char *argv
[])
887 adg_test_init(&argc
, &argv
);
889 adg_test_add_object_checks("/adg/dim-style/type/object", ADG_TYPE_DIM_STYLE
);
891 g_test_add_func("/adg/dim-style/property/baseline-spacing", _adg_property_baseline_spacing
);
892 g_test_add_func("/adg/dim-style/property/beyond", _adg_property_beyond
);
893 g_test_add_func("/adg/dim-style/property/color-dress", _adg_property_color_dress
);
894 g_test_add_func("/adg/dim-style/property/from-offset", _adg_property_from_offset
);
895 g_test_add_func("/adg/dim-style/property/limits-shift", _adg_property_limits_shift
);
896 g_test_add_func("/adg/dim-style/property/limits-spacing", _adg_property_limits_spacing
);
897 g_test_add_func("/adg/dim-style/property/line-dress", _adg_property_line_dress
);
898 g_test_add_func("/adg/dim-style/property/marker1", _adg_property_marker1
);
899 g_test_add_func("/adg/dim-style/property/marker2", _adg_property_marker2
);
900 g_test_add_func("/adg/dim-style/property/max-dress", _adg_property_max_dress
);
901 g_test_add_func("/adg/dim-style/property/min-dress", _adg_property_min_dress
);
902 g_test_add_func("/adg/dim-style/property/number-format", _adg_property_number_format
);
903 g_test_add_func("/adg/dim-style/property/number-arguments", _adg_property_number_arguments
);
904 g_test_add_func("/adg/dim-style/property/number-tag", _adg_property_number_tag
);
905 g_test_add_func("/adg/dim-style/property/decimals", _adg_property_decimals
);
906 g_test_add_func("/adg/dim-style/property/quote-shift", _adg_property_quote_shift
);
907 g_test_add_func("/adg/dim-style/property/to-offset", _adg_property_to_offset
);
908 g_test_add_func("/adg/dim-style/property/value-dress", _adg_property_value_dress
);
910 g_test_add_func("/adg/dim-style/method/convert", _adg_method_convert
);