2008-06-16 Emmanuele Bassi <ebassi@openedhand.com>

* 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).
This commit is contained in:
Emmanuele Bassi 2008-06-16 13:40:39 +00:00
parent aef6fc5f61
commit 6ec5cc538c
4 changed files with 210 additions and 1 deletions

View File

@ -1,3 +1,13 @@
2008-06-16 Emmanuele Bassi <ebassi@openedhand.com>
* 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 <ebassi@openedhand.com> 2008-06-16 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/eglnative/clutter-stage-egl.c: Ignore any size allocation * clutter/eglnative/clutter-stage-egl.c: Ignore any size allocation

View File

@ -5657,6 +5657,13 @@ clutter_actor_unparent (ClutterActor *self)
clutter_actor_unrealize (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); g_signal_emit (self, actor_signals[PARENT_SET], 0, old_parent);
/* remove the reference we acquired in clutter_actor_set_parent() */ /* remove the reference we acquired in clutter_actor_set_parent() */

View File

@ -13,7 +13,8 @@ noinst_PROGRAMS = test-textures test-events test-offscreen test-scale \
test-cogl-tex-getset test-cogl-offscreen \ test-cogl-tex-getset test-cogl-offscreen \
test-cogl-tex-polygon test-stage-read-pixels \ test-cogl-tex-polygon test-stage-read-pixels \
test-random-text test-clip test-paint-wrapper \ 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 if X11_TESTS
noinst_PROGRAMS += test-pixmap 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_texture_quality_SOURCES = test-texture-quality.c
test_entry_auto_SOURCES = test-entry-auto.c test_entry_auto_SOURCES = test-entry-auto.c
test_layout_SOURCES = test-layout.c test_layout_SOURCES = test-layout.c
test_invariants_SOURCES = test-invariants.c
EXTRA_DIST = redhand.png test-script.json EXTRA_DIST = redhand.png test-script.json

190
tests/test-invariants.c Normal file
View File

@ -0,0 +1,190 @@
#include <stdlib.h>
#include <string.h>
#include <clutter/clutter.h>
/* 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 ();
}