]> git.ozlabs.org Git - ccan/blob - ccan/tal/autoptr/test/run.c
tal/autoptr: new module.
[ccan] / ccan / tal / autoptr / test / run.c
1 #include <ccan/tal/autoptr/autoptr.h>
2 /* Include the C files directly. */
3 #include <ccan/tal/autoptr/autoptr.c>
4 #include <ccan/tap/tap.h>
5
6 int main(void)
7 {
8         char *p1, *p2, *p3;
9         struct autonull *a;
10
11         /* This is how many tests you plan to run */
12         plan_tests(8);
13
14         p1 = tal(NULL, char);
15
16         // Sets p1 to point to p2.
17         autonull_set_ptr(NULL, &p2, p1);
18         ok1(p2 == p1);
19         tal_free(p1);
20         ok1(p2 == NULL);
21
22         // Using p1 as the parent is the same. */
23         p1 = tal(NULL, char);
24         autonull_set_ptr(p1, &p2, p1);
25         ok1(p2 == p1);
26         tal_free(p1);
27         ok1(p2 == NULL);
28
29         // Freeing autodata deactivates it.
30         p1 = tal(NULL, char);
31         a = autonull_set_ptr(NULL, &p2, p1);
32         ok1(p2 == p1);
33         tal_free(a);
34         tal_free(p1);
35         ok1(p2 == p1);
36
37         // Making p3 the parent means freeing p3 deactivates it.
38         p3 = tal(NULL, char);
39         p1 = tal(NULL, char);
40         autonull_set_ptr(p3, &p2, p1);
41         ok1(p2 == p1);
42         tal_free(p3);
43         tal_free(p1);
44         ok1(p2 == p1);
45
46
47         /* This exits depending on whether all tests passed */
48         return exit_status();
49 }