summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>2019-12-22 01:46:28 +0900
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>2019-12-22 12:11:01 +0900
commitd2292c7d8ce8a30788a38ff6dd0a8b9c0f930a63 (patch)
tree6c844d731f8cc399d061457130d379109485cc82 /unittests
parentab1665679b00fd2b3f955596da837d9694732b24 (diff)
downloadfio-d2292c7d8ce8a30788a38ff6dd0a8b9c0f930a63.tar.gz
fio-d2292c7d8ce8a30788a38ff6dd0a8b9c0f930a63.tar.bz2
unittests: add unittest suite for oslib/strcasestr.c
See b8b0e1eea7780a02ff67f0caeba446cc403f1b37 ("unittests: add CUnit based unittest framework") for usage. Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>
Diffstat (limited to 'unittests')
-rw-r--r--unittests/oslib/strcasestr.c87
-rw-r--r--unittests/unittest.c1
-rw-r--r--unittests/unittest.h1
3 files changed, 89 insertions, 0 deletions
diff --git a/unittests/oslib/strcasestr.c b/unittests/oslib/strcasestr.c
new file mode 100644
index 00000000..19a2de37
--- /dev/null
+++ b/unittests/oslib/strcasestr.c
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2019 Tomohiro Kusumi <tkusumi@netbsd.org>
+ */
+#include "../unittest.h"
+
+#ifndef CONFIG_STRCASESTR
+#include "../../oslib/strcasestr.h"
+#else
+#include <string.h>
+#endif
+
+static void test_strcasestr_1(void)
+{
+ const char *haystack = "0123456789";
+ const char *p;
+
+ p = strcasestr(haystack, "012");
+ CU_ASSERT_EQUAL(p, haystack);
+
+ p = strcasestr(haystack, "12345");
+ CU_ASSERT_EQUAL(p, haystack + 1);
+
+ p = strcasestr(haystack, "1234567890");
+ CU_ASSERT_EQUAL(p, NULL);
+
+ p = strcasestr(haystack, "");
+ CU_ASSERT_EQUAL(p, haystack); /* is this expected ? */
+}
+
+static void test_strcasestr_2(void)
+{
+ const char *haystack = "ABCDEFG";
+ const char *p;
+
+ p = strcasestr(haystack, "ABC");
+ CU_ASSERT_EQUAL(p, haystack);
+
+ p = strcasestr(haystack, "BCD");
+ CU_ASSERT_EQUAL(p, haystack + 1);
+
+ p = strcasestr(haystack, "ABCDEFGH");
+ CU_ASSERT_EQUAL(p, NULL);
+
+ p = strcasestr(haystack, "");
+ CU_ASSERT_EQUAL(p, haystack); /* is this expected ? */
+}
+
+static void test_strcasestr_3(void)
+{
+ const char *haystack = "ABCDEFG";
+ const char *p;
+
+ p = strcasestr(haystack, "AbC");
+ CU_ASSERT_EQUAL(p, haystack);
+
+ p = strcasestr(haystack, "bCd");
+ CU_ASSERT_EQUAL(p, haystack + 1);
+
+ p = strcasestr(haystack, "AbcdEFGH");
+ CU_ASSERT_EQUAL(p, NULL);
+
+ p = strcasestr(haystack, "");
+ CU_ASSERT_EQUAL(p, haystack); /* is this expected ? */
+}
+
+static struct fio_unittest_entry tests[] = {
+ {
+ .name = "strcasestr/1",
+ .fn = test_strcasestr_1,
+ },
+ {
+ .name = "strcasestr/2",
+ .fn = test_strcasestr_2,
+ },
+ {
+ .name = "strcasestr/3",
+ .fn = test_strcasestr_3,
+ },
+ {
+ .name = NULL,
+ },
+};
+
+CU_ErrorCode fio_unittest_oslib_strcasestr(void)
+{
+ return fio_unittest_add_suite("oslib/strcasestr.c", NULL, NULL, tests);
+}
diff --git a/unittests/unittest.c b/unittests/unittest.c
index 1166e6ef..2f253ba1 100644
--- a/unittests/unittest.c
+++ b/unittests/unittest.c
@@ -62,6 +62,7 @@ int main(void)
fio_unittest_register(fio_unittest_lib_strntol);
fio_unittest_register(fio_unittest_oslib_strlcat);
fio_unittest_register(fio_unittest_oslib_strndup);
+ fio_unittest_register(fio_unittest_oslib_strcasestr);
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
diff --git a/unittests/unittest.h b/unittests/unittest.h
index d3e3822f..1e62afa6 100644
--- a/unittests/unittest.h
+++ b/unittests/unittest.h
@@ -22,5 +22,6 @@ CU_ErrorCode fio_unittest_lib_memalign(void);
CU_ErrorCode fio_unittest_lib_strntol(void);
CU_ErrorCode fio_unittest_oslib_strlcat(void);
CU_ErrorCode fio_unittest_oslib_strndup(void);
+CU_ErrorCode fio_unittest_oslib_strcasestr(void);
#endif