summaryrefslogtreecommitdiff
path: root/src/tests/ecore/ecore_test_ecore.c
diff options
context:
space:
mode:
authorValerii Kanunik <v.kanunik@samsung.com>2013-04-12 11:06:37 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-04-12 11:07:11 +0900
commit89f108312ebae7ebca5148e950a8abe1caf342ad (patch)
tree1125a73089210e396bfe7208c66a443faa318f30 /src/tests/ecore/ecore_test_ecore.c
parentfbec2b33dbf0bd893cf52165df1777a0b7c2a58a (diff)
ecore: add tests for ecore_poll module.
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.c136
1 files changed, 136 insertions, 0 deletions
diff --git a/src/tests/ecore/ecore_test_ecore.c b/src/tests/ecore/ecore_test_ecore.c
index aca7b2c713..872c7dc554 100644
--- a/src/tests/ecore/ecore_test_ecore.c
+++ b/src/tests/ecore/ecore_test_ecore.c
@@ -10,6 +10,9 @@
10 10
11#include "ecore_suite.h" 11#include "ecore_suite.h"
12 12
13#define FP_ERR (0.0000001)
14#define CHECK_FP(a, b) ((a - b) < FP_ERR)
15
13static int _log_dom; 16static int _log_dom;
14#define INF(...) EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__) 17#define INF(...) EINA_LOG_DOM_INFO(_log_dom, __VA_ARGS__)
15 18
@@ -379,6 +382,137 @@ START_TEST(ecore_test_ecore_app)
379} 382}
380END_TEST 383END_TEST
381 384
385Eina_Bool _poller_cb(void *data)
386{
387 int *val = data;
388 (*val)++;
389 return ECORE_CALLBACK_RENEW;
390}
391
392START_TEST(ecore_test_ecore_main_loop_poller)
393{
394 int ret;
395
396 Ecore_Poller *poll1_ptr = NULL;
397 int poll1_interval = 1;
398 int poll1_counter = 0;
399
400 Ecore_Poller *poll2_ptr = NULL;
401 int poll2_interval = 2;
402 int poll2_counter = 0;
403
404 Ecore_Poller *poll3_ptr = NULL;
405 int poll3_interval = 4;
406 int poll3_counter = 0;
407
408 Eina_Bool did = EINA_FALSE;
409
410 ret = ecore_init();
411 fail_if(ret != 1);
412
413 /* Check ECORE_POLLER_CORE poll interval */
414 double interval = 1.0;
415 ecore_poller_poll_interval_set(ECORE_POLLER_CORE, interval);
416 fail_unless(CHECK_FP(ecore_poller_poll_interval_get(ECORE_POLLER_CORE), interval));
417
418 /* Create three pollers with different poller interval */
419 poll1_ptr = ecore_poller_add(ECORE_POLLER_CORE, poll1_interval, _poller_cb, &poll1_counter);
420 poll2_ptr = ecore_poller_add(ECORE_POLLER_CORE, poll2_interval, _poller_cb, &poll2_counter);
421 poll3_ptr = ecore_poller_add(ECORE_POLLER_CORE, poll3_interval, _poller_cb, &poll3_counter);
422
423 /* Add one time processed quit poller */
424 ecore_poller_add(ECORE_POLLER_CORE, 8, _quit_cb, &did);
425
426 /* Enter main loop and wait 8 seconds for quit */
427 ecore_main_loop_begin();
428
429 /* Check each poller poll interval */
430 fail_if(ecore_poller_poller_interval_get(poll1_ptr) != poll1_interval);
431 fail_if(ecore_poller_poller_interval_get(poll2_ptr) != poll2_interval);
432 fail_if(ecore_poller_poller_interval_get(poll3_ptr) != poll3_interval);
433
434 /* Check each poller call counter */
435 fail_if(8 != poll1_counter);
436 fail_if(4 != poll2_counter);
437 fail_if(2 != poll3_counter);
438
439 /* Destroy renewable pollers */
440 ecore_poller_del(poll3_ptr);
441 ecore_poller_del(poll2_ptr);
442 ecore_poller_del(poll1_ptr);
443
444 fail_if(did == EINA_FALSE);
445
446 ret = ecore_shutdown();
447 fail_if(ret != 0);
448}
449END_TEST
450
451Eina_Bool _poller_handler(void *data)
452{
453 int *val = data;
454 (*val)++;
455 return ECORE_CALLBACK_RENEW;
456}
457
458Eina_Bool _poller_loop(void *data)
459{
460 int *res = data;
461
462 static Ecore_Poller *poll_ptr = NULL;
463 static int count = 0;
464
465 switch (count)
466 {
467 case 2:
468 poll_ptr = ecore_poller_add(ECORE_POLLER_CORE, 2, _poller_handler, res);
469 break;
470 case 6:
471 ecore_poller_poller_interval_set(poll_ptr, 1);
472 break;
473 case 10:
474 ecore_poller_del(poll_ptr);
475 break;
476 default:
477 // do nothing
478 break;
479 }
480 count++;
481 return ECORE_CALLBACK_RENEW;
482}
483
484START_TEST(ecore_test_ecore_main_loop_poller_add_del)
485{
486 int ret, count_res = 0;
487
488 Eina_Bool did = EINA_FALSE;
489
490 ret = ecore_init();
491 fail_if(ret != 1);
492
493 /* Create renewable main poller */
494 Ecore_Poller *poll_ptr = ecore_poller_add(ECORE_POLLER_CORE, 1, _poller_loop, &count_res);
495
496 /* One time processed poller */
497 ecore_poller_add(ECORE_POLLER_CORE, 16, _quit_cb, &did);
498
499 /* Enter main loop and wait for quit*/
500 ecore_main_loop_begin();
501
502 fprintf(stderr, "count_res: %i\n", count_res);
503 /* Validation call counter */
504 fail_if(6 != count_res);
505
506 /* Destroy renewable main poller */
507 ecore_poller_del(poll_ptr);
508
509 fail_if(did == EINA_FALSE);
510
511 ret = ecore_shutdown();
512 fail_if(ret != 0);
513}
514END_TEST
515
382void ecore_test_ecore(TCase *tc) 516void ecore_test_ecore(TCase *tc)
383{ 517{
384 tcase_add_test(tc, ecore_test_ecore_init); 518 tcase_add_test(tc, ecore_test_ecore_init);
@@ -392,4 +526,6 @@ void ecore_test_ecore(TCase *tc)
392 tcase_add_test(tc, ecore_test_ecore_main_loop_timer_inner); 526 tcase_add_test(tc, ecore_test_ecore_main_loop_timer_inner);
393 tcase_add_test(tc, ecore_test_ecore_main_loop_event_recursive); 527 tcase_add_test(tc, ecore_test_ecore_main_loop_event_recursive);
394 tcase_add_test(tc, ecore_test_ecore_app); 528 tcase_add_test(tc, ecore_test_ecore_app);
529 tcase_add_test(tc, ecore_test_ecore_main_loop_poller);
530 tcase_add_test(tc, ecore_test_ecore_main_loop_poller_add_del);
395} 531}