From 6befb6e17bf4afb3c5b650be3b5238029253bce6 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Fri, 8 Nov 2019 12:14:15 -0800 Subject: [PATCH] efl: improve Efl.BooleanModel test by checking the child del case. This has detected the bug that previous commit fix. Reviewed-by: Marcel Hollerbach Differential Revision: https://phab.enlightenment.org/D10634 --- src/tests/efl/efl_test_composite_model.c | 126 ++++++++++++++++++++--- 1 file changed, 109 insertions(+), 17 deletions(-) diff --git a/src/tests/efl/efl_test_composite_model.c b/src/tests/efl/efl_test_composite_model.c index abae4c3666..8d05b6d447 100644 --- a/src/tests/efl/efl_test_composite_model.c +++ b/src/tests/efl/efl_test_composite_model.c @@ -25,18 +25,26 @@ #include #include -static const int child_number = 3; -static const int base_ints[] = { 41, 42, 43 }; +static const int child_number = 7; +static const int base_ints[] = { 41, 42, 43, 44, 45, 46, 47 }; + +static void +_cleanup(Eo *o EINA_UNUSED, void *data EINA_UNUSED, const Eina_Future *dead_future EINA_UNUSED) +{ + ecore_main_loop_quit(); +} static Eina_Value -_children_slice_get_then(void *data EINA_UNUSED, - const Eina_Value v, - const Eina_Future *dead_future EINA_UNUSED) +_children_slice_get_then(Eo *o EINA_UNUSED, + void *data EINA_UNUSED, + const Eina_Value v) { unsigned int i, len; Efl_Model *child; + Eina_Future **all; - fail_if(eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY); + all = calloc(1, sizeof (Eina_Future *) * (eina_value_array_count(&v) + 1)); + if (!all) return eina_value_error_init(ENOMEM); EINA_VALUE_ARRAY_FOREACH(&v, len, i, child) { @@ -55,6 +63,8 @@ _children_slice_get_then(void *data EINA_UNUSED, fail_if(!eina_value_bool_get(p_true, &v_true)); fail_if(!eina_value_bool_get(p_false, &v_false)); + all[i] = efl_model_property_set(child, "test_odd_even", v_int & 0x1 ? p_true : p_false); + fail_if(v_int != base_ints[i]); fail_if(v_true != EINA_TRUE); fail_if(v_false != EINA_FALSE); @@ -63,12 +73,87 @@ _children_slice_get_then(void *data EINA_UNUSED, eina_value_free(p_true); eina_value_free(p_false); } + all[i] = EINA_FUTURE_SENTINEL; - ecore_main_loop_quit(); + return eina_future_as_value(eina_future_all_array(all)); +} + +static Eina_Value +_children_odd_even_ready(Eo *model, void *data EINA_UNUSED, const Eina_Value v EINA_UNUSED) +{ + return eina_future_as_value(efl_model_children_slice_get(model, 0, child_number)); +} + +static Eina_Value +_children_odd_even_check(Eo *model, void *data EINA_UNUSED, const Eina_Value v) +{ + unsigned int i, len; + Efl_Model *child, *first_child = NULL; + + EINA_VALUE_ARRAY_FOREACH(&v, len, i, child) + { + Eina_Value *p_odd_even = NULL; + Eina_Value *p_int = NULL; + Eina_Bool v_odd_even = EINA_TRUE; + int v_int = -1; + + if (!first_child) first_child = child; + + p_int = efl_model_property_get(child, "test_p_int"); + p_odd_even = efl_model_property_get(child, "test_odd_even"); + + fail_if(!eina_value_bool_get(p_odd_even, &v_odd_even)); + fail_if(!eina_value_int_get(p_int, &v_int)); + + fail_if(v_int & 0x1 ? !v_odd_even : v_odd_even); + + eina_value_free(p_int); + eina_value_free(p_odd_even); + } + + efl_model_child_del(model, first_child); + + return eina_future_as_value(efl_model_children_slice_get(model, 0, child_number - 1)); +} + +static Eina_Value +_children_odd_even_check_after_removal(Eo *model EINA_UNUSED, void *data EINA_UNUSED, + const Eina_Value v) +{ + unsigned int i, len; + Efl_Model *child; + + EINA_VALUE_ARRAY_FOREACH(&v, len, i, child) + { + Eina_Value *p_odd_even = NULL; + Eina_Value *p_int = NULL; + Eina_Bool v_odd_even = EINA_TRUE; + int v_int = -1; + + p_int = efl_model_property_get(child, "test_p_int"); + p_odd_even = efl_model_property_get(child, "test_odd_even"); + + fail_if(!eina_value_bool_get(p_odd_even, &v_odd_even)); + fail_if(!eina_value_int_get(p_int, &v_int)); + + fail_if(v_int & 0x1 ? !v_odd_even : v_odd_even); + fail_if(v_int != base_ints[i + 1]); + + eina_value_free(p_int); + eina_value_free(p_odd_even); + } return v; } +static Eina_Value +_assert_on_error(Eo *o EINA_UNUSED, void *data EINA_UNUSED, Eina_Error error) +{ + ck_abort_msg("Assert on error triggered duing Boolean Model test with error '%s'.\n", + eina_error_msg_get(error)); + return eina_value_error_init(error); +} + EFL_START_TEST(efl_test_boolean_model) { Efl_Generic_Model *base_model, *child; @@ -91,13 +176,26 @@ EFL_START_TEST(efl_test_boolean_model) } model = efl_add_ref(EFL_BOOLEAN_MODEL_CLASS, efl_main_loop_get(), - efl_ui_view_model_set(efl_added, base_model), - efl_boolean_model_boolean_add(efl_added, "test_p_true", EINA_TRUE), - efl_boolean_model_boolean_add(efl_added, "test_p_false", EINA_FALSE)); + efl_ui_view_model_set(efl_added, base_model), + efl_boolean_model_boolean_add(efl_added, "test_p_true", EINA_TRUE), + efl_boolean_model_boolean_add(efl_added, "test_p_false", EINA_FALSE), + efl_boolean_model_boolean_add(efl_added, "test_odd_even", EINA_FALSE)); ck_assert(!!model); future = efl_model_children_slice_get(model, 0, efl_model_children_count_get(model)); - eina_future_then(future, _children_slice_get_then, NULL, NULL); + future = efl_future_then(model, future, + .success = _children_slice_get_then, + .success_type = EINA_VALUE_TYPE_ARRAY); + future = efl_future_then(model, future, + .success = _children_odd_even_ready, + .success_type = EINA_VALUE_TYPE_ARRAY); + future = efl_future_then(model, future, + .success = _children_odd_even_check, + .success_type = EINA_VALUE_TYPE_ARRAY); + future = efl_future_then(model, future, + .success = _children_odd_even_check_after_removal, + .success_type = EINA_VALUE_TYPE_ARRAY); + future = efl_future_then(model, future, .error = _assert_on_error, .free = _cleanup); ecore_main_loop_begin(); } @@ -303,12 +401,6 @@ _check_index(Eo *o EINA_UNUSED, void *data EINA_UNUSED, const Eina_Value v) return v; } -static void -_cleanup(Eo *o EINA_UNUSED, void *data EINA_UNUSED, const Eina_Future *dead_future EINA_UNUSED) -{ - ecore_main_loop_quit(); -} - EFL_START_TEST(efl_test_filter_model) { Efl_Generic_Model *base_model, *child;