[U-Boot] [PATCH 1/1] test: tests for u16_strdup() and u16_strcpy()

Heinrich Schuchardt xypron.glpk at gmx.de
Fri Dec 14 21:00:37 UTC 2018


Provide unit tests for u16_strdup() and u16_strcpy().

Cc: AKASHI Takahiro <takahiro.akashi at linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
This patch is a follow up to Takahiro's patch
"lib: add u16_strcpy/strdup functions"
https://lists.denx.de/pipermail/u-boot/2018-December/352019.html
---
 test/unicode_ut.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/test/unicode_ut.c b/test/unicode_ut.c
index b115d18afd3..84fc9a3b537 100644
--- a/test/unicode_ut.c
+++ b/test/unicode_ut.c
@@ -50,6 +50,29 @@ static const char j1[] = {0x6a, 0x31, 0xa1, 0x6c, 0x00};
 static const char j2[] = {0x6a, 0x32, 0xc3, 0xc3, 0x6c, 0x00};
 static const char j3[] = {0x6a, 0x33, 0xf0, 0x90, 0xf0, 0x00};
 
+static int ut_u16_strdup(struct unit_test_state *uts)
+{
+	u16 *copy = u16_strdup(c4);
+
+	ut_assert(copy != c4);
+	ut_assert(!memcmp(copy, c4, sizeof(c4)));
+	free(copy);
+	return 0;
+}
+UNICODE_TEST(ut_u16_strdup);
+
+static int ut_u16_strcpy(struct unit_test_state *uts)
+{
+	u16 *r;
+	u16 copy[10];
+
+	r = u16_strcpy(copy, c1);
+	ut_assert(r == copy);
+	ut_assert(!memcmp(copy, c1, sizeof(c1)));
+	return 0;
+}
+UNICODE_TEST(ut_u16_strcpy);
+
 /* U-Boot uses UTF-16 strings in the EFI context only. */
 #if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD)
 static int ut_string16(struct unit_test_state *uts)
-- 
2.19.2



More information about the U-Boot mailing list