summaryrefslogtreecommitdiff
path: root/src/tests/ecore/ecore_test_ecore.c
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-12-03 18:29:51 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-12-03 18:29:51 +0000
commit128074a2bd09fa5c1f467b95c1c0446c68052d99 (patch)
tree25b6b5e8c07763b0bfb48ef6d72c10a769cd147a /src/tests/ecore/ecore_test_ecore.c
parent9e8e98f736cf3f0149b02d52e235402486647b53 (diff)
Ecore: merge unit tests, ignore++
SVN revision: 80090
Diffstat (limited to 'src/tests/ecore/ecore_test_ecore.c')
-rw-r--r--src/tests/ecore/ecore_test_ecore.c366
1 files changed, 366 insertions, 0 deletions
diff --git a/src/tests/ecore/ecore_test_ecore.c b/src/tests/ecore/ecore_test_ecore.c
new file mode 100644
index 0000000000..357ad007bb
--- /dev/null
+++ b/src/tests/ecore/ecore_test_ecore.c
@@ -0,0 +1,366 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdio.h>
6#include <unistd.h>
7
8#include <Eina.h>
9#include <Ecore.h>
10
11#include "ecore_suite.h"
12
13static int _log_dom;
14#define INF(...) EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__)
15
16static Eina_Bool
17_quit_cb(void *data)
18{
19 Eina_Bool *val = data;
20 *val = EINA_TRUE;
21 ecore_main_loop_quit();
22 return EINA_FALSE;
23}
24
25static Eina_Bool
26_dummy_cb(void *data)
27{
28 return !!data;
29}
30
31START_TEST(ecore_test_ecore_init)
32{
33 int ret;
34
35 ret = ecore_init();
36 fail_if(ret != 1);
37
38 ret = ecore_shutdown();
39 fail_if(ret != 0);
40}
41END_TEST
42
43START_TEST(ecore_test_ecore_main_loop)
44{
45 Eina_Bool did = EINA_FALSE;
46 Ecore_Timer *timer;
47 int ret;
48
49 ret = ecore_init();
50 fail_if(ret != 1);
51
52 timer = ecore_timer_add(0.0, _quit_cb, &did);
53 fail_if(timer == NULL);
54
55 ecore_main_loop_begin();
56
57 fail_if(did == EINA_FALSE);
58
59 ret = ecore_shutdown();
60 fail_if(ret != 0);
61}
62END_TEST
63
64START_TEST(ecore_test_ecore_main_loop_idler)
65{
66 Eina_Bool did = EINA_FALSE;
67 Ecore_Idler *idler;
68 int ret;
69
70 ret = ecore_init();
71 fail_if(ret != 1);
72
73 idler = ecore_idler_add(_quit_cb, &did);
74 fail_if(idler == NULL);
75
76 ecore_main_loop_begin();
77
78 fail_if(did == EINA_FALSE);
79
80 ret = ecore_shutdown();
81 fail_if(ret != 0);
82}
83END_TEST
84
85START_TEST(ecore_test_ecore_main_loop_idle_enterer)
86{
87 Eina_Bool did = EINA_FALSE;
88 Ecore_Idle_Enterer *idle_enterer;
89 int ret;
90
91 ret = ecore_init();
92 fail_if(ret != 1);
93
94 idle_enterer = ecore_idle_enterer_add(_quit_cb, &did);
95 fail_if(idle_enterer == NULL);
96
97 ecore_main_loop_begin();
98
99 fail_if(did == EINA_FALSE);
100
101 ret = ecore_shutdown();
102 fail_if(ret != 0);
103}
104END_TEST
105
106START_TEST(ecore_test_ecore_main_loop_idle_exiter)
107{
108 Eina_Bool did = EINA_FALSE;
109 Ecore_Timer *timer;
110 Ecore_Idle_Exiter *idle_exiter;
111 int ret;
112
113 ret = ecore_init();
114 fail_if(ret != 1);
115
116 /* make system exit idle */
117 timer = ecore_timer_add(0.0, _dummy_cb, (void *)(long)0);
118 fail_if(timer == NULL);
119
120 idle_exiter = ecore_idle_exiter_add(_quit_cb, &did);
121 fail_if(idle_exiter == NULL);
122
123 ecore_main_loop_begin();
124
125 fail_if(did == EINA_FALSE);
126
127 ret = ecore_shutdown();
128 fail_if(ret != 0);
129}
130END_TEST
131
132START_TEST(ecore_test_ecore_main_loop_timer)
133{
134 Eina_Bool did = EINA_FALSE;
135 Ecore_Timer *timer;
136 double start, end, elapsed;
137 int ret;
138
139 ret = ecore_init();
140 fail_if(ret != 1);
141
142 timer = ecore_timer_add(2.0, _quit_cb, &did);
143 fail_if(timer == NULL);
144
145 start = ecore_time_get();
146 ecore_main_loop_begin();
147 end = ecore_time_get();
148 elapsed = end - start;
149
150 fail_if(did == EINA_FALSE);
151 fail_if(elapsed < 2.0);
152 fail_if(elapsed > 3.0); /* 1 second "error margin" */
153
154 ret = ecore_shutdown();
155 fail_if(ret != 0);
156}
157END_TEST
158
159static Eina_Bool _timer3(void *data EINA_UNUSED)
160{
161 /* timer 3, do nothing */
162 return EINA_FALSE;
163}
164
165static Eina_Bool _timer2(void *data EINA_UNUSED)
166{
167 /* timer 2, quit inner mainloop */
168 ecore_main_loop_quit();
169 return EINA_FALSE;
170}
171
172static Eina_Bool _timer1(void *data)
173{
174 /* timer 1, begin inner mainloop */
175 int *times = data;
176 (*times)++;
177
178 ecore_timer_add(0.3, _timer2, NULL);
179 ecore_timer_add(0.1, _timer3, NULL);
180 ecore_main_loop_begin();
181
182 ecore_main_loop_quit();
183
184 return EINA_FALSE;
185}
186
187START_TEST(ecore_test_ecore_main_loop_timer_inner)
188{
189 Ecore_Timer *timer;
190 int ret;
191 int times = 0;
192
193 ret = ecore_init();
194 fail_if(ret != 1);
195
196 timer = ecore_timer_add(1.0, _timer1, &times);
197 fail_if(timer == NULL);
198
199 /* BEGIN: outer mainloop */
200 ecore_main_loop_begin();
201 /*END: outer mainloop */
202
203 fail_if(times != 1);
204}
205END_TEST
206
207static Eina_Bool
208_fd_handler_cb(void *data, Ecore_Fd_Handler *handler EINA_UNUSED)
209{
210 /* FIXME: why setting val if it is overwritten just after and what is its purpose ??? */
211 Eina_Bool *val = data;
212
213 *val = EINA_TRUE;
214 ecore_main_loop_quit();
215 return EINA_FALSE;
216}
217
218START_TEST(ecore_test_ecore_main_loop_fd_handler)
219{
220 Eina_Bool did = EINA_FALSE;
221 Ecore_Fd_Handler *fd_handler;
222 int comm[2];
223 int ret;
224
225 ret = ecore_init();
226 fail_if(ret != 1);
227
228 ret = pipe(comm);
229 fail_if(ret != 0);
230
231 fd_handler = ecore_main_fd_handler_add
232 (comm[0], ECORE_FD_READ, _fd_handler_cb, &did, NULL, NULL);
233 fail_if(fd_handler == NULL);
234
235 ret = write(comm[1], &did, 1);
236 fail_if(ret != 1);
237
238 ecore_main_loop_begin();
239
240 close(comm[0]);
241 close(comm[1]);
242
243 fail_if(did == EINA_FALSE);
244
245 ret = ecore_shutdown();
246 fail_if(ret != 0);
247}
248END_TEST
249
250static Eina_Bool
251_event_handler_cb(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
252{
253 /* FIXME: why setting val if it is overwritten just after and what is its purpose ??? */
254 Eina_Bool *val = data;
255
256 *val = EINA_TRUE;
257 ecore_main_loop_quit();
258 return EINA_FALSE;
259}
260
261START_TEST(ecore_test_ecore_main_loop_event)
262{
263 Eina_Bool did = EINA_FALSE;
264 Ecore_Event_Handler *handler;
265 Ecore_Event *event;
266 int ret, type;
267
268 ret = ecore_init();
269 fail_if(ret != 1);
270
271 type = ecore_event_type_new();
272 fail_if(type < 1);
273
274 handler = ecore_event_handler_add(type, _event_handler_cb, &did);
275 fail_if(handler == NULL);
276
277 event = ecore_event_add(type, NULL, NULL, NULL);
278 fail_if(event == NULL);
279
280 ecore_main_loop_begin();
281
282 fail_if(did == EINA_FALSE);
283
284 ret = ecore_shutdown();
285 fail_if(ret != 0);
286}
287END_TEST
288
289static Eina_Bool
290_timer_quit_recursive(void *data EINA_UNUSED)
291{
292 INF(" _timer_quit_recursive: begin");
293 ecore_main_loop_quit(); /* quits inner main loop */
294 INF(" _timer_quit_recursive: end");
295 return EINA_FALSE;
296}
297
298static Eina_Bool
299_event_recursive_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
300{
301 static int guard = 0;
302
303 /* If we enter this callback more than once, it's wrong! */
304 fail_if(guard != 0);
305 guard++;
306
307 INF(" event_recursive_cb: begin");
308
309 ecore_timer_add(1.0, _timer_quit_recursive, NULL);
310 INF(" add 1.0s timer (once) to trigger _timer_quit_recursive");
311
312 INF(" inner main loop begin (recurse)");
313 ecore_main_loop_begin();
314 INF(" inner main loop end (recurse)");
315
316 ecore_main_loop_quit(); /* quits outer main loop */
317
318 INF(" guard = %d", guard);
319 INF(" event_recursive_cb: end");
320 return EINA_FALSE;
321}
322
323
324START_TEST(ecore_test_ecore_main_loop_event_recursive)
325{
326 /* This test tests if the event handlers are really called only once when
327 * recursive main loops are used and any number of events may have occurred
328 * between the beginning and the end of recursive main loop.
329 */
330 Ecore_Event *e;
331 int type;
332 int ret;
333
334 _log_dom = eina_log_domain_register("test", EINA_COLOR_CYAN);
335
336 INF("main: begin");
337 ret = ecore_init();
338 fail_if(ret != 1);
339
340
341 type = ecore_event_type_new();
342 ecore_event_handler_add(type, _event_recursive_cb, NULL);
343 e = ecore_event_add(type, NULL, NULL, NULL);
344 INF(" add event to trigger cb1: event=%p", e);
345 INF(" main loop begin");
346 ecore_main_loop_begin();
347 INF(" main loop end");
348
349 INF("main: end");
350 ecore_shutdown();
351}
352END_TEST
353
354void ecore_test_ecore(TCase *tc)
355{
356 tcase_add_test(tc, ecore_test_ecore_init);
357 tcase_add_test(tc, ecore_test_ecore_main_loop);
358 tcase_add_test(tc, ecore_test_ecore_main_loop_idler);
359 tcase_add_test(tc, ecore_test_ecore_main_loop_idle_enterer);
360 tcase_add_test(tc, ecore_test_ecore_main_loop_idle_exiter);
361 tcase_add_test(tc, ecore_test_ecore_main_loop_timer);
362 tcase_add_test(tc, ecore_test_ecore_main_loop_fd_handler);
363 tcase_add_test(tc, ecore_test_ecore_main_loop_event);
364 tcase_add_test(tc, ecore_test_ecore_main_loop_timer_inner);
365 tcase_add_test(tc, ecore_test_ecore_main_loop_event_recursive);
366}