test: Add tests for isd_get_commercial_credit()
[libisds.git] / test / offline / isds_list_free.c
blobc6114aadbbc277a67ebe54e60c589fd254c381e0
1 #include "../test.h"
2 #include "isds.h"
4 int counter;
6 static void destructor(void **data) {
7 counter++;
10 static int test_isds_list_free(struct isds_list **list, int destructor_hits) {
11 counter = 0;
13 isds_list_free(list);
15 if (destructor_hits != counter)
16 FAIL_TEST("Destructor called wrong times: expected=%d, called=%d",
17 destructor_hits, counter);
19 if (!list) PASS_TEST;
21 if (*list)
22 FAIL_TEST("isds_list_free() did not null pointer");
24 PASS_TEST;
28 int main(int argc, char **argv) {
30 INIT_TEST("isds_list_free()");
31 if (isds_init())
32 ABORT_UNIT("isds_init() failed");
35 /* isds_list_free() */
36 struct isds_list *list = NULL;
37 TEST("NULL", test_isds_list_free, NULL, 0);
38 TEST("*NULL", test_isds_list_free, &list, 0);
40 TEST_CALLOC(list);
41 TEST("One item without destructor", test_isds_list_free, &list, 0);
43 TEST_CALLOC(list);
44 list->destructor = destructor;
45 TEST("One item with destructor", test_isds_list_free, &list, 1);
47 TEST_CALLOC(list);
48 list->destructor = destructor;
49 TEST_CALLOC(list->next);
50 list->next->destructor = destructor;
51 TEST("Two items list", test_isds_list_free, &list, 2);
53 isds_cleanup();
54 SUM_TEST();