/** * dll-expt.c * Some experiments for doubly-linked lists. */ // +---------+-------------------------------------------------------- // | Headers | // +---------+ #include #include #include // For strcmp #include "dll.h" // What we're testing #include "expt.h" // Experiment utilities #include "mem.h" // Memory is important to explore. // +--------+--------------------------------------------------------- // | Macros | // +--------+ #define PRINT_LIST(LIST) \ BLOCK( \ fprintf (stderr, VAR_PREFIX "%s = ", #LIST); \ if (LIST == NULL) \ fprintf (stderr, ""); \ else \ dll_print (LIST, stderr); \ fprintf (stderr, "\n"); ) #define PRINT_STUFF() \ BLOCK( \ PRINT_LIST (lst1); \ PRINT_LIST (lst2); \ PRINT_INT (mem_allocated ()); \ ) // +------+----------------------------------------------------------- // | Main | // +------+ int main () { struct dll *lst1, *lst2; char stuff[] = "Hello"; PRINT_INT (mem_allocated ()); EXPERIMENT (lst1 = dll_new ()); EXPERIMENT (lst2 = dll_new ()); PRINT_STUFF (); EXPERIMENT (dll_append (lst1, stuff)); PRINT_STUFF (); EXPERIMENT (dll_append (lst1, stuff)); PRINT_STUFF (); EXPERIMENT (dll_append (lst1, "Hi")); PRINT_STUFF (); EXPERIMENT (dll_append (lst2, "Goodbye")); PRINT_STUFF (); EXPERIMENT (dll_clear (lst1)); PRINT_STUFF (); EXPERIMENT (dll_append (lst1, stuff)); PRINT_STUFF (); return 0; } // main