doc: update copyright line for 2021
[adg.git] / src / adg / tests / test-ldim.c
blobf87f31106421b8b38b440f20065334e095db7f77
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_direction(void)
28 AdgLDim *ldim;
29 gdouble valid_value, invalid_value;
30 gdouble direction;
32 ldim = adg_ldim_new();
33 valid_value = -G_PI_2;
34 invalid_value = G_PI + 1;
36 /* Using the public APIs */
37 adg_ldim_set_direction(ldim, valid_value);
38 direction = adg_ldim_get_direction(ldim);
39 adg_assert_isapprox(direction, valid_value);
41 adg_ldim_set_direction(ldim, -G_PI);
42 direction = adg_ldim_get_direction(ldim);
43 adg_assert_isapprox(direction, G_PI);
45 adg_ldim_set_direction(ldim, invalid_value);
46 direction = adg_ldim_get_direction(ldim);
47 g_assert_cmpfloat(direction, !=, invalid_value);
49 /* Using GObject property methods */
50 g_object_set(ldim, "direction", valid_value, NULL);
51 g_object_get(ldim, "direction", &direction, NULL);
52 adg_assert_isapprox(direction, valid_value);
54 g_object_set(ldim, "direction", -G_PI, NULL);
55 g_object_get(ldim, "direction", &direction, NULL);
56 adg_assert_isapprox(direction, G_PI);
58 g_object_set(ldim, "direction", invalid_value, NULL);
59 g_object_get(ldim, "direction", &direction, NULL);
60 g_assert_cmpfloat(direction, !=, invalid_value);
62 adg_entity_destroy(ADG_ENTITY(ldim));
64 /* Checking constructors */
65 ldim = adg_ldim_new();
66 direction = adg_ldim_get_direction(ldim);
67 adg_assert_isapprox(direction, ADG_DIR_RIGHT);
68 adg_entity_destroy(ADG_ENTITY(ldim));
70 ldim = adg_ldim_new_full(NULL, NULL, NULL, 2);
71 direction = adg_ldim_get_direction(ldim);
72 adg_assert_isapprox(direction, 2);
73 adg_entity_destroy(ADG_ENTITY(ldim));
75 ldim = adg_ldim_new_full_explicit(0, 1,
76 2, 3,
77 4, 5,
78 3);
79 direction = adg_ldim_get_direction(ldim);
80 adg_assert_isapprox(direction, 3);
81 adg_entity_destroy(ADG_ENTITY(ldim));
84 static void
85 _adg_property_has_extension1(void)
87 AdgLDim *ldim;
88 gboolean invalid_boolean;
89 gboolean has_extension1;
91 ldim = adg_ldim_new();
92 invalid_boolean = (gboolean) 1234;
94 /* Using the public APIs */
95 adg_ldim_switch_extension1(ldim, FALSE);
96 has_extension1 = adg_ldim_has_extension1(ldim);
97 g_assert_false(has_extension1);
99 adg_ldim_switch_extension1(ldim, invalid_boolean);
100 has_extension1 = adg_ldim_has_extension1(ldim);
101 g_assert_false(has_extension1);
103 adg_ldim_switch_extension1(ldim, TRUE);
104 has_extension1 = adg_ldim_has_extension1(ldim);
105 g_assert_true(has_extension1);
107 /* Using GObject property methods */
108 g_object_set(ldim, "has-extension1", FALSE, NULL);
109 g_object_get(ldim, "has-extension1", &has_extension1, NULL);
110 g_assert_false(has_extension1);
112 g_object_set(ldim, "has-extension1", invalid_boolean, NULL);
113 g_object_get(ldim, "has-extension1", &has_extension1, NULL);
114 g_assert_false(has_extension1);
116 g_object_set(ldim, "has-extension1", TRUE, NULL);
117 g_object_get(ldim, "has-extension1", &has_extension1, NULL);
118 g_assert_true(has_extension1);
120 adg_entity_destroy(ADG_ENTITY(ldim));
123 static void
124 _adg_property_has_extension2(void)
126 AdgLDim *ldim;
127 gboolean invalid_boolean;
128 gboolean has_extension2;
130 ldim = adg_ldim_new();
131 invalid_boolean = (gboolean) 1234;
133 /* Using the public APIs */
134 adg_ldim_switch_extension2(ldim, FALSE);
135 has_extension2 = adg_ldim_has_extension2(ldim);
136 g_assert_false(has_extension2);
138 adg_ldim_switch_extension2(ldim, invalid_boolean);
139 has_extension2 = adg_ldim_has_extension2(ldim);
140 g_assert_false(has_extension2);
142 adg_ldim_switch_extension2(ldim, TRUE);
143 has_extension2 = adg_ldim_has_extension2(ldim);
144 g_assert_true(has_extension2);
146 /* Using GObject property methods */
147 g_object_set(ldim, "has-extension2", FALSE, NULL);
148 g_object_get(ldim, "has-extension2", &has_extension2, NULL);
149 g_assert_false(has_extension2);
151 g_object_set(ldim, "has-extension2", invalid_boolean, NULL);
152 g_object_get(ldim, "has-extension2", &has_extension2, NULL);
153 g_assert_false(has_extension2);
155 g_object_set(ldim, "has-extension2", TRUE, NULL);
156 g_object_get(ldim, "has-extension2", &has_extension2, NULL);
157 g_assert_true(has_extension2);
159 adg_entity_destroy(ADG_ENTITY(ldim));
164 main(int argc, char *argv[])
166 adg_test_init(&argc, &argv);
168 adg_test_add_object_checks("/adg/ldim/type/object", ADG_TYPE_LDIM);
169 adg_test_add_entity_checks("/adg/ldim/type/entity", ADG_TYPE_LDIM);
171 /* Linear dimensions does not properly scale on global space
172 * adg_test_add_global_space_checks("/adg/ldim/behavior/global-space",
173 * adg_ldim_new_full_explicit(1, 5,
174 * 2, 4,
175 * 9, 7,
176 * ADG_DIR_UP));
178 adg_test_add_local_space_checks("/adg/ldim/behavior/local-space",
179 adg_ldim_new_full_explicit(1, 5,
180 2, 4,
181 9, 7,
182 ADG_DIR_UP));
184 g_test_add_func("/adg/ldim/property/direction", _adg_property_direction);
185 g_test_add_func("/adg/ldim/property/has-extension1", _adg_property_has_extension1);
186 g_test_add_func("/adg/ldim/property/has-extension2", _adg_property_has_extension2);
188 return g_test_run();