50 #define DATA(...) { __VA_ARGS__ } 53 #define UTF8_ACCUMULATE( name, BYTES, EXPECTED ) \ 54 static const char name ## _bytes[] = BYTES; \ 55 static const unsigned int name ## _expected[] = EXPECTED; \ 56 static struct utf8_accumulate_test name = { \ 57 .bytes = name ## _bytes, \ 58 .expected = name ## _expected, \ 59 .len = ( sizeof ( name ## _expected ) / \ 60 sizeof ( name ## _expected[0] ) ), \ 65 DATA (
'H',
'e',
'l',
'l',
'o',
' ',
66 'w',
'o',
'r',
'l',
'd',
'!' ) );
70 DATA (
'H', 0, L
'é',
'l',
'l', 0, L
'ô',
' ',
71 'w', 0, L
'ö',
'r',
'l',
'd',
' ',
76 DATA (
'a', 0x81,
'b', 0xc3, 0x82, 0x83,
'c' ),
77 DATA (
'a', 0xfffd,
'b', 0, 0xc2, 0xfffd,
'c' ) );
81 DATA (
'a', 0xc3,
'b', 0xe1, 0x86, 0xc3, 0x89,
'c' ),
82 DATA (
'a', 0,
'b', 0, 0, 0, 0xc9,
'c' ) );
86 DATA (
'a', 0xc2, 0x80,
'b', 0xc1, 0xbf,
'c', 0xc0, 0x80,
88 DATA (
'a', 0, 0x80,
'b', 0, 0xfffd,
'c', 0, 0xfffd,
'd' ) );
92 DATA (
'a', 0xe0, 0xa0, 0x80,
'b', 0xe0, 0x9f, 0xbf,
'c',
93 0xe0, 0x80, 0x80,
'd' ),
94 DATA (
'a', 0, 0, 0x800,
'b', 0, 0, 0xfffd,
'c',
95 0, 0, 0xfffd,
'd' ) );
99 DATA (
'a', 0xf0, 0x90, 0x80, 0x80,
'b', 0xf0, 0x8f, 0xbf,
100 0xbf,
'c', 0xf0, 0x80, 0x80, 0x80,
'd' ),
101 DATA (
'a', 0, 0, 0, 0x10000,
'b', 0, 0, 0, 0xfffd,
'c',
102 0, 0, 0, 0xfffd,
'd' ) );
106 DATA (
'a', 0xf8, 0xbf, 0xbf, 0xbf, 0xbf,
'b', 0xfc, 0xbf,
107 0xbf, 0xbf, 0xbf, 0xbf,
'c', 0xfe, 0xbf, 0xbf, 0xbf,
108 0xbf, 0xbf, 0xbf,
'd', 0xff, 0xbf, 0xbf, 0xbf, 0xbf,
109 0xbf, 0xbf, 0xbf,
'e' ),
110 DATA (
'a', 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
'b',
111 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
'c',
112 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
113 0xfffd,
'd', 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd,
114 0xfffd, 0xfffd, 0xfffd,
'e' ) );
124 const char *file,
unsigned int line ) {
130 memset ( &utf8, 0,
sizeof ( utf8 ) );
133 for ( i = 0 ; i <
test->len ; i++ ) {
135 DBGC (
test,
"UTF8 byte %02x character %02x\n",
140 #define utf8_accumulate_ok( test ) \ 141 utf8_accumulate_okx ( test, __FILE__, __LINE__ ) #define utf8_accumulate_ok(test)
Self-test infrastructure.
const char * name
Test set name.
A UTF-8 accumulation test.
#define UTF8_ACCUMULATE(name, BYTES, EXPECTED)
Define a UTF-8 accumulation test.
const unsigned int * expected
Expected character sequence.
#define okx(success, file, line)
Report test result.
#define DATA(...)
Define inline data.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
const char * bytes
UTF-8 byte string.
A UTF-8 character accumulator.
unsigned int utf8_accumulate(struct utf8_accumulator *utf8, uint8_t byte)
Accumulate Unicode character from UTF-8 byte sequence.
unsigned int character
Character in progress.
static void utf8_test_exec(void)
Perform UTF-8 self-test.
struct self_test utf8_test __self_test
UTF-8 self-test.
void * memset(void *dest, int character, size_t len) __nonnull
static void utf8_accumulate_okx(struct utf8_accumulate_test *test, const char *file, unsigned int line)
Report UTF-8 accumulation test result.