tests/test_list.cpp

changeset 800
1274e46b3013
parent 798
7644da6e2d35
child 801
04aa3913c0e3
--- a/tests/test_list.cpp	Tue Jan 09 00:09:11 2024 +0100
+++ b/tests/test_list.cpp	Tue Jan 09 21:25:08 2024 +0100
@@ -481,93 +481,6 @@
 class PointerArrayList : public HighLevelTest {
 };
 
-TEST_F(PointerLinkedList, cxListStorePointers) {
-    auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, 47));
-    CX_TEST_ASSERT(!cxListIsStoringPointers(list));
-    cxListStorePointers(list);
-    EXPECT_EQ(list->item_size, sizeof(void *));
-    CX_TEST_ASSERT(list->cl != NULL);
-    CX_TEST_ASSERT(list->climpl != NULL);
-    CX_TEST_ASSERT(cxListIsStoringPointers(list));
-    cxListStoreObjects(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, NULL);
-    EXPECT_EQ(list->item_size, sizeof(int));
-    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);
-    CX_TEST_ASSERT(!cxListIsStoringPointers(list));
-}
-
-TEST_F(LinkedList, cxLinkedListCreateSimple) {
-    CxList *list = autofree(cxLinkedListCreateSimple(sizeof(int)));
-    ASSERT_NE(list, NULL);
-    EXPECT_EQ(list->item_size, sizeof(int));
-    EXPECT_EQ(list->cmpfunc, NULL);
-    EXPECT_EQ(list->allocator, cxDefaultAllocator);
-    EXPECT_EQ(list->simple_destructor, NULL);
-    EXPECT_EQ(list->advanced_destructor, NULL);
-    EXPECT_EQ(list->destructor_data, NULL);
-    EXPECT_EQ(cxListSize(list), 0);
-    CX_TEST_ASSERT(!cxListIsStoringPointers(list));
-}
-
-TEST_F(PointerLinkedList, cxLinkedListCreateSimpleForPointers) {
-    CxList *list = autofree(cxLinkedListCreateSimple(CX_STORE_POINTERS));
-    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, NULL);
-    EXPECT_EQ(list->advanced_destructor, NULL);
-    EXPECT_EQ(list->destructor_data, NULL);
-    EXPECT_EQ(cxListSize(list), 0);
-    CX_TEST_ASSERT(cxListIsStoringPointers(list));
-}
-
-TEST_F(ArrayList, cxArrayListCreate) {
-    CxList *list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8));
-    ASSERT_NE(list, NULL);
-    EXPECT_EQ(list->item_size, sizeof(int));
-    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);
-    CX_TEST_ASSERT(!cxListIsStoringPointers(list));
-}
-
-TEST_F(ArrayList, cxArrayListCreateSimple) {
-    CxList *list = autofree(cxArrayListCreateSimple(sizeof(int), 8));
-    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, NULL);
-    EXPECT_EQ(list->advanced_destructor, NULL);
-    EXPECT_EQ(list->destructor_data, NULL);
-    EXPECT_EQ(cxListSize(list), 0);
-    CX_TEST_ASSERT(!cxListIsStoringPointers(list));
-}
-
-TEST_F(PointerArrayList, cxArrayListCreateSimpleForPointers) {
-    CxList *list = autofree(cxArrayListCreateSimple(CX_STORE_POINTERS, 8));
-    ASSERT_NE(list, NULL);
-    EXPECT_EQ(list->cmpfunc, cx_cmp_ptr);
-    EXPECT_EQ(list->allocator, cxDefaultAllocator);
-    EXPECT_EQ(list->item_size, sizeof(void *));
-    CX_TEST_ASSERT(cxListIsStoringPointers(list));
-}
 
 TEST_F(LinkedList, cxListAdd) {
     auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, sizeof(int)));
@@ -935,6 +848,94 @@
     verifyAdvancedDestructor(pointerArrayListFromTestData());
 }
 
