summaryrefslogtreecommitdiff
path: root/test/lib/string.c
diff options
context:
space:
mode:
authorStefano Babic <sbabic@denx.de>2021-10-21 13:57:38 +0200
committerStefano Babic <sbabic@denx.de>2021-10-21 13:58:13 +0200
commit5fac11e6d5ab350429b8c8ddf47d3d3877ca89d1 (patch)
treea6fd50ca6f8a79b0647469871fa99223a55d8a96 /test/lib/string.c
parente03aa34bdf97f96ad478f7a105482d8231b98aa6 (diff)
parent79b8849d4c1e73df2a79a1d5a5f6166d0dd67a12 (diff)
Merge branch 'master' of git://git.denx.de/u-boot
Signed-off-by: Stefano Babic <sbabic@denx.de>
Diffstat (limited to 'test/lib/string.c')
-rw-r--r--test/lib/string.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/lib/string.c b/test/lib/string.c
index 64234bef36c..5dcf4d6db00 100644
--- a/test/lib/string.c
+++ b/test/lib/string.c
@@ -23,6 +23,8 @@
/* Allow for copying up to 32 bytes */
#define BUFLEN (SWEEP + 33)
+#define TEST_STR "hello"
+
/**
* init_buffer() - initialize buffer
*
@@ -193,3 +195,33 @@ static int lib_memmove(struct unit_test_state *uts)
}
LIB_TEST(lib_memmove, 0);
+
+/** lib_memdup() - unit test for memdup() */
+static int lib_memdup(struct unit_test_state *uts)
+{
+ char buf[BUFLEN];
+ size_t len;
+ char *p, *q;
+
+ /* Zero size should do nothing */
+ p = memdup(NULL, 0);
+ ut_assertnonnull(p);
+ free(p);
+
+ p = memdup(buf, 0);
+ ut_assertnonnull(p);
+ free(p);
+
+ strcpy(buf, TEST_STR);
+ len = sizeof(TEST_STR);
+ p = memdup(buf, len);
+ ut_asserteq_mem(p, buf, len);
+
+ q = memdup(p, len);
+ ut_asserteq_mem(q, buf, len);
+ free(q);
+ free(p);
+
+ return 0;
+}
+LIB_TEST(lib_memdup, 0);