summaryrefslogtreecommitdiff
path: root/ccan/tal/test/run-steal.c
diff options
context:
space:
mode:
authorWilliam Casarin <jb55@jb55.com>2018-07-09 12:10:32 -0700
committerWilliam Casarin <jb55@jb55.com>2018-07-09 12:10:32 -0700
commit1b8fbbd843ddeb5fc81c9303db9c590a436d499b (patch)
treea7227dfe8e4fbaee7b1e0b58b24994dce8078f3f /ccan/tal/test/run-steal.c
parent37a9cdd2e80386f2c94e14e4f511284ae14c745a (diff)
progress
Diffstat (limited to 'ccan/tal/test/run-steal.c')
-rw-r--r--ccan/tal/test/run-steal.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/ccan/tal/test/run-steal.c b/ccan/tal/test/run-steal.c
new file mode 100644
index 0000000..36251cb
--- /dev/null
+++ b/ccan/tal/test/run-steal.c
@@ -0,0 +1,41 @@
+#include <ccan/tal/tal.h>
+#include <ccan/tal/tal.c>
+#include <ccan/tap/tap.h>
+
+int main(void)
+{
+ char *p[5];
+ unsigned int i;
+
+ plan_tests(9);
+
+ p[0] = tal(NULL, char);
+ for (i = 1; i < 5; i++)
+ p[i] = tal(p[i-1], char);
+
+ tal_check(NULL, "check");
+ /* Steal node with no children. */
+ ok1(tal_steal(p[0], p[4]) == p[4]);
+ tal_check(NULL, "check");
+ /* Noop steal. */
+ ok1(tal_steal(p[0], p[4]) == p[4]);
+ tal_check(NULL, "check");
+ /* Steal with children. */
+ ok1(tal_steal(p[0], p[1]) == p[1]);
+ tal_check(NULL, "check");
+ /* Noop steal. */
+ ok1(tal_steal(p[0], p[1]) == p[1]);
+ tal_check(NULL, "check");
+ /* Steal from direct child. */
+ ok1(tal_steal(p[0], p[2]) == p[2]);
+ tal_check(NULL, "check");
+
+ ok1(tal_parent(p[1]) == p[0]);
+ ok1(tal_parent(p[2]) == p[0]);
+ ok1(tal_parent(p[3]) == p[2]);
+ ok1(tal_parent(p[4]) == p[0]);
+ tal_free(p[0]);
+
+ tal_cleanup();
+ return exit_status();
+}