2018-06-27 13:46:42 +08:00
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
#include "base/array.h"
|
|
|
|
|
#include "base/theme.h"
|
|
|
|
|
#include "base/widget.h"
|
|
|
|
|
#include "tools/theme_gen/xml_theme_gen.h"
|
2018-02-22 08:36:54 +08:00
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include <stdlib.h>
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
TEST(ThemeGen, basic) {
|
|
|
|
|
uint8_t buff[1024];
|
|
|
|
|
theme_t theme;
|
|
|
|
|
style_t style;
|
|
|
|
|
const char* str =
|
2018-04-21 07:43:02 +08:00
|
|
|
|
"<widget><style><normal bg_color=\"yellow\" fg_color=\"#fafbfc\" font_name=\"sans\" font_size=\"12\" /></style></widget>\
|
|
|
|
|
<progress_bar><style><normal bg_color=\"rgb(255,255,0)\" fg_color=\"rgba(255,255,0,0.5)\" border_color=\"#ff00ff\" /></style></progress_bar>";
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
|
|
xml_gen_buff(str, buff, sizeof(buff));
|
|
|
|
|
theme.data = buff;
|
|
|
|
|
|
2018-06-25 17:27:17 +08:00
|
|
|
|
style.data = theme_find_style(&theme, WIDGET_TYPE_NONE, 0, WIDGET_STATE_NORMAL);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
ASSERT_EQ(style.data != NULL, true);
|
2018-03-04 08:32:52 +08:00
|
|
|
|
ASSERT_EQ(style_get_int(&style, STYLE_ID_FONT_SIZE, 0), 12);
|
|
|
|
|
ASSERT_EQ(style_get_int(&style, STYLE_ID_BG_COLOR, 0), 0xff00ffff);
|
|
|
|
|
ASSERT_EQ(style_get_int(&style, STYLE_ID_FG_COLOR, 0), 0xfffcfbfa);
|
|
|
|
|
ASSERT_EQ(style_get_str(&style, STYLE_ID_FONT_NAME, ""), string("sans"));
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
2018-06-25 17:27:17 +08:00
|
|
|
|
style.data = theme_find_style(&theme, WIDGET_TYPE_PROGRESS_BAR, 0, WIDGET_STATE_NORMAL);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
ASSERT_EQ(style.data != NULL, true);
|
2018-03-04 08:32:52 +08:00
|
|
|
|
ASSERT_EQ(style_get_int(&style, STYLE_ID_BG_COLOR, 0), 0xff00ffff);
|
|
|
|
|
ASSERT_EQ(style_get_int(&style, STYLE_ID_FG_COLOR, 0), 0x7f00ffff);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ThemeGen, state) {
|
|
|
|
|
uint8_t buff[1024];
|
|
|
|
|
theme_t theme;
|
|
|
|
|
style_t style;
|
|
|
|
|
const char* str =
|
2018-04-21 07:43:02 +08:00
|
|
|
|
"<button><style><over bg_color=\"yellow\" fg_color=\"#fafbfc\" font_name=\"sans\" font_size=\"12\" /></style></button>\
|
|
|
|
|
<button><style><pressed bg_color=\"rgb(255,255,0)\" fg_color=\"rgba(255,255,0,0.5)\" border_color=\"#ff00ff\"/></style></button>";
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
|
|
xml_gen_buff(str, buff, sizeof(buff));
|
|
|
|
|
theme.data = buff;
|
|
|
|
|
|
2018-06-25 17:27:17 +08:00
|
|
|
|
style.data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, 0, WIDGET_STATE_OVER);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
ASSERT_EQ(style.data != NULL, true);
|
2018-03-04 08:32:52 +08:00
|
|
|
|
ASSERT_EQ(style_get_int(&style, STYLE_ID_FONT_SIZE, 0), 12);
|
|
|
|
|
ASSERT_EQ(style_get_int(&style, STYLE_ID_BG_COLOR, 0), 0xff00ffff);
|
|
|
|
|
ASSERT_EQ(style_get_int(&style, STYLE_ID_FG_COLOR, 0), 0xfffcfbfa);
|
|
|
|
|
ASSERT_EQ(style_get_str(&style, STYLE_ID_FONT_NAME, ""), string("sans"));
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
2018-06-25 17:27:17 +08:00
|
|
|
|
style.data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, 0, WIDGET_STATE_PRESSED);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
ASSERT_EQ(style.data != NULL, true);
|
2018-03-04 08:32:52 +08:00
|
|
|
|
ASSERT_EQ(style_get_int(&style, STYLE_ID_BG_COLOR, 0), 0xff00ffff);
|
|
|
|
|
ASSERT_EQ(style_get_int(&style, STYLE_ID_FG_COLOR, 0), 0x7f00ffff);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
2018-03-26 12:16:52 +08:00
|
|
|
|
|
|
|
|
|
TEST(ThemeGen, style_type) {
|
|
|
|
|
uint8_t buff[1024];
|
|
|
|
|
theme_t theme;
|
|
|
|
|
style_t style;
|
|
|
|
|
const char* str =
|
2018-04-21 07:43:02 +08:00
|
|
|
|
"<button><style name=\"1:yellow\"><over bg_color=\"yellow\" fg_color=\"#fafbfc\" font_name=\"sans\" font_size=\"12\" /></style></button>\
|
|
|
|
|
<button><style name=\"1:yellow\"><pressed bg_color=\"rgb(255,255,0)\" fg_color=\"rgba(255,255,0,0.5)\" border_color=\"#ff00ff\" /></style></button>";
|
2018-03-26 12:16:52 +08:00
|
|
|
|
|
|
|
|
|
xml_gen_buff(str, buff, sizeof(buff));
|
|
|
|
|
theme.data = buff;
|
|
|
|
|
|
2018-06-25 17:27:17 +08:00
|
|
|
|
style.data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, 1, WIDGET_STATE_OVER);
|
2018-03-26 12:16:52 +08:00
|
|
|
|
ASSERT_EQ(style.data != NULL, true);
|
2018-03-30 22:15:45 +08:00
|
|
|
|
|
2018-06-25 17:27:17 +08:00
|
|
|
|
style.data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, 1, WIDGET_STATE_PRESSED);
|
2018-03-26 12:16:52 +08:00
|
|
|
|
ASSERT_EQ(style.data != NULL, true);
|
|
|
|
|
}
|
2018-03-31 19:48:56 +08:00
|
|
|
|
|
|
|
|
|
TEST(ThemeGen, inher) {
|
|
|
|
|
uint8_t buff[1024];
|
|
|
|
|
theme_t theme;
|
|
|
|
|
style_t style;
|
|
|
|
|
const char* str =
|
2018-04-21 07:43:02 +08:00
|
|
|
|
"<button font_size=\"12\"><style name=\"1:yellow\" font_name=\"sans\"><over bg_color=\"yellow\" fg_color=\"#fafbfc\" /></style>\
|
|
|
|
|
<style name=\"1:yellow\"><pressed bg_color=\"rgb(255,255,0)\" font_name=\"serif\" font_size=\"14\" /></style></button>";
|
2018-03-31 19:48:56 +08:00
|
|
|
|
|
|
|
|
|
xml_gen_buff(str, buff, sizeof(buff));
|
|
|
|
|
theme.data = buff;
|
|
|
|
|
|
2018-06-25 17:27:17 +08:00
|
|
|
|
style.data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, 1, WIDGET_STATE_OVER);
|
2018-03-31 19:48:56 +08:00
|
|
|
|
ASSERT_EQ(style.data != NULL, true);
|
|
|
|
|
ASSERT_EQ(style_get_int(&style, STYLE_ID_FONT_SIZE, 0), 12);
|
|
|
|
|
ASSERT_EQ(style_get_str(&style, STYLE_ID_FONT_NAME, ""), string("sans"));
|
|
|
|
|
|
2018-06-25 17:27:17 +08:00
|
|
|
|
style.data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, 1, WIDGET_STATE_PRESSED);
|
2018-03-31 19:48:56 +08:00
|
|
|
|
ASSERT_EQ(style.data != NULL, true);
|
|
|
|
|
ASSERT_EQ(style_get_int(&style, STYLE_ID_FONT_SIZE, 0), 14);
|
|
|
|
|
ASSERT_EQ(style_get_str(&style, STYLE_ID_FONT_NAME, ""), string("serif"));
|
|
|
|
|
}
|