int test_clear() { const char *test_name = "test_clear"; const int num_elements = 100000; struct llist *list_p; int i; list_p = create_llist(); for (i = 0; i < num_elements; i++) prepend_element(list_p, &i); if (list_p->count != num_elements) { printf("count wrong: %d, expected %d.\n", list_p->count, num_elements); return 1; } clear_llist(list_p); if (0 != list_p->count ) { printf ("%s: count wrong: expected 0, got %d\n", test_name, list_p->count); return 1; } if (NULL != list_p->head) { printf ("%s: expected NULL head.\n", test_name); return 1; } if (NULL != list_p->tail) { printf ("%s: expected NULL tail.\n", test_name); return 1; } printf("%s ok.\n", test_name); return 0; }
void destroy_llist(struct llist *l) { clear_llist(l); free(l); }