diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2017-09-12 12:10:03 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-09-12 12:39:05 +0100 |
commit | 3f03499bf8a7cf3c3f8d19a020179c1205980bde (patch) | |
tree | 518b0ef3fb1b31d3856f43124150ef41acb8c1aa /tests | |
parent | 8a4b9ebadb9e63ae367694f04786c7faf6306f27 (diff) | |
parent | bf5fd7a78c91e29332ce70ad844b756150f32f18 (diff) |
Merge branch '5.9' into 5.10
Change-Id: Id6a3d4ec579a2f2a2e559c22a2293d0e184f0bdf
Diffstat (limited to 'tests')
15 files changed, 207 insertions, 829 deletions
diff --git a/tests/auto/core/arrayresourcesmanager/arrayresourcesmanager.pro b/tests/auto/core/arrayresourcesmanager/arrayresourcesmanager.pro deleted file mode 100644 index cc929575f..000000000 --- a/tests/auto/core/arrayresourcesmanager/arrayresourcesmanager.pro +++ /dev/null @@ -1,5 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS = \ - dynamicarraypolicy \ - preallocatedarraypolicy diff --git a/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/dynamicarraypolicy.pro b/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/dynamicarraypolicy.pro deleted file mode 100644 index ee2a73e03..000000000 --- a/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/dynamicarraypolicy.pro +++ /dev/null @@ -1,7 +0,0 @@ -TARGET = tst_dynamicarraypolicy -CONFIG += testcase -TEMPLATE = app - -SOURCES += tst_dynamicarraypolicy.cpp - -QT += testlib 3dcore 3dcore-private diff --git a/tests/auto/core/arrayresourcesmanager/preallocatedarraypolicy/preallocatedarraypolicy.pro b/tests/auto/core/arrayresourcesmanager/preallocatedarraypolicy/preallocatedarraypolicy.pro deleted file mode 100644 index 636c155b2..000000000 --- a/tests/auto/core/arrayresourcesmanager/preallocatedarraypolicy/preallocatedarraypolicy.pro +++ /dev/null @@ -1,7 +0,0 @@ -TARGET = tst_preallocatedarraypolicy -CONFIG += testcase -TEMPLATE = app - -SOURCES += tst_preallocatedarraypolicy.cpp - -QT += testlib 3dcore 3dcore-private diff --git a/tests/auto/core/arrayresourcesmanager/preallocatedarraypolicy/tst_preallocatedarraypolicy.cpp b/tests/auto/core/arrayresourcesmanager/preallocatedarraypolicy/tst_preallocatedarraypolicy.cpp deleted file mode 100644 index dbed2abfb..000000000 --- a/tests/auto/core/arrayresourcesmanager/preallocatedarraypolicy/tst_preallocatedarraypolicy.cpp +++ /dev/null @@ -1,426 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include <QList> -#include <Qt3DCore/private/qresourcemanager_p.h> -#include <Qt3DCore/private/qhandle_p.h> - -class tst_PreallocatedArrayPolicy : public QObject -{ - Q_OBJECT -public: - tst_PreallocatedArrayPolicy() {} - ~tst_PreallocatedArrayPolicy() {} - -private slots: - void createResourcesManager(); - void acquireResources(); - void getResources(); - void registerResourcesResize(); - void removeResource(); - void resetResource(); - void lookupResource(); - void releaseResource(); - void heavyDutyMultiThreadedAccess(); - void heavyDutyMultiThreadedAccessRelease(); - void maximumNumberOfResources(); -}; - -class tst_ArrayResource -{ -public: - tst_ArrayResource() : m_value(0) - {} - - QAtomicInt m_value; -}; - -typedef Qt3DCore::QHandle<tst_ArrayResource> tHandle; -typedef Qt3DCore::QHandle<tst_ArrayResource, 4> tHandle4; -typedef Qt3DCore::QHandle<tst_ArrayResource, 8> tHandle8; -typedef Qt3DCore::QHandle<tst_ArrayResource, 16> tHandle16; - -void tst_PreallocatedArrayPolicy::createResourcesManager() -{ - Qt3DCore::QResourceManager<tst_ArrayResource, int, 16, Qt3DCore::ArrayPreallocationPolicy> manager16; - Qt3DCore::QResourceManager<tst_ArrayResource, int, 4, Qt3DCore::ArrayPreallocationPolicy> manager4; - Qt3DCore::QResourceManager<tst_ArrayResource, int, 8, Qt3DCore::ArrayPreallocationPolicy> manager8; - QVERIFY(manager16.maximumSize() == 65535); - QVERIFY(manager8.maximumSize() == 255); - QVERIFY(manager4.maximumSize() == 15); -} - -/*! - * Check that the handles returned when a registering resources - * have a correct index and counter. - */ -void tst_PreallocatedArrayPolicy::acquireResources() -{ - Qt3DCore::QResourceManager<tst_ArrayResource, uint, 4, Qt3DCore::ArrayPreallocationPolicy> manager; - - QList<tHandle4> handles; - - for (int i = 0; i < 5; i++) { - handles << manager.acquire(); - } - - for (uint i = 0; i < 5; i++) { - QVERIFY(handles.at(i).index() == i); - QVERIFY(handles.at(i).counter() == 1); - } -} - -/*! - * Test that values can be properly retrieved. - */ -void tst_PreallocatedArrayPolicy::getResources() -{ - - Qt3DCore::QResourceManager<tst_ArrayResource, int, 8, Qt3DCore::ArrayPreallocationPolicy> manager; - QList<tst_ArrayResource *> resources; - QList<tHandle8> handles; - - for (int i = 0; i < 5; i++) { - handles << manager.acquire(); - } - - 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; - } - - for (int i = 0; i < 5; i++) - QVERIFY(manager.data(handles.at(i))->m_value == i); - - // Check that an invalid resource returns NULL - tHandle8 iHandle; - QVERIFY(manager.data(iHandle) == nullptr); - -} - -/*! - * Test that when a resize of the data vectors in the manager occurs, - * everything behaves correctly. - */ -void tst_PreallocatedArrayPolicy::registerResourcesResize() -{ - Qt3DCore::QResourceManager<tst_ArrayResource, uint, 16, Qt3DCore::ArrayPreallocationPolicy> manager; - QList<tHandle16> handles; - - for (uint i = 0; i < 2; i++) { - handles << manager.acquire(); - manager.data(handles.at(i))->m_value = i + 2; - } - - for (uint i = 0; i < 5; i++) { - handles << manager.acquire(); - manager.data(handles.at(i + 2))->m_value = i + 2 + 5; - } - - 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 - QVERIFY(manager.data(handles.at(i))->m_value == i + 5); - } -} - -/*! - * Checks for the removal of resources. - */ -void tst_PreallocatedArrayPolicy::removeResource() -{ - Qt3DCore::QResourceManager<tst_ArrayResource, int, 16, Qt3DCore::ArrayPreallocationPolicy> manager; - - QList<tst_ArrayResource *> resources; - QList<tHandle> handles; - - for (int i = 0; i < 32; i++) { - handles << manager.acquire(); - resources << manager.data(handles.at(i)); - } - - manager.release(handles.at(2)); - QVERIFY(manager.data(handles.at(2)) == nullptr); - // Triggers QASSERT so commented - // manager.release(handles.at(2)); - - tHandle nHandle = manager.acquire(); - QVERIFY(manager.data(nHandle) != nullptr); -} - -/*! - * Checks that reset behaves correctly. - */ -void tst_PreallocatedArrayPolicy::resetResource() -{ - Qt3DCore::QResourceManager<tst_ArrayResource, uint, 16, Qt3DCore::ArrayPreallocationPolicy> manager; - - QList<tst_ArrayResource *> resources; - QList<tHandle16> handles; - - for (int i = 0; i < 5; i++) { - handles << manager.acquire(); - resources << manager.data(handles.at(i)); - resources.at(i)->m_value = 4; - } - manager.reset(); - for (uint i = 0; i < 5; i++) { - QVERIFY(manager.data(handles.at(i)) == nullptr); - } - handles.clear(); - for (uint i = 0; i < 5; i++) - handles << manager.acquire(); - - for (uint i = 0; i < 5; i++) { - QVERIFY(handles.at(i).index() == i); - QVERIFY(handles.at(i).counter() == 1); - QVERIFY(manager.data(handles.at(i))->m_value != 4); - } -} - -void tst_PreallocatedArrayPolicy::lookupResource() -{ - Qt3DCore::QResourceManager<tst_ArrayResource, uint, 16, Qt3DCore::ArrayPreallocationPolicy> manager; - - QList<tst_ArrayResource *> resources; - QList<tHandle16> handles; - - for (int i = 0; i < 5; i++) { - handles << manager.acquire(); - resources << manager.data(handles.at(i)); - resources.at(i)->m_value = 4; - } - - tHandle16 t = manager.lookupHandle(2); - QVERIFY(t.handle() == 0); - QVERIFY(manager.data(t) == nullptr); - tst_ArrayResource *resource = manager.getOrCreateResource(2); - QVERIFY(resource != nullptr); - t = manager.lookupHandle(2); - QVERIFY(manager.data(t) == manager.lookupResource(2)); - QVERIFY(t == manager.getOrAcquireHandle(2)); - QVERIFY(resource == manager.getOrCreateResource(2)); - QVERIFY(manager.data(t) == resource); -} - -void tst_PreallocatedArrayPolicy::releaseResource() -{ - Qt3DCore::QResourceManager<tst_ArrayResource, uint, 16, Qt3DCore::ArrayPreallocationPolicy> manager; - QList<tst_ArrayResource *> resources; - - for (int i = 0; i < 5; i++) { - resources << manager.getOrCreateResource(i); - } - - for (int i = 0; i < 5; i++) { - QVERIFY(resources.at(i) == manager.lookupResource(i)); - } - - for (int i = 0; i < 5; i++) { - manager.releaseResource(i); - QVERIFY(manager.lookupResource(i) == nullptr); - } -} - -class tst_Thread : public QThread -{ - Q_OBJECT -public: - - typedef Qt3DCore::QResourceManager<tst_ArrayResource, - int, - 16, - Qt3DCore::ArrayPreallocationPolicy, - Qt3DCore::ObjectLevelLockingPolicy> Manager; - - tst_Thread() - : QThread() - { - } - - void setManager(Manager *manager) - { - m_manager = manager; - } - - // QThread interface -protected: - void run() - { - int i = 0; - int max = tHandle::maxIndex(); - while (i < max) { - tst_ArrayResource *r = m_manager->getOrCreateResource(i); - i++; - QVERIFY(r != nullptr); - Manager::Locker lock(m_manager); - r->m_value++; - } - qDebug() << QThread::currentThread() << "Done"; - } - - Manager *m_manager; -}; - -void tst_PreallocatedArrayPolicy::heavyDutyMultiThreadedAccess() -{ - tst_Thread::Manager *manager = new tst_Thread::Manager(); - - QList<tst_Thread *> threads; - - int iterations = 8; - int max = tHandle16::maxIndex(); - - for (int i = 0; i < iterations; i++) { - tst_Thread *thread = new tst_Thread(); - thread->setManager(manager); - threads << thread; - } - - for (int i = 0; i < iterations; i++) { - threads[i]->start(); - } - - for (int i = 0; i < iterations; i++) { - threads[i]->wait(); - } - - for (int i = 0; i < max; i++) { - QVERIFY(manager->lookupResource(i) != nullptr); - QVERIFY(manager->lookupResource(i)->m_value = iterations); - } - - qDeleteAll(threads); - delete manager; -} - -class tst_Thread2 : public QThread -{ - Q_OBJECT -public: - - typedef Qt3DCore::QResourceManager<tst_ArrayResource, - int, - 16, - Qt3DCore::ArrayPreallocationPolicy, - Qt3DCore::ObjectLevelLockingPolicy> Manager; - - tst_Thread2(int releaseAbove = 7) - : QThread() - , m_releaseAbove(releaseAbove) - { - } - - void setManager(Manager *manager) - { - m_manager = manager; - } - - // QThread interface -protected: - void run() - { - int i = 0; - int max = tHandle::maxIndex(); - while (i < max) { - tst_ArrayResource *r = m_manager->getOrCreateResource(i); - QVERIFY(r != nullptr); - int oldValue = r->m_value.fetchAndAddOrdered(+1); - if (oldValue == m_releaseAbove) - m_manager->releaseResource(i); - i++; - } - qDebug() << QThread::currentThread() << "Done"; - } - - Manager *m_manager; - int m_releaseAbove; -}; - -void tst_PreallocatedArrayPolicy::heavyDutyMultiThreadedAccessRelease() -{ - tst_Thread2::Manager *manager = new tst_Thread2::Manager(); - - QList<tst_Thread2 *> threads; - - int iterations = 8; - int max = tHandle16::maxIndex(); - - for (int u = 0; u < 2; u++) { - - for (int i = 0; i < iterations; i++) { - tst_Thread2 *thread = new tst_Thread2(); - thread->setManager(manager); - threads << thread; - } - - for (int i = 0; i < iterations; i++) { - threads[i]->start(); - } - - for (int i = 0; i < iterations; i++) { - threads[i]->wait(); - } - - for (int i = 0; i < max; i++) { - QVERIFY(manager->lookupResource(i) == nullptr); - } - - qDeleteAll(threads); - threads.clear(); - } - - delete manager; -} - -void tst_PreallocatedArrayPolicy::maximumNumberOfResources() -{ - Qt3DCore::QResourceManager<tst_ArrayResource, uint, 16, Qt3DCore::ArrayPreallocationPolicy> manager; - - 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)); - resources.at(i)->m_value = 4; - } -} - -QTEST_APPLESS_MAIN(tst_PreallocatedArrayPolicy) - -#include "tst_preallocatedarraypolicy.moc" diff --git a/tests/auto/core/core.pro b/tests/auto/core/core.pro index 4ac74471e..25440ce0e 100644 --- a/tests/auto/core/core.pro +++ b/tests/auto/core/core.pro @@ -2,8 +2,7 @@ TEMPLATE = subdirs SUBDIRS = \ handle \ - handlemanager \ - arrayresourcesmanager \ + qresourcemanager \ qcircularbuffer \ qboundedcircularbuffer \ nodes \ diff --git a/tests/auto/core/handlemanager/tst_handlemanager.cpp b/tests/auto/core/handlemanager/tst_handlemanager.cpp deleted file mode 100644 index f4879a3df..000000000 --- a/tests/auto/core/handlemanager/tst_handlemanager.cpp +++ /dev/null @@ -1,306 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include <Qt3DCore/private/qhandlemanager_p.h> -#include <Qt3DCore/private/qhandle_p.h> - -class tst_HandleManager : public QObject -{ - Q_OBJECT -public: - tst_HandleManager() {} - ~tst_HandleManager() {} - -private slots: - void construction(); - void correctPointer(); - void correctPointers(); - void correctConstPointer(); - void nullForRemovedEntry(); - void validHandleForReplacementEntry(); - void updateChangesValue(); - void resetRemovesAllEntries(); - void maximumEntries(); - void checkNoCounterOverflow(); -}; - -class SimpleResource -{ -public: - SimpleResource() - : m_value(0) - {} - - int m_value; -}; - -typedef Qt3DCore::QHandle<SimpleResource> Handle; - -void tst_HandleManager::construction() -{ - // GIVEN - Qt3DCore::QHandleManager<SimpleResource> manager; - - // THEN - QVERIFY(manager.activeEntries() == 0); -} - -void tst_HandleManager::correctPointer() -{ - // GIVEN - Qt3DCore::QHandleManager<SimpleResource> manager; - SimpleResource *p1 = (SimpleResource *)(quintptr)0xdeadbeef; - - // WHEN - const Handle h = manager.acquire(p1); - - bool ok = false; - SimpleResource *p2 = manager.data(h, &ok); - - // THEN - QVERIFY(ok == true); - QVERIFY(p1 == p2); -} - -void tst_HandleManager::correctPointers() -{ - // GIVEN - Qt3DCore::QHandleManager<SimpleResource> manager; - SimpleResource *p[3]; - p[0] = (SimpleResource *)(quintptr)0xdeadbeef; - p[1] = (SimpleResource *)(quintptr)0x11111111; - p[2] = (SimpleResource *)(quintptr)0x22222222; - - // WHEN - for (int i = 0; i < 3; ++i) { - // WHEN - const Handle h = manager.acquire(p[i]); - - bool ok = false; - SimpleResource *q = manager.data(h, &ok); - - // THEN - QVERIFY(ok == true); - QVERIFY(p[i] == q); - } - - // THEN - QVERIFY(manager.activeEntries() == 3); -} - -void tst_HandleManager::correctConstPointer() -{ - // GIVEN - Qt3DCore::QHandleManager<SimpleResource> manager; - QSharedPointer<SimpleResource> p1(new SimpleResource); - const Handle h = manager.acquire(p1.data()); - - // WHEN - bool ok = false; - const SimpleResource *p2 = manager.constData(h, &ok); - - // THEN - QVERIFY(ok == true); - QVERIFY(p1.data() == p2); -} - -void tst_HandleManager::nullForRemovedEntry() -{ - // GIVEN - Qt3DCore::QHandleManager<SimpleResource> manager; - QSharedPointer<SimpleResource> p1(new SimpleResource); - const Handle h = manager.acquire(p1.data()); - - // WHEN - manager.release(h); - - // THEN - bool ok = false; - SimpleResource *p2 = manager.data(h, &ok); - QVERIFY(ok == false); - QVERIFY(p2 == nullptr); -} - -void tst_HandleManager::validHandleForReplacementEntry() -{ - // GIVEN - Qt3DCore::QHandleManager<SimpleResource> manager; - QSharedPointer<SimpleResource> p1(new SimpleResource); - const Handle h = manager.acquire(p1.data()); - - // THEN - QVERIFY(manager.activeEntries() == 1); - - // WHEN - manager.release(h); - - // THEN - QVERIFY(manager.activeEntries() == 0); - - // WHEN - QSharedPointer<SimpleResource> p2(new SimpleResource); - const Handle h2 = manager.acquire(p2.data()); - - // THEN - QVERIFY(h2.isNull() == false); - QVERIFY(h2.counter() == 2); - QVERIFY(manager.activeEntries() == 1); - - // WHEN - bool ok = false; - SimpleResource *p3 = manager.data(h2, &ok); - - // THEN - QVERIFY(ok == true); - QVERIFY(p3 == p2); -} - -void tst_HandleManager::updateChangesValue() -{ - // GIVEN - Qt3DCore::QHandleManager<SimpleResource> manager; - QSharedPointer<SimpleResource> p1(new SimpleResource); - const Handle h = manager.acquire(p1.data()); - - // WHEN - QSharedPointer<SimpleResource> p2(new SimpleResource); - manager.update(h, p2.data()); - - // THEN - QVERIFY(manager.activeEntries() == 1); - - // WHEN - bool ok = false; - SimpleResource *p3 = manager.data(h, &ok); - - // THEN - QVERIFY(ok == true); - QVERIFY(p3 == p2); -} - -void tst_HandleManager::resetRemovesAllEntries() -{ - // GIVEN - Qt3DCore::QHandleManager<SimpleResource> manager; - - // WHEN - for (int i = 0; i < 100; ++i) { - SimpleResource *p = (SimpleResource *)(quintptr)(0xdead0000 + i); - const Handle h = manager.acquire(p); - - bool ok = false; - SimpleResource *q = manager.data(h, &ok); - QVERIFY(ok == true); - QVERIFY(p == q); - } - - // THEN - QVERIFY(manager.activeEntries() == 100); - - // WHEN - manager.reset(); - - // THEN - QVERIFY(manager.activeEntries() == 0); -} - -void tst_HandleManager::maximumEntries() -{ - // GIVEN - Qt3DCore::QHandleManager<SimpleResource> manager; - - // THEN - QCOMPARE(Handle::maxIndex(), (uint)((1 << 16) - 1)); - - // WHEN - for (int i = 0; i < (int)Handle::maxIndex(); ++i) { - SimpleResource *p = (SimpleResource *)(quintptr)(0xdead0000 + i); - const Handle h = manager.acquire(p); - - bool ok = false; - SimpleResource *q = manager.data(h, &ok); - QVERIFY(ok == true); - QVERIFY(p == q); - } - - // THEN - QVERIFY(manager.activeEntries() == Handle::maxIndex());\ - - // WHEN - manager.reset(); - - // THEN - QVERIFY(manager.activeEntries() == 0); -} - -void tst_HandleManager::checkNoCounterOverflow() -{ - // GIVEN - const int indexBits = 16; - Qt3DCore::QHandleManager<SimpleResource, indexBits> manager; - SimpleResource *p = (SimpleResource *)(quintptr)0xdead0000; - Qt3DCore::QHandle<SimpleResource, indexBits> h = manager.acquire(p); - - // THEN - QCOMPARE(h.maxCounter(), (quint32)((1 << (32 - indexBits - 2)) - 1)); - QCOMPARE(h.counter(), (quint32)1); - - // WHEN - const quint32 maxIterations = h.maxCounter() - 2; - const quint32 handleIndex = h.index(); - - qDebug() << maxIterations << handleIndex; - - // Acquire and release maxIteration time to increase counter - for (quint32 i = 0; i < maxIterations; ++i) { - // WHEN - manager.release(h); - h = manager.acquire(p); - - // THEN - QCOMPARE(h.index(), handleIndex); - QCOMPARE(h.counter(), i + 2); - } - - // THEN - QCOMPARE(h.counter(), h.maxCounter() - 1); - - // WHEN - manager.release(h); - h = manager.acquire(p); - - // THEN - QCOMPARE(h.counter(), (quint32)1); -} - - - -QTEST_APPLESS_MAIN(tst_HandleManager) - -#include "tst_handlemanager.moc" diff --git a/tests/auto/core/handlemanager/handlemanager.pro b/tests/auto/core/qresourcemanager/qresourcemanager.pro index ad18d5b9b..8fdf9b569 100644 --- a/tests/auto/core/handlemanager/handlemanager.pro +++ b/tests/auto/core/qresourcemanager/qresourcemanager.pro @@ -1,7 +1,7 @@ -TARGET = tst_handlemanager +TARGET = tst_qresourcemanager CONFIG += testcase TEMPLATE = app -SOURCES += tst_handlemanager.cpp +SOURCES += tst_qresourcemanager.cpp QT += testlib 3dcore 3dcore-private diff --git a/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/tst_dynamicarraypolicy.cpp b/tests/auto/core/qresourcemanager/tst_qresourcemanager.cpp index 874ac42ca..c3238fc8f 100644 --- a/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/tst_dynamicarraypolicy.cpp +++ b/tests/auto/core/qresourcemanager/tst_qresourcemanager.cpp @@ -44,7 +44,6 @@ private slots: void getResources(); void registerResourcesResize(); void removeResource(); - void resetResource(); void lookupResource(); void releaseResource(); void heavyDutyMultiThreadedAccess(); @@ -187,36 +186,6 @@ void tst_DynamicArrayPolicy::removeResource() QVERIFY(manager.data(nHandle) != nullptr); } -/*! - * Checks that reset behaves correctly. - */ -void tst_DynamicArrayPolicy::resetResource() -{ - Qt3DCore::QResourceManager<tst_ArrayResource, uint> manager; - - QList<tst_ArrayResource *> resources; - QList<tHandle16> handles; - - for (int i = 0; i < 5; i++) { - handles << manager.acquire(); - resources << manager.data(handles.at(i)); - resources.at(i)->m_value = 4; - } - manager.reset(); - for (uint i = 0; i < 5; i++) { - QVERIFY(manager.data(handles.at(i)) == nullptr); - } - handles.clear(); - for (uint i = 0; i < 5; i++) - handles << manager.acquire(); - - for (uint i = 0; i < 5; i++) { - QVERIFY(handles.at(i).index() == i); - QVERIFY(handles.at(i).counter() == 1); - QVERIFY(manager.data(handles.at(i))->m_value != 4); - } -} - void tst_DynamicArrayPolicy::lookupResource() { Qt3DCore::QResourceManager<tst_ArrayResource, uint> manager; @@ -269,7 +238,6 @@ public: typedef Qt3DCore::QResourceManager<tst_ArrayResource, int, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::ObjectLevelLockingPolicy> Manager; tst_Thread() @@ -340,7 +308,6 @@ public: typedef Qt3DCore::QResourceManager<tst_ArrayResource, int, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::ObjectLevelLockingPolicy> Manager; tst_Thread2(int releaseAbove = 7) @@ -466,4 +433,4 @@ void tst_DynamicArrayPolicy::activeHandles() QTEST_APPLESS_MAIN(tst_DynamicArrayPolicy) -#include "tst_dynamicarraypolicy.moc" +#include "tst_qresourcemanager.moc" diff --git a/tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp b/tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp index 292bcfba3..584b675ee 100644 --- a/tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp +++ b/tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp @@ -951,7 +951,13 @@ private Q_SLOTS: ADD_UNIFORM_ENTRY(fragCodeUniformsInt, "multiplierVec4", GL_INT_VEC4, 1, 4 * 4); ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m2", GL_FLOAT_MAT2, 1, 4 * 2 * 2); + ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m23", GL_FLOAT_MAT2x3, 1, 4 * 2 * 3); + ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m32", GL_FLOAT_MAT3x2, 1, 4 * 3 * 2); + ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m24", GL_FLOAT_MAT2x4, 1, 4 * 2 * 4); + ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m42", GL_FLOAT_MAT4x2, 1, 4 * 4 * 2); ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m3", GL_FLOAT_MAT3, 1, 4 * 3 * 3); + ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m34", GL_FLOAT_MAT3x4, 1, 4 * 3 * 4); + ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m43", GL_FLOAT_MAT4x3, 1, 4 * 4 * 3); ADD_UNIFORM_ENTRY(fragCodeUniformsFloatMatrices, "m4", GL_FLOAT_MAT4, 1, 4 * 4 * 4); ADD_UNIFORM_ENTRY(fragCodeSamplers, "s1", GL_SAMPLER_1D, 1, 4); diff --git a/tests/auto/render/pickboundingvolumejob/pickboundingvolumejob.qrc b/tests/auto/render/pickboundingvolumejob/pickboundingvolumejob.qrc index fbd6a0a05..c2b0c7fff 100644 --- a/tests/auto/render/pickboundingvolumejob/pickboundingvolumejob.qrc +++ b/tests/auto/render/pickboundingvolumejob/pickboundingvolumejob.qrc @@ -7,5 +7,6 @@ <file>testscene_dragenabledhoverenabled.qml</file> <file>testscene_pickersdisabled.qml</file> <file>testscene_dragenabledoverlapping.qml</file> + <file>testscene_parententity.qml</file> </qresource> </RCC> diff --git a/tests/auto/render/pickboundingvolumejob/testscene_parententity.qml b/tests/auto/render/pickboundingvolumejob/testscene_parententity.qml new file mode 100644 index 000000000..759544bb9 --- /dev/null +++ b/tests/auto/render/pickboundingvolumejob/testscene_parententity.qml @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 +import Qt3D.Extras 2.0 +import QtQuick.Window 2.0 + +Entity { + id: sceneRoot + + Window { + id: win + width: 600 + height: 600 + visible: true + } + + Camera { + id: camera + projectionType: CameraLens.PerspectiveProjection + fieldOfView: 45 + nearPlane : 0.1 + farPlane : 1000.0 + position: Qt.vector3d( 0.0, 0.0, -40.0 ) + upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) + viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) + } + + components: [ + RenderSettings { + Viewport { + normalizedRect: Qt.rect(0.0, 0.0, 1.0, 1.0) + + RenderSurfaceSelector { + + surface: win + + ClearBuffers { + buffers : ClearBuffers.ColorDepthBuffer + NoDraw {} + } + + CameraSelector { + camera: camera + } + } + } + } + ] + + CuboidMesh { id: cubeMesh } + PhongMaterial { id: material } + + // Parent Entity + Entity { + + Entity { + components: [ + PlaneMesh { + width: 100 + height: 100 + }, + PhongMaterial { + } + ] + } + + // Child Entity + Entity { + property Transform transform: Transform { + translation: Qt.vector3d(-5, 0, 0) + scale: 2.0 + } + + property ObjectPicker picker: ObjectPicker { + objectName: "Picker" + dragEnabled: true + } + + components: [cubeMesh, material, transform, picker] + } + } + +} diff --git a/tests/auto/render/pickboundingvolumejob/tst_pickboundingvolumejob.cpp b/tests/auto/render/pickboundingvolumejob/tst_pickboundingvolumejob.cpp index e2cc190df..d9d90a03d 100644 --- a/tests/auto/render/pickboundingvolumejob/tst_pickboundingvolumejob.cpp +++ b/tests/auto/render/pickboundingvolumejob/tst_pickboundingvolumejob.cpp @@ -1156,6 +1156,56 @@ private Q_SLOTS: arbiter1.events.clear(); arbiter2.events.clear(); } + + void checkParentNoPickerChildPicker() + { + // GIVEN + QmlSceneReader sceneReader(QUrl("qrc:/testscene_parententity.qml")); + QScopedPointer<Qt3DCore::QNode> root(qobject_cast<Qt3DCore::QNode *>(sceneReader.root())); + QVERIFY(root); + + QList<Qt3DRender::QRenderSettings *> renderSettings = root->findChildren<Qt3DRender::QRenderSettings *>(); + QCOMPARE(renderSettings.size(), 1); + Qt3DRender::QPickingSettings *settings = renderSettings.first()->pickingSettings(); + + settings->setPickMethod(Qt3DRender::QPickingSettings::BoundingVolumePicking); + settings->setPickResultMode(Qt3DRender::QPickingSettings::NearestPick); + settings->setFaceOrientationPickingMode(Qt3DRender::QPickingSettings::FrontFace); + + QScopedPointer<Qt3DRender::TestAspect> test(new Qt3DRender::TestAspect(root.data())); + TestArbiter arbiter; + + // Runs Required jobs + runRequiredJobs(test.data()); + + // THEN + // large no pickable object encapsing child and camera should not interfere with smaller picking object + QList<Qt3DRender::QObjectPicker *> pickers = root->findChildren<Qt3DRender::QObjectPicker *>(); + QCOMPARE(pickers.size(), 1); + + Qt3DRender::QObjectPicker *picker = pickers.first(); + QCOMPARE(pickers.first()->objectName(), QLatin1String("Picker")); + + Qt3DRender::Render::ObjectPicker *backendPicker = test->nodeManagers()->objectPickerManager()->lookupResource(picker->id()); + QVERIFY(backendPicker); + Qt3DCore::QBackendNodePrivate::get(backendPicker)->setArbiter(&arbiter); + + // WHEN -> Pressed on object + Qt3DRender::Render::PickBoundingVolumeJob pickBVJob; + initializePickBoundingVolumeJob(&pickBVJob, test.data()); + + QList<QMouseEvent> events; + events.push_back(QMouseEvent(QMouseEvent::MouseButtonPress, QPointF(400.0f, 300.0f), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier)); + pickBVJob.setMouseEvents(events); + bool earlyReturn = !pickBVJob.runHelper(); + + // THEN -> Pressed + QVERIFY(!earlyReturn); + QVERIFY(backendPicker->isPressed()); + QCOMPARE(arbiter.events.count(), 1); + Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "pressed"); + } }; QTEST_MAIN(tst_PickBoundingVolumeJob) diff --git a/tests/auto/render/qrendersurfaceselector/tst_qrendersurfaceselector.cpp b/tests/auto/render/qrendersurfaceselector/tst_qrendersurfaceselector.cpp index 1e003e6b8..982a58b2b 100644 --- a/tests/auto/render/qrendersurfaceselector/tst_qrendersurfaceselector.cpp +++ b/tests/auto/render/qrendersurfaceselector/tst_qrendersurfaceselector.cpp @@ -188,8 +188,8 @@ private Q_SLOTS: void checkCreationData() { // GIVEN - Qt3DRender::QRenderSurfaceSelector renderSurfaceSelector; QWindow newValue; + Qt3DRender::QRenderSurfaceSelector renderSurfaceSelector; renderSurfaceSelector.setSurface(&newValue); renderSurfaceSelector.setExternalRenderTargetSize(QSize(128, 128)); @@ -250,10 +250,10 @@ private Q_SLOTS: void checkSurfaceUpdate() { // GIVEN + QWindow newWindow; TestArbiter arbiter; Qt3DRender::QRenderSurfaceSelector renderSurfaceSelector; arbiter.setArbiterOnNode(&renderSurfaceSelector); - QWindow newWindow; { // WHEN diff --git a/tests/benchmarks/core/qresourcesmanager/arraypolicy/tst_bench_arraypolicy.cpp b/tests/benchmarks/core/qresourcesmanager/arraypolicy/tst_bench_arraypolicy.cpp index 0d89bd8c4..0813fff91 100644 --- a/tests/benchmarks/core/qresourcesmanager/arraypolicy/tst_bench_arraypolicy.cpp +++ b/tests/benchmarks/core/qresourcesmanager/arraypolicy/tst_bench_arraypolicy.cpp @@ -38,11 +38,6 @@ private Q_SLOTS: void benchmarkDynamicReleaseSmallResources(); void benchmarkDynamicAllocateBigResources(); void benchmarkDynamicReleaseBigResources(); - - void benchmarkPreallocatedAllocateSmallResources(); - void benchmarkPreallocatedReleaseSmallResources(); - void benchmarkPreallocatedAllocateBigResources(); - void benchmarkPreallocatedReleaseBigResources(); }; struct SmallType @@ -55,33 +50,32 @@ struct BigType QMatrix4x4 a; }; -template<typename C, typename T> +template<typename T> void benchmarkAllocateResources() { - C allocator; + Qt3DCore::ArrayAllocatingPolicy<T> allocator; const int max = (1 << 16) - 1; QBENCHMARK_ONCE { for (int i = 0; i < max; i++) { - T* ptr = allocator.allocateResource(); - Q_UNUSED(ptr); + (void) allocator.allocateResource(); } } } -template<typename C, typename T> +template<typename T> void benchmarkReleaseResources() { - C allocator; + Qt3DCore::ArrayAllocatingPolicy<T> allocator; const int max = (1 << 16) - 1; - QVector<T*> resources(max); + QVector<Qt3DCore::QHandle<T>> resources(max); for (int i = 0; i < max; i++) { resources[i] = allocator.allocateResource(); } QBENCHMARK_ONCE { - foreach (T* ptr, resources) { + foreach (auto ptr, resources) { allocator.releaseResource(ptr); } } @@ -89,42 +83,22 @@ void benchmarkReleaseResources() void tst_ArrayPolicy::benchmarkDynamicAllocateSmallResources() { - benchmarkAllocateResources<Qt3DCore::ArrayAllocatingPolicy<SmallType, 16>, SmallType>(); + benchmarkAllocateResources<SmallType>(); } void tst_ArrayPolicy::benchmarkDynamicReleaseSmallResources() { - benchmarkReleaseResources<Qt3DCore::ArrayAllocatingPolicy<SmallType, 16>, SmallType>(); + benchmarkReleaseResources<SmallType>(); } void tst_ArrayPolicy::benchmarkDynamicAllocateBigResources() { - benchmarkAllocateResources<Qt3DCore::ArrayAllocatingPolicy<BigType, 16>, BigType>(); + benchmarkAllocateResources<BigType>(); } void tst_ArrayPolicy::benchmarkDynamicReleaseBigResources() { - benchmarkReleaseResources<Qt3DCore::ArrayAllocatingPolicy<BigType, 16>, BigType>(); -} - -void tst_ArrayPolicy::benchmarkPreallocatedAllocateSmallResources() -{ - benchmarkAllocateResources<Qt3DCore::ArrayPreallocationPolicy<SmallType, 16>, SmallType>(); -} - -void tst_ArrayPolicy::benchmarkPreallocatedReleaseSmallResources() -{ - benchmarkReleaseResources<Qt3DCore::ArrayPreallocationPolicy<SmallType, 16>, SmallType>(); -} - -void tst_ArrayPolicy::benchmarkPreallocatedAllocateBigResources() -{ - benchmarkAllocateResources<Qt3DCore::ArrayPreallocationPolicy<BigType, 16>, BigType>(); -} - -void tst_ArrayPolicy::benchmarkPreallocatedReleaseBigResources() -{ - benchmarkReleaseResources<Qt3DCore::ArrayPreallocationPolicy<BigType, 16>, BigType>(); + benchmarkReleaseResources<BigType>(); } QTEST_APPLESS_MAIN(tst_ArrayPolicy) diff --git a/tests/benchmarks/core/qresourcesmanager/qresourcesmanager/tst_bench_qresourcesmanager.cpp b/tests/benchmarks/core/qresourcesmanager/qresourcesmanager/tst_bench_qresourcesmanager.cpp index 48b12b5f2..6ddb058a1 100644 --- a/tests/benchmarks/core/qresourcesmanager/qresourcesmanager/tst_bench_qresourcesmanager.cpp +++ b/tests/benchmarks/core/qresourcesmanager/qresourcesmanager/tst_bench_qresourcesmanager.cpp @@ -161,7 +161,7 @@ void benchmarkReleaseResources() handles[i] = manager.acquire(); QBENCHMARK_ONCE { - manager.reset(); + /*manager.reset()*/; } } |