2021-12-24 13:35:28 +08:00
|
|
|
|
#include "tkc/utf8.h"
|
|
|
|
|
#include "charset/encoding.h"
|
2020-08-19 10:55:25 +08:00
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
TEST(Encoding, basic) {
|
2021-12-24 13:35:28 +08:00
|
|
|
|
char str[16];
|
|
|
|
|
const wchar_t* wstr = L"中文";
|
|
|
|
|
tk_utf8_from_utf16(wstr, str, sizeof(str));
|
|
|
|
|
|
2020-08-19 10:55:25 +08:00
|
|
|
|
char gbk[32];
|
|
|
|
|
char utf8[32];
|
2020-08-20 10:14:39 +08:00
|
|
|
|
ASSERT_EQ(encoding_utf8_to_gbk(str, strlen(str), gbk, sizeof(gbk)), RET_OK);
|
|
|
|
|
ASSERT_EQ(encoding_gbk_to_utf8(gbk, strlen(gbk), utf8, sizeof(utf8)), RET_OK);
|
2020-08-19 10:55:25 +08:00
|
|
|
|
ASSERT_STREQ(str, utf8);
|
|
|
|
|
}
|