Debian Codegraph @

tests/conform/actor-size.c

raw
1 #include <stdlib.h>
2 #include <string.h>
3
4 #include <clutter/clutter.h>
5
6 #define TEST_TYPE_ACTOR (test_actor_get_type ())
7
8 typedef struct _TestActor TestActor;
9 typedef struct _ClutterActorClass TestActorClass;
10
11 struct _TestActor
12 {
13 ClutterActor parent_instance;
14
15 guint preferred_width_called : 1;
16 guint preferred_height_called : 1;
17 };
18
19 GType test_actor_get_type (void);
20
21 G_DEFINE_TYPE (TestActor, test_actor, CLUTTER_TYPE_ACTOR);
22
23 static void
24 test_actor_get_preferred_width (ClutterActor *self,
25 gfloat for_height,
26 gfloat *min_width_p,
27 gfloat *nat_width_p)
28 {
29 TestActor *test = (TestActor *) self;
30
31 test->preferred_width_called = TRUE;
32
33 if (for_height == 10)
34 {
35 *min_width_p = 10;
36 *nat_width_p = 100;
37 }
38 else
39 {
40 *min_width_p = 100;
41 *nat_width_p = 100;
42 }
43 }
44
45 static void
46 test_actor_get_preferred_height (ClutterActor *self,
47 gfloat for_width,
48 gfloat *min_height_p,
49 gfloat *nat_height_p)
50 {
51 TestActor *test = (TestActor *) self;
52
53 test->preferred_height_called = TRUE;
54
55 if (for_width == 10)
56 {
57 *min_height_p = 50;
58 *nat_height_p = 100;
59 }
60 else
61 {
62 *min_height_p = 100;
63 *nat_height_p = 100;
64 }
65 }
66
67 static void
68 test_actor_class_init (TestActorClass *klass)
69 {
70 ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
71
72 actor_class->get_preferred_width = test_actor_get_preferred_width;
73 actor_class->get_preferred_height = test_actor_get_preferred_height;
74 }
75
76 static void
77 test_actor_init (TestActor *self)
78 {
79 }
80
81 static void
82 actor_preferred_size (void)
83 {
84 ClutterActor *test;
85 TestActor *self;
86 gfloat min_width, min_height;
87 gfloat nat_width, nat_height;
88
89 test = g_object_new (TEST_TYPE_ACTOR, NULL);
90 self = (TestActor *) test;
91
92 if (g_test_verbose ())
93 g_print ("Preferred size\n");
94
95 clutter_actor_get_preferred_size (test,
96 &min_width, &min_height,
97 &nat_width, &nat_height);
98
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);
105
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);
113
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);
121
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);
129
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);
137
138 clutter_actor_destroy (test);
139 }
140
141 static void
142 actor_fixed_size (void)
143 {
144 ClutterActor *rect;
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;
149
150 rect = clutter_actor_new ();
151 g_object_ref_sink (rect);
152
153 if (g_test_verbose ())
154 g_print ("Initial size is 0\n");
155
156 g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 0);
157 g_assert_cmpfloat (clutter_actor_get_height (rect), ==, 0);
158
159 clutter_actor_set_size (rect, 100, 100);
160
161 if (g_test_verbose ())
162 g_print ("Explicit size set\n");
163
164 g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 100);
165 g_assert_cmpfloat (clutter_actor_get_height (rect), ==, 100);
166
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,
172 NULL);
173
174 if (g_test_verbose ())
175 g_print ("Notification properties\n");
176
177 g_assert (min_width_set && nat_width_set);
178 g_assert (min_height_set && nat_height_set);
179
180 clutter_actor_get_preferred_size (rect,
181 &min_width, &min_height,
182 &nat_width, &nat_height);
183
184 if (g_test_verbose ())
185 g_print ("Preferred size\n");
186
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);
191
192 clutter_actor_set_size (rect, -1, -1);
193
194 if (g_test_verbose ())
195 g_print ("Explicit size unset\n");
196
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,
202 NULL);
203 g_assert (!min_width_set && !nat_width_set);
204 g_assert (!min_height_set && !nat_height_set);
205
206 g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 0);
207 g_assert_cmpfloat (clutter_actor_get_height (rect), ==, 0);
208
209 clutter_actor_destroy (rect);
210 g_object_unref (rect);
211 }
212
213 CLUTTER_TEST_SUITE (
214 CLUTTER_TEST_UNIT ("/actor/size/preferred", actor_preferred_size)
215 CLUTTER_TEST_UNIT ("/actor/size/fixed", actor_fixed_size)
216 )