X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftal%2Fautoptr%2Ftest%2Frun.c;fp=ccan%2Ftal%2Fautoptr%2Ftest%2Frun.c;h=33f1b042cfaea4481dad4bf0a9eda48612ae9e92;hb=97ac5832db26f5f836fff979b08f01e17d7216bd;hp=0000000000000000000000000000000000000000;hpb=58277ab6c8b4dd6bb66638b88bd8505f46fdcb07;p=ccan diff --git a/ccan/tal/autoptr/test/run.c b/ccan/tal/autoptr/test/run.c new file mode 100644 index 00000000..33f1b042 --- /dev/null +++ b/ccan/tal/autoptr/test/run.c @@ -0,0 +1,49 @@ +#include +/* Include the C files directly. */ +#include +#include + +int main(void) +{ + char *p1, *p2, *p3; + struct autonull *a; + + /* This is how many tests you plan to run */ + plan_tests(8); + + p1 = tal(NULL, char); + + // Sets p1 to point to p2. + autonull_set_ptr(NULL, &p2, p1); + ok1(p2 == p1); + tal_free(p1); + ok1(p2 == NULL); + + // Using p1 as the parent is the same. */ + p1 = tal(NULL, char); + autonull_set_ptr(p1, &p2, p1); + ok1(p2 == p1); + tal_free(p1); + ok1(p2 == NULL); + + // Freeing autodata deactivates it. + p1 = tal(NULL, char); + a = autonull_set_ptr(NULL, &p2, p1); + ok1(p2 == p1); + tal_free(a); + tal_free(p1); + ok1(p2 == p1); + + // Making p3 the parent means freeing p3 deactivates it. + p3 = tal(NULL, char); + p1 = tal(NULL, char); + autonull_set_ptr(p3, &p2, p1); + ok1(p2 == p1); + tal_free(p3); + tal_free(p1); + ok1(p2 == p1); + + + /* This exits depending on whether all tests passed */ + return exit_status(); +}