t/nvmept_trim: increase transfer size for some tests
[fio.git] / unittests / oslib / strndup.c
1 #include "../unittest.h"
2
3 #ifndef CONFIG_HAVE_STRNDUP
4 #include "../../oslib/strndup.h"
5 #else
6 #include <string.h>
7 #endif
8
9 static void test_strndup_1(void)
10 {
11         char s[] = "test";
12         char *p = strndup(s, 3);
13
14         if (p) {
15                 CU_ASSERT_EQUAL(strcmp(p, "tes"), 0);
16                 CU_ASSERT_EQUAL(strlen(p), 3);
17         }
18 }
19
20 static void test_strndup_2(void)
21 {
22         char s[] = "test";
23         char *p = strndup(s, 4);
24
25         if (p) {
26                 CU_ASSERT_EQUAL(strcmp(p, s), 0);
27                 CU_ASSERT_EQUAL(strlen(p), 4);
28         }
29 }
30
31 static void test_strndup_3(void)
32 {
33         char s[] = "test";
34         char *p = strndup(s, 5);
35
36         if (p) {
37                 CU_ASSERT_EQUAL(strcmp(p, s), 0);
38                 CU_ASSERT_EQUAL(strlen(p), 4);
39         }
40 }
41
42 static struct fio_unittest_entry tests[] = {
43         {
44                 .name   = "strndup/1",
45                 .fn     = test_strndup_1,
46         },
47         {
48                 .name   = "strndup/2",
49                 .fn     = test_strndup_2,
50         },
51         {
52                 .name   = "strndup/3",
53                 .fn     = test_strndup_3,
54         },
55         {
56                 .name   = NULL,
57         },
58 };
59
60 CU_ErrorCode fio_unittest_oslib_strndup(void)
61 {
62         return fio_unittest_add_suite("oslib/strndup.c", NULL, NULL, tests);
63 }