summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-11-08 12:14:15 -0800
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-11-13 21:16:22 +0100
commit6befb6e17bf4afb3c5b650be3b5238029253bce6 (patch)
tree0ffba911d941fd8ce90986ec95de8b2655a8fa59
parent06873a6fdb7a31679a14aefdba45db49f360d68a (diff)
efl: improve Efl.BooleanModel test by checking the child del case.
This has detected the bug that previous commit fix. Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de> Differential Revision: https://phab.enlightenment.org/D10634
-rw-r--r--src/tests/efl/efl_test_composite_model.c126
1 files 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 abae4c3..8d05b6d 100644
--- a/src/tests/efl/efl_test_composite_model.c
+++ b/src/tests/efl/efl_test_composite_model.c
@@ -25,18 +25,26 @@
25#include <Efl.h> 25#include <Efl.h>
26#include <Ecore.h> 26#include <Ecore.h>
27 27
28static const int child_number = 3; 28static const int child_number = 7;
29static const int base_ints[] = { 41, 42, 43 }; 29static const int base_ints[] = { 41, 42, 43, 44, 45, 46, 47 };
30
31static void
32_cleanup(Eo *o EINA_UNUSED, void *data EINA_UNUSED, const Eina_Future *dead_future EINA_UNUSED)
33{
34 ecore_main_loop_quit();
35}
30 36
31static Eina_Value 37static Eina_Value
32_children_slice_get_then(void *data EINA_UNUSED, 38_children_slice_get_then(Eo *o EINA_UNUSED,
33 const Eina_Value v, 39 void *data EINA_UNUSED,
34 const Eina_Future *dead_future EINA_UNUSED) 40 const Eina_Value v)
35{ 41{
36 unsigned int i, len; 42 unsigned int i, len;
37 Efl_Model *child; 43 Efl_Model *child;
44 Eina_Future **all;
38 45
39 fail_if(eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY); 46 all = calloc(1, sizeof (Eina_Future *) * (eina_value_array_count(&v) + 1));
47 if (!all) return eina_value_error_init(ENOMEM);
40 48
41 EINA_VALUE_ARRAY_FOREACH(&v, len, i, child) 49 EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
42 { 50 {
@@ -55,6 +63,8 @@ _children_slice_get_then(void *data EINA_UNUSED,
55 fail_if(!eina_value_bool_get(p_true, &v_true)); 63 fail_if(!eina_value_bool_get(p_true, &v_true));
56 fail_if(!eina_value_bool_get(p_false, &v_false)); 64 fail_if(!eina_value_bool_get(p_false, &v_false));
57 65
66 all[i] = efl_model_property_set(child, "test_odd_even", v_int & 0x1 ? p_true : p_false);
67
58 fail_if(v_int != base_ints[i]); 68 fail_if(v_int != base_ints[i]);
59 fail_if(v_true != EINA_TRUE); 69 fail_if(v_true != EINA_TRUE);
60 fail_if(v_false != EINA_FALSE); 70 fail_if(v_false != EINA_FALSE);
@@ -63,12 +73,87 @@ _children_slice_get_then(void *data EINA_UNUSED,
63 eina_value_free(p_true); 73 eina_value_free(p_true);
64 eina_value_free(p_false); 74 eina_value_free(p_false);
65 } 75 }
76 all[i] = EINA_FUTURE_SENTINEL;
66 77
67 ecore_main_loop_quit(); 78 return eina_future_as_value(eina_future_all_array(all));
79}
80
81static Eina_Value
82_children_odd_even_ready(Eo *model, void *data EINA_UNUSED, const Eina_Value v EINA_UNUSED)
83{
84 return eina_future_as_value(efl_model_children_slice_get(model, 0, child_number));
85}
86
87static Eina_Value
88_children_odd_even_check(Eo *model, void *data EINA_UNUSED, const Eina_Value v)
89{
90 unsigned int i, len;
91 Efl_Model *child, *first_child = NULL;
92
93 EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
94 {
95 Eina_Value *p_odd_even = NULL;
96 Eina_Value *p_int = NULL;
97 Eina_Bool v_odd_even = EINA_TRUE;
98 int v_int = -1;
99
100 if (!first_child) first_child = child;
101
102 p_int = efl_model_property_get(child, "test_p_int");
103 p_odd_even = efl_model_property_get(child, "test_odd_even");
104
105 fail_if(!eina_value_bool_get(p_odd_even, &v_odd_even));
106 fail_if(!eina_value_int_get(p_int, &v_int));
107
108 fail_if(v_int & 0x1 ? !v_odd_even : v_odd_even);
109
110 eina_value_free(p_int);
111 eina_value_free(p_odd_even);
112 }
113
114 efl_model_child_del(model, first_child);
115
116 return eina_future_as_value(efl_model_children_slice_get(model, 0, child_number - 1));
117}
118
119static Eina_Value
120_children_odd_even_check_after_removal(Eo *model EINA_UNUSED, void *data EINA_UNUSED,
121 const Eina_Value v)
122{
123 unsigned int i, len;
124 Efl_Model *child;
125
126 EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
127 {
128 Eina_Value *p_odd_even = NULL;
129 Eina_Value *p_int = NULL;
130 Eina_Bool v_odd_even = EINA_TRUE;
131 int v_int = -1;
132
133 p_int = efl_model_property_get(child, "test_p_int");
134 p_odd_even = efl_model_property_get(child, "test_odd_even");
135
136 fail_if(!eina_value_bool_get(p_odd_even, &v_odd_even));
137 fail_if(!eina_value_int_get(p_int, &v_int));
138
139 fail_if(v_int & 0x1 ? !v_odd_even : v_odd_even);
140 fail_if(v_int != base_ints[i + 1]);
141
142 eina_value_free(p_int);
143 eina_value_free(p_odd_even);
144 }
68 145
69 return v; 146 return v;
70} 147}
71 148
149static Eina_Value
150_assert_on_error(Eo *o EINA_UNUSED, void *data EINA_UNUSED, Eina_Error error)
151{
152 ck_abort_msg("Assert on error triggered duing Boolean Model test with error '%s'.\n",
153 eina_error_msg_get(error));
154 return eina_value_error_init(error);
155}
156
72EFL_START_TEST(efl_test_boolean_model) 157EFL_START_TEST(efl_test_boolean_model)
73{ 158{
74 Efl_Generic_Model *base_model, *child; 159 Efl_Generic_Model *base_model, *child;
@@ -91,13 +176,26 @@ EFL_START_TEST(efl_test_boolean_model)
91 } 176 }
92 177
93 model = efl_add_ref(EFL_BOOLEAN_MODEL_CLASS, efl_main_loop_get(), 178 model = efl_add_ref(EFL_BOOLEAN_MODEL_CLASS, efl_main_loop_get(),
94 efl_ui_view_model_set(efl_added, base_model), 179 efl_ui_view_model_set(efl_added, base_model),
95 efl_boolean_model_boolean_add(efl_added, "test_p_true", EINA_TRUE), 180 efl_boolean_model_boolean_add(efl_added, "test_p_true", EINA_TRUE),
96 efl_boolean_model_boolean_add(efl_added, "test_p_false", EINA_FALSE)); 181 efl_boolean_model_boolean_add(efl_added, "test_p_false", EINA_FALSE),
182 efl_boolean_model_boolean_add(efl_added, "test_odd_even", EINA_FALSE));
97 ck_assert(!!model); 183 ck_assert(!!model);
98 184
99 future = efl_model_children_slice_get(model, 0, efl_model_children_count_get(model)); 185 future = efl_model_children_slice_get(model, 0, efl_model_children_count_get(model));
100 eina_future_then(future, _children_slice_get_then, NULL, NULL); 186 future = efl_future_then(model, future,
187 .success = _children_slice_get_then,
188 .success_type = EINA_VALUE_TYPE_ARRAY);
189 future = efl_future_then(model, future,
190 .success = _children_odd_even_ready,
191 .success_type = EINA_VALUE_TYPE_ARRAY);
192 future = efl_future_then(model, future,
193 .success = _children_odd_even_check,
194 .success_type = EINA_VALUE_TYPE_ARRAY);
195 future = efl_future_then(model, future,
196 .success = _children_odd_even_check_after_removal,
197 .success_type = EINA_VALUE_TYPE_ARRAY);
198 future = efl_future_then(model, future, .error = _assert_on_error, .free = _cleanup);
101 199
102 ecore_main_loop_begin(); 200 ecore_main_loop_begin();
103} 201}
@@ -303,12 +401,6 @@ _check_index(Eo *o EINA_UNUSED, void *data EINA_UNUSED, const Eina_Value v)
303 return v; 401 return v;
304} 402}
305 403
306static void
307_cleanup(Eo *o EINA_UNUSED, void *data EINA_UNUSED, const Eina_Future *dead_future EINA_UNUSED)
308{
309 ecore_main_loop_quit();
310}
311
312EFL_START_TEST(efl_test_filter_model) 404EFL_START_TEST(efl_test_filter_model)
313{ 405{
314 Efl_Generic_Model *base_model, *child; 406 Efl_Generic_Model *base_model, *child;