awtk/tests/widget_animator_factory_test.cc

316 lines
9.4 KiB
C++
Raw Normal View History

2018-10-22 07:38:18 +08:00
#include "gtest/gtest.h"
2018-11-05 17:32:23 +08:00
#include "base/image.h"
2018-10-22 07:38:18 +08:00
#include "base/button.h"
2018-11-05 17:32:23 +08:00
#include "base/progress_bar.h"
2018-10-22 07:38:18 +08:00
#include "base/widget_animator_factory.h"
#include "widget_animators/widget_animator_move.h"
#include "widget_animators/widget_animator_scale.h"
#include "widget_animators/widget_animator_value.h"
#include "widget_animators/widget_animator_opacity.h"
#include "widget_animators/widget_animator_rotation.h"
2018-11-05 17:32:23 +08:00
#include <string>
using std::string;
2018-10-22 07:38:18 +08:00
TEST(WidgetAnimatorFactory, opacity) {
widget_t* b = button_create(NULL, 10, 20, 100, 30);
widget_animator_t* wa = widget_animator_create(
b, "opacity(from=1, to=200, yoyo_times=1000, duration=2000, delay=1234)");
widget_animator_opacity_t* opacity = (widget_animator_opacity_t*)wa;
ASSERT_EQ(wa != NULL, true);
ASSERT_EQ(wa->delay, 1234);
ASSERT_EQ(wa->yoyo_times, 1000);
ASSERT_EQ(wa->duration, 2000);
ASSERT_EQ(opacity->from, 1);
ASSERT_EQ(opacity->to, 200);
widget_animator_destroy(wa);
widget_destroy(b);
}
2018-11-05 17:32:23 +08:00
TEST(WidgetAnimatorFactory, opacity_default) {
widget_t* b = button_create(NULL, 10, 20, 100, 30);
b->opacity = 200;
widget_animator_t* wa = widget_animator_create(b, "opacity(from=12)");
widget_animator_opacity_t* opacity = (widget_animator_opacity_t*)wa;
ASSERT_EQ(opacity->from, 12);
ASSERT_EQ(opacity->to, 200);
widget_animator_destroy(wa);
b->opacity = 200;
wa = widget_animator_create(b, "opacity(to=12)");
opacity = (widget_animator_opacity_t*)wa;
ASSERT_EQ(opacity->from, 200);
ASSERT_EQ(opacity->to, 12);
widget_animator_destroy(wa);
widget_destroy(b);
}
2018-10-22 07:38:18 +08:00
TEST(WidgetAnimatorFactory, rotation) {
widget_t* b = button_create(NULL, 10, 20, 100, 30);
widget_animator_t* wa = widget_animator_create(
b, "rotation(from=1, to=200, yoyo_times=1000, duration=2000, delay=1234)");
widget_animator_rotation_t* rotation = (widget_animator_rotation_t*)wa;
ASSERT_EQ(wa != NULL, true);
ASSERT_EQ(wa->delay, 1234);
ASSERT_EQ(wa->yoyo_times, 1000);
ASSERT_EQ(wa->duration, 2000);
ASSERT_EQ(rotation->from, 1);
ASSERT_EQ(rotation->to, 200);
widget_animator_destroy(wa);
widget_destroy(b);
}
2018-11-05 17:32:23 +08:00
TEST(WidgetAnimatorFactory, rotation_default) {
value_t v;
2018-10-22 07:38:18 +08:00
widget_t* b = button_create(NULL, 10, 20, 100, 30);
2018-11-05 17:32:23 +08:00
value_set_float(&v, 200);
widget_set_prop(b, WIDGET_PROP_ROTATION, &v);
widget_animator_t* wa = widget_animator_create(b, "rotation(from=1)");
widget_animator_rotation_t* rotation = (widget_animator_rotation_t*)wa;
ASSERT_EQ(rotation->from, 1);
ASSERT_EQ(rotation->to, 200);
widget_animator_destroy(wa);
wa = widget_animator_create(b, "rotation(to=1)");
rotation = (widget_animator_rotation_t*)wa;
ASSERT_EQ(rotation->to, 1);
ASSERT_EQ(rotation->from, 200);
widget_animator_destroy(wa);
widget_destroy(b);
}
TEST(WidgetAnimatorFactory, value) {
widget_t* b = progress_bar_create(NULL, 10, 20, 100, 30);
2018-10-22 07:38:18 +08:00
widget_animator_t* wa = widget_animator_create(
b, "value(from=1, to=200, yoyo_times=1000, duration=2000, delay=1234)");
widget_animator_value_t* value = (widget_animator_value_t*)wa;
ASSERT_EQ(wa != NULL, true);
ASSERT_EQ(wa->delay, 1234);
ASSERT_EQ(wa->yoyo_times, 1000);
ASSERT_EQ(wa->duration, 2000);
ASSERT_EQ(value->from, 1);
ASSERT_EQ(value->to, 200);
widget_animator_destroy(wa);
widget_destroy(b);
}
2018-11-05 17:32:23 +08:00
TEST(WidgetAnimatorFactory, value_default) {
widget_t* b = progress_bar_create(NULL, 10, 20, 100, 30);
widget_set_value(b, 20);
widget_animator_t* wa = widget_animator_create(b, "value(from=10)");
widget_animator_value_t* value = (widget_animator_value_t*)wa;
ASSERT_EQ(value->from, 10);
ASSERT_EQ(value->to, 20);
widget_animator_destroy(wa);
wa = widget_animator_create(b, "value(to=10)");
value = (widget_animator_value_t*)wa;
ASSERT_EQ(value->from, 20);
ASSERT_EQ(value->to, 10);
widget_animator_destroy(wa);
widget_destroy(b);
}
2018-10-22 07:38:18 +08:00
TEST(WidgetAnimatorFactory, move) {
widget_t* b = button_create(NULL, 10, 20, 100, 30);
widget_animator_t* wa = widget_animator_create(
b, "move(x_from=1, x_to=200, yoyo_times=1000, duration=2000, delay=1234)");
widget_animator_move_t* move = (widget_animator_move_t*)wa;
ASSERT_EQ(wa != NULL, true);
ASSERT_EQ(wa->delay, 1234);
ASSERT_EQ(wa->yoyo_times, 1000);
ASSERT_EQ(wa->duration, 2000);
ASSERT_EQ(move->x_from, 1);
ASSERT_EQ(move->x_to, 200);
ASSERT_EQ(move->y_from, b->y);
ASSERT_EQ(move->y_to, b->y);
widget_animator_destroy(wa);
widget_destroy(b);
}
2018-11-05 17:32:23 +08:00
TEST(WidgetAnimatorFactory, move_default) {
widget_t* b = button_create(NULL, 10, 20, 100, 30);
widget_animator_t* wa = widget_animator_create(b, "move(x_from=1, x_to=200)");
widget_animator_move_t* move = (widget_animator_move_t*)wa;
ASSERT_EQ(move->x_from, 1);
ASSERT_EQ(move->x_to, 200);
ASSERT_EQ(move->y_from, b->y);
ASSERT_EQ(move->y_to, b->y);
widget_animator_destroy(wa);
wa = widget_animator_create(b, "move(y_from=1, y_to=200)");
move = (widget_animator_move_t*)wa;
ASSERT_EQ(move->y_from, 1);
ASSERT_EQ(move->y_to, 200);
ASSERT_EQ(move->x_from, b->x);
ASSERT_EQ(move->x_to, b->x);
widget_animator_destroy(wa);
widget_destroy(b);
}
2018-10-22 07:38:18 +08:00
TEST(WidgetAnimatorFactory, scale) {
widget_t* b = button_create(NULL, 10, 20, 100, 30);
widget_animator_t* wa = widget_animator_create(
2018-11-05 17:32:23 +08:00
b, "scale(x_from=1, x_to=-1, repeat_times=1000, duration=2000, delay=1234)");
2018-10-22 07:38:18 +08:00
widget_animator_scale_t* scale = (widget_animator_scale_t*)wa;
ASSERT_EQ(wa != NULL, true);
ASSERT_EQ(wa->delay, 1234);
ASSERT_EQ(wa->repeat_times, 1000);
ASSERT_EQ(wa->duration, 2000);
ASSERT_EQ(scale->x_from, 1);
2018-11-05 17:32:23 +08:00
ASSERT_EQ(scale->x_to, -1);
2018-10-22 07:38:18 +08:00
ASSERT_EQ(scale->y_from, 1);
ASSERT_EQ(scale->y_to, 1);
2018-10-23 15:08:08 +08:00
ASSERT_EQ(wa->forever, FALSE);
widget_animator_destroy(wa);
widget_destroy(b);
}
2018-11-05 17:32:23 +08:00
TEST(WidgetAnimatorFactory, scale_default) {
widget_t* b = image_create(NULL, 10, 20, 100, 30);
image_set_scale(b, 2, 4);
widget_animator_t* wa = widget_animator_create(b, "scale(x_from=1, x_to=200)");
widget_animator_scale_t* scale = (widget_animator_scale_t*)wa;
ASSERT_EQ(scale->x_from, 1);
ASSERT_EQ(scale->x_to, 200);
ASSERT_EQ(scale->y_from, 4);
ASSERT_EQ(scale->y_to, 4);
widget_animator_destroy(wa);
wa = widget_animator_create(b, "scale(y_from=1, y_to=200)");
scale = (widget_animator_scale_t*)wa;
ASSERT_EQ(scale->y_from, 1);
ASSERT_EQ(scale->y_to, 200);
ASSERT_EQ(scale->x_from, 2);
ASSERT_EQ(scale->x_to, 2);
widget_animator_destroy(wa);
widget_destroy(b);
}
2018-10-23 15:08:08 +08:00
TEST(WidgetAnimatorFactory, yoyo_forever) {
widget_t* b = button_create(NULL, 10, 20, 100, 30);
widget_animator_t* wa = widget_animator_create(
b, "scale(x_from=1, x_to=200, yoyo_times=0, duration=2000, delay=1234)");
ASSERT_EQ(wa != NULL, true);
ASSERT_EQ(wa->yoyo_times, TK_UINT32_MAX);
ASSERT_EQ(wa->forever, TRUE);
widget_animator_destroy(wa);
widget_destroy(b);
}
TEST(WidgetAnimatorFactory, repeat_forever) {
widget_t* b = button_create(NULL, 10, 20, 100, 30);
widget_animator_t* wa = widget_animator_create(
b, "scale(x_from=1, x_to=200, repeat_times=0, duration=2000, delay=1234)");
ASSERT_EQ(wa != NULL, true);
ASSERT_EQ(wa->repeat_times, TK_UINT32_MAX);
ASSERT_EQ(wa->forever, TRUE);
2018-10-22 07:38:18 +08:00
widget_animator_destroy(wa);
widget_destroy(b);
}
2018-11-05 17:32:23 +08:00
TEST(WidgetAnimatorFactory, auto_start) {
widget_t* b = button_create(NULL, 10, 20, 100, 30);
widget_animator_t* wa =
widget_animator_create(b, "scale(x_from=1, x_to=200, repeat_times=0, duration=2000)");
ASSERT_EQ(wa->state, ANIMATOR_RUNNING);
widget_animator_destroy(wa);
wa = widget_animator_create(
b, "scale(x_from=1, x_to=200, repeat_times=0, duration=2000, auto_start=false)");
ASSERT_EQ(wa->state, ANIMATOR_CREATED);
widget_animator_destroy(wa);
wa = widget_animator_create(
b, "scale(x_from=1, x_to=200, repeat_times=0, duration=2000, auto_start=true)");
ASSERT_EQ(wa->state, ANIMATOR_RUNNING);
widget_animator_destroy(wa);
widget_destroy(b);
}
TEST(WidgetAnimatorFactory, auto_destroy) {
widget_t* b = button_create(NULL, 10, 20, 100, 30);
widget_animator_t* wa =
widget_animator_create(b, "scale(x_from=1, x_to=200, repeat_times=0, duration=2000)");
ASSERT_EQ(wa->destroy_when_done, TRUE);
widget_animator_destroy(wa);
wa = widget_animator_create(
b, "scale(x_from=1, x_to=200, repeat_times=0, duration=2000, auto_destroy=false)");
ASSERT_EQ(wa->destroy_when_done, FALSE);
widget_animator_destroy(wa);
wa = widget_animator_create(
b, "scale(x_from=1, x_to=200, repeat_times=0, duration=2000, auto_destroy=true)");
ASSERT_EQ(wa->destroy_when_done, TRUE);
widget_animator_destroy(wa);
widget_destroy(b);
}
TEST(WidgetAnimatorFactory, name) {
widget_t* b = button_create(NULL, 10, 20, 100, 30);
widget_animator_t* wa =
widget_animator_create(b, "scale(x_from=1, x_to=200, repeat_times=0, duration=2000)");
ASSERT_EQ(string(wa->name), string("scale"));
widget_animator_destroy(wa);
wa = widget_animator_create(
b, "scale(name=scale_1_200 x_from=1, x_to=200, repeat_times=0, duration=2000)");
ASSERT_EQ(string(wa->name), string("scale_1_200"));
widget_destroy(b);
}
TEST(WidgetAnimatorFactory, time_scale) {
widget_t* b = button_create(NULL, 10, 20, 100, 30);
widget_animator_t* wa =
widget_animator_create(b, "scale(x_from=1, x_to=200, repeat_times=0, duration=2000)");
ASSERT_EQ(wa->time_scale, 1);
widget_animator_destroy(wa);
wa = widget_animator_create(
b, "scale(time_scale=1.5 x_from=1, x_to=200, repeat_times=0, duration=2000)");
ASSERT_EQ(wa->time_scale, 1.5);
widget_destroy(b);
}