summaryrefslogtreecommitdiff
path: root/src/tests/ecore/ecore_test_promise.c
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2016-03-08 14:23:57 +0000
committerTom Hacohen <tom@stosb.com>2016-03-08 14:23:57 +0000
commit7d8cd6c40f61537bff5ced41dce62d54cd311eb5 (patch)
tree126f01b4b7886f0d62f15e62c9a6cb10409207e0 /src/tests/ecore/ecore_test_promise.c
parentf1a6ff29567c3db71c7ddd58e90715463ac81af9 (diff)
Revert "ecore: Create Promises"
Reverting this at Felipe's request following my email. There are many things I strongly object to in this commit. I've touched the surface of those on the ML (which doesn't work at the moment), though we need to better discuss it. The gist: 1. dlsym is a really bad hack that is not even needed. 2. I don't see why eo should even be aware of promises. It's not aware of list, hash and etc. 3. The eolian changes were done wrong. This should have been discussed and consulted before done, even if only because of the amount of hacks it includes and the cross-domain (ecore, eo and eolian) nature of it. This reverts commit f9ba80ab33e0b94dad7ec103e6d261a644f7835f.
Diffstat (limited to 'src/tests/ecore/ecore_test_promise.c')
-rw-r--r--src/tests/ecore/ecore_test_promise.c364
1 files changed, 0 insertions, 364 deletions
diff --git a/src/tests/ecore/ecore_test_promise.c b/src/tests/ecore/ecore_test_promise.c
deleted file mode 100644
index 0f003fd..0000000
--- a/src/tests/ecore/ecore_test_promise.c
+++ /dev/null
@@ -1,364 +0,0 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <Ecore.h>
6#include "ecore_suite.h"
7#include <time.h>
8
9void promised_thread(const void* data EINA_UNUSED, Ecore_Promise* promise)
10{
11 fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, __func__); fflush(stderr);
12 ecore_promise_value_set(promise, NULL);
13}
14
15void promise_callback(void* data EINA_UNUSED, void* value EINA_UNUSED)
16{
17 fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, __func__); fflush(stderr);
18 ecore_main_loop_quit();
19}
20
21START_TEST(ecore_test_promise)
22{
23 ecore_init();
24 fprintf(stderr, "%s:%d %s ---------- BEGIN test\n", __FILE__, __LINE__, __func__); fflush(stderr);
25
26 fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, __func__); fflush(stderr);
27 Ecore_Promise* promise = ecore_promise_thread_run(&promised_thread, NULL, 0);
28 ecore_promise_then(promise, &promise_callback, NULL);
29 fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, __func__); fflush(stderr);
30
31 ecore_main_loop_begin();
32
33 fprintf(stderr, "%s:%d %s ---------- END test\n", __FILE__, __LINE__, __func__); fflush(stderr);
34 ecore_shutdown();
35}
36END_TEST
37
38void promise_error_thread(const void* data EINA_UNUSED, Ecore_Promise* promise)
39{
40 fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, __func__); fflush(stderr);
41 ecore_promise_error_set(promise, EINA_ERROR_OUT_OF_MEMORY);
42}
43
44void promise_error_callback(void* data EINA_UNUSED, void* value EINA_UNUSED)
45{
46 fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, __func__); fflush(stderr);
47 ecore_main_loop_quit();
48}
49
50START_TEST(ecore_test_promise_error)
51{
52 ecore_init();
53 fprintf(stderr, "%s:%d %s ---------- BEGIN test\n", __FILE__, __LINE__, __func__); fflush(stderr);
54
55 fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, __func__); fflush(stderr);
56 Ecore_Promise* promise = ecore_promise_thread_run(&promise_error_thread, NULL, 0);
57 ecore_promise_then(promise, &promise_error_callback, NULL);
58 fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, __func__); fflush(stderr);
59
60 ecore_main_loop_begin();
61
62 fprintf(stderr, "%s:%d %s ---------- END test\n", __FILE__, __LINE__, __func__); fflush(stderr);
63 ecore_shutdown();
64}
65END_TEST
66
67START_TEST(ecore_test_promise_all)
68{
69 ecore_init();
70 fprintf(stderr, "%s:%d %s ---------- BEGIN test\n", __FILE__, __LINE__, __func__); fflush(stderr);
71
72 fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, __func__); fflush(stderr);
73 Ecore_Promise* first[2] = { ecore_promise_thread_run(&promised_thread, NULL, 0), NULL };
74 Ecore_Promise* promise = ecore_promise_all(eina_carray_iterator_new((void**)&first[0]));
75 ecore_promise_then(promise, &promise_callback, NULL);
76 fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, __func__); fflush(stderr);
77
78 ecore_main_loop_begin();
79
80 fprintf(stderr, "%s:%d %s ---------- END test\n", __FILE__, __LINE__, __func__); fflush(stderr);
81 ecore_shutdown();
82}
83END_TEST
84
85void promise_callback2(void* data, void* value EINA_UNUSED)
86{
87 fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, __func__); fflush(stderr);
88 if(++(*(int*)data) == 2)
89 ecore_main_loop_quit();
90}
91
92START_TEST(ecore_test_promise_all_then_then)
93{
94 ecore_init();
95 fprintf(stderr, "%s:%d %s ---------- BEGIN test\n", __FILE__, __LINE__, __func__); fflush(stderr);
96
97 int i = 0;
98
99 fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, __func__); fflush(stderr);
100 Ecore_Promise* first[2] = { ecore_promise_thread_run(&promised_thread, NULL, 0), NULL };
101 ecore_promise_then(first[0], &promise_callback2, &i);
102 Ecore_Promise* promise = ecore_promise_all(eina_carray_iterator_new((void**)&first[0]));
103 ecore_promise_then(promise, &promise_callback2, &i);
104 fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, __func__); fflush(stderr);
105
106 ecore_main_loop_begin();
107
108 fprintf(stderr, "%s:%d %s ---------- END test\n", __FILE__, __LINE__, __func__); fflush(stderr);
109 ecore_shutdown();
110}
111END_TEST
112
113struct sync_data
114{
115 Eina_Lock lock;
116 Eina_Condition cond;
117 Eina_Bool var;
118};
119
120void promised_exit_thread(struct sync_data* data EINA_UNUSED, Ecore_Promise* promise)
121{
122 fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, __func__); fflush(stderr);
123 ecore_promise_value_set(promise, NULL);
124 eina_lock_take(&data->lock);
125 data->var = EINA_TRUE;
126 eina_condition_broadcast(&data->cond);
127 eina_lock_release(&data->lock);
128}
129
130static void _ecore_test_promise_then_after_thread_finished_main_cb()
131{
132 struct sync_data data;
133 data.var = EINA_FALSE;
134 eina_lock_new(&data.lock);
135 eina_condition_new(&data.cond, &data.lock);
136
137 Ecore_Promise* promise = ecore_promise_thread_run((Ecore_Promise_Thread_Cb)&promised_exit_thread, &data, 0);
138
139 eina_lock_take(&data.lock);
140 while(!data.var)
141 {
142 eina_condition_wait(&data.cond);
143 }
144 eina_lock_release(&data.lock);
145 ecore_promise_then(promise, &promise_callback, NULL);
146}
147
148START_TEST(ecore_test_promise_then_after_thread_finished)
149{
150 ecore_init();
151 fprintf(stderr, "%s:%d %s ---------- BEGIN test\n", __FILE__, __LINE__, __func__); fflush(stderr);
152
153 ecore_job_add(&_ecore_test_promise_then_after_thread_finished_main_cb, NULL);
154 ecore_main_loop_begin();
155
156 fprintf(stderr, "%s:%d %s ---------- END test\n", __FILE__, __LINE__, __func__); fflush(stderr);
157 ecore_shutdown();
158}
159END_TEST
160
161static void _ecore_test_promise_then_after_thread_finished_all_main_cb()
162{
163 struct sync_data data;
164 data.var = EINA_FALSE;
165 eina_lock_new(&data.lock);
166 eina_condition_new(&data.cond, &data.lock);
167
168 Ecore_Promise* first[] = {ecore_promise_thread_run((Ecore_Promise_Thread_Cb)&promised_exit_thread, &data, 0), NULL};
169 Ecore_Promise* promise = ecore_promise_all(eina_carray_iterator_new((void**)&first[0]));
170
171 eina_lock_take(&data.lock);
172 while(!data.var)
173 {
174 eina_condition_wait(&data.cond);
175 }
176 eina_lock_release(&data.lock);
177 ecore_promise_then(promise, &promise_callback, NULL);
178}
179
180START_TEST(ecore_test_promise_then_after_thread_finished_all)
181{
182 ecore_init();
183 fprintf(stderr, "%s:%d %s ---------- BEGIN test\n", __FILE__, __LINE__, __func__); fflush(stderr);
184
185 ecore_job_add(&_ecore_test_promise_then_after_thread_finished_all_main_cb, NULL);
186 ecore_main_loop_begin();
187
188 fprintf(stderr, "%s:%d %s ---------- END test\n", __FILE__, __LINE__, __func__); fflush(stderr);
189 ecore_shutdown();
190}
191END_TEST
192
193void promised_block_thread(const void* data EINA_UNUSED, Ecore_Promise* promise)
194{
195 struct timespec v = {.tv_sec = 1, .tv_nsec = 0}, rem;
196 if(nanosleep(&v, &rem) == -1 && errno == EINTR)
197 do
198 {
199 v = rem;
200 }
201 while(nanosleep(&v, &rem) == -1 && errno == EINTR);
202
203 int r = 10;
204 ecore_promise_value_set(promise, &r);
205}
206
207static void
208_ecore_test_promise_blocking_get_quit_cb(void* data EINA_UNUSED)
209{
210 ecore_main_loop_quit();
211}
212
213static void
214_ecore_test_promise_blocking_get_main_cb(void* data EINA_UNUSED)
215{
216 Ecore_Promise* promise = ecore_promise_thread_run(&promised_block_thread, NULL, sizeof(int));
217 const void* value = ecore_promise_value_get(promise);
218 ck_assert(*(int*)value == 10);
219
220 ecore_job_add(&_ecore_test_promise_blocking_get_quit_cb, NULL);
221}
222
223START_TEST(ecore_test_promise_blocking_get)
224{
225 ecore_init();
226 fprintf(stderr, "%s:%d %s ---------- BEGIN test\n", __FILE__, __LINE__, __func__); fflush(stderr);
227
228 ecore_job_add(&_ecore_test_promise_blocking_get_main_cb, NULL);
229 ecore_main_loop_begin();
230
231 fprintf(stderr, "%s:%d %s ---------- END test\n", __FILE__, __LINE__, __func__); fflush(stderr);
232 ecore_shutdown();
233}
234END_TEST
235
236static void
237_ecore_test_promise_blocking_get_all_value_get_cb(Ecore_Promise* promise, Ecore_Thread* thread EINA_UNUSED)
238{
239 Eina_Iterator** iterator = ecore_promise_value_get(promise);
240 int* v;
241 ck_assert(eina_iterator_next(*iterator, (void**)&v));
242 ck_assert(*v == 10);
243 ecore_main_loop_quit();
244}
245
246static void
247_ecore_test_promise_blocking_get_all_main_cb(void* data EINA_UNUSED)
248{
249 Ecore_Promise* first[2] = {ecore_promise_thread_run(&promised_block_thread, NULL, sizeof(int)), NULL};
250 Ecore_Promise* promise = ecore_promise_all(eina_carray_iterator_new((void**)&first[0]));
251
252 ecore_thread_run((Ecore_Thread_Cb)&_ecore_test_promise_blocking_get_all_value_get_cb, NULL, NULL, promise);
253}
254
255START_TEST(ecore_test_promise_blocking_get_all)
256{
257 ecore_init();
258 fprintf(stderr, "%s:%d %s ---------- BEGIN test\n", __FILE__, __LINE__, __func__); fflush(stderr);
259
260 ecore_job_add(&_ecore_test_promise_blocking_get_all_main_cb, NULL);
261 ecore_main_loop_begin();
262
263 fprintf(stderr, "%s:%d %s ---------- END test\n", __FILE__, __LINE__, __func__); fflush(stderr);
264 ecore_shutdown();
265}
266END_TEST
267
268static void
269_ecore_test_promise_normal_lifetime_cb(void* data EINA_UNUSED, void* value EINA_UNUSED)
270{
271 ecore_main_loop_quit();
272}
273
274START_TEST(ecore_test_promise_normal_lifetime)
275{
276 ecore_init();
277 fprintf(stderr, "%s:%d %s ---------- BEGIN test\n", __FILE__, __LINE__, __func__); fflush(stderr);
278
279 Ecore_Promise* promise = ecore_promise_add(0);
280
281 ecore_promise_then(promise, &_ecore_test_promise_normal_lifetime_cb, NULL);
282 ecore_promise_value_set(promise, NULL);
283
284 ecore_main_loop_begin();
285
286 fprintf(stderr, "%s:%d %s ---------- END test\n", __FILE__, __LINE__, __func__); fflush(stderr);
287 ecore_shutdown();
288}
289END_TEST
290
291START_TEST(ecore_test_promise_normal_lifetime_all)
292{
293 ecore_init();
294 fprintf(stderr, "%s:%d %s ---------- BEGIN test\n", __FILE__, __LINE__, __func__); fflush(stderr);
295
296 Ecore_Promise* first[2] = {ecore_promise_add(0), NULL};
297 Ecore_Promise* promise = ecore_promise_all(eina_carray_iterator_new((void**)&first[0]));
298
299 ecore_promise_then(promise, &_ecore_test_promise_normal_lifetime_cb, NULL);
300 ecore_promise_value_set(promise, NULL);
301
302 ecore_main_loop_begin();
303
304 fprintf(stderr, "%s:%d %s ---------- END test\n", __FILE__, __LINE__, __func__); fflush(stderr);
305 ecore_shutdown();
306}
307END_TEST
308
309static void
310_ecore_test_promise_immediate_set_lifetime_cb(void* data EINA_UNUSED, void* value EINA_UNUSED)
311{
312 ecore_main_loop_quit();
313}
314
315START_TEST(ecore_test_promise_immediate_set_lifetime)
316{
317 ecore_init();
318 fprintf(stderr, "%s:%d %s ---------- BEGIN test\n", __FILE__, __LINE__, __func__); fflush(stderr);
319
320 Ecore_Promise* promise = ecore_promise_add(0);
321
322 ecore_promise_value_set(promise, NULL);
323 ecore_promise_then(promise, &_ecore_test_promise_immediate_set_lifetime_cb, NULL);
324
325 ecore_main_loop_begin();
326
327 fprintf(stderr, "%s:%d %s ---------- END test\n", __FILE__, __LINE__, __func__); fflush(stderr);
328 ecore_shutdown();
329}
330END_TEST
331
332START_TEST(ecore_test_promise_immediate_set_lifetime_all)
333{
334 ecore_init();
335 fprintf(stderr, "%s:%d %s ---------- BEGIN test\n", __FILE__, __LINE__, __func__); fflush(stderr);
336
337 Ecore_Promise* first[2] = {ecore_promise_add(0), NULL};
338 Ecore_Promise* promise = ecore_promise_all(eina_carray_iterator_new((void**)&first[0]));
339
340 ecore_promise_value_set(first[0], NULL);
341 ecore_promise_then(promise, &_ecore_test_promise_immediate_set_lifetime_cb, NULL);
342
343 ecore_main_loop_begin();
344
345 fprintf(stderr, "%s:%d %s ---------- END test\n", __FILE__, __LINE__, __func__); fflush(stderr);
346 ecore_shutdown();
347}
348END_TEST
349
350void ecore_test_ecore_promise(TCase *tc EINA_UNUSED)
351{
352 tcase_add_test(tc, ecore_test_promise);
353 tcase_add_test(tc, ecore_test_promise_error);
354 tcase_add_test(tc, ecore_test_promise_all);
355 tcase_add_test(tc, ecore_test_promise_all_then_then);
356 tcase_add_test(tc, ecore_test_promise_then_after_thread_finished);
357 tcase_add_test(tc, ecore_test_promise_then_after_thread_finished_all);
358 tcase_add_test(tc, ecore_test_promise_blocking_get);
359 tcase_add_test(tc, ecore_test_promise_blocking_get_all);
360 tcase_add_test(tc, ecore_test_promise_normal_lifetime);
361 tcase_add_test(tc, ecore_test_promise_normal_lifetime_all);
362 tcase_add_test(tc, ecore_test_promise_immediate_set_lifetime);
363 tcase_add_test(tc, ecore_test_promise_immediate_set_lifetime_all);
364}