summaryrefslogtreecommitdiff
path: root/src/tests/ecore/ecore_test_ecore.c
diff options
context:
space:
mode:
authorValerii Kanunik <v.kanunik@samsung.com>2013-04-19 15:42:41 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-04-19 15:43:42 +0900
commitd601c15302277010725d2cdd34fa40eaf5be801d (patch)
tree0bf2122681ebb9859a444e3848aac8bcbe52adc6 /src/tests/ecore/ecore_test_ecore.c
parent9abcb77c73e37d7f35a2b8884b7a62383ad11df9 (diff)
ecore: update ecore_test_ecore_main_loop_event test for more coverage code.
Signed-off-by: Cedric Bail <cedric.bail@samsung.com>
Diffstat (limited to 'src/tests/ecore/ecore_test_ecore.c')
-rw-r--r--src/tests/ecore/ecore_test_ecore.c202
1 files changed, 187 insertions, 15 deletions
diff --git a/src/tests/ecore/ecore_test_ecore.c b/src/tests/ecore/ecore_test_ecore.c
index 872c7dc554..c6eca20dc4 100644
--- a/src/tests/ecore/ecore_test_ecore.c
+++ b/src/tests/ecore/ecore_test_ecore.c
@@ -13,6 +13,9 @@
13#define FP_ERR (0.0000001) 13#define FP_ERR (0.0000001)
14#define CHECK_FP(a, b) ((a - b) < FP_ERR) 14#define CHECK_FP(a, b) ((a - b) < FP_ERR)
15 15
16#define ECORE_EVENT_CUSTOM_1 1
17#define ECORE_EVENT_CUSTOM_2 2
18
16static int _log_dom; 19static int _log_dom;
17#define INF(...) EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__) 20#define INF(...) EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__)
18 21
@@ -251,41 +254,210 @@ START_TEST(ecore_test_ecore_main_loop_fd_handler)
251END_TEST 254END_TEST
252 255
253static Eina_Bool 256static Eina_Bool
254_event_handler_cb(void *data, int type EINA_UNUSED, void *event EINA_UNUSED) 257_event_handler_cb(void *data, int type, void *event)
255{ 258{
256 /* FIXME: why setting val if it is overwritten just after and what is its purpose ??? */ 259 int *did = data;
257 Eina_Bool *val = data;
258 260
259 *val = EINA_TRUE; 261 int t1 = type;
260 ecore_main_loop_quit(); 262 int *e1 = event;
261 return EINA_FALSE; 263
264 int t2 = ecore_event_current_type_get();
265 int *e2 = ecore_event_current_event_get();
266
267 if (t1 == t2)
268 (*did)++;
269
270 if (*e1 == *e2 && (ECORE_EVENT_CUSTOM_1 == *e1 || ECORE_EVENT_CUSTOM_2 == *e1))
271 (*did)++;
272
273 return EINA_TRUE;
274}
275
276static Eina_Bool
277_event_handler_cb2(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
278{
279 int *did = data;
280 (*did)++;
281 return EINA_TRUE;
282}
283
284static Eina_Bool
285_event_handler_cb3(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
286{
287 int *did = data;
288 (*did)++;
289 return EINA_TRUE;
290}
291
292static int *
293_event_new(int id)
294{
295 int *ev = malloc(sizeof(int));
296
297 switch(id)
298 {
299 case ECORE_EVENT_CUSTOM_1:
300 *ev = ECORE_EVENT_CUSTOM_1;
301 break;
302
303 case ECORE_EVENT_CUSTOM_2:
304 *ev = ECORE_EVENT_CUSTOM_2;
305 break;
306
307 default:
308 *ev = ECORE_EVENT_NONE;
309 }
310
311 return ev;
312}
313
314static void
315_event_free(void *user_data, void *func_data)
316{
317 int *did = user_data;
318 int *ev = func_data;
319
320 if (ECORE_EVENT_CUSTOM_1 == *ev || ECORE_EVENT_CUSTOM_2 == *ev)
321 (*did)++;
322
323 free(ev);
324}
325
326static void*
327_filter_start(void *data)
328{
329 int *did = data;
330 (*did)++;
331 return NULL;
332}
333
334static Eina_Bool
335_filter(void *data, void *loop_data EINA_UNUSED, int type EINA_UNUSED, void *event)
336{
337 Eina_Bool res = EINA_TRUE;
338 int *did = data;
339 int *ev = event;
340
341 if (NULL != event)
342 {
343 /* Ignore second event */
344 if (ECORE_EVENT_CUSTOM_2 == *ev)
345 {
346 res = EINA_FALSE;
347 }
348 }
349
350 (*did)++;
351
352 return res;
353}
354
355static void
356_filter_end(void *user_data, void *func_data EINA_UNUSED)
357{
358 int *did = user_data;
359 (*did)++;
262} 360}
263 361
264START_TEST(ecore_test_ecore_main_loop_event) 362START_TEST(ecore_test_ecore_main_loop_event)
265{ 363{
266 Eina_Bool did = EINA_FALSE; 364 Ecore_Event_Handler *handler, *handler2, *handler3;
267 Ecore_Event_Handler *handler; 365 Ecore_Event_Filter *filter_handler;
268 Ecore_Event *event; 366 Ecore_Event *event;
269 int ret, type; 367 int res_counter;
368 int type, type2;
369 int *ev = NULL;
370 int did = 0;
371 int filter = 0;
270 372
271 ret = ecore_init(); 373 res_counter = ecore_init();
272 fail_if(ret != 1); 374 fail_if(res_counter != 1);
273 375
376 /* Create 2 new event types */
274 type = ecore_event_type_new(); 377 type = ecore_event_type_new();
275 fail_if(type < 1); 378 fail_if(type < 1);
276 379
380 type2 = ecore_event_type_new();
381 fail_if(type < 1);
382
383 /* Add handler for new type of event */
277 handler = ecore_event_handler_add(type, _event_handler_cb, &did); 384 handler = ecore_event_handler_add(type, _event_handler_cb, &did);
278 fail_if(handler == NULL); 385 fail_if(handler == NULL);
279 386
280 event = ecore_event_add(type, NULL, NULL, NULL); 387 /* Add another handler for event which will be deleted in next step */
388 handler2 = ecore_event_handler_add(type, _event_handler_cb2, &did);
389 fail_if(handler2 == NULL);
390
391 /* Add handler for event which will be filtered */
392 handler3 = ecore_event_handler_add(type2, _event_handler_cb3, &did);
393 fail_if(handler3 == NULL);
394
395 /* Add filtering mechanism */
396 filter_handler = ecore_event_filter_add(_filter_start, _filter, _filter_end, &filter);
397
398 /* Add into main loop three events: one to process, one to filter, one to quit */
399 ev = _event_new(ECORE_EVENT_CUSTOM_1);
400 event = ecore_event_add(type, ev, _event_free, &did);
401 fail_if(event == NULL);
402
403 ev = _event_new(ECORE_EVENT_CUSTOM_2);
404 event = ecore_event_add(type2, ev, _event_free, &did);
405 fail_if(event == NULL);
406
407 event = ecore_event_add(ECORE_EVENT_SIGNAL_EXIT, NULL, NULL, NULL);
281 fail_if(event == NULL); 408 fail_if(event == NULL);
282 409
283 ecore_main_loop_begin(); 410 ecore_main_loop_begin();
284 411
285 fail_if(did == EINA_FALSE); 412 /*
413 Check internal fail cases:
414 event_cbx - 3 increments (4th should be ignored)
415 free - 2 increments
416 */
417 fail_if(did != 3 + 2); // 5
286 418
287 ret = ecore_shutdown(); 419 /*
288 fail_if(ret != 0); 420 Check filter procedures calls:
421 start - 1 call
422 filter - 3 calls
423 end - 1 call
424 */
425 fail_if(filter != 1 + 3 + 1); // 5
426
427 /* New loop but with new data and without filter and one callback procedure */
428 int did2 = 0;
429 filter = 0;
430
431 int *old = ecore_event_handler_data_set(handler, &did2);
432 int *new = ecore_event_handler_data_get(handler);
433
434 ecore_event_handler_del(handler2);
435 ecore_event_filter_del(filter_handler);
436
437 fail_if(*old != did);
438 fail_if(*new != did2);
439
440 ev = _event_new(ECORE_EVENT_CUSTOM_1);
441 event = ecore_event_add(type, ev, _event_free, &did2);
442 fail_if(event == NULL);
443
444 event = ecore_event_add(ECORE_EVENT_SIGNAL_EXIT, NULL, NULL, NULL);
445 fail_if(event == NULL);
446
447 ecore_main_loop_begin();
448
449 /*
450 Check internal fail cases:
451 event_cb - 2 increments in first callback (another one was deleted)
452 free - 1 increment
453 */
454 fail_if(did2 != 2 + 1); // 3
455
456 /* Filter counter shouldn't change */
457 fail_if(filter != 0); // 0
458
459 res_counter = ecore_shutdown();
460 fail_if(res_counter != 0);
289} 461}
290END_TEST 462END_TEST
291 463