1 // SPDX-License-Identifier: GPL-2.0+
3 * Unit tests for Unicode functions
5 * Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de>
11 #include <efi_loader.h>
15 #include <test/test.h>
16 #include <test/suites.h>
19 /* Linker list entry for a Unicode test */
20 #define UNICODE_TEST(_name) UNIT_TEST(_name, 0, unicode_test)
22 /* Constants c1-c4 and d1-d4 encode the same letters */
24 /* Six characters translating to one utf-8 byte each. */
25 static const u16 c1
[] = {0x55, 0x2d, 0x42, 0x6f, 0x6f, 0x74, 0x00};
26 /* One character translating to two utf-8 bytes */
27 static const u16 c2
[] = {0x6b, 0x61, 0x66, 0x62, 0xe1, 0x74, 0x75, 0x72, 0x00};
28 /* Three characters translating to three utf-8 bytes each */
29 static const u16 c3
[] = {0x6f5c, 0x6c34, 0x8266, 0x00};
30 /* Three letters translating to four utf-8 bytes each */
31 static const u16 c4
[] = {0xd801, 0xdc8d, 0xd801, 0xdc96, 0xd801, 0xdc87,
34 /* Illegal utf-16 strings */
35 static const u16 i1
[] = {0x69, 0x31, 0xdc87, 0x6c, 0x00};
36 static const u16 i2
[] = {0x69, 0x32, 0xd801, 0xd801, 0x6c, 0x00};
37 static const u16 i3
[] = {0x69, 0x33, 0xd801, 0x00};
39 /* Six characters translating to one utf-16 word each. */
40 static const char d1
[] = {0x55, 0x2d, 0x42, 0x6f, 0x6f, 0x74, 0x00};
41 /* Eight characters translating to one utf-16 word each */
42 static const char d2
[] = {0x6b, 0x61, 0x66, 0x62, 0xc3, 0xa1, 0x74, 0x75,
44 /* Three characters translating to one utf-16 word each */
45 static const char d3
[] = {0xe6, 0xbd, 0x9c, 0xe6, 0xb0, 0xb4, 0xe8, 0x89,
47 /* Three letters translating to two utf-16 word each */
48 static const char d4
[] = {0xf0, 0x90, 0x92, 0x8d, 0xf0, 0x90, 0x92, 0x96,
49 0xf0, 0x90, 0x92, 0x87, 0x00};
50 /* Letter not in code page 437 */
51 static const char d5
[] = {0xCE, 0x92, 0x20, 0x69, 0x73, 0x20, 0x6E, 0x6F,
52 0x74, 0x20, 0x42, 0x00};
54 /* Illegal utf-8 strings */
55 static const char j1
[] = {0x6a, 0x31, 0xa1, 0x6c, 0x00};
56 static const char j2
[] = {0x6a, 0x32, 0xc3, 0xc3, 0x6c, 0x00};
57 static const char j3
[] = {0x6a, 0x33, 0xf0, 0x90, 0xf0, 0x00};
58 static const char j4
[] = {0xa1, 0x00};
60 static int unicode_test_u16_strlen(struct unit_test_state
*uts
)
62 ut_asserteq(6, u16_strlen(c1
));
63 ut_asserteq(8, u16_strlen(c2
));
64 ut_asserteq(3, u16_strlen(c3
));
65 ut_asserteq(6, u16_strlen(c4
));
68 UNICODE_TEST(unicode_test_u16_strlen
);
70 static int unicode_test_u16_strdup(struct unit_test_state
*uts
)
72 u16
*copy
= u16_strdup(c4
);
74 ut_assert(copy
!= c4
);
75 ut_asserteq_mem(copy
, c4
, sizeof(c4
));
80 UNICODE_TEST(unicode_test_u16_strdup
);
82 static int unicode_test_u16_strcpy(struct unit_test_state
*uts
)
87 r
= u16_strcpy(copy
, c1
);
89 ut_asserteq_mem(copy
, c1
, sizeof(c1
));
93 UNICODE_TEST(unicode_test_u16_strcpy
);
95 /* U-Boot uses UTF-16 strings in the EFI context only. */
96 #if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD)
97 static int unicode_test_string16(struct unit_test_state
*uts
)
101 /* Test length and precision */
102 memset(buf
, 0xff, sizeof(buf
));
103 sprintf(buf
, "%8.6ls", c2
);
104 ut_asserteq(' ', buf
[1]);
105 ut_assert(!strncmp(&buf
[2], d2
, 7));
108 memset(buf
, 0xff, sizeof(buf
));
109 sprintf(buf
, "%8.6ls", c4
);
110 ut_asserteq(' ', buf
[4]);
111 ut_assert(!strncmp(&buf
[5], d4
, 12));
114 memset(buf
, 0xff, sizeof(buf
));
115 sprintf(buf
, "%-8.2ls", c4
);
116 ut_asserteq(' ', buf
[8]);
117 ut_assert(!strncmp(buf
, d4
, 8));
120 /* Test handling of illegal utf-16 sequences */
121 memset(buf
, 0xff, sizeof(buf
));
122 sprintf(buf
, "%ls", i1
);
123 ut_asserteq_str("i1?l", buf
);
125 memset(buf
, 0xff, sizeof(buf
));
126 sprintf(buf
, "%ls", i2
);
127 ut_asserteq_str("i2?l", buf
);
129 memset(buf
, 0xff, sizeof(buf
));
130 sprintf(buf
, "%ls", i3
);
131 ut_asserteq_str("i3?", buf
);
135 UNICODE_TEST(unicode_test_string16
);
138 static int unicode_test_utf8_get(struct unit_test_state
*uts
)
144 /* Check characters less than 0x800 */
146 for (i
= 0; i
< 8; ++i
) {
147 code
= utf8_get((const char **)&s
);
148 /* c2 is the utf-8 encoding of d2 */
149 ut_asserteq(c2
[i
], code
);
153 ut_asserteq_ptr(s
, d2
+ 9)
155 /* Check characters less than 0x10000 */
157 for (i
= 0; i
< 4; ++i
) {
158 code
= utf8_get((const char **)&s
);
159 /* c3 is the utf-8 encoding of d3 */
160 ut_asserteq(c3
[i
], code
);
164 ut_asserteq_ptr(s
, d3
+ 9)
166 /* Check character greater 0xffff */
168 code
= utf8_get((const char **)&s
);
169 ut_asserteq(0x0001048d, code
);
170 ut_asserteq_ptr(s
, d4
+ 4);
172 /* Check illegal character */
174 code
= utf8_get((const char **)&s
);
175 ut_asserteq(-1, code
);
176 ut_asserteq_ptr(j4
+ 1, s
);
180 UNICODE_TEST(unicode_test_utf8_get
);
182 static int unicode_test_utf8_put(struct unit_test_state
*uts
)
184 char buffer
[8] = { 0, };
187 /* Commercial at, translates to one character */
189 ut_assert(!utf8_put('@', &pos
))
190 ut_asserteq(1, pos
- buffer
);
191 ut_asserteq('@', buffer
[0]);
192 ut_assert(!buffer
[1]);
194 /* Latin letter G with acute, translates to two charactes */
196 ut_assert(!utf8_put(0x1f4, &pos
));
197 ut_asserteq(2, pos
- buffer
);
198 ut_asserteq_str("\xc7\xb4", buffer
);
200 /* Tagalog letter i, translates to three characters */
202 ut_assert(!utf8_put(0x1701, &pos
));
203 ut_asserteq(3, pos
- buffer
);
204 ut_asserteq_str("\xe1\x9c\x81", buffer
);
206 /* Hamster face, translates to four characters */
208 ut_assert(!utf8_put(0x1f439, &pos
));
209 ut_asserteq(4, pos
- buffer
);
210 ut_asserteq_str("\xf0\x9f\x90\xb9", buffer
);
214 ut_asserteq(-1, utf8_put(0xd888, &pos
));
218 UNICODE_TEST(unicode_test_utf8_put
);
220 static int unicode_test_utf8_utf16_strlen(struct unit_test_state
*uts
)
222 ut_asserteq(6, utf8_utf16_strlen(d1
));
223 ut_asserteq(8, utf8_utf16_strlen(d2
));
224 ut_asserteq(3, utf8_utf16_strlen(d3
));
225 ut_asserteq(6, utf8_utf16_strlen(d4
));
227 /* illegal utf-8 sequences */
228 ut_asserteq(4, utf8_utf16_strlen(j1
));
229 ut_asserteq(4, utf8_utf16_strlen(j2
));
230 ut_asserteq(3, utf8_utf16_strlen(j3
));
234 UNICODE_TEST(unicode_test_utf8_utf16_strlen
);
236 static int unicode_test_utf8_utf16_strnlen(struct unit_test_state
*uts
)
238 ut_asserteq(3, utf8_utf16_strnlen(d1
, 3));
239 ut_asserteq(6, utf8_utf16_strnlen(d1
, 13));
240 ut_asserteq(6, utf8_utf16_strnlen(d2
, 6));
241 ut_asserteq(2, utf8_utf16_strnlen(d3
, 2));
242 ut_asserteq(4, utf8_utf16_strnlen(d4
, 2));
243 ut_asserteq(6, utf8_utf16_strnlen(d4
, 3));
245 /* illegal utf-8 sequences */
246 ut_asserteq(4, utf8_utf16_strnlen(j1
, 16));
247 ut_asserteq(4, utf8_utf16_strnlen(j2
, 16));
248 ut_asserteq(3, utf8_utf16_strnlen(j3
, 16));
252 UNICODE_TEST(unicode_test_utf8_utf16_strnlen
);
255 * ut_u16_strcmp() - Compare to u16 strings.
259 * @count: number of u16 to compare
260 * Return: -1 if a1 < a2, 0 if a1 == a2, 1 if a1 > a2
262 static int unicode_test_u16_strcmp(const u16
*a1
, const u16
*a2
, size_t count
)
264 for (; (*a1
|| *a2
) && count
; ++a1
, ++a2
, --count
) {
273 static int unicode_test_utf8_utf16_strcpy(struct unit_test_state
*uts
)
279 utf8_utf16_strcpy(&pos
, d1
);
280 ut_asserteq(6, pos
- buf
);
281 ut_assert(!unicode_test_u16_strcmp(buf
, c1
, SIZE_MAX
));
284 utf8_utf16_strcpy(&pos
, d2
);
285 ut_asserteq(8, pos
- buf
);
286 ut_assert(!unicode_test_u16_strcmp(buf
, c2
, SIZE_MAX
));
289 utf8_utf16_strcpy(&pos
, d3
);
290 ut_asserteq(3, pos
- buf
);
291 ut_assert(!unicode_test_u16_strcmp(buf
, c3
, SIZE_MAX
));
294 utf8_utf16_strcpy(&pos
, d4
);
295 ut_asserteq(6, pos
- buf
);
296 ut_assert(!unicode_test_u16_strcmp(buf
, c4
, SIZE_MAX
));
298 /* Illegal utf-8 strings */
300 utf8_utf16_strcpy(&pos
, j1
);
301 ut_asserteq(4, pos
- buf
);
302 ut_assert(!unicode_test_u16_strcmp(buf
, L
"j1?l", SIZE_MAX
));
305 utf8_utf16_strcpy(&pos
, j2
);
306 ut_asserteq(4, pos
- buf
);
307 ut_assert(!unicode_test_u16_strcmp(buf
, L
"j2?l", SIZE_MAX
));
310 utf8_utf16_strcpy(&pos
, j3
);
311 ut_asserteq(3, pos
- buf
);
312 ut_assert(!unicode_test_u16_strcmp(buf
, L
"j3?", SIZE_MAX
));
316 UNICODE_TEST(unicode_test_utf8_utf16_strcpy
);
318 static int unicode_test_utf8_utf16_strncpy(struct unit_test_state
*uts
)
324 memset(buf
, 0, sizeof(buf
));
325 utf8_utf16_strncpy(&pos
, d1
, 4);
326 ut_asserteq(4, pos
- buf
);
328 ut_assert(!unicode_test_u16_strcmp(buf
, c1
, 4));
331 memset(buf
, 0, sizeof(buf
));
332 utf8_utf16_strncpy(&pos
, d2
, 10);
333 ut_asserteq(8, pos
- buf
);
335 ut_assert(!unicode_test_u16_strcmp(buf
, c2
, SIZE_MAX
));
338 memset(buf
, 0, sizeof(buf
));
339 utf8_utf16_strncpy(&pos
, d3
, 2);
340 ut_asserteq(2, pos
- buf
);
342 ut_assert(!unicode_test_u16_strcmp(buf
, c3
, 2));
345 memset(buf
, 0, sizeof(buf
));
346 utf8_utf16_strncpy(&pos
, d4
, 2);
347 ut_asserteq(4, pos
- buf
);
349 ut_assert(!unicode_test_u16_strcmp(buf
, c4
, 4));
352 memset(buf
, 0, sizeof(buf
));
353 utf8_utf16_strncpy(&pos
, d4
, 10);
354 ut_asserteq(6, pos
- buf
);
356 ut_assert(!unicode_test_u16_strcmp(buf
, c4
, SIZE_MAX
));
360 UNICODE_TEST(unicode_test_utf8_utf16_strncpy
);
362 static int unicode_test_utf16_get(struct unit_test_state
*uts
)
368 /* Check characters less than 0x10000 */
370 for (i
= 0; i
< 9; ++i
) {
371 code
= utf16_get((const u16
**)&s
);
372 ut_asserteq(c2
[i
], code
);
376 ut_asserteq_ptr(c2
+ 8, s
);
378 /* Check character greater 0xffff */
380 code
= utf16_get((const u16
**)&s
);
381 ut_asserteq(0x0001048d, code
);
382 ut_asserteq_ptr(c4
+ 2, s
);
386 UNICODE_TEST(unicode_test_utf16_get
);
388 static int unicode_test_utf16_put(struct unit_test_state
*uts
)
390 u16 buffer
[4] = { 0, };
393 /* Commercial at, translates to one word */
395 ut_assert(!utf16_put('@', &pos
));
396 ut_asserteq(1, pos
- buffer
);
397 ut_asserteq((u16
)'@', buffer
[0]);
398 ut_assert(!buffer
[1]);
400 /* Hamster face, translates to two words */
402 ut_assert(!utf16_put(0x1f439, &pos
));
403 ut_asserteq(2, pos
- buffer
);
404 ut_asserteq((u16
)0xd83d, buffer
[0]);
405 ut_asserteq((u16
)0xdc39, buffer
[1]);
406 ut_assert(!buffer
[2]);
410 ut_asserteq(-1, utf16_put(0xd888, &pos
));
414 UNICODE_TEST(unicode_test_utf16_put
);
416 static int unicode_test_utf16_strnlen(struct unit_test_state
*uts
)
418 ut_asserteq(3, utf16_strnlen(c1
, 3));
419 ut_asserteq(6, utf16_strnlen(c1
, 13));
420 ut_asserteq(6, utf16_strnlen(c2
, 6));
421 ut_asserteq(2, utf16_strnlen(c3
, 2));
422 ut_asserteq(2, utf16_strnlen(c4
, 2));
423 ut_asserteq(3, utf16_strnlen(c4
, 3));
425 /* illegal utf-16 word sequences */
426 ut_asserteq(4, utf16_strnlen(i1
, 16));
427 ut_asserteq(4, utf16_strnlen(i2
, 16));
428 ut_asserteq(3, utf16_strnlen(i3
, 16));
432 UNICODE_TEST(unicode_test_utf16_strnlen
);
434 static int unicode_test_utf16_utf8_strlen(struct unit_test_state
*uts
)
436 ut_asserteq(6, utf16_utf8_strlen(c1
));
437 ut_asserteq(9, utf16_utf8_strlen(c2
));
438 ut_asserteq(9, utf16_utf8_strlen(c3
));
439 ut_asserteq(12, utf16_utf8_strlen(c4
));
441 /* illegal utf-16 word sequences */
442 ut_asserteq(4, utf16_utf8_strlen(i1
));
443 ut_asserteq(4, utf16_utf8_strlen(i2
));
444 ut_asserteq(3, utf16_utf8_strlen(i3
));
448 UNICODE_TEST(unicode_test_utf16_utf8_strlen
);
450 static int unicode_test_utf16_utf8_strnlen(struct unit_test_state
*uts
)
452 ut_asserteq(3, utf16_utf8_strnlen(c1
, 3));
453 ut_asserteq(6, utf16_utf8_strnlen(c1
, 13));
454 ut_asserteq(7, utf16_utf8_strnlen(c2
, 6));
455 ut_asserteq(6, utf16_utf8_strnlen(c3
, 2));
456 ut_asserteq(8, utf16_utf8_strnlen(c4
, 2));
457 ut_asserteq(12, utf16_utf8_strnlen(c4
, 3));
460 UNICODE_TEST(unicode_test_utf16_utf8_strnlen
);
462 static int unicode_test_utf16_utf8_strcpy(struct unit_test_state
*uts
)
468 utf16_utf8_strcpy(&pos
, c1
);
469 ut_asserteq(6, pos
- buf
);
470 ut_asserteq_str(d1
, buf
);
473 utf16_utf8_strcpy(&pos
, c2
);
474 ut_asserteq(9, pos
- buf
);
475 ut_asserteq_str(d2
, buf
);
478 utf16_utf8_strcpy(&pos
, c3
);
479 ut_asserteq(9, pos
- buf
);
480 ut_asserteq_str(d3
, buf
);
483 utf16_utf8_strcpy(&pos
, c4
);
484 ut_asserteq(12, pos
- buf
);
485 ut_asserteq_str(d4
, buf
);
487 /* Illegal utf-16 strings */
489 utf16_utf8_strcpy(&pos
, i1
);
490 ut_asserteq(4, pos
- buf
);
491 ut_asserteq_str("i1?l", buf
);
494 utf16_utf8_strcpy(&pos
, i2
);
495 ut_asserteq(4, pos
- buf
);
496 ut_asserteq_str("i2?l", buf
);
499 utf16_utf8_strcpy(&pos
, i3
);
500 ut_asserteq(3, pos
- buf
);
501 ut_asserteq_str("i3?", buf
);
505 UNICODE_TEST(unicode_test_utf16_utf8_strcpy
);
507 static int unicode_test_utf16_utf8_strncpy(struct unit_test_state
*uts
)
513 memset(buf
, 0, sizeof(buf
));
514 utf16_utf8_strncpy(&pos
, c1
, 4);
515 ut_asserteq(4, pos
- buf
);
517 ut_assert(!strncmp(buf
, d1
, 4));
520 memset(buf
, 0, sizeof(buf
));
521 utf16_utf8_strncpy(&pos
, c2
, 10);
522 ut_asserteq(9, pos
- buf
);
524 ut_assert(!strncmp(buf
, d2
, SIZE_MAX
));
527 memset(buf
, 0, sizeof(buf
));
528 utf16_utf8_strncpy(&pos
, c3
, 2);
529 ut_asserteq(6, pos
- buf
);
531 ut_assert(!strncmp(buf
, d3
, 6));
534 memset(buf
, 0, sizeof(buf
));
535 utf16_utf8_strncpy(&pos
, c4
, 2);
536 ut_asserteq(8, pos
- buf
);
538 ut_assert(!strncmp(buf
, d4
, 8));
541 memset(buf
, 0, sizeof(buf
));
542 utf16_utf8_strncpy(&pos
, c4
, 10);
543 ut_asserteq(12, pos
- buf
);
545 ut_assert(!strncmp(buf
, d4
, SIZE_MAX
));
549 UNICODE_TEST(unicode_test_utf16_utf8_strncpy
);
551 static int unicode_test_utf_to_lower(struct unit_test_state
*uts
)
553 ut_asserteq('@', utf_to_lower('@'));
554 ut_asserteq('a', utf_to_lower('A'));
555 ut_asserteq('z', utf_to_lower('Z'));
556 ut_asserteq('[', utf_to_lower('['));
557 ut_asserteq('m', utf_to_lower('m'));
558 /* Latin letter O with diaresis (umlaut) */
559 ut_asserteq(0x00f6, utf_to_lower(0x00d6));
560 #ifdef CONFIG_EFI_UNICODE_CAPITALIZATION
561 /* Cyrillic letter I*/
562 ut_asserteq(0x0438, utf_to_lower(0x0418));
566 UNICODE_TEST(unicode_test_utf_to_lower
);
568 static int unicode_test_utf_to_upper(struct unit_test_state
*uts
)
570 ut_asserteq('`', utf_to_upper('`'));
571 ut_asserteq('A', utf_to_upper('a'));
572 ut_asserteq('Z', utf_to_upper('z'));
573 ut_asserteq('{', utf_to_upper('{'));
574 ut_asserteq('M', utf_to_upper('M'));
575 /* Latin letter O with diaresis (umlaut) */
576 ut_asserteq(0x00d6, utf_to_upper(0x00f6));
577 #ifdef CONFIG_EFI_UNICODE_CAPITALIZATION
578 /* Cyrillic letter I */
579 ut_asserteq(0x0418, utf_to_upper(0x0438));
583 UNICODE_TEST(unicode_test_utf_to_upper
);
585 static int unicode_test_u16_strncmp(struct unit_test_state
*uts
)
587 ut_assert(u16_strncmp(L
"abc", L
"abc", 3) == 0);
588 ut_assert(u16_strncmp(L
"abcdef", L
"abcghi", 3) == 0);
589 ut_assert(u16_strncmp(L
"abcdef", L
"abcghi", 6) < 0);
590 ut_assert(u16_strncmp(L
"abcghi", L
"abcdef", 6) > 0);
591 ut_assert(u16_strcmp(L
"abc", L
"abc") == 0);
592 ut_assert(u16_strcmp(L
"abcdef", L
"deghi") < 0);
593 ut_assert(u16_strcmp(L
"deghi", L
"abcdef") > 0);
596 UNICODE_TEST(unicode_test_u16_strncmp
);
598 static int unicode_test_u16_strsize(struct unit_test_state
*uts
)
600 ut_asserteq_64(u16_strsize(c1
), 14);
601 ut_asserteq_64(u16_strsize(c2
), 18);
602 ut_asserteq_64(u16_strsize(c3
), 8);
603 ut_asserteq_64(u16_strsize(c4
), 14);
606 UNICODE_TEST(unicode_test_u16_strsize
);
608 static int unicode_test_utf_to_cp(struct unit_test_state
*uts
)
614 ret
= utf_to_cp(&c
, codepage_437
);
616 ut_asserteq('\n', c
);
619 ret
= utf_to_cp(&c
, codepage_437
);
623 c
= 0x03c4; /* Greek small letter tau */
624 ret
= utf_to_cp(&c
, codepage_437
);
626 ut_asserteq(0xe7, c
);
628 c
= 0x03a4; /* Greek capital letter tau */
629 ret
= utf_to_cp(&c
, codepage_437
);
630 ut_asserteq(-ENOENT
, ret
);
635 UNICODE_TEST(unicode_test_utf_to_cp
);
637 static void utf8_to_cp437_stream_helper(const char *in
, char *out
)
644 ret
= utf8_to_cp437_stream(*in
, buffer
);
651 static int unicode_test_utf8_to_cp437_stream(struct unit_test_state
*uts
)
655 utf8_to_cp437_stream_helper(d1
, buf
);
656 ut_asserteq_str("U-Boot", buf
);
657 utf8_to_cp437_stream_helper(d2
, buf
);
658 ut_asserteq_str("kafb\xa0tur", buf
);
659 utf8_to_cp437_stream_helper(d5
, buf
);
660 ut_asserteq_str("? is not B", buf
);
661 utf8_to_cp437_stream_helper(j2
, buf
);
662 ut_asserteq_str("j2l", buf
);
666 UNICODE_TEST(unicode_test_utf8_to_cp437_stream
);
668 static void utf8_to_utf32_stream_helper(const char *in
, s32
*out
)
675 ret
= utf8_to_utf32_stream(*in
, buffer
);
682 static int unicode_test_utf8_to_utf32_stream(struct unit_test_state
*uts
)
686 const u32 u1
[] = {0x55, 0x2D, 0x42, 0x6F, 0x6F, 0x74, 0x0000};
687 const u32 u2
[] = {0x6B, 0x61, 0x66, 0x62, 0xE1, 0x74, 0x75, 0x72, 0x00};
688 const u32 u3
[] = {0x0392, 0x20, 0x69, 0x73, 0x20, 0x6E, 0x6F, 0x74,
690 const u32 u4
[] = {0x6A, 0x32, 0x6C, 0x00};
692 memset(buf
, 0, sizeof(buf
));
693 utf8_to_utf32_stream_helper(d1
, buf
);
694 ut_asserteq_mem(u1
, buf
, sizeof(u1
));
696 memset(buf
, 0, sizeof(buf
));
697 utf8_to_utf32_stream_helper(d2
, buf
);
698 ut_asserteq_mem(u2
, buf
, sizeof(u2
));
700 memset(buf
, 0, sizeof(buf
));
701 utf8_to_utf32_stream_helper(d5
, buf
);
702 ut_asserteq_mem(u3
, buf
, sizeof(u3
));
704 memset(buf
, 0, sizeof(buf
));
705 utf8_to_utf32_stream_helper(j2
, buf
);
706 ut_asserteq_mem(u4
, buf
, sizeof(u4
));
710 UNICODE_TEST(unicode_test_utf8_to_utf32_stream
);
712 #ifdef CONFIG_EFI_LOADER
713 static int unicode_test_efi_create_indexed_name(struct unit_test_state
*uts
)
716 u16
const expected
[] = L
"Capsule0AF9";
719 memset(buf
, 0xeb, sizeof(buf
));
720 pos
= efi_create_indexed_name(buf
, sizeof(buf
), "Capsule", 0x0af9);
722 ut_asserteq_mem(expected
, buf
, sizeof(expected
));
723 ut_asserteq(pos
- buf
, u16_strnlen(buf
, SIZE_MAX
));
727 UNICODE_TEST(unicode_test_efi_create_indexed_name
);
730 int do_ut_unicode(struct cmd_tbl
*cmdtp
, int flag
, int argc
, char *const argv
[])
732 struct unit_test
*tests
= ll_entry_start(struct unit_test
, unicode_test
);
733 const int n_ents
= ll_entry_count(struct unit_test
, unicode_test
);
735 return cmd_ut_category("Unicode", "unicode_test_",
736 tests
, n_ents
, argc
, argv
);