conformance: Add actor tests

Port the ClutterActor tests to the test API, and ensure they run under
the new TAP harness.
This commit is contained in:
Emmanuele Bassi 2013-12-12 14:51:00 +00:00
parent 2a660fa298
commit 7ec337f26f
14 changed files with 407 additions and 557 deletions

View File

@ -13,6 +13,19 @@ AM_CPPFLAGS = \
$(CLUTTER_PROFILE_CFLAGS) $(CLUTTER_PROFILE_CFLAGS)
actor_tests = \ actor_tests = \
actor-anchors \
actor-destroy \
actor-graph \
actor-invariants \
actor-iter \
actor-layout \
actor-meta \
actor-offscreen-limit-max-size \
actor-offscreen-redirect \
actor-paint-opacity \
actor-pick \
actor-shader-effect \
actor-size \
$(NULL) $(NULL)
general_tests = \ general_tests = \

View File

@ -1,8 +1,8 @@
#include <clutter/clutter.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "test-conform-common.h" #define CLUTTER_DISABLE_DEPRECATION_WARNINGS
#include <clutter/clutter.h>
#define NOTIFY_ANCHOR_X (1 << 0) #define NOTIFY_ANCHOR_X (1 << 0)
#define NOTIFY_ANCHOR_Y (1 << 1) #define NOTIFY_ANCHOR_Y (1 << 1)
@ -671,16 +671,16 @@ idle_cb (gpointer data)
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
void static void
actor_anchors (void) actor_anchors (void)
{ {
TestState state; TestState state;
ClutterActor *stage; ClutterActor *stage;
stage = clutter_stage_new (); stage = clutter_test_get_stage ();
state.rect = clutter_rectangle_new (); state.rect = clutter_actor_new ();
clutter_container_add (CLUTTER_CONTAINER (stage), state.rect, NULL); clutter_actor_add_child (stage, state.rect);
clutter_actor_set_position (state.rect, 100, 200); clutter_actor_set_position (state.rect, 100, 200);
clutter_actor_set_size (state.rect, RECT_WIDTH, RECT_HEIGHT); clutter_actor_set_size (state.rect, RECT_WIDTH, RECT_HEIGHT);
@ -696,9 +696,46 @@ actor_anchors (void)
clutter_actor_show (stage); clutter_actor_show (stage);
clutter_main (); clutter_main ();
g_idle_remove_by_data (&state);
clutter_actor_destroy (stage);
} }
static void
actor_pivot (void)
{
ClutterActor *stage, *actor_implicit, *actor_explicit;
ClutterMatrix transform, result_implicit, result_explicit;
ClutterActorBox allocation = CLUTTER_ACTOR_BOX_INIT (0, 0, 90, 30);
gfloat angle = 30;
stage = clutter_test_get_stage ();
actor_implicit = clutter_actor_new ();
actor_explicit = clutter_actor_new ();
clutter_actor_add_child (stage, actor_implicit);
clutter_actor_add_child (stage, actor_explicit);
/* Fake allocation or pivot-point will not have any effect */
clutter_actor_allocate (actor_implicit, &allocation, CLUTTER_ALLOCATION_NONE);
clutter_actor_allocate (actor_explicit, &allocation, CLUTTER_ALLOCATION_NONE);
clutter_actor_set_pivot_point (actor_implicit, 0.5, 0.5);
clutter_actor_set_pivot_point (actor_explicit, 0.5, 0.5);
/* Implict transformation */
clutter_actor_set_rotation_angle (actor_implicit, CLUTTER_Z_AXIS, angle);
/* Explict transformation */
clutter_matrix_init_identity(&transform);
cogl_matrix_rotate (&transform, angle, 0, 0, 1.0);
clutter_actor_set_transform (actor_explicit, &transform);
clutter_actor_get_transform (actor_implicit, &result_implicit);
clutter_actor_get_transform (actor_explicit, &result_explicit);
g_assert (cogl_matrix_equal (&result_implicit, &result_explicit));
}
CLUTTER_TEST_SUITE (
CLUTTER_TEST_UNIT ("/actor/transforms/anchor-point", actor_anchors)
CLUTTER_TEST_UNIT ("/actor/transforms/pivot-point", actor_pivot)
)

View File

@ -1,5 +1,5 @@
#define CLUTTER_DISABLE_DEPRECATION_WARNINGS
#include <clutter/clutter.h> #include <clutter/clutter.h>
#include "test-conform-common.h"
#define TEST_TYPE_DESTROY (test_destroy_get_type ()) #define TEST_TYPE_DESTROY (test_destroy_get_type ())
#define TEST_DESTROY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_DESTROY, TestDestroy)) #define TEST_DESTROY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_DESTROY, TestDestroy))
@ -26,6 +26,8 @@ struct _TestDestroyClass
static void clutter_container_init (ClutterContainerIface *iface); static void clutter_container_init (ClutterContainerIface *iface);
GType test_destroy_get_type (void);
G_DEFINE_TYPE_WITH_CODE (TestDestroy, test_destroy, CLUTTER_TYPE_ACTOR, G_DEFINE_TYPE_WITH_CODE (TestDestroy, test_destroy, CLUTTER_TYPE_ACTOR,
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER, G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER,
clutter_container_init)); clutter_container_init));
@ -160,13 +162,18 @@ on_destroy (ClutterActor *actor,
*destroy_called = TRUE; *destroy_called = TRUE;
} }
void static void
actor_destruction (void) actor_destruction (void)
{ {
ClutterActor *test = g_object_new (TEST_TYPE_DESTROY, NULL); ClutterActor *test = g_object_new (TEST_TYPE_DESTROY, NULL);
ClutterActor *child = clutter_rectangle_new (); ClutterActor *child = clutter_rectangle_new ();
gboolean destroy_called = FALSE; gboolean destroy_called = FALSE;
g_object_ref_sink (test);
g_object_add_weak_pointer (G_OBJECT (test), (gpointer *) &test);
g_object_add_weak_pointer (G_OBJECT (child), (gpointer *) &child);
if (g_test_verbose ()) if (g_test_verbose ())
g_print ("Adding external child...\n"); g_print ("Adding external child...\n");
@ -179,4 +186,10 @@ actor_destruction (void)
clutter_actor_destroy (test); clutter_actor_destroy (test);
g_assert (destroy_called); g_assert (destroy_called);
g_assert_null (child);
g_assert_null (test);
} }
CLUTTER_TEST_SUITE (
CLUTTER_TEST_UNIT ("/actor/destruction", actor_destruction)
)

View File

