/* * Do some basic list manipulations and output to log for * script comparison. Only testing the macros we use. */ int main(int argc, char *argv[]) { PTEST_NODE pNode = NULL; START(argc, argv, "win_lists"); LIST_INIT(&TestListHead); UT_ASSERT_rt(LIST_EMPTY(&TestListHead)); pNode = allocNode(); pNode->dummy = 0; LIST_INSERT_HEAD(&TestListHead, pNode, ListEntry); UT_ASSERTeq_rt(1, getListCount()); dump_list(); /* Remove one node */ LIST_REMOVE(pNode, ListEntry); UT_ASSERTeq_rt(0, getListCount()); dump_list(); free(pNode); /* Add a bunch of nodes */ for (int i = 1; i < 10; i++) { pNode = allocNode(); pNode->dummy = i; LIST_INSERT_HEAD(&TestListHead, pNode, ListEntry); } UT_ASSERTeq_rt(9, getListCount()); dump_list(); /* Remove all of them */ while (!LIST_EMPTY(&TestListHead)) { PTEST_NODE pNode = (PTEST_NODE)LIST_FIRST(&TestListHead); LIST_REMOVE(pNode, ListEntry); free(pNode); } UT_ASSERTeq_rt(0, getListCount()); dump_list(); DONE(NULL); }
/* * test_list - Do some basic list manipulations and output to log for * script comparison. Only testing the macros we use. */ static void test_list(void) { PTEST_LIST_NODE pNode = NULL; struct TestList head = LIST_HEAD_INITIALIZER(head); LIST_INIT(&head); UT_ASSERT_rt(LIST_EMPTY(&head)); pNode = MALLOC(sizeof(struct TEST_LIST_NODE)); pNode->dummy = 0; LIST_INSERT_HEAD(&head, pNode, ListEntry); UT_ASSERTeq_rt(1, get_list_count(&head)); dump_list(&head); /* Remove one node */ LIST_REMOVE(pNode, ListEntry); UT_ASSERTeq_rt(0, get_list_count(&head)); dump_list(&head); free(pNode); /* Add a bunch of nodes */ for (int i = 1; i < 10; i++) { pNode = MALLOC(sizeof(struct TEST_LIST_NODE)); pNode->dummy = i; LIST_INSERT_HEAD(&head, pNode, ListEntry); } UT_ASSERTeq_rt(9, get_list_count(&head)); dump_list(&head); /* Remove all of them */ while (!LIST_EMPTY(&head)) { pNode = (PTEST_LIST_NODE)LIST_FIRST(&head); LIST_REMOVE(pNode, ListEntry); free(pNode); } UT_ASSERTeq_rt(0, get_list_count(&head)); dump_list(&head); }