Debian Codegraph @

tests/check/ges/group.c

raw
1 /* GStreamer Editing Services
2 *
3 * Copyright (C) <2013> Thibault Saunier <[email protected]>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #include "test-utils.h"
22 #include <ges/ges.h>
23 #include <gst/check/gstcheck.h>
24
25 GST_START_TEST (test_move_group)
26 {
27 GESAsset *asset;
28 GESGroup *group;
29 GESTimeline *timeline;
30 GESLayer *layer, *layer1;
31 GESClip *clip, *clip1, *clip2;
32
33 GList *clips = NULL;
34
35 ges_init ();
36
37 timeline = ges_timeline_new_audio_video ();
38
39 layer = ges_timeline_append_layer (timeline);
40 layer1 = ges_timeline_append_layer (timeline);
41 asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
42
43 /**
44 * Our timeline:
45 * -------------
46 *
47 * 0------------Group1---------------110
48 * |-------- |
49 * layer: | clip | |
50 * |-------10 |
51 * |----------------------------------|
52 * | 0--------- 0-----------|
53 * layer1: | | clip1 | | clip2 |
54 * | 10--------20 50----------|
55 * |----------------------------------|
56 */
57 clip = ges_layer_add_asset (layer, asset, 0, 0, 10, GES_TRACK_TYPE_UNKNOWN);
58 clip1 =
59 ges_layer_add_asset (layer1, asset, 10, 0, 10, GES_TRACK_TYPE_UNKNOWN);
60 clip2 =
61 ges_layer_add_asset (layer1, asset, 50, 0, 60, GES_TRACK_TYPE_UNKNOWN);
62 clips = g_list_prepend (clips, clip);
63 clips = g_list_prepend (clips, clip1);
64 clips = g_list_prepend (clips, clip2);
65 group = GES_GROUP (ges_container_group (clips));
66 g_list_free (clips);
67 ASSERT_OBJECT_REFCOUNT (group, "2 ref for the timeline", 2);
68
69 fail_unless (GES_IS_GROUP (group));
70 ASSERT_OBJECT_REFCOUNT (group, "2 ref for the timeline", 2);
71 fail_unless (g_list_length (GES_CONTAINER_CHILDREN (group)) == 3);
72 assert_equals_int (GES_CONTAINER_HEIGHT (group), 2);
73
74 /* Nothing should move */
75 ges_timeline_element_set_start (GES_TIMELINE_ELEMENT (clip1), 5);
76
77 CHECK_OBJECT_PROPS (clip, 0, 0, 10);
78 CHECK_OBJECT_PROPS (clip1, 10, 0, 10);
79 CHECK_OBJECT_PROPS (clip2, 50, 0, 60);
80 CHECK_OBJECT_PROPS (group, 0, 0, 110);
81
82 /*
83 * 0 10------------Group1---------------120
84 * |-------- |
85 * layer: | clip | |
86 * |-------20 |
87 * |----------------------------------|
88 * | 0--------- 0-----------|
89 * layer1: | | clip1 | | clip2 |
90 * | 20--------30 60----------|
91 * |----------------------------------|
92 */
93 ges_timeline_element_set_start (GES_TIMELINE_ELEMENT (clip), 10);
94 CHECK_OBJECT_PROPS (clip, 10, 0, 10);
95 CHECK_OBJECT_PROPS (clip1, 20, 0, 10);
96 CHECK_OBJECT_PROPS (clip2, 60, 0, 60);
97 CHECK_OBJECT_PROPS (group, 10, 0, 110);
98
99 /*
100 * 0 10------------Group1---------------120
101 * |------ |
102 * layer: |clip | |
103 * |-----15 |
104 * |----------------------------------|
105 * | 0--------- 0-----------|
106 * layer1: | | clip1 | | clip2 |
107 * | 20--------30 60----------|
108 * |----------------------------------|
109 */
110 ges_timeline_element_set_duration (GES_TIMELINE_ELEMENT (clip), 5);
111 CHECK_OBJECT_PROPS (clip, 10, 0, 5);
112 CHECK_OBJECT_PROPS (clip1, 20, 0, 10);
113 CHECK_OBJECT_PROPS (clip2, 60, 0, 60);
114 CHECK_OBJECT_PROPS (group, 10, 0, 110);
115 ASSERT_OBJECT_REFCOUNT (group, "2 ref for the timeline", 2);
116
117 /*
118 * 0 10------------Group1---------------110
119 * |------ |
120 * layer: |clip | |
121 * |-----15 |
122 * |----------------------------------|
123 * | 0--------- 0-----------|
124 * layer1: | | clip1 | | clip2 |
125 * | 20--------30 60----------|
126 * |----------------------------------|
127 */
128 ges_timeline_element_set_duration (GES_TIMELINE_ELEMENT (clip2), 50);
129 CHECK_OBJECT_PROPS (clip, 10, 0, 5);
130 CHECK_OBJECT_PROPS (clip1, 20, 0, 10);
131 CHECK_OBJECT_PROPS (clip2, 60, 0, 50);
132 CHECK_OBJECT_PROPS (group, 10, 0, 100);
133
134 /*
135 * 0 10------------Group1---------------110
136 * |------ |
137 * layer: |clip | |
138 * |-----15 |
139 * |----------------------------------|
140 * | 5--------- 0-----------|
141 * layer1: | | clip1 | | clip2 |
142 * | 20--------30 60----------|
143 * |----------------------------------|
144 */
145 ges_timeline_element_set_inpoint (GES_TIMELINE_ELEMENT (clip1), 5);
146 CHECK_OBJECT_PROPS (clip, 10, 0, 5);
147 CHECK_OBJECT_PROPS (clip1, 20, 5, 10);
148 CHECK_OBJECT_PROPS (clip2, 60, 0, 50);
149 CHECK_OBJECT_PROPS (group, 10, 0, 100);
150
151 /*
152 * 0 10------------Group1---------------110
153 * |------ |
154 * layer: |clip | |
155 * |-----15 |
156 * |----------------------------------|
157 * | 5--------- 0-----------|
158 * layer1: | | clip1 | | clip2 |
159 * | 20--------30 60----------|
160 * |----------------------------------|
161 */
162 ges_timeline_element_set_inpoint (GES_TIMELINE_ELEMENT (clip1), 5);
163 CHECK_OBJECT_PROPS (clip, 10, 0, 5);
164 CHECK_OBJECT_PROPS (clip1, 20, 5, 10);
165 CHECK_OBJECT_PROPS (clip2, 60, 0, 50);
166 CHECK_OBJECT_PROPS (group, 10, 0, 100);
167 ASSERT_OBJECT_REFCOUNT (group, "2 ref for the timeline", 2);
168 fail_if (ges_timeline_element_trim (GES_TIMELINE_ELEMENT (group), 20));
169 CHECK_OBJECT_PROPS (clip, 10, 0, 5);
170 CHECK_OBJECT_PROPS (clip1, 20, 5, 10);
171 CHECK_OBJECT_PROPS (clip2, 60, 0, 50);
172 CHECK_OBJECT_PROPS (group, 10, 0, 100);
173 ASSERT_OBJECT_REFCOUNT (group, "2 ref for the timeline", 2);
174
175 fail_if (ges_timeline_element_trim (GES_TIMELINE_ELEMENT (group), 25));
176 CHECK_OBJECT_PROPS (clip, 10, 0, 5);
177 CHECK_OBJECT_PROPS (clip1, 20, 5, 10);
178 CHECK_OBJECT_PROPS (clip2, 60, 0, 50);
179 CHECK_OBJECT_PROPS (group, 10, 0, 100);
180 ASSERT_OBJECT_REFCOUNT (group, "2 ref for the timeline", 2);
181
182 /* Same thing in the end... */
183 ges_timeline_element_trim (GES_TIMELINE_ELEMENT (group), 10);
184 CHECK_OBJECT_PROPS (clip, 10, 0, 5);
185 CHECK_OBJECT_PROPS (clip1, 20, 5, 10);
186 CHECK_OBJECT_PROPS (clip2, 60, 0, 50);
187 CHECK_OBJECT_PROPS (group, 10, 0, 100);
188 ASSERT_OBJECT_REFCOUNT (group, "2 ref for the timeline", 2);
189
190 /*
191 * 0 12------------Group1---------------110
192 * 2------ |
193 * layer: |clip | |
194 * |-----15 |
195 * |----------------------------------|
196 * | 7--------- 2----------|
197 * layer1: | | clip1 | | clip2 |
198 * | 20--------30 60----------|
199 * |----------------------------------|
200 */
201 ges_timeline_element_trim (GES_TIMELINE_ELEMENT (group), 12);
202 CHECK_OBJECT_PROPS (clip, 12, 2, 3);
203 CHECK_OBJECT_PROPS (clip1, 20, 5, 10);
204 CHECK_OBJECT_PROPS (clip2, 60, 0, 50);
205 CHECK_OBJECT_PROPS (group, 12, 0, 98);
206 ASSERT_OBJECT_REFCOUNT (group, "2 ref for the timeline", 2);
207
208 /* Setting the duration would lead to overlaps */
209 fail_if (ges_timeline_element_set_duration (GES_TIMELINE_ELEMENT (group),
210 10));
211 CHECK_OBJECT_PROPS (clip, 12, 2, 3);
212 CHECK_OBJECT_PROPS (clip1, 20, 5, 10);
213 CHECK_OBJECT_PROPS (clip2, 60, 0, 50);
214 CHECK_OBJECT_PROPS (group, 12, 0, 98);
215 ges_timeline_element_set_duration (GES_TIMELINE_ELEMENT (group), 100);
216 CHECK_OBJECT_PROPS (clip, 12, 2, 3);
217 CHECK_OBJECT_PROPS (clip1, 20, 5, 10);
218 CHECK_OBJECT_PROPS (clip2, 60, 0, 52);
219 CHECK_OBJECT_PROPS (group, 12, 0, 100);
220
221 ges_timeline_element_set_start (GES_TIMELINE_ELEMENT (group), 20);
222 CHECK_OBJECT_PROPS (clip, 20, 2, 3);
223 CHECK_OBJECT_PROPS (clip1, 28, 5, 10);
224 CHECK_OBJECT_PROPS (clip2, 68, 0, 52);
225 CHECK_OBJECT_PROPS (group, 20, 0, 100);
226
227 /* Trim fails because clip inpoint would become negative */
228 fail_if (ges_timeline_element_trim (GES_TIMELINE_ELEMENT (group), 10));
229 CHECK_OBJECT_PROPS (clip, 20, 2, 3);
230 CHECK_OBJECT_PROPS (clip1, 28, 5, 10);
231 CHECK_OBJECT_PROPS (clip2, 68, 0, 52);
232 CHECK_OBJECT_PROPS (group, 20, 0, 100);
233
234 fail_unless (ges_timeline_element_trim (GES_TIMELINE_ELEMENT (group), 18));
235 CHECK_OBJECT_PROPS (clip, 18, 0, 5);
236 CHECK_OBJECT_PROPS (clip1, 28, 5, 10);
237 CHECK_OBJECT_PROPS (clip2, 68, 0, 52);
238 CHECK_OBJECT_PROPS (group, 18, 0, 102);
239
240 fail_unless (ges_timeline_element_set_duration (GES_TIMELINE_ELEMENT (clip),
241 17));
242 CHECK_OBJECT_PROPS (clip, 18, 0, 17);
243 CHECK_OBJECT_PROPS (clip1, 28, 5, 10);
244 CHECK_OBJECT_PROPS (clip2, 68, 0, 52);
245 CHECK_OBJECT_PROPS (group, 18, 0, 102);
246
247 fail_unless (ges_timeline_element_trim (GES_TIMELINE_ELEMENT (group), 30));
248 CHECK_OBJECT_PROPS (clip, 30, 12, 5);
249 CHECK_OBJECT_PROPS (clip1, 30, 7, 8);
250 CHECK_OBJECT_PROPS (clip2, 68, 0, 52);
251 CHECK_OBJECT_PROPS (group, 30, 0, 90);
252
253 fail_unless (ges_timeline_element_trim (GES_TIMELINE_ELEMENT (group), 25));
254 CHECK_OBJECT_PROPS (clip, 25, 7, 10);
255 CHECK_OBJECT_PROPS (clip1, 25, 2, 13);
256 CHECK_OBJECT_PROPS (clip2, 68, 0, 52);
257 CHECK_OBJECT_PROPS (group, 25, 0, 95);
258
259 ASSERT_OBJECT_REFCOUNT (group, "2 ref for the timeline", 2);
260 check_destroyed (G_OBJECT (timeline), G_OBJECT (group), NULL);
261 gst_object_unref (asset);
262
263 ges_deinit ();
264 }
265
266 GST_END_TEST;
267
268
269
270 static void
271 _changed_layer_cb (GESTimelineElement * clip,
272 GParamSpec * arg G_GNUC_UNUSED, guint * nb_calls)
273 {
274 *nb_calls = *nb_calls + 1;
275 }
276
277 GST_START_TEST (test_group_in_group)
278 {
279 GESAsset *asset;
280 GESTimeline *timeline;
281 GESGroup *group, *group1;
282 GESLayer *layer, *layer1, *layer2, *layer3;
283 GESClip *c, *c1, *c2, *c3, *c4, *c5;
284
285 guint nb_layer_notifies = 0;
286 GList *clips = NULL;
287
288 ges_init ();
289
290 timeline = ges_timeline_new_audio_video ();
291
292 /* Our timeline
293 *
294 * --0------------10-Group-----20---------------30-------Group1----------70
295 * | +-----------+ |+-----------50 |
296 * L | | C | || C3 | |
297 * | +-----------+ |+-----------+ |
298 * --|-------------------------------------------|-----40----------------|
299 * | +------------+ +-------------+ | +--------60 |
300 * L1 | | C1 | | C2 | | | C4 | |
301 * | +------------+ +-------------+ | +--------+ |
302 * --|-------------------------------------------|-----------------------|
303 * | | +--------+|
304 * L2 | | | c5 ||
305 * | | +--------+|
306 * --+-------------------------------------------+-----------------------+
307 *
308 * L3
309 *
310 * -----------------------------------------------------------------------
311 */
312
313 layer = ges_timeline_append_layer (timeline);
314 layer1 = ges_timeline_append_layer (timeline);
315 layer2 = ges_timeline_append_layer (timeline);
316 layer3 = ges_timeline_append_layer (timeline);
317 assert_equals_int (ges_layer_get_priority (layer3), 3);
318 asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
319
320 c = ges_layer_add_asset (layer, asset, 0, 0, 10, GES_TRACK_TYPE_UNKNOWN);
321 c1 = ges_layer_add_asset (layer1, asset, 10, 0, 10, GES_TRACK_TYPE_UNKNOWN);
322 c2 = ges_layer_add_asset (layer1, asset, 20, 0, 10, GES_TRACK_TYPE_UNKNOWN);
323 clips = g_list_prepend (clips, c);
324 clips = g_list_prepend (clips, c1);
325 clips = g_list_prepend (clips, c2);
326 group = GES_GROUP (ges_container_group (clips));
327 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (group) == timeline);
328 g_list_free (clips);
329
330 fail_unless (GES_IS_GROUP (group));
331 CHECK_OBJECT_PROPS (c, 0, 0, 10);
332 CHECK_OBJECT_PROPS (c1, 10, 0, 10);
333 CHECK_OBJECT_PROPS (c2, 20, 0, 10);
334 CHECK_OBJECT_PROPS (group, 0, 0, 30);
335
336 c3 = ges_layer_add_asset (layer, asset, 30, 0, 20, GES_TRACK_TYPE_UNKNOWN);
337 c4 = ges_layer_add_asset (layer1, asset, 40, 0, 20, GES_TRACK_TYPE_UNKNOWN);
338 c5 = ges_layer_add_asset (layer2, asset, 50, 0, 20, GES_TRACK_TYPE_UNKNOWN);
339 clips = g_list_prepend (NULL, c3);
340 clips = g_list_prepend (clips, c4);
341 clips = g_list_prepend (clips, c5);
342 group1 = GES_GROUP (ges_container_group (clips));
343 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (group1) == timeline);
344 g_list_free (clips);
345
346 fail_unless (GES_IS_GROUP (group1));
347 CHECK_OBJECT_PROPS (c3, 30, 0, 20);
348 CHECK_OBJECT_PROPS (c4, 40, 0, 20);
349 CHECK_OBJECT_PROPS (c5, 50, 0, 20);
350 CHECK_OBJECT_PROPS (group1, 30, 0, 40);
351 check_layer (c, 0);
352 check_layer (c1, 1);
353 check_layer (c2, 1);
354 check_layer (c3, 0);
355 check_layer (c4, 1);
356 check_layer (c5, 2);
357
358 fail_unless (ges_container_add (GES_CONTAINER (group),
359 GES_TIMELINE_ELEMENT (group1)));
360 CHECK_OBJECT_PROPS (c, 0, 0, 10);
361 CHECK_OBJECT_PROPS (c1, 10, 0, 10);
362 CHECK_OBJECT_PROPS (c2, 20, 0, 10);
363 CHECK_OBJECT_PROPS (c3, 30, 0, 20);
364 CHECK_OBJECT_PROPS (c4, 40, 0, 20);
365 CHECK_OBJECT_PROPS (c5, 50, 0, 20);
366 CHECK_OBJECT_PROPS (group, 0, 0, 70);
367 CHECK_OBJECT_PROPS (group1, 30, 0, 40);
368 check_layer (c, 0);
369 check_layer (c1, 1);
370 check_layer (c2, 1);
371 check_layer (c3, 0);
372 check_layer (c4, 1);
373 check_layer (c5, 2);
374
375 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (group) == timeline);
376 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (group1) == timeline);
377
378 ges_timeline_element_set_start (GES_TIMELINE_ELEMENT (c4), 50);
379 CHECK_OBJECT_PROPS (c, 10, 0, 10);
380 CHECK_OBJECT_PROPS (c1, 20, 0, 10);
381 CHECK_OBJECT_PROPS (c2, 30, 0, 10);
382 CHECK_OBJECT_PROPS (c3, 40, 0, 20);
383 CHECK_OBJECT_PROPS (c4, 50, 0, 20);
384 CHECK_OBJECT_PROPS (c5, 60, 0, 20);
385 CHECK_OBJECT_PROPS (group, 10, 0, 70);
386 CHECK_OBJECT_PROPS (group1, 40, 0, 40);
387 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (group) == timeline);
388 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (group1) == timeline);
389 check_layer (c, 0);
390 check_layer (c1, 1);
391 check_layer (c2, 1);
392 check_layer (c3, 0);
393 check_layer (c4, 1);
394 check_layer (c5, 2);
395
396 /* Our timeline
397 *
398 * L
399 * -----------------------------------------------------------------------
400 * 0------------10-Group-----20---------------30-------Group1----------70
401 * | +-----------+ |+-----------50 |
402 * L1 | | C | || C3 | |
403 * | +-----------+ |+-----------+ |
404 * | | |
405 * --|-------------------------------------------|-----40----------------|
406 * | +------------+ +-------------+ | +--------60 |
407 * L2 | | C1 | | C2 | | | C4 | |
408 * | +------------+ +-------------+ | +--------+ |
409 * --|-------------------------------------------|-----------------------|
410 * | | +--------+|
411 * L3 | | | c5 ||
412 * | | +--------+|
413 * --+-------------------------------------------+-----------------------+
414 */
415 fail_unless (ges_clip_move_to_layer (c, layer1));
416 check_layer (c, 1);
417 check_layer (c1, 2);
418 check_layer (c2, 2);
419 check_layer (c3, 1);
420 check_layer (c4, 2);
421 check_layer (c5, 3);
422 assert_equals_int (_PRIORITY (group), 1);
423 assert_equals_int (_PRIORITY (group1), 1);
424
425 /* We can not move so far! */
426 g_signal_connect_after (c4, "notify::layer",
427 (GCallback) _changed_layer_cb, &nb_layer_notifies);
428 fail_if (ges_clip_move_to_layer (c4, layer));
429 assert_equals_int (nb_layer_notifies, 0);
430 check_layer (c, 1);
431 check_layer (c1, 2);
432 check_layer (c2, 2);
433 check_layer (c3, 1);
434 check_layer (c4, 2);
435 check_layer (c5, 3);
436 assert_equals_int (_PRIORITY (group), 1);
437 assert_equals_int (_PRIORITY (group1), 1);
438
439 clips = ges_container_ungroup (GES_CONTAINER (group), FALSE);
440 assert_equals_int (g_list_length (clips), 4);
441 g_list_free_full (clips, gst_object_unref);
442
443 gst_object_unref (timeline);
444 gst_object_unref (asset);
445
446 ges_deinit ();
447 }
448
449 GST_END_TEST;
450
451 GST_START_TEST (test_group_in_group_layer_moving)
452 {
453 GESAsset *asset;
454 GESTimeline *timeline;
455 GESGroup *group;
456 GESLayer *layer, *layer1, *layer2, *layer3;
457 GESClip *c, *c1;
458
459 GList *clips = NULL;
460
461 ges_init ();
462
463 timeline = ges_timeline_new_audio_video ();
464
465 /* Our timeline
466 *
467 * --0------------10-Group-----20
468 * | +-----------+ |
469 * L | | C | |
470 * | +-----------+ |
471 * --|--------------------------
472 * | +------------+
473 * L1 | | C1 |
474 * | +------------+
475 * -----------------------------
476 */
477
478 layer = ges_timeline_append_layer (timeline);
479 layer1 = ges_timeline_append_layer (timeline);
480 layer2 = ges_timeline_append_layer (timeline);
481 layer3 = ges_timeline_append_layer (timeline);
482 fail_unless (layer2 && layer3);
483 assert_equals_int (ges_layer_get_priority (layer3), 3);
484 asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
485
486 c = ges_layer_add_asset (layer, asset, 0, 0, 10, GES_TRACK_TYPE_UNKNOWN);
487 c1 = ges_layer_add_asset (layer1, asset, 10, 0, 10, GES_TRACK_TYPE_UNKNOWN);
488 clips = g_list_prepend (clips, c);
489 clips = g_list_prepend (clips, c1);
490 group = GES_GROUP (ges_container_group (clips));
491 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (group) == timeline);
492 g_list_free (clips);
493
494 fail_unless (GES_IS_GROUP (group));
495 CHECK_OBJECT_PROPS (c, 0, 0, 10);
496 CHECK_OBJECT_PROPS (c1, 10, 0, 10);
497 CHECK_OBJECT_PROPS (group, 0, 0, 20);
498
499 /* Our timeline
500 *
501 * --0--------10-----------20-Group----30
502 * | +-----------+ |
503 * L | | C | |
504 * | +-----------+ |
505 * --|-----------------------------------
506 * | +------------+
507 * L1 | | C1 |
508 * | +------------+
509 * -------------------------------------
510 */
511 fail_unless (ges_container_edit (GES_CONTAINER (c), NULL,
512 -1, GES_EDIT_MODE_NORMAL, GES_EDGE_NONE, 10));
513
514 CHECK_OBJECT_PROPS (c, 10, 0, 10);
515 CHECK_OBJECT_PROPS (c1, 20, 0, 10);
516 CHECK_OBJECT_PROPS (group, 10, 0, 20);
517 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c), 0);
518 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c1), 1);
519 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (group), 0);
520
521 ges_layer_set_priority (layer2, 0);
522 /* no change since none of the clips are in layer2 */
523 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c), 0);
524 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c1), 1);
525 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (group), 0);
526
527 ges_layer_set_priority (layer, 1);
528 /* c's layer now has priority 1 (conflicts with layer1) */
529 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c), 1);
530 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c1), 1);
531 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (group), 1);
532
533 ges_layer_set_priority (layer1, 2);
534 /* conflicting layer priorities now resolved */
535 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c), 1);
536 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c1), 2);
537 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (group), 1);
538
539 /* Our timeline
540 *
541 * --0--------10-----------20-Group----30
542 * | +-----------+ |
543 * L2 | | C | |
544 * | +-----------+ |
545 * --|-----------------------------------
546 * | +------------+
547 * L | | C1 |
548 * | +------------+
549 * -------------------------------------
550 *
551 * L1
552 * -------------------------------------
553 */
554 fail_unless (ges_container_edit (GES_CONTAINER (c), NULL,
555 0, GES_EDIT_MODE_NORMAL, GES_EDGE_NONE, 10));
556 CHECK_OBJECT_PROPS (c, 10, 0, 10);
557 CHECK_OBJECT_PROPS (c1, 20, 0, 10);
558 CHECK_OBJECT_PROPS (group, 10, 0, 20);
559 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c), 0);
560 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c1), 1);
561
562 /* Our timeline
563 *
564 * --0--------10-----------20-Group----30
565 * L2 | |
566 * --------------------------------------
567 * | +-----------+ |
568 * L | | C | |
569 * | +-----------+ |
570 * --|-----------------------------------
571 * | +------------+
572 * L1 | | C1 |
573 * | +------------+
574 * -------------------------------------
575 */
576 fail_unless (ges_container_edit (GES_CONTAINER (c), NULL,
577 1, GES_EDIT_MODE_NORMAL, GES_EDGE_NONE, 10));
578 CHECK_OBJECT_PROPS (c, 10, 0, 10);
579 CHECK_OBJECT_PROPS (c1, 20, 0, 10);
580 CHECK_OBJECT_PROPS (group, 10, 0, 20);
581 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c), 1);
582 assert_equals_int (GES_TIMELINE_ELEMENT_LAYER_PRIORITY (c1), 2);
583
584 gst_object_unref (timeline);
585 gst_object_unref (asset);
586
587 ges_deinit ();
588 }
589
590 GST_END_TEST;
591
592
593 GST_START_TEST (test_group_in_self)
594 {
595 GESLayer *layer;
596 GESClip *c, *c1;
597 GESAsset *asset;
598 GESTimeline *timeline;
599 GESGroup *group;
600
601 GList *clips = NULL;
602
603 ges_init ();
604
605 timeline = ges_timeline_new_audio_video ();
606
607 layer = ges_timeline_append_layer (timeline);
608 asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
609
610 c = ges_layer_add_asset (layer, asset, 0, 0, 10, GES_TRACK_TYPE_UNKNOWN);
611 c1 = ges_layer_add_asset (layer, asset, 10, 0, 10, GES_TRACK_TYPE_UNKNOWN);
612 clips = g_list_prepend (clips, c);
613 clips = g_list_prepend (clips, c1);
614
615
616 group = GES_GROUP (ges_container_group (clips));
617 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (group) == timeline);
618 g_list_free (clips);
619
620 fail_if (ges_container_add (GES_CONTAINER (group),
621 GES_TIMELINE_ELEMENT (group)));
622 clips = ges_container_get_children (GES_CONTAINER (group), TRUE);
623 assert_equals_int (g_list_length (clips), 6);
624 g_list_free_full (clips, g_object_unref);
625
626 gst_object_unref (timeline);
627 gst_object_unref (asset);
628
629 ges_deinit ();
630 }
631
632 GST_END_TEST;
633
634 static void
635 project_loaded_cb (GESProject * project, GESTimeline * timeline,
636 GMainLoop * mainloop)
637 {
638 g_main_loop_quit (mainloop);
639 }
640
641 GST_START_TEST (test_group_serialization)
642 {
643 gchar *tmpuri;
644 GESLayer *layer;
645 GESClip *c, *c1, *c2, *c3;
646 GESAsset *asset;
647 GESTimeline *timeline;
648 GESGroup *group;
649 GESProject *project;
650 GMainLoop *mainloop;
651
652 GError *err = NULL;
653 GList *tmp, *clips = NULL;
654
655 ges_init ();
656
657 timeline = ges_timeline_new_audio_video ();
658
659 layer = ges_timeline_append_layer (timeline);
660 asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
661
662 c = ges_layer_add_asset (layer, asset, 0, 0, 10, GES_TRACK_TYPE_UNKNOWN);
663
664 c1 = ges_layer_add_asset (layer, asset, 10, 0, 10, GES_TRACK_TYPE_UNKNOWN);
665
666 clips = g_list_prepend (clips, c);
667 clips = g_list_prepend (clips, c1);
668
669 c2 = ges_layer_add_asset (layer, asset, 20, 0, 10, GES_TRACK_TYPE_UNKNOWN);
670
671 c3 = ges_layer_add_asset (layer, asset, 30, 0, 10, GES_TRACK_TYPE_UNKNOWN);
672
673 group = GES_GROUP (ges_container_group (clips));
674 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (group) == timeline);
675 g_list_free (clips);
676
677
678 clips = g_list_append (NULL, group);
679 clips = g_list_append (clips, c2);
680 group = GES_GROUP (ges_container_group (clips));
681 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (group) == timeline);
682 g_list_free (clips);
683
684 clips = g_list_append (NULL, group);
685 clips = g_list_append (clips, c3);
686 group = GES_GROUP (ges_container_group (clips));
687 fail_unless (GES_TIMELINE_ELEMENT_TIMELINE (group) == timeline);
688 g_list_free (clips);
689
690 project =
691 GES_PROJECT (ges_extractable_get_asset (GES_EXTRACTABLE (timeline)));
692
693 tmpuri = ges_test_get_tmp_uri ("test-auto-transition-save.xges");
694 fail_unless (ges_project_save (project, timeline, tmpuri, NULL, TRUE, NULL));
695 gst_object_unref (timeline);
696 gst_object_unref (asset);
697
698 project = ges_project_new (tmpuri);
699 mainloop = g_main_loop_new (NULL, FALSE);
700 g_signal_connect (project, "loaded", (GCallback) project_loaded_cb, mainloop);
701 timeline = GES_TIMELINE (ges_asset_extract (GES_ASSET (project), &err));
702 g_main_loop_run (mainloop);
703
704 fail_unless (err == NULL, "%s", err ? err->message : "Nothing");
705 fail_unless (timeline != NULL);
706
707 layer = timeline->layers->data;
708 clips = ges_layer_get_clips (layer);
709 for (tmp = clips; tmp; tmp = tmp->next) {
710 fail_unless (GES_IS_GROUP (GES_TIMELINE_ELEMENT_PARENT (tmp->data)),
711 "%s parent is %p, NOT a group", GES_TIMELINE_ELEMENT_NAME (tmp->data),
712 GES_TIMELINE_ELEMENT_PARENT (tmp->data));
713 }
714 g_list_free_full (clips, g_object_unref);
715
716 g_free (tmpuri);
717 gst_object_unref (timeline);
718 gst_object_unref (asset);
719
720 ges_deinit ();
721 }
722
723 GST_END_TEST;
724
725 GST_START_TEST (test_children_properties_contain)
726 {
727 GESTimeline *timeline;
728 GESLayer *layer;
729 GESAsset *asset;
730 GESTimelineElement *audioc0, *videoc, *audioc1, *g1, *g2;
731 GParamSpec **child_props1, **child_props2;
732 guint num_props1, num_props2;
733
734 ges_init ();
735
736 timeline = ges_timeline_new_audio_video ();
737 layer = ges_timeline_append_layer (timeline);
738
739 asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
740 /* choose one audio and one video to give them different properties */
741 audioc0 = GES_TIMELINE_ELEMENT (ges_layer_add_asset (layer, asset, 0, 0, 10,
742 GES_TRACK_TYPE_AUDIO));
743 videoc = GES_TIMELINE_ELEMENT (ges_layer_add_asset (layer, asset, 20, 0, 10,
744 GES_TRACK_TYPE_VIDEO));
745 /* but audioc1 will have the same child properties as audioc0! */
746 audioc1 = GES_TIMELINE_ELEMENT (ges_layer_add_asset (layer, asset, 40, 0, 10,
747 GES_TRACK_TYPE_AUDIO));
748
749 fail_unless (audioc0);
750 fail_unless (videoc);
751
752 g1 = GES_TIMELINE_ELEMENT (ges_group_new ());
753 g2 = GES_TIMELINE_ELEMENT (ges_group_new ());
754
755 /* group should have the same as its children */
756 fail_unless (ges_container_add (GES_CONTAINER (g1), audioc0));
757
758 num_props1 = 0;
759 child_props1 = append_children_properties (NULL, audioc0, &num_props1);
760 num_props2 = 0;
761 child_props2 = append_children_properties (NULL, g1, &num_props2);
762
763 /* audioc0 VS g1 */
764 assert_property_list_match (child_props1, num_props1,
765 child_props2, num_props2);
766
767 /* add next child and gain its children properties as well */
768 fail_unless (ges_container_add (GES_CONTAINER (g1), videoc));
769
770 /* add the child properties of videoc to the existing list for audioc0 */
771 child_props1 = append_children_properties (child_props1, videoc, &num_props1);
772
773 free_children_properties (child_props2, num_props2);
774 num_props2 = 0;
775 child_props2 = append_children_properties (NULL, g1, &num_props2);
776
777 /* audioc0+videoc VS g1 */
778 assert_property_list_match (child_props1, num_props1,
779 child_props2, num_props2);
780
781 fail_unless (ges_container_add (GES_CONTAINER (g1), audioc1));
782
783 child_props1 =
784 append_children_properties (child_props1, audioc1, &num_props1);
785 free_children_properties (child_props2, num_props2);
786 num_props2 = 0;
787 child_props2 = append_children_properties (NULL, g1, &num_props2);
788
789 /* audioc0+videoc+audioc1 VS g1 */
790 assert_property_list_match (child_props1, num_props1,
791 child_props2, num_props2);
792
793 /* remove audioc1 */
794 fail_unless (ges_container_remove (GES_CONTAINER (g1), audioc1));
795
796 free_children_properties (child_props1, num_props1);
797 num_props1 = 0;
798 child_props1 = append_children_properties (NULL, audioc0, &num_props1);
799 child_props1 = append_children_properties (child_props1, videoc, &num_props1);
800
801 free_children_properties (child_props2, num_props2);
802 num_props2 = 0;
803 child_props2 = append_children_properties (NULL, g1, &num_props2);
804
805 /* audioc0+videoc VS g1 */
806 assert_property_list_match (child_props1, num_props1,
807 child_props2, num_props2);
808
809 /* remove audioc0 */
810 fail_unless (ges_container_remove (GES_CONTAINER (g1), audioc0));
811
812 free_children_properties (child_props1, num_props1);
813 num_props1 = 0;
814 child_props1 = append_children_properties (NULL, videoc, &num_props1);
815
816 free_children_properties (child_props2, num_props2);
817 num_props2 = 0;
818 child_props2 = append_children_properties (NULL, g1, &num_props2);
819
820 /* videoc VS g1 */
821 assert_property_list_match (child_props1, num_props1,
822 child_props2, num_props2);
823
824 /* add g1 and audioc0 to g2 */
825 fail_unless (ges_container_add (GES_CONTAINER (g2), g1));
826 fail_unless (ges_container_add (GES_CONTAINER (g2), audioc0));
827
828 free_children_properties (child_props1, num_props1);
829 num_props1 = 0;
830 child_props1 = append_children_properties (NULL, g2, &num_props1);
831
832 free_children_properties (child_props2, num_props2);
833 num_props2 = 0;
834 child_props2 = append_children_properties (NULL, audioc0, &num_props2);
835 child_props2 = append_children_properties (child_props2, g1, &num_props2);
836
837 /* g2+audioc0 VS g2 */
838 assert_property_list_match (child_props1, num_props1,
839 child_props2, num_props2);
840
841 free_children_properties (child_props1, num_props1);
842 free_children_properties (child_props2, num_props2);
843
844 gst_object_unref (timeline);
845 gst_object_unref (asset);
846
847 ges_deinit ();
848 }
849
850 GST_END_TEST;
851
852
853
854
855 static Suite *
856 ges_suite (void)
857 {
858 Suite *s = suite_create ("ges-group");
859 TCase *tc_chain = tcase_create ("group");
860
861 suite_add_tcase (s, tc_chain);
862
863 tcase_add_test (tc_chain, test_move_group);
864 tcase_add_test (tc_chain, test_group_in_group);
865 tcase_add_test (tc_chain, test_group_in_self);
866 tcase_add_test (tc_chain, test_group_serialization);
867 tcase_add_test (tc_chain, test_group_in_group_layer_moving);
868 tcase_add_test (tc_chain, test_children_properties_contain);
869
870 return s;
871 }
872
873 GST_CHECK_MAIN (ges);