1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2010 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"
25 _adg_test_parent(void)
28 AdgEntity
*valid_container
, *invalid_container
;
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 g_object_unref(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 g_object_unref(parent
);
59 g_object_set(entity
, "parent", NULL
, NULL
);
60 g_object_get(entity
, "parent", &parent
, NULL
);
61 g_assert(parent
== NULL
);
63 g_object_unref(entity
);
64 g_object_unref(valid_container
);
68 _adg_test_global_map(void)
71 const AdgMatrix
*identity_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);
83 /* Using the public APIs */
84 adg_entity_set_global_map(entity
, &null_map
);
85 global_map
= adg_entity_get_global_map(entity
);
86 g_assert(adg_matrix_equal(global_map
, &null_map
));
88 adg_entity_set_global_map(entity
, NULL
);
89 global_map
= adg_entity_get_global_map(entity
);
90 g_assert(adg_matrix_equal(global_map
, &null_map
));
92 adg_entity_set_global_map(entity
, identity_map
);
93 global_map
= adg_entity_get_global_map(entity
);
94 g_assert(adg_matrix_equal(global_map
, identity_map
));
96 /* Using GObject property methods */
97 g_object_set(entity
, "global-map", &null_map
, NULL
);
98 g_object_get(entity
, "global-map", &global_map_dup
, NULL
);
99 g_assert(adg_matrix_equal(global_map_dup
, &null_map
));
100 g_free(global_map_dup
);
102 g_object_set(entity
, "global-map", NULL
, NULL
);
103 g_object_get(entity
, "global-map", &global_map_dup
, NULL
);
104 g_assert(adg_matrix_equal(global_map_dup
, &null_map
));
105 g_free(global_map_dup
);
107 g_object_set(entity
, "global-map", identity_map
, NULL
);
108 g_object_get(entity
, "global-map", &global_map_dup
, NULL
);
109 g_assert(adg_matrix_equal(global_map_dup
, identity_map
));
110 g_free(global_map_dup
);
112 g_object_unref(entity
);
116 _adg_test_local_map(void)
119 const AdgMatrix
*identity_map
;
121 const AdgMatrix
*local_map
;
122 AdgMatrix
*local_map_dup
;
124 entity
= ADG_ENTITY(adg_logo_new());
125 identity_map
= adg_matrix_identity();
127 /* A null map is a kind of degenerated matrix: it must be
128 * treated as valid value by the API */
129 cairo_matrix_init(&null_map
, 0, 0, 0, 0, 0, 0);
131 /* Using the public APIs */
132 adg_entity_set_local_map(entity
, &null_map
);
133 local_map
= adg_entity_get_local_map(entity
);
134 g_assert(adg_matrix_equal(local_map
, &null_map
));
136 adg_entity_set_local_map(entity
, NULL
);
137 local_map
= adg_entity_get_local_map(entity
);
138 g_assert(adg_matrix_equal(local_map
, &null_map
));
140 adg_entity_set_local_map(entity
, identity_map
);
141 local_map
= adg_entity_get_local_map(entity
);
142 g_assert(adg_matrix_equal(local_map
, identity_map
));
144 /* Using GObject property methods */
145 g_object_set(entity
, "local-map", &null_map
, NULL
);
146 g_object_get(entity
, "local-map", &local_map_dup
, NULL
);
147 g_assert(adg_matrix_equal(local_map_dup
, &null_map
));
148 g_free(local_map_dup
);
150 g_object_set(entity
, "local-map", NULL
, NULL
);
151 g_object_get(entity
, "local-map", &local_map_dup
, NULL
);
152 g_assert(adg_matrix_equal(local_map_dup
, &null_map
));
153 g_free(local_map_dup
);
155 g_object_set(entity
, "local-map", identity_map
, NULL
);
156 g_object_get(entity
, "local-map", &local_map_dup
, NULL
);
157 g_assert(adg_matrix_equal(local_map_dup
, identity_map
));
158 g_free(local_map_dup
);
160 g_object_unref(entity
);
164 _adg_test_local_method(void)
167 AdgMixMethod valid_method1
, valid_method2
, invalid_method
;
168 AdgMixMethod local_method
;
170 entity
= ADG_ENTITY(adg_logo_new());
171 valid_method1
= ADG_MIX_UNDEFINED
;
172 valid_method2
= ADG_MIX_ANCESTORS_NORMALIZED
;
173 invalid_method
= G_MAXINT
;
175 /* Using the public APIs */
176 adg_entity_set_local_method(entity
, valid_method1
);
177 local_method
= adg_entity_get_local_method(entity
);
178 g_assert_cmpint(local_method
, ==, valid_method1
);
180 adg_entity_set_local_method(entity
, invalid_method
);
181 local_method
= adg_entity_get_local_method(entity
);
182 g_assert_cmpint(local_method
, !=, invalid_method
);
184 adg_entity_set_local_method(entity
, valid_method2
);
185 local_method
= adg_entity_get_local_method(entity
);
186 g_assert_cmpint(local_method
, ==, valid_method2
);
188 /* Using GObject property methods */
189 g_object_set(entity
, "local-method", valid_method1
, NULL
);
190 g_object_get(entity
, "local-method", &local_method
, NULL
);
191 g_assert_cmpint(local_method
, ==, valid_method1
);
193 g_object_set(entity
, "local-method", invalid_method
, NULL
);
194 g_object_get(entity
, "local-method", &local_method
, NULL
);
195 g_assert_cmpint(local_method
, ==, valid_method1
);
197 g_object_set(entity
, "local-method", valid_method2
, NULL
);
198 g_object_get(entity
, "local-method", &local_method
, NULL
);
199 g_assert_cmpint(local_method
, ==, valid_method2
);
201 g_object_unref(entity
);
206 main(int argc
, char *argv
[])
208 adg_test_init(&argc
, &argv
);
210 adg_test_add_func("/adg/entity/parent", _adg_test_parent
);
211 adg_test_add_func("/adg/entity/global-map", _adg_test_global_map
);
212 adg_test_add_func("/adg/entity/local-map", _adg_test_local_map
);
213 adg_test_add_func("/adg/entity/local-method", _adg_test_local_method
);