AdgEntity: added "destroy" signal
[adg.git] / src / adg / tests / test-entity.c
blobef1eb4714edfae1749d92e06eb08b9b9bbe9e899
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"
24 static void
25 _adg_test_parent(void)
27 AdgEntity *entity;
28 AdgEntity *valid_container, *invalid_container;
29 AdgEntity *parent;
31 entity = ADG_ENTITY(adg_logo_new());
32 valid_container = ADG_ENTITY(adg_container_new());
33 invalid_container = adg_test_invalid_pointer();
35 /* Using the public APIs */
36 adg_entity_set_parent(entity, valid_container);
37 parent = adg_entity_get_parent(entity);
38 g_assert(parent == valid_container);
40 adg_entity_set_parent(entity, invalid_container);
41 parent = adg_entity_get_parent(entity);
42 g_assert(parent == valid_container);
44 adg_entity_set_parent(entity, NULL);
45 parent = adg_entity_get_parent(entity);
46 g_assert(parent == NULL);
48 /* Using GObject property methods */
49 g_object_set(entity, "parent", valid_container, NULL);
50 g_object_get(entity, "parent", &parent, NULL);
51 g_assert(parent == valid_container);
52 adg_entity_destroy(parent);
54 g_object_set(entity, "parent", invalid_container, NULL);
55 g_object_get(entity, "parent", &parent, NULL);
56 g_assert(parent == valid_container);
57 adg_entity_destroy(parent);
59 g_object_set(entity, "parent", NULL, NULL);
60 g_object_get(entity, "parent", &parent, NULL);
61 g_assert(parent == NULL);
63 adg_entity_destroy(entity);
64 adg_entity_destroy(valid_container);
67 static void
68 _adg_test_global_map(void)
70 AdgEntity *entity;
71 const AdgMatrix *identity_map;
72 AdgMatrix null_map, dummy_map;
73 const AdgMatrix *global_map;
74 AdgMatrix *global_map_dup;
76 entity = ADG_ENTITY(adg_logo_new());
77 identity_map = adg_matrix_identity();
79 /* A null map is a kind of degenerated matrix: it must be
80 * treated as valid value by the API */
81 cairo_matrix_init(&null_map, 0, 0, 0, 0, 0, 0);
82 /* A general purpose map value without translations */
83 cairo_matrix_init(&dummy_map, 1, 2, 3, 4, 0, 0);
85 /* Using the public APIs */
86 adg_entity_set_global_map(entity, &null_map);
87 global_map = adg_entity_get_global_map(entity);
88 g_assert(adg_matrix_equal(global_map, &null_map));
90 adg_entity_transform_global_map(entity, &dummy_map, ADG_TRANSFORM_AFTER);
91 global_map = adg_entity_get_global_map(entity);
92 g_assert(adg_matrix_equal(global_map, &null_map));
94 adg_entity_set_global_map(entity, identity_map);
95 global_map = adg_entity_get_global_map(entity);
96 g_assert(adg_matrix_equal(global_map, identity_map));
98 adg_entity_set_global_map(entity, NULL);
99 global_map = adg_entity_get_global_map(entity);
100 g_assert(adg_matrix_equal(global_map, identity_map));
102 adg_entity_transform_global_map(entity, &dummy_map, ADG_TRANSFORM_BEFORE);
103 global_map = adg_entity_get_global_map(entity);
104 g_assert(adg_matrix_equal(global_map, &dummy_map));
106 /* Using GObject property methods */
107 g_object_set(entity, "global-map", &null_map, NULL);
108 g_object_get(entity, "global-map", &global_map_dup, NULL);
109 g_assert(adg_matrix_equal(global_map_dup, &null_map));
110 g_free(global_map_dup);
112 g_object_set(entity, "global-map", NULL, NULL);
113 g_object_get(entity, "global-map", &global_map_dup, NULL);
114 g_assert(adg_matrix_equal(global_map_dup, &null_map));
115 g_free(global_map_dup);
117 g_object_set(entity, "global-map", identity_map, NULL);
118 g_object_get(entity, "global-map", &global_map_dup, NULL);
119 g_assert(adg_matrix_equal(global_map_dup, identity_map));
120 g_free(global_map_dup);
122 adg_entity_destroy(entity);
125 static void
126 _adg_test_local_map(void)
128 AdgEntity *entity;
129 const AdgMatrix *identity_map;
130 AdgMatrix null_map, dummy_map;
131 const AdgMatrix *local_map;
132 AdgMatrix *local_map_dup;
134 entity = ADG_ENTITY(adg_logo_new());
135 identity_map = adg_matrix_identity();
137 /* A null map is a kind of degenerated matrix: it must be
138 * treated as valid value by the API */
139 cairo_matrix_init(&null_map, 0, 0, 0, 0, 0, 0);
140 /* A general purpose map value without translations */
141 cairo_matrix_init(&dummy_map, 1, 2, 3, 4, 0, 0);
143 /* Using the public APIs */
144 adg_entity_set_local_map(entity, &null_map);
145 local_map = adg_entity_get_local_map(entity);
146 g_assert(adg_matrix_equal(local_map, &null_map));
148 adg_entity_transform_local_map(entity, &dummy_map, ADG_TRANSFORM_AFTER);
149 local_map = adg_entity_get_local_map(entity);
150 g_assert(adg_matrix_equal(local_map, &null_map));
152 adg_entity_set_local_map(entity, identity_map);
153 local_map = adg_entity_get_local_map(entity);
154 g_assert(adg_matrix_equal(local_map, identity_map));
156 adg_entity_set_local_map(entity, NULL);
157 local_map = adg_entity_get_local_map(entity);
158 g_assert(adg_matrix_equal(local_map, identity_map));
160 adg_entity_transform_local_map(entity, &dummy_map, ADG_TRANSFORM_BEFORE);
161 local_map = adg_entity_get_local_map(entity);
162 g_assert(adg_matrix_equal(local_map, &dummy_map));
164 /* Using GObject property methods */
165 g_object_set(entity, "local-map", &null_map, NULL);
166 g_object_get(entity, "local-map", &local_map_dup, NULL);
167 g_assert(adg_matrix_equal(local_map_dup, &null_map));
168 g_free(local_map_dup);
170 g_object_set(entity, "local-map", NULL, NULL);
171 g_object_get(entity, "local-map", &local_map_dup, NULL);
172 g_assert(adg_matrix_equal(local_map_dup, &null_map));
173 g_free(local_map_dup);
175 g_object_set(entity, "local-map", identity_map, NULL);
176 g_object_get(entity, "local-map", &local_map_dup, NULL);
177 g_assert(adg_matrix_equal(local_map_dup, identity_map));
178 g_free(local_map_dup);
180 adg_entity_destroy(entity);
183 static void
184 _adg_test_local_method(void)
186 AdgEntity *entity;
187 AdgMixMethod valid_method1, valid_method2, invalid_method;
188 AdgMixMethod local_method;
190 entity = ADG_ENTITY(adg_logo_new());
191 valid_method1 = ADG_MIX_UNDEFINED;
192 valid_method2 = ADG_MIX_ANCESTORS_NORMALIZED;
193 invalid_method = G_MAXINT;
195 /* Using the public APIs */
196 adg_entity_set_local_method(entity, valid_method1);
197 local_method = adg_entity_get_local_method(entity);
198 g_assert_cmpint(local_method, ==, valid_method1);
200 adg_entity_set_local_method(entity, invalid_method);
201 local_method = adg_entity_get_local_method(entity);
202 g_assert_cmpint(local_method, !=, invalid_method);
204 adg_entity_set_local_method(entity, valid_method2);
205 local_method = adg_entity_get_local_method(entity);
206 g_assert_cmpint(local_method, ==, valid_method2);
208 /* Using GObject property methods */
209 g_object_set(entity, "local-method", valid_method1, NULL);
210 g_object_get(entity, "local-method", &local_method, NULL);
211 g_assert_cmpint(local_method, ==, valid_method1);
213 g_object_set(entity, "local-method", invalid_method, NULL);
214 g_object_get(entity, "local-method", &local_method, NULL);
215 g_assert_cmpint(local_method, ==, valid_method1);
217 g_object_set(entity, "local-method", valid_method2, NULL);
218 g_object_get(entity, "local-method", &local_method, NULL);
219 g_assert_cmpint(local_method, ==, valid_method2);
221 adg_entity_destroy(entity);
226 main(int argc, char *argv[])
228 adg_test_init(&argc, &argv);
230 adg_test_add_func("/adg/entity/parent", _adg_test_parent);
231 adg_test_add_func("/adg/entity/global-map", _adg_test_global_map);
232 adg_test_add_func("/adg/entity/local-map", _adg_test_local_map);
233 adg_test_add_func("/adg/entity/local-method", _adg_test_local_method);
235 return g_test_run();