2018-08-24 11:20:34 +08:00
|
|
|
|
#include "scroll_view/scroll_bar.h"
|
2018-07-09 11:44:06 +08:00
|
|
|
|
#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;
|
2018-07-09 11:44:06 +08:00
|
|
|
|
|
|
|
|
|
TEST(ScrollBar, basic) {
|
|
|
|
|
value_t v1;
|
|
|
|
|
value_t v2;
|
2018-07-15 18:10:44 +08:00
|
|
|
|
widget_t* w1 = NULL;
|
2018-07-09 11:44:06 +08:00
|
|
|
|
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
|
|
|
|
|
2018-07-09 11:44:06 +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
|
|
|
|
|
2018-07-09 11:44:06 +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
|
|
|
|
|
2018-07-09 11:44:06 +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);
|
|
|
|
|
ASSERT_EQ(string(str.str), string("<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);
|
2018-07-09 11:44:06 +08:00
|
|
|
|
widget_destroy(w);
|
|
|
|
|
}
|
2019-02-26 15:17:51 +08:00
|
|
|
|
|
|
|
|
|
TEST(ScrollBar, cast) {
|
|
|
|
|
widget_t* w = scroll_bar_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(w, scroll_bar_cast(w));
|
|
|
|
|
|
|
|
|
|
widget_destroy(w);
|
|
|
|
|
}
|