5#include "testing/testing.h"
52#define STR_MB_ALPHA_1 "\x41"
53#define STR_MB_ALPHA_2 "\xc2\xaa"
54#define STR_MB_ALPHA_3 "\xe0\xa0\x80"
55#define STR_MB_ALPHA_4 "\xf0\x90\x80\x80"
61#define STR_MB_ALPHA_5 "\xf8\x80\x80\x80\x80"
62#define STR_MB_ALPHA_6 "\xfc\x80\x80\x80\x80\x80"
79 {
"You should see the Greek word 'kosme': \"\xce\xba\xe1\xbd\xb9\xcf\x83\xce\xbc\xce\xb5\" |",
80 "You should see the Greek word 'kosme': \"\xce\xba\xe1\xbd\xb9\xcf\x83\xce\xbc\xce\xb5\" |",
"\x00"},
86 {
"2.1.1 1 byte (U-00000000): \"\x00\" |",
87 "2.1.1 1 byte (U-00000000): \"\" |",
"\x01"},
88 {
"2.1.2 2 bytes (U-00000080): \"\xc2\x80\" |",
89 "2.1.2 2 bytes (U-00000080): \"\xc2\x80\" |",
"\x00"},
90 {
"2.1.3 3 bytes (U-00000800): \"\xe0\xa0\x80\" |",
91 "2.1.3 3 bytes (U-00000800): \"\xe0\xa0\x80\" |",
"\x00"},
92 {
"2.1.4 4 bytes (U-00010000): \"\xf0\x90\x80\x80\" |",
93 "2.1.4 4 bytes (U-00010000): \"\xf0\x90\x80\x80\" |",
"\x00"},
94 {
"2.1.5 5 bytes (U-00200000): \"\xf8\x88\x80\x80\x80\" |",
95 "2.1.5 5 bytes (U-00200000): \"\xf8\x88\x80\x80\x80\" |",
"\x00"},
96 {
"2.1.6 6 bytes (U-04000000): \"\xfc\x84\x80\x80\x80\x80\" |",
97 "2.1.6 6 bytes (U-04000000): \"\xfc\x84\x80\x80\x80\x80\" |",
"\x00"},
99 {
"2.2.1 1 byte (U-0000007F): \"\x7f\" |",
100 "2.2.1 1 byte (U-0000007F): \"\x7f\" |",
"\x00"},
101 {
"2.2.2 2 bytes (U-000007FF): \"\xdf\xbf\" |",
102 "2.2.2 2 bytes (U-000007FF): \"\xdf\xbf\" |",
"\x00"},
103 {
"2.2.3 3 bytes (U-0000FFFF): \"\xef\xbf\xbf\" |",
104 "2.2.3 3 bytes (U-0000FFFF): \"\" |",
"\x03"},
105 {
"2.2.4 4 bytes (U-001FFFFF): \"\xf7\xbf\xbf\xbf\" |",
106 "2.2.4 4 bytes (U-001FFFFF): \"\xf7\xbf\xbf\xbf\" |",
"\x00"},
107 {
"2.2.5 5 bytes (U-03FFFFFF): \"\xfb\xbf\xbf\xbf\xbf\" |",
108 "2.2.5 5 bytes (U-03FFFFFF): \"\xfb\xbf\xbf\xbf\xbf\" |",
"\x00"},
109 {
"2.2.6 6 bytes (U-7FFFFFFF): \"\xfd\xbf\xbf\xbf\xbf\xbf\" |",
110 "2.2.6 6 bytes (U-7FFFFFFF): \"\xfd\xbf\xbf\xbf\xbf\xbf\" |",
"\x00"},
112 {
"2.3.1 U-0000D7FF = ed 9f bf = \"\xed\x9f\xbf\" |",
113 "2.3.1 U-0000D7FF = ed 9f bf = \"\xed\x9f\xbf\" |",
"\x00"},
114 {
"2.3.2 U-0000E000 = ee 80 80 = \"\xee\x80\x80\" |",
115 "2.3.2 U-0000E000 = ee 80 80 = \"\xee\x80\x80\" |",
"\x00"},
116 {
"2.3.3 U-0000FFFD = ef bf bd = \"\xef\xbf\xbd\" |",
117 "2.3.3 U-0000FFFD = ef bf bd = \"\xef\xbf\xbd\" |",
"\x00"},
118 {
"2.3.4 U-0010FFFF = f4 8f bf bf = \"\xf4\x8f\xbf\xbf\" |",
119 "2.3.4 U-0010FFFF = f4 8f bf bf = \"\xf4\x8f\xbf\xbf\" |",
"\x00"},
120 {
"2.3.5 U-00110000 = f4 90 80 80 = \"\xf4\x90\x80\x80\" |",
121 "2.3.5 U-00110000 = f4 90 80 80 = \"\xf4\x90\x80\x80\" |",
"\x00"},
126 {
"3.1.1 First continuation byte 0x80: \"\x80\" |",
127 "3.1.1 First continuation byte 0x80: \"\" |",
"\x01"},
128 {
"3.1.2 Last continuation byte 0xbf: \"\xbf\" |",
129 "3.1.2 Last continuation byte 0xbf: \"\" |",
"\x01"},
130 {
"3.1.3 2 continuation bytes: \"\x80\xbf\" |",
131 "3.1.3 2 continuation bytes: \"\" |",
"\x02"},
132 {
"3.1.4 3 continuation bytes: \"\x80\xbf\x80\" |",
133 "3.1.4 3 continuation bytes: \"\" |",
"\x03"},
134 {
"3.1.5 4 continuation bytes: \"\x80\xbf\x80\xbf\" |",
135 "3.1.5 4 continuation bytes: \"\" |",
"\x04"},
136 {
"3.1.6 5 continuation bytes: \"\x80\xbf\x80\xbf\x80\" |",
137 "3.1.6 5 continuation bytes: \"\" |",
"\x05"},
138 {
"3.1.7 6 continuation bytes: \"\x80\xbf\x80\xbf\x80\xbf\" |",
139 "3.1.7 6 continuation bytes: \"\" |",
"\x06"},
140 {
"3.1.8 7 continuation bytes: \"\x80\xbf\x80\xbf\x80\xbf\x80\" |",
141 "3.1.8 7 continuation bytes: \"\" |",
"\x07"},
143 {
"3.1.9 \"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
144 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
145 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
146 "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\" |",
147 "3.1.9 \"\" |",
"\x40"},
150 {
"3.2.1 \"\xc0 \xc1 \xc2 \xc3 \xc4 \xc5 \xc6 \xc7 \xc8 \xc9 \xca \xcb \xcc \xcd \xce \xcf "
151 "\xd0 \xd1 \xd2 \xd3 \xd4 \xd5 \xd6 \xd7 \xd8 \xd9 \xda \xdb \xdc \xdd \xde \xdf \" |",
152 "3.2.1 \" \" |",
"\x20"},
154 {
"3.2.2 \"\xe0 \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea \xeb \xec \xed \xee \xef \" |",
155 "3.2.2 \" \" |",
"\x10"},
157 {
"3.2.3 \"\xf0 \xf1 \xf2 \xf3 \xf4 \xf5 \xf6 \xf7 \" |",
158 "3.2.3 \" \" |",
"\x08"},
160 {
"3.2.4 \"\xf8 \xf9 \xfa \xfb \" |",
161 "3.2.4 \" \" |",
"\x04"},
163 {
"3.2.4 \"\xfc \xfd \" |",
164 "3.2.4 \" \" |",
"\x02"},
169 {
"3.3.1 2-byte sequence with last byte missing (U+0000): \"\xc0\" |",
170 "3.3.1 2-byte sequence with last byte missing (U+0000): \"\" |",
"\x01"},
171 {
"3.3.2 3-byte sequence with last byte missing (U+0000): \"\xe0\x80\" |",
172 "3.3.2 3-byte sequence with last byte missing (U+0000): \"\" |",
"\x02"},
173 {
"3.3.3 4-byte sequence with last byte missing (U+0000): \"\xf0\x80\x80\" |",
174 "3.3.3 4-byte sequence with last byte missing (U+0000): \"\" |",
"\x03"},
175 {
"3.3.4 5-byte sequence with last byte missing (U+0000): \"\xf8\x80\x80\x80\" |",
176 "3.3.4 5-byte sequence with last byte missing (U+0000): \"\" |",
"\x04"},
177 {
"3.3.5 6-byte sequence with last byte missing (U+0000): \"\xfc\x80\x80\x80\x80\" |",
178 "3.3.5 6-byte sequence with last byte missing (U+0000): \"\" |",
"\x05"},
179 {
"3.3.6 2-byte sequence with last byte missing (U-000007FF): \"\xdf\" |",
180 "3.3.6 2-byte sequence with last byte missing (U-000007FF): \"\" |",
"\x01"},
181 {
"3.3.7 3-byte sequence with last byte missing (U-0000FFFF): \"\xef\xbf\" |",
182 "3.3.7 3-byte sequence with last byte missing (U-0000FFFF): \"\" |",
"\x02"},
183 {
"3.3.8 4-byte sequence with last byte missing (U-001FFFFF): \"\xf7\xbf\xbf\" |",
184 "3.3.8 4-byte sequence with last byte missing (U-001FFFFF): \"\" |",
"\x03"},
185 {
"3.3.9 5-byte sequence with last byte missing (U-03FFFFFF): \"\xfb\xbf\xbf\xbf\" |",
186 "3.3.9 5-byte sequence with last byte missing (U-03FFFFFF): \"\" |",
"\x04"},
187 {
"3.3.10 6-byte sequence with last byte missing (U-7FFFFFFF): \"\xfd\xbf\xbf\xbf\xbf\" |",
188 "3.3.10 6-byte sequence with last byte missing (U-7FFFFFFF): \"\" |",
"\x05"},
191 {
"3.4 \"\xc0\xe0\x80\xf0\x80\x80\xf8\x80\x80\x80\xfc\x80\x80\x80\x80"
192 "\xdf\xef\xbf\xf7\xbf\xbf\xfb\xbf\xbf\xbf\xfd\xbf\xbf\xbf\xbf\""
194 "3.4 \"\" |",
"\x1e"},
197 {
"3.5.1 fe = \"\xfe\" |",
198 "3.5.1 fe = \"\" |",
"\x01"},
199 {
"3.5.2 ff = \"\xff\" |",
200 "3.5.2 ff = \"\" |",
"\x01"},
201 {
"3.5.3 fe fe ff ff = \"\xfe\xfe\xff\xff\" |",
202 "3.5.3 fe fe ff ff = \"\" |",
"\x04"},
222 {
"4.1.1 U+002F = c0 af = \"\xc0\xaf\" |",
223 "4.1.1 U+002F = c0 af = \"\" |",
"\x02"},
224 {
"4.1.2 U+002F = e0 80 af = \"\xe0\x80\xaf\" |",
225 "4.1.2 U+002F = e0 80 af = \"\" |",
"\x03"},
226 {
"4.1.3 U+002F = f0 80 80 af = \"\xf0\x80\x80\xaf\" |",
227 "4.1.3 U+002F = f0 80 80 af = \"\" |",
"\x04"},
228 {
"4.1.4 U+002F = f8 80 80 80 af = \"\xf8\x80\x80\x80\xaf\" |",
229 "4.1.4 U+002F = f8 80 80 80 af = \"\" |",
"\x05"},
230 {
"4.1.5 U+002F = fc 80 80 80 80 af = \"\xfc\x80\x80\x80\x80\xaf\" |",
231 "4.1.5 U+002F = fc 80 80 80 80 af = \"\" |",
"\x06"},
236 {
"4.2.1 U-0000007F = c1 bf = \"\xc1\xbf\" |",
237 "4.2.1 U-0000007F = c1 bf = \"\" |",
"\x02"},
238 {
"4.2.2 U-000007FF = e0 9f bf = \"\xe0\x9f\xbf\" |",
239 "4.2.2 U-000007FF = e0 9f bf = \"\" |",
"\x03"},
240 {
"4.2.3 U-0000FFFF = f0 8f bf bf = \"\xf0\x8f\xbf\xbf\" |",
241 "4.2.3 U-0000FFFF = f0 8f bf bf = \"\" |",
"\x04"},
242 {
"4.2.4 U-001FFFFF = f8 87 bf bf bf = \"\xf8\x87\xbf\xbf\xbf\" |",
243 "4.2.4 U-001FFFFF = f8 87 bf bf bf = \"\" |",
"\x05"},
244 {
"4.2.5 U+0000 = fc 83 bf bf bf bf = \"\xfc\x83\xbf\xbf\xbf\xbf\" |",
245 "4.2.5 U+0000 = fc 83 bf bf bf bf = \"\" |",
"\x06"},
249 {
"4.3.1 U+0000 = c0 80 = \"\xc0\x80\" |",
250 "4.3.1 U+0000 = c0 80 = \"\" |",
"\x02"},
251 {
"4.3.2 U+0000 = e0 80 80 = \"\xe0\x80\x80\" |",
252 "4.3.2 U+0000 = e0 80 80 = \"\" |",
"\x03"},
253 {
"4.3.3 U+0000 = f0 80 80 80 = \"\xf0\x80\x80\x80\" |",
254 "4.3.3 U+0000 = f0 80 80 80 = \"\" |",
"\x04"},
255 {
"4.3.4 U+0000 = f8 80 80 80 80 = \"\xf8\x80\x80\x80\x80\" |",
256 "4.3.4 U+0000 = f8 80 80 80 80 = \"\" |",
"\x05"},
257 {
"4.3.5 U+0000 = fc 80 80 80 80 80 = \"\xfc\x80\x80\x80\x80\x80\" |",
258 "4.3.5 U+0000 = fc 80 80 80 80 80 = \"\" |",
"\x06"},
265 {
"5.1.1 U+D800 = ed a0 80 = \"\xed\xa0\x80\" |",
266 "5.1.1 U+D800 = ed a0 80 = \"\" |",
"\x03"},
267 {
"5.1.2 U+DB7F = ed ad bf = \"\xed\xad\xbf\" |",
268 "5.1.2 U+DB7F = ed ad bf = \"\" |",
"\x03"},
269 {
"5.1.3 U+DB80 = ed ae 80 = \"\xed\xae\x80\" |",
270 "5.1.3 U+DB80 = ed ae 80 = \"\" |",
"\x03"},
271 {
"5.1.4 U+DBFF = ed af bf = \"\xed\xaf\xbf\" |",
272 "5.1.4 U+DBFF = ed af bf = \"\" |",
"\x03"},
273 {
"5.1.5 U+DC00 = ed b0 80 = \"\xed\xb0\x80\" |",
274 "5.1.5 U+DC00 = ed b0 80 = \"\" |",
"\x03"},
275 {
"5.1.6 U+DF80 = ed be 80 = \"\xed\xbe\x80\" |",
276 "5.1.6 U+DF80 = ed be 80 = \"\" |",
"\x03"},
277 {
"5.1.7 U+DFFF = ed bf bf = \"\xed\xbf\xbf\" |",
278 "5.1.7 U+DFFF = ed bf bf = \"\" |",
"\x03"},
280 {
"5.2.1 U+D800 U+DC00 = ed a0 80 ed b0 80 = \"\xed\xa0\x80\xed\xb0\x80\" |",
281 "5.2.1 U+D800 U+DC00 = ed a0 80 ed b0 80 = \"\" |",
"\x06"},
282 {
"5.2.2 U+D800 U+DFFF = ed a0 80 ed bf bf = \"\xed\xa0\x80\xed\xbf\xbf\" |",
283 "5.2.2 U+D800 U+DFFF = ed a0 80 ed bf bf = \"\" |",
"\x06"},
284 {
"5.2.3 U+DB7F U+DC00 = ed ad bf ed b0 80 = \"\xed\xad\xbf\xed\xb0\x80\" |",
285 "5.2.3 U+DB7F U+DC00 = ed ad bf ed b0 80 = \"\" |",
"\x06"},
286 {
"5.2.4 U+DB7F U+DFFF = ed ad bf ed bf bf = \"\xed\xad\xbf\xed\xbf\xbf\" |",
287 "5.2.4 U+DB7F U+DFFF = ed ad bf ed bf bf = \"\" |",
"\x06"},
288 {
"5.2.5 U+DB80 U+DC00 = ed ae 80 ed b0 80 = \"\xed\xae\x80\xed\xb0\x80\" |",
289 "5.2.5 U+DB80 U+DC00 = ed ae 80 ed b0 80 = \"\" |",
"\x06"},
290 {
"5.2.6 U+DB80 U+DFFF = ed ae 80 ed bf bf = \"\xed\xae\x80\xed\xbf\xbf\" |",
291 "5.2.6 U+DB80 U+DFFF = ed ae 80 ed bf bf = \"\" |",
"\x06"},
292 {
"5.2.7 U+DBFF U+DC00 = ed af bf ed b0 80 = \"\xed\xaf\xbf\xed\xb0\x80\" |",
293 "5.2.7 U+DBFF U+DC00 = ed af bf ed b0 80 = \"\" |",
"\x06"},
294 {
"5.2.8 U+DBFF U+DFFF = ed af bf ed bf bf = \"\xed\xaf\xbf\xed\xbf\xbf\" |",
295 "5.2.8 U+DBFF U+DFFF = ed af bf ed bf bf = \"\" |",
"\x06"},
310 {
"5.3.1 U+FFFE = ef bf be = \"\xef\xbf\xbe\" |",
311 "5.3.1 U+FFFE = ef bf be = \"\" |",
"\x03"},
312 {
"5.3.2 U+FFFF = ef bf bf = \"\xef\xbf\xbf\" |",
313 "5.3.2 U+FFFF = ef bf bf = \"\" |",
"\x03"},
317 {
nullptr,
nullptr,
nullptr},
322TEST(
string, Utf8InvalidBytesStrip)
330 memcpy(buff, tst,
sizeof(buff));
334 printf(
"[%02d] -> [%02d] \"%s\" -> \"%s\"\n", errors_num, errors_found_num, tst, buff);
336 EXPECT_STREQ(buff, tst_stripped);
341TEST(
string, Utf8InvalidBytesSubstitute)
348 memcpy(buff, tst,
sizeof(buff));
354 EXPECT_EQ(strlen(buff),
sizeof(buff) - 1);
358TEST(
string, Utf8InvalidBytesSubstitutePatterns)
360#define TEST_SIMPLE(src_chars, expected_error_count, expected_str) \
362 char buff[] = src_chars; \
363 EXPECT_EQ(BLI_str_utf8_invalid_substitute(buff, strlen(buff), '?'), expected_error_count); \
364 EXPECT_STREQ(buff, expected_str); \
368#define ARRAY_ARG(...) __VA_ARGS__
400TEST(
string, StringNLenUTF8_Incomplete)
402 const char *ref_str =
405 const size_t ref_str_len = 21;
407#define EXPECT_BYTE_OFFSET(truncate_ofs, expect_nchars) \
409 size_t buf_ofs = 0; \
410 STRNCPY(buf, ref_str); \
411 buf[truncate_ofs] = '\0'; \
412 EXPECT_EQ(BLI_strnlen_utf8_ex(buf, ref_str_len, &buf_ofs), expect_nchars); \
413 EXPECT_EQ(buf_ofs, truncate_ofs); \
444#undef EXPECT_BYTE_OFFSET
455#define STRNCPY_UTF8_ASCII(...) \
457 const char src[] = {__VA_ARGS__, 0}; \
458 char dst[sizeof(src)]; \
459 memset(dst, 0xff, sizeof(dst)); \
460 STRNCPY_UTF8(dst, src); \
461 EXPECT_EQ(strlen(dst), sizeof(dst) - 1); \
462 EXPECT_STREQ(dst, src); \
468#undef STRNCPY_UTF8_ASCII
471TEST(
string, StrCopyUTF8_ASCII_Truncate)
473#define STRNCPY_UTF8_ASCII_TRUNCATE(maxncpy, ...) \
475 char src[] = {__VA_ARGS__}; \
476 char dst[sizeof(src)]; \
477 memset(dst, 0xff, sizeof(dst)); \
478 BLI_strncpy_utf8(dst, src, maxncpy); \
479 int len_expect = std::min<int>(sizeof(src), maxncpy) - 1; \
480 src[len_expect] = '\0'; \
481 EXPECT_EQ(strlen(dst), len_expect); \
482 EXPECT_STREQ(dst, src); \
488#undef STRNCPY_UTF8_ASCII_TRUNCATE
491TEST(
string, StrCopyUTF8_TruncateEncoding)
494#define STRNCPY_UTF8_TRUNCATE(byte_size, ...) \
496 const char src[] = {__VA_ARGS__, 0}; \
497 EXPECT_EQ(BLI_str_utf8_size_or_error(src), byte_size); \
498 char dst[sizeof(src)]; \
499 memset(dst, 0xff, sizeof(dst)); \
500 STRNCPY_UTF8(dst, src); \
501 EXPECT_EQ(strlen(dst), sizeof(dst) - 1); \
502 EXPECT_STREQ(dst, src); \
503 BLI_strncpy_utf8(dst, src, sizeof(dst) - 1); \
504 EXPECT_STREQ(dst, ""); \
514#undef STRNCPY_UTF8_TRUNCATE
517TEST(
string, StrCopyUTF8_TruncateEncodingMulti)
519#define STRNCPY_UTF8_TRUNC_EXPECT(src, dst_expect, dst_maxncpy) \
521 char dst[dst_maxncpy + 1]; \
522 dst[dst_maxncpy] = 0xff; \
523 size_t len = BLI_strncpy_utf8_rlen(dst, src, dst_maxncpy); \
524 EXPECT_EQ(len, strlen(dst)); \
525 EXPECT_STREQ(dst, dst_expect); \
526 EXPECT_EQ(dst[dst_maxncpy], 0xff); \
614#undef STRNCPY_UTF8_TRUNC_EXPECT
617TEST(
string, StrCopyUTF8_TerminateEncodingEarly)
621#define STRNCPY_UTF8_TERMINATE_EARLY(byte_size, ...) \
623 char src[] = {__VA_ARGS__, 0}; \
624 EXPECT_EQ(BLI_str_utf8_size_or_error(src), byte_size); \
625 char dst[sizeof(src)]; \
626 memset(dst, 0xff, sizeof(dst)); \
627 STRNCPY_UTF8(dst, src); \
628 EXPECT_EQ(strlen(dst), sizeof(dst) - 1); \
629 EXPECT_STREQ(dst, src); \
630 for (int i = sizeof(dst) - 1; i > 1; i--) { \
632 memset(dst, 0xff, sizeof(dst)); \
633 const int dst_copied = STRNCPY_UTF8_RLEN(dst, src); \
634 EXPECT_STREQ(dst, src); \
635 EXPECT_EQ(strlen(dst), i); \
636 EXPECT_EQ(dst_copied, i); \
647#undef STRNCPY_UTF8_TERMINATE_EARLY
656TEST(
string, StrPrintfUTF8_ASCII)
658#define SNPRINTF_UTF8_ASCII(...) \
660 const char src[] = {__VA_ARGS__, 0}; \
661 char dst[sizeof(src)]; \
662 memset(dst, 0xff, sizeof(dst)); \
663 SNPRINTF_UTF8(dst, "%s", src); \
664 EXPECT_EQ(strlen(dst), sizeof(dst) - 1); \
665 EXPECT_STREQ(dst, src); \
671#undef SNPRINTF_UTF8_ASCII
674TEST(
string, StrPrintfUTF8_TerminateEncodingEarly)
678#define SNPRINTF_UTF8_TERMINATE_EARLY(byte_size, ...) \
680 char src[] = {__VA_ARGS__, 0}; \
681 EXPECT_EQ(BLI_str_utf8_size_or_error(src), byte_size); \
682 char dst[sizeof(src)]; \
683 memset(dst, 0xff, sizeof(dst)); \
684 SNPRINTF_UTF8(dst, "%s", src); \
685 EXPECT_EQ(strlen(dst), sizeof(dst) - 1); \
686 EXPECT_STREQ(dst, src); \
687 for (int i = sizeof(dst) - 1; i > 1; i--) { \
689 memset(dst, 0xff, sizeof(dst)); \
690 const int dst_copied = SNPRINTF_UTF8_RLEN(dst, "%s", src); \
691 EXPECT_STREQ(dst, src); \
692 EXPECT_EQ(strlen(dst), i); \
693 EXPECT_EQ(dst_copied, i); \
704#undef STRNCPY_UTF8_TERMINATE_EARLY
707TEST(
string, StrPrintfUTF8_TruncateEncodingMulti)
709#define SNPRINTF_UTF8_TRUNC_EXPECT(src, dst_expect, dst_maxncpy) \
711 char dst[dst_maxncpy + 1]; \
712 dst[dst_maxncpy] = 0xff; \
713 size_t len = BLI_snprintf_utf8_rlen(dst, dst_maxncpy, "%s", src); \
714 EXPECT_EQ(len, strlen(dst)); \
715 EXPECT_STREQ(dst, dst_expect); \
716 EXPECT_EQ(dst[dst_maxncpy], 0xff); \
753#undef STRNCPY_UTF8_TRUNC_EXPECT
762TEST(
string, Utf8OffsetFromIndex_ClampedIndex)
766 const char *test_strings[] = {
777 const char *
str = test_strings[
i];
778 const size_t str_len = strlen(
str);
795 size_t i = 0, result_len = 0;
796 while ((
i < str_len) && (
str[
i] !=
'\0')) {
802template<
size_t Size,
size_t SizeWithPadding>
805 char utf8_src_with_pad[SizeWithPadding] = {0};
807 memcpy(utf8_src_with_pad, utf8_src, Size);
809 char32_t unicode_dst_a[Size], unicode_dst_b[Size];
811 memset(unicode_dst_a, 0xff,
sizeof(unicode_dst_a));
812 const size_t index_a =
utf8_as_char32(utf8_src, Size, unicode_dst_a);
816 for (
int pass = 0; pass < 2; pass++) {
817 memset(unicode_dst_b, 0xff,
sizeof(unicode_dst_b));
819 utf8_src_with_pad, pass ? Size : SizeWithPadding, unicode_dst_b);
822 EXPECT_EQ_ARRAY(unicode_dst_a, unicode_dst_b, Size);
842 for (
int i = 0;
i <= 0xff;
i++) {
843 memset(utf8_src,
i,
sizeof(utf8_src));
849 for (
int ofs = 1; ofs < int(Size); ofs++) {
850 utf8_src[ofs] = char(
i + (ofs *
mul));
854 for (
int ofs = 1; ofs < int(Size); ofs++) {
855 utf8_src[ofs] = char(
i - (ofs *
mul));
864 for (
int i = 0;
i < 256;
i++) {
895TEST(
string, StrCursorStepNextUtf32Empty)
897 const char32_t empty[] =
U"";
898 const size_t len = 0;
911TEST(
string, StrCursorStepNextUtf32Single)
914 const char32_t single[] =
U"0";
915 const size_t len = 1;
927TEST(
string, StrCursorStepNextUtf32Simple)
929 const char32_t simple[] =
U"012";
930 const size_t len = 3;
945TEST(
string, StrCursorStepNextUtf32AllCombining)
947 const char32_t allcombining[] =
U"\u0300\u0300\u0300";
948 const size_t len = 3;
965TEST(
string, StrCursorStepNextUtf32Complex)
968 const char32_t complex[] =
U"\u0300\u0041\u0300\u0320\u0042";
969 const size_t len = 5;
990TEST(
string, StrCursorStepNextUtf32Invalid)
993 const char32_t invalid[] =
U"\u00C0\u0300\u0009\u0300\u000D\u0300\u000A\u0300";
994 const size_t len = 8;
1021TEST(
string, StrCursorStepPrevUtf32Empty)
1023 const char32_t emtpy[] =
U"";
1024 const size_t len = 0;
1035TEST(
string, StrCursorStepPrevUtf32Single)
1037 const char32_t single[] =
U"0";
1038 const size_t len = 1;
1050TEST(
string, StrCursorStepPrevUtf32Simple)
1052 const char32_t simple[] =
U"012";
1053 const size_t len = 3;
1067TEST(
string, StrCursorStepPrevUtf32AllCombining)
1069 const char32_t allcombining[] =
U"\u0300\u0300\u0300";
1070 const size_t len = 3;
1087TEST(
string, StrCursorStepPrevUtf32Complex)
1090 const char32_t complex[] =
U"\u0300\u0041\u0300\u0320\u0042";
1091 const size_t len = 5;
1112TEST(
string, StrCursorStepPrevUtf32Invalid)
1115 const char32_t invalid[] =
U"\u00C0\u0300\u0009\u0300\u000D\u0300\u000A\u0300";
1116 const size_t len = 8;
1142TEST(
string, StrCursorStepNextUtf8Empty)
1144 const char empty[] =
"";
1145 const size_t len = 0;
1157TEST(
string, StrCursorStepNextUtf8Single)
1159 const char single[] =
"0";
1160 const size_t len = 1;
1172TEST(
string, StrCursorStepNextUtf8Simple)
1174 const char simple[] =
"012";
1175 const size_t len = 3;
1190TEST(
string, StrCursorStepNextUtf8AllCombining)
1192 const char allcombining[] =
"\xCC\x80\xCC\x80\xCC\x80";
1193 const size_t len = 6;
1216TEST(
string, StrCursorStepNextUtf8AllComplex)
1219 const char complex[] =
"\xCC\x80\x41\xC2\xA9\xCC\x80\xCC\xA0\x42";
1220 const size_t len = 10;
1251TEST(
string, StrCursorStepNextUtf8Invalid)
1254 const char invalid[] =
"\xC0\xCC\x80\x09\x0D\x0A\xCC\x80";
1255 const size_t len = 8;
1282TEST(
string, StrCursorStepPrevUtf8Empty)
1284 const char empty[] =
"";
1285 const size_t len = 0;
1298TEST(
string, StrCursorStepPrevUtf8Single)
1300 const char single[] =
"0";
1301 const size_t len = 1;
1313TEST(
string, StrCursorStepPrevUtf8Simple)
1315 const char simple[] =
"012";
1316 const size_t len = 3;
1330TEST(
string, StrCursorStepPrevUtf8AllCombining)
1332 const char allcombining[] =
"\xCC\x80\xCC\x80\xCC\x80";
1333 const size_t len = 6;
1356TEST(
string, StrCursorStepPrevUtf8Complex)
1359 const char complex[] =
"\xCC\x80\x41\xC2\xA9\xCC\x80\xCC\xA0\x42";
1360 const size_t len = 10;
1391TEST(
string, StrCursorStepPrevUtf8Invalid)
1394 const char invalid[] =
"\xC0\xCC\x80\x09\x0D\x0A\xCC\x80";
1395 const size_t len = 8;
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
struct RNG * BLI_rng_new(unsigned int seed)
void BLI_rng_free(struct RNG *rng) ATTR_NONNULL(1)
void BLI_rng_get_char_n(RNG *rng, char *bytes, size_t bytes_len) ATTR_NONNULL(1
bool BLI_str_cursor_step_prev_utf32(const char32_t *str, int str_maxlen, int *pos)
bool BLI_str_cursor_step_next_utf8(const char *str, int str_maxlen, int *pos)
bool BLI_str_cursor_step_prev_utf8(const char *str, int str_maxlen, int *pos)
bool BLI_str_cursor_step_next_utf32(const char32_t *str, int str_maxlen, int *pos)
int BLI_str_utf8_offset_from_index(const char *str, size_t str_len, int index_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_str_utf8_invalid_substitute(char *str, size_t str_len, const char substitute) ATTR_NONNULL(1)
ptrdiff_t BLI_str_utf8_invalid_byte(const char *str, size_t str_len) ATTR_NONNULL(1)
size_t size_t BLI_strnlen_utf8(const char *strc, size_t strc_maxlen) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
unsigned int BLI_str_utf8_as_unicode_step_safe(const char *__restrict p, size_t p_len, size_t *__restrict index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
int BLI_str_utf8_invalid_strip(char *str, size_t str_len) ATTR_NONNULL(1)
void utf8_as_char32_test_at_buffer_size()
#define SNPRINTF_UTF8_ASCII(...)
#define STRNCPY_UTF8_TRUNCATE(byte_size,...)
#define SNPRINTF_UTF8_TERMINATE_EARLY(byte_size,...)
#define EXPECT_BYTE_OFFSET(truncate_ofs, expect_nchars)
#define STRNCPY_UTF8_ASCII_TRUNCATE(maxncpy,...)
#define STRNCPY_UTF8_ASCII(...)
#define STRNCPY_UTF8_TERMINATE_EARLY(byte_size,...)
static size_t utf8_as_char32(const char *str, const char str_len, char32_t *r_result)
#define SNPRINTF_UTF8_TRUNC_EXPECT(src, dst_expect, dst_maxncpy)
void utf8_as_char32_test_compare_with_pad_bytes(const char utf8_src[Size])
void utf8_as_char32_test_compare(const char utf8_src[Size])
TEST(string, Utf8InvalidBytesStrip)
#define STRNCPY_UTF8_TRUNC_EXPECT(src, dst_expect, dst_maxncpy)
static const char * utf8_invalid_tests[][3]
#define TEST_SIMPLE(src_chars, expected_error_count, expected_str)
static void mul(btAlignedObjectArray< T > &items, const Q &value)