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