diff options
| author | William Casarin <jb55@jb55.com> | 2018-07-09 12:10:32 -0700 |
|---|---|---|
| committer | William Casarin <jb55@jb55.com> | 2018-07-09 12:10:32 -0700 |
| commit | 1b8fbbd843ddeb5fc81c9303db9c590a436d499b (patch) | |
| tree | a7227dfe8e4fbaee7b1e0b58b24994dce8078f3f /ccan/tal/test/run-destructor2.c | |
| parent | 37a9cdd2e80386f2c94e14e4f511284ae14c745a (diff) | |
progress
Diffstat (limited to 'ccan/tal/test/run-destructor2.c')
| -rw-r--r-- | ccan/tal/test/run-destructor2.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/ccan/tal/test/run-destructor2.c b/ccan/tal/test/run-destructor2.c new file mode 100644 index 0000000..a92f07f --- /dev/null +++ b/ccan/tal/test/run-destructor2.c @@ -0,0 +1,38 @@ +#include <ccan/tal/tal.h> +#include <ccan/tal/tal.c> +#include <ccan/tap/tap.h> + +static void destroy_inc(char *p UNNEEDED, int *destroy_count) +{ + (*destroy_count)++; +} + +static void destroy_dec(char *p UNNEEDED, int *destroy_count) +{ + (*destroy_count)--; +} + +int main(void) +{ + char *p; + int destroy_count1 = 0, destroy_count2 = 0; + + plan_tests(10); + + p = tal(NULL, char); + /* Del must match both fn and arg. */ + ok1(tal_add_destructor2(p, destroy_inc, &destroy_count1)); + ok1(!tal_del_destructor2(p, destroy_inc, &destroy_count2)); + ok1(!tal_del_destructor2(p, destroy_dec, &destroy_count1)); + ok1(tal_del_destructor2(p, destroy_inc, &destroy_count1)); + ok1(!tal_del_destructor2(p, destroy_inc, &destroy_count1)); + + ok1(tal_add_destructor2(p, destroy_inc, &destroy_count1)); + ok1(tal_add_destructor2(p, destroy_dec, &destroy_count2)); + ok1(tal_free(p) == NULL); + ok1(destroy_count1 == 1); + ok1(destroy_count2 == -1); + + tal_cleanup(); + return exit_status(); +} |
