1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009,2010,2011,2012,2013 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", (CpmlPair
*) explicit_point
);
41 adg_point_set_pair_from_model(model_point
, model
, "named-pair");
43 /* Ensure ADG does not consider an explicit point equals to
44 * a point bound to a named pair with the same coordinates */
45 g_assert(!adg_point_equal(explicit_point
, model_point
));
47 org1
= adg_adim_get_org1(adim
);
48 g_assert(org1
== NULL
);
50 /* Using the public APIs */
51 adg_adim_set_org1_explicit(adim
, 0, 0);
52 org1
= adg_adim_get_org1(adim
);
53 g_assert(adg_point_equal(org1
, origin
));
55 adg_adim_set_org1(adim
, NULL
);
56 org1
= adg_adim_get_org1(adim
);
57 g_assert(org1
== NULL
);
59 adg_adim_set_org1(adim
, explicit_point
);
60 org1
= adg_adim_get_org1(adim
);
61 g_assert(adg_point_equal(org1
, explicit_point
));
63 adg_adim_set_org1_from_model(adim
, model
, "dummy");
64 org1
= adg_adim_get_org1(adim
);
65 g_assert(org1
!= NULL
);
67 adg_adim_set_org1_from_model(adim
, model
, "named-pair");
68 org1
= adg_adim_get_org1(adim
);
69 g_assert(adg_point_equal(org1
, model_point
));
71 /* Using GObject property methods */
72 g_object_set(adim
, "org1", origin
, NULL
);
73 g_object_get(adim
, "org1", &org1
, NULL
);
74 g_assert(adg_point_equal(org1
, origin
));
75 adg_point_destroy(org1
);
77 g_object_set(adim
, "org1", NULL
, NULL
);
78 g_object_get(adim
, "org1", &org1
, NULL
);
79 g_assert(org1
== NULL
);
81 g_object_set(adim
, "org1", explicit_point
, NULL
);
82 g_object_get(adim
, "org1", &org1
, NULL
);
83 g_assert(adg_point_equal(org1
, explicit_point
));
84 adg_point_destroy(org1
);
86 adg_adim_set_org1_from_model(adim
, model
, "dummy");
87 g_object_get(adim
, "org1", &org1
, NULL
);
88 g_assert(org1
!= NULL
);
89 adg_point_destroy(org1
);
91 g_object_set(adim
, "org1", model_point
, NULL
);
92 g_object_get(adim
, "org1", &org1
, NULL
);
93 g_assert(adg_point_equal(org1
, model_point
));
94 adg_point_destroy(org1
);
96 adg_point_destroy(origin
);
97 adg_point_destroy(explicit_point
);
98 adg_point_destroy(model_point
);
99 adg_entity_destroy(ADG_ENTITY(adim
));
100 g_object_unref(model
);
108 AdgPoint
*origin
, *explicit_point
, *model_point
;
111 adim
= adg_adim_new();
112 model
= ADG_MODEL(adg_path_new());
113 origin
= adg_point_new();
114 explicit_point
= adg_point_new();
115 model_point
= adg_point_new();
117 adg_point_set_pair_explicit(origin
, 0, 0);
118 adg_point_set_pair_explicit(explicit_point
, 123, 321);
119 adg_model_set_named_pair(model
, "named-pair", (CpmlPair
*) explicit_point
);
120 adg_point_set_pair_from_model(model_point
, model
, "named-pair");
122 /* Ensure ADG does not consider an explicit point equals to
123 * a point bound to a named pair with the same coordinates */
124 g_assert(!adg_point_equal(explicit_point
, model_point
));
126 org2
= adg_adim_get_org2(adim
);
127 g_assert(org2
== NULL
);
129 /* Using the public APIs */
130 adg_adim_set_org2_explicit(adim
, 0, 0);
131 org2
= adg_adim_get_org2(adim
);
132 g_assert(adg_point_equal(org2
, origin
));
134 adg_adim_set_org2(adim
, NULL
);
135 org2
= adg_adim_get_org2(adim
);
136 g_assert(org2
== NULL
);
138 adg_adim_set_org2(adim
, explicit_point
);
139 org2
= adg_adim_get_org2(adim
);
140 g_assert(adg_point_equal(org2
, explicit_point
));
142 adg_adim_set_org2_from_model(adim
, model
, "dummy");
143 org2
= adg_adim_get_org2(adim
);
144 g_assert(org2
!= NULL
);
146 adg_adim_set_org2_from_model(adim
, model
, "named-pair");
147 org2
= adg_adim_get_org2(adim
);
148 g_assert(adg_point_equal(org2
, model_point
));
150 /* Using GObject property methods */
151 g_object_set(adim
, "org2", origin
, NULL
);
152 g_object_get(adim
, "org2", &org2
, NULL
);
153 g_assert(adg_point_equal(org2
, origin
));
154 adg_point_destroy(org2
);
156 g_object_set(adim
, "org2", NULL
, NULL
);
157 g_object_get(adim
, "org2", &org2
, NULL
);
158 g_assert(org2
== NULL
);
160 g_object_set(adim
, "org2", explicit_point
, NULL
);
161 g_object_get(adim
, "org2", &org2
, NULL
);
162 g_assert(adg_point_equal(org2
, explicit_point
));
163 adg_point_destroy(org2
);
165 adg_adim_set_org2_from_model(adim
, model
, "dummy");
166 g_object_get(adim
, "org2", &org2
, NULL
);
167 g_assert(org2
!= NULL
);
168 adg_point_destroy(org2
);
170 g_object_set(adim
, "org2", model_point
, NULL
);
171 g_object_get(adim
, "org2", &org2
, NULL
);
172 g_assert(adg_point_equal(org2
, model_point
));
173 adg_point_destroy(org2
);
175 adg_point_destroy(origin
);
176 adg_point_destroy(explicit_point
);
177 adg_point_destroy(model_point
);
178 adg_entity_destroy(ADG_ENTITY(adim
));
179 g_object_unref(model
);
183 _adg_test_has_extension1(void)
186 gboolean invalid_boolean
;
187 gboolean has_extension1
;
189 adim
= adg_adim_new();
190 invalid_boolean
= (gboolean
) 1234;
192 /* Using the public APIs */
193 adg_adim_switch_extension1(adim
, FALSE
);
194 has_extension1
= adg_adim_has_extension1(adim
);
195 g_assert(!has_extension1
);
197 adg_adim_switch_extension1(adim
, invalid_boolean
);
198 has_extension1
= adg_adim_has_extension1(adim
);
199 g_assert(!has_extension1
);
201 adg_adim_switch_extension1(adim
, TRUE
);
202 has_extension1
= adg_adim_has_extension1(adim
);
203 g_assert(has_extension1
);
205 /* Using GObject property methods */
206 g_object_set(adim
, "has-extension1", FALSE
, NULL
);
207 g_object_get(adim
, "has-extension1", &has_extension1
, NULL
);
208 g_assert(!has_extension1
);
210 g_object_set(adim
, "has-extension1", invalid_boolean
, NULL
);
211 g_object_get(adim
, "has-extension1", &has_extension1
, NULL
);
212 g_assert(!has_extension1
);
214 g_object_set(adim
, "has-extension1", TRUE
, NULL
);
215 g_object_get(adim
, "has-extension1", &has_extension1
, NULL
);
216 g_assert(has_extension1
);
218 adg_entity_destroy(ADG_ENTITY(adim
));
222 _adg_test_has_extension2(void)
225 gboolean invalid_boolean
;
226 gboolean has_extension2
;
228 adim
= adg_adim_new();
229 invalid_boolean
= (gboolean
) 1234;
231 /* Using the public APIs */
232 adg_adim_switch_extension2(adim
, FALSE
);
233 has_extension2
= adg_adim_has_extension2(adim
);
234 g_assert(!has_extension2
);
236 adg_adim_switch_extension2(adim
, invalid_boolean
);
237 has_extension2
= adg_adim_has_extension2(adim
);
238 g_assert(!has_extension2
);
240 adg_adim_switch_extension2(adim
, TRUE
);
241 has_extension2
= adg_adim_has_extension2(adim
);
242 g_assert(has_extension2
);
244 /* Using GObject property methods */
245 g_object_set(adim
, "has-extension2", FALSE
, NULL
);
246 g_object_get(adim
, "has-extension2", &has_extension2
, NULL
);
247 g_assert(!has_extension2
);
249 g_object_set(adim
, "has-extension2", invalid_boolean
, NULL
);
250 g_object_get(adim
, "has-extension2", &has_extension2
, NULL
);
251 g_assert(!has_extension2
);
253 g_object_set(adim
, "has-extension2", TRUE
, NULL
);
254 g_object_get(adim
, "has-extension2", &has_extension2
, NULL
);
255 g_assert(has_extension2
);
257 adg_entity_destroy(ADG_ENTITY(adim
));
262 main(int argc
, char *argv
[])
264 adg_test_init(&argc
, &argv
);
266 adg_test_add_func("/adg/adim/property/org1", _adg_test_org1
);
267 adg_test_add_func("/adg/adim/property/org2", _adg_test_org2
);
268 adg_test_add_func("/adg/adim/property/has-extension1", _adg_test_has_extension1
);
269 adg_test_add_func("/adg/adim/property/has-extension2", _adg_test_has_extension2
);