summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2018-02-09 14:51:08 -0800
committerCedric BAIL <cedric@osg.samsung.com>2018-05-01 10:39:01 -0700
commit5351720b66dcdb59c88a93cef61cb9449df7907d (patch)
treee194d9997f94d12c8737b16c7fd16fbe595c6fb5 /src
parentbf2e65a38d0af1189639270e2983e3cdf39c8158 (diff)
ecore: update Ecore Efl.Model tests.
Diffstat (limited to 'src')
-rw-r--r--src/tests/efl/efl_test_model_composite.c216
-rw-r--r--src/tests/efl/efl_test_model_container.c107
2 files changed, 105 insertions, 218 deletions
diff --git a/src/tests/efl/efl_test_model_composite.c b/src/tests/efl/efl_test_model_composite.c
index 6d958162b8..7e9932d02d 100644
--- a/src/tests/efl/efl_test_model_composite.c
+++ b/src/tests/efl/efl_test_model_composite.c
@@ -25,148 +25,77 @@
25#include <Efl.h> 25#include <Efl.h>
26#include <Ecore.h> 26#include <Ecore.h>
27 27
28typedef struct _Test_Data
29{
30 Eina_Bool success_flag;
31 unsigned int child_count;
32} Test_Data;
33
34typedef struct _Test_Child_Data
35{
36 Test_Data *tdata;
37 unsigned int idx;
38} Test_Child_Data;
39
40const int child_number = 3; 28const int child_number = 3;
41const int base_ints[] = { 41, 42, 43 }; 29const int base_ints[] = { 41, 42, 43 };
42const Eina_Bool base_selections[] = { EINA_FALSE, EINA_FALSE, EINA_TRUE }; 30const Eina_Bool base_selections[] = { EINA_FALSE, EINA_FALSE, EINA_TRUE };
43 31
44static void 32static Eina_Value
45_future_error_then(void *data EINA_UNUSED, Efl_Event const* event EINA_UNUSED) 33_children_slice_get_then(void *data EINA_UNUSED,
46{ 34 const Eina_Value v,
47 fprintf(stderr, "Promise failed!\n"); fflush(stderr); 35 const Eina_Future *dead_future EINA_UNUSED)
48 ck_abort_msg("Promise failed");
49}
50
51static void
52_property_get_then(void *data, Efl_Event const *event)
53{
54 Test_Child_Data *t = data;
55 Eina_Accessor *value_itt = (Eina_Accessor*)((Efl_Future_Event_Success*)event->info)->value;
56 int v_int = 0;
57 Eina_Bool v_bool = EINA_FALSE;
58
59#define _value_get_and_compare(it, i, var, cmp) \
60 do { \
61 Eina_Value *vvv = NULL; \
62 if (!eina_accessor_data_get(it, i, (void **)&vvv) || !vvv || \
63 !eina_value_get(vvv, &var) || var != cmp) \
64 { \
65 fprintf(stderr, "Could not get value!\n"); fflush(stderr); \
66 ck_abort_msg("Could not get value"); \
67 return; \
68 } \
69 } while(0)
70
71 _value_get_and_compare(value_itt, 0, v_int, base_ints[t->idx]);
72 _value_get_and_compare(value_itt, 1, v_bool, EINA_TRUE);
73 _value_get_and_compare(value_itt, 2, v_bool, EINA_FALSE);
74
75 t->tdata->child_count++;
76 if (t->tdata->child_count == 3)
77 t->tdata->success_flag = EINA_TRUE;
78
79#undef _value_get_and_compare
80}
81
82static void
83_selection_property_get_then(void *data, Efl_Event const *event)
84{
85 Test_Child_Data *t = data;
86 Eina_Accessor *value_itt = (Eina_Accessor*)((Efl_Future_Event_Success*)event->info)->value;
87 int v_int = 0;
88 Eina_Bool v_bool = EINA_FALSE;
89
90
91#define EFL_TEST_value_get_and_compare(it, i, var, cmp) \
92 do { \
93 Eina_Value *vvv = NULL; \
94 if (!eina_accessor_data_get(it, i, (void **)&vvv) || !vvv || \
95 !eina_value_get(vvv, &var)) \
96 { \
97 fprintf(stderr, "Could not get value!\n"); fflush(stderr); \
98 ck_abort_msg("Could not get value"); \
99 return; \
100 } \
101 else if(var != cmp) \
102 { \
103 fprintf(stderr, "Value did not match!\n"); fflush(stderr); \
104 ck_abort_msg("Value did not match"); \
105 return; \
106 } \
107 else \
108 fprintf(stderr, "Value matched\n"); fflush(stderr); \
109 } while(0)
110
111 EFL_TEST_value_get_and_compare(value_itt, 0, v_bool, base_selections[t->idx]);
112 EFL_TEST_value_get_and_compare(value_itt, 1, v_int, base_ints[t->idx]);
113
114 t->tdata->child_count++;
115 if (t->tdata->child_count == 3)
116 t->tdata->success_flag = EINA_TRUE;
117
118#undef EFL_TEST_value_get_and_compare
119}
120
121static void
122_children_slice_get_then(void *data, Efl_Event const* event)
123{ 36{
124 Eina_Accessor *children = (Eina_Accessor *)((Efl_Future_Event_Success*)event->info)->value; 37 unsigned int i, len;
125 Efl_Model *child; 38 Efl_Model *child;
126 Test_Child_Data *t;
127 unsigned int i = 0;
128 39
129 EINA_ACCESSOR_FOREACH(children, i, child) 40 fail_if(eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY);
130 {
131 Efl_Future *futures[3] = {NULL,};
132 Efl_Future *future_all = NULL;
133 41
134 futures[0] = efl_model_property_get(child, "test_p_int"); 42 EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
135 futures[1] = efl_model_property_get(child, "test_p_true"); 43 {
136 futures[2] = efl_model_property_get(child, "test_p_false"); 44 Eina_Value *p_int = NULL;
45 Eina_Value *p_true = NULL;
46 Eina_Value *p_false = NULL;
47 int v_int = 0;
48 Eina_Bool v_true = EINA_FALSE;
49 Eina_Bool v_false = EINA_TRUE;
50
51 p_int = efl_model_property_get(child, "test_p_int");
52 p_true = efl_model_property_get(child, "test_p_true");
53 p_false = efl_model_property_get(child, "test_p_false");
54
55 eina_value_get(p_int, &v_int);
56 eina_value_get(p_true, &v_true);
57 eina_value_get(p_false, &v_false);
58
59 fail_if(v_int != base_ints[i]);
60 fail_if(v_true != EINA_TRUE);
61 fail_if(v_false != EINA_FALSE);
62 }
137 63
138 future_all = efl_future_all(futures[0], futures[1], futures[2]); 64 ecore_main_loop_quit();
139 65
140 t = calloc(1, sizeof(Test_Child_Data)); 66 return v;
141 t->tdata = data;
142 t->idx = i;
143 efl_future_then(future_all, _property_get_then, _future_error_then, NULL, t);
144 }
145} 67}
146 68
147static void 69static Eina_Value
148_selection_children_slice_get_then(void *data, Efl_Event const* event) 70_selection_children_slice_get_then(void *data EINA_UNUSED,
71 const Eina_Value v,
72 const Eina_Future *dead_future EINA_UNUSED)
149{ 73{
150 Eina_Accessor *children = (Eina_Accessor *)((Efl_Future_Event_Success*)event->info)->value; 74 unsigned int i, len;
151 Efl_Model *child; 75 Efl_Model *child = NULL;
152 Test_Child_Data *t; 76
153 unsigned int i = 0; 77 fail_if(eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY);
154 78
155 EINA_ACCESSOR_FOREACH(children, i, child) 79 EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
156 { 80 {
157 Efl_Future *futures[2] = {NULL,}; 81 Eina_Value *p_int = NULL;
158 Efl_Future *future_all = NULL; 82 Eina_Value *p_bool = NULL;
83 int v_int = 0;
84 Eina_Bool v_bool = EINA_FALSE;
159 85
160 futures[0] = efl_model_property_get(child, "selected"); 86 p_bool = efl_model_property_get(child, "selected");
161 futures[1] = efl_model_property_get(child, "test_p_int"); 87 p_int = efl_model_property_get(child, "test_p_int");
162 88
163 future_all = efl_future_all(futures[0], futures[1]); 89 eina_value_get(p_bool, &v_bool);
90 eina_value_get(p_int, &v_int);
164 91
165 t = calloc(1, sizeof(Test_Child_Data)); 92 fail_if(v_bool != base_selections[i]);
166 t->tdata = data; 93 fail_if(v_int != base_ints[i]);
167 t->idx = i;
168 efl_future_then(future_all, _selection_property_get_then, _future_error_then, NULL, t);
169 } 94 }
95
96 ecore_main_loop_quit();
97
98 return v;
170} 99}
171 100
172EFL_START_TEST(efl_test_model_composite_boolean) 101EFL_START_TEST(efl_test_model_composite_boolean)
@@ -175,8 +104,7 @@ EFL_START_TEST(efl_test_model_composite_boolean)
175 int i; 104 int i;
176 Eina_Value v; 105 Eina_Value v;
177 Efl_Model_Composite_Boolean *model; 106 Efl_Model_Composite_Boolean *model;
178 Test_Data *tdata; 107 Eina_Future *future;
179 Efl_Future *future;
180 108
181 eina_value_setup(&v, EINA_VALUE_TYPE_INT); 109 eina_value_setup(&v, EINA_VALUE_TYPE_INT);
182 110
@@ -193,28 +121,33 @@ EFL_START_TEST(efl_test_model_composite_boolean)
193 121
194 model = efl_add(EFL_MODEL_COMPOSITE_BOOLEAN_CLASS, efl_main_loop_get(), 122 model = efl_add(EFL_MODEL_COMPOSITE_BOOLEAN_CLASS, efl_main_loop_get(),
195 efl_ui_view_model_set(efl_added, base_model), 123 efl_ui_view_model_set(efl_added, base_model),
196 efl_model_composite_boolean_property_add(efl_added, "test_p_true", EINA_TRUE), 124 efl_model_composite_boolean_add(efl_added, "test_p_true", EINA_TRUE),
197 efl_model_composite_boolean_property_add(efl_added, "test_p_false", EINA_FALSE)); 125 efl_model_composite_boolean_add(efl_added, "test_p_false", EINA_FALSE));
198 ck_assert(!!model); 126 ck_assert(!!model);
199 127
200 tdata = calloc(1, sizeof(Test_Data)); 128 future = efl_model_children_slice_get(model, 0, efl_model_children_count_get(model));
201 future = efl_model_children_slice_get(model, 0, 0); 129 eina_future_then(future, _children_slice_get_then, NULL);
202 efl_future_then(future, _children_slice_get_then, _future_error_then, NULL, tdata);
203
204 while (!tdata->success_flag) ecore_main_loop_iterate();
205 130
206 ck_assert(tdata->success_flag); 131 ecore_main_loop_begin();
207} 132}
208EFL_END_TEST 133EFL_END_TEST
209 134
135static Eina_Value
136_wait_propagate(void *data EINA_UNUSED,
137 const Eina_Value v,
138 const Eina_Future *dead_future EINA_UNUSED)
139{
140 ecore_main_loop_quit();
141 return v;
142}
143
210EFL_START_TEST(efl_test_model_composite_selection) 144EFL_START_TEST(efl_test_model_composite_selection)
211{ 145{
212 Efl_Model_Item *base_model, *child; 146 Efl_Model_Item *base_model, *child;
213 int i; 147 int i;
214 Eina_Value v; 148 Eina_Value v;
215 Efl_Model_Composite_Selection *model; 149 Efl_Model_Composite_Selection *model;
216 Test_Data *tdata; 150 Eina_Future *future;
217 Efl_Future *future;
218 151
219 eina_value_setup(&v, EINA_VALUE_TYPE_INT); 152 eina_value_setup(&v, EINA_VALUE_TYPE_INT);
220 153
@@ -232,15 +165,14 @@ EFL_START_TEST(efl_test_model_composite_selection)
232 model = efl_add(EFL_MODEL_COMPOSITE_SELECTION_CLASS, efl_main_loop_get(), 165 model = efl_add(EFL_MODEL_COMPOSITE_SELECTION_CLASS, efl_main_loop_get(),
233 efl_ui_view_model_set(efl_added, base_model)); 166 efl_ui_view_model_set(efl_added, base_model));
234 ck_assert(!!model); 167 ck_assert(!!model);
235 efl_model_composite_selection_select(model, 2); 168 future = efl_model_property_set(model, "selected", eina_value_int_new(2));
236 169 eina_future_then(future, _wait_propagate, NULL);
237 tdata = calloc(1, sizeof(Test_Data)); 170 ecore_main_loop_begin();
238 future = efl_model_children_slice_get(model, 0, 0);
239 efl_future_then(future, _selection_children_slice_get_then, _future_error_then, NULL, tdata);
240 171
241 while (!tdata->success_flag) ecore_main_loop_iterate(); 172 future = efl_model_children_slice_get(model, 0, efl_model_children_count_get(model));
173 eina_future_then(future, _selection_children_slice_get_then, NULL);
242 174
243 ck_assert(tdata->success_flag); 175 ecore_main_loop_begin();
244} 176}
245EFL_END_TEST 177EFL_END_TEST
246 178
diff --git a/src/tests/efl/efl_test_model_container.c b/src/tests/efl/efl_test_model_container.c
index aee7dab078..50a2fd401a 100644
--- a/src/tests/efl/efl_test_model_container.c
+++ b/src/tests/efl/efl_test_model_container.c
@@ -25,95 +25,57 @@
25#include <Efl.h> 25#include <Efl.h>
26#include <Ecore.h> 26#include <Ecore.h>
27 27
28typedef struct _Test_Container_Data {
29 int item_count;
30 Eina_Bool pass_flag;
31 Eina_Bool fail_flag;
32} Test_Container_Data;
33
34typedef struct _Test_Container_Item_Data { 28typedef struct _Test_Container_Item_Data {
35 Test_Container_Data* test_data;
36 unsigned int index; 29 unsigned int index;
37} Test_Container_Item_Data; 30} Test_Container_Item_Data;
38 31
39const int base_int[7] = {10, 11, 12, 13, 14, 0, 16}; 32const int base_int[7] = {10, 11, 12, 13, 14, 0, 16};
40const char * const base_str[7] = {"A", "B", "C", "D", "E", "", "GH"}; 33const char * const base_str[7] = {"A", "B", "C", "D", "E", "", "GH"};
41 34
42static void 35static Eina_Value
43_future_error_then(void *data EINA_UNUSED, Efl_Event const* event EINA_UNUSED) 36_children_slice_future_then(void *data EINA_UNUSED,
37 const Eina_Value v, const Eina_Future *dead_future EINA_UNUSED)
44{ 38{
45 ck_abort_msg("Promise failed"); 39 unsigned int i, len;
46} 40 Efl_Model *child = NULL;
47 41
48static void 42 fail_if(eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY);
49_container_property_get_then(void *data, Efl_Event const *event)
50{
51 Eina_Accessor *value_itt = (Eina_Accessor*)((Efl_Future_Event_Success*)event->info)->value;
52 Test_Container_Item_Data *test_item_data = data;
53 Eina_Value *value_int = NULL;
54 Eina_Value *value_str = NULL;
55 int cmp_int = 0;
56 const char *cmp_str = NULL;
57 43
58 test_item_data->test_data->item_count++; 44 EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
59
60 if (!value_itt || !eina_accessor_data_get(value_itt, 0, (void**)&value_int) ||
61 !eina_accessor_data_get(value_itt, 1, (void**)&value_str))
62 { 45 {
63 test_item_data->test_data->fail_flag = EINA_TRUE; 46 Eina_Value *value_int = NULL;
64 ecore_main_loop_quit(); 47 Eina_Value *value_str = NULL;
65 return; 48 const char *cmp_str = NULL;
66 } 49 int cmp_int = 0;
67 50
68 eina_value_get(value_int, &cmp_int); 51 value_int = efl_model_property_get(child, "test_p_int");
69 eina_value_get(value_str, &cmp_str); 52 value_str = efl_model_property_get(child, "test_p_str");
70 53
71 if (cmp_int != base_int[test_item_data->index] || 54 fail_if(eina_value_type_get(value_int) != EINA_VALUE_TYPE_INT);
72 strcmp(cmp_str, base_str[test_item_data->index]) != 0) 55 fail_if(eina_value_type_get(value_str) != EINA_VALUE_TYPE_STRING);
73 {
74 test_item_data->test_data->fail_flag = EINA_TRUE;
75 }
76
77 if (test_item_data->test_data->item_count == 7)
78 {
79 test_item_data->test_data->pass_flag = EINA_TRUE;
80 }
81 ecore_main_loop_quit();
82}
83 56
84static void 57 eina_value_get(value_int, &cmp_int);
85_children_slice_future_then(void *data, Efl_Event const *event) 58 eina_value_get(value_str, &cmp_str);
86{
87 Eina_Accessor *children_accessor = (Eina_Accessor *)((Efl_Future_Event_Success*)event->info)->value;
88 unsigned int i = 0;
89 Efl_Model *child;
90 59
91 if (children_accessor) 60 if (cmp_int != base_int[i] ||
92 { 61 strcmp(cmp_str, base_str[i]) != 0)
93 EINA_ACCESSOR_FOREACH(children_accessor, i, child) 62 {
94 { 63 abort();
95 Efl_Future *futures[3] = {NULL,}; 64 }
96 Efl_Future *future_all = NULL; 65 }
97 Test_Container_Item_Data *test_item_data = calloc(1, sizeof(Test_Container_Item_Data)); 66 fprintf(stderr, "len: %i\n", len);
98 67
99 test_item_data->test_data = data; 68 fail_if(len != 7);
100 test_item_data->index = i;
101 69
102 futures[0] = efl_model_property_get(child, "test_p_int"); 70 ecore_main_loop_quit();
103 futures[1] = efl_model_property_get(child, "test_p_str");
104 71
105 future_all = efl_future_all(futures[0], futures[1]); 72 return v;
106 efl_future_then(future_all, _container_property_get_then, _future_error_then, NULL, test_item_data);
107 }
108 }
109} 73}
110 74
111
112EFL_START_TEST(efl_test_model_container_values) 75EFL_START_TEST(efl_test_model_container_values)
113{ 76{
114 Efl_Model_Container* model; 77 Efl_Model_Container* model;
115 Efl_Future *future; 78 Eina_Future *future;
116 Test_Container_Data test_data;
117 int **cmp_int; 79 int **cmp_int;
118 const char **cmp_str; 80 const char **cmp_str;
119 int i; 81 int i;
@@ -143,18 +105,11 @@ EFL_START_TEST(efl_test_model_container_values)
143 free(cmp_int); 105 free(cmp_int);
144 free(cmp_str); 106 free(cmp_str);
145 107
146 future = efl_model_children_slice_get(model, 0, 0); 108 future = efl_model_children_slice_get(model, 0, efl_model_children_count_get(model));
147
148 test_data.item_count = 0;
149 test_data.pass_flag = EINA_FALSE;
150 test_data.fail_flag = EINA_FALSE;
151
152 efl_future_then(future, _children_slice_future_then, _future_error_then, NULL, &test_data);
153 109
154 while ((!test_data.pass_flag) && (!test_data.fail_flag)) ecore_main_loop_iterate(); 110 eina_future_then(future, _children_slice_future_then, NULL);
155 111
156 ck_assert(!!test_data.pass_flag); 112 ecore_main_loop_begin();
157 ck_assert(!test_data.fail_flag);
158} 113}
159EFL_END_TEST 114EFL_END_TEST
160 115