1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2010,2011 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 "test-internal.h"
29 AdgPoint
*origin
, *explicit_point
, *model_point
;
32 adim
= adg_adim_new();
33 model
= ADG_MODEL(adg_path_new());
34 origin
= adg_point_new();
35 explicit_point
= adg_point_new();
36 model_point
= adg_point_new();
38 adg_point_set_pair_explicit(origin
, 0, 0);
39 adg_point_set_pair_explicit(explicit_point
, 123, 321);
40 adg_model_set_named_pair(model
, "named-pair",
41 adg_point_get_pair(explicit_point
));
42 adg_point_set_pair_from_model(model_point
, model
, "named-pair");
44 /* Ensure ADG does not consider an explicit point equals to
45 * a point bound to a named pair with the same coordinates */
46 g_assert(!adg_point_equal(explicit_point
, model_point
));
48 org1
= adg_adim_get_org1(adim
);
49 g_assert(org1
== NULL
);
51 /* Using the public APIs */
52 adg_adim_set_org1_explicit(adim
, 0, 0);
53 org1
= adg_adim_get_org1(adim
);
54 g_assert(adg_point_equal(org1
, origin
));
56 adg_adim_set_org1(adim
, NULL
);
57 org1
= adg_adim_get_org1(adim
);
58 g_assert(org1
== NULL
);
60 adg_adim_set_org1(adim
, explicit_point
);
61 org1
= adg_adim_get_org1(adim
);
62 g_assert(adg_point_equal(org1
, explicit_point
));
64 /* Checking the lazy assignment feature */
65 adg_adim_set_org1_from_model(adim
, model
, "dummy");
66 org1
= adg_adim_get_org1(adim
);
67 g_assert(org1
!= NULL
);
68 g_assert(adg_point_get_pair(org1
) == NULL
);
70 adg_adim_set_org1_from_model(adim
, model
, "named-pair");
71 org1
= adg_adim_get_org1(adim
);
72 g_assert(adg_point_equal(org1
, model_point
));
74 /* Using GObject property methods */
75 g_object_set(adim
, "org1", origin
, NULL
);
76 g_object_get(adim
, "org1", &org1
, NULL
);
77 g_assert(adg_point_equal(org1
, origin
));
78 adg_point_destroy(org1
);
80 g_object_set(adim
, "org1", NULL
, NULL
);
81 g_object_get(adim
, "org1", &org1
, NULL
);
82 g_assert(org1
== NULL
);
84 g_object_set(adim
, "org1", explicit_point
, NULL
);
85 g_object_get(adim
, "org1", &org1
, NULL
);
86 g_assert(adg_point_equal(org1
, explicit_point
));
87 adg_point_destroy(org1
);
89 /* Checking the lazy assignment feature */
90 adg_adim_set_org1_from_model(adim
, model
, "dummy");
91 g_object_get(adim
, "org1", &org1
, NULL
);
92 g_assert(org1
!= NULL
);
93 g_assert(adg_point_get_pair(org1
) == NULL
);
94 adg_point_destroy(org1
);
96 g_object_set(adim
, "org1", model_point
, NULL
);
97 g_object_get(adim
, "org1", &org1
, NULL
);
98 g_assert(adg_point_equal(org1
, model_point
));
99 adg_point_destroy(org1
);
101 adg_point_destroy(origin
);
102 adg_point_destroy(explicit_point
);
103 adg_point_destroy(model_point
);
104 adg_entity_destroy(ADG_ENTITY(adim
));
105 g_object_unref(model
);
113 AdgPoint
*origin
, *explicit_point
, *model_point
;
116 adim
= adg_adim_new();
117 model
= ADG_MODEL(adg_path_new());
118 origin
= adg_point_new();
119 explicit_point
= adg_point_new();
120 model_point
= adg_point_new();
122 adg_point_set_pair_explicit(origin
, 0, 0);
123 adg_point_set_pair_explicit(explicit_point
, 123, 321);
124 adg_model_set_named_pair(model
, "named-pair",
125 adg_point_get_pair(explicit_point
));
126 adg_point_set_pair_from_model(model_point
, model
, "named-pair");
128 /* Ensure ADG does not consider an explicit point equals to
129 * a point bound to a named pair with the same coordinates */
130 g_assert(!adg_point_equal(explicit_point
, model_point
));
132 org2
= adg_adim_get_org2(adim
);
133 g_assert(org2
== NULL
);
135 /* Using the public APIs */
136 adg_adim_set_org2_explicit(adim
, 0, 0);
137 org2
= adg_adim_get_org2(adim
);
138 g_assert(adg_point_equal(org2
, origin
));
140 adg_adim_set_org2(adim
, NULL
);
141 org2
= adg_adim_get_org2(adim
);
142 g_assert(org2
== NULL
);
144 adg_adim_set_org2(adim
, explicit_point
);
145 org2
= adg_adim_get_org2(adim
);
146 g_assert(adg_point_equal(org2
, explicit_point
));
148 /* Checking the lazy assignment feature */
149 adg_adim_set_org2_from_model(adim
, model
, "dummy");
150 org2
= adg_adim_get_org2(adim
);
151 g_assert(org2
!= NULL
);
152 g_assert(adg_point_get_pair(org2
) == NULL
);
154 adg_adim_set_org2_from_model(adim
, model
, "named-pair");
155 org2
= adg_adim_get_org2(adim
);
156 g_assert(adg_point_equal(org2
, model_point
));
158 /* Using GObject property methods */
159 g_object_set(adim
, "org2", origin
, NULL
);
160 g_object_get(adim
, "org2", &org2
, NULL
);
161 g_assert(adg_point_equal(org2
, origin
));
162 adg_point_destroy(org2
);
164 g_object_set(adim
, "org2", NULL
, NULL
);
165 g_object_get(adim
, "org2", &org2
, NULL
);
166 g_assert(org2
== NULL
);
168 g_object_set(adim
, "org2", explicit_point
, NULL
);
169 g_object_get(adim
, "org2", &org2
, NULL
);
170 g_assert(adg_point_equal(org2
, explicit_point
));
171 adg_point_destroy(org2
);
173 /* Checking the lazy assignment feature */
174 adg_adim_set_org2_from_model(adim
, model
, "dummy");
175 g_object_get(adim
, "org2", &org2
, NULL
);
176 g_assert(org2
!= NULL
);
177 g_assert(adg_point_get_pair(org2
) == NULL
);
178 adg_point_destroy(org2
);
180 g_object_set(adim
, "org2", model_point
, NULL
);
181 g_object_get(adim
, "org2", &org2
, NULL
);
182 g_assert(adg_point_equal(org2
, model_point
));
183 adg_point_destroy(org2
);
185 adg_point_destroy(origin
);
186 adg_point_destroy(explicit_point
);
187 adg_point_destroy(model_point
);
188 adg_entity_destroy(ADG_ENTITY(adim
));
189 g_object_unref(model
);
193 _adg_test_has_extension1(void)
196 gboolean invalid_boolean
;
197 gboolean has_extension1
;
199 adim
= adg_adim_new();
200 invalid_boolean
= (gboolean
) 1234;
202 /* Using the public APIs */
203 adg_adim_switch_extension1(adim
, FALSE
);
204 has_extension1
= adg_adim_has_extension1(adim
);
205 g_assert(!has_extension1
);
207 adg_adim_switch_extension1(adim
, invalid_boolean
);
208 has_extension1
= adg_adim_has_extension1(adim
);
209 g_assert(!has_extension1
);
211 adg_adim_switch_extension1(adim
, TRUE
);
212 has_extension1
= adg_adim_has_extension1(adim
);
213 g_assert(has_extension1
);
215 /* Using GObject property methods */
216 g_object_set(adim
, "has-extension1", FALSE
, NULL
);
217 g_object_get(adim
, "has-extension1", &has_extension1
, NULL
);
218 g_assert(!has_extension1
);
220 g_object_set(adim
, "has-extension1", invalid_boolean
, NULL
);
221 g_object_get(adim
, "has-extension1", &has_extension1
, NULL
);
222 g_assert(!has_extension1
);
224 g_object_set(adim
, "has-extension1", TRUE
, NULL
);
225 g_object_get(adim
, "has-extension1", &has_extension1
, NULL
);
226 g_assert(has_extension1
);
228 adg_entity_destroy(ADG_ENTITY(adim
));
232 _adg_test_has_extension2(void)
235 gboolean invalid_boolean
;
236 gboolean has_extension2
;
238 adim
= adg_adim_new();
239 invalid_boolean
= (gboolean
) 1234;
241 /* Using the public APIs */
242 adg_adim_switch_extension2(adim
, FALSE
);
243 has_extension2
= adg_adim_has_extension2(adim
);
244 g_assert(!has_extension2
);
246 adg_adim_switch_extension2(adim
, invalid_boolean
);
247 has_extension2
= adg_adim_has_extension2(adim
);
248 g_assert(!has_extension2
);
250 adg_adim_switch_extension2(adim
, TRUE
);
251 has_extension2
= adg_adim_has_extension2(adim
);
252 g_assert(has_extension2
);
254 /* Using GObject property methods */
255 g_object_set(adim
, "has-extension2", FALSE
, NULL
);
256 g_object_get(adim
, "has-extension2", &has_extension2
, NULL
);
257 g_assert(!has_extension2
);
259 g_object_set(adim
, "has-extension2", invalid_boolean
, NULL
);
260 g_object_get(adim
, "has-extension2", &has_extension2
, NULL
);
261 g_assert(!has_extension2
);
263 g_object_set(adim
, "has-extension2", TRUE
, NULL
);
264 g_object_get(adim
, "has-extension2", &has_extension2
, NULL
);
265 g_assert(has_extension2
);
267 adg_entity_destroy(ADG_ENTITY(adim
));
272 main(int argc
, char *argv
[])
274 adg_test_init(&argc
, &argv
);
276 adg_test_add_func("/adg/adim/property/org1", _adg_test_org1
);
277 adg_test_add_func("/adg/adim/property/org2", _adg_test_org2
);
278 adg_test_add_func("/adg/adim/property/has-extension1", _adg_test_has_extension1
);
279 adg_test_add_func("/adg/adim/property/has-extension2", _adg_test_has_extension2
);