diff options
author | Mike Blumenkrantz <zmike@samsung.com> | 2019-10-25 13:56:04 -0400 |
---|---|---|
committer | Marcel Hollerbach <mail@marcel-hollerbach.de> | 2019-10-29 16:09:49 +0100 |
commit | 9870b7992d1a4dd1f1ab4b650283447d950a6087 (patch) | |
tree | e85bd4c4f521a13b657ad9a3edfc124036b40cd2 | |
parent | cb23d14d11c0a751792143014a0f855d3cf957f6 (diff) | |
download | efl-9870b7992d1a4dd1f1ab4b650283447d950a6087.tar.gz |
tests/loop_timer: add port of ecore_timer behavior tests for loop_timer
ensure that the behavior here is also working exactly as expected
Reviewed-by: Cedric BAIL <cedric.bail@free.fr>
Differential Revision: https://phab.enlightenment.org/D10531
-rw-r--r-- | src/tests/ecore/efl_app_test_loop_timer.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/tests/ecore/efl_app_test_loop_timer.c b/src/tests/ecore/efl_app_test_loop_timer.c index e866689012..790e56768e 100644 --- a/src/tests/ecore/efl_app_test_loop_timer.c +++ b/src/tests/ecore/efl_app_test_loop_timer.c @@ -71,6 +71,86 @@ EFL_START_TEST(efl_app_test_loop_timer_invalid) } EFL_END_TEST + + +static int count = 0; + +static void +_timer_cb(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED) +{ + count++; +} + +static void +array_clean(Eina_Array *arr) +{ + Eo *t; + + while ((t = eina_array_pop(arr))) + efl_del(t); +} + +EFL_START_TEST(efl_loop_test_loop_timer_iteration) +{ + Eo *t, *loop; + Eina_Array *arr; + + loop = efl_main_loop_get(); + count = 0; + arr = eina_array_new(5); +#define TIMER(duration) \ + t = efl_add(EFL_LOOP_TIMER_CLASS, loop, \ + efl_loop_timer_interval_set(efl_added, (duration)), \ + efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TIMER_TICK, _timer_cb, NULL) \ + ); \ + eina_array_push(arr, t) + /* verify that timers expire after exactly one loop iteration */ + TIMER(0); + efl_loop_iterate(loop); + /* timers should not expire for one loop iteration */ + ck_assert_int_eq(count, 0); + efl_loop_iterate(loop); + /* timers should expire after one loop iteration */ + ck_assert_int_eq(count, 1); + array_clean(arr); + + count = 0; + /* verify multiple timer expiration in single mainloop iteration */ + TIMER(0); + TIMER(0); + efl_loop_iterate(loop); + /* timers should not expire for one loop iteration */ + ck_assert_int_eq(count, 0); + TIMER(0); + efl_loop_iterate(loop); + /* all pending and instantiated timers should expire after exactly one loop iteration */ + ck_assert_int_eq(count, 2); + efl_loop_iterate(loop); + /* this should not interfere with successive timer processing */ + ck_assert_int_eq(count, 5); + array_clean(arr); + + count = 0; + /* verify out-of-order timer processing solely based on timer times */ + TIMER(1); + efl_loop_iterate(loop); + ck_assert_int_eq(count, 0); + TIMER(0); + efl_loop_iterate(loop); + ck_assert_int_eq(count, 0); + /* timer should expire after exactly 2 iterations */ + efl_loop_iterate(loop); + ck_assert_int_eq(count, 1); + efl_loop_timer_interval_set(eina_array_data_get(arr, 0), 0); + efl_loop_timer_reset(eina_array_data_get(arr, 0)); + /* timer should expire after exactly 2 iterations since it becomes un-instantiated now */ + efl_loop_iterate(loop); + efl_loop_iterate(loop); + ck_assert_int_eq(count, 4); + array_clean(arr); +} +EFL_END_TEST + void efl_app_test_efl_loop_timer(TCase *tc EINA_UNUSED) { /* XXX: this seems a silly test - that we del the loop object? @@ -78,4 +158,5 @@ void efl_app_test_efl_loop_timer(TCase *tc EINA_UNUSED) */ tcase_add_test(tc, efl_app_test_loop_timer_invalid); + tcase_add_test(tc, efl_loop_test_loop_timer_iteration); } |