summaryrefslogtreecommitdiff
path: root/src/tests/ecore/efl_app_test_loop.c
blob: 0ab7bb6bdbde3c138146ce490ce4caf72f67ff0f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdio.h>
#include <unistd.h>
#define EFL_NOLEGACY_API_SUPPORT
#include <Efl_Core.h>
#include "efl_app_suite.h"
#include "../efl_check.h"

EFL_START_TEST(efl_app_test_efl_loop_register)
{
   Efl_Object *t, *n;

   ecore_init();

   t = efl_provider_find(efl_app_main_get(), EFL_LOOP_CLASS);
   fail_if(!efl_isa(t, EFL_LOOP_CLASS));
   fail_if(!efl_isa(t, EFL_APP_CLASS));

   t = efl_provider_find(efl_app_main_get(), EFL_LOOP_TIMER_CLASS);
   fail_if(t != NULL);

   n = efl_add(EFL_LOOP_TIMER_CLASS, efl_app_main_get(),
               efl_loop_timer_interval_set(efl_added, 1.0));
   efl_loop_register(efl_app_main_get(), EFL_LOOP_TIMER_CLASS, n);

   t = efl_provider_find(efl_app_main_get(), EFL_LOOP_TIMER_CLASS);
   fail_if(!efl_isa(t, EFL_LOOP_TIMER_CLASS));
   fail_if(t != n);

   efl_loop_unregister(efl_app_main_get(), EFL_LOOP_TIMER_CLASS, n);

   t = efl_provider_find(efl_app_main_get(), EFL_LOOP_TIMER_CLASS);
   fail_if(t != NULL);

   ecore_shutdown();
}
EFL_END_TEST

static void
efl_app_test_efl_loop_concentric_fail(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{
   ck_abort_msg("test timeout");
}

static void
loop_idle_enter(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{
   static int num = 0;

   if (num++ == 5) efl_loop_quit(efl_main_loop_get(), eina_value_int_init(0));
}

static void
loop_idle(void *data, const Efl_Event *ev EINA_UNUSED)
{
   efl_loop_iterate(data);
}

static void
loop_timer_tick(void *data, const Efl_Event *ev EINA_UNUSED)
{
   efl_loop_iterate(data);
}

EFL_START_TEST(efl_app_test_efl_loop_concentric)
{
   Eo *loop, *loop2, *timer, *timer2;
   int exitcode;

   loop = efl_main_loop_get();
   loop2 = efl_add(EFL_LOOP_CLASS, loop);
   efl_event_callback_add(loop, EFL_LOOP_EVENT_IDLE, loop_idle, loop2);
   efl_event_callback_add(loop, EFL_LOOP_EVENT_IDLE_ENTER, loop_idle_enter, NULL);
   timer = efl_add(EFL_LOOP_TIMER_CLASS, loop2,
     efl_loop_timer_interval_set(efl_added, 0.01),
     efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TICK, loop_timer_tick, loop)
     );
   timer2 = efl_add(EFL_LOOP_TIMER_CLASS, loop,
     efl_loop_timer_interval_set(efl_added, 0.5),
     efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TICK, efl_app_test_efl_loop_concentric_fail, NULL)
     );
   exitcode = efl_loop_exit_code_process(efl_loop_begin(loop));
   ck_assert_int_eq(exitcode, 0);
   efl_del(timer2);
   efl_del(timer);
   efl_del(loop2);
}
EFL_END_TEST

void efl_app_test_efl_loop(TCase *tc)
{
   tcase_add_test(tc, efl_app_test_efl_loop_register);
   tcase_add_test(tc, efl_app_test_efl_loop_concentric);
}