summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorYeongjong Lee <yj34.lee@samsung.com>2019-03-20 10:28:45 -0400
committerMike Blumenkrantz <zmike@samsung.com>2019-03-20 10:37:42 -0400
commit77f2782d29eb7b51340ff47292afc018978cde84 (patch)
treeed3ed7dae56226d9f595c82582cb1aa878e5707a /src/tests
parente80169a844aaf9cf2f75a814c7561abd9a7bdd25 (diff)
ui.box_stack: refactor layout_update
Summary: This patch remove evas_box function from Efl.Ui.Box_Stack and add unit test. Depends on D8214 Test Plan: 1. make check 2. elementary_test -to 'efl.ui.box_stack' Reviewers: zmike, Jaehyun_Cho, cedric Reviewed By: zmike, Jaehyun_Cho, cedric Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8094
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/elementary/efl_ui_suite.c1
-rw-r--r--src/tests/elementary/efl_ui_suite.h1
-rw-r--r--src/tests/elementary/efl_ui_test_box_stack.c244
-rw-r--r--src/tests/elementary/meson.build1
4 files changed, 247 insertions, 0 deletions
diff --git a/src/tests/elementary/efl_ui_suite.c b/src/tests/elementary/efl_ui_suite.c
index 5783c203ce..097f432e8a 100644
--- a/src/tests/elementary/efl_ui_suite.c
+++ b/src/tests/elementary/efl_ui_suite.c
@@ -14,6 +14,7 @@ static const Efl_Test_Case etc[] = {
14 { "efl_ui_focus_sub", efl_ui_test_focus_sub}, 14 { "efl_ui_focus_sub", efl_ui_test_focus_sub},
15 { "efl_ui_box", efl_ui_test_box}, 15 { "efl_ui_box", efl_ui_test_box},
16 { "efl_ui_box_flow", efl_ui_test_box_flow}, 16 { "efl_ui_box_flow", efl_ui_test_box_flow},
17 { "efl_ui_box_stack", efl_ui_test_box_stack},
17 { "efl_ui_table", efl_ui_test_table}, 18 { "efl_ui_table", efl_ui_test_table},
18 { "efl_ui_grid", efl_ui_test_grid}, 19 { "efl_ui_grid", efl_ui_test_grid},
19 { "efl_ui_relative_layout", efl_ui_test_relative_layout}, 20 { "efl_ui_relative_layout", efl_ui_test_relative_layout},
diff --git a/src/tests/elementary/efl_ui_suite.h b/src/tests/elementary/efl_ui_suite.h
index 1f393828f4..3755a0e56f 100644
--- a/src/tests/elementary/efl_ui_suite.h
+++ b/src/tests/elementary/efl_ui_suite.h
@@ -21,6 +21,7 @@
21 21
22void efl_ui_test_box(TCase *tc); 22void efl_ui_test_box(TCase *tc);
23void efl_ui_test_box_flow(TCase *tc); 23void efl_ui_test_box_flow(TCase *tc);
24void efl_ui_test_box_stack(TCase *tc);
24void efl_ui_test_table(TCase *tc); 25void efl_ui_test_table(TCase *tc);
25void efl_ui_test_grid(TCase *tc); 26void efl_ui_test_grid(TCase *tc);
26void efl_ui_test_relative_layout(TCase *tc); 27void efl_ui_test_relative_layout(TCase *tc);
diff --git a/src/tests/elementary/efl_ui_test_box_stack.c b/src/tests/elementary/efl_ui_test_box_stack.c
new file mode 100644
index 0000000000..dccbe1fa2c
--- /dev/null
+++ b/src/tests/elementary/efl_ui_test_box_stack.c
@@ -0,0 +1,244 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include <Efl_Ui.h>
6#include "elm_suite.h"
7
8#define COORD_EQ(a, b) (!!(abs(a - b) < 2))
9#define GEOMETRY_EQ(a, b) (COORD_EQ(a.x, b.x) && COORD_EQ(a.y, b.y) && \
10 COORD_EQ(a.w, b.w) && COORD_EQ(a.h, b.h))
11
12typedef struct {
13 Eina_Size2D max;
14 Eina_Size2D min;
15 double weightx;
16 double weighty;
17 double alignx;
18 double aligny;
19 int marginl;
20 int marginr;
21 int margint;
22 int marginb;
23 Efl_Gfx_Hint_Aspect mode;
24 Eina_Size2D aspect;
25 Eina_Bool fillx;
26 Eina_Bool filly;
27 Eina_Size2D layout_size;
28 Eina_Size2D layout_expected;
29 Eina_Rect expected;
30 char testname[1024];
31} Hint;
32
33static Hint hints[] = {
34 { EINA_SIZE2D(-1, -1), EINA_SIZE2D(0, 0), 1, 1, 0.5, 0.5, 0, 0, 0, 0,
35 EFL_GFX_HINT_ASPECT_NONE, EINA_SIZE2D(0, 0), EINA_TRUE, EINA_TRUE,
36 EINA_SIZE2D(200, 200), EINA_SIZE2D(200, 200),
37 EINA_RECT(0, 0, 200, 200), "[0]" },
38 { EINA_SIZE2D(-1, -1), EINA_SIZE2D(70, 70), 1, 1, 0.3, 0.5, 0, 0, 0, 0,
39 EFL_GFX_HINT_ASPECT_NONE, EINA_SIZE2D(0, 0), EINA_TRUE, EINA_TRUE,
40 EINA_SIZE2D(200, 200), EINA_SIZE2D(200, 200),
41 EINA_RECT(0, 0, 200, 200), "[1]" },
42 { EINA_SIZE2D(50, 150), EINA_SIZE2D(70, 70), 1, 1, 0.3, 0.7, 0, 0, 0, 0,
43 EFL_GFX_HINT_ASPECT_NONE, EINA_SIZE2D(0, 0), EINA_TRUE, EINA_TRUE,
44 EINA_SIZE2D(200, 200), EINA_SIZE2D(200, 200),
45 EINA_RECT((200 - 70) * 0.3, (200 - 150) * 0.7, 70, 150), "[2]" },
46 { EINA_SIZE2D(150, -1), EINA_SIZE2D(70, 70), 0, 0, 0.3, 0.7, 0, 0, 0, 0,
47 EFL_GFX_HINT_ASPECT_NONE, EINA_SIZE2D(0, 0), EINA_FALSE, EINA_FALSE,
48 EINA_SIZE2D(200, 200), EINA_SIZE2D(200, 200),
49 EINA_RECT((200 - 70) * 0.3, (200 - 70) * 0.7, 70, 70), "[3]" },
50 { EINA_SIZE2D(-1, -1), EINA_SIZE2D(70, 70), 1, 0, 0.3, 0.7, 0, 0, 0, 0,
51 EFL_GFX_HINT_ASPECT_NONE, EINA_SIZE2D(0, 0), EINA_FALSE, EINA_TRUE,
52 EINA_SIZE2D(200, 200), EINA_SIZE2D(200, 200),
53 EINA_RECT((200 - 70) * 0.3, (200 - 70) * 0.7, 70, 70), "[4]" },
54 { EINA_SIZE2D(150, 150), EINA_SIZE2D(70, 70), 1, 0, 0.3, 0.7, 0, 0, 0, 0,
55 EFL_GFX_HINT_ASPECT_NONE, EINA_SIZE2D(0, 0), EINA_FALSE, EINA_TRUE,
56 EINA_SIZE2D(200, 200), EINA_SIZE2D(200, 200),
57 EINA_RECT((200 - 70) * 0.3, (200 - 70) * 0.7, 70, 70), "[5]" },
58 { EINA_SIZE2D(-1, -1), EINA_SIZE2D(70, 70), 0, 1, 0.3, 0.7, 0, 0, 0, 0,
59 EFL_GFX_HINT_ASPECT_BOTH, EINA_SIZE2D(1, 3), EINA_TRUE, EINA_FALSE,
60 EINA_SIZE2D(200, 200), EINA_SIZE2D(200, 210),
61 EINA_RECT((200 - 70) * 0.3, 0, 70, 70 * 3), "[6]" },
62 { EINA_SIZE2D(-1, -1), EINA_SIZE2D(70, 70), 0, 1, 0.3, 0.7, 0, 0, 0, 0,
63 EFL_GFX_HINT_ASPECT_BOTH, EINA_SIZE2D(1, 3), EINA_TRUE, EINA_FALSE,
64 EINA_SIZE2D(300, 300), EINA_SIZE2D(300, 300),
65 EINA_RECT((300 - 70) * 0.3, (300 - 70 * 3) * 0.7, 70, 70 * 3), "[7]" },
66 { EINA_SIZE2D(-1, -1), EINA_SIZE2D(70, 70), 1, 0, 0.3, 0.7, 0, 0, 0, 0,
67 EFL_GFX_HINT_ASPECT_BOTH, EINA_SIZE2D(1, 3), EINA_TRUE, EINA_FALSE,
68 EINA_SIZE2D(200, 200), EINA_SIZE2D(200, 210),
69 EINA_RECT((200 - 70) * 0.3, 0, 70, 70 * 3), "[8]" },
70 { EINA_SIZE2D(-1, -1), EINA_SIZE2D(70, 70), 1, 0, 0.3, 0.7, 0, 0, 0, 0,
71 EFL_GFX_HINT_ASPECT_BOTH, EINA_SIZE2D(1, 3), EINA_TRUE, EINA_FALSE,
72 EINA_SIZE2D(300, 300), EINA_SIZE2D(300, 300),
73 EINA_RECT((300 - 70) * 0.3, (300 - 70 * 3) * 0.7, 70, 70 * 3), "[9]" },
74 { EINA_SIZE2D(-1, 150), EINA_SIZE2D(70, 70), 0, 1, 0.3, 0.7, 0, 0, 0, 0,
75 EFL_GFX_HINT_ASPECT_BOTH, EINA_SIZE2D(1, 3), EINA_TRUE, EINA_FALSE,
76 EINA_SIZE2D(200, 200), EINA_SIZE2D(200, 210),
77 EINA_RECT((200 - 70) * 0.3, 0, 70, 70 * 3), "[10]" },
78 { EINA_SIZE2D(-1, 150), EINA_SIZE2D(70, 70), 0, 1, 0.3, 0.7, 0, 0, 0, 0,
79 EFL_GFX_HINT_ASPECT_BOTH, EINA_SIZE2D(1, 3), EINA_TRUE, EINA_FALSE,
80 EINA_SIZE2D(300, 300), EINA_SIZE2D(300, 300),
81 EINA_RECT((300 - 70) * 0.3, (300 - 70 * 3) * 0.7, 70, 70 * 3), "[11]" },
82 { EINA_SIZE2D(-1, 150), EINA_SIZE2D(70, 70), 1, 0, 0.3, 0.7, 0, 0, 0, 0,
83 EFL_GFX_HINT_ASPECT_BOTH, EINA_SIZE2D(1, 3), EINA_TRUE, EINA_FALSE,
84 EINA_SIZE2D(200, 200), EINA_SIZE2D(200, 210),
85 EINA_RECT((200 - 70) * 0.3, 0, 70, 70 * 3), "[12]" },
86 { EINA_SIZE2D(-1, 150), EINA_SIZE2D(70, 70), 1, 0, 0.3, 0.7, 0, 0, 0, 0,
87 EFL_GFX_HINT_ASPECT_BOTH, EINA_SIZE2D(1, 3), EINA_TRUE, EINA_FALSE,
88 EINA_SIZE2D(300, 300), EINA_SIZE2D(300, 300),
89 EINA_RECT((300 - 70) * 0.3, (300 - 70 * 3) * 0.7, 70, 70 * 3), "[13]" },
90};
91
92static Eo *win, *layout;
93
94static void
95btn_hint_set(Eo *btn, Hint *hint)
96{
97 efl_gfx_entity_size_set(layout, hint->layout_size);
98 efl_gfx_hint_size_max_set(btn, hint->max);
99 efl_gfx_hint_size_min_set(btn, hint->min);
100 efl_gfx_hint_margin_set(btn, hint->marginl, hint->marginr, hint->margint,
101 hint->marginb);
102 efl_gfx_hint_weight_set(btn, hint->weightx, hint->weighty);
103 efl_gfx_hint_align_set(btn, hint->alignx, hint->aligny);
104 efl_gfx_hint_fill_set(btn, hint->fillx, hint->filly);
105 efl_gfx_hint_aspect_set(btn, hint->mode, hint->aspect);
106 efl_canvas_group_calculate(layout);
107}
108
109static void
110btn_geom_assert(Hint *hint, Eina_Rect btn_geom)
111{
112 Eina_Size2D layout_size, layout_min;
113
114 layout_size = efl_gfx_entity_size_get(layout);
115 layout_min = efl_gfx_hint_size_combined_min_get(layout);
116 layout_size.w = layout_size.w > layout_min.w ? layout_size.w : layout_min.w;
117 layout_size.h = layout_size.h > layout_min.h ? layout_size.h : layout_min.h;
118
119 ck_assert_msg(GEOMETRY_EQ(btn_geom, hint->expected),
120 "Case %s failed... button geometry: (%d, %d, %d, %d) expected geometry: (%d, %d, %d, %d)",
121 hint->testname, btn_geom.x, btn_geom.y, btn_geom.w, btn_geom.h,
122 hint->expected.x, hint->expected.y, hint->expected.w, hint->expected.h);
123 ck_assert_msg(COORD_EQ(layout_size.w, hint->layout_expected.w) &&
124 COORD_EQ(layout_size.h, hint->layout_expected.h),
125 "Case %s failed... layout size: (%d, %d) expected size: (%d, %d)",
126 hint->testname, layout_size.w, layout_size.h,
127 hint->layout_expected.w, hint->layout_expected.h);
128}
129
130static void
131layout_setup()
132{
133 win = win_add();
134
135 layout = efl_add(EFL_UI_BOX_STACK_CLASS, win,
136 efl_pack_align_set(efl_added, 0.8, 0.2),
137 efl_ui_direction_set(efl_added, EFL_UI_DIR_VERTICAL));
138}
139
140static void
141layout_teardown()
142{
143 if (win)
144 {
145 efl_del(win);
146 win = NULL;
147 }
148}
149
150EFL_START_TEST (efl_ui_box_stack_class_check)
151{
152 const char *class;
153
154 class = efl_class_name_get(layout);
155
156 ck_assert(class != NULL);
157 ck_assert(!strcmp(class, "Efl.Ui.Box_Stack"));
158}
159EFL_END_TEST
160
161EFL_START_TEST (efl_ui_box_stack_layout_update)
162{
163 int i, max_index = (sizeof(hints) / sizeof(Hint));
164
165 Eo *btn = efl_add(EFL_UI_BUTTON_CLASS, layout,
166 efl_pack_end(layout, efl_added));
167
168 for (i = 0; i < max_index; i++)
169 {
170 btn_hint_set(btn, &hints[i]);
171 btn_geom_assert(&hints[i], efl_gfx_entity_geometry_get(btn));
172 }
173}
174EFL_END_TEST
175
176EFL_START_TEST (efl_ui_box_stack_size)
177{
178#define USERMIN_CHECK(a, b) \
179 efl_canvas_group_calculate(layout); \
180 user_min = efl_gfx_hint_size_min_get(layout); \
181 ck_assert_msg(COORD_EQ(user_min.w, (a)) && COORD_EQ(user_min.h, (b)), \
182 "Case box_size failed... user_min: (%d, %d) expected user_min: (%d, %d)", \
183 user_min.w, user_min.h, (a), (b));
184
185#define MIN_CHECK(a, b) \
186 efl_canvas_group_calculate(layout); \
187 min = efl_gfx_hint_size_combined_min_get(layout); \
188 ck_assert_msg(COORD_EQ(min.w, (a)) && COORD_EQ(min.h, (b)), \
189 "Case box_size failed... min: (%d, %d) expected min: (%d, %d)", \
190 min.w, min.h, (a), (b));
191
192 Eo *btn, *btn2, *btn3;
193 Eina_Size2D min, user_min;
194
195 btn = efl_add(EFL_UI_BUTTON_CLASS, layout,
196 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(100, 100)),
197 efl_pack_end(layout, efl_added));
198
199 USERMIN_CHECK(0, 0);
200 MIN_CHECK(100, 100);
201
202 btn2 = efl_add(EFL_UI_BUTTON_CLASS, layout,
203 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(300, 300)),
204 efl_pack_end(layout, efl_added));
205 btn3 = efl_add(EFL_UI_BUTTON_CLASS, layout,
206 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(200, 200)),
207 efl_pack_end(layout, efl_added));
208 USERMIN_CHECK(0, 0);
209 MIN_CHECK(300, 300);
210
211 efl_pack_unpack(layout, btn2);
212 USERMIN_CHECK(0, 0);
213 MIN_CHECK(200, 200);
214
215 efl_pack_unpack(layout, btn3);
216 USERMIN_CHECK(0, 0);
217 MIN_CHECK(100, 100);
218
219 efl_pack_unpack(layout, btn);
220 USERMIN_CHECK(0, 0);
221 MIN_CHECK(0, 0);
222
223 efl_pack_end(layout, btn);
224 efl_gfx_hint_size_min_set(layout, EINA_SIZE2D(200, 200));
225 USERMIN_CHECK(200, 200);
226 MIN_CHECK(200, 200);
227
228 efl_pack_end(layout, btn2);
229 efl_pack_end(layout, btn3);
230 USERMIN_CHECK(200, 200);
231 MIN_CHECK(300, 300);
232
233#undef USERMIN_ASSERT
234#undef MIN_ASSERT
235}
236EFL_END_TEST
237
238void efl_ui_test_box_stack(TCase *tc)
239{
240 tcase_add_checked_fixture(tc, layout_setup, layout_teardown);
241 tcase_add_test(tc, efl_ui_box_stack_class_check);
242 tcase_add_test(tc, efl_ui_box_stack_layout_update);
243 tcase_add_test(tc, efl_ui_box_stack_size);
244}
diff --git a/src/tests/elementary/meson.build b/src/tests/elementary/meson.build
index 5ffbf96789..987913aef2 100644
--- a/src/tests/elementary/meson.build
+++ b/src/tests/elementary/meson.build
@@ -126,6 +126,7 @@ efl_ui_suite_src = [
126 'efl_ui_test_focus_sub.c', 126 'efl_ui_test_focus_sub.c',
127 'efl_ui_test_box.c', 127 'efl_ui_test_box.c',
128 'efl_ui_test_box_flow.c', 128 'efl_ui_test_box_flow.c',
129 'efl_ui_test_box_stack.c',
129 'efl_ui_test_table.c', 130 'efl_ui_test_table.c',
130 'efl_ui_test_grid.c', 131 'efl_ui_test_grid.c',
131 'efl_ui_test_relative_layout.c', 132 'efl_ui_test_relative_layout.c',