+TEST_F(PointerLinkedList, cxListStorePointers) {
+    auto list = autofree(cxLinkedListCreate(&testingAllocator, cx_cmp_int, 47));
+    CX_TEST_ASSERT(!cxListIsStoringPointers(list));
+    cxListStorePointers(list);
+    EXPECT_EQ(list->item_size, sizeof(void *));
+    CX_TEST_ASSERT(list->cl != NULL);
+    CX_TEST_ASSERT(list->climpl != NULL);
+    CX_TEST_ASSERT(cxListIsStoringPointers(list));
+    cxListStoreObjects(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, NULL);
+    EXPECT_EQ(list->item_size, sizeof(int));
+    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);
+    CX_TEST_ASSERT(!cxListIsStoringPointers(list));
+}
+
+TEST_F(LinkedList, cxLinkedListCreateSimple) {
+    CxList *list = autofree(cxLinkedListCreateSimple(sizeof(int)));
+    ASSERT_NE(list, NULL);
+    EXPECT_EQ(list->item_size, sizeof(int));
+    EXPECT_EQ(list->cmpfunc, NULL);
+    EXPECT_EQ(list->allocator, cxDefaultAllocator);
+    EXPECT_EQ(list->simple_destructor, NULL);
+    EXPECT_EQ(list->advanced_destructor, NULL);
+    EXPECT_EQ(list->destructor_data, NULL);
+    EXPECT_EQ(cxListSize(list), 0);
+    CX_TEST_ASSERT(!cxListIsStoringPointers(list));
+}
+
+TEST_F(PointerLinkedList, cxLinkedListCreateSimpleForPointers) {
+    CxList *list = autofree(cxLinkedListCreateSimple(CX_STORE_POINTERS));
+    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, NULL);
+    EXPECT_EQ(list->advanced_destructor, NULL);
+    EXPECT_EQ(list->destructor_data, NULL);
+    EXPECT_EQ(cxListSize(list), 0);
+    CX_TEST_ASSERT(cxListIsStoringPointers(list));
+}
+
+TEST_F(ArrayList, cxArrayListCreate) {
+    CxList *list = autofree(cxArrayListCreate(&testingAllocator, cx_cmp_int, sizeof(int), 8));
+    ASSERT_NE(list, NULL);
+    EXPECT_EQ(list->item_size, sizeof(int));
+    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);
+    CX_TEST_ASSERT(!cxListIsStoringPointers(list));
+}
+
+TEST_F(ArrayList, cxArrayListCreateSimple) {
+    CxList *list = autofree(cxArrayListCreateSimple(sizeof(int), 8));
+    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, NULL);
+    EXPECT_EQ(list->advanced_destructor, NULL);
+    EXPECT_EQ(list->destructor_data, NULL);
+    EXPECT_EQ(cxListSize(list), 0);
+    CX_TEST_ASSERT(!cxListIsStoringPointers(list));
+}
+
+TEST_F(PointerArrayList, cxArrayListCreateSimpleForPointers) {
+    CxList *list = autofree(cxArrayListCreateSimple(CX_STORE_POINTERS, 8));
+    ASSERT_NE(list, NULL);
+    EXPECT_EQ(list->cmpfunc, cx_cmp_ptr);
+    EXPECT_EQ(list->allocator, cxDefaultAllocator);
+    EXPECT_EQ(list->item_size, sizeof(void *));
+    CX_TEST_ASSERT(cxListIsStoringPointers(list));
+}
+
 TEST_F(PointerLinkedList, DestroyNoDestructor) {
     void *item = cxMalloc(&testingAllocator, sizeof(int));
     auto list = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_int, CX_STORE_POINTERS);
@@ -997,80 +998,3 @@
     CX_TEST_ASSERT(testingAllocator.verify());
 }
 
-TEST(EmptyList, Size) {
-    auto list = cxEmptyList;
-
-    EXPECT_EQ(list->size, 0);
-    EXPECT_EQ(cxListSize(list), 0);
-}
-
-TEST(EmptyList, Iterator) {
-    auto list = cxEmptyList;
-
-    auto it1 = cxListIterator(list);
-    auto it2 = cxListBackwardsIterator(list);
-    auto it3 = cxListMutIterator(list);
-    auto it4 = cxListMutBackwardsIterator(list);
-
-    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++;
-    cx_foreach(void*, data, it2) c++;
-    cx_foreach(void*, data, it3) c++;
-    cx_foreach(void*, data, it4) c++;
-    EXPECT_EQ(c, 0);
-}
-
-TEST(EmptyList, NoOps) {
-    auto list = cxEmptyList;
-
-    ASSERT_NO_FATAL_FAILURE(cxListSort(list));
-    ASSERT_NO_FATAL_FAILURE(cxListClear(list));
-    ASSERT_NO_FATAL_FAILURE(cxListDestroy(list));
-}
-
-TEST(EmptyList, At) {
-    auto list = cxEmptyList;
-
-    EXPECT_EQ(cxListAt(list, 0), NULL);
-    EXPECT_EQ(cxListAt(list, 1), NULL);
-}
-
-TEST(EmptyList, Find) {
-    auto list = cxEmptyList;
-
-    int x = 42, y = 1337;
-
-    EXPECT_LT(cxListFind(list, &x), 0);
-    EXPECT_LT(cxListFind(list, &y), 0);
-}
-
-TEST(EmptyList, Compare) {
-    auto empty = cxEmptyList;
-
-    auto ll = cxLinkedListCreateSimple(sizeof(int));
-    auto al = cxArrayListCreateSimple(sizeof(int), 8);
-
-    int x = 5;
-
-    EXPECT_EQ(cxListCompare(empty, cxEmptyList), 0);
-    EXPECT_EQ(cxListCompare(ll, cxEmptyList), 0);
-    EXPECT_EQ(cxListCompare(al, cxEmptyList), 0);
-    EXPECT_EQ(cxListCompare(cxEmptyList, ll), 0);
-    EXPECT_EQ(cxListCompare(cxEmptyList, al), 0);
-
-    cxListAdd(ll, &x);
-    cxListAdd(al, &x);
-
-    EXPECT_GT(cxListCompare(ll, cxEmptyList), 0);
-    EXPECT_GT(cxListCompare(al, cxEmptyList), 0);
-    EXPECT_LT(cxListCompare(cxEmptyList, ll), 0);
-    EXPECT_LT(cxListCompare(cxEmptyList, al), 0);
-
-    cxListDestroy(ll);
-    cxListDestroy(al);
-}

mercurial