4 #include <clutter/clutter.h>
6 #include "test-conform-common.h"
8 #define TEST_TYPE_ACTOR (test_actor_get_type ())
10 typedef struct _TestActor TestActor;
11 typedef struct _ClutterActorClass TestActorClass;
15 ClutterActor parent_instance;
17 guint preferred_width_called : 1;
18 guint preferred_height_called : 1;
21 G_DEFINE_TYPE (TestActor, test_actor, CLUTTER_TYPE_ACTOR);
24 test_actor_get_preferred_width (ClutterActor *self,
29 TestActor *test = (TestActor *) self;
31 test->preferred_width_called = TRUE;
46 test_actor_get_preferred_height (ClutterActor *self,
51 TestActor *test = (TestActor *) self;
53 test->preferred_height_called = TRUE;
68 test_actor_class_init (TestActorClass *klass)
70 ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
72 actor_class->get_preferred_width = test_actor_get_preferred_width;
73 actor_class->get_preferred_height = test_actor_get_preferred_height;
77 test_actor_init (TestActor *self)
82 actor_preferred_size (void)
86 gfloat min_width, min_height;
87 gfloat nat_width, nat_height;
89 test = g_object_new (TEST_TYPE_ACTOR, NULL);
90 self = (TestActor *) test;
92 if (g_test_verbose ())
93 g_print ("Preferred size\n");
95 clutter_actor_get_preferred_size (test,
96 &min_width, &min_height,
97 &nat_width, &nat_height);
99 g_assert (self->preferred_width_called);
100 g_assert (self->preferred_height_called);
101 g_assert_cmpfloat (min_width, ==, 100);
102 g_assert_cmpfloat (min_height, ==, 100);
103 g_assert_cmpfloat (nat_width, ==, min_width);
104 g_assert_cmpfloat (nat_height, ==, min_height);
106 if (g_test_verbose ())
107 g_print ("Preferred width\n");
108 self->preferred_width_called = FALSE;
109 clutter_actor_get_preferred_width (test, 10, &min_width, &nat_width);
110 g_assert (self->preferred_width_called);
111 g_assert_cmpfloat (min_width, ==, 10);
112 g_assert_cmpfloat (nat_width, ==, 100);
114 if (g_test_verbose ())
115 g_print ("Preferred height\n");
116 self->preferred_height_called = FALSE;
117 clutter_actor_get_preferred_height (test, 200, &min_height, &nat_height);
118 g_assert (self->preferred_height_called);
119 g_assert_cmpfloat (min_height, !=, 10);
120 g_assert_cmpfloat (nat_height, ==, 100);
122 if (g_test_verbose ())
123 g_print ("Preferred width (cached)\n");
124 self->preferred_width_called = FALSE;
125 clutter_actor_get_preferred_width (test, 10, &min_width, &nat_width);
126 g_assert (!self->preferred_width_called);
127 g_assert_cmpfloat (min_width, ==, 10);
128 g_assert_cmpfloat (nat_width, ==, 100);
130 if (g_test_verbose ())
131 g_print ("Preferred height (cache eviction)\n");
132 self->preferred_height_called = FALSE;
133 clutter_actor_get_preferred_height (test, 10, &min_height, &nat_height);
134 g_assert (self->preferred_height_called);
135 g_assert_cmpfloat (min_height, ==, 50);
136 g_assert_cmpfloat (nat_height, ==, 100);
138 clutter_actor_destroy (test);
142 actor_fixed_size (void)
145 gboolean min_width_set, nat_width_set;
146 gboolean min_height_set, nat_height_set;
147 gfloat min_width, min_height;
148 gfloat nat_width, nat_height;
150 rect = clutter_actor_new ();
151 g_object_ref_sink (rect);
153 if (g_test_verbose ())
154 g_print ("Initial size is 0\n");
156 g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 0);
157 g_assert_cmpfloat (clutter_actor_get_height (rect), ==, 0);
159 clutter_actor_set_size (rect, 100, 100);
161 if (g_test_verbose ())
162 g_print ("Explicit size set\n");
164 g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 100);
165 g_assert_cmpfloat (clutter_actor_get_height (rect), ==, 100);
167 g_object_get (G_OBJECT (rect),
168 "min-width-set", &min_width_set,
169 "min-height-set", &min_height_set,
170 "natural-width-set", &nat_width_set,
171 "natural-height-set", &nat_height_set,
174 if (g_test_verbose ())
175 g_print ("Notification properties\n");
177 g_assert (min_width_set && nat_width_set);
178 g_assert (min_height_set && nat_height_set);
180 clutter_actor_get_preferred_size (rect,
181 &min_width, &min_height,
182 &nat_width, &nat_height);
184 if (g_test_verbose ())
185 g_print ("Preferred size\n");
187 g_assert_cmpfloat (min_width, ==, 100);
188 g_assert_cmpfloat (min_height, ==, 100);
189 g_assert_cmpfloat (min_width, ==, nat_width);
190 g_assert_cmpfloat (min_height, ==, nat_height);
192 clutter_actor_set_size (rect, -1, -1);
194 if (g_test_verbose ())
195 g_print ("Explicit size unset\n");
197 g_object_get (G_OBJECT (rect),
198 "min-width-set", &min_width_set,
199 "min-height-set", &min_height_set,
200 "natural-width-set", &nat_width_set,
201 "natural-height-set", &nat_height_set,
203 g_assert (!min_width_set && !nat_width_set);
204 g_assert (!min_height_set && !nat_height_set);
206 g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 0);
207 g_assert_cmpfloat (clutter_actor_get_height (rect), ==, 0);
209 clutter_actor_destroy (rect);
210 g_object_unref (rect);