}
}
+class ObjCountElem
+{
+public:
+ ObjCountElem (int* liveCount)
+ : m_liveCount(liveCount)
+ {
+ *m_liveCount += 1;
+ }
+
+ ~ObjCountElem (void)
+ {
+ *m_liveCount -= 1;
+ }
+
+ ObjCountElem (const ObjCountElem& other)
+ : m_liveCount(other.m_liveCount)
+ {
+ *m_liveCount += 1;
+ }
+
+ ObjCountElem& operator= (const ObjCountElem& other)
+ {
+ m_liveCount = other.m_liveCount;
+ *m_liveCount += 1;
+ return *this;
+ }
+
+private:
+ int* m_liveCount;
+};
+
+void runClearTest (deUint32 numElements1, deUint32 numElements2, deUint32 numElementsHint)
+{
+ int liveCount = 0;
+
+ {
+ de::AppendList<ObjCountElem> testList (numElementsHint);
+
+ for (deUint32 ndx = 0; ndx < numElements1; ++ndx)
+ testList.append(ObjCountElem(&liveCount));
+
+ DE_TEST_ASSERT(liveCount == (int)numElements1);
+
+ testList.clear();
+
+ DE_TEST_ASSERT(liveCount == 0);
+
+ for (deUint32 ndx = 0; ndx < numElements2; ++ndx)
+ testList.append(ObjCountElem(&liveCount));
+
+ DE_TEST_ASSERT(liveCount == (int)numElements2);
+ }
+
+ DE_TEST_ASSERT(liveCount == 0);
+}
+
} // anonymous
void AppendList_selfTest (void)
runAppendListTest(4, 10000, 500);
runAppendListTest(4, 100, 10);
}
+
+ // Dtor + clear()
+ runClearTest(1, 1, 1);
+ runClearTest(1, 2, 10);
+ runClearTest(50, 25, 10);
+ runClearTest(9, 50, 10);
+ runClearTest(10, 50, 10);
+ runClearTest(50, 9, 10);
+ runClearTest(50, 10, 10);
}
} // de
curBlock = delBlock->next;
// Call destructor for allocated elements
- for (; elementNdx < min(m_numElements, delBlock->blockNdx*m_blockSize); ++elementNdx)
+ for (; elementNdx < min(m_numElements, (delBlock->blockNdx+1)*m_blockSize); ++elementNdx)
delBlock->elements[elementNdx%m_blockSize].~ElementType();
delete delBlock;
curBlock = delBlock->next;
// Call destructor for allocated elements
- for (; elementNdx < min(m_numElements, delBlock->blockNdx*m_blockSize); ++elementNdx)
+ for (; elementNdx < min(m_numElements, (delBlock->blockNdx+1)*m_blockSize); ++elementNdx)
delBlock->elements[elementNdx%m_blockSize].~ElementType();
if (delBlock != m_first)
DE_ASSERT(elementNdx == m_numElements);
m_numElements = 0;
+ m_first->next = DE_NULL;
m_last = m_first;
}