[clutter/clutter-1.14] conform: Ensure that we don't leak references



commit dbdedc727df902af823e212b320214a6d266cfe9
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Wed Jun 12 10:27:37 2013 +0100

    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 7e4dcd2..81b31f4 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 a9e21ee..eb62239 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)));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]