From 150090c19b1370c125d57bfe2676669162940941 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 12 Jun 2013 10:27:37 +0100 Subject: [PATCH] conform: Ensure that we don't leak references Especially on actors that are not parented and get destroyed. --- tests/conform/actor-graph.c | 26 ++++++++++++++++++-------- tests/conform/actor-invariants.c | 18 ++++++++++-------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/tests/conform/actor-graph.c b/tests/conform/actor-graph.c index 7e4dcd293..81b31f4e4 100644 --- a/tests/conform/actor-graph.c +++ b/tests/conform/actor-graph.c @@ -9,6 +9,7 @@ actor_add_child (TestConformSimpleFixture *fixture, ClutterActor *iter; g_object_ref_sink (actor); + g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, "name", "foo", @@ -45,7 +46,7 @@ actor_add_child (TestConformSimpleFixture *fixture, g_assert (clutter_actor_get_previous_sibling (iter) == NULL); clutter_actor_destroy (actor); - g_object_unref (actor); + g_assert (actor == NULL); } void @@ -56,6 +57,7 @@ actor_insert_child (TestConformSimpleFixture *fixture, ClutterActor *iter; g_object_ref_sink (actor); + g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); clutter_actor_insert_child_at_index (actor, g_object_new (CLUTTER_TYPE_ACTOR, @@ -132,7 +134,7 @@ actor_insert_child (TestConformSimpleFixture *fixture, g_assert (clutter_actor_get_last_child (actor) == iter); clutter_actor_destroy (actor); - g_object_unref (actor); + g_assert (actor == NULL); } void @@ -143,6 +145,7 @@ actor_remove_child (TestConformSimpleFixture *fixture, ClutterActor *iter; g_object_ref_sink (actor); + g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, "name", "foo", @@ -176,7 +179,7 @@ actor_remove_child (TestConformSimpleFixture *fixture, g_assert (clutter_actor_get_last_child (actor) == NULL); clutter_actor_destroy (actor); - g_object_unref (actor); + g_assert (actor == NULL); } void @@ -188,6 +191,7 @@ actor_raise_child (TestConformSimpleFixture *fixture, gboolean show_on_set_parent; g_object_ref_sink (actor); + g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, "name", "foo", @@ -225,6 +229,7 @@ actor_raise_child (TestConformSimpleFixture *fixture, iter = clutter_actor_get_child_at_index (actor, 0); clutter_actor_set_child_above_sibling (actor, iter, NULL); + g_object_add_weak_pointer (G_OBJECT (iter), (gpointer *) &iter); g_assert_cmpstr (clutter_actor_get_name (clutter_actor_get_child_at_index (actor, 0)), ==, @@ -240,7 +245,8 @@ actor_raise_child (TestConformSimpleFixture *fixture, g_assert (!show_on_set_parent); clutter_actor_destroy (actor); - g_object_unref (actor); + g_assert (actor == NULL); + g_assert (iter == NULL); } void @@ -252,6 +258,7 @@ actor_lower_child (TestConformSimpleFixture *fixture, gboolean show_on_set_parent; g_object_ref_sink (actor); + g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, "name", "foo", @@ -304,7 +311,7 @@ actor_lower_child (TestConformSimpleFixture *fixture, g_assert (!show_on_set_parent); clutter_actor_destroy (actor); - g_object_unref (actor); + g_assert (actor == NULL); } void @@ -315,6 +322,7 @@ actor_replace_child (TestConformSimpleFixture *fixture, ClutterActor *iter; g_object_ref_sink (actor); + g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, "name", "foo", @@ -364,7 +372,7 @@ actor_replace_child (TestConformSimpleFixture *fixture, g_assert_cmpstr (clutter_actor_get_name (iter), ==, "baz"); clutter_actor_destroy (actor); - g_object_unref (actor); + g_assert (actor == NULL); } void @@ -374,6 +382,7 @@ actor_remove_all (TestConformSimpleFixture *fixture, ClutterActor *actor = clutter_actor_new (); g_object_ref_sink (actor); + g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, "name", "foo", @@ -392,7 +401,7 @@ actor_remove_all (TestConformSimpleFixture *fixture, g_assert_cmpint (clutter_actor_get_n_children (actor), ==, 0); clutter_actor_destroy (actor); - g_object_unref (actor); + g_assert (actor == NULL); } static void @@ -435,6 +444,7 @@ actor_container_signals (TestConformSimpleFixture *fixture G_GNUC_UNUSED, int add_count, remove_count; g_object_ref_sink (actor); + g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); add_count = remove_count = 0; g_signal_connect (actor, @@ -466,5 +476,5 @@ actor_container_signals (TestConformSimpleFixture *fixture G_GNUC_UNUSED, &remove_count); clutter_actor_destroy (actor); - g_object_unref (actor); + g_assert (actor == NULL); } diff --git a/tests/conform/actor-invariants.c b/tests/conform/actor-invariants.c index a9e21eeb8..eb6223991 100644 --- a/tests/conform/actor-invariants.c +++ b/tests/conform/actor-invariants.c @@ -11,8 +11,9 @@ actor_initial_state (TestConformSimpleFixture *fixture, { ClutterActor *actor; - actor = clutter_rectangle_new (); + actor = clutter_actor_new (); g_object_ref_sink (actor); + g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); if (g_test_verbose ()) g_print ("initial state - visible: %s, realized: %s, mapped: %s\n", @@ -25,7 +26,7 @@ actor_initial_state (TestConformSimpleFixture *fixture, g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor))); clutter_actor_destroy (actor); - g_object_unref (actor); + g_assert (actor == NULL); } void @@ -36,6 +37,7 @@ actor_shown_not_parented (TestConformSimpleFixture *fixture, actor = clutter_rectangle_new (); g_object_ref_sink (actor); + g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); clutter_actor_show (actor); @@ -50,7 +52,7 @@ actor_shown_not_parented (TestConformSimpleFixture *fixture, g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor)); clutter_actor_destroy (actor); - g_object_unref (actor); + g_assert (actor == NULL); } void @@ -335,20 +337,20 @@ clone_no_map (TestConformSimpleFixture *fixture, stage = clutter_stage_new (); clutter_actor_show (stage); - group = clutter_group_new (); - actor = clutter_rectangle_new (); + group = clutter_actor_new (); + actor = clutter_actor_new (); clutter_actor_hide (group); - clutter_container_add_actor (CLUTTER_CONTAINER (group), actor); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), group); + clutter_actor_add_child (group, actor); + clutter_actor_add_child (stage, group); g_assert (!(CLUTTER_ACTOR_IS_MAPPED (group))); g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); clone = clutter_clone_new (group); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), clone); + clutter_actor_add_child (stage, clone); g_assert (CLUTTER_ACTOR_IS_MAPPED (clone)); g_assert (!(CLUTTER_ACTOR_IS_MAPPED (group)));