summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>2018-10-26 09:35:43 -0700
committerJens Axboe <axboe@kernel.dk>2018-10-26 10:24:23 -0600
commitcdcd7e998f7b11371b73f646a750efc4e6eb378c (patch)
tree145085bb07b9639b3e7948112024f3d7a416379c /unittests
parentce87503183fc2ecb71b105a56daf49ddc897b9f9 (diff)
downloadfio-cdcd7e998f7b11371b73f646a750efc4e6eb378c.tar.gz
fio-cdcd7e998f7b11371b73f646a750efc4e6eb378c.tar.bz2
unittests: add unittest suite for oslib/strlcat.c
Add test cases for oslib/strlcat.c as an example of unittest. Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'unittests')
-rw-r--r--unittests/oslib/strlcat.c52
-rw-r--r--unittests/unittest.c1
-rw-r--r--unittests/unittest.h1
3 files changed, 54 insertions, 0 deletions
diff --git a/unittests/oslib/strlcat.c b/unittests/oslib/strlcat.c
new file mode 100644
index 00000000..8d35d419
--- /dev/null
+++ b/unittests/oslib/strlcat.c
@@ -0,0 +1,52 @@
+#include "../unittest.h"
+
+#ifndef CONFIG_STRLCAT
+#include "../../oslib/strlcat.h"
+#else
+#include <string.h>
+#endif
+
+static void test_strlcat_1(void)
+{
+ char dst[32];
+ char src[] = "test";
+ size_t ret;
+
+ dst[0] = '\0';
+ ret = strlcat(dst, src, sizeof(dst));
+
+ CU_ASSERT_EQUAL(strcmp(dst, "test"), 0);
+ CU_ASSERT_EQUAL(ret, 4); /* total length it tried to create */
+}
+
+static void test_strlcat_2(void)
+{
+ char dst[32];
+ char src[] = "test";
+ size_t ret;
+
+ dst[0] = '\0';
+ ret = strlcat(dst, src, strlen(dst));
+
+ CU_ASSERT_EQUAL(strcmp(dst, ""), 0);
+ CU_ASSERT_EQUAL(ret, 4); /* total length it tried to create */
+}
+
+static struct fio_unittest_entry tests[] = {
+ {
+ .name = "strlcat/1",
+ .fn = test_strlcat_1,
+ },
+ {
+ .name = "strlcat/2",
+ .fn = test_strlcat_2,
+ },
+ {
+ .name = NULL,
+ },
+};
+
+CU_ErrorCode fio_unittest_oslib_strlcat(void)
+{
+ return fio_unittest_add_suite("oslib/strlcat.c", NULL, NULL, tests);
+}
diff --git a/unittests/unittest.c b/unittests/unittest.c
index dc627b4e..20f92050 100644
--- a/unittests/unittest.c
+++ b/unittests/unittest.c
@@ -60,6 +60,7 @@ int main(void)
fio_unittest_register(fio_unittest_lib_memalign);
fio_unittest_register(fio_unittest_lib_strntol);
+ fio_unittest_register(fio_unittest_oslib_strlcat);
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
diff --git a/unittests/unittest.h b/unittests/unittest.h
index e0121ec3..f45e193a 100644
--- a/unittests/unittest.h
+++ b/unittests/unittest.h
@@ -20,5 +20,6 @@ CU_ErrorCode fio_unittest_add_suite(const char*, CU_InitializeFunc,
CU_ErrorCode fio_unittest_lib_memalign(void);
CU_ErrorCode fio_unittest_lib_strntol(void);
+CU_ErrorCode fio_unittest_oslib_strlcat(void);
#endif