summaryrefslogtreecommitdiff
path: root/src/tests/ecore/efl_app_test_promise.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2018-12-07 12:58:36 +0100
committerXavi Artigas <xavierartigas@yahoo.es>2018-12-07 13:20:56 +0100
commit524c05d82562bcbbf9ab6291a5dd59eff776b4b3 (patch)
treedfe9fda0ee058aff3b70e43f24c3f529e0036818 /src/tests/ecore/efl_app_test_promise.c
parent500a36ba3d3d00ed292ed3e85bb9ac40a55bd2a9 (diff)
ecore: add a full test for efl_future_then and efl_future_chain.
Summary: Depends on D7392 Reviewers: bu5hm4n, segfaultxavi Reviewed By: bu5hm4n, segfaultxavi Subscribers: #reviewers, #committers Tags: #efl Maniphest Tasks: T7472 Differential Revision: https://phab.enlightenment.org/D7393
Diffstat (limited to 'src/tests/ecore/efl_app_test_promise.c')
-rw-r--r--src/tests/ecore/efl_app_test_promise.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/tests/ecore/efl_app_test_promise.c b/src/tests/ecore/efl_app_test_promise.c
index dfd92f6..6f71881 100644
--- a/src/tests/ecore/efl_app_test_promise.c
+++ b/src/tests/ecore/efl_app_test_promise.c
@@ -1316,6 +1316,103 @@ EFL_END_TEST
1316 1316
1317#endif 1317#endif
1318 1318
1319const char *test_strings[] = { "another", "string" };
1320
1321static Eina_Value
1322test_generate_int(Eo *o, void *data, const Eina_Value value)
1323{
1324 const Eina_Value empty = EINA_VALUE_EMPTY;
1325
1326 ck_assert_int_eq(memcmp(&value, &empty, sizeof (Eina_Value)), 0);
1327 ck_assert_ptr_eq(data, test_strings[0]);
1328 ck_assert_ptr_eq(o, efl_main_loop_get());
1329 return eina_value_int_init(42);
1330}
1331
1332static Eina_Value
1333test_got_int(Eo *o EINA_UNUSED, void *data EINA_UNUSED, const Eina_Value value)
1334{
1335 int i = 0;
1336 ck_assert_ptr_eq(eina_value_type_get(&value), EINA_VALUE_TYPE_INT);
1337 eina_value_get(&value, &i);
1338 ck_assert_int_eq(i, 42);
1339
1340 return eina_value_error_init(EAGAIN);
1341}
1342
1343static Eina_Value
1344test_error_not_reached(Eo *o EINA_UNUSED, void *data EINA_UNUSED, Eina_Error error)
1345{
1346 abort();
1347
1348 return eina_value_error_init(EAGAIN);
1349}
1350
1351static Eina_Value
1352test_not_reached(Eo *o EINA_UNUSED, void *data EINA_UNUSED, const Eina_Value value)
1353{
1354 abort();
1355
1356 return value;
1357}
1358
1359static Eina_Value
1360test_failure(Eo *o, void *data EINA_UNUSED, Eina_Error error)
1361{
1362 ck_assert_int_eq(error, EAGAIN);
1363 ck_assert_ptr_eq(o, efl_main_loop_get());
1364
1365 return eina_value_error_init(error);
1366}
1367
1368static Eina_Value
1369test_end_future(Eo *o, void *data, Eina_Error error)
1370{
1371 ck_assert_ptr_eq(o, efl_main_loop_get());
1372 ck_assert_ptr_eq(data, test_strings[1]);
1373 ck_assert_int_eq(error, EAGAIN);
1374
1375 return eina_value_error_init(error);
1376}
1377
1378static void
1379test_cleanup(Eo *o, void *data, const Eina_Future *dead_future EINA_UNUSED)
1380{
1381 ck_assert_ptr_eq(o, efl_main_loop_get());
1382 ck_assert_ptr_eq(data, test_strings[1]);
1383 efl_loop_quit(o, eina_value_error_init(EAGAIN));
1384}
1385
1386static void
1387efl_main_test(void *data EINA_UNUSED, const Efl_Event *ev)
1388{
1389 Eina_Future *f;
1390
1391 f = efl_future_chain(ev->object, efl_loop_idle(ev->object),
1392 { .success = test_generate_int, .data = test_strings[0] },
1393 { .success_type = EINA_VALUE_TYPE_INT, .success = test_got_int , .error = test_error_not_reached },
1394 { .success = test_not_reached, .error = test_failure });
1395 efl_future_then(ev->object, f, .success = test_not_reached, .error = test_end_future, .data = test_strings[1], .free = test_cleanup);
1396}
1397
1398
1399EFL_START_TEST(efl_test_future_then)
1400{
1401 char *argv[] = { "Future" };
1402 Eina_Value *ret = NULL;
1403 Eina_Error err = 0;
1404
1405 efl_event_callback_add(efl_main_loop_get(), EFL_LOOP_EVENT_ARGUMENTS, efl_main_test, NULL);
1406 ecore_init_ex(1, argv);
1407 ret = efl_loop_begin(efl_main_loop_get());
1408 ecore_shutdown_ex();
1409
1410 ck_assert_ptr_eq(eina_value_type_get(ret), EINA_VALUE_TYPE_ERROR);
1411 eina_value_get(ret, &err);
1412 ck_assert_int_eq(err, EAGAIN);
1413}
1414EFL_END_TEST
1415
1319static void 1416static void
1320promise_init(void) 1417promise_init(void)
1321{ 1418{
@@ -1327,6 +1424,8 @@ static void
1327promise_shutdown(void) 1424promise_shutdown(void)
1328{ 1425{
1329 /* enable ecore init count manipulation for these tests */ 1426 /* enable ecore init count manipulation for these tests */
1427 _efl_startup_time = ecore_time_unix_get();
1428 _EFL_APP_VERSION_SET();
1330 ecore_init(); 1429 ecore_init();
1331} 1430}
1332 1431
@@ -1340,6 +1439,7 @@ void efl_app_test_promise(TCase *tc)
1340 tcase_add_test(tc, efl_test_promise_future_ignore_error); 1439 tcase_add_test(tc, efl_test_promise_future_ignore_error);
1341 tcase_add_test(tc, efl_test_promise_future_success); 1440 tcase_add_test(tc, efl_test_promise_future_success);
1342 tcase_add_test(tc, efl_test_promise_future_failure); 1441 tcase_add_test(tc, efl_test_promise_future_failure);
1442 tcase_add_test(tc, efl_test_future_then);
1343} 1443}
1344 1444
1345void efl_app_test_promise_2(TCase *tc) 1445void efl_app_test_promise_2(TCase *tc)