summaryrefslogtreecommitdiff
path: root/src/tests/ecore/ecore_test_promise.c
diff options
context:
space:
mode:
authorCedric Bail <cedric@osg.samsung.com>2018-04-04 15:59:41 -0700
committerCedric BAIL <cedric@osg.samsung.com>2018-04-05 13:17:32 -0700
commit8563e3780e02ba1b9eab1e7d9c91eb11cba8226b (patch)
tree78d7c945cbc279ed25067fd04b61a28c0fd3e064 /src/tests/ecore/ecore_test_promise.c
parent5ebe5bb62ce64b0d8bd5824da0ba7dfbc2691608 (diff)
ecore: remove tests of old Efl_Future based on Eo.
Diffstat (limited to 'src/tests/ecore/ecore_test_promise.c')
-rw-r--r--src/tests/ecore/ecore_test_promise.c1004
1 files changed, 0 insertions, 1004 deletions
diff --git a/src/tests/ecore/ecore_test_promise.c b/src/tests/ecore/ecore_test_promise.c
deleted file mode 100644
index 83c34b632b..0000000000
--- a/src/tests/ecore/ecore_test_promise.c
+++ /dev/null
@@ -1,1004 +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
9typedef struct _Future_Ok Future_Ok;
10struct _Future_Ok
11{
12 Eina_Bool then : 1;
13 Eina_Bool cancel : 1;
14 Eina_Bool progress : 1;
15};
16
17static void
18_then(void *data, const Efl_Event *ev)
19{
20 Efl_Future_Event_Success *s = ev->info;
21 int *value = s->value;
22 Future_Ok *fo = data;
23
24 fail_if(*value != 42);
25 fo->then = EINA_TRUE;
26}
27
28static void
29_cancel(void *data, const Efl_Event *ev)
30{
31 Efl_Future_Event_Failure *f = ev->info;
32 Future_Ok *fo = data;
33
34 fail_if(f->error != EINA_ERROR_FUTURE_CANCEL);
35 fo->cancel = EINA_TRUE;
36}
37
38static void
39_progress(void *data, const Efl_Event *ev)
40{
41 Efl_Future_Event_Progress *p = ev->info;
42 const int *value = p->progress;
43 Future_Ok *fo = data;
44
45 fail_if(*value != 7);
46 fo->progress = EINA_TRUE;
47}
48
49static void
50_death(void *data, const Efl_Event *ev EINA_UNUSED)
51{
52 Eina_Bool *death = data;
53
54 *death = EINA_TRUE;
55}
56
57// Test value set after then
58EFL_START_TEST(efl_test_promise_future_success)
59{
60 Efl_Promise *p;
61 Efl_Future *f;
62 Future_Ok fo = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
63 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE;
64 int progress = 7;
65 int value = 42;
66
67 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
68 fail_if(!p);
69
70 f = efl_promise_future_get(p);
71 fail_if(!f);
72
73 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
74 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
75
76 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo));
77
78 fail_if(deadp || deadf);
79
80 efl_promise_progress_set(p, &progress);
81 efl_promise_value_set(p, &value, NULL);
82
83 ecore_main_loop_iterate();
84
85 fail_if(!fo.then || fo.cancel || !fo.progress);
86 fail_if(!deadf || deadp);
87
88 efl_del(p);
89
90 fail_if(!deadp);
91
92}
93EFL_END_TEST
94
95// Test value set before future_get
96EFL_START_TEST(efl_test_promise_future_success_before_get)
97{
98 Efl_Promise *p;
99 Efl_Future *f;
100 Future_Ok fo = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
101 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE;
102 int value = 42;
103
104 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
105 fail_if(!p);
106
107 efl_promise_value_set(p, &value, NULL);
108
109 efl_future_use(&f, efl_promise_future_get(p));
110 fail_if(!f);
111
112 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
113 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
114
115 fail_if(deadp || deadf);
116
117 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo));
118
119 ecore_main_loop_iterate();
120
121 fail_if(f);
122 fail_if(!fo.then || fo.cancel || fo.progress);
123 fail_if(!deadf || deadp);
124
125 efl_del(p);
126
127 fail_if(!deadp);
128
129}
130EFL_END_TEST
131
132EFL_START_TEST(efl_test_promise_future_cancel)
133{
134 Efl_Promise *p;
135 Efl_Future *f;
136 Future_Ok fo = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
137 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE, none = EINA_FALSE;
138 int progress = 7;
139 int value = 42;
140
141 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
142 fail_if(!p);
143
144 efl_future_use(&f, efl_promise_future_get(p));
145 fail_if(!f);
146
147 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
148 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
149 efl_event_callback_add(p, EFL_PROMISE_EVENT_FUTURE_NONE, _death, &none);
150
151 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo));
152
153 fail_if(deadp || deadf);
154
155 efl_promise_progress_set(p, &progress);
156 efl_future_cancel(f);
157
158 efl_promise_value_set(p, &value, NULL);
159
160 ecore_main_loop_iterate();
161
162 fail_if(fo.then || !fo.cancel || !fo.progress);
163 fail_if(!deadf || deadp);
164 fail_if(!none);
165
166 efl_del(p);
167
168 fail_if(!deadp);
169
170}
171EFL_END_TEST
172
173// Test value set before then
174EFL_START_TEST(efl_test_promise_before_future_success)
175{
176 Efl_Promise *p;
177 Efl_Future *f;
178 Future_Ok fo = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
179 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE;
180 int progress = 7;
181 int value = 42;
182
183 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
184 fail_if(!p);
185
186 f = efl_promise_future_get(p);
187 fail_if(!f);
188
189 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
190 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
191
192 efl_promise_progress_set(p, &progress);
193 efl_promise_value_set(p, &value, NULL);
194
195 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo));
196
197 ecore_main_loop_iterate();
198
199 fail_if(deadp || !deadf);
200 fail_if(!fo.then || fo.cancel || fo.progress);
201
202 efl_del(p);
203
204 fail_if(!deadp);
205
206}
207EFL_END_TEST
208
209EFL_START_TEST(efl_test_promise_before_future_cancel)
210{
211 Efl_Promise *p;
212 Efl_Future *f;
213 Future_Ok fo = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
214 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE, none = EINA_FALSE;
215 int progress = 7;
216 int value = 42;
217
218 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
219 fail_if(!p);
220
221 efl_future_use(&f, efl_promise_future_get(p));
222 fail_if(!f);
223
224 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
225 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
226 efl_event_callback_add(p, EFL_PROMISE_EVENT_FUTURE_NONE, _death, &none);
227
228 efl_promise_progress_set(p, &progress);
229 efl_future_cancel(f);
230
231 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo));
232
233 fail_if(deadp || !deadf);
234
235 efl_promise_value_set(p, &value, NULL);
236
237 ecore_main_loop_iterate();
238
239 fail_if(fo.then || !fo.cancel || fo.progress);
240 fail_if(!none);
241
242 efl_del(p);
243
244 fail_if(!deadp);
245
246}
247EFL_END_TEST
248
249static void
250_chain_then(void *data, const Efl_Event *ev)
251{
252 Efl_Future_Event_Success *s = ev->info;
253 int *v = s->value;
254 Future_Ok *fo = data;
255
256 fo->then = EINA_TRUE;
257
258 fail_if(*v != 42);
259
260 efl_promise_value_set(s->next, v, NULL);
261}
262
263static void
264_chain_fail(void *data, const Efl_Event *ev)
265{
266 Efl_Future_Event_Failure *f = ev->info;
267 Future_Ok *fo = data;
268
269 fo->cancel = EINA_TRUE;
270
271 efl_promise_failed_set(f->next, f->error);
272}
273
274static void
275_chain_progress(void *data, const Efl_Event *ev)
276{
277 Efl_Future_Event_Progress *p = ev->info;
278 Future_Ok *fo = data;
279
280 fo->progress = EINA_TRUE;
281
282 efl_promise_progress_set(p->next, p->progress);
283}
284
285// Test chained then
286EFL_START_TEST(efl_test_promise_future_chain_success)
287{
288 Efl_Promise *p;
289 Efl_Future *f1, *f2;
290 Future_Ok fo1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
291 Future_Ok fo2 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
292 Eina_Bool deadf1 = EINA_FALSE, deadf2 = EINA_FALSE, deadp = EINA_FALSE;
293 int progress = 7;
294 int value = 42;
295
296 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
297 fail_if(!p);
298
299 f1 = efl_promise_future_get(p);
300 fail_if(!f1);
301
302 efl_event_callback_add(f1, EFL_EVENT_DEL, _death, &deadf1);
303 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
304
305 f2 = efl_future_then(f1, _chain_then, _chain_fail, _chain_progress, &fo1);
306 fail_if(!f2);
307
308 efl_event_callback_add(f2, EFL_EVENT_DEL, _death, &deadf2);
309
310 fail_if(!efl_future_then(f2, _then, _cancel, _progress, &fo2));
311
312 fail_if(deadp || deadf1 || deadf2);
313
314 efl_promise_progress_set(p, &progress);
315 efl_promise_value_set(p, &value, NULL);
316
317 ecore_main_loop_iterate();
318
319 fail_if(!fo1.then || fo1.cancel || !fo1.progress);
320 fail_if(!fo2.then || fo2.cancel || !fo2.progress);
321 fail_if(!deadf1 || !deadf2 || deadp);
322
323 efl_del(p);
324
325 fail_if(!deadp);
326
327}
328EFL_END_TEST
329
330EFL_START_TEST(efl_test_promise_future_chain_cancel)
331{
332 Efl_Promise *p;
333 Efl_Future *f1, *f2;
334 Future_Ok fo1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
335 Future_Ok fo2 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
336 Eina_Bool deadf1 = EINA_FALSE, deadf2 = EINA_FALSE, deadp = EINA_FALSE, none = EINA_FALSE;
337 int progress = 7;
338 int value = 42;
339
340 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
341 fail_if(!p);
342
343 efl_future_use(&f1, efl_promise_future_get(p));
344 fail_if(!f1);
345
346 efl_event_callback_add(f1, EFL_EVENT_DEL, _death, &deadf1);
347 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
348 efl_event_callback_add(p, EFL_PROMISE_EVENT_FUTURE_NONE, _death, &none);
349
350 f2 = efl_future_then(f1, _chain_then, _chain_fail, _chain_progress, &fo1);
351 fail_if(!f2);
352
353 efl_event_callback_add(f2, EFL_EVENT_DEL, _death, &deadf2);
354
355 fail_if(!efl_future_then(f2, _then, _cancel, _progress, &fo2));
356
357 fail_if(deadp || deadf1 || deadf2);
358
359 efl_promise_progress_set(p, &progress);
360 efl_future_cancel(f1);
361
362 efl_promise_value_set(p, &value, NULL);
363
364 ecore_main_loop_iterate();
365
366 fail_if(fo1.then || !fo1.cancel || !fo1.progress);
367 fail_if(fo2.then || !fo2.cancel || !fo2.progress);
368 fail_if(!deadf1 || !deadf2 || deadp);
369 fail_if(!none);
370
371 efl_del(p);
372
373 fail_if(!deadp);
374
375}
376EFL_END_TEST
377
378// Test value set after multi then
379EFL_START_TEST(efl_test_promise_future_multi_success)
380{
381 Efl_Promise *p;
382 Efl_Future *f;
383 Future_Ok fo1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
384 Future_Ok fo2 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
385 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE;
386 int progress = 7;
387 int value = 42;
388
389 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
390 fail_if(!p);
391
392 f = efl_promise_future_get(p);
393 fail_if(!f);
394
395 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
396 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
397
398 efl_ref(f);
399 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo1));
400 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo2));
401 efl_unref(f);
402
403 fail_if(deadp || deadf);
404
405 efl_promise_progress_set(p, &progress);
406 efl_promise_value_set(p, &value, NULL);
407
408 ecore_main_loop_iterate();
409
410 fail_if(!fo1.then || fo1.cancel || !fo1.progress);
411 fail_if(!fo2.then || fo2.cancel || !fo2.progress);
412 fail_if(!deadf || deadp);
413
414 efl_del(p);
415
416 fail_if(!deadp);
417
418}
419EFL_END_TEST
420
421EFL_START_TEST(efl_test_promise_future_multi_success_noref)
422{
423 Efl_Promise *p;
424 Efl_Future *f;
425 Future_Ok fo1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
426 Future_Ok fo2 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
427 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE;
428 int progress = 7;
429 int value = 42;
430
431 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
432 fail_if(!p);
433
434 f = efl_promise_future_get(p);
435 fail_if(!f);
436
437 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
438 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
439
440 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo1));
441 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo2));
442
443 fail_if(deadp || deadf);
444
445 efl_promise_progress_set(p, &progress);
446 efl_promise_value_set(p, &value, NULL);
447
448 ecore_main_loop_iterate();
449
450 fail_if(!fo1.then || fo1.cancel || !fo1.progress);
451 fail_if(!fo2.then || fo2.cancel || !fo2.progress);
452 fail_if(!deadf || deadp);
453
454 efl_del(p);
455
456 fail_if(!deadp);
457
458}
459EFL_END_TEST
460
461EFL_START_TEST(efl_test_promise_future_multi_cancel)
462{
463 Efl_Promise *p;
464 Efl_Future *f;
465 Future_Ok fo1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
466 Future_Ok fo2 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
467 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE, none = EINA_FALSE;
468 int progress = 7;
469 int value = 42;
470
471 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
472 fail_if(!p);
473
474 efl_future_use(&f, efl_promise_future_get(p));
475 fail_if(!f);
476
477 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
478 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
479 efl_event_callback_add(p, EFL_PROMISE_EVENT_FUTURE_NONE, _death, &none);
480
481 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo1));
482 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo2));
483
484 fail_if(deadp || deadf);
485
486 efl_promise_progress_set(p, &progress);
487 efl_future_cancel(f);
488
489 efl_promise_value_set(p, &value, NULL);
490
491 ecore_main_loop_iterate();
492
493 fail_if(fo1.then || !fo1.cancel || !fo1.progress);
494 fail_if(fo2.then || !fo2.cancel || !fo2.progress);
495 fail_if(!deadf || deadp);
496 fail_if(!none);
497
498 efl_del(p);
499
500 fail_if(!deadp);
501
502}
503EFL_END_TEST
504
505// Test value set before multi then
506EFL_START_TEST(efl_test_promise_before_future_multi_success)
507{
508 Efl_Promise *p;
509 Efl_Future *f;
510 Future_Ok fo1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
511 Future_Ok fo2 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
512 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE;
513 int progress = 7;
514 int value = 42;
515
516 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
517 fail_if(!p);
518
519 f = efl_promise_future_get(p);
520 fail_if(!f);
521
522 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
523 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
524
525 efl_promise_progress_set(p, &progress);
526 efl_promise_value_set(p, &value, NULL);
527
528 efl_ref(f);
529 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo1));
530 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo2));
531 efl_unref(f);
532
533 ecore_main_loop_iterate();
534
535 fail_if(deadp || !deadf);
536 fail_if(!fo1.then || fo1.cancel || fo1.progress);
537 fail_if(!fo2.then || fo2.cancel || fo2.progress);
538
539 efl_del(p);
540
541 fail_if(!deadp);
542
543}
544EFL_END_TEST
545
546EFL_START_TEST(efl_test_promise_before_future_multi_success_noref)
547{
548 Efl_Promise *p;
549 Efl_Future *f;
550 Future_Ok fo1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
551 Future_Ok fo2 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
552 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE;
553 int progress = 7;
554 int value = 42;
555
556 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
557 fail_if(!p);
558
559 f = efl_promise_future_get(p);
560 fail_if(!f);
561
562 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
563 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
564
565 efl_promise_progress_set(p, &progress);
566 efl_promise_value_set(p, &value, NULL);
567
568 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo1));
569 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo2));
570
571 ecore_main_loop_iterate();
572
573 fail_if(deadp || !deadf);
574 fail_if(!fo1.then || fo1.cancel || fo1.progress);
575 fail_if(!fo2.then || fo2.cancel || fo2.progress);
576
577 efl_del(p);
578
579 fail_if(!deadp);
580
581}
582EFL_END_TEST
583
584EFL_START_TEST(efl_test_promise_before_future_multi_cancel)
585{
586 Efl_Promise *p;
587 Efl_Future *f;
588 Future_Ok fo1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
589 Future_Ok fo2 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
590 Future_Ok fo3 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
591 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE, none = EINA_FALSE;
592 int progress = 7;
593 int value = 42;
594
595 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
596 fail_if(!p);
597
598 efl_future_use(&f, efl_promise_future_get(p));
599 fail_if(!f);
600
601 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
602 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
603 efl_event_callback_add(p, EFL_PROMISE_EVENT_FUTURE_NONE, _death, &none);
604
605 efl_promise_progress_set(p, &progress);
606 efl_future_cancel(f);
607
608 efl_ref(f);
609 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo1));
610 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo2));
611 efl_unref(f);
612
613 fail_if(efl_future_then(f, _then, _cancel, _progress, &fo3));
614
615 fail_if(deadp || !deadf);
616
617 efl_promise_value_set(p, &value, NULL);
618
619 ecore_main_loop_iterate();
620
621 fail_if(fo1.then || !fo1.cancel || fo1.progress);
622 fail_if(fo2.then || !fo2.cancel || fo2.progress);
623 fail_if(fo3.then || fo3.cancel || fo3.progress);
624 fail_if(!none);
625
626 efl_del(p);
627
628 fail_if(!deadp);
629
630}
631EFL_END_TEST
632
633EFL_START_TEST(efl_test_promise_before_future_multi_cancel_noref)
634{
635 Efl_Promise *p;
636 Efl_Future *f;
637 Future_Ok fo1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
638 Future_Ok fo2 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
639 Future_Ok fo3 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
640 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE, none = EINA_FALSE;
641 int progress = 7;
642 int value = 42;
643
644 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
645 fail_if(!p);
646
647 efl_future_use(&f, efl_promise_future_get(p));
648 fail_if(!f);
649
650 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
651 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
652 efl_event_callback_add(p, EFL_PROMISE_EVENT_FUTURE_NONE, _death, &none);
653
654 efl_promise_progress_set(p, &progress);
655
656 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo1));
657 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo2));
658
659 // efl_future_cancel is not delayed, only operation on promise are.
660 efl_future_cancel(f);
661
662 fail_if(efl_future_then(f, _then, _cancel, _progress, &fo3));
663
664 fail_if(deadp || !deadf);
665
666 efl_promise_value_set(p, &value, NULL);
667
668 ecore_main_loop_iterate();
669
670 fail_if(fo1.then || !fo1.cancel || fo1.progress);
671 fail_if(fo2.then || !fo2.cancel || fo2.progress);
672 fail_if(fo3.then || fo3.cancel || fo3.progress);
673 fail_if(!none);
674
675 efl_del(p);
676
677 fail_if(!deadp);
678
679}
680EFL_END_TEST
681
682static Eina_Bool cleanup = EINA_FALSE;
683
684static void
685_cleanup_called(void *s EINA_UNUSED)
686{
687 cleanup = EINA_TRUE;
688}
689
690// Test optional value set without then
691EFL_START_TEST(efl_test_promise_future_optional_success)
692{
693 Efl_Promise *p;
694 Efl_Future *f;
695 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE;
696 int progress = 7;
697 int value = 42;
698
699 cleanup = EINA_FALSE;
700
701 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
702 fail_if(!p);
703
704 f = efl_promise_future_get(p);
705 fail_if(!f);
706
707 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
708 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
709
710 fail_if(deadp || deadf);
711
712 efl_promise_progress_set(p, &progress);
713 efl_promise_value_set(p, &value, _cleanup_called);
714
715 fail_if(deadf || deadp);
716
717 ecore_main_loop_iterate();
718
719 fail_if(!deadf);
720
721 efl_del(p);
722
723 fail_if(!deadp || !cleanup);
724
725}
726EFL_END_TEST
727
728EFL_START_TEST(efl_test_promise_future_optional_cancel)
729{
730 Efl_Promise *p;
731 Efl_Future *f;
732 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE, none = EINA_FALSE;
733 int progress = 7;
734 int value = 42;
735
736 cleanup = EINA_FALSE;
737
738 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
739 fail_if(!p);
740
741 efl_future_use(&f, efl_promise_future_get(p));
742 fail_if(!f);
743
744 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
745 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
746 efl_event_callback_add(p, EFL_PROMISE_EVENT_FUTURE_NONE, _death, &none);
747
748 fail_if(deadp || deadf);
749
750 efl_promise_progress_set(p, &progress);
751 efl_future_cancel(f);
752
753 efl_promise_value_set(p, &value, _cleanup_called);
754
755 fail_if(deadf || deadp);
756 fail_if(!none);
757
758 ecore_main_loop_iterate();
759
760 fail_if(!deadf || deadp);
761
762 efl_del(p);
763
764 fail_if(!deadp);
765
766}
767EFL_END_TEST
768
769static int value[] = { 42, 7, 3 };
770
771static void
772_then_all(void *data, const Efl_Event *ev)
773{
774 Future_Ok *fo = data;
775 Efl_Future_Event_Success *s = ev->info;
776 Eina_Accessor *ac = s->value;
777 int *i;
778
779 fail_if(!eina_accessor_data_get(ac, 0, (void**) &i));
780 fail_if(i != &value[0]);
781 fail_if(!eina_accessor_data_get(ac, 1, (void**) &i));
782 fail_if(i != &value[1]);
783 fail_if(!eina_accessor_data_get(ac, 2, (void**) &i));
784 fail_if(i != &value[2]);
785
786 fo->then = EINA_TRUE;
787}
788
789EFL_START_TEST(efl_test_promise_all)
790{
791 Efl_Promise *p1, *p2, *p3;
792 Efl_Future *all = NULL, *f1;
793 Future_Ok donea = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
794 Future_Ok donep1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
795
796 p1 = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
797 p2 = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
798 p3 = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
799 fail_if(!p1 || !p2 || !p3);
800
801 f1 = efl_ref(efl_promise_future_get(p1));
802 fail_if(!efl_future_then(f1, _then, _cancel, _progress, &donep1));
803 efl_future_use(&all, efl_future_all(f1, efl_promise_future_get(p2), efl_promise_future_get(p3)));
804 efl_unref(f1);
805
806 fail_if(!efl_future_then(all, _then_all, _cancel, _progress, &donea));
807 fail_if(!all);
808
809 efl_promise_value_set(p1, &value[0], NULL);
810
811 // XXX: assuming a single iteration does it? wrong. need to fix...
812 ecore_main_loop_iterate();
813 ecore_main_loop_iterate();
814 ecore_main_loop_iterate();
815
816 fail_if(!donep1.then || donep1.cancel || donep1.progress);
817 fail_if(donea.then || donea.cancel || donea.progress);
818
819 efl_promise_value_set(p2, &value[1], NULL);
820 efl_promise_value_set(p3, &value[2], NULL);
821
822 // XXX: assuming a single iteration does it? wrong. need to fix...
823 ecore_main_loop_iterate();
824 ecore_main_loop_iterate();
825 ecore_main_loop_iterate();
826
827 fail_if(!donea.then || donea.cancel || donea.progress);
828 fail_if(all);
829
830 efl_del(p1);
831 efl_del(p2);
832 efl_del(p3);
833
834}
835EFL_END_TEST
836
837EFL_START_TEST(efl_test_promise_all_after_value_set)
838{
839 Efl_Promise *p1, *p2, *p3;
840 Efl_Future *all = NULL, *f1, *f2, *f3;
841 Future_Ok donea = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
842
843 p1 = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
844 p2 = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
845 p3 = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
846 fail_if(!p1 || !p2 || !p3);
847
848 f1 = efl_promise_future_get(p1);
849 f2 = efl_promise_future_get(p2);
850 f3 = efl_promise_future_get(p3);
851
852 efl_promise_value_set(p1, &value[0], NULL);
853 efl_promise_value_set(p2, &value[1], NULL);
854 efl_promise_value_set(p3, &value[2], NULL);
855
856 efl_future_use(&all, efl_future_all(f1, f2, f3));
857
858 fail_if(!all);
859
860 fail_if(!efl_future_then(all, _then_all, _cancel, _progress, &donea));
861
862 // XXX: assuming a single iteration does it? wrong. need to fix...
863 ecore_main_loop_iterate();
864 ecore_main_loop_iterate();
865 ecore_main_loop_iterate();
866
867 fail_if(!donea.then || donea.cancel || donea.progress);
868
869 fail_if(all);
870
871 efl_del(p1);
872 efl_del(p2);
873 efl_del(p3);
874
875}
876EFL_END_TEST
877
878static void
879_then_race(void *data, const Efl_Event *ev)
880{
881 Future_Ok *fo = data;
882 Efl_Future_Event_Success *s = ev->info;
883 Efl_Future_Race_Success *rs = s->value;
884
885 fail_if(rs->index != 1);
886 fail_if(rs->value != &value[0]);
887
888 fo->then = EINA_TRUE;
889}
890
891EFL_START_TEST(efl_test_promise_race)
892{
893 Efl_Promise *p1, *p2, *p3;
894 Efl_Future *race = NULL, *f1;
895 Future_Ok donea = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
896 Future_Ok donep1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
897
898 p1 = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
899 p2 = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
900 p3 = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
901 fail_if(!p1 || !p2 || !p3);
902
903 f1 = efl_ref(efl_promise_future_get(p1));
904 fail_if(!efl_future_then(f1, _then, _cancel, _progress, &donep1));
905 efl_future_use(&race, efl_future_race(f1, efl_promise_future_get(p2), efl_promise_future_get(p3)));
906 efl_unref(f1);
907
908 fail_if(!efl_future_then(race, _then_race, _cancel, _progress, &donea));
909 fail_if(!race);
910
911 efl_promise_value_set(p2, &value[0], NULL);
912
913 ecore_main_loop_iterate();
914
915 fail_if(donep1.then || !donep1.cancel || donep1.progress);
916 fail_if(!donea.then || donea.cancel || donea.progress);
917
918 fail_if(race);
919
920 efl_del(p1);
921 efl_del(p2);
922 efl_del(p3);
923
924}
925EFL_END_TEST
926
927EFL_START_TEST(efl_test_future_link)
928{
929 Efl_Promise *p;
930 Efl_Future *f;
931 Eo *o;
932
933 o = efl_add(EFL_LOOP_TIMER_CLASS, efl_main_loop_get(),
934 efl_loop_timer_interval_set(efl_added, 0.0));
935 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
936 efl_future_use(&f, efl_promise_future_get(p));
937 efl_future_link(o, f);
938
939 fail_if(!o || !p || !f);
940 efl_del(o);
941 fail_if(f);
942
943 o = efl_add(EFL_LOOP_TIMER_CLASS, efl_main_loop_get(),
944 efl_loop_timer_interval_set(efl_added, 0.0));
945 efl_future_use(&f, efl_promise_future_get(p));
946 efl_future_cancel(f);
947
948 efl_del(o);
949 efl_del(p);
950
951}
952EFL_END_TEST
953
954static Efl_Future *recursive_future = NULL;
955
956static void
957_then_cleanup(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
958{
959 efl_future_cancel(recursive_future);
960}
961
962EFL_START_TEST(efl_test_recursive_mess)
963{
964 Efl_Promise *p;
965 Future_Ok done = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
966
967 p = efl_add(EFL_PROMISE_CLASS, efl_main_loop_get());
968 efl_future_use(&recursive_future, efl_promise_future_get(p));
969 efl_future_then(recursive_future, _then_cleanup, _cancel, NULL, &done);
970
971 efl_promise_value_set(p, &value[0], NULL);
972
973 ecore_main_loop_iterate();
974
975 efl_del(p);
976
977}
978EFL_END_TEST
979
980void ecore_test_ecore_promise(TCase *tc)
981{
982 tcase_add_test(tc, efl_test_promise_future_success);
983 tcase_add_test(tc, efl_test_promise_future_cancel);
984 tcase_add_test(tc, efl_test_promise_future_chain_success);
985 tcase_add_test(tc, efl_test_promise_future_chain_cancel);
986 tcase_add_test(tc, efl_test_promise_before_future_success);
987 tcase_add_test(tc, efl_test_promise_before_future_cancel);
988 tcase_add_test(tc, efl_test_promise_future_multi_success);
989 tcase_add_test(tc, efl_test_promise_future_multi_success_noref);
990 tcase_add_test(tc, efl_test_promise_future_multi_cancel);
991 tcase_add_test(tc, efl_test_promise_before_future_multi_success);
992 tcase_add_test(tc, efl_test_promise_before_future_multi_success_noref);
993 tcase_add_test(tc, efl_test_promise_before_future_multi_cancel);
994 tcase_add_test(tc, efl_test_promise_before_future_multi_success_noref);
995 tcase_add_test(tc, efl_test_promise_before_future_multi_cancel_noref);
996 tcase_add_test(tc, efl_test_promise_future_optional_success);
997 tcase_add_test(tc, efl_test_promise_future_optional_cancel);
998 tcase_add_test(tc, efl_test_promise_all);
999 tcase_add_test(tc, efl_test_promise_all_after_value_set);
1000 tcase_add_test(tc, efl_test_promise_future_success_before_get);
1001 tcase_add_test(tc, efl_test_promise_race);
1002 tcase_add_test(tc, efl_test_future_link);
1003 tcase_add_test(tc, efl_test_recursive_mess);
1004}