diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2014-09-17 15:28:07 +0200 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2014-09-30 00:24:31 +0200 |
commit | b3c7fd36830ef71e336a97fc5e69864f29cfc628 (patch) | |
tree | 469c9518eba7bf187b6112556ed1d5c66a554ee6 /tests | |
parent | a16ac5f912485b70a27900e36d3ec302d1d458f1 (diff) |
QFrameAllocator allocate based on size instead of type
Allows to handle allocation of subclasses using the overloaded new operator
from the parent.
Change-Id: Ie587c81fb3a5cb5aa6735377bfcc57bb4407b117
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/core/qframeallocator/tst_qframeallocator.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/auto/core/qframeallocator/tst_qframeallocator.cpp b/tests/auto/core/qframeallocator/tst_qframeallocator.cpp index e3d4cdb03..4bf6bdc31 100644 --- a/tests/auto/core/qframeallocator/tst_qframeallocator.cpp +++ b/tests/auto/core/qframeallocator/tst_qframeallocator.cpp @@ -77,6 +77,11 @@ public: int t; } composed; + typedef struct s_subclass : public composed + { + float toto; + } subclass; + private slots: void initQFrameChunk(); @@ -97,6 +102,8 @@ private slots: void allocateWithQFrameAllocator(); void deallocateWithQFrameAllocator(); void testAllocationComposedValues(); + void allocateSubclass(); + void deallocateSubclass(); void clearQFrameAllocator(); }; @@ -592,6 +599,64 @@ void tst_QFrameAllocator::testAllocationComposedValues() } } +void tst_QFrameAllocator::allocateSubclass() +{ + Qt3D::QFrameAllocator f(128, 32); + + QList<composed *> composeds; + + for (int i = 0; i < 256; i++) { + // Allocate a composed object of size subclass + // c is actually a subclass + composed *c = f.allocateRawMemory<composed>(sizeof(subclass)); + composeds << c; + } + + QCOMPARE(composeds.count(), 256); + + Q_FOREACH (composed *c, composeds) { + subclass *s = static_cast<subclass *>(c); + s->toto = 2586.0f; + } + + for (int i = 0; i < 256; i++) { + subclass *s = static_cast<subclass *>(composeds.takeLast()); + QVERIFY(s->toto == 2586.0f); + } +} + +void tst_QFrameAllocator::deallocateSubclass() +{ + Qt3D::QFrameAllocator f(128, 32); + + QList<composed *> composeds; + + for (int i = 0; i < 256; i++) { + // Allocate a composed object of size subclass + // c is actually a subclass + composed *c = f.allocateRawMemory<composed>(sizeof(subclass)); + composeds << c; + } + + for (int l = 0; l < 5; l++) { + + uint chunkCount = f.totalChunkCount(); + + for (int i = 0; i < 256; i++) { + f.deallocateRawMemory(composeds.takeLast()); + } + + for (int i = 0; i < 256; i++) { + // Allocate a composed object of size subclass + // c is actually a subclass + composed *c = f.allocateRawMemory<composed>(sizeof(subclass)); + composeds << c; + } + QCOMPARE(chunkCount, f.totalChunkCount()); + } + +} + void tst_QFrameAllocator::clearQFrameAllocator() { Qt3D::QFrameAllocator f(128, 32); |