summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2018-12-13 11:51:52 -0800
committerCedric BAIL <cedric.bail@free.fr>2019-01-02 13:39:27 -0800
commit1e3ecdd55ffdf4dd0bd8edc556b4d7d3a42149a1 (patch)
tree5f6300fcbc6cf98013b2551b40b90125d8a2599f
parent29fcdd8a4b4fb5140a0070c6f87469f6662acb42 (diff)
ecore: test for Efl.ModelView.
This does cover pretty much everything that Efl.ModelView provide. Reviewed-by: SangHyeon Jade Lee <sh10233.lee@samsung.com> Differential Revision: https://phab.enlightenment.org/D7488
-rw-r--r--src/Makefile_Efl.am1
-rw-r--r--src/tests/efl/efl_suite.c1
-rw-r--r--src/tests/efl/efl_suite.h1
-rw-r--r--src/tests/efl/efl_test_model_composite.c6
-rw-r--r--src/tests/efl/efl_test_model_view.c309
-rw-r--r--src/tests/efl/meson.build3
6 files changed, 317 insertions, 4 deletions
diff --git a/src/Makefile_Efl.am b/src/Makefile_Efl.am
index 154e054b4f..4c775b8085 100644
--- a/src/Makefile_Efl.am
+++ b/src/Makefile_Efl.am
@@ -199,6 +199,7 @@ tests_efl_efl_suite_SOURCES = \
199tests/efl/efl_suite.c \ 199tests/efl/efl_suite.c \
200tests/efl/efl_test_model_container.c \ 200tests/efl/efl_test_model_container.c \
201tests/efl/efl_test_model_composite.c \ 201tests/efl/efl_test_model_composite.c \
202tests/efl/efl_test_model_view.c \
202tests/efl/efl_suite.h 203tests/efl/efl_suite.h
203 204
204tests_efl_efl_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ 205tests_efl_efl_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
diff --git a/src/tests/efl/efl_suite.c b/src/tests/efl/efl_suite.c
index d8aea76759..97b17d7b2d 100644
--- a/src/tests/efl/efl_suite.c
+++ b/src/tests/efl/efl_suite.c
@@ -27,6 +27,7 @@
27 27
28static const Efl_Test_Case etc[] = { 28static const Efl_Test_Case etc[] = {
29 { "Efl_Model_Container", efl_test_case_model_container }, 29 { "Efl_Model_Container", efl_test_case_model_container },
30 { "Efl_Model_View", efl_test_case_model_view },
30 { "Efl_Model_Composite_Boolean", efl_test_case_model_composite_boolean }, 31 { "Efl_Model_Composite_Boolean", efl_test_case_model_composite_boolean },
31 { NULL, NULL } 32 { NULL, NULL }
32}; 33};
diff --git a/src/tests/efl/efl_suite.h b/src/tests/efl/efl_suite.h
index 4c2ff15f19..e353395ffb 100644
--- a/src/tests/efl/efl_suite.h
+++ b/src/tests/efl/efl_suite.h
@@ -22,6 +22,7 @@
22#include <check.h> 22#include <check.h>
23#include "../efl_check.h" 23#include "../efl_check.h"
24void efl_test_case_model_container(TCase *tc); 24void efl_test_case_model_container(TCase *tc);
25void efl_test_case_model_view(TCase *tc);
25void efl_test_case_model_composite_boolean(TCase *tc); 26void efl_test_case_model_composite_boolean(TCase *tc);
26 27
27#endif /* EFL_SUITE_H_ */ 28#endif /* EFL_SUITE_H_ */
diff --git a/src/tests/efl/efl_test_model_composite.c b/src/tests/efl/efl_test_model_composite.c
index a4ce5ba576..315c34ac5f 100644
--- a/src/tests/efl/efl_test_model_composite.c
+++ b/src/tests/efl/efl_test_model_composite.c
@@ -25,9 +25,9 @@
25#include <Efl.h> 25#include <Efl.h>
26#include <Ecore.h> 26#include <Ecore.h>
27 27
28const int child_number = 3; 28static const int child_number = 3;
29const int base_ints[] = { 41, 42, 43 }; 29static const int base_ints[] = { 41, 42, 43 };
30const Eina_Bool base_selections[] = { EINA_FALSE, EINA_FALSE, EINA_TRUE }; 30static const Eina_Bool base_selections[] = { EINA_FALSE, EINA_FALSE, EINA_TRUE };
31 31
32static Eina_Value 32static Eina_Value
33_children_slice_get_then(void *data EINA_UNUSED, 33_children_slice_get_then(void *data EINA_UNUSED,
diff --git a/src/tests/efl/efl_test_model_view.c b/src/tests/efl/efl_test_model_view.c
new file mode 100644
index 0000000000..607ee4851f
--- /dev/null
+++ b/src/tests/efl/efl_test_model_view.c
@@ -0,0 +1,309 @@
1/* EFL - EFL library
2 * Copyright (C) 2018 Cedric Bail
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include "efl_suite.h"
24
25#include <Efl.h>
26#include <Ecore.h>
27
28static const int child_number = 3;
29static const int base_ints[] = { 41, 42, 43 };
30static const char *_efl_test_model_view_label_format = "Index %i.";
31static const char *dependences[] = { "test_p_int" };
32
33static Eina_Value *
34_efl_test_model_view_label_get(void *data, const Efl_Model_View *mv, Eina_Stringshare *property)
35{
36 Eina_Strbuf *buf;
37 Eina_Value *r;
38 Eina_Value *p_int;
39 int v_int;
40 const char *format = data;
41
42 ck_assert(strcmp(property, "label") == 0);
43
44 p_int = efl_model_property_get(mv, "test_p_int");
45 ck_assert(eina_value_int_get(p_int, &v_int) == EINA_TRUE);
46
47 buf = eina_strbuf_new();
48 eina_strbuf_append_printf(buf, format, v_int);
49
50 r = eina_value_string_new(eina_strbuf_string_get(buf));
51 eina_strbuf_free(buf);
52
53 return r;
54}
55
56static Eina_Future *
57_efl_test_model_view_label_set(void *data EINA_UNUSED, Efl_Model_View *mv, Eina_Stringshare *property EINA_UNUSED, Eina_Value *value EINA_UNUSED)
58{
59 return efl_loop_future_rejected(mv, EFL_MODEL_ERROR_READ_ONLY);
60}
61
62static void
63_efl_test_model_view_label_clean(void *data)
64{
65 ck_assert_ptr_eq(data, _efl_test_model_view_label_format);
66}
67
68static Eina_Value *
69_efl_test_model_view_color_get(void *data EINA_UNUSED, const Efl_Model_View *mv, Eina_Stringshare *property)
70{
71 Eina_Strbuf *buf;
72 Eina_Value *r;
73 Eina_Value *p_int;
74 int v_int;
75
76 ck_assert(strcmp(property, "color") == 0);
77
78 p_int = efl_model_property_get(mv, "test_p_int");
79 ck_assert(eina_value_int_get(p_int, &v_int) == EINA_TRUE);
80
81 buf = eina_strbuf_new();
82 eina_strbuf_append_printf(buf, "#%02x%02x%02x%02x", v_int, v_int, v_int, v_int);
83
84 r = eina_value_string_new(eina_strbuf_string_get(buf));
85 eina_strbuf_free(buf);
86
87 return r;
88}
89
90static Eina_Future *
91_efl_test_model_view_color_set(void *data EINA_UNUSED, Efl_Model_View *mv, Eina_Stringshare *property EINA_UNUSED, Eina_Value *value EINA_UNUSED)
92{
93 return efl_loop_future_rejected(mv, EFL_MODEL_ERROR_READ_ONLY);
94}
95
96static void
97_efl_test_model_view_color_clean(void *data EINA_UNUSED)
98{
99}
100
101static Eina_Value
102_dummy(Eo *obj EINA_UNUSED, void *data EINA_UNUSED, const Eina_Value value)
103{
104 ck_abort();
105
106 return value;
107}
108
109static Eina_Value
110_expected_fail(Eo *o EINA_UNUSED, void *data EINA_UNUSED, Eina_Error error)
111{
112 ck_assert_int_eq(error, EFL_MODEL_ERROR_READ_ONLY);
113 return eina_value_int_init(0);
114}
115
116static unsigned int counting = 0;
117
118typedef struct _Property_Change_Test Property_Change_Test;
119struct _Property_Change_Test
120{
121 Eina_Bool checked;
122 const char *name;
123};
124
125static void
126_properties_changed(void *data, const Efl_Event *event)
127{
128 Efl_Model_Property_Event *ev = event->info;
129 unsigned int *count = data;
130 const char *property;
131 Eina_Array_Iterator iterator;
132 unsigned int i, j;
133 Property_Change_Test tests[] = {
134 { EINA_FALSE, "test_p_int" },
135 { EINA_FALSE, "color" },
136 { EINA_FALSE, "label" }
137 };
138
139 EINA_ARRAY_ITER_NEXT(ev->changed_properties, i, property, iterator)
140 {
141 for (j = 0; j < EINA_C_ARRAY_LENGTH(tests); j++)
142 if (!strcmp(tests[j].name, property))
143 {
144 fail_if(tests[j].checked);
145 tests[j].checked = EINA_TRUE;
146 break;
147 }
148 }
149
150 for (j = 0; j < EINA_C_ARRAY_LENGTH(tests); j++)
151 {
152 fail_if(!tests[j].checked);
153 }
154
155 *count += 1;
156}
157
158static Eina_Value
159_efl_test_model_view_child_get(Eo *obj EINA_UNUSED,
160 void *data EINA_UNUSED,
161 const Eina_Value v)
162{
163 Efl_Model *child;
164 Eina_Future **all = NULL;
165 Eina_Future *r;
166 unsigned int i, len;
167
168 fail_if(eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY);
169
170 all = calloc(eina_value_array_count(&v) + 1, sizeof (Eina_Future*));
171 if (!all) return eina_value_error_init(ENOMEM);
172
173 EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
174 {
175 Eina_Value *p_int = NULL;
176 Eina_Value *p_color = NULL;
177 Eina_Value *p_label = NULL;
178 int v_int = 0;
179
180 p_int = efl_model_property_get(child, "test_p_int");
181 ck_assert(eina_value_int_get(p_int, &v_int));
182
183 p_color = efl_model_property_get(child, "color");
184 p_label = efl_model_property_get(child, "label");
185
186 efl_event_callback_add(child, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _properties_changed, &counting);
187
188 efl_future_then(child, efl_model_property_set(child, "color", p_label),
189 .success = _dummy, .error = _expected_fail);
190 efl_future_then(child, efl_model_property_set(child, "color", p_color),
191 .success = _dummy, .error = _expected_fail);
192
193 all[i] = efl_model_property_set(child, "test_p_int", eina_value_int_new(v_int+100));
194 }
195
196 all[i] = EINA_FUTURE_SENTINEL;
197 r = eina_future_all_array(all);
198 return eina_future_as_value(r);
199}
200
201static Eina_Value
202_efl_test_model_view_child_fetch(Eo *mv,
203 void *data EINA_UNUSED,
204 const Eina_Value v)
205{
206 Eina_Future *r;
207
208 r = efl_model_children_slice_get(mv, 0, efl_model_children_count_get(mv));
209 return eina_future_as_value(r);
210}
211
212static Eina_Value
213_efl_test_model_view_child_updated_get(Eo *obj EINA_UNUSED,
214 void *data EINA_UNUSED,
215 const Eina_Value v)
216{
217 Efl_Model *child;
218 unsigned int i, len;
219
220 fail_if(eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY);
221
222 EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
223 {
224 Eina_Value *p_int = NULL;
225 Eina_Value *p_color = NULL;
226 Eina_Value *p_label = NULL;
227 const char *s_color = NULL;
228 const char *s_label = NULL;
229 int v_int = 0;
230
231 p_int = efl_model_property_get(child, "test_p_int");
232 ck_assert(eina_value_int_get(p_int, &v_int));
233 ck_assert_int_gt(v_int, 100);
234
235 p_color = efl_model_property_get(child, "color");
236 p_label = efl_model_property_get(child, "label");
237 eina_value_string_get(p_color, &s_color);
238 eina_value_string_get(p_label, &s_label);
239
240 ck_assert_ptr_ne(s_color, NULL);
241 ck_assert_ptr_ne(s_label, NULL);
242 }
243
244 return eina_value_int_init(0);
245}
246
247static Eina_Value
248_efl_test_model_view_tests_end(Eo *obj,
249 void *data EINA_UNUSED,
250 const Eina_Value v)
251{
252 efl_loop_quit(efl_loop_get(obj), v);
253 return v;
254}
255
256EFL_START_TEST(efl_test_model_view)
257{
258 Efl_Model_Item *base_model, *child, *mv;
259 Eina_Future *f;
260 int i;
261 Eina_Value v;
262
263 base_model = efl_add_ref(EFL_MODEL_ITEM_CLASS, efl_main_loop_get());
264 ck_assert(!!base_model);
265
266 for (i = 0; i < child_number; ++i)
267 {
268 child = efl_model_child_add(base_model);
269 ck_assert(!!child);
270 v = eina_value_int_init(base_ints[i]);
271 efl_model_property_set(child, "test_p_int", &v);
272 }
273
274 mv = efl_add_ref(EFL_MODEL_VIEW_CLASS, efl_main_loop_get(),
275 efl_ui_view_model_set(efl_added, base_model));
276 ck_assert(!!mv);
277
278 efl_model_view_property_logic_add(mv, "label",
279 (void*) _efl_test_model_view_label_format, _efl_test_model_view_label_get, _efl_test_model_view_label_clean,
280 (void*) _efl_test_model_view_label_format, _efl_test_model_view_label_set, _efl_test_model_view_label_clean,
281 EINA_C_ARRAY_ITERATOR_NEW(dependences));
282
283 efl_model_view_property_logic_add(mv, "color",
284 NULL, _efl_test_model_view_color_get, _efl_test_model_view_color_clean,
285 NULL, _efl_test_model_view_color_set, _efl_test_model_view_color_clean,
286 EINA_C_ARRAY_ITERATOR_NEW(dependences));
287
288 f = efl_model_children_slice_get(mv, 0, efl_model_children_count_get(mv));
289 f = efl_future_then(mv, f, .success_type = EINA_VALUE_TYPE_ARRAY,
290 .success = _efl_test_model_view_child_get);
291 f = efl_future_then(mv, f, .success = _efl_test_model_view_child_fetch);
292 f = efl_future_then(mv, f, .success_type = EINA_VALUE_TYPE_ARRAY,
293 .success = _efl_test_model_view_child_updated_get);
294 f = efl_future_then(mv, f, .success_type = EINA_VALUE_TYPE_INT,
295 .success = _efl_test_model_view_tests_end);
296
297 // And run !
298 ecore_main_loop_begin();
299
300 // We expect each child to have their property updated
301 ck_assert_int_eq(counting, child_number);
302}
303EFL_END_TEST
304
305void
306efl_test_case_model_view(TCase *tc)
307{
308 tcase_add_test(tc, efl_test_model_view);
309}
diff --git a/src/tests/efl/meson.build b/src/tests/efl/meson.build
index 10b24071b8..d036b9af8d 100644
--- a/src/tests/efl/meson.build
+++ b/src/tests/efl/meson.build
@@ -2,7 +2,8 @@ efl_suite_src = [
2 'efl_suite.c', 2 'efl_suite.c',
3 'efl_suite.h', 3 'efl_suite.h',
4 'efl_test_model_composite.c', 4 'efl_test_model_composite.c',
5 'efl_test_model_container.c' 5 'efl_test_model_container.c',
6 'efl_test_model_view.c'
6] 7]
7 8
8efl_suite_bin = executable('efl_suite', 9efl_suite_bin = executable('efl_suite',