Reimplement the timeline editing API
[platform/upstream/gst-editing-services.git] / tests / check / ges / basic.c
1 /* GStreamer Editing Services
2  * Copyright (C) 2009 Edward Hervey <bilboed@bilboed.com>
3  *               2012 Collabora Ltd.
4  *                 Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #include "test-utils.h"
23
24 #include <ges/ges.h>
25 #include <gst/check/gstcheck.h>
26
27
28 GST_START_TEST (test_ges_scenario)
29 {
30   GESTimeline *timeline;
31   GESLayer *layer, *tmp_layer;
32   GESTrack *track;
33   GESTestClip *source;
34   GESTrackElement *trackelement;
35   GList *trackelements, *layers, *tracks;
36
37   ges_init ();
38   /* This is the simplest scenario ever */
39
40   /* Timeline and 1 Layer */
41   GST_DEBUG ("Create a timeline");
42   timeline = ges_timeline_new ();
43   fail_unless (timeline != NULL);
44
45   GST_DEBUG ("Create a layer");
46   layer = ges_layer_new ();
47   fail_unless (layer != NULL);
48
49   GST_DEBUG ("Add the layer to the timeline");
50   fail_unless (ges_timeline_add_layer (timeline, layer));
51   /* The timeline steals our reference to the layer */
52   ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
53   fail_unless (layer->timeline == timeline);
54
55   layers = ges_timeline_get_layers (timeline);
56   fail_unless (g_list_find (layers, layer) != NULL);
57   g_list_foreach (layers, (GFunc) gst_object_unref, NULL);
58   g_list_free (layers);
59
60   /* Give the Timeline a Track */
61   GST_DEBUG ("Create a Track");
62   track = GES_TRACK (ges_video_track_new ());
63   fail_unless (track != NULL);
64
65   GST_DEBUG ("Add the track to the timeline");
66   fail_unless (ges_timeline_add_track (timeline, track));
67
68   /* The timeline steals the reference to the track */
69   ASSERT_OBJECT_REFCOUNT (track, "track", 1);
70   fail_unless (ges_track_get_timeline (track) == timeline);
71   fail_unless ((gpointer) GST_ELEMENT_PARENT (track) == (gpointer) timeline);
72
73   /* Create a source and add it to the Layer */
74   GST_DEBUG ("Creating a source");
75   source = ges_test_clip_new ();
76   fail_unless (source != NULL);
77
78   /* The source will be floating before added to the layer... */
79   fail_unless (g_object_is_floating (source));
80   GST_DEBUG ("Adding the source to the timeline layer");
81   fail_unless (ges_layer_add_clip (layer, GES_CLIP (source)));
82   fail_if (g_object_is_floating (source));
83   tmp_layer = ges_clip_get_layer (GES_CLIP (source));
84   fail_unless (tmp_layer == layer);
85   /* The timeline stole our reference */
86   ASSERT_OBJECT_REFCOUNT (source, "source + 1 timeline", 2);
87   gst_object_unref (tmp_layer);
88   ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
89
90   /* Make sure the associated TrackElement is in the Track */
91   trackelements = GES_CONTAINER_CHILDREN (source);
92   fail_unless (trackelements != NULL);
93   trackelement = GES_TRACK_ELEMENT (trackelements->data);
94   /* There are 3 references:
95    * 1 by the clip
96    * 1 by the track
97    * 1 by the timeline */
98   ASSERT_OBJECT_REFCOUNT (trackelement, "trackelement", 3);
99   /* There are 3 references:
100    * 1 by the clip
101    * 3 by the timeline
102    * 1 by the track */
103   ASSERT_OBJECT_REFCOUNT (trackelement, "trackelement", 3);
104
105   GST_DEBUG ("Remove the Clip from the layer");
106
107   /* Now remove the clip */
108   gst_object_ref (source);
109   ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
110   fail_unless (ges_layer_remove_clip (layer, GES_CLIP (source)));
111   ASSERT_OBJECT_REFCOUNT (source, "source", 1);
112   ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
113   tmp_layer = ges_clip_get_layer (GES_CLIP (source));
114   fail_unless (tmp_layer == NULL);
115   gst_object_unref (source);
116
117   GST_DEBUG ("Removing track from the timeline");
118   /* Remove the track from the timeline */
119   gst_object_ref (track);
120   fail_unless (ges_timeline_remove_track (timeline, track));
121   fail_unless (ges_track_get_timeline (track) == NULL);
122
123   tracks = ges_timeline_get_tracks (timeline);
124   fail_unless (tracks == NULL);
125   ASSERT_OBJECT_REFCOUNT (track, "track", 1);
126   gst_object_unref (track);
127
128   GST_DEBUG ("Removing layer from the timeline");
129   /* Remove the layer from the timeline */
130   gst_object_ref (layer);
131   fail_unless (ges_timeline_remove_layer (timeline, layer));
132   fail_unless (layer->timeline == NULL);
133
134   layers = ges_timeline_get_layers (timeline);
135   fail_unless (layers == NULL);
136   ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
137   gst_object_unref (layer);
138
139   /* Finally clean up our object */
140   ASSERT_OBJECT_REFCOUNT (timeline, "timeline", 1);
141   gst_object_unref (timeline);
142
143   ges_deinit ();
144 }
145
146 GST_END_TEST;
147
148 /* very similar to the above, except we add the clip to the layer
149  * and then add it to the timeline.
150  */
151
152 GST_START_TEST (test_ges_timeline_add_layer)
153 {
154   GESTimeline *timeline;
155   GESLayer *layer, *tmp_layer;
156   GESTrack *track;
157   GESTestClip *s1, *s2, *s3;
158   GList *trackelements, *layers;
159   GESTrackElement *trackelement;
160
161   ges_init ();
162
163   /* Timeline and 1 Layer */
164   GST_DEBUG ("Create a timeline");
165   timeline = ges_timeline_new ();
166   fail_unless (timeline != NULL);
167
168   GST_DEBUG ("Create a layer");
169   layer = ges_layer_new ();
170   fail_unless (layer != NULL);
171   /* Give the Timeline a Track */
172   GST_DEBUG ("Create a Track");
173   track = GES_TRACK (ges_video_track_new ());
174   fail_unless (track != NULL);
175
176   GST_DEBUG ("Add the track to the timeline");
177   fail_unless (ges_timeline_add_track (timeline, track));
178   /* The timeline steals the reference to the track */
179   ASSERT_OBJECT_REFCOUNT (track, "track", 1);
180   fail_unless (ges_track_get_timeline (track) == timeline);
181   fail_unless ((gpointer) GST_ELEMENT_PARENT (track) == (gpointer) timeline);
182
183   /* Create a source and add it to the Layer */
184   GST_DEBUG ("Creating a source");
185   s1 = ges_test_clip_new ();
186   fail_unless (s1 != NULL);
187   fail_unless (ges_layer_add_clip (layer, GES_CLIP (s1)));
188   tmp_layer = ges_clip_get_layer (GES_CLIP (s1));
189   fail_unless (tmp_layer == layer);
190   ASSERT_OBJECT_REFCOUNT (layer, "layer", 2);
191   gst_object_unref (tmp_layer);
192
193   GST_DEBUG ("Creating a source");
194   s2 = ges_test_clip_new ();
195   fail_unless (s2 != NULL);
196   fail_unless (ges_layer_add_clip (layer, GES_CLIP (s2)));
197   tmp_layer = ges_clip_get_layer (GES_CLIP (s2));
198   fail_unless (tmp_layer == layer);
199   ASSERT_OBJECT_REFCOUNT (layer, "layer", 2);
200   gst_object_unref (tmp_layer);
201
202   GST_DEBUG ("Creating a source");
203   s3 = ges_test_clip_new ();
204   fail_unless (s3 != NULL);
205   fail_unless (ges_layer_add_clip (layer, GES_CLIP (s3)));
206   tmp_layer = ges_clip_get_layer (GES_CLIP (s3));
207   fail_unless (tmp_layer == layer);
208   ASSERT_OBJECT_REFCOUNT (layer, "layer", 2);
209   gst_object_unref (tmp_layer);
210
211   GST_DEBUG ("Add the layer to the timeline");
212   fail_unless (ges_timeline_add_layer (timeline, layer));
213   /* The timeline steals our reference to the layer */
214   ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
215   fail_unless (layer->timeline == timeline);
216   layers = ges_timeline_get_layers (timeline);
217   fail_unless (g_list_find (layers, layer) != NULL);
218   g_list_foreach (layers, (GFunc) gst_object_unref, NULL);
219   g_list_free (layers);
220
221   /* Make sure the associated TrackElements are in the Track */
222   trackelements = GES_CONTAINER_CHILDREN (s1);
223   fail_unless (trackelements != NULL);
224   trackelement = GES_TRACK_ELEMENT (trackelements->data);
225   /* There are 3 references:
226    * 1 by the clip
227    * 1 by the trackelement
228    * 1 by the timeline */
229   ASSERT_OBJECT_REFCOUNT (trackelement, "trackelement", 3);
230   /* There are 3 references:
231    * 1 by the clip
232    * 1 by the timeline
233    * 1 by the trackelement */
234   ASSERT_OBJECT_REFCOUNT (trackelement, "trackelement", 3);
235
236   trackelements = GES_CONTAINER_CHILDREN (s2);
237   trackelement = GES_TRACK_ELEMENT (trackelements->data);
238   fail_unless (trackelements != NULL);
239
240   /* There are 3 references:
241    * 1 by the clip
242    * 1 by the timeline
243    * 1 by the trackelement */
244   ASSERT_OBJECT_REFCOUNT (GES_TRACK_ELEMENT (trackelement), "trackelement", 3);
245
246   trackelements = GES_CONTAINER_CHILDREN (s3);
247   trackelement = GES_TRACK_ELEMENT (trackelements->data);
248   fail_unless (trackelements != NULL);
249
250   /* There are 3 references:
251    * 1 by the clip
252    * 1 by the timeline
253    * 2 by the trackelement */
254   ASSERT_OBJECT_REFCOUNT (trackelement, "trackelement", 3);
255
256   /* theoretically this is all we need to do to ensure cleanup */
257   gst_object_unref (timeline);
258
259   ges_deinit ();
260 }
261
262 GST_END_TEST;
263
264 /* this time we add the layer before we add the track. */
265
266 GST_START_TEST (test_ges_timeline_add_layer_first)
267 {
268   GESTimeline *timeline;
269   GESLayer *layer, *tmp_layer;
270   GESTrack *track;
271   GESTestClip *s1, *s2, *s3;
272   GList *trackelements, *tmp, *layers;
273
274   ges_init ();
275
276   /* Timeline and 1 Layer */
277   GST_DEBUG ("Create a timeline");
278   timeline = ges_timeline_new ();
279   fail_unless (timeline != NULL);
280
281   GST_DEBUG ("Create a layer");
282   layer = ges_layer_new ();
283   fail_unless (layer != NULL);
284   /* Give the Timeline a Track */
285   GST_DEBUG ("Create a Track");
286   track = GES_TRACK (ges_video_track_new ());
287   fail_unless (track != NULL);
288
289   /* Create a source and add it to the Layer */
290   GST_DEBUG ("Creating a source");
291   s1 = ges_test_clip_new ();
292   fail_unless (s1 != NULL);
293   fail_unless (ges_layer_add_clip (layer, GES_CLIP (s1)));
294   tmp_layer = ges_clip_get_layer (GES_CLIP (s1));
295   fail_unless (tmp_layer == layer);
296   gst_object_unref (tmp_layer);
297
298   GST_DEBUG ("Creating a source");
299   s2 = ges_test_clip_new ();
300   fail_unless (s2 != NULL);
301   fail_unless (ges_layer_add_clip (layer, GES_CLIP (s2)));
302   tmp_layer = ges_clip_get_layer (GES_CLIP (s2));
303   fail_unless (tmp_layer == layer);
304   gst_object_unref (tmp_layer);
305
306   GST_DEBUG ("Creating a source");
307   s3 = ges_test_clip_new ();
308   fail_unless (s3 != NULL);
309   fail_unless (ges_layer_add_clip (layer, GES_CLIP (s3)));
310   tmp_layer = ges_clip_get_layer (GES_CLIP (s3));
311   fail_unless (tmp_layer == layer);
312   gst_object_unref (tmp_layer);
313
314   GST_DEBUG ("Add the layer to the timeline");
315   fail_unless (ges_timeline_add_layer (timeline, layer));
316   /* The timeline steals our reference to the layer */
317   ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
318   fail_unless (layer->timeline == timeline);
319   layers = ges_timeline_get_layers (timeline);
320   fail_unless (g_list_find (layers, layer) != NULL);
321   g_list_foreach (layers, (GFunc) gst_object_unref, NULL);
322   g_list_free (layers);
323
324   GST_DEBUG ("Add the track to the timeline");
325   fail_unless (ges_timeline_add_track (timeline, track));
326   ASSERT_OBJECT_REFCOUNT (track, "track", 1);
327   fail_unless (ges_track_get_timeline (track) == timeline);
328   fail_unless ((gpointer) GST_ELEMENT_PARENT (track) == (gpointer) timeline);
329
330   /* Make sure the associated TrackElements are in the Track */
331   trackelements = GES_CONTAINER_CHILDREN (s1);
332   fail_unless (trackelements != NULL);
333   for (tmp = trackelements; tmp; tmp = tmp->next) {
334     /* Each object has 3 references:
335      * 1 by the clip
336      * 1 by the track
337      * 1 by the timeline */
338     ASSERT_OBJECT_REFCOUNT (GES_TRACK_ELEMENT (tmp->data), "trackelement", 3);
339   }
340
341   trackelements = GES_CONTAINER_CHILDREN (s2);
342   fail_unless (trackelements != NULL);
343   for (tmp = trackelements; tmp; tmp = tmp->next) {
344     /* Each object has 3 references:
345      * 1 by the clip
346      * 1 by the track
347      * 1 by the timeline */
348     ASSERT_OBJECT_REFCOUNT (GES_TRACK_ELEMENT (tmp->data), "trackelement", 3);
349   }
350
351   trackelements = GES_CONTAINER_CHILDREN (s3);
352   fail_unless (trackelements != NULL);
353   for (tmp = trackelements; tmp; tmp = tmp->next) {
354     /* Each object has 3 references:
355      * 1 by the clip
356      * 1 by the track
357      * 1 by the timeline */
358     ASSERT_OBJECT_REFCOUNT (GES_TRACK_ELEMENT (tmp->data), "trackelement", 3);
359   }
360
361   /* theoretically this is all we need to do to ensure cleanup */
362   gst_object_unref (timeline);
363
364   ges_deinit ();
365 }
366
367 GST_END_TEST;
368
369 GST_START_TEST (test_ges_timeline_remove_track)
370 {
371   GESTimeline *timeline;
372   GESLayer *layer, *tmp_layer;
373   GESTrack *track;
374   GESTestClip *s1, *s2, *s3;
375   GESTrackElement *t1, *t2, *t3;
376   GList *trackelements, *tmp, *layers;
377
378   ges_init ();
379
380   /* Timeline and 1 Layer */
381   GST_DEBUG ("Create a timeline");
382   timeline = ges_timeline_new ();
383   fail_unless (timeline != NULL);
384
385   GST_DEBUG ("Create a layer");
386   layer = ges_layer_new ();
387   fail_unless (layer != NULL);
388   /* Give the Timeline a Track */
389   GST_DEBUG ("Create a Track");
390   track = GES_TRACK (ges_video_track_new ());
391   fail_unless (track != NULL);
392
393   /* Create a source and add it to the Layer */
394   GST_DEBUG ("Creating a source");
395   s1 = ges_test_clip_new ();
396   fail_unless (s1 != NULL);
397   fail_unless (ges_layer_add_clip (layer, GES_CLIP (s1)));
398   tmp_layer = ges_clip_get_layer (GES_CLIP (s1));
399   fail_unless (tmp_layer == layer);
400   gst_object_unref (tmp_layer);
401   ASSERT_OBJECT_REFCOUNT (layer, "1 for the timeline", 1);
402
403   GST_DEBUG ("Creating a source");
404   s2 = ges_test_clip_new ();
405   fail_unless (s2 != NULL);
406   fail_unless (ges_layer_add_clip (layer, GES_CLIP (s2)));
407   tmp_layer = ges_clip_get_layer (GES_CLIP (s2));
408   fail_unless (tmp_layer == layer);
409   gst_object_unref (tmp_layer);
410   ASSERT_OBJECT_REFCOUNT (layer, "1 for the timeline", 1);
411
412   GST_DEBUG ("Creating a source");
413   s3 = ges_test_clip_new ();
414   fail_unless (s3 != NULL);
415   fail_unless (ges_layer_add_clip (layer, GES_CLIP (s3)));
416   tmp_layer = ges_clip_get_layer (GES_CLIP (s3));
417   fail_unless (tmp_layer == layer);
418   gst_object_unref (tmp_layer);
419   ASSERT_OBJECT_REFCOUNT (layer, "1 for the timeline", 1);
420
421   GST_DEBUG ("Add the layer to the timeline");
422   fail_unless (ges_timeline_add_layer (timeline, layer));
423   /* The timeline steals our reference to the layer */
424   ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
425   fail_unless (layer->timeline == timeline);
426
427   layers = ges_timeline_get_layers (timeline);
428   fail_unless (g_list_find (layers, layer) != NULL);
429   g_list_foreach (layers, (GFunc) gst_object_unref, NULL);
430   g_list_free (layers);
431   ASSERT_OBJECT_REFCOUNT (layer, "1 for the timeline", 1);
432
433   GST_DEBUG ("Add the track to the timeline");
434   fail_unless (ges_timeline_add_track (timeline, track));
435   ASSERT_OBJECT_REFCOUNT (track, "track", 1);
436   fail_unless (ges_track_get_timeline (track) == timeline);
437   fail_unless ((gpointer) GST_ELEMENT_PARENT (track) == (gpointer) timeline);
438
439   /* Make sure the associated TrackElements are in the Track */
440   trackelements = GES_CONTAINER_CHILDREN (s1);
441   fail_unless (trackelements != NULL);
442   t1 = GES_TRACK_ELEMENT ((trackelements)->data);
443   for (tmp = trackelements; tmp; tmp = tmp->next) {
444     /* There are 3 references held:
445      * 1 by the clip
446      * 1 by the track
447      * 1 by the timeline */
448     ASSERT_OBJECT_REFCOUNT (GES_TRACK_ELEMENT (tmp->data), "trackelement", 3);
449   }
450   /* There are 3 references held:
451    * 1 by the container
452    * 1 by the track
453    * 1 by the timeline */
454   ASSERT_OBJECT_REFCOUNT (t1, "trackelement", 3);
455
456   trackelements = GES_CONTAINER_CHILDREN (s2);
457   fail_unless (trackelements != NULL);
458   t2 = GES_TRACK_ELEMENT (trackelements->data);
459   for (tmp = trackelements; tmp; tmp = tmp->next) {
460     /* There are 3 references held:
461      * 1 by the clip
462      * 1 by the track
463      * 1 by the timeline */
464     ASSERT_OBJECT_REFCOUNT (GES_TRACK_ELEMENT (tmp->data), "trackelement", 3);
465   }
466   /* There are 3 references held:
467    * 1 by the container
468    * 1 by the track
469    * 1 by the timeline */
470   ASSERT_OBJECT_REFCOUNT (t2, "t2", 3);
471
472   trackelements = GES_CONTAINER_CHILDREN (s3);
473   fail_unless (trackelements != NULL);
474   t3 = GES_TRACK_ELEMENT (trackelements->data);
475   for (tmp = trackelements; tmp; tmp = tmp->next) {
476     /* There are 3 references held:
477      * 1 by the clip
478      * 1 by the track
479      * 1 by the timeline */
480     ASSERT_OBJECT_REFCOUNT (GES_TRACK_ELEMENT (tmp->data), "trackelement", 3);
481   }
482   /* There are 3 references held:
483    * 1 by the container
484    * 1 by the track
485    * 1 by the timeline */
486   ASSERT_OBJECT_REFCOUNT (t3, "t3", 3);
487
488   /* remove the track and check that the track elements have been released */
489   fail_unless (ges_timeline_remove_track (timeline, track));
490
491   ASSERT_OBJECT_REFCOUNT (t1, "trackelement", 1);
492   ASSERT_OBJECT_REFCOUNT (t2, "trackelement", 1);
493   ASSERT_OBJECT_REFCOUNT (t3, "trackelement", 1);
494   ASSERT_OBJECT_REFCOUNT (layer, "1 for the timeline", 1);
495   ASSERT_OBJECT_REFCOUNT (timeline, "1 for the us", 1);
496   tmp = ges_layer_get_clips (layer);
497   assert_equals_int (g_list_length (tmp), 3);
498   g_list_free_full (tmp, (GDestroyNotify) gst_object_unref);
499
500   gst_check_objects_destroyed_on_unref (G_OBJECT (timeline),
501       G_OBJECT (layer), t1, t2, t3, NULL);
502
503   ges_deinit ();
504 }
505
506 GST_END_TEST;
507
508 typedef struct
509 {
510   GESTestClip **o1, **o2, **o3;
511   GESTrack **tr1, **tr2;
512 } SelectTracksData;
513
514 static GPtrArray *
515 select_tracks_cb (GESTimeline * timeline, GESClip * clip,
516     GESTrackElement * track_element, SelectTracksData * st_data)
517 {
518   GESTrack *track;
519
520   GPtrArray *ret = g_ptr_array_new ();
521   track = (clip == (GESClip *) * st_data->o2) ? *st_data->tr2 : *st_data->tr1;
522
523   gst_object_ref (track);
524
525   g_ptr_array_add (ret, track);
526
527   return ret;
528 }
529
530 GST_START_TEST (test_ges_timeline_multiple_tracks)
531 {
532   GESTimeline *timeline;
533   GESLayer *layer, *tmp_layer;
534   GESTrack *track1, *track2;
535   GESTestClip *s1, *s2, *s3;
536   GESTrackElement *t1, *t2, *t3;
537   GList *trackelements, *tmp, *layers;
538   SelectTracksData st_data = { &s1, &s2, &s3, &track1, &track2 };
539
540   ges_init ();
541
542   /* Timeline and 1 Layer */
543   GST_DEBUG ("Create a timeline");
544   timeline = ges_timeline_new ();
545   fail_unless (timeline != NULL);
546
547   g_signal_connect (timeline, "select-tracks-for-object",
548       G_CALLBACK (select_tracks_cb), &st_data);
549
550   GST_DEBUG ("Create a layer");
551   layer = ges_layer_new ();
552   fail_unless (layer != NULL);
553   /* Give the Timeline a Track */
554   GST_DEBUG ("Create Track 1");
555   track1 = GES_TRACK (ges_video_track_new ());
556   fail_unless (track1 != NULL);
557   GST_DEBUG ("Create Track 2");
558   track2 = GES_TRACK (ges_video_track_new ());
559   fail_unless (track2 != NULL);
560
561   GST_DEBUG ("Add the track 1 to the timeline");
562   fail_unless (ges_timeline_add_track (timeline, track1));
563   ASSERT_OBJECT_REFCOUNT (track1, "track", 1);
564   fail_unless (ges_track_get_timeline (track1) == timeline);
565   fail_unless ((gpointer) GST_ELEMENT_PARENT (track1) == (gpointer) timeline);
566
567   GST_DEBUG ("Add the track 2 to the timeline");
568   fail_unless (ges_timeline_add_track (timeline, track2));
569   ASSERT_OBJECT_REFCOUNT (track2, "track", 1);
570   fail_unless (ges_track_get_timeline (track2) == timeline);
571   fail_unless ((gpointer) GST_ELEMENT_PARENT (track2) == (gpointer) timeline);
572
573   /* Create a source and add it to the Layer */
574   GST_DEBUG ("Creating a source");
575   s1 = ges_test_clip_new ();
576   fail_unless (s1 != NULL);
577   fail_unless (ges_layer_add_clip (layer, GES_CLIP (s1)));
578   tmp_layer = ges_clip_get_layer (GES_CLIP (s1));
579   fail_unless (tmp_layer == layer);
580   gst_object_unref (tmp_layer);
581
582   GST_DEBUG ("Creating a source");
583   s2 = ges_test_clip_new ();
584   fail_unless (s2 != NULL);
585   fail_unless (ges_layer_add_clip (layer, GES_CLIP (s2)));
586   tmp_layer = ges_clip_get_layer (GES_CLIP (s2));
587   fail_unless (tmp_layer == layer);
588   gst_object_unref (tmp_layer);
589
590   GST_DEBUG ("Creating a source");
591   s3 = ges_test_clip_new ();
592   fail_unless (s3 != NULL);
593   fail_unless (ges_layer_add_clip (layer, GES_CLIP (s3)));
594   tmp_layer = ges_clip_get_layer (GES_CLIP (s3));
595   fail_unless (tmp_layer == layer);
596   gst_object_unref (tmp_layer);
597
598   GST_DEBUG ("Add the layer to the timeline");
599   fail_unless (ges_timeline_add_layer (timeline, layer));
600   /* The timeline steals our reference to the layer */
601   ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
602   fail_unless (layer->timeline == timeline);
603
604   layers = ges_timeline_get_layers (timeline);
605   fail_unless (g_list_find (layers, layer) != NULL);
606   g_list_foreach (layers, (GFunc) gst_object_unref, NULL);
607   g_list_free (layers);
608
609   /* Make sure the associated TrackElements are in the Track */
610   trackelements = GES_CONTAINER_CHILDREN (s1);
611   fail_unless (trackelements != NULL);
612   t1 = GES_TRACK_ELEMENT ((trackelements)->data);
613   for (tmp = trackelements; tmp; tmp = tmp->next) {
614     /* There are 3 references held:
615      * 1 by the clip
616      * 1 by the track
617      * 1 by the timeline */
618     ASSERT_OBJECT_REFCOUNT (GES_TRACK_ELEMENT (tmp->data), "trackelement", 3);
619     fail_unless (ges_track_element_get_track (tmp->data) == track1);
620   }
621   gst_object_ref (t1);
622   /* There are 3 references held:
623    * 1 by the container
624    * 1 by the track
625    * 1 by the timeline
626    * 1 added by ourselves above (gst_object_ref (t1)) */
627   ASSERT_OBJECT_REFCOUNT (t1, "trackelement", 4);
628
629   trackelements = GES_CONTAINER_CHILDREN (s2);
630   fail_unless (trackelements != NULL);
631   t2 = GES_TRACK_ELEMENT (trackelements->data);
632   for (tmp = trackelements; tmp; tmp = tmp->next) {
633     /* There are 3 references held:
634      * 1 by the clip
635      * 1 by the track
636      * 1 by the timeline */
637     ASSERT_OBJECT_REFCOUNT (GES_TRACK_ELEMENT (tmp->data), "trackelement", 3);
638     fail_unless (ges_track_element_get_track (tmp->data) == track2);
639   }
640   gst_object_ref (t2);
641   /* There are 3 references held:
642    * 1 by the container
643    * 1 by the track
644    * 1 by the timeline
645    * 1 added by ourselves above (gst_object_ref (t2)) */
646   ASSERT_OBJECT_REFCOUNT (t2, "t2", 4);
647
648   trackelements = GES_CONTAINER_CHILDREN (s3);
649   fail_unless (trackelements != NULL);
650   t3 = GES_TRACK_ELEMENT (trackelements->data);
651   for (tmp = trackelements; tmp; tmp = tmp->next) {
652     /* There are 3 references held:
653      * 1 by the clip
654      * 1 by the track
655      * 1 by the timeline */
656     ASSERT_OBJECT_REFCOUNT (GES_TRACK_ELEMENT (tmp->data), "trackelement", 3);
657     fail_unless (ges_track_element_get_track (tmp->data) == track1);
658   }
659   gst_object_ref (t3);
660   /* There are 3 references held:
661    * 1 by the container
662    * 1 by the track
663    * 1 by the timeline
664    * 1 added by ourselves above (gst_object_ref (t3)) */
665   ASSERT_OBJECT_REFCOUNT (t3, "t3", 4);
666
667   gst_object_unref (t1);
668   gst_object_unref (t2);
669   gst_object_unref (t3);
670
671   gst_object_unref (timeline);
672
673   ges_deinit ();
674 }
675
676 GST_END_TEST;
677
678 GST_START_TEST (test_ges_pipeline_change_state)
679 {
680   GstState state;
681   GESAsset *asset;
682   GESLayer *layer;
683   GESTimeline *timeline;
684   GESPipeline *pipeline;
685
686   ges_init ();
687
688   layer = ges_layer_new ();
689   timeline = ges_timeline_new_audio_video ();
690   fail_unless (ges_timeline_add_layer (timeline, layer));
691
692   pipeline = ges_test_create_pipeline (timeline);
693
694   asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
695   ges_layer_add_asset (layer, asset, 0, 0, 10, GES_TRACK_TYPE_UNKNOWN);
696   gst_object_unref (asset);
697
698   ges_timeline_commit (timeline);
699   ASSERT_SET_STATE (GST_ELEMENT (pipeline), GST_STATE_PLAYING,
700       GST_STATE_CHANGE_ASYNC);
701   fail_unless (gst_element_get_state (GST_ELEMENT (pipeline), &state, NULL,
702           GST_CLOCK_TIME_NONE) == GST_STATE_CHANGE_SUCCESS);
703   fail_unless (state == GST_STATE_PLAYING);
704   ASSERT_SET_STATE (GST_ELEMENT (pipeline), GST_STATE_NULL,
705       GST_STATE_CHANGE_SUCCESS);
706
707   gst_object_unref (pipeline);
708
709   ges_deinit ();
710 }
711
712 GST_END_TEST;
713
714 GST_START_TEST (test_ges_timeline_element_name)
715 {
716   GESClip *clip, *clip1, *clip2, *clip3, *clip4, *clip5;
717   GESAsset *asset;
718   GESTimeline *timeline;
719   GESLayer *layer;
720
721   ges_init ();
722
723   timeline = ges_timeline_new_audio_video ();
724   layer = ges_layer_new ();
725   fail_unless (ges_timeline_add_layer (timeline, layer));
726
727   asset = ges_asset_request (GES_TYPE_TEST_CLIP, NULL, NULL);
728   clip = ges_layer_add_asset (layer, asset, 0, 0, 10, GES_TRACK_TYPE_UNKNOWN);
729   fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip), "testclip0");
730
731
732   clip1 = GES_CLIP (ges_test_clip_new ());
733   fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip1), "testclip1");
734
735   ges_timeline_element_set_name (GES_TIMELINE_ELEMENT (clip1), "testclip1");
736   fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip1), "testclip1");
737
738   /* Check that trying to set to a name that is already used leads to
739    * a change in the name */
740   ges_timeline_element_set_name (GES_TIMELINE_ELEMENT (clip), "testclip1");
741   fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip), "testclip2");
742
743   ges_timeline_element_set_name (GES_TIMELINE_ELEMENT (clip1), "testclip4");
744   fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip1), "testclip4");
745
746   clip2 = GES_CLIP (ges_test_clip_new ());
747   fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip2), "testclip5");
748   ges_timeline_element_set_name (GES_TIMELINE_ELEMENT (clip2), NULL);
749   fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip2), "testclip6");
750
751   clip3 = GES_CLIP (ges_test_clip_new ());
752   fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip3), "testclip7");
753   ges_timeline_element_set_name (GES_TIMELINE_ELEMENT (clip3), "testclip5");
754   fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip3), "testclip8");
755
756   clip4 = GES_CLIP (ges_test_clip_new ());
757   fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip4), "testclip9");
758
759
760   clip5 = GES_CLIP (ges_test_clip_new ());
761   ges_timeline_element_set_name (GES_TIMELINE_ELEMENT (clip5),
762       "Something I want!");
763   fail_unless_equals_string (GES_TIMELINE_ELEMENT_NAME (clip5),
764       "Something I want!");
765
766   gst_object_unref (asset);
767
768   gst_object_unref (clip1);
769   gst_object_unref (clip2);
770   gst_object_unref (clip3);
771   gst_object_unref (clip4);
772   gst_object_unref (clip5);
773   gst_object_unref (timeline);
774
775   ges_deinit ();
776 }
777
778 GST_END_TEST;
779
780 static Suite *
781 ges_suite (void)
782 {
783   Suite *s = suite_create ("ges-basic");
784   TCase *tc_chain = tcase_create ("basic");
785
786   suite_add_tcase (s, tc_chain);
787
788   tcase_add_test (tc_chain, test_ges_scenario);
789   tcase_add_test (tc_chain, test_ges_timeline_add_layer);
790   tcase_add_test (tc_chain, test_ges_timeline_add_layer_first);
791   tcase_add_test (tc_chain, test_ges_timeline_remove_track);
792   tcase_add_test (tc_chain, test_ges_timeline_multiple_tracks);
793   tcase_add_test (tc_chain, test_ges_pipeline_change_state);
794   tcase_add_test (tc_chain, test_ges_timeline_element_name);
795
796   return s;
797 }
798
799 GST_CHECK_MAIN (ges);