forked from lc-soft/LCUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_charset.c
47 lines (40 loc) · 1.31 KB
/
test_charset.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <wchar.h>
#include <string.h>
#include <LCUI_Build.h>
#include <LCUI/util/logger.h>
#include <LCUI/util/charset.h>
#include "test.h"
#include "libtest.h"
void test_charset(void)
{
size_t len;
char str[64];
wchar_t wcs[64];
len = LCUI_DecodeUTF8String(wcs, "hello", 64);
it_b("test decode ascii string", len == 5 && wcscmp(wcs, L"hello") == 0,
TRUE);
#ifdef WIN32
len = LCUI_DecodeString(wcs, "简体中文", 64, ENCODING_ANSI);
it_b("test decode ansi string",
len == 4 && wcscmp(wcs, L"简体中文") == 0, TRUE);
len = LCUI_EncodeString(str, L"简体中文", 64, ENCODING_ANSI);
it_b("test encode unicode string to ansi",
len == strlen("简体中文") && strcmp(str, "简体中文") == 0, TRUE);
#else
len = LCUI_DecodeUTF8String(wcs, "简体中文", 64);
it_b("test decode utf-8 string",
len == 4 && wcscmp(wcs, L"简体中文") == 0, TRUE);
len = LCUI_EncodeUTF8String(str, L"简体中文", 64);
it_b("test encode unicode string to utf-8",
len == strlen("简体中文") && strcmp(str, "简体中文") == 0, TRUE);
#endif
len = LCUI_EncodeUTF8String(str, L"hello", 64);
it_b("test encode ascii string to utf-8",
len == 5 && strcmp(str, "hello") == 0, TRUE);
}
#ifdef PREVIEW_MODE
int main(void)
{
test_charset();
}
#endif