global: Migrate CONFIG_STACKBASE to CFG
[platform/kernel/u-boot.git] / test / unicode_ut.c
index f821e5a..d104bd5 100644 (file)
@@ -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);
@@ -727,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);