summaryrefslogtreecommitdiff
path: root/src/tests/elementary
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-05-29 13:03:37 +0200
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-06-20 16:02:00 +0200
commitc9177a9f8d75fc7bd2634a0adb63106492f3e94c (patch)
treec116e4c39d0f3f7d36233fdfc9b57dedc6b91441 /src/tests/elementary
parent42b293ae1f89aa3737fe7a4d81ebc3596fd2c631 (diff)
Introduce Efl.Ui.Radio_Group & Efl.Ui.Radio_Box
Radio_Group is a interface that manages that radio groups can be grouped inside a external object, the current API of radio was considered confusing in that regard. It is implemented in the Radio_Group_Internal class which is private to EFL, a instance of it can be found with get due to the class function in efl_ui_radio.eo. This architecture was taken like this, in order to have implementation and interface seperated. With those two seperated we can inherit from regular widgets, implement the interface, and composite attach the internal object to the regular widget. This makes a lot of things easier. Radio_Box is a class which is extending Efl.Ui.Box, which has an internal Radio_Group. This is extremly usefull for cases where you just want to have a list of radio buttons in your UI. The radio group is also exposed using composition to the internal object. Simular things can be done for the table. For now i did not add API to find the group of a radio button. However, this can be quickly added if requested. ref T7867 Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Reviewed-by: Xavi Artigas <xavierartigas@yahoo.es> Differential Revision: https://phab.enlightenment.org/D9058
Diffstat (limited to 'src/tests/elementary')
-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_radio_group.c266
-rw-r--r--src/tests/elementary/meson.build1
4 files changed, 269 insertions, 0 deletions
diff --git a/src/tests/elementary/efl_ui_suite.c b/src/tests/elementary/efl_ui_suite.c
index 6fab5d7003..66395696bc 100644
--- a/src/tests/elementary/efl_ui_suite.c
+++ b/src/tests/elementary/efl_ui_suite.c
@@ -27,6 +27,7 @@ static const Efl_Test_Case etc[] = {
27 { "efl_ui_widget", efl_ui_test_widget }, 27 { "efl_ui_widget", efl_ui_test_widget },
28 { "efl_ui_active_view", efl_ui_test_active_view}, 28 { "efl_ui_active_view", efl_ui_test_active_view},
29 { "efl_ui_check", efl_ui_test_check }, 29 { "efl_ui_check", efl_ui_test_check },
30 { "efl_ui_radio_group", efl_ui_test_radio_group },
30 { NULL, NULL } 31 { NULL, NULL }
31}; 32};
32 33
diff --git a/src/tests/elementary/efl_ui_suite.h b/src/tests/elementary/efl_ui_suite.h
index 472493818a..b5aec1b098 100644
--- a/src/tests/elementary/efl_ui_suite.h
+++ b/src/tests/elementary/efl_ui_suite.h
@@ -36,6 +36,7 @@ void efl_ui_model(TCase *tc);
36void efl_ui_test_widget(TCase *tc); 36void efl_ui_test_widget(TCase *tc);
37void efl_ui_test_active_view(TCase *tc); 37void efl_ui_test_active_view(TCase *tc);
38void efl_ui_test_check(TCase *tc); 38void efl_ui_test_check(TCase *tc);
39void efl_ui_test_radio_group(TCase *tc);
39 40
40void loop_timer_interval_set(Eo *obj, double in); 41void loop_timer_interval_set(Eo *obj, double in);
41 42
diff --git a/src/tests/elementary/efl_ui_test_radio_group.c b/src/tests/elementary/efl_ui_test_radio_group.c
new file mode 100644
index 0000000000..4c515bf140
--- /dev/null
+++ b/src/tests/elementary/efl_ui_test_radio_group.c
@@ -0,0 +1,266 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include <Efl_Ui.h>
6#include "efl_ui_suite.h"
7#include "suite_helpers.h"
8
9static Eo *win, *radio_group;
10
11int state_values = 0;
12
13typedef struct {
14 int called;
15 int value;
16} Group_Changed_Called;
17
18Group_Changed_Called changed_evt;
19
20#define RESET_EVT \
21 changed_evt.called = 0; \
22 changed_evt.value = 200000000;
23
24#define EXPECT_EVT(c, v) \
25 ck_assert_int_eq(changed_evt.called, c); \
26 ck_assert_int_eq(changed_evt.value, v);
27
28static void
29_group_value_changed_cb(void *data EINA_UNUSED, const Efl_Event *ev)
30{
31 changed_evt.called ++;
32 changed_evt.value = *((int*)ev->info);
33}
34
35static void
36check_setup()
37{
38 win = win_add();
39 radio_group = efl_new(EFL_UI_RADIO_GROUP_IMPL_CLASS, NULL);
40 efl_event_callback_add(radio_group, EFL_UI_RADIO_GROUP_EVENT_VALUE_CHANGED, _group_value_changed_cb, NULL);
41}
42
43static void
44check_teardown()
45{
46 efl_unref(radio_group);
47 if (win)
48 {
49 efl_del(win);
50 win = NULL;
51 }
52}
53
54static Eo*
55radio(void)
56{
57 state_values += 1;
58 return efl_add(EFL_UI_RADIO_CLASS, win, efl_ui_radio_state_value_set(efl_added, state_values));
59}
60
61EFL_START_TEST(active_selected_value_setting)
62{
63 Eo *r1 = radio();
64 Eo *r2 = radio();
65
66 efl_ui_radio_group_register(radio_group, radio());
67 efl_ui_radio_group_register(radio_group, radio());
68 efl_ui_radio_group_register(radio_group, r1);
69 efl_ui_radio_group_register(radio_group, r2);
70
71 ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), -1);
72 ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), NULL);
73
74 RESET_EVT
75 efl_ui_radio_group_selected_value_set(radio_group, 1);
76 ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 1);
77 ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), r1);
78 ck_assert_int_eq(efl_ui_check_selected_get(r1), EINA_TRUE);
79 ck_assert_int_eq(efl_ui_check_selected_get(r2), EINA_FALSE);
80 EXPECT_EVT(1,1);
81
82 RESET_EVT
83 efl_ui_radio_group_selected_object_set(radio_group, r2);
84 ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 2);
85 ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), r2);
86 ck_assert_int_eq(efl_ui_check_selected_get(r1), EINA_FALSE);
87 ck_assert_int_eq(efl_ui_check_selected_get(r2), EINA_TRUE);
88 EXPECT_EVT(1,2);
89}
90EFL_END_TEST
91
92EFL_START_TEST(active_selection_setting)
93{
94 Eo *r1 = radio();
95 Eo *r2 = radio();
96
97 efl_ui_radio_group_register(radio_group, radio());
98 efl_ui_radio_group_register(radio_group, radio());
99 efl_ui_radio_group_register(radio_group, r1);
100 efl_ui_radio_group_register(radio_group, r2);
101
102 ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), -1);
103 ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), NULL);
104
105 RESET_EVT
106 efl_ui_radio_group_selected_object_set(radio_group, r1);
107 ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 1);
108 ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), r1);
109 ck_assert_int_eq(efl_ui_check_selected_get(r1), EINA_TRUE);
110 ck_assert_int_eq(efl_ui_check_selected_get(r2), EINA_FALSE);
111 EXPECT_EVT(1,1);
112
113 RESET_EVT
114 efl_ui_radio_group_selected_object_set(radio_group, r2);
115 ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 2);
116 ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), r2);
117 ck_assert_int_eq(efl_ui_check_selected_get(r1), EINA_FALSE);
118 ck_assert_int_eq(efl_ui_check_selected_get(r2), EINA_TRUE);
119 EXPECT_EVT(1,2);
120}
121EFL_END_TEST
122
123EFL_START_TEST(active_selection_object_setting)
124{
125 Eo *r = radio();
126 efl_ui_radio_group_register(radio_group, radio());
127 efl_ui_radio_group_register(radio_group, radio());
128 efl_ui_radio_group_register(radio_group, r);
129 efl_ui_radio_group_register(radio_group, radio());
130
131 RESET_EVT
132 ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), -1);
133 ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), NULL);
134 efl_ui_check_selected_set(r, EINA_TRUE);
135 ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 1);
136 ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), r);
137 EXPECT_EVT(1,1);
138}
139EFL_END_TEST
140
141EFL_START_TEST(unregister_setted)
142{
143 Eo *r = radio();
144 efl_ui_radio_group_register(radio_group, radio());
145 efl_ui_radio_group_register(radio_group, radio());
146 efl_ui_radio_group_register(radio_group, r);
147 efl_ui_radio_group_register(radio_group, radio());
148
149 RESET_EVT
150 efl_ui_radio_group_selected_object_set(radio_group, r);
151 ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 1);
152 ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), r);
153 EXPECT_EVT(1,1);
154 RESET_EVT
155 efl_ui_radio_group_unregister(radio_group, r);
156 ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), -1);
157 ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), NULL);
158 EXPECT_EVT(1,-1);
159}
160EFL_END_TEST
161
162EFL_START_TEST(delete_setted)
163{
164 Eo *r = radio();
165 efl_ui_radio_group_register(radio_group, radio());
166 efl_ui_radio_group_register(radio_group, radio());
167 efl_ui_radio_group_register(radio_group, r);
168 efl_ui_radio_group_register(radio_group, radio());
169 RESET_EVT
170 efl_ui_radio_group_selected_object_set(radio_group, r);
171 ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 1);
172 ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), r);
173 EXPECT_EVT(1,1);
174 RESET_EVT
175 efl_del(r);
176 ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), -1);
177 ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), NULL);
178 EXPECT_EVT(1,-1);
179}
180EFL_END_TEST
181
182EFL_START_TEST(external_setting)
183{
184 Eo *r = radio();
185 efl_ui_radio_group_register(radio_group, radio());
186 efl_ui_radio_group_register(radio_group, radio());
187 efl_ui_radio_group_register(radio_group, r);
188 efl_ui_radio_group_register(radio_group, radio());
189 RESET_EVT
190 efl_ui_check_selected_set(r, EINA_TRUE);
191 ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 1);
192 ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), r);
193 EXPECT_EVT(1,1);
194 RESET_EVT
195 efl_ui_check_selected_set(r, EINA_FALSE);
196 ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), -1);
197 ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), NULL);
198 EXPECT_EVT(1,-1);
199}
200EFL_END_TEST
201
202EFL_START_TEST(pairwise_different_error)
203{
204 Eo *r = radio();
205 Eo *r1 = radio();
206 Eo *r2 = radio();
207 efl_ui_radio_state_value_set(r, -1);
208 efl_ui_radio_state_value_set(r1, 14);
209 efl_ui_radio_state_value_set(r2, 14);
210 EXPECT_ERROR_START;
211 efl_ui_radio_group_register(radio_group, r);
212 EXPECT_ERROR_END;
213 efl_ui_radio_group_register(radio_group, r1);
214 EXPECT_ERROR_START;
215 efl_ui_radio_group_register(radio_group, r2);
216 EXPECT_ERROR_END;
217}
218EFL_END_TEST
219
220EFL_START_TEST(group_double_registeration)
221{
222 Eo *r = radio();
223 efl_ui_radio_group_register(radio_group, r);
224 EXPECT_ERROR_START;
225 efl_ui_radio_group_register(radio_group, r);
226 EXPECT_ERROR_END;
227}
228EFL_END_TEST
229
230EFL_START_TEST(group_registeration_in_two_groups)
231{
232 Eo *radio_group2 = efl_new(EFL_UI_RADIO_GROUP_IMPL_CLASS, NULL);
233 Eo *r = radio();
234 efl_ui_radio_group_register(radio_group, r);
235 EXPECT_ERROR_START;
236 efl_ui_radio_group_register(radio_group2, r);
237 EXPECT_ERROR_END;
238}
239EFL_END_TEST
240
241EFL_START_TEST(group_invalid_value)
242{
243 Eo *radio_group2 = efl_new(EFL_UI_RADIO_GROUP_IMPL_CLASS, NULL);
244 Eo *r = radio();
245 efl_ui_radio_group_register(radio_group, r);
246 EXPECT_ERROR_START;
247 efl_ui_radio_group_selected_value_set(radio_group2, 1000);
248 EXPECT_ERROR_END;
249}
250EFL_END_TEST
251
252void efl_ui_test_radio_group(TCase *tc)
253{
254 tcase_add_checked_fixture(tc, fail_on_errors_setup, fail_on_errors_teardown);
255 tcase_add_checked_fixture(tc, check_setup, check_teardown);
256 tcase_add_test(tc, active_selected_value_setting);
257 tcase_add_test(tc, active_selection_setting);
258 tcase_add_test(tc, active_selection_object_setting);
259 tcase_add_test(tc, pairwise_different_error);
260 tcase_add_test(tc, group_double_registeration);
261 tcase_add_test(tc, group_registeration_in_two_groups);
262 tcase_add_test(tc, unregister_setted);
263 tcase_add_test(tc, external_setting);
264 tcase_add_test(tc, delete_setted);
265 tcase_add_test(tc, group_invalid_value);
266}
diff --git a/src/tests/elementary/meson.build b/src/tests/elementary/meson.build
index 735ba0a829..43b3ca1cfe 100644
--- a/src/tests/elementary/meson.build
+++ b/src/tests/elementary/meson.build
@@ -140,6 +140,7 @@ efl_ui_suite_src = [
140 'efl_ui_test_widget.c', 140 'efl_ui_test_widget.c',
141 'efl_ui_test_active_view.c', 141 'efl_ui_test_active_view.c',
142 'efl_ui_test_check.c', 142 'efl_ui_test_check.c',
143 'efl_ui_test_radio_group.c',
143] 144]
144 145
145efl_ui_suite = executable('efl_ui_suite', 146efl_ui_suite = executable('efl_ui_suite',