diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2015-07-02 15:14:06 +0200 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2015-07-02 20:11:21 +0000 |
commit | e5a6a2abdfbf0620a5782665ea03a82f30c3def3 (patch) | |
tree | 493475c004090d14b00c12152cd377ba6c206a5f /tests/auto/core/qframeallocator/tst_qframeallocator.cpp | |
parent | f6e989709cef935027ae5b822328004527ff3711 (diff) |
QFrameAllocator: add even more unit tests
Change-Id: Ib4d906962346782038b4b8d10a497ce895f8c184
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests/auto/core/qframeallocator/tst_qframeallocator.cpp')
-rw-r--r-- | tests/auto/core/qframeallocator/tst_qframeallocator.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/auto/core/qframeallocator/tst_qframeallocator.cpp b/tests/auto/core/qframeallocator/tst_qframeallocator.cpp index 38c97ed6d..e78cf568f 100644 --- a/tests/auto/core/qframeallocator/tst_qframeallocator.cpp +++ b/tests/auto/core/qframeallocator/tst_qframeallocator.cpp @@ -103,6 +103,9 @@ private slots: void deallocateSubclass(); void clearQFrameAllocator(); void isEmptyQFrameAllocator(); + void subclassPointerClearing(); + void allocateWithRawMemoryDeallocate(); + void allocateDeallocateRawMemory(); }; void tst_QFrameAllocator::initQFrameChunk() @@ -714,6 +717,59 @@ void tst_QFrameAllocator::isEmptyQFrameAllocator() } } +void tst_QFrameAllocator::subclassPointerClearing() +{ + // GIVEN + Qt3D::QFrameAllocator f(128, 32); + QVector<composed *> data; + + // WHEN + for (int i = 0; i < 32; ++i) { + composed *c = (i % 2 == 0) ? f.allocate<composed>() : f.allocate<subclass>(); + data.append(c); + } + // THEN + QVERIFY(!f.isEmpty()); + + // WHEN + for (int j = 0; j < 32; ++j) { + if ((j % 2 == 0)) + f.deallocate<composed>(data.takeAt(0)); + else + f.deallocate<subclass>(static_cast<subclass *>(data.takeAt(0))); + } + + // THEN + QVERIFY(f.isEmpty()); +} + +void tst_QFrameAllocator::allocateWithRawMemoryDeallocate() +{ + // GIVEN + Qt3D::QFrameAllocator f(128, 32); + subclass *s = static_cast<subclass *>(f.allocateRawMemory(sizeof(subclass))); + new (s) subclass(); + + // WHEN + f.deallocate(s); + + // THEN + QVERIFY(f.isEmpty()); +} + +void tst_QFrameAllocator::allocateDeallocateRawMemory() +{ + // GIVEN + Qt3D::QFrameAllocator f(128, 32); + subclass *s = f.allocate<subclass>(); + + // WHEN + f.deallocateRawMemory(s, sizeof(subclass)); + + // THEN + QVERIFY(f.isEmpty()); +} + QTEST_APPLESS_MAIN(tst_QFrameAllocator) #include "tst_qframeallocator.moc" |