@ -1,9 +1,7 @@
#include <clutter/clutter.h> #include <clutter/clutter.h>
#include "test-conform-common.h"
void static void
actor_add_child (TestConformSimpleFixture *fixture, actor_add_child (void)
gconstpointer dummy)
{ {
ClutterActor *actor = clutter_actor_new (); ClutterActor *actor = clutter_actor_new ();
ClutterActor *iter; ClutterActor *iter;
@ -49,9 +47,8 @@ actor_add_child (TestConformSimpleFixture *fixture,
g_assert (actor == NULL); g_assert (actor == NULL);
} }
void static void
actor_insert_child (TestConformSimpleFixture *fixture, actor_insert_child (void)
gconstpointer data)
{ {
ClutterActor *actor = clutter_actor_new (); ClutterActor *actor = clutter_actor_new ();
ClutterActor *iter; ClutterActor *iter;
@ -137,9 +134,8 @@ actor_insert_child (TestConformSimpleFixture *fixture,
g_assert (actor == NULL); g_assert (actor == NULL);
} }
void static void
actor_remove_child (TestConformSimpleFixture *fixture, actor_remove_child (void)
gconstpointer data)
{ {
ClutterActor *actor = clutter_actor_new (); ClutterActor *actor = clutter_actor_new ();
ClutterActor *iter; ClutterActor *iter;
@ -182,9 +178,8 @@ actor_remove_child (TestConformSimpleFixture *fixture,
g_assert (actor == NULL); g_assert (actor == NULL);
} }
void static void
actor_raise_child (TestConformSimpleFixture *fixture, actor_raise_child (void)
gconstpointer dummy)
{ {
ClutterActor *actor = clutter_actor_new (); ClutterActor *actor = clutter_actor_new ();
ClutterActor *iter; ClutterActor *iter;
@ -249,9 +244,8 @@ actor_raise_child (TestConformSimpleFixture *fixture,
g_assert (iter == NULL); g_assert (iter == NULL);
} }
void static void
actor_lower_child (TestConformSimpleFixture *fixture, actor_lower_child (void)
gconstpointer dummy)
{ {
ClutterActor *actor = clutter_actor_new (); ClutterActor *actor = clutter_actor_new ();
ClutterActor *iter; ClutterActor *iter;
@ -314,9 +308,8 @@ actor_lower_child (TestConformSimpleFixture *fixture,
g_assert (actor == NULL); g_assert (actor == NULL);
} }
void static void
actor_replace_child (TestConformSimpleFixture *fixture, actor_replace_child (void)
gconstpointer dummy)
{ {
ClutterActor *actor = clutter_actor_new (); ClutterActor *actor = clutter_actor_new ();
ClutterActor *iter; ClutterActor *iter;
@ -375,9 +368,8 @@ actor_replace_child (TestConformSimpleFixture *fixture,
g_assert (actor == NULL); g_assert (actor == NULL);
} }
void static void
actor_remove_all (TestConformSimpleFixture *fixture, actor_remove_all (void)
gconstpointer dummy)
{ {
ClutterActor *actor = clutter_actor_new (); ClutterActor *actor = clutter_actor_new ();
@ -436,9 +428,8 @@ actor_removed (ClutterContainer *container,
*counter += 1; *counter += 1;
} }
void static void
actor_container_signals (TestConformSimpleFixture *fixture G_GNUC_UNUSED, actor_container_signals (void)
gconstpointer data G_GNUC_UNUSED)
{ {
ClutterActor *actor = clutter_actor_new (); ClutterActor *actor = clutter_actor_new ();
int add_count, remove_count; int add_count, remove_count;
@ -478,3 +469,81 @@ actor_container_signals (TestConformSimpleFixture *fixture G_GNUC_UNUSED,
clutter_actor_destroy (actor); clutter_actor_destroy (actor);
g_assert (actor == NULL); g_assert (actor == NULL);
} }
static void
actor_contains (void)
{
/* This build up the following tree:
*
* a
*
*
* b c d
*
* e f g h i j
*/
struct {
ClutterActor *actor_a, *actor_b, *actor_c, *actor_d, *actor_e;
ClutterActor *actor_f, *actor_g, *actor_h, *actor_i, *actor_j;
} d;
int x, y;
ClutterActor **actor_array = &d.actor_a;
/* Matrix of expected results */
static const gboolean expected_results[] =
{ /* a, b, c, d, e, f, g, h, i, j */
/* a */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
/* b */ 0, 1, 0, 0, 1, 1, 0, 0, 0, 0,
/* c */ 0, 0, 1, 0, 0, 0, 1, 1, 0, 0,
/* d */ 0, 0, 0, 1, 0, 0, 0, 0, 1, 1,
/* e */ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
/* f */ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
/* g */ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
/* h */ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
/* i */ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
/* j */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
};
d.actor_a = clutter_actor_new ();
d.actor_b = clutter_actor_new ();
d.actor_c = clutter_actor_new ();
d.actor_d = clutter_actor_new ();
d.actor_e = clutter_actor_new ();
d.actor_f = clutter_actor_new ();
d.actor_g = clutter_actor_new ();
d.actor_h = clutter_actor_new ();
d.actor_i = clutter_actor_new ();
d.actor_j = clutter_actor_new ();
clutter_actor_add_child (d.actor_a, d.actor_b);
clutter_actor_add_child (d.actor_a, d.actor_c);
clutter_actor_add_child (d.actor_a, d.actor_d);
clutter_actor_add_child (d.actor_b, d.actor_e);
clutter_actor_add_child (d.actor_b, d.actor_f);
clutter_actor_add_child (d.actor_c, d.actor_g);
clutter_actor_add_child (d.actor_c, d.actor_h);
clutter_actor_add_child (d.actor_d, d.actor_i);
clutter_actor_add_child (d.actor_d, d.actor_j);
for (y = 0; y < 10; y++)
for (x = 0; x < 10; x++)
g_assert_cmpint (clutter_actor_contains (actor_array[x],
actor_array[y]),
==,
expected_results[x * 10 + y]);
}
CLUTTER_TEST_SUITE (
CLUTTER_TEST_UNIT ("/actor/graph/add-child", actor_add_child)
CLUTTER_TEST_UNIT ("/actor/graph/insert-child", actor_insert_child)
CLUTTER_TEST_UNIT ("/actor/graph/remove-child", actor_remove_child)
CLUTTER_TEST_UNIT ("/actor/graph/raise-child", actor_raise_child)
CLUTTER_TEST_UNIT ("/actor/graph/lower-child", actor_lower_child)
CLUTTER_TEST_UNIT ("/actor/graph/replace-child", actor_replace_child)
CLUTTER_TEST_UNIT ("/actor/graph/remove-all", actor_remove_all)
CLUTTER_TEST_UNIT ("/actor/graph/container-signals", actor_container_signals)
CLUTTER_TEST_UNIT ("/actor/graph/contains", actor_contains)
)

View File

@ -3,11 +3,8 @@
#include <clutter/clutter.h> #include <clutter/clutter.h>
#include "test-conform-common.h" static void
actor_initial_state (void)
void
actor_initial_state (TestConformSimpleFixture *fixture,
gconstpointer data)
{ {
ClutterActor *actor; ClutterActor *actor;
@ -29,13 +26,12 @@ actor_initial_state (TestConformSimpleFixture *fixture,
g_assert (actor == NULL); g_assert (actor == NULL);
} }
void static void
actor_shown_not_parented (TestConformSimpleFixture *fixture, actor_shown_not_parented (void)
gconstpointer data)
{ {
ClutterActor *actor; ClutterActor *actor;
actor = clutter_rectangle_new (); actor = clutter_actor_new ();
g_object_ref_sink (actor); g_object_ref_sink (actor);
g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor);
@ -55,14 +51,13 @@ actor_shown_not_parented (TestConformSimpleFixture *fixture,
g_assert (actor == NULL); g_assert (actor == NULL);
} }
void static void
actor_realized (TestConformSimpleFixture *fixture, actor_realized (void)
gconstpointer data)
{ {
ClutterActor *actor; ClutterActor *actor;
ClutterActor *stage; ClutterActor *stage;
stage = clutter_stage_new (); stage = clutter_test_get_stage ();
actor = clutter_actor_new (); actor = clutter_actor_new ();
@ -76,18 +71,15 @@ actor_realized (TestConformSimpleFixture *fixture,
g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor)));
g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor))); g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor)));
clutter_actor_destroy (stage);
} }
void static void
actor_mapped (TestConformSimpleFixture *fixture, actor_mapped (void)
gconstpointer data)
{ {
ClutterActor *actor; ClutterActor *actor;
ClutterActor *stage; ClutterActor *stage;
stage = clutter_stage_new (); stage = clutter_test_get_stage ();
clutter_actor_show (stage); clutter_actor_show (stage);
actor = clutter_actor_new (); actor = clutter_actor_new ();
@ -120,18 +112,16 @@ actor_mapped (TestConformSimpleFixture *fixture,
g_assert (CLUTTER_ACTOR_IS_REALIZED (actor)); g_assert (CLUTTER_ACTOR_IS_REALIZED (actor));
g_assert (!CLUTTER_ACTOR_IS_MAPPED (actor)); g_assert (!CLUTTER_ACTOR_IS_MAPPED (actor));
g_assert (!CLUTTER_ACTOR_IS_VISIBLE (actor)); g_assert (!CLUTTER_ACTOR_IS_VISIBLE (actor));
clutter_actor_destroy (stage);
} }
void static void
actor_visibility_not_recursive (TestConformSimpleFixture *fixture, actor_visibility_not_recursive (void)
gconstpointer data)
{ {
ClutterActor *actor, *group; ClutterActor *actor, *group;
ClutterActor *stage; ClutterActor *stage;
stage = clutter_stage_new (); stage = clutter_test_get_stage ();
group = clutter_actor_new (); group = clutter_actor_new ();
actor = clutter_actor_new (); actor = clutter_actor_new ();
@ -162,18 +152,15 @@ actor_visibility_not_recursive (TestConformSimpleFixture *fixture,
clutter_actor_show (stage); clutter_actor_show (stage);
g_assert (!CLUTTER_ACTOR_IS_VISIBLE (actor)); g_assert (!CLUTTER_ACTOR_IS_VISIBLE (actor));
clutter_actor_destroy (stage);
} }
void static void
actor_realize_not_recursive (TestConformSimpleFixture *fixture, actor_realize_not_recursive (void)
gconstpointer data)
{ {
ClutterActor *actor, *group; ClutterActor *actor, *group;
ClutterActor *stage; ClutterActor *stage;
stage = clutter_stage_new (); stage = clutter_test_get_stage ();
clutter_actor_show (stage); clutter_actor_show (stage);
group = clutter_actor_new (); group = clutter_actor_new ();
@ -200,18 +187,15 @@ actor_realize_not_recursive (TestConformSimpleFixture *fixture,
g_assert (!CLUTTER_ACTOR_IS_REALIZED (actor)); g_assert (!CLUTTER_ACTOR_IS_REALIZED (actor));
g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor)));
g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor))); g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor)));
clutter_actor_destroy (stage);
} }
void static void
actor_map_recursive (TestConformSimpleFixture *fixture, actor_map_recursive (void)
gconstpointer data)
{ {
ClutterActor *actor, *group; ClutterActor *actor, *group;
ClutterActor *stage; ClutterActor *stage;
stage = clutter_stage_new (); stage = clutter_test_get_stage ();
clutter_actor_show (stage); clutter_actor_show (stage);
group = clutter_actor_new (); group = clutter_actor_new ();
@ -248,19 +232,16 @@ actor_map_recursive (TestConformSimpleFixture *fixture,
g_assert (CLUTTER_ACTOR_IS_MAPPED (actor)); g_assert (CLUTTER_ACTOR_IS_MAPPED (actor));
g_assert (CLUTTER_ACTOR_IS_VISIBLE (group)); g_assert (CLUTTER_ACTOR_IS_VISIBLE (group));
g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor)); g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor));
clutter_actor_destroy (stage);
} }
void static void
actor_show_on_set_parent (TestConformSimpleFixture *fixture, actor_show_on_set_parent (void)
gconstpointer data)
{ {
ClutterActor *actor, *group; ClutterActor *actor, *group;
gboolean show_on_set_parent; gboolean show_on_set_parent;
ClutterActor *stage; ClutterActor *stage;
stage = clutter_stage_new (); stage = clutter_test_get_stage ();
group = clutter_actor_new (); group = clutter_actor_new ();
@ -321,20 +302,17 @@ actor_show_on_set_parent (TestConformSimpleFixture *fixture,
g_assert (!show_on_set_parent); g_assert (!show_on_set_parent);
clutter_actor_destroy (actor); clutter_actor_destroy (actor);
clutter_actor_destroy (stage);
} }
void static void
clone_no_map (TestConformSimpleFixture *fixture, clone_no_map (void)
gconstpointer data)
{ {
ClutterActor *stage; ClutterActor *stage;
ClutterActor *group; ClutterActor *group;
ClutterActor *actor; ClutterActor *actor;
ClutterActor *clone; ClutterActor *clone;
stage = clutter_stage_new (); stage = clutter_test_get_stage ();
clutter_actor_show (stage); clutter_actor_show (stage);
group = clutter_actor_new (); group = clutter_actor_new ();
@ -358,83 +336,15 @@ clone_no_map (TestConformSimpleFixture *fixture,
clutter_actor_destroy (CLUTTER_ACTOR (clone)); clutter_actor_destroy (CLUTTER_ACTOR (clone));
clutter_actor_destroy (CLUTTER_ACTOR (group)); clutter_actor_destroy (CLUTTER_ACTOR (group));
clutter_actor_destroy (stage);
} }
void G_GNUC_BEGIN_IGNORE_DEPRECATIONS
actor_contains (TestConformSimpleFixture *fixture, static void
gconstpointer data) default_stage (void)
{
/* This build up the following tree:
*
* a
*
*
* b c d
*
* e f g h i j
*/
struct {
ClutterActor *actor_a, *actor_b, *actor_c, *actor_d, *actor_e;
ClutterActor *actor_f, *actor_g, *actor_h, *actor_i, *actor_j;
} d;
int x, y;
ClutterActor **actor_array = &d.actor_a;
/* Matrix of expected results */
static const gboolean expected_results[] =
{ /* a, b, c, d, e, f, g, h, i, j */
/* a */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
/* b */ 0, 1, 0, 0, 1, 1, 0, 0, 0, 0,
/* c */ 0, 0, 1, 0, 0, 0, 1, 1, 0, 0,
/* d */ 0, 0, 0, 1, 0, 0, 0, 0, 1, 1,
/* e */ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
/* f */ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
/* g */ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
/* h */ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
/* i */ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
/* j */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
};
d.actor_a = clutter_actor_new ();
d.actor_b = clutter_actor_new ();
d.actor_c = clutter_actor_new ();
d.actor_d = clutter_actor_new ();
d.actor_e = clutter_actor_new ();
d.actor_f = clutter_actor_new ();
d.actor_g = clutter_actor_new ();
d.actor_h = clutter_actor_new ();
d.actor_i = clutter_actor_new ();
d.actor_j = clutter_actor_new ();
clutter_actor_add_child (d.actor_a, d.actor_b);
clutter_actor_add_child (d.actor_a, d.actor_c);
clutter_actor_add_child (d.actor_a, d.actor_d);
clutter_actor_add_child (d.actor_b, d.actor_e);
clutter_actor_add_child (d.actor_b, d.actor_f);
clutter_actor_add_child (d.actor_c, d.actor_g);
clutter_actor_add_child (d.actor_c, d.actor_h);
clutter_actor_add_child (d.actor_d, d.actor_i);
clutter_actor_add_child (d.actor_d, d.actor_j);
for (y = 0; y < 10; y++)
for (x = 0; x < 10; x++)
g_assert_cmpint (clutter_actor_contains (actor_array[x],
actor_array[y]),
==,
expected_results[x * 10 + y]);
}
void
default_stage (TestConformSimpleFixture *fixture,
gconstpointer data)
{ {
ClutterActor *stage, *def_stage; ClutterActor *stage, *def_stage;
stage = clutter_stage_new (); stage = clutter_test_get_stage ();
def_stage = clutter_stage_get_default (); def_stage = clutter_stage_get_default ();
if (clutter_feature_available (CLUTTER_FEATURE_STAGE_MULTIPLE)) if (clutter_feature_available (CLUTTER_FEATURE_STAGE_MULTIPLE))
@ -444,43 +354,17 @@ default_stage (TestConformSimpleFixture *fixture,
g_assert (CLUTTER_ACTOR_IS_REALIZED (def_stage)); g_assert (CLUTTER_ACTOR_IS_REALIZED (def_stage));
} }
G_GNUC_END_IGNORE_DEPRECATIONS
void CLUTTER_TEST_SUITE (
actor_pivot_transformation (TestConformSimpleFixture *fixture, CLUTTER_TEST_UNIT ("/actor/invariants/initial-state", actor_initial_state)
gconstpointer data) CLUTTER_TEST_UNIT ("/actor/invariants/show-not-parented", actor_shown_not_parented)
{ CLUTTER_TEST_UNIT ("/actor/invariants/realized", actor_realized)
ClutterActor *stage, *actor_implicit, *actor_explicit; CLUTTER_TEST_UNIT ("/actor/invariants/mapped", actor_mapped)
ClutterMatrix transform, result_implicit, result_explicit; CLUTTER_TEST_UNIT ("/actor/invariants/visibility-not-recursive", actor_visibility_not_recursive)
ClutterActorBox allocation = CLUTTER_ACTOR_BOX_INIT (0, 0, 90, 30); CLUTTER_TEST_UNIT ("/actor/invariants/realize-not-recursive", actor_realize_not_recursive)
gfloat angle = 30; CLUTTER_TEST_UNIT ("/actor/invariants/map-recursive", actor_map_recursive)
CLUTTER_TEST_UNIT ("/actor/invariants/show-on-set-parent", actor_show_on_set_parent)
stage = clutter_stage_new (); CLUTTER_TEST_UNIT ("/actor/invariants/clone-no-map", clone_no_map)
CLUTTER_TEST_UNIT ("/actor/invariants/default-stage", default_stage)
actor_implicit = clutter_actor_new (); )
actor_explicit = clutter_actor_new ();
clutter_actor_add_child (stage, actor_implicit);
clutter_actor_add_child (stage, actor_explicit);
/* Fake allocation or pivot-point will not have any effect */
clutter_actor_allocate (actor_implicit, &allocation, CLUTTER_ALLOCATION_NONE);
clutter_actor_allocate (actor_explicit, &allocation, CLUTTER_ALLOCATION_NONE);
clutter_actor_set_pivot_point (actor_implicit, 0.5, 0.5);
clutter_actor_set_pivot_point (actor_explicit, 0.5, 0.5);
/* Implict transformation */
clutter_actor_set_rotation_angle (actor_implicit, CLUTTER_Z_AXIS, angle);
/* Explict transformation */
clutter_matrix_init_identity(&transform);
cogl_matrix_rotate (&transform, angle, 0, 0, 1.0);
clutter_actor_set_transform (actor_explicit, &transform);
clutter_actor_get_transform (actor_implicit, &result_implicit);
clutter_actor_get_transform (actor_explicit, &result_explicit);
clutter_actor_destroy (stage);
g_assert (cogl_matrix_equal (&result_implicit, &result_explicit));
}

View File

@ -1,10 +1,8 @@
#include <glib.h> #include <glib.h>
#include <clutter/clutter.h> #include <clutter/clutter.h>
#include "test-conform-common.h"
void static void
actor_iter_traverse_children (TestConformSimpleFixture *fixture G_GNUC_UNUSED, actor_iter_traverse_children (void)
gconstpointer dummy G_GNUC_UNUSED)
{ {
ClutterActorIter iter; ClutterActorIter iter;
ClutterActor *actor; ClutterActor *actor;
@ -78,9 +76,8 @@ actor_iter_traverse_children (TestConformSimpleFixture *fixture G_GNUC_UNUSED,
g_object_unref (actor); g_object_unref (actor);
} }
void static void
actor_iter_traverse_remove (TestConformSimpleFixture *fixture G_GNUC_UNUSED, actor_iter_traverse_remove (void)
gconstpointer dummy G_GNUC_UNUSED)
{ {
ClutterActorIter iter; ClutterActorIter iter;
ClutterActor *actor; ClutterActor *actor;
@ -135,9 +132,8 @@ actor_iter_traverse_remove (TestConformSimpleFixture *fixture G_GNUC_UNUSED,
g_assert_cmpint (0, ==, clutter_actor_get_n_children (actor)); g_assert_cmpint (0, ==, clutter_actor_get_n_children (actor));
} }
void static void
actor_iter_assignment (TestConformSimpleFixture *fixure G_GNUC_UNUSED, actor_iter_assignment (void)
gconstpointer dummy G_GNUC_UNUSED)
{ {
ClutterActorIter iter_a, iter_b; ClutterActorIter iter_a, iter_b;
ClutterActor *actor; ClutterActor *actor;
@ -214,3 +210,9 @@ actor_iter_assignment (TestConformSimpleFixture *fixure G_GNUC_UNUSED,
g_object_unref (actor); g_object_unref (actor);
} }
CLUTTER_TEST_SUITE (
CLUTTER_TEST_UNIT ("/actor/iter/traverse-children", actor_iter_traverse_children)
CLUTTER_TEST_UNIT ("/actor/iter/traverse-remove", actor_iter_traverse_remove)
CLUTTER_TEST_UNIT ("/actor/iter/assignment", actor_iter_assignment)
)

View File

@ -1,199 +1,15 @@
#include <math.h>
#include <clutter/clutter.h> #include <clutter/clutter.h>
#include "test-conform-common.h"
typedef struct _TestState TestState;
struct _TestState
{
GPtrArray *actors;
GPtrArray *colors;
ClutterActor *stage;
gulong id;
gint in_validation;
guint was_painted : 1;
};
static TestState *
test_state_new (void)
{
return g_slice_new0 (TestState);
}
static void static void
test_state_free (TestState *state) actor_basic_layout (void)
{ {
if (state->id != 0) ClutterActor *stage = clutter_test_get_stage ();
g_source_remove (state->id);
if (state->actors != NULL)
g_ptr_array_unref (state->actors);
if (state->colors != NULL)
g_ptr_array_unref (state->colors);
if (state->stage != NULL)
clutter_actor_destroy (state->stage);
g_slice_free (TestState, state);
}
static void
test_state_set_stage (TestState *state,
ClutterActor *stage)
{
g_assert (!state->was_painted);
state->stage = stage;
}
static void
test_state_add_actor (TestState *state,
ClutterActor *actor,
const ClutterColor *color)
{
g_assert (!state->was_painted);
if (state->actors == NULL)
{
state->actors = g_ptr_array_new ();
g_ptr_array_set_free_func (state->actors,
(GDestroyNotify) g_object_unref);
}
g_ptr_array_add (state->actors, g_object_ref (actor));
if (state->colors == NULL)
{
state->colors = g_ptr_array_new ();
g_ptr_array_set_free_func (state->colors,
(GDestroyNotify) clutter_color_free);
}
g_ptr_array_add (state->colors, clutter_color_copy (color));
}
static void
test_state_push_validation (TestState *state)
{
state->in_validation += 1;
}
static void
test_state_pop_validation (TestState *state)
{
state->in_validation -= 1;
}
static gboolean
test_state_in_validation (TestState *state)
{
return state->in_validation > 0;
}
static gboolean
check_color_at (ClutterActor *stage,
ClutterActor *actor,
ClutterColor *expected_color,
float x,
float y)
{
guchar *buffer;
if (g_test_verbose ())
g_print ("Checking actor '%s'\n", clutter_actor_get_name (actor));
if (g_test_verbose ())
g_print ("Sampling at { %d, %d }\t", (int) x, (int) y);
buffer = clutter_stage_read_pixels (CLUTTER_STAGE (stage), x, y, 1, 1);
g_assert (buffer != NULL);
if (g_test_verbose ())
g_print ("Color: { %d, %d, %d } - Expected color { %d, %d, %d }\n",
buffer[0],
buffer[1],
buffer[2],
expected_color->red,
expected_color->green,
expected_color->blue);
g_assert_cmpint (buffer[0], ==, expected_color->red);
g_assert_cmpint (buffer[1], ==, expected_color->green);
g_assert_cmpint (buffer[2], ==, expected_color->blue);
g_free (buffer);
return TRUE;
}
static gboolean
validate_state (gpointer data)
{
TestState *state = data;
int i;
/* avoid recursion */
if (test_state_in_validation (state))
return G_SOURCE_REMOVE;
g_assert (state->actors != NULL);
g_assert (state->colors != NULL);
g_assert_cmpint (state->actors->len, ==, state->colors->len);
test_state_push_validation (state);
if (g_test_verbose ())
g_print ("Sampling %d actors\n", state->actors->len);
for (i = 0; i < state->actors->len; i++)
{
ClutterActor *actor = g_ptr_array_index (state->actors, i);
ClutterColor *color = g_ptr_array_index (state->colors, i);
ClutterActorBox box;
clutter_actor_get_allocation_box (actor, &box);
check_color_at (state->stage, actor, color, box.x1 + 2, box.y1 + 2);
check_color_at (state->stage, actor, color, box.x2 - 2, box.y2 - 2);
}
test_state_pop_validation (state);
state->was_painted = TRUE;
return G_SOURCE_REMOVE;
}
static gboolean
test_state_run (TestState *state)
{
clutter_threads_add_repaint_func_full (CLUTTER_REPAINT_FLAGS_POST_PAINT,
validate_state,
state,
NULL);
while (!state->was_painted)
g_main_context_iteration (NULL, FALSE);
return TRUE;
}
void
actor_basic_layout (TestConformSimpleFixture *fixture,
gconstpointer data)
{
ClutterActor *stage = clutter_stage_new ();
ClutterActor *vase; ClutterActor *vase;
ClutterActor *flower[3]; ClutterActor *flower[3];
TestState *state; ClutterPoint p;
vase = clutter_actor_new (); vase = clutter_actor_new ();
clutter_actor_set_name (vase, "Vase");
clutter_actor_set_layout_manager (vase, clutter_flow_layout_new (CLUTTER_FLOW_HORIZONTAL)); clutter_actor_set_layout_manager (vase, clutter_flow_layout_new (CLUTTER_FLOW_HORIZONTAL));
clutter_actor_add_child (stage, vase); clutter_actor_add_child (stage, vase);
@ -215,30 +31,27 @@ actor_basic_layout (TestConformSimpleFixture *fixture,
clutter_actor_set_name (flower[2], "Green Flower"); clutter_actor_set_name (flower[2], "Green Flower");
clutter_actor_add_child (vase, flower[2]); clutter_actor_add_child (vase, flower[2]);
clutter_actor_show_all (stage); clutter_point_init (&p, 50, 50);
clutter_test_assert_actor_at_point (stage, &p, flower[0]);
state = test_state_new (); clutter_point_init (&p, 150, 50);
test_state_set_stage (state, stage); clutter_test_assert_actor_at_point (stage, &p, flower[1]);
test_state_add_actor (state, flower[0], CLUTTER_COLOR_Red);
test_state_add_actor (state, flower[1], CLUTTER_COLOR_Yellow);
test_state_add_actor (state, flower[2], CLUTTER_COLOR_Green);
g_assert (test_state_run (state)); clutter_point_init (&p, 250, 50);
clutter_test_assert_actor_at_point (stage, &p, flower[2]);
test_state_free (state);
} }
void static void
actor_margin_layout (TestConformSimpleFixture *fixture, actor_margin_layout (void)
gconstpointer data)
{ {
ClutterActor *stage = clutter_stage_new (); ClutterActor *stage = clutter_test_get_stage ();
ClutterActor *vase; ClutterActor *vase;
ClutterActor *flower[3]; ClutterActor *flower[3];
TestState *state; ClutterPoint p;
vase = clutter_actor_new (); vase = clutter_actor_new ();
clutter_actor_set_layout_manager (vase, clutter_flow_layout_new (CLUTTER_FLOW_HORIZONTAL)); clutter_actor_set_name (vase, "Vase");
clutter_actor_set_layout_manager (vase, clutter_box_layout_new ());
clutter_actor_add_child (stage, vase); clutter_actor_add_child (stage, vase);
flower[0] = clutter_actor_new (); flower[0] = clutter_actor_new ();
@ -263,15 +76,17 @@ actor_margin_layout (TestConformSimpleFixture *fixture,
clutter_actor_set_margin_bottom (flower[2], 6); clutter_actor_set_margin_bottom (flower[2], 6);
clutter_actor_add_child (vase, flower[2]); clutter_actor_add_child (vase, flower[2]);
clutter_actor_show_all (stage); clutter_point_init (&p, 0, 7);
clutter_test_assert_actor_at_point (stage, &p, flower[0]);
state = test_state_new (); clutter_point_init (&p, 106, 50);
test_state_set_stage (state, stage); clutter_test_assert_actor_at_point (stage, &p, flower[1]);
test_state_add_actor (state, flower[0], CLUTTER_COLOR_Red);
test_state_add_actor (state, flower[1], CLUTTER_COLOR_Yellow);
test_state_add_actor (state, flower[2], CLUTTER_COLOR_Green);
g_assert (test_state_run (state)); clutter_point_init (&p, 212, 7);
clutter_test_assert_actor_at_point (stage, &p, flower[2]);
test_state_free (state);
} }
CLUTTER_TEST_SUITE (
CLUTTER_TEST_UNIT ("/actor/layout/basic", actor_basic_layout)
CLUTTER_TEST_UNIT ("/actor/layout/margin", actor_margin_layout)
)

View File

@ -3,15 +3,12 @@
#include <clutter/clutter.h> #include <clutter/clutter.h>
#include "test-conform-common.h" static void
actor_meta_clear (void)
void
actor_meta_clear (TestConformSimpleFixture *fixture G_GNUC_UNUSED,
gconstpointer data G_GNUC_UNUSED)
{ {
ClutterActor *actor, *stage; ClutterActor *actor, *stage;
stage = clutter_stage_new (); stage = clutter_test_get_stage ();
actor = clutter_actor_new (); actor = clutter_actor_new ();
g_object_ref_sink (actor); g_object_ref_sink (actor);
@ -36,6 +33,8 @@ actor_meta_clear (TestConformSimpleFixture *fixture G_GNUC_UNUSED,
clutter_actor_destroy (actor); clutter_actor_destroy (actor);
g_assert (actor == NULL); g_assert (actor == NULL);
clutter_actor_destroy (stage);
} }
CLUTTER_TEST_SUITE (
CLUTTER_TEST_UNIT ("/actor/meta/clear", actor_meta_clear)
)

View File

@ -1,7 +1,6 @@
#define CLUTTER_ENABLE_EXPERIMENTAL_API
#include <clutter/clutter.h> #include <clutter/clutter.h>
#include "test-conform-common.h"
#define STAGE_WIDTH (300) #define STAGE_WIDTH (300)
#define STAGE_HEIGHT (300) #define STAGE_HEIGHT (300)
@ -21,18 +20,27 @@ check_results (ClutterStage *stage, gpointer user_data)
{ {
Data *data = user_data; Data *data = user_data;
gfloat width, height; gfloat width, height;
ClutterRect rect;
clutter_offscreen_effect_get_target_size (CLUTTER_OFFSCREEN_EFFECT (data->blur_effect1), clutter_offscreen_effect_get_target_rect (CLUTTER_OFFSCREEN_EFFECT (data->blur_effect1),
&width, &height); &rect);
width = clutter_rect_get_width (&rect);
height = clutter_rect_get_height (&rect);
if (g_test_verbose ()) if (g_test_verbose ())
g_print ("Checking effect1 size: %.2f x %.2f\n", width, height); g_print ("Checking effect1 size: %.2f x %.2f\n",
clutter_rect_get_width (&rect),
clutter_rect_get_height (&rect));
g_assert_cmpint (width, <, STAGE_WIDTH); g_assert_cmpint (width, <, STAGE_WIDTH);
g_assert_cmpint (height, <, STAGE_HEIGHT); g_assert_cmpint (height, <, STAGE_HEIGHT);
clutter_offscreen_effect_get_target_size (CLUTTER_OFFSCREEN_EFFECT (data->blur_effect2), clutter_offscreen_effect_get_target_rect (CLUTTER_OFFSCREEN_EFFECT (data->blur_effect2),
&width, &height); &rect);
width = clutter_rect_get_width (&rect);
height = clutter_rect_get_height (&rect);
if (g_test_verbose ()) if (g_test_verbose ())
g_print ("Checking effect2 size: %.2f x %.2f\n", width, height); g_print ("Checking effect2 size: %.2f x %.2f\n", width, height);
@ -58,60 +66,56 @@ create_actor (gfloat x, gfloat y,
NULL); NULL);
} }
void static void
actor_offscreen_limit_max_size (TestConformSimpleFixture *fixture, actor_offscreen_limit_max_size (void)
gconstpointer test_data)
{ {
if (cogl_features_available (COGL_FEATURE_OFFSCREEN)) Data data;
{
Data data;
data.stage = clutter_stage_new (); if (!cogl_features_available (COGL_FEATURE_OFFSCREEN))
clutter_stage_set_paint_callback (CLUTTER_STAGE (data.stage), return;
check_results,
&data,
NULL);
clutter_actor_set_size (data.stage, STAGE_WIDTH, STAGE_HEIGHT);
data.actor_group1 = clutter_actor_new (); data.stage = clutter_test_get_stage ();
clutter_actor_add_child (data.stage, data.actor_group1); clutter_stage_set_paint_callback (CLUTTER_STAGE (data.stage),
data.blur_effect1 = clutter_blur_effect_new (); check_results,
clutter_actor_add_effect (data.actor_group1, data.blur_effect1); &data,
clutter_actor_add_child (data.actor_group1, NULL);
create_actor (10, 10, clutter_actor_set_size (data.stage, STAGE_WIDTH, STAGE_HEIGHT);
100, 100,
CLUTTER_COLOR_Blue));
clutter_actor_add_child (data.actor_group1,
create_actor (100, 100,
100, 100,
CLUTTER_COLOR_Gray));
data.actor_group2 = clutter_actor_new (); data.actor_group1 = clutter_actor_new ();
clutter_actor_add_child (data.stage, data.actor_group2); clutter_actor_add_child (data.stage, data.actor_group1);
data.blur_effect2 = clutter_blur_effect_new (); data.blur_effect1 = clutter_blur_effect_new ();
clutter_actor_add_effect (data.actor_group2, data.blur_effect2); clutter_actor_add_effect (data.actor_group1, data.blur_effect1);
clutter_actor_add_child (data.actor_group2, clutter_actor_add_child (data.actor_group1,
create_actor (-10, -10, create_actor (10, 10,
100, 100, 100, 100,
CLUTTER_COLOR_Yellow)); CLUTTER_COLOR_Blue));
clutter_actor_add_child (data.actor_group2, clutter_actor_add_child (data.actor_group1,
create_actor (250, 10, create_actor (100, 100,
100, 100, 100, 100,
CLUTTER_COLOR_ScarletRed)); CLUTTER_COLOR_Gray));
clutter_actor_add_child (data.actor_group2,
create_actor (10, 250,
100, 100,
CLUTTER_COLOR_Yellow));
clutter_actor_show (data.stage); data.actor_group2 = clutter_actor_new ();
clutter_actor_add_child (data.stage, data.actor_group2);
data.blur_effect2 = clutter_blur_effect_new ();
clutter_actor_add_effect (data.actor_group2, data.blur_effect2);
clutter_actor_add_child (data.actor_group2,
create_actor (-10, -10,
100, 100,
CLUTTER_COLOR_Yellow));
clutter_actor_add_child (data.actor_group2,
create_actor (250, 10,
100, 100,
CLUTTER_COLOR_ScarletRed));
clutter_actor_add_child (data.actor_group2,
create_actor (10, 250,
100, 100,
CLUTTER_COLOR_Yellow));
clutter_main (); clutter_actor_show (data.stage);
clutter_actor_destroy (data.stage); clutter_main ();
if (g_test_verbose ())
g_print ("OK\n");
}
else if (g_test_verbose ())
g_print ("Skipping\n");
} }
CLUTTER_TEST_SUITE (
CLUTTER_TEST_UNIT ("/actor/offscreen/limit-max-size", actor_offscreen_limit_max_size)
)

View File

@ -1,7 +1,6 @@
#define CLUTTER_DISABLE_DEPRECATION_WARNINGS
#include <clutter/clutter.h> #include <clutter/clutter.h>
#include "test-conform-common.h"
typedef struct _FooActor FooActor; typedef struct _FooActor FooActor;
typedef struct _FooActorClass FooActorClass; typedef struct _FooActorClass FooActorClass;
@ -98,6 +97,8 @@ struct _FooGroup
ClutterActor parent; ClutterActor parent;
}; };
GType foo_group_get_type (void);
G_DEFINE_TYPE (FooGroup, foo_group, CLUTTER_TYPE_ACTOR) G_DEFINE_TYPE (FooGroup, foo_group, CLUTTER_TYPE_ACTOR)
static gboolean static gboolean
@ -294,21 +295,15 @@ run_verify (gpointer user_data)
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
void static void
actor_offscreen_redirect (TestConformSimpleFixture *fixture, actor_offscreen_redirect (void)
gconstpointer test_data)
{ {
Data data; Data data;
if (!cogl_features_available (COGL_FEATURE_OFFSCREEN)) if (!cogl_features_available (COGL_FEATURE_OFFSCREEN))
{ return;
if (g_test_verbose ())
g_print ("Offscreen buffers are not available, skipping test.\n");
return; data.stage = clutter_test_get_stage ();
}
data.stage = clutter_stage_new ();
data.parent_container = clutter_actor_new (); data.parent_container = clutter_actor_new ();
data.container = g_object_new (foo_group_get_type (), NULL); data.container = g_object_new (foo_group_get_type (), NULL);
data.foo_actor = g_object_new (foo_actor_get_type (), NULL); data.foo_actor = g_object_new (foo_actor_get_type (), NULL);
@ -335,6 +330,8 @@ actor_offscreen_redirect (TestConformSimpleFixture *fixture,
while (!data.was_painted) while (!data.was_painted)
g_main_context_iteration (NULL, FALSE); g_main_context_iteration (NULL, FALSE);
clutter_actor_destroy (data.stage);
} }
CLUTTER_TEST_SUITE (
CLUTTER_TEST_UNIT ("/actor/offscreen/redirect", actor_offscreen_redirect)
)

View File

@ -1,18 +1,15 @@
#include <clutter/clutter.h> #include <clutter/clutter.h>
#include <stdlib.h> #include <stdlib.h>
#include "test-conform-common.h" static void
opacity_label (void)
void
opacity_label (TestConformSimpleFixture *fixture,
gpointer dummy)
{ {
ClutterActor *stage; ClutterActor *stage;
ClutterActor *label; ClutterActor *label;
ClutterColor label_color = { 255, 0, 0, 128 }; ClutterColor label_color = { 255, 0, 0, 128 };
ClutterColor color_check = { 0, }; ClutterColor color_check = { 0, };
stage = clutter_stage_new (); stage = clutter_test_get_stage ();
label = clutter_text_new_with_text ("Sans 18px", "Label, 50% opacity"); label = clutter_text_new_with_text ("Sans 18px", "Label, 50% opacity");
clutter_text_set_color (CLUTTER_TEXT (label), &label_color); clutter_text_set_color (CLUTTER_TEXT (label), &label_color);
@ -22,7 +19,7 @@ opacity_label (TestConformSimpleFixture *fixture,
clutter_text_get_color (CLUTTER_TEXT (label), &color_check); clutter_text_get_color (CLUTTER_TEXT (label), &color_check);
g_assert (color_check.alpha == label_color.alpha); g_assert (color_check.alpha == label_color.alpha);
clutter_container_add (CLUTTER_CONTAINER (stage), label, NULL); clutter_actor_add_child (stage, label);
clutter_actor_set_position (label, 10, 10); clutter_actor_set_position (label, 10, 10);
if (g_test_verbose ()) if (g_test_verbose ())
@ -38,20 +35,18 @@ opacity_label (TestConformSimpleFixture *fixture,
g_print ("label 50%%.get_paint_opacity()/2\n"); g_print ("label 50%%.get_paint_opacity()/2\n");
clutter_actor_set_opacity (label, 128); clutter_actor_set_opacity (label, 128);
g_assert (clutter_actor_get_paint_opacity (label) == 128); g_assert (clutter_actor_get_paint_opacity (label) == 128);
clutter_actor_destroy (stage);
} }
void G_GNUC_BEGIN_IGNORE_DEPRECATIONS
opacity_rectangle (TestConformSimpleFixture *fixture, static void
gpointer dummy) opacity_rectangle (void)
{ {
ClutterActor *stage; ClutterActor *stage;
ClutterActor *rect; ClutterActor *rect;
ClutterColor rect_color = { 0, 0, 255, 255 }; ClutterColor rect_color = { 0, 0, 255, 255 };
ClutterColor color_check = { 0, }; ClutterColor color_check = { 0, };
stage = clutter_stage_new (); stage = clutter_test_get_stage ();
rect = clutter_rectangle_new_with_color (&rect_color); rect = clutter_rectangle_new_with_color (&rect_color);
clutter_actor_set_size (rect, 128, 128); clutter_actor_set_size (rect, 128, 128);
@ -62,7 +57,7 @@ opacity_rectangle (TestConformSimpleFixture *fixture,
clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &color_check); clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &color_check);
g_assert (color_check.alpha == rect_color.alpha); g_assert (color_check.alpha == rect_color.alpha);
clutter_container_add (CLUTTER_CONTAINER (stage), rect, NULL); clutter_actor_add_child (stage, rect);
if (g_test_verbose ()) if (g_test_verbose ())
g_print ("rect 100%%.get_color()/2\n"); g_print ("rect 100%%.get_color()/2\n");
@ -72,13 +67,12 @@ opacity_rectangle (TestConformSimpleFixture *fixture,
if (g_test_verbose ()) if (g_test_verbose ())
g_print ("rect 100%%.get_paint_opacity()\n"); g_print ("rect 100%%.get_paint_opacity()\n");
g_assert (clutter_actor_get_paint_opacity (rect) == 255); g_assert (clutter_actor_get_paint_opacity (rect) == 255);
clutter_actor_destroy (stage);
} }
G_GNUC_END_IGNORE_DEPRECATIONS
void G_GNUC_BEGIN_IGNORE_DEPRECATIONS
opacity_paint (TestConformSimpleFixture *fixture, static void
gpointer dummy) opacity_paint (void)
{ {
ClutterActor *stage, *group1, *group2; ClutterActor *stage, *group1, *group2;
ClutterActor *label, *rect; ClutterActor *label, *rect;
@ -86,7 +80,7 @@ opacity_paint (TestConformSimpleFixture *fixture,
ClutterColor rect_color = { 0, 0, 255, 255 }; ClutterColor rect_color = { 0, 0, 255, 255 };
ClutterColor color_check = { 0, }; ClutterColor color_check = { 0, };
stage = clutter_stage_new (); stage = clutter_test_get_stage ();
group1 = clutter_group_new (); group1 = clutter_group_new ();
clutter_actor_set_opacity (group1, 128); clutter_actor_set_opacity (group1, 128);
@ -137,6 +131,11 @@ opacity_paint (TestConformSimpleFixture *fixture,
if (g_test_verbose ()) if (g_test_verbose ())
g_print ("rect 100%%.get_paint_opacity()\n"); g_print ("rect 100%%.get_paint_opacity()\n");
g_assert (clutter_actor_get_paint_opacity (rect) == 128); g_assert (clutter_actor_get_paint_opacity (rect) == 128);
clutter_actor_destroy (stage);
} }
G_GNUC_END_IGNORE_DEPRECATIONS
CLUTTER_TEST_SUITE (
CLUTTER_TEST_UNIT ("/actor/opacity/text", opacity_label)
CLUTTER_TEST_UNIT ("/actor/opacity/rectangle", opacity_rectangle)
CLUTTER_TEST_UNIT ("/actor/opacity/paint", opacity_paint)
)

View File

@ -1,7 +1,6 @@
#define CLUTTER_DISABLE_DEPRECATION_WARNINGS
#include <clutter/clutter.h> #include <clutter/clutter.h>
#include "test-conform-common.h"
#define STAGE_WIDTH 640 #define STAGE_WIDTH 640
#define STAGE_HEIGHT 480 #define STAGE_HEIGHT 480
#define ACTORS_X 12 #define ACTORS_X 12
@ -34,6 +33,8 @@ typedef struct _ShiftEffectClass ShiftEffectClass;
#define TYPE_SHIFT_EFFECT (shift_effect_get_type ()) #define TYPE_SHIFT_EFFECT (shift_effect_get_type ())
GType shift_effect_get_type (void);
G_DEFINE_TYPE (ShiftEffect, G_DEFINE_TYPE (ShiftEffect,
shift_effect, shift_effect,
CLUTTER_TYPE_SHADER_EFFECT); CLUTTER_TYPE_SHADER_EFFECT);
@ -120,8 +121,7 @@ on_timeout (gpointer data)
isn't visible so it shouldn't affect the picking */ isn't visible so it shouldn't affect the picking */
over_actor = clutter_rectangle_new_with_color (&red); over_actor = clutter_rectangle_new_with_color (&red);
clutter_actor_set_size (over_actor, STAGE_WIDTH, STAGE_HEIGHT); clutter_actor_set_size (over_actor, STAGE_WIDTH, STAGE_HEIGHT);
clutter_container_add (CLUTTER_CONTAINER (state->stage), clutter_actor_add_child (state->stage, over_actor);
over_actor, NULL);
clutter_actor_hide (over_actor); clutter_actor_hide (over_actor);
if (g_test_verbose ()) if (g_test_verbose ())
@ -165,8 +165,9 @@ on_timeout (gpointer data)
"blur"); "blur");
clutter_actor_add_effect_with_name (CLUTTER_ACTOR (state->stage), clutter_actor_add_effect_with_name (CLUTTER_ACTOR (state->stage),
"shift", "shift",
g_object_new (TYPE_SHIFT_EFFECT, NULL)); g_object_new (TYPE_SHIFT_EFFECT,
NULL));
if (g_test_verbose ()) if (g_test_verbose ())
g_print ("With shift effect:\n"); g_print ("With shift effect:\n");
@ -190,12 +191,12 @@ on_timeout (gpointer data)
if (test_num == 4) if (test_num == 4)
pick_x -= SHIFT_STEP; pick_x -= SHIFT_STEP;
actor actor =
= clutter_stage_get_actor_at_pos (CLUTTER_STAGE (state->stage), clutter_stage_get_actor_at_pos (CLUTTER_STAGE (state->stage),
CLUTTER_PICK_ALL, CLUTTER_PICK_ALL,
pick_x, pick_x,
y * state->actor_height y * state->actor_height
+ state->actor_height / 2); + state->actor_height / 2);
if (g_test_verbose ()) if (g_test_verbose ())
g_print ("% 3i,% 3i / %p -> ", g_print ("% 3i,% 3i / %p -> ",
@ -239,7 +240,7 @@ on_timeout (gpointer data)
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
void static void
actor_pick (void) actor_pick (void)
{ {
int y, x; int y, x;
@ -247,7 +248,7 @@ actor_pick (void)
state.pass = TRUE; state.pass = TRUE;
state.stage = clutter_stage_new (); state.stage = clutter_test_get_stage ();
state.actor_width = STAGE_WIDTH / ACTORS_X; state.actor_width = STAGE_WIDTH / ACTORS_X;
state.actor_height = STAGE_HEIGHT / ACTORS_Y; state.actor_height = STAGE_HEIGHT / ACTORS_Y;
@ -267,7 +268,7 @@ actor_pick (void)
state.actor_width, state.actor_width,
state.actor_height); state.actor_height);
clutter_container_add (CLUTTER_CONTAINER (state.stage), rect, NULL); clutter_actor_add_child (state.stage, rect);
state.actors[y * ACTORS_X + x] = rect; state.actors[y * ACTORS_X + x] = rect;
} }
@ -278,10 +279,9 @@ actor_pick (void)
clutter_main (); clutter_main ();
if (g_test_verbose ())
g_print ("end result: %s\n", state.pass ? "pass" : "FAIL");
g_assert (state.pass); g_assert (state.pass);
clutter_actor_destroy (state.stage);
} }
CLUTTER_TEST_SUITE (
CLUTTER_TEST_UNIT ("/actor/pick", actor_pick)
)

View File

@ -1,7 +1,7 @@
#define CLUTTER_ENABLE_EXPERIMENTAL_API
#define CLUTTER_DISABLE_DEPRECATION_WARNINGS
#include <clutter/clutter.h> #include <clutter/clutter.h>
#include "test-conform-common.h"
/**************************************************************** /****************************************************************
Old style shader effect Old style shader effect
This uses clutter_shader_effect_set_source This uses clutter_shader_effect_set_source
@ -27,6 +27,8 @@ typedef struct _FooOldShaderEffect
ClutterShaderEffect parent; ClutterShaderEffect parent;
} FooOldShaderEffect; } FooOldShaderEffect;
GType foo_old_shader_effect_get_type (void);
G_DEFINE_TYPE (FooOldShaderEffect, G_DEFINE_TYPE (FooOldShaderEffect,
foo_old_shader_effect, foo_old_shader_effect,
CLUTTER_TYPE_SHADER_EFFECT); CLUTTER_TYPE_SHADER_EFFECT);
@ -85,6 +87,8 @@ typedef struct _FooNewShaderEffect
ClutterShaderEffect parent; ClutterShaderEffect parent;
} FooNewShaderEffect; } FooNewShaderEffect;
GType foo_new_shader_effect_get_type (void);
G_DEFINE_TYPE (FooNewShaderEffect, G_DEFINE_TYPE (FooNewShaderEffect,
foo_new_shader_effect, foo_new_shader_effect,
CLUTTER_TYPE_SHADER_EFFECT); CLUTTER_TYPE_SHADER_EFFECT);
@ -160,6 +164,8 @@ typedef struct _FooAnotherNewShaderEffect
ClutterShaderEffect parent; ClutterShaderEffect parent;
} FooAnotherNewShaderEffect; } FooAnotherNewShaderEffect;
GType foo_another_new_shader_effect_get_type (void);
G_DEFINE_TYPE (FooAnotherNewShaderEffect, G_DEFINE_TYPE (FooAnotherNewShaderEffect,
foo_another_new_shader_effect, foo_another_new_shader_effect,
CLUTTER_TYPE_SHADER_EFFECT); CLUTTER_TYPE_SHADER_EFFECT);
@ -218,8 +224,11 @@ get_pixel (int x, int y)
} }
static void static void
paint_cb (ClutterActor *stage) paint_cb (ClutterStage *stage,
gpointer data)
{ {
gboolean *was_painted = data;
/* old shader effect */ /* old shader effect */
g_assert_cmpint (get_pixel (50, 50), ==, 0xff0000); g_assert_cmpint (get_pixel (50, 50), ==, 0xff0000);
/* new shader effect */ /* new shader effect */
@ -229,15 +238,15 @@ paint_cb (ClutterActor *stage)
/* new shader effect */ /* new shader effect */
g_assert_cmpint (get_pixel (350, 50), ==, 0x00ffff); g_assert_cmpint (get_pixel (350, 50), ==, 0x00ffff);
clutter_main_quit (); *was_painted = TRUE;
} }
void static void
actor_shader_effect (TestConformSimpleFixture *fixture, actor_shader_effect (void)
gconstpointer data)
{ {
ClutterActor *stage; ClutterActor *stage;
ClutterActor *rect; ClutterActor *rect;
gboolean was_painted;
if (!clutter_feature_available (CLUTTER_FEATURE_SHADERS_GLSL)) if (!clutter_feature_available (CLUTTER_FEATURE_SHADERS_GLSL))
return; return;
@ -261,12 +270,16 @@ actor_shader_effect (TestConformSimpleFixture *fixture,
clutter_actor_show (stage); clutter_actor_show (stage);
g_signal_connect_after (stage, "paint", G_CALLBACK (paint_cb), NULL); was_painted = FALSE;
clutter_stage_set_paint_callback (CLUTTER_STAGE (stage),
paint_cb,
&was_painted,
NULL);
clutter_main (); while (!was_painted)
g_main_context_iteration (NULL, FALSE);
clutter_actor_destroy (stage);
if (g_test_verbose ())
g_print ("OK\n");
} }
CLUTTER_TEST_SUITE (
CLUTTER_TEST_UNIT ("/actor/shader-effect", actor_shader_effect)
)

View File

@ -3,8 +3,6 @@
#include <clutter/clutter.h> #include <clutter/clutter.h>
#include "test-conform-common.h"
#define TEST_TYPE_ACTOR (test_actor_get_type ()) #define TEST_TYPE_ACTOR (test_actor_get_type ())
typedef struct _TestActor TestActor; typedef struct _TestActor TestActor;
@ -18,6 +16,8 @@ struct _TestActor
guint preferred_height_called : 1; guint preferred_height_called : 1;
}; };
GType test_actor_get_type (void);
G_DEFINE_TYPE (TestActor, test_actor, CLUTTER_TYPE_ACTOR); G_DEFINE_TYPE (TestActor, test_actor, CLUTTER_TYPE_ACTOR);
static void static void
@ -78,7 +78,7 @@ test_actor_init (TestActor *self)
{ {
} }
void static void
actor_preferred_size (void) actor_preferred_size (void)
{ {
ClutterActor *test; ClutterActor *test;
@ -138,7 +138,7 @@ actor_preferred_size (void)
clutter_actor_destroy (test); clutter_actor_destroy (test);
} }
void static void
actor_fixed_size (void) actor_fixed_size (void)
{ {
ClutterActor *rect; ClutterActor *rect;
@ -209,3 +209,8 @@ actor_fixed_size (void)
clutter_actor_destroy (rect); clutter_actor_destroy (rect);
g_object_unref (rect); g_object_unref (rect);
} }
CLUTTER_TEST_SUITE (
CLUTTER_TEST_UNIT ("/actor/size/preferred", actor_preferred_size)
CLUTTER_TEST_UNIT ("/actor/size/fixed", actor_fixed_size)
)