--- a/tests/test_list.cpp Mon Jan 01 16:42:37 2024 +0100 +++ b/tests/test_list.cpp Mon Jan 01 16:43:18 2024 +0100 @@ -39,8 +39,8 @@ #include <algorithm> struct node { - node *next = nullptr; - node *prev = nullptr; + node *next = NULL; + node *prev = NULL; int data = 0; }; @@ -49,11 +49,11 @@ const ptrdiff_t loc_data = offsetof(struct node, data); struct node_test_data { - node *begin = nullptr; + node *begin = NULL; explicit node_test_data(node *begin) : begin(begin) { auto n = begin; - while (n != nullptr) { + while (n != NULL) { nodes.push_back(n); n = n->next; } @@ -72,7 +72,7 @@ }; static node_test_data create_nodes_test_data(size_t len) { - if (len == 0) return node_test_data{nullptr}; + if (len == 0) return node_test_data{NULL}; auto begin = new node; auto prev = begin; for (size_t i = 1; i < len; i++) { @@ -88,7 +88,7 @@ InputIter begin, InputIter end ) { - if (begin == end) return node_test_data{nullptr}; + if (begin == end) return node_test_data{NULL}; node *first = new node; first->data = *begin; node *prev = first; @@ -119,26 +119,26 @@ node a, b, c; cx_linked_list_link(&a, &b, loc_prev, loc_next); - EXPECT_EQ(a.prev, nullptr); - EXPECT_EQ(a.next, &b); - EXPECT_EQ(b.prev, &a); - EXPECT_EQ(b.next, nullptr); + CX_TEST_ASSERT(a.prev == NULL); + CX_TEST_ASSERT(a.next == &b); + CX_TEST_ASSERT(b.prev == &a); + CX_TEST_ASSERT(b.next == NULL); cx_linked_list_unlink(&a, &b, loc_prev, loc_next); - EXPECT_EQ(a.prev, nullptr); - EXPECT_EQ(a.next, nullptr); - EXPECT_EQ(b.prev, nullptr); - EXPECT_EQ(b.next, nullptr); + CX_TEST_ASSERT(a.prev == NULL); + CX_TEST_ASSERT(a.next == NULL); + CX_TEST_ASSERT(b.prev == NULL); + CX_TEST_ASSERT(b.next == NULL); cx_linked_list_link(&b, &c, loc_prev, loc_next); cx_linked_list_link(&a, &b, loc_prev, loc_next); cx_linked_list_unlink(&b, &c, loc_prev, loc_next); - EXPECT_EQ(a.prev, nullptr); - EXPECT_EQ(a.next, &b); - EXPECT_EQ(b.prev, &a); - EXPECT_EQ(b.next, nullptr); - EXPECT_EQ(c.prev, nullptr); - EXPECT_EQ(c.next, nullptr); + CX_TEST_ASSERT(a.prev == NULL); + CX_TEST_ASSERT(a.next == &b); + CX_TEST_ASSERT(b.prev == &a); + CX_TEST_ASSERT(b.next == NULL); + CX_TEST_ASSERT(c.prev == NULL); + CX_TEST_ASSERT(c.next == NULL); } TEST(LinkedList_LowLevel, cx_linked_list_at) { @@ -151,13 +151,13 @@ EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 1), &b); EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 2), &c); EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 3), &d); - EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 4), nullptr); + EXPECT_EQ(cx_linked_list_at(&a, 0, loc_next, 4), NULL); EXPECT_EQ(cx_linked_list_at(&b, 1, loc_prev, 0), &a); EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 1), &b); EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 2), &c); EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 3), &d); - EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 4), nullptr); + EXPECT_EQ(cx_linked_list_at(&b, 1, loc_next, 4), NULL); EXPECT_EQ(cx_linked_list_at(&d, 3, loc_prev, 0), &a); EXPECT_EQ(cx_linked_list_at(&d, 3, loc_prev, 1), &b); @@ -199,68 +199,68 @@ // test with begin, end / prev, next { node nodes[4]; - void *begin = nullptr, *end = nullptr; + void *begin = NULL, *end = NULL; cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[0]); - EXPECT_EQ(begin, &nodes[0]); - EXPECT_EQ(end, &nodes[0]); - EXPECT_EQ(nodes[0].prev, nullptr); - EXPECT_EQ(nodes[0].next, nullptr); + CX_TEST_ASSERT(begin == &nodes[0]); + CX_TEST_ASSERT(end == &nodes[0]); + CX_TEST_ASSERT(nodes[0].prev == NULL); + CX_TEST_ASSERT(nodes[0].next == NULL); cx_linked_list_add(&begin, &end, loc_prev, loc_next, &nodes[1]); - EXPECT_EQ(begin, &nodes[0]); - EXPECT_EQ(end, &nodes[1]); - EXPECT_EQ(nodes[0].next, &nodes[1]); - EXPECT_EQ(nodes[1].prev, &nodes[0]); + CX_TEST_ASSERT(begin == &nodes[0]); + CX_TEST_ASSERT(end == &nodes[1]); + CX_TEST_ASSERT(nodes[0].next == &nodes[1]); + CX_TEST_ASSERT(nodes[1].prev == &nodes[0]); } // test with begin only / prev, next { node nodes[4]; - void *begin = nullptr; + void *begin = NULL; - cx_linked_list_add(&begin, nullptr, loc_prev, loc_next, &nodes[0]); - EXPECT_EQ(begin, &nodes[0]); - cx_linked_list_add(&begin, nullptr, loc_prev, loc_next, &nodes[1]); - EXPECT_EQ(begin, &nodes[0]); - EXPECT_EQ(nodes[0].next, &nodes[1]); - EXPECT_EQ(nodes[1].prev, &nodes[0]); + cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[0]); + CX_TEST_ASSERT(begin == &nodes[0]); + cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[1]); + CX_TEST_ASSERT(begin == &nodes[0]); + CX_TEST_ASSERT(nodes[0].next == &nodes[1]); + CX_TEST_ASSERT(nodes[1].prev == &nodes[0]); - cx_linked_list_add(&begin, nullptr, loc_prev, loc_next, &nodes[2]); - EXPECT_EQ(nodes[1].next, &nodes[2]); - EXPECT_EQ(nodes[2].prev, &nodes[1]); + cx_linked_list_add(&begin, NULL, loc_prev, loc_next, &nodes[2]); + CX_TEST_ASSERT(nodes[1].next == &nodes[2]); + CX_TEST_ASSERT(nodes[2].prev == &nodes[1]); } // test with end only / prev, next { node nodes[4]; - void *end = nullptr; + void *end = NULL; - cx_linked_list_add(nullptr, &end, loc_prev, loc_next, &nodes[0]); - EXPECT_EQ(end, &nodes[0]); - cx_linked_list_add(nullptr, &end, loc_prev, loc_next, &nodes[1]); - EXPECT_EQ(end, &nodes[1]); - EXPECT_EQ(nodes[0].next, &nodes[1]); - EXPECT_EQ(nodes[1].prev, &nodes[0]); + cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[0]); + CX_TEST_ASSERT(end == &nodes[0]); + cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[1]); + CX_TEST_ASSERT(end == &nodes[1]); + CX_TEST_ASSERT(nodes[0].next == &nodes[1]); + CX_TEST_ASSERT(nodes[1].prev == &nodes[0]); - cx_linked_list_add(nullptr, &end, loc_prev, loc_next, &nodes[2]); - EXPECT_EQ(end, &nodes[2]); - EXPECT_EQ(nodes[1].next, &nodes[2]); - EXPECT_EQ(nodes[2].prev, &nodes[1]); + cx_linked_list_add(NULL, &end, loc_prev, loc_next, &nodes[2]); + CX_TEST_ASSERT(end == &nodes[2]); + CX_TEST_ASSERT(nodes[1].next == &nodes[2]); + CX_TEST_ASSERT(nodes[2].prev == &nodes[1]); } // test with begin, end / next { node nodes[4]; - void *begin = nullptr, *end = nullptr; + void *begin = NULL, *end = NULL; cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[0]); - EXPECT_EQ(begin, &nodes[0]); - EXPECT_EQ(end, &nodes[0]); + CX_TEST_ASSERT(begin == &nodes[0]); + CX_TEST_ASSERT(end == &nodes[0]); cx_linked_list_add(&begin, &end, -1, loc_next, &nodes[1]); - EXPECT_EQ(end, &nodes[1]); - EXPECT_EQ(nodes[0].next, &nodes[1]); - EXPECT_EQ(nodes[1].prev, nullptr); + CX_TEST_ASSERT(end == &nodes[1]); + CX_TEST_ASSERT(nodes[0].next == &nodes[1]); + CX_TEST_ASSERT(nodes[1].prev == NULL); } } @@ -268,73 +268,73 @@ // test with begin, end / prev, next { node nodes[4]; - void *begin = nullptr, *end = nullptr; + void *begin = NULL, *end = NULL; cx_linked_list_prepend(&begin, &end, loc_prev, loc_next, &nodes[0]); - EXPECT_EQ(begin, &nodes[0]); - EXPECT_EQ(end, &nodes[0]); - EXPECT_EQ(nodes[0].prev, nullptr); - EXPECT_EQ(nodes[0].next, nullptr); + CX_TEST_ASSERT(begin == &nodes[0]); + CX_TEST_ASSERT(end == &nodes[0]); + CX_TEST_ASSERT(nodes[0].prev == NULL); + CX_TEST_ASSERT(nodes[0].next == NULL); cx_linked_list_prepend(&begin, &end, loc_prev, loc_next, &nodes[1]); - EXPECT_EQ(begin, &nodes[1]); - EXPECT_EQ(end, &nodes[0]); - EXPECT_EQ(nodes[1].next, &nodes[0]); - EXPECT_EQ(nodes[0].prev, &nodes[1]); + CX_TEST_ASSERT(begin == &nodes[1]); + CX_TEST_ASSERT(end == &nodes[0]); + CX_TEST_ASSERT(nodes[1].next == &nodes[0]); + CX_TEST_ASSERT(nodes[0].prev == &nodes[1]); } // test with begin only / prev, next { node nodes[4]; - void *begin = nullptr; + void *begin = NULL; - cx_linked_list_prepend(&begin, nullptr, loc_prev, loc_next, &nodes[0]); - EXPECT_EQ(begin, &nodes[0]); - cx_linked_list_prepend(&begin, nullptr, loc_prev, loc_next, &nodes[1]); - EXPECT_EQ(begin, &nodes[1]); - EXPECT_EQ(nodes[1].next, &nodes[0]); - EXPECT_EQ(nodes[0].prev, &nodes[1]); + cx_linked_list_prepend(&begin, NULL, loc_prev, loc_next, &nodes[0]); + CX_TEST_ASSERT(begin == &nodes[0]); + cx_linked_list_prepend(&begin, NULL, loc_prev, loc_next, &nodes[1]); + CX_TEST_ASSERT(begin == &nodes[1]); + CX_TEST_ASSERT(nodes[1].next == &nodes[0]); + CX_TEST_ASSERT(nodes[0].prev == &nodes[1]); - cx_linked_list_prepend(&begin, nullptr, loc_prev, loc_next, &nodes[2]); - EXPECT_EQ(begin, &nodes[2]); - EXPECT_EQ(nodes[2].next, &nodes[1]); - EXPECT_EQ(nodes[1].prev, &nodes[2]); + cx_linked_list_prepend(&begin, NULL, loc_prev, loc_next, &nodes[2]); + CX_TEST_ASSERT(begin == &nodes[2]); + CX_TEST_ASSERT(nodes[2].next == &nodes[1]); + CX_TEST_ASSERT(nodes[1].prev == &nodes[2]); } // test with end only / prev, next { node nodes[4]; - void *end = nullptr; + void *end = NULL; - cx_linked_list_prepend(nullptr, &end, loc_prev, loc_next, &nodes[0]); - EXPECT_EQ(end, &nodes[0]); - cx_linked_list_prepend(nullptr, &end, loc_prev, loc_next, &nodes[1]); - EXPECT_EQ(end, &nodes[0]); - EXPECT_EQ(nodes[1].next, &nodes[0]); - EXPECT_EQ(nodes[0].prev, &nodes[1]); + cx_linked_list_prepend(NULL, &end, loc_prev, loc_next, &nodes[0]); + CX_TEST_ASSERT(end == &nodes[0]); + cx_linked_list_prepend(NULL, &end, loc_prev, loc_next, &nodes[1]); + CX_TEST_ASSERT(end == &nodes[0]); + CX_TEST_ASSERT(nodes[1].next == &nodes[0]); + CX_TEST_ASSERT(nodes[0].prev == &nodes[1]); - cx_linked_list_prepend(nullptr, &end, loc_prev, loc_next, &nodes[2]); - EXPECT_EQ(end, &nodes[0]); - EXPECT_EQ(nodes[2].next, &nodes[1]); - EXPECT_EQ(nodes[1].prev, &nodes[2]); + cx_linked_list_prepend(NULL, &end, loc_prev, loc_next, &nodes[2]); + CX_TEST_ASSERT(end == &nodes[0]); + CX_TEST_ASSERT(nodes[2].next == &nodes[1]); + CX_TEST_ASSERT(nodes[1].prev == &nodes[2]); } // test with begin, end / next { node nodes[4]; - void *begin = nullptr, *end = nullptr; + void *begin = NULL, *end = NULL; cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[0]); - EXPECT_EQ(begin, &nodes[0]); - EXPECT_EQ(end, &nodes[0]); + CX_TEST_ASSERT(begin == &nodes[0]); + CX_TEST_ASSERT(end == &nodes[0]); cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[1]); cx_linked_list_prepend(&begin, &end, -1, loc_next, &nodes[2]); - EXPECT_EQ(begin, &nodes[2]); - EXPECT_EQ(end, &nodes[0]); - EXPECT_EQ(nodes[1].next, &nodes[0]); - EXPECT_EQ(nodes[2].next, &nodes[1]); - EXPECT_EQ(nodes[1].prev, nullptr); - EXPECT_EQ(nodes[0].prev, nullptr); + CX_TEST_ASSERT(begin == &nodes[2]); + CX_TEST_ASSERT(end == &nodes[0]); + CX_TEST_ASSERT(nodes[1].next == &nodes[0]); + CX_TEST_ASSERT(nodes[2].next == &nodes[1]); + CX_TEST_ASSERT(nodes[1].prev == NULL); + CX_TEST_ASSERT(nodes[0].prev == NULL); } } @@ -348,12 +348,12 @@ cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); cx_linked_list_insert(&begin, &end, loc_prev, loc_next, &nodes[1], &nodes[3]); - EXPECT_EQ(begin, &nodes[0]); - EXPECT_EQ(end, &nodes[2]); - EXPECT_EQ(nodes[1].next, &nodes[3]); - EXPECT_EQ(nodes[2].prev, &nodes[3]); - EXPECT_EQ(nodes[3].prev, &nodes[1]); - EXPECT_EQ(nodes[3].next, &nodes[2]); + CX_TEST_ASSERT(begin == &nodes[0]); + CX_TEST_ASSERT(end == &nodes[2]); + CX_TEST_ASSERT(nodes[1].next == &nodes[3]); + CX_TEST_ASSERT(nodes[2].prev == &nodes[3]); + CX_TEST_ASSERT(nodes[3].prev == &nodes[1]); + CX_TEST_ASSERT(nodes[3].next == &nodes[2]); } // insert end @@ -365,11 +365,11 @@ cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); cx_linked_list_insert(&begin, &end, loc_prev, loc_next, &nodes[2], &nodes[3]); - EXPECT_EQ(begin, &nodes[0]); - EXPECT_EQ(end, &nodes[3]); - EXPECT_EQ(nodes[2].next, &nodes[3]); - EXPECT_EQ(nodes[3].prev, &nodes[2]); - EXPECT_EQ(nodes[3].next, nullptr); + CX_TEST_ASSERT(begin == &nodes[0]); + CX_TEST_ASSERT(end == &nodes[3]); + CX_TEST_ASSERT(nodes[2].next == &nodes[3]); + CX_TEST_ASSERT(nodes[3].prev == &nodes[2]); + CX_TEST_ASSERT(nodes[3].next == NULL); } // insert begin @@ -380,12 +380,12 @@ cx_linked_list_link(&nodes[0], &nodes[1], loc_prev, loc_next); cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); - cx_linked_list_insert(&begin, &end, loc_prev, loc_next, nullptr, &nodes[3]); - EXPECT_EQ(begin, &nodes[3]); - EXPECT_EQ(end, &nodes[2]); - EXPECT_EQ(nodes[0].prev, &nodes[3]); - EXPECT_EQ(nodes[3].prev, nullptr); - EXPECT_EQ(nodes[3].next, &nodes[0]); + cx_linked_list_insert(&begin, &end, loc_prev, loc_next, NULL, &nodes[3]); + CX_TEST_ASSERT(begin == &nodes[3]); + CX_TEST_ASSERT(end == &nodes[2]); + CX_TEST_ASSERT(nodes[0].prev == &nodes[3]); + CX_TEST_ASSERT(nodes[3].prev == NULL); + CX_TEST_ASSERT(nodes[3].next == &nodes[0]); } } @@ -399,13 +399,13 @@ cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next); - cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, &nodes[1], &nodes[3], nullptr); - EXPECT_EQ(begin, &nodes[0]); - EXPECT_EQ(end, &nodes[2]); - EXPECT_EQ(nodes[1].next, &nodes[3]); - EXPECT_EQ(nodes[2].prev, &nodes[4]); - EXPECT_EQ(nodes[3].prev, &nodes[1]); - EXPECT_EQ(nodes[4].next, &nodes[2]); + cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, &nodes[1], &nodes[3], NULL); + CX_TEST_ASSERT(begin == &nodes[0]); + CX_TEST_ASSERT(end == &nodes[2]); + CX_TEST_ASSERT(nodes[1].next == &nodes[3]); + CX_TEST_ASSERT(nodes[2].prev == &nodes[4]); + CX_TEST_ASSERT(nodes[3].prev == &nodes[1]); + CX_TEST_ASSERT(nodes[4].next == &nodes[2]); } // insert end @@ -417,12 +417,12 @@ cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next); - cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, &nodes[2], &nodes[3], nullptr); - EXPECT_EQ(begin, &nodes[0]); - EXPECT_EQ(end, &nodes[4]); - EXPECT_EQ(nodes[2].next, &nodes[3]); - EXPECT_EQ(nodes[3].prev, &nodes[2]); - EXPECT_EQ(nodes[4].next, nullptr); + cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, &nodes[2], &nodes[3], NULL); + CX_TEST_ASSERT(begin == &nodes[0]); + CX_TEST_ASSERT(end == &nodes[4]); + CX_TEST_ASSERT(nodes[2].next == &nodes[3]); + CX_TEST_ASSERT(nodes[3].prev == &nodes[2]); + CX_TEST_ASSERT(nodes[4].next == NULL); } // insert begin @@ -434,12 +434,12 @@ cx_linked_list_link(&nodes[1], &nodes[2], loc_prev, loc_next); cx_linked_list_link(&nodes[3], &nodes[4], loc_prev, loc_next); - cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, nullptr, &nodes[3], nullptr); - EXPECT_EQ(begin, &nodes[3]); - EXPECT_EQ(end, &nodes[2]); - EXPECT_EQ(nodes[0].prev, &nodes[4]); - EXPECT_EQ(nodes[3].prev, nullptr); - EXPECT_EQ(nodes[4].next, &nodes[0]); + cx_linked_list_insert_chain(&begin, &end, loc_prev, loc_next, NULL, &nodes[3], NULL); + CX_TEST_ASSERT(begin == &nodes[3]); + CX_TEST_ASSERT(end == &nodes[2]); + CX_TEST_ASSERT(nodes[0].prev == &nodes[4]); + CX_TEST_ASSERT(nodes[3].prev == NULL); + CX_TEST_ASSERT(nodes[4].next == &nodes[0]); } } @@ -463,7 +463,7 @@ TEST(LinkedList_LowLevel, cx_linked_list_prev) { auto testdata = create_nodes_test_data(3); auto begin = testdata.begin; - EXPECT_EQ(cx_linked_list_prev(begin, loc_next, begin), nullptr); + EXPECT_EQ(cx_linked_list_prev(begin, loc_next, begin), NULL); EXPECT_EQ(cx_linked_list_prev(begin, loc_next, begin->next), begin); EXPECT_EQ(cx_linked_list_prev(begin, loc_next, begin->next->next), begin->next); } @@ -477,26 +477,26 @@ auto end = reinterpret_cast<void *>(third); cx_linked_list_remove(&begin, &end, loc_prev, loc_next, second); - EXPECT_EQ(begin, first); - EXPECT_EQ(end, third); - EXPECT_EQ(first->prev, nullptr); - EXPECT_EQ(first->next, third); - EXPECT_EQ(third->prev, first); - EXPECT_EQ(third->next, nullptr); + CX_TEST_ASSERT(begin == first); + CX_TEST_ASSERT(end == third); + CX_TEST_ASSERT(first->prev == NULL); + CX_TEST_ASSERT(first->next == third); + CX_TEST_ASSERT(third->prev == first); + CX_TEST_ASSERT(third->next == NULL); cx_linked_list_remove(&begin, &end, loc_prev, loc_next, third); - EXPECT_EQ(begin, first); - EXPECT_EQ(end, first); - EXPECT_EQ(first->prev, nullptr); - EXPECT_EQ(first->next, nullptr); + CX_TEST_ASSERT(begin == first); + CX_TEST_ASSERT(end == first); + CX_TEST_ASSERT(first->prev == NULL); + CX_TEST_ASSERT(first->next == NULL); cx_linked_list_remove(&begin, &end, loc_prev, loc_next, first); - EXPECT_EQ(begin, nullptr); - EXPECT_EQ(end, nullptr); + CX_TEST_ASSERT(begin == NULL); + CX_TEST_ASSERT(end == NULL); } TEST(LinkedList_LowLevel, cx_linked_list_size) { - EXPECT_EQ(cx_linked_list_size(nullptr, loc_next), 0); + EXPECT_EQ(cx_linked_list_size(NULL, loc_next), 0); { auto testdata = create_nodes_test_data(5); @@ -510,9 +510,9 @@ } TEST(LinkedList_LowLevel, cx_linked_list_sort_empty) { - void *begin = nullptr; + void *begin = NULL; EXPECT_NO_FATAL_FAILURE( - cx_linked_list_sort(&begin, nullptr, loc_prev, loc_next, loc_data, cx_cmp_int); + cx_linked_list_sort(&begin, NULL, loc_prev, loc_next, loc_data, cx_cmp_int); ); } @@ -528,18 +528,18 @@ cx_linked_list_sort(&begin, &end, loc_prev, loc_next, loc_data, cx_cmp_int); node *check = reinterpret_cast<node *>(begin); - node *check_last = nullptr; + node *check_last = NULL; cx_for_n (i, sorted.size()) { - EXPECT_EQ(check->data, sorted[i]); - EXPECT_EQ(check->prev, check_last); + CX_TEST_ASSERT(check->data == sorted[i]); + CX_TEST_ASSERT(check->prev == check_last); if (i < sorted.size() - 1) { - ASSERT_NE(check->next, nullptr); + ASSERT_NE(check->next, NULL); } check_last = check; check = check->next; } - EXPECT_EQ(check, nullptr); - EXPECT_EQ(end, check_last); + CX_TEST_ASSERT(check == NULL); + CX_TEST_ASSERT(end == check_last); } TEST(LinkedList_LowLevel, cx_linked_list_reverse) { @@ -551,8 +551,8 @@ auto orig_begin = begin, orig_end = end; cx_linked_list_reverse(&begin, &end, loc_prev, loc_next); - EXPECT_EQ(end, orig_begin); - EXPECT_EQ(begin, orig_end); + CX_TEST_ASSERT(end == orig_begin); + CX_TEST_ASSERT(begin == orig_end); EXPECT_EQ(cx_linked_list_compare(begin, expected.begin, loc_next, loc_data, cx_cmp_int), 0); } @@ -563,14 +563,14 @@ void TearDown() override { for (auto &&l: lists) cxListDestroy(l); - EXPECT_TRUE(testingAllocator.verify()); + CX_TEST_ASSERT(testingAllocator.verify()); } static constexpr size_t testdata_len = 250; int_test_data<testdata_len> testdata; auto autofree(CxList *list) const -> CxList * { - if (list != nullptr) lists.insert(list); + if (list != NULL) lists.insert(list); return list; } @@ -606,7 +606,7 @@ ) { auto len = testdata_len; cx_for_n (i, len) EXPECT_EQ(cxListAdd(list, &testdata.data[i]), 0); - EXPECT_EQ(cxListSize(list), len); + CX_TEST_ASSERT(cxListSize(list) == len); cx_for_n (i, len) EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]); cx_for_n (i, len) ++testdata.data[i]; if (as_pointer) { @@ -629,7 +629,7 @@ EXPECT_EQ(cxListSize(list), 3); EXPECT_EQ(cxListInsert(list, 3, &d), 0); - ASSERT_EQ(cxListSize(list), 4); + CX_TEST_ASSERT(cxListSize(list) == 4); EXPECT_EQ(*(int *) cxListAt(list, 0), 47); EXPECT_EQ(*(int *) cxListAt(list, 1), 13); @@ -657,7 +657,7 @@ } else { inserted = cxListInsertArray(list, 0, a, 5); } - EXPECT_EQ(inserted, 5); + CX_TEST_ASSERT(inserted == 5); EXPECT_EQ(*(int *) cxListAt(list, 0), 5); EXPECT_EQ(*(int *) cxListAt(list, 1), 47); EXPECT_EQ(*(int *) cxListAt(list, 2), 11); @@ -668,7 +668,7 @@ } else { inserted = cxListInsertArray(list, 3, b, 5); } - EXPECT_EQ(inserted, 5); + CX_TEST_ASSERT(inserted == 5); EXPECT_EQ(*(int *) cxListAt(list, 0), 5); EXPECT_EQ(*(int *) cxListAt(list, 1), 47); EXPECT_EQ(*(int *) cxListAt(list, 2), 11); @@ -794,7 +794,7 @@ } static void verifySwap(CxList *list) { - ASSERT_EQ(cxListSize(list), 0); + CX_TEST_ASSERT(cxListSize(list) == 0); int original[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; int swapped[16] = {8, 4, 14, 3, 1, 5, 9, 12, 0, 6, 11, 10, 7, 15, 2, 13}; @@ -825,11 +825,11 @@ EXPECT_EQ(0, result); result = cxListSwap(list, 5, 16); - EXPECT_NE(0, result); + CX_TEST_ASSERT(0 != result); result = cxListSwap(list, 16, 6); - EXPECT_NE(0, result); + CX_TEST_ASSERT(0 != result); result = cxListSwap(list, 16, 17); - EXPECT_NE(0, result); + CX_TEST_ASSERT(0 != result); auto iter = cxListIterator(list); cx_foreach(int*, e, iter) { @@ -847,7 +847,7 @@ cx_for_n (i, len) { EXPECT_EQ(*(int *) cxListAt(list, i), testdata.data[i]); } - EXPECT_EQ(cxListAt(list, cxListSize(list)), nullptr); + EXPECT_EQ(cxListAt(list, cxListSize(list)), NULL); } void verifyFind(CxList *list) const { @@ -872,49 +872,49 @@ std::array<int, testdata_len> expected{}; std::partial_sort_copy(testdata.data.begin(), testdata.data.end(), expected.begin(), expected.end()); cxListSort(list); - cx_for_n (i, testdata_len) ASSERT_EQ(*(int *) cxListAt(list, i), expected[i]); + cx_for_n (i, testdata_len) CX_TEST_ASSERT(*(int *) cxListAt(list, i) == expected[i]); } void verifyIterator(CxList *list) const { auto iter = cxListIterator(list); size_t i = 0; cx_foreach(int*, x, iter) { - ASSERT_EQ(i, iter.index); + CX_TEST_ASSERT(i == iter.index); EXPECT_EQ(*x, testdata.data[iter.index]); i++; } - ASSERT_EQ(i, cxListSize(list)); + CX_TEST_ASSERT(i == cxListSize(list)); iter = cxListBackwardsIterator(list); cx_foreach(int*, x, iter) { - ASSERT_EQ(i - 1, iter.index); + CX_TEST_ASSERT(i - 1 == iter.index); EXPECT_EQ(*x, testdata.data[iter.index]); i--; } - ASSERT_EQ(i, 0); + CX_TEST_ASSERT(i == 0); auto len = testdata_len; i = len / 2; auto mut_iter = cxListMutIteratorAt(list, i); size_t j = 0; cx_foreach(int*, x, mut_iter) { - ASSERT_EQ(mut_iter.index, len / 2 + j / 2); - ASSERT_EQ(*x, testdata.data[i]); + CX_TEST_ASSERT(mut_iter.index == len / 2 + j / 2); + CX_TEST_ASSERT(*x == testdata.data[i]); if (i % 2 == 1) cxIteratorFlagRemoval(mut_iter); i++; j++; } - ASSERT_EQ(i, len); + CX_TEST_ASSERT(i == len); i = len / 2; j = 0; mut_iter = cxListMutBackwardsIteratorAt(list, i - 1); cx_foreach(int*, x, mut_iter) { - ASSERT_EQ(mut_iter.index, len / 2 - 1 - j); - ASSERT_EQ(*x, testdata.data[i - 1]); + CX_TEST_ASSERT(mut_iter.index == len / 2 - 1 - j); + CX_TEST_ASSERT(*x == testdata.data[i - 1]); if (i % 2 == 0) cxIteratorFlagRemoval(mut_iter); i--; j++; } - ASSERT_EQ(i, 0); - ASSERT_EQ(cxListSize(list), len / 2); + CX_TEST_ASSERT(i == 0); + CX_TEST_ASSERT(cxListSize(list) == len / 2); cx_for_n(j, len / 2) ASSERT_EQ(*(int *) cxListAt(list, j), testdata.data[j * 2]); } @@ -922,30 +922,30 @@ int newdata[] = {10, 20, 30, 40, 50}; auto iter = cxListMutIteratorAt(list, 2); - EXPECT_TRUE(cxIteratorValid(iter)); + CX_TEST_ASSERT(cxIteratorValid(iter)); EXPECT_EQ(iter.index, 2); EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2); cxListInsertAfter(&iter, &newdata[0]); - EXPECT_TRUE(cxIteratorValid(iter)); + CX_TEST_ASSERT(cxIteratorValid(iter)); EXPECT_EQ(iter.index, 2); EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2); cxListInsertBefore(&iter, &newdata[1]); - EXPECT_TRUE(cxIteratorValid(iter)); + CX_TEST_ASSERT(cxIteratorValid(iter)); EXPECT_EQ(iter.index, 3); EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 2); iter = cxListMutIterator(list); cxListInsertBefore(&iter, &newdata[2]); - EXPECT_TRUE(cxIteratorValid(iter)); + CX_TEST_ASSERT(cxIteratorValid(iter)); EXPECT_EQ(iter.index, 1); EXPECT_EQ(*(int *) cxIteratorCurrent(iter), 0); iter = cxListMutIteratorAt(list, cxListSize(list)); cxListInsertBefore(&iter, &newdata[3]); - EXPECT_FALSE(cxIteratorValid(iter)); + CX_TEST_ASSERT(!cxIteratorValid(iter)); EXPECT_EQ(iter.index, 9); iter = cxListMutIteratorAt(list, cxListSize(list)); cxListInsertAfter(&iter, &newdata[4]); - EXPECT_FALSE(cxIteratorValid(iter)); + CX_TEST_ASSERT(!cxIteratorValid(iter)); EXPECT_EQ(iter.index, 10); int expdata[] = {30, 0, 1, 20, 2, 10, 3, 4, 40, 50}; @@ -970,12 +970,12 @@ EXPECT_GT(cxListCompare(left, right), 0); EXPECT_LT(cxListCompare(right, left), 0); cxListAdd(right, &x); - ASSERT_EQ(cxListSize(left), cxListSize(right)); + CX_TEST_ASSERT(cxListSize(left) == cxListSize(right)); EXPECT_EQ(cxListCompare(left, right), 0); int a = 5, b = 10; cxListInsert(left, 15, &a); cxListInsert(right, 15, &b); - ASSERT_EQ(cxListSize(left), cxListSize(right)); + CX_TEST_ASSERT(cxListSize(left) == cxListSize(right)); EXPECT_LT(cxListCompare(left, right), 0); EXPECT_GT(cxListCompare(right, left), 0); *(int *) cxListAt(left, 15) = 10; @@ -1000,90 +1000,90 @@ TEST_F(PointerLinkedList, cxListStorePointers) { auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, 47)); - EXPECT_FALSE(cxListIsStoringPointers(list)); + CX_TEST_ASSERT(!cxListIsStoringPointers(list)); cxListStorePointers(list); EXPECT_EQ(list->item_size, sizeof(void *)); - EXPECT_NE(list->cl, nullptr); - EXPECT_NE(list->climpl, nullptr); - EXPECT_TRUE(cxListIsStoringPointers(list)); + CX_TEST_ASSERT(list->cl != NULL); + CX_TEST_ASSERT(list->climpl != NULL); + CX_TEST_ASSERT(cxListIsStoringPointers(list)); cxListStoreObjects(list); - EXPECT_NE(list->cl, nullptr); - EXPECT_EQ(list->climpl, nullptr); - EXPECT_FALSE(cxListIsStoringPointers(list)); + CX_TEST_ASSERT(list->cl != NULL); + EXPECT_EQ(list->climpl, NULL); + CX_TEST_ASSERT(!cxListIsStoringPointers(list)); } TEST_F(LinkedList, cxLinkedListCreate) { CxList *list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int))); - ASSERT_NE(list, nullptr); + ASSERT_NE(list, NULL); EXPECT_EQ(list->item_size, sizeof(int)); - EXPECT_EQ(list->simple_destructor, nullptr); - EXPECT_EQ(list->advanced_destructor, nullptr); - EXPECT_EQ(list->destructor_data, nullptr); + EXPECT_EQ(list->simple_destructor, NULL); + EXPECT_EQ(list->advanced_destructor, NULL); + EXPECT_EQ(list->destructor_data, NULL); EXPECT_EQ(cxListSize(list), 0); EXPECT_EQ(list->allocator, &testingAllocator); EXPECT_EQ(list->cmpfunc, cx_cmp_int); - EXPECT_FALSE(cxListIsStoringPointers(list)); + CX_TEST_ASSERT(!cxListIsStoringPointers(list)); } TEST_F(LinkedList, cxLinkedListCreateSimple) { CxList *list = autofree(cxLinkedListCreateSimple(sizeof(int))); - ASSERT_NE(list, nullptr); + ASSERT_NE(list, NULL); EXPECT_EQ(list->item_size, sizeof(int)); - EXPECT_EQ(list->cmpfunc, nullptr); + EXPECT_EQ(list->cmpfunc, NULL); EXPECT_EQ(list->allocator, cxDefaultAllocator); - EXPECT_EQ(list->simple_destructor, nullptr); - EXPECT_EQ(list->advanced_destructor, nullptr); - EXPECT_EQ(list->destructor_data, nullptr); + EXPECT_EQ(list->simple_destructor, NULL); + EXPECT_EQ(list->advanced_destructor, NULL); + EXPECT_EQ(list->destructor_data, NULL); EXPECT_EQ(cxListSize(list), 0); - EXPECT_FALSE(cxListIsStoringPointers(list)); + CX_TEST_ASSERT(!cxListIsStoringPointers(list)); } TEST_F(PointerLinkedList, cxLinkedListCreateSimpleForPointers) { CxList *list = autofree(cxLinkedListCreateSimple(CX_STORE_POINTERS)); - ASSERT_NE(list, nullptr); + ASSERT_NE(list, NULL); EXPECT_EQ(list->item_size, sizeof(void *)); EXPECT_EQ(list->cmpfunc, cx_cmp_ptr); EXPECT_EQ(list->allocator, cxDefaultAllocator); - EXPECT_EQ(list->simple_destructor, nullptr); - EXPECT_EQ(list->advanced_destructor, nullptr); - EXPECT_EQ(list->destructor_data, nullptr); + EXPECT_EQ(list->simple_destructor, NULL); + EXPECT_EQ(list->advanced_destructor, NULL); + EXPECT_EQ(list->destructor_data, NULL); EXPECT_EQ(cxListSize(list), 0); - EXPECT_TRUE(cxListIsStoringPointers(list)); + CX_TEST_ASSERT(cxListIsStoringPointers(list)); } TEST_F(ArrayList, cxArrayListCreate) { CxList *list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8)); - ASSERT_NE(list, nullptr); + ASSERT_NE(list, NULL); EXPECT_EQ(list->item_size, sizeof(int)); - EXPECT_EQ(list->simple_destructor, nullptr); - EXPECT_EQ(list->advanced_destructor, nullptr); - EXPECT_EQ(list->destructor_data, nullptr); + EXPECT_EQ(list->simple_destructor, NULL); + EXPECT_EQ(list->advanced_destructor, NULL); + EXPECT_EQ(list->destructor_data, NULL); EXPECT_EQ(cxListSize(list), 0); EXPECT_EQ(list->allocator, &testingAllocator); EXPECT_EQ(list->cmpfunc, cx_cmp_int); - EXPECT_FALSE(cxListIsStoringPointers(list)); + CX_TEST_ASSERT(!cxListIsStoringPointers(list)); } TEST_F(ArrayList, cxArrayListCreateSimple) { CxList *list = autofree(cxArrayListCreateSimple(sizeof(int), 8)); - ASSERT_NE(list, nullptr); - EXPECT_EQ(list->cmpfunc, nullptr); + ASSERT_NE(list, NULL); + EXPECT_EQ(list->cmpfunc, NULL); EXPECT_EQ(list->allocator, cxDefaultAllocator); EXPECT_EQ(list->item_size, sizeof(int)); - EXPECT_EQ(list->simple_destructor, nullptr); - EXPECT_EQ(list->advanced_destructor, nullptr); - EXPECT_EQ(list->destructor_data, nullptr); + EXPECT_EQ(list->simple_destructor, NULL); + EXPECT_EQ(list->advanced_destructor, NULL); + EXPECT_EQ(list->destructor_data, NULL); EXPECT_EQ(cxListSize(list), 0); - EXPECT_FALSE(cxListIsStoringPointers(list)); + CX_TEST_ASSERT(!cxListIsStoringPointers(list)); } TEST_F(PointerArrayList, cxArrayListCreateSimpleForPointers) { CxList *list = autofree(cxArrayListCreateSimple(CX_STORE_POINTERS, 8)); - ASSERT_NE(list, nullptr); + ASSERT_NE(list, NULL); EXPECT_EQ(list->cmpfunc, cx_cmp_ptr); EXPECT_EQ(list->allocator, cxDefaultAllocator); EXPECT_EQ(list->item_size, sizeof(void *)); - EXPECT_TRUE(cxListIsStoringPointers(list)); + CX_TEST_ASSERT(cxListIsStoringPointers(list)); } TEST_F(LinkedList, cxListAdd) { @@ -1456,11 +1456,11 @@ void *item = cxMalloc(&testingAllocator, sizeof(int)); auto list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS); cxListAdd(list, item); - ASSERT_FALSE(testingAllocator.verify()); + CX_TEST_ASSERT(!testingAllocator.verify()); cxListDestroy(list); - EXPECT_FALSE(testingAllocator.verify()); + CX_TEST_ASSERT(!testingAllocator.verify()); cxFree(&testingAllocator, item); - EXPECT_TRUE(testingAllocator.verify()); + CX_TEST_ASSERT(testingAllocator.verify()); } TEST_F(PointerLinkedList, DestroySimpleDestructor) { @@ -1478,20 +1478,20 @@ list->destructor_data = &testingAllocator; list->advanced_destructor = (cx_destructor_func2) cxFree; cxListAdd(list, item); - ASSERT_FALSE(testingAllocator.verify()); + CX_TEST_ASSERT(!testingAllocator.verify()); cxListDestroy(list); - EXPECT_TRUE(testingAllocator.verify()); + CX_TEST_ASSERT(testingAllocator.verify()); } TEST_F(PointerArrayList, DestroyNoDestructor) { void *item = cxMalloc(&testingAllocator, sizeof(int)); auto list = cxArrayListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS, 4); cxListAdd(list, item); - ASSERT_FALSE(testingAllocator.verify()); + CX_TEST_ASSERT(!testingAllocator.verify()); cxListDestroy(list); - EXPECT_FALSE(testingAllocator.verify()); + CX_TEST_ASSERT(!testingAllocator.verify()); cxFree(&testingAllocator, item); - EXPECT_TRUE(testingAllocator.verify()); + CX_TEST_ASSERT(testingAllocator.verify()); } TEST_F(PointerArrayList, DestroySimpleDestructor) { @@ -1509,9 +1509,9 @@ list->destructor_data = &testingAllocator; list->advanced_destructor = (cx_destructor_func2) cxFree; cxListAdd(list, item); - ASSERT_FALSE(testingAllocator.verify()); + CX_TEST_ASSERT(!testingAllocator.verify()); cxListDestroy(list); - EXPECT_TRUE(testingAllocator.verify()); + CX_TEST_ASSERT(testingAllocator.verify()); } TEST(EmptyList, Size) { @@ -1529,10 +1529,10 @@ auto it3 = cxListMutIterator(list); auto it4 = cxListMutBackwardsIterator(list); - EXPECT_FALSE(cxIteratorValid(it1)); - EXPECT_FALSE(cxIteratorValid(it2)); - EXPECT_FALSE(cxIteratorValid(it3)); - EXPECT_FALSE(cxIteratorValid(it4)); + CX_TEST_ASSERT(!cxIteratorValid(it1)); + CX_TEST_ASSERT(!cxIteratorValid(it2)); + CX_TEST_ASSERT(!cxIteratorValid(it3)); + CX_TEST_ASSERT(!cxIteratorValid(it4)); int c = 0; cx_foreach(void*, data, it1) c++; @@ -1553,8 +1553,8 @@ TEST(EmptyList, At) { auto list = cxEmptyList; - EXPECT_EQ(cxListAt(list, 0), nullptr); - EXPECT_EQ(cxListAt(list, 1), nullptr); + EXPECT_EQ(cxListAt(list, 0), NULL); + EXPECT_EQ(cxListAt(list, 1), NULL); } TEST(EmptyList, Find) {