X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftal%2Fstr%2Ftest%2Frun-string.c;fp=ccan%2Ftal%2Fstr%2Ftest%2Frun-string.c;h=4f8899de2acabe843ffe321fd06f4a34024d1858;hb=5582b011948769779b0d839d35873c2bc557f9cb;hp=0000000000000000000000000000000000000000;hpb=15ed4f453713f1a7bdeec22b53704819fa3d447f;p=ccan diff --git a/ccan/tal/str/test/run-string.c b/ccan/tal/str/test/run-string.c new file mode 100644 index 00000000..4f8899de --- /dev/null +++ b/ccan/tal/str/test/run-string.c @@ -0,0 +1,41 @@ +#include +#include +#include + +int main(void) +{ + char *parent, *c; + + plan_tests(13); + + parent = tal(NULL, char); + ok1(parent); + + c = tal_strdup(parent, "hello"); + ok1(strcmp(c, "hello") == 0); + ok1(tal_parent(c) == parent); + + c = tal_strndup(parent, "hello", 3); + ok1(strcmp(c, "hel") == 0); + ok1(tal_parent(c) == parent); + + c = tal_typechk_(parent, char *); + c = tal_dup(parent, char, "hello", 6, 0); + ok1(strcmp(c, "hello") == 0); + ok1(strcmp(tal_name(c), "char[]") == 0); + ok1(tal_parent(c) == parent); + + /* Now with an extra byte. */ + c = tal_dup(parent, char, "hello", 6, 1); + ok1(strcmp(c, "hello") == 0); + ok1(strcmp(tal_name(c), "char[]") == 0); + ok1(tal_parent(c) == parent); + strcat(c, "x"); + + c = tal_asprintf(parent, "hello %s", "there"); + ok1(strcmp(c, "hello there") == 0); + ok1(tal_parent(c) == parent); + tal_free(parent); + + return exit_status(); +}