awtk/tests/theme_gen_test.cc

451 lines
20 KiB
C++
Raw Normal View History

2018-06-27 13:46:42 +08:00

2018-02-21 19:36:38 +08:00
#include "base/theme.h"
#include "base/widget.h"
#include "gtest/gtest.h"
2021-01-29 12:42:14 +08:00
#include "base/style_factory.h"
2022-05-02 16:54:00 +08:00
#include "base/theme_xml.h"
#include <stdlib.h>
2018-02-21 19:36:38 +08:00
#include <string>
using std::string;
2019-12-10 17:56:31 +08:00
TEST(ThemeGen, basic0) {
2022-05-02 16:54:00 +08:00
theme_t* theme = NULL;
2019-12-10 17:56:31 +08:00
const uint8_t* style_data = NULL;
2021-01-29 12:42:14 +08:00
const char* str = "<widget><style><normal margin=\"-10\" bg_color=\"#fafbfc\"/></style></widget>";
2022-05-02 16:54:00 +08:00
style_t* s = style_factory_create_style(NULL, theme_get_style_type(theme));
2019-12-10 17:56:31 +08:00
2022-05-02 16:54:00 +08:00
theme = theme_xml_create(str);
2019-12-10 17:56:31 +08:00
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_NONE, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
2019-12-10 17:56:31 +08:00
ASSERT_EQ(style_data != NULL, true);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_NORMAL), RET_OK);
ASSERT_EQ(style_get_int(s, STYLE_ID_MARGIN, 0), -10);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(style_get_uint(s, STYLE_ID_BG_COLOR, 0), 0xfffcfbfau);
2021-04-22 09:46:33 +08:00
style_destroy(s);
2022-05-02 16:54:00 +08:00
theme_destroy(theme);
2019-12-10 17:56:31 +08:00
}
TEST(ThemeGen, basic1) {
2022-05-02 16:54:00 +08:00
theme_t* theme = NULL;
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 =
2019-12-10 17:56:31 +08:00
"<widget><style><normal bg_color=\"#fafbfc\" fg_color=\"#223344\" font_name=\"sans\" "
"font_size=\"12\"/></style></widget>";
2018-02-21 19:36:38 +08:00
2022-05-02 16:54:00 +08:00
style_t* s = style_factory_create_style(NULL, theme_get_style_type(theme));
2021-01-29 12:42:14 +08:00
2022-05-02 16:54:00 +08:00
theme = theme_xml_create(str);
2018-02-21 19:36:38 +08:00
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_NONE, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
2018-10-27 18:34:18 +08:00
ASSERT_EQ(style_data != NULL, true);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_NORMAL), RET_OK);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(style_get_uint(s, STYLE_ID_BG_COLOR, 0), 0xfffcfbfau);
ASSERT_EQ(style_get_uint(s, STYLE_ID_FG_COLOR, 0), 0xff443322u);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_get_int(s, STYLE_ID_FONT_SIZE, 0), 12);
ASSERT_EQ(style_get_str(s, STYLE_ID_FONT_NAME, ""), string("sans"));
2021-04-22 09:46:33 +08:00
style_destroy(s);
2022-05-02 16:54:00 +08:00
theme_destroy(theme);
2019-12-10 17:56:31 +08:00
}
2018-02-21 19:36:38 +08:00
2019-12-10 17:56:31 +08:00
TEST(ThemeGen, basic2) {
2022-05-02 16:54:00 +08:00
theme_t* theme = NULL;
2019-12-10 17:56:31 +08:00
const uint8_t* style_data = NULL;
const char* str =
"<widget>\
<style><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
<style><over bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
<style><focus bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
</widget>";
2022-05-02 16:54:00 +08:00
style_t* s = style_factory_create_style(NULL, theme_get_style_type(theme));
2019-12-10 17:56:31 +08:00
2022-05-02 16:54:00 +08:00
theme = theme_xml_create(str);
style_data = theme_find_style(theme, WIDGET_TYPE_NONE, TK_DEFAULT_STYLE, WIDGET_STATE_OVER);
2018-10-27 18:34:18 +08:00
ASSERT_EQ(style_data != NULL, true);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_OVER), RET_OK);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(style_get_uint(s, STYLE_ID_BG_COLOR, 0), 0xff332211u);
ASSERT_EQ(style_get_uint(s, STYLE_ID_FG_COLOR, 0), 0xff443322u);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_get_int(s, STYLE_ID_FONT_SIZE, 0), 12);
ASSERT_EQ(style_get_str(s, STYLE_ID_FONT_NAME, ""), string("sans"));
2021-04-22 09:46:33 +08:00
style_destroy(s);
2022-05-02 16:54:00 +08:00
theme_destroy(theme);
2019-12-10 17:56:31 +08:00
}
TEST(ThemeGen, basic3) {
2022-05-02 16:54:00 +08:00
theme_t* theme = NULL;
2019-12-10 17:56:31 +08:00
const uint8_t* style_data = NULL;
const char* str =
"<widget>\
<style name=\"default\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
<style name=\"1\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
<style name=\"2\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
</widget>\
<button>\
<style name=\"default\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
<style name=\"1\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
<style name=\"2\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
</button>\
<label>\
<style name=\"default\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
<style name=\"1\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
<style name=\"2\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
</label>\
";
2022-05-02 16:54:00 +08:00
style_t* s = style_factory_create_style(NULL, theme_get_style_type(theme));
theme = theme_xml_create(str);
2019-12-10 17:56:31 +08:00
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_BUTTON, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
2019-12-10 17:56:31 +08:00
ASSERT_EQ(style_data != NULL, true);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_NORMAL), RET_OK);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(style_get_uint(s, STYLE_ID_BG_COLOR, 0), 0xff332211u);
ASSERT_EQ(style_get_uint(s, STYLE_ID_FG_COLOR, 0), 0xff443322u);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_get_int(s, STYLE_ID_FONT_SIZE, 0), 12);
ASSERT_EQ(style_get_str(s, STYLE_ID_FONT_NAME, ""), string("sans"));
2021-04-22 09:46:33 +08:00
style_destroy(s);
2022-05-02 16:54:00 +08:00
theme_destroy(theme);
2019-12-10 17:56:31 +08:00
}
TEST(ThemeGen, basic4) {
2022-05-02 16:54:00 +08:00
theme_t* theme = NULL;
2019-12-10 17:56:31 +08:00
const uint8_t* style_data = NULL;
const char* str =
"<widget>\
<style name=\"default\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
<style name=\"1\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
<style name=\"2\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
</widget>\
<button>\
<style name=\"default\"> \
<normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/> \
<over bg_color=\"#112244\" fg_color=\"#223355\" font_name=\"sans\" font_size=\"12\"/> \
<focus bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/> \
</style>\
<style name=\"1\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
<style name=\"2\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
</button>\
<label>\
<style name=\"default\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
<style name=\"1\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
<style name=\"2\"><normal bg_color=\"#112233\" fg_color=\"#223344\" font_name=\"sans\" font_size=\"12\"/></style>\
</label>\
";
2022-05-02 16:54:00 +08:00
style_t* s = style_factory_create_style(NULL, theme_get_style_type(theme));
theme = theme_xml_create(str);
2019-12-10 17:56:31 +08:00
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_BUTTON, TK_DEFAULT_STYLE, WIDGET_STATE_OVER);
2019-12-10 17:56:31 +08:00
ASSERT_EQ(style_data != NULL, true);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_OVER), RET_OK);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(style_get_uint(s, STYLE_ID_BG_COLOR, 0), 0xff442211u);
ASSERT_EQ(style_get_uint(s, STYLE_ID_FG_COLOR, 0), 0xff553322u);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_get_int(s, STYLE_ID_FONT_SIZE, 0), 12);
ASSERT_EQ(style_get_str(s, STYLE_ID_FONT_NAME, ""), string("sans"));
2021-04-22 09:46:33 +08:00
style_destroy(s);
2022-05-02 16:54:00 +08:00
theme_destroy(theme);
2018-02-21 19:36:38 +08:00
}
TEST(ThemeGen, state) {
2022-05-02 16:54:00 +08:00
theme_t* theme = NULL;
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 =
2019-12-10 17:56:31 +08:00
"<button><style><over bg_color=\"#f1f2f3\" fg_color=\"#fafbfc\" font_name=\"sans\" font_size=\"12\" /></style></button>\
2018-04-21 07:43:02 +08:00
<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
2022-05-02 16:54:00 +08:00
style_t* s = style_factory_create_style(NULL, theme_get_style_type(theme));
2018-02-21 19:36:38 +08:00
2022-05-02 16:54:00 +08:00
theme = theme_xml_create(str);
style_data = theme_find_style(theme, WIDGET_TYPE_BUTTON, TK_DEFAULT_STYLE, WIDGET_STATE_OVER);
2018-10-27 18:34:18 +08:00
ASSERT_EQ(style_data != NULL, true);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_OVER), RET_OK);
ASSERT_EQ(style_get_int(s, STYLE_ID_FONT_SIZE, 0), 12);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(style_get_uint(s, STYLE_ID_BG_COLOR, 0), 0xfff3f2f1u);
ASSERT_EQ(style_get_uint(s, STYLE_ID_FG_COLOR, 0), 0xfffcfbfau);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_get_str(s, STYLE_ID_FONT_NAME, ""), string("sans"));
2018-10-27 18:34:18 +08:00
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_BUTTON, TK_DEFAULT_STYLE, WIDGET_STATE_PRESSED);
2018-10-27 18:34:18 +08:00
ASSERT_EQ(style_data != NULL, true);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_PRESSED), RET_OK);
2021-09-16 16:06:55 +08:00
ASSERT_EQ((uint32_t)style_get_int(s, STYLE_ID_BG_COLOR, 0), 0xff00ffffu);
2021-04-22 09:46:33 +08:00
style_destroy(s);
2022-05-02 16:54:00 +08:00
theme_destroy(theme);
2018-02-21 19:36:38 +08:00
}
2018-03-26 12:16:52 +08:00
TEST(ThemeGen, style_type) {
2022-05-02 16:54:00 +08:00
theme_t* theme = NULL;
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
2022-05-02 16:54:00 +08:00
style_t* s = style_factory_create_style(NULL, theme_get_style_type(theme));
theme = theme_xml_create(str);
2018-03-26 12:16:52 +08:00
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_BUTTON, "yellow", WIDGET_STATE_OVER);
2018-10-27 18:34:18 +08:00
ASSERT_EQ(style_data != NULL, true);
2018-03-30 22:15:45 +08:00
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_BUTTON, "yellow", WIDGET_STATE_PRESSED);
2018-10-27 18:34:18 +08:00
ASSERT_EQ(style_data != NULL, true);
2021-04-22 09:46:33 +08:00
style_destroy(s);
2022-05-02 16:54:00 +08:00
theme_destroy(theme);
2018-03-26 12:16:52 +08:00
}
2018-03-31 19:48:56 +08:00
TEST(ThemeGen, inher) {
2022-05-02 16:54:00 +08:00
theme_t* theme = NULL;
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>\
2021-01-29 12:42:14 +08:00
<style name=\"yellow\"><pressed margin=\"-10\" bg_color=\"rgb(255,255,0)\" font_name=\"serif\" font_size=\"14\" /></style></button>";
2018-03-31 19:48:56 +08:00
2022-05-02 16:54:00 +08:00
style_t* s = style_factory_create_style(NULL, theme_get_style_type(theme));
2018-03-31 19:48:56 +08:00
2022-05-02 16:54:00 +08:00
theme = theme_xml_create(str);
style_data = theme_find_style(theme, WIDGET_TYPE_BUTTON, "yellow", WIDGET_STATE_OVER);
2018-10-27 18:34:18 +08:00
ASSERT_EQ(style_data != NULL, true);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_OVER), RET_OK);
ASSERT_EQ(style_get_int(s, STYLE_ID_FONT_SIZE, 0), 12);
ASSERT_EQ(style_get_str(s, STYLE_ID_FONT_NAME, ""), string("sans"));
2018-03-31 19:48:56 +08:00
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_BUTTON, "yellow", WIDGET_STATE_PRESSED);
2018-10-27 18:34:18 +08:00
ASSERT_EQ(style_data != NULL, true);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_PRESSED), RET_OK);
ASSERT_EQ(style_get_int(s, STYLE_ID_MARGIN, 0), -10);
ASSERT_EQ(style_get_int(s, STYLE_ID_FONT_SIZE, 0), 14);
ASSERT_EQ(style_get_str(s, STYLE_ID_FONT_NAME, ""), string("serif"));
2021-04-22 09:46:33 +08:00
style_destroy(s);
2022-05-02 16:54:00 +08:00
theme_destroy(theme);
2018-03-31 19:48:56 +08:00
}
2018-06-29 19:12:04 +08:00
2020-11-25 11:16:33 +08:00
TEST(ThemeGen, cdata) {
2022-05-02 16:54:00 +08:00
theme_t* theme = NULL;
2020-11-25 11:16:33 +08:00
const uint8_t* style_data = NULL;
const char* str =
"<button><property name=\"font_size\"><![CDATA[12]]></property>\
<style name=\"yellow\"><property name=\"font_name\"><![CDATA[sans]]></property>\
<over bg_color=\"yellow\" fg_color=\"#fafbfc\"><property name=\"text_color\"><![CDATA[#fdfeff]]></property>\
</over></style></button>";
2022-05-02 16:54:00 +08:00
style_t* s = style_factory_create_style(NULL, theme_get_style_type(theme));
theme = theme_xml_create(str);
2020-11-25 11:16:33 +08:00
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_BUTTON, "yellow", WIDGET_STATE_OVER);
2020-11-25 11:16:33 +08:00
ASSERT_EQ(style_data != NULL, true);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_OVER), RET_OK);
ASSERT_EQ(style_get_int(s, STYLE_ID_FONT_SIZE, 0), 12);
ASSERT_EQ(style_get_str(s, STYLE_ID_FONT_NAME, ""), string("sans"));
ASSERT_EQ(style_get_uint(s, STYLE_ID_TEXT_COLOR, 0), 0xfffffefd);
2021-04-22 09:46:33 +08:00
style_destroy(s);
2022-05-02 16:54:00 +08:00
theme_destroy(theme);
2020-11-25 11:16:33 +08:00
}
2018-06-29 19:12:04 +08:00
TEST(ThemeGen, border) {
2022-05-02 16:54:00 +08:00
theme_t* theme = NULL;
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>";
2021-01-29 12:42:14 +08:00
2022-05-02 16:54:00 +08:00
theme = theme_xml_create(str);
2018-06-29 19:12:04 +08:00
2022-05-02 17:24:23 +08:00
style_t* s = style_factory_create_style(NULL, theme_get_style_type(theme));
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_BUTTON, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_NORMAL), RET_OK);
ASSERT_EQ(style_get_int(s, STYLE_ID_BORDER, 0), BORDER_LEFT);
2022-05-02 17:24:23 +08:00
theme_destroy(theme);
2018-06-29 19:12:04 +08:00
str = "<button><style><normal border=\"right\" /></style></button>";
2022-05-02 16:54:00 +08:00
theme = theme_xml_create(str);
style_data = theme_find_style(theme, WIDGET_TYPE_BUTTON, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_NORMAL), RET_OK);
ASSERT_EQ(style_get_int(s, STYLE_ID_BORDER, 0), BORDER_RIGHT);
2022-05-02 17:24:23 +08:00
theme_destroy(theme);
2018-06-29 19:12:04 +08:00
str = "<button><style><normal border=\"top\" /></style></button>";
2022-05-02 16:54:00 +08:00
theme = theme_xml_create(str);
style_data = theme_find_style(theme, WIDGET_TYPE_BUTTON, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_NORMAL), RET_OK);
ASSERT_EQ(style_get_int(s, STYLE_ID_BORDER, 0), BORDER_TOP);
2022-05-02 17:24:23 +08:00
theme_destroy(theme);
2018-06-29 19:12:04 +08:00
str = "<button><style><normal border=\"bottom\" /></style></button>";
2022-05-02 16:54:00 +08:00
theme = theme_xml_create(str);
style_data = theme_find_style(theme, WIDGET_TYPE_BUTTON, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_NORMAL), RET_OK);
ASSERT_EQ(style_get_int(s, STYLE_ID_BORDER, 0), BORDER_BOTTOM);
2022-05-02 17:24:23 +08:00
theme_destroy(theme);
2018-06-29 19:12:04 +08:00
str = "<button><style><normal border=\"all\" /></style></button>";
2022-05-02 16:54:00 +08:00
theme = theme_xml_create(str);
style_data = theme_find_style(theme, WIDGET_TYPE_BUTTON, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_NORMAL), RET_OK);
ASSERT_EQ(style_get_int(s, STYLE_ID_BORDER, 0), BORDER_ALL);
2021-04-22 09:46:33 +08:00
style_destroy(s);
2022-05-02 16:54:00 +08:00
theme_destroy(theme);
2018-06-29 19:12:04 +08:00
}
TEST(ThemeGen, active_state) {
2022-05-02 16:54:00 +08:00
theme_t* theme = NULL;
color_t def = color_init(0, 0, 0, 0);
const uint8_t* style_data = NULL;
const char* str =
"<tab_button> \
<style name=\"default\" text_align_h=\"left\" margin=\"4\" border_color=\"#cccccc\" bg_color=\"#eeeeee\"> \
<normal text_color=\"#111111\"/> \
<pressed text_color=\"#222222\"/> \
<over text_color=\"#333333\"/> \
<normal_of_active text_color=\"#444444\"/> \
<pressed_of_active text_color=\"#555555\"/> \
<over_of_active text_color=\"#666666\"/> \
</style> \
</tab_button>";
2022-05-02 16:54:00 +08:00
style_t* s = style_factory_create_style(NULL, theme_get_style_type(theme));
theme = theme_xml_create(str);
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_TAB_BUTTON, "default", WIDGET_STATE_NORMAL);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_NORMAL), RET_OK);
ASSERT_EQ(style_get_color(s, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x11);
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_TAB_BUTTON, "default", WIDGET_STATE_PRESSED);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_PRESSED), RET_OK);
ASSERT_EQ(style_get_color(s, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x22);
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_TAB_BUTTON, "default", WIDGET_STATE_OVER);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_OVER), RET_OK);
ASSERT_EQ(style_get_color(s, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x33);
style_data =
2022-05-02 16:54:00 +08:00
theme_find_style(theme, WIDGET_TYPE_TAB_BUTTON, "default", WIDGET_STATE_NORMAL_OF_ACTIVE);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_NORMAL_OF_ACTIVE), RET_OK);
ASSERT_EQ(style_get_color(s, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x44);
style_data =
2022-05-02 16:54:00 +08:00
theme_find_style(theme, WIDGET_TYPE_TAB_BUTTON, "default", WIDGET_STATE_PRESSED_OF_ACTIVE);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_PRESSED_OF_ACTIVE), RET_OK);
ASSERT_EQ(style_get_color(s, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x55);
style_data =
2022-05-02 16:54:00 +08:00
theme_find_style(theme, WIDGET_TYPE_TAB_BUTTON, "default", WIDGET_STATE_OVER_OF_ACTIVE);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_OVER_OF_ACTIVE), RET_OK);
ASSERT_EQ(style_get_color(s, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x66);
2021-04-22 09:46:33 +08:00
style_destroy(s);
2022-05-02 16:54:00 +08:00
theme_destroy(theme);
}
TEST(ThemeGen, selected_state) {
2022-05-02 16:54:00 +08:00
theme_t* theme = NULL;
color_t def = color_init(0, 0, 0, 0);
const uint8_t* style_data = NULL;
const char* str =
"<combo_box_item> \
<style name=\"default\" text_align_h=\"left\" margin=\"4\" border_color=\"#cccccc\" bg_color=\"#eeeeee\"> \
<normal text_color=\"#111111\"/> \
<pressed text_color=\"#222222\"/> \
<over text_color=\"#333333\"/> \
2018-10-28 11:33:38 +08:00
<normal_of_checked text_color=\"#444444\"/> \
<pressed_of_checked text_color=\"#555555\"/> \
<over_of_checked text_color=\"#666666\"/> \
</style> \
</combo_box_item>";
2022-05-02 16:54:00 +08:00
style_t* s = style_factory_create_style(NULL, theme_get_style_type(theme));
2022-05-02 16:54:00 +08:00
theme = theme_xml_create(str);
style_data = theme_find_style(theme, WIDGET_TYPE_COMBO_BOX_ITEM, "default", WIDGET_STATE_NORMAL);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_NORMAL), RET_OK);
ASSERT_EQ(style_get_color(s, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x11);
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_COMBO_BOX_ITEM, "default", WIDGET_STATE_PRESSED);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_PRESSED), RET_OK);
ASSERT_EQ(style_get_color(s, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x22);
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_COMBO_BOX_ITEM, "default", WIDGET_STATE_OVER);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_OVER), RET_OK);
ASSERT_EQ(style_get_color(s, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x33);
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_COMBO_BOX_ITEM, "default",
2018-12-25 15:33:44 +08:00
WIDGET_STATE_NORMAL_OF_CHECKED);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_NORMAL_OF_CHECKED), RET_OK);
ASSERT_EQ(style_get_color(s, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x44);
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_COMBO_BOX_ITEM, "default",
2018-12-25 15:33:44 +08:00
WIDGET_STATE_PRESSED_OF_CHECKED);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_PRESSED_OF_CHECKED), RET_OK);
ASSERT_EQ(style_get_color(s, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x55);
style_data =
2022-05-02 16:54:00 +08:00
theme_find_style(theme, WIDGET_TYPE_COMBO_BOX_ITEM, "default", WIDGET_STATE_OVER_OF_CHECKED);
2021-01-29 12:42:14 +08:00
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_OVER_OF_CHECKED), RET_OK);
ASSERT_EQ(style_get_color(s, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x66);
2021-04-22 09:46:33 +08:00
style_destroy(s);
2022-05-02 16:54:00 +08:00
theme_destroy(theme);
}
2021-09-14 18:13:00 +08:00
TEST(ThemeGen, gradient) {
gradient_t g;
2022-05-02 16:54:00 +08:00
theme_t* theme = NULL;
2021-09-14 18:13:00 +08:00
const uint8_t* style_data = NULL;
2021-10-11 15:52:40 +08:00
const char* str =
"<widget><style><normal fg_color=\"red\" bg_color=\"linear-gradient(180deg, #FF0000 0%, "
"#0000FF 100%)\"/></style></widget>";
2021-09-14 18:13:00 +08:00
2022-05-02 16:54:00 +08:00
style_t* s = style_factory_create_style(NULL, theme_get_style_type(theme));
2021-09-14 18:13:00 +08:00
2022-05-02 16:54:00 +08:00
theme = theme_xml_create(str);
2021-09-14 18:13:00 +08:00
2022-05-02 16:54:00 +08:00
style_data = theme_find_style(theme, WIDGET_TYPE_NONE, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
2021-09-14 18:13:00 +08:00
ASSERT_EQ(style_data != NULL, true);
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_NORMAL), RET_OK);
ASSERT_EQ(style_get_gradient(s, STYLE_ID_BG_COLOR, &g) != NULL, true);
2021-10-11 15:52:40 +08:00
2021-09-14 18:13:00 +08:00
ASSERT_EQ(g.type, GRADIENT_LINEAR);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(g.nr, 2u);
ASSERT_EQ(g.degree, 180u);
2021-10-11 15:52:40 +08:00
2021-09-16 16:06:55 +08:00
ASSERT_EQ(g.stops[0].offset, 0.0f);
2021-09-14 18:13:00 +08:00
ASSERT_EQ(g.stops[0].color.rgba.r, 0xff);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(g.stops[1].offset, 1.0f);
2021-09-14 18:13:00 +08:00
ASSERT_EQ(g.stops[1].color.rgba.b, 0xff);
2021-10-11 15:52:40 +08:00
2021-09-14 18:13:00 +08:00
ASSERT_EQ(style_get_gradient(s, STYLE_ID_FG_COLOR, &g) != NULL, true);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(g.nr, 1u);
ASSERT_EQ(g.degree, 0u);
2021-10-11 15:52:40 +08:00
2021-09-16 16:06:55 +08:00
ASSERT_EQ(g.stops[0].offset, 0.0f);
2021-09-14 18:13:00 +08:00
ASSERT_EQ(g.stops[0].color.rgba.r, 0xff);
ASSERT_EQ(g.stops[0].color.rgba.g, 0);
ASSERT_EQ(g.stops[0].color.rgba.b, 0);
ASSERT_EQ(g.stops[0].color.rgba.a, 0xff);
2021-10-11 15:52:40 +08:00
2021-09-14 18:13:00 +08:00
style_destroy(s);
2022-05-02 16:54:00 +08:00
theme_destroy(theme);
2021-09-14 18:13:00 +08:00
}
2022-05-06 18:25:23 +08:00
TEST(ThemeGen, bool) {
theme_t* theme = NULL;
const uint8_t* style_data = NULL;
const char* str = "<widget><style><normal feedback=\"true\" focusable=\"2\" clear_bg=\"1\"/></style></widget>";
style_t* s = style_factory_create_style(NULL, theme_get_style_type(theme));
theme = theme_xml_create(str);
style_data = theme_find_style(theme, WIDGET_TYPE_NONE, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL);
ASSERT_EQ(style_data != NULL, true);
ASSERT_EQ(style_set_style_data(s, style_data, WIDGET_STATE_NORMAL), RET_OK);
ASSERT_EQ(style_get_int(s, STYLE_ID_FEEDBACK, 0), 1);
ASSERT_EQ(style_get_int(s, STYLE_ID_FOCUSABLE, 0), 1);
ASSERT_EQ(style_get_int(s, STYLE_ID_CLEAR_BG, 0), 1);
style_destroy(s);
theme_destroy(theme);
}