tests/efl_app: add port of intensive timer recursion
this is roughly the same as the similarly-named ecore_timer unit test Reviewed-by: Cedric BAIL <cedric.bail@free.fr> Differential Revision: https://phab.enlightenment.org/D10556
This commit is contained in:
parent
a6c92e2fc0
commit
78bc0b77b7
|
@ -151,6 +151,108 @@ EFL_START_TEST(efl_loop_test_loop_timer_iteration)
|
|||
}
|
||||
EFL_END_TEST
|
||||
|
||||
#undef TIMER
|
||||
#define TIMER(duration) \
|
||||
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_del_cb, NULL) \
|
||||
); \
|
||||
|
||||
static void
|
||||
_timer_del_cb(void *data EINA_UNUSED, const Efl_Event *ev)
|
||||
{
|
||||
count++;
|
||||
efl_del(ev->object);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
_recursion(void *data EINA_UNUSED, const Efl_Event *ev)
|
||||
{
|
||||
static unsigned int recurse = 0;
|
||||
static Eo *timer;
|
||||
Eo *loop = efl_main_loop_get();
|
||||
|
||||
switch (recurse++)
|
||||
{
|
||||
case 0:
|
||||
/* verify multiple timer expiration in single mainloop iteration */
|
||||
TIMER(0);
|
||||
TIMER(0);
|
||||
efl_loop_iterate(loop);
|
||||
efl_loop_iterate(loop);
|
||||
ck_assert_int_eq(count, 6);
|
||||
efl_loop_quit(loop, EINA_VALUE_EMPTY);
|
||||
break;
|
||||
case 1:
|
||||
/* timers should not expire for one loop iteration */
|
||||
ck_assert_int_eq(count, 1);
|
||||
TIMER(0);
|
||||
efl_loop_iterate(loop);
|
||||
efl_loop_iterate(loop);
|
||||
break;
|
||||
case 2:
|
||||
/* all pending and instantiated timers should expire after exactly one loop iteration */
|
||||
ck_assert_int_eq(count, 3);
|
||||
efl_loop_iterate(loop);
|
||||
efl_loop_iterate(loop);
|
||||
break;
|
||||
case 3:
|
||||
/* this should not interfere with successive timer processing */
|
||||
ck_assert_int_eq(count, 4);
|
||||
|
||||
/* verify out-of-order timer processing solely based on timer times */
|
||||
timer = TIMER(1);
|
||||
efl_loop_iterate(loop);
|
||||
efl_loop_iterate(loop);
|
||||
break;
|
||||
case 4:
|
||||
ck_assert_int_eq(count, 4);
|
||||
TIMER(0);
|
||||
efl_loop_iterate(loop);
|
||||
efl_loop_iterate(loop);
|
||||
break;
|
||||
case 5:
|
||||
ck_assert_int_eq(count, 4);
|
||||
/* timer should expire after exactly 2 iterations */
|
||||
efl_loop_iterate(loop);
|
||||
efl_loop_iterate(loop);
|
||||
break;
|
||||
case 6:
|
||||
ck_assert_int_eq(count, 5);
|
||||
efl_loop_timer_interval_set(timer, 0);
|
||||
efl_loop_timer_reset(timer);
|
||||
/* timer should expire after exactly 2 iterations since it becomes un-instantiated now */
|
||||
efl_loop_iterate(loop);
|
||||
efl_loop_iterate(loop);
|
||||
break;
|
||||
case 7:
|
||||
efl_loop_iterate(loop);
|
||||
efl_loop_iterate(loop);
|
||||
efl_del(ev->object);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EFL_START_TEST(efl_loop_test_loop_timer_recursion)
|
||||
{
|
||||
Eina_Bool crit = eina_log_abort_on_critical_get();
|
||||
int critlevel = eina_log_abort_on_critical_level_get();
|
||||
Eo *loop = efl_main_loop_get();
|
||||
count = 1;
|
||||
eina_log_abort_on_critical_set(1);
|
||||
eina_log_abort_on_critical_level_set(1);
|
||||
efl_add(EFL_LOOP_TIMER_CLASS, loop,
|
||||
efl_loop_timer_interval_set(efl_added, 0),
|
||||
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TIMER_TICK, _recursion, NULL)
|
||||
);
|
||||
efl_loop_begin(loop);
|
||||
ck_assert_int_eq(count, 6);
|
||||
eina_log_abort_on_critical_set(crit);
|
||||
eina_log_abort_on_critical_level_set(critlevel);
|
||||
}
|
||||
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?
|
||||
|
@ -159,4 +261,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);
|
||||
tcase_add_test(tc, efl_loop_test_loop_timer_recursion);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue