summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-08-20 18:22:00 +0200
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-08-26 14:42:50 +0200
commit43edd17f41308ba3bf42b38f727aad76db87aa72 (patch)
tree57efe2129759f427e1adb21f60426e35c7a33eb7 /src/tests
parent1c1c3685fee081f314d4a77169435e9589436109 (diff)
efl_ui_single_selectable: add properties and events
this commit adds 2 new features, a new event and a new property The fallback property is usefull if you want to have a selection that always falls back to some preconfigured things. As a usecase, think about a list of languges where you can select the languages you want to have. When everything is deselected, the list will simply fallback to the preconfigured element (for example the language configured before) The event is annoncing that there was a change to the selection. The event is allowed to be defered, it will be emitted once for a range of selection elements that happened during one loop iteration. This is usefull if you are interested in a general selection where you want to know that we changed from a specific set of selected element to another set of elements, without monitoring every selectable in the widget. ref T8057 Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Reviewed-by: Cedric BAIL <cedric.bail@free.fr> Differential Revision: https://phab.enlightenment.org/D9662
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/elementary/spec/efl_test_multi_selectable.c126
-rw-r--r--src/tests/elementary/spec/efl_test_single_selectable.c25
2 files changed, 80 insertions, 71 deletions
diff --git a/src/tests/elementary/spec/efl_test_multi_selectable.c b/src/tests/elementary/spec/efl_test_multi_selectable.c
index 5d5c1ed824..da36e5b8f2 100644
--- a/src/tests/elementary/spec/efl_test_multi_selectable.c
+++ b/src/tests/elementary/spec/efl_test_multi_selectable.c
@@ -42,23 +42,22 @@ _iterator_to_array(Eina_Array **arr, Eina_Iterator *iter)
42 42
43EFL_START_TEST(test_multi_select) 43EFL_START_TEST(test_multi_select)
44{ 44{
45 Efl_Ui_Item *selected = NULL; 45 int c = 0;
46 Efl_Ui_Item *unselected = NULL; 46
47 Eina_Array *arr_selected; 47 Eina_Array *arr_selected;
48 efl_ui_select_mode_set(widget, EFL_UI_SELECT_MODE_MULTI); 48 efl_ui_select_mode_set(widget, EFL_UI_SELECT_MODE_MULTI);
49 efl_event_callback_add(widget, EFL_UI_EVENT_ITEM_SELECTED, _set_pointer_quit, &selected); 49 efl_event_callback_add(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, (Efl_Event_Cb) event_callback_single_call_int_data, &c);
50 efl_event_callback_add(widget, EFL_UI_EVENT_ITEM_UNSELECTED, _set_pointer_quit, &unselected); 50 efl_event_callback_add(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, event_callback_that_quits_the_main_loop_when_called, NULL);
51 51
52 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 0), EINA_TRUE); 52 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 0), EINA_TRUE);
53 ck_assert_ptr_eq(selected, efl_pack_content_get(widget, 0)); 53 if (c == 0) efl_loop_begin(efl_main_loop_get());
54 ck_assert_ptr_eq(unselected, NULL); 54 ck_assert_int_eq(c, 1);
55 selected = NULL; 55 c = 0;
56 unselected = NULL; 56
57 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 2), EINA_TRUE); 57 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 2), EINA_TRUE);
58 ck_assert_ptr_eq(selected, efl_pack_content_get(widget, 2)); 58 if (c == 0) efl_loop_begin(efl_main_loop_get());
59 ck_assert_ptr_eq(unselected, NULL); 59 ck_assert_int_eq(c, 1);
60 selected = NULL; 60 c = 0;
61 unselected = NULL;
62 ck_assert_int_eq(efl_ui_selectable_selected_get(efl_pack_content_get(widget, 0)), EINA_TRUE); 61 ck_assert_int_eq(efl_ui_selectable_selected_get(efl_pack_content_get(widget, 0)), EINA_TRUE);
63 ck_assert_int_eq(efl_ui_selectable_selected_get(efl_pack_content_get(widget, 2)), EINA_TRUE); 62 ck_assert_int_eq(efl_ui_selectable_selected_get(efl_pack_content_get(widget, 2)), EINA_TRUE);
64 ck_assert_ptr_eq(efl_ui_single_selectable_last_selected_get(widget), efl_pack_content_get(widget, 2)); 63 ck_assert_ptr_eq(efl_ui_single_selectable_last_selected_get(widget), efl_pack_content_get(widget, 2));
@@ -68,68 +67,59 @@ EFL_START_TEST(test_multi_select)
68 ck_assert_ptr_eq(eina_array_data_get(arr_selected, 1), efl_pack_content_get(widget, 2)); 67 ck_assert_ptr_eq(eina_array_data_get(arr_selected, 1), efl_pack_content_get(widget, 2));
69 68
70 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 2), EINA_TRUE); 69 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 2), EINA_TRUE);
71 ck_assert_ptr_eq(selected, NULL); 70 ck_assert_int_eq(c, 0);
72 ck_assert_ptr_eq(unselected, NULL); 71
73 selected = NULL; 72 efl_event_callback_del(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, (Efl_Event_Cb) event_callback_single_call_int_data, &c);
74 unselected = NULL; 73 efl_event_callback_del(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, event_callback_that_quits_the_main_loop_when_called, NULL);
75 efl_event_callback_del(widget, EFL_UI_EVENT_ITEM_SELECTED, _set_pointer_quit, &selected);
76 efl_event_callback_del(widget, EFL_UI_EVENT_ITEM_UNSELECTED, _set_pointer_quit, &unselected);
77} 74}
78EFL_END_TEST 75EFL_END_TEST
79 76
80EFL_START_TEST(test_multi_select_removal) 77EFL_START_TEST(test_multi_select_removal)
81{ 78{
82 Efl_Ui_Item *selected = NULL; 79 int c = 0;
83 Efl_Ui_Item *unselected = NULL;
84 Eina_Array *arr_selected; 80 Eina_Array *arr_selected;
85 efl_ui_select_mode_set(widget, EFL_UI_SELECT_MODE_MULTI); 81 efl_ui_select_mode_set(widget, EFL_UI_SELECT_MODE_MULTI);
86 efl_event_callback_add(widget, EFL_UI_EVENT_ITEM_SELECTED, _set_pointer_quit, &selected); 82 efl_event_callback_add(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, (Efl_Event_Cb) event_callback_single_call_int_data, &c);
87 efl_event_callback_add(widget, EFL_UI_EVENT_ITEM_UNSELECTED, _set_pointer_quit, &unselected); 83 efl_event_callback_add(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, event_callback_that_quits_the_main_loop_when_called, NULL);
88 84
89 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 0), EINA_TRUE); 85 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 0), EINA_TRUE);
90 selected = NULL;//No need to ckeck the flag, we asserted in the tcase before 86 c = 0;
91 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 2), EINA_TRUE); 87 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 2), EINA_TRUE);
92 selected = NULL;//No need to ckeck the flag, we asserted in the tcase before 88 c = 0;
93 unselected = NULL;
94 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 0), EINA_FALSE); 89 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 0), EINA_FALSE);
95 ck_assert_ptr_eq(selected, NULL); 90 if (c == 0) efl_loop_begin(efl_main_loop_get());
96 ck_assert_ptr_eq(unselected, efl_pack_content_get(widget, 0)); 91 ck_assert_int_eq(c, 1);
97 selected = NULL; 92 c = 0;
98 unselected = NULL;
99 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 2), EINA_FALSE); 93 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 2), EINA_FALSE);
100 ck_assert_ptr_eq(selected, NULL); 94 if (c == 0) efl_loop_begin(efl_main_loop_get());
101 ck_assert_ptr_eq(unselected, efl_pack_content_get(widget, 2)); 95 ck_assert_int_eq(c, 1);
102 selected = NULL; 96 c = 0;
103 unselected = NULL;
104 97
105 ck_assert_ptr_eq(efl_ui_single_selectable_last_selected_get(widget), NULL); 98 ck_assert_ptr_eq(efl_ui_single_selectable_last_selected_get(widget), NULL);
106 _iterator_to_array(&arr_selected, efl_ui_selected_items_get(widget)); 99 _iterator_to_array(&arr_selected, efl_ui_selected_items_get(widget));
107 ck_assert_int_eq(eina_array_count(arr_selected), 0); 100 ck_assert_int_eq(eina_array_count(arr_selected), 0);
108 efl_event_callback_del(widget, EFL_UI_EVENT_ITEM_SELECTED, _set_pointer_quit, &selected); 101 efl_event_callback_del(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, (Efl_Event_Cb) event_callback_single_call_int_data, &c);
109 efl_event_callback_del(widget, EFL_UI_EVENT_ITEM_UNSELECTED, _set_pointer_quit, &unselected); 102 efl_event_callback_del(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, event_callback_that_quits_the_main_loop_when_called, NULL);
110} 103}
111EFL_END_TEST 104EFL_END_TEST
112 105
113EFL_START_TEST(test_single_select) 106EFL_START_TEST(test_single_select)
114{ 107{
115 Efl_Ui_Item *selected = NULL; 108 int c = 0;
116 Efl_Ui_Item *unselected = NULL;
117 Eina_Array *arr_selected; 109 Eina_Array *arr_selected;
118 110
119 efl_ui_select_mode_set(widget, EFL_UI_SELECT_MODE_SINGLE); 111 efl_ui_select_mode_set(widget, EFL_UI_SELECT_MODE_SINGLE);
120 efl_event_callback_add(widget, EFL_UI_EVENT_ITEM_SELECTED, _set_pointer_quit, &selected); 112 efl_event_callback_add(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, (Efl_Event_Cb) event_callback_single_call_int_data, &c);
121 efl_event_callback_add(widget, EFL_UI_EVENT_ITEM_UNSELECTED, _set_pointer_quit, &unselected); 113 efl_event_callback_add(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, event_callback_that_quits_the_main_loop_when_called, NULL);
122 114
123 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 0), EINA_TRUE); 115 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 0), EINA_TRUE);
124 ck_assert_ptr_eq(selected, efl_pack_content_get(widget, 0)); 116 if (c == 0) efl_loop_begin(efl_main_loop_get());
125 ck_assert_ptr_eq(unselected, NULL); 117 ck_assert_int_eq(c, 1);
126 selected = NULL; 118 c = 0;
127 unselected = NULL;
128 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 2), EINA_TRUE); 119 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 2), EINA_TRUE);
129 ck_assert_ptr_eq(selected, efl_pack_content_get(widget, 2)); 120 if (c == 0) efl_loop_begin(efl_main_loop_get());
130 ck_assert_ptr_eq(unselected, efl_pack_content_get(widget, 0)); 121 ck_assert_int_eq(c, 1);
131 selected = NULL; 122 c = 0;
132 unselected = NULL;
133 ck_assert_int_eq(efl_ui_selectable_selected_get(efl_pack_content_get(widget, 0)), EINA_FALSE); 123 ck_assert_int_eq(efl_ui_selectable_selected_get(efl_pack_content_get(widget, 0)), EINA_FALSE);
134 ck_assert_int_eq(efl_ui_selectable_selected_get(efl_pack_content_get(widget, 2)), EINA_TRUE); 124 ck_assert_int_eq(efl_ui_selectable_selected_get(efl_pack_content_get(widget, 2)), EINA_TRUE);
135 ck_assert_ptr_eq(efl_ui_single_selectable_last_selected_get(widget), efl_pack_content_get(widget, 2)); 125 ck_assert_ptr_eq(efl_ui_single_selectable_last_selected_get(widget), efl_pack_content_get(widget, 2));
@@ -138,48 +128,42 @@ EFL_START_TEST(test_single_select)
138 ck_assert_ptr_eq(eina_array_data_get(arr_selected, 0), efl_pack_content_get(widget, 2)); 128 ck_assert_ptr_eq(eina_array_data_get(arr_selected, 0), efl_pack_content_get(widget, 2));
139 129
140 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 2), EINA_TRUE); 130 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 2), EINA_TRUE);
141 ck_assert_ptr_eq(selected, NULL); 131 ck_assert_int_eq(c, 0);
142 ck_assert_ptr_eq(unselected, NULL); 132
143 selected = NULL; 133 efl_event_callback_del(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, (Efl_Event_Cb) event_callback_single_call_int_data, &c);
144 unselected = NULL; 134 efl_event_callback_del(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, event_callback_that_quits_the_main_loop_when_called, NULL);
145 efl_event_callback_del(widget, EFL_UI_EVENT_ITEM_SELECTED, _set_pointer_quit, &selected);
146 efl_event_callback_del(widget, EFL_UI_EVENT_ITEM_UNSELECTED, _set_pointer_quit, &unselected);
147} 135}
148EFL_END_TEST 136EFL_END_TEST
149 137
150EFL_START_TEST(test_single_select_always) 138EFL_START_TEST(test_single_select_always)
151{ 139{
152 Efl_Ui_Item *selected = NULL; 140 int c = 0;
153 Efl_Ui_Item *unselected = NULL;
154 Eina_Array *arr_selected; 141 Eina_Array *arr_selected;
155 142
156 efl_ui_select_mode_set(widget, EFL_UI_SELECT_MODE_SINGLE_ALWAYS); 143 efl_ui_select_mode_set(widget, EFL_UI_SELECT_MODE_SINGLE_ALWAYS);
157 efl_event_callback_add(widget, EFL_UI_EVENT_ITEM_SELECTED, _set_pointer_quit, &selected); 144 efl_event_callback_add(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, (Efl_Event_Cb) event_callback_single_call_int_data, &c);
158 efl_event_callback_add(widget, EFL_UI_EVENT_ITEM_UNSELECTED, _set_pointer_quit, &unselected); 145 efl_event_callback_add(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, event_callback_that_quits_the_main_loop_when_called, NULL);
159 146
160 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 0), EINA_TRUE); 147 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 0), EINA_TRUE);
161 ck_assert_ptr_eq(selected, efl_pack_content_get(widget, 0)); 148 if (c == 0) efl_loop_begin(efl_main_loop_get());
162 ck_assert_ptr_eq(unselected, NULL); 149 ck_assert_int_eq(c, 1);
163 selected = NULL; 150 c = 0;
164 unselected = NULL;
165 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 2), EINA_TRUE); 151 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 2), EINA_TRUE);
166 ck_assert_ptr_eq(selected, efl_pack_content_get(widget, 2)); 152 if (c == 0) efl_loop_begin(efl_main_loop_get());
167 ck_assert_ptr_eq(unselected, efl_pack_content_get(widget, 0)); 153 ck_assert_int_eq(c, 1);
168 selected = NULL; 154 c = 0;
169 unselected = NULL;
170 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 2), EINA_TRUE); 155 efl_ui_selectable_selected_set(efl_pack_content_get(widget, 2), EINA_TRUE);
171 ck_assert_ptr_eq(selected, efl_pack_content_get(widget, 2)); 156 if (c == 0) efl_loop_begin(efl_main_loop_get());
172 ck_assert_ptr_eq(unselected, NULL); 157 ck_assert_int_eq(c, 1);
173 selected = NULL; 158 c = 0;
174 unselected = NULL;
175 ck_assert_int_eq(efl_ui_selectable_selected_get(efl_pack_content_get(widget, 0)), EINA_FALSE); 159 ck_assert_int_eq(efl_ui_selectable_selected_get(efl_pack_content_get(widget, 0)), EINA_FALSE);
176 ck_assert_int_eq(efl_ui_selectable_selected_get(efl_pack_content_get(widget, 2)), EINA_TRUE); 160 ck_assert_int_eq(efl_ui_selectable_selected_get(efl_pack_content_get(widget, 2)), EINA_TRUE);
177 ck_assert_ptr_eq(efl_ui_single_selectable_last_selected_get(widget), efl_pack_content_get(widget, 2)); 161 ck_assert_ptr_eq(efl_ui_single_selectable_last_selected_get(widget), efl_pack_content_get(widget, 2));
178 _iterator_to_array(&arr_selected, efl_ui_selected_items_get(widget)); 162 _iterator_to_array(&arr_selected, efl_ui_selected_items_get(widget));
179 ck_assert_int_eq(eina_array_count(arr_selected), 1); 163 ck_assert_int_eq(eina_array_count(arr_selected), 1);
180 ck_assert_ptr_eq(eina_array_data_get(arr_selected, 0), efl_pack_content_get(widget, 2)); 164 ck_assert_ptr_eq(eina_array_data_get(arr_selected, 0), efl_pack_content_get(widget, 2));
181 efl_event_callback_del(widget, EFL_UI_EVENT_ITEM_SELECTED, _set_pointer_quit, &selected); 165 efl_event_callback_del(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, (Efl_Event_Cb) event_callback_single_call_int_data, &c);
182 efl_event_callback_del(widget, EFL_UI_EVENT_ITEM_UNSELECTED, _set_pointer_quit, &unselected); 166 efl_event_callback_del(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, event_callback_that_quits_the_main_loop_when_called, NULL);
183} 167}
184EFL_END_TEST 168EFL_END_TEST
185 169
diff --git a/src/tests/elementary/spec/efl_test_single_selectable.c b/src/tests/elementary/spec/efl_test_single_selectable.c
index c62f78afc4..fd4b5e0a8b 100644
--- a/src/tests/elementary/spec/efl_test_single_selectable.c
+++ b/src/tests/elementary/spec/efl_test_single_selectable.c
@@ -33,11 +33,19 @@ _setup(void)
33 33
34EFL_START_TEST(last_selectable_check) 34EFL_START_TEST(last_selectable_check)
35{ 35{
36 int c = 0;
37
38 efl_event_callback_add(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, (Efl_Event_Cb) event_callback_single_call_int_data, &c);
39 efl_event_callback_add(widget, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, event_callback_that_quits_the_main_loop_when_called, NULL);
40
36 Eo *c1 = efl_pack_content_get(widget, 0); 41 Eo *c1 = efl_pack_content_get(widget, 0);
37 Eo *c2 = efl_pack_content_get(widget, 2); 42 Eo *c2 = efl_pack_content_get(widget, 2);
38 43
39 efl_ui_selectable_selected_set(c1, EINA_TRUE); 44 efl_ui_selectable_selected_set(c1, EINA_TRUE);
40 ck_assert_ptr_eq(efl_ui_single_selectable_last_selected_get(widget), c1); 45 ck_assert_ptr_eq(efl_ui_single_selectable_last_selected_get(widget), c1);
46 if (c == 0) efl_loop_begin(efl_main_loop_get());
47 ck_assert_int_eq(c, 1);
48 c = 0;
41 49
42 efl_ui_selectable_selected_set(c2, EINA_TRUE); 50 efl_ui_selectable_selected_set(c2, EINA_TRUE);
43 ck_assert_ptr_eq(efl_ui_single_selectable_last_selected_get(widget), c2); 51 ck_assert_ptr_eq(efl_ui_single_selectable_last_selected_get(widget), c2);
@@ -48,9 +56,26 @@ EFL_START_TEST(last_selectable_check)
48} 56}
49EFL_END_TEST 57EFL_END_TEST
50 58
59EFL_START_TEST(fallback_selection)
60{
61 Eo *c1 = efl_pack_content_get(widget, 0);
62 Eo *c2 = efl_pack_content_get(widget, 2);
63
64 efl_ui_single_selectable_fallback_selection_set(widget, c2);
65 ck_assert_int_eq(efl_ui_selectable_selected_get(c2), EINA_TRUE);
66 efl_ui_selectable_selected_set(c1, EINA_TRUE);
67 ck_assert_int_eq(efl_ui_selectable_selected_get(c2), EINA_FALSE);
68 ck_assert_int_eq(efl_ui_selectable_selected_get(c1), EINA_TRUE);
69 efl_ui_selectable_selected_set(c1, EINA_FALSE);
70 ck_assert_int_eq(efl_ui_selectable_selected_get(c2), EINA_TRUE);
71 ck_assert_int_eq(efl_ui_selectable_selected_get(c1), EINA_FALSE);
72}
73EFL_END_TEST
74
51void 75void
52efl_ui_single_selectable_behavior_test(TCase *tc) 76efl_ui_single_selectable_behavior_test(TCase *tc)
53{ 77{
54 tcase_add_checked_fixture(tc, _setup, NULL); 78 tcase_add_checked_fixture(tc, _setup, NULL);
55 tcase_add_test(tc, last_selectable_check); 79 tcase_add_test(tc, last_selectable_check);
80 tcase_add_test(tc, fallback_selection);
56} 81}