forked from enlightenment/efl
tests/ecore: Add test for ecore_animator
Signed-off-by: Daniel Willmann <d.willmann@samsung.com>
This commit is contained in:
parent
5f1614e1d5
commit
62325dd693
|
@ -73,6 +73,7 @@ tests/ecore/ecore_test_ecore_imf.c \
|
|||
tests/ecore/ecore_test_coroutine.c \
|
||||
tests/ecore/ecore_test_timer.c \
|
||||
tests/ecore/ecore_test_ecore_evas.c \
|
||||
tests/ecore/ecore_test_animator.c \
|
||||
tests/ecore/ecore_suite.h
|
||||
|
||||
tests_ecore_ecore_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
|
||||
|
|
|
@ -28,6 +28,7 @@ static const Ecore_Test_Case etc[] = {
|
|||
{ "Ecore_Coroutine", ecore_test_coroutine },
|
||||
{ "Ecore_Timers", ecore_test_timer },
|
||||
{ "Ecore_Evas", ecore_test_ecore_evas },
|
||||
{ "Ecore_Animators", ecore_test_animator },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
|
|
@ -11,5 +11,6 @@ void ecore_test_ecore_audio(TCase *tc);
|
|||
void ecore_test_coroutine(TCase *tc);
|
||||
void ecore_test_timer(TCase *tc);
|
||||
void ecore_test_ecore_evas(TCase *tc);
|
||||
void ecore_test_animator(TCase *tc);
|
||||
|
||||
#endif /* _ECORE_SUITE_H */
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <Ecore.h>
|
||||
|
||||
#include "ecore_suite.h"
|
||||
#include <math.h>
|
||||
|
||||
static double prev = 0;
|
||||
static Eina_Bool _anim_cb(void *data, double pos)
|
||||
{
|
||||
double interval = *(double *)data;
|
||||
|
||||
/* Make sure the intervals are within tolerances
|
||||
* Ignore first and last step */
|
||||
if (prev != 0 && pos != 1.0) {
|
||||
fail_if(pos-prev > interval*1.1);
|
||||
fail_if(pos-prev < interval*0.9);
|
||||
}
|
||||
|
||||
prev = pos;
|
||||
|
||||
if (pos == 1.0)
|
||||
ecore_main_loop_quit();
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
START_TEST(ecore_test_animators)
|
||||
{
|
||||
Eo *animator;
|
||||
double interval1 = 0.02;
|
||||
double interval2 = 0.01;
|
||||
|
||||
fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n");
|
||||
|
||||
ecore_animator_frametime_set(interval1);
|
||||
animator = eo_add_custom(ECORE_ANIMATOR_CLASS, NULL, ecore_animator_timeline_constructor(1, _anim_cb, &interval1));
|
||||
|
||||
fail_if(!animator);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
ecore_animator_frametime_set(interval2);
|
||||
prev = 0;
|
||||
animator = eo_add_custom(ECORE_ANIMATOR_CLASS, NULL, ecore_animator_timeline_constructor(1, _anim_cb, &interval2));
|
||||
fail_if(!animator);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
ecore_shutdown();
|
||||
|
||||
}
|
||||
END_TEST
|
||||
|
||||
Eina_Bool test_pos(Ecore_Pos_Map posmap, double v1, double v2, double (*testmap)(double val, double v1, double v2))
|
||||
{
|
||||
double pos;
|
||||
double res1;
|
||||
double res2;
|
||||
|
||||
for (pos = 0.0; pos < 1.01; pos += 0.01) {
|
||||
res1 = ecore_animator_pos_map(pos, posmap, v1, v2);
|
||||
res2 = testmap(pos, v1, v2);
|
||||
|
||||
if (fabs(res1-res2) > 0.005) {
|
||||
printf("(%f): %f != %f\n", pos, res1, res2);
|
||||
return EINA_FALSE;
|
||||
}
|
||||
}
|
||||
fail_if(ecore_animator_pos_map(1.0, posmap, v1, v2) != 1.0);
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
double _linear(double val, double v1, double v2)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
double _accel(double val, double v1, double v2)
|
||||
{
|
||||
return 1 - sin(M_PI_2 + val * M_PI_2);
|
||||
}
|
||||
|
||||
double _decel(double val, double v1, double v2)
|
||||
{
|
||||
return sin(val * M_PI_2);
|
||||
}
|
||||
|
||||
double _sinusoidal(double val, double v1, double v2)
|
||||
{
|
||||
return (1 - cos(val * M_PI)) / 2;
|
||||
}
|
||||
|
||||
START_TEST(ecore_test_pos_map)
|
||||
{
|
||||
fail_if(!test_pos(ECORE_POS_MAP_LINEAR, 0, 0, _linear));
|
||||
fail_if(!test_pos(ECORE_POS_MAP_ACCELERATE, 0, 0, _accel));
|
||||
fail_if(!test_pos(ECORE_POS_MAP_DECELERATE, 0, 0, _decel));
|
||||
fail_if(!test_pos(ECORE_POS_MAP_SINUSOIDAL, 0, 0, _sinusoidal));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void ecore_test_animator(TCase *tc)
|
||||
{
|
||||
tcase_add_test(tc, ecore_test_animators);
|
||||
tcase_add_test(tc, ecore_test_pos_map);
|
||||
}
|
Loading…
Reference in New Issue