diff options
author | Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | 2022-01-29 18:28:08 +0100 |
---|---|---|
committer | Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | 2022-02-05 20:20:01 +0100 |
commit | c672dd770ee0d9874086543c20a9088124514051 (patch) | |
tree | 591d38e22b68f19b109500bc36da5c9b6d52b76c /test | |
parent | fe14f880500cd842eadd581b7261538bb9646b7f (diff) | |
download | u-boot-c672dd770ee0d9874086543c20a9088124514051.tar.gz u-boot-c672dd770ee0d9874086543c20a9088124514051.tar.bz2 u-boot-c672dd770ee0d9874086543c20a9088124514051.zip |
test: test UTF-16 truncation in snprintf()
Check that snprintf() returns the correct required buffer length and prints
the correct string for UTF-16 strings.
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/unicode_ut.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/unicode_ut.c b/test/unicode_ut.c index f821e5a6be..f2f63d5367 100644 --- a/test/unicode_ut.c +++ b/test/unicode_ut.c @@ -97,6 +97,7 @@ UNICODE_TEST(unicode_test_u16_strcpy); static int unicode_test_string16(struct unit_test_state *uts) { char buf[20]; + int ret; /* Test length and precision */ memset(buf, 0xff, sizeof(buf)); @@ -130,6 +131,36 @@ static int unicode_test_string16(struct unit_test_state *uts) sprintf(buf, "%ls", i3); ut_asserteq_str("i3?", buf); + memset(buf, 0xff, sizeof(buf)); + ret = snprintf(buf, 4, "%ls", c1); + ut_asserteq(6, ret); + ut_asserteq_str("U-B", buf); + + memset(buf, 0xff, sizeof(buf)); + ret = snprintf(buf, 6, "%ls", c2); + ut_asserteq_str("kafb", buf); + ut_asserteq(9, ret); + + memset(buf, 0xff, sizeof(buf)); + ret = snprintf(buf, 7, "%ls", c2); + ut_asserteq_str("kafb\xC3\xA1", buf); + ut_asserteq(9, ret); + + memset(buf, 0xff, sizeof(buf)); + ret = snprintf(buf, 8, "%ls", c3); + ut_asserteq_str("\xE6\xBD\x9C\xE6\xB0\xB4", buf); + ut_asserteq(9, ret); + + memset(buf, 0xff, sizeof(buf)); + ret = snprintf(buf, 11, "%ls", c4); + ut_asserteq_str("\xF0\x90\x92\x8D\xF0\x90\x92\x96", buf); + ut_asserteq(12, ret); + + memset(buf, 0xff, sizeof(buf)); + ret = snprintf(buf, 4, "%ls", c4); + ut_asserteq_str("", buf); + ut_asserteq(12, ret); + return 0; } UNICODE_TEST(unicode_test_string16); |