summaryrefslogtreecommitdiff
path: root/src/tests/elementary/efl_ui_model.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-01-31 11:08:46 +0900
committerSangHyeon Jade Lee <sh10233.lee@samsung.com>2019-01-31 11:09:16 +0900
commitc713bb90d3fe4a56ebd5f4f88cd5a248c5b7e482 (patch)
tree987056f5056b8d499dec1529aebb8076444c8ae6 /src/tests/elementary/efl_ui_model.c
parentf4e5948c0fd819f5259f139a9ec009f4110343a1 (diff)
elementary: add test for Efl.Ui.Model_Average.
Summary: Depends on D7664 Reviewers: SanghyeonLee, felipealmeida, segfaultxavi, zmike Reviewed By: SanghyeonLee Subscribers: #reviewers, #committers Tags: #efl Maniphest Tasks: T7382 Differential Revision: https://phab.enlightenment.org/D7665
Diffstat (limited to '')
-rw-r--r--src/tests/elementary/efl_ui_model.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/tests/elementary/efl_ui_model.c b/src/tests/elementary/efl_ui_model.c
index b8965dfc54..f94642f9e3 100644
--- a/src/tests/elementary/efl_ui_model.c
+++ b/src/tests/elementary/efl_ui_model.c
@@ -5,9 +5,11 @@
5#include "efl_ui_suite.h" 5#include "efl_ui_suite.h"
6#include "efl_ui_model_homogeneous.eo.h" 6#include "efl_ui_model_homogeneous.eo.h"
7#include "efl_ui_model_exact.eo.h" 7#include "efl_ui_model_exact.eo.h"
8#include "efl_ui_model_average.eo.h"
8 9
9static const int child_number = 3; 10static const int child_number = 3;
10static const int base_ints[] = { 41, 42, 43 }; 11static const int base_ints[] = { 41, 42, 43 };
12static int expected_average[] = { 0, 0, 0 };
11 13
12static Efl_Model * 14static Efl_Model *
13_generate_base_model(void) 15_generate_base_model(void)
@@ -247,9 +249,103 @@ EFL_START_TEST(efl_ui_model_exact_test)
247} 249}
248EFL_END_TEST 250EFL_END_TEST
249 251
252static Eina_Value
253_child_updated_average(Efl_Model *model, void *data, const Eina_Value v)
254{
255 Eina_Value *r;
256 int *ex = data;
257 int got = 0;
258
259 r = efl_model_property_get(model, "total.height");
260 ck_assert(eina_value_int_convert(r, &got));
261 ck_assert_int_eq(got, *ex);
262 eina_value_free(r);
263
264 return v;
265}
266
267static Eina_Value
268_children_average_slice_get_then(Efl_Model *model, void *data EINA_UNUSED, const Eina_Value v)
269{
270 unsigned int i, len;
271 Efl_Model *child = NULL;
272 Eina_Future *all[4] = { NULL, NULL, NULL, EINA_FUTURE_SENTINEL };
273 Eina_Future *f;
274
275 fail_if(eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY);
276
277 EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
278 {
279 ck_assert_int_eq(_property_uint_expected(child, "self.width"), 0);
280 ck_assert_int_eq(_property_uint_expected(child, "self.height"), 0);
281 }
282
283 EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
284 {
285 Eina_Value *v;
286 unsigned int w, h;
287
288 v = efl_model_property_get(child, "test_p_int");
289 eina_value_uint_convert(v, &w);
290 eina_value_uint_convert(v, &h);
291 eina_value_free(v);
292
293 w *= 2;
294 h *= 3;
295
296 all[i] = eina_future_all(efl_model_property_set(child, "self.width", eina_value_uint_new(w)),
297 efl_model_property_set(child, "self.height", eina_value_uint_new(h)));
298 all[i] = efl_future_then(model, all[i], .success = _child_should_succeed);
299
300 // The model average is not updated until the property have succeeded, so we have
301 // to wait before we can fetch the property.
302 all[i] = efl_future_then(model, all[i], .success = _child_updated_average, .data = &expected_average[i]);
303 }
304
305 f = eina_future_all_array(all);
306 f = efl_future_then(model, f, .success = _total_succeed, .error = _total_failed);
307 return eina_future_as_value(f);
308}
309
310EFL_START_TEST(efl_ui_model_average_test)
311{
312 Efl_Model_Item *base_model, *model;
313 Eina_Future *future;
314 Eina_Value *ret__;
315 int real__;
316
317 base_model = _generate_base_model();
318
319 model = efl_add_ref(EFL_UI_MODEL_AVERAGE_CLASS, efl_main_loop_get(),
320 efl_ui_view_model_set(efl_added, base_model));
321 ck_assert(!!model);
322
323 future = efl_model_children_slice_get(model, 0, efl_model_children_count_get(model));
324 efl_future_then(model, future, .success = _children_average_slice_get_then);
325
326 ck_assert_int_eq(_property_uint_expected(model, "total.width"), 0);
327 ck_assert_int_eq(_property_uint_expected(model, "total.height"), 0);
328 ck_assert_int_eq(_property_error_expected(model, "item.width"), EAGAIN);
329 ck_assert_int_eq(_property_error_expected(model, "item.height"), EAGAIN);
330
331 ret__ = efl_loop_begin(efl_app_main_get(EFL_APP_CLASS));
332 real__ = efl_loop_exit_code_process(ret__);
333 fail_if(real__ != 0);
334
335 ck_assert_int_eq(_property_uint_expected(model, "total.width"), base_ints[2] * 2);
336 ck_assert_int_eq(_property_uint_expected(model, "total.height"), base_ints[0] * 3 + base_ints[1] * 3 + base_ints[2] * 3);
337}
338EFL_END_TEST
339
250void 340void
251efl_ui_model(TCase *tc) 341efl_ui_model(TCase *tc)
252{ 342{
343 // This is done here as some system can not initialize computed value from another data at compile time.
344 expected_average[0] = base_ints[0] * 3 * 3;
345 expected_average[1] = ((base_ints[0] * 3 + base_ints[1] * 3) * 3) / 2;
346 expected_average[2] = base_ints[0] * 3 + base_ints[1] * 3 + base_ints[2] * 3;
347
253 tcase_add_test(tc, efl_ui_model_homogeneous_test); 348 tcase_add_test(tc, efl_ui_model_homogeneous_test);
349 tcase_add_test(tc, efl_ui_model_average_test);
254 tcase_add_test(tc, efl_ui_model_exact_test); 350 tcase_add_test(tc, efl_ui_model_exact_test);
255} 351}