From 8ba0351c7ab8f1c9e0d76c78fb56c3b9e8fe4210 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 9 Feb 2012 16:44:28 +0000 Subject: [PATCH] conform/actor: Add unit for the Container signals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ClutterActor should be emitting signals defined on the ClutterContainer interface, as well as ensuring that manipulating the scene graph is still possible from within them. The new unit checks that we're emitting signals, by implementing something similar to the Bin class available in toolkits like gtk, st, and mx — i.e. a container that can only hold one child at any given point. --- tests/conform/test-actor-graph.c | 74 +++++++++++++++++++++++++++++++ tests/conform/test-conform-main.c | 1 + 2 files changed, 75 insertions(+) diff --git a/tests/conform/test-actor-graph.c b/tests/conform/test-actor-graph.c index af2343b73..6f2db617c 100644 --- a/tests/conform/test-actor-graph.c +++ b/tests/conform/test-actor-graph.c @@ -374,3 +374,77 @@ actor_remove_all (TestConformSimpleFixture *fixture, clutter_actor_destroy (actor); g_object_unref (actor); } + +static void +actor_added (ClutterContainer *container, + ClutterActor *child, + gpointer data) +{ + ClutterActor *actor = CLUTTER_ACTOR (container); + int *counter = data; + ClutterActor *old_child; + + if (g_test_verbose ()) + g_print ("Adding actor '%s'\n", clutter_actor_get_name (child)); + + old_child = clutter_actor_get_child_at_index (actor, 0); + if (old_child != child) + clutter_actor_remove_child (actor, old_child); + + *counter += 1; +} + +static void +actor_removed (ClutterContainer *container, + ClutterActor *child, + gpointer data) +{ + int *counter = data; + + if (g_test_verbose ()) + g_print ("Removing actor '%s'\n", clutter_actor_get_name (child)); + + *counter += 1; +} + +void +actor_container_signals (TestConformSimpleFixture *fixture G_GNUC_UNUSED, + gconstpointer data G_GNUC_UNUSED) +{ + ClutterActor *actor = clutter_actor_new (); + int add_count, remove_count; + + g_object_ref_sink (actor); + + add_count = remove_count = 0; + g_signal_connect (actor, + "actor-added", G_CALLBACK (actor_added), + &add_count); + g_signal_connect (actor, + "actor-removed", G_CALLBACK (actor_removed), + &remove_count); + + clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, + "name", "foo", + NULL)); + + g_assert_cmpint (add_count, ==, 1); + g_assert_cmpint (remove_count, ==, 0); + g_assert_cmpint (clutter_actor_get_n_children (actor), ==, 1); + + clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, + "name", "bar", + NULL)); + + g_assert_cmpint (add_count, ==, 2); + g_assert_cmpint (remove_count, ==, 1); + g_assert_cmpint (clutter_actor_get_n_children (actor), ==, 1); + + g_signal_handlers_disconnect_by_func (actor, G_CALLBACK (actor_added), + &add_count); + g_signal_handlers_disconnect_by_func (actor, G_CALLBACK (actor_removed), + &remove_count); + + clutter_actor_destroy (actor); + g_object_unref (actor); +} diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c index 1a6f608fc..c2aba658c 100644 --- a/tests/conform/test-conform-main.c +++ b/tests/conform/test-conform-main.c @@ -135,6 +135,7 @@ main (int argc, char **argv) TEST_CONFORM_SIMPLE ("/actor", actor_replace_child); TEST_CONFORM_SIMPLE ("/actor", actor_remove_child); TEST_CONFORM_SIMPLE ("/actor", actor_remove_all); + TEST_CONFORM_SIMPLE ("/actor", actor_container_signals); TEST_CONFORM_SIMPLE ("/actor", actor_destruction); TEST_CONFORM_SIMPLE ("/actor", actor_anchors); TEST_CONFORM_SIMPLE ("/actor", actor_picking);