2018-06-27 13:46:42 +08:00
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
#include "base/array.h"
|
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-06-12 08:55:18 +08:00
|
|
|
|
#include "base/buffer.h"
|
2018-02-21 19:36:38 +08:00
|
|
|
|
#include "tools/theme_gen/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;
|
|
|
|
|
|
|
|
|
|
void GenThemeData(uint8_t* buff, uint32_t size, uint32_t type_nr, uint32_t state_nr,
|
|
|
|
|
uint32_t name_nr) {
|
|
|
|
|
ThemeGen g;
|
|
|
|
|
for (uint32_t type = 0; type < type_nr; type++) {
|
|
|
|
|
for (uint32_t state = 0; state < state_nr; state++) {
|
2018-06-25 17:27:17 +08:00
|
|
|
|
const key_type_value_t* kv = widget_type_find_by_value(type);
|
|
|
|
|
|
2018-07-17 11:27:14 +08:00
|
|
|
|
Style s(kv->name, TK_DEFAULT_STYLE, state);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
for (uint32_t name = 0; name < name_nr; name++) {
|
|
|
|
|
char str[32];
|
|
|
|
|
snprintf(str, sizeof(str), "%d", name);
|
|
|
|
|
s.AddInt(name, name);
|
|
|
|
|
s.AddString(name, str);
|
|
|
|
|
}
|
|
|
|
|
g.AddStyle(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g.Output(buff, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Theme, saveLoad) {
|
|
|
|
|
uint8_t v8;
|
|
|
|
|
uint16_t v16;
|
|
|
|
|
uint32_t v32;
|
|
|
|
|
uint8_t buff[7];
|
|
|
|
|
uint8_t* p = buff;
|
|
|
|
|
|
|
|
|
|
save_uint8(p, 0x1f);
|
|
|
|
|
save_uint16(p, 0x2f2f);
|
|
|
|
|
save_uint32(p, 0x3f3f3f3f);
|
|
|
|
|
|
|
|
|
|
p = buff;
|
|
|
|
|
load_uint8(p, v8);
|
|
|
|
|
ASSERT_EQ(v8, 0x1f);
|
|
|
|
|
|
|
|
|
|
load_uint16(p, v16);
|
|
|
|
|
ASSERT_EQ(v16, 0x2f2f);
|
|
|
|
|
|
|
|
|
|
load_uint32(p, v32);
|
|
|
|
|
ASSERT_EQ(v32, 0x3f3f3f3f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Theme, basic) {
|
2018-06-24 18:03:28 +08:00
|
|
|
|
uint8_t buff[4 * 10240];
|
2018-03-30 22:15:45 +08:00
|
|
|
|
uint32_t type_nr = WIDGET_NR;
|
2018-02-21 19:36:38 +08:00
|
|
|
|
uint32_t state_nr = 5;
|
|
|
|
|
uint32_t name_nr = 5;
|
|
|
|
|
theme_t t;
|
|
|
|
|
style_t s;
|
|
|
|
|
|
|
|
|
|
GenThemeData(buff, sizeof(buff), type_nr, state_nr, name_nr);
|
|
|
|
|
t.data = buff;
|
|
|
|
|
|
2018-03-30 22:15:45 +08:00
|
|
|
|
for (uint32_t type = WIDGET_NONE + 1; type < WIDGET_NR; type++) {
|
2018-02-21 19:36:38 +08:00
|
|
|
|
for (uint32_t state = 0; state < state_nr; state++) {
|
2018-06-25 17:27:17 +08:00
|
|
|
|
const key_type_value_t* kv = widget_type_find_by_value(type);
|
|
|
|
|
|
|
|
|
|
s.data = theme_find_style(&t, kv->name, 0, state);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
ASSERT_EQ(s.data != NULL, true);
|
|
|
|
|
for (uint32_t name = 0; name < name_nr; name++) {
|
|
|
|
|
uint32_t v = style_get_int(&s, name, 0);
|
|
|
|
|
ASSERT_EQ(v, name);
|
|
|
|
|
v = atoi(style_get_str(&s, name, NULL));
|
|
|
|
|
ASSERT_EQ(v, name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|