@@ -758,6 +758,51 @@ 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[11];
+ u16 dest[] = u"U-Boot";
+ u16 src[] = u"test";
+ u16 expected[] = u"U-Boottest";
+ u16 null_src = u'\0';
+ size_t ret;
+
+ memcpy(buf, dest, sizeof(dest));
+ ret = u16_strlcat(buf, src, sizeof(buf));
+ ut_asserteq(20, ret);
+ ut_assert(!unicode_test_u16_strcmp(buf, expected, 11));
+
+ /* dest is empty string */
+ memset(buf, 0, sizeof(buf));
+ ret = u16_strlcat(buf, src, sizeof(buf));
+ ut_asserteq(8, ret);
+ ut_assert(!unicode_test_u16_strcmp(buf, src, 11));
+
+ /* src is empty string */
+ memset(buf, 0, sizeof(buf));
+ memcpy(buf, dest, sizeof(dest));
+ ret = u16_strlcat(buf, &null_src, sizeof(buf));
+ ut_asserteq(12, ret);
+ ut_assert(!unicode_test_u16_strcmp(buf, dest, 11));
+
+ /* size is smaller than dest size */
+ memset(buf, 0, sizeof(buf));
+ memcpy(buf, dest, sizeof(dest));
+ ret = u16_strlcat(buf, src, 6);
+ ut_asserteq(14, ret);
+ ut_assert(!unicode_test_u16_strcmp(buf, dest, 11));
+
+ /* size is insufficient to append src string */
+ memset(buf, 0, sizeof(buf));
+ memcpy(buf, dest, sizeof(dest));
+ ret = u16_strlcat(buf, src, 20);
+ ut_asserteq(20, ret);
+ ut_assert(!unicode_test_u16_strcmp(buf, u"U-Boottes", 11));
+
+ 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);
Provide a unit test for function u16_strlcat(). Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org> --- test/unicode_ut.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)