awtk/tests/image_test.cc

92 lines
2.6 KiB
C++
Raw Normal View History

#include "widgets/image.h"
2018-03-26 07:36:18 +08:00
#include "gtest/gtest.h"
#include "base/canvas.h"
#include "base/font_manager.h"
#include "font_dummy.h"
#include "lcd_log.h"
TEST(Image, basic) {
value_t v;
2018-07-11 17:37:08 +08:00
value_t v1;
2018-03-26 07:36:18 +08:00
widget_t* img = image_create(NULL, 0, 0, 100, 100);
value_set_str(&v, "repeat");
2018-07-17 07:47:53 +08:00
2018-07-11 17:37:08 +08:00
ASSERT_EQ(widget_set_prop(img, WIDGET_PROP_DRAW_TYPE, &v), RET_OK);
2018-03-26 07:36:18 +08:00
ASSERT_EQ(IMAGE(img)->draw_type, IMAGE_DRAW_REPEAT);
ASSERT_EQ(image_set_draw_type(img, IMAGE_DRAW_REPEAT_X), RET_OK);
ASSERT_EQ(IMAGE(img)->draw_type, IMAGE_DRAW_REPEAT_X);
2018-07-11 17:37:08 +08:00
value_set_str(&v, "repeat_y");
ASSERT_EQ(widget_set_prop(img, WIDGET_PROP_DRAW_TYPE, &v), RET_OK);
ASSERT_EQ(IMAGE(img)->draw_type, IMAGE_DRAW_REPEAT_Y);
2018-03-26 07:36:18 +08:00
value_set_str(&v, "earth");
2018-07-11 17:37:08 +08:00
ASSERT_EQ(widget_set_prop(img, WIDGET_PROP_IMAGE, &v), RET_OK);
ASSERT_EQ(widget_get_prop(img, WIDGET_PROP_IMAGE, &v1), RET_OK);
ASSERT_EQ(strcmp(value_str(&v), value_str(&v1)), 0);
widget_destroy(img);
2018-03-26 07:36:18 +08:00
}
2018-07-18 10:36:54 +08:00
2019-02-26 11:08:46 +08:00
TEST(Image, rotation) {
2018-07-18 10:36:54 +08:00
image_t* w = IMAGE(image_create(NULL, 0, 0, 400, 300));
2018-11-22 14:58:21 +08:00
image_base_t* image_base = IMAGE_BASE(w);
ASSERT_EQ(image_base->rotation, 0);
2018-07-18 10:36:54 +08:00
ASSERT_EQ(image_set_rotation(WIDGET(w), 0.4), RET_OK);
2018-11-22 14:58:21 +08:00
ASSERT_EQ(image_base->rotation, 0.4f);
2018-07-18 10:36:54 +08:00
widget_destroy(WIDGET(w));
}
2019-02-26 11:08:46 +08:00
TEST(Image, scale) {
2018-07-18 10:36:54 +08:00
image_t* w = IMAGE(image_create(NULL, 0, 0, 400, 300));
2018-11-22 14:58:21 +08:00
image_base_t* image_base = IMAGE_BASE(w);
ASSERT_EQ(image_base->scale_x, 1.0f);
ASSERT_EQ(image_base->scale_y, 1.0f);
2018-07-18 10:36:54 +08:00
ASSERT_EQ(image_set_scale(WIDGET(w), 0.4, 4.0), RET_OK);
2018-11-22 14:58:21 +08:00
ASSERT_EQ(image_base->scale_x, 0.4f);
ASSERT_EQ(image_base->scale_y, 4.0f);
2018-07-18 10:36:54 +08:00
widget_destroy(WIDGET(w));
}
2019-02-26 11:08:46 +08:00
TEST(Image, anchor) {
2018-07-18 10:36:54 +08:00
image_t* w = IMAGE(image_create(NULL, 0, 0, 400, 300));
2018-11-22 14:58:21 +08:00
image_base_t* image_base = IMAGE_BASE(w);
ASSERT_EQ(image_base->anchor_x, 0.5f);
ASSERT_EQ(image_base->anchor_y, 0.5f);
2018-07-18 10:36:54 +08:00
ASSERT_EQ(image_set_anchor(WIDGET(w), 0.1f, 1.0f), RET_OK);
2018-11-22 14:58:21 +08:00
ASSERT_EQ(image_base->anchor_x, 0.1f);
ASSERT_EQ(image_base->anchor_y, 1.0f);
2018-07-18 10:36:54 +08:00
widget_destroy(WIDGET(w));
}
2019-02-26 11:08:46 +08:00
2019-05-13 17:53:02 +08:00
TEST(Image, animator) {
widget_t* w = (image_create(NULL, 0, 0, 400, 300));
ASSERT_EQ(widget_create_animator(w, "move(y_from=0, y_to=128)"), RET_OK);
ASSERT_EQ(widget_start_animator(w, "move"), RET_OK);
ASSERT_EQ(widget_pause_animator(w, "move"), RET_OK);
ASSERT_EQ(widget_find_animator(w, "move") != NULL, TRUE);
ASSERT_EQ(widget_destroy_animator(w, "move"), RET_OK);
ASSERT_EQ(widget_find_animator(w, "move") == NULL, TRUE);
widget_destroy((w));
}
2019-02-26 11:08:46 +08:00
TEST(Image, cast) {
widget_t* w = image_create(NULL, 0, 0, 400, 300);
ASSERT_EQ(w, image_cast(w));
ASSERT_EQ(w, image_base_cast(w));
widget_destroy(w);
}