awtk/tests/scroll_bar_test.cc

107 lines
3.2 KiB
C++
Raw Normal View History

#include "scroll_view/scroll_bar.h"
#include "base/canvas.h"
#include "base/widget.h"
#include "font_dummy.h"
#include "lcd_log.h"
#include "gtest/gtest.h"
#include <stdlib.h>
2018-07-15 18:10:44 +08:00
#include <string>
#include "ui_loader/ui_serializer.h"
using std::string;
TEST(ScrollBar, basic) {
value_t v1;
value_t v2;
2018-07-15 18:10:44 +08:00
widget_t* w1 = NULL;
widget_t* w = scroll_bar_create(NULL, 10, 20, 30, 400);
value_set_int(&v1, 2000);
ASSERT_EQ(widget_set_prop(w, WIDGET_PROP_MAX, &v1), RET_OK);
ASSERT_EQ(widget_get_prop(w, WIDGET_PROP_MAX, &v2), RET_OK);
ASSERT_EQ(value_int(&v1), value_int(&v2));
2018-07-09 16:53:43 +08:00
value_set_int(&v1, 20);
ASSERT_EQ(widget_set_prop(w, WIDGET_PROP_ROW, &v1), RET_OK);
ASSERT_EQ(widget_get_prop(w, WIDGET_PROP_ROW, &v2), RET_OK);
ASSERT_EQ(value_int(&v1), value_int(&v2));
2018-07-09 16:53:43 +08:00
value_set_int(&v1, 50);
ASSERT_EQ(widget_set_prop(w, WIDGET_PROP_VALUE, &v1), RET_OK);
ASSERT_EQ(widget_get_prop(w, WIDGET_PROP_VALUE, &v2), RET_OK);
ASSERT_EQ(value_int(&v1), value_int(&v2));
2018-07-09 16:53:43 +08:00
value_set_bool(&v1, FALSE);
ASSERT_EQ(widget_set_prop(w, WIDGET_PROP_ANIMATABLE, &v1), RET_OK);
ASSERT_EQ(widget_get_prop(w, WIDGET_PROP_ANIMATABLE, &v2), RET_OK);
ASSERT_EQ(value_bool(&v1), value_bool(&v2));
2018-07-15 18:10:44 +08:00
w1 = widget_clone(w, NULL);
ASSERT_EQ(widget_equal(w, w1), TRUE);
widget_destroy(w);
widget_destroy(w1);
}
TEST(ScrollBar, to_xml) {
str_t str;
widget_t* w = scroll_bar_create(NULL, 10, 20, 30, 400);
str_init(&str, 1024);
ASSERT_EQ(widget_to_xml(w, &str), RET_OK);
2020-08-20 10:14:39 +08:00
ASSERT_EQ(string(str.str), string("<?xml version='1.0' encoding='UTF-8' standalone='yes' "
"?>\r\n<scroll_bar_d x=\"10\" y=\"20\" w=\"30\" h=\"400\" "
2019-03-20 11:41:09 +08:00
"animatable=\"true\">\n</scroll_bar_d>\n"));
2018-07-15 18:10:44 +08:00
str_reset(&str);
widget_destroy(w);
}
TEST(ScrollBar, cast) {
widget_t* w = scroll_bar_create(NULL, 10, 20, 30, 40);
ASSERT_EQ(w, scroll_bar_cast(w));
widget_destroy(w);
}
2021-06-04 17:35:48 +08:00
TEST(ScrollBar, auto_hide) {
widget_t* w = scroll_bar_create_mobile(NULL, 10, 20, 30, 40);
ASSERT_EQ(SCROLL_BAR(w)->auto_hide, TRUE);
scroll_bar_set_auto_hide(w, FALSE);
ASSERT_EQ(SCROLL_BAR(w)->auto_hide, FALSE);
ASSERT_EQ(widget_set_prop_bool(w, WIDGET_PROP_AUTO_HIDE, TRUE), RET_OK);
ASSERT_EQ(SCROLL_BAR(w)->auto_hide, TRUE);
ASSERT_EQ(widget_get_prop_bool(w, WIDGET_PROP_AUTO_HIDE, FALSE), TRUE);
widget_destroy(w);
}
2021-08-16 18:42:30 +08:00
2021-11-19 17:13:10 +08:00
TEST(ScrollBar, animator_time) {
widget_t* w = scroll_bar_create_mobile(NULL, 10, 20, 30, 40);
ASSERT_EQ(SCROLL_BAR(w)->animator_time, TK_ANIMATING_TIME);
scroll_bar_set_animator_time(w, 0);
ASSERT_EQ(SCROLL_BAR(w)->animator_time, 0);
ASSERT_EQ(widget_set_prop_int(w, SCROLL_BAR_PROP_ANIMATOR_TIME, 200), RET_OK);
ASSERT_EQ(SCROLL_BAR(w)->auto_hide, TRUE);
ASSERT_EQ(widget_get_prop_int(w, SCROLL_BAR_PROP_ANIMATOR_TIME, 0) == 200, TRUE);
widget_destroy(w);
}
2021-08-16 18:42:30 +08:00
TEST(ScrollBar, is_mobile_prop) {
widget_t* w = scroll_bar_create_mobile(NULL, 10, 20, 30, 40);
ASSERT_EQ(widget_set_prop_bool(w, SCROLL_BAR_PROP_IS_MOBILE, TRUE), RET_OK);
ASSERT_EQ(widget_get_prop_bool(w, SCROLL_BAR_PROP_IS_MOBILE, FALSE), TRUE);
2021-08-30 17:17:48 +08:00
2021-08-16 18:42:30 +08:00
ASSERT_EQ(widget_set_prop_bool(w, SCROLL_BAR_PROP_IS_MOBILE, FALSE), RET_OK);
ASSERT_EQ(widget_get_prop_bool(w, SCROLL_BAR_PROP_IS_MOBILE, TRUE), FALSE);
widget_destroy(w);
}