aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMasahisa Kojima <masahisa.kojima@linaro.org>2022-04-28 17:09:35 +0900
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>2022-05-03 21:39:22 +0200
commitb8cd1e7fc2802fb4a9f42caf5d8f8e194eb8266f (patch)
treee1fa2ec8692a0ce9c5393a56ee6a6f681194c212 /test
parenteca08ce94ceb72358c5fb00e82506c0f74e65e3f (diff)
downloadu-boot-b8cd1e7fc2802fb4a9f42caf5d8f8e194eb8266f.zip
u-boot-b8cd1e7fc2802fb4a9f42caf5d8f8e194eb8266f.tar.gz
u-boot-b8cd1e7fc2802fb4a9f42caf5d8f8e194eb8266f.tar.bz2
test: unit test for u16_strlcat()
Provide a unit test for function u16_strlcat(). Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Diffstat (limited to 'test')
-rw-r--r--test/unicode_ut.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/unicode_ut.c b/test/unicode_ut.c
index f2f63d5..d104bd5 100644
--- a/test/unicode_ut.c
+++ b/test/unicode_ut.c
@@ -758,6 +758,56 @@ static int unicode_test_efi_create_indexed_name(struct unit_test_state *uts)
UNICODE_TEST(unicode_test_efi_create_indexed_name);
#endif
+static int unicode_test_u16_strlcat(struct unit_test_state *uts)
+{
+ u16 buf[40];
+ u16 dest[] = {0x3053, 0x3093, 0x306b, 0x3061, 0x306f, 0};
+ u16 src[] = {0x03B1, 0x2172, 0x6F5C, 0x8247, 0};
+ u16 concat_str[] = {0x3053, 0x3093, 0x306b, 0x3061, 0x306f,
+ 0x03B1, 0x2172, 0x6F5C, 0x8247, 0};
+ u16 null_src = u'\0';
+ size_t ret, expected;
+ int i;
+
+ /* dest and src are empty string */
+ memset(buf, 0, sizeof(buf));
+ ret = u16_strlcat(buf, &null_src, sizeof(buf));
+ ut_asserteq(1, ret);
+
+ /* dest is empty string */
+ memset(buf, 0, sizeof(buf));
+ ret = u16_strlcat(buf, src, sizeof(buf));
+ ut_asserteq(5, ret);
+ ut_assert(!unicode_test_u16_strcmp(buf, src, 40));
+
+ /* src is empty string */
+ memset(buf, 0xCD, (sizeof(buf) - sizeof(u16)));
+ buf[39] = 0;
+ memcpy(buf, dest, sizeof(dest));
+ ret = u16_strlcat(buf, &null_src, sizeof(buf));
+ ut_asserteq(6, ret);
+ ut_assert(!unicode_test_u16_strcmp(buf, dest, 40));
+
+ for (i = 0; i <= 40; i++) {
+ memset(buf, 0xCD, (sizeof(buf) - sizeof(u16)));
+ buf[39] = 0;
+ memcpy(buf, dest, sizeof(dest));
+ expected = 10;
+ ret = u16_strlcat(buf, src, i);
+ ut_asserteq(expected, ret);
+ if (i <= 6) {
+ ut_assert(!unicode_test_u16_strcmp(buf, dest, 40));
+ } else if (i < 10) {
+ ut_assert(!unicode_test_u16_strcmp(buf, concat_str, i - 1));
+ } else {
+ ut_assert(!unicode_test_u16_strcmp(buf, concat_str, 40));
+ }
+ }
+
+ return 0;
+}
+UNICODE_TEST(unicode_test_u16_strlcat);
+
int do_ut_unicode(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
struct unit_test *tests = UNIT_TEST_SUITE_START(unicode_test);