]> git.ozlabs.org Git - ccan/blob - ccan/stringbuilder/test/run.c
stringbuilder: fix ccan/str test dependency.
[ccan] / ccan / stringbuilder / test / run.c
1 #include <ccan/stringbuilder/stringbuilder.h>
2 #include <ccan/stringbuilder/stringbuilder.c>
3 #include <ccan/str/str.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <errno.h>
7
8 #include <ccan/tap/tap.h>
9
10 int main(int argc, char *argv[])
11 {
12         char string[20];
13         const char* str_array[] = {
14                 "xxx", "yyy"
15         };
16         int res;
17
18         res = stringbuilder(string, sizeof(string), NULL,
19                         "aaa", "bbb");
20         printf("res: %s, string: %s\n",
21                         strerror(res), string);
22         ok1(res == 0);
23         ok1(streq(string, "aaabbb"));
24
25         res = stringbuilder(string, sizeof(string), NULL,
26                         "aaaaa", "bbbbb", "ccccc", "ddddd",
27                         "eeeee", "fffff");
28         printf("res: %s, string: %s\n",
29                         strerror(res), string);
30         ok1(res == EMSGSIZE);
31
32         res = stringbuilder(string, sizeof(string), ", ",
33                         "aaa");
34         printf("res: %s, string: %s\n",
35                         strerror(res), string);
36         ok1(res == 0);
37         ok1(streq(string, "aaa"));
38
39         res = stringbuilder(string, sizeof(string), ", ",
40                         "aaa", "bbb");
41         printf("res: %s, string: %s\n",
42                         strerror(res), string);
43         ok1(res == 0);
44         ok1(streq(string, "aaa, bbb"));
45
46         res = stringbuilder_array(string, sizeof(string), NULL,
47                         sizeof(str_array)/sizeof(str_array[0]), str_array);
48         printf("res: %s, string: %s\n",
49                         strerror(res), string);
50         ok1(res == 0);
51         ok1(streq(string, "xxxyyy"));
52
53         res = stringbuilder_array(string, sizeof(string), ", ",
54                         sizeof(str_array)/sizeof(str_array[0]), str_array);
55         printf("res: %s, string: %s\n",
56                         strerror(res), string);
57         ok1(res == 0);
58         ok1(streq(string, "xxx, yyy"));
59
60         return exit_status();
61 }