doc: update copyright line for 2021
[adg.git] / src / adg / tests / test-dash.c
blobc9720ecfe35c76fd0a3041008415f4441cfbdaf4
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_dashes(void)
28 AdgDash *dash;
29 gint num_dashes;
30 const gdouble *dashes;
31 const gdouble dashes_array[] = { 1., 2., 3. };
33 dash = adg_dash_new();
34 g_assert_nonnull(dash);
35 num_dashes = adg_dash_get_num_dashes(dash);
36 g_assert_cmpint(num_dashes, ==, 0);
37 dashes = adg_dash_get_dashes(dash);
38 g_assert_null(dashes);
40 adg_dash_append_dash(dash, 1234.);
41 num_dashes = adg_dash_get_num_dashes(dash);
42 g_assert_cmpint(num_dashes, ==, 1);
43 dashes = adg_dash_get_dashes(dash);
44 g_assert_nonnull(dashes);
45 adg_assert_isapprox(dashes[0], 1234.);
47 adg_dash_append_dashes(dash, 2, 0., 4321.);
48 num_dashes = adg_dash_get_num_dashes(dash);
49 g_assert_cmpint(num_dashes, ==, 3);
50 dashes = adg_dash_get_dashes(dash);
51 g_assert_nonnull(dashes);
52 adg_assert_isapprox(dashes[0], 1234.);
53 adg_assert_isapprox(dashes[1], 0.);
54 adg_assert_isapprox(dashes[2], 4321.);
56 adg_dash_clear_dashes(dash);
57 num_dashes = adg_dash_get_num_dashes(dash);
58 g_assert_cmpint(num_dashes, ==, 0);
59 dashes = adg_dash_get_dashes(dash);
60 g_assert_null(dashes);
62 adg_dash_append_dashes_array(dash, 3, dashes_array);
63 num_dashes = adg_dash_get_num_dashes(dash);
64 g_assert_cmpint(num_dashes, ==, 3);
65 dashes = adg_dash_get_dashes(dash);
66 g_assert_nonnull(dashes);
67 adg_assert_isapprox(dashes[0], 1.);
68 adg_assert_isapprox(dashes[1], 2.);
69 adg_assert_isapprox(dashes[2], 3.);
71 adg_dash_destroy(dash);
73 dash = adg_dash_new_with_dashes(3, 1., 2., 3.);
74 g_assert_nonnull(dash);
75 num_dashes = adg_dash_get_num_dashes(dash);
76 g_assert_cmpint(num_dashes, ==, 3);
77 dashes = adg_dash_get_dashes(dash);
78 g_assert_nonnull(dashes);
79 adg_assert_isapprox(dashes[0], 1.);
80 adg_assert_isapprox(dashes[1], 2.);
81 adg_assert_isapprox(dashes[2], 3.);
83 adg_dash_destroy(dash);
86 static void
87 _adg_property_offset(void)
89 AdgDash *dash;
90 gdouble offset;
92 dash = adg_dash_new();
94 /* Ensure the default is 0 */
95 offset = adg_dash_get_offset(dash);
96 adg_assert_isapprox(offset, 0);
98 /* Check some special values */
99 adg_dash_set_offset(dash, G_MINDOUBLE);
100 offset = adg_dash_get_offset(dash);
101 g_assert_cmpfloat(offset, ==, G_MINDOUBLE);
103 adg_dash_set_offset(dash, G_MAXDOUBLE);
104 offset = adg_dash_get_offset(dash);
105 g_assert_cmpfloat(offset, ==, G_MAXDOUBLE);
107 adg_dash_set_offset(dash, 0);
108 offset = adg_dash_get_offset(dash);
109 adg_assert_isapprox(offset, 0);
111 adg_dash_destroy(dash);
116 main(int argc, char *argv[])
118 adg_test_init(&argc, &argv);
120 adg_test_add_boxed_checks("/adg/dash/type/boxed", ADG_TYPE_DASH, adg_dash_new());
122 g_test_add_func("/adg/dash/property/dashes", _adg_property_dashes);
123 g_test_add_func("/adg/dash/property/offset", _adg_property_offset);
125 return g_test_run();