2018-12-15 17:22:05 +08:00
|
|
|
|
#include "widgets/button.h"
|
2018-07-14 18:04:52 +08:00
|
|
|
|
#include "base/canvas.h"
|
|
|
|
|
#include "base/widget.h"
|
|
|
|
|
#include "base/layout.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include "ui_loader/ui_serializer.h"
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
TEST(UISerializer, basic) {
|
|
|
|
|
str_t str;
|
|
|
|
|
widget_t* w = button_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
|
|
|
|
|
str_init(&str, 1024);
|
2018-07-15 18:10:44 +08:00
|
|
|
|
widget_to_xml(w, &str);
|
2018-07-14 18:04:52 +08:00
|
|
|
|
|
2018-12-22 19:04:55 +08:00
|
|
|
|
ASSERT_EQ(string(str.str), "<button x=\"10\" y=\"20\" w=\"30\" h=\"40\">\n</button>\n");
|
2018-07-14 18:04:52 +08:00
|
|
|
|
|
2018-08-04 11:58:43 +08:00
|
|
|
|
str_reset(&str);
|
2018-07-14 18:04:52 +08:00
|
|
|
|
widget_destroy(w);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-22 12:05:10 +08:00
|
|
|
|
TEST(UISerializer, repeat) {
|
|
|
|
|
str_t str;
|
|
|
|
|
widget_t* w = button_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
button_set_repeat(w, 100);
|
|
|
|
|
str_init(&str, 1024);
|
|
|
|
|
widget_to_xml(w, &str);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(string(str.str),
|
|
|
|
|
"<button x=\"10\" y=\"20\" w=\"30\" h=\"40\" repeat=\"100\">\n</button>\n");
|
|
|
|
|
|
|
|
|
|
str_reset(&str);
|
|
|
|
|
widget_destroy(w);
|
|
|
|
|
}
|
2018-07-14 18:04:52 +08:00
|
|
|
|
TEST(UISerializer, layout_self) {
|
|
|
|
|
str_t str;
|
|
|
|
|
widget_t* w = button_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
|
|
|
|
|
widget_set_self_layout_params(w, "right:100", "middle:10", "fill", "10%");
|
|
|
|
|
str_init(&str, 1024);
|
2018-07-15 18:10:44 +08:00
|
|
|
|
widget_to_xml(w, &str);
|
2018-07-14 18:04:52 +08:00
|
|
|
|
|
2018-12-20 11:01:37 +08:00
|
|
|
|
ASSERT_EQ(string(str.str),
|
2018-12-20 16:18:49 +08:00
|
|
|
|
"<button x=\"10\" y=\"20\" w=\"30\" h=\"40\" "
|
2018-12-22 12:05:10 +08:00
|
|
|
|
"self_layout=\"default(x=r:100,y=m:10,w=0,h=10%)\">\n</button>\n");
|
2018-07-14 18:04:52 +08:00
|
|
|
|
|
2018-08-04 11:58:43 +08:00
|
|
|
|
str_reset(&str);
|
2018-07-14 18:04:52 +08:00
|
|
|
|
widget_destroy(w);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(UISerializer, layout_self1) {
|
|
|
|
|
str_t str;
|
|
|
|
|
widget_t* w = button_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
|
|
|
|
|
widget_set_self_layout_params(w, "center:100", "bottom:10", "fill", "10%");
|
|
|
|
|
str_init(&str, 1024);
|
2018-07-15 18:10:44 +08:00
|
|
|
|
widget_to_xml(w, &str);
|
2018-07-14 18:04:52 +08:00
|
|
|
|
|
2018-12-20 11:01:37 +08:00
|
|
|
|
ASSERT_EQ(string(str.str),
|
2018-12-20 16:18:49 +08:00
|
|
|
|
"<button x=\"10\" y=\"20\" w=\"30\" h=\"40\" "
|
2018-12-22 12:05:10 +08:00
|
|
|
|
"self_layout=\"default(x=c:100,y=b:10,w=0,h=10%)\">\n</button>\n");
|
2018-07-14 18:04:52 +08:00
|
|
|
|
|
2018-08-04 11:58:43 +08:00
|
|
|
|
str_reset(&str);
|
2018-07-14 18:04:52 +08:00
|
|
|
|
widget_destroy(w);
|
|
|
|
|
}
|