From 6ec5cc538c6b705de1a00c8ff6080cfbffec0428 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 16 Jun 2008 13:40:39 +0000 Subject: [PATCH] 2008-06-16 Emmanuele Bassi * clutter/clutter-actor.c (clutter_actor_unparent): Reset the :show-on-set-parent property to TRUE when unparenting. * tests/Makefile.am: Add test-invariant to the build. * tests/test-invariants.c: Test the invariants that we are going to honour (and document, at some point). --- ChangeLog | 10 +++ clutter/clutter-actor.c | 7 ++ tests/Makefile.am | 4 +- tests/test-invariants.c | 190 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 tests/test-invariants.c diff --git a/ChangeLog b/ChangeLog index 5ecf381c4..9451be38b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-06-16 Emmanuele Bassi + + * clutter/clutter-actor.c (clutter_actor_unparent): Reset the + :show-on-set-parent property to TRUE when unparenting. + + * tests/Makefile.am: Add test-invariant to the build. + + * tests/test-invariants.c: Test the invariants that we are going + to honour (and document, at some point). + 2008-06-16 Emmanuele Bassi * clutter/eglnative/clutter-stage-egl.c: Ignore any size allocation diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c index 1f5fb0c72..db321d9cf 100644 --- a/clutter/clutter-actor.c +++ b/clutter/clutter-actor.c @@ -5657,6 +5657,13 @@ clutter_actor_unparent (ClutterActor *self) clutter_actor_unrealize (self); } + /* clutter_actor_hide() will set the :show-on-set-parent property + * to FALSE because the actor doesn't have a parent anymore; but + * we need to return the actor to its initial state, so we force + * the :show-on-set-parent to be TRUE here + */ + self->priv->show_on_set_parent = TRUE; + g_signal_emit (self, actor_signals[PARENT_SET], 0, old_parent); /* remove the reference we acquired in clutter_actor_set_parent() */ diff --git a/tests/Makefile.am b/tests/Makefile.am index 38132a6e7..829d8bcbd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -13,7 +13,8 @@ noinst_PROGRAMS = test-textures test-events test-offscreen test-scale \ test-cogl-tex-getset test-cogl-offscreen \ test-cogl-tex-polygon test-stage-read-pixels \ test-random-text test-clip test-paint-wrapper \ - test-texture-quality test-entry-auto test-layout + test-texture-quality test-entry-auto test-layout \ + test-invariants if X11_TESTS noinst_PROGRAMS += test-pixmap @@ -68,5 +69,6 @@ test_paint_wrapper_SOURCES = test-paint-wrapper.c test_texture_quality_SOURCES = test-texture-quality.c test_entry_auto_SOURCES = test-entry-auto.c test_layout_SOURCES = test-layout.c +test_invariants_SOURCES = test-invariants.c EXTRA_DIST = redhand.png test-script.json diff --git a/tests/test-invariants.c b/tests/test-invariants.c new file mode 100644 index 000000000..c987adb04 --- /dev/null +++ b/tests/test-invariants.c @@ -0,0 +1,190 @@ +#include +#include + +#include + +/* dummy unit testing API; to be replaced by GTest in 1.0 */ +typedef void (* test_func) (void); + +typedef struct _TestUnit TestUnit; + +struct _TestUnit +{ + gchar *name; + test_func func; +}; + +static GSList *units = NULL; + +static void +test_init (gint *argc, + gchar ***argv) +{ + g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL); + + g_assert (clutter_init (argc, argv) == CLUTTER_INIT_SUCCESS); +} + +static void +test_add_func (const gchar *name, + test_func func) +{ + TestUnit *unit; + + unit = g_slice_new (TestUnit); + unit->name = g_strdup (name); + unit->func = func; + + units = g_slist_prepend (units, unit); +} + +static int +test_run (void) +{ + GSList *l; + + units = g_slist_reverse (units); + + for (l = units; l != NULL; l = l->next) + { + TestUnit *u = l->data; + GString *test_name = g_string_sized_new (75); + gsize len, i; + + g_string_append (test_name, "Testing: "); + g_string_append (test_name, u->name); + len = 75 - test_name->len; + + for (i = 0; i < len; i++) + g_string_append_c (test_name, '.'); + + g_print ("%s", test_name->str); + + u->func (); + + g_print ("OK\n"); + } + + for (l = units; l != NULL; l = l->next) + { + TestUnit *u = l->data; + + g_free (u->name); + g_slice_free (TestUnit, u); + } + + g_slist_free (units); + + return EXIT_SUCCESS; +} + +/* test units */ +static void +test_initial_state (void) +{ + ClutterActor *actor; + + actor = clutter_rectangle_new (); + + g_assert (!(CLUTTER_ACTOR_IS_REALIZED (actor))); + g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); + g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor))); + + clutter_actor_destroy (actor); +} + +static void +test_realized (void) +{ + ClutterActor *actor; + + actor = clutter_rectangle_new (); + + g_assert (!(CLUTTER_ACTOR_IS_REALIZED (actor))); + + clutter_actor_realize (actor); + + g_assert (CLUTTER_ACTOR_IS_REALIZED (actor)); + + g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); + g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor))); + + clutter_actor_destroy (actor); +} + + +static void +test_mapped (void) +{ + ClutterActor *actor; + + actor = clutter_rectangle_new (); + + g_assert (!(CLUTTER_ACTOR_IS_REALIZED (actor))); + g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); + + clutter_actor_show (actor); + + g_assert (CLUTTER_ACTOR_IS_REALIZED (actor)); + g_assert (CLUTTER_ACTOR_IS_MAPPED (actor)); + + g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor)); + + clutter_actor_destroy (actor); +} + +static void +test_show_on_set_parent (void) +{ + ClutterActor *actor, *group; + gboolean show_on_set_parent; + + group = clutter_group_new (); + + g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (group))); + + actor = clutter_rectangle_new (); + g_object_get (G_OBJECT (actor), + "show-on-set-parent", &show_on_set_parent, + NULL); + + g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor))); + g_assert (show_on_set_parent == TRUE); + + clutter_group_add (group, actor); + g_object_get (G_OBJECT (actor), + "show-on-set-parent", &show_on_set_parent, + NULL); + + g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor)); + g_assert (show_on_set_parent == TRUE); + + g_object_ref (actor); + clutter_actor_unparent (actor); + g_object_get (G_OBJECT (actor), + "show-on-set-parent", &show_on_set_parent, + NULL); + + g_assert (!(CLUTTER_ACTOR_IS_REALIZED (actor))); + g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor))); + g_assert (show_on_set_parent == TRUE); + + clutter_actor_destroy (actor); + clutter_actor_destroy (group); +} + +int +main (int argc, + char *argv[]) +{ + ClutterActor *stage; + + test_init (&argc, &argv); + + test_add_func ("/invariants/initial-state", test_initial_state); + test_add_func ("/invariants/realized", test_realized); + test_add_func ("/invariants/mapped", test_mapped); + test_add_func ("/invariants/show-on-set-parent", test_show_on_set_parent); + + return test_run (); +}