summaryrefslogtreecommitdiff
path: root/test/lib/string.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2021-10-08 16:02:55 -0400
committerTom Rini <trini@konsulko.com>2021-10-08 16:02:55 -0400
commit94e922c76a0e1fcdead3359e340f53fd0709a963 (patch)
tree667372191c3a70cd9343180c8d7f6273afbb9ab9 /test/lib/string.c
parent0caf37e973015255a3c5b9439ddb8c6aef1b5001 (diff)
parent4cb35b7a1fdf060a0839b71f6dbf8d08b1ae62e0 (diff)
Merge branch '2021-10-08-image-cleanups'
- A large number of image file and tooling related cleanups
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);