summaryrefslogtreecommitdiff
path: root/src/tests/ecore/efl_app_test_promise.c
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2018-04-09 13:37:03 +0200
committerStefan Schmidt <stefan@osg.samsung.com>2018-04-10 11:28:01 +0200
commit5e806ee41ff3c3384fa63644e0dddce6105aa756 (patch)
tree0f3b814846bf2f46921730aa104eff465a168a7e /src/tests/ecore/efl_app_test_promise.c
parentb4da776b3b6b0e44c153b159ef8b23554555084b (diff)
tests: move ecore promise tests into efl_app_suite
Summary: ref T6815 Depends on D5902 Reviewers: stefan_schmidt Subscribers: cedric Maniphest Tasks: T6815 Differential Revision: https://phab.enlightenment.org/D5903
Diffstat (limited to 'src/tests/ecore/efl_app_test_promise.c')
-rw-r--r--src/tests/ecore/efl_app_test_promise.c1365
1 files changed, 1365 insertions, 0 deletions
diff --git a/src/tests/ecore/efl_app_test_promise.c b/src/tests/ecore/efl_app_test_promise.c
new file mode 100644
index 0000000..e719e53
--- /dev/null
+++ b/src/tests/ecore/efl_app_test_promise.c
@@ -0,0 +1,1365 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdio.h>
6#include <unistd.h>
7#define EFL_NOLEGACY_API_SUPPORT
8#include <Efl_Core.h>
9#include <Efl_Net.h>
10#include "efl_app_suite.h"
11#include "../efl_check.h"
12
13#define CHAIN_SIZE (3)
14#define DEFAULT_ERROR (EFBIG)
15#define DEFAULT_MSG ("Future resolve is working!")
16#define DEFAULT_INT_VALUE (5466)
17#define DEFAULT_INT_VALUE_AS_STRING ("5466")
18#define DEFAULT_TIMEOUT (0.1)
19
20#define VALUE_TYPE_CHECK(_v, _type) \
21 do { \
22 ck_assert_ptr_eq(_v.type, _type); \
23} while(0)
24
25#define ERROR_CHECK(_v, _errno) \
26 do { \
27 Eina_Error _err; \
28 VALUE_TYPE_CHECK(_v, EINA_VALUE_TYPE_ERROR); \
29 fail_if(!eina_value_get(&_v, &_err)); \
30 ck_assert_int_eq(_err, _errno); \
31 } while (0)
32
33typedef struct _PromiseCtx {
34 Eina_Promise *p;
35 Efl_Object *t;
36 Eina_Bool fail;
37 Eina_Value *value;
38} PromiseCtx;
39
40typedef struct _Easy_Ctx {
41 Eina_Bool success_called;
42 Eina_Bool error_called;
43 Eina_Bool free_called;
44 Eina_Bool stop_loop;
45} Easy_Ctx;
46
47typedef struct _Race_Ctx {
48 Eina_Value value;
49 unsigned int success_idx;
50 unsigned int failed;
51 unsigned int success;
52} Race_Ctx;
53
54typedef struct _Race_Future_Ctx {
55 Race_Ctx *race_ctx;
56 unsigned int idx;
57 int value;
58} Race_Future_Ctx;
59
60#ifdef EINA_SAFETY_CHECKS
61
62#define LOG_CTX_MULTIPLE_FUNC_CTX_SET(_ctx, ...) \
63 do { \
64 _ctx.level = EINA_LOG_LEVEL_ERR; \
65 _ctx.did = EINA_FALSE; \
66 _ctx.just_fmt = EINA_FALSE; \
67 _ctx.func_ctx_idx = 0; \
68 _ctx.func_ctx = (struct Func_Ctx []){ __VA_ARGS__, {NULL, NULL}}; \
69 } while(0)
70
71#define LOG_CTX_SET(_ctx, _fnc, _msg) LOG_CTX_MULTIPLE_FUNC_CTX_SET(_ctx, {_fnc, _msg})
72
73typedef struct _Log_Ctx {
74 struct Func_Ctx {
75 const char *fnc;
76 const char *msg;
77 } *func_ctx;
78 int level;
79 int func_ctx_idx;
80 Eina_Bool did;
81 Eina_Bool just_fmt;
82} Log_Ctx;
83
84static void
85_eina_test_safety_print_cb(const Eina_Log_Domain *d,
86 Eina_Log_Level level,
87 const char *file,
88 const char *fnc, int line,
89 const char *fmt,
90 void *data,
91 va_list args)
92{
93 Log_Ctx *ctx = data;
94 va_list cp_args;
95 const char *str;
96
97 va_copy(cp_args, args);
98 str = va_arg(cp_args, const char *);
99 va_end(cp_args);
100
101 ck_assert_ptr_ne(ctx->func_ctx[ctx->func_ctx_idx].msg, NULL);
102 ck_assert_int_eq(level, ctx->level);
103 if (ctx->just_fmt)
104 ck_assert_str_eq(fmt, ctx->func_ctx[ctx->func_ctx_idx].msg);
105 else
106 {
107 ck_assert_str_eq(fmt, "%s");
108 ck_assert_str_eq(ctx->func_ctx[ctx->func_ctx_idx].msg, str);
109 }
110 ck_assert_str_eq(ctx->func_ctx[ctx->func_ctx_idx].fnc, fnc);
111 ctx->did = EINA_TRUE;
112 ctx->func_ctx_idx++;
113
114 (void)d;
115 (void)file;
116 (void)line;
117}
118#endif
119
120static void
121_cancel(void *data, const Eina_Promise *dead_ptr EINA_UNUSED)
122{
123 PromiseCtx *ctx = data;
124 if (ctx->t) efl_del(ctx->t);
125 ctx->t = NULL;
126 eina_value_free(ctx->value);
127 free(ctx);
128}
129
130static void
131_promise_cancel_test(void *data, const Eina_Promise *dead_ptr EINA_UNUSED)
132{
133 Eina_Bool *cancel_called = data;
134 *cancel_called = EINA_TRUE;
135}
136
137static void
138_simple_timeout(void *data, const Efl_Event *ev EINA_UNUSED)
139{
140 PromiseCtx *ctx = data;
141
142 if (ctx->fail) eina_promise_reject(ctx->p, DEFAULT_ERROR);
143 else
144 {
145 Eina_Value v;
146
147 fail_if(!eina_value_copy(ctx->value, &v));
148 eina_promise_resolve(ctx->p, v);
149 eina_value_free(ctx->value);
150 }
151 efl_del(ctx->t);
152 free(ctx);
153}
154
155static Eina_Future_Scheduler *
156_future_scheduler_get(void)
157{
158 return efl_loop_future_scheduler_get(efl_main_loop_get());
159}
160
161static PromiseCtx *
162_promise_ctx_new(void)
163{
164 PromiseCtx *ctx;
165 ctx = calloc(1, sizeof(PromiseCtx));
166 fail_if(!ctx);
167 ctx->p = eina_promise_new(_future_scheduler_get(), _cancel, ctx);
168 fail_if(!ctx->p);
169 return ctx;
170}
171
172static Eina_Future *
173_future_get(PromiseCtx *ctx, double timeout)
174{
175 Eina_Future *f;
176
177 f = eina_future_new(ctx->p);
178 fail_if(!f);
179 ctx->t = efl_add(EFL_LOOP_TIMER_CLASS, efl_main_loop_get(),
180 efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TICK, _simple_timeout, ctx),
181 efl_loop_timer_interval_set(efl_added, timeout));
182 fail_if(!ctx->t);
183 return f;
184}
185
186static Eina_Future *
187_fail_future_get(void)
188{
189 PromiseCtx *ctx = _promise_ctx_new();
190 ctx->fail = EINA_TRUE;
191 return _future_get(ctx, DEFAULT_TIMEOUT);
192}
193
194static Eina_Future *
195_int_future_with_value_and_timeout(int value, double timeout)
196{
197 PromiseCtx *ctx = _promise_ctx_new();
198 ctx->value = eina_value_util_int_new(value);
199 fail_if(!ctx->value);
200 return _future_get(ctx, timeout);
201}
202
203static Eina_Future *
204_int_future_get(void)
205{
206 return _int_future_with_value_and_timeout(DEFAULT_INT_VALUE, DEFAULT_TIMEOUT);
207}
208
209static Eina_Future *
210_str_future_get(void)
211{
212 PromiseCtx *ctx = _promise_ctx_new();
213 ctx->value = eina_value_util_string_new(DEFAULT_MSG);
214 fail_if(!ctx->value);
215 return _future_get(ctx, DEFAULT_TIMEOUT);
216}
217
218static Eina_Value
219_simple_err(void *data EINA_UNUSED, const Eina_Value v, const Eina_Future *dead_future EINA_UNUSED)
220{
221 ERROR_CHECK(v, DEFAULT_ERROR);
222 ecore_main_loop_quit();
223 return v;
224}
225
226static Eina_Value
227_simple_ok(void *data EINA_UNUSED, const Eina_Value v, const Eina_Future *dead_future EINA_UNUSED)
228{
229 const char *msg;
230
231 VALUE_TYPE_CHECK(v, EINA_VALUE_TYPE_STRING);
232 fail_if(!eina_value_get(&v, &msg));
233 ck_assert_str_eq(DEFAULT_MSG, msg);
234 ecore_main_loop_quit();
235 return v;
236}
237
238static Eina_Value
239_chain_stop(void *data, const Eina_Value v, const Eina_Future *dead_future EINA_UNUSED)
240{
241 int *i = data;
242 fail_if(*i != CHAIN_SIZE);
243 ecore_main_loop_quit();
244 return v;
245}
246
247static Eina_Value
248_chain_no_error(void *data, const Eina_Value v, const Eina_Future *dead_future EINA_UNUSED)
249{
250 Eina_Value new_v;
251 static int count = DEFAULT_INT_VALUE;
252 int current_i;
253 int *i = data;
254
255 VALUE_TYPE_CHECK(v, EINA_VALUE_TYPE_INT);
256 fail_if(!eina_value_get(&v, &current_i));
257 fail_if(current_i != count++);
258 fail_if(!eina_value_setup(&new_v, EINA_VALUE_TYPE_INT));
259 fail_if(!eina_value_set(&new_v, count));
260 (*i)++;
261 return new_v;
262}
263
264static Eina_Value
265_chain_error(void *data, const Eina_Value v, const Eina_Future *dead_future EINA_UNUSED)
266{
267 int *i = data;
268
269 ERROR_CHECK(v, DEFAULT_ERROR);
270 (*i)++;
271 return v;
272}
273
274static Eina_Value
275_cancel_cb(void *data, const Eina_Value v, const Eina_Future *dead_future EINA_UNUSED)
276{
277 Eina_Value new_v;
278 int *cancel_count = data;
279
280 fail_if(!eina_value_setup(&new_v, EINA_VALUE_TYPE_INT));
281 ERROR_CHECK(v, ECANCELED);
282 (*cancel_count)++;
283 /* Although this function returns an INT Eina_Value, the next
284 _cancel_cb must receive a EINA_VALYE_TYPE_ERROR as ECANCELED */
285 return new_v;
286}
287
288static Eina_Value
289_inner_resolve(void *data, const Eina_Value v, const Eina_Future *dead_future EINA_UNUSED)
290{
291 Eina_Value new_v;
292 fail_if(!eina_value_setup(&new_v, EINA_VALUE_TYPE_STRING));
293 fail_if(!eina_value_set(&new_v, DEFAULT_MSG));
294 eina_promise_resolve(data, new_v);
295 return v;
296}
297
298static Eina_Value
299_inner_fail(void *data, const Eina_Value v, const Eina_Future *dead_future EINA_UNUSED)
300{
301 eina_promise_reject(data, DEFAULT_ERROR);
302 return v;
303}
304
305static void
306_inner_promise_cancel(void *data EINA_UNUSED, const Eina_Promise *dead_ptr EINA_UNUSED)
307{
308 //This must never happen...
309 fail_if(EINA_FALSE);
310}
311
312static Eina_Value
313_future_promise_create(void *data, const Eina_Value v EINA_UNUSED, const Eina_Future *dead_future EINA_UNUSED)
314{
315 Eina_Promise *p;
316
317 p = eina_promise_new(_future_scheduler_get(), _inner_promise_cancel, NULL);
318 fail_if(!p);
319 eina_future_then(_str_future_get(),
320 data ? _inner_fail : _inner_resolve,
321 p);
322 return eina_promise_as_value(p);
323}
324
325static Eina_Value
326_inner_future_last(void *data, const Eina_Value v, const Eina_Future *dead_future EINA_UNUSED)
327{
328 if (data)
329 ERROR_CHECK(v, DEFAULT_ERROR);
330 else
331 {
332 const char *msg;
333 VALUE_TYPE_CHECK(v, EINA_VALUE_TYPE_STRING);
334 fail_if(!eina_value_get(&v, &msg));
335 ck_assert_str_eq(DEFAULT_MSG, msg);
336 }
337 ecore_main_loop_quit();
338 return v;
339}
340
341static Eina_Value
342_convert_check(void *data EINA_UNUSED, const Eina_Value v, const Eina_Future *dead_future EINA_UNUSED)
343{
344 const char *number;
345 VALUE_TYPE_CHECK(v, EINA_VALUE_TYPE_STRING);
346 fail_if(!eina_value_get(&v, &number));
347 ck_assert_str_eq(DEFAULT_INT_VALUE_AS_STRING, number);
348 ecore_main_loop_quit();
349 return v;
350}
351
352static Eina_Value
353_easy_success(void *data, const Eina_Value v)
354{
355 Easy_Ctx *ctx = data;
356 const char *msg;
357
358 ctx->success_called = EINA_TRUE;
359 VALUE_TYPE_CHECK(v, EINA_VALUE_TYPE_STRING);
360 fail_if(!eina_value_get(&v, &msg));
361 ck_assert_str_eq(DEFAULT_MSG, msg);
362 return v;
363}
364
365static Eina_Value
366_easy_error(void *data, const Eina_Error err)
367{
368 Eina_Value v;
369 Easy_Ctx *ctx = data;
370 fail_if(err != EINVAL);
371 fail_if(!eina_value_setup(&v, EINA_VALUE_TYPE_ERROR));
372 fail_if(!eina_value_set(&v, err));
373 ctx->error_called = EINA_TRUE;
374 return v;
375}
376
377static void
378_easy_free(void *data, const Eina_Future *dead_future EINA_UNUSED)
379{
380 Easy_Ctx *ctx = data;
381 ctx->free_called = EINA_TRUE;
382 if (ctx->stop_loop) ecore_main_loop_quit();
383}
384
385static Eina_Value
386_all_cb(void *data, const Eina_Value array, const Eina_Future *dead EINA_UNUSED)
387{
388 unsigned int len, i, *expected_len = data;
389
390 VALUE_TYPE_CHECK(array, EINA_VALUE_TYPE_ARRAY);
391 len = eina_value_array_count(&array);
392 fail_if(len != *expected_len);
393
394 for (i = 0; i < len; i++)
395 {
396 Eina_Value v;
397
398 fail_if(!eina_value_array_get(&array, i, &v));
399 if (i % 2 == 0)
400 {
401 const char *msg;
402 VALUE_TYPE_CHECK(v, EINA_VALUE_TYPE_STRING);
403 fail_if(!eina_value_get(&v, &msg));
404 ck_assert_str_eq(DEFAULT_MSG, msg);
405 }
406 else
407 {
408 int ivalue = 0;
409 VALUE_TYPE_CHECK(v, EINA_VALUE_TYPE_INT);
410 fail_if(!eina_value_get(&v, &ivalue));
411 fail_if(ivalue != DEFAULT_INT_VALUE);
412 }
413 eina_value_flush(&v);
414 }
415 ecore_main_loop_quit();
416 return array;
417}
418
419static Eina_Value
420_future_all_count(void *data, const Eina_Value v, const Eina_Future *dead EINA_UNUSED)
421{
422 unsigned int *futures_called = data;
423 (*futures_called)++;
424 return v;
425}
426
427static Eina_Value
428_race_cb(void *data, const Eina_Value v, const Eina_Future *dead EINA_UNUSED)
429{
430 Race_Future_Ctx *future_ctx = data;
431 Race_Ctx *ctx = future_ctx->race_ctx;
432
433 if (v.type == EINA_VALUE_TYPE_ERROR)
434 {
435 Eina_Error err;
436 eina_value_get(&v, &err);
437 fail_if(err != ECANCELED);
438 ctx->failed++;
439 }
440 else if (v.type == EINA_VALUE_TYPE_INT)
441 {
442 int i;
443 fail_if(!eina_value_get(&v, &i));
444 fail_if(future_ctx->value != i);
445 ctx->success++;
446 ctx->success_idx = future_ctx->idx;
447 fail_if(!eina_value_copy(&v, &ctx->value));
448 }
449 else fail_if(EINA_TRUE); //This is not supposed to happen!
450 free(future_ctx);
451 return v;
452}
453
454static Eina_Value
455_race_end_cb(void *data, const Eina_Value v, const Eina_Future *dead EINA_UNUSED)
456{
457 Race_Ctx *ctx = data;
458 unsigned int idx;
459 Eina_Value_Struct *st;
460 Eina_Value r;
461
462 VALUE_TYPE_CHECK(v, EINA_VALUE_TYPE_STRUCT);
463
464 st = eina_value_memory_get(&v);
465 fail_if(!st);
466 fail_if(st->desc != EINA_PROMISE_RACE_STRUCT_DESC);
467 fail_if(!eina_value_struct_get(&v, "index", &idx));
468 fail_if(idx != ctx->success_idx);
469 fail_if(!eina_value_struct_get(&v, "value", &r));
470 fail_if(eina_value_compare(&r, &ctx->value));
471 eina_value_flush(&r);
472 ecore_main_loop_quit();
473 return v;
474}
475
476static Eina_Value
477_promise_empty_done(void *data, const Eina_Value value, const Eina_Future *dead_future EINA_UNUSED)
478{
479 Eina_Bool *pdone = data;
480
481 if (!value.type) *pdone = EINA_TRUE;
482
483 ecore_main_loop_quit();
484
485 return value;
486}
487
488EFL_START_TEST(efl_test_timeout)
489{
490 Eina_Future *f;
491 Eina_Bool done = EINA_FALSE;
492
493 fail_if(!ecore_init());
494 f = eina_future_then(efl_loop_timeout(efl_main_loop_get(), 0.0001),
495 _promise_empty_done, &done);
496 fail_if(!f);
497 ecore_main_loop_begin();
498 ecore_shutdown();
499
500 fail_unless(done);
501}
502EFL_END_TEST
503
504EFL_START_TEST(efl_test_job)
505{
506 Eina_Future *f;
507 Eina_Bool done = EINA_FALSE;
508
509 fail_if(!ecore_init());
510 f = eina_future_then(efl_loop_job(efl_main_loop_get()),
511 _promise_empty_done, &done);
512 fail_if(!f);
513 ecore_main_loop_begin();
514 ecore_shutdown();
515
516 fail_unless(done);
517}
518EFL_END_TEST
519
520EFL_START_TEST(efl_test_idle)
521{
522 Eina_Future *f;
523 Eina_Bool done = EINA_FALSE;
524
525 fail_if(!ecore_init());
526 f = eina_future_then(efl_loop_idle(efl_main_loop_get()),
527 _promise_empty_done, &done);
528 fail_if(!f);
529 ecore_main_loop_begin();
530 ecore_shutdown();
531
532 fail_unless(done);
533}
534EFL_END_TEST
535
536
537EFL_START_TEST(efl_test_promise_future_success)
538{
539 Eina_Future *f;
540 fail_if(!ecore_init());
541 f = eina_future_then(_str_future_get(),
542 _simple_ok, NULL);
543 fail_if(!f);
544 ecore_main_loop_begin();
545 ecore_shutdown();
546}
547EFL_END_TEST
548
549EFL_START_TEST(efl_test_promise_future_failure)
550{
551 Eina_Future *f;
552 fail_if(!ecore_init());
553 f = eina_future_then(_fail_future_get(),
554 _simple_err, NULL);
555 fail_if(!f);
556 ecore_main_loop_begin();
557 ecore_shutdown();
558}
559EFL_END_TEST
560
561EFL_START_TEST(efl_test_promise_future_chain_no_error)
562{
563 Eina_Future *f;
564 static int i = 0;
565
566 fail_if(!ecore_init());
567 f = eina_future_chain(_int_future_get(),
568 {.cb = _chain_no_error, .data = &i},
569 {.cb = _chain_no_error, .data = &i},
570 {.cb = _chain_no_error, .data = &i},
571 {.cb = _chain_stop, .data = &i});
572 fail_if(!f);
573 ecore_main_loop_begin();
574 ecore_shutdown();
575}
576EFL_END_TEST
577
578EFL_START_TEST(efl_test_promise_future_chain_error)
579{
580 Eina_Future *f;
581 static int i = 0;
582
583 fail_if(!ecore_init());
584 f = eina_future_chain(_fail_future_get(),
585 {.cb = _chain_error, .data = &i},
586 {.cb = _chain_error, .data = &i},
587 {.cb = _chain_error, .data = &i},
588 {.cb = _chain_stop, .data = &i});
589 fail_if(!f);
590 ecore_main_loop_begin();
591 ecore_shutdown();
592}
593EFL_END_TEST
594
595EFL_START_TEST(efl_test_promise_future_cancel)
596{
597 fail_if(!ecore_init());
598 int i;
599
600 for (i = 0; i < 3; i++)
601 {
602 Eina_Promise *p;
603 Eina_Future *first, *last, *middle;
604 int cancel_count = 0;
605 Eina_Bool cancel_called = EINA_FALSE;
606
607 p = eina_promise_new(_future_scheduler_get(), _promise_cancel_test, &cancel_called);
608 fail_if(!p);
609 first = eina_future_new(p);
610 fail_if(!first);
611 if (i == 2)
612 {
613 Eina_Future *f;
614 last = NULL;
615 f = eina_future_then(first, _cancel_cb, &cancel_count);
616 fail_if(!f);
617 middle = eina_future_then(f, _cancel_cb, &cancel_count);
618 fail_if(!middle);
619 f = eina_future_then(middle, _cancel_cb, &cancel_count);
620 fail_if(!f);
621 }
622 else
623 {
624 middle = NULL;
625 last = eina_future_chain(first,
626 {.cb = _cancel_cb, .data = &cancel_count},
627 {.cb = _cancel_cb, .data = &cancel_count},
628 {.cb = _cancel_cb, .data = &cancel_count});
629 fail_if(!last);
630 }
631 if (i == 0)
632 eina_future_cancel(last);
633 else if (i == 1)
634 eina_future_cancel(first);
635 else
636 eina_future_cancel(middle);
637 fail_if(cancel_count != CHAIN_SIZE);
638 fail_if(!cancel_called);
639 }
640 ecore_shutdown();
641}
642EFL_END_TEST
643
644EFL_START_TEST(efl_test_promise_future_inner_promise)
645{
646 Eina_Future *f;
647
648 fail_if(!ecore_init());
649 f = eina_future_chain(_str_future_get(),
650 {.cb = _future_promise_create, .data = NULL},
651 {.cb = _inner_future_last, .data = NULL});
652 fail_if(!f);
653 ecore_main_loop_begin();
654 ecore_shutdown();
655}
656EFL_END_TEST
657
658EFL_START_TEST(efl_test_promise_future_inner_promise_fail)
659{
660 Eina_Future *f;
661 void *data =(void *) 0x01;
662
663 fail_if(!ecore_init());
664 f = eina_future_chain(_str_future_get(),
665 {.cb = _future_promise_create, .data = data},
666 {.cb = _inner_future_last, .data = data});
667 fail_if(!f);
668 ecore_main_loop_begin();
669 ecore_shutdown();
670}
671EFL_END_TEST
672
673EFL_START_TEST(efl_test_promise_future_implicit_cancel)
674{
675 Eina_Promise *p;
676 Eina_Future *f;
677 int cancel_count = 0;
678 Eina_Bool cancel_called = EINA_FALSE;
679 Eina_Value v = EINA_VALUE_EMPTY;
680
681 fail_if(!ecore_init());
682
683 p = eina_promise_new(_future_scheduler_get(), _promise_cancel_test, &cancel_called);
684 fail_if(!p);
685 f = eina_future_new(p);
686 fail_if(!f);
687 f = eina_future_chain(f,
688 {.cb = _cancel_cb, .data = &cancel_count},
689 {.cb = _cancel_cb, .data = &cancel_count},
690 {.cb = _cancel_cb, .data = &cancel_count});
691 fail_if(!f);
692 eina_promise_resolve(p, v);
693 /*
694 The promise was resolved, but the mainloop is not running.
695 Since ecore_shutdown() will be called all the futures must be cancelled
696 */
697 ecore_shutdown();
698 //All the futures were cancelled at this point
699 fail_if(cancel_count != CHAIN_SIZE);
700 //Cancel should not be called, since we called eina_promise_resolve()
701 fail_if(cancel_called);
702}
703EFL_END_TEST
704
705EFL_START_TEST(efl_test_promise_future_convert)
706{
707 Eina_Future *f;
708
709 fail_if(!ecore_init());
710 f = eina_future_chain(_int_future_get(),
711 eina_future_cb_convert_to(EINA_VALUE_TYPE_STRING),
712 { .cb = _convert_check, .data = NULL });
713 fail_if(!f);
714 ecore_main_loop_begin();
715 ecore_shutdown();
716
717}
718EFL_END_TEST
719
720EFL_START_TEST(efl_test_promise_future_easy)
721{
722 Eina_Future *f;
723 Easy_Ctx easy1 = { 0 };
724 Easy_Ctx easy2 = { 0 };
725 Easy_Ctx easy3 = { 0 };
726
727 easy3.stop_loop = EINA_TRUE;
728 fail_if(!ecore_init());
729 f = eina_future_then_from_desc(_str_future_get(),
730 eina_future_cb_easy(_easy_success,
731 _easy_error,
732 _easy_free,
733 EINA_VALUE_TYPE_STRING,
734 &easy1));
735 fail_if(!f);
736 f = eina_future_then_easy(f, _easy_success, _easy_error,
737 _easy_free, NULL, &easy2);
738 fail_if(!f);
739 f = eina_future_chain_easy(f, {_easy_success, _easy_error,
740 _easy_free, EINA_VALUE_TYPE_INT, &easy3});
741 fail_if(!f);
742 ecore_main_loop_begin();
743 ecore_shutdown();
744 fail_if(!(easy1.success_called && !easy1.error_called && easy1.free_called));
745 fail_if(!(easy2.success_called && !easy2.error_called && easy2.free_called));
746 fail_if(!(!easy3.success_called && easy3.error_called && easy3.free_called));
747}
748EFL_END_TEST
749
750EFL_START_TEST(efl_test_promise_future_all)
751{
752 Eina_Future *futures[11];
753 unsigned int i, futures_called = 0, len = EINA_C_ARRAY_LENGTH(futures);
754
755 fail_if(!ecore_init());
756 for (i = 0; i < len - 1; i++)
757 {
758 Eina_Future *f;
759 if (i % 2 == 0)
760 f = _str_future_get();
761 else
762 f = _int_future_get();
763 fail_if(!f);
764 futures[i] = eina_future_then(f, _future_all_count, &futures_called);
765 fail_if(!futures[i]);
766 }
767
768 futures[--len] = EINA_FUTURE_SENTINEL;
769 fail_if(!eina_future_then(eina_future_all_array(futures), _all_cb, &len));
770 ecore_main_loop_begin();
771 ecore_shutdown();
772 fail_if(futures_called != len);
773}
774EFL_END_TEST
775
776EFL_START_TEST(efl_test_promise_future_race)
777{
778 Race_Ctx ctx = { 0 };
779 Eina_Future *futures[11];
780 unsigned int i, len = EINA_C_ARRAY_LENGTH(futures);
781 double timeouts[10] = {
782 2.0, 1.0, 0.5, 0.1, 4.5, 2.3, 5.6, 1.0, 0.5, 0.3
783 };
784
785 srand(time(NULL));
786 fail_if(!ecore_init());
787 for (i = 0; i < len - 1; i++)
788 {
789 Race_Future_Ctx *future_ctx = calloc(1, sizeof(Race_Future_Ctx));
790 fail_if(!future_ctx);
791 future_ctx->race_ctx = &ctx;
792 future_ctx->idx = i;
793 future_ctx->value = rand() % RAND_MAX;
794 futures[i] = eina_future_then(_int_future_with_value_and_timeout(future_ctx->value, timeouts[i]),
795 _race_cb, future_ctx);
796 fail_if(!futures[i]);
797 }
798
799 futures[--len] = EINA_FUTURE_SENTINEL;
800 fail_if(!eina_future_then(eina_future_race_array(futures),
801 _race_end_cb, &ctx));
802 ecore_main_loop_begin();
803 eina_value_flush(&ctx.value);
804 ecore_shutdown();
805 fail_if(ctx.success != 1);
806 fail_if(ctx.failed != (len - 1));
807}
808EFL_END_TEST
809
810static Eina_Value
811_eo_future1_ok(Eo *eo EINA_UNUSED, const Eina_Value v)
812{
813 const char *number;
814
815 VALUE_TYPE_CHECK(v, EINA_VALUE_TYPE_STRING);
816 fail_if(!eina_value_get(&v, &number));
817 ck_assert_str_eq(DEFAULT_INT_VALUE_AS_STRING, number);
818 return v;
819}
820
821static Eina_Value
822_eo_future1_err(Eo *eo EINA_UNUSED, Eina_Error err EINA_UNUSED)
823{
824 //Should not happen
825 fail_if(EINA_TRUE);
826}
827
828static Eina_Value
829_eo_future2_ok(Eo *eo EINA_UNUSED, const Eina_Value v)
830{
831 //Should not happen
832 fail_if(EINA_TRUE);
833 return v;
834}
835
836static Eina_Value
837_eo_future2_err(Eo *eo EINA_UNUSED, Eina_Error err)
838{
839 Eina_Value v;
840
841 fail_if(err != EINVAL);
842 fail_if(!eina_value_setup(&v, EINA_VALUE_TYPE_INT));
843 fail_if(!eina_value_set(&v, DEFAULT_INT_VALUE));
844 return v;
845}
846
847static void
848_eo_future_free(Eo *eo, const Eina_Future *dead EINA_UNUSED)
849{
850 int *free_called = efl_key_data_get(eo, "free_called");
851 (*free_called)++;
852}
853
854static Eina_Value
855_eo_chain_stop(void *data EINA_UNUSED, const Eina_Value v, const Eina_Future *dead_future EINA_UNUSED)
856{
857 int ivalue = 0;
858 VALUE_TYPE_CHECK(v, EINA_VALUE_TYPE_INT);
859 fail_if(!eina_value_get(&v, &ivalue));
860 ck_assert_int_eq(ivalue, DEFAULT_INT_VALUE);
861 ecore_main_loop_quit();
862 return v;
863}
864
865EFL_START_TEST(efl_test_promise_eo)
866{
867 Eina_Future *f;
868 Eo *obj;
869 int free_called = 0;
870
871 fail_if(!efl_object_init());
872 fail_if(!ecore_init());
873
874 //Use a random object..
875 obj = efl_add(EFL_IO_BUFFER_CLASS, efl_main_loop_get());
876 fail_if(!obj);
877 efl_key_data_set(obj, "free_called", &free_called);
878 f = eina_future_chain(_int_future_get(),
879 eina_future_cb_convert_to(EINA_VALUE_TYPE_STRING),
880 efl_future_cb(obj, _eo_future1_ok, _eo_future1_err, _eo_future_free, EINA_VALUE_TYPE_STRING),
881 efl_future_cb(obj, _eo_future2_ok, _eo_future2_err, _eo_future_free, EINA_VALUE_TYPE_INT),
882 { .cb = _eo_chain_stop });
883 fail_if(!f);
884 ecore_main_loop_begin();
885 efl_unref(obj);
886 ecore_shutdown();
887 efl_object_shutdown();
888 ck_assert_int_eq(free_called, 2);
889}
890EFL_END_TEST
891
892static Eina_Value
893_eo_future_link_success(Eo *eo EINA_UNUSED, const Eina_Value v)
894{
895 //This should never happen
896 fail_if(EINA_TRUE);
897 return v;
898}
899
900static Eina_Value
901_eo_future_link_err(Eo *eo, Eina_Error err)
902{
903 int *err_called = efl_key_data_get(eo, "err_called");
904 Eina_Value v;
905
906 fail_if(!err_called);
907 ck_assert_int_eq(err, ECANCELED);
908 fail_if(!eina_value_setup(&v, EINA_VALUE_TYPE_ERROR));
909 fail_if(!eina_value_set(&v, err));
910 (*err_called)++;
911 return v;
912}
913
914static Eina_Value
915_eo_link_chain_end(void *data EINA_UNUSED, const Eina_Value v, const Eina_Future *dead EINA_UNUSED)
916{
917 int *err_called = data;
918 VALUE_TYPE_CHECK(v, EINA_VALUE_TYPE_ERROR);
919 ERROR_CHECK(v, ECANCELED);
920 (*err_called)++;
921 return v;
922}
923
924EFL_START_TEST(efl_test_promise_eo_link)
925{
926 Eina_Future *f;
927 Eo *obj;
928 int err_called = 0;
929
930 fail_if(!efl_object_init());
931 fail_if(!ecore_init());
932
933 //Use a random object..
934 obj = efl_add(EFL_IO_BUFFER_CLASS, efl_main_loop_get());
935 fail_if(!obj);
936
937 efl_key_data_set(obj, "err_called", &err_called);
938 fail_if(!efl_key_data_get(obj, "err_called"));
939 f = efl_future_chain(obj, _int_future_get(),
940 {.success = _eo_future_link_success, .error = _eo_future_link_err},
941 {.success = _eo_future_link_success, .error = _eo_future_link_err},
942 {.success = _eo_future_link_success, .error = _eo_future_link_err},
943 {.success = _eo_future_link_success, .error = _eo_future_link_err},
944 {.success = _eo_future_link_success, .error = _eo_future_link_err});
945 fail_if(!f);
946 f = eina_future_then(f, _eo_link_chain_end, &err_called);
947 fail_if(!f);
948 /*
949 Since the mainloop is not running and the object is deleted the whole chain must be cancelled.
950 */
951 efl_unref(obj);
952 ecore_shutdown();
953 efl_object_shutdown();
954 ck_assert_int_eq(err_called, 6);
955}
956EFL_END_TEST
957
958static Eina_Value
959_err_ignored(void *data EINA_UNUSED, const Eina_Value v, const Eina_Future *f EINA_UNUSED)
960{
961 //Must be NULL since the error must be ignored.
962 VALUE_TYPE_CHECK(v, NULL);
963 ecore_main_loop_quit();
964 return v;
965}
966
967EFL_START_TEST(efl_test_promise_future_ignore_error)
968{
969 Eina_Future *f;
970
971 fail_if(!ecore_init());
972 f = _fail_future_get();
973 fail_if(!f);
974 eina_future_chain(f, eina_future_cb_ignore_error(DEFAULT_ERROR),
975 {.cb = _err_ignored});
976 ecore_main_loop_begin();
977 ecore_shutdown();
978}
979EFL_END_TEST
980
981#define PROMISE_LOG_DOMAIN_STR ("promise_test_domain")
982
983typedef struct _Promise_Log_Ctx {
984 Eina_Future_Cb_Log_Desc dbg;
985 Eina_Future_Cb_Log_Desc crit;
986 Eina_Future_Cb_Log_Desc warn;
987 Eina_Future_Cb_Log_Desc info;
988 Eina_Future_Cb_Log_Desc err;
989 Eina_Bool dbg_log_ok;
990 Eina_Bool crit_log_ok;
991 Eina_Bool warn_log_ok;
992 Eina_Bool info_log_ok;
993 Eina_Bool err_log_ok;
994} Promise_Log_Ctx;
995
996static Eina_Value
997_log_quit(void *data EINA_UNUSED, const Eina_Value v, const Eina_Future *dead EINA_UNUSED)
998{
999 int ivalue;
1000
1001 VALUE_TYPE_CHECK(v, EINA_VALUE_TYPE_INT);
1002 fail_if(!eina_value_get(&v, &ivalue));
1003 fail_if(ivalue != DEFAULT_INT_VALUE);
1004 ecore_main_loop_quit();
1005 return v;
1006}
1007
1008static void
1009_log_test(const Eina_Log_Domain *d,
1010 Eina_Log_Level level,
1011 const char *file, const char *fnc, int line,
1012 const char *fmt, void *data, va_list args)
1013{
1014 Promise_Log_Ctx *ctx = data;
1015 Eina_Bool *log_ok;
1016 Eina_Future_Cb_Log_Desc *desc;
1017 va_list cpy;
1018 const char *prefix, *suffix, *value;
1019
1020 if (strcmp(d->name, PROMISE_LOG_DOMAIN_STR))
1021 return;
1022
1023 switch (level)
1024 {
1025 case EINA_LOG_LEVEL_DBG:
1026 log_ok = &ctx->dbg_log_ok;
1027 desc = &ctx->dbg;
1028 break;
1029 case EINA_LOG_LEVEL_CRITICAL:
1030 log_ok = &ctx->crit_log_ok;
1031 desc = &ctx->crit;
1032 break;
1033 case EINA_LOG_LEVEL_WARN:
1034 log_ok = &ctx->warn_log_ok;
1035 desc = &ctx->warn;
1036 break;
1037 case EINA_LOG_LEVEL_INFO:
1038 log_ok = &ctx->info_log_ok;
1039 desc = &ctx->info;
1040 break;
1041 default:
1042 log_ok = &ctx->err_log_ok;
1043 desc = &ctx->err;
1044 }
1045
1046 ck_assert_str_eq(fnc, desc->func);
1047 ck_assert_str_eq(file, desc->file);
1048 ck_assert_str_eq(fmt, "%s%s%s");
1049 ck_assert_int_eq(desc->line, line);
1050 //FIXME: REmove this check
1051 ck_assert_int_eq(desc->level, level);
1052 va_copy(cpy, args);
1053 prefix = va_arg(cpy, const char *);
1054 value = va_arg(cpy, const char *);
1055 suffix = va_arg(cpy, const char *);
1056 ck_assert_str_eq(prefix, desc->prefix ? desc->prefix : "");
1057 ck_assert_str_eq(suffix, desc->suffix ? desc->suffix : "");
1058 ck_assert_str_eq(value, DEFAULT_INT_VALUE_AS_STRING);
1059 va_end(cpy);
1060 *log_ok = EINA_TRUE;
1061}
1062
1063EFL_START_TEST(efl_test_promise_log)
1064{
1065 Promise_Log_Ctx ctx = { 0 };
1066 Eina_Future *f;
1067 int domain;
1068
1069 fail_if(!ecore_init());
1070
1071 domain = eina_log_domain_register(PROMISE_LOG_DOMAIN_STR, EINA_COLOR_CYAN);
1072 fail_if(domain < 0);
1073 eina_log_domain_level_set(PROMISE_LOG_DOMAIN_STR, EINA_LOG_LEVEL_DBG);
1074 ctx.dbg = (Eina_Future_Cb_Log_Desc){"dbg prefix:", " dbg suffix", __FILE__,
1075 __FUNCTION__, EINA_LOG_LEVEL_DBG,
1076 domain, __LINE__};
1077 ctx.crit = (Eina_Future_Cb_Log_Desc){NULL, NULL, __FILE__,
1078 __FUNCTION__, EINA_LOG_LEVEL_CRITICAL,
1079 domain, __LINE__};
1080 ctx.warn = (Eina_Future_Cb_Log_Desc){"warn prefix:", NULL, __FILE__,
1081 __FUNCTION__, EINA_LOG_LEVEL_WARN,
1082 domain, __LINE__};
1083 ctx.err = (Eina_Future_Cb_Log_Desc){NULL, " err suffix", __FILE__,
1084 __FUNCTION__, EINA_LOG_LEVEL_ERR,
1085 domain, __LINE__};
1086 ctx.info = (Eina_Future_Cb_Log_Desc){"info prefix:", " info suffix",
1087 __FILE__, __FUNCTION__, EINA_LOG_LEVEL_INFO,
1088 domain, __LINE__};
1089 eina_log_print_cb_set(_log_test, &ctx);
1090 f = eina_future_chain(_int_future_get(),
1091 eina_future_cb_log_from_desc(ctx.dbg),
1092 eina_future_cb_log_from_desc(ctx.crit),
1093 eina_future_cb_log_from_desc(ctx.warn),
1094 eina_future_cb_log_from_desc(ctx.err),
1095 eina_future_cb_log_from_desc(ctx.info),
1096 { _log_quit });
1097 fail_if(!f);
1098 ecore_main_loop_begin();
1099 eina_log_domain_unregister(domain);
1100 ecore_shutdown();
1101 fail_if(!ctx.dbg_log_ok);
1102 fail_if(!ctx.crit_log_ok);
1103 fail_if(!ctx.warn_log_ok);
1104 fail_if(!ctx.err_log_ok);
1105 fail_if(!ctx.info_log_ok);
1106}
1107EFL_END_TEST
1108
1109#ifdef EINA_SAFETY_CHECKS
1110
1111static void
1112_dummy_cancel(void *data EINA_UNUSED, const Eina_Promise *dead EINA_UNUSED)
1113{
1114}
1115
1116EFL_START_TEST(efl_test_promise_null)
1117{
1118 Log_Ctx ctx = { 0 };
1119 Eina_Promise *p;
1120
1121 fail_if(!ecore_init());
1122
1123 eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx);
1124 LOG_CTX_SET(ctx, "eina_promise_new", "safety check failed: scheduler == NULL");
1125 p = eina_promise_new(NULL, _dummy_cancel, NULL);
1126 ck_assert_ptr_eq(p, NULL);
1127 fail_unless(ctx.did);
1128
1129 LOG_CTX_SET(ctx, "eina_promise_new", "safety check failed: cancel_cb == NULL");
1130 p = eina_promise_new(_future_scheduler_get(), NULL, NULL);
1131 ck_assert_ptr_eq(p, NULL);
1132 fail_unless(ctx.did);
1133
1134 ecore_shutdown();
1135}
1136EFL_END_TEST
1137
1138EFL_START_TEST(efl_test_promise_reject_resolve_null)
1139{
1140 Log_Ctx ctx = { 0 };
1141 Eina_Value v;
1142
1143 fail_if(!ecore_init());
1144
1145 LOG_CTX_SET(ctx, "eina_promise_resolve", "safety check failed: (p) == NULL");
1146 eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx);
1147 eina_value_setup(&v, EINA_VALUE_TYPE_INT);
1148 VALUE_TYPE_CHECK(v, EINA_VALUE_TYPE_INT);
1149 eina_promise_resolve(NULL, v);
1150 fail_unless(ctx.did);
1151
1152 LOG_CTX_SET(ctx, "eina_promise_reject", "safety check failed: (p) == NULL");
1153 eina_promise_reject(NULL, DEFAULT_ERROR);
1154 fail_unless(ctx.did);
1155 ecore_shutdown();
1156}
1157EFL_END_TEST
1158
1159static Eina_Value
1160_future_null_cb(void *data, const Eina_Value v, const Eina_Future *dead)
1161{
1162 int err;
1163 int *cb_called = data;
1164
1165 ck_assert_ptr_eq(dead, NULL);
1166 VALUE_TYPE_CHECK(v, EINA_VALUE_TYPE_ERROR);
1167 fail_if(!eina_value_get(&v, &err));
1168 ck_assert_int_eq(err, EINVAL);
1169 (*cb_called)++;
1170 return v;
1171}
1172
1173static Eina_Value
1174_future_easy_null_success(void *data EINA_UNUSED, const Eina_Value v)
1175{
1176 //Should not happen
1177 fail_if(EINA_TRUE);
1178 return v;
1179}
1180
1181static Eina_Value
1182_future_easy_null_err(void *data, Eina_Error err)
1183{
1184 int *cb_called = data;
1185 ck_assert_int_eq(err, EINVAL);
1186 (*cb_called)++;
1187 return eina_value_error_init(err);
1188}
1189
1190static void
1191_future_easy_null_free(void *data, const Eina_Future *dead)
1192{
1193 int *cb_called = data;
1194 ck_assert_ptr_eq(dead, NULL);
1195 (*cb_called)++;
1196}
1197
1198EFL_START_TEST(efl_test_future_null)
1199{
1200 Eina_Future *f;
1201 Log_Ctx ctx = { 0 };
1202 int cb_called = 0;
1203 int easy_cb_calls = 0;
1204
1205 fail_if(!ecore_init());
1206
1207 LOG_CTX_SET(ctx, "eina_future_then_from_desc", "safety check failed: (prev) == NULL");
1208 eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx);
1209 f = eina_future_then(NULL, _future_null_cb, &cb_called);
1210 ck_assert_ptr_eq(f, NULL);
1211
1212 ck_assert_int_eq(cb_called, 1);
1213
1214 cb_called = 0;
1215 LOG_CTX_SET(ctx, "eina_future_chain_array", "safety check failed: (prev) == NULL");
1216 f = eina_future_chain(NULL,
1217 eina_future_cb_easy(_future_easy_null_success,
1218 _future_easy_null_err,
1219 _future_easy_null_free,
1220 NULL, &easy_cb_calls),
1221 {_future_null_cb, &cb_called},
1222 {_future_null_cb, &cb_called},
1223 {_future_null_cb, &cb_called},
1224 {_future_null_cb, &cb_called},
1225 {_future_null_cb, &cb_called});
1226 ck_assert_ptr_eq(f, NULL);
1227 ck_assert_int_eq(cb_called, 5);
1228 ck_assert_int_eq(easy_cb_calls, 2);
1229
1230 easy_cb_calls = 0;
1231 LOG_CTX_SET(ctx, "eina_future_chain_easy_array", "safety check failed: (prev) == NULL");
1232 f = eina_future_chain_easy(NULL,
1233 {_future_easy_null_success,
1234 _future_easy_null_err,
1235 _future_easy_null_free,
1236 NULL, &easy_cb_calls});
1237 ck_assert_ptr_eq(f, NULL);
1238 ck_assert_int_eq(easy_cb_calls, 2);
1239 ecore_shutdown();
1240}
1241EFL_END_TEST
1242
1243static Eina_Value
1244_future_race_all_null_cb(void *data, const Eina_Value v, const Eina_Future *dead EINA_UNUSED)
1245{
1246 int err;
1247 int *cb_called = data;
1248
1249 VALUE_TYPE_CHECK(v, EINA_VALUE_TYPE_ERROR);
1250 fail_if(!eina_value_get(&v, &err));
1251 ck_assert_int_eq(err, ENOMEM);
1252 (*cb_called)++;
1253 return v;
1254}
1255
1256EFL_START_TEST(efl_test_future_all_null)
1257{
1258 Log_Ctx ctx = { 0 };
1259 unsigned i, len;
1260 int cb_called = 0;
1261 Eina_Future *futures[11] = { 0 }, *f;
1262
1263 fail_if(!ecore_init());
1264
1265 eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx);
1266
1267 len = EINA_C_ARRAY_LENGTH(futures);
1268 len--;
1269 for (i = 0; i < len; i++)
1270 {
1271 futures[i] = eina_future_then(_int_future_get(),
1272 _future_race_all_null_cb, &cb_called);
1273 fail_if(!futures[i]);
1274 }
1275
1276 LOG_CTX_MULTIPLE_FUNC_CTX_SET(ctx,
1277 {"promise_proxy_of_future_array_create", "safety check failed: array[i] == NULL"},
1278 {"eina_promise_all_array", "safety check failed: r is false"});
1279 //The last future is NULL, which may cause the cancel.
1280 f = eina_future_all_array(futures);
1281 ck_assert_ptr_eq(f, NULL);
1282 ecore_shutdown();
1283 ck_assert_int_eq(cb_called, len);
1284}
1285EFL_END_TEST
1286
1287EFL_START_TEST(efl_test_future_race_null)
1288{
1289 Log_Ctx ctx = { 0 };
1290 unsigned i, len;
1291 int cb_called = 0;
1292 Eina_Future *futures[11] = { 0 }, *f;
1293
1294 fail_if(!ecore_init());
1295
1296 eina_log_print_cb_set(_eina_test_safety_print_cb, &ctx);
1297
1298 len = EINA_C_ARRAY_LENGTH(futures);
1299 len--;
1300 for (i = 0; i < len; i++)
1301 {
1302 futures[i] = eina_future_then(_int_future_get(),
1303 _future_race_all_null_cb, &cb_called);
1304 fail_if(!futures[i]);
1305 }
1306
1307 LOG_CTX_MULTIPLE_FUNC_CTX_SET(ctx,
1308 {"promise_proxy_of_future_array_create", "safety check failed: array[i] == NULL"},
1309 {"eina_promise_race_array", "safety check failed: r is false"});
1310 //The last future is NULL, which may cause the cancel.
1311 f = eina_future_race_array(futures);
1312 ck_assert_ptr_eq(f, NULL);
1313 ecore_shutdown();
1314 ck_assert_int_eq(cb_called, len);
1315}
1316EFL_END_TEST
1317
1318#endif
1319
1320static void
1321promise_init(void)
1322{
1323 /* enable ecore init count manipulation for these tests */
1324 ecore_shutdown();
1325}
1326
1327static void
1328promise_shutdown(void)
1329{
1330 /* enable ecore init count manipulation for these tests */
1331 ecore_init();
1332}
1333
1334void efl_app_test_promise(TCase *tc)
1335{
1336 tcase_add_checked_fixture(tc, promise_init, promise_shutdown);
1337 tcase_add_test(tc, efl_test_timeout);
1338 tcase_add_test(tc, efl_test_job);
1339 tcase_add_test(tc, efl_test_idle);
1340 tcase_add_test(tc, efl_test_promise_future_success);
1341 tcase_add_test(tc, efl_test_promise_future_failure);
1342 tcase_add_test(tc, efl_test_promise_future_chain_no_error);
1343 tcase_add_test(tc, efl_test_promise_future_chain_error);
1344 tcase_add_test(tc, efl_test_promise_future_cancel);
1345 tcase_add_test(tc, efl_test_promise_future_implicit_cancel);
1346 tcase_add_test(tc, efl_test_promise_future_inner_promise);
1347 tcase_add_test(tc, efl_test_promise_future_inner_promise_fail);
1348 tcase_add_test(tc, efl_test_promise_future_convert);
1349 tcase_add_test(tc, efl_test_promise_future_easy);
1350 tcase_add_test(tc, efl_test_promise_future_all);
1351 tcase_add_test(tc, efl_test_promise_future_race);
1352 tcase_add_test(tc, efl_test_promise_future_ignore_error);
1353 tcase_add_test(tc, efl_test_promise_log);
1354 //FIXME: We should move this to EO tests, however they depend on Ecore...
1355 tcase_add_test(tc, efl_test_promise_eo);
1356 tcase_add_test(tc, efl_test_promise_eo_link);
1357
1358#ifdef EINA_SAFETY_CHECKS
1359 tcase_add_test(tc, efl_test_promise_null);
1360 tcase_add_test(tc, efl_test_promise_reject_resolve_null);
1361 tcase_add_test(tc, efl_test_future_null);
1362 tcase_add_test(tc, efl_test_future_all_null);
1363 tcase_add_test(tc, efl_test_future_race_null);
1364#endif
1365}