From 0df2d4f94561ba3ebb731891002803bd7add51b9 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Sat, 23 Mar 2013 03:27:46 -0300 Subject: [PATCH] container: Make sure that the child exists when emiting the "child-removed" signal + Add a test --- ges/ges-container.c | 2 +- tests/check/ges/clip.c | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/ges/ges-container.c b/ges/ges-container.c index c088602d99..22de7c0b6c 100644 --- a/ges/ges-container.c +++ b/ges/ges-container.c @@ -136,7 +136,6 @@ _free_mapping (ChildMapping * mapping) g_signal_handler_disconnect (child, mapping->priority_notifyid); ges_timeline_element_set_parent (child, NULL); - gst_object_unref (child); g_slice_free (ChildMapping, mapping); } @@ -658,6 +657,7 @@ ges_container_remove (GESContainer * container, GESTimelineElement * child) g_signal_emit (container, ges_container_signals[CHILD_REMOVED_SIGNAL], 0, child); + gst_object_unref (child); return TRUE; } diff --git a/tests/check/ges/clip.c b/tests/check/ges/clip.c index e1028dc443..31a7f85c12 100644 --- a/tests/check/ges/clip.c +++ b/tests/check/ges/clip.c @@ -324,6 +324,51 @@ GST_START_TEST (test_clip_group_ungroup) GST_END_TEST; + +static void +child_removed_cb (GESClip * clip, GESTimelineElement * effect, + gboolean * called) +{ + ASSERT_OBJECT_REFCOUNT (effect, "Keeping alive ref + emission ref", 2); + *called = TRUE; +} + +GST_START_TEST (test_clip_refcount_remove_child) +{ + GESClip *clip; + GESTrack *track; + gboolean called; + GESTrackElement *effect; + + ges_init (); + + clip = GES_CLIP (ges_test_clip_new ()); + track = ges_track_audio_raw_new (); + effect = GES_TRACK_ELEMENT (ges_effect_new ("identity")); + + fail_unless (ges_track_add_element (track, effect)); + fail_unless (ges_container_add (GES_CONTAINER (clip), + GES_TIMELINE_ELEMENT (effect))); + ASSERT_OBJECT_REFCOUNT (effect, "1 for the container + 1 for the track", 2); + + fail_unless (ges_track_remove_element (track, effect)); + ASSERT_OBJECT_REFCOUNT (effect, "1 for the container + 1 for the track", 1); + + g_signal_connect (clip, "child-removed", G_CALLBACK (child_removed_cb), + &called); + fail_unless (ges_container_remove (GES_CONTAINER (clip), + GES_TIMELINE_ELEMENT (effect))); + fail_unless (called == TRUE); + fail_if (G_IS_OBJECT (effect)); + + gst_object_unref (track); + gst_object_unref (clip); + fail_if (G_IS_OBJECT (track)); + fail_if (G_IS_OBJECT (clip)); +} + +GST_END_TEST; + static Suite * ges_suite (void) { @@ -335,6 +380,7 @@ ges_suite (void) tcase_add_test (tc_chain, test_object_properties); tcase_add_test (tc_chain, test_split_object); tcase_add_test (tc_chain, test_clip_group_ungroup); + tcase_add_test (tc_chain, test_clip_refcount_remove_child); return s; } -- 2.34.1