summaryrefslogtreecommitdiff
path: root/ccan/tal/test/run-steal.c
blob: 36251cb7b249914077663d3b42185e5e1f33fdbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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();
}