From 0206052b5660cb77cdd0a0ac3c83dd4c3d996007 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 9 Jul 2018 15:48:55 -0700 Subject: started on positioning + command structure --- ccan/tal/str/test/run-take.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 ccan/tal/str/test/run-take.c (limited to 'ccan/tal/str/test/run-take.c') diff --git a/ccan/tal/str/test/run-take.c b/ccan/tal/str/test/run-take.c new file mode 100644 index 0000000..edf173f --- /dev/null +++ b/ccan/tal/str/test/run-take.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include "helper.h" + +int main(void) +{ + char *parent, *c; + + plan_tests(14); + + parent = tal(NULL, char); + ok1(parent); + + c = tal_strdup(parent, "hello"); + + c = tal_strdup(parent, take(c)); + ok1(strcmp(c, "hello") == 0); + ok1(tal_parent(c) == parent); + + c = tal_strndup(parent, take(c), 5); + ok1(strcmp(c, "hello") == 0); + ok1(tal_parent(c) == parent); + + c = tal_strndup(parent, take(c), 3); + ok1(strcmp(c, "hel") == 0); + ok1(tal_parent(c) == parent); + tal_free(c); + + c = tal_strdup(parent, "hello %s"); + c = tal_fmt(parent, take(c), "there"); + ok1(strcmp(c, "hello there") == 0); + ok1(tal_parent(c) == parent); + /* No leftover allocations. */ + tal_free(c); + ok1(no_children(parent)); + + tal_free(parent); + ok1(!taken_any()); + + /* NULL pass-through. */ + c = NULL; + ok1(tal_strdup(NULL, take(c)) == NULL); + ok1(tal_strndup(NULL, take(c), 5) == NULL); + ok1(tal_fmt(NULL, take(c), 0) == NULL); + + return exit_status(); +} -- cgit v1.2.3