summaryrefslogtreecommitdiffstats
path: root/tests/auto/core
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/core')
-rw-r--r--tests/auto/core/handle/tst_handle.cpp96
-rw-r--r--tests/auto/core/qresourcemanager/tst_qresourcemanager.cpp25
2 files changed, 32 insertions, 89 deletions
diff --git a/tests/auto/core/handle/tst_handle.cpp b/tests/auto/core/handle/tst_handle.cpp
index 07155844f..4d4ccb645 100644
--- a/tests/auto/core/handle/tst_handle.cpp
+++ b/tests/auto/core/handle/tst_handle.cpp
@@ -28,12 +28,7 @@
#include <QtTest/QtTest>
#include <Qt3DCore/private/qhandle_p.h>
-
-#if Q_BYTE_ORDER == Q_BIG_ENDIAN
-#define GET_EXPECTED_HANDLE(qHandle) ((qHandle.index() << (qHandle.CounterBits + 2)) + (qHandle.counter() << 2))
-#else /* Q_LITTLE_ENDIAN */
-#define GET_EXPECTED_HANDLE(qHandle) (qHandle.index() + (qHandle.counter() << qHandle.IndexBits))
-#endif
+#include <Qt3DCore/private/qresourcemanager_p.h>
class tst_Handle : public QObject
{
@@ -49,8 +44,6 @@ private slots:
void assignment();
void equality();
void inequality();
- void staticLimits();
- void bigHandle();
};
class SimpleResource
@@ -64,107 +57,60 @@ public:
};
typedef Qt3DCore::QHandle<SimpleResource> Handle;
-typedef Qt3DCore::QHandle<SimpleResource, 22> BigHandle;
+typedef Qt3DCore::QHandleData<SimpleResource> HandleData;
void tst_Handle::defaultConstruction()
{
Handle h;
QVERIFY(h.isNull() == true);
- QVERIFY(h.index() == 0);
- QVERIFY(h.counter() == 0);
QVERIFY(h.handle() == 0);
}
void tst_Handle::construction()
{
- Handle h(0, 1);
+ HandleData d;
+ Handle h(&d);
QVERIFY(h.isNull() == false);
- QVERIFY(h.index() == 0);
- QVERIFY(h.counter() == 1);
qDebug() << h;
- QVERIFY(h.handle() == GET_EXPECTED_HANDLE(h));
-
- Handle h2(1, 1);
- QVERIFY(h2.isNull() == false);
- QVERIFY(h2.index() == 1);
- QVERIFY(h2.counter() == 1);
- qDebug() << h2;
- QVERIFY(h2.handle() == GET_EXPECTED_HANDLE(h2));
+ QVERIFY(h.handle() == reinterpret_cast<quintptr>(&d));
}
void tst_Handle::copyConstruction()
{
- Handle h1(0, 1);
- Handle h2(h1);
+ HandleData d;
+ Handle h(&d);
+ Handle h2(h);
QVERIFY(h2.isNull() == false);
- QVERIFY(h2.index() == 0);
- QVERIFY(h2.counter() == 1);
- QVERIFY(h2.handle() == GET_EXPECTED_HANDLE(h2));
+ QVERIFY(h2.handle() == h.handle());
}
void tst_Handle::assignment()
{
- Handle h1(0, 1);
- Handle h2 = h1;
+ HandleData d;
+ Handle h(&d);
+ Handle h2;
+ h2 = h;
QVERIFY(h2.isNull() == false);
- QVERIFY(h2.index() == 0);
- QVERIFY(h2.counter() == 1);
- QVERIFY(h2.handle() == GET_EXPECTED_HANDLE(h2));
+ QVERIFY(h2.handle() == h.handle());
}
void tst_Handle::equality()
{
- Handle h1(2, 1);
- Handle h2(2, 1);
+ HandleData d;
+ Handle h1(&d);
+ Handle h2(&d);
QVERIFY(h1.isNull() == false);
- QVERIFY(h1.index() == 2);
- QVERIFY(h1.counter() == 1);
- QVERIFY(h1.handle() == GET_EXPECTED_HANDLE(h1));
QVERIFY(h1 == h2);
}
void tst_Handle::inequality()
{
- Handle h1(2, 1);
- Handle h2(3, 1);
+ HandleData d1;
+ HandleData d2;
+ Handle h1(&d1);
+ Handle h2(&d2);
QVERIFY(h1.isNull() == false);
- QVERIFY(h1.index() == 2);
- QVERIFY(h1.counter() == 1);
- QVERIFY(h1.handle() == GET_EXPECTED_HANDLE(h1));
QVERIFY(h1 != h2);
-
- Handle h3(2, 2);
- QVERIFY(h1 != h3);
-}
-
-void tst_Handle::staticLimits()
-{
- QVERIFY(Handle::maxIndex() == (1 << 16) - 1);
- QVERIFY(Handle::maxCounter() == (1 << (32 - 16 - 2)) - 1);
-}
-
-void tst_Handle::bigHandle()
-{
- BigHandle h;
- QVERIFY(h.isNull() == true);
- QVERIFY(h.index() == 0);
- QVERIFY(h.counter() == 0);
- QVERIFY(h.handle() == 0);
-
- BigHandle h1(0, 1);
- QVERIFY(h1.isNull() == false);
- QVERIFY(h1.index() == 0);
- QVERIFY(h1.counter() == 1);
- QVERIFY(h1.handle() == GET_EXPECTED_HANDLE(h1));
-
- BigHandle h2(1, 1);
- QVERIFY(h2.isNull() == false);
- QVERIFY(h2.index() == 1);
- QVERIFY(h2.counter() == 1);
- QVERIFY(h2.handle() == GET_EXPECTED_HANDLE(h2));
-
- QVERIFY(BigHandle::maxIndex() == (1 << 22) - 1);
- QVERIFY(BigHandle::maxCounter() == (1 << (32 - 22 - 2)) - 1);
}
QTEST_APPLESS_MAIN(tst_Handle)
diff --git a/tests/auto/core/qresourcemanager/tst_qresourcemanager.cpp b/tests/auto/core/qresourcemanager/tst_qresourcemanager.cpp
index c3238fc8f..b7bd7c28a 100644
--- a/tests/auto/core/qresourcemanager/tst_qresourcemanager.cpp
+++ b/tests/auto/core/qresourcemanager/tst_qresourcemanager.cpp
@@ -97,8 +97,9 @@ void tst_DynamicArrayPolicy::acquireResources()
}
for (uint i = 0; i < 5; i++) {
- QVERIFY(handles.at(i).index() == i);
- QVERIFY(handles.at(i).counter() == 1);
+ QVERIFY(!handles.at(i).isNull());
+ if (i > 0)
+ QVERIFY(handles.at(i) != handles.at(i-1));
}
}
@@ -117,8 +118,6 @@ void tst_DynamicArrayPolicy::getResources()
}
for (uint i = 0; i < 5; i++) {
- QVERIFY(handles.at(i).index() == i);
- QVERIFY(handles.at(i).counter() == 1);
resources << manager.data(handles.at(i));
QVERIFY(resources.at(i) != nullptr);
resources.at(i)->m_value = i;
@@ -153,8 +152,6 @@ void tst_DynamicArrayPolicy::registerResourcesResize()
}
for (int i = 0; i < 7; i++) {
- QVERIFY(handles.at(i).index() == static_cast<uint>(i));
- QVERIFY(handles.at(i).counter() == 1);
if (i < 2)
QVERIFY(manager.data(handles.at(i))->m_value == i + 2);
else
@@ -169,14 +166,16 @@ void tst_DynamicArrayPolicy::removeResource()
{
Qt3DCore::QResourceManager<tst_ArrayResource, int> manager;
- QList<tst_ArrayResource *> resources;
QList<tHandle> handles;
for (int i = 0; i < 32; i++) {
handles << manager.acquire();
- resources << manager.data(handles.at(i));
}
+
+ tst_ArrayResource *resource = handles.at(2).data();
+ QVERIFY(resource != nullptr);
+
manager.release(handles.at(2));
QVERIFY(manager.data(handles.at(2)) == nullptr);
// Triggers QASSERT so commented
@@ -255,7 +254,7 @@ protected:
void run()
{
int i = 0;
- int max = tHandle::maxIndex();
+ int max = 65535;
while (i < max) {
tst_ArrayResource *r = m_manager->getOrCreateResource(i);
i++;
@@ -275,7 +274,7 @@ void tst_DynamicArrayPolicy::heavyDutyMultiThreadedAccess()
QList<tst_Thread *> threads;
int iterations = 8;
- int max = tHandle16::maxIndex();
+ int max = 65535;
for (int i = 0; i < iterations; i++) {
tst_Thread *thread = new tst_Thread();
@@ -326,7 +325,7 @@ protected:
void run()
{
int i = 0;
- int max = tHandle::maxIndex();
+ int max = 65535;
while (i < max) {
tst_ArrayResource *r = m_manager->getOrCreateResource(i);
QVERIFY(r != nullptr);
@@ -349,7 +348,7 @@ void tst_DynamicArrayPolicy::heavyDutyMultiThreadedAccessRelease()
QList<tst_Thread2 *> threads;
int iterations = 8;
- int max = tHandle16::maxIndex();
+ int max = 65535;
for (int u = 0; u < 2; u++) {
@@ -385,8 +384,6 @@ void tst_DynamicArrayPolicy::maximumNumberOfResources()
QList<tst_ArrayResource *> resources;
QList<tHandle16> handles;
- QCOMPARE(tHandle16::maxIndex(), (uint)manager.maximumSize());
-
for (int i = 0; i < manager.maximumSize(); i++) {
handles << manager.acquire();
resources << manager.data(handles.at(i));