#include "base/theme.h" #include "base/widget.h" #include "tools/theme_gen/xml_theme_gen.h" #include "gtest/gtest.h" #include #include using std::string; TEST(ThemeGen, basic) { uint8_t buff[1024]; theme_t theme; const uint8_t* style_data = NULL; const char* str = "\ "; xml_gen_buff(str, buff, sizeof(buff)); theme.data = buff; 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")); style_data = theme_find_style(&theme, WIDGET_TYPE_PROGRESS_BAR, TK_DEFAULT_STYLE, WIDGET_STATE_NORMAL); 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); } TEST(ThemeGen, state) { uint8_t buff[1024]; theme_t theme; const uint8_t* style_data = NULL; const char* str = "\ "; xml_gen_buff(str, buff, sizeof(buff)); theme.data = buff; 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); } TEST(ThemeGen, style_type) { uint8_t buff[1024]; theme_t theme; const uint8_t* style_data = NULL; const char* str = "\ "; xml_gen_buff(str, buff, sizeof(buff)); theme.data = buff; style_data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, "yellow", WIDGET_STATE_OVER); ASSERT_EQ(style_data != NULL, true); style_data = theme_find_style(&theme, WIDGET_TYPE_BUTTON, "yellow", WIDGET_STATE_PRESSED); ASSERT_EQ(style_data != NULL, true); } TEST(ThemeGen, inher) { uint8_t buff[1024]; theme_t theme; const uint8_t* style_data = NULL; const char* str = ""; xml_gen_buff(str, buff, sizeof(buff)); theme.data = buff; 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")); 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")); } TEST(ThemeGen, border) { uint8_t buff[1024]; theme_t theme; const uint8_t* style_data = NULL; const char* str = ""; xml_gen_buff(str, buff, sizeof(buff)); theme.data = buff; 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); str = ""; xml_gen_buff(str, buff, sizeof(buff)); theme.data = buff; 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); str = ""; xml_gen_buff(str, buff, sizeof(buff)); theme.data = buff; 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); str = ""; xml_gen_buff(str, buff, sizeof(buff)); theme.data = buff; 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); str = ""; xml_gen_buff(str, buff, sizeof(buff)); theme.data = buff; 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); } TEST(ThemeGen, active_state) { uint8_t buff[10240]; theme_t theme; color_t def = color_init(0, 0, 0, 0); const uint8_t* style_data = NULL; const char* str = " \ \ "; xml_gen_buff(str, buff, sizeof(buff)); theme.data = buff; style_data = theme_find_style(&theme, WIDGET_TYPE_TAB_BUTTON, "default", WIDGET_STATE_NORMAL); ASSERT_EQ(style_data_get_color(style_data, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x11); style_data = theme_find_style(&theme, WIDGET_TYPE_TAB_BUTTON, "default", WIDGET_STATE_PRESSED); ASSERT_EQ(style_data_get_color(style_data, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x22); style_data = theme_find_style(&theme, WIDGET_TYPE_TAB_BUTTON, "default", WIDGET_STATE_OVER); ASSERT_EQ(style_data_get_color(style_data, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x33); style_data = theme_find_style(&theme, WIDGET_TYPE_TAB_BUTTON, "default", WIDGET_STATE_NORMAL_OF_ACTIVE); ASSERT_EQ(style_data_get_color(style_data, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x44); style_data = theme_find_style(&theme, WIDGET_TYPE_TAB_BUTTON, "default", WIDGET_STATE_PRESSED_OF_ACTIVE); ASSERT_EQ(style_data_get_color(style_data, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x55); style_data = theme_find_style(&theme, WIDGET_TYPE_TAB_BUTTON, "default", WIDGET_STATE_OVER_OF_ACTIVE); ASSERT_EQ(style_data_get_color(style_data, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x66); } TEST(ThemeGen, selected_state) { uint8_t buff[10240]; theme_t theme; color_t def = color_init(0, 0, 0, 0); const uint8_t* style_data = NULL; const char* str = " \ \ "; xml_gen_buff(str, buff, sizeof(buff)); theme.data = buff; style_data = theme_find_style(&theme, WIDGET_TYPE_COMBO_BOX_ITEM, "default", WIDGET_STATE_NORMAL); ASSERT_EQ(style_data_get_color(style_data, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x11); style_data = theme_find_style(&theme, WIDGET_TYPE_COMBO_BOX_ITEM, "default", WIDGET_STATE_PRESSED); ASSERT_EQ(style_data_get_color(style_data, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x22); style_data = theme_find_style(&theme, WIDGET_TYPE_COMBO_BOX_ITEM, "default", WIDGET_STATE_OVER); ASSERT_EQ(style_data_get_color(style_data, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x33); style_data = theme_find_style(&theme, WIDGET_TYPE_COMBO_BOX_ITEM, "default", WIDGET_STATE_NORMAL_OF_CHECKED); ASSERT_EQ(style_data_get_color(style_data, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x44); style_data = theme_find_style(&theme, WIDGET_TYPE_COMBO_BOX_ITEM, "default", WIDGET_STATE_PRESSED_OF_CHECKED); ASSERT_EQ(style_data_get_color(style_data, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x55); style_data = theme_find_style(&theme, WIDGET_TYPE_COMBO_BOX_ITEM, "default", WIDGET_STATE_OVER_OF_CHECKED); ASSERT_EQ(style_data_get_color(style_data, STYLE_ID_TEXT_COLOR, def).rgba.r, 0x66); }