summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2018-04-09 13:37:02 +0200
committerStefan Schmidt <stefan@osg.samsung.com>2018-04-10 11:28:01 +0200
commit1bd52cc1167fc6ce83a845b0d6393e3a9ae60b90 (patch)
tree22de6dd39bddd445b60186a26233b922d7e55515
parent88a6a3c76908d10d83c0f24e04ef2614fa4e94c2 (diff)
tests: split ecore poller tests into separate file
Summary: ref T6850 Depends on D5900 Reviewers: stefan_schmidt Subscribers: cedric Maniphest Tasks: T6850 Differential Revision: https://phab.enlightenment.org/D5901
-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_ecore.c144
-rw-r--r--src/tests/ecore/ecore_test_poller.c168
5 files changed, 171 insertions, 144 deletions
diff --git a/src/Makefile_Ecore.am b/src/Makefile_Ecore.am
index 2fb22318cd..2c6221dfca 100644
--- a/src/Makefile_Ecore.am
+++ b/src/Makefile_Ecore.am
@@ -277,6 +277,7 @@ tests/ecore/ecore_suite.c \
277tests/ecore/ecore_test_ecore.c \ 277tests/ecore/ecore_test_ecore.c \
278tests/ecore/ecore_test_ecore_imf.c \ 278tests/ecore/ecore_test_ecore_imf.c \
279tests/ecore/ecore_test_idle.c \ 279tests/ecore/ecore_test_idle.c \
280tests/ecore/ecore_test_poller.c \
280tests/ecore/ecore_test_timer.c \ 281tests/ecore/ecore_test_timer.c \
281tests/ecore/ecore_test_ecore_evas.c \ 282tests/ecore/ecore_test_ecore_evas.c \
282tests/ecore/ecore_test_animator.c \ 283tests/ecore/ecore_test_animator.c \
diff --git a/src/tests/ecore/ecore_suite.c b/src/tests/ecore/ecore_suite.c
index a418a7cce7..04314e1922 100644
--- a/src/tests/ecore/ecore_suite.c
+++ b/src/tests/ecore/ecore_suite.c
@@ -9,6 +9,7 @@
9static const Efl_Test_Case etc[] = { 9static const Efl_Test_Case etc[] = {
10 { "Ecore", ecore_test_ecore }, 10 { "Ecore", ecore_test_ecore },
11 { "idle", ecore_test_ecore_idle }, 11 { "idle", ecore_test_ecore_idle },
12 { "poller", ecore_test_ecore_idle },
12#if HAVE_ECORE_X 13#if HAVE_ECORE_X
13 { "Ecore_X", ecore_test_ecore_x }, 14 { "Ecore_X", ecore_test_ecore_x },
14#endif 15#endif
diff --git a/src/tests/ecore/ecore_suite.h b/src/tests/ecore/ecore_suite.h
index 3416e395c2..5917a43a0c 100644
--- a/src/tests/ecore/ecore_suite.h
+++ b/src/tests/ecore/ecore_suite.h
@@ -5,6 +5,7 @@
5#include "../efl_check.h" 5#include "../efl_check.h"
6void ecore_test_ecore(TCase *tc); 6void ecore_test_ecore(TCase *tc);
7void ecore_test_ecore_idle(TCase *tc); 7void ecore_test_ecore_idle(TCase *tc);
8void ecore_test_ecore_poller(TCase *tc);
8void ecore_test_ecore_x(TCase *tc); 9void ecore_test_ecore_x(TCase *tc);
9void ecore_test_ecore_imf(TCase *tc); 10void ecore_test_ecore_imf(TCase *tc);
10void ecore_test_ecore_audio(TCase *tc); 11void ecore_test_ecore_audio(TCase *tc);
diff --git a/src/tests/ecore/ecore_test_ecore.c b/src/tests/ecore/ecore_test_ecore.c
index 0314eebc6e..8159e22fb4 100644
--- a/src/tests/ecore/ecore_test_ecore.c
+++ b/src/tests/ecore/ecore_test_ecore.c
@@ -10,9 +10,6 @@
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
16#define ECORE_EVENT_CUSTOM_1 1 13#define ECORE_EVENT_CUSTOM_1 1
17#define ECORE_EVENT_CUSTOM_2 2 14#define ECORE_EVENT_CUSTOM_2 2
18 15
@@ -471,143 +468,6 @@ EFL_START_TEST(ecore_test_ecore_app)
471} 468}
472EFL_END_TEST 469EFL_END_TEST
473 470
474Eina_Bool _poller_cb(void *data)
475{
476 int *val = data;
477 (*val)++;
478 return ECORE_CALLBACK_RENEW;
479}
480
481EFL_START_TEST(ecore_test_ecore_main_loop_poller)
482{
483 Ecore_Poller *poll1_ptr = NULL;
484 int poll1_interval = 1;
485 int poll1_counter = 0;
486
487 Ecore_Poller *poll2_ptr = NULL;
488 int poll2_interval = 2;
489 int poll2_counter = 0;
490
491 Ecore_Poller *poll3_ptr = NULL;
492 int poll3_interval = 4;
493 int poll3_counter = 0;
494
495 Eina_Bool did = EINA_FALSE;
496
497 /* Check ECORE_POLLER_CORE poll interval */
498 double interval = 0.05;
499 ecore_poller_poll_interval_set(ECORE_POLLER_CORE, interval);
500 fail_unless(CHECK_FP(ecore_poller_poll_interval_get(ECORE_POLLER_CORE), interval));
501
502 /* Create three pollers with different poller interval */
503 poll1_ptr = ecore_poller_add(ECORE_POLLER_CORE, poll1_interval, _poller_cb, &poll1_counter);
504 poll2_ptr = ecore_poller_add(ECORE_POLLER_CORE, poll2_interval, _poller_cb, &poll2_counter);
505 poll3_ptr = ecore_poller_add(ECORE_POLLER_CORE, poll3_interval, _poller_cb, &poll3_counter);
506
507 /* Add one time processed quit poller */
508 ecore_poller_add(ECORE_POLLER_CORE, 8, _quit_cb, &did);
509
510 /* Enter main loop and wait 8 intervals for quit */
511 ecore_main_loop_begin();
512
513 /* Check each poller poll interval */
514 fail_if(ecore_poller_poller_interval_get(poll1_ptr) != poll1_interval);
515 fail_if(ecore_poller_poller_interval_get(poll2_ptr) != poll2_interval);
516 fail_if(ecore_poller_poller_interval_get(poll3_ptr) != poll3_interval);
517
518 /* Check each poller call counter */
519 ck_assert_int_eq(8, poll1_counter);
520 ck_assert_int_eq(4, poll2_counter);
521 ck_assert_int_eq(2, poll3_counter);
522
523 /* Destroy renewable pollers */
524 ecore_poller_del(poll3_ptr);
525 ecore_poller_del(poll2_ptr);
526 ecore_poller_del(poll1_ptr);
527
528 fail_if(did == EINA_FALSE);
529
530}
531EFL_END_TEST
532
533Eina_Bool _poller_handler(void *data)
534{
535 int *val = data;
536 (*val)++;
537 return ECORE_CALLBACK_RENEW;
538}
539
540static Eina_Bool
541_poller_loop_add(void *data EINA_UNUSED)
542{
543 ecore_poller_add(ECORE_POLLER_CORE, 1, _quit_cb, NULL);
544 return ECORE_CALLBACK_RENEW;
545}
546
547static Eina_Bool
548_poller_loop_fail(void *data EINA_UNUSED)
549{
550 ecore_main_loop_quit();
551 ck_abort();
552 return ECORE_CALLBACK_RENEW;
553}
554
555static Eina_Bool
556_poller_loop_del(void *data)
557{
558 static int count = 0;
559
560 if (count++ == 0)
561 ecore_poller_del(data);
562 else
563 ecore_main_loop_quit();
564 return ECORE_CALLBACK_RENEW;
565}
566
567static Eina_Bool
568_poller_loop_modify(void *data)
569{
570 ecore_poller_poller_interval_set(data, 1);
571 return EINA_FALSE;
572}
573
574EFL_START_TEST(ecore_test_ecore_main_loop_poller_add)
575{
576 /* Create renewable main poller */
577 Ecore_Poller *poll_ptr = ecore_poller_add(ECORE_POLLER_CORE, 1, _poller_loop_add, NULL);
578
579 /* Enter main loop and wait for quit*/
580 ecore_main_loop_begin();
581
582 /* Destroy renewable main poller */
583 ecore_poller_del(poll_ptr);
584}
585EFL_END_TEST
586
587
588EFL_START_TEST(ecore_test_ecore_main_loop_poller_del)
589{
590 /* Create renewable main poller */
591 Ecore_Poller *poller = ecore_poller_add(ECORE_POLLER_CORE, 2, _poller_loop_fail, NULL);
592 ecore_poller_add(ECORE_POLLER_CORE, 1, _poller_loop_del, poller);
593
594 /* Enter main loop and wait for quit*/
595 ecore_main_loop_begin();
596}
597EFL_END_TEST
598
599EFL_START_TEST(ecore_test_ecore_main_loop_poller_modify)
600{
601 /* Create renewable main poller */
602 Ecore_Poller *poller = ecore_poller_add(ECORE_POLLER_CORE, 4, _quit_cb, NULL);
603 ecore_poller_add(ECORE_POLLER_CORE, 1, _poller_loop_modify, poller);
604 ecore_poller_add(ECORE_POLLER_CORE, 4, _poller_loop_fail, NULL);
605
606 /* Enter main loop and wait for quit*/
607 ecore_main_loop_begin();
608}
609EFL_END_TEST
610
611void ecore_test_ecore(TCase *tc) 471void ecore_test_ecore(TCase *tc)
612{ 472{
613 tcase_add_test(tc, ecore_test_ecore_init); 473 tcase_add_test(tc, ecore_test_ecore_init);
@@ -621,8 +481,4 @@ void ecore_test_ecore(TCase *tc)
621 tcase_add_test(tc, ecore_test_ecore_main_loop_event_recursive); 481 tcase_add_test(tc, ecore_test_ecore_main_loop_event_recursive);
622#endif 482#endif
623 tcase_add_test(tc, ecore_test_ecore_app); 483 tcase_add_test(tc, ecore_test_ecore_app);
624 tcase_add_test(tc, ecore_test_ecore_main_loop_poller);
625 tcase_add_test(tc, ecore_test_ecore_main_loop_poller_add);
626 tcase_add_test(tc, ecore_test_ecore_main_loop_poller_del);
627 tcase_add_test(tc, ecore_test_ecore_main_loop_poller_modify);
628} 484}
diff --git a/src/tests/ecore/ecore_test_poller.c b/src/tests/ecore/ecore_test_poller.c
new file mode 100644
index 0000000000..9e981ff367
--- /dev/null
+++ b/src/tests/ecore/ecore_test_poller.c
@@ -0,0 +1,168 @@
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
13#define FP_ERR (0.0000001)
14#define CHECK_FP(a, b) ((a - b) < FP_ERR)
15
16static Eina_Bool
17_quit_cb(void *data)
18{
19 Eina_Bool *val = data;
20 if (val) *val = EINA_TRUE;
21 ecore_main_loop_quit();
22 return EINA_FALSE;
23}
24
25Eina_Bool _poller_handler(void *data)
26{
27 int *val = data;
28 (*val)++;
29 return ECORE_CALLBACK_RENEW;
30}
31
32static Eina_Bool
33_poller_loop_add(void *data EINA_UNUSED)
34{
35 ecore_poller_add(ECORE_POLLER_CORE, 1, _quit_cb, NULL);
36 return ECORE_CALLBACK_RENEW;
37}
38
39static Eina_Bool
40_poller_loop_fail(void *data EINA_UNUSED)
41{
42 ecore_main_loop_quit();
43 ck_abort();
44 return ECORE_CALLBACK_RENEW;
45}
46
47static Eina_Bool
48_poller_loop_del(void *data)
49{
50 static int count = 0;
51
52 if (count++ == 0)
53 ecore_poller_del(data);
54 else
55 ecore_main_loop_quit();
56 return ECORE_CALLBACK_RENEW;
57}
58
59static Eina_Bool
60_poller_loop_modify(void *data)
61{
62 ecore_poller_poller_interval_set(data, 1);
63 return EINA_FALSE;
64}
65
66EFL_START_TEST(ecore_test_ecore_main_loop_poller_add)
67{
68 /* Create renewable main poller */
69 Ecore_Poller *poll_ptr = ecore_poller_add(ECORE_POLLER_CORE, 1, _poller_loop_add, NULL);
70
71 /* Enter main loop and wait for quit*/
72 ecore_main_loop_begin();
73
74 /* Destroy renewable main poller */
75 ecore_poller_del(poll_ptr);
76}
77EFL_END_TEST
78
79
80EFL_START_TEST(ecore_test_ecore_main_loop_poller_del)
81{
82 /* Create renewable main poller */
83 Ecore_Poller *poller = ecore_poller_add(ECORE_POLLER_CORE, 2, _poller_loop_fail, NULL);
84 ecore_poller_add(ECORE_POLLER_CORE, 1, _poller_loop_del, poller);
85
86 /* Enter main loop and wait for quit*/
87 ecore_main_loop_begin();
88}
89EFL_END_TEST
90
91EFL_START_TEST(ecore_test_ecore_main_loop_poller_modify)
92{
93 /* Create renewable main poller */
94 Ecore_Poller *poller = ecore_poller_add(ECORE_POLLER_CORE, 4, _quit_cb, NULL);
95 ecore_poller_add(ECORE_POLLER_CORE, 1, _poller_loop_modify, poller);
96 ecore_poller_add(ECORE_POLLER_CORE, 4, _poller_loop_fail, NULL);
97
98 /* Enter main loop and wait for quit*/
99 ecore_main_loop_begin();
100}
101EFL_END_TEST
102
103Eina_Bool _poller_cb(void *data)
104{
105 int *val = data;
106 (*val)++;
107 return ECORE_CALLBACK_RENEW;
108}
109
110EFL_START_TEST(ecore_test_ecore_main_loop_poller)
111{
112 Ecore_Poller *poll1_ptr = NULL;
113 int poll1_interval = 1;
114 int poll1_counter = 0;
115
116 Ecore_Poller *poll2_ptr = NULL;
117 int poll2_interval = 2;
118 int poll2_counter = 0;
119
120 Ecore_Poller *poll3_ptr = NULL;
121 int poll3_interval = 4;
122 int poll3_counter = 0;
123
124 Eina_Bool did = EINA_FALSE;
125
126 /* Check ECORE_POLLER_CORE poll interval */
127 double interval = 0.05;
128 ecore_poller_poll_interval_set(ECORE_POLLER_CORE, interval);
129 fail_unless(CHECK_FP(ecore_poller_poll_interval_get(ECORE_POLLER_CORE), interval));
130
131 /* Create three pollers with different poller interval */
132 poll1_ptr = ecore_poller_add(ECORE_POLLER_CORE, poll1_interval, _poller_cb, &poll1_counter);
133 poll2_ptr = ecore_poller_add(ECORE_POLLER_CORE, poll2_interval, _poller_cb, &poll2_counter);
134 poll3_ptr = ecore_poller_add(ECORE_POLLER_CORE, poll3_interval, _poller_cb, &poll3_counter);
135
136 /* Add one time processed quit poller */
137 ecore_poller_add(ECORE_POLLER_CORE, 8, _quit_cb, &did);
138
139 /* Enter main loop and wait 8 intervals for quit */
140 ecore_main_loop_begin();
141
142 /* Check each poller poll interval */
143 fail_if(ecore_poller_poller_interval_get(poll1_ptr) != poll1_interval);
144 fail_if(ecore_poller_poller_interval_get(poll2_ptr) != poll2_interval);
145 fail_if(ecore_poller_poller_interval_get(poll3_ptr) != poll3_interval);
146
147 /* Check each poller call counter */
148 ck_assert_int_eq(8, poll1_counter);
149 ck_assert_int_eq(4, poll2_counter);
150 ck_assert_int_eq(2, poll3_counter);
151
152 /* Destroy renewable pollers */
153 ecore_poller_del(poll3_ptr);
154 ecore_poller_del(poll2_ptr);
155 ecore_poller_del(poll1_ptr);
156
157 fail_if(did == EINA_FALSE);
158
159}
160EFL_END_TEST
161
162void ecore_test_ecore_poller(TCase *tc)
163{
164 tcase_add_test(tc, ecore_test_ecore_main_loop_poller);
165 tcase_add_test(tc, ecore_test_ecore_main_loop_poller_add);
166 tcase_add_test(tc, ecore_test_ecore_main_loop_poller_del);
167 tcase_add_test(tc, ecore_test_ecore_main_loop_poller_modify);
168}