void test_slist_reverse_empty(void) { assert_true(test_slist == NULL); test_slist = slist_create(); assert_true(test_slist != NULL); assert_true(slist_is_empty(test_slist)); assert_true(slist_reverse(test_slist) == 0); slist_free_all(test_slist, NULL); test_slist = NULL; }
void test_slist_reverse_existing(void) { unsigned long *val; unsigned long i, val_check; val = NULL; val_check = *(unsigned long *)slist_index(test_slist, slist_size(test_slist) - 1); assert_true(slist_reverse(test_slist) == 0); for(i = 0; i < slist_size(test_slist); i++, val_check--) { val = slist_index(test_slist, i); assert_true(val != NULL); assert_ulong_equal(*val, val_check); } }
int mod_unload_modules(char *modules) { int ok = 1; slist_t *sl0, *sl; sl0 = slist_reverse(slist_split(' ', modules)); for(sl = sl0; sl; sl = sl->next) { if(mod_is_loaded(sl->key)) { mod_unload_module(sl->key); if(mod_is_loaded(sl->key)) ok = 0; } } slist_free(sl0); return ok; }
void do_test(unsigned int c) { unsigned int i; struct node *p, *n; SLIST_HEAD(head); for (i = 0; i < c; ++i) { p = (struct node*)malloc(sizeof(*p)); if (!p) { perror("malloc failed"); exit(1); } p->data = c - i; slist_add(&p->slist, &head); } slist_for_each_entry(p, &head, slist) printf("%d ", p->data); printf("\n"); slist_reverse(&head); slist_for_each_entry(p, &head, slist) printf("%d ", p->data); printf("\n"); slist_for_each_entry(p, &head, slist) p->data = (size_t)rand()%100; printf("before sort: "); slist_for_each_entry(p, &head, slist) printf("%d ", p->data); printf("\n"); slist_sort(NULL, &head, int_cmp); printf("after sort: "); slist_for_each_entry(p, &head, slist) printf("%d ", p->data); printf("\n"); slist_for_each_entry_safe(p, n, &head, slist) free(p); }