summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaliy Venzak <v.venzak@samsung.com>2013-04-12 10:35:45 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-04-12 10:46:47 +0900
commitb3159a889ca4a46f7512bcd462af442aae4a540f (patch)
tree92fb64a563f835f32b5d2fcef01595a6b18eb5e8
parent4c992a4f85b63176c6e9d74ef89e924cf4f61a5f (diff)
ecore: add ecore timer test.
Signed-off-by: Cedric Bail <cedric.bail@samsung.com>
-rw-r--r--src/Makefile_Ecore.am1
-rw-r--r--src/tests/ecore/ecore_suite.c1
-rw-r--r--src/tests/ecore/ecore_suite.h1
-rw-r--r--src/tests/ecore/ecore_test_timer.c179
4 files changed, 182 insertions, 0 deletions
diff --git a/src/Makefile_Ecore.am b/src/Makefile_Ecore.am
index 1dcbc84a18..58e367d224 100644
--- a/src/Makefile_Ecore.am
+++ b/src/Makefile_Ecore.am
@@ -68,6 +68,7 @@ tests/ecore/ecore_test_ecore_con.c \
68tests/ecore/ecore_test_ecore_x.c \ 68tests/ecore/ecore_test_ecore_x.c \
69tests/ecore/ecore_test_ecore_imf.c \ 69tests/ecore/ecore_test_ecore_imf.c \
70tests/ecore/ecore_test_coroutine.c \ 70tests/ecore/ecore_test_coroutine.c \
71tests/ecore/ecore_test_timer.c \
71tests/ecore/ecore_suite.h 72tests/ecore/ecore_suite.h
72 73
73tests_ecore_ecore_suite_CPPFLAGS = \ 74tests_ecore_ecore_suite_CPPFLAGS = \
diff --git a/src/tests/ecore/ecore_suite.c b/src/tests/ecore/ecore_suite.c
index 0d89390a99..552602b627 100644
--- a/src/tests/ecore/ecore_suite.c
+++ b/src/tests/ecore/ecore_suite.c
@@ -26,6 +26,7 @@ static const Ecore_Test_Case etc[] = {
26 { "Ecore Audio", ecore_test_ecore_audio}, 26 { "Ecore Audio", ecore_test_ecore_audio},
27#endif 27#endif
28 { "Ecore_Coroutine", ecore_test_coroutine }, 28 { "Ecore_Coroutine", ecore_test_coroutine },
29 { "Ecore_Timers", ecore_test_timer },
29 { NULL, NULL } 30 { NULL, NULL }
30}; 31};
31 32
diff --git a/src/tests/ecore/ecore_suite.h b/src/tests/ecore/ecore_suite.h
index 80aee40f5b..428e17b67a 100644
--- a/src/tests/ecore/ecore_suite.h
+++ b/src/tests/ecore/ecore_suite.h
@@ -9,5 +9,6 @@ void ecore_test_ecore_x(TCase *tc);
9void ecore_test_ecore_imf(TCase *tc); 9void ecore_test_ecore_imf(TCase *tc);
10void ecore_test_ecore_audio(TCase *tc); 10void ecore_test_ecore_audio(TCase *tc);
11void ecore_test_coroutine(TCase *tc); 11void ecore_test_coroutine(TCase *tc);
12void ecore_test_timer(TCase *tc);
12 13
13#endif /* _ECORE_SUITE_H */ 14#endif /* _ECORE_SUITE_H */
diff --git a/src/tests/ecore/ecore_test_timer.c b/src/tests/ecore/ecore_test_timer.c
new file mode 100644
index 0000000000..072bb9ad6e
--- /dev/null
+++ b/src/tests/ecore/ecore_test_timer.c
@@ -0,0 +1,179 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Ecore.h>
6
7#include "ecore_suite.h"
8
9#define TIMEOUT_1 0.01 // interval for timer1
10#define TIMEOUT_2 0.02 // timer2
11#define TIMEOUT_3 0.06 // timer3
12#define TIMEOUT_4 0.1 // timer4
13#define TIMEOUT_5 1.0 // timer5 - end ecore_main_loop_begin()
14#define SIZE 3
15
16static int freeze_thaw = 0; // 1 - freeze timer, 0 - thaw
17
18struct _timers // timer struct
19{
20 Ecore_Timer *timer1; // timer 1
21 Ecore_Timer *timer2;
22 Ecore_Timer *timer3;
23 Ecore_Timer *timer4;
24 Ecore_Timer *timer5;
25 int count_timer1;
26 int count_timer3; // check count timer 3
27 int add_timer2; // flag add timer 2
28 int check_freeze_thaw_timer3;
29 int num_elem;
30 float delay_1[3];
31 float interval_1[3];
32 float precision[3];
33};
34
35static Eina_Bool
36_timer1_cb(void *data)
37{
38 struct _timers *timer = data;
39 timer->count_timer1++;
40
41 return ECORE_CALLBACK_RENEW;
42}
43
44static Eina_Bool
45_timer2_cb(void *data)
46{
47 struct _timers *timer = (struct _timers*)data;
48
49 // choose next settings (delay, interval, precision) for timer 1
50 if (timer->num_elem++ > 2)
51 timer->num_elem = 0;
52
53 // check add/delay timer 2
54 fail_if(timer->add_timer2 > 1, "Error add/delay timer");
55
56 // check set new delay for timer 1
57 ecore_timer_delay(timer->timer1, timer->delay_1[timer->num_elem]);
58
59 // check set new interval for timer 1
60 ecore_timer_interval_set(timer->timer1, timer->interval_1[timer->num_elem]);
61 fail_if(timer->interval_1[timer->num_elem] != ecore_timer_interval_get(timer->timer1), "Error set new interval");
62
63 // check set new precision
64 ecore_timer_precision_set(timer->precision[timer->num_elem]);
65 fail_if(timer->precision[timer->num_elem] != ecore_timer_precision_get(), "Error set new precision");
66
67 // check removal timer 2
68 if (ecore_timer_del(timer->timer2))
69 {
70 timer->add_timer2 = 0;
71 timer->timer2 = NULL;
72 }
73 return ECORE_CALLBACK_RENEW;
74}
75
76static Eina_Bool
77_timer3_cb(void *data)
78{
79 struct _timers *timer = (struct _timers*)data;
80
81 timer->count_timer3++; // number of starts timer 3
82
83 // check add timer 2
84 if (!timer->timer2)
85 {
86 timer->add_timer2++; // amount of added timer
87 timer->timer2 = ecore_timer_add(TIMEOUT_2, _timer2_cb, timer);
88 }
89
90 return ECORE_CALLBACK_RENEW;
91}
92
93static Eina_Bool
94_timer4_cb(void *data)
95{
96 struct _timers *timer = (struct _timers*)data;
97
98 // check frezze/thaw timer 3
99 if (freeze_thaw)
100 {
101 fail_if(timer->check_freeze_thaw_timer3 != timer->count_timer3, "Error frezze/thaw timer");
102
103 ecore_timer_thaw(timer->timer3);
104 freeze_thaw = 0;
105 }
106 else
107 {
108 ecore_timer_freeze(timer->timer3);
109 freeze_thaw = 1;
110 timer->check_freeze_thaw_timer3 = timer->count_timer3;
111 }
112
113 return ECORE_CALLBACK_RENEW;
114}
115
116static Eina_Bool
117_timer5_cb(void *data)
118{
119 struct _timers *timer = (struct _timers*)data;
120 if (timer->timer2) timer->timer2 = NULL;
121 ecore_main_loop_quit();
122 return ECORE_CALLBACK_RENEW;
123}
124
125/*
126 Timer2 sets new parameters (delay, interval and precision) for Timer1 and checks them.
127 Timer3 creates and runs Timer2 and increases parameter add_timer2 to 1. Timer2 removes himself
128 and sets parameter add_timer2 to 0. Inside callback of Timer2 parameter add_timer2 should be
129 equal to 1 otherwise "Error add/delay timer".
130 Timer4 controls 'freezing' or 'thaw' for Timer3. Timer4 sets flag freeze_thaw to state: 'freeze' or 'thaw'.
131 When Timer3 is frozen counter of Timer3 saved in the parameter check_freeze_thaw_timer3.
132 Otherwise (thaw mode) check that parameter check_freeze_thaw_timer3 equals to counter Timer3.
133 If not equal then "Error frezze/thaw timer".
134 Timer 5 finishes testing.
135*/
136
137START_TEST(ecore_test_timers)
138{
139 struct _timers timer = \
140 {
141 .num_elem = 0,
142 .delay_1 = {0.01, 0.05, 0.1},
143 .interval_1 = {0.01, 0.05, 0.1},
144 .precision = {0.01, 0.02, 0.03}
145 };
146
147 fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n");
148
149 timer.timer1 = ecore_timer_add(TIMEOUT_1, _timer1_cb, &timer);
150 timer.timer2 = ecore_timer_add(TIMEOUT_2, _timer2_cb, &timer);
151 timer.add_timer2++;
152 timer.timer3 = ecore_timer_add(TIMEOUT_3, _timer3_cb, &timer);
153 timer.timer4 = ecore_timer_add(TIMEOUT_4, _timer4_cb, &timer);
154 timer.timer5 = ecore_timer_add(TIMEOUT_5, _timer5_cb, &timer);
155
156 fail_if((!timer.timer1 || !timer.timer2 || !timer.timer3 || !timer.timer4 || !timer.timer5), "Error add timer\n");
157
158 ecore_main_loop_begin();
159
160 if (timer.timer1)
161 ecore_timer_del(timer.timer1);
162 if (timer.timer2)
163 ecore_timer_del(timer.timer2);
164 if (timer.timer3)
165 ecore_timer_del(timer.timer3);
166 if (timer.timer4)
167 ecore_timer_del(timer.timer4);
168 if (timer.timer5)
169 ecore_timer_del(timer.timer5);
170
171 ecore_shutdown();
172
173}
174END_TEST
175
176void ecore_test_timer(TCase *tc)
177{
178 tcase_add_test(tc, ecore_test_timers);
179}