tests: Make basic test check for proper reference counting.
authorEdward Hervey <edward.hervey@collabora.co.uk>
Mon, 14 Sep 2009 17:45:43 +0000 (19:45 +0200)
committerEdward Hervey <edward.hervey@collabora.co.uk>
Mon, 14 Sep 2009 17:48:21 +0000 (19:48 +0200)
tests/check/ges/basic.c

index 34aa1b8..392fa5b 100644 (file)
@@ -44,7 +44,6 @@ my_fill_track_func (GESTimelineObject * object,
 
 GST_START_TEST (test_ges_scenario)
 {
-  GESTimelinePipeline *pipeline;
   GESTimeline *timeline;
   GESTimelineLayer *layer;
   GESTrack *track;
@@ -53,59 +52,78 @@ GST_START_TEST (test_ges_scenario)
   ges_init ();
   /* This is the simplest scenario ever */
 
-  /* Pipeline, Timeline and 1 Layer */
-
-  pipeline = ges_timeline_pipeline_new ();
-  fail_unless (pipeline != NULL);
-
+  /* Timeline and 1 Layer */
+  GST_DEBUG ("Create a timeline");
   timeline = ges_timeline_new ();
   fail_unless (timeline != NULL);
 
+  GST_DEBUG ("Create a layer");
   layer = ges_timeline_layer_new ();
   fail_unless (layer != NULL);
 
+  GST_DEBUG ("Add the layer to the timeline");
   fail_unless (ges_timeline_add_layer (timeline, layer));
+  /* The timeline steals our reference to the layer */
+  ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
   fail_unless (layer->timeline == timeline);
   fail_unless (g_list_find (timeline->layers, layer) != NULL);
 
   /* Give the Timeline a Track */
-
+  GST_DEBUG ("Create a Track");
   track = ges_track_new (GES_TRACK_TYPE_CUSTOM, GST_CAPS_ANY);
   fail_unless (track != NULL);
 
+  GST_DEBUG ("Add the track to the timeline");
   fail_unless (ges_timeline_add_track (timeline, track));
+  /* The timeline steals the reference to the track */
+  ASSERT_OBJECT_REFCOUNT (track, "track", 1);
   fail_unless (track->timeline == timeline);
-  /* fail_unless (g_list_find (timeline->tracks, track) != NULL); */
-  fail_unless ((gpointer) gst_element_get_parent (track) ==
-      (gpointer) timeline);
+  fail_unless ((gpointer) GST_ELEMENT_PARENT (track) == (gpointer) timeline);
 
   /* Create a source and add it to the Layer */
-
+  GST_DEBUG ("Creating a source");
   source = ges_custom_timeline_source_new (my_fill_track_func, NULL);
   fail_unless (source != NULL);
 
+  GST_DEBUG ("Adding the source to the timeline layer");
   fail_unless (ges_timeline_layer_add_object (layer,
           GES_TIMELINE_OBJECT (source)));
   fail_unless (GES_TIMELINE_OBJECT (source)->layer == layer);
-
+  ASSERT_OBJECT_REFCOUNT (source, "source", 1);
   /* Make sure the associated TrackObject is in the Track */
   fail_unless (GES_TIMELINE_OBJECT (source)->trackobjects != NULL);
 
+  GST_DEBUG ("Remove the TimelineObject from the layer");
   /* Now remove the timelineobject */
+  g_object_ref (source);
   fail_unless (ges_timeline_layer_remove_object (layer,
           GES_TIMELINE_OBJECT (source)));
+  ASSERT_OBJECT_REFCOUNT (source, "source", 1);
   fail_unless (GES_TIMELINE_OBJECT (source)->layer == NULL);
   fail_unless (GES_TIMELINE_OBJECT (source)->trackobjects == NULL);
+  g_object_unref (source);
 
+  GST_DEBUG ("Removing track from the timeline");
   /* Remove the track from the timeline */
+  g_object_ref (track);
   fail_unless (ges_timeline_remove_track (timeline, track));
   fail_unless (track->timeline == NULL);
   fail_unless (timeline->tracks == NULL);
+  ASSERT_OBJECT_REFCOUNT (track, "track", 1);
+  g_object_unref (track);
 
+  GST_DEBUG ("Removing layer from the timeline");
   /* Remove the layer from the timeline */
+  g_object_ref (layer);
   fail_unless (ges_timeline_remove_layer (timeline, layer));
   fail_unless (layer->timeline == NULL);
   fail_unless (timeline->layers == NULL);
+  ASSERT_OBJECT_REFCOUNT (layer, "layer", 1);
+  g_object_unref (layer);
+
+  /* Finally clean up our object */
+  ASSERT_OBJECT_REFCOUNT (timeline, "timeline", 1);
+  g_object_unref (timeline);
 }
 
 GST_END_TEST;