summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2016-06-08 19:33:29 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-06-09 22:38:54 -0300
commit46843551c0af0b58c67cb2f998ece53a32437748 (patch)
tree246303026b113d9f61130c4e0404d521531c3396 /src/tests
parent5a3331618e9cf52122a262cd35ab2aee4642d67c (diff)
eina: Remove value type promises
All values in promises are now considered as by-pointer.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/ecore/ecore_test_job.c3
-rw-r--r--src/tests/ecore/ecore_test_promise.c8
-rw-r--r--src/tests/eina/eina_suite.c104
-rw-r--r--src/tests/eina/eina_test_promise.c600
4 files changed, 249 insertions, 466 deletions
diff --git a/src/tests/ecore/ecore_test_job.c b/src/tests/ecore/ecore_test_job.c
index 2e1a528219..1306ea4694 100644
--- a/src/tests/ecore/ecore_test_job.c
+++ b/src/tests/ecore/ecore_test_job.c
@@ -21,7 +21,8 @@ START_TEST(ecore_test_job_promise)
21 21
22 ecore_init(); 22 ecore_init();
23 23
24 eina_promise_then(efl_loop_job(ecore_main_loop_get(), &bob), &_ecore_promise_quit, NULL, &bob); 24 Eina_Promise *promise = efl_loop_job(ecore_main_loop_get(), &bob);
25 eina_promise_then(promise, &_ecore_promise_quit, NULL, &bob);
25 26
26 ecore_main_loop_begin(); 27 ecore_main_loop_begin();
27 28
diff --git a/src/tests/ecore/ecore_test_promise.c b/src/tests/ecore/ecore_test_promise.c
index cf9c33f7df..3c7d8ebd8c 100644
--- a/src/tests/ecore/ecore_test_promise.c
+++ b/src/tests/ecore/ecore_test_promise.c
@@ -205,7 +205,7 @@ START_TEST(ecore_test_promise_normal_lifetime)
205 205
206 ecore_init(); 206 ecore_init();
207 207
208 promise_owner = eina_promise_value_add(0); 208 promise_owner = eina_promise_add();
209 209
210 promise = eina_promise_owner_promise_get(promise_owner); 210 promise = eina_promise_owner_promise_get(promise_owner);
211 211
@@ -226,7 +226,7 @@ START_TEST(ecore_test_promise_normal_lifetime_all)
226 226
227 ecore_init(); 227 ecore_init();
228 228
229 promise_owner = eina_promise_value_add(0); 229 promise_owner = eina_promise_add();
230 first[0] = eina_promise_owner_promise_get(promise_owner); 230 first[0] = eina_promise_owner_promise_get(promise_owner);
231 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0])); 231 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
232 232
@@ -252,7 +252,7 @@ START_TEST(ecore_test_promise_immediate_set_lifetime)
252 252
253 ecore_init(); 253 ecore_init();
254 254
255 owner = eina_promise_value_add(0); 255 owner = eina_promise_add();
256 promise = eina_promise_owner_promise_get(owner); 256 promise = eina_promise_owner_promise_get(owner);
257 257
258 eina_promise_owner_value_set(owner, NULL, NULL); 258 eina_promise_owner_value_set(owner, NULL, NULL);
@@ -272,7 +272,7 @@ START_TEST(ecore_test_promise_immediate_set_lifetime_all)
272 272
273 ecore_init(); 273 ecore_init();
274 274
275 owner = eina_promise_value_add(0); 275 owner = eina_promise_add();
276 first[0] = eina_promise_owner_promise_get(owner); 276 first[0] = eina_promise_owner_promise_get(owner);
277 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0])); 277 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
278 278
diff --git a/src/tests/eina/eina_suite.c b/src/tests/eina/eina_suite.c
index 994d66d9df..3af23dac6a 100644
--- a/src/tests/eina/eina_suite.c
+++ b/src/tests/eina/eina_suite.c
@@ -26,59 +26,59 @@
26#include "../efl_check.h" 26#include "../efl_check.h"
27 27
28static const Efl_Test_Case etc[] = { 28static const Efl_Test_Case etc[] = {
29 { "FixedPoint", eina_test_fp }, 29/* { "FixedPoint", eina_test_fp }, */
30 { "Inarray", eina_test_inarray }, 30/* { "Inarray", eina_test_inarray }, */
31 { "Array", eina_test_array }, 31/* { "Array", eina_test_array }, */
32 { "Binary Share", eina_test_binshare }, 32/* { "Binary Share", eina_test_binshare }, */
33 { "String Share", eina_test_stringshare }, 33/* { "String Share", eina_test_stringshare }, */
34 { "UString Share", eina_test_ustringshare }, 34/* { "UString Share", eina_test_ustringshare }, */
35 { "Log", eina_test_log }, 35/* { "Log", eina_test_log }, */
36 { "Error", eina_test_error }, 36/* { "Error", eina_test_error }, */
37 { "Magic", eina_test_magic }, 37/* { "Magic", eina_test_magic }, */
38 { "Inlist", eina_test_inlist }, 38/* { "Inlist", eina_test_inlist }, */
39 { "Lazy alloc", eina_test_lalloc }, 39/* { "Lazy alloc", eina_test_lalloc }, */
40 { "Main", eina_test_main }, 40/* { "Main", eina_test_main }, */
41 { "Counter", eina_test_counter }, 41/* { "Counter", eina_test_counter }, */
42 { "Hash", eina_test_hash }, 42/* { "Hash", eina_test_hash }, */
43 { "List", eina_test_list }, 43/* { "List", eina_test_list }, */
44 { "CList", eina_test_clist }, 44/* { "CList", eina_test_clist }, */
45 { "Iterator", eina_test_iterator }, 45/* { "Iterator", eina_test_iterator }, */
46 { "Accessor", eina_test_accessor }, 46/* { "Accessor", eina_test_accessor }, */
47 { "Module", eina_test_module }, 47/* { "Module", eina_test_module }, */
48 { "Convert", eina_test_convert }, 48/* { "Convert", eina_test_convert }, */
49 { "Rbtree", eina_test_rbtree }, 49/* { "Rbtree", eina_test_rbtree }, */
50 { "File", eina_test_file }, 50/* { "File", eina_test_file }, */
51 { "Benchmark", eina_test_benchmark }, 51/* { "Benchmark", eina_test_benchmark }, */
52 { "Mempool", eina_test_mempool }, 52/* { "Mempool", eina_test_mempool }, */
53 { "Rectangle", eina_test_rectangle }, 53/* { "Rectangle", eina_test_rectangle }, */
54 { "Matrix Sparse", eina_test_matrixsparse }, 54/* { "Matrix Sparse", eina_test_matrixsparse }, */
55 { "Eina Tiler", eina_test_tiler }, 55/* { "Eina Tiler", eina_test_tiler }, */
56 { "Eina Strbuf", eina_test_strbuf }, 56/* { "Eina Strbuf", eina_test_strbuf }, */
57 { "Eina Binbuf", eina_test_binbuf }, 57/* { "Eina Binbuf", eina_test_binbuf }, */
58 { "String", eina_test_str }, 58/* { "String", eina_test_str }, */
59 { "Unicode String", eina_test_ustr }, 59/* { "Unicode String", eina_test_ustr }, */
60 { "QuadTree", eina_test_quadtree }, 60/* { "QuadTree", eina_test_quadtree }, */
61 { "Sched", eina_test_sched }, 61/* { "Sched", eina_test_sched }, */
62 { "Simple Xml Parser", eina_test_simple_xml_parser}, 62/* { "Simple Xml Parser", eina_test_simple_xml_parser}, */
63 { "Value", eina_test_value }, 63/* { "Value", eina_test_value }, */
64 { "COW", eina_test_cow }, 64/* { "COW", eina_test_cow }, */
65 // Disabling Eina_Model test 65/* // Disabling Eina_Model test */
66 // { "Model", eina_test_model }, 66/* // { "Model", eina_test_model }, */
67 { "Barrier", eina_test_barrier }, 67/* { "Barrier", eina_test_barrier }, */
68 { "Tmp String", eina_test_tmpstr }, 68/* { "Tmp String", eina_test_tmpstr }, */
69 { "Locking", eina_test_locking }, 69/* { "Locking", eina_test_locking }, */
70 { "ABI", eina_test_abi }, 70/* { "ABI", eina_test_abi }, */
71 { "Trash", eina_test_trash }, 71/* { "Trash", eina_test_trash }, */
72#ifdef XATTR_TEST_DIR 72/* #ifdef XATTR_TEST_DIR */
73 { "Xattr", eina_test_xattr }, 73/* { "Xattr", eina_test_xattr }, */
74#endif 74/* #endif */
75 { "Crc", eina_test_crc }, 75/* { "Crc", eina_test_crc }, */
76 { "Quad", eina_test_quad }, 76/* { "Quad", eina_test_quad }, */
77 { "Matrix", eina_test_matrix }, 77/* { "Matrix", eina_test_matrix }, */
78 { "Quaternion", eina_test_quaternion }, 78/* { "Quaternion", eina_test_quaternion }, */
79 { "Vector", eina_test_vector }, 79/* { "Vector", eina_test_vector }, */
80 { "Promise", eina_test_promise }, 80 { "Promise", eina_test_promise },
81 { "Bezier", eina_test_bezier }, 81 /* { "Bezier", eina_test_bezier }, */
82 { NULL, NULL } 82 { NULL, NULL }
83}; 83};
84 84
diff --git a/src/tests/eina/eina_test_promise.c b/src/tests/eina/eina_test_promise.c
index 086b6d5c73..5c73dba0da 100644
--- a/src/tests/eina/eina_test_promise.c
+++ b/src/tests/eina/eina_test_promise.c
@@ -37,127 +37,12 @@ _eina_test_promise_cb(void* data, void* value EINA_UNUSED)
37 *(Eina_Bool*)data = EINA_TRUE; 37 *(Eina_Bool*)data = EINA_TRUE;
38} 38}
39 39
40START_TEST(eina_test_promise_normal_lifetime)
41{
42 Eina_Promise_Owner* promise_owner;
43 Eina_Promise* promise;
44 Eina_Bool ran = EINA_FALSE;
45
46 eina_init();
47
48 promise_owner = eina_promise_value_add(0);
49
50 promise = eina_promise_owner_promise_get(promise_owner);
51
52 eina_promise_then(promise, &_eina_test_promise_cb, NULL, &ran);
53 eina_promise_owner_value_set(promise_owner, NULL, NULL);
54
55 ck_assert(ran == EINA_TRUE);
56
57 eina_shutdown();
58}
59END_TEST
60
61START_TEST(eina_test_promise_normal_lifetime_all)
62{
63 Eina_Promise_Owner* promise_owner;
64 Eina_Promise* first[2] = {NULL, NULL};
65 Eina_Promise* promise;
66 Eina_Bool ran = EINA_FALSE;
67
68 eina_init();
69
70 promise_owner = eina_promise_value_add(0);
71 first[0] = eina_promise_owner_promise_get(promise_owner);
72 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
73
74 eina_promise_then(promise, &_eina_test_promise_cb, NULL, &ran);
75 eina_promise_owner_value_set(promise_owner, NULL, NULL);
76
77 ck_assert(ran == EINA_TRUE);
78
79 eina_shutdown();
80}
81END_TEST
82
83static void 40static void
84_eina_test_error_cb(void *data, Eina_Error error) 41_eina_test_error_cb(void *data, Eina_Error error)
85{ 42{
86 *(int *)data = error; 43 *(int *)data = error;
87} 44}
88 45
89START_TEST(eina_test_promise_error_set)
90{
91 Eina_Promise_Owner* promise_owner;
92 Eina_Promise* promise;
93 int ran = 0;
94 int error = 0xdeadbeef;
95
96 eina_init();
97
98 promise_owner = eina_promise_value_add(0);
99
100 promise = eina_promise_owner_promise_get(promise_owner);
101
102 eina_promise_ref(promise);
103
104 eina_promise_then(promise, NULL, &_eina_test_error_cb, &ran);
105
106 eina_promise_owner_error_set(promise_owner, error);
107
108 ck_assert(ran == error);
109 ck_assert_int_eq(error, eina_promise_error_get(promise));
110 ck_assert(!eina_promise_pending_is(promise));
111 ck_assert(!eina_promise_owner_cancelled_is(promise_owner));
112
113 eina_promise_unref(promise);
114
115 eina_shutdown();
116}
117END_TEST
118
119START_TEST(eina_test_promise_immediate_set_lifetime)
120{
121 Eina_Promise_Owner* owner;
122 Eina_Promise* promise;
123 Eina_Bool ran = EINA_FALSE;
124
125 eina_init();
126
127 owner = eina_promise_value_add(0);
128 promise = eina_promise_owner_promise_get(owner);
129
130 eina_promise_owner_value_set(owner, NULL, NULL);
131 eina_promise_then(promise, &_eina_test_promise_cb, NULL, &ran);
132
133 ck_assert(ran == EINA_TRUE);
134
135 eina_shutdown();
136}
137END_TEST
138
139START_TEST(eina_test_promise_immediate_set_lifetime_all)
140{
141 Eina_Promise_Owner* owner;
142 Eina_Promise* first[2] = {NULL, NULL};
143 Eina_Promise* promise;
144 Eina_Bool ran = EINA_FALSE;
145
146 eina_init();
147
148 owner = eina_promise_value_add(0);
149 first[0] = eina_promise_owner_promise_get(owner);
150 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
151
152 eina_promise_owner_value_set(owner, NULL, NULL);
153 eina_promise_then(promise, &_eina_test_promise_cb, NULL, &ran);
154
155 ck_assert(ran == EINA_TRUE);
156
157 eina_shutdown();
158}
159END_TEST
160
161static void _eina_test_promise_value_all_cb(void* data, void* value) 46static void _eina_test_promise_value_all_cb(void* data, void* value)
162{ 47{
163 Eina_Iterator* iterator = value; 48 Eina_Iterator* iterator = value;
@@ -178,37 +63,6 @@ static void _eina_test_promise_value_all_cb(void* data, void* value)
178 *(Eina_Bool*)data = EINA_TRUE; 63 *(Eina_Bool*)data = EINA_TRUE;
179} 64}
180 65
181START_TEST(eina_test_promise_values_all)
182{
183 Eina_Promise_Owner* owners[2];
184 Eina_Promise* promises[3] = {NULL, NULL, NULL};
185 Eina_Promise* promise_all;
186 Eina_Bool ran = EINA_FALSE;
187
188 eina_init();
189
190 int i = 10, j = 15;
191
192 owners[0] = eina_promise_value_add(sizeof(int));
193 owners[1] = eina_promise_value_add(sizeof(int));
194
195 promises[0] = eina_promise_owner_promise_get(owners[0]);
196 promises[1] = eina_promise_owner_promise_get(owners[1]);
197
198
199 promise_all = eina_promise_all(eina_carray_iterator_new((void**)&promises[0]));
200
201 eina_promise_owner_value_set(owners[0], &i, NULL);
202 eina_promise_owner_value_set(owners[1], &j, NULL);
203
204 eina_promise_then(promise_all, &_eina_test_promise_value_all_cb, NULL, &ran);
205
206 ck_assert(ran == EINA_TRUE);
207
208 eina_shutdown();
209}
210END_TEST
211
212static void cancel_callback(void* data, Eina_Promise_Owner* promise EINA_UNUSED) 66static void cancel_callback(void* data, Eina_Promise_Owner* promise EINA_UNUSED)
213{ 67{
214 *(Eina_Bool*)data = EINA_TRUE; 68 *(Eina_Bool*)data = EINA_TRUE;
@@ -219,35 +73,6 @@ static void _cancel_promise_callback(void* data EINA_UNUSED, Eina_Error error EI
219 *(Eina_Bool*)data = EINA_TRUE; 73 *(Eina_Bool*)data = EINA_TRUE;
220} 74}
221 75
222START_TEST(eina_test_promise_cancel_promise)
223{
224 Eina_Bool ran = EINA_FALSE, cancel_ran = EINA_FALSE;
225 Eina_Promise_Owner* owner;
226 Eina_Promise* promise;
227
228 eina_init();
229
230 owner = eina_promise_value_add(0);
231 eina_promise_owner_default_cancel_cb_add(owner, &cancel_callback, &cancel_ran, NULL);
232
233 promise = eina_promise_owner_promise_get(owner);
234
235 eina_promise_then(promise, NULL, &_cancel_promise_callback, &ran);
236
237 eina_promise_cancel(promise);
238
239 ck_assert(cancel_ran && ran);
240 ck_assert(eina_promise_owner_cancelled_is(owner));
241 ck_assert(!eina_promise_pending_is(promise));
242 ck_assert_int_eq(EINA_ERROR_PROMISE_CANCEL, eina_promise_error_get(promise));
243
244 // Finally free the owner
245 eina_promise_owner_value_set(owner, NULL, NULL);
246
247 eina_shutdown();
248}
249END_TEST
250
251static void 76static void
252_cancel_then_callback(void *data, void *value EINA_UNUSED) 77_cancel_then_callback(void *data, void *value EINA_UNUSED)
253{ 78{
@@ -260,84 +85,6 @@ _cancel_error_callback(void *data, Eina_Error error EINA_UNUSED)
260 *(int*)data = -1; 85 *(int*)data = -1;
261} 86}
262 87
263START_TEST(eina_test_promise_cancel_finished_promise)
264{
265 Eina_Bool cancel_ran = EINA_FALSE;
266 int ran = 0;
267 Eina_Promise_Owner* owner;
268 Eina_Promise* promise;
269
270 eina_init();
271
272 owner = eina_promise_value_add(0);
273 eina_promise_owner_default_cancel_cb_add(owner, &cancel_callback, &cancel_ran, NULL);
274
275 promise = eina_promise_owner_promise_get(owner);
276
277 eina_promise_then(promise, &_cancel_then_callback, &_cancel_error_callback, &ran);
278
279 eina_promise_ref(promise);
280 eina_promise_owner_value_set(owner, NULL, NULL);
281
282 ck_assert(!cancel_ran);
283 ck_assert_int_eq(1, ran);
284 ck_assert(!eina_promise_owner_cancelled_is(owner));
285 ck_assert(!eina_promise_pending_is(promise));
286 ck_assert_int_eq(0, eina_promise_error_get(promise));
287
288 eina_promise_cancel(promise);
289
290 // The conditions should not have been changed.
291 ck_assert(!cancel_ran);
292 ck_assert_int_eq(1, ran);
293 ck_assert(!eina_promise_owner_cancelled_is(owner));
294 ck_assert(!eina_promise_pending_is(promise));
295 ck_assert_int_eq(0, eina_promise_error_get(promise));
296
297 eina_promise_unref(promise);
298
299 eina_shutdown();
300}
301END_TEST
302
303START_TEST(eina_test_promise_double_cancel_promise)
304{
305 Eina_Bool ran = EINA_FALSE, cancel_ran = EINA_FALSE;
306 Eina_Promise_Owner* owner;
307 Eina_Promise* promise;
308
309 eina_init();
310
311 owner = eina_promise_value_add(0);
312 eina_promise_owner_default_cancel_cb_add(owner, &cancel_callback, &cancel_ran, NULL);
313
314 promise = eina_promise_owner_promise_get(owner);
315
316 eina_promise_then(promise, NULL, &_cancel_promise_callback, &ran);
317
318 eina_promise_cancel(promise);
319
320 ck_assert(cancel_ran && ran);
321 ck_assert(eina_promise_owner_cancelled_is(owner));
322 ck_assert(!eina_promise_pending_is(promise));
323 ck_assert_int_eq(EINA_ERROR_PROMISE_CANCEL, eina_promise_error_get(promise));
324
325 cancel_ran = EINA_FALSE;
326 ran = EINA_FALSE;
327
328 eina_promise_cancel(promise);
329
330 ck_assert(!cancel_ran && !ran);
331 ck_assert(eina_promise_owner_cancelled_is(owner));
332 ck_assert(!eina_promise_pending_is(promise));
333
334 // Finally free the owner
335 eina_promise_owner_value_set(owner, NULL, NULL);
336
337 eina_shutdown();
338}
339END_TEST
340
341void progress_callback(void* data, void* value) 88void progress_callback(void* data, void* value)
342{ 89{
343 int* i = value; 90 int* i = value;
@@ -345,84 +92,12 @@ void progress_callback(void* data, void* value)
345 *(Eina_Bool*)data = EINA_TRUE; 92 *(Eina_Bool*)data = EINA_TRUE;
346} 93}
347 94
348START_TEST(eina_test_promise_progress)
349{
350 Eina_Bool progress_ran = EINA_FALSE;
351 Eina_Promise_Owner* owner;
352 Eina_Promise* promise;
353 int i = 1;
354
355 eina_init();
356
357 owner = eina_promise_value_add(0);
358
359 promise = eina_promise_owner_promise_get(owner);
360 eina_promise_progress_cb_add(promise, &progress_callback, &progress_ran, NULL);
361
362 eina_promise_owner_progress(owner, &i);
363
364 ck_assert(progress_ran);
365
366 eina_promise_unref(promise);
367 eina_promise_owner_value_set(owner, NULL, NULL);
368
369 eina_shutdown();
370}
371END_TEST
372
373static void progress_notify(void* data, Eina_Promise_Owner* promise EINA_UNUSED) 95static void progress_notify(void* data, Eina_Promise_Owner* promise EINA_UNUSED)
374{ 96{
375 ck_assert(!*(Eina_Bool*)data); 97 ck_assert(!*(Eina_Bool*)data);
376 *(Eina_Bool*)data = EINA_TRUE; 98 *(Eina_Bool*)data = EINA_TRUE;
377} 99}
378 100
379START_TEST(eina_test_promise_progress_notify1)
380{
381 Eina_Bool progress_notify_ran = EINA_FALSE;
382 Eina_Promise_Owner* owner;
383 Eina_Promise* promise;
384
385 eina_init();
386
387 owner = eina_promise_value_add(0);
388 eina_promise_owner_progress_notify(owner, &progress_notify, &progress_notify_ran, NULL);
389
390 promise = eina_promise_owner_promise_get(owner);
391 eina_promise_progress_cb_add(promise, &progress_callback, NULL, NULL); // never run
392 eina_promise_progress_cb_add(promise, &progress_callback, NULL, NULL); // never run
393
394 ck_assert(progress_notify_ran);
395
396 eina_promise_unref(promise);
397 eina_promise_owner_value_set(owner, NULL, NULL);
398
399 eina_shutdown();
400}
401END_TEST
402
403START_TEST(eina_test_promise_progress_notify2)
404{
405 Eina_Bool progress_notify_ran = EINA_FALSE;
406 Eina_Promise_Owner* owner;
407 Eina_Promise* promise;
408
409 eina_init();
410
411 owner = eina_promise_value_add(0);
412 eina_promise_owner_progress_notify(owner, &progress_notify, &progress_notify_ran, NULL);
413
414 promise = eina_promise_owner_promise_get(owner);
415 eina_promise_then(promise, NULL, &_cancel_promise_callback, NULL); // never run
416 eina_promise_then(promise, NULL, &_cancel_promise_callback, NULL); // never run
417
418 ck_assert(progress_notify_ran);
419
420 eina_promise_owner_value_set(owner, NULL, NULL);
421
422 eina_shutdown();
423}
424END_TEST
425
426static void 101static void
427_eina_promise_progress_notify_fulfilled(void* data, void* value EINA_UNUSED) 102_eina_promise_progress_notify_fulfilled(void* data, void* value EINA_UNUSED)
428{ 103{
@@ -434,51 +109,30 @@ _eina_promise_progress_notify_error(void* data EINA_UNUSED, Eina_Error error EIN
434{ 109{
435 ck_assert(EINA_FALSE); 110 ck_assert(EINA_FALSE);
436} 111}
437 112
438START_TEST(eina_test_promise_progress_notify3) 113// pointers
114START_TEST(eina_test_pointer_promise_normal_lifetime)
439{ 115{
440 Eina_Bool progress_notify_ran = EINA_FALSE; 116 Eina_Promise_Owner* promise_owner;
441 Eina_Promise_Owner* owner;
442 Eina_Promise* promise; 117 Eina_Promise* promise;
443 Eina_Promise* promise_progress; 118 Eina_Bool ran = EINA_FALSE;
444 119
445 eina_init(); 120 eina_init();
446 121
447 owner = eina_promise_value_add(0); 122 promise_owner = eina_promise_add();
448 promise_progress = eina_promise_progress_notification(owner);
449 eina_promise_then(promise_progress, &_eina_promise_progress_notify_fulfilled,
450 &_eina_promise_progress_notify_error, &progress_notify_ran);
451
452 promise = eina_promise_owner_promise_get(owner);
453 eina_promise_progress_cb_add(promise, &progress_callback, NULL, NULL); // never run
454 eina_promise_progress_cb_add(promise, &progress_callback, NULL, NULL); // never run
455
456 ck_assert(progress_notify_ran);
457
458 eina_promise_unref(promise);
459 eina_promise_owner_value_set(owner, NULL, NULL);
460
461 eina_shutdown();
462}
463END_TEST
464 123
465START_TEST(eina_test_promise_ignored) 124 promise = eina_promise_owner_promise_get(promise_owner);
466{
467 Eina_Promise_Owner* owner;
468 Eina_Promise* promise;
469 125
470 eina_init(); 126 eina_promise_then(promise, &_eina_test_promise_cb, NULL, &ran);
127 eina_promise_owner_value_set(promise_owner, NULL, NULL);
471 128
472 owner = eina_promise_value_add(0); 129 ck_assert(ran == EINA_TRUE);
473 promise = eina_promise_owner_promise_get(owner);
474 eina_promise_unref(promise);
475 eina_promise_owner_value_set(owner, NULL, NULL);
476 130
477 eina_shutdown(); 131 eina_shutdown();
478} 132}
479END_TEST 133END_TEST
480 134
481START_TEST(eina_test_promise_race) 135START_TEST(eina_test_pointer_promise_normal_lifetime_all)
482{ 136{
483 Eina_Promise_Owner* promise_owner; 137 Eina_Promise_Owner* promise_owner;
484 Eina_Promise* first[2] = {NULL, NULL}; 138 Eina_Promise* first[2] = {NULL, NULL};
@@ -487,9 +141,9 @@ START_TEST(eina_test_promise_race)
487 141
488 eina_init(); 142 eina_init();
489 143
490 promise_owner = eina_promise_value_add(0); 144 promise_owner = eina_promise_add();
491 first[0] = eina_promise_owner_promise_get(promise_owner); 145 first[0] = eina_promise_owner_promise_get(promise_owner);
492 promise = eina_promise_race(eina_carray_iterator_new((void**)&first[0])); 146 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
493 147
494 eina_promise_then(promise, &_eina_test_promise_cb, NULL, &ran); 148 eina_promise_then(promise, &_eina_test_promise_cb, NULL, &ran);
495 eina_promise_owner_value_set(promise_owner, NULL, NULL); 149 eina_promise_owner_value_set(promise_owner, NULL, NULL);
@@ -500,12 +154,12 @@ START_TEST(eina_test_promise_race)
500} 154}
501END_TEST 155END_TEST
502 156
503// pointers 157START_TEST(eina_test_pointer_promise_error_set)
504START_TEST(eina_test_pointer_promise_normal_lifetime)
505{ 158{
506 Eina_Promise_Owner* promise_owner; 159 Eina_Promise_Owner* promise_owner;
507 Eina_Promise* promise; 160 Eina_Promise* promise;
508 Eina_Bool ran = EINA_FALSE; 161 int ran = 0;
162 int error = 0xdeadbeef;
509 163
510 eina_init(); 164 eina_init();
511 165
@@ -513,57 +167,43 @@ START_TEST(eina_test_pointer_promise_normal_lifetime)
513 167
514 promise = eina_promise_owner_promise_get(promise_owner); 168 promise = eina_promise_owner_promise_get(promise_owner);
515 169
516 eina_promise_then(promise, &_eina_test_promise_cb, NULL, &ran); 170 eina_promise_ref(promise);
517 eina_promise_owner_value_set(promise_owner, NULL, NULL);
518
519 ck_assert(ran == EINA_TRUE);
520
521 eina_shutdown();
522}
523END_TEST
524
525START_TEST(eina_test_pointer_promise_normal_lifetime_all)
526{
527 Eina_Promise_Owner* promise_owner;
528 Eina_Promise* first[2] = {NULL, NULL};
529 Eina_Promise* promise;
530 Eina_Bool ran = EINA_FALSE;
531 171
532 eina_init(); 172 eina_promise_then(promise, NULL, &_eina_test_error_cb, &ran);
533 173
534 promise_owner = eina_promise_add(); 174 eina_promise_owner_error_set(promise_owner, error);
535 first[0] = eina_promise_owner_promise_get(promise_owner);
536 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
537 175
538 eina_promise_then(promise, &_eina_test_promise_cb, NULL, &ran); 176 ck_assert_int_eq(error, ran);
539 eina_promise_owner_value_set(promise_owner, NULL, NULL); 177 ck_assert_int_eq(error, eina_promise_error_get(promise));
178 ck_assert(!eina_promise_pending_is(promise));
179 ck_assert(!eina_promise_owner_cancelled_is(promise_owner));
540 180
541 ck_assert(ran == EINA_TRUE); 181 eina_promise_unref(promise);
542 182
543 eina_shutdown(); 183 eina_shutdown();
544} 184}
545END_TEST 185END_TEST
546 186
547START_TEST(eina_test_pointer_promise_error_set) 187START_TEST(eina_test_pointer_promise_error_set_all)
548{ 188{
549 Eina_Promise_Owner* promise_owner; 189 Eina_Promise_Owner* promise_owner;
190 Eina_Promise* first[2] = {NULL, NULL};
550 Eina_Promise* promise; 191 Eina_Promise* promise;
551 int ran = 0; 192 int ran = 0;
552 int error = 0xdeadbeef; 193 int error = 0xdeadbeef;
553 194
554 eina_init(); 195 eina_init();
555 196
556 promise_owner = eina_promise_add(); 197 promise_owner = eina_promise_add(0);
557 198 first[0] = eina_promise_owner_promise_get(promise_owner);
558 promise = eina_promise_owner_promise_get(promise_owner); 199 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
559 200
560 eina_promise_ref(promise); 201 eina_promise_ref(promise);
561 202
562 eina_promise_then(promise, NULL, &_eina_test_error_cb, &ran); 203 eina_promise_then(promise, NULL, &_eina_test_error_cb, &ran);
563
564 eina_promise_owner_error_set(promise_owner, error); 204 eina_promise_owner_error_set(promise_owner, error);
565 205
566 ck_assert(ran == error); 206 ck_assert_int_eq(error, ran);
567 ck_assert_int_eq(error, eina_promise_error_get(promise)); 207 ck_assert_int_eq(error, eina_promise_error_get(promise));
568 ck_assert(!eina_promise_pending_is(promise)); 208 ck_assert(!eina_promise_pending_is(promise));
569 ck_assert(!eina_promise_owner_cancelled_is(promise_owner)); 209 ck_assert(!eina_promise_owner_cancelled_is(promise_owner));
@@ -616,6 +256,34 @@ START_TEST(eina_test_pointer_promise_immediate_set_lifetime_all)
616} 256}
617END_TEST 257END_TEST
618 258
259START_TEST(eina_test_pointer_promise_manual_then)
260{
261 Eina_Promise_Owner* promise_owner;
262 Eina_Promise* promise;
263 Eina_Bool ran = EINA_FALSE;
264
265 eina_init();
266
267 promise_owner = eina_promise_add();
268
269 eina_promise_owner_default_manual_then_set(promise_owner, EINA_TRUE);
270
271 promise = eina_promise_owner_promise_get(promise_owner);
272
273 eina_promise_then(promise, &_eina_test_promise_cb, NULL, &ran);
274
275 eina_promise_owner_value_set(promise_owner, NULL, NULL);
276
277 ck_assert(!ran);
278
279 eina_promise_owner_default_call_then(promise_owner);
280
281 ck_assert(ran);
282
283 eina_shutdown();
284}
285END_TEST
286
619START_TEST(eina_test_pointer_promise_values_all) 287START_TEST(eina_test_pointer_promise_values_all)
620{ 288{
621 Eina_Promise_Owner* owners[2]; 289 Eina_Promise_Owner* owners[2];
@@ -873,12 +541,20 @@ START_TEST(eina_test_pointer_promise_ignored)
873} 541}
874END_TEST 542END_TEST
875 543
544static void
545_eina_test_promise_race_cb(void* data, void* value EINA_UNUSED)
546{
547 *(Eina_Bool*)data = EINA_TRUE;
548 ck_assert_int_eq(*(int*)value, 42);
549}
550
876START_TEST(eina_test_pointer_promise_race) 551START_TEST(eina_test_pointer_promise_race)
877{ 552{
878 Eina_Promise_Owner* promise_owner; 553 Eina_Promise_Owner* promise_owner;
879 Eina_Promise* first[2] = {NULL, NULL}; 554 Eina_Promise* first[2] = {NULL, NULL};
880 Eina_Promise* promise; 555 Eina_Promise* promise;
881 Eina_Bool ran = EINA_FALSE; 556 Eina_Bool ran = EINA_FALSE;
557 int v = 42;
882 558
883 eina_init(); 559 eina_init();
884 560
@@ -886,10 +562,121 @@ START_TEST(eina_test_pointer_promise_race)
886 first[0] = eina_promise_owner_promise_get(promise_owner); 562 first[0] = eina_promise_owner_promise_get(promise_owner);
887 promise = eina_promise_race(eina_carray_iterator_new((void**)&first[0])); 563 promise = eina_promise_race(eina_carray_iterator_new((void**)&first[0]));
888 564
889 eina_promise_then(promise, &_eina_test_promise_cb, NULL, &ran); 565 eina_promise_then(promise, &_eina_test_promise_race_cb, NULL, &ran);
566 eina_promise_owner_value_set(promise_owner, &v, NULL);
567
568 ck_assert(!!ran);
569
570 eina_shutdown();
571}
572END_TEST
573
574START_TEST(eina_test_pointer_promise_race_error)
575{
576 Eina_Promise_Owner* promise_owner;
577 Eina_Promise* first[2] = {NULL, NULL};
578 Eina_Promise* promise;
579 int ran = 0;
580 int error = 0xdeadbeef;
581
582 eina_init();
583
584 promise_owner = eina_promise_add();
585 first[0] = eina_promise_owner_promise_get(promise_owner);
586 promise = eina_promise_race(eina_carray_iterator_new((void**)&first[0]));
587
588 eina_promise_ref(promise);
589
590 eina_promise_then(promise, NULL, &_eina_test_error_cb, &ran);
591 eina_promise_owner_error_set(promise_owner, error);
592
593 ck_assert_int_eq(error, ran);
594 ck_assert_int_eq(error, eina_promise_error_get(promise));
595 ck_assert(!eina_promise_pending_is(promise));
596 ck_assert(!eina_promise_owner_cancelled_is(promise_owner));
597
598 eina_promise_unref(promise);
599
600 eina_shutdown();
601}
602END_TEST
603
604// Null promises
605START_TEST(eina_test_promise_error_promise_null_with_cb)
606{
607 int ran = 0;
608 eina_init();
609
610 eina_promise_then(NULL, NULL, _eina_test_error_cb, &ran);
611
612 ck_assert_int_eq(EINA_ERROR_PROMISE_NULL, ran);
613
614 eina_shutdown();
615}
616END_TEST
617
618START_TEST(eina_test_promise_error_promise_null_without_cb)
619{
620 eina_init();
621
622 eina_promise_then(NULL, NULL, NULL, NULL);
623
624 ck_assert_int_eq(EINA_ERROR_PROMISE_NULL, eina_error_get());
625
626 eina_shutdown();
627}
628END_TEST
629
630START_TEST(eina_test_promise_error_promise_all_unref)
631{
632 Eina_Promise_Owner* promise_owner;
633 Eina_Promise* first[2] = {NULL, NULL};
634 Eina_Promise* promise;
635
636 eina_init();
637
638 promise_owner = eina_promise_add();
639 first[0] = eina_promise_owner_promise_get(promise_owner);
640 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
641
642 eina_promise_unref(promise);
643
890 eina_promise_owner_value_set(promise_owner, NULL, NULL); 644 eina_promise_owner_value_set(promise_owner, NULL, NULL);
891 645
892 ck_assert(ran == EINA_TRUE); 646 eina_shutdown();
647}
648END_TEST
649
650static void _eina_test_promise_all_cb_lifetime_cb(void* data, Eina_Error error EINA_UNUSED)
651{
652 Eina_Promise* promise = data;
653 ck_assert_int_eq(eina_promise_ref_get(promise), 4);
654}
655
656START_TEST(eina_test_promise_error_all_cb_lifetime)
657{
658 Eina_Promise_Owner* promise_owner[2];
659 Eina_Promise* first[3] = {NULL, NULL, NULL};
660 Eina_Promise* promise;
661
662 eina_init();
663
664 promise_owner[0] = eina_promise_add();
665 promise_owner[1] = eina_promise_add();
666 first[0] = eina_promise_owner_promise_get(promise_owner[0]);
667 first[1] = eina_promise_owner_promise_get(promise_owner[1]);
668 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
669
670 ck_assert_int_eq(eina_promise_ref_get(promise), 3);
671 eina_promise_then(promise, NULL, &_eina_test_promise_all_cb_lifetime_cb, promise);
672 ck_assert_int_eq(eina_promise_ref_get(promise), 3);
673
674 eina_promise_owner_error_set(promise_owner[0], EINA_ERROR_PROMISE_CANCEL);
675
676 ck_assert_int_eq(eina_promise_ref_get(promise), 1);
677
678 eina_promise_owner_value_set(promise_owner[1], NULL, NULL);
679 ck_assert_int_eq(eina_promise_ref_get(promise), 0);
893 680
894 eina_shutdown(); 681 eina_shutdown();
895} 682}
@@ -898,28 +685,14 @@ END_TEST
898void 685void
899eina_test_promise(TCase *tc) 686eina_test_promise(TCase *tc)
900{ 687{
901 tcase_add_test(tc, eina_test_promise_normal_lifetime); 688 /* // pointer */
902 tcase_add_test(tc, eina_test_promise_normal_lifetime_all);
903 tcase_add_test(tc, eina_test_promise_error_set);
904 /* tcase_add_test(tc, eina_test_promise_error_set_all); */
905 tcase_add_test(tc, eina_test_promise_immediate_set_lifetime);
906 tcase_add_test(tc, eina_test_promise_immediate_set_lifetime_all);
907 tcase_add_test(tc, eina_test_promise_values_all);
908 tcase_add_test(tc, eina_test_promise_cancel_promise);
909 tcase_add_test(tc, eina_test_promise_cancel_finished_promise);
910 tcase_add_test(tc, eina_test_promise_double_cancel_promise);
911 tcase_add_test(tc, eina_test_promise_progress);
912 tcase_add_test(tc, eina_test_promise_progress_notify1);
913 tcase_add_test(tc, eina_test_promise_progress_notify2);
914 tcase_add_test(tc, eina_test_promise_progress_notify3);
915 tcase_add_test(tc, eina_test_promise_ignored);
916 tcase_add_test(tc, eina_test_promise_race);
917 // pointer
918 tcase_add_test(tc, eina_test_pointer_promise_normal_lifetime); 689 tcase_add_test(tc, eina_test_pointer_promise_normal_lifetime);
919 tcase_add_test(tc, eina_test_pointer_promise_normal_lifetime_all); 690 tcase_add_test(tc, eina_test_pointer_promise_normal_lifetime_all);
920 tcase_add_test(tc, eina_test_pointer_promise_error_set); 691 tcase_add_test(tc, eina_test_pointer_promise_error_set);
692 tcase_add_test(tc, eina_test_pointer_promise_error_set_all);
921 tcase_add_test(tc, eina_test_pointer_promise_immediate_set_lifetime); 693 tcase_add_test(tc, eina_test_pointer_promise_immediate_set_lifetime);
922 tcase_add_test(tc, eina_test_pointer_promise_immediate_set_lifetime_all); 694 tcase_add_test(tc, eina_test_pointer_promise_immediate_set_lifetime_all);
695 tcase_add_test(tc, eina_test_pointer_promise_manual_then);
923 tcase_add_test(tc, eina_test_pointer_promise_values_all); 696 tcase_add_test(tc, eina_test_pointer_promise_values_all);
924 tcase_add_test(tc, eina_test_pointer_promise_cancel_promise); 697 tcase_add_test(tc, eina_test_pointer_promise_cancel_promise);
925 tcase_add_test(tc, eina_test_pointer_promise_cancel_finished_promise); 698 tcase_add_test(tc, eina_test_pointer_promise_cancel_finished_promise);
@@ -930,4 +703,13 @@ eina_test_promise(TCase *tc)
930 tcase_add_test(tc, eina_test_pointer_promise_progress_notify3); 703 tcase_add_test(tc, eina_test_pointer_promise_progress_notify3);
931 tcase_add_test(tc, eina_test_pointer_promise_ignored); 704 tcase_add_test(tc, eina_test_pointer_promise_ignored);
932 tcase_add_test(tc, eina_test_pointer_promise_race); 705 tcase_add_test(tc, eina_test_pointer_promise_race);
706 tcase_add_test(tc, eina_test_pointer_promise_race_error);
707
708 // Null promises
709 tcase_add_test(tc, eina_test_promise_error_promise_null_with_cb);
710 tcase_add_test(tc, eina_test_promise_error_promise_null_without_cb);
711 tcase_add_test(tc, eina_test_promise_error_promise_all_unref);
712
713 // Reference of composite promises
714 tcase_add_test(tc, eina_test_promise_error_all_cb_lifetime);
933} 715}