mirror of
https://github.com/brl/mutter.git
synced 2024-12-25 04:22:05 +00:00
actor: Add ActorIter.is_valid()
It can be useful to check whether a ClutterActorIter is currently valid, i.e. if the iterator has been initialized *and* if the actor to which it refers to hasn't been updated. We can also use the is_valid() method in the conformance test suite to check that initialization has been successful, and that changing the children list through the ClutterActorIter API leaves the iterator in a valid state.
This commit is contained in:
parent
1ca4937f1e
commit
1da42dd8a0
@ -17193,6 +17193,33 @@ clutter_actor_iter_init (ClutterActorIter *iter,
|
|||||||
ri->age = root->priv->age;
|
ri->age = root->priv->age;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clutter_actor_iter_is_valid:
|
||||||
|
* @iter: a #ClutterActorIter
|
||||||
|
*
|
||||||
|
* Checks whether a #ClutterActorIter is still valid.
|
||||||
|
*
|
||||||
|
* An iterator is considered valid if it has been initialized, and
|
||||||
|
* if the #ClutterActor that it refers to hasn't been modified after
|
||||||
|
* the initialization.
|
||||||
|
*
|
||||||
|
* Return value: %TRUE if the iterator is valid, and %FALSE otherwise
|
||||||
|
*
|
||||||
|
* Since: 1.12
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
clutter_actor_iter_is_valid (const ClutterActorIter *iter)
|
||||||
|
{
|
||||||
|
RealActorIter *ri = (RealActorIter *) iter;
|
||||||
|
|
||||||
|
g_return_val_if_fail (iter != NULL, FALSE);
|
||||||
|
|
||||||
|
if (ri->root == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
return ri->root->priv->age == ri->age;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clutter_actor_iter_next:
|
* clutter_actor_iter_next:
|
||||||
* @iter: a #ClutterActorIter
|
* @iter: a #ClutterActorIter
|
||||||
|
@ -617,6 +617,8 @@ CLUTTER_AVAILABLE_IN_1_10
|
|||||||
void clutter_actor_iter_remove (ClutterActorIter *iter);
|
void clutter_actor_iter_remove (ClutterActorIter *iter);
|
||||||
CLUTTER_AVAILABLE_IN_1_10
|
CLUTTER_AVAILABLE_IN_1_10
|
||||||
void clutter_actor_iter_destroy (ClutterActorIter *iter);
|
void clutter_actor_iter_destroy (ClutterActorIter *iter);
|
||||||
|
CLUTTER_AVAILABLE_IN_1_12
|
||||||
|
gboolean clutter_actor_iter_is_valid (const ClutterActorIter *iter);
|
||||||
|
|
||||||
/* Transformations */
|
/* Transformations */
|
||||||
gboolean clutter_actor_is_rotated (ClutterActor *self);
|
gboolean clutter_actor_is_rotated (ClutterActor *self);
|
||||||
|
@ -178,6 +178,7 @@ clutter_actor_is_rotated
|
|||||||
clutter_actor_is_scaled
|
clutter_actor_is_scaled
|
||||||
clutter_actor_iter_destroy
|
clutter_actor_iter_destroy
|
||||||
clutter_actor_iter_init
|
clutter_actor_iter_init
|
||||||
|
clutter_actor_iter_is_valid
|
||||||
clutter_actor_iter_next
|
clutter_actor_iter_next
|
||||||
clutter_actor_iter_prev
|
clutter_actor_iter_prev
|
||||||
clutter_actor_iter_remove
|
clutter_actor_iter_remove
|
||||||
|
@ -33,6 +33,8 @@ actor_iter_traverse_children (TestConformSimpleFixture *fixture G_GNUC_UNUSED,
|
|||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
clutter_actor_iter_init (&iter, actor);
|
clutter_actor_iter_init (&iter, actor);
|
||||||
|
g_assert (clutter_actor_iter_is_valid (&iter));
|
||||||
|
|
||||||
while (clutter_actor_iter_next (&iter, &child))
|
while (clutter_actor_iter_next (&iter, &child))
|
||||||
{
|
{
|
||||||
g_assert (CLUTTER_IS_ACTOR (child));
|
g_assert (CLUTTER_IS_ACTOR (child));
|
||||||
@ -54,6 +56,8 @@ actor_iter_traverse_children (TestConformSimpleFixture *fixture G_GNUC_UNUSED,
|
|||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
clutter_actor_iter_init (&iter, actor);
|
clutter_actor_iter_init (&iter, actor);
|
||||||
|
g_assert (clutter_actor_iter_is_valid (&iter));
|
||||||
|
|
||||||
while (clutter_actor_iter_prev (&iter, &child))
|
while (clutter_actor_iter_prev (&iter, &child))
|
||||||
{
|
{
|
||||||
g_assert (CLUTTER_IS_ACTOR (child));
|
g_assert (CLUTTER_IS_ACTOR (child));
|
||||||
@ -105,6 +109,8 @@ actor_iter_traverse_remove (TestConformSimpleFixture *fixture G_GNUC_UNUSED,
|
|||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
clutter_actor_iter_init (&iter, actor);
|
clutter_actor_iter_init (&iter, actor);
|
||||||
|
g_assert (clutter_actor_iter_is_valid (&iter));
|
||||||
|
|
||||||
while (clutter_actor_iter_next (&iter, &child))
|
while (clutter_actor_iter_next (&iter, &child))
|
||||||
{
|
{
|
||||||
g_assert (CLUTTER_IS_ACTOR (child));
|
g_assert (CLUTTER_IS_ACTOR (child));
|
||||||
@ -120,6 +126,7 @@ actor_iter_traverse_remove (TestConformSimpleFixture *fixture G_GNUC_UNUSED,
|
|||||||
g_assert (child == clutter_actor_get_last_child (actor));
|
g_assert (child == clutter_actor_get_last_child (actor));
|
||||||
|
|
||||||
clutter_actor_iter_remove (&iter);
|
clutter_actor_iter_remove (&iter);
|
||||||
|
g_assert (clutter_actor_iter_is_valid (&iter));
|
||||||
|
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
@ -163,6 +170,9 @@ actor_iter_assignment (TestConformSimpleFixture *fixure G_GNUC_UNUSED,
|
|||||||
|
|
||||||
iter_b = iter_a;
|
iter_b = iter_a;
|
||||||
|
|
||||||
|
g_assert (clutter_actor_iter_is_valid (&iter_a));
|
||||||
|
g_assert (clutter_actor_iter_is_valid (&iter_b));
|
||||||
|
|
||||||
while (clutter_actor_iter_next (&iter_a, &child))
|
while (clutter_actor_iter_next (&iter_a, &child))
|
||||||
{
|
{
|
||||||
g_assert (CLUTTER_IS_ACTOR (child));
|
g_assert (CLUTTER_IS_ACTOR (child));
|
||||||
@ -182,7 +192,7 @@ actor_iter_assignment (TestConformSimpleFixture *fixure G_GNUC_UNUSED,
|
|||||||
|
|
||||||
g_assert_cmpint (i, ==, n_actors);
|
g_assert_cmpint (i, ==, n_actors);
|
||||||
|
|
||||||
i = n_actors;
|
i = n_actors - 1;
|
||||||
|
|
||||||
while (clutter_actor_iter_prev (&iter_b, &child))
|
while (clutter_actor_iter_prev (&iter_b, &child))
|
||||||
{
|
{
|
||||||
@ -191,16 +201,16 @@ actor_iter_assignment (TestConformSimpleFixture *fixure G_GNUC_UNUSED,
|
|||||||
if (g_test_verbose ())
|
if (g_test_verbose ())
|
||||||
g_print ("actor %2d = '%s'\n", i, clutter_actor_get_name (child));
|
g_print ("actor %2d = '%s'\n", i, clutter_actor_get_name (child));
|
||||||
|
|
||||||
if (i == n_actors)
|
if (i == n_actors - 1)
|
||||||
g_assert (child == clutter_actor_get_last_child (actor));
|
g_assert (child == clutter_actor_get_last_child (actor));
|
||||||
|
|
||||||
if (i == 1)
|
if (i == 0)
|
||||||
g_assert (child == clutter_actor_get_first_child (actor));
|
g_assert (child == clutter_actor_get_first_child (actor));
|
||||||
|
|
||||||
i -= 1;
|
i -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_assert_cmpint (i, ==, 0);
|
g_assert_cmpint (i, ==, -1);
|
||||||
|
|
||||||
g_object_unref (actor);
|
g_object_unref (actor);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user