summaryrefslogtreecommitdiff
path: root/src/tests/ecore/ecore_test_promise.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-12-16 14:06:02 -0800
committerCedric BAIL <cedric@osg.samsung.com>2016-12-16 14:10:58 -0800
commit2b7a68eb1be1fe4811cf4ed2762475d6328ef385 (patch)
tree6fc292bf961daaab55266966907418f02b4fc05c /src/tests/ecore/ecore_test_promise.c
parent637073813b197b36bacb566af34144576fde3a57 (diff)
ecore: add test for efl_promise_connect.
Diffstat (limited to 'src/tests/ecore/ecore_test_promise.c')
-rw-r--r--src/tests/ecore/ecore_test_promise.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/tests/ecore/ecore_test_promise.c b/src/tests/ecore/ecore_test_promise.c
index 204009551d..944331e12b 100644
--- a/src/tests/ecore/ecore_test_promise.c
+++ b/src/tests/ecore/ecore_test_promise.c
@@ -26,6 +26,29 @@ _then(void *data, const Efl_Event *ev)
26} 26}
27 27
28static void 28static void
29_time_then(void *data, const Efl_Event *ev)
30{
31 Efl_Future_Event_Success *s = ev->info;
32 Future_Ok *value = s->value;
33 Future_Ok *fo = data;
34
35 fail_if(value != fo);
36 fo->then = EINA_TRUE;
37
38 ecore_main_loop_quit();
39}
40
41static void
42_connected_then(void *data, const Efl_Event *ev)
43{
44 Efl_Future_Event_Success *s = ev->info;
45 Efl_Future *f;
46
47 f = efl_loop_timeout(efl_provider_find(ev->object, EFL_LOOP_CLASS), 0.01, data);
48 efl_promise_connect(s->next, f);
49}
50
51static void
29_cancel(void *data, const Efl_Event *ev) 52_cancel(void *data, const Efl_Event *ev)
30{ 53{
31 Efl_Future_Event_Failure *f = ev->info; 54 Efl_Future_Event_Failure *f = ev->info;
@@ -95,6 +118,52 @@ START_TEST(efl_test_promise_future_success)
95} 118}
96END_TEST 119END_TEST
97 120
121// Test value set after then
122START_TEST(efl_test_promise_future_connected)
123{
124 Efl_Promise *p;
125 Efl_Future *chain;
126 Efl_Future *f;
127 Future_Ok fo = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
128 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE;
129 int progress = 7;
130 int value = 42;
131
132 ecore_init();
133
134 p = efl_add(EFL_PROMISE_CLASS, ecore_main_loop_get());
135 fail_if(!p);
136
137 f = efl_promise_future_get(p);
138 fail_if(!f);
139
140 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
141 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
142
143 chain = efl_future_then(f, _connected_then, _cancel, _progress, &fo);
144 fail_if(!chain);
145 fail_if(!efl_future_then(chain, _time_then, _cancel, NULL, &fo));
146
147 fail_if(deadp || deadf);
148
149 efl_promise_progress_set(p, &progress);
150 efl_promise_value_set(p, &value, NULL);
151
152 ecore_main_loop_begin();
153
154 ecore_main_loop_iterate();
155
156 fail_if(!fo.then || fo.cancel || !fo.progress);
157 fail_if(!deadf || deadp);
158
159 efl_del(p);
160
161 fail_if(!deadp);
162
163 ecore_shutdown();
164}
165END_TEST
166
98// Test value set before future_get 167// Test value set before future_get
99START_TEST(efl_test_promise_future_success_before_get) 168START_TEST(efl_test_promise_future_success_before_get)
100{ 169{
@@ -1033,6 +1102,7 @@ void ecore_test_ecore_promise(TCase *tc)
1033{ 1102{
1034 tcase_add_test(tc, efl_test_promise_future_success); 1103 tcase_add_test(tc, efl_test_promise_future_success);
1035 tcase_add_test(tc, efl_test_promise_future_cancel); 1104 tcase_add_test(tc, efl_test_promise_future_cancel);
1105 tcase_add_test(tc, efl_test_promise_future_connected);
1036 tcase_add_test(tc, efl_test_promise_future_chain_success); 1106 tcase_add_test(tc, efl_test_promise_future_chain_success);
1037 tcase_add_test(tc, efl_test_promise_future_chain_cancel); 1107 tcase_add_test(tc, efl_test_promise_future_chain_cancel);
1038 tcase_add_test(tc, efl_test_promise_before_future_success); 1108 tcase_add_test(tc, efl_test_promise_before_future_success);