summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-06-03 16:52:03 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-06-03 17:22:12 -0300
commit8fec0d5139a3ff30037ba159bb62ff2f733d96a8 (patch)
tree0316d756b8150e9ef40d76668e5084fdb06af29a /src/tests
parent1dcccfdf8160ca6113d66c51c226302221b9a049 (diff)
eina: Remove unnecessary indirection to promises
Now when dealing with pointer types, we will not get pointer to pointer semantics in callbacks and eina_promise_owner_value_set for Eina_Promise. It will work as expected: Eina_Promise_Owner* promise = eina_promise_add(); void* p = malloc(sizeof(T)); eina_promise_owner_value_set(promise, p, &free);
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/ecore/ecore_test_job.c6
-rw-r--r--src/tests/ecore/ecore_test_promise.c50
-rw-r--r--src/tests/ecore/ecore_test_timer.c2
-rw-r--r--src/tests/eina/eina_test_promise.c313
-rw-r--r--src/tests/eio/eio_test_job.c43
-rw-r--r--src/tests/eldbus/eldbus_test_eldbus_model.c20
6 files changed, 356 insertions, 78 deletions
diff --git a/src/tests/ecore/ecore_test_job.c b/src/tests/ecore/ecore_test_job.c
index 47257104f6..60eebdef86 100644
--- a/src/tests/ecore/ecore_test_job.c
+++ b/src/tests/ecore/ecore_test_job.c
@@ -10,7 +10,7 @@ _ecore_promise_quit(void *data, void *value, Eina_Promise* promise EINA_UNUSED)
10{ 10{
11 Eina_Bool *bob = data; 11 Eina_Bool *bob = data;
12 12
13 fail_if(data != *(Eina_Bool**)value); 13 fail_if(data != value);
14 *bob = EINA_TRUE; 14 *bob = EINA_TRUE;
15 ecore_main_loop_quit(); 15 ecore_main_loop_quit();
16} 16}
@@ -18,12 +18,10 @@ _ecore_promise_quit(void *data, void *value, Eina_Promise* promise EINA_UNUSED)
18START_TEST(ecore_test_job_promise) 18START_TEST(ecore_test_job_promise)
19{ 19{
20 Eina_Bool bob = EINA_FALSE; 20 Eina_Bool bob = EINA_FALSE;
21 Eina_Promise *job = NULL;
22 21
23 ecore_init(); 22 ecore_init();
24 23
25 job = efl_loop_job(ecore_main_loop_get(), &bob); 24 eina_promise_then(efl_loop_job(ecore_main_loop_get(), &bob), &_ecore_promise_quit, NULL, &bob);
26 eina_promise_then(job, &_ecore_promise_quit, NULL, &bob);
27 25
28 ecore_main_loop_begin(); 26 ecore_main_loop_begin();
29 27
diff --git a/src/tests/ecore/ecore_test_promise.c b/src/tests/ecore/ecore_test_promise.c
index decd5c9588..f016580360 100644
--- a/src/tests/ecore/ecore_test_promise.c
+++ b/src/tests/ecore/ecore_test_promise.c
@@ -22,7 +22,7 @@ START_TEST(ecore_test_promise)
22 22
23 ecore_init(); 23 ecore_init();
24 24
25 ecore_thread_promise_run(&promised_thread, NULL, NULL, 0, &promise); 25 ecore_thread_promise_run(&promised_thread, NULL, NULL, &promise);
26 eina_promise_then(promise, &promise_callback, NULL, NULL); 26 eina_promise_then(promise, &promise_callback, NULL, NULL);
27 27
28 ecore_main_loop_begin(); 28 ecore_main_loop_begin();
@@ -48,7 +48,7 @@ START_TEST(ecore_test_promise_error)
48 48
49 ecore_init(); 49 ecore_init();
50 50
51 ecore_thread_promise_run(&promise_error_thread, NULL, NULL, 0, &promise); 51 ecore_thread_promise_run(&promise_error_thread, NULL, NULL, &promise);
52 eina_promise_then(promise, NULL, &promise_error_callback, NULL); 52 eina_promise_then(promise, NULL, &promise_error_callback, NULL);
53 53
54 ecore_main_loop_begin(); 54 ecore_main_loop_begin();
@@ -64,7 +64,7 @@ START_TEST(ecore_test_promise_all)
64 64
65 ecore_init(); 65 ecore_init();
66 66
67 ecore_thread_promise_run(&promised_thread, NULL, NULL, 0, &first[0]); 67 ecore_thread_promise_run(&promised_thread, NULL, NULL, &first[0]);
68 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0])); 68 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
69 eina_promise_then(promise, &promise_callback, NULL, NULL); 69 eina_promise_then(promise, &promise_callback, NULL, NULL);
70 70
@@ -89,7 +89,7 @@ START_TEST(ecore_test_promise_all_then_then)
89 89
90 int i = 0; 90 int i = 0;
91 91
92 ecore_thread_promise_run(&promised_thread, NULL, NULL, 0, &first[0]); 92 ecore_thread_promise_run(&promised_thread, NULL, NULL, &first[0]);
93 eina_promise_then(first[0], &promise_callback2, NULL, &i); 93 eina_promise_then(first[0], &promise_callback2, NULL, &i);
94 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0])); 94 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
95 eina_promise_then(promise, &promise_callback2, NULL, &i); 95 eina_promise_then(promise, &promise_callback2, NULL, &i);
@@ -126,7 +126,7 @@ static void _ecore_test_promise_then_after_thread_finished_main_cb()
126 eina_lock_new(&data.lock); 126 eina_lock_new(&data.lock);
127 eina_condition_new(&data.cond, &data.lock); 127 eina_condition_new(&data.cond, &data.lock);
128 128
129 thread = ecore_thread_promise_run((Ecore_Thread_Promise_Cb)&promised_exit_thread, NULL, &data, 0, &promise); 129 thread = ecore_thread_promise_run((Ecore_Thread_Promise_Cb)&promised_exit_thread, NULL, &data, &promise);
130 130
131 eina_lock_take(&data.lock); 131 eina_lock_take(&data.lock);
132 while(!data.var) 132 while(!data.var)
@@ -161,7 +161,7 @@ static void _ecore_test_promise_then_after_thread_finished_all_main_cb()
161 eina_lock_new(&data.lock); 161 eina_lock_new(&data.lock);
162 eina_condition_new(&data.cond, &data.lock); 162 eina_condition_new(&data.cond, &data.lock);
163 163
164 thread = ecore_thread_promise_run((Ecore_Thread_Promise_Cb)&promised_exit_thread, NULL, &data, 0, &first[0]); 164 thread = ecore_thread_promise_run((Ecore_Thread_Promise_Cb)&promised_exit_thread, NULL, &data, &first[0]);
165 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0])); 165 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
166 166
167 eina_lock_take(&data.lock); 167 eina_lock_take(&data.lock);
@@ -186,19 +186,19 @@ START_TEST(ecore_test_promise_then_after_thread_finished_all)
186} 186}
187END_TEST 187END_TEST
188 188
189void promised_block_thread(const void* data EINA_UNUSED, Eina_Promise_Owner* promise, Ecore_Thread* thread EINA_UNUSED) 189/* void promised_block_thread(const void* data EINA_UNUSED, Eina_Promise_Owner* promise, Ecore_Thread* thread EINA_UNUSED) */
190{ 190/* { */
191 struct timespec v = {.tv_sec = 1, .tv_nsec = 0}, rem; 191/* struct timespec v = {.tv_sec = 1, .tv_nsec = 0}, rem; */
192 if(nanosleep(&v, &rem) == -1 && errno == EINTR) 192/* if(nanosleep(&v, &rem) == -1 && errno == EINTR) */
193 do 193/* do */
194 { 194/* { */
195 v = rem; 195/* v = rem; */
196 } 196/* } */
197 while(nanosleep(&v, &rem) == -1 && errno == EINTR); 197/* while(nanosleep(&v, &rem) == -1 && errno == EINTR); */
198 198
199 int r = 10; 199/* int r = 10; */
200 eina_promise_owner_value_set(promise, &r, NULL); 200/* eina_promise_owner_value_set(promise, &r, NULL); */
201} 201/* } */
202 202
203static void 203static void
204_ecore_test_promise_normal_lifetime_cb(void* data EINA_UNUSED, void* value EINA_UNUSED, Eina_Promise* promise EINA_UNUSED) 204_ecore_test_promise_normal_lifetime_cb(void* data EINA_UNUSED, void* value EINA_UNUSED, Eina_Promise* promise EINA_UNUSED)
@@ -219,7 +219,7 @@ START_TEST(ecore_test_promise_normal_lifetime)
219 219
220 ecore_init(); 220 ecore_init();
221 221
222 promise_owner = eina_promise_default_add(0); 222 promise_owner = eina_promise_value_add(0);
223 223
224 promise = eina_promise_owner_promise_get(promise_owner); 224 promise = eina_promise_owner_promise_get(promise_owner);
225 225
@@ -240,7 +240,7 @@ START_TEST(ecore_test_promise_normal_lifetime_all)
240 240
241 ecore_init(); 241 ecore_init();
242 242
243 promise_owner = eina_promise_default_add(0); 243 promise_owner = eina_promise_value_add(0);
244 first[0] = eina_promise_owner_promise_get(promise_owner); 244 first[0] = eina_promise_owner_promise_get(promise_owner);
245 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0])); 245 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
246 246
@@ -266,7 +266,7 @@ START_TEST(ecore_test_promise_immediate_set_lifetime)
266 266
267 ecore_init(); 267 ecore_init();
268 268
269 owner = eina_promise_default_add(0); 269 owner = eina_promise_value_add(0);
270 promise = eina_promise_owner_promise_get(owner); 270 promise = eina_promise_owner_promise_get(owner);
271 271
272 eina_promise_owner_value_set(owner, NULL, NULL); 272 eina_promise_owner_value_set(owner, NULL, NULL);
@@ -286,7 +286,7 @@ START_TEST(ecore_test_promise_immediate_set_lifetime_all)
286 286
287 ecore_init(); 287 ecore_init();
288 288
289 owner = eina_promise_default_add(0); 289 owner = eina_promise_value_add(0);
290 first[0] = eina_promise_owner_promise_get(owner); 290 first[0] = eina_promise_owner_promise_get(owner);
291 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0])); 291 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
292 292
@@ -343,7 +343,7 @@ START_TEST(ecore_test_promise_cancel_promise)
343 eina_lock_new(&v.lock); 343 eina_lock_new(&v.lock);
344 eina_condition_new(&v.condvar, &v.lock); 344 eina_condition_new(&v.condvar, &v.lock);
345 345
346 ecore_thread_promise_run(&promise_cancel_thread, &_cancel_callback, &v, 0, &promise); 346 ecore_thread_promise_run(&promise_cancel_thread, &_cancel_callback, &v, &promise);
347 eina_promise_then(promise, NULL, &_cancel_promise_callback, NULL); 347 eina_promise_then(promise, NULL, &_cancel_promise_callback, NULL);
348 348
349 eina_promise_cancel(promise); 349 eina_promise_cancel(promise);
@@ -376,7 +376,7 @@ START_TEST(ecore_test_promise_progress_promise)
376 376
377 ecore_init(); 377 ecore_init();
378 378
379 ecore_thread_promise_run(&promise_progress_thread, NULL, NULL, 0, &promise); 379 ecore_thread_promise_run(&promise_progress_thread, NULL, NULL, &promise);
380 380
381 eina_promise_progress_cb_add(promise, &_progress_callback, NULL, NULL); 381 eina_promise_progress_cb_add(promise, &_progress_callback, NULL, NULL);
382 382
diff --git a/src/tests/ecore/ecore_test_timer.c b/src/tests/ecore/ecore_test_timer.c
index 2e07b5347b..d073d5d05b 100644
--- a/src/tests/ecore/ecore_test_timer.c
+++ b/src/tests/ecore/ecore_test_timer.c
@@ -179,7 +179,7 @@ static void
179_ecore_promise_quit(void *data, void *value, Eina_Promise* promise EINA_UNUSED) 179_ecore_promise_quit(void *data, void *value, Eina_Promise* promise EINA_UNUSED)
180{ 180{
181 Eina_Bool *bob = data; 181 Eina_Bool *bob = data;
182 double *start = *(double**)value; 182 double *start = value;
183 double delta = ecore_loop_time_get() - *start; 183 double delta = ecore_loop_time_get() - *start;
184 184
185 fail_if(delta - 0.2 > 0.01); 185 fail_if(delta - 0.2 > 0.01);
diff --git a/src/tests/eina/eina_test_promise.c b/src/tests/eina/eina_test_promise.c
index f8b355bf33..7c6d33af1b 100644
--- a/src/tests/eina/eina_test_promise.c
+++ b/src/tests/eina/eina_test_promise.c
@@ -45,7 +45,7 @@ START_TEST(eina_test_promise_normal_lifetime)
45 45
46 eina_init(); 46 eina_init();
47 47
48 promise_owner = eina_promise_default_add(0); 48 promise_owner = eina_promise_value_add(0);
49 49
50 promise = eina_promise_owner_promise_get(promise_owner); 50 promise = eina_promise_owner_promise_get(promise_owner);
51 51
@@ -67,7 +67,7 @@ START_TEST(eina_test_promise_normal_lifetime_all)
67 67
68 eina_init(); 68 eina_init();
69 69
70 promise_owner = eina_promise_default_add(0); 70 promise_owner = eina_promise_value_add(0);
71 first[0] = eina_promise_owner_promise_get(promise_owner); 71 first[0] = eina_promise_owner_promise_get(promise_owner);
72 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0])); 72 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
73 73
@@ -88,7 +88,7 @@ START_TEST(eina_test_promise_immediate_set_lifetime)
88 88
89 eina_init(); 89 eina_init();
90 90
91 owner = eina_promise_default_add(0); 91 owner = eina_promise_value_add(0);
92 promise = eina_promise_owner_promise_get(owner); 92 promise = eina_promise_owner_promise_get(owner);
93 93
94 eina_promise_owner_value_set(owner, NULL, NULL); 94 eina_promise_owner_value_set(owner, NULL, NULL);
@@ -109,7 +109,7 @@ START_TEST(eina_test_promise_immediate_set_lifetime_all)
109 109
110 eina_init(); 110 eina_init();
111 111
112 owner = eina_promise_default_add(0); 112 owner = eina_promise_value_add(0);
113 first[0] = eina_promise_owner_promise_get(owner); 113 first[0] = eina_promise_owner_promise_get(owner);
114 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0])); 114 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
115 115
@@ -124,14 +124,14 @@ END_TEST
124 124
125static void _eina_test_promise_value_all_cb(void* data, void* value, Eina_Promise* promise EINA_UNUSED) 125static void _eina_test_promise_value_all_cb(void* data, void* value, Eina_Promise* promise EINA_UNUSED)
126{ 126{
127 Eina_Iterator** iterator = value; 127 Eina_Iterator* iterator = value;
128 int *i, *j; 128 int *i, *j;
129 Eina_Bool b; 129 Eina_Bool b;
130 130
131 b = eina_iterator_next(*iterator, (void**)&i); 131 b = eina_iterator_next(iterator, (void**)&i);
132 ck_assert(!!b); 132 ck_assert(!!b);
133 133
134 b = eina_iterator_next(*iterator, (void**)&j); 134 b = eina_iterator_next(iterator, (void**)&j);
135 ck_assert(!!b); 135 ck_assert(!!b);
136 136
137 ck_assert(i != NULL); 137 ck_assert(i != NULL);
@@ -153,8 +153,8 @@ START_TEST(eina_test_promise_values_all)
153 153
154 int i = 10, j = 15; 154 int i = 10, j = 15;
155 155
156 owners[0] = eina_promise_default_add(sizeof(int)); 156 owners[0] = eina_promise_value_add(sizeof(int));
157 owners[1] = eina_promise_default_add(sizeof(int)); 157 owners[1] = eina_promise_value_add(sizeof(int));
158 158
159 promises[0] = eina_promise_owner_promise_get(owners[0]); 159 promises[0] = eina_promise_owner_promise_get(owners[0]);
160 promises[1] = eina_promise_owner_promise_get(owners[1]); 160 promises[1] = eina_promise_owner_promise_get(owners[1]);
@@ -191,7 +191,7 @@ START_TEST(eina_test_promise_cancel_promise)
191 191
192 eina_init(); 192 eina_init();
193 193
194 owner = eina_promise_default_add(0); 194 owner = eina_promise_value_add(0);
195 eina_promise_owner_default_cancel_cb_add(owner, &cancel_callback, &cancel_ran, NULL); 195 eina_promise_owner_default_cancel_cb_add(owner, &cancel_callback, &cancel_ran, NULL);
196 196
197 promise = eina_promise_owner_promise_get(owner); 197 promise = eina_promise_owner_promise_get(owner);
@@ -222,7 +222,7 @@ START_TEST(eina_test_promise_progress)
222 222
223 eina_init(); 223 eina_init();
224 224
225 owner = eina_promise_default_add(0); 225 owner = eina_promise_value_add(0);
226 226
227 promise = eina_promise_owner_promise_get(owner); 227 promise = eina_promise_owner_promise_get(owner);
228 eina_promise_progress_cb_add(promise, &progress_callback, &progress_ran, NULL); 228 eina_promise_progress_cb_add(promise, &progress_callback, &progress_ran, NULL);
@@ -249,7 +249,7 @@ START_TEST(eina_test_promise_progress_notify1)
249 249
250 eina_init(); 250 eina_init();
251 251
252 owner = eina_promise_default_add(0); 252 owner = eina_promise_value_add(0);
253 eina_promise_owner_progress_notify(owner, &progress_notify, &progress_notify_ran, NULL); 253 eina_promise_owner_progress_notify(owner, &progress_notify, &progress_notify_ran, NULL);
254 254
255 promise = eina_promise_owner_promise_get(owner); 255 promise = eina_promise_owner_promise_get(owner);
@@ -270,7 +270,7 @@ START_TEST(eina_test_promise_progress_notify2)
270 270
271 eina_init(); 271 eina_init();
272 272
273 owner = eina_promise_default_add(0); 273 owner = eina_promise_value_add(0);
274 eina_promise_owner_progress_notify(owner, &progress_notify, &progress_notify_ran, NULL); 274 eina_promise_owner_progress_notify(owner, &progress_notify, &progress_notify_ran, NULL);
275 275
276 promise = eina_promise_owner_promise_get(owner); 276 promise = eina_promise_owner_promise_get(owner);
@@ -304,7 +304,7 @@ START_TEST(eina_test_promise_progress_notify3)
304 304
305 eina_init(); 305 eina_init();
306 306
307 owner = eina_promise_default_add(0); 307 owner = eina_promise_value_add(0);
308 promise_progress = eina_promise_progress_notification(owner); 308 promise_progress = eina_promise_progress_notification(owner);
309 eina_promise_then(promise_progress, &_eina_promise_progress_notify_fulfilled, 309 eina_promise_then(promise_progress, &_eina_promise_progress_notify_fulfilled,
310 &_eina_promise_progress_notify_error, &progress_notify_ran); 310 &_eina_promise_progress_notify_error, &progress_notify_ran);
@@ -326,7 +326,7 @@ START_TEST(eina_test_promise_ignored)
326 326
327 eina_init(); 327 eina_init();
328 328
329 owner = eina_promise_default_add(0); 329 owner = eina_promise_value_add(0);
330 promise = eina_promise_owner_promise_get(owner); 330 promise = eina_promise_owner_promise_get(owner);
331 eina_promise_unref(promise); 331 eina_promise_unref(promise);
332 eina_promise_owner_value_set(owner, NULL, NULL); 332 eina_promise_owner_value_set(owner, NULL, NULL);
@@ -344,7 +344,275 @@ START_TEST(eina_test_promise_race)
344 344
345 eina_init(); 345 eina_init();
346 346
347 promise_owner = eina_promise_default_add(0); 347 promise_owner = eina_promise_value_add(0);
348 first[0] = eina_promise_owner_promise_get(promise_owner);
349 promise = eina_promise_race(eina_carray_iterator_new((void**)&first[0]));
350
351 eina_promise_then(promise, &_eina_test_promise_cb, NULL, &ran);
352 eina_promise_owner_value_set(promise_owner, NULL, NULL);
353
354 ck_assert(ran == EINA_TRUE);
355
356 eina_shutdown();
357}
358END_TEST
359
360// pointers
361START_TEST(eina_test_pointer_promise_normal_lifetime)
362{
363 Eina_Promise_Owner* promise_owner;
364 Eina_Promise* promise;
365 Eina_Bool ran = EINA_FALSE;
366
367 eina_init();
368
369 promise_owner = eina_promise_add();
370
371 promise = eina_promise_owner_promise_get(promise_owner);
372
373 eina_promise_then(promise, &_eina_test_promise_cb, NULL, &ran);
374 eina_promise_owner_value_set(promise_owner, NULL, NULL);
375
376 ck_assert(ran == EINA_TRUE);
377
378 eina_shutdown();
379}
380END_TEST
381
382START_TEST(eina_test_pointer_promise_normal_lifetime_all)
383{
384 Eina_Promise_Owner* promise_owner;
385 Eina_Promise* first[2] = {NULL, NULL};
386 Eina_Promise* promise;
387 Eina_Bool ran = EINA_FALSE;
388
389 eina_init();
390
391 promise_owner = eina_promise_add();
392 first[0] = eina_promise_owner_promise_get(promise_owner);
393 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
394
395 eina_promise_then(promise, &_eina_test_promise_cb, NULL, &ran);
396 eina_promise_owner_value_set(promise_owner, NULL, NULL);
397
398 ck_assert(ran == EINA_TRUE);
399
400 eina_shutdown();
401}
402END_TEST
403
404START_TEST(eina_test_pointer_promise_immediate_set_lifetime)
405{
406 Eina_Promise_Owner* owner;
407 Eina_Promise* promise;
408 Eina_Bool ran = EINA_FALSE;
409
410 eina_init();
411
412 owner = eina_promise_add();
413 promise = eina_promise_owner_promise_get(owner);
414
415 eina_promise_owner_value_set(owner, NULL, NULL);
416 eina_promise_then(promise, &_eina_test_promise_cb, NULL, &ran);
417
418 ck_assert(ran == EINA_TRUE);
419
420 eina_shutdown();
421}
422END_TEST
423
424START_TEST(eina_test_pointer_promise_immediate_set_lifetime_all)
425{
426 Eina_Promise_Owner* owner;
427 Eina_Promise* first[2] = {NULL, NULL};
428 Eina_Promise* promise;
429 Eina_Bool ran = EINA_FALSE;
430
431 eina_init();
432
433 owner = eina_promise_add();
434 first[0] = eina_promise_owner_promise_get(owner);
435 promise = eina_promise_all(eina_carray_iterator_new((void**)&first[0]));
436
437 eina_promise_owner_value_set(owner, NULL, NULL);
438 eina_promise_then(promise, &_eina_test_promise_cb, NULL, &ran);
439
440 ck_assert(ran == EINA_TRUE);
441
442 eina_shutdown();
443}
444END_TEST
445
446START_TEST(eina_test_pointer_promise_values_all)
447{
448 Eina_Promise_Owner* owners[2];
449 Eina_Promise* promises[3] = {NULL, NULL, NULL};
450 Eina_Promise* promise_all;
451 Eina_Bool ran = EINA_FALSE;
452
453 eina_init();
454
455 int* i = malloc(sizeof(int)), *j = malloc(sizeof(int));
456 *i = 10;
457 *j = 15;
458
459 owners[0] = eina_promise_add();
460 owners[1] = eina_promise_add();
461
462 promises[0] = eina_promise_owner_promise_get(owners[0]);
463 promises[1] = eina_promise_owner_promise_get(owners[1]);
464
465
466 promise_all = eina_promise_all(eina_carray_iterator_new((void**)&promises[0]));
467
468 eina_promise_owner_value_set(owners[0], i, free);
469 eina_promise_owner_value_set(owners[1], j, free);
470
471 eina_promise_then(promise_all, &_eina_test_promise_value_all_cb, NULL, &ran);
472
473 ck_assert(ran == EINA_TRUE);
474
475 eina_shutdown();
476}
477END_TEST
478
479START_TEST(eina_test_pointer_promise_cancel_promise)
480{
481 Eina_Bool ran = EINA_FALSE, cancel_ran = EINA_FALSE;
482 Eina_Promise_Owner* owner;
483 Eina_Promise* promise;
484
485 eina_init();
486
487 owner = eina_promise_add();
488 eina_promise_owner_default_cancel_cb_add(owner, &cancel_callback, &cancel_ran, NULL);
489
490 promise = eina_promise_owner_promise_get(owner);
491
492 eina_promise_then(promise, NULL, &_cancel_promise_callback, &ran);
493
494 eina_promise_cancel(promise);
495
496 ck_assert(cancel_ran && ran);
497
498 eina_shutdown();
499}
500END_TEST
501
502START_TEST(eina_test_pointer_promise_progress)
503{
504 Eina_Bool progress_ran = EINA_FALSE;
505 Eina_Promise_Owner* owner;
506 Eina_Promise* promise;
507 int i = 1;
508
509 eina_init();
510
511 owner = eina_promise_add();
512
513 promise = eina_promise_owner_promise_get(owner);
514 eina_promise_progress_cb_add(promise, &progress_callback, &progress_ran, NULL);
515
516 eina_promise_owner_progress(owner, &i);
517
518 ck_assert(progress_ran);
519
520 eina_shutdown();
521}
522END_TEST
523
524START_TEST(eina_test_pointer_promise_progress_notify1)
525{
526 Eina_Bool progress_notify_ran = EINA_FALSE;
527 Eina_Promise_Owner* owner;
528 Eina_Promise* promise;
529
530 eina_init();
531
532 owner = eina_promise_add();
533 eina_promise_owner_progress_notify(owner, &progress_notify, &progress_notify_ran, NULL);
534
535 promise = eina_promise_owner_promise_get(owner);
536 eina_promise_progress_cb_add(promise, &progress_callback, NULL, NULL); // never run
537 eina_promise_progress_cb_add(promise, &progress_callback, NULL, NULL); // never run
538
539 ck_assert(progress_notify_ran);
540
541 eina_shutdown();
542}
543END_TEST
544
545START_TEST(eina_test_pointer_promise_progress_notify2)
546{
547 Eina_Bool progress_notify_ran = EINA_FALSE;
548 Eina_Promise_Owner* owner;
549 Eina_Promise* promise;
550
551 eina_init();
552
553 owner = eina_promise_add();
554 eina_promise_owner_progress_notify(owner, &progress_notify, &progress_notify_ran, NULL);
555
556 promise = eina_promise_owner_promise_get(owner);
557 eina_promise_then(promise, NULL, &_cancel_promise_callback, NULL); // never run
558 eina_promise_then(promise, NULL, &_cancel_promise_callback, NULL); // never run
559
560 ck_assert(progress_notify_ran);
561
562 eina_shutdown();
563}
564END_TEST
565
566START_TEST(eina_test_pointer_promise_progress_notify3)
567{
568 Eina_Bool progress_notify_ran = EINA_FALSE;
569 Eina_Promise_Owner* owner;
570 Eina_Promise* promise;
571 Eina_Promise* promise_progress;
572
573 eina_init();
574
575 owner = eina_promise_add();
576 promise_progress = eina_promise_progress_notification(owner);
577 eina_promise_then(promise_progress, &_eina_promise_progress_notify_fulfilled,
578 &_eina_promise_progress_notify_error, &progress_notify_ran);
579
580 promise = eina_promise_owner_promise_get(owner);
581 eina_promise_progress_cb_add(promise, &progress_callback, NULL, NULL); // never run
582 eina_promise_progress_cb_add(promise, &progress_callback, NULL, NULL); // never run
583
584 ck_assert(progress_notify_ran);
585
586 eina_shutdown();
587}
588END_TEST
589
590START_TEST(eina_test_pointer_promise_ignored)
591{
592 Eina_Promise_Owner* owner;
593 Eina_Promise* promise;
594
595 eina_init();
596
597 owner = eina_promise_add();
598 promise = eina_promise_owner_promise_get(owner);
599 eina_promise_unref(promise);
600 eina_promise_owner_value_set(owner, NULL, NULL);
601
602 eina_shutdown();
603}
604END_TEST
605
606START_TEST(eina_test_pointer_promise_race)
607{
608 Eina_Promise_Owner* promise_owner;
609 Eina_Promise* first[2] = {NULL, NULL};
610 Eina_Promise* promise;
611 Eina_Bool ran = EINA_FALSE;
612
613 eina_init();
614
615 promise_owner = eina_promise_add();
348 first[0] = eina_promise_owner_promise_get(promise_owner); 616 first[0] = eina_promise_owner_promise_get(promise_owner);
349 promise = eina_promise_race(eina_carray_iterator_new((void**)&first[0])); 617 promise = eina_promise_race(eina_carray_iterator_new((void**)&first[0]));
350 618
@@ -372,4 +640,17 @@ eina_test_promise(TCase *tc)
372 tcase_add_test(tc, eina_test_promise_progress_notify3); 640 tcase_add_test(tc, eina_test_promise_progress_notify3);
373 tcase_add_test(tc, eina_test_promise_ignored); 641 tcase_add_test(tc, eina_test_promise_ignored);
374 tcase_add_test(tc, eina_test_promise_race); 642 tcase_add_test(tc, eina_test_promise_race);
643 // pointer
644 tcase_add_test(tc, eina_test_pointer_promise_normal_lifetime);
645 tcase_add_test(tc, eina_test_pointer_promise_normal_lifetime_all);
646 tcase_add_test(tc, eina_test_pointer_promise_immediate_set_lifetime);
647 tcase_add_test(tc, eina_test_pointer_promise_immediate_set_lifetime_all);
648 tcase_add_test(tc, eina_test_pointer_promise_values_all);
649 tcase_add_test(tc, eina_test_pointer_promise_cancel_promise);
650 tcase_add_test(tc, eina_test_pointer_promise_progress);
651 tcase_add_test(tc, eina_test_pointer_promise_progress_notify1);
652 tcase_add_test(tc, eina_test_pointer_promise_progress_notify2);
653 tcase_add_test(tc, eina_test_pointer_promise_progress_notify3);
654 tcase_add_test(tc, eina_test_pointer_promise_ignored);
655 tcase_add_test(tc, eina_test_pointer_promise_race);
375} 656}
diff --git a/src/tests/eio/eio_test_job.c b/src/tests/eio/eio_test_job.c
index 9ef8ced03c..7c9a007216 100644
--- a/src/tests/eio/eio_test_job.c
+++ b/src/tests/eio/eio_test_job.c
@@ -62,7 +62,7 @@ _main_cb(void *data, const char *file, Eina_Promise* promise EINA_UNUSED)
62} 62}
63 63
64static void 64static void
65_done_cb(void *data, Eio_File *handler EINA_UNUSED, Eina_Promise* promise EINA_UNUSED) 65_done_cb(void *data, void* value EINA_UNUSED, Eina_Promise* promise EINA_UNUSED)
66{ 66{
67 int *number_of_listed_files = (int *)data; 67 int *number_of_listed_files = (int *)data;
68 fail_if((*number_of_listed_files) != test_count); 68 fail_if((*number_of_listed_files) != test_count);
@@ -79,19 +79,20 @@ _error_cb(void *data EINA_UNUSED, Eina_Error error, Eina_Promise* promise EINA_U
79} 79}
80 80
81static void 81static void
82_open_done_cb(void *data, Eina_File **file, Eina_Promise* promise) 82_open_done_cb(void *data, void *file_value, Eina_Promise* promise EINA_UNUSED)
83{ 83{
84 Eina_Bool *opened = (Eina_Bool *)data; 84 Eina_Bool *opened = (Eina_Bool *)data;
85 *opened = EINA_TRUE; 85 *opened = EINA_TRUE;
86 eina_promise_release_value_ownership(promise); 86 Eina_File* file = eina_file_dup(file_value);
87 eina_file_close(*file); 87 eina_file_close(file);
88 ecore_main_loop_quit(); 88 ecore_main_loop_quit();
89} 89}
90 90
91static void 91static void
92_stat_done_cb(void *data, const Eina_Stat *stat, Eina_Promise* promise EINA_UNUSED) 92_stat_done_cb(void *data, void *value, Eina_Promise* promise EINA_UNUSED)
93{ 93{
94 Eina_Bool *is_dir = (Eina_Bool *)data; 94 Eina_Stat const* stat = value;
95 Eina_Bool *is_dir = data;
95 unsigned int rights; 96 unsigned int rights;
96 fail_if(eio_file_is_dir(stat) != *is_dir); 97 fail_if(eio_file_is_dir(stat) != *is_dir);
97 fail_if(eio_file_is_lnk(stat)); 98 fail_if(eio_file_is_lnk(stat));
@@ -119,10 +120,7 @@ _do_ls_test(Eio_Job_Test_Stat_Ls_Func ls_func,
119 promise = ls_func(job, test_dirname); 120 promise = ls_func(job, test_dirname);
120 test_count = expected_test_count; 121 test_count = expected_test_count;
121 eina_promise_progress_cb_add(promise, progress_cb, &main_files, NULL); 122 eina_promise_progress_cb_add(promise, progress_cb, &main_files, NULL);
122 eina_promise_then(promise, 123 eina_promise_then(promise, &_done_cb, &_error_cb, &main_files);
123 (Eina_Promise_Cb)&_done_cb,
124 (Eina_Promise_Error_Cb)&_error_cb,
125 &main_files);
126 124
127 ecore_main_loop_begin(); 125 ecore_main_loop_begin();
128 126
@@ -137,11 +135,11 @@ _do_direct_ls_test(Eio_Job_Test_Stat_Ls_Func ls_func,
137 const char *test_dirname) 135 const char *test_dirname)
138{ 136{
139 _do_ls_test(ls_func, 137 _do_ls_test(ls_func,
140 EIO_JOB_EVENT_FILTER_DIRECT, 138 EIO_JOB_EVENT_FILTER_DIRECT,
141 (Eo_Event_Cb)&_filter_direct_cb, 139 (Eo_Event_Cb)&_filter_direct_cb,
142 (Eina_Promise_Progress_Cb)&_main_direct_cb, 140 (Eina_Promise_Progress_Cb)&_main_direct_cb,
143 expected_test_count, 141 expected_test_count,
144 test_dirname); 142 test_dirname);
145} 143}
146 144
147START_TEST(eio_job_test_file_direct_stat) 145START_TEST(eio_job_test_file_direct_stat)
@@ -168,12 +166,12 @@ START_TEST(eio_job_test_file_direct_stat)
168 is_dir = EINA_TRUE; 166 is_dir = EINA_TRUE;
169 167
170 promise = eio_job_file_direct_stat(job, nested_dirname); 168 promise = eio_job_file_direct_stat(job, nested_dirname);
171 eina_promise_then(promise, (Eina_Promise_Cb)&_stat_done_cb, (Eina_Promise_Error_Cb)&_error_cb, &is_dir); 169 eina_promise_then(promise, &_stat_done_cb, &_error_cb, &is_dir);
172 ecore_main_loop_begin(); 170 ecore_main_loop_begin();
173 171
174 is_dir = EINA_FALSE; 172 is_dir = EINA_FALSE;
175 promise = eio_job_file_direct_stat(job, nested_filename); 173 promise = eio_job_file_direct_stat(job, nested_filename);
176 eina_promise_then(promise, (Eina_Promise_Cb)&_stat_done_cb, (Eina_Promise_Error_Cb)&_error_cb, &is_dir); 174 eina_promise_then(promise, &_stat_done_cb, &_error_cb, &is_dir);
177 ecore_main_loop_begin(); 175 ecore_main_loop_begin();
178 eo_unref(job); 176 eo_unref(job);
179 177
@@ -209,14 +207,12 @@ START_TEST(eio_job_test_ls_funcs)
209 207
210 // Start testing 208 // Start testing
211 209
212 fprintf(stderr, __FILE__ ":%d %s\n", __LINE__, __func__); fflush(stderr);
213 _do_ls_test(&eio_job_file_ls, 210 _do_ls_test(&eio_job_file_ls,
214 EIO_JOB_EVENT_FILTER_NAME, 211 EIO_JOB_EVENT_FILTER_NAME,
215 (Eo_Event_Cb)&_filter_cb, 212 (Eo_Event_Cb)&_filter_cb,
216 (Eina_Promise_Progress_Cb)&_main_cb, 213 (Eina_Promise_Progress_Cb)&_main_cb,
217 5, 214 5,
218 test_dirname); 215 test_dirname);
219 fprintf(stderr, __FILE__ ":%d %s\n", __LINE__, __func__); fflush(stderr);
220 216
221 _do_direct_ls_test(&eio_job_file_stat_ls, 5, test_dirname); 217 _do_direct_ls_test(&eio_job_file_stat_ls, 5, test_dirname);
222 218
@@ -246,12 +242,12 @@ START_TEST(eio_job_test_open)
246 242
247 ret = ecore_init(); 243 ret = ecore_init();
248 fail_if(ret < 1); 244 fail_if(ret < 1);
249 ret = eio_init();
250 fail_if(ret < 1);
251 ret = eina_init(); 245 ret = eina_init();
252 fail_if(ret < 1); 246 fail_if(ret < 1);
253 ret = ecore_file_init(); 247 ret = ecore_file_init();
254 fail_if(ret < 1); 248 fail_if(ret < 1);
249 ret = eio_init();
250 fail_if(ret < 1);
255 251
256 Eina_Tmpstr *test_dirname = get_eio_test_file_tmp_dir(); 252 Eina_Tmpstr *test_dirname = get_eio_test_file_tmp_dir();
257 Eina_Tmpstr *nested_dirname = create_test_dirs(test_dirname); 253 Eina_Tmpstr *nested_dirname = create_test_dirs(test_dirname);
@@ -262,7 +258,7 @@ START_TEST(eio_job_test_open)
262 Eina_Promise *promise = NULL; 258 Eina_Promise *promise = NULL;
263 259
264 promise = eio_job_file_open(job, nested_filename, EINA_FALSE); 260 promise = eio_job_file_open(job, nested_filename, EINA_FALSE);
265 eina_promise_then(promise, (Eina_Promise_Cb)&_open_done_cb, (Eina_Promise_Error_Cb)&_error_cb, &opened_file); 261 eina_promise_then(promise, &_open_done_cb, &_error_cb, &opened_file);
266 ecore_main_loop_begin(); 262 ecore_main_loop_begin();
267 eo_unref(job); 263 eo_unref(job);
268 fail_if(!opened_file); 264 fail_if(!opened_file);
@@ -272,10 +268,11 @@ START_TEST(eio_job_test_open)
272 268
273 eina_tmpstr_del(nested_dirname); 269 eina_tmpstr_del(nested_dirname);
274 eina_tmpstr_del(test_dirname); 270 eina_tmpstr_del(test_dirname);
271
272 eio_shutdown();
275 eina_tmpstr_del(nested_filename); 273 eina_tmpstr_del(nested_filename);
276 ecore_file_shutdown(); 274 ecore_file_shutdown();
277 eina_shutdown(); 275 eina_shutdown();
278 eio_shutdown();
279 ecore_shutdown(); 276 ecore_shutdown();
280} 277}
281END_TEST 278END_TEST
diff --git a/src/tests/eldbus/eldbus_test_eldbus_model.c b/src/tests/eldbus/eldbus_test_eldbus_model.c
index 68398ca11f..8dd1c07aa2 100644
--- a/src/tests/eldbus/eldbus_test_eldbus_model.c
+++ b/src/tests/eldbus/eldbus_test_eldbus_model.c
@@ -15,21 +15,23 @@
15#include "eldbus_suite.h" 15#include "eldbus_suite.h"
16 16
17static void 17static void
18_promise_then_quit_cb(void **data , void **value, Eina_Promise* promise EINA_UNUSED) 18_promise_then_quit_cb(void *data , void *value, Eina_Promise* promise EINA_UNUSED)
19{ 19{
20 *data = *value; 20 *(void**)data = value;
21 ecore_main_loop_quit(); 21 ecore_main_loop_quit();
22} 22}
23 23
24static void 24static void
25_promise_then_quit_u_cb(unsigned *data , unsigned *value, Eina_Promise* promise EINA_UNUSED) 25_promise_then_quit_u_cb(void *data , void *value, Eina_Promise* promise EINA_UNUSED)
26{ 26{
27 *data = *value; 27 unsigned *lhs = data;
28 unsigned *rhs = value;
29 *lhs = *rhs;
28 ecore_main_loop_quit(); 30 ecore_main_loop_quit();
29} 31}
30 32
31static void 33static void
32_promise_then_cp(Eina_Value *data , void *value, Eina_Promise* promise EINA_UNUSED) 34_promise_then_cp(void *data , void *value, Eina_Promise* promise EINA_UNUSED)
33{ 35{
34 eina_value_copy(value, data); 36 eina_value_copy(value, data);
35 ecore_main_loop_quit(); 37 ecore_main_loop_quit();
@@ -73,7 +75,7 @@ void *
73efl_model_promise_then(Eina_Promise *promise) 75efl_model_promise_then(Eina_Promise *promise)
74{ 76{
75 void *data = NULL; 77 void *data = NULL;
76 eina_promise_then(promise, (Eina_Promise_Cb)&_promise_then_quit_cb, &_error_then_cb, &data); 78 eina_promise_then(promise, &_promise_then_quit_cb, &_error_then_cb, &data);
77 ecore_main_loop_begin(); 79 ecore_main_loop_begin();
78 return data; 80 return data;
79} 81}
@@ -89,7 +91,7 @@ int
89efl_model_promise_then_u(Eina_Promise *promise) 91efl_model_promise_then_u(Eina_Promise *promise)
90{ 92{
91 unsigned i = 0; 93 unsigned i = 0;
92 eina_promise_then(promise, (Eina_Promise_Cb)&_promise_then_quit_u_cb, &_error_then_cb, &i); 94 eina_promise_then(promise, &_promise_then_quit_u_cb, &_error_then_cb, &i);
93 ecore_main_loop_begin(); 95 ecore_main_loop_begin();
94 return i; 96 return i;
95} 97}
@@ -407,7 +409,7 @@ check_efl_model_property_int_eq(Efl_Model *efl_model, const char *property, int
407 efl_model_property_get(efl_model, property, &promise); 409 efl_model_property_get(efl_model, property, &promise);
408 ck_assert_ptr_ne(NULL, promise); 410 ck_assert_ptr_ne(NULL, promise);
409 411
410 eina_promise_then(promise, (Eina_Promise_Cb)&_promise_then_cp, &_error_then_cb, &property_value); 412 eina_promise_then(promise, &_promise_then_cp, &_error_then_cb, &property_value);
411 ecore_main_loop_begin(); 413 ecore_main_loop_begin();
412 414
413 const Eina_Value_Type *property_type = eina_value_type_get(&property_value); 415 const Eina_Value_Type *property_type = eina_value_type_get(&property_value);
@@ -429,7 +431,7 @@ check_efl_model_property_int_set(Efl_Model *efl_model, const char *property, int
429 eina_value_set(&eina_value, value); 431 eina_value_set(&eina_value, value);
430 efl_model_property_set(efl_model, property, &eina_value, &promise); 432 efl_model_property_set(efl_model, property, &eina_value, &promise);
431 433
432 eina_promise_then(promise, (Eina_Promise_Cb)&_promise_then_cp, &_error_then_cb, &value_ret); 434 eina_promise_then(promise, &_promise_then_cp, &_error_then_cb, &value_ret);
433 ecore_main_loop_begin(); 435 ecore_main_loop_begin();
434 436
435 const Eina_Value_Type *property_type = eina_value_type_get(&value_ret); 437 const Eina_Value_Type *property_type = eina_value_type_get(&value_ret);