1 #include <ccan/tal/tal.h> 2 #include <ccan/tal/tal.c> 3 #include <ccan/tap/tap.h> 4 main(void)5int main(void) 6 { 7 char *parent, *c[4], *p; 8 int i, j; 9 10 plan_tests(14); 11 12 /* tal_free(NULL) works. */ 13 ok1(tal_free(NULL) == NULL); 14 15 parent = tal(NULL, char); 16 ok1(parent); 17 ok1(tal_parent(parent) == NULL); 18 ok1(tal_parent(NULL) == NULL); 19 20 for (i = 0; i < 4; i++) 21 c[i] = tal(parent, char); 22 23 for (i = 0; i < 4; i++) 24 ok1(tal_parent(c[i]) == parent); 25 26 /* Iteration test. */ 27 i = 0; 28 for (p = tal_first(parent); p; p = tal_next(p)) { 29 *p = '1'; 30 i++; 31 } 32 ok1(i == 4); 33 ok1(*c[0] == '1'); 34 ok1(*c[1] == '1'); 35 ok1(*c[2] == '1'); 36 ok1(*c[3] == '1'); 37 38 /* Free parent. */ 39 ok1(tal_free(parent) == NULL); 40 41 parent = tal(NULL, char); 42 43 /* Test freeing in every order */ 44 for (i = 0; i < 4; i++) { 45 for (j = 0; j < 4; j++) 46 c[j] = tal(parent, char); 47 48 tal_free(c[i]); 49 debug_tal(to_tal_hdr(parent)); 50 tal_free(c[(i+1) % 4]); 51 debug_tal(to_tal_hdr(parent)); 52 tal_free(c[(i+2) % 4]); 53 debug_tal(to_tal_hdr(parent)); 54 tal_free(c[(i+3) % 4]); 55 debug_tal(to_tal_hdr(parent)); 56 } 57 tal_free(parent); 58 59 tal_cleanup(); 60 return exit_status(); 61 } 62