]> git.ozlabs.org Git - ccan/blob - test/run.c
base64: fix for unsigned chars (e.g. ARM).
[ccan] / test / run.c
1 #include "str_talloc/str_talloc.h"
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include "str_talloc/str_talloc.c"
5 #include "tap/tap.h"
6 #include "str/str.h"
7
8 /* FIXME: ccanize */
9 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
10
11 static char *substrings[] = { "far", "bar", "baz", "b", "ba", "z", "ar", NULL };
12
13 int main(int argc, char *argv[])
14 {
15         unsigned int n;
16         char **split, *str;
17         void *ctx;
18
19         plan_tests(19);
20         split = strsplit(NULL, "hello  world", " ", &n);
21         ok1(n == 3);
22         ok1(streq(split[0], "hello"));
23         ok1(streq(split[1], ""));
24         ok1(streq(split[2], "world"));
25         ok1(split[3] == NULL);
26         talloc_free(split);
27
28         split = strsplit(NULL, "hello  world", " ", NULL);
29         ok1(streq(split[0], "hello"));
30         ok1(streq(split[1], ""));
31         ok1(streq(split[2], "world"));
32         ok1(split[3] == NULL);
33         talloc_free(split);
34
35         split = strsplit(NULL, "hello  world", "o ", NULL);
36         ok1(streq(split[0], "hell"));
37         ok1(streq(split[1], ""));
38         ok1(streq(split[2], ""));
39         ok1(streq(split[3], "w"));
40         ok1(streq(split[4], "rld"));
41         ok1(split[5] == NULL);
42
43         ctx = split;
44         split = strsplit(ctx, "hello  world", "o ", NULL);
45         ok1(talloc_parent(split) == ctx);
46         talloc_free(ctx);
47
48         str = strjoin(NULL, substrings, ", ");
49         ok1(streq(str, "far, bar, baz, b, ba, z, ar, "));
50         ctx = str;
51         str = strjoin(ctx, substrings, "");
52         ok1(streq(str, "farbarbazbbazar"));
53         ok1(talloc_parent(str) == ctx);
54         talloc_free(ctx);
55
56         return exit_status();
57 }