summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Willmann <d.willmann@samsung.com>2013-05-16 18:07:56 +0100
committerDaniel Willmann <d.willmann@samsung.com>2013-05-17 17:15:27 +0100
commit62325dd693a82c4f10d7d5c46a65b1f4b75df22c (patch)
tree636b5b9c5c9bae4b129e1f2d093ef787956752e3 /src
parent5f1614e1d504d8b9ffe4509528791ef1009a730b (diff)
tests/ecore: Add test for ecore_animator
Signed-off-by: Daniel Willmann <d.willmann@samsung.com>
Diffstat (limited to 'src')
-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_animator.c110
4 files changed, 113 insertions, 0 deletions
diff --git a/src/Makefile_Ecore.am b/src/Makefile_Ecore.am
index c3728ba33e..40329a06c3 100644
--- a/src/Makefile_Ecore.am
+++ b/src/Makefile_Ecore.am
@@ -73,6 +73,7 @@ tests/ecore/ecore_test_ecore_imf.c \
73tests/ecore/ecore_test_coroutine.c \ 73tests/ecore/ecore_test_coroutine.c \
74tests/ecore/ecore_test_timer.c \ 74tests/ecore/ecore_test_timer.c \
75tests/ecore/ecore_test_ecore_evas.c \ 75tests/ecore/ecore_test_ecore_evas.c \
76tests/ecore/ecore_test_animator.c \
76tests/ecore/ecore_suite.h 77tests/ecore/ecore_suite.h
77 78
78tests_ecore_ecore_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ 79tests_ecore_ecore_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
diff --git a/src/tests/ecore/ecore_suite.c b/src/tests/ecore/ecore_suite.c
index d8b28e4bf8..e9e737069a 100644
--- a/src/tests/ecore/ecore_suite.c
+++ b/src/tests/ecore/ecore_suite.c
@@ -28,6 +28,7 @@ static const Ecore_Test_Case etc[] = {
28 { "Ecore_Coroutine", ecore_test_coroutine }, 28 { "Ecore_Coroutine", ecore_test_coroutine },
29 { "Ecore_Timers", ecore_test_timer }, 29 { "Ecore_Timers", ecore_test_timer },
30 { "Ecore_Evas", ecore_test_ecore_evas }, 30 { "Ecore_Evas", ecore_test_ecore_evas },
31 { "Ecore_Animators", ecore_test_animator },
31 { NULL, NULL } 32 { NULL, NULL }
32}; 33};
33 34
diff --git a/src/tests/ecore/ecore_suite.h b/src/tests/ecore/ecore_suite.h
index 9fd306b96a..03f13ef440 100644
--- a/src/tests/ecore/ecore_suite.h
+++ b/src/tests/ecore/ecore_suite.h
@@ -11,5 +11,6 @@ void ecore_test_ecore_audio(TCase *tc);
11void ecore_test_coroutine(TCase *tc); 11void ecore_test_coroutine(TCase *tc);
12void ecore_test_timer(TCase *tc); 12void ecore_test_timer(TCase *tc);
13void ecore_test_ecore_evas(TCase *tc); 13void ecore_test_ecore_evas(TCase *tc);
14void ecore_test_animator(TCase *tc);
14 15
15#endif /* _ECORE_SUITE_H */ 16#endif /* _ECORE_SUITE_H */
diff --git a/src/tests/ecore/ecore_test_animator.c b/src/tests/ecore/ecore_test_animator.c
new file mode 100644
index 0000000000..4f291b794a
--- /dev/null
+++ b/src/tests/ecore/ecore_test_animator.c
@@ -0,0 +1,110 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <Ecore.h>
6
7#include "ecore_suite.h"
8#include <math.h>
9
10static double prev = 0;
11static Eina_Bool _anim_cb(void *data, double pos)
12{
13 double interval = *(double *)data;
14
15 /* Make sure the intervals are within tolerances
16 * Ignore first and last step */
17 if (prev != 0 && pos != 1.0) {
18 fail_if(pos-prev > interval*1.1);
19 fail_if(pos-prev < interval*0.9);
20 }
21
22 prev = pos;
23
24 if (pos == 1.0)
25 ecore_main_loop_quit();
26
27 return EINA_TRUE;
28}
29
30START_TEST(ecore_test_animators)
31{
32 Eo *animator;
33 double interval1 = 0.02;
34 double interval2 = 0.01;
35
36 fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n");
37
38 ecore_animator_frametime_set(interval1);
39 animator = eo_add_custom(ECORE_ANIMATOR_CLASS, NULL, ecore_animator_timeline_constructor(1, _anim_cb, &interval1));
40
41 fail_if(!animator);
42
43 ecore_main_loop_begin();
44
45 ecore_animator_frametime_set(interval2);
46 prev = 0;
47 animator = eo_add_custom(ECORE_ANIMATOR_CLASS, NULL, ecore_animator_timeline_constructor(1, _anim_cb, &interval2));
48 fail_if(!animator);
49
50 ecore_main_loop_begin();
51
52 ecore_shutdown();
53
54}
55END_TEST
56
57Eina_Bool test_pos(Ecore_Pos_Map posmap, double v1, double v2, double (*testmap)(double val, double v1, double v2))
58{
59 double pos;
60 double res1;
61 double res2;
62
63 for (pos = 0.0; pos < 1.01; pos += 0.01) {
64 res1 = ecore_animator_pos_map(pos, posmap, v1, v2);
65 res2 = testmap(pos, v1, v2);
66
67 if (fabs(res1-res2) > 0.005) {
68 printf("(%f): %f != %f\n", pos, res1, res2);
69 return EINA_FALSE;
70 }
71 }
72 fail_if(ecore_animator_pos_map(1.0, posmap, v1, v2) != 1.0);
73
74 return EINA_TRUE;
75}
76
77double _linear(double val, double v1, double v2)
78{
79 return val;
80}
81
82double _accel(double val, double v1, double v2)
83{
84 return 1 - sin(M_PI_2 + val * M_PI_2);
85}
86
87double _decel(double val, double v1, double v2)
88{
89 return sin(val * M_PI_2);
90}
91
92double _sinusoidal(double val, double v1, double v2)
93{
94 return (1 - cos(val * M_PI)) / 2;
95}
96
97START_TEST(ecore_test_pos_map)
98{
99 fail_if(!test_pos(ECORE_POS_MAP_LINEAR, 0, 0, _linear));
100 fail_if(!test_pos(ECORE_POS_MAP_ACCELERATE, 0, 0, _accel));
101 fail_if(!test_pos(ECORE_POS_MAP_DECELERATE, 0, 0, _decel));
102 fail_if(!test_pos(ECORE_POS_MAP_SINUSOIDAL, 0, 0, _sinusoidal));
103}
104END_TEST
105
106void ecore_test_animator(TCase *tc)
107{
108 tcase_add_test(tc, ecore_test_animators);
109 tcase_add_test(tc, ecore_test_pos_map);
110}