summaryrefslogtreecommitdiff
path: root/src/tests/elementary/spec/efl_test_pack_linear.c
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-03-29 08:14:05 +0100
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-04-17 15:21:11 +0200
commit6440e509a0e94c14aa9e18740cdb09466280b17e (patch)
treed46f3796162d1090f5d3cbc79fe7c5749f22e089 /src/tests/elementary/spec/efl_test_pack_linear.c
parentb0549bb8cccead28182ed89dd63598e547032075 (diff)
elm: here comes a new testsuite
We have two elementary test suite, what is more obvious than just adding a third one! This testsuite aims for establishing a standard behaviour for the interfaces we have added in efl now. This first part here brings a few testcases for Efl.Pack which are currently only passing for Efl.Ui.Box. More widgets will be added afterwards. The testcases themself are not defined after what worked or did not work, but rather what made sence (in my opinion ^_^). ref T7767 Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Differential Revision: https://phab.enlightenment.org/D8518
Diffstat (limited to 'src/tests/elementary/spec/efl_test_pack_linear.c')
-rw-r--r--src/tests/elementary/spec/efl_test_pack_linear.c396
1 files changed, 396 insertions, 0 deletions
diff --git a/src/tests/elementary/spec/efl_test_pack_linear.c b/src/tests/elementary/spec/efl_test_pack_linear.c
new file mode 100644
index 0000000000..cf85f9192b
--- /dev/null
+++ b/src/tests/elementary/spec/efl_test_pack_linear.c
@@ -0,0 +1,396 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include <Efl_Ui.h>
6#include "efl_ui_spec_suite.h"
7#include "suite_helpers.h"
8#include <limits.h>
9
10static void
11_fill_array(Efl_Ui_Widget *wid[3])
12{
13 for (int i = 0; i < 3; ++i)
14 {
15 wid[i] = efl_add(WIDGET_CLASS, win);
16 }
17}
18
19static void
20_ordering_equals(Efl_Ui_Widget **wid, unsigned int len)
21{
22 for (unsigned int i = 0; i < len; ++i)
23 {
24 ck_assert_ptr_eq(efl_pack_content_get(widget, i), wid[i]);
25 }
26 efl_test_container_content_equal(wid, len);
27}
28
29EFL_START_TEST(pack_begin1)
30{
31 Efl_Ui_Widget *wid[3];
32 Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win);
33
34 _fill_array(wid);
35
36 for (int i = 2; i >= 0; i--)
37 {
38 efl_pack_begin(widget, wid[i]);
39 ck_assert_ptr_eq(efl_ui_widget_parent_get(wid[i]), widget);
40 }
41 _ordering_equals(wid, 3);
42 efl_pack_begin(widget, inv);
43 ck_assert_ptr_eq(efl_pack_content_get(widget, 0), inv);
44 Efl_Ui_Widget *wid2[] = {inv, wid[0], wid[1], wid[2]};
45 _ordering_equals(wid2, 4);
46}
47EFL_END_TEST
48
49EFL_START_TEST(pack_begin2)
50{
51 Efl_Ui_Widget *wid[3];
52
53 _fill_array(wid);
54
55 for (int i = 2; i >= 0; i--)
56 {
57 efl_pack_begin(widget, wid[i]);
58 ck_assert_ptr_eq(efl_ui_widget_parent_get(wid[i]), widget);
59 }
60
61 EXPECT_ERROR_START;
62 ck_assert_int_eq(efl_pack_begin(widget, wid[0]), EINA_FALSE);
63 EXPECT_ERROR_END;
64 _ordering_equals(wid, 3);
65}
66EFL_END_TEST
67
68EFL_START_TEST(pack_end1)
69{
70 Efl_Ui_Widget *wid[3];
71 Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win);
72
73 _fill_array(wid);
74
75 for (int i = 0; i < 3; i++)
76 {
77 efl_pack_end(widget, wid[i]);
78 ck_assert_ptr_eq(efl_ui_widget_parent_get(wid[i]), widget);
79 }
80
81 _ordering_equals(wid, 3);
82 efl_pack_end(widget, inv);
83 ck_assert_ptr_eq(efl_pack_content_get(widget, 3), inv);
84 Efl_Ui_Widget *wid2[] = {wid[0], wid[1], wid[2], inv};
85 _ordering_equals(wid2, 4);
86}
87EFL_END_TEST
88
89EFL_START_TEST(pack_end2)
90{
91 Efl_Ui_Widget *wid[3];
92
93 _fill_array(wid);
94
95 for (int i = 0; i < 3; i++)
96 {
97 efl_pack_end(widget, wid[i]);
98 ck_assert_ptr_eq(efl_ui_widget_parent_get(wid[i]), widget);
99 }
100
101 EXPECT_ERROR_START;
102 ck_assert_int_eq(efl_pack_end(widget, wid[0]), EINA_FALSE);
103 EXPECT_ERROR_END;
104 _ordering_equals(wid, 3);
105}
106EFL_END_TEST
107
108EFL_START_TEST(pack_before1)
109{
110 Efl_Ui_Widget *wid[3];
111 Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win);
112
113 _fill_array(wid);
114
115 for (int i = 0; i < 3; i++)
116 efl_pack_end(widget, wid[i]);
117
118 ck_assert_int_eq(efl_pack_before(widget, inv, wid[0]), EINA_TRUE);
119 ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget);
120 Efl_Ui_Widget *wid2[] = {inv, wid[0], wid[1], wid[2]};
121 _ordering_equals(wid2, 4);
122 efl_pack_unpack(widget, inv);
123
124 ck_assert_int_eq(efl_pack_before(widget, inv, wid[2]), EINA_TRUE);
125 ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget);
126 Efl_Ui_Widget *wid3[] = {wid[0], wid[1], inv, wid[2]};
127 _ordering_equals(wid3, 4);
128}
129EFL_END_TEST
130
131EFL_START_TEST(pack_before2)
132{
133 Efl_Ui_Widget *wid[3];
134 Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win);
135
136 _fill_array(wid);
137
138 for (int i = 0; i < 3; i++)
139 efl_pack_end(widget, wid[i]);
140
141 ck_assert_int_eq(efl_pack_before(widget, inv, wid[0]), EINA_TRUE);
142 ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget);
143 Efl_Ui_Widget *wid2[] = {inv, wid[0], wid[1], wid[2]};
144 _ordering_equals(wid2, 4);
145
146 EXPECT_ERROR_START;
147 ck_assert_int_eq(efl_pack_before(widget, inv, wid[2]), EINA_FALSE);
148 EXPECT_ERROR_END;
149}
150EFL_END_TEST
151
152EFL_START_TEST(pack_after1)
153{
154 Efl_Ui_Widget *wid[3];
155 Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win);
156
157 _fill_array(wid);
158
159 for (int i = 0; i < 3; i++)
160 efl_pack_end(widget, wid[i]);
161
162 ck_assert_int_eq(efl_pack_after(widget, inv, wid[0]), EINA_TRUE);
163 ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget);
164 Efl_Ui_Widget *wid2[] = {wid[0], inv, wid[1], wid[2]};
165 _ordering_equals(wid2, 4);
166 efl_pack_unpack(widget, inv);
167
168 ck_assert_int_eq(efl_pack_after(widget, inv, wid[2]), EINA_TRUE);
169 ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget);
170 Efl_Ui_Widget *wid3[] = {wid[0], wid[1], wid[2], inv};
171 _ordering_equals(wid3, 4);
172}
173EFL_END_TEST
174
175EFL_START_TEST(pack_after2)
176{
177 Efl_Ui_Widget *wid[3];
178 Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win);
179
180 _fill_array(wid);
181
182 for (int i = 0; i < 3; i++)
183 efl_pack_end(widget, wid[i]);
184
185 ck_assert_int_eq(efl_pack_after(widget, inv, wid[0]), EINA_TRUE);
186 ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget);
187 Efl_Ui_Widget *wid2[] = {wid[0], inv, wid[1], wid[2]};
188 _ordering_equals(wid2, 4);
189
190 EXPECT_ERROR_START;
191 ck_assert_int_eq(efl_pack_after(widget, inv, wid[2]), EINA_FALSE);
192 EXPECT_ERROR_END;
193}
194EFL_END_TEST
195
196EFL_START_TEST(pack_at1)
197{
198 for (int x = -3; x < 3; ++x)
199 {
200 Efl_Ui_Widget *wid[3];
201 Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win);
202 unsigned int i;
203
204 _fill_array(wid);
205 for (int i = 0; i < 3; i++)
206 efl_pack_end(widget, wid[i]);
207
208 efl_pack_at(widget, inv, x);
209 ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget);
210
211 for (i = 0; i < 4; ++i)
212 {
213 Efl_Ui_Widget *w = efl_pack_content_get(widget, i);
214 unsigned int place_to_expect_inv = (3 + x) % 3;
215 if (i == place_to_expect_inv)
216 ck_assert_ptr_eq(w, inv);
217 else if (i < place_to_expect_inv)
218 ck_assert_ptr_eq(w, wid[i]);
219 else if (i > place_to_expect_inv)
220 ck_assert_ptr_eq(w, wid[i - 1]);
221 }
222 efl_pack_clear(widget);
223 }
224}
225EFL_END_TEST
226
227EFL_START_TEST(pack_at2)
228{
229 for (int x = -3; x < 3; ++x)
230 {
231 Efl_Ui_Widget *wid[3];
232 Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win);
233 unsigned int i;
234
235 _fill_array(wid);
236 for (int i = 0; i < 3; i++)
237 efl_pack_end(widget, wid[i]);
238
239 ck_assert_int_eq(efl_pack_at(widget, inv, x), EINA_TRUE);
240 ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget);
241
242 EXPECT_ERROR_START;
243 ck_assert_int_eq(efl_pack_at(widget, inv, x - 1), EINA_FALSE);
244 EXPECT_ERROR_END;
245
246 for (i = 0; i < 4; ++i)
247 {
248 Efl_Ui_Widget *w = efl_pack_content_get(widget, i);
249 unsigned int place_to_expect_inv = (3 + x) % 3;
250 if (i == place_to_expect_inv)
251 ck_assert_ptr_eq(w, inv);
252 else if (i < place_to_expect_inv)
253 ck_assert_ptr_eq(w, wid[i]);
254 else if (i > place_to_expect_inv)
255 ck_assert_ptr_eq(w, wid[i - 1]);
256 }
257 efl_pack_clear(widget);
258 }
259}
260EFL_END_TEST
261
262
263EFL_START_TEST(pack_at3)
264{
265 Efl_Ui_Widget *wid[3];
266 Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win);
267 Efl_Ui_Widget *inv2 = efl_add(WIDGET_CLASS, win);
268
269 _fill_array(wid);
270 for (int i = 0; i < 3; i++)
271 efl_pack_end(widget, wid[i]);
272
273 ck_assert_int_eq(efl_pack_at(widget, inv,-100000), EINA_TRUE);
274 ck_assert_ptr_eq(efl_ui_widget_parent_get(inv), widget);
275 ck_assert_int_eq(efl_pack_at(widget, inv2, 100000), EINA_TRUE);
276 ck_assert_ptr_eq(efl_ui_widget_parent_get(inv2), widget);
277 Efl_Ui_Widget *wid2[] = {inv, wid[0], wid[1], wid[2], inv2};
278 _ordering_equals(wid2, 5);
279}
280EFL_END_TEST
281
282EFL_START_TEST(pack_content_get1)
283{
284 Efl_Ui_Widget *wid[3];
285
286 _fill_array(wid);
287
288 for (int i = 0; i < 3; i++)
289 efl_pack_end(widget, wid[i]);
290
291 for (int i = -100000; i <= 100000; i++)
292 {
293 if (i < -3)
294 ck_assert_ptr_eq(efl_pack_content_get(widget, i), efl_pack_content_get(widget, 0));
295 else if (i >= -3 && i < 3)
296 ck_assert_ptr_eq(efl_pack_content_get(widget, i), wid[(i + 3) % 3]);
297 else
298 ck_assert_ptr_eq(efl_pack_content_get(widget, i), efl_pack_content_get(widget, 2));
299 }
300}
301EFL_END_TEST
302
303EFL_START_TEST(pack_index_get1)
304{
305 Efl_Ui_Widget *wid[3];
306 Efl_Ui_Widget *inv = efl_add(WIDGET_CLASS, win);
307
308 _fill_array(wid);
309 for (int i = 0; i < 3; i++)
310 efl_pack_end(widget, wid[i]);
311 for (int i = 0; i < 3; i++)
312 ck_assert_int_eq(efl_pack_index_get(widget, wid[i]), i);
313
314 ck_assert_int_eq(efl_pack_index_get(widget, (void*)0xAFFE), -1);
315 ck_assert_int_eq(efl_pack_index_get(widget, inv), -1);
316}
317EFL_END_TEST
318
319EFL_START_TEST(pack_unpack_at1)
320{
321 Efl_Ui_Widget *wid[3];
322
323 _fill_array(wid);
324 for (int i = 0; i < 3; i++)
325 efl_pack_end(widget, wid[i]);
326 for (int i = 0; i < 3; i++)
327 ck_assert_int_eq(efl_pack_index_get(widget, wid[i]), i);
328
329 ck_assert_ptr_eq(efl_pack_unpack_at(widget, 1), wid[1]);
330 Efl_Ui_Widget *wid1[] = {wid[0], wid[2]};
331 _ordering_equals(wid1, 2);
332 ck_assert_ptr_eq(efl_pack_unpack_at(widget, 1), wid[2]);
333 Efl_Ui_Widget *wid2[] = {wid[0]};
334 _ordering_equals(wid2, 1);
335 ck_assert_ptr_eq(efl_pack_unpack_at(widget, 0), wid[0]);
336 Efl_Ui_Widget *wid3[] = {};
337 _ordering_equals(wid3, 0);
338}
339EFL_END_TEST
340
341
342EFL_START_TEST(pack_unpack_at2)
343{
344 Efl_Ui_Widget *wid[3];
345
346 _fill_array(wid);
347 for (int i = 0; i < 3; i++)
348 efl_pack_end(widget, wid[i]);
349 for (int i = 0; i < 3; i++)
350 ck_assert_int_eq(efl_pack_index_get(widget, wid[i]), i);
351
352 ck_assert_ptr_eq(efl_pack_unpack_at(widget, 1), wid[1]);
353 efl_del(widget);
354 ck_assert_int_eq(efl_ref_count(wid[1]), 1);
355 ck_assert_int_eq(efl_ref_count(widget), 0);
356}
357EFL_END_TEST
358
359EFL_START_TEST(pack_unpack_at3)
360{
361 for (int x = -3; x < 3; ++x)
362 {
363 Efl_Ui_Widget *wid[3];
364
365 _fill_array(wid);
366 for (int i = 0; i < 3; i++)
367 efl_pack_end(widget, wid[i]);
368 ck_assert_ptr_eq(efl_pack_unpack_at(widget, x), wid[(3+x)%3]);
369 ck_assert_int_eq(efl_content_count(widget), 2);
370 ck_assert_ptr_ne(efl_ui_widget_parent_get(wid[(3+x)%3]), widget);
371 efl_pack_unpack_all(widget);
372 }
373}
374EFL_END_TEST
375
376void
377efl_pack_linear_behavior_test(TCase *tc)
378{
379 tcase_add_test(tc, pack_begin1);
380 tcase_add_test(tc, pack_begin2);
381 tcase_add_test(tc, pack_end1);
382 tcase_add_test(tc, pack_end2);
383 tcase_add_test(tc, pack_before1);
384 tcase_add_test(tc, pack_before2);
385 tcase_add_test(tc, pack_after1);
386 tcase_add_test(tc, pack_after2);
387 tcase_add_test(tc, pack_at1);
388 tcase_add_test(tc, pack_at2);
389 tcase_add_test(tc, pack_at3);
390 tcase_add_test(tc, pack_content_get1);
391 tcase_add_test(tc, pack_index_get1);
392 tcase_add_test(tc, pack_unpack_at1);
393 tcase_add_test(tc, pack_unpack_at2);
394 tcase_add_test(tc, pack_unpack_at3);
395 efl_pack_behavior_test(tc);
396}