重构代码的架构设计,增加测试单元,提高代码可靠性
This commit is contained in:
27
tests/test_p0_utf8_next.c
Normal file
27
tests/test_p0_utf8_next.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "../src/Drv/lcd/lcd_text.h"
|
||||
#include "test_common.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint32_t unicode = 0;
|
||||
const unsigned char ascii[] = "A";
|
||||
const unsigned char u2[] = {0xC2, 0xA2, 0x00}; /* U+00A2 */
|
||||
const unsigned char u3[] = {0xE4, 0xBD, 0xA0, 0x00}; /* U+4F60 */
|
||||
const unsigned char invalid[] = {0xF0, 0x00}; /* 4-byte start not supported */
|
||||
const unsigned char truncated2[] = {0xC2, 0x00};
|
||||
const unsigned char truncated3[] = {0xE4, 0xBD, 0x00};
|
||||
|
||||
ASSERT_EQ_INT(1, utf8_next(ascii, &unicode));
|
||||
ASSERT_EQ_U32(0x41u, unicode);
|
||||
|
||||
ASSERT_EQ_INT(2, utf8_next(u2, &unicode));
|
||||
ASSERT_EQ_U32(0x00A2u, unicode);
|
||||
|
||||
ASSERT_EQ_INT(3, utf8_next(u3, &unicode));
|
||||
ASSERT_EQ_U32(0x4F60u, unicode);
|
||||
|
||||
ASSERT_EQ_INT(0, utf8_next(invalid, &unicode));
|
||||
ASSERT_EQ_INT(0, utf8_next(truncated2, &unicode));
|
||||
ASSERT_EQ_INT(0, utf8_next(truncated3, &unicode));
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user