Debian Codegraph @

tests/conform/actor-invariants.c

raw
1 #include <stdlib.h>
2 #include <string.h>
3
4 #define CLUTTER_DISABLE_DEPRECATION_WARNINGS
5 #include <clutter/clutter.h>
6
7 static void
8 actor_initial_state (void)
9 {
10 ClutterActor *actor;
11
12 actor = clutter_actor_new ();
13 g_object_ref_sink (actor);
14 g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor);
15
16 if (g_test_verbose ())
17 g_print ("initial state - visible: %s, realized: %s, mapped: %s\n",
18 CLUTTER_ACTOR_IS_VISIBLE (actor) ? "yes" : "no",
19 CLUTTER_ACTOR_IS_REALIZED (actor) ? "yes" : "no",
20 CLUTTER_ACTOR_IS_MAPPED (actor) ? "yes" : "no");
21
22 g_assert (!(CLUTTER_ACTOR_IS_REALIZED (actor)));
23 g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor)));
24 g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor)));
25
26 clutter_actor_destroy (actor);
27 g_assert (actor == NULL);
28 }
29
30 static void
31 actor_shown_not_parented (void)
32 {
33 ClutterActor *actor;
34
35 actor = clutter_actor_new ();
36 g_object_ref_sink (actor);
37 g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor);
38
39 clutter_actor_show (actor);
40
41 if (g_test_verbose ())
42 g_print ("show without a parent - visible: %s, realized: %s, mapped: %s\n",
43 CLUTTER_ACTOR_IS_VISIBLE (actor) ? "yes" : "no",
44 CLUTTER_ACTOR_IS_REALIZED (actor) ? "yes" : "no",
45 CLUTTER_ACTOR_IS_MAPPED (actor) ? "yes" : "no");
46
47 g_assert (!CLUTTER_ACTOR_IS_REALIZED (actor));
48 g_assert (!CLUTTER_ACTOR_IS_MAPPED (actor));
49 g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor));
50
51 clutter_actor_destroy (actor);
52 g_assert (actor == NULL);
53 }
54
55 static void
56 actor_realized (void)
57 {
58 ClutterActor *actor;
59 ClutterActor *stage;
60
61 stage = clutter_test_get_stage ();
62
63 actor = clutter_actor_new ();
64
65 g_assert (!(CLUTTER_ACTOR_IS_REALIZED (actor)));
66
67 clutter_actor_hide (actor); /* don't show, so won't map */
68 clutter_actor_add_child (stage, actor);
69 clutter_actor_realize (actor);
70
71 g_assert (CLUTTER_ACTOR_IS_REALIZED (actor));
72
73 g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor)));
74 g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor)));
75 }
76
77 static void
78 actor_mapped (void)
79 {
80 ClutterActor *actor;
81 ClutterActor *stage;
82
83 stage = clutter_test_get_stage ();
84 clutter_actor_show (stage);
85
86 actor = clutter_actor_new ();
87
88 g_assert (!(CLUTTER_ACTOR_IS_REALIZED (actor)));
89 g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor)));
90
91 clutter_actor_add_child (stage, actor);
92
93 if (g_test_verbose ())
94 g_print ("adding to a container should map - "
95 "visible: %s, realized: %s, mapped: %s\n",
96 CLUTTER_ACTOR_IS_VISIBLE (actor) ? "yes" : "no",
97 CLUTTER_ACTOR_IS_REALIZED (actor) ? "yes" : "no",
98 CLUTTER_ACTOR_IS_MAPPED (actor) ? "yes" : "no");
99
100 g_assert (CLUTTER_ACTOR_IS_REALIZED (actor));
101 g_assert (CLUTTER_ACTOR_IS_MAPPED (actor));
102 g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor));
103
104 clutter_actor_hide (actor);
105
106 if (g_test_verbose ())
107 g_print ("hiding should unmap - "
108 "visible: %s, realized: %s, mapped: %s\n",
109 CLUTTER_ACTOR_IS_VISIBLE (actor) ? "yes" : "no",
110 CLUTTER_ACTOR_IS_REALIZED (actor) ? "yes" : "no",
111 CLUTTER_ACTOR_IS_MAPPED (actor) ? "yes" : "no");
112
113 g_assert (CLUTTER_ACTOR_IS_REALIZED (actor));
114 g_assert (!CLUTTER_ACTOR_IS_MAPPED (actor));
115 g_assert (!CLUTTER_ACTOR_IS_VISIBLE (actor));
116 }
117
118 static void
119 actor_visibility_not_recursive (void)
120 {
121 ClutterActor *actor, *group;
122 ClutterActor *stage;
123
124 stage = clutter_test_get_stage ();
125
126 group = clutter_actor_new ();
127 actor = clutter_actor_new ();
128
129 clutter_actor_hide (group); /* don't show, so won't map */
130 clutter_actor_hide (actor); /* don't show, so won't map */
131
132 g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (stage)));
133 g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (group)));
134 g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor)));
135
136 clutter_actor_add_child (stage, group);
137 clutter_actor_add_child (group, actor);
138
139 clutter_actor_show (actor);
140 g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor));
141 g_assert (!CLUTTER_ACTOR_IS_VISIBLE (group));
142 g_assert (!CLUTTER_ACTOR_IS_VISIBLE (stage));
143
144 clutter_actor_show (stage);
145 g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor));
146 g_assert (!CLUTTER_ACTOR_IS_VISIBLE (group));
147 g_assert (CLUTTER_ACTOR_IS_VISIBLE (stage));
148
149 clutter_actor_hide (actor);
150 clutter_actor_hide (group);
151 clutter_actor_hide (stage);
152 g_assert (!CLUTTER_ACTOR_IS_VISIBLE (actor));
153
154 clutter_actor_show (stage);
155 g_assert (!CLUTTER_ACTOR_IS_VISIBLE (actor));
156 }
157
158 static void
159 actor_realize_not_recursive (void)
160 {
161 ClutterActor *actor, *group;
162 ClutterActor *stage;
163
164 stage = clutter_test_get_stage ();
165 clutter_actor_show (stage);
166
167 group = clutter_actor_new ();
168
169 actor = clutter_actor_new ();
170
171 clutter_actor_hide (group); /* don't show, so won't map */
172 clutter_actor_hide (actor); /* don't show, so won't map */
173
174 g_assert (!(CLUTTER_ACTOR_IS_REALIZED (group)));
175 g_assert (!(CLUTTER_ACTOR_IS_REALIZED (actor)));
176
177 clutter_actor_add_child (stage, group);
178 clutter_actor_add_child (group, actor);
179
180 clutter_actor_realize (group);
181
182 g_assert (CLUTTER_ACTOR_IS_REALIZED (group));
183
184 g_assert (!(CLUTTER_ACTOR_IS_MAPPED (group)));
185 g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (group)));
186
187 /* realizing group did not realize the child */
188 g_assert (!CLUTTER_ACTOR_IS_REALIZED (actor));
189 g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor)));
190 g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor)));
191 }
192
193 static void
194 actor_map_recursive (void)
195 {
196 ClutterActor *actor, *group;
197 ClutterActor *stage;
198
199 stage = clutter_test_get_stage ();
200 clutter_actor_show (stage);
201
202 group = clutter_actor_new ();
203
204 actor = clutter_actor_new ();
205
206 clutter_actor_hide (group); /* hide at first */
207 clutter_actor_show (actor); /* show at first */
208
209 g_assert (!(CLUTTER_ACTOR_IS_REALIZED (group)));
210 g_assert (!(CLUTTER_ACTOR_IS_REALIZED (actor)));
211 g_assert (!(CLUTTER_ACTOR_IS_MAPPED (group)));
212 g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor)));
213 g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (group)));
214 g_assert ((CLUTTER_ACTOR_IS_VISIBLE (actor)));
215
216 clutter_actor_add_child (stage, group);
217 clutter_actor_add_child (group, actor);
218
219 g_assert (!(CLUTTER_ACTOR_IS_REALIZED (group)));
220 g_assert (!(CLUTTER_ACTOR_IS_REALIZED (actor)));
221 g_assert (!(CLUTTER_ACTOR_IS_MAPPED (group)));
222 g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor)));
223 g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (group)));
224 g_assert ((CLUTTER_ACTOR_IS_VISIBLE (actor)));
225
226 /* show group, which should map and realize both
227 * group and child.
228 */
229 clutter_actor_show (group);
230 g_assert (CLUTTER_ACTOR_IS_REALIZED (group));
231 g_assert (CLUTTER_ACTOR_IS_REALIZED (actor));
232 g_assert (CLUTTER_ACTOR_IS_MAPPED (group));
233 g_assert (CLUTTER_ACTOR_IS_MAPPED (actor));
234 g_assert (CLUTTER_ACTOR_IS_VISIBLE (group));
235 g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor));
236 }
237
238 static void
239 actor_show_on_set_parent (void)
240 {
241 ClutterActor *actor, *group;
242 gboolean show_on_set_parent;
243 ClutterActor *stage;
244
245 stage = clutter_test_get_stage ();
246
247 group = clutter_actor_new ();
248
249 g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (group)));
250
251 clutter_actor_add_child (stage, group);
252
253 actor = clutter_actor_new ();
254 g_object_get (actor,
255 "show-on-set-parent", &show_on_set_parent,
256 NULL);
257
258 g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor)));
259 g_assert (show_on_set_parent);
260
261 clutter_actor_add_child (group, actor);
262 g_object_get (actor,
263 "show-on-set-parent", &show_on_set_parent,
264 NULL);
265
266 g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor));
267 g_assert (show_on_set_parent);
268
269 g_object_ref (actor);
270 clutter_actor_remove_child (group, actor);
271 g_object_get (actor,
272 "show-on-set-parent", &show_on_set_parent,
273 NULL);
274
275 g_assert (!CLUTTER_ACTOR_IS_REALIZED (actor));
276 g_assert (!CLUTTER_ACTOR_IS_MAPPED (actor));
277 g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor));
278 g_assert (show_on_set_parent);
279
280 clutter_actor_destroy (actor);
281 clutter_actor_destroy (group);
282
283 actor = clutter_actor_new ();
284 clutter_actor_add_child (stage, actor);
285 clutter_actor_hide (actor);
286 g_object_get (actor,
287 "show-on-set-parent", &show_on_set_parent,
288 NULL);
289 g_assert (!CLUTTER_ACTOR_IS_VISIBLE (actor));
290 g_assert (!CLUTTER_ACTOR_IS_MAPPED (actor));
291 g_assert (show_on_set_parent);
292
293 clutter_actor_destroy (actor);
294
295 actor = clutter_actor_new ();
296 clutter_actor_hide (actor);
297 clutter_actor_add_child (stage, actor);
298 g_object_get (actor,
299 "show-on-set-parent", &show_on_set_parent,
300 NULL);
301 g_assert (!CLUTTER_ACTOR_IS_VISIBLE (actor));
302 g_assert (!CLUTTER_ACTOR_IS_MAPPED (actor));
303 g_assert (!show_on_set_parent);
304
305 clutter_actor_destroy (actor);
306 }
307
308 static void
309 clone_no_map (void)
310 {
311 ClutterActor *stage;
312 ClutterActor *group;
313 ClutterActor *actor;
314 ClutterActor *clone;
315
316 stage = clutter_test_get_stage ();
317 clutter_actor_show (stage);
318
319 group = clutter_actor_new ();
320 actor = clutter_actor_new ();
321
322 clutter_actor_hide (group);
323
324 clutter_actor_add_child (group, actor);
325 clutter_actor_add_child (stage, group);
326
327 g_assert (!(CLUTTER_ACTOR_IS_MAPPED (group)));
328 g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor)));
329
330 clone = clutter_clone_new (group);
331
332 clutter_actor_add_child (stage, clone);
333
334 g_assert (CLUTTER_ACTOR_IS_MAPPED (clone));
335 g_assert (!(CLUTTER_ACTOR_IS_MAPPED (group)));
336 g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor)));
337
338 clutter_actor_destroy (CLUTTER_ACTOR (clone));
339 clutter_actor_destroy (CLUTTER_ACTOR (group));
340 }
341
342 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
343 static void
344 default_stage (void)
345 {
346 ClutterActor *stage, *def_stage;
347
348 stage = clutter_test_get_stage ();
349 def_stage = clutter_stage_get_default ();
350
351 if (clutter_feature_available (CLUTTER_FEATURE_STAGE_MULTIPLE))
352 g_assert (stage != def_stage);
353 else
354 g_assert (stage == def_stage);
355
356 g_assert (CLUTTER_ACTOR_IS_REALIZED (def_stage));
357 }
358 G_GNUC_END_IGNORE_DEPRECATIONS
359
360 CLUTTER_TEST_SUITE (
361 CLUTTER_TEST_UNIT ("/actor/invariants/initial-state", actor_initial_state)
362 CLUTTER_TEST_UNIT ("/actor/invariants/show-not-parented", actor_shown_not_parented)
363 CLUTTER_TEST_UNIT ("/actor/invariants/realized", actor_realized)
364 CLUTTER_TEST_UNIT ("/actor/invariants/mapped", actor_mapped)
365 CLUTTER_TEST_UNIT ("/actor/invariants/visibility-not-recursive", actor_visibility_not_recursive)
366 CLUTTER_TEST_UNIT ("/actor/invariants/realize-not-recursive", actor_realize_not_recursive)
367 CLUTTER_TEST_UNIT ("/actor/invariants/map-recursive", actor_map_recursive)
368 CLUTTER_TEST_UNIT ("/actor/invariants/show-on-set-parent", actor_show_on_set_parent)
369 CLUTTER_TEST_UNIT ("/actor/invariants/clone-no-map", clone_no_map)
370 CLUTTER_TEST_UNIT ("/actor/invariants/default-stage", default_stage)
371 )