mirror of
https://github.com/brl/mutter.git
synced 2024-12-24 12:02:04 +00:00
[tests] Add preferred size conformance test unit
This unit verifies that an Actor class will invoke the get_preferred_* virtual functions unless the caching is in effect; it also verifies that the cached values are correctly evicted.
This commit is contained in:
parent
092401c01b
commit
561f5868e8
@ -5,9 +5,143 @@
|
||||
|
||||
#include "test-conform-common.h"
|
||||
|
||||
#define TEST_TYPE_ACTOR (test_actor_get_type ())
|
||||
|
||||
typedef struct _TestActor TestActor;
|
||||
typedef struct _ClutterActorClass TestActorClass;
|
||||
|
||||
struct _TestActor
|
||||
{
|
||||
ClutterActor parent_instance;
|
||||
|
||||
guint preferred_width_called : 1;
|
||||
guint preferred_height_called : 1;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (TestActor, test_actor, CLUTTER_TYPE_ACTOR);
|
||||
|
||||
static void
|
||||
test_actor_get_preferred_width (ClutterActor *self,
|
||||
gfloat for_height,
|
||||
gfloat *min_width_p,
|
||||
gfloat *nat_width_p)
|
||||
{
|
||||
TestActor *test = (TestActor *) self;
|
||||
|
||||
test->preferred_width_called = TRUE;
|
||||
|
||||
if (for_height == 10)
|
||||
{
|
||||
*min_width_p = 10;
|
||||
*nat_width_p = 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
*min_width_p = 100;
|
||||
*nat_width_p = 100;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_actor_get_preferred_height (ClutterActor *self,
|
||||
gfloat for_width,
|
||||
gfloat *min_height_p,
|
||||
gfloat *nat_height_p)
|
||||
{
|
||||
TestActor *test = (TestActor *) self;
|
||||
|
||||
test->preferred_height_called = TRUE;
|
||||
|
||||
if (for_width == 10)
|
||||
{
|
||||
*min_height_p = 50;
|
||||
*nat_height_p = 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
*min_height_p = 100;
|
||||
*nat_height_p = 100;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_actor_class_init (TestActorClass *klass)
|
||||
{
|
||||
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
||||
|
||||
actor_class->get_preferred_width = test_actor_get_preferred_width;
|
||||
actor_class->get_preferred_height = test_actor_get_preferred_height;
|
||||
}
|
||||
|
||||
static void
|
||||
test_actor_init (TestActor *self)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
test_preferred_size (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterActor *test;
|
||||
TestActor *self;
|
||||
gfloat min_width, min_height;
|
||||
gfloat nat_width, nat_height;
|
||||
|
||||
test = g_object_new (TEST_TYPE_ACTOR, NULL);
|
||||
self = (TestActor *) test;
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("Preferred size\n");
|
||||
|
||||
clutter_actor_get_preferred_size (test,
|
||||
&min_width, &min_height,
|
||||
&nat_width, &nat_height);
|
||||
|
||||
g_assert (self->preferred_width_called);
|
||||
g_assert (self->preferred_height_called);
|
||||
g_assert_cmpfloat (min_width, ==, 100);
|
||||
g_assert_cmpfloat (min_height, ==, 100);
|
||||
g_assert_cmpfloat (nat_width, ==, min_width);
|
||||
g_assert_cmpfloat (nat_height, ==, min_height);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("Preferred width\n");
|
||||
self->preferred_width_called = FALSE;
|
||||
clutter_actor_get_preferred_width (test, 10, &min_width, &nat_width);
|
||||
g_assert (self->preferred_width_called);
|
||||
g_assert_cmpfloat (min_width, ==, 10);
|
||||
g_assert_cmpfloat (nat_width, ==, 100);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("Preferred height\n");
|
||||
self->preferred_height_called = FALSE;
|
||||
clutter_actor_get_preferred_height (test, 200, &min_height, &nat_height);
|
||||
g_assert (self->preferred_height_called);
|
||||
g_assert_cmpfloat (min_height, !=, 10);
|
||||
g_assert_cmpfloat (nat_height, ==, 100);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("Preferred width (cached)\n");
|
||||
self->preferred_width_called = FALSE;
|
||||
clutter_actor_get_preferred_width (test, 10, &min_width, &nat_width);
|
||||
g_assert (!self->preferred_width_called);
|
||||
g_assert_cmpfloat (min_width, ==, 10);
|
||||
g_assert_cmpfloat (nat_width, ==, 100);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("Preferred height (cache eviction)\n");
|
||||
self->preferred_height_called = FALSE;
|
||||
clutter_actor_get_preferred_height (test, 10, &min_height, &nat_height);
|
||||
g_assert (self->preferred_height_called);
|
||||
g_assert_cmpfloat (min_height, ==, 50);
|
||||
g_assert_cmpfloat (nat_height, ==, 100);
|
||||
|
||||
clutter_actor_destroy (test);
|
||||
}
|
||||
|
||||
void
|
||||
test_fixed_size (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterActor *rect;
|
||||
gboolean min_width_set, nat_width_set;
|
||||
|
@ -171,6 +171,7 @@ main (int argc, char **argv)
|
||||
TEST_CONFORM_SIMPLE ("/group", test_group_depth_sorting);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/sizing", test_fixed_size);
|
||||
TEST_CONFORM_SIMPLE ("/sizing", test_preferred_size);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user