2 * Copyright (C) 2019 Tomohiro Kusumi <tkusumi@netbsd.org>
4 #include "../unittest.h"
7 #include "../../oslib/strsep.h"
13 * strsep(3) - "If *stringp is NULL, the strsep() function returns NULL and does
16 static void test_strsep_1(void)
21 p = strsep(&string, "");
22 CU_ASSERT_EQUAL(p, NULL);
23 CU_ASSERT_EQUAL(string, NULL);
25 p = strsep(&string, "ABC");
26 CU_ASSERT_EQUAL(p, NULL);
27 CU_ASSERT_EQUAL(string, NULL);
31 * strsep(3) - "In case no delimiter was found, the token is taken to be the
32 * entire string *stringp, and *stringp is made NULL."
34 static void test_strsep_2(void)
36 char src[] = "ABCDEFG";
40 p = strsep(&string, "");
41 CU_ASSERT_EQUAL(p, src);
42 CU_ASSERT_EQUAL(*p, 'A');
43 CU_ASSERT_EQUAL(string, NULL);
46 p = strsep(&string, "@");
47 CU_ASSERT_EQUAL(p, src);
48 CU_ASSERT_EQUAL(*p, 'A');
49 CU_ASSERT_EQUAL(string, NULL);
53 * strsep(3) - "This token is terminated with a '\0' character (by overwriting
54 * the delimiter) and *stringp is updated to point past the token."
56 static void test_strsep_3(void)
58 char src[] = "ABCDEFG";
62 p = strsep(&string, "ABC");
63 CU_ASSERT_EQUAL(p, &src[0]);
64 CU_ASSERT_EQUAL(*p, '\0');
65 CU_ASSERT_EQUAL(strcmp(string, "BCDEFG"), 0);
66 CU_ASSERT_EQUAL(*string, 'B');
68 p = strsep(&string, "ABC");
69 CU_ASSERT_EQUAL(p, &src[1]);
70 CU_ASSERT_EQUAL(*p, '\0');
71 CU_ASSERT_EQUAL(strcmp(string, "CDEFG"), 0);
72 CU_ASSERT_EQUAL(*string, 'C');
74 p = strsep(&string, "ABC");
75 CU_ASSERT_EQUAL(p, &src[2]);
76 CU_ASSERT_EQUAL(*p, '\0');
77 CU_ASSERT_EQUAL(strcmp(string, "DEFG"), 0);
78 CU_ASSERT_EQUAL(*string, 'D');
80 p = strsep(&string, "ABC");
81 CU_ASSERT_EQUAL(p, &src[3]);
82 CU_ASSERT_EQUAL(*p, 'D');
83 CU_ASSERT_EQUAL(string, NULL);
86 static struct fio_unittest_entry tests[] = {
104 CU_ErrorCode fio_unittest_oslib_strsep(void)
106 return fio_unittest_add_suite("oslib/strsep.c", NULL, NULL, tests);