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
);
53 g_object_set(entity
, "parent", invalid_container
, NULL
);
54 g_object_get(entity
, "parent", &parent
, NULL
);
55 g_assert(parent
== valid_container
);
57 g_object_set(entity
, "parent", NULL
, NULL
);
58 g_object_get(entity
, "parent", &parent
, NULL
);
59 g_assert(parent
== NULL
);
61 g_object_unref(entity
);
62 g_object_unref(valid_container
);
66 _adg_test_global_map(void)
69 const AdgMatrix
*identity_map
;
71 const AdgMatrix
*global_map
;
73 entity
= ADG_ENTITY(adg_logo_new());
74 identity_map
= adg_matrix_identity();
76 /* A null map is a kind of degenerated matrix: it must be
77 * treated as valid value by the API */
78 cairo_matrix_init(&null_map
, 0, 0, 0, 0, 0, 0);
80 /* Using the public APIs */
81 adg_entity_set_global_map(entity
, &null_map
);
82 global_map
= adg_entity_get_global_map(entity
);
83 g_assert(adg_matrix_equal(global_map
, &null_map
));
85 adg_entity_set_global_map(entity
, NULL
);
86 global_map
= adg_entity_get_global_map(entity
);
87 g_assert(adg_matrix_equal(global_map
, &null_map
));
89 adg_entity_set_global_map(entity
, identity_map
);
90 global_map
= adg_entity_get_global_map(entity
);
91 g_assert(adg_matrix_equal(global_map
, identity_map
));
93 /* Using GObject property methods */
94 g_object_set(entity
, "global-map", &null_map
, NULL
);
95 g_object_get(entity
, "global-map", &global_map
, NULL
);
96 g_assert(adg_matrix_equal(global_map
, &null_map
));
98 g_object_set(entity
, "global-map", NULL
, NULL
);
99 g_object_get(entity
, "global-map", &global_map
, NULL
);
100 g_assert(adg_matrix_equal(global_map
, &null_map
));
102 g_object_set(entity
, "global-map", identity_map
, NULL
);
103 g_object_get(entity
, "global-map", &global_map
, NULL
);
104 g_assert(adg_matrix_equal(global_map
, identity_map
));
106 g_object_unref(entity
);
110 _adg_test_local_map(void)
113 const AdgMatrix
*identity_map
;
115 const AdgMatrix
*local_map
;
117 entity
= ADG_ENTITY(adg_logo_new());
118 identity_map
= adg_matrix_identity();
120 /* A null map is a kind of degenerated matrix: it must be
121 * treated as valid value by the API */
122 cairo_matrix_init(&null_map
, 0, 0, 0, 0, 0, 0);
124 /* Using the public APIs */
125 adg_entity_set_local_map(entity
, &null_map
);
126 local_map
= adg_entity_get_local_map(entity
);
127 g_assert(adg_matrix_equal(local_map
, &null_map
));
129 adg_entity_set_local_map(entity
, NULL
);
130 local_map
= adg_entity_get_local_map(entity
);
131 g_assert(adg_matrix_equal(local_map
, &null_map
));
133 adg_entity_set_local_map(entity
, identity_map
);
134 local_map
= adg_entity_get_local_map(entity
);
135 g_assert(adg_matrix_equal(local_map
, identity_map
));
137 /* Using GObject property methods */
138 g_object_set(entity
, "local-map", &null_map
, NULL
);
139 g_object_get(entity
, "local-map", &local_map
, NULL
);
140 g_assert(adg_matrix_equal(local_map
, &null_map
));
142 g_object_set(entity
, "local-map", NULL
, NULL
);
143 g_object_get(entity
, "local-map", &local_map
, NULL
);
144 g_assert(adg_matrix_equal(local_map
, &null_map
));
146 g_object_set(entity
, "local-map", identity_map
, NULL
);
147 g_object_get(entity
, "local-map", &local_map
, NULL
);
148 g_assert(adg_matrix_equal(local_map
, identity_map
));
150 g_object_unref(entity
);
154 _adg_test_local_method(void)
157 AdgMixMethod valid_method1
, valid_method2
, invalid_method
;
158 AdgMixMethod local_method
;
160 entity
= ADG_ENTITY(adg_logo_new());
161 valid_method1
= ADG_MIX_UNDEFINED
;
162 valid_method2
= ADG_MIX_ANCESTORS_NORMALIZED
;
163 invalid_method
= G_MAXINT
;
165 /* Using the public APIs */
166 adg_entity_set_local_method(entity
, valid_method1
);
167 local_method
= adg_entity_get_local_method(entity
);
168 g_assert_cmpint(local_method
, ==, valid_method1
);
170 adg_entity_set_local_method(entity
, invalid_method
);
171 local_method
= adg_entity_get_local_method(entity
);
172 g_assert_cmpint(local_method
, !=, invalid_method
);
174 adg_entity_set_local_method(entity
, valid_method2
);
175 local_method
= adg_entity_get_local_method(entity
);
176 g_assert_cmpint(local_method
, ==, valid_method2
);
178 /* Using GObject property methods */
179 g_object_set(entity
, "local-method", valid_method1
, NULL
);
180 g_object_get(entity
, "local-method", &local_method
, NULL
);
181 g_assert_cmpint(local_method
, ==, valid_method1
);
183 g_object_set(entity
, "local-method", invalid_method
, NULL
);
184 g_object_get(entity
, "local-method", &local_method
, NULL
);
185 g_assert_cmpint(local_method
, ==, valid_method1
);
187 g_object_set(entity
, "local-method", valid_method2
, NULL
);
188 g_object_get(entity
, "local-method", &local_method
, NULL
);
189 g_assert_cmpint(local_method
, ==, valid_method2
);
191 g_object_unref(entity
);
196 main(int argc
, char *argv
[])
198 adg_test_init(&argc
, &argv
);
200 adg_test_add_func("/adg/entity/parent", _adg_test_parent
);
201 adg_test_add_func("/adg/entity/global-map", _adg_test_global_map
);
202 adg_test_add_func("/adg/entity/local-map", _adg_test_local_map
);
203 adg_test_add_func("/adg/entity/local-method", _adg_test_local_method
);