awtk/tests/theme_gen_test.cc

136 lines
5.9 KiB
C++
Raw Normal View History

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"
#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;
2018-10-27 18:34:18 +08:00
const uint8_t* style_data = NULL;
2018-02-21 19:36:38 +08:00
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-10-27 18:34:18 +08:00
style_data = theme_find_style(&theme, WIDGET_TYPE_NONE, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
ASSERT_EQ(style_data != NULL, true);
ASSERT_EQ(style_data_get_int(style_data, STYLE_ID_FONT_SIZE, 0), 12);
ASSERT_EQ(style_data_get_int(style_data, STYLE_ID_BG_COLOR, 0), 0xff00ffff);
ASSERT_EQ(style_data_get_int(style_data, STYLE_ID_FG_COLOR, 0), 0xfffcfbfa);
ASSERT_EQ(style_data_get_str(style_data, STYLE_ID_FONT_NAME, ""), string("sans"));
2018-02-21 19:36:38 +08:00
2018-10-27 18:34:18 +08:00
style_data =
2018-07-17 11:27:14 +08:00
theme_find_style(&theme, WIDGET_TYPE_PROGRESS_BAR, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
2018-10-27 18:34:18 +08:00
ASSERT_EQ(style_data != NULL, true);
ASSERT_EQ(style_data_get_int(style_data, STYLE_ID_BG_COLOR, 0), 0xff00ffff);
ASSERT_EQ(style_data_get_int(style_data, STYLE_ID_FG_COLOR, 0), 0x7f00ffff);
2018-02-21 19:36:38 +08:00
}
TEST(ThemeGen, state) {
uint8_t buff[1024];
theme_t theme;
2018-10-27 18:34:18 +08:00
const uint8_t* style_data = NULL;
2018-02-21 19:36:38 +08:00
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-10-27 18:34:18 +08:00
style_data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, TK_DEFAULT_STYLE, WIDGET_STATE_OVER);
ASSERT_EQ(style_data != NULL, true);
ASSERT_EQ(style_data_get_int(style_data, STYLE_ID_FONT_SIZE, 0), 12);
ASSERT_EQ(style_data_get_int(style_data, STYLE_ID_BG_COLOR, 0), 0xff00ffff);
ASSERT_EQ(style_data_get_int(style_data, STYLE_ID_FG_COLOR, 0), 0xfffcfbfa);
ASSERT_EQ(style_data_get_str(style_data, STYLE_ID_FONT_NAME, ""), string("sans"));
style_data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, TK_DEFAULT_STYLE, WIDGET_STATE_PRESSED);
ASSERT_EQ(style_data != NULL, true);
ASSERT_EQ(style_data_get_int(style_data, STYLE_ID_BG_COLOR, 0), 0xff00ffff);
ASSERT_EQ(style_data_get_int(style_data, 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;
2018-10-27 18:34:18 +08:00
const uint8_t* style_data = NULL;
2018-03-26 12:16:52 +08:00
const char* str =
2018-07-17 11:27:14 +08:00
"<button><style name=\"yellow\"><over bg_color=\"yellow\" fg_color=\"#fafbfc\" font_name=\"sans\" font_size=\"12\" /></style></button>\
<button><style name=\"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-10-27 18:34:18 +08:00
style_data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, "yellow", WIDGET_STATE_OVER);
ASSERT_EQ(style_data != NULL, true);
2018-03-30 22:15:45 +08:00
2018-10-27 18:34:18 +08:00
style_data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, "yellow", WIDGET_STATE_PRESSED);
ASSERT_EQ(style_data != NULL, true);
2018-03-26 12:16:52 +08:00
}
2018-03-31 19:48:56 +08:00
TEST(ThemeGen, inher) {
uint8_t buff[1024];
theme_t theme;
2018-10-27 18:34:18 +08:00
const uint8_t* style_data = NULL;
2018-03-31 19:48:56 +08:00
const char* str =
2018-07-17 11:27:14 +08:00
"<button font_size=\"12\"><style name=\"yellow\" font_name=\"sans\"><over bg_color=\"yellow\" fg_color=\"#fafbfc\" /></style>\
<style name=\"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-10-27 18:34:18 +08:00
style_data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, "yellow", WIDGET_STATE_OVER);
ASSERT_EQ(style_data != NULL, true);
ASSERT_EQ(style_data_get_int(style_data, STYLE_ID_FONT_SIZE, 0), 12);
ASSERT_EQ(style_data_get_str(style_data, STYLE_ID_FONT_NAME, ""), string("sans"));
2018-03-31 19:48:56 +08:00
2018-10-27 18:34:18 +08:00
style_data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, "yellow", WIDGET_STATE_PRESSED);
ASSERT_EQ(style_data != NULL, true);
ASSERT_EQ(style_data_get_int(style_data, STYLE_ID_FONT_SIZE, 0), 14);
ASSERT_EQ(style_data_get_str(style_data, STYLE_ID_FONT_NAME, ""), string("serif"));
2018-03-31 19:48:56 +08:00
}
2018-06-29 19:12:04 +08:00
TEST(ThemeGen, border) {
uint8_t buff[1024];
theme_t theme;
2018-10-27 18:34:18 +08:00
const uint8_t* style_data = NULL;
2018-06-29 19:12:04 +08:00
const char* str = "<button><style><normal border=\"left\" /></style></button>";
xml_gen_buff(str, buff, sizeof(buff));
theme.data = buff;
2018-10-27 18:34:18 +08:00
style_data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
ASSERT_EQ(style_data_get_int(style_data, STYLE_ID_BORDER, 0), BORDER_LEFT);
2018-06-29 19:12:04 +08:00
str = "<button><style><normal border=\"right\" /></style></button>";
xml_gen_buff(str, buff, sizeof(buff));
theme.data = buff;
2018-10-27 18:34:18 +08:00
style_data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
ASSERT_EQ(style_data_get_int(style_data, STYLE_ID_BORDER, 0), BORDER_RIGHT);
2018-06-29 19:12:04 +08:00
str = "<button><style><normal border=\"top\" /></style></button>";
xml_gen_buff(str, buff, sizeof(buff));
theme.data = buff;
2018-10-27 18:34:18 +08:00
style_data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
ASSERT_EQ(style_data_get_int(style_data, STYLE_ID_BORDER, 0), BORDER_TOP);
2018-06-29 19:12:04 +08:00
str = "<button><style><normal border=\"bottom\" /></style></button>";
xml_gen_buff(str, buff, sizeof(buff));
theme.data = buff;
2018-10-27 18:34:18 +08:00
style_data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
ASSERT_EQ(style_data_get_int(style_data, STYLE_ID_BORDER, 0), BORDER_BOTTOM);
2018-06-29 19:12:04 +08:00
str = "<button><style><normal border=\"all\" /></style></button>";
xml_gen_buff(str, buff, sizeof(buff));
theme.data = buff;
2018-10-27 18:34:18 +08:00
style_data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
ASSERT_EQ(style_data_get_int(style_data, STYLE_ID_BORDER, 0), BORDER_ALL);
2018-06-29 19:12:04 +08:00
}