Optimize the code that copies strings
[fio.git] / unittests / oslib / strlcat.c
1 #include "../unittest.h"
2
3 #ifndef CONFIG_STRLCAT
4 #include "../../oslib/strlcat.h"
5 #else
6 #include <string.h>
7 #endif
8
9 static void test_strlcat_1(void)
10 {
11         char dst[32];
12         char src[] = "test";
13         size_t ret;
14
15         dst[0] = '\0';
16         ret = strlcat(dst, src, sizeof(dst));
17
18         CU_ASSERT_EQUAL(strcmp(dst, "test"), 0);
19         CU_ASSERT_EQUAL(ret, 4); /* total length it tried to create */
20 }
21
22 static void test_strlcat_2(void)
23 {
24         char dst[32];
25         char src[] = "test";
26         size_t ret;
27
28         dst[0] = '\0';
29         ret = strlcat(dst, src, strlen(dst));
30
31         CU_ASSERT_EQUAL(strcmp(dst, ""), 0);
32         CU_ASSERT_EQUAL(ret, 4); /* total length it tried to create */
33 }
34
35 static struct fio_unittest_entry tests[] = {
36         {
37                 .name   = "strlcat/1",
38                 .fn     = test_strlcat_1,
39         },
40         {
41                 .name   = "strlcat/2",
42                 .fn     = test_strlcat_2,
43         },
44         {
45                 .name   = NULL,
46         },
47 };
48
49 CU_ErrorCode fio_unittest_oslib_strlcat(void)
50 {
51         return fio_unittest_add_suite("oslib/strlcat.c", NULL, NULL, tests);
52 }