tal: new module.
[ccan] / ccan / tal / test / run-string.c
1 #include <ccan/tal/tal.h>
2 #include <ccan/tal/tal.c>
3 #include <ccan/tap/tap.h>
4
5 int main(void)
6 {
7         char *parent, *c;
8
9         plan_tests(9);
10
11         parent = tal(NULL, char);
12         ok1(parent);
13
14         c = tal_strdup(parent, "hello");
15         ok1(strcmp(c, "hello") == 0);
16         ok1(tal_parent(c) == parent);
17
18         c = tal_strndup(parent, "hello", 3);
19         ok1(strcmp(c, "hel") == 0);
20         ok1(tal_parent(c) == parent);
21
22         c = tal_memdup(parent, "hello", 6);
23         ok1(strcmp(c, "hello") == 0);
24         ok1(tal_parent(c) == parent);
25
26         c = tal_asprintf(parent, "hello %s", "there");
27         ok1(strcmp(c, "hello there") == 0);
28         ok1(tal_parent(c) == parent);
29         tal_free(parent);
30
31         return exit_status();
32 }