diff options
author | Mike Krus <mike.krus@kdab.com> | 2020-02-07 18:08:29 +0000 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2020-02-07 18:10:43 +0000 |
commit | b0eb152b82cdd9658154ff7d9ef9e764eccc1ebd (patch) | |
tree | d754ad4412d5c1d26caedd54f2455f3e27cbbd46 /tests/auto/core | |
parent | 137b0cbbc746eecc6dd6a93f9a268f8d42c96bcc (diff) | |
parent | fa6799f63f3211300705b814b97716ca689d4bfa (diff) |
Merge remote-tracking branch 5.15 into dev
Change-Id: I731aa986e1cc45b3af920db1a23f256927beecf7
Diffstat (limited to 'tests/auto/core')
18 files changed, 367 insertions, 369 deletions
diff --git a/tests/auto/core/common/qbackendnodetester.cpp b/tests/auto/core/common/qbackendnodetester.cpp index a2685f556..13f4683d9 100644 --- a/tests/auto/core/common/qbackendnodetester.cpp +++ b/tests/auto/core/common/qbackendnodetester.cpp @@ -56,20 +56,29 @@ void QBackendNodeTester::simulateInitialization(QNode *frontend, QBackendNode *b { Q_ASSERT(frontend); Q_ASSERT(backend); + QT_WARNING_PUSH + QT_WARNING_DISABLE_DEPRECATED const auto change = frontend->createNodeCreationChange(); backend->setPeerId(change->subjectId()); backend->setEnabled(change->isNodeEnabled()); backend->initializeFromPeer(change); + QT_WARNING_POP } void QBackendNodeTester::sceneChangeEvent(QBackendNode *backend, const Qt3DCore::QSceneChangePtr &e) { + QT_WARNING_PUSH + QT_WARNING_DISABLE_DEPRECATED backend->sceneChangeEvent(e); + QT_WARNING_POP } QNodeCreatedChangeBasePtr QBackendNodeTester::creationChange(QNode *frontend) const { + QT_WARNING_PUSH + QT_WARNING_DISABLE_DEPRECATED return frontend->createNodeCreationChange(); + QT_WARNING_POP } } // namespace Qt3DCore diff --git a/tests/auto/core/common/testpostmanarbiter.cpp b/tests/auto/core/common/testpostmanarbiter.cpp index 5869cbad3..f0c362744 100644 --- a/tests/auto/core/common/testpostmanarbiter.cpp +++ b/tests/auto/core/common/testpostmanarbiter.cpp @@ -26,6 +26,10 @@ ** ****************************************************************************/ +// TODO Remove in Qt6 +#include <QtCore/qcompilerdetection.h> +QT_WARNING_DISABLE_DEPRECATED + #include "testpostmanarbiter.h" #include <Qt3DCore/private/qnode_p.h> diff --git a/tests/auto/core/common/testpostmanarbiter.h b/tests/auto/core/common/testpostmanarbiter.h index cecc24f93..e927c2489 100644 --- a/tests/auto/core/common/testpostmanarbiter.h +++ b/tests/auto/core/common/testpostmanarbiter.h @@ -70,7 +70,10 @@ public: void setArbiterOnNode(Qt3DCore::QNode *node); void addDirtyFrontEndNode(Qt3DCore::QNode *node) final; + QT_WARNING_PUSH + QT_WARNING_DISABLE_DEPRECATED void addDirtyFrontEndNode(Qt3DCore::QNode *node, Qt3DCore::QNode *subNode, const char *property, Qt3DCore::ChangeFlag change) final; + QT_WARNING_POP void removeDirtyFrontEndNode(Qt3DCore::QNode *node) final; private: diff --git a/tests/auto/core/core.pro b/tests/auto/core/core.pro index 37c707aa7..3e4a8479d 100644 --- a/tests/auto/core/core.pro +++ b/tests/auto/core/core.pro @@ -22,10 +22,11 @@ qtConfig(private_tests) { threadpooler \ qpostman \ vector4d_base \ - vector3d_base + vector3d_base \ + aspectcommanddebugger \ + qscheduler QT_FOR_CONFIG += 3dcore-private - qtConfig(qt3d-profile-jobs): SUBDIRS += aspectcommanddebugger qtConfig(qt3d-simd-sse2) { SUBDIRS += \ vector4d_sse \ diff --git a/tests/auto/core/nodes/tst_nodes.cpp b/tests/auto/core/nodes/tst_nodes.cpp index d65e20708..c39638754 100644 --- a/tests/auto/core/nodes/tst_nodes.cpp +++ b/tests/auto/core/nodes/tst_nodes.cpp @@ -26,6 +26,10 @@ ** ****************************************************************************/ +// TODO Remove in Qt6 +#include <QtCore/qcompilerdetection.h> +QT_WARNING_DISABLE_DEPRECATED + #include <QtTest/QTest> #include <Qt3DCore/qnode.h> #include <Qt3DCore/qentity.h> @@ -40,6 +44,7 @@ #include <Qt3DCore/qpropertynoderemovedchange.h> #include <Qt3DCore/private/qnodecreatedchangegenerator_p.h> #include <Qt3DCore/private/qaspectengine_p.h> +#include <Qt3DCore/private/qaspectengine_p.h> #include <private/qabstractaspect_p.h> #include <private/qpostman_p.h> @@ -92,6 +97,7 @@ private slots: void checkConstructionWithNonRootParent(); // QTBUG-73986 void checkConstructionAsListElement(); void checkSceneIsSetOnConstructionWithParent(); // QTBUG-69352 + void checkSubNodePostConstructIsCalledWhenReferincingNodeProperty(); // QTBUG-79350 void appendingComponentToEntity(); void appendingParentlessComponentToEntityWithoutScene(); @@ -290,22 +296,15 @@ public slots: if (!attribute->parent()) attribute->setParent(this); - if (d->m_changeArbiter != nullptr) { - const auto change = Qt3DCore::QPropertyNodeAddedChangePtr::create(id(), attribute); - change->setPropertyName("attribute"); - d->notifyObservers(change); - } + d->updateNode(attribute, "attribute", Qt3DCore::PropertyValueAdded); } } void removeAttribute(MyQNode *attribute) { Qt3DCore::QNodePrivate *d = Qt3DCore::QNodePrivate::get(this); - if (d->m_changeArbiter != nullptr) { - const auto change = Qt3DCore::QPropertyNodeRemovedChangePtr::create(id(), attribute); - change->setPropertyName("attribute"); - d->notifyObservers(change); - } + d->updateNode(attribute, "attribute", Qt3DCore::PropertyValueRemoved); + m_attributes.removeOne(attribute); // Remove bookkeeping connection d->unregisterDestructionHelper(attribute); @@ -384,11 +383,7 @@ public: if (!attribute->parent()) attribute->setParent(this); - if (d->m_changeArbiter != nullptr) { - const auto change = Qt3DCore::QPropertyNodeAddedChangePtr::create(id(), attribute); - change->setPropertyName("attribute"); - d->notifyObservers(change); - } + d->updateNode(attribute, "attribute", Qt3DCore::PropertyValueRemoved); } } @@ -435,6 +430,29 @@ public: } }; +class MyFakeMaterial : public Qt3DCore::QComponent +{ + Q_OBJECT +public: + explicit MyFakeMaterial(Qt3DCore::QNode *parent = nullptr) + : QComponent(parent) + , m_effect(new MyQNode(this)) + , m_technique(new MyQNode(m_effect)) + , m_renderPass(new MyQNode(m_technique)) + { + } + + void setArbiter(Qt3DCore::QAbstractArbiter *arbiter) + { + Q_ASSERT(arbiter); + Qt3DCore::QComponentPrivate::get(this)->setArbiter(arbiter); + } + + MyQNode *m_effect; + MyQNode *m_technique; + MyQNode *m_renderPass; +}; + class TestAspectPrivate; class TestAspect : public Qt3DCore::QAbstractAspect { @@ -928,6 +946,7 @@ void tst_Nodes::checkParentChangeFromExistingBackendParentToNewlyCreatedParent() // GIVEN ObserverSpy spy; Qt3DCore::QAspectEngine engine; + engine.setRunMode(Qt3DCore::QAspectEngine::Manual); QScopedPointer<MyQEntity> root(new MyQEntity()); root->setArbiterAndEngine(&spy, &engine); auto aspect = new TestAspect; @@ -937,6 +956,7 @@ void tst_Nodes::checkParentChangeFromExistingBackendParentToNewlyCreatedParent() MyQNode *child2(new MyQNode(root.data())); QCoreApplication::processEvents(); + engine.processFrame(); // Due to the way we create root, it has a backend QVERIFY(Qt3DCore::QNodePrivate::get(root.data())->m_hasBackendNode == true); @@ -967,6 +987,7 @@ void tst_Nodes::checkParentChangeFromExistingBackendParentToNewlyCreatedParent() // WHEN QCoreApplication::processEvents(); + engine.processFrame(); // THEN QCOMPARE(spy.events.size(), 2); @@ -1043,6 +1064,7 @@ void tst_Nodes::checkParentChangeFromExistingBackendParentToNewlyCreatedParent() // WHEN QCoreApplication::processEvents(); + engine.processFrame(); // THEN QCOMPARE(spy.events.size(), 2); @@ -1221,6 +1243,7 @@ void tst_Nodes::checkAllBackendCreationDoneInSingleFrame() // GIVEN ObserverSpy spy; Qt3DCore::QAspectEngine engine; + engine.setRunMode(Qt3DCore::QAspectEngine::Manual); auto aspect = new TestAspect; engine.registerAspect(aspect); @@ -1253,6 +1276,7 @@ void tst_Nodes::checkAllBackendCreationDoneInSingleFrame() // WHEN QCoreApplication::processEvents(); + engine.processFrame(); // THEN - both children have their backend nodes actually created. QCOMPARE(aspect->events.count(), 2); @@ -1544,20 +1568,8 @@ void tst_Nodes::checkConstructionAsListElement() QCoreApplication::processEvents(); QCOMPARE(root->children().count(), 1); - QCOMPARE(spy.events.size(), 2); // 1 child added change, 1 property change - - const auto newChildEvent = spy.events.takeFirst().change().dynamicCast<Qt3DCore::QPropertyNodeAddedChange>(); - QVERIFY(!newChildEvent.isNull()); - QCOMPARE(newChildEvent->subjectId(), root->id()); - QCOMPARE(newChildEvent->propertyName(), "children"); - QCOMPARE(newChildEvent->addedNodeId(), node->id()); - - // Ensure second and last event is property set change - const auto propertyEvent = spy.events.takeFirst().change().dynamicCast<Qt3DCore::QPropertyNodeAddedChange>(); - QVERIFY(!propertyEvent.isNull()); - QCOMPARE(propertyEvent->subjectId(), root->id()); - QCOMPARE(propertyEvent->propertyName(), "attribute"); - QCOMPARE(newChildEvent->addedNodeId(), node->id()); + QCOMPARE(spy.dirtyNodes.size(), 1); // 1 property change + QCOMPARE(spy.dirtySubNodes.size(), 1); // 1 child added change } void tst_Nodes::checkSceneIsSetOnConstructionWithParent() @@ -1606,6 +1618,52 @@ void tst_Nodes::checkSceneIsSetOnConstructionWithParent() QCOMPARE(spy.dirtySubNodes.size(), 5); // 5 entities changed } +void tst_Nodes::checkSubNodePostConstructIsCalledWhenReferincingNodeProperty() +{ + // GIVEN + ObserverSpy spy; + Qt3DCore::QAspectEngine engine; + Qt3DCore::QScene scene(&engine); + QScopedPointer<MyQNode> root(new MyQNode()); + + // WHEN + root->setArbiterAndScene(&spy, &scene); + root->setSimulateBackendCreated(true); + + // THEN + QVERIFY(Qt3DCore::QNodePrivate::get(root.data())->scene() != nullptr); + + // WHEN + Qt3DCore::QEntity *subTreeRoot = new Qt3DCore::QEntity(root.data()); + QCoreApplication::processEvents(); + + // THEN + QVERIFY(Qt3DCore::QNodePrivate::get(subTreeRoot)->m_hasBackendNode); + + // WHEN + MyFakeMaterial *material = new MyFakeMaterial(subTreeRoot); + subTreeRoot->addComponent(material); + + // THEN + QVERIFY(Qt3DCore::QNodePrivate::get(material)->m_hasBackendNode); + QVERIFY(Qt3DCore::QNodePrivate::get(material->m_effect)->m_hasBackendNode); + QVERIFY(Qt3DCore::QNodePrivate::get(material->m_technique)->m_hasBackendNode); + QVERIFY(Qt3DCore::QNodePrivate::get(material->m_renderPass)->m_hasBackendNode); + + // WHEN + MyQNode *fakeRenderState = new MyQNode(material); + Qt3DCore::QNodePrivate *dPtr = Qt3DCore::QNodePrivate::get(fakeRenderState); + + // THEN + QVERIFY(!dPtr->m_hasBackendNode); + + // WHEN + material->m_renderPass->addAttribute(fakeRenderState); + + // THEN + QVERIFY(dPtr->m_hasBackendNode); +} + void tst_Nodes::appendingParentlessComponentToEntityWithoutScene() { // GIVEN diff --git a/tests/auto/core/qaspectengine/tst_qaspectengine.cpp b/tests/auto/core/qaspectengine/tst_qaspectengine.cpp index eb20536e6..48443a66f 100644 --- a/tests/auto/core/qaspectengine/tst_qaspectengine.cpp +++ b/tests/auto/core/qaspectengine/tst_qaspectengine.cpp @@ -146,6 +146,10 @@ private Q_SLOTS: void shouldNotCrashInNormalStartupShutdownSequence() { +#ifdef Q_OS_MACOS + QSKIP("Test frequently times out. See QTBUG-80660."); +#endif + // GIVEN // An initialized aspect engine... QAspectEngine engine; @@ -168,7 +172,7 @@ private Q_SLOTS: engine.setRootEntity(entity); QEventLoop eventLoop; - QTimer::singleShot(100, &eventLoop, SLOT(quit())); + QTimer::singleShot(1000, &eventLoop, SLOT(quit())); eventLoop.exec(); // THEN @@ -179,7 +183,7 @@ private Q_SLOTS: // WHEN // we set an empty/null scene root... engine.setRootEntity(QEntityPtr()); - QTimer::singleShot(1000, &eventLoop, SLOT(quit())); + QTimer::singleShot(600, &eventLoop, SLOT(quit())); // ...and allow events to process... eventLoop.exec(); @@ -243,21 +247,21 @@ private Q_SLOTS: // THEN QCOMPARE(engine.executeCommand("list aspects").toString(), - QString("Loaded aspects:\n * fake")); + QString("fake")); // WHEN engine.registerAspect("otherfake"); // THEN QCOMPARE(engine.executeCommand("list aspects").toString(), - QString("Loaded aspects:\n * fake\n * otherfake")); + QString("fake\notherfake")); // WHEN engine.registerAspect(new FakeAspect3); // THEN QCOMPARE(engine.executeCommand("list aspects").toString(), - QString("Loaded aspects:\n * fake\n * otherfake\n * <unnamed>")); + QString("fake\notherfake\n<unnamed>")); } void shouldDelegateCommandsToAspects() diff --git a/tests/auto/core/qchangearbiter/tst_qchangearbiter.cpp b/tests/auto/core/qchangearbiter/tst_qchangearbiter.cpp index e54193398..3e9b24408 100644 --- a/tests/auto/core/qchangearbiter/tst_qchangearbiter.cpp +++ b/tests/auto/core/qchangearbiter/tst_qchangearbiter.cpp @@ -26,6 +26,10 @@ ** ****************************************************************************/ +// TODO Remove in Qt6 +#include <QtCore/qcompilerdetection.h> +QT_WARNING_DISABLE_DEPRECATED + #include <QtTest/QTest> #include <Qt3DCore/private/qobserverinterface_p.h> #include <Qt3DCore/private/qobservableinterface_p.h> diff --git a/tests/auto/core/qentity/tst_qentity.cpp b/tests/auto/core/qentity/tst_qentity.cpp index 7770a2632..7b41c9783 100644 --- a/tests/auto/core/qentity/tst_qentity.cpp +++ b/tests/auto/core/qentity/tst_qentity.cpp @@ -26,6 +26,10 @@ ** ****************************************************************************/ +// TODO Remove in Qt6 +#include <QtCore/qcompilerdetection.h> +QT_WARNING_DISABLE_DEPRECATED + #include <QtTest/QtTest> #include <Qt3DCore/qentity.h> #include <Qt3DCore/private/qentity_p.h> diff --git a/tests/auto/core/qpostman/tst_qpostman.cpp b/tests/auto/core/qpostman/tst_qpostman.cpp index f548d38fa..d0dfa0f49 100644 --- a/tests/auto/core/qpostman/tst_qpostman.cpp +++ b/tests/auto/core/qpostman/tst_qpostman.cpp @@ -86,227 +86,6 @@ private Q_SLOTS: QCOMPARE(QPostmanPrivate::get(&postman)->m_scene, &scene); } - void checkSceneChangeEvent() - { - // GIVEN - QScopedPointer<QScene> scene(new QScene); - QPostman postman; - TestArbiter arbiter; - QNode rootNode; - NodeChangeReceiver *receiverNode = new NodeChangeReceiver(); - - QNodePrivate::get(&rootNode)->m_scene = scene.data(); - scene->setArbiter(&arbiter); - postman.setScene(scene.data()); - // Setting the parent (which has a scene) adds the node into the observable lookup - // table of the scene which is needed by the postman to distribute changes - static_cast<QNode *>(receiverNode)->setParent(&rootNode); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(receiverNode->hasReceivedChange(), false); - QCOMPARE(QNodePrivate::get(receiverNode)->m_scene, scene.data()); - - // WHEN - QPropertyUpdatedChangePtr updateChange(new QPropertyUpdatedChange(receiverNode->id())); - updateChange->setValue(1584); - updateChange->setPropertyName("someName"); - postman.sceneChangeEvent(updateChange); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(receiverNode->hasReceivedChange(), true); - } - - void checkNotifyBackend() - { - // GIVEN - QScopedPointer<QScene> scene(new QScene); - QPostman postman; - TestArbiter arbiter; - - scene->setArbiter(&arbiter); - postman.setScene(scene.data()); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - - // WHEN - QPropertyUpdatedChangePtr updateChange(new QPropertyUpdatedChange(QNodeId())); - updateChange->setValue(1584); - updateChange->setPropertyName("someName"); - postman.notifyBackend(updateChange); - - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - } - - void checkShouldNotifyFrontend() - { - // GIVEN - QScopedPointer<QScene> scene(new QScene); - QPostman postman; - TestArbiter arbiter; - QNode rootNode; - NodeChangeReceiver *receiverNode = new NodeChangeReceiver(); - - QNodePrivate::get(&rootNode)->m_scene = scene.data(); - scene->setArbiter(&arbiter); - postman.setScene(scene.data()); - // Setting the parent (which has a scene) adds the node into the observable lookup - // table of the scene which is needed by the postman to distribute changes - static_cast<QNode *>(receiverNode)->setParent(&rootNode); - QCoreApplication::processEvents(); - - { - // WHEN - auto updateChange = QPropertyUpdatedChangePtr::create(receiverNode->id()); - updateChange->setValue(1584); - updateChange->setPropertyName("someName"); - - - // THEN -> we do track properties by default QNode::DefaultTrackMode - // (unless marked as an intermediate change) - QCOMPARE(postman.shouldNotifyFrontend(updateChange), true); - } - - { - // WHEN - receiverNode->setDefaultPropertyTrackingMode(QNode::TrackAllValues); - - auto updateChange = QPropertyUpdatedChangePtr::create(receiverNode->id()); - updateChange->setValue(1584); - updateChange->setPropertyName("someName"); - QPropertyUpdatedChangeBasePrivate::get(updateChange.data())->m_isIntermediate - = true; - - // THEN -> we do track properties marked as intermediate when - // using TrackAllPropertiesMode - QCOMPARE(postman.shouldNotifyFrontend(updateChange), true); - } - - { - // GIVEN - receiverNode->setDefaultPropertyTrackingMode(QNode::DontTrackValues); - receiverNode->setPropertyTracking(QStringLiteral("vette"), Qt3DCore::QNode::TrackAllValues); - - { - // WHEN - auto updateChange = QPropertyUpdatedChangePtr::create(receiverNode->id()); - updateChange->setValue(1584); - updateChange->setPropertyName("someName"); - QPropertyUpdatedChangeBasePrivate::get(updateChange.data())->m_isIntermediate - = true; - - // THEN -> we don't track properties by default, unless named when - // using TrackNamedPropertiesMode - QCOMPARE(postman.shouldNotifyFrontend(updateChange), false); - } - - { - // WHEN - auto updateChange = QPropertyUpdatedChangePtr::create(receiverNode->id()); - updateChange->setValue(1584); - updateChange->setPropertyName("vette"); - QPropertyUpdatedChangeBasePrivate::get(updateChange.data())->m_isIntermediate - = true; - - // THEN - QCOMPARE(postman.shouldNotifyFrontend(updateChange), true); - } - } - - { - // GIVEN - receiverNode->setPropertyTracking(QStringLiteral("vette"), Qt3DCore::QNode::TrackAllValues); - receiverNode->setDefaultPropertyTrackingMode(QNode::TrackAllValues); - - { - // WHEN - auto updateChange = QPropertyUpdatedChangePtr::create(receiverNode->id()); - updateChange->setValue(1584); - updateChange->setPropertyName("someName"); - - // THEN -> we don't track properties by default - QCOMPARE(postman.shouldNotifyFrontend(updateChange), true); - } - - { - // WHEN - auto updateChange = QPropertyUpdatedChangePtr::create(receiverNode->id()); - updateChange->setValue(1584); - updateChange->setPropertyName("vette"); - - // THEN -> we don't track properties by default - QCOMPARE(postman.shouldNotifyFrontend(updateChange), true); - } - } - - { - // GIVEN - receiverNode->clearPropertyTrackings(); - receiverNode->setDefaultPropertyTrackingMode(QNode::TrackFinalValues); - - { - // WHEN - auto updateChange = QPropertyUpdatedChangePtr::create(receiverNode->id()); - updateChange->setValue(1584); - updateChange->setPropertyName("someName"); - - // THEN -> we do track properties by default, unless marked as intermediate - QCOMPARE(postman.shouldNotifyFrontend(updateChange), true); - } - - { - // WHEN - auto addedChange - = QPropertyNodeAddedChangePtr::create(receiverNode->id(), receiverNode); - - // THEN -> only QPropertyUpdatedChangePtr are filtered - QCOMPARE(postman.shouldNotifyFrontend(addedChange), true); - } - { - // WHEN - auto removedChange - = QPropertyNodeRemovedChangePtr::create(receiverNode->id(), receiverNode); - - // THEN -> only QPropertyUpdatedChangePtr are filtered - QCOMPARE(postman.shouldNotifyFrontend(removedChange), true); - } - } - - { - // GIVEN - receiverNode->clearPropertyTrackings(); - receiverNode->setDefaultPropertyTrackingMode(QNode::TrackFinalValues); - - { - // WHEN - auto updateChange = QPropertyUpdatedChangePtr::create(receiverNode->id()); - updateChange->setValue(1584); - updateChange->setPropertyName("someName"); - QPropertyUpdatedChangeBasePrivate::get(updateChange.data())->m_isIntermediate - = true; - - // THEN -> we don't track intermediate properties by default - QCOMPARE(postman.shouldNotifyFrontend(updateChange), false); - } - - { - // WHEN - auto updateChange = QPropertyUpdatedChangePtr::create(receiverNode->id()); - updateChange->setValue(1584); - updateChange->setPropertyName("someName"); - - // THEN - QCOMPARE(postman.shouldNotifyFrontend(updateChange), true); - } - - } - } - }; QTEST_MAIN(tst_QPostman) diff --git a/tests/auto/core/qresourcemanager/tst_qresourcemanager.cpp b/tests/auto/core/qresourcemanager/tst_qresourcemanager.cpp index 9a387a919..a41ea83b5 100644 --- a/tests/auto/core/qresourcemanager/tst_qresourcemanager.cpp +++ b/tests/auto/core/qresourcemanager/tst_qresourcemanager.cpp @@ -50,6 +50,7 @@ private slots: void heavyDutyMultiThreadedAccessRelease(); void collectResources(); void activeHandles(); + void checkCleanup(); }; class tst_ArrayResource @@ -422,6 +423,26 @@ void tst_QResourceManager::activeHandles() } } +void tst_QResourceManager::checkCleanup() +{ + // GIVEN + Qt3DCore::QResourceManager<tst_ArrayResource, uint> manager; + + // WHEN + tHandle newHandle = manager.getOrAcquireHandle(883U); + tst_ArrayResource *data = manager.data(newHandle); + + data->m_value.ref(); + // THEN + QCOMPARE(data->m_value.load(), 1); + + // WHEN + manager.release(newHandle); + + // THEN + QCOMPARE(data->m_value.load(), 0); +} + diff --git a/tests/auto/core/qscene/tst_qscene.cpp b/tests/auto/core/qscene/tst_qscene.cpp index ecc72e992..eb6a8c5ec 100644 --- a/tests/auto/core/qscene/tst_qscene.cpp +++ b/tests/auto/core/qscene/tst_qscene.cpp @@ -26,6 +26,10 @@ ** ****************************************************************************/ +// TODO Remove in Qt6 +#include <QtCore/qcompilerdetection.h> +QT_WARNING_DISABLE_DEPRECATED + #include <QtTest/QtTest> #include <Qt3DCore/private/qscene_p.h> #include <Qt3DCore/qnode.h> diff --git a/tests/auto/core/qscheduler/qscheduler.pro b/tests/auto/core/qscheduler/qscheduler.pro new file mode 100644 index 000000000..078716116 --- /dev/null +++ b/tests/auto/core/qscheduler/qscheduler.pro @@ -0,0 +1,7 @@ +TARGET = tst_qscheduler +CONFIG += testcase +TEMPLATE = app + +SOURCES += tst_qscheduler.cpp + +QT += testlib 3dcore 3dcore-private diff --git a/tests/auto/core/qscheduler/tst_qscheduler.cpp b/tests/auto/core/qscheduler/tst_qscheduler.cpp new file mode 100644 index 000000000..d1afb5aac --- /dev/null +++ b/tests/auto/core/qscheduler/tst_qscheduler.cpp @@ -0,0 +1,201 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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/qaspectjob.h> +#include <Qt3DCore/qabstractaspect.h> +#include <Qt3DCore/private/qaspectmanager_p.h> +#include <Qt3DCore/private/qscheduler_p.h> +#include <private/qabstractaspect_p.h> +#include <private/qaspectjob_p.h> + +using namespace Qt3DCore; + +class JobPrivate : public QAspectJobPrivate +{ + bool m_postFrameCalled = false; + + +public: + // QAspectJobPrivate interface + void postFrame(QAspectManager *aspectManager) + { + Q_ASSERT(aspectManager); + m_postFrameCalled = true; + } + + bool postFrameCalled() const + { + return m_postFrameCalled; + } +}; + +class Job : public QAspectJob +{ + bool m_wasExecuted = false; + +public: + Job() + : QAspectJob(*new JobPrivate) + {} + + bool wasExecuted() const + { + return m_wasExecuted; + } + + bool postFrameCalled() const + { + Q_D(const Job); + return d->postFrameCalled(); + } + + void run() override + { + m_wasExecuted = true; + } + +private: + Q_DECLARE_PRIVATE(Job) +}; +using JobPtr = QSharedPointer<Job>; + +class AspectPrivate : public QAbstractAspectPrivate +{ + bool m_jobsDoneCalled = false; + bool m_frameDoneCalled = false; + +public: + + bool jobsDoneCalled() const + { + return m_jobsDoneCalled; + } + + bool frameDoneCalled() const + { + return m_frameDoneCalled; + } + + // QAspectJobProviderInterface interface + void jobsDone() override + { + m_jobsDoneCalled = true; + } + + void frameDone() override + { + m_frameDoneCalled = true; + } +}; + +class Aspect : public QAbstractAspect +{ + Q_OBJECT + +public: + Aspect() + : QAbstractAspect(*new AspectPrivate) + {} + + JobPtr firstJob() const { return m_first; } + JobPtr secondJob() const { return m_second; } + +private: + // QAbstractAspect interface + QVector<QAspectJobPtr> jobsToExecute(qint64) + { + return { m_first, m_second }; + } + + JobPtr m_first = JobPtr::create(); + JobPtr m_second = JobPtr::create(); + Q_DECLARE_PRIVATE(Aspect) +}; + +class tst_QScheduler : public QObject +{ + Q_OBJECT +private Q_SLOTS: + + void checkInitialState() + { + // GIVEN + QScheduler scheduler; + + // THEN + QVERIFY(scheduler.aspectManager() == nullptr); + + // WHEN + QAspectManager m; + scheduler.setAspectManager(&m); + + // THEN + QCOMPARE(scheduler.aspectManager(), &m); + } + + void checkScheduleAndWaitForFrameAspectJobs() + { + // GIVEN + QScheduler scheduler; + QAspectManager manager; + Aspect aspect; + AspectPrivate *aspectPriv = static_cast<AspectPrivate *>(QObjectPrivate::get(&aspect)); + + manager.registerAspect(&aspect); + scheduler.setAspectManager(&manager); + + // THEN + const JobPtr first = aspect.firstJob(); + const JobPtr second = aspect.secondJob(); + QVERIFY(!aspectPriv->jobsDoneCalled()); + QVERIFY(!aspectPriv->frameDoneCalled()); + QVERIFY(!first->wasExecuted()); + QVERIFY(!second->wasExecuted()); + QVERIFY(!first->postFrameCalled()); + QVERIFY(!second->postFrameCalled()); + + // WHEN + const int count = scheduler.scheduleAndWaitForFrameAspectJobs(0); + + // THEN + QCOMPARE(count, 2); + QVERIFY(first->wasExecuted()); + QVERIFY(second->wasExecuted()); + QVERIFY(first->postFrameCalled()); + QVERIFY(second->postFrameCalled()); + QVERIFY(aspectPriv->jobsDoneCalled()); + QVERIFY(!aspectPriv->frameDoneCalled()); + + manager.unregisterAspect(&aspect); + } +}; + +QTEST_MAIN(tst_QScheduler) + +#include "tst_qscheduler.moc" diff --git a/tests/auto/core/qservicelocator/tst_qservicelocator.cpp b/tests/auto/core/qservicelocator/tst_qservicelocator.cpp index cde9834b4..40f0610df 100644 --- a/tests/auto/core/qservicelocator/tst_qservicelocator.cpp +++ b/tests/auto/core/qservicelocator/tst_qservicelocator.cpp @@ -52,11 +52,8 @@ class DummySystemInfoService : public QSystemInformationService { public: DummySystemInfoService() - : QSystemInformationService(QStringLiteral("Dummy System Information Service")) + : QSystemInformationService(nullptr, QStringLiteral("Dummy System Information Service")) {} - - QStringList aspectNames() const final { return QStringList(); } - int threadPoolThreadCount() const final { return 4; } }; @@ -90,8 +87,8 @@ void tst_QServiceLocator::defaultServices() QSystemInformationService *sysInfo = locator.systemInformation(); QVERIFY(sysInfo != nullptr); - QVERIFY(sysInfo->description() == QStringLiteral("Null System Information Service")); - QVERIFY(sysInfo->threadPoolThreadCount() == 0); + QVERIFY(sysInfo->description() == QStringLiteral("Default System Information Service")); + QVERIFY(sysInfo->threadPoolThreadCount() != 0); } void tst_QServiceLocator::addRemoveDefaultService() @@ -105,7 +102,6 @@ void tst_QServiceLocator::addRemoveDefaultService() // Get the service from the locator and check it works as expected QSystemInformationService *service = locator.systemInformation(); QVERIFY(service == dummy.data()); - QVERIFY(service->threadPoolThreadCount() == 4); // Ensure the other default services work QOpenGLInformationService *glInfo = locator.openGLInformation(); @@ -118,7 +114,7 @@ void tst_QServiceLocator::addRemoveDefaultService() QVERIFY(locator.serviceCount() == QServiceLocator::DefaultServiceCount); // Check the dummy service still exists - QVERIFY(dummy->threadPoolThreadCount() == 4); + QVERIFY(!dummy.isNull()); } void tst_QServiceLocator::addRemoveUserService() @@ -138,8 +134,8 @@ void tst_QServiceLocator::addRemoveUserService() // Ensure the default services work QSystemInformationService *sysInfo = locator.systemInformation(); QVERIFY(sysInfo != nullptr); - QVERIFY(sysInfo->description() == QStringLiteral("Null System Information Service")); - QVERIFY(sysInfo->threadPoolThreadCount() == 0); + QVERIFY(sysInfo->description() == QStringLiteral("Default System Information Service")); + QVERIFY(sysInfo->threadPoolThreadCount() != 0); // Remove custom service locator.unregisterServiceProvider(dummy->type()); diff --git a/tests/auto/core/qskeleton/tst_qskeleton.cpp b/tests/auto/core/qskeleton/tst_qskeleton.cpp index 299567806..5c88bd754 100644 --- a/tests/auto/core/qskeleton/tst_qskeleton.cpp +++ b/tests/auto/core/qskeleton/tst_qskeleton.cpp @@ -30,7 +30,6 @@ #include <Qt3DCore/qskeleton.h> #include <Qt3DCore/private/qskeleton_p.h> #include <Qt3DCore/qjoint.h> -#include <Qt3DCore/qpropertyupdatedchange.h> #include <Qt3DCore/private/qnode_p.h> #include <Qt3DCore/private/qscene_p.h> @@ -160,41 +159,6 @@ private Q_SLOTS: // THEN Should not crash when the joint is destroyed (tests for failed removal of destruction helper) } } - - void checkJointCountPropertyUpdate() - { - // GIVEN - TestArbiter arbiter; - arbiter.setArbiterOnNode(this); - QSignalSpy spy(this, SIGNAL(jointCountChanged(int))); - const int newJointCount = 99; - - // THEN - QVERIFY(spy.isValid()); - - // WHEN - auto valueChange = QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - valueChange->setPropertyName("jointCount"); - valueChange->setValue(QVariant(newJointCount)); - sceneChangeEvent(valueChange); - - // THEN - QCOMPARE(spy.count(), 1); - QCOMPARE(arbiter.events.size(), 0); - QCOMPARE(jointCount(), newJointCount); - - // WHEN - spy.clear(); - sceneChangeEvent(valueChange); - - // THEN - QCOMPARE(spy.count(), 0); - QCOMPARE(arbiter.events.size(), 0); - QCOMPARE(jointCount(), newJointCount); - - // Cleanup - QNodePrivate::get(this)->setArbiter(nullptr); - } }; QTEST_MAIN(tst_QSkeleton) diff --git a/tests/auto/core/qskeletonloader/tst_qskeletonloader.cpp b/tests/auto/core/qskeletonloader/tst_qskeletonloader.cpp index 7fcdc4bbe..f0f4c3872 100644 --- a/tests/auto/core/qskeletonloader/tst_qskeletonloader.cpp +++ b/tests/auto/core/qskeletonloader/tst_qskeletonloader.cpp @@ -209,71 +209,6 @@ private Q_SLOTS: QCOMPARE(arbiter.events.size(), 0); } } - - void checkStatusPropertyUpdate() - { - // GIVEN - qRegisterMetaType<Qt3DCore::QSkeletonLoader::Status>("Status"); - TestArbiter arbiter; - arbiter.setArbiterOnNode(this); - QSignalSpy spy(this, SIGNAL(statusChanged(Status))); - const QSkeletonLoader::Status newStatus = QSkeletonLoader::Error; - - // THEN - QVERIFY(spy.isValid()); - - // WHEN - QPropertyUpdatedChangePtr valueChange(new QPropertyUpdatedChange(QNodeId())); - valueChange->setPropertyName("status"); - valueChange->setValue(QVariant::fromValue(newStatus)); - sceneChangeEvent(valueChange); - - // THEN - QCOMPARE(spy.count(), 1); - QCOMPARE(arbiter.events.size(), 0); - QCOMPARE(status(), newStatus); - - // WHEN - spy.clear(); - sceneChangeEvent(valueChange); - - // THEN - QCOMPARE(spy.count(), 0); - QCOMPARE(arbiter.events.size(), 0); - QCOMPARE(status(), newStatus); - - // Cleanup - QNodePrivate::get(this)->setArbiter(nullptr); - } - - void checkRootJointPropertyUpdate() - { - // GIVEN - qRegisterMetaType<Qt3DCore::QJoint*>(); - TestArbiter arbiter; - arbiter.setArbiterOnNode(this); - QSignalSpy spy(this, SIGNAL(rootJointChanged(Qt3DCore::QJoint*))); - std::unique_ptr<QJoint> root(new QJoint()); - - // THEN - QVERIFY(spy.isValid()); - QVERIFY(rootJoint() == nullptr); - - // WHEN - auto valueChange = QJointChangePtr::create(id()); - valueChange->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes); - valueChange->setPropertyName("rootJoint"); - valueChange->data = std::move(root); - sceneChangeEvent(valueChange); - - // THEN - QCOMPARE(spy.count(), 1); - QCOMPARE(arbiter.dirtyNodes.size(), 1); - QVERIFY(rootJoint() != nullptr); - - // Cleanup - QNodePrivate::get(this)->setArbiter(nullptr); - } }; QTEST_MAIN(tst_QSkeletonLoader) diff --git a/tests/auto/core/qtransform/tst_qtransform.cpp b/tests/auto/core/qtransform/tst_qtransform.cpp index 37848ffd6..18a906e4c 100644 --- a/tests/auto/core/qtransform/tst_qtransform.cpp +++ b/tests/auto/core/qtransform/tst_qtransform.cpp @@ -26,6 +26,10 @@ ** ****************************************************************************/ +// TODO Remove in Qt6 +#include <QtCore/qcompilerdetection.h> +QT_WARNING_DISABLE_DEPRECATED + #include <QtTest/QtTest> #include <Qt3DCore/qpropertyupdatedchange.h> #include <Qt3DCore/qtransform.h> diff --git a/tests/auto/core/threadpooler/tst_threadpooler.cpp b/tests/auto/core/threadpooler/tst_threadpooler.cpp index cfe3480ee..289f0b103 100644 --- a/tests/auto/core/threadpooler/tst_threadpooler.cpp +++ b/tests/auto/core/threadpooler/tst_threadpooler.cpp @@ -182,7 +182,7 @@ void massTestFunction(QVector3D *data) void tst_ThreadPooler::initTestCase() { - m_jobManager = new JobManager(this); + m_jobManager = new JobManager(nullptr); } void tst_ThreadPooler::cleanupTestCase() |