summaryrefslogtreecommitdiff
path: root/src/tests/ecore/ecore_test_promise.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-11-07 10:47:31 -0800
committerCedric BAIL <cedric@osg.samsung.com>2016-11-07 10:47:31 -0800
commitaf3788439ba74ae38a0ba1c70372e4b0ec80ce9f (patch)
treefab4b6ebb0c28d92e74034ef3be902fa2f255b46 /src/tests/ecore/ecore_test_promise.c
parente1e28ce32062d83b95620c854bbc8c70e48b305b (diff)
ecore: remove tests for ecore_thread_promise_run.
Diffstat (limited to 'src/tests/ecore/ecore_test_promise.c')
-rw-r--r--src/tests/ecore/ecore_test_promise.c279
1 files changed, 0 insertions, 279 deletions
diff --git a/src/tests/ecore/ecore_test_promise.c b/src/tests/ecore/ecore_test_promise.c
index 32a9018..c7176d2 100644
--- a/src/tests/ecore/ecore_test_promise.c
+++ b/src/tests/ecore/ecore_test_promise.c
@@ -6,186 +6,6 @@
6#include "ecore_suite.h" 6#include "ecore_suite.h"
7#include <time.h> 7#include <time.h>
8 8
9void promised_thread(const void* data EINA_UNUSED, Eina_Promise_Owner* promise, Ecore_Thread* thread EINA_UNUSED)
10{
11 eina_promise_owner_value_set(promise, NULL, NULL);
12}
13
14void promise_callback(void* data EINA_UNUSED, void* value EINA_UNUSED)
15{
16 ecore_main_loop_quit();
17}
18
19START_TEST(ecore_test_promise)
20{
21 Eina_Promise* promise;
22
23 ecore_init();
24
25 ecore_thread_promise_run(&promised_thread, NULL, NULL, &promise);
26 eina_promise_then(promise, &promise_callback, NULL, NULL);
27
28 ecore_main_loop_begin();
29
30 ecore_shutdown();
31}
32END_TEST
33
34void promise_error_thread(const void* data EINA_UNUSED, Eina_Promise_Owner* promise, Ecore_Thread* thread EINA_UNUSED)
35{
36 eina_promise_owner_error_set(promise, ENOMEM);
37}
38
39void promise_error_callback(void* data EINA_UNUSED, Eina_Error error)
40{
41 ck_assert(error == ENOMEM);
42 ecore_main_loop_quit();
43}
44
45START_TEST(ecore_test_promise_error)
46{
47 Eina_Promise* promise;
48
49 ecore_init();
50
51 ecore_thread_promise_run(&promise_error_thread, NULL, NULL, &promise);
52 eina_promise_then(promise, NULL, &promise_error_callback, NULL);
53
54 ecore_main_loop_begin();
55
56 ecore_shutdown();
57}
58END_TEST
59
60START_TEST(ecore_test_promise_all)
61{
62 Eina_Promise* promise;
63 Eina_Promise* first[2] = { NULL, NULL };
64
65 ecore_init();
66
67 ecore_thread_promise_run(&promised_thread, NULL, NULL, &first[0]);
68 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
69 eina_promise_then(promise, &promise_callback, NULL, NULL);
70
71 ecore_main_loop_begin();
72
73 ecore_shutdown();
74}
75END_TEST
76
77void promise_callback2(void* data, void* value EINA_UNUSED)
78{
79 if(++(*(int*)data) == 2)
80 ecore_main_loop_quit();
81}
82
83START_TEST(ecore_test_promise_all_then_then)
84{
85 Eina_Promise* promise;
86 Eina_Promise* first[2] = { NULL, NULL };
87
88 ecore_init();
89
90 int i = 0;
91
92 ecore_thread_promise_run(&promised_thread, NULL, NULL, &first[0]);
93 eina_promise_then(first[0], &promise_callback2, NULL, &i);
94 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
95 eina_promise_then(promise, &promise_callback2, NULL, &i);
96
97 ecore_main_loop_begin();
98
99 ecore_shutdown();
100}
101END_TEST
102
103struct sync_data
104{
105 Eina_Lock lock;
106 Eina_Condition cond;
107 Eina_Bool var;
108};
109
110void promised_exit_thread(struct sync_data* data EINA_UNUSED, Eina_Promise_Owner* promise, Ecore_Thread* thread EINA_UNUSED)
111{
112 eina_promise_owner_value_set(promise, NULL, NULL);
113 eina_lock_take(&data->lock);
114 data->var = EINA_TRUE;
115 eina_condition_broadcast(&data->cond);
116 eina_lock_release(&data->lock);
117}
118
119static void _ecore_test_promise_then_after_thread_finished_main_cb()
120{
121 Eina_Promise* promise;
122 Ecore_Thread* thread;
123 struct sync_data data;
124
125 data.var = EINA_FALSE;
126 eina_lock_new(&data.lock);
127 eina_condition_new(&data.cond, &data.lock);
128
129 thread = ecore_thread_promise_run((Ecore_Thread_Promise_Cb)&promised_exit_thread, NULL, &data, &promise);
130
131 eina_lock_take(&data.lock);
132 while(!data.var)
133 {
134 eina_condition_wait(&data.cond);
135 }
136 eina_lock_release(&data.lock);
137 eina_promise_then(promise, &promise_callback, NULL, NULL);
138
139 while(ecore_thread_wait(thread, 1.0) != EINA_TRUE); // join thread
140}
141
142START_TEST(ecore_test_promise_then_after_thread_finished)
143{
144 ecore_init();
145
146 ecore_job_add(&_ecore_test_promise_then_after_thread_finished_main_cb, NULL);
147 ecore_main_loop_begin();
148
149 ecore_shutdown();
150}
151END_TEST
152
153static void _ecore_test_promise_then_after_thread_finished_all_main_cb()
154{
155 Eina_Promise* first[] = {NULL, NULL};
156 Ecore_Thread* thread;
157 Eina_Promise* promise;
158 struct sync_data data;
159
160 data.var = EINA_FALSE;
161 eina_lock_new(&data.lock);
162 eina_condition_new(&data.cond, &data.lock);
163
164 thread = ecore_thread_promise_run((Ecore_Thread_Promise_Cb)&promised_exit_thread, NULL, &data, &first[0]);
165 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
166
167 eina_lock_take(&data.lock);
168 while(!data.var)
169 {
170 eina_condition_wait(&data.cond);
171 }
172 eina_lock_release(&data.lock);
173 eina_promise_then(promise, &promise_callback, NULL, NULL);
174
175 while(ecore_thread_wait(thread, 1.0) != EINA_TRUE); // join thread
176}
177
178START_TEST(ecore_test_promise_then_after_thread_finished_all)
179{
180 ecore_init();
181
182 ecore_job_add(&_ecore_test_promise_then_after_thread_finished_all_main_cb, NULL);
183 ecore_main_loop_begin();
184
185 ecore_shutdown();
186}
187END_TEST
188
189static void 9static void
190_ecore_test_promise_normal_lifetime_cb(void* data EINA_UNUSED, void* value EINA_UNUSED) 10_ecore_test_promise_normal_lifetime_cb(void* data EINA_UNUSED, void* value EINA_UNUSED)
191{ 11{
@@ -285,97 +105,6 @@ START_TEST(ecore_test_promise_immediate_set_lifetime_all)
285} 105}
286END_TEST 106END_TEST
287 107
288struct _condition_var
289{
290 Eina_Lock lock;
291 Eina_Condition condvar;
292 Eina_Bool boolean;
293};
294typedef struct _condition_var _condition_var;
295
296static void promise_cancel_thread(const void* data, Eina_Promise_Owner* promise EINA_UNUSED, Ecore_Thread* thread EINA_UNUSED)
297{
298 _condition_var* v = (void*)data;
299
300 eina_lock_take(&v->lock);
301 while(!v->boolean)
302 eina_condition_wait(&v->condvar);
303 eina_lock_release(&v->lock);
304}
305
306static void _cancel_callback(const void* data, Eina_Promise_Owner* promise, Ecore_Thread* thread EINA_UNUSED)
307{
308 _condition_var* v = (void*)data;
309
310 eina_lock_take(&v->lock);
311 v->boolean = EINA_TRUE;
312 eina_condition_broadcast(&v->condvar);
313 eina_lock_release(&v->lock);
314
315 eina_promise_owner_value_set(promise, NULL, NULL);
316}
317
318static void _cancel_promise_callback(void* data EINA_UNUSED, Eina_Error value)
319{
320 ck_assert(value == EINA_ERROR_PROMISE_CANCEL);
321 ecore_main_loop_quit();
322}
323
324START_TEST(ecore_test_promise_cancel_promise)
325{
326 _condition_var v = {.boolean = EINA_FALSE};
327 Eina_Promise* promise;
328
329 ecore_init();
330
331 eina_lock_new(&v.lock);
332 eina_condition_new(&v.condvar, &v.lock);
333
334 ecore_thread_promise_run(&promise_cancel_thread, &_cancel_callback, &v, &promise);
335 eina_promise_then(promise, NULL, &_cancel_promise_callback, NULL);
336
337 eina_promise_cancel(promise);
338
339 ecore_main_loop_begin();
340
341
342 eina_condition_free(&v.condvar);
343 eina_lock_free(&v.lock);
344 ecore_shutdown();
345}
346END_TEST
347
348static void promise_progress_thread(const void* data EINA_UNUSED,
349 Eina_Promise_Owner* promise, Ecore_Thread* thread EINA_UNUSED)
350{
351 void* v = (void*)1;
352 eina_promise_owner_progress(promise, v);
353 // Release the promise to avoid leaks
354 eina_promise_owner_value_set(promise, NULL, NULL);
355}
356
357static void _progress_callback(void* data EINA_UNUSED, void* value)
358{
359 ck_assert(value == (void*)1);
360 ecore_main_loop_quit();
361}
362
363START_TEST(ecore_test_promise_progress_promise)
364{
365 Eina_Promise* promise;
366
367 ecore_init();
368
369 ecore_thread_promise_run(&promise_progress_thread, NULL, NULL, &promise);
370
371 eina_promise_progress_cb_add(promise, &_progress_callback, NULL, NULL);
372
373 ecore_main_loop_begin();
374
375 ecore_shutdown();
376}
377END_TEST
378
379typedef struct _Future_Ok Future_Ok; 108typedef struct _Future_Ok Future_Ok;
380struct _Future_Ok 109struct _Future_Ok
381{ 110{
@@ -1231,18 +960,10 @@ END_TEST
1231 960
1232void ecore_test_ecore_promise(TCase *tc) 961void ecore_test_ecore_promise(TCase *tc)
1233{ 962{
1234 tcase_add_test(tc, ecore_test_promise);
1235 tcase_add_test(tc, ecore_test_promise_error);
1236 tcase_add_test(tc, ecore_test_promise_all);
1237 tcase_add_test(tc, ecore_test_promise_all_then_then);
1238 tcase_add_test(tc, ecore_test_promise_then_after_thread_finished);
1239 tcase_add_test(tc, ecore_test_promise_then_after_thread_finished_all);
1240 tcase_add_test(tc, ecore_test_promise_normal_lifetime); 963 tcase_add_test(tc, ecore_test_promise_normal_lifetime);
1241 tcase_add_test(tc, ecore_test_promise_normal_lifetime_all); 964 tcase_add_test(tc, ecore_test_promise_normal_lifetime_all);
1242 tcase_add_test(tc, ecore_test_promise_immediate_set_lifetime); 965 tcase_add_test(tc, ecore_test_promise_immediate_set_lifetime);
1243 tcase_add_test(tc, ecore_test_promise_immediate_set_lifetime_all); 966 tcase_add_test(tc, ecore_test_promise_immediate_set_lifetime_all);
1244 tcase_add_test(tc, ecore_test_promise_cancel_promise);
1245 tcase_add_test(tc, ecore_test_promise_progress_promise);
1246 967
1247 tcase_add_test(tc, efl_test_promise_future_success); 968 tcase_add_test(tc, efl_test_promise_future_success);
1248 tcase_add_test(tc, efl_test_promise_future_cancel); 969 tcase_add_test(tc, efl_test_promise_future_cancel);