2018-06-27 13:46:42 +08:00
|
|
|
|
|
2018-06-25 17:27:17 +08:00
|
|
|
|
#include "base/enums.h"
|
2018-02-22 08:36:54 +08:00
|
|
|
|
#include "base/theme.h"
|
2018-03-30 22:15:45 +08:00
|
|
|
|
#include "base/widget.h"
|
2018-12-15 17:22:05 +08:00
|
|
|
|
#include "tkc/buffer.h"
|
2018-02-21 19:36:38 +08:00
|
|
|
|
#include "tools/theme_gen/theme_gen.h"
|
2021-01-29 12:42:14 +08:00
|
|
|
|
#include "base/style_factory.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;
|
|
|
|
|
|
2018-12-25 15:33:44 +08:00
|
|
|
|
static const char* state_names[] = {WIDGET_STATE_NORMAL, WIDGET_STATE_PRESSED, WIDGET_STATE_OVER,
|
|
|
|
|
WIDGET_STATE_DISABLE, WIDGET_STATE_FOCUSED, NULL};
|
|
|
|
|
|
2018-08-01 12:53:59 +08:00
|
|
|
|
static const char* widget_types[] = {WIDGET_TYPE_WINDOW_MANAGER,
|
|
|
|
|
WIDGET_TYPE_NORMAL_WINDOW,
|
|
|
|
|
WIDGET_TYPE_TOOL_BAR,
|
|
|
|
|
WIDGET_TYPE_DIALOG,
|
|
|
|
|
WIDGET_TYPE_POPUP,
|
|
|
|
|
WIDGET_TYPE_SPRITE,
|
|
|
|
|
WIDGET_TYPE_KEYBOARD,
|
|
|
|
|
WIDGET_TYPE_DND,
|
|
|
|
|
WIDGET_TYPE_LABEL,
|
|
|
|
|
WIDGET_TYPE_BUTTON,
|
|
|
|
|
WIDGET_TYPE_IMAGE,
|
|
|
|
|
WIDGET_TYPE_EDIT,
|
|
|
|
|
WIDGET_TYPE_PROGRESS_BAR,
|
|
|
|
|
WIDGET_TYPE_GROUP_BOX,
|
|
|
|
|
WIDGET_TYPE_CHECK_BUTTON,
|
|
|
|
|
WIDGET_TYPE_RADIO_BUTTON,
|
|
|
|
|
WIDGET_TYPE_DIALOG_TITLE,
|
|
|
|
|
WIDGET_TYPE_DIALOG_CLIENT,
|
|
|
|
|
WIDGET_TYPE_SLIDER,
|
|
|
|
|
WIDGET_TYPE_VIEW,
|
|
|
|
|
WIDGET_TYPE_COMBO_BOX,
|
|
|
|
|
WIDGET_TYPE_COMBO_BOX_ITEM,
|
|
|
|
|
WIDGET_TYPE_SLIDE_VIEW,
|
|
|
|
|
WIDGET_TYPE_PAGES,
|
|
|
|
|
WIDGET_TYPE_TAB_BUTTON,
|
|
|
|
|
WIDGET_TYPE_TAB_CONTROL,
|
|
|
|
|
WIDGET_TYPE_TAB_BUTTON_GROUP,
|
|
|
|
|
WIDGET_TYPE_BUTTON_GROUP,
|
|
|
|
|
WIDGET_TYPE_CANDIDATES,
|
|
|
|
|
WIDGET_TYPE_SPIN_BOX,
|
|
|
|
|
WIDGET_TYPE_DRAGGER,
|
|
|
|
|
WIDGET_TYPE_SCROLL_BAR,
|
|
|
|
|
WIDGET_TYPE_SCROLL_BAR_DESKTOP,
|
|
|
|
|
WIDGET_TYPE_SCROLL_BAR_MOBILE,
|
|
|
|
|
WIDGET_TYPE_SCROLL_VIEW,
|
|
|
|
|
WIDGET_TYPE_LIST_VIEW,
|
|
|
|
|
WIDGET_TYPE_LIST_VIEW_H,
|
|
|
|
|
WIDGET_TYPE_LIST_ITEM,
|
|
|
|
|
NULL};
|
|
|
|
|
void GenThemeData(uint8_t* buff, uint32_t size, uint32_t state_nr, uint32_t name_nr) {
|
2018-02-21 19:36:38 +08:00
|
|
|
|
ThemeGen g;
|
2018-08-01 12:53:59 +08:00
|
|
|
|
for (int32_t i = 0; widget_types[i]; i++) {
|
|
|
|
|
const char* type = widget_types[i];
|
2018-02-21 19:36:38 +08:00
|
|
|
|
for (uint32_t state = 0; state < state_nr; state++) {
|
2018-12-25 15:33:44 +08:00
|
|
|
|
Style s(type, TK_DEFAULT_STYLE, state_names[state]);
|
2018-12-25 18:00:46 +08:00
|
|
|
|
for (uint32_t k = 0; k < name_nr; k++) {
|
|
|
|
|
char name[32];
|
|
|
|
|
char value[32];
|
|
|
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "%d", k);
|
|
|
|
|
snprintf(value, sizeof(value), "%d", k);
|
|
|
|
|
|
2021-01-29 12:42:14 +08:00
|
|
|
|
s.AddValue(name, k);
|
|
|
|
|
s.AddValue(name, value);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
g.AddStyle(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-08 16:39:01 +08:00
|
|
|
|
wbuffer_t wbuffer;
|
|
|
|
|
wbuffer_t* b = wbuffer_init(&wbuffer, buff, size);
|
|
|
|
|
g.Output(b);
|
|
|
|
|
wbuffer_deinit(b);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Theme, saveLoad) {
|
|
|
|
|
uint8_t v8;
|
|
|
|
|
uint16_t v16;
|
2021-01-29 12:42:14 +08:00
|
|
|
|
int32_t i32;
|
2018-02-21 19:36:38 +08:00
|
|
|
|
uint32_t v32;
|
2021-01-29 12:42:14 +08:00
|
|
|
|
uint8_t buff[15];
|
2018-02-21 19:36:38 +08:00
|
|
|
|
uint8_t* p = buff;
|
|
|
|
|
|
|
|
|
|
save_uint8(p, 0x1f);
|
|
|
|
|
save_uint16(p, 0x2f2f);
|
2021-01-29 12:42:14 +08:00
|
|
|
|
save_int32(p, 50);
|
|
|
|
|
save_int32(p, -100);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
save_uint32(p, 0x3f3f3f3f);
|
|
|
|
|
|
|
|
|
|
p = buff;
|
|
|
|
|
load_uint8(p, v8);
|
|
|
|
|
ASSERT_EQ(v8, 0x1f);
|
|
|
|
|
|
|
|
|
|
load_uint16(p, v16);
|
|
|
|
|
ASSERT_EQ(v16, 0x2f2f);
|
|
|
|
|
|
2021-01-29 12:42:14 +08:00
|
|
|
|
load_int32(p, i32);
|
|
|
|
|
ASSERT_EQ(i32, 50);
|
|
|
|
|
|
|
|
|
|
load_int32(p, i32);
|
|
|
|
|
ASSERT_EQ(i32, -100);
|
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
load_uint32(p, v32);
|
|
|
|
|
ASSERT_EQ(v32, 0x3f3f3f3f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Theme, basic) {
|
2018-12-25 18:00:46 +08:00
|
|
|
|
uint8_t buff[40 * 10240];
|
2018-02-21 19:36:38 +08:00
|
|
|
|
uint32_t state_nr = 5;
|
|
|
|
|
uint32_t name_nr = 5;
|
|
|
|
|
theme_t t;
|
2018-10-27 18:34:18 +08:00
|
|
|
|
const uint8_t* style_data;
|
2021-04-28 09:03:35 +08:00
|
|
|
|
|
|
|
|
|
memset(&t, 0x00, sizeof(t));
|
2018-08-01 12:53:59 +08:00
|
|
|
|
GenThemeData(buff, sizeof(buff), state_nr, name_nr);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
t.data = buff;
|
|
|
|
|
|
2018-08-01 12:53:59 +08:00
|
|
|
|
for (int32_t i = 0; widget_types[i]; i++) {
|
|
|
|
|
const char* type = widget_types[i];
|
2018-02-21 19:36:38 +08:00
|
|
|
|
for (uint32_t state = 0; state < state_nr; state++) {
|
2018-12-25 15:33:44 +08:00
|
|
|
|
style_data = theme_find_style(&t, type, 0, state_names[state]);
|
2018-10-27 18:34:18 +08:00
|
|
|
|
ASSERT_EQ(style_data != NULL, true);
|
2021-01-29 12:42:14 +08:00
|
|
|
|
ASSERT_EQ(tk_str_eq(theme_get_style_type(&t), THEME_DEFAULT_STYLE_TYPE), true);
|
|
|
|
|
style_t* s = style_factory_create_style(NULL, theme_get_style_type(&t));
|
|
|
|
|
ASSERT_EQ(s != NULL, true);
|
|
|
|
|
ASSERT_EQ(style_set_style_data(s, style_data, NULL), RET_OK);
|
2018-12-25 18:00:46 +08:00
|
|
|
|
for (uint32_t k = 0; k < name_nr; k++) {
|
|
|
|
|
char name[32];
|
|
|
|
|
snprintf(name, sizeof(name), "%d", k);
|
2021-02-01 18:12:36 +08:00
|
|
|
|
uint32_t v = (uint32_t)style_get_int(s, name, 0);
|
2018-12-25 18:00:46 +08:00
|
|
|
|
ASSERT_EQ(v, k);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
2021-01-29 12:42:14 +08:00
|
|
|
|
ASSERT_EQ(style_destroy(s), RET_OK);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|