layer: Add ability to get clips in a given interval
[platform/upstream/gstreamer.git] / tests / check / ges / layer.c
1 /* GStreamer Editing Services
2  * Copyright (C) 2010 Edward Hervey <bilboed@bilboed.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library 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.
8  *
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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include "test-utils.h"
21 #include <ges/ges.h>
22 #include <gst/check/gstcheck.h>
23
24 #define LAYER_HEIGHT 1000
25
26 GST_START_TEST (test_layer_properties)
27 {
28   GESTimeline *timeline;
29   GESLayer *layer;
30   GESTrack *track;
31   GESTrackElement *trackelement;
32   GESClip *clip;
33
34   ges_init ();
35
36   /* Timeline and 1 Layer */
37   timeline = ges_timeline_new ();
38   layer = (GESLayer *) ges_layer_new ();
39
40   /* The default priority is 0 */
41   fail_unless_equals_int (ges_layer_get_priority (layer), 0);
42
43   /* Layers are initially floating, once we add them to the timeline,
44    * the timeline will take that reference. */
45   fail_unless (g_object_is_floating (layer));
46   fail_unless (ges_timeline_add_layer (timeline, layer));
47   fail_if (g_object_is_floating (layer));
48
49   track = GES_TRACK (ges_video_track_new ());
50   fail_unless (track != NULL);
51   fail_unless (ges_timeline_add_track (timeline, track));
52
53   clip = (GESClip *) ges_test_clip_new ();
54   fail_unless (clip != NULL);
55
56   /* Set some properties */
57   g_object_set (clip, "start", (guint64) 42, "duration", (guint64) 51,
58       "in-point", (guint64) 12, NULL);
59   assert_equals_uint64 (_START (clip), 42);
60   assert_equals_uint64 (_DURATION (clip), 51);
61   assert_equals_uint64 (_INPOINT (clip), 12);
62   assert_equals_uint64 (_PRIORITY (clip), 0);
63
64   /* Add the clip to the timeline */
65   fail_unless (g_object_is_floating (clip));
66   fail_unless (ges_layer_add_clip (layer, GES_CLIP (clip)));
67   fail_if (g_object_is_floating (clip));
68   trackelement = ges_clip_find_track_element (clip, track, G_TYPE_NONE);
69   fail_unless (trackelement != NULL);
70
71   /* This is not a SimpleLayer, therefore the properties shouldn't have changed */
72   assert_equals_uint64 (_START (clip), 42);
73   assert_equals_uint64 (_DURATION (clip), 51);
74   assert_equals_uint64 (_INPOINT (clip), 12);
75   assert_equals_uint64 (_PRIORITY (clip), 1);
76   ges_timeline_commit (timeline);
77   nle_object_check (ges_track_element_get_nleobject (trackelement), 42, 51, 12,
78       51, MIN_NLE_PRIO + TRANSITIONS_HEIGHT, TRUE);
79
80   /* Change the priority of the layer */
81   g_object_set (layer, "priority", 1, NULL);
82   assert_equals_int (ges_layer_get_priority (layer), 1);
83   assert_equals_uint64 (_PRIORITY (clip), 1);
84   ges_timeline_commit (timeline);
85   nle_object_check (ges_track_element_get_nleobject (trackelement), 42, 51, 12,
86       51, LAYER_HEIGHT + MIN_NLE_PRIO + TRANSITIONS_HEIGHT, TRUE);
87
88   /* Change it to an insanely high value */
89   g_object_set (layer, "priority", 31, NULL);
90   assert_equals_int (ges_layer_get_priority (layer), 31);
91   assert_equals_uint64 (_PRIORITY (clip), 1);
92   ges_timeline_commit (timeline);
93   nle_object_check (ges_track_element_get_nleobject (trackelement), 42, 51, 12,
94       51, MIN_NLE_PRIO + TRANSITIONS_HEIGHT + LAYER_HEIGHT * 31, TRUE);
95
96   /* and back to 0 */
97   g_object_set (layer, "priority", 0, NULL);
98   assert_equals_int (ges_layer_get_priority (layer), 0);
99   assert_equals_uint64 (_PRIORITY (clip), 1);
100   ges_timeline_commit (timeline);
101   nle_object_check (ges_track_element_get_nleobject (trackelement), 42, 51, 12,
102       51, MIN_NLE_PRIO + TRANSITIONS_HEIGHT + 0, TRUE);
103
104   gst_object_unref (trackelement);
105   fail_unless (ges_layer_remove_clip (layer, clip));
106   fail_unless (ges_timeline_remove_track (timeline, track));
107   fail_unless (ges_timeline_remove_layer (timeline, layer));
108   gst_object_unref (timeline);
109 }
110
111 GST_END_TEST;
112
113 GST_START_TEST (test_layer_priorities)
114 {
115   GESTrack *track;
116   GESTimeline *timeline;
117   GESLayer *layer1, *layer2, *layer3;
118   GESTrackElement *trackelement1, *trackelement2, *trackelement3;
119   GESClip *clip1, *clip2, *clip3;
120   GstElement *nleobj1, *nleobj2, *nleobj3;
121   guint prio1, prio2, prio3;
122   GList *objs;
123
124   ges_init ();
125
126   /* Timeline and 3 Layer */
127   timeline = ges_timeline_new ();
128   layer1 = (GESLayer *) ges_layer_new ();
129   layer2 = (GESLayer *) ges_layer_new ();
130   layer3 = (GESLayer *) ges_layer_new ();
131
132   ges_layer_set_priority (layer2, 1);
133   ges_layer_set_priority (layer3, 2);
134
135   fail_unless (ges_timeline_add_layer (timeline, layer1));
136   fail_unless (ges_timeline_add_layer (timeline, layer2));
137   fail_unless (ges_timeline_add_layer (timeline, layer3));
138   fail_unless_equals_int (ges_layer_get_priority (layer1), 0);
139   fail_unless_equals_int (ges_layer_get_priority (layer2), 1);
140   fail_unless_equals_int (ges_layer_get_priority (layer3), 2);
141
142   track = GES_TRACK (ges_video_track_new ());
143   fail_unless (track != NULL);
144   fail_unless (ges_timeline_add_track (timeline, track));
145
146   clip1 = GES_CLIP (ges_test_clip_new ());
147   clip2 = GES_CLIP (ges_test_clip_new ());
148   clip3 = GES_CLIP (ges_test_clip_new ());
149   fail_unless (clip1 != NULL);
150   fail_unless (clip2 != NULL);
151   fail_unless (clip3 != NULL);
152
153   g_object_set (clip1, "start", 0, "duration", 10, NULL);
154   g_object_set (clip2, "start", 10, "duration", 10, NULL);
155   g_object_set (clip3, "start", 20, "duration", 10, NULL);
156
157   /* Add objects to the timeline */
158   fail_unless (ges_layer_add_clip (layer1, clip1));
159   trackelement1 = ges_clip_find_track_element (clip1, track, G_TYPE_NONE);
160   fail_unless (trackelement1 != NULL);
161
162   fail_unless (ges_layer_add_clip (layer2, clip2));
163   trackelement2 = ges_clip_find_track_element (clip2, track, G_TYPE_NONE);
164   fail_unless (trackelement2 != NULL);
165
166   fail_unless (ges_layer_add_clip (layer3, clip3));
167   trackelement3 = ges_clip_find_track_element (clip3, track, G_TYPE_NONE);
168   fail_unless (trackelement3 != NULL);
169
170   ges_timeline_commit (timeline);
171   assert_equals_int (_PRIORITY (clip1), 1);
172   nleobj1 = ges_track_element_get_nleobject (trackelement1);
173   fail_unless (nleobj1 != NULL);
174   g_object_get (nleobj1, "priority", &prio1, NULL);
175   assert_equals_int (prio1, MIN_NLE_PRIO + TRANSITIONS_HEIGHT);
176
177   assert_equals_int (_PRIORITY (clip2), 1);
178   nleobj2 = ges_track_element_get_nleobject (trackelement2);
179   fail_unless (nleobj2 != NULL);
180   g_object_get (nleobj2, "priority", &prio2, NULL);
181   /* clip2 is on the second layer and has a priority of 1 */
182   assert_equals_int (prio2, MIN_NLE_PRIO + LAYER_HEIGHT + 1);
183
184   /* We do not take into account users set priorities */
185   assert_equals_int (_PRIORITY (clip3), 1);
186
187   nleobj3 = ges_track_element_get_nleobject (trackelement3);
188   fail_unless (nleobj3 != NULL);
189
190   /* clip3 is on the third layer and has a priority of LAYER_HEIGHT + 1
191    * it priority must have the maximum priority of this layer*/
192   g_object_get (nleobj3, "priority", &prio3, NULL);
193   assert_equals_int (prio3, 1 + MIN_NLE_PRIO + LAYER_HEIGHT * 2);
194
195   /* Move layers around */
196   g_object_set (layer1, "priority", 2, NULL);
197   g_object_set (layer2, "priority", 0, NULL);
198   g_object_set (layer3, "priority", 1, NULL);
199   ges_timeline_commit (timeline);
200
201   /* And check the new priorities */
202   assert_equals_int (ges_layer_get_priority (layer1), 2);
203   assert_equals_int (ges_layer_get_priority (layer2), 0);
204   assert_equals_int (ges_layer_get_priority (layer3), 1);
205   assert_equals_int (_PRIORITY (clip1), 1);
206   assert_equals_int (_PRIORITY (clip2), 1);
207   assert_equals_int (_PRIORITY (clip3), 1);
208   g_object_get (nleobj1, "priority", &prio1, NULL);
209   g_object_get (nleobj2, "priority", &prio2, NULL);
210   g_object_get (nleobj3, "priority", &prio3, NULL);
211   assert_equals_int (prio1,
212       2 * LAYER_HEIGHT + MIN_NLE_PRIO + TRANSITIONS_HEIGHT);
213   assert_equals_int (prio2, MIN_NLE_PRIO + 1);
214   assert_equals_int (prio3, LAYER_HEIGHT + MIN_NLE_PRIO + TRANSITIONS_HEIGHT);
215
216   /* And move objects around */
217   fail_unless (ges_clip_move_to_layer (clip2, layer1));
218   fail_unless (ges_clip_move_to_layer (clip3, layer1));
219   ges_timeline_commit (timeline);
220
221   objs = ges_layer_get_clips (layer1);
222   assert_equals_int (g_list_length (objs), 3);
223   fail_unless (ges_layer_get_clips (layer2) == NULL);
224   fail_unless (ges_layer_get_clips (layer3) == NULL);
225   g_list_free_full (objs, gst_object_unref);
226
227   /*  Check their priorities (layer1 priority is now 2) */
228   assert_equals_int (_PRIORITY (clip1), 1);
229   assert_equals_int (_PRIORITY (clip2), 2);
230   assert_equals_int (_PRIORITY (clip3), 3);
231   g_object_get (nleobj1, "priority", &prio1, NULL);
232   g_object_get (nleobj2, "priority", &prio2, NULL);
233   g_object_get (nleobj3, "priority", &prio3, NULL);
234   assert_equals_int (prio1,
235       2 * LAYER_HEIGHT + MIN_NLE_PRIO + TRANSITIONS_HEIGHT);
236   assert_equals_int (prio2,
237       2 * LAYER_HEIGHT + 1 + MIN_NLE_PRIO + TRANSITIONS_HEIGHT);
238   assert_equals_int (prio3,
239       2 * LAYER_HEIGHT + 2 + MIN_NLE_PRIO + TRANSITIONS_HEIGHT);
240
241   gst_object_unref (trackelement1);
242   gst_object_unref (trackelement2);
243   gst_object_unref (trackelement3);
244   gst_object_unref (timeline);
245 }
246
247 GST_END_TEST;
248
249 GST_START_TEST (test_timeline_auto_transition)
250 {
251   GESAsset *asset;
252   GESTimeline *timeline;
253   GESLayer *layer, *layer1, *layer2;
254
255   ges_init ();
256
257   asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
258   fail_unless (GES_IS_ASSET (asset));
259
260   GST_DEBUG ("Create timeline");
261   timeline = ges_timeline_new_audio_video ();
262   assert_is_type (timeline, GES_TYPE_TIMELINE);
263
264   GST_DEBUG ("Create layers");
265   layer = ges_layer_new ();
266   assert_is_type (layer, GES_TYPE_LAYER);
267   layer1 = ges_layer_new ();
268   assert_is_type (layer, GES_TYPE_LAYER);
269   layer2 = ges_layer_new ();
270   assert_is_type (layer, GES_TYPE_LAYER);
271
272   GST_DEBUG ("Set auto-transition to the layers");
273   ges_layer_set_auto_transition (layer, TRUE);
274   ges_layer_set_auto_transition (layer1, TRUE);
275   ges_layer_set_auto_transition (layer2, TRUE);
276
277   GST_DEBUG ("Add layers to the timeline");
278   ges_timeline_add_layer (timeline, layer);
279   ges_timeline_add_layer (timeline, layer1);
280   ges_timeline_add_layer (timeline, layer2);
281
282   GST_DEBUG ("Check that auto-transition was properly set to the layers");
283   fail_unless (ges_layer_get_auto_transition (layer));
284   fail_unless (ges_layer_get_auto_transition (layer1));
285   fail_unless (ges_layer_get_auto_transition (layer2));
286
287   GST_DEBUG ("Set timeline auto-transition property to FALSE");
288   ges_timeline_set_auto_transition (timeline, FALSE);
289
290   GST_DEBUG
291       ("Check that layers auto-transition has the same value as timeline");
292   fail_if (ges_layer_get_auto_transition (layer));
293   fail_if (ges_layer_get_auto_transition (layer1));
294   fail_if (ges_layer_get_auto_transition (layer2));
295
296   GST_DEBUG ("Set timeline auto-transition property to TRUE");
297   ges_timeline_set_auto_transition (timeline, TRUE);
298
299   GST_DEBUG
300       ("Check that layers auto-transition has the same value as timeline");
301   fail_unless (ges_layer_get_auto_transition (layer));
302   fail_unless (ges_layer_get_auto_transition (layer1));
303   fail_unless (ges_layer_get_auto_transition (layer2));
304
305   gst_object_unref (timeline);
306 }
307
308 GST_END_TEST;
309
310 GST_START_TEST (test_single_layer_automatic_transition)
311 {
312   GESAsset *asset;
313   GESTimeline *timeline;
314   GList *objects, *current;
315   GESClip *transition;
316   GESLayer *layer;
317   GESTimelineElement *src, *src1, *src2;
318
319   ges_init ();
320
321   asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
322   fail_unless (GES_IS_ASSET (asset));
323
324   GST_DEBUG ("Create timeline");
325   timeline = ges_timeline_new_audio_video ();
326   assert_is_type (timeline, GES_TYPE_TIMELINE);
327
328   GST_DEBUG ("Create first layer");
329   layer = ges_layer_new ();
330   assert_is_type (layer, GES_TYPE_LAYER);
331
332   GST_DEBUG ("Add first layer to timeline");
333   fail_unless (ges_timeline_add_layer (timeline, layer));
334
335   GST_DEBUG ("Set auto transition to first layer");
336   ges_layer_set_auto_transition (layer, TRUE);
337
338   GST_DEBUG ("Check that auto-transition was properly set");
339   fail_unless (ges_layer_get_auto_transition (layer));
340
341   GST_DEBUG ("Adding assets to first layer");
342   GST_DEBUG ("Adding clip from 0 -- 1000 to first layer");
343   src = GES_TIMELINE_ELEMENT (ges_layer_add_asset (layer, asset, 0, 0,
344           1000, GES_TRACK_TYPE_UNKNOWN));
345   fail_unless (GES_IS_CLIP (src));
346
347   GST_DEBUG ("Adding clip from 500 -- 1000 to first layer");
348   src1 = GES_TIMELINE_ELEMENT (ges_layer_add_asset (layer, asset, 500,
349           0, 1000, GES_TRACK_TYPE_UNKNOWN));
350   fail_unless (GES_IS_CLIP (src1));
351
352   /*
353    *        500__transition__1000
354    * 0___________src_________1000
355    *        500___________src1_________1500
356    */
357   GST_DEBUG ("Checking src timing values");
358   assert_equals_uint64 (_START (src), 0);
359   assert_equals_uint64 (_DURATION (src), 1000);
360   assert_equals_uint64 (_START (src1), 500);
361   assert_equals_uint64 (_DURATION (src1), 1500 - 500);
362   ges_timeline_commit (timeline);
363
364   GST_DEBUG ("Checking that a transition has been added");
365   objects = ges_layer_get_clips (layer);
366   assert_equals_int (g_list_length (objects), 4);
367   assert_is_type (objects->data, GES_TYPE_TEST_CLIP);
368
369   transition = objects->next->data;
370   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
371   assert_equals_uint64 (_START (transition), 500);
372   assert_equals_uint64 (_DURATION (transition), 500);
373
374   transition = objects->next->next->data;
375   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
376   assert_equals_uint64 (_START (transition), 500);
377   assert_equals_uint64 (_DURATION (transition), 500);
378   g_list_free_full (objects, gst_object_unref);
379   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
380
381   GST_DEBUG ("Moving first source to 250");
382   ges_timeline_element_set_start (src, 250);
383
384   /*
385    *        500_____transition____1250
386    *    250___________src_________1250
387    *        500___________src1_________1500
388    */
389   GST_DEBUG ("Checking src timing values");
390   assert_equals_uint64 (_START (src), 250);
391   assert_equals_uint64 (_DURATION (src), 1250 - 250);
392   assert_equals_uint64 (_START (src1), 500);
393   assert_equals_uint64 (_DURATION (src1), 1500 - 500);
394
395   objects = ges_layer_get_clips (layer);
396   assert_equals_int (g_list_length (objects), 4);
397   assert_is_type (objects->data, GES_TYPE_TEST_CLIP);
398
399   transition = objects->next->data;
400   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
401   assert_equals_uint64 (_START (transition), 500);
402   assert_equals_uint64 (_DURATION (transition), 750);
403
404   transition = objects->next->next->data;
405   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
406   assert_equals_int (_START (transition), 500);
407   assert_equals_uint64 (_DURATION (transition), 750);
408   g_list_free_full (objects, gst_object_unref);
409
410   GST_DEBUG ("Moving second source to 250, the transitions should be removed");
411   ges_timeline_element_set_start (src1, 250);
412
413   /* The transition should be removed
414    *    250___________src_________1250
415    *    250___________src1________1250
416    */
417   GST_DEBUG ("Checking src timing values");
418   assert_equals_uint64 (_START (src), 250);
419   assert_equals_uint64 (_DURATION (src), 1250 - 250);
420   assert_equals_uint64 (_START (src1), 250);
421   assert_equals_uint64 (_DURATION (src1), 1250 - 250);
422
423   objects = ges_layer_get_clips (layer);
424   assert_equals_int (g_list_length (objects), 2);
425   g_list_free_full (objects, gst_object_unref);
426
427   GST_DEBUG ("Trimming second source to 500 no transition should be created "
428       "as they have the same end");
429   ges_container_edit (GES_CONTAINER (src1), NULL, -1,
430       GES_EDIT_MODE_TRIM, GES_EDGE_START, 500);
431
432   /*    250___________src_________1250
433    *          500______src1_______1250
434    */
435   GST_DEBUG ("Checking src timing values");
436   assert_equals_uint64 (_START (src), 250);
437   assert_equals_uint64 (_DURATION (src), 1250 - 250);
438   assert_equals_uint64 (_START (src1), 500);
439   assert_equals_uint64 (_DURATION (src1), 1250 - 500);
440
441   objects = ges_layer_get_clips (layer);
442   assert_equals_int (g_list_length (objects), 2);
443   g_list_free_full (objects, gst_object_unref);
444
445   GST_DEBUG ("Trimming second source to 500, no transition should be created");
446   ges_timeline_element_trim (src, 500);
447
448   /*        500___________src_________1250
449    *        500___________src1________1250
450    */
451   GST_DEBUG ("Checking src timing values");
452   assert_equals_uint64 (_START (src), 500);
453   assert_equals_uint64 (_DURATION (src), 1250 - 500);
454   assert_equals_uint64 (_START (src1), 500);
455   assert_equals_uint64 (_DURATION (src1), 1250 - 500);
456
457   GST_DEBUG ("Trimming first source to 750, no transition should be created");
458   ges_timeline_element_trim (src, 750);
459
460   /*              750_______src_______1250
461    *        500___________src1________1250
462    */
463   GST_DEBUG ("Checking src timing values");
464   assert_equals_uint64 (_START (src), 750);
465   assert_equals_uint64 (_DURATION (src), 1250 - 750);
466   assert_equals_uint64 (_START (src1), 500);
467   assert_equals_uint64 (_DURATION (src1), 1250 - 500);
468
469   objects = ges_layer_get_clips (layer);
470   assert_equals_int (g_list_length (objects), 2);
471   g_list_free_full (objects, gst_object_unref);
472
473   objects = ges_layer_get_clips (layer);
474   assert_equals_int (g_list_length (objects), 2);
475   g_list_free_full (objects, gst_object_unref);
476
477   GST_DEBUG ("Moving first source to 500, no transition should be created");
478   ges_timeline_element_set_start (src, 500);
479
480   /*        500________src______1000
481    *        500___________src1________1250
482    */
483   GST_DEBUG ("Checking src timing values");
484   assert_equals_uint64 (_START (src), 500);
485   assert_equals_uint64 (_DURATION (src), 1000 - 500);
486   assert_equals_uint64 (_START (src1), 500);
487   assert_equals_uint64 (_DURATION (src1), 1250 - 500);
488
489   objects = ges_layer_get_clips (layer);
490   assert_equals_int (g_list_length (objects), 2);
491   g_list_free_full (objects, gst_object_unref);
492
493   objects = ges_layer_get_clips (layer);
494   assert_equals_int (g_list_length (objects), 2);
495   g_list_free_full (objects, gst_object_unref);
496
497   GST_DEBUG ("Moving first source to 600, no transition should be created");
498   ges_timeline_element_set_start (src, 600);
499   /*             600____src___1100
500    *        500___________src1________1250
501    */
502   GST_DEBUG ("Checking src timing values");
503   assert_equals_uint64 (_START (src), 600);
504   assert_equals_uint64 (_DURATION (src), 1100 - 600);
505   assert_equals_uint64 (_START (src1), 500);
506   assert_equals_uint64 (_DURATION (src1), 1250 - 500);
507
508   objects = ges_layer_get_clips (layer);
509   assert_equals_int (g_list_length (objects), 2);
510   g_list_free_full (objects, gst_object_unref);
511
512   objects = ges_layer_get_clips (layer);
513   assert_equals_int (g_list_length (objects), 2);
514   g_list_free_full (objects, gst_object_unref);
515
516   GST_DEBUG ("Adding asset to first layer");
517   GST_DEBUG ("Adding clip from 1250 -- 1000 to first layer");
518   src2 =
519       GES_TIMELINE_ELEMENT (ges_layer_add_asset (layer, asset, 1250, 0,
520           1000, GES_TRACK_TYPE_UNKNOWN));
521   assert_is_type (src2, GES_TYPE_TEST_CLIP);
522
523   /*             600____src___1100
524    *        500___________src1________1250
525    *                                  1250___________src2________2250
526    */
527   assert_equals_uint64 (_START (src), 600);
528   assert_equals_uint64 (_DURATION (src), 1100 - 600);
529   assert_equals_uint64 (_START (src1), 500);
530   assert_equals_uint64 (_DURATION (src1), 1250 - 500);
531   assert_equals_uint64 (_START (src2), 1250);
532   assert_equals_uint64 (_DURATION (src2), 1000);
533
534   objects = ges_layer_get_clips (layer);
535   assert_equals_int (g_list_length (objects), 3);
536   g_list_free_full (objects, gst_object_unref);
537
538   GST_DEBUG
539       ("Changig first source duration to 800 2 transitions should be created");
540   ges_timeline_element_set_duration (src, 800);
541   ges_timeline_commit (timeline);
542   /*             600__________________src_____________1400
543    *        500___________src1________1250
544    *                                  1250___________src2________2250
545    *             600_____trans1_______1250
546    *                                  1250___trans2___1400
547    */
548   GST_DEBUG ("Checking src timing values");
549   assert_equals_uint64 (_START (src), 600);
550   assert_equals_uint64 (_DURATION (src), 1400 - 600);
551   assert_equals_uint64 (_START (src1), 500);
552   assert_equals_uint64 (_DURATION (src1), 1250 - 500);
553
554   current = objects = ges_layer_get_clips (layer);
555   assert_equals_int (g_list_length (objects), 7);
556   assert_is_type (objects->data, GES_TYPE_TEST_CLIP);
557   fail_unless (objects->data == src1);
558
559   current = current->next;
560   transition = current->data;
561   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
562   assert_equals_uint64 (_START (transition), 600);
563   assert_equals_uint64 (_DURATION (transition), 1250 - 600);
564   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline + ourself", 3);
565
566   current = current->next;
567   transition = current->data;
568   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
569   assert_equals_uint64 (_START (transition), 600);
570   assert_equals_uint64 (_DURATION (transition), 1250 - 600);
571   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline + ourself", 3);
572
573   current = current->next;
574   fail_unless (current->data == src);
575
576   current = current->next;
577   transition = current->data;
578   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
579   assert_equals_uint64 (_START (transition), 1250);
580   assert_equals_uint64 (_DURATION (transition), 1400 - 1250);
581   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline + ourself", 3);
582
583   current = current->next;
584   transition = current->data;
585   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
586   assert_equals_uint64 (_START (transition), 1250);
587   assert_equals_uint64 (_DURATION (transition), 1400 - 1250);
588   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline + ourself", 3);
589
590   current = current->next;
591   fail_unless (current->data == src2);
592   g_list_free_full (objects, gst_object_unref);
593
594   GST_DEBUG ("Back to previous state");
595   /*  Make sure to keep 1 ref so we can check_destroyed afterward */
596   gst_object_ref (transition);
597   ges_timeline_element_set_duration (src, 1100 - 600);
598   /*             600____src___1100
599    *        500___________src1________1250
600    *                                  1250___________src2________2250
601    */
602   assert_equals_uint64 (_START (src), 600);
603   assert_equals_uint64 (_DURATION (src), 1100 - 600);
604   assert_equals_uint64 (_START (src1), 500);
605   assert_equals_uint64 (_DURATION (src1), 1250 - 500);
606   assert_equals_uint64 (_START (src2), 1250);
607   assert_equals_uint64 (_DURATION (src2), 1000);
608
609   /* We check that the transition as actually been freed */
610   check_destroyed (G_OBJECT (transition), NULL, NULL);
611
612   objects = ges_layer_get_clips (layer);
613   assert_equals_int (g_list_length (objects), 3);
614   g_list_free_full (objects, gst_object_unref);
615
616   GST_DEBUG
617       ("Set third clip start to 1100, 1 new transition should be created");
618   ges_timeline_element_set_start (src2, 1100);
619   ges_timeline_commit (timeline);
620   /*             600____src___1100
621    *        500___________src1________1250
622    *                          1100___________src2________2100
623    *                          ^__trans___^
624    */
625   assert_equals_uint64 (_START (src), 600);
626   assert_equals_uint64 (_DURATION (src), 1100 - 600);
627   assert_equals_uint64 (_START (src1), 500);
628   assert_equals_uint64 (_DURATION (src1), 1250 - 500);
629   assert_equals_uint64 (_START (src2), 1100);
630   assert_equals_uint64 (_DURATION (src2), 1000);
631
632   current = objects = ges_layer_get_clips (layer);
633   assert_equals_int (g_list_length (objects), 5);
634   assert_is_type (objects->data, GES_TYPE_TEST_CLIP);
635   fail_unless (current->data == src1);
636
637   current = current->next;
638   fail_unless (current->data == src);
639
640   current = current->next;
641   transition = current->data;
642   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
643   assert_equals_uint64 (_START (transition), 1100);
644   assert_equals_uint64 (_DURATION (transition), 1250 - 1100);
645
646   current = current->next;
647   transition = current->data;
648   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
649   assert_equals_uint64 (_START (transition), 1100);
650   assert_equals_uint64 (_DURATION (transition), 1250 - 1100);
651
652   current = current->next;
653   fail_unless (current->data == src2);
654   g_list_free_full (objects, gst_object_unref);
655
656   GST_DEBUG ("Check that we can not create 2 transitions at the same place");
657   fail_if (ges_container_edit (GES_CONTAINER (src2), NULL, -1,
658           GES_EDIT_MODE_NORMAL, GES_EDGE_START, 1000));
659
660   /*
661    *        500___________src1________1250
662    *                       1000___________src2________2000
663    *                       ^____trans____^
664    */
665   ges_layer_remove_clip (layer, GES_CLIP (src));
666   fail_unless (ges_container_edit (GES_CONTAINER (src2), NULL, -1,
667           GES_EDIT_MODE_NORMAL, GES_EDGE_START, 1000));
668   assert_equals_uint64 (_START (src1), 500);
669   assert_equals_uint64 (_DURATION (src1), 1250 - 500);
670   assert_equals_uint64 (_START (src2), 1000);
671   assert_equals_uint64 (_DURATION (src2), 1000);
672
673   current = objects = ges_layer_get_clips (layer);
674   current = objects;
675   assert_equals_int (g_list_length (objects), 4);
676   assert_is_type (objects->data, GES_TYPE_TEST_CLIP);
677   transition = objects->next->data;
678   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
679   fail_unless (current->data == src1);
680   g_list_free_full (objects, gst_object_unref);
681
682   /*
683    *        500___________src1________1250
684    *                       ^____trans____^
685    *                       1100___________src2________2000
686    */
687   ges_container_edit (GES_CONTAINER (transition),
688       NULL, -1, GES_EDIT_MODE_TRIM, GES_EDGE_START, 1100);
689   assert_equals_uint64 (_START (src1), 500);
690   assert_equals_uint64 (_DURATION (src1), 1250 - 500);
691   assert_equals_uint64 (_START (src2), 1100);
692   assert_equals_uint64 (_DURATION (src2), 2000 - 1100);
693
694   current = objects = ges_layer_get_clips (layer);
695   current = objects;
696   assert_equals_int (g_list_length (objects), 4);
697   assert_is_type (objects->data, GES_TYPE_TEST_CLIP);
698   fail_unless (current->data == src1);
699   g_list_free_full (objects, gst_object_unref);
700
701   gst_object_unref (timeline);
702 }
703
704 GST_END_TEST;
705
706 GST_START_TEST (test_multi_layer_automatic_transition)
707 {
708   GESAsset *asset;
709   GESTimeline *timeline;
710   GList *objects, *current;
711   GESClip *transition;
712   GESLayer *layer, *layer1;
713   GESTimelineElement *src, *src1, *src2, *src3;
714
715   ges_init ();
716
717   asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
718   fail_unless (GES_IS_ASSET (asset));
719
720   GST_DEBUG ("Create timeline");
721   timeline = ges_timeline_new_audio_video ();
722   assert_is_type (timeline, GES_TYPE_TIMELINE);
723
724   GST_DEBUG ("Create first layer");
725   layer = ges_layer_new ();
726   assert_is_type (layer, GES_TYPE_LAYER);
727
728   GST_DEBUG ("Add first layer to timeline");
729   fail_unless (ges_timeline_add_layer (timeline, layer));
730
731   GST_DEBUG ("Append a new layer to the timeline");
732   layer1 = ges_timeline_append_layer (timeline);
733   assert_is_type (layer1, GES_TYPE_LAYER);
734
735   GST_DEBUG ("Set auto transition to first layer");
736   ges_layer_set_auto_transition (layer, TRUE);
737
738   GST_DEBUG ("Check that auto-transition was properly set");
739   fail_unless (ges_layer_get_auto_transition (layer));
740   fail_if (ges_layer_get_auto_transition (layer1));
741
742   GST_DEBUG ("Adding assets to first layer");
743   GST_DEBUG ("Adding clip from 0 -- 1000 to first layer");
744   src = GES_TIMELINE_ELEMENT (ges_layer_add_asset (layer, asset, 0, 0,
745           1000, GES_TRACK_TYPE_UNKNOWN));
746   fail_unless (GES_IS_CLIP (src));
747
748   GST_DEBUG ("Adding clip from 500 -- 1000 to first layer");
749   src1 = GES_TIMELINE_ELEMENT (ges_layer_add_asset (layer, asset, 500,
750           0, 1000, GES_TRACK_TYPE_UNKNOWN));
751   ges_timeline_commit (timeline);
752   fail_unless (GES_IS_CLIP (src1));
753
754   /*
755    *        500__transition__1000
756    * 0___________src_________1000
757    *        500___________src1_________1500
758    */
759   GST_DEBUG ("Checking src timing values");
760   assert_equals_uint64 (_START (src), 0);
761   assert_equals_uint64 (_DURATION (src), 1000);
762   assert_equals_uint64 (_START (src1), 500);
763   assert_equals_uint64 (_DURATION (src1), 1500 - 500);
764
765   GST_DEBUG ("Checking that a transition has been added");
766   current = objects = ges_layer_get_clips (layer);
767   assert_equals_int (g_list_length (objects), 4);
768   assert_is_type (current->data, GES_TYPE_TEST_CLIP);
769
770   current = current->next;
771   transition = current->data;
772   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
773   assert_equals_uint64 (_START (transition), 500);
774   assert_equals_uint64 (_DURATION (transition), 500);
775
776   current = current->next;
777   transition = current->data;
778   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
779   assert_equals_uint64 (_START (transition), 500);
780   assert_equals_uint64 (_DURATION (transition), 500);
781   g_list_free_full (objects, gst_object_unref);
782   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
783
784   GST_DEBUG ("Adding clip 2 from 500 -- 1000 to second layer");
785   src2 = GES_TIMELINE_ELEMENT (ges_layer_add_asset (layer1, asset, 0,
786           0, 1000, GES_TRACK_TYPE_UNKNOWN));
787   GST_DEBUG ("Adding clip 3 from 500 -- 1000 to second layer");
788   src3 = GES_TIMELINE_ELEMENT (ges_layer_add_asset (layer1, asset, 500,
789           0, 1000, GES_TRACK_TYPE_UNKNOWN));
790   assert_is_type (src3, GES_TYPE_TEST_CLIP);
791
792   /*        500__transition__1000
793    * 0___________src_________1000
794    *        500___________src1_________1500
795    *----------------------------------------------------
796    * 0___________src2_________1000
797    *        500___________src3_________1500         Layer1
798    */
799   GST_DEBUG ("Checking src timing values");
800   assert_equals_uint64 (_START (src), 0);
801   assert_equals_uint64 (_DURATION (src), 1000);
802   assert_equals_uint64 (_START (src1), 500);
803   assert_equals_uint64 (_DURATION (src1), 1500 - 500);
804   assert_equals_uint64 (_START (src2), 0);
805   assert_equals_uint64 (_DURATION (src2), 1000);
806   assert_equals_uint64 (_START (src3), 500);
807   assert_equals_uint64 (_DURATION (src3), 1500 - 500);
808
809   GST_DEBUG ("Checking transitions on first layer");
810   current = objects = ges_layer_get_clips (layer);
811   assert_equals_int (g_list_length (objects), 4);
812   assert_is_type (current->data, GES_TYPE_TEST_CLIP);
813
814   current = current->next;
815   transition = current->data;
816   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
817   assert_equals_uint64 (_START (transition), 500);
818   assert_equals_uint64 (_DURATION (transition), 500);
819
820   current = current->next;
821   transition = current->data;
822   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
823   assert_equals_uint64 (_START (transition), 500);
824   assert_equals_uint64 (_DURATION (transition), 500);
825   g_list_free_full (objects, gst_object_unref);
826   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
827
828   GST_DEBUG ("Checking transitions on second layer");
829   current = objects = ges_layer_get_clips (layer1);
830   assert_equals_int (g_list_length (objects), 2);
831   fail_unless (current->data == src2);
832   fail_unless (current->next->data == src3);
833   g_list_free_full (objects, gst_object_unref);
834
835   GST_DEBUG
836       ("Set auto transition to second layer, a new transition should be added");
837   ges_layer_set_auto_transition (layer1, TRUE);
838
839   /*        500__transition__1000
840    * 0___________src_________1000
841    *        500___________src1_________1500
842    *----------------------------------------------------
843    *        500__transition__1000
844    * 0__________src2_________1000
845    *        500___________src3_________1500         Layer1
846    */
847   GST_DEBUG ("Checking src timing values");
848   assert_equals_uint64 (_START (src), 0);
849   assert_equals_uint64 (_DURATION (src), 1000);
850   assert_equals_uint64 (_START (src1), 500);
851   assert_equals_uint64 (_DURATION (src1), 1500 - 500);
852   assert_equals_uint64 (_START (src2), 0);
853   assert_equals_uint64 (_DURATION (src2), 1000);
854   assert_equals_uint64 (_START (src3), 500);
855   assert_equals_uint64 (_DURATION (src3), 1500 - 500);
856
857   GST_DEBUG ("Checking transitions on first layer");
858   current = objects = ges_layer_get_clips (layer);
859   assert_equals_int (g_list_length (objects), 4);
860   assert_is_type (current->data, GES_TYPE_TEST_CLIP);
861
862   current = current->next;
863   transition = current->data;
864   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
865   assert_equals_uint64 (_START (transition), 500);
866   assert_equals_uint64 (_DURATION (transition), 500);
867
868   current = current->next;
869   transition = current->data;
870   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
871   assert_equals_uint64 (_START (transition), 500);
872   assert_equals_uint64 (_DURATION (transition), 500);
873   g_list_free_full (objects, gst_object_unref);
874   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
875
876   GST_DEBUG ("Checking transitions has been added on second layer");
877   current = objects = ges_layer_get_clips (layer1);
878   assert_equals_int (g_list_length (objects), 4);
879   assert_is_type (current->data, GES_TYPE_TEST_CLIP);
880
881   current = current->next;
882   transition = current->data;
883   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
884   assert_equals_uint64 (_START (transition), 500);
885   assert_equals_uint64 (_DURATION (transition), 500);
886
887   current = current->next;
888   transition = current->data;
889   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
890   assert_equals_uint64 (_START (transition), 500);
891   assert_equals_uint64 (_DURATION (transition), 500);
892   g_list_free_full (objects, gst_object_unref);
893   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
894
895   GST_DEBUG ("Moving src3 to 1000. should remove transition");
896   ges_timeline_element_set_start (src3, 1000);
897
898   /*        500__transition__1000
899    * 0___________src_________1000
900    *        500___________src1_________1500                           Layer
901    *----------------------------------------------------
902    * 0__________src2_________1000
903    *                         1000___________src3_________2000         Layer1
904    */
905   GST_DEBUG ("Checking src timing values");
906   assert_equals_uint64 (_START (src), 0);
907   assert_equals_uint64 (_DURATION (src), 1000);
908   assert_equals_uint64 (_START (src1), 500);
909   assert_equals_uint64 (_DURATION (src1), 1500 - 500);
910   assert_equals_uint64 (_START (src2), 0);
911   assert_equals_uint64 (_DURATION (src2), 1000);
912   assert_equals_uint64 (_START (src3), 1000);
913   assert_equals_uint64 (_DURATION (src3), 2000 - 1000);
914
915   GST_DEBUG ("Checking transitions on first layer");
916   current = objects = ges_layer_get_clips (layer);
917   assert_equals_int (g_list_length (objects), 4);
918   assert_is_type (current->data, GES_TYPE_TEST_CLIP);
919
920   current = current->next;
921   transition = current->data;
922   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
923   assert_equals_uint64 (_START (transition), 500);
924   assert_equals_uint64 (_DURATION (transition), 500);
925
926   current = current->next;
927   transition = current->data;
928   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
929   assert_equals_uint64 (_START (transition), 500);
930   assert_equals_uint64 (_DURATION (transition), 500);
931   g_list_free_full (objects, gst_object_unref);
932   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
933
934   GST_DEBUG ("Checking transitions has been removed on second layer");
935   current = objects = ges_layer_get_clips (layer1);
936   assert_equals_int (g_list_length (objects), 2);
937   fail_unless (current->data == src2);
938   fail_unless (current->next->data == src3);
939   g_list_free_full (objects, gst_object_unref);
940   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
941
942   GST_DEBUG ("Moving src3 to first layer, should add a transition");
943   ges_clip_move_to_layer (GES_CLIP (src3), layer);
944
945   /*        500__transition__1000
946    * 0___________src_________1000
947    *        500___________src1_________1500
948    *                         1000___________src3_________2000   Layer
949    *                         1000__tr__1500
950    *----------------------------------------------------
951    * 0__________src2_________1000                               Layer1
952    */
953   GST_DEBUG ("Checking src timing values");
954   assert_equals_uint64 (_START (src), 0);
955   assert_equals_uint64 (_DURATION (src), 1000);
956   assert_equals_uint64 (_START (src1), 500);
957   assert_equals_uint64 (_DURATION (src1), 1500 - 500);
958   assert_equals_uint64 (_START (src2), 0);
959   assert_equals_uint64 (_DURATION (src2), 1000);
960   assert_equals_uint64 (_START (src3), 1000);
961   assert_equals_uint64 (_DURATION (src3), 2000 - 1000);
962
963   GST_DEBUG ("Checking transitions on first layer");
964   current = objects = ges_layer_get_clips (layer);
965   assert_equals_int (g_list_length (objects), 7);
966   fail_unless (current->data == src);
967
968   current = current->next;
969   transition = current->data;
970   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
971   assert_equals_uint64 (_START (transition), 500);
972   assert_equals_uint64 (_DURATION (transition), 500);
973
974   current = current->next;
975   transition = current->data;
976   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
977   assert_equals_uint64 (_START (transition), 500);
978   assert_equals_uint64 (_DURATION (transition), 500);
979
980   current = current->next;
981   fail_unless (current->data == src1);
982
983   current = current->next;
984   transition = current->data;
985   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
986   assert_equals_uint64 (_START (transition), 1000);
987   assert_equals_uint64 (_DURATION (transition), 1500 - 1000);
988
989   current = current->next;
990   transition = current->data;
991   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
992   assert_equals_uint64 (_START (transition), 1000);
993   assert_equals_uint64 (_DURATION (transition), 1500 - 1000);
994
995   current = current->next;
996   fail_unless (current->data == src3);
997
998   g_list_free_full (objects, gst_object_unref);
999   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
1000
1001   GST_DEBUG ("Checking second layer");
1002   current = objects = ges_layer_get_clips (layer1);
1003   assert_equals_int (g_list_length (objects), 1);
1004   fail_unless (current->data == src2);
1005   g_list_free_full (objects, gst_object_unref);
1006   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
1007
1008   GST_DEBUG
1009       ("Moving src to second layer, should remove first transition on first layer");
1010   ges_clip_move_to_layer (GES_CLIP (src), layer1);
1011
1012   /*        500___________src1_________1500
1013    *                         1000___________src3_________2000   Layer
1014    *                         1000__tr__1500
1015    *----------------------------------------------------
1016    * 0___________src_________1000
1017    * 0__________src2_________1000                               Layer1
1018    */
1019   GST_DEBUG ("Checking src timing values");
1020   assert_equals_uint64 (_START (src), 0);
1021   assert_equals_uint64 (_DURATION (src), 1000);
1022   assert_equals_uint64 (_START (src1), 500);
1023   assert_equals_uint64 (_DURATION (src1), 1500 - 500);
1024   assert_equals_uint64 (_START (src2), 0);
1025   assert_equals_uint64 (_DURATION (src2), 1000);
1026   assert_equals_uint64 (_START (src3), 1000);
1027   assert_equals_uint64 (_DURATION (src3), 2000 - 1000);
1028
1029   GST_DEBUG ("Checking transitions on first layer");
1030   current = objects = ges_layer_get_clips (layer);
1031   assert_equals_int (g_list_length (objects), 4);
1032   fail_unless (current->data == src1);
1033
1034   current = current->next;
1035   transition = current->data;
1036   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1037   assert_equals_uint64 (_START (transition), 1000);
1038   assert_equals_uint64 (_DURATION (transition), 500);
1039
1040   current = current->next;
1041   transition = current->data;
1042   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1043   assert_equals_uint64 (_START (transition), 1000);
1044   assert_equals_uint64 (_DURATION (transition), 500);
1045
1046   current = current->next;
1047   fail_unless (current->data == src3);
1048   g_list_free_full (objects, gst_object_unref);
1049   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
1050
1051   GST_DEBUG ("Checking second layer");
1052   current = objects = ges_layer_get_clips (layer1);
1053   assert_equals_int (g_list_length (objects), 2);
1054   assert_is_type (current->data, GES_TYPE_TEST_CLIP);
1055   assert_is_type (current->next->data, GES_TYPE_TEST_CLIP);
1056   g_list_free_full (objects, gst_object_unref);
1057   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
1058
1059   GST_DEBUG ("Edit src to first layer start=1500");
1060   ges_container_edit (GES_CONTAINER (src), NULL, 0,
1061       GES_EDIT_MODE_NORMAL, GES_EDGE_NONE, 1500);
1062   /*                                   1500___________src_________2500
1063    *                                   1500______tr______2000
1064    *        500___________src1_________1500                 ^
1065    *                         1000_________^_src3_________2000   Layer
1066    *                         1000__tr__1500
1067    *---------------------------------------------------------------------------
1068    * 0__________src2_________1000                               Layer1
1069    */
1070   GST_DEBUG ("Checking src timing values");
1071   assert_equals_uint64 (_START (src), 1500);
1072   assert_equals_uint64 (_DURATION (src), 1000);
1073   assert_equals_uint64 (_START (src1), 500);
1074   assert_equals_uint64 (_DURATION (src1), 1500 - 500);
1075   assert_equals_uint64 (_START (src2), 0);
1076   assert_equals_uint64 (_DURATION (src2), 1000);
1077   assert_equals_uint64 (_START (src3), 1000);
1078   assert_equals_uint64 (_DURATION (src3), 2000 - 1000);
1079
1080   GST_DEBUG ("Checking transitions on first layer");
1081   current = objects = ges_layer_get_clips (layer);
1082   assert_equals_int (g_list_length (objects), 7);
1083   fail_unless (current->data == src1);
1084
1085   current = current->next;
1086   transition = current->data;
1087   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1088   assert_equals_uint64 (_START (transition), 1000);
1089   assert_equals_uint64 (_DURATION (transition), 500);
1090
1091   current = current->next;
1092   transition = current->data;
1093   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1094   assert_equals_uint64 (_START (transition), 1000);
1095   assert_equals_uint64 (_DURATION (transition), 500);
1096
1097   current = current->next;
1098   fail_unless (current->data == src3);
1099
1100   current = current->next;
1101   transition = current->data;
1102   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1103   assert_equals_uint64 (_START (transition), 1500);
1104   assert_equals_uint64 (_DURATION (transition), 500);
1105
1106   current = current->next;
1107   transition = current->data;
1108   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1109   assert_equals_uint64 (_START (transition), 1500);
1110   assert_equals_uint64 (_DURATION (transition), 500);
1111
1112   current = current->next;
1113   fail_unless (current->data == src);
1114   g_list_free_full (objects, gst_object_unref);
1115   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
1116
1117   GST_DEBUG ("Checking second layer");
1118   current = objects = ges_layer_get_clips (layer1);
1119   assert_equals_int (g_list_length (objects), 1);
1120   assert_is_type (current->data, GES_TYPE_TEST_CLIP);
1121   g_list_free_full (objects, gst_object_unref);
1122   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
1123
1124   GST_DEBUG ("Ripple src1 to 700");
1125   ges_container_edit (GES_CONTAINER (src1), NULL, 0,
1126       GES_EDIT_MODE_RIPPLE, GES_EDGE_NONE, 700);
1127
1128   /*                                           1700___________src_________2700
1129    *                                           1700__tr__2000
1130    *                700___________src1_________1700
1131    *                                1200___________src3_________2200   Layer
1132    *                                1200___tr__1700
1133    *---------------------------------------------------------------------------
1134    * 0__________src2_________1000                               Layer1
1135    */
1136   GST_DEBUG ("Checking src timing values");
1137   assert_equals_uint64 (_START (src), 1700);
1138   assert_equals_uint64 (_DURATION (src), 1000);
1139   assert_equals_uint64 (_START (src1), 700);
1140   assert_equals_uint64 (_DURATION (src1), 1700 - 700);
1141   assert_equals_uint64 (_START (src2), 0);
1142   assert_equals_uint64 (_DURATION (src2), 1000);
1143   assert_equals_uint64 (_START (src3), 1200);
1144   assert_equals_uint64 (_DURATION (src3), 2200 - 1200);
1145
1146   GST_DEBUG ("Checking transitions on first layer");
1147   current = objects = ges_layer_get_clips (layer);
1148   assert_equals_int (g_list_length (objects), 7);
1149   fail_unless (current->data == src1);
1150
1151   current = current->next;
1152   transition = current->data;
1153   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1154   assert_equals_uint64 (_START (transition), 1200);
1155   assert_equals_uint64 (_DURATION (transition), 1700 - 1200);
1156
1157   current = current->next;
1158   transition = current->data;
1159   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1160   assert_equals_uint64 (_START (transition), 1200);
1161   assert_equals_uint64 (_DURATION (transition), 1700 - 1200);
1162
1163   current = current->next;
1164   fail_unless (current->data == src3);
1165
1166   current = current->next;
1167   transition = current->data;
1168   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1169   assert_equals_uint64 (_START (transition), 1700);
1170   assert_equals_uint64 (_DURATION (transition), 2200 - 1700);
1171
1172   current = current->next;
1173   transition = current->data;
1174   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1175   assert_equals_uint64 (_START (transition), 1700);
1176   assert_equals_uint64 (_DURATION (transition), 2200 - 1700);
1177
1178   current = current->next;
1179   fail_unless (current->data == src);
1180   g_list_free_full (objects, gst_object_unref);
1181   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
1182
1183   GST_DEBUG ("Checking second layer");
1184   current = objects = ges_layer_get_clips (layer1);
1185   assert_equals_int (g_list_length (objects), 1);
1186   assert_is_type (current->data, GES_TYPE_TEST_CLIP);
1187   g_list_free_full (objects, gst_object_unref);
1188   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
1189
1190   gst_object_unref (timeline);
1191 }
1192
1193 GST_END_TEST;
1194
1195 GST_START_TEST (test_layer_activate_automatic_transition)
1196 {
1197   GESAsset *asset, *transition_asset;
1198   GESTimeline *timeline;
1199   GESLayer *layer;
1200   GList *objects, *current;
1201   GESClip *transition;
1202   GESTimelineElement *src, *src1, *src2, *src3;
1203
1204   ges_init ();
1205
1206   asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
1207   transition_asset =
1208       ges_asset_request (GES_TYPE_TRANSITION_CLIP, "crossfade", NULL);
1209   fail_unless (GES_IS_ASSET (asset));
1210
1211   GST_DEBUG ("Create timeline");
1212   timeline = ges_timeline_new_audio_video ();
1213   assert_is_type (timeline, GES_TYPE_TIMELINE);
1214
1215   GST_DEBUG ("Append a layer to the timeline");
1216   layer = ges_timeline_append_layer (timeline);
1217   assert_is_type (layer, GES_TYPE_LAYER);
1218
1219   GST_DEBUG ("Adding clip from 0 -- 1000 to layer");
1220   src = GES_TIMELINE_ELEMENT (ges_layer_add_asset (layer, asset, 0, 0,
1221           1000, GES_TRACK_TYPE_UNKNOWN));
1222   fail_unless (GES_IS_CLIP (src));
1223
1224   GST_DEBUG ("Adding clip from 500 -- 1000 to first layer");
1225   src1 = GES_TIMELINE_ELEMENT (ges_layer_add_asset (layer, asset, 500,
1226           0, 1000, GES_TRACK_TYPE_UNKNOWN));
1227   fail_unless (GES_IS_CLIP (src1));
1228
1229   GST_DEBUG ("Adding clip from 1000 -- 2000 to layer");
1230   src2 = GES_TIMELINE_ELEMENT (ges_layer_add_asset (layer, asset, 1000,
1231           0, 1000, GES_TRACK_TYPE_UNKNOWN));
1232   fail_unless (GES_IS_CLIP (src2));
1233
1234   GST_DEBUG ("Adding clip from 2000 -- 2500 to layer");
1235   src3 = GES_TIMELINE_ELEMENT (ges_layer_add_asset (layer, asset, 2000,
1236           0, 500, GES_TRACK_TYPE_UNKNOWN));
1237   fail_unless (GES_IS_CLIP (src3));
1238
1239   /*
1240    * 0___________src_________1000
1241    *        500___________src1_________1500
1242    *                         1000____src2_______2000
1243    *                                            2000_______src2_____2500
1244    */
1245   GST_DEBUG ("Checking src timing values");
1246   assert_equals_uint64 (_START (src), 0);
1247   assert_equals_uint64 (_DURATION (src), 1000);
1248   assert_equals_uint64 (_START (src1), 500);
1249   assert_equals_uint64 (_DURATION (src1), 1500 - 500);
1250   assert_equals_uint64 (_START (src2), 1000);
1251   assert_equals_uint64 (_DURATION (src2), 1000);
1252   assert_equals_uint64 (_START (src3), 2000);
1253   assert_equals_uint64 (_DURATION (src3), 500);
1254
1255   GST_DEBUG ("Checking that no transition has been added");
1256   current = objects = ges_layer_get_clips (layer);
1257   assert_equals_int (g_list_length (objects), 4);
1258   assert_is_type (current->data, GES_TYPE_TEST_CLIP);
1259   g_list_free_full (objects, gst_object_unref);
1260
1261   GST_DEBUG ("Adding transition from 1000 -- 1500 to layer");
1262   transition =
1263       GES_CLIP (ges_layer_add_asset (layer,
1264           transition_asset, 1000, 0, 500, GES_TRACK_TYPE_VIDEO));
1265   fail_unless (GES_IS_TRANSITION_CLIP (transition));
1266   objects = GES_CONTAINER_CHILDREN (transition);
1267   assert_equals_int (g_list_length (objects), 1);
1268
1269   GST_DEBUG ("Checking the transitions");
1270   /*
1271    * 0___________src_________1000
1272    *        500___________src1_________1500
1273    *                         1000__tr__1500 (1 of the 2 tracks only)
1274    *                         1000____src2_______2000
1275    *                                            2000_______src3_____2500
1276    */
1277   current = objects = ges_layer_get_clips (layer);
1278   assert_equals_int (g_list_length (objects), 5);
1279   current = current->next;
1280   assert_is_type (current->data, GES_TYPE_TEST_CLIP);
1281   current = current->next;
1282   assert_is_type (current->data, GES_TYPE_TRANSITION_CLIP);
1283   current = current->next;
1284   assert_is_type (current->data, GES_TYPE_TEST_CLIP);
1285   current = current->next;
1286   assert_is_type (current->data, GES_TYPE_TEST_CLIP);
1287   g_list_free_full (objects, gst_object_unref);
1288
1289   ges_layer_set_auto_transition (layer, TRUE);
1290   /*
1291    * 0___________src_________1000
1292    *        500______tr______1000
1293    *        500___________src1_________1500
1294    *                         1000__tr__1500
1295    *                         1000____src2_______2000
1296    *                                            2000_______src3_____2500
1297    */
1298   current = objects = ges_layer_get_clips (layer);
1299   assert_equals_int (g_list_length (objects), 8);
1300   assert_equals_uint64 (_START (src), 0);
1301   assert_equals_uint64 (_DURATION (src), 1000);
1302   assert_equals_uint64 (_START (src1), 500);
1303   assert_equals_uint64 (_DURATION (src1), 1500 - 500);
1304   assert_equals_uint64 (_START (src2), 1000);
1305   assert_equals_uint64 (_DURATION (src2), 1000);
1306   assert_equals_uint64 (_START (src3), 2000);
1307   assert_equals_uint64 (_DURATION (src3), 500);
1308
1309   GST_DEBUG ("Checking transitions");
1310   fail_unless (current->data == src);
1311
1312   current = current->next;
1313   transition = current->data;
1314   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1315   assert_equals_uint64 (_START (transition), 500);
1316   assert_equals_uint64 (_DURATION (transition), 500);
1317
1318   current = current->next;
1319   transition = current->data;
1320   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1321   assert_equals_uint64 (_START (transition), 500);
1322   assert_equals_uint64 (_DURATION (transition), 500);
1323
1324   current = current->next;
1325   fail_unless (current->data == src1);
1326
1327   current = current->next;
1328   transition = current->data;
1329   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1330   assert_equals_uint64 (_START (transition), 1000);
1331   assert_equals_uint64 (_DURATION (transition), 500);
1332
1333   current = current->next;
1334   transition = current->data;
1335   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1336   assert_equals_uint64 (_START (transition), 1000);
1337   assert_equals_uint64 (_DURATION (transition), 500);
1338
1339   current = current->next;
1340   fail_unless (current->data == src2);
1341
1342   current = current->next;
1343   fail_unless (current->data == src3);
1344   g_list_free_full (objects, gst_object_unref);
1345   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
1346
1347   GST_DEBUG ("Moving src2 to 1200, check everything updates properly");
1348   ges_timeline_element_set_start (src2, 1200);
1349   ges_timeline_commit (timeline);
1350   /*
1351    * 0___________src_________1000
1352    *        500______tr______1000
1353    *        500___________src1_________1500
1354    *                           1200_tr_1500
1355    *                           1200____src2_______2200
1356    *                                          !__tr__^
1357    *                                          2000_______src3_____2500
1358    */
1359   current = objects = ges_layer_get_clips (layer);
1360   assert_equals_int (g_list_length (objects), 10);
1361   assert_equals_uint64 (_START (src), 0);
1362   assert_equals_uint64 (_DURATION (src), 1000);
1363   assert_equals_uint64 (_START (src1), 500);
1364   assert_equals_uint64 (_DURATION (src1), 1500 - 500);
1365   assert_equals_uint64 (_START (src2), 1200);
1366   assert_equals_uint64 (_DURATION (src2), 1000);
1367   assert_equals_uint64 (_START (src3), 2000);
1368   assert_equals_uint64 (_DURATION (src3), 500);
1369
1370   GST_DEBUG ("Checking transitions");
1371   fail_unless (current->data == src);
1372
1373   current = current->next;
1374   transition = current->data;
1375   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1376   assert_equals_uint64 (_START (transition), 500);
1377   assert_equals_uint64 (_DURATION (transition), 500);
1378
1379   current = current->next;
1380   transition = current->data;
1381   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1382   assert_equals_uint64 (_START (transition), 500);
1383   assert_equals_uint64 (_DURATION (transition), 500);
1384
1385   current = current->next;
1386   fail_unless (current->data == src1);
1387
1388   current = current->next;
1389   transition = current->data;
1390   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1391   assert_equals_uint64 (_START (transition), 1200);
1392   assert_equals_uint64 (_DURATION (transition), 300);
1393
1394   current = current->next;
1395   transition = current->data;
1396   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1397   assert_equals_uint64 (_START (transition), 1200);
1398   assert_equals_uint64 (_DURATION (transition), 300);
1399
1400   current = current->next;
1401   fail_unless (current->data == src2);
1402
1403   current = current->next;
1404   transition = current->data;
1405   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1406   assert_equals_uint64 (_START (transition), 2000);
1407   assert_equals_uint64 (_DURATION (transition), 200);
1408
1409   current = current->next;
1410   transition = current->data;
1411   assert_is_type (transition, GES_TYPE_TRANSITION_CLIP);
1412   assert_equals_uint64 (_START (transition), 2000);
1413   assert_equals_uint64 (_DURATION (transition), 200);
1414
1415   current = current->next;
1416   fail_unless (current->data == src3);
1417   g_list_free_full (objects, gst_object_unref);
1418   ASSERT_OBJECT_REFCOUNT (transition, "layer + timeline", 2);
1419
1420
1421   gst_object_unref (timeline);
1422 }
1423
1424 GST_END_TEST;
1425
1426 GST_START_TEST (test_layer_meta_string)
1427 {
1428   GESTimeline *timeline;
1429   GESLayer *layer;
1430   const gchar *result;
1431
1432   ges_init ();
1433
1434   timeline = ges_timeline_new_audio_video ();
1435   layer = ges_layer_new ();
1436   ges_timeline_add_layer (timeline, layer);
1437
1438   ges_meta_container_set_string (GES_META_CONTAINER (layer),
1439       "ges-test", "blub");
1440
1441   fail_unless ((result = ges_meta_container_get_string (GES_META_CONTAINER
1442               (layer), "ges-test")) != NULL);
1443
1444   assert_equals_string (result, "blub");
1445 }
1446
1447 GST_END_TEST;
1448
1449 GST_START_TEST (test_layer_meta_boolean)
1450 {
1451   GESTimeline *timeline;
1452   GESLayer *layer;
1453   gboolean result;
1454
1455   ges_init ();
1456
1457   timeline = ges_timeline_new_audio_video ();
1458   layer = ges_layer_new ();
1459   ges_timeline_add_layer (timeline, layer);
1460
1461   ges_meta_container_set_boolean (GES_META_CONTAINER (layer), "ges-test", TRUE);
1462
1463   fail_unless (ges_meta_container_get_boolean (GES_META_CONTAINER
1464           (layer), "ges-test", &result));
1465
1466   fail_unless (result);
1467 }
1468
1469 GST_END_TEST;
1470
1471 GST_START_TEST (test_layer_meta_int)
1472 {
1473   GESTimeline *timeline;
1474   GESLayer *layer;
1475   gint result;
1476
1477   ges_init ();
1478
1479   timeline = ges_timeline_new_audio_video ();
1480   layer = ges_layer_new ();
1481   ges_timeline_add_layer (timeline, layer);
1482
1483   ges_meta_container_set_int (GES_META_CONTAINER (layer), "ges-test", 1234);
1484
1485   fail_unless (ges_meta_container_get_int (GES_META_CONTAINER (layer),
1486           "ges-test", &result));
1487
1488   assert_equals_int (result, 1234);
1489 }
1490
1491 GST_END_TEST;
1492
1493 GST_START_TEST (test_layer_meta_uint)
1494 {
1495   GESTimeline *timeline;
1496   GESLayer *layer;
1497   guint result;
1498
1499   ges_init ();
1500
1501   timeline = ges_timeline_new_audio_video ();
1502   layer = ges_layer_new ();
1503   ges_timeline_add_layer (timeline, layer);
1504
1505   ges_meta_container_set_uint (GES_META_CONTAINER (layer), "ges-test", 42);
1506
1507   fail_unless (ges_meta_container_get_uint (GES_META_CONTAINER
1508           (layer), "ges-test", &result));
1509
1510   assert_equals_int (result, 42);
1511 }
1512
1513 GST_END_TEST;
1514
1515 GST_START_TEST (test_layer_meta_int64)
1516 {
1517   GESTimeline *timeline;
1518   GESLayer *layer;
1519   gint64 result;
1520
1521   ges_init ();
1522
1523   timeline = ges_timeline_new_audio_video ();
1524   layer = ges_layer_new ();
1525   ges_timeline_add_layer (timeline, layer);
1526
1527   ges_meta_container_set_int64 (GES_META_CONTAINER (layer), "ges-test", 1234);
1528
1529   fail_unless (ges_meta_container_get_int64 (GES_META_CONTAINER (layer),
1530           "ges-test", &result));
1531
1532   assert_equals_int64 (result, 1234);
1533 }
1534
1535 GST_END_TEST;
1536
1537 GST_START_TEST (test_layer_meta_uint64)
1538 {
1539   GESTimeline *timeline;
1540   GESLayer *layer;
1541   guint64 result;
1542
1543   ges_init ();
1544
1545   timeline = ges_timeline_new_audio_video ();
1546   layer = ges_layer_new ();
1547   ges_timeline_add_layer (timeline, layer);
1548
1549   ges_meta_container_set_uint64 (GES_META_CONTAINER (layer), "ges-test", 42);
1550
1551   fail_unless (ges_meta_container_get_uint64 (GES_META_CONTAINER
1552           (layer), "ges-test", &result));
1553
1554   assert_equals_uint64 (result, 42);
1555 }
1556
1557 GST_END_TEST;
1558
1559 GST_START_TEST (test_layer_meta_float)
1560 {
1561   GESTimeline *timeline;
1562   GESLayer *layer;
1563   gfloat result;
1564
1565   ges_init ();
1566
1567   timeline = ges_timeline_new_audio_video ();
1568   layer = ges_layer_new ();
1569   ges_timeline_add_layer (timeline, layer);
1570
1571   fail_unless (ges_meta_container_set_float (GES_META_CONTAINER (layer),
1572           "ges-test", 23.456));
1573
1574   fail_unless (ges_meta_container_get_float (GES_META_CONTAINER (layer),
1575           "ges-test", &result));
1576
1577   assert_equals_float (result, 23.456f);
1578 }
1579
1580 GST_END_TEST;
1581
1582 GST_START_TEST (test_layer_meta_double)
1583 {
1584   GESTimeline *timeline;
1585   GESLayer *layer;
1586   gdouble result;
1587
1588   ges_init ();
1589
1590   timeline = ges_timeline_new_audio_video ();
1591   layer = ges_layer_new ();
1592   ges_timeline_add_layer (timeline, layer);
1593
1594   ges_meta_container_set_double (GES_META_CONTAINER (layer),
1595       "ges-test", 23.456);
1596
1597   fail_unless (ges_meta_container_get_double (GES_META_CONTAINER
1598           (layer), "ges-test", &result));
1599   fail_unless (result == 23.456);
1600
1601   //TODO CHECK
1602   assert_equals_float (result, 23.456);
1603 }
1604
1605 GST_END_TEST;
1606
1607 GST_START_TEST (test_layer_meta_date)
1608 {
1609   GESTimeline *timeline;
1610   GESLayer *layer;
1611   GDate *input;
1612   GDate *result;
1613
1614   ges_init ();
1615
1616   timeline = ges_timeline_new_audio_video ();
1617   layer = ges_layer_new ();
1618   ges_timeline_add_layer (timeline, layer);
1619
1620   input = g_date_new_dmy (1, 1, 2012);
1621
1622   ges_meta_container_set_date (GES_META_CONTAINER (layer), "ges-test", input);
1623
1624   fail_unless (ges_meta_container_get_date (GES_META_CONTAINER
1625           (layer), "ges-test", &result));
1626
1627   fail_unless (g_date_compare (result, input) == 0);
1628
1629   g_date_free (input);
1630   g_date_free (result);
1631 }
1632
1633 GST_END_TEST;
1634
1635 GST_START_TEST (test_layer_meta_date_time)
1636 {
1637   GESTimeline *timeline;
1638   GESLayer *layer;
1639   GstDateTime *input;
1640   GstDateTime *result = NULL;
1641
1642   ges_init ();
1643
1644   timeline = ges_timeline_new_audio_video ();
1645   layer = ges_layer_new ();
1646   ges_timeline_add_layer (timeline, layer);
1647
1648   input = gst_date_time_new_from_unix_epoch_local_time (123456789);
1649
1650   fail_unless (ges_meta_container_set_date_time (GES_META_CONTAINER
1651           (layer), "ges-test", input));
1652
1653   fail_unless (ges_meta_container_get_date_time (GES_META_CONTAINER
1654           (layer), "ges-test", &result));
1655
1656   fail_unless (result != NULL);
1657   fail_unless (gst_date_time_get_day (input) == gst_date_time_get_day (result));
1658   fail_unless (gst_date_time_get_hour (input) ==
1659       gst_date_time_get_hour (result));
1660
1661   gst_date_time_unref (input);
1662   gst_date_time_unref (result);
1663 }
1664
1665 GST_END_TEST;
1666
1667
1668 GST_START_TEST (test_layer_meta_value)
1669 {
1670   GESTimeline *timeline;
1671   GESLayer *layer;
1672   GValue data = G_VALUE_INIT;
1673   const GValue *result;
1674
1675   ges_init ();
1676
1677   timeline = ges_timeline_new_audio_video ();
1678   layer = ges_layer_new ();
1679   ges_timeline_add_layer (timeline, layer);
1680
1681   g_value_init (&data, G_TYPE_STRING);
1682   g_value_set_string (&data, "Hello world!");
1683
1684   ges_meta_container_set_meta (GES_META_CONTAINER (layer),
1685       "ges-test-value", &data);
1686
1687   result =
1688       ges_meta_container_get_meta (GES_META_CONTAINER (layer),
1689       "ges-test-value");
1690   assert_equals_string (g_value_get_string (result), "Hello world!");
1691
1692   g_value_unset (&data);
1693 }
1694
1695 GST_END_TEST;
1696
1697 GST_START_TEST (test_layer_meta_register)
1698 {
1699   GESTimeline *timeline;
1700   GESLayer *layer;
1701   const gchar *result;
1702
1703   ges_init ();
1704
1705   timeline = ges_timeline_new_audio_video ();
1706   layer = ges_layer_new ();
1707   ges_timeline_add_layer (timeline, layer);
1708
1709   fail_unless (ges_meta_container_register_meta_string (GES_META_CONTAINER
1710           (layer), GES_META_READABLE, "ges-test-value", "Hello world!"));
1711
1712   result = ges_meta_container_get_string (GES_META_CONTAINER (layer),
1713       "ges-test-value");
1714   assert_equals_string (result, "Hello world!");
1715
1716   fail_if (ges_meta_container_set_int (GES_META_CONTAINER (layer),
1717           "ges-test-value", 123456));
1718
1719   result = ges_meta_container_get_string (GES_META_CONTAINER (layer),
1720       "ges-test-value");
1721   assert_equals_string (result, "Hello world!");
1722 }
1723
1724 GST_END_TEST;
1725
1726 static void
1727 test_foreach (const GESMetaContainer * container, const gchar * key,
1728     GValue * value, gpointer user_data)
1729 {
1730   fail_unless ((0 == g_strcmp0 (key, "some-string")) ||
1731       (0 == g_strcmp0 (key, "some-int")) || (0 == g_strcmp0 (key, "volume")));
1732 }
1733
1734 GST_START_TEST (test_layer_meta_foreach)
1735 {
1736   GESTimeline *timeline;
1737   GESLayer *layer;
1738
1739   ges_init ();
1740
1741   timeline = ges_timeline_new_audio_video ();
1742   layer = ges_layer_new ();
1743   ges_timeline_add_layer (timeline, layer);
1744
1745   ges_meta_container_set_string (GES_META_CONTAINER (layer),
1746       "some-string", "some-content");
1747
1748   ges_meta_container_set_int (GES_META_CONTAINER (layer), "some-int", 123456);
1749
1750   ges_meta_container_foreach (GES_META_CONTAINER (layer),
1751       (GESMetaForeachFunc) test_foreach, NULL);
1752 }
1753
1754 GST_END_TEST;
1755
1756 GST_START_TEST (test_layer_get_clips_in_interval)
1757 {
1758   GESTimeline *timeline;
1759   GESLayer *layer;
1760   GESClip *clip, *clip2, *clip3;
1761   GList *objects, *current;
1762
1763   ges_init ();
1764
1765   timeline = ges_timeline_new_audio_video ();
1766   layer = ges_layer_new ();
1767   ges_timeline_add_layer (timeline, layer);
1768
1769   clip = (GESClip *) ges_test_clip_new ();
1770   fail_unless (clip != NULL);
1771   g_object_set (clip, "start", 10, "duration", 30, NULL);
1772   assert_equals_uint64 (_START (clip), 10);
1773   assert_equals_uint64 (_DURATION (clip), 30);
1774
1775   ges_layer_add_clip (layer, GES_CLIP (clip));
1776
1777   /* Clip's start lies between the interval */
1778   current = objects = ges_layer_get_clips_in_interval (layer, 0, 30);
1779   assert_equals_int (g_list_length (objects), 1);
1780   fail_unless (current->data == GES_TIMELINE_ELEMENT (clip));
1781
1782   current = objects = ges_layer_get_clips_in_interval (layer, 0, 11);
1783   assert_equals_int (g_list_length (objects), 1);
1784   fail_unless (current->data == GES_TIMELINE_ELEMENT (clip));
1785
1786   /* Clip's end lies between the interval */
1787   current = objects = ges_layer_get_clips_in_interval (layer, 30, 50);
1788   assert_equals_int (g_list_length (objects), 1);
1789   fail_unless (current->data == GES_TIMELINE_ELEMENT (clip));
1790
1791   current = objects = ges_layer_get_clips_in_interval (layer, 39, 50);
1792   assert_equals_int (g_list_length (objects), 1);
1793   fail_unless (current->data == GES_TIMELINE_ELEMENT (clip));
1794
1795   /* Clip exactly overlaps the interval */
1796   current = objects = ges_layer_get_clips_in_interval (layer, 10, 40);
1797   assert_equals_int (g_list_length (objects), 1);
1798   fail_unless (current->data == GES_TIMELINE_ELEMENT (clip));
1799
1800   /* Clip completely inside the interval */
1801   current = objects = ges_layer_get_clips_in_interval (layer, 0, 50);
1802   assert_equals_int (g_list_length (objects), 1);
1803   fail_unless (current->data == GES_TIMELINE_ELEMENT (clip));
1804
1805   /* Interval completely inside the clip duration */
1806   current = objects = ges_layer_get_clips_in_interval (layer, 20, 30);
1807   assert_equals_int (g_list_length (objects), 1);
1808   fail_unless (current->data == GES_TIMELINE_ELEMENT (clip));
1809
1810   /* No intersecting clip */
1811   objects = ges_layer_get_clips_in_interval (layer, 0, 10);
1812   assert_equals_int (g_list_length (objects), 0);
1813
1814   objects = ges_layer_get_clips_in_interval (layer, 40, 50);
1815   assert_equals_int (g_list_length (objects), 0);
1816
1817   /* Multiple intersecting clips */
1818   clip2 = (GESClip *) ges_test_clip_new ();
1819   fail_unless (clip2 != NULL);
1820   g_object_set (clip2, "start", 50, "duration", 10, NULL);
1821   assert_equals_uint64 (_START (clip2), 50);
1822   assert_equals_uint64 (_DURATION (clip2), 10);
1823
1824   ges_layer_add_clip (layer, GES_CLIP (clip2));
1825
1826   clip3 = (GESClip *) ges_test_clip_new ();
1827   fail_unless (clip3 != NULL);
1828   g_object_set (clip3, "start", 0, "duration", 5, NULL);
1829   assert_equals_uint64 (_START (clip3), 0);
1830   assert_equals_uint64 (_DURATION (clip3), 5);
1831
1832   ges_layer_add_clip (layer, GES_CLIP (clip3));
1833
1834   /**
1835   * Our timeline:
1836   * -------------
1837   *
1838   *          |--------    0---------------     0---------       |
1839   * layer:   |  clip3 |   |     clip     |     |  clip2  |      |
1840   *          |-------05  10-------------40    50--------60      |
1841   *          |--------------------------------------------------|
1842   *
1843   */
1844
1845   current = objects = ges_layer_get_clips_in_interval (layer, 4, 52);
1846   assert_equals_int (g_list_length (objects), 3);
1847   fail_unless (current->data == GES_TIMELINE_ELEMENT (clip3));
1848   current = current->next;
1849   fail_unless (current->data == GES_TIMELINE_ELEMENT (clip));
1850   current = current->next;
1851   fail_unless (current->data == GES_TIMELINE_ELEMENT (clip2));
1852
1853   current = objects = ges_layer_get_clips_in_interval (layer, 39, 65);
1854   assert_equals_int (g_list_length (objects), 2);
1855   fail_unless (current->data == GES_TIMELINE_ELEMENT (clip));
1856   current = current->next;
1857   fail_unless (current->data == GES_TIMELINE_ELEMENT (clip2));
1858
1859 }
1860
1861 GST_END_TEST;
1862
1863 static Suite *
1864 ges_suite (void)
1865 {
1866   Suite *s = suite_create ("ges-layer");
1867   TCase *tc_chain = tcase_create ("timeline-layer");
1868
1869   if (atexit (ges_deinit) != 0) {
1870     GST_ERROR ("failed to set ges_deinit as exit function");
1871   }
1872
1873   suite_add_tcase (s, tc_chain);
1874
1875   tcase_add_test (tc_chain, test_layer_properties);
1876   tcase_add_test (tc_chain, test_layer_priorities);
1877   tcase_add_test (tc_chain, test_timeline_auto_transition);
1878   tcase_add_test (tc_chain, test_single_layer_automatic_transition);
1879   tcase_add_test (tc_chain, test_multi_layer_automatic_transition);
1880   tcase_add_test (tc_chain, test_layer_activate_automatic_transition);
1881   tcase_add_test (tc_chain, test_layer_meta_string);
1882   tcase_add_test (tc_chain, test_layer_meta_boolean);
1883   tcase_add_test (tc_chain, test_layer_meta_int);
1884   tcase_add_test (tc_chain, test_layer_meta_uint);
1885   tcase_add_test (tc_chain, test_layer_meta_int64);
1886   tcase_add_test (tc_chain, test_layer_meta_uint64);
1887   tcase_add_test (tc_chain, test_layer_meta_float);
1888   tcase_add_test (tc_chain, test_layer_meta_double);
1889   tcase_add_test (tc_chain, test_layer_meta_date);
1890   tcase_add_test (tc_chain, test_layer_meta_date_time);
1891   tcase_add_test (tc_chain, test_layer_meta_value);
1892   tcase_add_test (tc_chain, test_layer_meta_register);
1893   tcase_add_test (tc_chain, test_layer_meta_foreach);
1894   tcase_add_test (tc_chain, test_layer_get_clips_in_interval);
1895
1896   return s;
1897 }
1898
1899 GST_CHECK_MAIN (ges);