]> git.ozlabs.org Git - ccan/blob - ccan/talloc/test/run-talloc_set.c
modules: update documentation examples so they compile under ccanlint.
[ccan] / ccan / talloc / test / run-talloc_set.c
1 #include <ccan/talloc/talloc.c>
2 #include <ccan/tap/tap.h>
3 #include <assert.h>
4
5 int main(void)
6 {
7         char *c;
8         int *i;
9
10         plan_tests(12);
11
12         /* Set C to a valid pointer, with correct parent. */
13         talloc_set(&c, NULL);
14         ok1(c >= (char *)(intptr_t)getpagesize());
15         ok1(talloc_parent(c) == NULL);
16
17         /* Free it, should blatt c. */
18         talloc_free(c);
19         ok1(c);
20         ok1(c < (char *)(intptr_t)getpagesize());
21
22         /* Same test, indirect. */
23         talloc_set(&i, NULL);
24         talloc_set(&c, i);
25         ok1(c >= (char *)(intptr_t)getpagesize());
26         ok1(i >= (int *)(intptr_t)getpagesize());
27         ok1(talloc_parent(i) == NULL);
28         ok1(talloc_parent(c) == i);
29         talloc_free(i);
30         ok1(c);
31         ok1(c < (char *)(intptr_t)getpagesize());
32         ok1(i);
33         ok1(i < (int *)(intptr_t)getpagesize());
34
35         return exit_status();
36 }