From 28236a292be0f26b2f46b58249e498e153f286dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Mon, 14 Nov 2016 09:54:26 +0200 Subject: Add sharecontext to testrender Change-Id: I9cd67d7d1fe19a7a617c9752ecc40f6c24a1a1c3 Reviewed-by: Kevin Ottens --- tests/auto/render/commons/testrenderer.cpp | 5 +++++ tests/auto/render/commons/testrenderer.h | 1 + 2 files changed, 6 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/render/commons/testrenderer.cpp b/tests/auto/render/commons/testrenderer.cpp index 87e60a263..f318797ca 100644 --- a/tests/auto/render/commons/testrenderer.cpp +++ b/tests/auto/render/commons/testrenderer.cpp @@ -76,4 +76,9 @@ QSurfaceFormat TestRenderer::format() return QSurfaceFormat(); } +QOpenGLContext *TestRenderer::shareContext() const +{ + return nullptr; +} + QT_END_NAMESPACE diff --git a/tests/auto/render/commons/testrenderer.h b/tests/auto/render/commons/testrenderer.h index 2e572582e..ecbec4aa3 100644 --- a/tests/auto/render/commons/testrenderer.h +++ b/tests/auto/render/commons/testrenderer.h @@ -74,6 +74,7 @@ public: void resetDirty(); QVariant executeCommand(const QStringList &args) Q_DECL_OVERRIDE; + QOpenGLContext *shareContext() const Q_DECL_OVERRIDE; void setOffscreenSurfaceHelper(Qt3DRender::Render::OffscreenSurfaceHelper *helper) Q_DECL_OVERRIDE; QSurfaceFormat format() Q_DECL_OVERRIDE; -- cgit v1.2.3 From a60d19c1dba26debc3037c94b3b2c4e89716479d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Fri, 21 Oct 2016 12:04:25 +0300 Subject: Add the autotests for renderqmltotexture frontend node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I072c9a86d7730f6c494cd1e7474f84bc76fbb28f Reviewed-by: Tomi Korpipää Reviewed-by: Sean Harmer --- .../qrenderqmltotexture/qrenderqmltotexture.pro | 11 + .../tst_qrenderqmltotexture.cpp | 284 +++++++++++++++++++++ 2 files changed, 295 insertions(+) create mode 100644 tests/auto/render/qrenderqmltotexture/qrenderqmltotexture.pro create mode 100644 tests/auto/render/qrenderqmltotexture/tst_qrenderqmltotexture.cpp (limited to 'tests/auto') diff --git a/tests/auto/render/qrenderqmltotexture/qrenderqmltotexture.pro b/tests/auto/render/qrenderqmltotexture/qrenderqmltotexture.pro new file mode 100644 index 000000000..8b2840929 --- /dev/null +++ b/tests/auto/render/qrenderqmltotexture/qrenderqmltotexture.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +TARGET = qrenderqmltotexture + +QT += 3dcore 3dcore-private 3drender 3drender-private testlib + +CONFIG += testcase + +SOURCES += tst_qrenderqmltotexture.cpp + +include(../commons/commons.pri) diff --git a/tests/auto/render/qrenderqmltotexture/tst_qrenderqmltotexture.cpp b/tests/auto/render/qrenderqmltotexture/tst_qrenderqmltotexture.cpp new file mode 100644 index 000000000..b337306be --- /dev/null +++ b/tests/auto/render/qrenderqmltotexture/tst_qrenderqmltotexture.cpp @@ -0,0 +1,284 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include "testpostmanarbiter.h" + +class tst_QRenderQmlToTexture : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void checkDefaultConstruction() + { + // GIVEN + Qt3DRender::QRenderQmlToTexture renderQmlToTexture; + + // THEN + QCOMPARE(renderQmlToTexture.texture(), nullptr); + QCOMPARE(renderQmlToTexture.source(), QUrl(QStringLiteral(""))); + QCOMPARE(renderQmlToTexture.renderOnce(), false); + QCOMPARE(renderQmlToTexture.loaded(), false); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DRender::QRenderQmlToTexture renderQmlToTexture; + QScopedPointer texture(new Qt3DRender::QTexture2D()); + + { + // WHEN + QSignalSpy spy(&renderQmlToTexture, SIGNAL(textureChanged(Qt3DRender::QAbstractTexture *))); + Qt3DRender::QAbstractTexture * newValue = texture.data(); + renderQmlToTexture.setTexture(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(renderQmlToTexture.texture(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + renderQmlToTexture.setTexture(newValue); + + // THEN + QCOMPARE(renderQmlToTexture.texture(), newValue); + QCOMPARE(spy.count(), 0); + } + { + // WHEN + QSignalSpy spy(&renderQmlToTexture, SIGNAL(sourceChanged(QUrl))); + const QUrl newValue = QUrl(QStringLiteral("qrc://source.qml")); + renderQmlToTexture.setSource(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(renderQmlToTexture.source(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + renderQmlToTexture.setSource(newValue); + + // THEN + QCOMPARE(renderQmlToTexture.source(), newValue); + QCOMPARE(spy.count(), 0); + } + { + // WHEN + QSignalSpy spy(&renderQmlToTexture, SIGNAL(renderOnceChanged(bool))); + const bool newValue = true; + renderQmlToTexture.setRenderOnce(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(renderQmlToTexture.renderOnce(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + renderQmlToTexture.setRenderOnce(newValue); + + // THEN + QCOMPARE(renderQmlToTexture.renderOnce(), newValue); + QCOMPARE(spy.count(), 0); + } + } + + void checkCreationData() + { + // GIVEN + Qt3DRender::QRenderQmlToTexture renderQmlToTexture; + QScopedPointer texture(new Qt3DRender::QTexture2D()); + + renderQmlToTexture.setTexture(texture.data()); + renderQmlToTexture.setSource(QUrl(QStringLiteral("qrc://source.qml"))); + renderQmlToTexture.setRenderOnce(true); + + // WHEN + QVector creationChanges; + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&renderQmlToTexture); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 1); + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DRender::QRenderQmlToTextureData cloneData = creationChangeData->data; + + QCOMPARE(renderQmlToTexture.texture()->id(), cloneData.textureId); + QCOMPARE(renderQmlToTexture.renderOnce(), cloneData.renderOnce); + QCOMPARE(renderQmlToTexture.id(), creationChangeData->subjectId()); + QCOMPARE(renderQmlToTexture.isEnabled(), true); + QCOMPARE(renderQmlToTexture.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(renderQmlToTexture.metaObject(), creationChangeData->metaObject()); + } + + // WHEN + renderQmlToTexture.setEnabled(false); + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&renderQmlToTexture); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 1); + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DRender::QRenderQmlToTextureData cloneData = creationChangeData->data; + + QCOMPARE(renderQmlToTexture.texture()->id(), cloneData.textureId); + QCOMPARE(renderQmlToTexture.renderOnce(), cloneData.renderOnce); + QCOMPARE(renderQmlToTexture.id(), creationChangeData->subjectId()); + QCOMPARE(renderQmlToTexture.isEnabled(), false); + QCOMPARE(renderQmlToTexture.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(renderQmlToTexture.metaObject(), creationChangeData->metaObject()); + } + } + + void checkTextureUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::QRenderQmlToTexture renderQmlToTexture; + arbiter.setArbiterOnNode(&renderQmlToTexture); + QScopedPointer texture(new Qt3DRender::QTexture2D()); + + { + // WHEN + renderQmlToTexture.setTexture(texture.data()); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "texture"); + QCOMPARE(change->value().value(), renderQmlToTexture.texture()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + renderQmlToTexture.setTexture(texture.data()); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + + void checkSourceUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::QRenderQmlToTexture renderQmlToTexture; + arbiter.setArbiterOnNode(&renderQmlToTexture); + + { + // WHEN + renderQmlToTexture.setSource(QUrl(QStringLiteral("qrc://source.qml"))); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "source"); + QCOMPARE(change->value().value(), renderQmlToTexture.source()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + renderQmlToTexture.setSource(QUrl(QStringLiteral("qrc://source.qml"))); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + + void checkRenderOnceUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::QRenderQmlToTexture renderQmlToTexture; + arbiter.setArbiterOnNode(&renderQmlToTexture); + + { + // WHEN + renderQmlToTexture.setRenderOnce(true); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "renderOnce"); + QCOMPARE(change->value().value(), renderQmlToTexture.renderOnce()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + renderQmlToTexture.setRenderOnce(true); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + +}; + +QTEST_MAIN(tst_QRenderQmlToTexture) + +#include "tst_qrenderqmltotexture.moc" -- cgit v1.2.3 From 70d10675b5cc5e1a42a6cb5a4e2da5a31e198a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Fri, 21 Oct 2016 12:05:30 +0300 Subject: Add autotests for renderqmltotexture backend node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I68871b18238eb5aa3c9387e8b5130d848af3ae79 Reviewed-by: Tomi Korpipää Reviewed-by: Sean Harmer --- .../renderqmltotexture/renderqmltotexture.pro | 12 ++ .../renderqmltotexture/tst_renderqmltotexture.cpp | 150 +++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 tests/auto/render/renderqmltotexture/renderqmltotexture.pro create mode 100644 tests/auto/render/renderqmltotexture/tst_renderqmltotexture.cpp (limited to 'tests/auto') diff --git a/tests/auto/render/renderqmltotexture/renderqmltotexture.pro b/tests/auto/render/renderqmltotexture/renderqmltotexture.pro new file mode 100644 index 000000000..2c0f56391 --- /dev/null +++ b/tests/auto/render/renderqmltotexture/renderqmltotexture.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_renderqmltotexture + +QT += 3dcore 3dcore-private 3drender 3drender-private testlib + +CONFIG += testcase + +SOURCES += tst_renderqmltotexture.cpp + +include(../../core/common/common.pri) +include(../commons/commons.pri) diff --git a/tests/auto/render/renderqmltotexture/tst_renderqmltotexture.cpp b/tests/auto/render/renderqmltotexture/tst_renderqmltotexture.cpp new file mode 100644 index 000000000..b6148c514 --- /dev/null +++ b/tests/auto/render/renderqmltotexture/tst_renderqmltotexture.cpp @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** 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 +#include +#include +#include +#include +#include +#include "testrenderer.h" + +class tst_RenderQmlToTexture : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + + void checkInitialState() + { + // GIVEN + Qt3DRender::Render::RenderQmlToTexture backendRenderQmlToTexture; + + // THEN + QCOMPARE(backendRenderQmlToTexture.isEnabled(), false); + QVERIFY(backendRenderQmlToTexture.peerId().isNull()); + QCOMPARE(backendRenderQmlToTexture.m_context, nullptr); + QCOMPARE(backendRenderQmlToTexture.m_graphicsContext, nullptr); + QCOMPARE(backendRenderQmlToTexture.m_renderThread, nullptr); + QCOMPARE(backendRenderQmlToTexture.m_textureId, Qt3DCore::QNodeId()); + QCOMPARE(backendRenderQmlToTexture.m_texture, nullptr); + QCOMPARE(backendRenderQmlToTexture.m_initialized, false); + QCOMPARE(backendRenderQmlToTexture.m_renderInitialized, false); + QCOMPARE(backendRenderQmlToTexture.m_renderOnce, false); + } + + void checkInitializeFromPeer() + { + // GIVEN + Qt3DRender::QRenderQmlToTexture renderQmlToTexture; + + { + // WHEN + Qt3DRender::Render::RenderQmlToTexture backendRenderQmlToTexture; + simulateInitialization(&renderQmlToTexture, &backendRenderQmlToTexture); + + // THEN + QCOMPARE(backendRenderQmlToTexture.isEnabled(), true); + QCOMPARE(backendRenderQmlToTexture.peerId(), renderQmlToTexture.id()); + QCOMPARE(backendRenderQmlToTexture.m_textureId, Qt3DCore::QNodeId()); + QCOMPARE(backendRenderQmlToTexture.m_sharedObject.data(), nullptr); + QCOMPARE(backendRenderQmlToTexture.m_renderOnce, false); + } + { + // WHEN + Qt3DRender::Render::RenderQmlToTexture backendRenderQmlToTexture; + renderQmlToTexture.setEnabled(false); + simulateInitialization(&renderQmlToTexture, &backendRenderQmlToTexture); + + // THEN + QCOMPARE(backendRenderQmlToTexture.peerId(), renderQmlToTexture.id()); + QCOMPARE(backendRenderQmlToTexture.isEnabled(), false); + } + } + + void checkSceneChangeEvents() + { + // GIVEN + Qt3DRender::Render::RenderQmlToTexture backendRenderQmlToTexture; + TestRenderer renderer; + QScopedPointer texture(new Qt3DRender::QTexture2D()); + backendRenderQmlToTexture.setRenderer(&renderer); + + { + // WHEN + const bool newValue = false; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("enabled"); + change->setValue(newValue); + backendRenderQmlToTexture.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendRenderQmlToTexture.isEnabled(), newValue); + } + { + // WHEN + const Qt3DCore::QNodeId newValue = texture.data()->id(); + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("textureId"); + change->setValue(QVariant::fromValue(newValue)); + backendRenderQmlToTexture.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendRenderQmlToTexture.m_textureId, newValue); + } + { + // WHEN + const QSharedPointer newValue + = QSharedPointer(new Qt3DRender::RenderQmlToTextureSharedObject(nullptr)); + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("sharedObject"); + change->setValue(QVariant::fromValue(newValue)); + backendRenderQmlToTexture.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendRenderQmlToTexture.m_sharedObject, newValue); + QCOMPARE(backendRenderQmlToTexture.m_sharedObject.data(), newValue.data()); + } + { + // WHEN + const bool newValue = true; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("renderOnce"); + change->setValue(QVariant::fromValue(newValue)); + backendRenderQmlToTexture.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendRenderQmlToTexture.m_renderOnce, newValue); + } + } + +}; + +QTEST_MAIN(tst_RenderQmlToTexture) + +#include "tst_renderqmltotexture.moc" -- cgit v1.2.3 From 6b66636edab861a5eafa576305efd859f0d58395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Mon, 24 Oct 2016 16:15:29 +0300 Subject: Add unit tests for the QEventForward frontend node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I84c3d8e4bcca14f4aa0c5bde34d3f2e3c76ebaee Reviewed-by: Tomi Korpipää Reviewed-by: Sean Harmer --- tests/auto/render/qeventforward/qeventforward.pro | 12 + .../render/qeventforward/tst_qeventforward.cpp | 406 +++++++++++++++++++++ tests/auto/render/render.pro | 3 +- 3 files changed, 420 insertions(+), 1 deletion(-) create mode 100644 tests/auto/render/qeventforward/qeventforward.pro create mode 100644 tests/auto/render/qeventforward/tst_qeventforward.cpp (limited to 'tests/auto') diff --git a/tests/auto/render/qeventforward/qeventforward.pro b/tests/auto/render/qeventforward/qeventforward.pro new file mode 100644 index 000000000..2479b038c --- /dev/null +++ b/tests/auto/render/qeventforward/qeventforward.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_qeventforward + +QT += 3dcore 3dcore-private 3drender 3drender-private testlib + +CONFIG += testcase + +SOURCES += tst_qeventforward.cpp + +include(../../core/common/common.pri) +include(../commons/commons.pri) diff --git a/tests/auto/render/qeventforward/tst_qeventforward.cpp b/tests/auto/render/qeventforward/tst_qeventforward.cpp new file mode 100644 index 000000000..87ba114f2 --- /dev/null +++ b/tests/auto/render/qeventforward/tst_qeventforward.cpp @@ -0,0 +1,406 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include "testpostmanarbiter.h" + +class tst_QEventForward : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void checkDefaultConstruction() + { + // GIVEN + Qt3DRender::QEventForward eventForward; + + // THEN + QCOMPARE(eventForward.target(), nullptr); + QCOMPARE(eventForward.forwardMouseEvents(), true); + QCOMPARE(eventForward.forwardKeyboardEvents(), false); + QCOMPARE(eventForward.coordinateTransform(), QMatrix4x4()); + QCOMPARE(eventForward.coordinateAttribute(), QStringLiteral("default")); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DRender::QEventForward eventForward; + + { + // WHEN + QScopedPointer obj(new QObject()); + QSignalSpy spy(&eventForward, SIGNAL(targetChanged(QObject*))); + QObject* newValue = obj.data(); + eventForward.setTarget(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(eventForward.target(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + eventForward.setTarget(newValue); + + // THEN + QCOMPARE(eventForward.target(), newValue); + QCOMPARE(spy.count(), 0); + } + { + // WHEN + QSignalSpy spy(&eventForward, SIGNAL(forwardMouseEventsChanged(bool))); + const bool newValue = false; + eventForward.setForwardMouseEvents(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(eventForward.forwardMouseEvents(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + eventForward.setForwardMouseEvents(newValue); + + // THEN + QCOMPARE(eventForward.forwardMouseEvents(), newValue); + QCOMPARE(spy.count(), 0); + } + { + // WHEN + QSignalSpy spy(&eventForward, SIGNAL(forwardKeyboardEventsChanged(bool))); + const bool newValue = true; + eventForward.setForwardKeyboardEvents(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(eventForward.forwardKeyboardEvents(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + eventForward.setForwardKeyboardEvents(newValue); + + // THEN + QCOMPARE(eventForward.forwardKeyboardEvents(), newValue); + QCOMPARE(spy.count(), 0); + } + { + // WHEN + QSignalSpy spy(&eventForward, SIGNAL(coordinateTransformChanged(QMatrix4x4))); + QMatrix4x4 newValue; + newValue.scale(3.0f); + eventForward.setCoordinateTransform(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(eventForward.coordinateTransform(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + eventForward.setCoordinateTransform(newValue); + + // THEN + QCOMPARE(eventForward.coordinateTransform(), newValue); + QCOMPARE(spy.count(), 0); + } + { + // WHEN + QSignalSpy spy(&eventForward, SIGNAL(coordinateAttributeChanged(QString))); + const QString newValue = Qt3DRender::QAttribute::defaultColorAttributeName(); + eventForward.setCoordinateAttribute(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(eventForward.coordinateAttribute(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + eventForward.setCoordinateAttribute(newValue); + + // THEN + QCOMPARE(eventForward.coordinateAttribute(), newValue); + QCOMPARE(spy.count(), 0); + } + } + + void checkCreationData() + { + // GIVEN + Qt3DRender::QEventForward eventForward; + QScopedPointer obj(new QObject()); + QMatrix4x4 transform; + transform.translate(1.0f, 2.0f, 3.0f); + + eventForward.setTarget(obj.data()); + eventForward.setForwardMouseEvents(true); + eventForward.setForwardKeyboardEvents(true); + eventForward.setCoordinateTransform(transform); + eventForward.setCoordinateAttribute(QStringLiteral("position")); + + // WHEN + QVector creationChanges; + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&eventForward); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 1); + + const auto creationChangeData + = qSharedPointerCast>(creationChanges.first()); + const Qt3DRender::QEventForwardData cloneData = creationChangeData->data; + + QCOMPARE(eventForward.target(), cloneData.target); + QCOMPARE(eventForward.forwardMouseEvents(), cloneData.forwardMouseEvents); + QCOMPARE(eventForward.forwardKeyboardEvents(), cloneData.forwardKeyboardEvents); + QCOMPARE(eventForward.coordinateTransform(), cloneData.coordinateTransform); + QCOMPARE(eventForward.coordinateAttribute(), cloneData.coordinateAttribute); + QCOMPARE(eventForward.id(), creationChangeData->subjectId()); + QCOMPARE(eventForward.isEnabled(), true); + QCOMPARE(eventForward.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(eventForward.metaObject(), creationChangeData->metaObject()); + } + + // WHEN + eventForward.setEnabled(false); + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&eventForward); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 1); + + const auto creationChangeData + = qSharedPointerCast>(creationChanges.first()); + const Qt3DRender::QEventForwardData cloneData = creationChangeData->data; + + QCOMPARE(eventForward.target(), cloneData.target); + QCOMPARE(eventForward.forwardMouseEvents(), cloneData.forwardMouseEvents); + QCOMPARE(eventForward.forwardKeyboardEvents(), cloneData.forwardKeyboardEvents); + QCOMPARE(eventForward.coordinateTransform(), cloneData.coordinateTransform); + QCOMPARE(eventForward.coordinateAttribute(), cloneData.coordinateAttribute); + QCOMPARE(eventForward.id(), creationChangeData->subjectId()); + QCOMPARE(eventForward.isEnabled(), false); + QCOMPARE(eventForward.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(eventForward.metaObject(), creationChangeData->metaObject()); + } + } + + void checkTargetUpdate() + { + // GIVEN + TestArbiter arbiter; + QScopedPointer obj(new QObject()); + Qt3DRender::QEventForward eventForward; + arbiter.setArbiterOnNode(&eventForward); + + { + // WHEN + eventForward.setTarget(obj.data()); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "target"); + QCOMPARE(change->value().value(), eventForward.target()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + eventForward.setTarget(obj.data()); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + + void checkForwardMouseEventsUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::QEventForward eventForward; + arbiter.setArbiterOnNode(&eventForward); + + { + // WHEN + eventForward.setForwardMouseEvents(false); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "forwardMouseEvents"); + QCOMPARE(change->value().value(), eventForward.forwardMouseEvents()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + eventForward.setForwardMouseEvents(false); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + + void checkForwardKeyboardEventsUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::QEventForward eventForward; + arbiter.setArbiterOnNode(&eventForward); + + { + // WHEN + eventForward.setForwardKeyboardEvents(true); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "forwardKeyboardEvents"); + QCOMPARE(change->value().value(), eventForward.forwardKeyboardEvents()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + eventForward.setForwardKeyboardEvents(true); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + + void checkCoordinateTransformUpdate() + { + // GIVEN + TestArbiter arbiter; + QMatrix4x4 transform; + Qt3DRender::QEventForward eventForward; + arbiter.setArbiterOnNode(&eventForward); + transform.translate(2.0f, 1.0f, 4.0f); + + { + // WHEN + eventForward.setCoordinateTransform(transform); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "coordinateTransform"); + QCOMPARE(change->value().value(), eventForward.coordinateTransform()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + eventForward.setCoordinateTransform(transform); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + + void checkCoordinateAttributeUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::QEventForward eventForward; + arbiter.setArbiterOnNode(&eventForward); + + { + // WHEN + eventForward.setCoordinateAttribute(QStringLiteral("normal")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "coordinateAttribute"); + QCOMPARE(change->value().value(), eventForward.coordinateAttribute()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + eventForward.setCoordinateAttribute(QStringLiteral("normal")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + +}; + +QTEST_MAIN(tst_QEventForward) + +#include "tst_qeventforward.moc" diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro index bb24205e4..c42d47e1f 100644 --- a/tests/auto/render/render.pro +++ b/tests/auto/render/render.pro @@ -96,7 +96,8 @@ qtConfig(private_tests) { filtercompatibletechniquejob \ rendercapture \ trianglevisitor \ - qmemorybarrier + qmemorybarrier \ + qeventforward !macos: SUBDIRS += graphicshelpergl4 } -- cgit v1.2.3 From 16e11dd7635c7d908a5fd8f97bff3ecddf63e899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Mon, 24 Oct 2016 16:21:06 +0300 Subject: Add unit tests for the EventForward backend node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I1b04c3a89e52923b31adbd60bc88c906c020a93a Reviewed-by: Tomi Korpipää Reviewed-by: Sean Harmer --- tests/auto/render/eventforward/eventforward.pro | 12 ++ .../auto/render/eventforward/tst_eventforward.cpp | 197 +++++++++++++++++++++ tests/auto/render/render.pro | 3 +- 3 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 tests/auto/render/eventforward/eventforward.pro create mode 100644 tests/auto/render/eventforward/tst_eventforward.cpp (limited to 'tests/auto') diff --git a/tests/auto/render/eventforward/eventforward.pro b/tests/auto/render/eventforward/eventforward.pro new file mode 100644 index 000000000..22b481c77 --- /dev/null +++ b/tests/auto/render/eventforward/eventforward.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_eventforward + +QT += 3dcore 3dcore-private 3drender 3drender-private testlib + +CONFIG += testcase + +SOURCES += tst_eventforward.cpp + +include(../../core/common/common.pri) +include(../commons/commons.pri) diff --git a/tests/auto/render/eventforward/tst_eventforward.cpp b/tests/auto/render/eventforward/tst_eventforward.cpp new file mode 100644 index 000000000..9a87fc40f --- /dev/null +++ b/tests/auto/render/eventforward/tst_eventforward.cpp @@ -0,0 +1,197 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** 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 +#include +#include +#include +#include +#include "qbackendnodetester.h" +#include "testrenderer.h" + +class tst_EventForward : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + + void checkInitialState() + { + // GIVEN + Qt3DRender::Render::EventForward backendEventForward; + + // THEN + QCOMPARE(backendEventForward.isEnabled(), false); + QVERIFY(backendEventForward.peerId().isNull()); + QCOMPARE(backendEventForward.target(), nullptr); + QCOMPARE(backendEventForward.coordinateAttribute(), QStringLiteral("")); + QCOMPARE(backendEventForward.coordinateTransform(), QMatrix4x4()); + QCOMPARE(backendEventForward.forwardMouseEvents(), false); + QCOMPARE(backendEventForward.forwardKeyboardEvents(), false); + } + + void checkCleanupState() + { + // GIVEN + Qt3DRender::Render::EventForward backendEventForward; + QScopedPointer obj(new QObject()); + QMatrix4x4 transform; + transform.scale(1.0f, 2.0f, 3.0f); + + // WHEN + backendEventForward.setEnabled(true); + backendEventForward.setTarget(obj.data()); + backendEventForward.setCoordinateAttribute(QStringLiteral("default")); + backendEventForward.setCoordinateTransform(transform); + backendEventForward.setForwardMouseEvents(true); + backendEventForward.setForwardKeyboardEvents(true); + + backendEventForward.cleanup(); + + // THEN + QCOMPARE(backendEventForward.isEnabled(), false); + QCOMPARE(backendEventForward.target(), nullptr); + QCOMPARE(backendEventForward.coordinateAttribute(), QStringLiteral("")); + QCOMPARE(backendEventForward.coordinateTransform(), QMatrix4x4()); + QCOMPARE(backendEventForward.forwardMouseEvents(), false); + QCOMPARE(backendEventForward.forwardKeyboardEvents(), false); + } + + void checkInitializeFromPeer() + { + // GIVEN + Qt3DRender::QEventForward eventForward; + + { + // WHEN + Qt3DRender::Render::EventForward backendEventForward; + simulateInitialization(&eventForward, &backendEventForward); + + // THEN + QCOMPARE(backendEventForward.isEnabled(), true); + QCOMPARE(backendEventForward.peerId(), eventForward.id()); + QCOMPARE(backendEventForward.target(), nullptr); + QCOMPARE(backendEventForward.coordinateAttribute(), QStringLiteral("default")); + QCOMPARE(backendEventForward.coordinateTransform(), QMatrix4x4()); + QCOMPARE(backendEventForward.forwardMouseEvents(), true); + QCOMPARE(backendEventForward.forwardKeyboardEvents(), false); + } + { + // WHEN + Qt3DRender::Render::EventForward backendEventForward; + eventForward.setEnabled(false); + simulateInitialization(&eventForward, &backendEventForward); + + // THEN + QCOMPARE(backendEventForward.peerId(), eventForward.id()); + QCOMPARE(backendEventForward.isEnabled(), false); + } + } + + void checkSceneChangeEvents() + { + // GIVEN + Qt3DRender::Render::EventForward backendEventForward; + TestRenderer renderer; + backendEventForward.setRenderer(&renderer); + + { + // WHEN + const bool newValue = false; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("enabled"); + change->setValue(newValue); + backendEventForward.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendEventForward.isEnabled(), newValue); + } + { + // WHEN + QScopedPointer obj(new Qt3DRender::QEventForward()); + Qt3DRender::QEventForward * newValue = obj.data(); + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("target"); + change->setValue(QVariant::fromValue(newValue)); + backendEventForward.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendEventForward.target(), newValue); + } + { + // WHEN + const QString newValue = QStringLiteral("position"); + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("coordinateAttribute"); + change->setValue(QVariant::fromValue(newValue)); + backendEventForward.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendEventForward.coordinateAttribute(), newValue); + } + { + // WHEN + QMatrix4x4 newValue; + newValue.rotate(2.0f, QVector3D(0, 0, 1.0f)); + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("coordinateTransform"); + change->setValue(QVariant::fromValue(newValue)); + backendEventForward.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendEventForward.coordinateTransform(), newValue); + } + { + // WHEN + const bool newValue = true; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("forwardMouseEvents"); + change->setValue(QVariant::fromValue(newValue)); + backendEventForward.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendEventForward.forwardMouseEvents(), newValue); + } + { + // WHEN + const bool newValue = true; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("forwardKeyboardEvents"); + change->setValue(QVariant::fromValue(newValue)); + backendEventForward.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendEventForward.forwardKeyboardEvents(), newValue); + } + } + +}; + +QTEST_MAIN(tst_EventForward) + +#include "tst_eventforward.moc" diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro index c42d47e1f..34c07f7dc 100644 --- a/tests/auto/render/render.pro +++ b/tests/auto/render/render.pro @@ -97,7 +97,8 @@ qtConfig(private_tests) { rendercapture \ trianglevisitor \ qmemorybarrier \ - qeventforward + qeventforward \ + eventforward !macos: SUBDIRS += graphicshelpergl4 } -- cgit v1.2.3 From fe8ba714347091a61d0b335d3413b49f8094dfd8 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Fri, 16 Dec 2016 15:10:16 +0100 Subject: Add unit test for QShaderProgram Change-Id: Icefb4f688143068334989fb9b64056f9fbe0dda3 Reviewed-by: Paul Lemire --- .../auto/render/qshaderprogram/qshaderprogram.pro | 12 + .../render/qshaderprogram/tst_qshaderprogram.cpp | 518 +++++++++++++++++++++ tests/auto/render/render.pro | 3 +- 3 files changed, 532 insertions(+), 1 deletion(-) create mode 100644 tests/auto/render/qshaderprogram/qshaderprogram.pro create mode 100644 tests/auto/render/qshaderprogram/tst_qshaderprogram.cpp (limited to 'tests/auto') diff --git a/tests/auto/render/qshaderprogram/qshaderprogram.pro b/tests/auto/render/qshaderprogram/qshaderprogram.pro new file mode 100644 index 000000000..6f40caee9 --- /dev/null +++ b/tests/auto/render/qshaderprogram/qshaderprogram.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_qshaderprogram + +QT += 3dcore 3dcore-private 3drender 3drender-private testlib + +CONFIG += testcase + +SOURCES += tst_qshaderprogram.cpp + +include(../../core/common/common.pri) +include(../commons/commons.pri) diff --git a/tests/auto/render/qshaderprogram/tst_qshaderprogram.cpp b/tests/auto/render/qshaderprogram/tst_qshaderprogram.cpp new file mode 100644 index 000000000..e5d001759 --- /dev/null +++ b/tests/auto/render/qshaderprogram/tst_qshaderprogram.cpp @@ -0,0 +1,518 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Paul Lemire +** 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 +#include +#include +#include +#include +#include +#include +#include +#include "testpostmanarbiter.h" + +// We need to call QShaderProgram::sceneChangeEvent +class tst_QShaderProgram : public Qt3DRender::QShaderProgram +{ + Q_OBJECT + +private Q_SLOTS: + + void checkDefaultConstruction() + { + // GIVEN + Qt3DRender::QShaderProgram shaderProgram; + + // THEN + QCOMPARE(shaderProgram.vertexShaderCode(), QByteArray()); + QCOMPARE(shaderProgram.tessellationControlShaderCode(), QByteArray()); + QCOMPARE(shaderProgram.tessellationEvaluationShaderCode(), QByteArray()); + QCOMPARE(shaderProgram.geometryShaderCode(), QByteArray()); + QCOMPARE(shaderProgram.fragmentShaderCode(), QByteArray()); + QCOMPARE(shaderProgram.computeShaderCode(), QByteArray()); + QCOMPARE(shaderProgram.log(), QString()); + QCOMPARE(shaderProgram.status(), Qt3DRender::QShaderProgram::NotReady); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DRender::QShaderProgram shaderProgram; + + { + // WHEN + QSignalSpy spy(&shaderProgram, SIGNAL(vertexShaderCodeChanged(QByteArray))); + const QByteArray newValue = "VERTEX"; + shaderProgram.setVertexShaderCode(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(shaderProgram.vertexShaderCode(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + shaderProgram.setVertexShaderCode(newValue); + + // THEN + QCOMPARE(shaderProgram.vertexShaderCode(), newValue); + QCOMPARE(spy.count(), 0); + } + { + // WHEN + QSignalSpy spy(&shaderProgram, SIGNAL(tessellationControlShaderCodeChanged(QByteArray))); + const QByteArray newValue = "TESSELATION_CONTROL"; + shaderProgram.setTessellationControlShaderCode(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(shaderProgram.tessellationControlShaderCode(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + shaderProgram.setTessellationControlShaderCode(newValue); + + // THEN + QCOMPARE(shaderProgram.tessellationControlShaderCode(), newValue); + QCOMPARE(spy.count(), 0); + } + { + // WHEN + QSignalSpy spy(&shaderProgram, SIGNAL(tessellationEvaluationShaderCodeChanged(QByteArray))); + const QByteArray newValue = "TESSELATION_EVALUTATION"; + shaderProgram.setTessellationEvaluationShaderCode(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(shaderProgram.tessellationEvaluationShaderCode(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + shaderProgram.setTessellationEvaluationShaderCode(newValue); + + // THEN + QCOMPARE(shaderProgram.tessellationEvaluationShaderCode(), newValue); + QCOMPARE(spy.count(), 0); + } + { + // WHEN + QSignalSpy spy(&shaderProgram, SIGNAL(geometryShaderCodeChanged(QByteArray))); + const QByteArray newValue = "GEOMETRY"; + shaderProgram.setGeometryShaderCode(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(shaderProgram.geometryShaderCode(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + shaderProgram.setGeometryShaderCode(newValue); + + // THEN + QCOMPARE(shaderProgram.geometryShaderCode(), newValue); + QCOMPARE(spy.count(), 0); + } + { + // WHEN + QSignalSpy spy(&shaderProgram, SIGNAL(fragmentShaderCodeChanged(QByteArray))); + const QByteArray newValue = "FRAGMENT"; + shaderProgram.setFragmentShaderCode(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(shaderProgram.fragmentShaderCode(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + shaderProgram.setFragmentShaderCode(newValue); + + // THEN + QCOMPARE(shaderProgram.fragmentShaderCode(), newValue); + QCOMPARE(spy.count(), 0); + } + { + // WHEN + QSignalSpy spy(&shaderProgram, SIGNAL(computeShaderCodeChanged(QByteArray))); + const QByteArray newValue = "COMPUTE"; + shaderProgram.setComputeShaderCode(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(shaderProgram.computeShaderCode(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + shaderProgram.setComputeShaderCode(newValue); + + // THEN + QCOMPARE(shaderProgram.computeShaderCode(), newValue); + QCOMPARE(spy.count(), 0); + } + } + + void checkCreationData() + { + // GIVEN + Qt3DRender::QShaderProgram shaderProgram; + + shaderProgram.setVertexShaderCode(QByteArrayLiteral("Vertex")); + shaderProgram.setTessellationControlShaderCode(QByteArrayLiteral("TesselControl")); + shaderProgram.setTessellationEvaluationShaderCode(QByteArrayLiteral("TesselEval")); + shaderProgram.setGeometryShaderCode(QByteArrayLiteral("Geometry")); + shaderProgram.setFragmentShaderCode(QByteArrayLiteral("Fragment")); + shaderProgram.setComputeShaderCode(QByteArrayLiteral("Compute")); + + // WHEN + QVector creationChanges; + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&shaderProgram); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 1); + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DRender::QShaderProgramData cloneData = creationChangeData->data; + + QCOMPARE(shaderProgram.vertexShaderCode(), cloneData.vertexShaderCode); + QCOMPARE(shaderProgram.tessellationControlShaderCode(), cloneData.tessellationControlShaderCode); + QCOMPARE(shaderProgram.tessellationEvaluationShaderCode(), cloneData.tessellationEvaluationShaderCode); + QCOMPARE(shaderProgram.geometryShaderCode(), cloneData.geometryShaderCode); + QCOMPARE(shaderProgram.fragmentShaderCode(), cloneData.fragmentShaderCode); + QCOMPARE(shaderProgram.computeShaderCode(), cloneData.computeShaderCode); + QCOMPARE(shaderProgram.id(), creationChangeData->subjectId()); + QCOMPARE(shaderProgram.isEnabled(), true); + QCOMPARE(shaderProgram.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(shaderProgram.metaObject(), creationChangeData->metaObject()); + } + + // WHEN + shaderProgram.setEnabled(false); + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&shaderProgram); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 1); + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DRender::QShaderProgramData cloneData = creationChangeData->data; + + QCOMPARE(shaderProgram.vertexShaderCode(), cloneData.vertexShaderCode); + QCOMPARE(shaderProgram.tessellationControlShaderCode(), cloneData.tessellationControlShaderCode); + QCOMPARE(shaderProgram.tessellationEvaluationShaderCode(), cloneData.tessellationEvaluationShaderCode); + QCOMPARE(shaderProgram.geometryShaderCode(), cloneData.geometryShaderCode); + QCOMPARE(shaderProgram.fragmentShaderCode(), cloneData.fragmentShaderCode); + QCOMPARE(shaderProgram.computeShaderCode(), cloneData.computeShaderCode); + QCOMPARE(shaderProgram.id(), creationChangeData->subjectId()); + QCOMPARE(shaderProgram.isEnabled(), false); + QCOMPARE(shaderProgram.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(shaderProgram.metaObject(), creationChangeData->metaObject()); + } + } + + void checkVertexShaderCodeUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::QShaderProgram shaderProgram; + arbiter.setArbiterOnNode(&shaderProgram); + + { + // WHEN + shaderProgram.setVertexShaderCode(QByteArrayLiteral("in vec3 toto;")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "vertexShaderCode"); + QCOMPARE(change->value().value(), shaderProgram.vertexShaderCode()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + shaderProgram.setVertexShaderCode(QByteArrayLiteral("in vec3 toto;")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + + void checkTessellationControlShaderCodeUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::QShaderProgram shaderProgram; + arbiter.setArbiterOnNode(&shaderProgram); + + { + // WHEN + shaderProgram.setTessellationControlShaderCode(QByteArrayLiteral("in vec3 toto2;")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "tessellationControlShaderCode"); + QCOMPARE(change->value().value(), shaderProgram.tessellationControlShaderCode()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + shaderProgram.setTessellationControlShaderCode(QByteArrayLiteral("in vec3 toto2;")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + + void checkTessellationEvaluationShaderCodeUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::QShaderProgram shaderProgram; + arbiter.setArbiterOnNode(&shaderProgram); + + { + // WHEN + shaderProgram.setTessellationEvaluationShaderCode(QByteArrayLiteral("in vec3 toto3;")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "tessellationEvaluationShaderCode"); + QCOMPARE(change->value().value(), shaderProgram.tessellationEvaluationShaderCode()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + shaderProgram.setTessellationEvaluationShaderCode(QByteArrayLiteral("in vec3 toto3;")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + + void checkGeometryShaderCodeUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::QShaderProgram shaderProgram; + arbiter.setArbiterOnNode(&shaderProgram); + + { + // WHEN + shaderProgram.setGeometryShaderCode(QByteArrayLiteral("in vec3 toto4;")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "geometryShaderCode"); + QCOMPARE(change->value().value(), shaderProgram.geometryShaderCode()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + shaderProgram.setGeometryShaderCode(QByteArrayLiteral("in vec3 toto4;")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + + void checkFragmentShaderCodeUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::QShaderProgram shaderProgram; + arbiter.setArbiterOnNode(&shaderProgram); + + { + // WHEN + shaderProgram.setFragmentShaderCode(QByteArrayLiteral("out vec4 fragColor;")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "fragmentShaderCode"); + QCOMPARE(change->value().value(), shaderProgram.fragmentShaderCode()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + shaderProgram.setFragmentShaderCode(QByteArrayLiteral("out vec4 fragColor;")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + + void checkComputeShaderCodeUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::QShaderProgram shaderProgram; + arbiter.setArbiterOnNode(&shaderProgram); + + { + // WHEN + shaderProgram.setComputeShaderCode(QByteArrayLiteral("uniform vec3 temp;")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "computeShaderCode"); + QCOMPARE(change->value().value(), shaderProgram.computeShaderCode()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + shaderProgram.setComputeShaderCode(QByteArrayLiteral("uniform vec3 temp;")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + + void checkLogPropertyUpdate() + { + // GIVEN + TestArbiter arbiter; + arbiter.setArbiterOnNode(this); + QSignalSpy spy(this, SIGNAL(logChanged(QString))); + const QString logValue = QStringLiteral("Some log..."); + + // THEN + QVERIFY(spy.isValid()); + + // WHEN + Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); + valueChange->setPropertyName("log"); + valueChange->setValue(QVariant::fromValue(logValue)); + sceneChangeEvent(valueChange); + + // THEN + QCOMPARE(spy.count(), 1); + QCOMPARE(arbiter.events.size(), 0); + QCOMPARE(log(), logValue); + + // WHEN + spy.clear(); + sceneChangeEvent(valueChange); + + // THEN + QCOMPARE(spy.count(), 0); + QCOMPARE(arbiter.events.size(), 0); + QCOMPARE(log(), logValue); + } + + void checkStatusPropertyUpdate() + { + // GIVEN + qRegisterMetaType("ShaderStatus"); + TestArbiter arbiter; + arbiter.setArbiterOnNode(this); + QSignalSpy spy(this, SIGNAL(statusChanged(ShaderStatus))); + const Qt3DRender::QShaderProgram::ShaderStatus newStatus = Qt3DRender::QShaderProgram::Error; + + // THEN + QVERIFY(spy.isValid()); + + // WHEN + Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::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); + } + +}; + +QTEST_MAIN(tst_QShaderProgram) + +#include "tst_qshaderprogram.moc" diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro index c1de2aff8..5c04c0fb8 100644 --- a/tests/auto/render/render.pro +++ b/tests/auto/render/render.pro @@ -100,7 +100,8 @@ qtConfig(private_tests) { rendercapture \ trianglevisitor \ qmemorybarrier \ - memorybarrier + memorybarrier \ + qshaderprogram !macos: SUBDIRS += graphicshelpergl4 } -- cgit v1.2.3 From 5578d5b89d06b502e05ef6b3e3c6ffa0c29a7aa7 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Fri, 16 Dec 2016 16:09:17 +0100 Subject: ShaderProgram: store and send log and status to frontend Change-Id: I00b02f8b73ecf1194b4c4db7b60a95ee7cc3df22 Task-number: QTBUG-57615 Reviewed-by: Sean Harmer --- tests/auto/render/shader/tst_shader.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/render/shader/tst_shader.cpp b/tests/auto/render/shader/tst_shader.cpp index 95576afe0..f6ed41a8b 100644 --- a/tests/auto/render/shader/tst_shader.cpp +++ b/tests/auto/render/shader/tst_shader.cpp @@ -81,6 +81,7 @@ void tst_RenderShader::hasCoherentInitialState() QVERIFY(shader->uniforms().isEmpty()); QVERIFY(shader->attributes().isEmpty()); QVERIFY(shader->uniformBlocks().isEmpty()); + QCOMPARE(shader->status(), Qt3DRender::QShaderProgram::NotReady); } void tst_RenderShader::matchesFrontendPeer() @@ -114,6 +115,7 @@ void tst_RenderShader::cleanupLeavesACoherentState() QVERIFY(shader->uniforms().isEmpty()); QVERIFY(shader->attributes().isEmpty()); QVERIFY(shader->uniformBlocks().isEmpty()); + QCOMPARE(shader->status(), Qt3DRender::QShaderProgram::NotReady); } QTEST_APPLESS_MAIN(tst_RenderShader) -- cgit v1.2.3 From c2da124e676c3e1b599210d1ee50a09b3fff9ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Tue, 25 Oct 2016 13:10:23 +0300 Subject: Update ObjectPicker unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I648e0b49e06c68779631870f9d31e3671eb5e691 Reviewed-by: Tomi Korpipää Reviewed-by: Sean Harmer --- tests/auto/render/objectpicker/tst_objectpicker.cpp | 17 +++++++++++++++++ tests/auto/render/qobjectpicker/tst_qobjectpicker.cpp | 14 ++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/render/objectpicker/tst_objectpicker.cpp b/tests/auto/render/objectpicker/tst_objectpicker.cpp index c42ec60c9..96ee76827 100644 --- a/tests/auto/render/objectpicker/tst_objectpicker.cpp +++ b/tests/auto/render/objectpicker/tst_objectpicker.cpp @@ -46,7 +46,9 @@ private Q_SLOTS: // GIVEN Qt3DRender::Render::ObjectPicker objectPicker; Qt3DRender::QObjectPicker picker; + Qt3DRender::QEventForward eventForward; picker.setHoverEnabled(true); + picker.setEventForward(&eventForward); // WHEN simulateInitialization(&picker, &objectPicker); @@ -55,6 +57,7 @@ private Q_SLOTS: QVERIFY(!objectPicker.peerId().isNull()); QCOMPARE(objectPicker.isHoverEnabled(), true); QCOMPARE(objectPicker.isDirty(), true); + QCOMPARE(objectPicker.eventForward(), eventForward.id()); } void checkInitialAndCleanedUpState() @@ -66,6 +69,8 @@ private Q_SLOTS: QVERIFY(objectPicker.peerId().isNull()); QCOMPARE(objectPicker.isHoverEnabled(), false); QCOMPARE(objectPicker.isDirty(), false); + QCOMPARE(objectPicker.isEventForwardingEnabled(), false); + QCOMPARE(objectPicker.eventForward(), Qt3DCore::QNodeId()); // GIVEN Qt3DRender::QObjectPicker picker; @@ -78,12 +83,15 @@ private Q_SLOTS: // THEN QCOMPARE(objectPicker.isHoverEnabled(), false); QCOMPARE(objectPicker.isDirty(), false); + QCOMPARE(objectPicker.isEventForwardingEnabled(), false); + QCOMPARE(objectPicker.eventForward(), Qt3DCore::QNodeId()); } void checkPropertyChanges() { // GIVEN Qt3DRender::Render::ObjectPicker objectPicker; + Qt3DRender::QEventForward eventForward; TestRenderer renderer; objectPicker.setRenderer(&renderer); @@ -102,6 +110,15 @@ private Q_SLOTS: objectPicker.unsetDirty(); QVERIFY(!objectPicker.isDirty()); + + // WHEN + updateChange->setValue(QVariant::fromValue(eventForward.id())); + updateChange->setPropertyName("eventForward"); + objectPicker.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(objectPicker.isEventForwardingEnabled(), true); + QCOMPARE(objectPicker.eventForward(), eventForward.id()); } void checkBackendPropertyNotifications() diff --git a/tests/auto/render/qobjectpicker/tst_qobjectpicker.cpp b/tests/auto/render/qobjectpicker/tst_qobjectpicker.cpp index 4397954ec..8cc87ce14 100644 --- a/tests/auto/render/qobjectpicker/tst_qobjectpicker.cpp +++ b/tests/auto/render/qobjectpicker/tst_qobjectpicker.cpp @@ -105,6 +105,7 @@ private Q_SLOTS: // GIVEN TestArbiter arbiter; QScopedPointer objectPicker(new Qt3DRender::QObjectPicker()); + QScopedPointer eventForward(new Qt3DRender::QEventForward()); arbiter.setArbiterOnNode(objectPicker.data()); // WHEN @@ -119,6 +120,19 @@ private Q_SLOTS: QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); arbiter.events.clear(); + + // WHEN + objectPicker->setEventForward(eventForward.data()); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.last().staticCast(); + QCOMPARE(change->propertyName(), "eventForward"); + QCOMPARE(change->value().value(), eventForward->id()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); } void checkBackendUpdates_data() -- cgit v1.2.3 From b11edfb98c14d91d8a59352b05b5e902e8d2231b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Tue, 25 Oct 2016 13:43:59 +0300 Subject: Update EventForward autotests with focus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I7bc92c46f9ebb8fddc30207635cb5252944dfbca Reviewed-by: Tomi Korpipää Reviewed-by: Sean Harmer --- .../auto/render/eventforward/tst_eventforward.cpp | 17 +++++++ .../render/qeventforward/tst_qeventforward.cpp | 56 ++++++++++++++++++++++ 2 files changed, 73 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/render/eventforward/tst_eventforward.cpp b/tests/auto/render/eventforward/tst_eventforward.cpp index 9a87fc40f..5352853a1 100644 --- a/tests/auto/render/eventforward/tst_eventforward.cpp +++ b/tests/auto/render/eventforward/tst_eventforward.cpp @@ -53,6 +53,7 @@ private Q_SLOTS: QCOMPARE(backendEventForward.coordinateTransform(), QMatrix4x4()); QCOMPARE(backendEventForward.forwardMouseEvents(), false); QCOMPARE(backendEventForward.forwardKeyboardEvents(), false); + QCOMPARE(backendEventForward.focus(), false); } void checkCleanupState() @@ -70,6 +71,7 @@ private Q_SLOTS: backendEventForward.setCoordinateTransform(transform); backendEventForward.setForwardMouseEvents(true); backendEventForward.setForwardKeyboardEvents(true); + backendEventForward.setFocus(true); backendEventForward.cleanup(); @@ -80,6 +82,7 @@ private Q_SLOTS: QCOMPARE(backendEventForward.coordinateTransform(), QMatrix4x4()); QCOMPARE(backendEventForward.forwardMouseEvents(), false); QCOMPARE(backendEventForward.forwardKeyboardEvents(), false); + QCOMPARE(backendEventForward.focus(), false); } void checkInitializeFromPeer() @@ -100,16 +103,19 @@ private Q_SLOTS: QCOMPARE(backendEventForward.coordinateTransform(), QMatrix4x4()); QCOMPARE(backendEventForward.forwardMouseEvents(), true); QCOMPARE(backendEventForward.forwardKeyboardEvents(), false); + QCOMPARE(backendEventForward.focus(), false); } { // WHEN Qt3DRender::Render::EventForward backendEventForward; eventForward.setEnabled(false); + eventForward.setFocus(true); simulateInitialization(&eventForward, &backendEventForward); // THEN QCOMPARE(backendEventForward.peerId(), eventForward.id()); QCOMPARE(backendEventForward.isEnabled(), false); + QCOMPARE(backendEventForward.focus(), true); } } @@ -188,6 +194,17 @@ private Q_SLOTS: // THEN QCOMPARE(backendEventForward.forwardKeyboardEvents(), newValue); } + { + // WHEN + const bool newValue = true; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("focus"); + change->setValue(QVariant::fromValue(newValue)); + backendEventForward.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendEventForward.focus(), newValue); + } } }; diff --git a/tests/auto/render/qeventforward/tst_qeventforward.cpp b/tests/auto/render/qeventforward/tst_qeventforward.cpp index 87ba114f2..aa525d4a2 100644 --- a/tests/auto/render/qeventforward/tst_qeventforward.cpp +++ b/tests/auto/render/qeventforward/tst_qeventforward.cpp @@ -54,6 +54,7 @@ private Q_SLOTS: QCOMPARE(eventForward.forwardKeyboardEvents(), false); QCOMPARE(eventForward.coordinateTransform(), QMatrix4x4()); QCOMPARE(eventForward.coordinateAttribute(), QStringLiteral("default")); + QCOMPARE(eventForward.focus(), false); } void checkPropertyChanges() @@ -158,6 +159,25 @@ private Q_SLOTS: QCOMPARE(eventForward.coordinateAttribute(), newValue); QCOMPARE(spy.count(), 0); } + { + // WHEN + QSignalSpy spy(&eventForward, SIGNAL(focusChanged(bool))); + const bool newValue = true; + eventForward.setFocus(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(eventForward.focus(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + eventForward.setFocus(newValue); + + // THEN + QCOMPARE(eventForward.focus(), newValue); + QCOMPARE(spy.count(), 0); + } } void checkCreationData() @@ -173,6 +193,7 @@ private Q_SLOTS: eventForward.setForwardKeyboardEvents(true); eventForward.setCoordinateTransform(transform); eventForward.setCoordinateAttribute(QStringLiteral("position")); + eventForward.setFocus(true); // WHEN QVector creationChanges; @@ -196,6 +217,7 @@ private Q_SLOTS: QCOMPARE(eventForward.forwardKeyboardEvents(), cloneData.forwardKeyboardEvents); QCOMPARE(eventForward.coordinateTransform(), cloneData.coordinateTransform); QCOMPARE(eventForward.coordinateAttribute(), cloneData.coordinateAttribute); + QCOMPARE(eventForward.focus(), cloneData.focus); QCOMPARE(eventForward.id(), creationChangeData->subjectId()); QCOMPARE(eventForward.isEnabled(), true); QCOMPARE(eventForward.isEnabled(), creationChangeData->isNodeEnabled()); @@ -224,6 +246,7 @@ private Q_SLOTS: QCOMPARE(eventForward.forwardKeyboardEvents(), cloneData.forwardKeyboardEvents); QCOMPARE(eventForward.coordinateTransform(), cloneData.coordinateTransform); QCOMPARE(eventForward.coordinateAttribute(), cloneData.coordinateAttribute); + QCOMPARE(eventForward.focus(), cloneData.focus); QCOMPARE(eventForward.id(), creationChangeData->subjectId()); QCOMPARE(eventForward.isEnabled(), false); QCOMPARE(eventForward.isEnabled(), creationChangeData->isNodeEnabled()); @@ -399,6 +422,39 @@ private Q_SLOTS: } + void checkFocusUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::QEventForward eventForward; + arbiter.setArbiterOnNode(&eventForward); + + { + // WHEN + eventForward.setFocus(true); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "focus"); + QCOMPARE(change->value().toBool(), eventForward.focus()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + eventForward.setFocus(true); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + }; QTEST_MAIN(tst_QEventForward) -- cgit v1.2.3 From de0270437c18d37a2cad6f6705ce73e2f3a8f76f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Mon, 28 Nov 2016 15:32:23 +0200 Subject: Update eventForward unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id0898fde106ac9a4407033867a13e46f7ce4b86e Reviewed-by: Tomi Korpipää Reviewed-by: Sean Harmer --- .../auto/render/eventforward/tst_eventforward.cpp | 100 +++++++++++++--- .../render/qeventforward/tst_qeventforward.cpp | 128 ++++++++++++++++++++- 2 files changed, 207 insertions(+), 21 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/eventforward/tst_eventforward.cpp b/tests/auto/render/eventforward/tst_eventforward.cpp index 5352853a1..de86b8ef3 100644 --- a/tests/auto/render/eventforward/tst_eventforward.cpp +++ b/tests/auto/render/eventforward/tst_eventforward.cpp @@ -28,11 +28,15 @@ #include #include -#include -#include +#include +#include +#include +#include #include #include "qbackendnodetester.h" #include "testrenderer.h" +#include "testpostmanarbiter.h" + class tst_EventForward : public Qt3DCore::QBackendNodeTester { @@ -48,7 +52,6 @@ private Q_SLOTS: // THEN QCOMPARE(backendEventForward.isEnabled(), false); QVERIFY(backendEventForward.peerId().isNull()); - QCOMPARE(backendEventForward.target(), nullptr); QCOMPARE(backendEventForward.coordinateAttribute(), QStringLiteral("")); QCOMPARE(backendEventForward.coordinateTransform(), QMatrix4x4()); QCOMPARE(backendEventForward.forwardMouseEvents(), false); @@ -66,7 +69,6 @@ private Q_SLOTS: // WHEN backendEventForward.setEnabled(true); - backendEventForward.setTarget(obj.data()); backendEventForward.setCoordinateAttribute(QStringLiteral("default")); backendEventForward.setCoordinateTransform(transform); backendEventForward.setForwardMouseEvents(true); @@ -77,7 +79,6 @@ private Q_SLOTS: // THEN QCOMPARE(backendEventForward.isEnabled(), false); - QCOMPARE(backendEventForward.target(), nullptr); QCOMPARE(backendEventForward.coordinateAttribute(), QStringLiteral("")); QCOMPARE(backendEventForward.coordinateTransform(), QMatrix4x4()); QCOMPARE(backendEventForward.forwardMouseEvents(), false); @@ -98,7 +99,6 @@ private Q_SLOTS: // THEN QCOMPARE(backendEventForward.isEnabled(), true); QCOMPARE(backendEventForward.peerId(), eventForward.id()); - QCOMPARE(backendEventForward.target(), nullptr); QCOMPARE(backendEventForward.coordinateAttribute(), QStringLiteral("default")); QCOMPARE(backendEventForward.coordinateTransform(), QMatrix4x4()); QCOMPARE(backendEventForward.forwardMouseEvents(), true); @@ -137,18 +137,6 @@ private Q_SLOTS: // THEN QCOMPARE(backendEventForward.isEnabled(), newValue); } - { - // WHEN - QScopedPointer obj(new Qt3DRender::QEventForward()); - Qt3DRender::QEventForward * newValue = obj.data(); - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("target"); - change->setValue(QVariant::fromValue(newValue)); - backendEventForward.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendEventForward.target(), newValue); - } { // WHEN const QString newValue = QStringLiteral("position"); @@ -206,7 +194,83 @@ private Q_SLOTS: QCOMPARE(backendEventForward.focus(), newValue); } } + void checkEventForwarding() + { + Qt3DRender::Render::EventForward backendEventForward; + TestRenderer renderer; + TestArbiter arbiter; + backendEventForward.setRenderer(&renderer); + Qt3DCore::QBackendNodePrivate::get(&backendEventForward)->setArbiter(&arbiter); + + { + // WHEN + const QPointF localPos; + QMouseEvent event = QMouseEvent(QEvent::MouseButtonPress, localPos, + Qt::LeftButton, Qt::LeftButton, 0); + + const QVector4D coordinate; + backendEventForward.forward(event, coordinate); + QCoreApplication::processEvents(); + + // THEN + QVERIFY(arbiter.events.size() == 1); + Qt3DCore::QPropertyUpdatedChangePtr change + = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "events"); + + Qt3DRender::PostEventsToFrontendPtr postedEvents + = change->value().value(); + QVERIFY(postedEvents->events().size() == 1); + + QEvent *receivedEvent = postedEvents->events().first(); + QCOMPARE(receivedEvent->type(), QEvent::MouseButtonPress); + + QMouseEvent *me = static_cast(receivedEvent); + QCOMPARE(me->localPos(), localPos); + QCOMPARE(me->button(), Qt::LeftButton); + QCOMPARE(me->buttons(), Qt::LeftButton); + QCOMPARE(me->modifiers(), 0); + + arbiter.events.clear(); + } + + { + // WHEN + QKeyEvent event1 = QKeyEvent(QEvent::KeyPress, 48, 0); + QKeyEvent event2 = QKeyEvent(QEvent::KeyRelease, 48, 0); + QList eventList; + eventList.push_back(event1); + eventList.push_back(event2); + backendEventForward.forward(eventList); + QCoreApplication::processEvents(); + + // THEN + QVERIFY(arbiter.events.size() == 1); + Qt3DCore::QPropertyUpdatedChangePtr change + = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "events"); + + Qt3DRender::PostEventsToFrontendPtr postedEvents + = change->value().value(); + QVERIFY(postedEvents->events().size() == 2); + + QEvent *receivedEvent1 = postedEvents->events().first(); + QCOMPARE(receivedEvent1->type(), QEvent::KeyPress); + + QEvent *receivedEvent2 = postedEvents->events().at(1); + QCOMPARE(receivedEvent2->type(), QEvent::KeyRelease); + + QKeyEvent *ke1 = static_cast(receivedEvent1); + QKeyEvent *ke2 = static_cast(receivedEvent2); + QCOMPARE(ke1->key(), 48); + QCOMPARE(ke1->modifiers(), 0); + QCOMPARE(ke2->key(), 48); + QCOMPARE(ke2->modifiers(), 0); + + arbiter.events.clear(); + } + } }; QTEST_MAIN(tst_EventForward) diff --git a/tests/auto/render/qeventforward/tst_qeventforward.cpp b/tests/auto/render/qeventforward/tst_qeventforward.cpp index aa525d4a2..eeca5b3ea 100644 --- a/tests/auto/render/qeventforward/tst_qeventforward.cpp +++ b/tests/auto/render/qeventforward/tst_qeventforward.cpp @@ -29,14 +29,73 @@ #include #include #include -#include +#include #include #include #include -#include +#include +#include #include #include "testpostmanarbiter.h" + +class EventReceiver : public QObject +{ +public: + EventReceiver() + : QObject() + { + + } + + ~EventReceiver() + { + + } + + int eventCount() + { + return m_events.size(); + } + + QEvent *eventAt(int index) const + { + return m_events.at(index); + } + bool event(QEvent *event) Q_DECL_OVERRIDE + { + m_events.push_back(event); + return true; + } + + void clearEvents() + { + m_events.clear(); + } + +private: + QVector m_events; +}; + +class TestEventForward : public Qt3DRender::QEventForward +{ + Q_OBJECT +public: + TestEventForward(Qt3DCore::QNode *parent = nullptr) + : Qt3DRender::QEventForward(parent) + {} + + void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) Q_DECL_FINAL + { + Qt3DRender::QEventForward::sceneChangeEvent(change); + } + +private: + friend class tst_QEventForward; + +}; + + class tst_QEventForward : public QObject { Q_OBJECT @@ -452,9 +511,72 @@ private Q_SLOTS: // THEN QCOMPARE(arbiter.events.size(), 0); } - } + void checkReceiveEvents() + { + EventReceiver receiver; + TestEventForward eventForward; + eventForward.setTarget(&receiver); + eventForward.setForwardKeyboardEvents(true); + eventForward.setForwardMouseEvents(true); + + { + // WHEN + const QPointF local = QPointF(); + QMouseEvent* mouseEvent + = new QMouseEvent(QEvent::MouseButtonPress, local, local, local, + Qt::LeftButton,0,0, Qt::MouseEventSynthesizedByApplication); + Qt3DRender::PostEventsToFrontendPtr events + = Qt3DRender::PostEventsToFrontendPtr::create(mouseEvent); + + auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); + e->setPropertyName("events"); + e->setValue(QVariant::fromValue(events)); + + eventForward.sceneChangeEvent(e); + + // THEN + QVERIFY(receiver.eventCount() == 1); + QEvent *event = receiver.eventAt(0); + QCOMPARE(event->type(), QEvent::MouseButtonPress); + + QMouseEvent *me = static_cast(receiver.eventAt(0)); + QCOMPARE(me->localPos(), local); + QCOMPARE(me->button(), Qt::LeftButton); + + receiver.clearEvents(); + } + + { + // WHEN + QKeyEvent *event1 = new QKeyEvent(QEvent::KeyPress, 48, 0); + QKeyEvent *event2 = new QKeyEvent(QEvent::KeyRelease, 48, 0); + QVector eventList; + eventList.push_back(event1); + eventList.push_back(event2); + Qt3DRender::PostEventsToFrontendPtr events + = Qt3DRender::PostEventsToFrontendPtr::create(eventList); + + auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); + e->setPropertyName("events"); + e->setValue(QVariant::fromValue(events)); + + eventForward.sceneChangeEvent(e); + + // THEN + QVERIFY(receiver.eventCount() == 2); + QEvent *event = receiver.eventAt(0); + QCOMPARE(event->type(), QEvent::KeyPress); + QCOMPARE(static_cast(event)->key(), 48); + + event = receiver.eventAt(1); + QCOMPARE(event->type(), QEvent::KeyRelease); + QCOMPARE(static_cast(event)->key(), 48); + } + } }; QTEST_MAIN(tst_QEventForward) -- cgit v1.2.3 From 2f44f4ecb3b0c9eb3f00c9a08e30ba7dd11785ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Mon, 14 Nov 2016 11:33:14 +0200 Subject: Rename and update qrenderqmltotexture unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ib80c7ade344a83c2ee900f87f69a8f7c4bf8cc2e Reviewed-by: Tomi Korpipää Reviewed-by: Sean Harmer --- .../qrenderqmltotexture/qrenderqmltotexture.pro | 11 - .../tst_qrenderqmltotexture.cpp | 284 ------------------ tests/auto/render/qscene2d/qscene2d.pro | 12 + tests/auto/render/qscene2d/tst_qscene2d.cpp | 316 +++++++++++++++++++++ tests/auto/render/render.pro | 3 +- 5 files changed, 330 insertions(+), 296 deletions(-) delete mode 100644 tests/auto/render/qrenderqmltotexture/qrenderqmltotexture.pro delete mode 100644 tests/auto/render/qrenderqmltotexture/tst_qrenderqmltotexture.cpp create mode 100644 tests/auto/render/qscene2d/qscene2d.pro create mode 100644 tests/auto/render/qscene2d/tst_qscene2d.cpp (limited to 'tests/auto') diff --git a/tests/auto/render/qrenderqmltotexture/qrenderqmltotexture.pro b/tests/auto/render/qrenderqmltotexture/qrenderqmltotexture.pro deleted file mode 100644 index 8b2840929..000000000 --- a/tests/auto/render/qrenderqmltotexture/qrenderqmltotexture.pro +++ /dev/null @@ -1,11 +0,0 @@ -TEMPLATE = app - -TARGET = qrenderqmltotexture - -QT += 3dcore 3dcore-private 3drender 3drender-private testlib - -CONFIG += testcase - -SOURCES += tst_qrenderqmltotexture.cpp - -include(../commons/commons.pri) diff --git a/tests/auto/render/qrenderqmltotexture/tst_qrenderqmltotexture.cpp b/tests/auto/render/qrenderqmltotexture/tst_qrenderqmltotexture.cpp deleted file mode 100644 index b337306be..000000000 --- a/tests/auto/render/qrenderqmltotexture/tst_qrenderqmltotexture.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include "testpostmanarbiter.h" - -class tst_QRenderQmlToTexture : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - - void checkDefaultConstruction() - { - // GIVEN - Qt3DRender::QRenderQmlToTexture renderQmlToTexture; - - // THEN - QCOMPARE(renderQmlToTexture.texture(), nullptr); - QCOMPARE(renderQmlToTexture.source(), QUrl(QStringLiteral(""))); - QCOMPARE(renderQmlToTexture.renderOnce(), false); - QCOMPARE(renderQmlToTexture.loaded(), false); - } - - void checkPropertyChanges() - { - // GIVEN - Qt3DRender::QRenderQmlToTexture renderQmlToTexture; - QScopedPointer texture(new Qt3DRender::QTexture2D()); - - { - // WHEN - QSignalSpy spy(&renderQmlToTexture, SIGNAL(textureChanged(Qt3DRender::QAbstractTexture *))); - Qt3DRender::QAbstractTexture * newValue = texture.data(); - renderQmlToTexture.setTexture(newValue); - - // THEN - QVERIFY(spy.isValid()); - QCOMPARE(renderQmlToTexture.texture(), newValue); - QCOMPARE(spy.count(), 1); - - // WHEN - spy.clear(); - renderQmlToTexture.setTexture(newValue); - - // THEN - QCOMPARE(renderQmlToTexture.texture(), newValue); - QCOMPARE(spy.count(), 0); - } - { - // WHEN - QSignalSpy spy(&renderQmlToTexture, SIGNAL(sourceChanged(QUrl))); - const QUrl newValue = QUrl(QStringLiteral("qrc://source.qml")); - renderQmlToTexture.setSource(newValue); - - // THEN - QVERIFY(spy.isValid()); - QCOMPARE(renderQmlToTexture.source(), newValue); - QCOMPARE(spy.count(), 1); - - // WHEN - spy.clear(); - renderQmlToTexture.setSource(newValue); - - // THEN - QCOMPARE(renderQmlToTexture.source(), newValue); - QCOMPARE(spy.count(), 0); - } - { - // WHEN - QSignalSpy spy(&renderQmlToTexture, SIGNAL(renderOnceChanged(bool))); - const bool newValue = true; - renderQmlToTexture.setRenderOnce(newValue); - - // THEN - QVERIFY(spy.isValid()); - QCOMPARE(renderQmlToTexture.renderOnce(), newValue); - QCOMPARE(spy.count(), 1); - - // WHEN - spy.clear(); - renderQmlToTexture.setRenderOnce(newValue); - - // THEN - QCOMPARE(renderQmlToTexture.renderOnce(), newValue); - QCOMPARE(spy.count(), 0); - } - } - - void checkCreationData() - { - // GIVEN - Qt3DRender::QRenderQmlToTexture renderQmlToTexture; - QScopedPointer texture(new Qt3DRender::QTexture2D()); - - renderQmlToTexture.setTexture(texture.data()); - renderQmlToTexture.setSource(QUrl(QStringLiteral("qrc://source.qml"))); - renderQmlToTexture.setRenderOnce(true); - - // WHEN - QVector creationChanges; - - { - Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&renderQmlToTexture); - creationChanges = creationChangeGenerator.creationChanges(); - } - - // THEN - { - QCOMPARE(creationChanges.size(), 1); - - const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); - const Qt3DRender::QRenderQmlToTextureData cloneData = creationChangeData->data; - - QCOMPARE(renderQmlToTexture.texture()->id(), cloneData.textureId); - QCOMPARE(renderQmlToTexture.renderOnce(), cloneData.renderOnce); - QCOMPARE(renderQmlToTexture.id(), creationChangeData->subjectId()); - QCOMPARE(renderQmlToTexture.isEnabled(), true); - QCOMPARE(renderQmlToTexture.isEnabled(), creationChangeData->isNodeEnabled()); - QCOMPARE(renderQmlToTexture.metaObject(), creationChangeData->metaObject()); - } - - // WHEN - renderQmlToTexture.setEnabled(false); - - { - Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&renderQmlToTexture); - creationChanges = creationChangeGenerator.creationChanges(); - } - - // THEN - { - QCOMPARE(creationChanges.size(), 1); - - const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); - const Qt3DRender::QRenderQmlToTextureData cloneData = creationChangeData->data; - - QCOMPARE(renderQmlToTexture.texture()->id(), cloneData.textureId); - QCOMPARE(renderQmlToTexture.renderOnce(), cloneData.renderOnce); - QCOMPARE(renderQmlToTexture.id(), creationChangeData->subjectId()); - QCOMPARE(renderQmlToTexture.isEnabled(), false); - QCOMPARE(renderQmlToTexture.isEnabled(), creationChangeData->isNodeEnabled()); - QCOMPARE(renderQmlToTexture.metaObject(), creationChangeData->metaObject()); - } - } - - void checkTextureUpdate() - { - // GIVEN - TestArbiter arbiter; - Qt3DRender::QRenderQmlToTexture renderQmlToTexture; - arbiter.setArbiterOnNode(&renderQmlToTexture); - QScopedPointer texture(new Qt3DRender::QTexture2D()); - - { - // WHEN - renderQmlToTexture.setTexture(texture.data()); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "texture"); - QCOMPARE(change->value().value(), renderQmlToTexture.texture()); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - - arbiter.events.clear(); - } - - { - // WHEN - renderQmlToTexture.setTexture(texture.data()); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - } - - } - - void checkSourceUpdate() - { - // GIVEN - TestArbiter arbiter; - Qt3DRender::QRenderQmlToTexture renderQmlToTexture; - arbiter.setArbiterOnNode(&renderQmlToTexture); - - { - // WHEN - renderQmlToTexture.setSource(QUrl(QStringLiteral("qrc://source.qml"))); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "source"); - QCOMPARE(change->value().value(), renderQmlToTexture.source()); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - - arbiter.events.clear(); - } - - { - // WHEN - renderQmlToTexture.setSource(QUrl(QStringLiteral("qrc://source.qml"))); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - } - - } - - void checkRenderOnceUpdate() - { - // GIVEN - TestArbiter arbiter; - Qt3DRender::QRenderQmlToTexture renderQmlToTexture; - arbiter.setArbiterOnNode(&renderQmlToTexture); - - { - // WHEN - renderQmlToTexture.setRenderOnce(true); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "renderOnce"); - QCOMPARE(change->value().value(), renderQmlToTexture.renderOnce()); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - - arbiter.events.clear(); - } - - { - // WHEN - renderQmlToTexture.setRenderOnce(true); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - } - - } - -}; - -QTEST_MAIN(tst_QRenderQmlToTexture) - -#include "tst_qrenderqmltotexture.moc" diff --git a/tests/auto/render/qscene2d/qscene2d.pro b/tests/auto/render/qscene2d/qscene2d.pro new file mode 100644 index 000000000..b7458d1c2 --- /dev/null +++ b/tests/auto/render/qscene2d/qscene2d.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = qscene2d + +QT += 3dcore 3dcore-private 3drender 3drender-private testlib 3dquickrender 3dquickrender-private + +CONFIG += testcase + +SOURCES += tst_qscene2d.cpp + +include(../../core/common/common.pri) +include(../commons/commons.pri) diff --git a/tests/auto/render/qscene2d/tst_qscene2d.cpp b/tests/auto/render/qscene2d/tst_qscene2d.cpp new file mode 100644 index 000000000..8d27945e4 --- /dev/null +++ b/tests/auto/render/qscene2d/tst_qscene2d.cpp @@ -0,0 +1,316 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include "testpostmanarbiter.h" + +using namespace Qt3DRender::Quick; + +class tst_QScene2D : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void initTestCase() + { + qRegisterMetaType( + "QScene2D::RenderPolicy"); + } + + void checkDefaultConstruction() + { + // GIVEN + Qt3DRender::Quick::QScene2D scene2d; + + // THEN + QCOMPARE(scene2d.output(), nullptr); + QCOMPARE(scene2d.source(), QUrl(QStringLiteral(""))); + QCOMPARE(scene2d.renderPolicy(), QScene2D::Continuous); + QCOMPARE(scene2d.loaded(), false); + QCOMPARE(scene2d.item(), nullptr); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DRender::Quick::QScene2D scene2d; + QScopedPointer output(new Qt3DRender::QRenderTargetOutput()); + QScopedPointer item(new QQuickItem()); + + { + // WHEN + QSignalSpy spy(&scene2d, SIGNAL(outputChanged(Qt3DRender::QRenderTargetOutput*))); + Qt3DRender::QRenderTargetOutput *newValue = output.data(); + scene2d.setOutput(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(scene2d.output(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + scene2d.setOutput(newValue); + + // THEN + QCOMPARE(scene2d.output(), newValue); + QCOMPARE(spy.count(), 0); + } + { + // WHEN + QSignalSpy spy(&scene2d, SIGNAL(sourceChanged(QUrl))); + const QUrl newValue = QUrl(QStringLiteral("qrc://source.qml")); + scene2d.setSource(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(scene2d.source(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + scene2d.setSource(newValue); + + // THEN + QCOMPARE(scene2d.source(), newValue); + QCOMPARE(spy.count(), 0); + } + { + // WHEN + QSignalSpy spy(&scene2d, SIGNAL(renderPolicyChanged(QScene2D::RenderPolicy))); + const QScene2D::RenderPolicy newValue = QScene2D::SingleShot; + scene2d.setRenderPolicy(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(scene2d.renderPolicy(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + scene2d.setRenderPolicy(newValue); + + // THEN + QCOMPARE(scene2d.renderPolicy(), newValue); + QCOMPARE(spy.count(), 0); + } + { + // WHEN + QSignalSpy spy(&scene2d, SIGNAL(itemChanged(QQuickItem*))); + QQuickItem *newValue = item.data(); + scene2d.setItem(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(scene2d.item(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + scene2d.setItem(newValue); + + // THEN + QCOMPARE(scene2d.item(), newValue); + QCOMPARE(spy.count(), 0); + } + } + + void checkCreationData() + { + // GIVEN + Qt3DRender::Quick::QScene2D scene2d; + QScopedPointer output(new Qt3DRender::QRenderTargetOutput()); + + scene2d.setOutput(output.data()); + scene2d.setSource(QUrl(QStringLiteral("qrc://source.qml"))); + scene2d.setRenderPolicy(QScene2D::SingleShot); + + // WHEN + QVector creationChanges; + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&scene2d); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 1); + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DRender::Quick::QScene2DData cloneData = creationChangeData->data; + + QCOMPARE(scene2d.output()->id(), cloneData.output); + QCOMPARE(scene2d.renderPolicy(), cloneData.renderPolicy); + QCOMPARE(scene2d.id(), creationChangeData->subjectId()); + QCOMPARE(scene2d.isEnabled(), true); + QCOMPARE(scene2d.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(scene2d.metaObject(), creationChangeData->metaObject()); + } + + // WHEN + scene2d.setEnabled(false); + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&scene2d); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 1); + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DRender::Quick::QScene2DData cloneData = creationChangeData->data; + + QCOMPARE(scene2d.output()->id(), cloneData.output); + QCOMPARE(scene2d.renderPolicy(), cloneData.renderPolicy); + QCOMPARE(scene2d.id(), creationChangeData->subjectId()); + QCOMPARE(scene2d.isEnabled(), false); + QCOMPARE(scene2d.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(scene2d.metaObject(), creationChangeData->metaObject()); + } + } + + void checkOutputUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::Quick::QScene2D scene2d; + arbiter.setArbiterOnNode(&scene2d); + QScopedPointer output(new Qt3DRender::QRenderTargetOutput()); + + { + // WHEN + scene2d.setOutput(output.data()); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "output"); + QCOMPARE(change->value().value(), scene2d.output()->id()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + scene2d.setOutput(output.data()); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + + void checkSourceUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::Quick::QScene2D scene2d; + arbiter.setArbiterOnNode(&scene2d); + + { + // WHEN + scene2d.setSource(QUrl(QStringLiteral("qrc://source.qml"))); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "source"); + QCOMPARE(change->value().value(), scene2d.source()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + scene2d.setSource(QUrl(QStringLiteral("qrc://source.qml"))); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + + void checkRenderPolicyUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::Quick::QScene2D scene2d; + arbiter.setArbiterOnNode(&scene2d); + + { + // WHEN + scene2d.setRenderPolicy(QScene2D::SingleShot); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "renderPolicy"); + QCOMPARE(change->value().value(), + scene2d.renderPolicy()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + scene2d.setRenderPolicy(QScene2D::SingleShot); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + +}; + +QTEST_MAIN(tst_QScene2D) + +#include "tst_qscene2d.moc" diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro index 34c07f7dc..c89299095 100644 --- a/tests/auto/render/render.pro +++ b/tests/auto/render/render.pro @@ -98,7 +98,8 @@ qtConfig(private_tests) { trianglevisitor \ qmemorybarrier \ qeventforward \ - eventforward + eventforward \ + qscene2d !macos: SUBDIRS += graphicshelpergl4 } -- cgit v1.2.3 From 3acea3a81c216c28aa0067e20b7ce5f17b4f5ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Mon, 14 Nov 2016 14:09:43 +0200 Subject: Rename and update renderqmltotexture unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I461db1324ca068a9f0f1ef2cf2c28bdeb2bee1b3 Reviewed-by: Tomi Korpipää Reviewed-by: Sean Harmer --- tests/auto/render/render.pro | 3 +- .../renderqmltotexture/renderqmltotexture.pro | 12 -- .../renderqmltotexture/tst_renderqmltotexture.cpp | 150 ------------------- tests/auto/render/scene2d/scene2d.pro | 12 ++ tests/auto/render/scene2d/tst_scene2d.cpp | 160 +++++++++++++++++++++ 5 files changed, 174 insertions(+), 163 deletions(-) delete mode 100644 tests/auto/render/renderqmltotexture/renderqmltotexture.pro delete mode 100644 tests/auto/render/renderqmltotexture/tst_renderqmltotexture.cpp create mode 100644 tests/auto/render/scene2d/scene2d.pro create mode 100644 tests/auto/render/scene2d/tst_scene2d.cpp (limited to 'tests/auto') diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro index c89299095..e03c07d41 100644 --- a/tests/auto/render/render.pro +++ b/tests/auto/render/render.pro @@ -99,7 +99,8 @@ qtConfig(private_tests) { qmemorybarrier \ qeventforward \ eventforward \ - qscene2d + qscene2d \ + scene2d !macos: SUBDIRS += graphicshelpergl4 } diff --git a/tests/auto/render/renderqmltotexture/renderqmltotexture.pro b/tests/auto/render/renderqmltotexture/renderqmltotexture.pro deleted file mode 100644 index 2c0f56391..000000000 --- a/tests/auto/render/renderqmltotexture/renderqmltotexture.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = app - -TARGET = tst_renderqmltotexture - -QT += 3dcore 3dcore-private 3drender 3drender-private testlib - -CONFIG += testcase - -SOURCES += tst_renderqmltotexture.cpp - -include(../../core/common/common.pri) -include(../commons/commons.pri) diff --git a/tests/auto/render/renderqmltotexture/tst_renderqmltotexture.cpp b/tests/auto/render/renderqmltotexture/tst_renderqmltotexture.cpp deleted file mode 100644 index b6148c514..000000000 --- a/tests/auto/render/renderqmltotexture/tst_renderqmltotexture.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** 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 -#include -#include -#include -#include -#include -#include "testrenderer.h" - -class tst_RenderQmlToTexture : public Qt3DCore::QBackendNodeTester -{ - Q_OBJECT - -private Q_SLOTS: - - void checkInitialState() - { - // GIVEN - Qt3DRender::Render::RenderQmlToTexture backendRenderQmlToTexture; - - // THEN - QCOMPARE(backendRenderQmlToTexture.isEnabled(), false); - QVERIFY(backendRenderQmlToTexture.peerId().isNull()); - QCOMPARE(backendRenderQmlToTexture.m_context, nullptr); - QCOMPARE(backendRenderQmlToTexture.m_graphicsContext, nullptr); - QCOMPARE(backendRenderQmlToTexture.m_renderThread, nullptr); - QCOMPARE(backendRenderQmlToTexture.m_textureId, Qt3DCore::QNodeId()); - QCOMPARE(backendRenderQmlToTexture.m_texture, nullptr); - QCOMPARE(backendRenderQmlToTexture.m_initialized, false); - QCOMPARE(backendRenderQmlToTexture.m_renderInitialized, false); - QCOMPARE(backendRenderQmlToTexture.m_renderOnce, false); - } - - void checkInitializeFromPeer() - { - // GIVEN - Qt3DRender::QRenderQmlToTexture renderQmlToTexture; - - { - // WHEN - Qt3DRender::Render::RenderQmlToTexture backendRenderQmlToTexture; - simulateInitialization(&renderQmlToTexture, &backendRenderQmlToTexture); - - // THEN - QCOMPARE(backendRenderQmlToTexture.isEnabled(), true); - QCOMPARE(backendRenderQmlToTexture.peerId(), renderQmlToTexture.id()); - QCOMPARE(backendRenderQmlToTexture.m_textureId, Qt3DCore::QNodeId()); - QCOMPARE(backendRenderQmlToTexture.m_sharedObject.data(), nullptr); - QCOMPARE(backendRenderQmlToTexture.m_renderOnce, false); - } - { - // WHEN - Qt3DRender::Render::RenderQmlToTexture backendRenderQmlToTexture; - renderQmlToTexture.setEnabled(false); - simulateInitialization(&renderQmlToTexture, &backendRenderQmlToTexture); - - // THEN - QCOMPARE(backendRenderQmlToTexture.peerId(), renderQmlToTexture.id()); - QCOMPARE(backendRenderQmlToTexture.isEnabled(), false); - } - } - - void checkSceneChangeEvents() - { - // GIVEN - Qt3DRender::Render::RenderQmlToTexture backendRenderQmlToTexture; - TestRenderer renderer; - QScopedPointer texture(new Qt3DRender::QTexture2D()); - backendRenderQmlToTexture.setRenderer(&renderer); - - { - // WHEN - const bool newValue = false; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("enabled"); - change->setValue(newValue); - backendRenderQmlToTexture.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendRenderQmlToTexture.isEnabled(), newValue); - } - { - // WHEN - const Qt3DCore::QNodeId newValue = texture.data()->id(); - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("textureId"); - change->setValue(QVariant::fromValue(newValue)); - backendRenderQmlToTexture.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendRenderQmlToTexture.m_textureId, newValue); - } - { - // WHEN - const QSharedPointer newValue - = QSharedPointer(new Qt3DRender::RenderQmlToTextureSharedObject(nullptr)); - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("sharedObject"); - change->setValue(QVariant::fromValue(newValue)); - backendRenderQmlToTexture.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendRenderQmlToTexture.m_sharedObject, newValue); - QCOMPARE(backendRenderQmlToTexture.m_sharedObject.data(), newValue.data()); - } - { - // WHEN - const bool newValue = true; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("renderOnce"); - change->setValue(QVariant::fromValue(newValue)); - backendRenderQmlToTexture.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendRenderQmlToTexture.m_renderOnce, newValue); - } - } - -}; - -QTEST_MAIN(tst_RenderQmlToTexture) - -#include "tst_renderqmltotexture.moc" diff --git a/tests/auto/render/scene2d/scene2d.pro b/tests/auto/render/scene2d/scene2d.pro new file mode 100644 index 000000000..8685b0b5b --- /dev/null +++ b/tests/auto/render/scene2d/scene2d.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_scene2d + +QT += 3dcore 3dcore-private 3drender 3drender-private testlib 3dquickrender 3dquickrender-private + +CONFIG += testcase + +SOURCES += tst_scene2d.cpp + +include(../../core/common/common.pri) +include(../commons/commons.pri) diff --git a/tests/auto/render/scene2d/tst_scene2d.cpp b/tests/auto/render/scene2d/tst_scene2d.cpp new file mode 100644 index 000000000..f07a35b19 --- /dev/null +++ b/tests/auto/render/scene2d/tst_scene2d.cpp @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** 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 +#include +#include +#include +#include +#include +#include "testrenderer.h" + +using namespace Qt3DRender::Quick; +using namespace Qt3DRender::Render::Quick; + +class tst_Scene2D : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + + void checkInitialState() + { + // GIVEN + Scene2D backendScene2d; + + // THEN + QCOMPARE(backendScene2d.isEnabled(), false); + QVERIFY(backendScene2d.peerId().isNull()); + QCOMPARE(backendScene2d.m_context, nullptr); + QCOMPARE(backendScene2d.m_shareContext, nullptr); + QCOMPARE(backendScene2d.m_renderThread, nullptr); + QCOMPARE(backendScene2d.m_outputId, Qt3DCore::QNodeId()); + QCOMPARE(backendScene2d.m_initialized, false); + QCOMPARE(backendScene2d.m_renderInitialized, false); + QCOMPARE(backendScene2d.m_renderPolicy, QScene2D::Continuous); + } + + void checkInitializeFromPeer() + { + // GIVEN + Qt3DRender::Quick::QScene2D frontend; + TestRenderer renderer; + + { + // WHEN + QScopedPointer backendScene2d(new Scene2D()); + backendScene2d->setRenderer(&renderer); + simulateInitialization(&frontend, backendScene2d.data()); + + // THEN + QCOMPARE(backendScene2d->isEnabled(), true); + QCOMPARE(backendScene2d->peerId(), frontend.id()); + QCOMPARE(backendScene2d->m_outputId, Qt3DCore::QNodeId()); + QVERIFY(backendScene2d->m_sharedObject.data() != nullptr); + QCOMPARE(backendScene2d->m_renderPolicy, QScene2D::Continuous); + backendScene2d->cleanup(); + } + { + // WHEN + QScopedPointer backendScene2d(new Scene2D()); + frontend.setEnabled(false); + backendScene2d->setRenderer(&renderer); + simulateInitialization(&frontend, backendScene2d.data()); + + // THEN + QCOMPARE(backendScene2d->peerId(), frontend.id()); + QCOMPARE(backendScene2d->isEnabled(), false); + backendScene2d->cleanup(); + } + } + + void checkSceneChangeEvents() + { + // GIVEN + QScopedPointer backendScene2d(new Scene2D()); + TestRenderer renderer; + QScopedPointer output(new Qt3DRender::QRenderTargetOutput()); + backendScene2d->setRenderer(&renderer); + + { + // WHEN + const bool newValue = false; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("enabled"); + change->setValue(newValue); + backendScene2d->sceneChangeEvent(change); + + // THEN + QCOMPARE(backendScene2d->isEnabled(), newValue); + } + { + // WHEN + const Qt3DCore::QNodeId newValue = output.data()->id(); + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("output"); + change->setValue(QVariant::fromValue(newValue)); + backendScene2d->sceneChangeEvent(change); + + // THEN + QCOMPARE(backendScene2d->m_outputId, newValue); + } + { + // WHEN + const QSharedPointer newValue + = QSharedPointer( + new Qt3DRender::Quick::Scene2DSharedObject(nullptr)); + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("sharedObject"); + change->setValue(QVariant::fromValue(newValue)); + backendScene2d->sceneChangeEvent(change); + + // THEN + QCOMPARE(backendScene2d->m_sharedObject, newValue); + QCOMPARE(backendScene2d->m_sharedObject.data(), newValue.data()); + } + { + // WHEN + const QScene2D::RenderPolicy newValue = QScene2D::SingleShot; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("renderPolicy"); + change->setValue(QVariant::fromValue(newValue)); + backendScene2d->sceneChangeEvent(change); + + // THEN + QCOMPARE(backendScene2d->m_renderPolicy, newValue); + } + + backendScene2d->cleanup(); + } + +}; + +QTEST_MAIN(tst_Scene2D) + +#include "tst_scene2d.moc" -- cgit v1.2.3 From 2f3cfb7f19911f29e6ea7c0528b26f9263d38121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Thu, 17 Nov 2016 09:44:15 +0200 Subject: Add unit tests for coordinate reader MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id2645f3ecf1d36b4b4fbbfd1457f45106ca608ed Reviewed-by: Tomi Korpipää Reviewed-by: Sean Harmer --- .../render/coordinatereader/coordinatereader.pro | 12 + .../coordinatereader/tst_coordinatereader.cpp | 491 +++++++++++++++++++++ tests/auto/render/render.pro | 3 +- 3 files changed, 505 insertions(+), 1 deletion(-) create mode 100644 tests/auto/render/coordinatereader/coordinatereader.pro create mode 100644 tests/auto/render/coordinatereader/tst_coordinatereader.cpp (limited to 'tests/auto') diff --git a/tests/auto/render/coordinatereader/coordinatereader.pro b/tests/auto/render/coordinatereader/coordinatereader.pro new file mode 100644 index 000000000..036898c2b --- /dev/null +++ b/tests/auto/render/coordinatereader/coordinatereader.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = coordinatereader + +QT += 3dcore 3dcore-private 3drender 3drender-private testlib + +CONFIG += testcase + +SOURCES += tst_coordinatereader.cpp + +include(../../core/common/common.pri) +include(../commons/commons.pri) diff --git a/tests/auto/render/coordinatereader/tst_coordinatereader.cpp b/tests/auto/render/coordinatereader/tst_coordinatereader.cpp new file mode 100644 index 000000000..7dfe3ceba --- /dev/null +++ b/tests/auto/render/coordinatereader/tst_coordinatereader.cpp @@ -0,0 +1,491 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "testrenderer.h" + +using namespace Qt3DRender::Render; + +class TestReader : public CoordinateReader +{ +public: + TestReader(NodeManagers *manager) + : CoordinateReader(manager) + { + + } + NodeManagers *manager() const + { + return m_manager; + } + + Attribute *attribute() const + { + return m_attribute; + } + + Buffer *buffer() const + { + return m_buffer; + } + + BufferInfo bufferInfo() const + { + return m_bufferInfo; + } + bool verifyCoordinate(uint index, QVector4D value) + { + return qFuzzyCompare(getCoordinate(index), value); + } +}; + +class tst_CoordinateReader : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + + void checkInitialize() + { + // WHEN + QScopedPointer nodeManagers(new NodeManagers()); + TestReader reader(nodeManagers.data()); + + // THEN + QCOMPARE(reader.manager(), nodeManagers.data()); + } + + void checkSetEmptyGeometry() + { + QScopedPointer nodeManagers(new NodeManagers()); + QScopedPointer geometryRenderer( + new Qt3DRender::QGeometryRenderer()); + TestReader reader(nodeManagers.data()); + TestRenderer renderer; + + GeometryRenderer *backendRenderer = nodeManagers->geometryRendererManager() + ->getOrCreateResource(geometryRenderer->id()); + backendRenderer->setRenderer(&renderer); + backendRenderer->setManager(nodeManagers->geometryRendererManager()); + simulateInitialization(geometryRenderer.data(), backendRenderer); + + // WHEN + bool ret = reader.setGeometry(backendRenderer, QString("")); + + // THEN + QCOMPARE(ret, false); + QCOMPARE(reader.attribute(), nullptr); + QCOMPARE(reader.buffer(), nullptr); + } + + void checkSetGeometry() + { + QScopedPointer nodeManagers(new NodeManagers()); + Qt3DRender::QGeometry *geometry = new Qt3DRender::QGeometry(); + QScopedPointer geometryRenderer( + new Qt3DRender::QGeometryRenderer()); + QScopedPointer positionAttribute(new Qt3DRender::QAttribute()); + QScopedPointer dataBuffer(new Qt3DRender::QBuffer()); + TestReader reader(nodeManagers.data()); + TestRenderer renderer; + + QByteArray data; + data.resize(sizeof(float) * 3 * 3 * 2); + float *dataPtr = reinterpret_cast(data.data()); + dataPtr[0] = 0; + dataPtr[1] = 0; + dataPtr[2] = 1.0f; + dataPtr[3] = 1.0f; + dataPtr[4] = 0; + dataPtr[5] = 0; + dataPtr[6] = 0; + dataPtr[7] = 1.0f; + dataPtr[8] = 0; + + dataPtr[9] = 0; + dataPtr[10] = 0; + dataPtr[11] = 1.0f; + dataPtr[12] = 1.0f; + dataPtr[13] = 0; + dataPtr[14] = 0; + dataPtr[15] = 0; + dataPtr[16] = 1.0f; + dataPtr[17] = 0; + dataBuffer->setData(data); + Buffer *backendBuffer = nodeManagers->bufferManager()->getOrCreateResource(dataBuffer->id()); + backendBuffer->setRenderer(&renderer); + backendBuffer->setManager(nodeManagers->bufferManager()); + simulateInitialization(dataBuffer.data(), backendBuffer); + + positionAttribute->setBuffer(dataBuffer.data()); + positionAttribute->setName(Qt3DRender::QAttribute::defaultPositionAttributeName()); + positionAttribute->setVertexBaseType(Qt3DRender::QAttribute::Float); + positionAttribute->setVertexSize(3); + positionAttribute->setCount(6); + positionAttribute->setByteStride(3 * 4); + positionAttribute->setByteOffset(0); + positionAttribute->setAttributeType(Qt3DRender::QAttribute::VertexAttribute); + geometry->addAttribute(positionAttribute.data()); + + geometryRenderer->setGeometry(geometry); + geometryRenderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles); + + Attribute *backendAttribute = nodeManagers->attributeManager() + ->getOrCreateResource(positionAttribute->id()); + backendAttribute->setRenderer(&renderer); + simulateInitialization(positionAttribute.data(), backendAttribute); + + Geometry *backendGeometry = nodeManagers->geometryManager() + ->getOrCreateResource(geometry->id()); + backendGeometry->setRenderer(&renderer); + simulateInitialization(geometry, backendGeometry); + + GeometryRenderer *backendRenderer = nodeManagers->geometryRendererManager() + ->getOrCreateResource(geometryRenderer->id()); + backendRenderer->setRenderer(&renderer); + backendRenderer->setManager(nodeManagers->geometryRendererManager()); + simulateInitialization(geometryRenderer.data(), backendRenderer); + + // WHEN + bool ret = reader.setGeometry(backendRenderer, + Qt3DRender::QAttribute::defaultPositionAttributeName()); + + // THEN + QCOMPARE(ret, true); + QCOMPARE(reader.attribute(), backendAttribute); + QCOMPARE(reader.buffer(), backendBuffer); + QCOMPARE(reader.bufferInfo().type, Qt3DRender::QAttribute::Float); + QCOMPARE(reader.bufferInfo().dataSize, 3u); + QCOMPARE(reader.bufferInfo().count, 6u); + QCOMPARE(reader.bufferInfo().byteStride, 12u); + QCOMPARE(reader.bufferInfo().byteOffset, 0u); + } + + void testReadCoordinate() + { + QScopedPointer nodeManagers(new NodeManagers()); + Qt3DRender::QGeometry *geometry = new Qt3DRender::QGeometry(); + QScopedPointer geometryRenderer( + new Qt3DRender::QGeometryRenderer()); + QScopedPointer positionAttribute(new Qt3DRender::QAttribute()); + QScopedPointer dataBuffer(new Qt3DRender::QBuffer()); + TestReader reader(nodeManagers.data()); + TestRenderer renderer; + + QByteArray data; + data.resize(sizeof(float) * 3 * 3 * 2); + float *dataPtr = reinterpret_cast(data.data()); + dataPtr[0] = 0; + dataPtr[1] = 0; + dataPtr[2] = 1.0f; + dataPtr[3] = 1.0f; + dataPtr[4] = 0; + dataPtr[5] = 0; + dataPtr[6] = 0; + dataPtr[7] = 1.0f; + dataPtr[8] = 0; + + dataPtr[9] = 0; + dataPtr[10] = 0; + dataPtr[11] = 1.0f; + dataPtr[12] = 1.0f; + dataPtr[13] = 0; + dataPtr[14] = 0; + dataPtr[15] = 0; + dataPtr[16] = 1.0f; + dataPtr[17] = 0; + dataBuffer->setData(data); + Buffer *backendBuffer = nodeManagers->bufferManager()->getOrCreateResource(dataBuffer->id()); + backendBuffer->setRenderer(&renderer); + backendBuffer->setManager(nodeManagers->bufferManager()); + simulateInitialization(dataBuffer.data(), backendBuffer); + + positionAttribute->setBuffer(dataBuffer.data()); + positionAttribute->setName(Qt3DRender::QAttribute::defaultPositionAttributeName()); + positionAttribute->setVertexBaseType(Qt3DRender::QAttribute::Float); + positionAttribute->setVertexSize(3); + positionAttribute->setCount(6); + positionAttribute->setByteStride(3 * 4); + positionAttribute->setByteOffset(0); + positionAttribute->setAttributeType(Qt3DRender::QAttribute::VertexAttribute); + geometry->addAttribute(positionAttribute.data()); + + geometryRenderer->setGeometry(geometry); + geometryRenderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles); + + Attribute *backendAttribute = nodeManagers->attributeManager() + ->getOrCreateResource(positionAttribute->id()); + backendAttribute->setRenderer(&renderer); + simulateInitialization(positionAttribute.data(), backendAttribute); + + Geometry *backendGeometry = nodeManagers->geometryManager() + ->getOrCreateResource(geometry->id()); + backendGeometry->setRenderer(&renderer); + simulateInitialization(geometry, backendGeometry); + + GeometryRenderer *backendRenderer = nodeManagers->geometryRendererManager() + ->getOrCreateResource(geometryRenderer->id()); + backendRenderer->setRenderer(&renderer); + backendRenderer->setManager(nodeManagers->geometryRendererManager()); + simulateInitialization(geometryRenderer.data(), backendRenderer); + + // WHEN + bool ret = reader.setGeometry(backendRenderer, + Qt3DRender::QAttribute::defaultPositionAttributeName()); + + // THEN + QCOMPARE(ret, true); + + QVERIFY(reader.verifyCoordinate(0, QVector4D(0, 0, 1, 1))); + QVERIFY(reader.verifyCoordinate(1, QVector4D(1, 0, 0, 1))); + QVERIFY(reader.verifyCoordinate(2, QVector4D(0, 1, 0, 1))); + QVERIFY(reader.verifyCoordinate(3, QVector4D(0, 0, 1, 1))); + QVERIFY(reader.verifyCoordinate(4, QVector4D(1, 0, 0, 1))); + QVERIFY(reader.verifyCoordinate(5, QVector4D(0, 1, 0, 1))); + } + + void testReadCoordinateVec4() + { + QScopedPointer nodeManagers(new NodeManagers()); + Qt3DRender::QGeometry *geometry = new Qt3DRender::QGeometry(); + QScopedPointer geometryRenderer( + new Qt3DRender::QGeometryRenderer()); + QScopedPointer positionAttribute(new Qt3DRender::QAttribute()); + QScopedPointer dataBuffer(new Qt3DRender::QBuffer()); + TestReader reader(nodeManagers.data()); + TestRenderer renderer; + + QByteArray data; + data.resize(sizeof(float) * 4 * 3 * 2); + float *dataPtr = reinterpret_cast(data.data()); + dataPtr[0] = 0; + dataPtr[1] = 0; + dataPtr[2] = 1.0f; + dataPtr[3] = 1.0f; + + dataPtr[4] = 1.0f; + dataPtr[5] = 0; + dataPtr[6] = 0; + dataPtr[7] = 1.0f; + + dataPtr[8] = 0; + dataPtr[9] = 1.0f; + dataPtr[10] = 0; + dataPtr[11] = 0; + + dataPtr[12] = 0; + dataPtr[13] = 0; + dataPtr[14] = 1.0f; + dataPtr[15] = 0; + + dataPtr[16] = 1.0f; + dataPtr[17] = 0; + dataPtr[18] = 0; + dataPtr[19] = 0; + + dataPtr[20] = 0; + dataPtr[21] = 1.0f; + dataPtr[22] = 0; + dataPtr[23] = 1.0f; + + dataBuffer->setData(data); + Buffer *backendBuffer = nodeManagers->bufferManager()->getOrCreateResource(dataBuffer->id()); + backendBuffer->setRenderer(&renderer); + backendBuffer->setManager(nodeManagers->bufferManager()); + simulateInitialization(dataBuffer.data(), backendBuffer); + + positionAttribute->setBuffer(dataBuffer.data()); + positionAttribute->setName(Qt3DRender::QAttribute::defaultPositionAttributeName()); + positionAttribute->setVertexBaseType(Qt3DRender::QAttribute::Float); + positionAttribute->setVertexSize(4); + positionAttribute->setCount(6); + positionAttribute->setByteStride(4 * 4); + positionAttribute->setByteOffset(0); + positionAttribute->setAttributeType(Qt3DRender::QAttribute::VertexAttribute); + geometry->addAttribute(positionAttribute.data()); + + geometryRenderer->setGeometry(geometry); + geometryRenderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles); + + Attribute *backendAttribute = nodeManagers->attributeManager() + ->getOrCreateResource(positionAttribute->id()); + backendAttribute->setRenderer(&renderer); + simulateInitialization(positionAttribute.data(), backendAttribute); + + Geometry *backendGeometry = nodeManagers->geometryManager() + ->getOrCreateResource(geometry->id()); + backendGeometry->setRenderer(&renderer); + simulateInitialization(geometry, backendGeometry); + + GeometryRenderer *backendRenderer = nodeManagers->geometryRendererManager() + ->getOrCreateResource(geometryRenderer->id()); + backendRenderer->setRenderer(&renderer); + backendRenderer->setManager(nodeManagers->geometryRendererManager()); + simulateInitialization(geometryRenderer.data(), backendRenderer); + + // WHEN + bool ret = reader.setGeometry(backendRenderer, + Qt3DRender::QAttribute::defaultPositionAttributeName()); + + // THEN + QCOMPARE(ret, true); + + QVERIFY(reader.verifyCoordinate(0, QVector4D(0, 0, 1, 1))); + QVERIFY(reader.verifyCoordinate(1, QVector4D(1, 0, 0, 1))); + QVERIFY(reader.verifyCoordinate(2, QVector4D(0, 1, 0, 0))); + QVERIFY(reader.verifyCoordinate(3, QVector4D(0, 0, 1, 0))); + QVERIFY(reader.verifyCoordinate(4, QVector4D(1, 0, 0, 0))); + QVERIFY(reader.verifyCoordinate(5, QVector4D(0, 1, 0, 1))); + } + + void testReadCoordinateFromAttribute() + { + QScopedPointer nodeManagers(new NodeManagers()); + Qt3DRender::QGeometry *geometry = new Qt3DRender::QGeometry(); + QScopedPointer geometryRenderer( + new Qt3DRender::QGeometryRenderer()); + QScopedPointer positionAttribute(new Qt3DRender::QAttribute()); + QScopedPointer texcoordAttribute(new Qt3DRender::QAttribute()); + QScopedPointer dataBuffer(new Qt3DRender::QBuffer()); + TestReader reader(nodeManagers.data()); + TestRenderer renderer; + + QByteArray data; + data.resize(sizeof(float) * 3 * 3 * 2); + float *dataPtr = reinterpret_cast(data.data()); + dataPtr[0] = 0; + dataPtr[1] = 0; + dataPtr[2] = 1.0f; + + dataPtr[3] = 1.0f; + dataPtr[4] = 0; + dataPtr[5] = 0; + + dataPtr[6] = 0; + dataPtr[7] = 1.0f; + dataPtr[8] = 0; + + dataPtr[9] = 0; + dataPtr[10] = 0; + dataPtr[11] = 1.0f; + + dataPtr[12] = 1.0f; + dataPtr[13] = 0; + dataPtr[14] = 0; + + dataPtr[15] = 0; + dataPtr[16] = 1.0f; + dataPtr[17] = 0; + + dataBuffer->setData(data); + Buffer *backendBuffer = nodeManagers->bufferManager()->getOrCreateResource(dataBuffer->id()); + backendBuffer->setRenderer(&renderer); + backendBuffer->setManager(nodeManagers->bufferManager()); + simulateInitialization(dataBuffer.data(), backendBuffer); + + positionAttribute->setBuffer(dataBuffer.data()); + positionAttribute->setName(Qt3DRender::QAttribute::defaultPositionAttributeName()); + positionAttribute->setVertexBaseType(Qt3DRender::QAttribute::Float); + positionAttribute->setVertexSize(3); + positionAttribute->setCount(3); + positionAttribute->setByteStride(3 * 4 * 2); + positionAttribute->setByteOffset(0); + positionAttribute->setAttributeType(Qt3DRender::QAttribute::VertexAttribute); + geometry->addAttribute(positionAttribute.data()); + + texcoordAttribute->setBuffer(dataBuffer.data()); + texcoordAttribute->setName(Qt3DRender::QAttribute::defaultTextureCoordinateAttributeName()); + texcoordAttribute->setVertexBaseType(Qt3DRender::QAttribute::Float); + texcoordAttribute->setVertexSize(3); + texcoordAttribute->setCount(6); + texcoordAttribute->setByteStride(3 * 4 * 2); + texcoordAttribute->setByteOffset(3 * 4); + texcoordAttribute->setAttributeType(Qt3DRender::QAttribute::VertexAttribute); + geometry->addAttribute(texcoordAttribute.data()); + + geometryRenderer->setGeometry(geometry); + geometryRenderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles); + + Attribute *backendAttribute = nodeManagers->attributeManager()->getOrCreateResource( + positionAttribute->id()); + backendAttribute->setRenderer(&renderer); + simulateInitialization(positionAttribute.data(), backendAttribute); + + Attribute *backendTexcoordAttribute = nodeManagers->attributeManager() + ->getOrCreateResource(texcoordAttribute->id()); + backendTexcoordAttribute->setRenderer(&renderer); + simulateInitialization(texcoordAttribute.data(), backendTexcoordAttribute); + + Geometry *backendGeometry = nodeManagers->geometryManager() + ->getOrCreateResource(geometry->id()); + backendGeometry->setRenderer(&renderer); + simulateInitialization(geometry, backendGeometry); + + GeometryRenderer *backendRenderer = nodeManagers->geometryRendererManager() + ->getOrCreateResource(geometryRenderer->id()); + backendRenderer->setRenderer(&renderer); + backendRenderer->setManager(nodeManagers->geometryRendererManager()); + simulateInitialization(geometryRenderer.data(), backendRenderer); + + // WHEN + bool ret = reader.setGeometry(backendRenderer, + Qt3DRender::QAttribute::defaultPositionAttributeName()); + + // THEN + QCOMPARE(ret, true); + + QVERIFY(reader.verifyCoordinate(0, QVector4D(0, 0, 1, 1))); + QVERIFY(reader.verifyCoordinate(1, QVector4D(0, 1, 0, 1))); + QVERIFY(reader.verifyCoordinate(2, QVector4D(1, 0, 0, 1))); + + // WHEN + ret = reader.setGeometry(backendRenderer, + Qt3DRender::QAttribute::defaultTextureCoordinateAttributeName()); + + // THEN + QCOMPARE(ret, true); + + QVERIFY(reader.verifyCoordinate(0, QVector4D(1, 0, 0, 1))); + QVERIFY(reader.verifyCoordinate(1, QVector4D(0, 0, 1, 1))); + QVERIFY(reader.verifyCoordinate(2, QVector4D(0, 1, 0, 1))); + } + +}; + +QTEST_MAIN(tst_CoordinateReader) + +#include "tst_coordinatereader.moc" diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro index e03c07d41..abaac7d05 100644 --- a/tests/auto/render/render.pro +++ b/tests/auto/render/render.pro @@ -100,7 +100,8 @@ qtConfig(private_tests) { qeventforward \ eventforward \ qscene2d \ - scene2d + scene2d \ + coordinatereader !macos: SUBDIRS += graphicshelpergl4 } -- cgit v1.2.3 From 946e78eada359f651d337309b25d51d4204289b0 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Tue, 24 Jan 2017 16:41:53 +0100 Subject: Change QTextureLoader defaults We realized that for rich formats the defaults are ignored by QTextureLoader. At the same time for simpler formats the defaults coming from QAbstractTexture are a bit subpar for quality. So change QTextureLoader defaults to be better in that regard to make QTextureLoader a nice way to load a texture from file in one line. Change-Id: Iefe1b07d14f362ef619e4a86d6599370534041ff Reviewed-by: Sean Harmer --- tests/auto/render/qtextureloader/tst_qtextureloader.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/render/qtextureloader/tst_qtextureloader.cpp b/tests/auto/render/qtextureloader/tst_qtextureloader.cpp index 252bc85af..56ad55adf 100644 --- a/tests/auto/render/qtextureloader/tst_qtextureloader.cpp +++ b/tests/auto/render/qtextureloader/tst_qtextureloader.cpp @@ -51,6 +51,13 @@ private Q_SLOTS: // THEN QCOMPARE(textureLoader.source(), QUrl()); QCOMPARE(textureLoader.isMirrored(), true); + QCOMPARE(textureLoader.target(), Qt3DRender::QTextureLoader::TargetAutomatic); + QCOMPARE(textureLoader.wrapMode()->x(), Qt3DRender::QTextureWrapMode::Repeat); + QCOMPARE(textureLoader.wrapMode()->y(), Qt3DRender::QTextureWrapMode::Repeat); + QCOMPARE(textureLoader.magnificationFilter(), Qt3DRender::QTextureLoader::Linear); + QCOMPARE(textureLoader.minificationFilter(), Qt3DRender::QTextureLoader::LinearMipMapLinear); + QCOMPARE(textureLoader.generateMipMaps(), true); + QCOMPARE(textureLoader.maximumAnisotropy(), 16.0f); } void checkPropertyChanges() -- cgit v1.2.3 From c5768dd2c04ebdb3a411e88bfa8af2767aa33368 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Wed, 25 Jan 2017 13:22:46 +0100 Subject: Align QForwardRenderer API with its QML counterpart The QML based ForwardRenderer was slightly different: * window property instead of surface, so we provide an alias window name for surface in QForwardRenderer * frustumCulling property to control the corresponding node, also added here. Change-Id: I7ec51ee27e97c612ba09b73a43cf4d1baba343bf Reviewed-by: Sean Harmer --- .../qforwardrenderer/tst_qforwardrenderer.cpp | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/extras/qforwardrenderer/tst_qforwardrenderer.cpp b/tests/auto/extras/qforwardrenderer/tst_qforwardrenderer.cpp index 122aed520..0d80f0e35 100644 --- a/tests/auto/extras/qforwardrenderer/tst_qforwardrenderer.cpp +++ b/tests/auto/extras/qforwardrenderer/tst_qforwardrenderer.cpp @@ -55,6 +55,7 @@ private Q_SLOTS: QCOMPARE(forwardRenderer.clearColor(), QColor(Qt::white)); QVERIFY(forwardRenderer.camera() == nullptr); QCOMPARE(forwardRenderer.externalRenderTargetSize(), QSize()); + QVERIFY(forwardRenderer.isFrustumCullingEnabled()); } void checkPropertyChanges() @@ -163,6 +164,31 @@ private Q_SLOTS: QCOMPARE(spy.count(), 0); } + { + // WHEN + QSignalSpy spy(&forwardRenderer, SIGNAL(frustumCullingEnabledChanged(bool))); + forwardRenderer.setFrustumCullingEnabled(false); + + // THEN + QVERIFY(!forwardRenderer.isFrustumCullingEnabled()); + QCOMPARE(spy.count(), 1); + QVERIFY(!spy.takeFirst().takeFirst().toBool()); + + // WHEN + forwardRenderer.setFrustumCullingEnabled(false); + + // THEN + QVERIFY(!forwardRenderer.isFrustumCullingEnabled()); + QCOMPARE(spy.count(), 0); + + // WHEN + forwardRenderer.setFrustumCullingEnabled(true); + + // THEN + QVERIFY(forwardRenderer.isFrustumCullingEnabled()); + QCOMPARE(spy.count(), 1); + QVERIFY(spy.takeFirst().takeFirst().toBool()); + } } }; -- cgit v1.2.3 From 3a895576bf188e15d5ff03e704e192a87d4c16a0 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Wed, 25 Jan 2017 15:40:47 +0100 Subject: Add (ac|de)celeration to QFirstPersonCameraController Those two properties were added to the QML variant but not the C++ one. Let's fix this. Change-Id: Ibd0765993f42a7562bd922f2db5456c1fa6d6ad1 Reviewed-by: Sean Harmer --- .../tst_qfirstpersoncameracontroller.cpp | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/extras/qfirstpersoncameracontroller/tst_qfirstpersoncameracontroller.cpp b/tests/auto/extras/qfirstpersoncameracontroller/tst_qfirstpersoncameracontroller.cpp index 22046051b..2cf4d7ba2 100644 --- a/tests/auto/extras/qfirstpersoncameracontroller/tst_qfirstpersoncameracontroller.cpp +++ b/tests/auto/extras/qfirstpersoncameracontroller/tst_qfirstpersoncameracontroller.cpp @@ -48,6 +48,8 @@ private Q_SLOTS: QVERIFY(firstPersonCameraController.camera() == nullptr); QCOMPARE(firstPersonCameraController.linearSpeed(), 10.0f); QCOMPARE(firstPersonCameraController.lookSpeed(), 180.0f); + QCOMPARE(firstPersonCameraController.acceleration(), -1.0f); + QCOMPARE(firstPersonCameraController.deceleration(), -1.0f); } void checkPropertyChanges() @@ -120,6 +122,44 @@ private Q_SLOTS: QCOMPARE(spy.count(), 0); } + { + // WHEN + QSignalSpy spy(&firstPersonCameraController, SIGNAL(accelerationChanged())); + const float newValue = 0.001f; + firstPersonCameraController.setAcceleration(newValue); + + // THEN + QCOMPARE(firstPersonCameraController.acceleration(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + firstPersonCameraController.setAcceleration(newValue); + + // THEN + QCOMPARE(firstPersonCameraController.acceleration(), newValue); + QCOMPARE(spy.count(), 0); + + } + { + // WHEN + QSignalSpy spy(&firstPersonCameraController, SIGNAL(decelerationChanged())); + const float newValue = 0.001f; + firstPersonCameraController.setDeceleration(newValue); + + // THEN + QCOMPARE(firstPersonCameraController.deceleration(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + firstPersonCameraController.setDeceleration(newValue); + + // THEN + QCOMPARE(firstPersonCameraController.deceleration(), newValue); + QCOMPARE(spy.count(), 0); + + } } }; -- cgit v1.2.3 From e72560976ea41ddf0a9940b322692cb425caa226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Mon, 30 Jan 2017 11:09:51 +0200 Subject: Fix scene2d autotest shutdown crash Change-Id: I0a4e12243b8fcf80d4849879211b87448096fab0 Reviewed-by: Sean Harmer --- tests/auto/render/render.pro | 2 +- tests/auto/render/scene2d/tst_scene2d.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro index 5a8b16e93..4f536d3f4 100644 --- a/tests/auto/render/render.pro +++ b/tests/auto/render/render.pro @@ -105,7 +105,7 @@ qtConfig(private_tests) { qeventforward \ eventforward \ qscene2d \ - #scene2d \ + scene2d \ coordinatereader !macos: SUBDIRS += graphicshelpergl4 diff --git a/tests/auto/render/scene2d/tst_scene2d.cpp b/tests/auto/render/scene2d/tst_scene2d.cpp index f07a35b19..45ea85b42 100644 --- a/tests/auto/render/scene2d/tst_scene2d.cpp +++ b/tests/auto/render/scene2d/tst_scene2d.cpp @@ -58,6 +58,7 @@ private Q_SLOTS: QCOMPARE(backendScene2d.m_initialized, false); QCOMPARE(backendScene2d.m_renderInitialized, false); QCOMPARE(backendScene2d.m_renderPolicy, QScene2D::Continuous); + backendScene2d.cleanup(); } void checkInitializeFromPeer() -- cgit v1.2.3 From 989ce5f0e3d128c0d47a410e53ca57578a25d202 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Mon, 30 Jan 2017 12:41:26 +0100 Subject: ClipBlendNode: add a virtual pure blend method Allows to make each subclass perform its own blending Change-Id: I0a8e32ebc549c988cf4cab59806152c7aa0825f4 Reviewed-by: Sean Harmer --- .../animation/clipblendnode/tst_clipblendnode.cpp | 2 ++ .../tst_clipblendnodemanager.cpp | 3 +++ tests/auto/animation/lerpblend/tst_lerpblend.cpp | 30 ++++++++++++++++++++++ 3 files changed, 35 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp index c045c2112..085979267 100644 --- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -47,6 +47,8 @@ public: TestClipBlendNode() : Qt3DAnimation::Animation::ClipBlendNode(Qt3DAnimation::Animation::ClipBlendNode::LerpBlendType) {} + + float blend(float , float ) const Q_DECL_FINAL { return 0.0f; } }; } // anonymous diff --git a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp index 2cf549f7e..962813d15 100644 --- a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp +++ b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp @@ -48,6 +48,9 @@ public: { deadCount += 1; } + + float blend(float , float ) const Q_DECL_FINAL { return 0.0f; } + }; } // anonymous diff --git a/tests/auto/animation/lerpblend/tst_lerpblend.cpp b/tests/auto/animation/lerpblend/tst_lerpblend.cpp index 9d758e7c4..5f494d9ec 100644 --- a/tests/auto/animation/lerpblend/tst_lerpblend.cpp +++ b/tests/auto/animation/lerpblend/tst_lerpblend.cpp @@ -50,6 +50,7 @@ private Q_SLOTS: QCOMPARE(backendLerpBlend.isEnabled(), false); QVERIFY(backendLerpBlend.peerId().isNull()); QCOMPARE(backendLerpBlend.blendFactor(), 0.0f); + QCOMPARE(backendLerpBlend.blendType(), Qt3DAnimation::Animation::ClipBlendNode::LerpBlendType); } void checkInitializeFromPeer() @@ -112,6 +113,35 @@ private Q_SLOTS: } } + void checkBlend_data() + { + QTest::addColumn("value1"); + QTest::addColumn("value2"); + QTest::addColumn("blendFactor"); + QTest::addColumn("result"); + + QTest::newRow("0_blending") << 8.0f << 5.0f << 0.0f << 8.0f; + QTest::newRow("0.5_blending") << 8.0f << 5.0f << 0.5f << 6.5f; + QTest::newRow("1_blending") << 8.0f << 5.0f << 1.0f << 5.0f; + } + + void checkBlend() + { + // GIVEN + QFETCH(float, value1); + QFETCH(float, value2); + QFETCH(float, blendFactor); + QFETCH(float, result); + Qt3DAnimation::Animation::LerpBlend lerpBlend; + + // WHEN + lerpBlend.setBlendFactor(blendFactor); + const float computed = lerpBlend.blend(value1, value2); + + // THEN + QCOMPARE(computed, result); + } + }; QTEST_MAIN(tst_LerpBlend) -- cgit v1.2.3 From bc0bf7accb22206a6e5d30b7d43d707cdc072f67 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Mon, 30 Jan 2017 13:05:56 +0100 Subject: Add QAddBlend frontend node Change-Id: If18e8dee32503c6172e67107adac57a158effc37 Reviewed-by: Sean Harmer --- tests/auto/animation/animation.pro | 3 +- tests/auto/animation/qaddblend/qaddblend.pro | 11 ++ tests/auto/animation/qaddblend/tst_qaddblend.cpp | 185 +++++++++++++++++++++++ 3 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 tests/auto/animation/qaddblend/qaddblend.pro create mode 100644 tests/auto/animation/qaddblend/tst_qaddblend.cpp (limited to 'tests/auto') diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index 43844ed88..6e255f6c0 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -25,5 +25,6 @@ qtConfig(private_tests) { clipblendnodemanager \ clipblendnode \ lerpblend \ - clipblendnodevisitor + clipblendnodevisitor \ + qaddblend } diff --git a/tests/auto/animation/qaddblend/qaddblend.pro b/tests/auto/animation/qaddblend/qaddblend.pro new file mode 100644 index 000000000..e633576f6 --- /dev/null +++ b/tests/auto/animation/qaddblend/qaddblend.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +TARGET = tst_qaddblend + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += tst_qaddblend.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/qaddblend/tst_qaddblend.cpp b/tests/auto/animation/qaddblend/tst_qaddblend.cpp new file mode 100644 index 000000000..57377b3c4 --- /dev/null +++ b/tests/auto/animation/qaddblend/tst_qaddblend.cpp @@ -0,0 +1,185 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Paul Lemire +** 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "testpostmanarbiter.h" + +class tst_QAddBlend : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void checkDefaultConstruction() + { + // GIVEN + Qt3DAnimation::QAddBlend addBlend; + + // THEN + QCOMPARE(addBlend.blendFactor(), 0.0f); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::QAddBlend addBlend; + + { + // WHEN + QSignalSpy spy(&addBlend, SIGNAL(blendFactorChanged(float))); + const float newValue = 0.5f; + addBlend.setBlendFactor(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(addBlend.blendFactor(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + addBlend.setBlendFactor(newValue); + + // THEN + QCOMPARE(addBlend.blendFactor(), newValue); + QCOMPARE(spy.count(), 0); + } + } + + void checkCreationData() + { + // GIVEN + Qt3DAnimation::QAddBlend addBlend; + Qt3DAnimation::QAnimationClip clip1; + Qt3DAnimation::QAnimationClip clip2; + + addBlend.addClip(&clip1); + addBlend.addClip(&clip2); + addBlend.setBlendFactor(0.8f); + + + // WHEN + QVector creationChanges; + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&addBlend); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 3); // 1 + 2 clips + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DAnimation::QAddBlendData cloneData = creationChangeData->data; + + QCOMPARE(addBlend.blendFactor(), cloneData.blendFactor); + QCOMPARE(addBlend.id(), creationChangeData->subjectId()); + QCOMPARE(addBlend.isEnabled(), true); + QCOMPARE(addBlend.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(addBlend.metaObject(), creationChangeData->metaObject()); + QCOMPARE(creationChangeData->clips().size(), 2); + QCOMPARE(creationChangeData->clips().first(), clip1.id()); + QCOMPARE(creationChangeData->clips().last(), clip2.id()); + QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); + } + + // WHEN + addBlend.setEnabled(false); + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&addBlend); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 3); // 1 + 2 clips + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DAnimation::QAddBlendData cloneData = creationChangeData->data; + + QCOMPARE(addBlend.blendFactor(), cloneData.blendFactor); + QCOMPARE(addBlend.id(), creationChangeData->subjectId()); + QCOMPARE(addBlend.isEnabled(), false); + QCOMPARE(addBlend.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(addBlend.metaObject(), creationChangeData->metaObject()); + QCOMPARE(creationChangeData->clips().size(), 2); + QCOMPARE(creationChangeData->clips().first(), clip1.id()); + QCOMPARE(creationChangeData->clips().last(), clip2.id()); + QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); + } + } + + void checkBlendFactorUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::QAddBlend addBlend; + arbiter.setArbiterOnNode(&addBlend); + + { + // WHEN + addBlend.setBlendFactor(0.4f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "blendFactor"); + QCOMPARE(change->value().value(), addBlend.blendFactor()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + addBlend.setBlendFactor(0.4f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + +}; + +QTEST_MAIN(tst_QAddBlend) + +#include "tst_qaddblend.moc" -- cgit v1.2.3 From 64172f28aea7d17ab4e12c87b677d6ac4591bdea Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Mon, 30 Jan 2017 15:23:00 +0100 Subject: Add AddBlend backend node Change-Id: I547ce2ffd7816fa905724df0ed0c417ecead1ce9 Reviewed-by: Sean Harmer --- tests/auto/animation/addblend/addblend.pro | 11 ++ tests/auto/animation/addblend/tst_addblend.cpp | 148 +++++++++++++++++++++++++ tests/auto/animation/animation.pro | 3 +- 3 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 tests/auto/animation/addblend/addblend.pro create mode 100644 tests/auto/animation/addblend/tst_addblend.cpp (limited to 'tests/auto') diff --git a/tests/auto/animation/addblend/addblend.pro b/tests/auto/animation/addblend/addblend.pro new file mode 100644 index 000000000..bfa9256f4 --- /dev/null +++ b/tests/auto/animation/addblend/addblend.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +TARGET = tst_addblend + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += tst_addblend.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/addblend/tst_addblend.cpp b/tests/auto/animation/addblend/tst_addblend.cpp new file mode 100644 index 000000000..961fb498e --- /dev/null +++ b/tests/auto/animation/addblend/tst_addblend.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Paul Lemire +** 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 +#include +#include +#include +#include +#include +#include "qbackendnodetester.h" + +class tst_AddBlend : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + + void checkInitialState() + { + // GIVEN + Qt3DAnimation::Animation::AddBlend backendAddBlend; + + // THEN + QCOMPARE(backendAddBlend.isEnabled(), false); + QVERIFY(backendAddBlend.peerId().isNull()); + QCOMPARE(backendAddBlend.blendFactor(), 0.0f); + QCOMPARE(backendAddBlend.blendType(), Qt3DAnimation::Animation::ClipBlendNode::AddBlendType); + } + + void checkInitializeFromPeer() + { + // GIVEN + Qt3DAnimation::QAddBlend AddBlend; + Qt3DAnimation::QAnimationClip clip; + AddBlend.setBlendFactor(0.8f); + AddBlend.addClip(&clip); + + { + // WHEN + Qt3DAnimation::Animation::AddBlend backendAddBlend; + simulateInitialization(&AddBlend, &backendAddBlend); + + // THEN + QCOMPARE(backendAddBlend.isEnabled(), true); + QCOMPARE(backendAddBlend.peerId(), AddBlend.id()); + QCOMPARE(backendAddBlend.blendFactor(), 0.8f); + QCOMPARE(backendAddBlend.clipIds().size(), 1); + QCOMPARE(backendAddBlend.clipIds().first(), clip.id()); + } + { + // WHEN + Qt3DAnimation::Animation::AddBlend backendAddBlend; + AddBlend.setEnabled(false); + simulateInitialization(&AddBlend, &backendAddBlend); + + // THEN + QCOMPARE(backendAddBlend.peerId(), AddBlend.id()); + QCOMPARE(backendAddBlend.isEnabled(), false); + } + } + + void checkSceneChangeEvents() + { + // GIVEN + Qt3DAnimation::Animation::AddBlend backendAddBlend; + { + // WHEN + const bool newValue = false; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("enabled"); + change->setValue(newValue); + backendAddBlend.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendAddBlend.isEnabled(), newValue); + } + { + // WHEN + const float newValue = 0.883f; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("blendFactor"); + change->setValue(QVariant::fromValue(newValue)); + backendAddBlend.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendAddBlend.blendFactor(), newValue); + } + } + + void checkBlend_data() + { + QTest::addColumn("value1"); + QTest::addColumn("value2"); + QTest::addColumn("blendFactor"); + QTest::addColumn("result"); + + QTest::newRow("0_blending") << 8.0f << 5.0f << 0.0f << 8.0f; + QTest::newRow("0.5_blending") << 8.0f << 5.0f << 0.5f << 10.5f; + QTest::newRow("1_blending") << 8.0f << 5.0f << 1.0f << 13.0f; + } + + void checkBlend() + { + // GIVEN + QFETCH(float, value1); + QFETCH(float, value2); + QFETCH(float, blendFactor); + QFETCH(float, result); + Qt3DAnimation::Animation::AddBlend addBlend; + + // WHEN + addBlend.setBlendFactor(blendFactor); + const float computed = addBlend.blend(value1, value2); + + // THEN + QCOMPARE(computed, result); + } +}; + +QTEST_MAIN(tst_AddBlend) + +#include "tst_addblend.moc" diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index 6e255f6c0..4acf2fe3e 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -26,5 +26,6 @@ qtConfig(private_tests) { clipblendnode \ lerpblend \ clipblendnodevisitor \ - qaddblend + qaddblend \ + addblend } -- cgit v1.2.3 From c35f8e7c5f573fcc89b3042157d5843d9322ac90 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Tue, 31 Jan 2017 11:57:02 +0100 Subject: BlendedAnimations: allow nested blending nodes evaluation Change-Id: Ic6a70ee57f56dff7406b5917d620ea15b74ecb44 Reviewed-by: Sean Harmer --- .../animation/blendedclipanimator/tst_blendedclipanimator.cpp | 5 ----- .../clipblendnodevisitor/tst_clipblendnodevisitor.cpp | 11 ++++++----- 2 files changed, 6 insertions(+), 10 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp b/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp index c53f6ec62..04cc1026e 100644 --- a/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp +++ b/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp @@ -65,7 +65,6 @@ private Q_SLOTS: QCOMPARE(backendBlendedClipAnimator.isRunning(), false); QCOMPARE(backendBlendedClipAnimator.startTime(), 0); QCOMPARE(backendBlendedClipAnimator.currentLoop(), 0); - QCOMPARE(backendBlendedClipAnimator.mappingData().size(), 0); QCOMPARE(backendBlendedClipAnimator.loops(), 1); } @@ -83,9 +82,6 @@ private Q_SLOTS: backendBlendedClipAnimator.setMapperId(Qt3DCore::QNodeId::createId()); backendBlendedClipAnimator.setRunning(true); backendBlendedClipAnimator.setStartTime(28); - QVector mappingData; - mappingData.resize(5); - backendBlendedClipAnimator.setMappingData(mappingData); backendBlendedClipAnimator.cleanup(); // THEN @@ -95,7 +91,6 @@ private Q_SLOTS: QCOMPARE(backendBlendedClipAnimator.isRunning(), false); QCOMPARE(backendBlendedClipAnimator.startTime(), 0); QCOMPARE(backendBlendedClipAnimator.currentLoop(), 0); - QCOMPARE(backendBlendedClipAnimator.mappingData().size(), 0); QCOMPARE(backendBlendedClipAnimator.loops(), 1); } diff --git a/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp b/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp index 6c6723920..78f0f1202 100644 --- a/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp +++ b/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp @@ -89,17 +89,18 @@ private Q_SLOTS: // WHEN int i = 0; + // Note: post-order traversal auto childCounter = [&] (Qt3DAnimation::Animation::ClipBlendNode *node) { if (i == 0) - QCOMPARE(node, backendRootBlendNode); + QCOMPARE(node, backendChildBlendNode11); else if (i == 1) - QCOMPARE(node, backendChildBlendNode1); + QCOMPARE(node, backendChildBlendNode12); else if (i == 2) - QCOMPARE(node, backendChildBlendNode11); + QCOMPARE(node, backendChildBlendNode1); else if (i == 3) - QCOMPARE(node, backendChildBlendNode12); - else if (i == 4) QCOMPARE(node, backendChildBlendNode2); + else if (i == 4) + QCOMPARE(node, backendRootBlendNode); ++i; }; -- cgit v1.2.3 From 68606da9f12482a7bd910dccc53daf2899082526 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Tue, 31 Jan 2017 12:26:27 +0100 Subject: Renamed QAddBlend to QAdditiveBlend Change-Id: I1a2737c335790507c3b598e274f8dc5f8f82d1a1 Reviewed-by: Sean Harmer --- tests/auto/animation/addblend/addblend.pro | 11 -- tests/auto/animation/addblend/tst_addblend.cpp | 148 ----------------- .../auto/animation/additiveblend/additiveblend.pro | 12 ++ .../animation/additiveblend/tst_additiveblend.cpp | 148 +++++++++++++++++ tests/auto/animation/animation.pro | 4 +- tests/auto/animation/qaddblend/qaddblend.pro | 11 -- tests/auto/animation/qaddblend/tst_qaddblend.cpp | 185 --------------------- .../animation/qadditiveblend/qadditiveblend.pro | 12 ++ .../qadditiveblend/tst_qadditiveblend.cpp | 185 +++++++++++++++++++++ 9 files changed, 359 insertions(+), 357 deletions(-) delete mode 100644 tests/auto/animation/addblend/addblend.pro delete mode 100644 tests/auto/animation/addblend/tst_addblend.cpp create mode 100644 tests/auto/animation/additiveblend/additiveblend.pro create mode 100644 tests/auto/animation/additiveblend/tst_additiveblend.cpp delete mode 100644 tests/auto/animation/qaddblend/qaddblend.pro delete mode 100644 tests/auto/animation/qaddblend/tst_qaddblend.cpp create mode 100644 tests/auto/animation/qadditiveblend/qadditiveblend.pro create mode 100644 tests/auto/animation/qadditiveblend/tst_qadditiveblend.cpp (limited to 'tests/auto') diff --git a/tests/auto/animation/addblend/addblend.pro b/tests/auto/animation/addblend/addblend.pro deleted file mode 100644 index bfa9256f4..000000000 --- a/tests/auto/animation/addblend/addblend.pro +++ /dev/null @@ -1,11 +0,0 @@ -TEMPLATE = app - -TARGET = tst_addblend - -QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib - -CONFIG += testcase - -SOURCES += tst_addblend.cpp - -include(../../core/common/common.pri) diff --git a/tests/auto/animation/addblend/tst_addblend.cpp b/tests/auto/animation/addblend/tst_addblend.cpp deleted file mode 100644 index 961fb498e..000000000 --- a/tests/auto/animation/addblend/tst_addblend.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Paul Lemire -** 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 -#include -#include -#include -#include -#include -#include "qbackendnodetester.h" - -class tst_AddBlend : public Qt3DCore::QBackendNodeTester -{ - Q_OBJECT - -private Q_SLOTS: - - void checkInitialState() - { - // GIVEN - Qt3DAnimation::Animation::AddBlend backendAddBlend; - - // THEN - QCOMPARE(backendAddBlend.isEnabled(), false); - QVERIFY(backendAddBlend.peerId().isNull()); - QCOMPARE(backendAddBlend.blendFactor(), 0.0f); - QCOMPARE(backendAddBlend.blendType(), Qt3DAnimation::Animation::ClipBlendNode::AddBlendType); - } - - void checkInitializeFromPeer() - { - // GIVEN - Qt3DAnimation::QAddBlend AddBlend; - Qt3DAnimation::QAnimationClip clip; - AddBlend.setBlendFactor(0.8f); - AddBlend.addClip(&clip); - - { - // WHEN - Qt3DAnimation::Animation::AddBlend backendAddBlend; - simulateInitialization(&AddBlend, &backendAddBlend); - - // THEN - QCOMPARE(backendAddBlend.isEnabled(), true); - QCOMPARE(backendAddBlend.peerId(), AddBlend.id()); - QCOMPARE(backendAddBlend.blendFactor(), 0.8f); - QCOMPARE(backendAddBlend.clipIds().size(), 1); - QCOMPARE(backendAddBlend.clipIds().first(), clip.id()); - } - { - // WHEN - Qt3DAnimation::Animation::AddBlend backendAddBlend; - AddBlend.setEnabled(false); - simulateInitialization(&AddBlend, &backendAddBlend); - - // THEN - QCOMPARE(backendAddBlend.peerId(), AddBlend.id()); - QCOMPARE(backendAddBlend.isEnabled(), false); - } - } - - void checkSceneChangeEvents() - { - // GIVEN - Qt3DAnimation::Animation::AddBlend backendAddBlend; - { - // WHEN - const bool newValue = false; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("enabled"); - change->setValue(newValue); - backendAddBlend.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendAddBlend.isEnabled(), newValue); - } - { - // WHEN - const float newValue = 0.883f; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("blendFactor"); - change->setValue(QVariant::fromValue(newValue)); - backendAddBlend.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendAddBlend.blendFactor(), newValue); - } - } - - void checkBlend_data() - { - QTest::addColumn("value1"); - QTest::addColumn("value2"); - QTest::addColumn("blendFactor"); - QTest::addColumn("result"); - - QTest::newRow("0_blending") << 8.0f << 5.0f << 0.0f << 8.0f; - QTest::newRow("0.5_blending") << 8.0f << 5.0f << 0.5f << 10.5f; - QTest::newRow("1_blending") << 8.0f << 5.0f << 1.0f << 13.0f; - } - - void checkBlend() - { - // GIVEN - QFETCH(float, value1); - QFETCH(float, value2); - QFETCH(float, blendFactor); - QFETCH(float, result); - Qt3DAnimation::Animation::AddBlend addBlend; - - // WHEN - addBlend.setBlendFactor(blendFactor); - const float computed = addBlend.blend(value1, value2); - - // THEN - QCOMPARE(computed, result); - } -}; - -QTEST_MAIN(tst_AddBlend) - -#include "tst_addblend.moc" diff --git a/tests/auto/animation/additiveblend/additiveblend.pro b/tests/auto/animation/additiveblend/additiveblend.pro new file mode 100644 index 000000000..e61417c73 --- /dev/null +++ b/tests/auto/animation/additiveblend/additiveblend.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_additiveblend + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += \ + tst_additiveblend.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/additiveblend/tst_additiveblend.cpp b/tests/auto/animation/additiveblend/tst_additiveblend.cpp new file mode 100644 index 000000000..31c103166 --- /dev/null +++ b/tests/auto/animation/additiveblend/tst_additiveblend.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Paul Lemire +** 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 +#include +#include +#include +#include +#include +#include "qbackendnodetester.h" + +class tst_AdditiveBlend : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + + void checkInitialState() + { + // GIVEN + Qt3DAnimation::Animation::AdditiveBlend backendAdditiveBlend; + + // THEN + QCOMPARE(backendAdditiveBlend.isEnabled(), false); + QVERIFY(backendAdditiveBlend.peerId().isNull()); + QCOMPARE(backendAdditiveBlend.blendFactor(), 0.0f); + QCOMPARE(backendAdditiveBlend.blendType(), Qt3DAnimation::Animation::ClipBlendNode::AdditiveBlendType); + } + + void checkInitializeFromPeer() + { + // GIVEN + Qt3DAnimation::QAdditiveBlend additiveBlend; + Qt3DAnimation::QAnimationClip clip; + additiveBlend.setBlendFactor(0.8f); + additiveBlend.addClip(&clip); + + { + // WHEN + Qt3DAnimation::Animation::AdditiveBlend backendAdditiveBlend; + simulateInitialization(&additiveBlend, &backendAdditiveBlend); + + // THEN + QCOMPARE(backendAdditiveBlend.isEnabled(), true); + QCOMPARE(backendAdditiveBlend.peerId(), additiveBlend.id()); + QCOMPARE(backendAdditiveBlend.blendFactor(), 0.8f); + QCOMPARE(backendAdditiveBlend.clipIds().size(), 1); + QCOMPARE(backendAdditiveBlend.clipIds().first(), clip.id()); + } + { + // WHEN + Qt3DAnimation::Animation::AdditiveBlend backendAdditiveBlend; + additiveBlend.setEnabled(false); + simulateInitialization(&additiveBlend, &backendAdditiveBlend); + + // THEN + QCOMPARE(backendAdditiveBlend.peerId(), additiveBlend.id()); + QCOMPARE(backendAdditiveBlend.isEnabled(), false); + } + } + + void checkSceneChangeEvents() + { + // GIVEN + Qt3DAnimation::Animation::AdditiveBlend backendAdditiveBlend; + { + // WHEN + const bool newValue = false; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("enabled"); + change->setValue(newValue); + backendAdditiveBlend.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendAdditiveBlend.isEnabled(), newValue); + } + { + // WHEN + const float newValue = 0.883f; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("blendFactor"); + change->setValue(QVariant::fromValue(newValue)); + backendAdditiveBlend.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendAdditiveBlend.blendFactor(), newValue); + } + } + + void checkBlend_data() + { + QTest::addColumn("value1"); + QTest::addColumn("value2"); + QTest::addColumn("blendFactor"); + QTest::addColumn("result"); + + QTest::newRow("0_blending") << 8.0f << 5.0f << 0.0f << 8.0f; + QTest::newRow("0.5_blending") << 8.0f << 5.0f << 0.5f << 10.5f; + QTest::newRow("1_blending") << 8.0f << 5.0f << 1.0f << 13.0f; + } + + void checkBlend() + { + // GIVEN + QFETCH(float, value1); + QFETCH(float, value2); + QFETCH(float, blendFactor); + QFETCH(float, result); + Qt3DAnimation::Animation::AdditiveBlend addBlend; + + // WHEN + addBlend.setBlendFactor(blendFactor); + const float computed = addBlend.blend(value1, value2); + + // THEN + QCOMPARE(computed, result); + } +}; + +QTEST_MAIN(tst_AdditiveBlend) + +#include "tst_additiveblend.moc" diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index 4acf2fe3e..43a00cd12 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -26,6 +26,6 @@ qtConfig(private_tests) { clipblendnode \ lerpblend \ clipblendnodevisitor \ - qaddblend \ - addblend + qadditiveblend \ + additiveblend } diff --git a/tests/auto/animation/qaddblend/qaddblend.pro b/tests/auto/animation/qaddblend/qaddblend.pro deleted file mode 100644 index e633576f6..000000000 --- a/tests/auto/animation/qaddblend/qaddblend.pro +++ /dev/null @@ -1,11 +0,0 @@ -TEMPLATE = app - -TARGET = tst_qaddblend - -QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib - -CONFIG += testcase - -SOURCES += tst_qaddblend.cpp - -include(../../core/common/common.pri) diff --git a/tests/auto/animation/qaddblend/tst_qaddblend.cpp b/tests/auto/animation/qaddblend/tst_qaddblend.cpp deleted file mode 100644 index 57377b3c4..000000000 --- a/tests/auto/animation/qaddblend/tst_qaddblend.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Paul Lemire -** 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "testpostmanarbiter.h" - -class tst_QAddBlend : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - - void checkDefaultConstruction() - { - // GIVEN - Qt3DAnimation::QAddBlend addBlend; - - // THEN - QCOMPARE(addBlend.blendFactor(), 0.0f); - } - - void checkPropertyChanges() - { - // GIVEN - Qt3DAnimation::QAddBlend addBlend; - - { - // WHEN - QSignalSpy spy(&addBlend, SIGNAL(blendFactorChanged(float))); - const float newValue = 0.5f; - addBlend.setBlendFactor(newValue); - - // THEN - QVERIFY(spy.isValid()); - QCOMPARE(addBlend.blendFactor(), newValue); - QCOMPARE(spy.count(), 1); - - // WHEN - spy.clear(); - addBlend.setBlendFactor(newValue); - - // THEN - QCOMPARE(addBlend.blendFactor(), newValue); - QCOMPARE(spy.count(), 0); - } - } - - void checkCreationData() - { - // GIVEN - Qt3DAnimation::QAddBlend addBlend; - Qt3DAnimation::QAnimationClip clip1; - Qt3DAnimation::QAnimationClip clip2; - - addBlend.addClip(&clip1); - addBlend.addClip(&clip2); - addBlend.setBlendFactor(0.8f); - - - // WHEN - QVector creationChanges; - - { - Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&addBlend); - creationChanges = creationChangeGenerator.creationChanges(); - } - - // THEN - { - QCOMPARE(creationChanges.size(), 3); // 1 + 2 clips - - const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); - const Qt3DAnimation::QAddBlendData cloneData = creationChangeData->data; - - QCOMPARE(addBlend.blendFactor(), cloneData.blendFactor); - QCOMPARE(addBlend.id(), creationChangeData->subjectId()); - QCOMPARE(addBlend.isEnabled(), true); - QCOMPARE(addBlend.isEnabled(), creationChangeData->isNodeEnabled()); - QCOMPARE(addBlend.metaObject(), creationChangeData->metaObject()); - QCOMPARE(creationChangeData->clips().size(), 2); - QCOMPARE(creationChangeData->clips().first(), clip1.id()); - QCOMPARE(creationChangeData->clips().last(), clip2.id()); - QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); - } - - // WHEN - addBlend.setEnabled(false); - - { - Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&addBlend); - creationChanges = creationChangeGenerator.creationChanges(); - } - - // THEN - { - QCOMPARE(creationChanges.size(), 3); // 1 + 2 clips - - const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); - const Qt3DAnimation::QAddBlendData cloneData = creationChangeData->data; - - QCOMPARE(addBlend.blendFactor(), cloneData.blendFactor); - QCOMPARE(addBlend.id(), creationChangeData->subjectId()); - QCOMPARE(addBlend.isEnabled(), false); - QCOMPARE(addBlend.isEnabled(), creationChangeData->isNodeEnabled()); - QCOMPARE(addBlend.metaObject(), creationChangeData->metaObject()); - QCOMPARE(creationChangeData->clips().size(), 2); - QCOMPARE(creationChangeData->clips().first(), clip1.id()); - QCOMPARE(creationChangeData->clips().last(), clip2.id()); - QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); - } - } - - void checkBlendFactorUpdate() - { - // GIVEN - TestArbiter arbiter; - Qt3DAnimation::QAddBlend addBlend; - arbiter.setArbiterOnNode(&addBlend); - - { - // WHEN - addBlend.setBlendFactor(0.4f); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "blendFactor"); - QCOMPARE(change->value().value(), addBlend.blendFactor()); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - - arbiter.events.clear(); - } - - { - // WHEN - addBlend.setBlendFactor(0.4f); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - } - - } - -}; - -QTEST_MAIN(tst_QAddBlend) - -#include "tst_qaddblend.moc" diff --git a/tests/auto/animation/qadditiveblend/qadditiveblend.pro b/tests/auto/animation/qadditiveblend/qadditiveblend.pro new file mode 100644 index 000000000..b3f2a4599 --- /dev/null +++ b/tests/auto/animation/qadditiveblend/qadditiveblend.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_qadditiveblend + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += \ + tst_qadditiveblend.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/qadditiveblend/tst_qadditiveblend.cpp b/tests/auto/animation/qadditiveblend/tst_qadditiveblend.cpp new file mode 100644 index 000000000..27acf2b47 --- /dev/null +++ b/tests/auto/animation/qadditiveblend/tst_qadditiveblend.cpp @@ -0,0 +1,185 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Paul Lemire +** 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "testpostmanarbiter.h" + +class tst_QAdditiveBlend : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void checkDefaultConstruction() + { + // GIVEN + Qt3DAnimation::QAdditiveBlend addBlend; + + // THEN + QCOMPARE(addBlend.blendFactor(), 0.0f); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::QAdditiveBlend addBlend; + + { + // WHEN + QSignalSpy spy(&addBlend, SIGNAL(blendFactorChanged(float))); + const float newValue = 0.5f; + addBlend.setBlendFactor(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(addBlend.blendFactor(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + addBlend.setBlendFactor(newValue); + + // THEN + QCOMPARE(addBlend.blendFactor(), newValue); + QCOMPARE(spy.count(), 0); + } + } + + void checkCreationData() + { + // GIVEN + Qt3DAnimation::QAdditiveBlend addBlend; + Qt3DAnimation::QAnimationClip clip1; + Qt3DAnimation::QAnimationClip clip2; + + addBlend.addClip(&clip1); + addBlend.addClip(&clip2); + addBlend.setBlendFactor(0.8f); + + + // WHEN + QVector creationChanges; + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&addBlend); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 3); // 1 + 2 clips + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DAnimation::QAdditiveBlendData cloneData = creationChangeData->data; + + QCOMPARE(addBlend.blendFactor(), cloneData.blendFactor); + QCOMPARE(addBlend.id(), creationChangeData->subjectId()); + QCOMPARE(addBlend.isEnabled(), true); + QCOMPARE(addBlend.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(addBlend.metaObject(), creationChangeData->metaObject()); + QCOMPARE(creationChangeData->clips().size(), 2); + QCOMPARE(creationChangeData->clips().first(), clip1.id()); + QCOMPARE(creationChangeData->clips().last(), clip2.id()); + QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); + } + + // WHEN + addBlend.setEnabled(false); + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&addBlend); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 3); // 1 + 2 clips + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DAnimation::QAdditiveBlendData cloneData = creationChangeData->data; + + QCOMPARE(addBlend.blendFactor(), cloneData.blendFactor); + QCOMPARE(addBlend.id(), creationChangeData->subjectId()); + QCOMPARE(addBlend.isEnabled(), false); + QCOMPARE(addBlend.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(addBlend.metaObject(), creationChangeData->metaObject()); + QCOMPARE(creationChangeData->clips().size(), 2); + QCOMPARE(creationChangeData->clips().first(), clip1.id()); + QCOMPARE(creationChangeData->clips().last(), clip2.id()); + QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); + } + } + + void checkBlendFactorUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::QAdditiveBlend addBlend; + arbiter.setArbiterOnNode(&addBlend); + + { + // WHEN + addBlend.setBlendFactor(0.4f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "blendFactor"); + QCOMPARE(change->value().value(), addBlend.blendFactor()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + addBlend.setBlendFactor(0.4f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + +}; + +QTEST_MAIN(tst_QAdditiveBlend) + +#include "tst_qadditiveblend.moc" -- cgit v1.2.3 From d7a8f157b78ab998b89e1ceb9cb321638f964e7f Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Tue, 31 Jan 2017 16:23:06 +0100 Subject: Add exposure to QCameraLens API Change-Id: I2ad776ec6a7371c7d057d4d5f0feee715e9df188 Reviewed-by: Sean Harmer --- tests/auto/render/qcameralens/tst_qcameralens.cpp | 56 +++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/render/qcameralens/tst_qcameralens.cpp b/tests/auto/render/qcameralens/tst_qcameralens.cpp index aab43d553..adff66dc5 100644 --- a/tests/auto/render/qcameralens/tst_qcameralens.cpp +++ b/tests/auto/render/qcameralens/tst_qcameralens.cpp @@ -63,6 +63,7 @@ private Q_SLOTS: QCOMPARE(cameraLens.right(), 0.5f); QCOMPARE(cameraLens.bottom(), -0.5f); QCOMPARE(cameraLens.top(), 0.5f); + QCOMPARE(cameraLens.exposure(), 0.0f); } void checkPropertyChanges() @@ -241,6 +242,26 @@ private Q_SLOTS: QCOMPARE(cameraLens.top(), newValue); QCOMPARE(spy.count(), 0); } + { + // WHEN + QSignalSpy spy(&cameraLens, SIGNAL(exposureChanged(float))); + const float newValue = -2.0f; + cameraLens.setExposure(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(cameraLens.exposure(), newValue); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().first().toFloat(), -2.0f); + + // WHEN + spy.clear(); + cameraLens.setExposure(newValue); + + // THEN + QCOMPARE(cameraLens.exposure(), newValue); + QCOMPARE(spy.count(), 0); + } { // WHEN QSignalSpy spy(&cameraLens, SIGNAL(projectionMatrixChanged(QMatrix4x4))); @@ -340,6 +361,7 @@ private Q_SLOTS: cameraLens.setFarPlane(1005.0f); cameraLens.setFieldOfView(35.0f); cameraLens.setAspectRatio(16.0f/9.0f); + cameraLens.setExposure(1.0f); // WHEN QVector creationChanges; @@ -357,6 +379,7 @@ private Q_SLOTS: const Qt3DRender::QCameraLensData cloneData = creationChangeData->data; QCOMPARE(cameraLens.projectionMatrix(), cloneData.projectionMatrix); + QCOMPARE(cameraLens.exposure(), cloneData.exposure); QCOMPARE(cameraLens.id(), creationChangeData->subjectId()); QCOMPARE(cameraLens.isEnabled(), true); QCOMPARE(cameraLens.isEnabled(), creationChangeData->isNodeEnabled()); @@ -379,6 +402,7 @@ private Q_SLOTS: const Qt3DRender::QCameraLensData cloneData = creationChangeData->data; QCOMPARE(cameraLens.projectionMatrix(), cloneData.projectionMatrix); + QCOMPARE(cameraLens.exposure(), cloneData.exposure); QCOMPARE(cameraLens.id(), creationChangeData->subjectId()); QCOMPARE(cameraLens.isEnabled(), false); QCOMPARE(cameraLens.isEnabled(), creationChangeData->isNodeEnabled()); @@ -674,6 +698,38 @@ private Q_SLOTS: } + void checkExposureUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::QCameraLens cameraLens; + arbiter.setArbiterOnNode(&cameraLens); + + { + // WHEN + cameraLens.setExposure(2.0f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "exposure"); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + cameraLens.setExposure(2.0f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + void checkProjectionMatrixUpdate() { // GIVEN -- cgit v1.2.3 From 9ae12590ac965ca454b67c27f4411d71ad05ae86 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Tue, 31 Jan 2017 17:09:21 +0100 Subject: Add gamma to QViewport's API Change-Id: Ieced911cf1e51c0befc5ce91e8529a421b5c5a80 Reviewed-by: Sean Harmer --- tests/auto/render/qviewport/tst_qviewport.cpp | 108 ++++++++++++++++++-------- 1 file changed, 75 insertions(+), 33 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/qviewport/tst_qviewport.cpp b/tests/auto/render/qviewport/tst_qviewport.cpp index 87b22e22b..93a2735f2 100644 --- a/tests/auto/render/qviewport/tst_qviewport.cpp +++ b/tests/auto/render/qviewport/tst_qviewport.cpp @@ -46,14 +46,15 @@ private Q_SLOTS: { QTest::addColumn("viewport"); QTest::addColumn("normalizedRect"); + QTest::addColumn("gamma"); Qt3DRender::QViewport *defaultConstructed = new Qt3DRender::QViewport(); - QTest::newRow("defaultConstructed") << defaultConstructed << QRectF(0.0f, 0.0f, 1.0f, 1.0f); + QTest::newRow("defaultConstructed") << defaultConstructed << QRectF(0.0f, 0.0f, 1.0f, 1.0f) << 2.2f; Qt3DRender::QViewport *smallGreenViewport = new Qt3DRender::QViewport(); smallGreenViewport->setNormalizedRect(QRectF(0.2f, 0.2f, 0.6f, 0.6f)); - QTest::newRow("smallGreenViewport") << smallGreenViewport << QRectF(0.2f, 0.2f, 0.6f, 0.6f); - + smallGreenViewport->setGamma(1.8f); + QTest::newRow("smallGreenViewport") << smallGreenViewport << QRectF(0.2f, 0.2f, 0.6f, 0.6f) << 1.8f; } void checkCloning() @@ -61,9 +62,11 @@ private Q_SLOTS: // GIVEN QFETCH(Qt3DRender::QViewport *, viewport); QFETCH(QRectF, normalizedRect); + QFETCH(float, gamma); // THEN QCOMPARE(viewport->normalizedRect(), normalizedRect); + QCOMPARE(viewport->gamma(), gamma); // WHEN Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(viewport); @@ -80,6 +83,7 @@ private Q_SLOTS: QCOMPARE(viewport->isEnabled(), creationChangeData->isNodeEnabled()); QCOMPARE(viewport->metaObject(), creationChangeData->metaObject()); QCOMPARE(viewport->normalizedRect(), cloneData.normalizedRect); + QCOMPARE(viewport->gamma(), cloneData.gamma); delete viewport; } @@ -91,39 +95,77 @@ private Q_SLOTS: QScopedPointer viewport(new Qt3DRender::QViewport()); arbiter.setArbiterOnNode(viewport.data()); - // WHEN - viewport->setNormalizedRect(QRectF(0.5f, 0.5f, 1.0f, 1.0f)); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "normalizedRect"); - QCOMPARE(change->subjectId(), viewport->id()); - QCOMPARE(change->value().value(), QRectF(0.5f, 0.5f, 1.0f, 1.0f)); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + { + // WHEN + viewport->setNormalizedRect(QRectF(0.5f, 0.5f, 1.0f, 1.0f)); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "normalizedRect"); + QCOMPARE(change->subjectId(), viewport->id()); + QCOMPARE(change->value().value(), QRectF(0.5f, 0.5f, 1.0f, 1.0f)); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // WHEN + viewport->setNormalizedRect(QRectF(0.5f, 0.5f, 1.0f, 1.0f)); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + + // WHEN + viewport->setNormalizedRect(QRectF(0.0f, 0.0f, 1.0f, 1.0f)); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "normalizedRect"); + QCOMPARE(change->subjectId(), viewport->id()); + QCOMPARE(change->value().value(), QRectF(0.0f, 0.0f, 1.0f, 1.0f)); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + } arbiter.events.clear(); - // WHEN - viewport->setNormalizedRect(QRectF(0.5f, 0.5f, 1.0f, 1.0f)); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - - // WHEN - viewport->setNormalizedRect(QRectF(0.0f, 0.0f, 1.0f, 1.0f)); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "normalizedRect"); - QCOMPARE(change->subjectId(), viewport->id()); - QCOMPARE(change->value().value(), QRectF(0.0f, 0.0f, 1.0f, 1.0f)); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - + { + // WHEN + viewport->setGamma(1.8f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "gamma"); + QCOMPARE(change->subjectId(), viewport->id()); + QCOMPARE(change->value().toFloat(), 1.8f); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // WHEN + viewport->setGamma(1.8f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + + // WHEN + viewport->setGamma(2.0f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "gamma"); + QCOMPARE(change->subjectId(), viewport->id()); + QCOMPARE(change->value().toFloat(), 2.0f); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + } } }; -- cgit v1.2.3 From 574fab140f3c389c59d955c092d30e0ad1d0bafb Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Tue, 31 Jan 2017 17:27:32 +0100 Subject: QForwardRenderer exposes the gamma of its viewport Change-Id: I67d5d23bdec1c01ef3e31cfdd47f4e4dd8eeacf4 Reviewed-by: Sean Harmer --- .../qforwardrenderer/tst_qforwardrenderer.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/extras/qforwardrenderer/tst_qforwardrenderer.cpp b/tests/auto/extras/qforwardrenderer/tst_qforwardrenderer.cpp index 0d80f0e35..d4d856a7c 100644 --- a/tests/auto/extras/qforwardrenderer/tst_qforwardrenderer.cpp +++ b/tests/auto/extras/qforwardrenderer/tst_qforwardrenderer.cpp @@ -56,6 +56,7 @@ private Q_SLOTS: QVERIFY(forwardRenderer.camera() == nullptr); QCOMPARE(forwardRenderer.externalRenderTargetSize(), QSize()); QVERIFY(forwardRenderer.isFrustumCullingEnabled()); + QCOMPARE(forwardRenderer.gamma(), 2.2f); } void checkPropertyChanges() @@ -189,6 +190,26 @@ private Q_SLOTS: QCOMPARE(spy.count(), 1); QVERIFY(spy.takeFirst().takeFirst().toBool()); } + { + // WHEN + QSignalSpy spy(&forwardRenderer, SIGNAL(gammaChanged(float))); + const float newValue = 1.8f; + forwardRenderer.setGamma(newValue); + + // THEN + QCOMPARE(forwardRenderer.gamma(), newValue); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().first().toFloat(), 1.8f); + + // WHEN + spy.clear(); + forwardRenderer.setClearColor(newValue); + + // THEN + QCOMPARE(forwardRenderer.gamma(), newValue); + QCOMPARE(spy.count(), 0); + + } } }; -- cgit v1.2.3 From f471bf3ac9ecf9d8149dd8916d057a31af51255f Mon Sep 17 00:00:00 2001 From: Wieland Hagen Date: Wed, 28 Dec 2016 19:56:38 +0700 Subject: Fix node de-registration from scene on deletion/reparenting QNodePrivate::unsetSceneHelper() used to be broken, in that it set the m_scene of the the item that the NodeVisitor functor was executed on. Subsequent calls for child nodes would then have a m_scene == nullptr, and could thus not be de-registered. This patch fixes this behavior by treating each node's m_scene separately Task-number: QTBUG-57571 Change-Id: I779caadd6957a97514fd105cd16935c3edc9f41f Reviewed-by: Paul Lemire --- tests/auto/core/qscene/tst_qscene.cpp | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/core/qscene/tst_qscene.cpp b/tests/auto/core/qscene/tst_qscene.cpp index eabcc96fb..561a67765 100644 --- a/tests/auto/core/qscene/tst_qscene.cpp +++ b/tests/auto/core/qscene/tst_qscene.cpp @@ -48,6 +48,7 @@ private slots: void removeObservable(); void removeNodeObservable(); void addChildNode(); + void deleteChildNode(); void removeChildNode(); void addEntityForComponent(); void removeEntityForComponent(); @@ -280,6 +281,69 @@ void tst_QScene::addChildNode() } } +void tst_QScene::deleteChildNode() +{ + // GIVEN + Qt3DCore::QScene *scene = new Qt3DCore::QScene; + + QList nodes1, nodes2; + + Qt3DCore::QNode *root1 = new tst_Node(); + Qt3DCore::QNode *root2 = new tst_Node(); + Qt3DCore::QNodePrivate::get(root1)->setScene(scene); + Qt3DCore::QNodePrivate::get(root2)->setScene(scene); + + // WHEN + scene->addObservable(root1); + scene->addObservable(root2); + // THEN + QVERIFY(scene->lookupNode(root1->id()) == root1); + QVERIFY(scene->lookupNode(root2->id()) == root2); + + // WHEN + for (int i = 0; i < 10; i++) { + Qt3DCore::QNode *child1 = new tst_Node(); + child1->setParent(nodes1.isEmpty() ? root1 : nodes1.last()); + nodes1.append(child1); + + Qt3DCore::QNode *child2 = new tst_Node(); + child2->setParent(nodes2.isEmpty() ? root2 : nodes2.last()); + nodes2.append(child2); + } + QCoreApplication::processEvents(); + + // THEN + for (Qt3DCore::QNode *n : qAsConst(nodes1)) { + QVERIFY(scene->lookupNode(n->id()) == n); + } + for (Qt3DCore::QNode *n : qAsConst(nodes2)) { + QVERIFY(scene->lookupNode(n->id()) == n); + } + + // gather node IDs + Qt3DCore::QNodeIdVector root1ChildIds; + for (Qt3DCore::QNode *n : qAsConst(nodes1)) + root1ChildIds << n->id(); + + // WHEN + delete root1; + QCoreApplication::processEvents(); + + // THEN + for (Qt3DCore::QNodeId id : qAsConst(root1ChildIds)) { + QVERIFY(scene->lookupNode(id) == nullptr); + } + + // WHEN + nodes2.first()->setParent(static_cast(nullptr)); + QCoreApplication::processEvents(); + + // THEN + for (Qt3DCore::QNode *n : qAsConst(nodes2)) { + QVERIFY(scene->lookupNode(n->id()) == nullptr); + } +} + void tst_QScene::removeChildNode() { // GIVEN -- cgit v1.2.3 From faa8fc18bfeca06de6c4a7bdbb14e1be9eb96f54 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Sun, 5 Feb 2017 14:29:05 +0000 Subject: Fix double -> float conversion warnings Change-Id: I7eac42f170de92bb34b69e72855e0b5de514de8c Reviewed-by: Mike Krus Reviewed-by: Paul Lemire --- tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp b/tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp index 9bc234c50..58e2373f5 100644 --- a/tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp +++ b/tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp @@ -1302,7 +1302,7 @@ private Q_SLOTS: // WHEN m_func->glUseProgram(shaderProgram.programId()); - GLfloat values[16] = { 454.0f, 350.0f, 883.0f, 355.0f, 1340.0f, 1584.0f, 1200.0f, 427.0f, 396.0f, 1603.0f, 55.0f, 5.7, 383.0f, 6.2f, 5.3f, 327.0f }; + GLfloat values[16] = { 454.0f, 350.0f, 883.0f, 355.0f, 1340.0f, 1584.0f, 1200.0f, 427.0f, 396.0f, 1603.0f, 55.0f, 5.7f, 383.0f, 6.2f, 5.3f, 327.0f }; const GLint location = shaderProgram.uniformLocation("m4"); m_glHelper.glUniformMatrix4fv(location, 1, values); -- cgit v1.2.3 From d1271dba68f03610c27e87963653bf1600b5f659 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Tue, 7 Feb 2017 11:07:26 +0000 Subject: Deliver all events by default unless marked as intermediate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change inverts m_final flag on property change events so that now, all events are delivered by default. The animation aspect now marks intermediate calculated changes and these are not delivered unless the user subscribes to them. Change-Id: Ide6c30b29a91ed874d47c52d0ee1352f6680c3d8 Reviewed-by: Antti Määttä --- .../animation/animationclip/tst_animationclip.cpp | 3 +- tests/auto/core/qpostman/tst_qpostman.cpp | 108 ++++++++++++--------- tests/auto/input/action/tst_action.cpp | 2 - tests/auto/input/axis/tst_axis.cpp | 2 - .../input/axisaccumulator/tst_axisaccumulator.cpp | 3 - .../tst_physicaldeviceproxy.cpp | 1 - tests/auto/render/buffer/tst_buffer.cpp | 2 - .../auto/render/objectpicker/tst_objectpicker.cpp | 6 -- tests/auto/render/sceneloader/tst_sceneloader.cpp | 2 - 9 files changed, 63 insertions(+), 66 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationclip/tst_animationclip.cpp b/tests/auto/animation/animationclip/tst_animationclip.cpp index f0b45bfeb..1a61dec2c 100644 --- a/tests/auto/animation/animationclip/tst_animationclip.cpp +++ b/tests/auto/animation/animationclip/tst_animationclip.cpp @@ -134,7 +134,8 @@ private Q_SLOTS: Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); QCOMPARE(change->propertyName(), "duration"); QCOMPARE(change->value().toFloat(), backendClip.duration()); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isFinal, true); + QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isIntermediate, + false); arbiter.events.clear(); diff --git a/tests/auto/core/qpostman/tst_qpostman.cpp b/tests/auto/core/qpostman/tst_qpostman.cpp index e51c21b59..1dabf143f 100644 --- a/tests/auto/core/qpostman/tst_qpostman.cpp +++ b/tests/auto/core/qpostman/tst_qpostman.cpp @@ -38,21 +38,22 @@ #include #include "testpostmanarbiter.h" +using namespace Qt3DCore; namespace { -class NodeChangeReceiver: public Qt3DCore::QNode +class NodeChangeReceiver: public QNode { public: - NodeChangeReceiver(Qt3DCore::QNode *parent = nullptr) - : Qt3DCore::QNode(parent) + NodeChangeReceiver(QNode *parent = nullptr) + : QNode(parent) , m_hasReceivedChange(false) {} inline bool hasReceivedChange() const { return m_hasReceivedChange; } protected: - void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &) Q_DECL_OVERRIDE + void sceneChangeEvent(const QSceneChangePtr &) Q_DECL_OVERRIDE { m_hasReceivedChange = true; } @@ -72,42 +73,42 @@ private Q_SLOTS: void checkSetScene() { // GIVEN - Qt3DCore::QPostman postman; + QPostman postman; // THEN - QVERIFY(Qt3DCore::QPostmanPrivate::get(&postman)->m_scene == nullptr); + QVERIFY(QPostmanPrivate::get(&postman)->m_scene == nullptr); // WHEN - Qt3DCore::QScene scene; + QScene scene; postman.setScene(&scene); // THEN - QCOMPARE(Qt3DCore::QPostmanPrivate::get(&postman)->m_scene, &scene); + QCOMPARE(QPostmanPrivate::get(&postman)->m_scene, &scene); } void checkSceneChangeEvent() { // GIVEN - QScopedPointer scene(new Qt3DCore::QScene); - Qt3DCore::QPostman postman; + QScopedPointer scene(new QScene); + QPostman postman; TestArbiter arbiter; - Qt3DCore::QNode rootNode; + QNode rootNode; NodeChangeReceiver *receiverNode = new NodeChangeReceiver(); - Qt3DCore::QNodePrivate::get(&rootNode)->m_scene = scene.data(); + 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(receiverNode)->setParent(&rootNode); + static_cast(receiverNode)->setParent(&rootNode); QCoreApplication::processEvents(); // THEN QCOMPARE(receiverNode->hasReceivedChange(), false); - QCOMPARE(Qt3DCore::QNodePrivate::get(receiverNode)->m_scene, scene.data()); + QCOMPARE(QNodePrivate::get(receiverNode)->m_scene, scene.data()); // WHEN - Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(receiverNode->id())); + QPropertyUpdatedChangePtr updateChange(new QPropertyUpdatedChange(receiverNode->id())); updateChange->setValue(1584); updateChange->setPropertyName("someName"); postman.sceneChangeEvent(updateChange); @@ -120,8 +121,8 @@ private Q_SLOTS: void checkNotifyBackend() { // GIVEN - QScopedPointer scene(new Qt3DCore::QScene); - Qt3DCore::QPostman postman; + QScopedPointer scene(new QScene); + QPostman postman; TestArbiter arbiter; scene->setArbiter(&arbiter); @@ -131,7 +132,7 @@ private Q_SLOTS: QCOMPARE(arbiter.events.size(), 0); // WHEN - Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); + QPropertyUpdatedChangePtr updateChange(new QPropertyUpdatedChange(QNodeId())); updateChange->setValue(1584); updateChange->setPropertyName("someName"); postman.notifyBackend(updateChange); @@ -145,62 +146,72 @@ private Q_SLOTS: void checkShouldNotifyFrontend() { // GIVEN - QScopedPointer scene(new Qt3DCore::QScene); - Qt3DCore::QPostman postman; + QScopedPointer scene(new QScene); + QPostman postman; TestArbiter arbiter; - Qt3DCore::QNode rootNode; + QNode rootNode; NodeChangeReceiver *receiverNode = new NodeChangeReceiver(); - Qt3DCore::QNodePrivate::get(&rootNode)->m_scene = scene.data(); + 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(receiverNode)->setParent(&rootNode); + static_cast(receiverNode)->setParent(&rootNode); QCoreApplication::processEvents(); { // WHEN - Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(receiverNode->id())); + auto updateChange = QPropertyUpdatedChangePtr::create(receiverNode->id()); updateChange->setValue(1584); updateChange->setPropertyName("someName"); - // THEN -> we don't track properties by default Qt3DCore::QNode::DontTrackProperties - QCOMPARE(postman.shouldNotifyFrontend(updateChange), false); + + // THEN -> we do track properties by default QNode::DefaultTrackMode + // (unless marked as an intermediate change) + QCOMPARE(postman.shouldNotifyFrontend(updateChange), true); } { // WHEN - receiverNode->setPropertyTrackMode(Qt3DCore::QNode::TrackAllPropertiesMode); + receiverNode->setPropertyTrackMode(QNode::TrackAllPropertiesMode); - Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(receiverNode->id())); + 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 + // THEN -> we do track properties marked as intermediate when + // using TrackAllPropertiesMode QCOMPARE(postman.shouldNotifyFrontend(updateChange), true); } { // GIVEN - receiverNode->setPropertyTrackMode(Qt3DCore::QNode::TrackNamedPropertiesMode); + receiverNode->setPropertyTrackMode(QNode::TrackNamedPropertiesMode); receiverNode->setTrackedProperties(QStringList() << QStringLiteral("vette")); { // WHEN - Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(receiverNode->id())); + 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 + // THEN -> we don't track properties by default, unless named when + // using TrackNamedPropertiesMode QCOMPARE(postman.shouldNotifyFrontend(updateChange), false); } { // WHEN - Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(receiverNode->id())); + 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); @@ -210,11 +221,11 @@ private Q_SLOTS: { // GIVEN receiverNode->setTrackedProperties(QStringList() << QStringLiteral("vette")); - receiverNode->setPropertyTrackMode(Qt3DCore::QNode::TrackAllPropertiesMode); + receiverNode->setPropertyTrackMode(QNode::TrackAllPropertiesMode); { // WHEN - Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(receiverNode->id())); + auto updateChange = QPropertyUpdatedChangePtr::create(receiverNode->id()); updateChange->setValue(1584); updateChange->setPropertyName("someName"); @@ -224,7 +235,7 @@ private Q_SLOTS: { // WHEN - Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(receiverNode->id())); + auto updateChange = QPropertyUpdatedChangePtr::create(receiverNode->id()); updateChange->setValue(1584); updateChange->setPropertyName("vette"); @@ -236,28 +247,30 @@ private Q_SLOTS: { // GIVEN receiverNode->setTrackedProperties(QStringList()); - receiverNode->setPropertyTrackMode(Qt3DCore::QNode::DefaultTrackMode); + receiverNode->setPropertyTrackMode(QNode::DefaultTrackMode); { // WHEN - Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(receiverNode->id())); + auto updateChange = QPropertyUpdatedChangePtr::create(receiverNode->id()); updateChange->setValue(1584); updateChange->setPropertyName("someName"); - // THEN -> we don't track properties by default - QCOMPARE(postman.shouldNotifyFrontend(updateChange), false); + // THEN -> we do track properties by default, unless marked as intermediate + QCOMPARE(postman.shouldNotifyFrontend(updateChange), true); } { // WHEN - Qt3DCore::QPropertyNodeAddedChangePtr addedChange(new Qt3DCore::QPropertyNodeAddedChange(receiverNode->id(), receiverNode)); + auto addedChange + = QPropertyNodeAddedChangePtr::create(receiverNode->id(), receiverNode); // THEN -> only QPropertyUpdatedChangePtr are filtered QCOMPARE(postman.shouldNotifyFrontend(addedChange), true); } { // WHEN - Qt3DCore::QPropertyNodeRemovedChangePtr removedChange(new Qt3DCore::QPropertyNodeRemovedChange(receiverNode->id(), receiverNode)); + auto removedChange + = QPropertyNodeRemovedChangePtr::create(receiverNode->id(), receiverNode); // THEN -> only QPropertyUpdatedChangePtr are filtered QCOMPARE(postman.shouldNotifyFrontend(removedChange), true); @@ -267,24 +280,25 @@ private Q_SLOTS: { // GIVEN receiverNode->setTrackedProperties(QStringList()); - receiverNode->setPropertyTrackMode(Qt3DCore::QNode::DefaultTrackMode); + receiverNode->setPropertyTrackMode(QNode::DefaultTrackMode); { // WHEN - Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(receiverNode->id())); + 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 + // THEN -> we don't track intermediate properties by default QCOMPARE(postman.shouldNotifyFrontend(updateChange), false); } { // WHEN - Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(receiverNode->id())); + auto updateChange = QPropertyUpdatedChangePtr::create(receiverNode->id()); updateChange->setValue(1584); updateChange->setPropertyName("someName"); - Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(updateChange.data())->m_isFinal = true; // THEN QCOMPARE(postman.shouldNotifyFrontend(updateChange), true); diff --git a/tests/auto/input/action/tst_action.cpp b/tests/auto/input/action/tst_action.cpp index da27446f6..91ca2f794 100644 --- a/tests/auto/input/action/tst_action.cpp +++ b/tests/auto/input/action/tst_action.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include "testpostmanarbiter.h" class DummyActionInput : public Qt3DInput::QActionInput @@ -160,7 +159,6 @@ private Q_SLOTS: Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); QCOMPARE(change->propertyName(), "active"); QCOMPARE(change->value().toBool(), backendAction.actionTriggered()); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isFinal, true); arbiter.events.clear(); diff --git a/tests/auto/input/axis/tst_axis.cpp b/tests/auto/input/axis/tst_axis.cpp index 90f774489..dc8b225ba 100644 --- a/tests/auto/input/axis/tst_axis.cpp +++ b/tests/auto/input/axis/tst_axis.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include "testpostmanarbiter.h" class DummyAxisInput : public Qt3DInput::QAbstractAxisInput @@ -160,7 +159,6 @@ private Q_SLOTS: Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); QCOMPARE(change->propertyName(), "value"); QCOMPARE(change->value().toFloat(), backendAxis.axisValue()); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isFinal, true); arbiter.events.clear(); diff --git a/tests/auto/input/axisaccumulator/tst_axisaccumulator.cpp b/tests/auto/input/axisaccumulator/tst_axisaccumulator.cpp index 9728ac0d0..94cb71030 100644 --- a/tests/auto/input/axisaccumulator/tst_axisaccumulator.cpp +++ b/tests/auto/input/axisaccumulator/tst_axisaccumulator.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include "testpostmanarbiter.h" class tst_AxisAccumulator: public Qt3DCore::QBackendNodeTester @@ -170,7 +169,6 @@ private Q_SLOTS: Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); QCOMPARE(change->propertyName(), "value"); QCOMPARE(change->value().toFloat(), backendAxisAccumulator.value()); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isFinal, true); arbiter.events.clear(); @@ -193,7 +191,6 @@ private Q_SLOTS: Qt3DCore::QPropertyUpdatedChangePtr velocityChange = arbiter.events.first().staticCast(); QCOMPARE(velocityChange->propertyName(), "velocity"); QCOMPARE(velocityChange->value().toFloat(), backendAxisAccumulator.velocity()); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isFinal, true); arbiter.events.clear(); diff --git a/tests/auto/input/physicaldeviceproxy/tst_physicaldeviceproxy.cpp b/tests/auto/input/physicaldeviceproxy/tst_physicaldeviceproxy.cpp index a5f54aec9..d19e69ecc 100644 --- a/tests/auto/input/physicaldeviceproxy/tst_physicaldeviceproxy.cpp +++ b/tests/auto/input/physicaldeviceproxy/tst_physicaldeviceproxy.cpp @@ -128,7 +128,6 @@ private Q_SLOTS: QCOMPARE(change->value().value(), &physicalDevice); QCOMPARE(change->subjectId(), backendPhysicalDeviceProxy.peerId()); QCOMPARE(backendPhysicalDeviceProxy.physicalDeviceId(), physicalDevice.id()); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isFinal, true); } void checkCleanupState() diff --git a/tests/auto/render/buffer/tst_buffer.cpp b/tests/auto/render/buffer/tst_buffer.cpp index da5f74dd6..b06425bd7 100644 --- a/tests/auto/render/buffer/tst_buffer.cpp +++ b/tests/auto/render/buffer/tst_buffer.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include "testpostmanarbiter.h" #include "testrenderer.h" @@ -234,7 +233,6 @@ private Q_SLOTS: Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); QCOMPARE(change->propertyName(), "data"); QCOMPARE(change->value().toByteArray(), QByteArrayLiteral("454")); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isFinal, true); arbiter.events.clear(); diff --git a/tests/auto/render/objectpicker/tst_objectpicker.cpp b/tests/auto/render/objectpicker/tst_objectpicker.cpp index c0e986e08..4ba57b0ad 100644 --- a/tests/auto/render/objectpicker/tst_objectpicker.cpp +++ b/tests/auto/render/objectpicker/tst_objectpicker.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include "testpostmanarbiter.h" #include "testrenderer.h" @@ -130,7 +129,6 @@ private Q_SLOTS: QCOMPARE(arbiter.events.count(), 1); Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); QCOMPARE(change->propertyName(), "pressed"); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isFinal, true); arbiter.events.clear(); @@ -141,7 +139,6 @@ private Q_SLOTS: QCOMPARE(arbiter.events.count(), 1); change = arbiter.events.first().staticCast(); QCOMPARE(change->propertyName(), "released"); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isFinal, true); arbiter.events.clear(); @@ -152,7 +149,6 @@ private Q_SLOTS: QCOMPARE(arbiter.events.count(), 1); change = arbiter.events.first().staticCast(); QCOMPARE(change->propertyName(), "clicked"); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isFinal, true); arbiter.events.clear(); @@ -163,7 +159,6 @@ private Q_SLOTS: QCOMPARE(arbiter.events.count(), 1); change = arbiter.events.first().staticCast(); QCOMPARE(change->propertyName(), "entered"); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isFinal, true); arbiter.events.clear(); @@ -174,7 +169,6 @@ private Q_SLOTS: QCOMPARE(arbiter.events.count(), 1); change = arbiter.events.first().staticCast(); QCOMPARE(change->propertyName(), "exited"); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isFinal, true); arbiter.events.clear(); } diff --git a/tests/auto/render/sceneloader/tst_sceneloader.cpp b/tests/auto/render/sceneloader/tst_sceneloader.cpp index edd6fabda..cd6d76a5a 100644 --- a/tests/auto/render/sceneloader/tst_sceneloader.cpp +++ b/tests/auto/render/sceneloader/tst_sceneloader.cpp @@ -147,7 +147,6 @@ private Q_SLOTS: QCOMPARE(arbiter.events.count(), 1); QCOMPARE(change->propertyName(), "scene"); QCOMPARE(change->value().value(), &subtree); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isFinal, true); arbiter.events.clear(); } @@ -170,7 +169,6 @@ private Q_SLOTS: QCOMPARE(arbiter.events.count(), 1); QCOMPARE(change->propertyName(), "status"); QCOMPARE(change->value().value(), Qt3DRender::QSceneLoader::Ready); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isFinal, true); arbiter.events.clear(); } -- cgit v1.2.3 From 387e60071b97234c135769401b5d288574d4fb3d Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Thu, 9 Feb 2017 13:12:45 +0000 Subject: Fix Clang warnings: silence unused variables Change-Id: I2dd185c1ae098034055fb1bbf7474554f8d1d13c Reviewed-by: Sean Harmer --- tests/auto/core/nodes/tst_nodes.cpp | 2 +- tests/auto/render/gltfplugins/tst_gltfplugins.cpp | 2 ++ tests/auto/render/texturedatamanager/tst_texturedatamanager.cpp | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/core/nodes/tst_nodes.cpp b/tests/auto/core/nodes/tst_nodes.cpp index 407e8d816..90e0084e8 100644 --- a/tests/auto/core/nodes/tst_nodes.cpp +++ b/tests/auto/core/nodes/tst_nodes.cpp @@ -105,7 +105,7 @@ public: void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &) Q_DECL_FINAL {}; void setScene(Qt3DCore::QScene *) Q_DECL_FINAL {}; void notifyBackend(const Qt3DCore::QSceneChangePtr &change) Q_DECL_FINAL; - bool shouldNotifyFrontend(const Qt3DCore::QSceneChangePtr &changee) Q_DECL_FINAL { return false; } + bool shouldNotifyFrontend(const Qt3DCore::QSceneChangePtr &changee) Q_DECL_FINAL { Q_UNUSED(changee); return false; } private: ObserverSpy *m_spy; diff --git a/tests/auto/render/gltfplugins/tst_gltfplugins.cpp b/tests/auto/render/gltfplugins/tst_gltfplugins.cpp index a800fc1fa..33aff94f8 100644 --- a/tests/auto/render/gltfplugins/tst_gltfplugins.cpp +++ b/tests/auto/render/gltfplugins/tst_gltfplugins.cpp @@ -139,8 +139,10 @@ private: Qt3DRender::QEffect *createOnTopEffect(); QTemporaryDir *m_exportDir; +#ifdef VISUAL_CHECK Qt3DExtras::Qt3DWindow *m_view1; Qt3DExtras::Qt3DWindow *m_view2; +#endif Qt3DCore::QEntity *m_sceneRoot1; Qt3DCore::QEntity *m_sceneRoot2; QHash m_entityMap; diff --git a/tests/auto/render/texturedatamanager/tst_texturedatamanager.cpp b/tests/auto/render/texturedatamanager/tst_texturedatamanager.cpp index b76495d93..5ba43aedc 100644 --- a/tests/auto/render/texturedatamanager/tst_texturedatamanager.cpp +++ b/tests/auto/render/texturedatamanager/tst_texturedatamanager.cpp @@ -58,7 +58,9 @@ class FakeData public: explicit FakeData(int value) : m_value(value) - {} + { + Q_UNUSED(m_value); + } private: int m_value; -- cgit v1.2.3 From 74d78e55ecd932bf2d17657906b3f67de5291520 Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Thu, 9 Feb 2017 13:13:45 +0000 Subject: Fix Clang warnings: missing enum values in switch Change-Id: Id5087114283d5ef978ebb77d415f67c6254cbee0 Reviewed-by: Sean Harmer --- tests/auto/render/geometryloaders/tst_geometryloaders.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/render/geometryloaders/tst_geometryloaders.cpp b/tests/auto/render/geometryloaders/tst_geometryloaders.cpp index 15600dc75..7b9f09d23 100644 --- a/tests/auto/render/geometryloaders/tst_geometryloaders.cpp +++ b/tests/auto/render/geometryloaders/tst_geometryloaders.cpp @@ -102,6 +102,9 @@ void tst_geometryloaders::testOBJLoader() case QAttribute::VertexAttribute: QCOMPARE(attr->count(), 24u); break; + default: + Q_UNREACHABLE(); + break; } } @@ -141,6 +144,9 @@ void tst_geometryloaders::testPLYLoader() case QAttribute::VertexAttribute: QCOMPARE(attr->count(), 24u); break; + default: + Q_UNREACHABLE(); + break; } } @@ -212,6 +218,9 @@ void tst_geometryloaders::testGLTFLoader() case QAttribute::VertexAttribute: QCOMPARE(attr->count(), 24u); break; + default: + Q_UNREACHABLE(); + break; } } -- cgit v1.2.3 From 7a4ab54b9265ac17bdd3355b5ec26ab82dacddde Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Thu, 9 Feb 2017 13:14:28 +0000 Subject: Fix Clang warnings: missing override declarations Change-Id: Ifd6d83cd38358eef44af74e887d3a649917d764c Reviewed-by: Sean Harmer --- tests/auto/render/textures/tst_textures.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/textures/tst_textures.cpp b/tests/auto/render/textures/tst_textures.cpp index 9246bba34..58cb76c94 100644 --- a/tests/auto/render/textures/tst_textures.cpp +++ b/tests/auto/render/textures/tst_textures.cpp @@ -52,11 +52,11 @@ class TestImageDataGenerator : public Qt3DRender::QTextureImageDataGenerator public: TestImageDataGenerator(int id) : m_id(id) {} - Qt3DRender::QTextureImageDataPtr operator ()() { + Qt3DRender::QTextureImageDataPtr operator ()() Q_DECL_OVERRIDE { return Qt3DRender::QTextureImageDataPtr::create(); } - bool operator ==(const Qt3DRender::QTextureImageDataGenerator &other) const { + bool operator ==(const Qt3DRender::QTextureImageDataGenerator &other) const Q_DECL_OVERRIDE { const TestImageDataGenerator *otherFunctor = functor_cast(&other); return (otherFunctor != Q_NULLPTR && otherFunctor->m_id == m_id); } @@ -73,11 +73,11 @@ class TestTextureGenerator : public Qt3DRender::QTextureGenerator public: TestTextureGenerator(int id) : m_id(id) {} - Qt3DRender::QTextureDataPtr operator ()() { + Qt3DRender::QTextureDataPtr operator ()() Q_DECL_OVERRIDE { return Qt3DRender::QTextureDataPtr::create(); } - bool operator ==(const Qt3DRender::QTextureGenerator &other) const { + bool operator ==(const Qt3DRender::QTextureGenerator &other) const Q_DECL_OVERRIDE { const TestTextureGenerator *otherFunctor = functor_cast(&other); return (otherFunctor != Q_NULLPTR && otherFunctor->m_id == m_id); } -- cgit v1.2.3 From 9e0571eedd75be6761bfc8ec32c07042379d66f9 Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Thu, 9 Feb 2017 13:15:08 +0000 Subject: Fix Clang warnings: wrong types in enum comparisons Change-Id: Ib3795f141eaa65d76c8e7aeda4d8a9f2531c7205 Reviewed-by: Sean Harmer --- tests/auto/render/gltfplugins/tst_gltfplugins.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/render/gltfplugins/tst_gltfplugins.cpp b/tests/auto/render/gltfplugins/tst_gltfplugins.cpp index 33aff94f8..e5a0eef21 100644 --- a/tests/auto/render/gltfplugins/tst_gltfplugins.cpp +++ b/tests/auto/render/gltfplugins/tst_gltfplugins.cpp @@ -783,7 +783,7 @@ void tst_gltfPlugins::compareComponents(Qt3DCore::QComponent *c1, Qt3DCore::QCom auto property = c1->metaObject()->property(i); auto v1 = c1->property(property.name()); auto v2 = c2->property(property.name()); - if (v1.type() == QMetaType::Bool) { + if (v1.type() == QVariant::Bool) { QCOMPARE(v1.toBool(), v2.toBool()); } else if (v1.type() == QVariant::Color) { QCOMPARE(v1.value(), v2.value()); -- cgit v1.2.3 From be8099cd83a9fedf84508538ab49a86a41fc61d6 Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Fri, 10 Feb 2017 22:08:28 +0000 Subject: Unit test for bounding spheres Change-Id: Iee1e7aeaf43a4b783a914d808e2e7ac1e215b263 Reviewed-by: Sean Harmer --- .../auto/render/boundingsphere/boundingsphere.pro | 17 ++ .../auto/render/boundingsphere/boundingsphere.qrc | 6 + tests/auto/render/boundingsphere/cube.qml | 69 +++++++ tests/auto/render/boundingsphere/sphere.qml | 69 +++++++ .../render/boundingsphere/tst_boundingsphere.cpp | 201 +++++++++++++++++++++ tests/auto/render/render.pro | 1 + 6 files changed, 363 insertions(+) create mode 100644 tests/auto/render/boundingsphere/boundingsphere.pro create mode 100644 tests/auto/render/boundingsphere/boundingsphere.qrc create mode 100644 tests/auto/render/boundingsphere/cube.qml create mode 100644 tests/auto/render/boundingsphere/sphere.qml create mode 100644 tests/auto/render/boundingsphere/tst_boundingsphere.cpp (limited to 'tests/auto') diff --git a/tests/auto/render/boundingsphere/boundingsphere.pro b/tests/auto/render/boundingsphere/boundingsphere.pro new file mode 100644 index 000000000..cebba17e7 --- /dev/null +++ b/tests/auto/render/boundingsphere/boundingsphere.pro @@ -0,0 +1,17 @@ +TEMPLATE = app + +TARGET = tst_boundingsphere +QT += core-private 3dcore 3dcore-private 3drender 3drender-private 3dextras testlib + +CONFIG += testcase + +SOURCES += tst_boundingsphere.cpp + +include(../commons/commons.pri) +include(../../core/common/common.pri) +include(../qmlscenereader/qmlscenereader.pri) +# Extra dependencies to build test scenes needed by the tests +QT += quick 3dquick 3dquick-private 3dextras 3dquickextras + +RESOURCES += \ + boundingsphere.qrc diff --git a/tests/auto/render/boundingsphere/boundingsphere.qrc b/tests/auto/render/boundingsphere/boundingsphere.qrc new file mode 100644 index 000000000..5ea2cb958 --- /dev/null +++ b/tests/auto/render/boundingsphere/boundingsphere.qrc @@ -0,0 +1,6 @@ + + + sphere.qml + cube.qml + + diff --git a/tests/auto/render/boundingsphere/cube.qml b/tests/auto/render/boundingsphere/cube.qml new file mode 100644 index 000000000..11d6d4db1 --- /dev/null +++ b/tests/auto/render/boundingsphere/cube.qml @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 + +Entity { + id: sceneRoot + + components: [ ] + + // Parent Entity + Entity { + + components: [ + CuboidMesh { id: testMesh; objectName: "testMesh" }, + PhongMaterial { id: material } + ] + } + +} diff --git a/tests/auto/render/boundingsphere/sphere.qml b/tests/auto/render/boundingsphere/sphere.qml new file mode 100644 index 000000000..1f0e2245a --- /dev/null +++ b/tests/auto/render/boundingsphere/sphere.qml @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 + +Entity { + id: sceneRoot + + components: [ ] + + // Parent Entity + Entity { + + components: [ + SphereMesh { id: testMesh; objectName: "testMesh" }, + PhongMaterial { id: material } + ] + } + +} diff --git a/tests/auto/render/boundingsphere/tst_boundingsphere.cpp b/tests/auto/render/boundingsphere/tst_boundingsphere.cpp new file mode 100644 index 000000000..fcbfaf6ba --- /dev/null +++ b/tests/auto/render/boundingsphere/tst_boundingsphere.cpp @@ -0,0 +1,201 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 "qmlscenereader.h" +#include "testpostmanarbiter.h" + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class TestAspect : public Qt3DRender::QRenderAspect +{ +public: + TestAspect(Qt3DCore::QNode *root) + : Qt3DRender::QRenderAspect(Qt3DRender::QRenderAspect::Synchronous) + , m_sceneRoot(nullptr) + { + QRenderAspect::onRegistered(); + + const Qt3DCore::QNodeCreatedChangeGenerator generator(root); + const QVector creationChanges = generator.creationChanges(); + + d_func()->setRootAndCreateNodes(qobject_cast(root), creationChanges); + + Render::Entity *rootEntity = nodeManagers()->lookupResource(rootEntityId()); + Q_ASSERT(rootEntity); + m_sceneRoot = rootEntity; + } + + ~TestAspect() + { + QRenderAspect::onUnregistered(); + } + + void onRegistered() { QRenderAspect::onRegistered(); } + void onUnregistered() { QRenderAspect::onUnregistered(); } + + Qt3DRender::Render::NodeManagers *nodeManagers() const { return d_func()->m_renderer->nodeManagers(); } + Qt3DRender::Render::FrameGraphNode *frameGraphRoot() const { return d_func()->m_renderer->frameGraphRoot(); } + Qt3DRender::Render::RenderSettings *renderSettings() const { return d_func()->m_renderer->settings(); } + Qt3DRender::Render::Entity *sceneRoot() const { return m_sceneRoot; } + +private: + Render::Entity *m_sceneRoot; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +namespace { + +void runRequiredJobs(Qt3DRender::TestAspect *test) +{ + Qt3DRender::Render::UpdateWorldTransformJob updateWorldTransform; + updateWorldTransform.setRoot(test->sceneRoot()); + updateWorldTransform.run(); + + // For each buffer + QVector bufferHandles = test->nodeManagers()->bufferManager()->activeHandles(); + for (auto bufferHandle : bufferHandles) { + Qt3DRender::Render::LoadBufferJob loadBuffer(bufferHandle); + loadBuffer.setNodeManager(test->nodeManagers()); + loadBuffer.run(); + } + + Qt3DRender::Render::CalculateBoundingVolumeJob calcBVolume; + calcBVolume.setManagers(test->nodeManagers()); + calcBVolume.setRoot(test->sceneRoot()); + calcBVolume.run(); + + Qt3DRender::Render::UpdateWorldBoundingVolumeJob updateWorldBVolume; + updateWorldBVolume.setManager(test->nodeManagers()->renderNodesManager()); + updateWorldBVolume.run(); + + Qt3DRender::Render::ExpandBoundingVolumeJob expandBVolume; + expandBVolume.setRoot(test->sceneRoot()); + expandBVolume.run(); + + Qt3DRender::Render::UpdateMeshTriangleListJob updateTriangleList; + updateTriangleList.setManagers(test->nodeManagers()); + updateTriangleList.run(); + + // For each geometry id + QVector geometryRenderHandles = test->nodeManagers()->geometryRendererManager()->activeHandles(); + for (auto geometryRenderHandle : geometryRenderHandles) { + Qt3DCore::QNodeId geometryRendererId = test->nodeManagers()->geometryRendererManager()->data(geometryRenderHandle)->peerId(); + Qt3DRender::Render::CalcGeometryTriangleVolumes calcGeometryTriangles(geometryRendererId, test->nodeManagers()); + calcGeometryTriangles.run(); + } +} + +} // anonymous + +class tst_BoundingSphere : public QObject +{ + Q_OBJECT +private: + +private Q_SLOTS: + void checkExtraGeometries_data() + { + QTest::addColumn("qmlFile"); + QTest::addColumn("sphereCenter"); + QTest::addColumn("sphereRadius"); + QTest::newRow("SphereMesh") << "qrc:/sphere.qml" << QVector3D(0.f, 0.f, 0.f) << 1.f; + QTest::newRow("CubeMesh") << "qrc:/cube.qml" << QVector3D(0.0928356f, -0.212021f, -0.0467958f) << 1.07583f; // weird! + } + + void checkExtraGeometries() + { + // GIVEN + QFETCH(QString, qmlFile); + QFETCH(QVector3D, sphereCenter); + QFETCH(float, sphereRadius); + + QUrl qmlUrl(qmlFile); + QmlSceneReader sceneReader(qmlUrl); + QScopedPointer root(qobject_cast(sceneReader.root())); + QVERIFY(root); + + QScopedPointer test(new Qt3DRender::TestAspect(root.data())); + + // Runs Required jobs + runRequiredJobs(test.data()); + + // THEN + QVERIFY(test->sceneRoot()->worldBoundingVolumeWithChildren()); + const auto boundingSphere = test->sceneRoot()->worldBoundingVolumeWithChildren(); + qDebug() << qmlFile << boundingSphere->radius() << boundingSphere->center(); + QCOMPARE(boundingSphere->radius(), sphereRadius); + QVERIFY(qAbs(boundingSphere->center().x() - sphereCenter.x()) < 0.000001f); // qFuzzyCompare hates 0s + QVERIFY(qAbs(boundingSphere->center().y() - sphereCenter.y()) < 0.000001f); + QVERIFY(qAbs(boundingSphere->center().z() - sphereCenter.z()) < 0.000001f); + } +}; + +QTEST_MAIN(tst_BoundingSphere) + +#include "tst_boundingsphere.moc" diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro index 4f536d3f4..052b19dd3 100644 --- a/tests/auto/render/render.pro +++ b/tests/auto/render/render.pro @@ -45,6 +45,7 @@ qtConfig(private_tests) { picking \ # qboundingvolumedebug \ # boundingvolumedebug \ + boundingsphere \ qdefaultmeshes \ trianglesextractor \ triangleboundingvolume \ -- cgit v1.2.3 From 9dd10069ad84a7d51bb890d78f7f5e1e79b94906 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Wed, 15 Feb 2017 10:19:23 +0000 Subject: Remove QConductedClipAnimator and defer to later MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Too much to fix up for 5.9 so remove and defer for 5.10. Task-number: QTBUG-58905 Change-Id: Ie5b4f172e57beac12933fa0db5f102b4dc9346fc Reviewed-by: Antti Määttä --- tests/auto/animation/animation.pro | 2 - .../conductedclipanimator.pro | 12 --- .../tst_conductedclipanimator.cpp | 98 ---------------------- .../qconductedclipanimator.pro | 12 --- .../tst_qconductedclipanimator.cpp | 64 -------------- 5 files changed, 188 deletions(-) delete mode 100644 tests/auto/animation/conductedclipanimator/conductedclipanimator.pro delete mode 100644 tests/auto/animation/conductedclipanimator/tst_conductedclipanimator.cpp delete mode 100644 tests/auto/animation/qconductedclipanimator/qconductedclipanimator.pro delete mode 100644 tests/auto/animation/qconductedclipanimator/tst_qconductedclipanimator.cpp (limited to 'tests/auto') diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index 43a00cd12..2f3776aaf 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -5,7 +5,6 @@ SUBDIRS += \ qanimationclip \ qclipanimator \ qblendedclipanimator \ - qconductedclipanimator \ qchannelmapping \ qchannelmapper @@ -18,7 +17,6 @@ qtConfig(private_tests) { bezierevaluator \ clipanimator \ blendedclipanimator \ - conductedclipanimator \ channelmapper \ channelmapping \ qlerpblend \ diff --git a/tests/auto/animation/conductedclipanimator/conductedclipanimator.pro b/tests/auto/animation/conductedclipanimator/conductedclipanimator.pro deleted file mode 100644 index 61a1106d9..000000000 --- a/tests/auto/animation/conductedclipanimator/conductedclipanimator.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = app - -TARGET = tst_conductedclipanimator - -QT += core-private 3dcore 3dcore-private 3danimation 3danimation-private testlib - -CONFIG += testcase - -SOURCES += \ - tst_conductedclipanimator.cpp - -include(../../core/common/common.pri) diff --git a/tests/auto/animation/conductedclipanimator/tst_conductedclipanimator.cpp b/tests/auto/animation/conductedclipanimator/tst_conductedclipanimator.cpp deleted file mode 100644 index 8536ab7e7..000000000 --- a/tests/auto/animation/conductedclipanimator/tst_conductedclipanimator.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** 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: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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class tst_ConductedClipAnimator: public Qt3DCore::QBackendNodeTester -{ - Q_OBJECT - -private Q_SLOTS: - void checkPeerPropertyMirroring() - { - // GIVEN - Qt3DAnimation::Animation::ConductedClipAnimator backendAnimator; - Qt3DAnimation::QConductedClipAnimator animator; - - // WHEN - simulateInitialization(&animator, &backendAnimator); - - // THEN - QCOMPARE(backendAnimator.peerId(), animator.id()); - QCOMPARE(backendAnimator.isEnabled(), animator.isEnabled()); - } - - void checkInitialAndCleanedUpState() - { - // GIVEN - Qt3DAnimation::Animation::ConductedClipAnimator backendAnimator; - - // THEN - QVERIFY(backendAnimator.peerId().isNull()); - QCOMPARE(backendAnimator.isEnabled(), false); - - // GIVEN - Qt3DAnimation::QConductedClipAnimator animator; - - // WHEN - simulateInitialization(&animator, &backendAnimator); - backendAnimator.cleanup(); - - // THEN - QCOMPARE(backendAnimator.isEnabled(), false); - } - - void checkPropertyChanges() - { - // GIVEN - Qt3DAnimation::Animation::ConductedClipAnimator backendAnimator; - Qt3DCore::QPropertyUpdatedChangePtr updateChange; - - // WHEN - updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); - updateChange->setPropertyName("enabled"); - updateChange->setValue(true); - backendAnimator.sceneChangeEvent(updateChange); - - // THEN - QCOMPARE(backendAnimator.isEnabled(), true); - } -}; - -QTEST_APPLESS_MAIN(tst_ConductedClipAnimator) - -#include "tst_conductedclipanimator.moc" diff --git a/tests/auto/animation/qconductedclipanimator/qconductedclipanimator.pro b/tests/auto/animation/qconductedclipanimator/qconductedclipanimator.pro deleted file mode 100644 index ef04bb54c..000000000 --- a/tests/auto/animation/qconductedclipanimator/qconductedclipanimator.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = app - -TARGET = tst_qconductedclipanimator - -QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib - -CONFIG += testcase - -SOURCES += \ - tst_qconductedclipanimator.cpp - -include(../../core/common/common.pri) diff --git a/tests/auto/animation/qconductedclipanimator/tst_qconductedclipanimator.cpp b/tests/auto/animation/qconductedclipanimator/tst_qconductedclipanimator.cpp deleted file mode 100644 index 7e40e5033..000000000 --- a/tests/auto/animation/qconductedclipanimator/tst_qconductedclipanimator.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** 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: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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class tst_QConductedClipAnimator : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - void initTestCase() - { - qRegisterMetaType(); - } - - void checkDefaultConstruction() - { - // GIVEN - Qt3DAnimation::QConductedClipAnimator animator; - - // THEN - // TODO: Check default property state - } -}; - -QTEST_MAIN(tst_QConductedClipAnimator) - -#include "tst_qconductedclipanimator.moc" -- cgit v1.2.3 From 5bceaee38908934078bbdb62b564daa68f7e182b Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Wed, 15 Feb 2017 10:33:28 +0000 Subject: Use QVector in level of detail APIs For consistency with rest of API and to avoid ambiguity inherent with qreal. Task-number: QTBUG-58888 Task-number: QTBUG-58889 Change-Id: Ib8729a11152165caf05ecea63f9e10c4d90689db Reviewed-by: Mike Krus --- tests/auto/render/levelofdetail/tst_levelofdetail.cpp | 6 +++--- tests/auto/render/qlevelofdetail/tst_qlevelofdetail.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/levelofdetail/tst_levelofdetail.cpp b/tests/auto/render/levelofdetail/tst_levelofdetail.cpp index ab0e8c4b8..731e36a36 100644 --- a/tests/auto/render/levelofdetail/tst_levelofdetail.cpp +++ b/tests/auto/render/levelofdetail/tst_levelofdetail.cpp @@ -112,7 +112,7 @@ private Q_SLOTS: } { - QVector thresholds = {20.f, 30.f, 40.f}; + QVector thresholds = {20.0f, 30.0f, 40.0f}; QVariant v; v.setValue(thresholds); @@ -129,12 +129,12 @@ private Q_SLOTS: { // WHEN Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); - updateChange->setValue(QVector3D(1., 2., 3.)); + updateChange->setValue(QVector3D(1.0f, 2.0f, 3.0f)); updateChange->setPropertyName("center"); renderLod.sceneChangeEvent(updateChange); // THEN - QCOMPARE(renderLod.center(), QVector3D(1., 2., 3.)); + QCOMPARE(renderLod.center(), QVector3D(1.0f, 2.0f, 3.0f)); } } }; diff --git a/tests/auto/render/qlevelofdetail/tst_qlevelofdetail.cpp b/tests/auto/render/qlevelofdetail/tst_qlevelofdetail.cpp index e2ffdd9da..2f8f6a957 100644 --- a/tests/auto/render/qlevelofdetail/tst_qlevelofdetail.cpp +++ b/tests/auto/render/qlevelofdetail/tst_qlevelofdetail.cpp @@ -103,7 +103,7 @@ private Q_SLOTS: { // WHEN - QVector thresholds = {10., 20., 30.}; + QVector thresholds = {10.0f, 20.0f, 30.0f}; lod->setThresholds(thresholds); QCoreApplication::processEvents(); -- cgit v1.2.3 From 0a399dbc2c0c8338522af0e106cea2d68c44c4b2 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Wed, 15 Feb 2017 09:56:02 +0000 Subject: QMemoryBarrier cleanup -rename barriertypes to waitOperation -in QML introduce a waitFor property -remove the Barrier suffix for the enum values -rename BarrierType to Operation Task-number: QTBUG-58878 Change-Id: Idc65f44b09e632509cd74286de26fea02e6b6dee Reviewed-by: Sean Harmer --- .../render/memorybarrier/tst_memorybarrier.cpp | 12 ++++----- .../render/qmemorybarrier/tst_qmemorybarrier.cpp | 30 +++++++++++----------- tests/auto/render/renderviews/tst_renderviews.cpp | 10 ++++---- 3 files changed, 26 insertions(+), 26 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/memorybarrier/tst_memorybarrier.cpp b/tests/auto/render/memorybarrier/tst_memorybarrier.cpp index d4f54f3af..f0d4931d9 100644 --- a/tests/auto/render/memorybarrier/tst_memorybarrier.cpp +++ b/tests/auto/render/memorybarrier/tst_memorybarrier.cpp @@ -50,14 +50,14 @@ private Q_SLOTS: QCOMPARE(backendMemoryBarrier.nodeType(), Qt3DRender::Render::FrameGraphNode::MemoryBarrier); QCOMPARE(backendMemoryBarrier.isEnabled(), false); QVERIFY(backendMemoryBarrier.peerId().isNull()); - QCOMPARE(backendMemoryBarrier.barrierTypes(), Qt3DRender::QMemoryBarrier::None); + QCOMPARE(backendMemoryBarrier.waitOperations(), Qt3DRender::QMemoryBarrier::None); } void checkInitializeFromPeer() { // GIVEN Qt3DRender::QMemoryBarrier memoryBarrier; - memoryBarrier.setBarrierTypes(Qt3DRender::QMemoryBarrier::VertexAttributeArrayBarrier); + memoryBarrier.setWaitOperations(Qt3DRender::QMemoryBarrier::VertexAttributeArray); { // WHEN @@ -67,7 +67,7 @@ private Q_SLOTS: // THEN QCOMPARE(backendMemoryBarrier.isEnabled(), true); QCOMPARE(backendMemoryBarrier.peerId(), memoryBarrier.id()); - QCOMPARE(backendMemoryBarrier.barrierTypes(), Qt3DRender::QMemoryBarrier::VertexAttributeArrayBarrier); + QCOMPARE(backendMemoryBarrier.waitOperations(), Qt3DRender::QMemoryBarrier::VertexAttributeArray); } { // WHEN @@ -101,14 +101,14 @@ private Q_SLOTS: } { // WHEN - const Qt3DRender::QMemoryBarrier::BarrierTypes newValue(Qt3DRender::QMemoryBarrier::AtomicCounterBarrier|Qt3DRender::QMemoryBarrier::ElementArrayBarrier); + const Qt3DRender::QMemoryBarrier::Operations newValue(Qt3DRender::QMemoryBarrier::AtomicCounter|Qt3DRender::QMemoryBarrier::ElementArray); const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("barrierTypes"); + change->setPropertyName("waitOperations"); change->setValue(QVariant::fromValue(newValue)); backendMemoryBarrier.sceneChangeEvent(change); // THEN - QCOMPARE(backendMemoryBarrier.barrierTypes(), newValue); + QCOMPARE(backendMemoryBarrier.waitOperations(), newValue); } } diff --git a/tests/auto/render/qmemorybarrier/tst_qmemorybarrier.cpp b/tests/auto/render/qmemorybarrier/tst_qmemorybarrier.cpp index 87c813a03..25ee10cad 100644 --- a/tests/auto/render/qmemorybarrier/tst_qmemorybarrier.cpp +++ b/tests/auto/render/qmemorybarrier/tst_qmemorybarrier.cpp @@ -45,7 +45,7 @@ private Q_SLOTS: void initTestCase() { - qRegisterMetaType("QMemoryBarrier::BarrierTypes"); + qRegisterMetaType("QMemoryBarrier::Operations"); } void checkDefaultConstruction() @@ -54,7 +54,7 @@ private Q_SLOTS: Qt3DRender::QMemoryBarrier memoryBarrier; // THEN - QCOMPARE(memoryBarrier.barrierTypes(), Qt3DRender::QMemoryBarrier::None); + QCOMPARE(memoryBarrier.waitOperations(), Qt3DRender::QMemoryBarrier::None); } void checkPropertyChanges() @@ -64,21 +64,21 @@ private Q_SLOTS: { // WHEN - QSignalSpy spy(&memoryBarrier, SIGNAL(barrierTypesChanged(QMemoryBarrier::BarrierTypes))); - const Qt3DRender::QMemoryBarrier::BarrierTypes newValue(Qt3DRender::QMemoryBarrier::ShaderStorageBarrier|Qt3DRender::QMemoryBarrier::VertexAttributeArrayBarrier); - memoryBarrier.setBarrierTypes(newValue); + QSignalSpy spy(&memoryBarrier, SIGNAL(waitOperationsChanged(QMemoryBarrier::Operations))); + const Qt3DRender::QMemoryBarrier::Operations newValue(Qt3DRender::QMemoryBarrier::ShaderStorage|Qt3DRender::QMemoryBarrier::VertexAttributeArray); + memoryBarrier.setWaitOperations(newValue); // THEN QVERIFY(spy.isValid()); - QCOMPARE(memoryBarrier.barrierTypes(), newValue); + QCOMPARE(memoryBarrier.waitOperations(), newValue); QCOMPARE(spy.count(), 1); // WHEN spy.clear(); - memoryBarrier.setBarrierTypes(newValue); + memoryBarrier.setWaitOperations(newValue); // THEN - QCOMPARE(memoryBarrier.barrierTypes(), newValue); + QCOMPARE(memoryBarrier.waitOperations(), newValue); QCOMPARE(spy.count(), 0); } } @@ -88,7 +88,7 @@ private Q_SLOTS: // GIVEN Qt3DRender::QMemoryBarrier memoryBarrier; - memoryBarrier.setBarrierTypes(Qt3DRender::QMemoryBarrier::CommandBarrier); + memoryBarrier.setWaitOperations(Qt3DRender::QMemoryBarrier::Command); // WHEN QVector creationChanges; @@ -105,7 +105,7 @@ private Q_SLOTS: const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); const Qt3DRender::QMemoryBarrierData cloneData = creationChangeData->data; - QCOMPARE(memoryBarrier.barrierTypes(), cloneData.barrierTypes); + QCOMPARE(memoryBarrier.waitOperations(), cloneData.waitOperations); QCOMPARE(memoryBarrier.id(), creationChangeData->subjectId()); QCOMPARE(memoryBarrier.isEnabled(), true); QCOMPARE(memoryBarrier.isEnabled(), creationChangeData->isNodeEnabled()); @@ -127,7 +127,7 @@ private Q_SLOTS: const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); const Qt3DRender::QMemoryBarrierData cloneData = creationChangeData->data; - QCOMPARE(memoryBarrier.barrierTypes(), cloneData.barrierTypes); + QCOMPARE(memoryBarrier.waitOperations(), cloneData.waitOperations); QCOMPARE(memoryBarrier.id(), creationChangeData->subjectId()); QCOMPARE(memoryBarrier.isEnabled(), false); QCOMPARE(memoryBarrier.isEnabled(), creationChangeData->isNodeEnabled()); @@ -144,14 +144,14 @@ private Q_SLOTS: { // WHEN - memoryBarrier.setBarrierTypes(Qt3DRender::QMemoryBarrier::ShaderStorageBarrier); + memoryBarrier.setWaitOperations(Qt3DRender::QMemoryBarrier::ShaderStorage); QCoreApplication::processEvents(); // THEN QCOMPARE(arbiter.events.size(), 1); auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "barrierTypes"); - QCOMPARE(change->value().value(), memoryBarrier.barrierTypes()); + QCOMPARE(change->propertyName(), "waitOperations"); + QCOMPARE(change->value().value(), memoryBarrier.waitOperations()); QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); arbiter.events.clear(); @@ -159,7 +159,7 @@ private Q_SLOTS: { // WHEN - memoryBarrier.setBarrierTypes(Qt3DRender::QMemoryBarrier::ShaderStorageBarrier); + memoryBarrier.setWaitOperations(Qt3DRender::QMemoryBarrier::ShaderStorage); QCoreApplication::processEvents(); // THEN diff --git a/tests/auto/render/renderviews/tst_renderviews.cpp b/tests/auto/render/renderviews/tst_renderviews.cpp index 70109d718..d469298f4 100644 --- a/tests/auto/render/renderviews/tst_renderviews.cpp +++ b/tests/auto/render/renderviews/tst_renderviews.cpp @@ -93,7 +93,7 @@ private Q_SLOTS: QCOMPARE(renderView.memoryBarrier(), QMemoryBarrier::None); // WHEN - const QMemoryBarrier::BarrierTypes barriers(QMemoryBarrier::BufferUpdateBarrier|QMemoryBarrier::ShaderImageAccessBarrier); + const QMemoryBarrier::Operations barriers(QMemoryBarrier::BufferUpdate|QMemoryBarrier::ShaderImageAccess); renderView.setMemoryBarrier(barriers); // THEN @@ -104,7 +104,7 @@ private Q_SLOTS: { { // GIVEN - const QMemoryBarrier::BarrierTypes barriers(QMemoryBarrier::AtomicCounterBarrier|QMemoryBarrier::ShaderStorageBarrier); + const QMemoryBarrier::Operations barriers(QMemoryBarrier::AtomicCounter|QMemoryBarrier::ShaderStorage); Qt3DRender::QMemoryBarrier frontendBarrier; FrameGraphManager frameGraphManager; MemoryBarrier backendBarrier; @@ -113,18 +113,18 @@ private Q_SLOTS: backendBarrier.setFrameGraphManager(&frameGraphManager); // WHEN - frontendBarrier.setBarrierTypes(barriers); + frontendBarrier.setWaitOperations(barriers); simulateInitialization(&frontendBarrier, &backendBarrier); // THEN QCOMPARE(renderView.memoryBarrier(), QMemoryBarrier::None); - QCOMPARE(backendBarrier.barrierTypes(), barriers); + QCOMPARE(backendBarrier.waitOperations(), barriers); // WHEN Qt3DRender::Render::setRenderViewConfigFromFrameGraphLeafNode(&renderView, &backendBarrier); // THEN - QCOMPARE(backendBarrier.barrierTypes(), renderView.memoryBarrier()); + QCOMPARE(backendBarrier.waitOperations(), renderView.memoryBarrier()); } // TO DO: Complete tests for other framegraph node types } -- cgit v1.2.3 From 4908bb231e32ecf0673f9f2dfa651e23fb3d325f Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Wed, 15 Feb 2017 10:36:48 +0000 Subject: QShaderProgram: rename enum ShaderStatus to Status Task-number: QTBUG-58896 Change-Id: I39be12a9fe00d3fd2e2f6074dd7f8df728ac1b7a Reviewed-by: Sean Harmer --- tests/auto/render/qshaderprogram/tst_qshaderprogram.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/qshaderprogram/tst_qshaderprogram.cpp b/tests/auto/render/qshaderprogram/tst_qshaderprogram.cpp index e5d001759..901ee7349 100644 --- a/tests/auto/render/qshaderprogram/tst_qshaderprogram.cpp +++ b/tests/auto/render/qshaderprogram/tst_qshaderprogram.cpp @@ -481,11 +481,11 @@ private Q_SLOTS: void checkStatusPropertyUpdate() { // GIVEN - qRegisterMetaType("ShaderStatus"); + qRegisterMetaType("Status"); TestArbiter arbiter; arbiter.setArbiterOnNode(this); - QSignalSpy spy(this, SIGNAL(statusChanged(ShaderStatus))); - const Qt3DRender::QShaderProgram::ShaderStatus newStatus = Qt3DRender::QShaderProgram::Error; + QSignalSpy spy(this, SIGNAL(statusChanged(Status))); + const Qt3DRender::QShaderProgram::Status newStatus = Qt3DRender::QShaderProgram::Error; // THEN QVERIFY(spy.isValid()); -- cgit v1.2.3 From 7328700ee5622fbb635205592c97280a8f84817a Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 17 Feb 2017 15:15:50 +0000 Subject: Revert "Use QVector in level of detail APIs" This reverts commit 5bceaee38908934078bbdb62b564daa68f7e182b. QML uses doubles throughout and there is no good way or place to reliably switch to floats in the API. We tried extending QtDeclarative to work with QJSValues containing vectors/lists of floats and doubles (rather than qreal) but this introduces rounding errors that are difficult to control robustly. We also looked at removing the Q_PROPERTY in C++ and adding it to a QML extension object. But that would make it not work with animations bound to this property. So, in the end, it seems like qreal is the best of a bad set of alternatives. We should make a renewed effort to kill qreal for Qt 6. Change-Id: I9d61e58e7223eb5a6b848ba33fc760b3654bbddd Reviewed-by: Mike Krus --- tests/auto/render/levelofdetail/tst_levelofdetail.cpp | 6 +++--- tests/auto/render/qlevelofdetail/tst_qlevelofdetail.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/levelofdetail/tst_levelofdetail.cpp b/tests/auto/render/levelofdetail/tst_levelofdetail.cpp index 731e36a36..ab0e8c4b8 100644 --- a/tests/auto/render/levelofdetail/tst_levelofdetail.cpp +++ b/tests/auto/render/levelofdetail/tst_levelofdetail.cpp @@ -112,7 +112,7 @@ private Q_SLOTS: } { - QVector thresholds = {20.0f, 30.0f, 40.0f}; + QVector thresholds = {20.f, 30.f, 40.f}; QVariant v; v.setValue(thresholds); @@ -129,12 +129,12 @@ private Q_SLOTS: { // WHEN Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); - updateChange->setValue(QVector3D(1.0f, 2.0f, 3.0f)); + updateChange->setValue(QVector3D(1., 2., 3.)); updateChange->setPropertyName("center"); renderLod.sceneChangeEvent(updateChange); // THEN - QCOMPARE(renderLod.center(), QVector3D(1.0f, 2.0f, 3.0f)); + QCOMPARE(renderLod.center(), QVector3D(1., 2., 3.)); } } }; diff --git a/tests/auto/render/qlevelofdetail/tst_qlevelofdetail.cpp b/tests/auto/render/qlevelofdetail/tst_qlevelofdetail.cpp index 2f8f6a957..e2ffdd9da 100644 --- a/tests/auto/render/qlevelofdetail/tst_qlevelofdetail.cpp +++ b/tests/auto/render/qlevelofdetail/tst_qlevelofdetail.cpp @@ -103,7 +103,7 @@ private Q_SLOTS: { // WHEN - QVector thresholds = {10.0f, 20.0f, 30.0f}; + QVector thresholds = {10., 20., 30.}; lod->setThresholds(thresholds); QCoreApplication::processEvents(); -- cgit v1.2.3 From a7942ff7260a213cdb3feb897173847742544f5b Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Fri, 17 Feb 2017 13:47:30 +0100 Subject: Clean up QRenderCapture(Reply) API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don't need the captureId in the public API so deprecate the functions which make it appear and create overloads with no such id when appropriate. Only a pointer to a QRenderCaptureReply is needed to represent a capture request. Also the "isCompleted" parameter is unneeded on the signal since it is always true anyway. If we'd want to do error management it would go via a status flag property or similar. Change-Id: I9571ece3e3f82f46db5b3993ccf035e770c9d55e Task-Id: QTBUG-58877 Reviewed-by: Antti Määttä Reviewed-by: Paul Lemire --- tests/auto/render/qrendercapture/tst_qrendercapture.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/qrendercapture/tst_qrendercapture.cpp b/tests/auto/render/qrendercapture/tst_qrendercapture.cpp index ef1e9f53c..e0037f3dd 100644 --- a/tests/auto/render/qrendercapture/tst_qrendercapture.cpp +++ b/tests/auto/render/qrendercapture/tst_qrendercapture.cpp @@ -67,7 +67,7 @@ private Q_SLOTS: arbiter.setArbiterOnNode(renderCapture.data()); // WHEN - QScopedPointer reply(renderCapture->requestCapture(12)); + QScopedPointer reply(renderCapture->requestCapture()); // THEN QCOMPARE(arbiter.events.size(), 1); @@ -75,7 +75,7 @@ private Q_SLOTS: QCOMPARE(change->propertyName(), "renderCaptureRequest"); QCOMPARE(change->subjectId(),renderCapture->id()); QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - QCOMPARE(change->value().toInt(), 12); + QCOMPARE(change->value().toInt(), 1); arbiter.events.clear(); } @@ -84,12 +84,12 @@ private Q_SLOTS: { // GIVEN QScopedPointer renderCapture(new MyRenderCapture()); - QScopedPointer reply(renderCapture->requestCapture(52)); + QScopedPointer reply(renderCapture->requestCapture()); QImage img = QImage(20, 20, QImage::Format_ARGB32); // WHEN Qt3DRender::RenderCaptureDataPtr data = Qt3DRender::RenderCaptureDataPtr::create(); - data.data()->captureId = 52; + data.data()->captureId = 2; data.data()->image = img; auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(renderCapture->id()); @@ -101,7 +101,6 @@ private Q_SLOTS: // THEN QCOMPARE(reply->isComplete(), true); - QCOMPARE(reply->captureId(), 52); QCOMPARE(reply->image().width(), 20); QCOMPARE(reply->image().height(), 20); QCOMPARE(reply->image().format(), QImage::Format_ARGB32); -- cgit v1.2.3 From 42af57acc976cf3142623ac2b13dabbfcf9e643a Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Wed, 15 Feb 2017 14:27:13 +0000 Subject: QNode PropertyTrackMode cleanup Task-number: QTBUG-58897 Change-Id: Ie92c26e7b34ea7730461786f484ff50b003f747a Reviewed-by: Sean Harmer --- tests/auto/core/nodes/tst_nodes.cpp | 48 ++++++-------- tests/auto/core/qpostman/tst_qpostman.cpp | 18 ++--- tests/auto/core/qscene/tst_qscene.cpp | 77 +++++++++++----------- tests/auto/quick3d/3dcore/3dcore.qml | 2 + tests/auto/quick3d/quick3d.pro | 3 +- tests/auto/quick3d/quick3dnode/quick3dnode.pro | 13 ++++ tests/auto/quick3d/quick3dnode/quick3dnode.qrc | 5 ++ tests/auto/quick3d/quick3dnode/quick3dnodev9.qml | 36 ++++++++++ tests/auto/quick3d/quick3dnode/tst_quick3dnode.cpp | 55 ++++++++++++++++ .../test_scene_model_to_eye.qml | 6 +- .../test_scene_model_to_world.qml | 6 +- .../tst_updateshaderdatatransformjob.cpp | 4 +- 12 files changed, 191 insertions(+), 82 deletions(-) create mode 100644 tests/auto/quick3d/quick3dnode/quick3dnode.pro create mode 100644 tests/auto/quick3d/quick3dnode/quick3dnode.qrc create mode 100644 tests/auto/quick3d/quick3dnode/quick3dnodev9.qml create mode 100644 tests/auto/quick3d/quick3dnode/tst_quick3dnode.cpp (limited to 'tests/auto') diff --git a/tests/auto/core/nodes/tst_nodes.cpp b/tests/auto/core/nodes/tst_nodes.cpp index 90e0084e8..89d396931 100644 --- a/tests/auto/core/nodes/tst_nodes.cpp +++ b/tests/auto/core/nodes/tst_nodes.cpp @@ -250,7 +250,7 @@ public: void tst_Nodes::initTestCase() { - qRegisterMetaType("PropertyTrackMode"); + qRegisterMetaType("PropertyTrackingMode"); } void tst_Nodes::defaultNodeConstruction() @@ -969,8 +969,7 @@ void tst_Nodes::checkDefaultConstruction() // THEN QCOMPARE(node.parentNode(), nullptr); QCOMPARE(node.isEnabled(), true); - QCOMPARE(node.propertyTrackMode(), Qt3DCore::QNode::DefaultTrackMode); - QCOMPARE(node.trackedProperties(), QStringList()); + QCOMPARE(node.defaultPropertyTrackingMode(), Qt3DCore::QNode::TrackFinalValues); } void tst_Nodes::checkPropertyChanges() @@ -1019,41 +1018,37 @@ void tst_Nodes::checkPropertyChanges() } { // WHEN - QSignalSpy spy(&node, SIGNAL(propertyUpdateModeChanged(PropertyTrackMode))); - const Qt3DCore::QNode::PropertyTrackMode newValue = Qt3DCore::QNode::TrackAllPropertiesMode; - node.setPropertyTrackMode(newValue); + QSignalSpy spy(&node, SIGNAL(defaultPropertyTrackingModeChanged(PropertyTrackingMode))); + const Qt3DCore::QNode::PropertyTrackingMode newValue = Qt3DCore::QNode::TrackAllValues; + node.setDefaultPropertyTrackingMode(newValue); // THEN QVERIFY(spy.isValid()); - QCOMPARE(node.propertyTrackMode(), newValue); + QCOMPARE(node.defaultPropertyTrackingMode(), newValue); QCOMPARE(spy.count(), 1); // WHEN spy.clear(); - node.setPropertyTrackMode(newValue); + node.setDefaultPropertyTrackingMode(newValue); // THEN - QCOMPARE(node.propertyTrackMode(), newValue); + QCOMPARE(node.defaultPropertyTrackingMode(), newValue); QCOMPARE(spy.count(), 0); } { // WHEN - QSignalSpy spy(&node, SIGNAL(trackedPropertiesChanged(const QStringList &))); - const QStringList newValue = QStringList() << QStringLiteral("C1") << QStringLiteral("C2") << QStringLiteral("C3"); - node.setTrackedProperties(newValue); + const QString enabledPropertyName = QStringLiteral("enabled"); + node.setDefaultPropertyTrackingMode(Qt3DCore::QNode::DontTrackValues); + node.setPropertyTracking(enabledPropertyName, Qt3DCore::QNode::TrackAllValues); // THEN - QVERIFY(spy.isValid()); - QCOMPARE(node.trackedProperties(), newValue); - QCOMPARE(spy.count(), 1); + QCOMPARE(node.propertyTracking(enabledPropertyName), Qt3DCore::QNode::TrackAllValues); // WHEN - spy.clear(); - node.setTrackedProperties(newValue); + node.clearPropertyTracking(enabledPropertyName); // THEN - QCOMPARE(node.trackedProperties(), newValue); - QCOMPARE(spy.count(), 0); + QCOMPARE(node.propertyTracking(enabledPropertyName), Qt3DCore::QNode::DontTrackValues); } } @@ -1065,9 +1060,9 @@ void tst_Nodes::checkCreationData() node.setParent(&root); node.setEnabled(true); - node.setPropertyTrackMode(Qt3DCore::QNode::TrackNamedPropertiesMode); - const QStringList trackedPropertyNames = QStringList() << QStringLiteral("327"); - node.setTrackedProperties(trackedPropertyNames); + const QString enabledPropertyName = QStringLiteral("enabled"); + node.setDefaultPropertyTrackingMode(Qt3DCore::QNode::DontTrackValues); + node.setPropertyTracking(enabledPropertyName, Qt3DCore::QNode::TrackAllValues); // WHEN QVector creationChanges; @@ -1152,7 +1147,7 @@ void tst_Nodes::checkPropertyTrackModeUpdate() { // WHEN - node.setPropertyTrackMode(Qt3DCore::QNode::TrackAllPropertiesMode); + node.setDefaultPropertyTrackingMode(Qt3DCore::QNode::TrackAllValues); QCoreApplication::processEvents(); // THEN -> this properties is non notifying @@ -1161,7 +1156,7 @@ void tst_Nodes::checkPropertyTrackModeUpdate() { // WHEN - node.setPropertyTrackMode(Qt3DCore::QNode::TrackAllPropertiesMode); + node.setDefaultPropertyTrackingMode(Qt3DCore::QNode::TrackAllValues); QCoreApplication::processEvents(); // THEN @@ -1176,11 +1171,10 @@ void tst_Nodes::checkTrackedPropertyNamesUpdate() TestArbiter arbiter; Qt3DCore::QNode node; arbiter.setArbiterOnNode(&node); - const QStringList newValue = QStringList() << QStringLiteral("883") << QStringLiteral("454"); { // WHEN - node.setTrackedProperties(newValue); + node.setPropertyTracking(QStringLiteral("883"), Qt3DCore::QNode::TrackAllValues); QCoreApplication::processEvents(); // THEN -> this properties is non notifying @@ -1189,7 +1183,7 @@ void tst_Nodes::checkTrackedPropertyNamesUpdate() { // WHEN - node.setTrackedProperties(newValue); + node.setPropertyTracking(QStringLiteral("883"), Qt3DCore::QNode::DontTrackValues); QCoreApplication::processEvents(); // THEN diff --git a/tests/auto/core/qpostman/tst_qpostman.cpp b/tests/auto/core/qpostman/tst_qpostman.cpp index 1dabf143f..612db6257 100644 --- a/tests/auto/core/qpostman/tst_qpostman.cpp +++ b/tests/auto/core/qpostman/tst_qpostman.cpp @@ -174,7 +174,7 @@ private Q_SLOTS: { // WHEN - receiverNode->setPropertyTrackMode(QNode::TrackAllPropertiesMode); + receiverNode->setDefaultPropertyTrackingMode(QNode::TrackAllValues); auto updateChange = QPropertyUpdatedChangePtr::create(receiverNode->id()); updateChange->setValue(1584); @@ -189,8 +189,8 @@ private Q_SLOTS: { // GIVEN - receiverNode->setPropertyTrackMode(QNode::TrackNamedPropertiesMode); - receiverNode->setTrackedProperties(QStringList() << QStringLiteral("vette")); + receiverNode->setDefaultPropertyTrackingMode(QNode::DontTrackValues); + receiverNode->setPropertyTracking(QStringLiteral("vette"), Qt3DCore::QNode::TrackAllValues); { // WHEN @@ -220,8 +220,8 @@ private Q_SLOTS: { // GIVEN - receiverNode->setTrackedProperties(QStringList() << QStringLiteral("vette")); - receiverNode->setPropertyTrackMode(QNode::TrackAllPropertiesMode); + receiverNode->setPropertyTracking(QStringLiteral("vette"), Qt3DCore::QNode::TrackAllValues); + receiverNode->setDefaultPropertyTrackingMode(QNode::TrackAllValues); { // WHEN @@ -246,8 +246,8 @@ private Q_SLOTS: { // GIVEN - receiverNode->setTrackedProperties(QStringList()); - receiverNode->setPropertyTrackMode(QNode::DefaultTrackMode); + receiverNode->clearPropertyTrackings(); + receiverNode->setDefaultPropertyTrackingMode(QNode::TrackFinalValues); { // WHEN @@ -279,8 +279,8 @@ private Q_SLOTS: { // GIVEN - receiverNode->setTrackedProperties(QStringList()); - receiverNode->setPropertyTrackMode(QNode::DefaultTrackMode); + receiverNode->clearPropertyTrackings(); + receiverNode->setDefaultPropertyTrackingMode(QNode::TrackFinalValues); { // WHEN diff --git a/tests/auto/core/qscene/tst_qscene.cpp b/tests/auto/core/qscene/tst_qscene.cpp index 485143041..f4b04362d 100644 --- a/tests/auto/core/qscene/tst_qscene.cpp +++ b/tests/auto/core/qscene/tst_qscene.cpp @@ -487,36 +487,37 @@ void tst_QScene::setPropertyTrackData() // GIVEN Qt3DCore::QNodeId fakeNodeId = Qt3DCore::QNodeId::createId(); QScopedPointer scene(new Qt3DCore::QScene); - const QStringList propertyNamesList = QStringList() << QStringLiteral("1340"); + QHash overridenTrackedProperties; + overridenTrackedProperties.insert(QStringLiteral("1340"), Qt3DCore::QNode::TrackAllValues); // WHEN { Qt3DCore::QScene::NodePropertyTrackData trackData; - trackData.namedProperties = propertyNamesList; - trackData.updateMode = Qt3DCore::QNode::TrackNamedPropertiesMode; + trackData.trackedPropertiesOverrides = overridenTrackedProperties; + trackData.defaultTrackMode = Qt3DCore::QNode::DontTrackValues; scene->setPropertyTrackDataForNode(fakeNodeId, trackData); } // THEN { Qt3DCore::QScene::NodePropertyTrackData trackData = scene->lookupNodePropertyTrackData(fakeNodeId); - QCOMPARE(trackData.namedProperties, propertyNamesList); - QCOMPARE(trackData.updateMode, Qt3DCore::QNode::TrackNamedPropertiesMode); + QCOMPARE(trackData.trackedPropertiesOverrides, overridenTrackedProperties); + QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::DontTrackValues); } // WHEN { Qt3DCore::QScene::NodePropertyTrackData trackData; - trackData.namedProperties = propertyNamesList; - trackData.updateMode = Qt3DCore::QNode::DefaultTrackMode; + trackData.trackedPropertiesOverrides.clear(); + trackData.defaultTrackMode = Qt3DCore::QNode::TrackFinalValues; scene->setPropertyTrackDataForNode(fakeNodeId, trackData); } // THEN { Qt3DCore::QScene::NodePropertyTrackData trackData = scene->lookupNodePropertyTrackData(fakeNodeId); - QCOMPARE(trackData.namedProperties, propertyNamesList); - QCOMPARE(trackData.updateMode, Qt3DCore::QNode::DefaultTrackMode); + QCOMPARE(trackData.trackedPropertiesOverrides.size(), 0); + QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::TrackFinalValues); } } @@ -525,21 +526,20 @@ void tst_QScene::lookupNodePropertyTrackData() // GIVEN QScopedPointer scene(new Qt3DCore::QScene); Qt3DCore::QNodeId fakeNodeId = Qt3DCore::QNodeId::createId(); - const QStringList propertyNamesList = QStringList() << QStringLiteral("383"); // THEN -> default value for non existent id Qt3DCore::QScene::NodePropertyTrackData trackData = scene->lookupNodePropertyTrackData(fakeNodeId); - QCOMPARE(trackData.namedProperties, QStringList()); - QCOMPARE(trackData.updateMode, Qt3DCore::QNode::DefaultTrackMode); + QCOMPARE(trackData.trackedPropertiesOverrides.size(), 0); + QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::TrackFinalValues); // WHEN - trackData.namedProperties = propertyNamesList; - trackData.updateMode = Qt3DCore::QNode::TrackNamedPropertiesMode; + trackData.trackedPropertiesOverrides.insert(QStringLiteral("383"), Qt3DCore::QNode::TrackAllValues); + trackData.defaultTrackMode = Qt3DCore::QNode::DontTrackValues; scene->setPropertyTrackDataForNode(fakeNodeId, trackData); trackData = scene->lookupNodePropertyTrackData(fakeNodeId); - QCOMPARE(trackData.namedProperties, propertyNamesList); - QCOMPARE(trackData.updateMode, Qt3DCore::QNode::TrackNamedPropertiesMode); + QCOMPARE(trackData.trackedPropertiesOverrides.size(), 1); + QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::DontTrackValues); } void tst_QScene::removePropertyTrackData() @@ -550,15 +550,15 @@ void tst_QScene::removePropertyTrackData() // WHEN Qt3DCore::QScene::NodePropertyTrackData trackData; - trackData.namedProperties = QStringList() << QStringLiteral("1584"); - trackData.updateMode = Qt3DCore::QNode::TrackNamedPropertiesMode; + trackData.trackedPropertiesOverrides.insert(QStringLiteral("1584"), Qt3DCore::QNode::TrackAllValues); + trackData.defaultTrackMode = Qt3DCore::QNode::DontTrackValues; scene->setPropertyTrackDataForNode(fakeNodeId, trackData); scene->removePropertyTrackDataForNode(fakeNodeId); // THEN -> default value for non existent id trackData = scene->lookupNodePropertyTrackData(fakeNodeId); - QCOMPARE(trackData.namedProperties, QStringList()); - QCOMPARE(trackData.updateMode, Qt3DCore::QNode::DefaultTrackMode); + QCOMPARE(trackData.trackedPropertiesOverrides.size(), 0); + QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::TrackFinalValues); } void tst_QScene::nodeSetAndUnsetPropertyTrackData() @@ -569,9 +569,8 @@ void tst_QScene::nodeSetAndUnsetPropertyTrackData() Qt3DCore::QNodePrivate::get(&parentNode)->setScene(scene.data()); Qt3DCore::QNode *childNode = new Qt3DCore::QNode(); - const QStringList propertyNamesList = QStringList() << QStringLiteral("883"); - childNode->setTrackedProperties(propertyNamesList); - childNode->setPropertyTrackMode(Qt3DCore::QNode::TrackNamedPropertiesMode); + childNode->setPropertyTracking(QStringLiteral("883"), Qt3DCore::QNode::TrackAllValues); + childNode->setDefaultPropertyTrackingMode(Qt3DCore::QNode::DontTrackValues); // WHEN childNode->setParent(&parentNode); @@ -580,8 +579,9 @@ void tst_QScene::nodeSetAndUnsetPropertyTrackData() // THEN QCOMPARE(Qt3DCore::QNodePrivate::get(childNode)->m_scene, scene.data()); Qt3DCore::QScene::NodePropertyTrackData trackData = scene->lookupNodePropertyTrackData(childNode->id()); - QCOMPARE(trackData.updateMode, Qt3DCore::QNode::TrackNamedPropertiesMode); - QCOMPARE(trackData.namedProperties, propertyNamesList); + QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::DontTrackValues); + QCOMPARE(trackData.trackedPropertiesOverrides.size(), 1); + QCOMPARE(trackData.trackedPropertiesOverrides[QStringLiteral("883")], Qt3DCore::QNode::TrackAllValues); // WHEN const Qt3DCore::QNodeId childNodeId = childNode->id(); @@ -590,8 +590,8 @@ void tst_QScene::nodeSetAndUnsetPropertyTrackData() // THEN -> default value for non existent id trackData = scene->lookupNodePropertyTrackData(childNodeId); - QCOMPARE(trackData.namedProperties, QStringList()); - QCOMPARE(trackData.updateMode, Qt3DCore::QNode::DefaultTrackMode); + QCOMPARE(trackData.trackedPropertiesOverrides.size(), 0); + QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::TrackFinalValues); } void tst_QScene::nodeUpdatePropertyTrackData() @@ -602,9 +602,9 @@ void tst_QScene::nodeUpdatePropertyTrackData() Qt3DCore::QNodePrivate::get(&parentNode)->setScene(scene.data()); Qt3DCore::QNode *childNode = new Qt3DCore::QNode(); - const QStringList propertyNamesList = QStringList() << QStringLiteral("883"); - childNode->setTrackedProperties(propertyNamesList); - childNode->setPropertyTrackMode(Qt3DCore::QNode::TrackNamedPropertiesMode); + const QString propertyName = QStringLiteral("883"); + childNode->setPropertyTracking(propertyName, Qt3DCore::QNode::TrackFinalValues); + childNode->setDefaultPropertyTrackingMode(Qt3DCore::QNode::DontTrackValues); // WHEN childNode->setParent(&parentNode); @@ -613,23 +613,26 @@ void tst_QScene::nodeUpdatePropertyTrackData() // THEN QCOMPARE(Qt3DCore::QNodePrivate::get(childNode)->m_scene, scene.data()); Qt3DCore::QScene::NodePropertyTrackData trackData = scene->lookupNodePropertyTrackData(childNode->id()); - QCOMPARE(trackData.updateMode, Qt3DCore::QNode::TrackNamedPropertiesMode); - QCOMPARE(trackData.namedProperties, propertyNamesList); + QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::DontTrackValues); + QCOMPARE(trackData.trackedPropertiesOverrides.size(), 1); + QCOMPARE(trackData.trackedPropertiesOverrides[propertyName], Qt3DCore::QNode::TrackFinalValues); // WHEN - childNode->setPropertyTrackMode(Qt3DCore::QNode::TrackAllPropertiesMode); + childNode->setDefaultPropertyTrackingMode(Qt3DCore::QNode::TrackAllValues); // THEN trackData = scene->lookupNodePropertyTrackData(childNode->id()); - QCOMPARE(trackData.updateMode, Qt3DCore::QNode::TrackAllPropertiesMode); + QCOMPARE(trackData.defaultTrackMode, Qt3DCore::QNode::TrackAllValues); // WHEN - const QStringList propertyNamesList2 = QStringList() << QStringLiteral("Viper"); - childNode->setTrackedProperties(propertyNamesList2); + const QString propertyName2 = QStringLiteral("Viper"); + childNode->setPropertyTracking(propertyName2, Qt3DCore::QNode::DontTrackValues); // THEN trackData = scene->lookupNodePropertyTrackData(childNode->id()); - QCOMPARE(trackData.namedProperties, propertyNamesList2); + QCOMPARE(trackData.trackedPropertiesOverrides.size(), 2); + QCOMPARE(trackData.trackedPropertiesOverrides[propertyName], Qt3DCore::QNode::TrackFinalValues); + QCOMPARE(trackData.trackedPropertiesOverrides[propertyName2], Qt3DCore::QNode::DontTrackValues); } QTEST_MAIN(tst_QScene) diff --git a/tests/auto/quick3d/3dcore/3dcore.qml b/tests/auto/quick3d/3dcore/3dcore.qml index 1d9d885ff..df9dd429b 100644 --- a/tests/auto/quick3d/3dcore/3dcore.qml +++ b/tests/auto/quick3d/3dcore/3dcore.qml @@ -28,6 +28,7 @@ import Qt3D.Core 2.0 as QQ3Core20 +import Qt3D.Core 2.9 as QQ3Core29 import QtQuick 2.0 Item { @@ -40,4 +41,5 @@ Item { QQ3Core20.Transform {} //Qt3DCore::QTransform QQ3Core20.QuaternionAnimation {} //Qt3DCore::Quick::QQuaternionAnimation + QQ3Core29.Entity {} //Qt3DCore::QEntity, Qt3DCore::Quick::Quick3DEntity } diff --git a/tests/auto/quick3d/quick3d.pro b/tests/auto/quick3d/quick3d.pro index 8abe04550..dd67a3ef4 100644 --- a/tests/auto/quick3d/quick3d.pro +++ b/tests/auto/quick3d/quick3d.pro @@ -7,5 +7,6 @@ qtConfig(private_tests) { 3drender \ 3dinput \ 3dcore \ - quick3dbuffer + quick3dbuffer \ + quick3dnode } diff --git a/tests/auto/quick3d/quick3dnode/quick3dnode.pro b/tests/auto/quick3d/quick3dnode/quick3dnode.pro new file mode 100644 index 000000000..5b3038c42 --- /dev/null +++ b/tests/auto/quick3d/quick3dnode/quick3dnode.pro @@ -0,0 +1,13 @@ +TEMPLATE = app + +TARGET = tst_quick3dnode + +QT += 3dcore 3dcore-private 3drender 3drender-private 3dquick 3dquick-private 3dquickrender-private testlib + +CONFIG += testcase + +include(../../render/qmlscenereader/qmlscenereader.pri) + +SOURCES += tst_quick3dnode.cpp + +RESOURCES += quick3dnode.qrc diff --git a/tests/auto/quick3d/quick3dnode/quick3dnode.qrc b/tests/auto/quick3d/quick3dnode/quick3dnode.qrc new file mode 100644 index 000000000..afdbbbb66 --- /dev/null +++ b/tests/auto/quick3d/quick3dnode/quick3dnode.qrc @@ -0,0 +1,5 @@ + + + quick3dnodev9.qml + + diff --git a/tests/auto/quick3d/quick3dnode/quick3dnodev9.qml b/tests/auto/quick3d/quick3dnode/quick3dnodev9.qml new file mode 100644 index 000000000..5429faf4e --- /dev/null +++ b/tests/auto/quick3d/quick3dnode/quick3dnodev9.qml @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Paul Lemire +** 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$ +** +****************************************************************************/ + +import Qt3D.Core 2.9 + +Entity { + propertyTrackingOverrides: { + "enabled": Entity.DontTrackValues, + "displacement": Entity.TrackFinalValues + } +} diff --git a/tests/auto/quick3d/quick3dnode/tst_quick3dnode.cpp b/tests/auto/quick3d/quick3dnode/tst_quick3dnode.cpp new file mode 100644 index 000000000..38bf46a7a --- /dev/null +++ b/tests/auto/quick3d/quick3dnode/tst_quick3dnode.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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: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 +#include +#include +#include + +class tst_Quick3DNode : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void checkPropertyTrackingOverrides_V9() + { + // GIVEN + QmlSceneReader sceneReader(QUrl("qrc:/quick3dnodev9.qml")); + + // THEN + QVERIFY(sceneReader.root() != nullptr); + Qt3DCore::QNode *node = static_cast(sceneReader.root()); + QCOMPARE(node->propertyTracking(QLatin1String("enabled")), Qt3DCore::QNode::DontTrackValues); + QCOMPARE(node->propertyTracking(QLatin1String("displacement")), Qt3DCore::QNode::TrackFinalValues); + } +}; + +QTEST_MAIN(tst_Quick3DNode) + +#include "tst_quick3dnode.moc" diff --git a/tests/auto/render/updateshaderdatatransformjob/test_scene_model_to_eye.qml b/tests/auto/render/updateshaderdatatransformjob/test_scene_model_to_eye.qml index 20585b5de..3b21b08ba 100644 --- a/tests/auto/render/updateshaderdatatransformjob/test_scene_model_to_eye.qml +++ b/tests/auto/render/updateshaderdatatransformjob/test_scene_model_to_eye.qml @@ -48,9 +48,9 @@ ** ****************************************************************************/ -import Qt3D.Core 2.0 -import Qt3D.Render 2.0 -import Qt3D.Extras 2.0 +import Qt3D.Core 2.9 +import Qt3D.Render 2.9 +import Qt3D.Extras 2.9 import QtQuick.Window 2.0 Entity { diff --git a/tests/auto/render/updateshaderdatatransformjob/test_scene_model_to_world.qml b/tests/auto/render/updateshaderdatatransformjob/test_scene_model_to_world.qml index d3e766021..59ccdd27f 100644 --- a/tests/auto/render/updateshaderdatatransformjob/test_scene_model_to_world.qml +++ b/tests/auto/render/updateshaderdatatransformjob/test_scene_model_to_world.qml @@ -48,9 +48,9 @@ ** ****************************************************************************/ -import Qt3D.Core 2.0 -import Qt3D.Render 2.0 -import Qt3D.Extras 2.0 +import Qt3D.Core 2.9 +import Qt3D.Render 2.9 +import Qt3D.Extras 2.9 import QtQuick.Window 2.0 Entity { diff --git a/tests/auto/render/updateshaderdatatransformjob/tst_updateshaderdatatransformjob.cpp b/tests/auto/render/updateshaderdatatransformjob/tst_updateshaderdatatransformjob.cpp index 9b53d1f65..c076aa21e 100644 --- a/tests/auto/render/updateshaderdatatransformjob/tst_updateshaderdatatransformjob.cpp +++ b/tests/auto/render/updateshaderdatatransformjob/tst_updateshaderdatatransformjob.cpp @@ -165,7 +165,7 @@ private Q_SLOTS: Qt3DRender::Render::ShaderData *backendShaderData = collection.backendShaderData.first(); // THEN - QCOMPARE(backendShaderData->properties().size(), 2); + QCOMPARE(backendShaderData->properties().size(), 3); QVERIFY(backendShaderData->properties().contains(QLatin1String("eyePosition"))); QVERIFY(backendShaderData->properties().contains(QLatin1String("eyePositionTransformed"))); @@ -205,7 +205,7 @@ private Q_SLOTS: Qt3DRender::Render::ShaderData *backendShaderData = collection.backendShaderData.first(); // THEN - QCOMPARE(backendShaderData->properties().size(), 2); + QCOMPARE(backendShaderData->properties().size(), 3); QVERIFY(backendShaderData->properties().contains(QLatin1String("position"))); QVERIFY(backendShaderData->properties().contains(QLatin1String("positionTransformed"))); -- cgit v1.2.3 From ddc878f2fc978a3b740b7ccf9258c824c6ba959a Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Thu, 16 Feb 2017 18:43:53 +0000 Subject: QBoundingSphere cleanup Is now a Q_GADGET value type Added QBoundingSphere creator functions on QLevelOfDetails and Quick3DLevelOfDetailsLoader Note: cannot be a nested type on QLevelOfDetails as moc doesn't support it Task-number: QTBUG-58892 Change-Id: Ic7b6d68c6e1119c1f61a858f49379efc1e9c2104 Reviewed-by: Sean Harmer --- tests/auto/render/levelofdetail/tst_levelofdetail.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/levelofdetail/tst_levelofdetail.cpp b/tests/auto/render/levelofdetail/tst_levelofdetail.cpp index ab0e8c4b8..1446811a8 100644 --- a/tests/auto/render/levelofdetail/tst_levelofdetail.cpp +++ b/tests/auto/render/levelofdetail/tst_levelofdetail.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -57,8 +57,8 @@ private Q_SLOTS: QCOMPARE(renderLod.currentIndex(), lod.currentIndex()); QCOMPARE(renderLod.thresholdType(), lod.thresholdType()); QCOMPARE(renderLod.thresholds(), lod.thresholds()); - QCOMPARE(renderLod.center(), lod.volumeOverride()->center()); - QCOMPARE(renderLod.radius(), lod.volumeOverride()->radius()); + QCOMPARE(renderLod.center(), lod.volumeOverride().center()); + QCOMPARE(renderLod.radius(), lod.volumeOverride().radius()); } void checkInitialAndCleanedUpState() @@ -129,8 +129,9 @@ private Q_SLOTS: { // WHEN Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); - updateChange->setValue(QVector3D(1., 2., 3.)); - updateChange->setPropertyName("center"); + Qt3DRender::QLevelOfDetailBoundingSphere sphere(QVector3D(1.0f, 2.0f, 3.0f), 1.0f); + updateChange->setValue(QVariant::fromValue(sphere)); + updateChange->setPropertyName("volumeOverride"); renderLod.sceneChangeEvent(updateChange); // THEN -- cgit v1.2.3 From 12111fd494d927bb75a8a41e3771ff6983119274 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Thu, 23 Feb 2017 13:53:23 +0100 Subject: QShaderData: fix texture support in properties There was only code dealing with sub-shader data but nothing allowing to check if a property was a texture, this is now properly handled. Change-Id: I48984727eff975e9f3e2c21c5185b336efc963fd Reviewed-by: Sean Harmer --- .../render/renderviewutils/tst_renderviewutils.cpp | 156 ++++++++++++++++++++- 1 file changed, 154 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/renderviewutils/tst_renderviewutils.cpp b/tests/auto/render/renderviewutils/tst_renderviewutils.cpp index e4681a257..c38b2795e 100644 --- a/tests/auto/render/renderviewutils/tst_renderviewutils.cpp +++ b/tests/auto/render/renderviewutils/tst_renderviewutils.cpp @@ -43,6 +43,8 @@ class tst_RenderViewUtils : public Qt3DCore::QBackendNodeTester private Q_SLOTS: void topLevelScalarValueNoUniforms(); void topLevelScalarValue(); + void topLevelTextureValueNoUniforms(); + void topLevelTextureValue(); void topLevelArrayValue(); void topLevelStructValue_data(); void topLevelStructValue(); @@ -66,6 +68,15 @@ private: // Init the backend element simulateInitialization(frontend, backend); } + + void initBackendTexture(Qt3DRender::QAbstractTexture *frontend, + Qt3DRender::Render::TextureManager *manager) + { + // Create backend element for frontend one + Qt3DRender::Render::Texture *backend = manager->getOrCreateResource(frontend->id()); + // Init the backend element + simulateInitialization(frontend, backend); + } }; class ScalarShaderData : public Qt3DRender::QShaderData @@ -109,6 +120,47 @@ private: float m_scalar; }; +class TextureShaderData : public Qt3DRender::QShaderData +{ + Q_OBJECT + Q_PROPERTY(Qt3DRender::QAbstractTexture* texture READ texture WRITE setTexture NOTIFY textureChanged) + +public: + TextureShaderData() + : Qt3DRender::QShaderData() + , m_texture(nullptr) + { + } + + void setTexture(Qt3DRender::QAbstractTexture *texture) + { + if (texture != m_texture) { + m_texture = texture; + emit textureChanged(); + } + } + + Qt3DRender::QAbstractTexture *texture() const + { + return m_texture; + } + + QHash buildUniformMap(const QString &blockName) + { + QHash uniforms; + + uniforms.insert(blockName + QStringLiteral(".texture"), Qt3DRender::Render::ShaderUniform()); + + return uniforms; + } + +Q_SIGNALS: + void textureChanged(); + +private: + Qt3DRender::QAbstractTexture *m_texture; +}; + class ArrayShaderData : public Qt3DRender::QShaderData { @@ -294,6 +346,7 @@ void tst_RenderViewUtils::topLevelScalarValueNoUniforms() // GIVEN QScopedPointer shaderData(new ScalarShaderData()); QScopedPointer manager(new Qt3DRender::Render::ShaderDataManager()); + QScopedPointer textureManager(new Qt3DRender::Render::TextureManager()); // WHEN shaderData->setScalar(883.0f); @@ -306,6 +359,7 @@ void tst_RenderViewUtils::topLevelScalarValueNoUniforms() // WHEB Qt3DRender::Render::UniformBlockValueBuilder blockBuilder; blockBuilder.shaderDataManager = manager.data(); + blockBuilder.textureManager = textureManager.data(); blockBuilder.updatedPropertiesOnly = false; // build name-value map blockBuilder.buildActiveUniformNameValueMapStructHelper(backendShaderData, QStringLiteral("")); @@ -320,6 +374,7 @@ void tst_RenderViewUtils::topLevelScalarValue() // GIVEN QScopedPointer shaderData(new ScalarShaderData()); QScopedPointer manager(new Qt3DRender::Render::ShaderDataManager()); + QScopedPointer textureManager(new Qt3DRender::Render::TextureManager()); // WHEN shaderData->setScalar(883.0f); @@ -332,6 +387,7 @@ void tst_RenderViewUtils::topLevelScalarValue() // WHEN Qt3DRender::Render::UniformBlockValueBuilder blockBuilder; blockBuilder.shaderDataManager = manager.data(); + blockBuilder.textureManager = textureManager.data(); blockBuilder.updatedPropertiesOnly = false; blockBuilder.uniforms = shaderData->buildUniformMap(QStringLiteral("MyBlock")); // build name-value map @@ -353,11 +409,83 @@ void tst_RenderViewUtils::topLevelScalarValue() } } +void tst_RenderViewUtils::topLevelTextureValueNoUniforms() +{ + // GIVEN + QScopedPointer shaderData(new TextureShaderData); + QScopedPointer manager(new Qt3DRender::Render::ShaderDataManager); + QScopedPointer texture(new Qt3DRender::QTexture2D); + QScopedPointer textureManager(new Qt3DRender::Render::TextureManager()); + + // WHEN + shaderData->setTexture(texture.data()); + initBackendShaderData(shaderData.data(), manager.data()); + + // THEN + Qt3DRender::Render::ShaderData *backendShaderData = manager->lookupResource(shaderData->id()); + QVERIFY(backendShaderData != nullptr); + + // WHEB + Qt3DRender::Render::UniformBlockValueBuilder blockBuilder; + blockBuilder.shaderDataManager = manager.data(); + blockBuilder.textureManager = textureManager.data(); + blockBuilder.updatedPropertiesOnly = false; + // build name-value map + blockBuilder.buildActiveUniformNameValueMapStructHelper(backendShaderData, QStringLiteral("")); + + // THEN + // activeUniformNamesToValue should be empty as blockBuilder.uniforms is + QVERIFY(blockBuilder.activeUniformNamesToValue.isEmpty()); +} + +void tst_RenderViewUtils::topLevelTextureValue() +{ + // GIVEN + QScopedPointer shaderData(new TextureShaderData); + QScopedPointer manager(new Qt3DRender::Render::ShaderDataManager); + QScopedPointer texture(new Qt3DRender::QTexture2D); + QScopedPointer textureManager(new Qt3DRender::Render::TextureManager()); + + // WHEN + initBackendTexture(texture.data(), textureManager.data()); + shaderData->setTexture(texture.data()); + initBackendShaderData(shaderData.data(), manager.data()); + + // THEN + Qt3DRender::Render::ShaderData *backendShaderData = manager->lookupResource(shaderData->id()); + QVERIFY(backendShaderData != nullptr); + + // WHEN + Qt3DRender::Render::UniformBlockValueBuilder blockBuilder; + blockBuilder.shaderDataManager = manager.data(); + blockBuilder.textureManager = textureManager.data(); + blockBuilder.updatedPropertiesOnly = false; + blockBuilder.uniforms = shaderData->buildUniformMap(QStringLiteral("MyBlock")); + // build name-value map + blockBuilder.buildActiveUniformNameValueMapStructHelper(backendShaderData, QStringLiteral("MyBlock")); + + // THEN + QVERIFY(blockBuilder.uniforms.count() == 1); + QCOMPARE(blockBuilder.activeUniformNamesToValue.count(), 1); + + // WHEN + Qt3DRender::Render::UniformBlockValueBuilderHash::const_iterator it = blockBuilder.activeUniformNamesToValue.begin(); + const Qt3DRender::Render::UniformBlockValueBuilderHash::const_iterator end = blockBuilder.activeUniformNamesToValue.end(); + + while (it != end) { + // THEN + QVERIFY(blockBuilder.uniforms.contains(Qt3DRender::Render::StringToInt::lookupString(it.key()))); + QCOMPARE(it.value(), QVariant::fromValue(shaderData->texture()->id())); + ++it; + } +} + void tst_RenderViewUtils::topLevelArrayValue() { // GIVEN QScopedPointer shaderData(new ArrayShaderData()); QScopedPointer manager(new Qt3DRender::Render::ShaderDataManager()); + QScopedPointer textureManager(new Qt3DRender::Render::TextureManager()); // WHEN QVariantList arrayValues = QVariantList() << 454 << 350 << 383 << 427 << 552; @@ -371,6 +499,7 @@ void tst_RenderViewUtils::topLevelArrayValue() // WHEN Qt3DRender::Render::UniformBlockValueBuilder blockBuilder; blockBuilder.shaderDataManager = manager.data(); + blockBuilder.textureManager = textureManager.data(); blockBuilder.updatedPropertiesOnly = false; blockBuilder.uniforms = shaderData->buildUniformMap(QStringLiteral("MyBlock")); // build name-value map @@ -430,6 +559,7 @@ void tst_RenderViewUtils::topLevelStructValue() QFETCH(StructShaderData *, shaderData); QFETCH(QString, blockName); QScopedPointer manager(new Qt3DRender::Render::ShaderDataManager()); + QScopedPointer textureManager(new Qt3DRender::Render::TextureManager()); // WHEN initBackendShaderData(shaderData, manager.data()); @@ -441,6 +571,7 @@ void tst_RenderViewUtils::topLevelStructValue() // WHEN Qt3DRender::Render::UniformBlockValueBuilder blockBuilder; blockBuilder.shaderDataManager = manager.data(); + blockBuilder.textureManager = textureManager.data(); blockBuilder.updatedPropertiesOnly = false; blockBuilder.uniforms = shaderData->buildUniformMap(blockName); const QHash expectedValues = shaderData->buildUniformMapValues(blockName); @@ -468,10 +599,14 @@ void tst_RenderViewUtils::topLevelDynamicProperties() // GIVEN QScopedPointer shaderData(new Qt3DRender::QShaderData()); QScopedPointer manager(new Qt3DRender::Render::ShaderDataManager()); + QScopedPointer texture(new Qt3DRender::QTexture2D); + QScopedPointer textureManager(new Qt3DRender::Render::TextureManager()); // WHEN + initBackendTexture(texture.data(), textureManager.data()); shaderData->setProperty("scalar", 883.0f); shaderData->setProperty("array", QVariantList() << 454 << 350 << 383 << 427 << 552); + shaderData->setProperty("texture", QVariant::fromValue(texture.data())); initBackendShaderData(shaderData.data(), manager.data()); // THEN @@ -481,20 +616,24 @@ void tst_RenderViewUtils::topLevelDynamicProperties() // WHEN Qt3DRender::Render::UniformBlockValueBuilder blockBuilder; blockBuilder.shaderDataManager = manager.data(); + blockBuilder.textureManager = textureManager.data(); blockBuilder.updatedPropertiesOnly = false; blockBuilder.uniforms.insert(QStringLiteral("MyBlock.scalar"), Qt3DRender::Render::ShaderUniform()); blockBuilder.uniforms.insert(QStringLiteral("MyBlock.array[0]"), Qt3DRender::Render::ShaderUniform()); + blockBuilder.uniforms.insert(QStringLiteral("MyBlock.texture"), Qt3DRender::Render::ShaderUniform()); // build name-value map blockBuilder.buildActiveUniformNameValueMapStructHelper(backendShaderData, QStringLiteral("MyBlock")); // THEN - QVERIFY(blockBuilder.uniforms.count() == 2); - QCOMPARE(blockBuilder.activeUniformNamesToValue.count(), 2); + QVERIFY(blockBuilder.uniforms.count() == 3); + QCOMPARE(blockBuilder.activeUniformNamesToValue.count(), 3); QCOMPARE(blockBuilder.activeUniformNamesToValue.value(Qt3DRender::Render::StringToInt::lookupId("MyBlock.scalar")), shaderData->property("scalar")); QCOMPARE(blockBuilder.activeUniformNamesToValue.value(Qt3DRender::Render::StringToInt::lookupId("MyBlock.array[0]")), shaderData->property("array")); + QCOMPARE(blockBuilder.activeUniformNamesToValue.value(Qt3DRender::Render::StringToInt::lookupId("MyBlock.texture")), + QVariant::fromValue(texture->id())); } void tst_RenderViewUtils::transformedProperties() @@ -558,6 +697,19 @@ void tst_RenderViewUtils::shouldNotifyDynamicPropertyChanges() QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); QCOMPARE(change->propertyName(), QByteArrayLiteral("scalar")); QCOMPARE(change->value().toFloat(), 883.0f); + + arbiter.events.clear(); + + // WHEN + QScopedPointer texture(new Qt3DRender::QTexture2D); + shaderData->setProperty("texture", QVariant::fromValue(texture.data())); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().dynamicCast(); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + QCOMPARE(change->propertyName(), QByteArrayLiteral("texture")); + QCOMPARE(change->value(), QVariant::fromValue(texture->id())); } QTEST_MAIN(tst_RenderViewUtils) -- cgit v1.2.3 From 67eec4f57a47271685e805c1ff74c80b2570c6ab Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Thu, 23 Feb 2017 15:13:28 +0100 Subject: Add QEnvironmentLight into Qt3DRender This is a better API to set the environment lighting than what we currently have on the metal/rough materials. Still needs to be integrated in the renderer and to adjust the materials to make use of it. Change-Id: Ie1e46a0fa67916460147200c9cbbfbab8b037cee Reviewed-by: Sean Harmer --- .../render/qenvironmentlight/qenvironmentlight.pro | 11 + .../qenvironmentlight/tst_qenvironmentlight.cpp | 301 +++++++++++++++++++++ tests/auto/render/render.pro | 1 + 3 files changed, 313 insertions(+) create mode 100644 tests/auto/render/qenvironmentlight/qenvironmentlight.pro create mode 100644 tests/auto/render/qenvironmentlight/tst_qenvironmentlight.cpp (limited to 'tests/auto') diff --git a/tests/auto/render/qenvironmentlight/qenvironmentlight.pro b/tests/auto/render/qenvironmentlight/qenvironmentlight.pro new file mode 100644 index 000000000..8a66f65ba --- /dev/null +++ b/tests/auto/render/qenvironmentlight/qenvironmentlight.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +TARGET = tst_environmentlight + +QT += core-private 3dcore 3dcore-private 3drender 3drender-private testlib + +CONFIG += testcase + +SOURCES += tst_qenvironmentlight.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/render/qenvironmentlight/tst_qenvironmentlight.cpp b/tests/auto/render/qenvironmentlight/tst_qenvironmentlight.cpp new file mode 100644 index 000000000..76b3603c9 --- /dev/null +++ b/tests/auto/render/qenvironmentlight/tst_qenvironmentlight.cpp @@ -0,0 +1,301 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** 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 +#include + +#include +#include +#include +#include + +#include +#include +#include "testpostmanarbiter.h" + +class tst_QEnvironmentLight: public QObject +{ + Q_OBJECT +private Q_SLOTS: + void checkDefaultConstruction() + { + // GIVEN + Qt3DRender::QEnvironmentLight light; + + // THEN + QVERIFY(light.findChild()); + QCOMPARE(light.irradiance(), nullptr); + QCOMPARE(light.specular(), nullptr); + } + + void shouldTakeOwnershipOfParentlessTextures() + { + // GIVEN + Qt3DRender::QEnvironmentLight light; + auto irradiance = new Qt3DRender::QTexture2D; + auto specular = new Qt3DRender::QTexture2D; + + // WHEN + light.setIrradiance(irradiance); + light.setSpecular(specular); + + // THEN + QCOMPARE(irradiance->parent(), &light); + QCOMPARE(specular->parent(), &light); + } + + void shouldNotChangeOwnershipOfParentedTextures() + { + // GIVEN + Qt3DCore::QNode node; + Qt3DRender::QEnvironmentLight light; + auto irradiance = new Qt3DRender::QTexture2D(&node); + auto specular = new Qt3DRender::QTexture2D(&node); + + // WHEN + light.setIrradiance(irradiance); + light.setSpecular(specular); + + // WHEN + delete irradiance; + delete specular; + + // THEN + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DRender::QEnvironmentLight light; + auto shaderData = light.findChild(); + + { + auto texture = new Qt3DRender::QTexture2D(&light); + QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::irradianceChanged); + + // WHEN + light.setIrradiance(texture); + + // THEN + QCOMPARE(light.irradiance(), texture); + QCOMPARE(shaderData->property("irradiance").value(), texture); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().first().value(), texture); + + // WHEN + light.setIrradiance(texture); + + // THEN + QCOMPARE(light.irradiance(), texture); + QCOMPARE(shaderData->property("irradiance").value(), texture); + QCOMPARE(spy.count(), 0); + + // WHEN + light.setIrradiance(nullptr); + + // THEN + QCOMPARE(light.irradiance(), nullptr); + QCOMPARE(shaderData->property("irradiance").value(), nullptr); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().first().value(), nullptr); + } + { + auto texture = new Qt3DRender::QTexture2D(&light); + QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::irradianceChanged); + + // WHEN + light.setIrradiance(texture); + + // THEN + QCOMPARE(light.irradiance(), texture); + QCOMPARE(shaderData->property("irradiance").value(), texture); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().first().value(), texture); + + // WHEN + delete texture; + + // THEN + QCOMPARE(light.irradiance(), nullptr); + QCOMPARE(shaderData->property("irradiance").value(), nullptr); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().first().value(), nullptr); + } + { + auto texture = new Qt3DRender::QTexture2D; + QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::irradianceChanged); + + // WHEN + light.setIrradiance(texture); + + // THEN + QCOMPARE(light.irradiance(), texture); + QCOMPARE(shaderData->property("irradiance").value(), texture); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().first().value(), texture); + + // WHEN + delete texture; + + // THEN + QCOMPARE(light.irradiance(), nullptr); + QCOMPARE(shaderData->property("irradiance").value(), nullptr); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().first().value(), nullptr); + } + { + auto texture = new Qt3DRender::QTexture2D(&light); + QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::specularChanged); + + // WHEN + light.setSpecular(texture); + + // THEN + QCOMPARE(light.specular(), texture); + QCOMPARE(shaderData->property("specular").value(), texture); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().first().value(), texture); + + // WHEN + light.setSpecular(texture); + + // THEN + QCOMPARE(light.specular(), texture); + QCOMPARE(shaderData->property("specular").value(), texture); + QCOMPARE(spy.count(), 0); + + // WHEN + light.setSpecular(nullptr); + + // THEN + QCOMPARE(light.specular(), nullptr); + QCOMPARE(shaderData->property("specular").value(), nullptr); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().first().value(), nullptr); + } + { + auto texture = new Qt3DRender::QTexture2D(&light); + QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::specularChanged); + + // WHEN + light.setSpecular(texture); + + // THEN + QCOMPARE(light.specular(), texture); + QCOMPARE(shaderData->property("specular").value(), texture); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().first().value(), texture); + + // WHEN + delete texture; + + // THEN + QCOMPARE(light.specular(), nullptr); + QCOMPARE(shaderData->property("specular").value(), nullptr); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().first().value(), nullptr); + } + { + auto texture = new Qt3DRender::QTexture2D; + QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::specularChanged); + + // WHEN + light.setSpecular(texture); + + // THEN + QCOMPARE(light.specular(), texture); + QCOMPARE(shaderData->property("specular").value(), texture); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().first().value(), texture); + + // WHEN + delete texture; + + // THEN + QCOMPARE(light.specular(), nullptr); + QCOMPARE(shaderData->property("specular").value(), nullptr); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().first().value(), nullptr); + } + } + + void checkCreationData() + { + // GIVEN + Qt3DRender::QEnvironmentLight light; + auto shaderData = light.findChild(); + + // WHEN + QVector creationChanges; + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&light); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 2); // EnvironmentLight + ShaderData + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DRender::QEnvironmentLightData cloneData = creationChangeData->data; + + QCOMPARE(cloneData.shaderDataId, shaderData->id()); + QCOMPARE(light.id(), creationChangeData->subjectId()); + QCOMPARE(light.isEnabled(), true); + QCOMPARE(light.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(light.metaObject(), creationChangeData->metaObject()); + } + + // WHEN + light.setEnabled(false); + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&light); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 2); // EnvironmentLight + ShaderData + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DRender::QEnvironmentLightData cloneData = creationChangeData->data; + + QCOMPARE(cloneData.shaderDataId, shaderData->id()); + QCOMPARE(light.id(), creationChangeData->subjectId()); + QCOMPARE(light.isEnabled(), false); + QCOMPARE(light.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(light.metaObject(), creationChangeData->metaObject()); + } + } +}; + +QTEST_MAIN(tst_QEnvironmentLight) + +#include "tst_qenvironmentlight.moc" diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro index 052b19dd3..fc98cf7da 100644 --- a/tests/auto/render/render.pro +++ b/tests/auto/render/render.pro @@ -31,6 +31,7 @@ qtConfig(private_tests) { qframegraphnode \ qlayerfilter \ qabstractlight \ + qenvironmentlight \ qray3d \ qrenderpassfilter \ qrendertargetselector \ -- cgit v1.2.3 From c10fa3bf20f5ac000a0ba67f2ec8e101af040d6f Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Thu, 23 Feb 2017 16:07:18 +0100 Subject: Integrate EnvironmentLight with Entity This will be needed to gather the environment lights in the scene. Change-Id: Icabcfb378c4938448bd241460b0f3fa3811c0287 Reviewed-by: Sean Harmer --- tests/auto/render/entity/tst_entity.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/render/entity/tst_entity.cpp b/tests/auto/render/entity/tst_entity.cpp index 0bd3a6054..d1a222c92 100644 --- a/tests/auto/render/entity/tst_entity.cpp +++ b/tests/auto/render/entity/tst_entity.cpp @@ -38,6 +38,7 @@ #include #include +#include #include #include #include @@ -64,6 +65,7 @@ QNodeId computeJobUuid(Entity *entity) { return entity->componentUuid layersUuid(Entity *entity) { return entity->componentsUuid(); } QVector shadersUuid(Entity *entity) { return entity->componentsUuid(); } +QVector environmentLightsUuid(Entity *entity) { return entity->componentsUuid(); } class tst_RenderEntity : public QObject { @@ -86,7 +88,8 @@ private slots: << new QObjectPicker << new QLayer << new QShaderData - << new QComputeCommand; + << new QComputeCommand + << new QEnvironmentLight; QTest::newRow("all components") << components; } @@ -112,6 +115,7 @@ private slots: QVERIFY(entity.componentUuid().isNull()); QVERIFY(entity.componentsUuid().isEmpty()); QVERIFY(entity.componentsUuid().isEmpty()); + QVERIFY(entity.componentsUuid().isEmpty()); QVERIFY(!entity.isBoundingVolumeDirty()); QVERIFY(entity.childrenHandles().isEmpty()); @@ -139,6 +143,7 @@ private slots: QVERIFY(!entity.componentUuid().isNull()); QVERIFY(!entity.componentsUuid().isEmpty()); QVERIFY(!entity.componentsUuid().isEmpty()); + QVERIFY(!entity.componentsUuid().isEmpty()); QVERIFY(entity.isBoundingVolumeDirty()); QVERIFY(!entity.childrenHandles().isEmpty()); QVERIFY(renderer.dirtyBits() != 0); @@ -157,6 +162,7 @@ private slots: QVERIFY(entity.componentUuid().isNull()); QVERIFY(entity.componentsUuid().isEmpty()); QVERIFY(entity.componentsUuid().isEmpty()); + QVERIFY(entity.componentsUuid().isEmpty()); QVERIFY(!entity.isBoundingVolumeDirty()); QVERIFY(entity.childrenHandles().isEmpty()); containsAll = entity.containsComponentsOfType(); @@ -236,6 +242,10 @@ private slots: components.clear(); components << new QShaderData << new QShaderData << new QShaderData; QTest::newRow("shader data") << components << reinterpret_cast(shadersUuid); + + components.clear(); + components << new QEnvironmentLight << new QEnvironmentLight << new QEnvironmentLight; + QTest::newRow("environmentLights") << components << reinterpret_cast(environmentLightsUuid); } void shouldHandleComponentsEvents() -- cgit v1.2.3 From 7a3648ef4e884429dbe4bb60ab5a0a838bc5abfc Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Thu, 16 Feb 2017 17:38:52 +0000 Subject: Introduce QAbstractAnimationClip and rename QAnimationClip Introduced an abstract base class for types of animation clip. Also renamed QAnimationClip to QAnimationClipLoader since it loads data from files. Also renamed corresponding backend type and fixed up unit tests accordingly. Task-number: QTBUG-58898 Change-Id: I01a96e108cbbcd12e01913693e96610598965018 Reviewed-by: Kevin Ottens --- .../animation/additiveblend/tst_additiveblend.cpp | 4 +- tests/auto/animation/animation.pro | 4 +- .../auto/animation/animationclip/animationclip.pro | 12 -- .../animation/animationclip/tst_animationclip.cpp | 155 ------------------- .../animationcliploader/animationcliploader.pro | 12 ++ .../tst_animationcliploader.cpp | 155 +++++++++++++++++++ .../tst_blendedclipanimator.cpp | 2 +- .../animation/clipanimator/tst_clipanimator.cpp | 8 +- .../animation/clipblendnode/tst_clipblendnode.cpp | 6 +- tests/auto/animation/lerpblend/tst_lerpblend.cpp | 4 +- .../tst_qabstractclipblendnode.cpp | 8 +- .../qadditiveblend/tst_qadditiveblend.cpp | 6 +- .../animation/qanimationclip/qanimationclip.pro | 12 -- .../qanimationclip/tst_qanimationclip.cpp | 166 --------------------- .../qanimationcliploader/qanimationcliploader.pro | 12 ++ .../tst_qanimationcliploader.cpp | 166 +++++++++++++++++++++ .../tst_qblendedclipanimator.cpp | 2 - .../animation/qclipanimator/tst_qclipanimator.cpp | 16 +- tests/auto/animation/qlerpblend/tst_qlerpblend.cpp | 6 +- 19 files changed, 377 insertions(+), 379 deletions(-) delete mode 100644 tests/auto/animation/animationclip/animationclip.pro delete mode 100644 tests/auto/animation/animationclip/tst_animationclip.cpp create mode 100644 tests/auto/animation/animationcliploader/animationcliploader.pro create mode 100644 tests/auto/animation/animationcliploader/tst_animationcliploader.cpp delete mode 100644 tests/auto/animation/qanimationclip/qanimationclip.pro delete mode 100644 tests/auto/animation/qanimationclip/tst_qanimationclip.cpp create mode 100644 tests/auto/animation/qanimationcliploader/qanimationcliploader.pro create mode 100644 tests/auto/animation/qanimationcliploader/tst_qanimationcliploader.cpp (limited to 'tests/auto') diff --git a/tests/auto/animation/additiveblend/tst_additiveblend.cpp b/tests/auto/animation/additiveblend/tst_additiveblend.cpp index 31c103166..c94efedd8 100644 --- a/tests/auto/animation/additiveblend/tst_additiveblend.cpp +++ b/tests/auto/animation/additiveblend/tst_additiveblend.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include #include @@ -57,7 +57,7 @@ private Q_SLOTS: { // GIVEN Qt3DAnimation::QAdditiveBlend additiveBlend; - Qt3DAnimation::QAnimationClip clip; + Qt3DAnimation::QAnimationClipLoader clip; additiveBlend.setBlendFactor(0.8f); additiveBlend.addClip(&clip); diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index 2f3776aaf..859f6c04f 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -2,7 +2,7 @@ TEMPLATE = subdirs SUBDIRS += \ qanimationaspect \ - qanimationclip \ + qanimationcliploader \ qclipanimator \ qblendedclipanimator \ qchannelmapping \ @@ -10,7 +10,7 @@ SUBDIRS += \ qtConfig(private_tests) { SUBDIRS += \ - animationclip \ + animationcliploader \ qabstractclipblendnode \ fcurve \ functionrangefinder \ diff --git a/tests/auto/animation/animationclip/animationclip.pro b/tests/auto/animation/animationclip/animationclip.pro deleted file mode 100644 index 09d9f2523..000000000 --- a/tests/auto/animation/animationclip/animationclip.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = app - -TARGET = tst_animationclip - -QT += core-private 3dcore 3dcore-private 3danimation 3danimation-private testlib - -CONFIG += testcase - -SOURCES += \ - tst_animationclip.cpp - -include(../../core/common/common.pri) diff --git a/tests/auto/animation/animationclip/tst_animationclip.cpp b/tests/auto/animation/animationclip/tst_animationclip.cpp deleted file mode 100644 index 1a61dec2c..000000000 --- a/tests/auto/animation/animationclip/tst_animationclip.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/**************************************************************************** -** -** 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: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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class tst_AnimationClip: public Qt3DCore::QBackendNodeTester -{ - Q_OBJECT - -private Q_SLOTS: - void checkPeerPropertyMirroring() - { - // GIVEN - Qt3DAnimation::Animation::AnimationClip backendClip; - Qt3DAnimation::Animation::Handler handler; - backendClip.setHandler(&handler); - Qt3DAnimation::QAnimationClip clip; - - clip.setSource(QUrl::fromLocalFile("walk.qlip")); - - // WHEN - simulateInitialization(&clip, &backendClip); - - // THEN - QCOMPARE(backendClip.peerId(), clip.id()); - QCOMPARE(backendClip.isEnabled(), clip.isEnabled()); - QCOMPARE(backendClip.source(), clip.source()); - } - - void checkInitialAndCleanedUpState() - { - // GIVEN - Qt3DAnimation::Animation::AnimationClip backendClip; - Qt3DAnimation::Animation::Handler handler; - backendClip.setHandler(&handler); - - // THEN - QVERIFY(backendClip.peerId().isNull()); - QCOMPARE(backendClip.isEnabled(), false); - QCOMPARE(backendClip.source(), QUrl()); - QCOMPARE(backendClip.duration(), 0.0f); - - // GIVEN - Qt3DAnimation::QAnimationClip clip; - clip.setSource(QUrl::fromLocalFile("walk.qlip")); - - // WHEN - simulateInitialization(&clip, &backendClip); - backendClip.setSource(QUrl::fromLocalFile("run.qlip")); - backendClip.cleanup(); - - // THEN - QCOMPARE(backendClip.source(), QUrl()); - QCOMPARE(backendClip.isEnabled(), false); - QCOMPARE(backendClip.duration(), 0.0f); - } - - void checkPropertyChanges() - { - // GIVEN - Qt3DAnimation::Animation::AnimationClip backendClip; - Qt3DAnimation::Animation::Handler handler; - backendClip.setHandler(&handler); - Qt3DCore::QPropertyUpdatedChangePtr updateChange; - - // WHEN - updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); - updateChange->setPropertyName("enabled"); - updateChange->setValue(true); - backendClip.sceneChangeEvent(updateChange); - - // THEN - QCOMPARE(backendClip.isEnabled(), true); - - // WHEN - const QUrl newSource = QUrl::fromLocalFile("fallover.qlip"); - updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); - updateChange->setPropertyName("source"); - updateChange->setValue(newSource); - backendClip.sceneChangeEvent(updateChange); - - // THEN - QCOMPARE(backendClip.source(), newSource); - } - - void checkDurationPropertyBackendNotification() - { - // GIVEN - TestArbiter arbiter; - Qt3DAnimation::Animation::AnimationClip backendClip; - backendClip.setEnabled(true); - Qt3DCore::QBackendNodePrivate::get(&backendClip)->setArbiter(&arbiter); - - // WHEN - backendClip.setDuration(64.0f); - - // THEN - QCOMPARE(backendClip.duration(), 64.0f); - QCOMPARE(arbiter.events.count(), 1); - Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "duration"); - QCOMPARE(change->value().toFloat(), backendClip.duration()); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isIntermediate, - false); - - arbiter.events.clear(); - - // WHEN - backendClip.setDuration(64.0f); - - // THEN - QCOMPARE(backendClip.duration(), 64.0f); - QCOMPARE(arbiter.events.count(), 0); - - arbiter.events.clear(); - } -}; - -QTEST_APPLESS_MAIN(tst_AnimationClip) - -#include "tst_animationclip.moc" diff --git a/tests/auto/animation/animationcliploader/animationcliploader.pro b/tests/auto/animation/animationcliploader/animationcliploader.pro new file mode 100644 index 000000000..b1bc6dbcc --- /dev/null +++ b/tests/auto/animation/animationcliploader/animationcliploader.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_animationcliploader + +QT += core-private 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += \ + tst_animationcliploader.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp b/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp new file mode 100644 index 000000000..8c001b5f7 --- /dev/null +++ b/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** 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: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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class tst_AnimationClipLoader: public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + void checkPeerPropertyMirroring() + { + // GIVEN + Qt3DAnimation::Animation::AnimationClipLoader backendClip; + Qt3DAnimation::Animation::Handler handler; + backendClip.setHandler(&handler); + Qt3DAnimation::QAnimationClipLoader clip; + + clip.setSource(QUrl::fromLocalFile("walk.qlip")); + + // WHEN + simulateInitialization(&clip, &backendClip); + + // THEN + QCOMPARE(backendClip.peerId(), clip.id()); + QCOMPARE(backendClip.isEnabled(), clip.isEnabled()); + QCOMPARE(backendClip.source(), clip.source()); + } + + void checkInitialAndCleanedUpState() + { + // GIVEN + Qt3DAnimation::Animation::AnimationClipLoader backendClip; + Qt3DAnimation::Animation::Handler handler; + backendClip.setHandler(&handler); + + // THEN + QVERIFY(backendClip.peerId().isNull()); + QCOMPARE(backendClip.isEnabled(), false); + QCOMPARE(backendClip.source(), QUrl()); + QCOMPARE(backendClip.duration(), 0.0f); + + // GIVEN + Qt3DAnimation::QAnimationClipLoader clip; + clip.setSource(QUrl::fromLocalFile("walk.qlip")); + + // WHEN + simulateInitialization(&clip, &backendClip); + backendClip.setSource(QUrl::fromLocalFile("run.qlip")); + backendClip.cleanup(); + + // THEN + QCOMPARE(backendClip.source(), QUrl()); + QCOMPARE(backendClip.isEnabled(), false); + QCOMPARE(backendClip.duration(), 0.0f); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::Animation::AnimationClipLoader backendClip; + Qt3DAnimation::Animation::Handler handler; + backendClip.setHandler(&handler); + Qt3DCore::QPropertyUpdatedChangePtr updateChange; + + // WHEN + updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); + updateChange->setPropertyName("enabled"); + updateChange->setValue(true); + backendClip.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backendClip.isEnabled(), true); + + // WHEN + const QUrl newSource = QUrl::fromLocalFile("fallover.qlip"); + updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); + updateChange->setPropertyName("source"); + updateChange->setValue(newSource); + backendClip.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backendClip.source(), newSource); + } + + void checkDurationPropertyBackendNotification() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::Animation::AnimationClipLoader backendClip; + backendClip.setEnabled(true); + Qt3DCore::QBackendNodePrivate::get(&backendClip)->setArbiter(&arbiter); + + // WHEN + backendClip.setDuration(64.0f); + + // THEN + QCOMPARE(backendClip.duration(), 64.0f); + QCOMPARE(arbiter.events.count(), 1); + Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "duration"); + QCOMPARE(change->value().toFloat(), backendClip.duration()); + QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isIntermediate, + false); + + arbiter.events.clear(); + + // WHEN + backendClip.setDuration(64.0f); + + // THEN + QCOMPARE(backendClip.duration(), 64.0f); + QCOMPARE(arbiter.events.count(), 0); + + arbiter.events.clear(); + } +}; + +QTEST_APPLESS_MAIN(tst_AnimationClipLoader) + +#include "tst_animationcliploader.moc" diff --git a/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp b/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp index 04cc1026e..5c0cef708 100644 --- a/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp +++ b/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include #include diff --git a/tests/auto/animation/clipanimator/tst_clipanimator.cpp b/tests/auto/animation/clipanimator/tst_clipanimator.cpp index 77f067973..b5173e56d 100644 --- a/tests/auto/animation/clipanimator/tst_clipanimator.cpp +++ b/tests/auto/animation/clipanimator/tst_clipanimator.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include #include @@ -49,7 +49,7 @@ private Q_SLOTS: Qt3DAnimation::Animation::ClipAnimator backendAnimator; backendAnimator.setHandler(&handler); Qt3DAnimation::QClipAnimator animator; - auto clip = new Qt3DAnimation::QAnimationClip(); + auto clip = new Qt3DAnimation::QAnimationClipLoader(); animator.setClip(clip); animator.setLoops(10); @@ -81,7 +81,7 @@ private Q_SLOTS: // GIVEN Qt3DAnimation::QClipAnimator animator; - auto clip = new Qt3DAnimation::QAnimationClip(); + auto clip = new Qt3DAnimation::QAnimationClipLoader(); animator.setClip(clip); animator.setRunning(true); animator.setLoops(25); @@ -116,7 +116,7 @@ private Q_SLOTS: QCOMPARE(backendAnimator.isEnabled(), true); // WHEN - auto newClip = new Qt3DAnimation::QAnimationClip(); + auto newClip = new Qt3DAnimation::QAnimationClipLoader(); updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); updateChange->setPropertyName("clip"); updateChange->setValue(QVariant::fromValue(newClip->id())); diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp index 085979267..d8163f13f 100644 --- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include #include @@ -78,7 +78,7 @@ private Q_SLOTS: { // GIVEN Qt3DAnimation::QLerpBlend clipBlendNode; - Qt3DAnimation::QAnimationClip clip; + Qt3DAnimation::QAnimationClipLoader clip; clipBlendNode.addClip(&clip); QCoreApplication::processEvents(); @@ -133,7 +133,7 @@ private Q_SLOTS: } { // WHEN - Qt3DAnimation::QAnimationClip clip; + Qt3DAnimation::QAnimationClipLoader clip; // To geneate the type_info in the QNodePrivate of clip Qt3DCore::QNodeCreatedChangeGenerator generator(&clip); diff --git a/tests/auto/animation/lerpblend/tst_lerpblend.cpp b/tests/auto/animation/lerpblend/tst_lerpblend.cpp index 5f494d9ec..b268fb42f 100644 --- a/tests/auto/animation/lerpblend/tst_lerpblend.cpp +++ b/tests/auto/animation/lerpblend/tst_lerpblend.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include #include @@ -57,7 +57,7 @@ private Q_SLOTS: { // GIVEN Qt3DAnimation::QLerpBlend lerpBlend; - Qt3DAnimation::QAnimationClip clip; + Qt3DAnimation::QAnimationClipLoader clip; lerpBlend.setBlendFactor(0.8f); lerpBlend.addClip(&clip); diff --git a/tests/auto/animation/qabstractclipblendnode/tst_qabstractclipblendnode.cpp b/tests/auto/animation/qabstractclipblendnode/tst_qabstractclipblendnode.cpp index e2d963310..f5f1e73d4 100644 --- a/tests/auto/animation/qabstractclipblendnode/tst_qabstractclipblendnode.cpp +++ b/tests/auto/animation/qabstractclipblendnode/tst_qabstractclipblendnode.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include #include @@ -76,7 +76,7 @@ private Q_SLOTS: { // WHEN - Qt3DAnimation::QAnimationClip newValue; + Qt3DAnimation::QAnimationClipLoader newValue; abstractClipBlendNode.addClip(&newValue); // THEN @@ -103,7 +103,7 @@ private Q_SLOTS: { // WHEN - Qt3DAnimation::QAnimationClip clip; + Qt3DAnimation::QAnimationClipLoader clip; abstractClipBlendNode.addClip(&clip); QCOMPARE(abstractClipBlendNode.clips().size(), 1); @@ -118,7 +118,7 @@ private Q_SLOTS: // GIVEN TestArbiter arbiter; TestClipBlendNode abstractClipBlendNode; - Qt3DAnimation::QAnimationClip clip; + Qt3DAnimation::QAnimationClipLoader clip; arbiter.setArbiterOnNode(&abstractClipBlendNode); { diff --git a/tests/auto/animation/qadditiveblend/tst_qadditiveblend.cpp b/tests/auto/animation/qadditiveblend/tst_qadditiveblend.cpp index 27acf2b47..369ca0078 100644 --- a/tests/auto/animation/qadditiveblend/tst_qadditiveblend.cpp +++ b/tests/auto/animation/qadditiveblend/tst_qadditiveblend.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include #include @@ -84,8 +84,8 @@ private Q_SLOTS: { // GIVEN Qt3DAnimation::QAdditiveBlend addBlend; - Qt3DAnimation::QAnimationClip clip1; - Qt3DAnimation::QAnimationClip clip2; + Qt3DAnimation::QAnimationClipLoader clip1; + Qt3DAnimation::QAnimationClipLoader clip2; addBlend.addClip(&clip1); addBlend.addClip(&clip2); diff --git a/tests/auto/animation/qanimationclip/qanimationclip.pro b/tests/auto/animation/qanimationclip/qanimationclip.pro deleted file mode 100644 index 5a9678496..000000000 --- a/tests/auto/animation/qanimationclip/qanimationclip.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = app - -TARGET = tst_qanimationclip - -QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib - -CONFIG += testcase - -SOURCES += \ - tst_qanimationclip.cpp - -include(../../core/common/common.pri) diff --git a/tests/auto/animation/qanimationclip/tst_qanimationclip.cpp b/tests/auto/animation/qanimationclip/tst_qanimationclip.cpp deleted file mode 100644 index 8c83f6530..000000000 --- a/tests/auto/animation/qanimationclip/tst_qanimationclip.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/**************************************************************************** -** -** 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: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 -#include -#include -#include -#include -#include -#include -#include -#include - -class tst_QAnimationClip : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - void checkDefaultConstruction() - { - // GIVEN - Qt3DAnimation::QAnimationClip clip; - - // THEN - QCOMPARE(clip.source(), QUrl()); - QCOMPARE(clip.duration(), 0.0f); - } - - void checkPropertyChanges() - { - // GIVEN - Qt3DAnimation::QAnimationClip clip; - - { - // WHEN - QSignalSpy spy(&clip, SIGNAL(sourceChanged(QUrl))); - const QUrl newValue(QStringLiteral("qrc:/walk.qlip")); - clip.setSource(newValue); - - // THEN - QVERIFY(spy.isValid()); - QCOMPARE(clip.source(), newValue); - QCOMPARE(spy.count(), 1); - - // WHEN - spy.clear(); - clip.setSource(newValue); - - // THEN - QCOMPARE(clip.source(), newValue); - QCOMPARE(spy.count(), 0); - } - } - - void checkCreationData() - { - // GIVEN - Qt3DAnimation::QAnimationClip clip; - - clip.setSource(QUrl(QStringLiteral("http://someRemoteURL.com"))); - - // WHEN - QVector creationChanges; - - { - Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&clip); - creationChanges = creationChangeGenerator.creationChanges(); - } - - // THEN - { - QCOMPARE(creationChanges.size(), 1); - - const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); - const Qt3DAnimation::QAnimationClipData data = creationChangeData->data; - - QCOMPARE(clip.id(), creationChangeData->subjectId()); - QCOMPARE(clip.isEnabled(), true); - QCOMPARE(clip.isEnabled(), creationChangeData->isNodeEnabled()); - QCOMPARE(clip.metaObject(), creationChangeData->metaObject()); - QCOMPARE(clip.source(), data.source); - } - - // WHEN - clip.setEnabled(false); - - { - Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&clip); - creationChanges = creationChangeGenerator.creationChanges(); - } - - // THEN - { - QCOMPARE(creationChanges.size(), 1); - - const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); - - QCOMPARE(clip.id(), creationChangeData->subjectId()); - QCOMPARE(clip.isEnabled(), false); - QCOMPARE(clip.isEnabled(), creationChangeData->isNodeEnabled()); - QCOMPARE(clip.metaObject(), creationChangeData->metaObject()); - } - } - - void checkSourceUpdate() - { - // GIVEN - TestArbiter arbiter; - Qt3DAnimation::QAnimationClip clip; - arbiter.setArbiterOnNode(&clip); - - { - // WHEN - clip.setSource(QUrl(QStringLiteral("qrc:/toyplane.qlip"))); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "source"); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - - arbiter.events.clear(); - } - - { - // WHEN - clip.setSource(QStringLiteral("qrc:/toyplane.qlip")); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - } - - } -}; - -QTEST_MAIN(tst_QAnimationClip) - -#include "tst_qanimationclip.moc" diff --git a/tests/auto/animation/qanimationcliploader/qanimationcliploader.pro b/tests/auto/animation/qanimationcliploader/qanimationcliploader.pro new file mode 100644 index 000000000..d6ef54df6 --- /dev/null +++ b/tests/auto/animation/qanimationcliploader/qanimationcliploader.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_qanimationclip + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += \ + tst_qanimationcliploader.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/qanimationcliploader/tst_qanimationcliploader.cpp b/tests/auto/animation/qanimationcliploader/tst_qanimationcliploader.cpp new file mode 100644 index 000000000..352587d51 --- /dev/null +++ b/tests/auto/animation/qanimationcliploader/tst_qanimationcliploader.cpp @@ -0,0 +1,166 @@ +/**************************************************************************** +** +** 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: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 +#include +#include +#include +#include +#include +#include +#include +#include + +class tst_QAnimationClipLoader : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void checkDefaultConstruction() + { + // GIVEN + Qt3DAnimation::QAnimationClipLoader clip; + + // THEN + QCOMPARE(clip.source(), QUrl()); + QCOMPARE(clip.duration(), 0.0f); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::QAnimationClipLoader clip; + + { + // WHEN + QSignalSpy spy(&clip, SIGNAL(sourceChanged(QUrl))); + const QUrl newValue(QStringLiteral("qrc:/walk.qlip")); + clip.setSource(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(clip.source(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + clip.setSource(newValue); + + // THEN + QCOMPARE(clip.source(), newValue); + QCOMPARE(spy.count(), 0); + } + } + + void checkCreationData() + { + // GIVEN + Qt3DAnimation::QAnimationClipLoader clip; + + clip.setSource(QUrl(QStringLiteral("http://someRemoteURL.com"))); + + // WHEN + QVector creationChanges; + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&clip); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 1); + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DAnimation::QAnimationClipLoaderData data = creationChangeData->data; + + QCOMPARE(clip.id(), creationChangeData->subjectId()); + QCOMPARE(clip.isEnabled(), true); + QCOMPARE(clip.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(clip.metaObject(), creationChangeData->metaObject()); + QCOMPARE(clip.source(), data.source); + } + + // WHEN + clip.setEnabled(false); + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&clip); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 1); + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + + QCOMPARE(clip.id(), creationChangeData->subjectId()); + QCOMPARE(clip.isEnabled(), false); + QCOMPARE(clip.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(clip.metaObject(), creationChangeData->metaObject()); + } + } + + void checkSourceUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::QAnimationClipLoader clip; + arbiter.setArbiterOnNode(&clip); + + { + // WHEN + clip.setSource(QUrl(QStringLiteral("qrc:/toyplane.qlip"))); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "source"); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + clip.setSource(QStringLiteral("qrc:/toyplane.qlip")); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } +}; + +QTEST_MAIN(tst_QAnimationClipLoader) + +#include "tst_qanimationcliploader.moc" diff --git a/tests/auto/animation/qblendedclipanimator/tst_qblendedclipanimator.cpp b/tests/auto/animation/qblendedclipanimator/tst_qblendedclipanimator.cpp index 42997d8aa..d8c18bac9 100644 --- a/tests/auto/animation/qblendedclipanimator/tst_qblendedclipanimator.cpp +++ b/tests/auto/animation/qblendedclipanimator/tst_qblendedclipanimator.cpp @@ -28,9 +28,7 @@ #include -#include #include -#include #include #include #include diff --git a/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp b/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp index d210d4365..084e78809 100644 --- a/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp +++ b/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp @@ -28,10 +28,10 @@ #include -#include +#include #include #include -#include +#include #include #include #include @@ -47,7 +47,7 @@ class tst_QClipAnimator : public QObject private Q_SLOTS: void initTestCase() { - qRegisterMetaType(); + qRegisterMetaType(); qRegisterMetaType(); } @@ -57,7 +57,7 @@ private Q_SLOTS: Qt3DAnimation::QClipAnimator animator; // THEN - QCOMPARE(animator.clip(), static_cast(nullptr)); + QCOMPARE(animator.clip(), static_cast(nullptr)); QCOMPARE(animator.channelMapper(), static_cast(nullptr)); QCOMPARE(animator.loops(), 1); } @@ -69,8 +69,8 @@ private Q_SLOTS: { // WHEN - QSignalSpy spy(&animator, SIGNAL(clipChanged(Qt3DAnimation::QAnimationClip *))); - auto newValue = new Qt3DAnimation::QAnimationClip(); + QSignalSpy spy(&animator, SIGNAL(clipChanged(Qt3DAnimation::QAbstractAnimationClip *))); + auto newValue = new Qt3DAnimation::QAnimationClipLoader(); animator.setClip(newValue); // THEN @@ -134,7 +134,7 @@ private Q_SLOTS: { // GIVEN Qt3DAnimation::QClipAnimator animator; - auto clip = new Qt3DAnimation::QAnimationClip(); + auto clip = new Qt3DAnimation::QAnimationClipLoader(); animator.setClip(clip); auto mapper = new Qt3DAnimation::QChannelMapper(); animator.setChannelMapper(mapper); @@ -187,7 +187,7 @@ private Q_SLOTS: // GIVEN TestArbiter arbiter; Qt3DAnimation::QClipAnimator animator; - auto clip = new Qt3DAnimation::QAnimationClip(); + auto clip = new Qt3DAnimation::QAnimationClipLoader(); arbiter.setArbiterOnNode(&animator); { diff --git a/tests/auto/animation/qlerpblend/tst_qlerpblend.cpp b/tests/auto/animation/qlerpblend/tst_qlerpblend.cpp index 6bd6bb324..25e403007 100644 --- a/tests/auto/animation/qlerpblend/tst_qlerpblend.cpp +++ b/tests/auto/animation/qlerpblend/tst_qlerpblend.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include #include @@ -84,8 +84,8 @@ private Q_SLOTS: { // GIVEN Qt3DAnimation::QLerpBlend lerpBlend; - Qt3DAnimation::QAnimationClip clip1; - Qt3DAnimation::QAnimationClip clip2; + Qt3DAnimation::QAnimationClipLoader clip1; + Qt3DAnimation::QAnimationClipLoader clip2; lerpBlend.addClip(&clip1); lerpBlend.addClip(&clip2); -- cgit v1.2.3 From d9d2f46e402a29c9e52279ec257f76320e699c9b Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Thu, 16 Feb 2017 18:31:57 +0000 Subject: Add Status property to QAnimationClipLoader Task-number: QTBUG-58898 Change-Id: I4c384c88c4846bc664dee1e050cc14f1dc9fd3fa Reviewed-by: Kevin Ottens --- .../tst_animationcliploader.cpp | 34 ++++++++++++++++++++ .../tst_qanimationcliploader.cpp | 36 +++++++++++++++++++++- 2 files changed, 69 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp b/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp index 8c001b5f7..35c0d5e54 100644 --- a/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp +++ b/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp @@ -73,6 +73,7 @@ private Q_SLOTS: QCOMPARE(backendClip.isEnabled(), false); QCOMPARE(backendClip.source(), QUrl()); QCOMPARE(backendClip.duration(), 0.0f); + QCOMPARE(backendClip.status(), Qt3DAnimation::QAnimationClipLoader::NotReady); // GIVEN Qt3DAnimation::QAnimationClipLoader clip; @@ -87,6 +88,7 @@ private Q_SLOTS: QCOMPARE(backendClip.source(), QUrl()); QCOMPARE(backendClip.isEnabled(), false); QCOMPARE(backendClip.duration(), 0.0f); + QCOMPARE(backendClip.status(), Qt3DAnimation::QAnimationClipLoader::NotReady); } void checkPropertyChanges() @@ -148,6 +150,38 @@ private Q_SLOTS: arbiter.events.clear(); } + + void checkStatusPropertyBackendNotification() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::Animation::AnimationClipLoader backendClip; + backendClip.setEnabled(true); + Qt3DCore::QBackendNodePrivate::get(&backendClip)->setArbiter(&arbiter); + + // WHEN + backendClip.setStatus(Qt3DAnimation::QAnimationClipLoader::Error); + + // THEN + QCOMPARE(backendClip.status(), Qt3DAnimation::QAnimationClipLoader::Error); + QCOMPARE(arbiter.events.count(), 1); + Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "status"); + QCOMPARE(change->value().value(), backendClip.status()); + QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isIntermediate, + false); + + arbiter.events.clear(); + + // WHEN + backendClip.setStatus(Qt3DAnimation::QAnimationClipLoader::Error); + + // THEN + QCOMPARE(backendClip.status(), Qt3DAnimation::QAnimationClipLoader::Error); + QCOMPARE(arbiter.events.count(), 0); + + arbiter.events.clear(); + } }; QTEST_APPLESS_MAIN(tst_AnimationClipLoader) diff --git a/tests/auto/animation/qanimationcliploader/tst_qanimationcliploader.cpp b/tests/auto/animation/qanimationcliploader/tst_qanimationcliploader.cpp index 352587d51..968ad8764 100644 --- a/tests/auto/animation/qanimationcliploader/tst_qanimationcliploader.cpp +++ b/tests/auto/animation/qanimationcliploader/tst_qanimationcliploader.cpp @@ -37,7 +37,7 @@ #include #include -class tst_QAnimationClipLoader : public QObject +class tst_QAnimationClipLoader : public Qt3DAnimation::QAnimationClipLoader { Q_OBJECT @@ -50,6 +50,7 @@ private Q_SLOTS: // THEN QCOMPARE(clip.source(), QUrl()); QCOMPARE(clip.duration(), 0.0f); + QCOMPARE(clip.status(), Qt3DAnimation::QAnimationClipLoader::NotReady); } void checkPropertyChanges() @@ -159,6 +160,39 @@ private Q_SLOTS: } } + + void checkStatusPropertyUpdate() + { + // GIVEN + qRegisterMetaType("Status"); + TestArbiter arbiter; + arbiter.setArbiterOnNode(this); + QSignalSpy spy(this, SIGNAL(statusChanged(Status))); + const Qt3DAnimation::QAnimationClipLoader::Status newStatus = Qt3DAnimation::QAnimationClipLoader::Error; + + // THEN + QVERIFY(spy.isValid()); + + // WHEN + Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::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); + } }; QTEST_MAIN(tst_QAnimationClipLoader) -- cgit v1.2.3 From de28bb3aafdfc2dec80aa65cd426bf2b74718358 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Wed, 22 Feb 2017 10:21:05 +0000 Subject: Rename QLerpBlend to QLerpClipBlend Also rename backend class accordingly. Task-number: QTBUG-58904 Change-Id: I3a8d3898507e5055c2727e4bb1b19b06fdba988b Reviewed-by: Kevin Ottens --- tests/auto/animation/animation.pro | 4 +- .../tst_blendedclipanimator.cpp | 4 +- .../animation/clipblendnode/tst_clipblendnode.cpp | 10 +- .../tst_clipblendnodevisitor.cpp | 42 ++--- tests/auto/animation/lerpblend/lerpblend.pro | 11 -- tests/auto/animation/lerpblend/tst_lerpblend.cpp | 149 ----------------- .../auto/animation/lerpclipblend/lerpclipblend.pro | 11 ++ .../animation/lerpclipblend/tst_lerpclipblend.cpp | 149 +++++++++++++++++ .../tst_qblendedclipanimator.cpp | 10 +- tests/auto/animation/qlerpblend/qlerpblend.pro | 11 -- tests/auto/animation/qlerpblend/tst_qlerpblend.cpp | 185 --------------------- .../animation/qlerpclipblend/qlerpclipblend.pro | 12 ++ .../qlerpclipblend/tst_qlerpclipblend.cpp | 185 +++++++++++++++++++++ 13 files changed, 392 insertions(+), 391 deletions(-) delete mode 100644 tests/auto/animation/lerpblend/lerpblend.pro delete mode 100644 tests/auto/animation/lerpblend/tst_lerpblend.cpp create mode 100644 tests/auto/animation/lerpclipblend/lerpclipblend.pro create mode 100644 tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp delete mode 100644 tests/auto/animation/qlerpblend/qlerpblend.pro delete mode 100644 tests/auto/animation/qlerpblend/tst_qlerpblend.cpp create mode 100644 tests/auto/animation/qlerpclipblend/qlerpclipblend.pro create mode 100644 tests/auto/animation/qlerpclipblend/tst_qlerpclipblend.cpp (limited to 'tests/auto') diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index 859f6c04f..e62c431d6 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -19,10 +19,10 @@ qtConfig(private_tests) { blendedclipanimator \ channelmapper \ channelmapping \ - qlerpblend \ + qlerpclipblend \ clipblendnodemanager \ clipblendnode \ - lerpblend \ + lerpclipblend \ clipblendnodevisitor \ qadditiveblend \ additiveblend diff --git a/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp b/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp index 5c0cef708..2b26fbfce 100644 --- a/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp +++ b/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include #include @@ -99,7 +99,7 @@ private Q_SLOTS: // GIVEN Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator; Qt3DAnimation::QChannelMapper mapper; - Qt3DAnimation::QLerpBlend blendTree; + Qt3DAnimation::QLerpClipBlend blendTree; blendedClipAnimator.setRunning(true); blendedClipAnimator.setBlendTree(&blendTree); blendedClipAnimator.setChannelMapper(&mapper); diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp index d8163f13f..3e0ebf4f6 100644 --- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -28,7 +28,7 @@ #include -#include +#include #include #include #include @@ -77,7 +77,7 @@ private Q_SLOTS: void checkInitializeFromPeer() { // GIVEN - Qt3DAnimation::QLerpBlend clipBlendNode; + Qt3DAnimation::QLerpClipBlend clipBlendNode; Qt3DAnimation::QAnimationClipLoader clip; clipBlendNode.addClip(&clip); @@ -153,7 +153,7 @@ private Q_SLOTS: } { // WHEN - Qt3DAnimation::QLerpBlend clipBlendChild; + Qt3DAnimation::QLerpClipBlend clipBlendChild; // Will be destroyed when manager is destroyed TestClipBlendNode *backenChildClipBlendNode = new TestClipBlendNode(); backendClipBlendNode.setClipBlendNodeManager(&manager); @@ -182,8 +182,8 @@ private Q_SLOTS: // GIVEN TestClipBlendNode *backendClipBlendNode = new TestClipBlendNode(); TestClipBlendNode *backendChildClipBlendNode = new TestClipBlendNode(); - Qt3DAnimation::QLerpBlend clipBlendParent; - Qt3DAnimation::QLerpBlend childClipBlend(&clipBlendParent); + Qt3DAnimation::QLerpClipBlend clipBlendParent; + Qt3DAnimation::QLerpClipBlend childClipBlend(&clipBlendParent); Qt3DAnimation::Animation::ClipBlendNodeManager manager; backendClipBlendNode->setClipBlendNodeManager(&manager); backendChildClipBlendNode->setClipBlendNodeManager(&manager); diff --git a/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp b/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp index 78f0f1202..77f835985 100644 --- a/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp +++ b/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp @@ -31,8 +31,8 @@ #include #include #include -#include -#include +#include +#include #include "qbackendnodetester.h" class tst_ClipBlendNodeVisitor : public Qt3DCore::QBackendNodeTester @@ -43,17 +43,17 @@ private Q_SLOTS: void checkVisitAllNodes() { // GIVEN - Qt3DAnimation::QLerpBlend rootBlendNode; - Qt3DAnimation::QLerpBlend childBlendNode1(&rootBlendNode); - Qt3DAnimation::QLerpBlend childBlendNode2(&rootBlendNode); - Qt3DAnimation::QLerpBlend childBlendNode11(&childBlendNode1); - Qt3DAnimation::QLerpBlend childBlendNode12(&childBlendNode1); - - Qt3DAnimation::Animation::LerpBlend *backendRootBlendNode = new Qt3DAnimation::Animation::LerpBlend(); - Qt3DAnimation::Animation::LerpBlend *backendChildBlendNode1 = new Qt3DAnimation::Animation::LerpBlend(); - Qt3DAnimation::Animation::LerpBlend *backendChildBlendNode2 = new Qt3DAnimation::Animation::LerpBlend(); - Qt3DAnimation::Animation::LerpBlend *backendChildBlendNode11 = new Qt3DAnimation::Animation::LerpBlend(); - Qt3DAnimation::Animation::LerpBlend *backendChildBlendNode12 = new Qt3DAnimation::Animation::LerpBlend(); + Qt3DAnimation::QLerpClipBlend rootBlendNode; + Qt3DAnimation::QLerpClipBlend childBlendNode1(&rootBlendNode); + Qt3DAnimation::QLerpClipBlend childBlendNode2(&rootBlendNode); + Qt3DAnimation::QLerpClipBlend childBlendNode11(&childBlendNode1); + Qt3DAnimation::QLerpClipBlend childBlendNode12(&childBlendNode1); + + Qt3DAnimation::Animation::LerpClipBlend *backendRootBlendNode = new Qt3DAnimation::Animation::LerpClipBlend(); + Qt3DAnimation::Animation::LerpClipBlend *backendChildBlendNode1 = new Qt3DAnimation::Animation::LerpClipBlend(); + Qt3DAnimation::Animation::LerpClipBlend *backendChildBlendNode2 = new Qt3DAnimation::Animation::LerpClipBlend(); + Qt3DAnimation::Animation::LerpClipBlend *backendChildBlendNode11 = new Qt3DAnimation::Animation::LerpClipBlend(); + Qt3DAnimation::Animation::LerpClipBlend *backendChildBlendNode12 = new Qt3DAnimation::Animation::LerpClipBlend(); Qt3DAnimation::Animation::ClipBlendNodeManager manager; backendRootBlendNode->setClipBlendNodeManager(&manager); @@ -112,9 +112,9 @@ private Q_SLOTS: void checkDoesntCrashIfRootNodeIsNotFound() { // GIVEN - Qt3DAnimation::QLerpBlend rootBlendNode; + Qt3DAnimation::QLerpClipBlend rootBlendNode; - Qt3DAnimation::Animation::LerpBlend *backendRootBlendNode = new Qt3DAnimation::Animation::LerpBlend(); + Qt3DAnimation::Animation::LerpClipBlend *backendRootBlendNode = new Qt3DAnimation::Animation::LerpClipBlend(); Qt3DAnimation::Animation::ClipBlendNodeManager manager; backendRootBlendNode->setClipBlendNodeManager(&manager); @@ -139,13 +139,13 @@ private Q_SLOTS: void checkDoesntCrashIfChildNodeIsNotFound() { // GIVEN - Qt3DAnimation::QLerpBlend rootBlendNode; - Qt3DAnimation::QLerpBlend childBlendNode1(&rootBlendNode); - Qt3DAnimation::QLerpBlend childBlendNode2(&rootBlendNode); + Qt3DAnimation::QLerpClipBlend rootBlendNode; + Qt3DAnimation::QLerpClipBlend childBlendNode1(&rootBlendNode); + Qt3DAnimation::QLerpClipBlend childBlendNode2(&rootBlendNode); - Qt3DAnimation::Animation::LerpBlend *backendRootBlendNode = new Qt3DAnimation::Animation::LerpBlend(); - Qt3DAnimation::Animation::LerpBlend *backendChildBlendNode1 = new Qt3DAnimation::Animation::LerpBlend(); - Qt3DAnimation::Animation::LerpBlend *backendChildBlendNode2 = new Qt3DAnimation::Animation::LerpBlend(); + Qt3DAnimation::Animation::LerpClipBlend *backendRootBlendNode = new Qt3DAnimation::Animation::LerpClipBlend(); + Qt3DAnimation::Animation::LerpClipBlend *backendChildBlendNode1 = new Qt3DAnimation::Animation::LerpClipBlend(); + Qt3DAnimation::Animation::LerpClipBlend *backendChildBlendNode2 = new Qt3DAnimation::Animation::LerpClipBlend(); Qt3DAnimation::Animation::ClipBlendNodeManager manager; backendRootBlendNode->setClipBlendNodeManager(&manager); diff --git a/tests/auto/animation/lerpblend/lerpblend.pro b/tests/auto/animation/lerpblend/lerpblend.pro deleted file mode 100644 index bc2cc383b..000000000 --- a/tests/auto/animation/lerpblend/lerpblend.pro +++ /dev/null @@ -1,11 +0,0 @@ -TEMPLATE = app - -TARGET = tst_lerpblend - -QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib - -CONFIG += testcase - -SOURCES += tst_lerpblend.cpp - -include(../../core/common/common.pri) diff --git a/tests/auto/animation/lerpblend/tst_lerpblend.cpp b/tests/auto/animation/lerpblend/tst_lerpblend.cpp deleted file mode 100644 index b268fb42f..000000000 --- a/tests/auto/animation/lerpblend/tst_lerpblend.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Paul Lemire -** 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 -#include -#include -#include -#include -#include -#include "qbackendnodetester.h" - -class tst_LerpBlend : public Qt3DCore::QBackendNodeTester -{ - Q_OBJECT - -private Q_SLOTS: - - void checkInitialState() - { - // GIVEN - Qt3DAnimation::Animation::LerpBlend backendLerpBlend; - - // THEN - QCOMPARE(backendLerpBlend.isEnabled(), false); - QVERIFY(backendLerpBlend.peerId().isNull()); - QCOMPARE(backendLerpBlend.blendFactor(), 0.0f); - QCOMPARE(backendLerpBlend.blendType(), Qt3DAnimation::Animation::ClipBlendNode::LerpBlendType); - } - - void checkInitializeFromPeer() - { - // GIVEN - Qt3DAnimation::QLerpBlend lerpBlend; - Qt3DAnimation::QAnimationClipLoader clip; - lerpBlend.setBlendFactor(0.8f); - lerpBlend.addClip(&clip); - - { - // WHEN - Qt3DAnimation::Animation::LerpBlend backendLerpBlend; - simulateInitialization(&lerpBlend, &backendLerpBlend); - - // THEN - QCOMPARE(backendLerpBlend.isEnabled(), true); - QCOMPARE(backendLerpBlend.peerId(), lerpBlend.id()); - QCOMPARE(backendLerpBlend.blendFactor(), 0.8f); - QCOMPARE(backendLerpBlend.clipIds().size(), 1); - QCOMPARE(backendLerpBlend.clipIds().first(), clip.id()); - } - { - // WHEN - Qt3DAnimation::Animation::LerpBlend backendLerpBlend; - lerpBlend.setEnabled(false); - simulateInitialization(&lerpBlend, &backendLerpBlend); - - // THEN - QCOMPARE(backendLerpBlend.peerId(), lerpBlend.id()); - QCOMPARE(backendLerpBlend.isEnabled(), false); - } - } - - void checkSceneChangeEvents() - { - // GIVEN - Qt3DAnimation::Animation::LerpBlend backendLerpBlend; - { - // WHEN - const bool newValue = false; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("enabled"); - change->setValue(newValue); - backendLerpBlend.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendLerpBlend.isEnabled(), newValue); - } - { - // WHEN - const float newValue = 0.883f; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("blendFactor"); - change->setValue(QVariant::fromValue(newValue)); - backendLerpBlend.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendLerpBlend.blendFactor(), newValue); - } - } - - void checkBlend_data() - { - QTest::addColumn("value1"); - QTest::addColumn("value2"); - QTest::addColumn("blendFactor"); - QTest::addColumn("result"); - - QTest::newRow("0_blending") << 8.0f << 5.0f << 0.0f << 8.0f; - QTest::newRow("0.5_blending") << 8.0f << 5.0f << 0.5f << 6.5f; - QTest::newRow("1_blending") << 8.0f << 5.0f << 1.0f << 5.0f; - } - - void checkBlend() - { - // GIVEN - QFETCH(float, value1); - QFETCH(float, value2); - QFETCH(float, blendFactor); - QFETCH(float, result); - Qt3DAnimation::Animation::LerpBlend lerpBlend; - - // WHEN - lerpBlend.setBlendFactor(blendFactor); - const float computed = lerpBlend.blend(value1, value2); - - // THEN - QCOMPARE(computed, result); - } - -}; - -QTEST_MAIN(tst_LerpBlend) - -#include "tst_lerpblend.moc" diff --git a/tests/auto/animation/lerpclipblend/lerpclipblend.pro b/tests/auto/animation/lerpclipblend/lerpclipblend.pro new file mode 100644 index 000000000..e5447cccf --- /dev/null +++ b/tests/auto/animation/lerpclipblend/lerpclipblend.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +TARGET = tst_lerpclipblend + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += tst_lerpclipblend.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp new file mode 100644 index 000000000..18eaa064e --- /dev/null +++ b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Paul Lemire +** 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 +#include +#include +#include +#include +#include +#include "qbackendnodetester.h" + +class tst_LerpClipBlend : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + + void checkInitialState() + { + // GIVEN + Qt3DAnimation::Animation::LerpClipBlend backendLerpBlend; + + // THEN + QCOMPARE(backendLerpBlend.isEnabled(), false); + QVERIFY(backendLerpBlend.peerId().isNull()); + QCOMPARE(backendLerpBlend.blendFactor(), 0.0f); + QCOMPARE(backendLerpBlend.blendType(), Qt3DAnimation::Animation::ClipBlendNode::LerpBlendType); + } + + void checkInitializeFromPeer() + { + // GIVEN + Qt3DAnimation::QLerpClipBlend lerpBlend; + Qt3DAnimation::QAnimationClipLoader clip; + lerpBlend.setBlendFactor(0.8f); + lerpBlend.addClip(&clip); + + { + // WHEN + Qt3DAnimation::Animation::LerpClipBlend backendLerpBlend; + simulateInitialization(&lerpBlend, &backendLerpBlend); + + // THEN + QCOMPARE(backendLerpBlend.isEnabled(), true); + QCOMPARE(backendLerpBlend.peerId(), lerpBlend.id()); + QCOMPARE(backendLerpBlend.blendFactor(), 0.8f); + QCOMPARE(backendLerpBlend.clipIds().size(), 1); + QCOMPARE(backendLerpBlend.clipIds().first(), clip.id()); + } + { + // WHEN + Qt3DAnimation::Animation::LerpClipBlend backendLerpBlend; + lerpBlend.setEnabled(false); + simulateInitialization(&lerpBlend, &backendLerpBlend); + + // THEN + QCOMPARE(backendLerpBlend.peerId(), lerpBlend.id()); + QCOMPARE(backendLerpBlend.isEnabled(), false); + } + } + + void checkSceneChangeEvents() + { + // GIVEN + Qt3DAnimation::Animation::LerpClipBlend backendLerpBlend; + { + // WHEN + const bool newValue = false; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("enabled"); + change->setValue(newValue); + backendLerpBlend.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendLerpBlend.isEnabled(), newValue); + } + { + // WHEN + const float newValue = 0.883f; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("blendFactor"); + change->setValue(QVariant::fromValue(newValue)); + backendLerpBlend.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendLerpBlend.blendFactor(), newValue); + } + } + + void checkBlend_data() + { + QTest::addColumn("value1"); + QTest::addColumn("value2"); + QTest::addColumn("blendFactor"); + QTest::addColumn("result"); + + QTest::newRow("0_blending") << 8.0f << 5.0f << 0.0f << 8.0f; + QTest::newRow("0.5_blending") << 8.0f << 5.0f << 0.5f << 6.5f; + QTest::newRow("1_blending") << 8.0f << 5.0f << 1.0f << 5.0f; + } + + void checkBlend() + { + // GIVEN + QFETCH(float, value1); + QFETCH(float, value2); + QFETCH(float, blendFactor); + QFETCH(float, result); + Qt3DAnimation::Animation::LerpClipBlend lerpBlend; + + // WHEN + lerpBlend.setBlendFactor(blendFactor); + const float computed = lerpBlend.blend(value1, value2); + + // THEN + QCOMPARE(computed, result); + } + +}; + +QTEST_MAIN(tst_LerpClipBlend) + +#include "tst_lerpclipblend.moc" diff --git a/tests/auto/animation/qblendedclipanimator/tst_qblendedclipanimator.cpp b/tests/auto/animation/qblendedclipanimator/tst_qblendedclipanimator.cpp index d8c18bac9..3ab8e007b 100644 --- a/tests/auto/animation/qblendedclipanimator/tst_qblendedclipanimator.cpp +++ b/tests/auto/animation/qblendedclipanimator/tst_qblendedclipanimator.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include @@ -71,7 +71,7 @@ private Q_SLOTS: { // WHEN QSignalSpy spy(&blendedClipAnimator, SIGNAL(blendTreeChanged(QAbstractClipBlendNode *))); - Qt3DAnimation::QLerpBlend newValue; + Qt3DAnimation::QLerpClipBlend newValue; blendedClipAnimator.setBlendTree(&newValue); // THEN @@ -152,7 +152,7 @@ private Q_SLOTS: // GIVEN Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator; Qt3DAnimation::QChannelMapper channelMapper; - Qt3DAnimation::QLerpBlend blendRoot; + Qt3DAnimation::QLerpClipBlend blendRoot; blendedClipAnimator.setBlendTree(&blendRoot); blendedClipAnimator.setChannelMapper(&channelMapper); @@ -214,7 +214,7 @@ private Q_SLOTS: TestArbiter arbiter; Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator; arbiter.setArbiterOnNode(&blendedClipAnimator); - Qt3DAnimation::QLerpBlend blendRoot; + Qt3DAnimation::QLerpClipBlend blendRoot; { // WHEN @@ -249,7 +249,7 @@ private Q_SLOTS: { // WHEN - Qt3DAnimation::QLerpBlend blendRoot; + Qt3DAnimation::QLerpClipBlend blendRoot; blendedClipAnimator.setBlendTree(&blendRoot); QCOMPARE(blendedClipAnimator.blendTree(), &blendRoot); diff --git a/tests/auto/animation/qlerpblend/qlerpblend.pro b/tests/auto/animation/qlerpblend/qlerpblend.pro deleted file mode 100644 index f5bdc848f..000000000 --- a/tests/auto/animation/qlerpblend/qlerpblend.pro +++ /dev/null @@ -1,11 +0,0 @@ -TEMPLATE = app - -TARGET = tst_qlerpblend - -QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib - -CONFIG += testcase - -SOURCES += tst_qlerpblend.cpp - -include(../../core/common/common.pri) diff --git a/tests/auto/animation/qlerpblend/tst_qlerpblend.cpp b/tests/auto/animation/qlerpblend/tst_qlerpblend.cpp deleted file mode 100644 index 25e403007..000000000 --- a/tests/auto/animation/qlerpblend/tst_qlerpblend.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Paul Lemire -** 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "testpostmanarbiter.h" - -class tst_QLerpBlend : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - - void checkDefaultConstruction() - { - // GIVEN - Qt3DAnimation::QLerpBlend lerpBlend; - - // THEN - QCOMPARE(lerpBlend.blendFactor(), 0.0f); - } - - void checkPropertyChanges() - { - // GIVEN - Qt3DAnimation::QLerpBlend lerpBlend; - - { - // WHEN - QSignalSpy spy(&lerpBlend, SIGNAL(blendFactorChanged(float))); - const float newValue = 0.5f; - lerpBlend.setBlendFactor(newValue); - - // THEN - QVERIFY(spy.isValid()); - QCOMPARE(lerpBlend.blendFactor(), newValue); - QCOMPARE(spy.count(), 1); - - // WHEN - spy.clear(); - lerpBlend.setBlendFactor(newValue); - - // THEN - QCOMPARE(lerpBlend.blendFactor(), newValue); - QCOMPARE(spy.count(), 0); - } - } - - void checkCreationData() - { - // GIVEN - Qt3DAnimation::QLerpBlend lerpBlend; - Qt3DAnimation::QAnimationClipLoader clip1; - Qt3DAnimation::QAnimationClipLoader clip2; - - lerpBlend.addClip(&clip1); - lerpBlend.addClip(&clip2); - lerpBlend.setBlendFactor(0.8f); - - - // WHEN - QVector creationChanges; - - { - Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&lerpBlend); - creationChanges = creationChangeGenerator.creationChanges(); - } - - // THEN - { - QCOMPARE(creationChanges.size(), 3); // 1 + 2 clips - - const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); - const Qt3DAnimation::QLerpBlendData cloneData = creationChangeData->data; - - QCOMPARE(lerpBlend.blendFactor(), cloneData.blendFactor); - QCOMPARE(lerpBlend.id(), creationChangeData->subjectId()); - QCOMPARE(lerpBlend.isEnabled(), true); - QCOMPARE(lerpBlend.isEnabled(), creationChangeData->isNodeEnabled()); - QCOMPARE(lerpBlend.metaObject(), creationChangeData->metaObject()); - QCOMPARE(creationChangeData->clips().size(), 2); - QCOMPARE(creationChangeData->clips().first(), clip1.id()); - QCOMPARE(creationChangeData->clips().last(), clip2.id()); - QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); - } - - // WHEN - lerpBlend.setEnabled(false); - - { - Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&lerpBlend); - creationChanges = creationChangeGenerator.creationChanges(); - } - - // THEN - { - QCOMPARE(creationChanges.size(), 3); // 1 + 2 clips - - const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); - const Qt3DAnimation::QLerpBlendData cloneData = creationChangeData->data; - - QCOMPARE(lerpBlend.blendFactor(), cloneData.blendFactor); - QCOMPARE(lerpBlend.id(), creationChangeData->subjectId()); - QCOMPARE(lerpBlend.isEnabled(), false); - QCOMPARE(lerpBlend.isEnabled(), creationChangeData->isNodeEnabled()); - QCOMPARE(lerpBlend.metaObject(), creationChangeData->metaObject()); - QCOMPARE(creationChangeData->clips().size(), 2); - QCOMPARE(creationChangeData->clips().first(), clip1.id()); - QCOMPARE(creationChangeData->clips().last(), clip2.id()); - QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); - } - } - - void checkBlendFactorUpdate() - { - // GIVEN - TestArbiter arbiter; - Qt3DAnimation::QLerpBlend lerpBlend; - arbiter.setArbiterOnNode(&lerpBlend); - - { - // WHEN - lerpBlend.setBlendFactor(0.4f); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "blendFactor"); - QCOMPARE(change->value().value(), lerpBlend.blendFactor()); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - - arbiter.events.clear(); - } - - { - // WHEN - lerpBlend.setBlendFactor(0.4f); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - } - - } - -}; - -QTEST_MAIN(tst_QLerpBlend) - -#include "tst_qlerpblend.moc" diff --git a/tests/auto/animation/qlerpclipblend/qlerpclipblend.pro b/tests/auto/animation/qlerpclipblend/qlerpclipblend.pro new file mode 100644 index 000000000..3c26dbb19 --- /dev/null +++ b/tests/auto/animation/qlerpclipblend/qlerpclipblend.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_qlerpclipblend + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += \ + tst_qlerpclipblend.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/qlerpclipblend/tst_qlerpclipblend.cpp b/tests/auto/animation/qlerpclipblend/tst_qlerpclipblend.cpp new file mode 100644 index 000000000..5f3bdeccf --- /dev/null +++ b/tests/auto/animation/qlerpclipblend/tst_qlerpclipblend.cpp @@ -0,0 +1,185 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Paul Lemire +** 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "testpostmanarbiter.h" + +class tst_QLerpClipBlend : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void checkDefaultConstruction() + { + // GIVEN + Qt3DAnimation::QLerpClipBlend lerpBlend; + + // THEN + QCOMPARE(lerpBlend.blendFactor(), 0.0f); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::QLerpClipBlend lerpBlend; + + { + // WHEN + QSignalSpy spy(&lerpBlend, SIGNAL(blendFactorChanged(float))); + const float newValue = 0.5f; + lerpBlend.setBlendFactor(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(lerpBlend.blendFactor(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + lerpBlend.setBlendFactor(newValue); + + // THEN + QCOMPARE(lerpBlend.blendFactor(), newValue); + QCOMPARE(spy.count(), 0); + } + } + + void checkCreationData() + { + // GIVEN + Qt3DAnimation::QLerpClipBlend lerpBlend; + Qt3DAnimation::QAnimationClipLoader clip1; + Qt3DAnimation::QAnimationClipLoader clip2; + + lerpBlend.addClip(&clip1); + lerpBlend.addClip(&clip2); + lerpBlend.setBlendFactor(0.8f); + + + // WHEN + QVector creationChanges; + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&lerpBlend); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 3); // 1 + 2 clips + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DAnimation::QLerpClipBlendData cloneData = creationChangeData->data; + + QCOMPARE(lerpBlend.blendFactor(), cloneData.blendFactor); + QCOMPARE(lerpBlend.id(), creationChangeData->subjectId()); + QCOMPARE(lerpBlend.isEnabled(), true); + QCOMPARE(lerpBlend.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(lerpBlend.metaObject(), creationChangeData->metaObject()); + QCOMPARE(creationChangeData->clips().size(), 2); + QCOMPARE(creationChangeData->clips().first(), clip1.id()); + QCOMPARE(creationChangeData->clips().last(), clip2.id()); + QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); + } + + // WHEN + lerpBlend.setEnabled(false); + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&lerpBlend); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 3); // 1 + 2 clips + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DAnimation::QLerpClipBlendData cloneData = creationChangeData->data; + + QCOMPARE(lerpBlend.blendFactor(), cloneData.blendFactor); + QCOMPARE(lerpBlend.id(), creationChangeData->subjectId()); + QCOMPARE(lerpBlend.isEnabled(), false); + QCOMPARE(lerpBlend.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(lerpBlend.metaObject(), creationChangeData->metaObject()); + QCOMPARE(creationChangeData->clips().size(), 2); + QCOMPARE(creationChangeData->clips().first(), clip1.id()); + QCOMPARE(creationChangeData->clips().last(), clip2.id()); + QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); + } + } + + void checkBlendFactorUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::QLerpClipBlend lerpBlend; + arbiter.setArbiterOnNode(&lerpBlend); + + { + // WHEN + lerpBlend.setBlendFactor(0.4f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "blendFactor"); + QCOMPARE(change->value().value(), lerpBlend.blendFactor()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + lerpBlend.setBlendFactor(0.4f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + +}; + +QTEST_MAIN(tst_QLerpClipBlend) + +#include "tst_qlerpclipblend.moc" -- cgit v1.2.3 From 28938073a228a38c2a5beccdb3357b5a8c172def Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Wed, 22 Feb 2017 13:59:57 +0000 Subject: Rename QAdditiveBlend -> QAdditiveClipBlend Also rename backend type accordingly. Task-number: QTBUG-58903 Change-Id: Ia1ad670937487dd84768e79d8c2be59ed3b6d0a5 Reviewed-by: Kevin Ottens --- .../auto/animation/additiveblend/additiveblend.pro | 12 -- .../animation/additiveblend/tst_additiveblend.cpp | 148 ----------------- .../additiveclipblend/additiveclipblend.pro | 12 ++ .../additiveclipblend/tst_additiveclipblend.cpp | 148 +++++++++++++++++ tests/auto/animation/animation.pro | 4 +- .../animation/qadditiveblend/qadditiveblend.pro | 12 -- .../qadditiveblend/tst_qadditiveblend.cpp | 185 --------------------- .../qadditiveclipblend/qadditiveclipblend.pro | 12 ++ .../qadditiveclipblend/tst_qadditiveclipblend.cpp | 185 +++++++++++++++++++++ 9 files changed, 359 insertions(+), 359 deletions(-) delete mode 100644 tests/auto/animation/additiveblend/additiveblend.pro delete mode 100644 tests/auto/animation/additiveblend/tst_additiveblend.cpp create mode 100644 tests/auto/animation/additiveclipblend/additiveclipblend.pro create mode 100644 tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp delete mode 100644 tests/auto/animation/qadditiveblend/qadditiveblend.pro delete mode 100644 tests/auto/animation/qadditiveblend/tst_qadditiveblend.cpp create mode 100644 tests/auto/animation/qadditiveclipblend/qadditiveclipblend.pro create mode 100644 tests/auto/animation/qadditiveclipblend/tst_qadditiveclipblend.cpp (limited to 'tests/auto') diff --git a/tests/auto/animation/additiveblend/additiveblend.pro b/tests/auto/animation/additiveblend/additiveblend.pro deleted file mode 100644 index e61417c73..000000000 --- a/tests/auto/animation/additiveblend/additiveblend.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = app - -TARGET = tst_additiveblend - -QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib - -CONFIG += testcase - -SOURCES += \ - tst_additiveblend.cpp - -include(../../core/common/common.pri) diff --git a/tests/auto/animation/additiveblend/tst_additiveblend.cpp b/tests/auto/animation/additiveblend/tst_additiveblend.cpp deleted file mode 100644 index c94efedd8..000000000 --- a/tests/auto/animation/additiveblend/tst_additiveblend.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Paul Lemire -** 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 -#include -#include -#include -#include -#include -#include "qbackendnodetester.h" - -class tst_AdditiveBlend : public Qt3DCore::QBackendNodeTester -{ - Q_OBJECT - -private Q_SLOTS: - - void checkInitialState() - { - // GIVEN - Qt3DAnimation::Animation::AdditiveBlend backendAdditiveBlend; - - // THEN - QCOMPARE(backendAdditiveBlend.isEnabled(), false); - QVERIFY(backendAdditiveBlend.peerId().isNull()); - QCOMPARE(backendAdditiveBlend.blendFactor(), 0.0f); - QCOMPARE(backendAdditiveBlend.blendType(), Qt3DAnimation::Animation::ClipBlendNode::AdditiveBlendType); - } - - void checkInitializeFromPeer() - { - // GIVEN - Qt3DAnimation::QAdditiveBlend additiveBlend; - Qt3DAnimation::QAnimationClipLoader clip; - additiveBlend.setBlendFactor(0.8f); - additiveBlend.addClip(&clip); - - { - // WHEN - Qt3DAnimation::Animation::AdditiveBlend backendAdditiveBlend; - simulateInitialization(&additiveBlend, &backendAdditiveBlend); - - // THEN - QCOMPARE(backendAdditiveBlend.isEnabled(), true); - QCOMPARE(backendAdditiveBlend.peerId(), additiveBlend.id()); - QCOMPARE(backendAdditiveBlend.blendFactor(), 0.8f); - QCOMPARE(backendAdditiveBlend.clipIds().size(), 1); - QCOMPARE(backendAdditiveBlend.clipIds().first(), clip.id()); - } - { - // WHEN - Qt3DAnimation::Animation::AdditiveBlend backendAdditiveBlend; - additiveBlend.setEnabled(false); - simulateInitialization(&additiveBlend, &backendAdditiveBlend); - - // THEN - QCOMPARE(backendAdditiveBlend.peerId(), additiveBlend.id()); - QCOMPARE(backendAdditiveBlend.isEnabled(), false); - } - } - - void checkSceneChangeEvents() - { - // GIVEN - Qt3DAnimation::Animation::AdditiveBlend backendAdditiveBlend; - { - // WHEN - const bool newValue = false; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("enabled"); - change->setValue(newValue); - backendAdditiveBlend.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendAdditiveBlend.isEnabled(), newValue); - } - { - // WHEN - const float newValue = 0.883f; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("blendFactor"); - change->setValue(QVariant::fromValue(newValue)); - backendAdditiveBlend.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendAdditiveBlend.blendFactor(), newValue); - } - } - - void checkBlend_data() - { - QTest::addColumn("value1"); - QTest::addColumn("value2"); - QTest::addColumn("blendFactor"); - QTest::addColumn("result"); - - QTest::newRow("0_blending") << 8.0f << 5.0f << 0.0f << 8.0f; - QTest::newRow("0.5_blending") << 8.0f << 5.0f << 0.5f << 10.5f; - QTest::newRow("1_blending") << 8.0f << 5.0f << 1.0f << 13.0f; - } - - void checkBlend() - { - // GIVEN - QFETCH(float, value1); - QFETCH(float, value2); - QFETCH(float, blendFactor); - QFETCH(float, result); - Qt3DAnimation::Animation::AdditiveBlend addBlend; - - // WHEN - addBlend.setBlendFactor(blendFactor); - const float computed = addBlend.blend(value1, value2); - - // THEN - QCOMPARE(computed, result); - } -}; - -QTEST_MAIN(tst_AdditiveBlend) - -#include "tst_additiveblend.moc" diff --git a/tests/auto/animation/additiveclipblend/additiveclipblend.pro b/tests/auto/animation/additiveclipblend/additiveclipblend.pro new file mode 100644 index 000000000..09b2e1156 --- /dev/null +++ b/tests/auto/animation/additiveclipblend/additiveclipblend.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_additiveclipblend + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += \ + tst_additiveclipblend.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp new file mode 100644 index 000000000..4875d67cc --- /dev/null +++ b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Paul Lemire +** 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 +#include +#include +#include +#include +#include +#include "qbackendnodetester.h" + +class tst_AdditiveClipBlend : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + + void checkInitialState() + { + // GIVEN + Qt3DAnimation::Animation::AdditiveClipBlend backendAdditiveBlend; + + // THEN + QCOMPARE(backendAdditiveBlend.isEnabled(), false); + QVERIFY(backendAdditiveBlend.peerId().isNull()); + QCOMPARE(backendAdditiveBlend.blendFactor(), 0.0f); + QCOMPARE(backendAdditiveBlend.blendType(), Qt3DAnimation::Animation::ClipBlendNode::AdditiveBlendType); + } + + void checkInitializeFromPeer() + { + // GIVEN + Qt3DAnimation::QAdditiveClipBlend additiveBlend; + Qt3DAnimation::QAnimationClipLoader clip; + additiveBlend.setBlendFactor(0.8f); + additiveBlend.addClip(&clip); + + { + // WHEN + Qt3DAnimation::Animation::AdditiveClipBlend backendAdditiveBlend; + simulateInitialization(&additiveBlend, &backendAdditiveBlend); + + // THEN + QCOMPARE(backendAdditiveBlend.isEnabled(), true); + QCOMPARE(backendAdditiveBlend.peerId(), additiveBlend.id()); + QCOMPARE(backendAdditiveBlend.blendFactor(), 0.8f); + QCOMPARE(backendAdditiveBlend.clipIds().size(), 1); + QCOMPARE(backendAdditiveBlend.clipIds().first(), clip.id()); + } + { + // WHEN + Qt3DAnimation::Animation::AdditiveClipBlend backendAdditiveBlend; + additiveBlend.setEnabled(false); + simulateInitialization(&additiveBlend, &backendAdditiveBlend); + + // THEN + QCOMPARE(backendAdditiveBlend.peerId(), additiveBlend.id()); + QCOMPARE(backendAdditiveBlend.isEnabled(), false); + } + } + + void checkSceneChangeEvents() + { + // GIVEN + Qt3DAnimation::Animation::AdditiveClipBlend backendAdditiveBlend; + { + // WHEN + const bool newValue = false; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("enabled"); + change->setValue(newValue); + backendAdditiveBlend.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendAdditiveBlend.isEnabled(), newValue); + } + { + // WHEN + const float newValue = 0.883f; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("blendFactor"); + change->setValue(QVariant::fromValue(newValue)); + backendAdditiveBlend.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendAdditiveBlend.blendFactor(), newValue); + } + } + + void checkBlend_data() + { + QTest::addColumn("value1"); + QTest::addColumn("value2"); + QTest::addColumn("blendFactor"); + QTest::addColumn("result"); + + QTest::newRow("0_blending") << 8.0f << 5.0f << 0.0f << 8.0f; + QTest::newRow("0.5_blending") << 8.0f << 5.0f << 0.5f << 10.5f; + QTest::newRow("1_blending") << 8.0f << 5.0f << 1.0f << 13.0f; + } + + void checkBlend() + { + // GIVEN + QFETCH(float, value1); + QFETCH(float, value2); + QFETCH(float, blendFactor); + QFETCH(float, result); + Qt3DAnimation::Animation::AdditiveClipBlend addBlend; + + // WHEN + addBlend.setBlendFactor(blendFactor); + const float computed = addBlend.blend(value1, value2); + + // THEN + QCOMPARE(computed, result); + } +}; + +QTEST_MAIN(tst_AdditiveClipBlend) + +#include "tst_additiveclipblend.moc" diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index e62c431d6..e756290f7 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -24,6 +24,6 @@ qtConfig(private_tests) { clipblendnode \ lerpclipblend \ clipblendnodevisitor \ - qadditiveblend \ - additiveblend + qadditiveclipblend \ + additiveclipblend } diff --git a/tests/auto/animation/qadditiveblend/qadditiveblend.pro b/tests/auto/animation/qadditiveblend/qadditiveblend.pro deleted file mode 100644 index b3f2a4599..000000000 --- a/tests/auto/animation/qadditiveblend/qadditiveblend.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = app - -TARGET = tst_qadditiveblend - -QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib - -CONFIG += testcase - -SOURCES += \ - tst_qadditiveblend.cpp - -include(../../core/common/common.pri) diff --git a/tests/auto/animation/qadditiveblend/tst_qadditiveblend.cpp b/tests/auto/animation/qadditiveblend/tst_qadditiveblend.cpp deleted file mode 100644 index 369ca0078..000000000 --- a/tests/auto/animation/qadditiveblend/tst_qadditiveblend.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Paul Lemire -** 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "testpostmanarbiter.h" - -class tst_QAdditiveBlend : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - - void checkDefaultConstruction() - { - // GIVEN - Qt3DAnimation::QAdditiveBlend addBlend; - - // THEN - QCOMPARE(addBlend.blendFactor(), 0.0f); - } - - void checkPropertyChanges() - { - // GIVEN - Qt3DAnimation::QAdditiveBlend addBlend; - - { - // WHEN - QSignalSpy spy(&addBlend, SIGNAL(blendFactorChanged(float))); - const float newValue = 0.5f; - addBlend.setBlendFactor(newValue); - - // THEN - QVERIFY(spy.isValid()); - QCOMPARE(addBlend.blendFactor(), newValue); - QCOMPARE(spy.count(), 1); - - // WHEN - spy.clear(); - addBlend.setBlendFactor(newValue); - - // THEN - QCOMPARE(addBlend.blendFactor(), newValue); - QCOMPARE(spy.count(), 0); - } - } - - void checkCreationData() - { - // GIVEN - Qt3DAnimation::QAdditiveBlend addBlend; - Qt3DAnimation::QAnimationClipLoader clip1; - Qt3DAnimation::QAnimationClipLoader clip2; - - addBlend.addClip(&clip1); - addBlend.addClip(&clip2); - addBlend.setBlendFactor(0.8f); - - - // WHEN - QVector creationChanges; - - { - Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&addBlend); - creationChanges = creationChangeGenerator.creationChanges(); - } - - // THEN - { - QCOMPARE(creationChanges.size(), 3); // 1 + 2 clips - - const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); - const Qt3DAnimation::QAdditiveBlendData cloneData = creationChangeData->data; - - QCOMPARE(addBlend.blendFactor(), cloneData.blendFactor); - QCOMPARE(addBlend.id(), creationChangeData->subjectId()); - QCOMPARE(addBlend.isEnabled(), true); - QCOMPARE(addBlend.isEnabled(), creationChangeData->isNodeEnabled()); - QCOMPARE(addBlend.metaObject(), creationChangeData->metaObject()); - QCOMPARE(creationChangeData->clips().size(), 2); - QCOMPARE(creationChangeData->clips().first(), clip1.id()); - QCOMPARE(creationChangeData->clips().last(), clip2.id()); - QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); - } - - // WHEN - addBlend.setEnabled(false); - - { - Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&addBlend); - creationChanges = creationChangeGenerator.creationChanges(); - } - - // THEN - { - QCOMPARE(creationChanges.size(), 3); // 1 + 2 clips - - const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); - const Qt3DAnimation::QAdditiveBlendData cloneData = creationChangeData->data; - - QCOMPARE(addBlend.blendFactor(), cloneData.blendFactor); - QCOMPARE(addBlend.id(), creationChangeData->subjectId()); - QCOMPARE(addBlend.isEnabled(), false); - QCOMPARE(addBlend.isEnabled(), creationChangeData->isNodeEnabled()); - QCOMPARE(addBlend.metaObject(), creationChangeData->metaObject()); - QCOMPARE(creationChangeData->clips().size(), 2); - QCOMPARE(creationChangeData->clips().first(), clip1.id()); - QCOMPARE(creationChangeData->clips().last(), clip2.id()); - QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); - } - } - - void checkBlendFactorUpdate() - { - // GIVEN - TestArbiter arbiter; - Qt3DAnimation::QAdditiveBlend addBlend; - arbiter.setArbiterOnNode(&addBlend); - - { - // WHEN - addBlend.setBlendFactor(0.4f); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "blendFactor"); - QCOMPARE(change->value().value(), addBlend.blendFactor()); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - - arbiter.events.clear(); - } - - { - // WHEN - addBlend.setBlendFactor(0.4f); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - } - - } - -}; - -QTEST_MAIN(tst_QAdditiveBlend) - -#include "tst_qadditiveblend.moc" diff --git a/tests/auto/animation/qadditiveclipblend/qadditiveclipblend.pro b/tests/auto/animation/qadditiveclipblend/qadditiveclipblend.pro new file mode 100644 index 000000000..e5c6797ee --- /dev/null +++ b/tests/auto/animation/qadditiveclipblend/qadditiveclipblend.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_qadditiveclipblend + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += \ + tst_qadditiveclipblend.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/qadditiveclipblend/tst_qadditiveclipblend.cpp b/tests/auto/animation/qadditiveclipblend/tst_qadditiveclipblend.cpp new file mode 100644 index 000000000..f0e40ca67 --- /dev/null +++ b/tests/auto/animation/qadditiveclipblend/tst_qadditiveclipblend.cpp @@ -0,0 +1,185 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Paul Lemire +** 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "testpostmanarbiter.h" + +class tst_QAdditiveClipBlend : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void checkDefaultConstruction() + { + // GIVEN + Qt3DAnimation::QAdditiveClipBlend addBlend; + + // THEN + QCOMPARE(addBlend.blendFactor(), 0.0f); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::QAdditiveClipBlend addBlend; + + { + // WHEN + QSignalSpy spy(&addBlend, SIGNAL(blendFactorChanged(float))); + const float newValue = 0.5f; + addBlend.setBlendFactor(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(addBlend.blendFactor(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + addBlend.setBlendFactor(newValue); + + // THEN + QCOMPARE(addBlend.blendFactor(), newValue); + QCOMPARE(spy.count(), 0); + } + } + + void checkCreationData() + { + // GIVEN + Qt3DAnimation::QAdditiveClipBlend addBlend; + Qt3DAnimation::QAnimationClipLoader clip1; + Qt3DAnimation::QAnimationClipLoader clip2; + + addBlend.addClip(&clip1); + addBlend.addClip(&clip2); + addBlend.setBlendFactor(0.8f); + + + // WHEN + QVector creationChanges; + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&addBlend); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 3); // 1 + 2 clips + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DAnimation::QAdditiveClipBlendData cloneData = creationChangeData->data; + + QCOMPARE(addBlend.blendFactor(), cloneData.blendFactor); + QCOMPARE(addBlend.id(), creationChangeData->subjectId()); + QCOMPARE(addBlend.isEnabled(), true); + QCOMPARE(addBlend.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(addBlend.metaObject(), creationChangeData->metaObject()); + QCOMPARE(creationChangeData->clips().size(), 2); + QCOMPARE(creationChangeData->clips().first(), clip1.id()); + QCOMPARE(creationChangeData->clips().last(), clip2.id()); + QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); + } + + // WHEN + addBlend.setEnabled(false); + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&addBlend); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 3); // 1 + 2 clips + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DAnimation::QAdditiveClipBlendData cloneData = creationChangeData->data; + + QCOMPARE(addBlend.blendFactor(), cloneData.blendFactor); + QCOMPARE(addBlend.id(), creationChangeData->subjectId()); + QCOMPARE(addBlend.isEnabled(), false); + QCOMPARE(addBlend.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(addBlend.metaObject(), creationChangeData->metaObject()); + QCOMPARE(creationChangeData->clips().size(), 2); + QCOMPARE(creationChangeData->clips().first(), clip1.id()); + QCOMPARE(creationChangeData->clips().last(), clip2.id()); + QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); + } + } + + void checkBlendFactorUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::QAdditiveClipBlend addBlend; + arbiter.setArbiterOnNode(&addBlend); + + { + // WHEN + addBlend.setBlendFactor(0.4f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "blendFactor"); + QCOMPARE(change->value().value(), addBlend.blendFactor()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + addBlend.setBlendFactor(0.4f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + +}; + +QTEST_MAIN(tst_QAdditiveClipBlend) + +#include "tst_qadditiveclipblend.moc" -- cgit v1.2.3 From 3624ddb7beeff87196cf1ccc6684dd05457945e1 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Wed, 22 Feb 2017 15:23:33 +0000 Subject: Add startClip and endClip properties to QLerpClipBlend Task-number: QTBUG-58904 Change-Id: I67a28b5f311d0065e8ca81df692de33ef1aeefcf Reviewed-by: Kevin Ottens --- .../qlerpclipblend/tst_qlerpclipblend.cpp | 197 +++++++++++++++++++-- 1 file changed, 187 insertions(+), 10 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/qlerpclipblend/tst_qlerpclipblend.cpp b/tests/auto/animation/qlerpclipblend/tst_qlerpclipblend.cpp index 5f3bdeccf..d6b449fdb 100644 --- a/tests/auto/animation/qlerpclipblend/tst_qlerpclipblend.cpp +++ b/tests/auto/animation/qlerpclipblend/tst_qlerpclipblend.cpp @@ -44,6 +44,10 @@ class tst_QLerpClipBlend : public QObject Q_OBJECT private Q_SLOTS: + void initTestCase() + { + qRegisterMetaType(); + } void checkDefaultConstruction() { @@ -52,6 +56,8 @@ private Q_SLOTS: // THEN QCOMPARE(lerpBlend.blendFactor(), 0.0f); + QCOMPARE(lerpBlend.startClip(), static_cast(nullptr)); + QCOMPARE(lerpBlend.endClip(), static_cast(nullptr)); } void checkPropertyChanges() @@ -78,17 +84,57 @@ private Q_SLOTS: QCOMPARE(lerpBlend.blendFactor(), newValue); QCOMPARE(spy.count(), 0); } + + { + // WHEN + QSignalSpy spy(&lerpBlend, SIGNAL(startClipChanged(Qt3DAnimation::QAbstractClipBlendNode*))); + auto newValue = new Qt3DAnimation::QLerpClipBlend(); + lerpBlend.setStartClip(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(lerpBlend.startClip(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + lerpBlend.setStartClip(newValue); + + // THEN + QCOMPARE(lerpBlend.startClip(), newValue); + QCOMPARE(spy.count(), 0); + } + + { + // WHEN + QSignalSpy spy(&lerpBlend, SIGNAL(endClipChanged(Qt3DAnimation::QAbstractClipBlendNode*))); + auto newValue = new Qt3DAnimation::QLerpClipBlend(); + lerpBlend.setEndClip(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(lerpBlend.endClip(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + lerpBlend.setEndClip(newValue); + + // THEN + QCOMPARE(lerpBlend.endClip(), newValue); + QCOMPARE(spy.count(), 0); + } } void checkCreationData() { // GIVEN Qt3DAnimation::QLerpClipBlend lerpBlend; - Qt3DAnimation::QAnimationClipLoader clip1; - Qt3DAnimation::QAnimationClipLoader clip2; + Qt3DAnimation::QLerpClipBlend startClip; + Qt3DAnimation::QLerpClipBlend endClip; - lerpBlend.addClip(&clip1); - lerpBlend.addClip(&clip2); + lerpBlend.setStartClip(&startClip); + lerpBlend.setEndClip(&endClip); lerpBlend.setBlendFactor(0.8f); @@ -112,9 +158,8 @@ private Q_SLOTS: QCOMPARE(lerpBlend.isEnabled(), true); QCOMPARE(lerpBlend.isEnabled(), creationChangeData->isNodeEnabled()); QCOMPARE(lerpBlend.metaObject(), creationChangeData->metaObject()); - QCOMPARE(creationChangeData->clips().size(), 2); - QCOMPARE(creationChangeData->clips().first(), clip1.id()); - QCOMPARE(creationChangeData->clips().last(), clip2.id()); + QCOMPARE(cloneData.startClipId, startClip.id()); + QCOMPARE(cloneData.endClipId, endClip.id()); QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); } @@ -138,9 +183,8 @@ private Q_SLOTS: QCOMPARE(lerpBlend.isEnabled(), false); QCOMPARE(lerpBlend.isEnabled(), creationChangeData->isNodeEnabled()); QCOMPARE(lerpBlend.metaObject(), creationChangeData->metaObject()); - QCOMPARE(creationChangeData->clips().size(), 2); - QCOMPARE(creationChangeData->clips().first(), clip1.id()); - QCOMPARE(creationChangeData->clips().last(), clip2.id()); + QCOMPARE(cloneData.startClipId, startClip.id()); + QCOMPARE(cloneData.endClipId, endClip.id()); QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); } } @@ -178,6 +222,139 @@ private Q_SLOTS: } + void checkStartClipUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::QLerpClipBlend lerpBlend; + arbiter.setArbiterOnNode(&lerpBlend); + auto startClip = new Qt3DAnimation::QLerpClipBlend(); + + { + // WHEN + lerpBlend.setStartClip(startClip); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "startClip"); + QCOMPARE(change->value().value(), lerpBlend.startClip()->id()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + lerpBlend.setStartClip(startClip); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + } + + void checkEndClipUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::QLerpClipBlend lerpBlend; + arbiter.setArbiterOnNode(&lerpBlend); + auto endClip = new Qt3DAnimation::QLerpClipBlend(); + + { + // WHEN + lerpBlend.setEndClip(endClip); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "endClip"); + QCOMPARE(change->value().value(), lerpBlend.endClip()->id()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + lerpBlend.setEndClip(endClip); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + } + + void checkStartClipBookkeeping() + { + // GIVEN + QScopedPointer lerpBlend(new Qt3DAnimation::QLerpClipBlend); + { + // WHEN + Qt3DAnimation::QLerpClipBlend clip; + lerpBlend->setStartClip(&clip); + + // THEN + QCOMPARE(clip.parent(), lerpBlend.data()); + QCOMPARE(lerpBlend->startClip(), &clip); + } + // THEN (Should not crash and clip be unset) + QVERIFY(lerpBlend->startClip() == nullptr); + + { + // WHEN + Qt3DAnimation::QLerpClipBlend someOtherLerpBlend; + QScopedPointer clip(new Qt3DAnimation::QLerpClipBlend(&someOtherLerpBlend)); + lerpBlend->setStartClip(clip.data()); + + // THEN + QCOMPARE(clip->parent(), &someOtherLerpBlend); + QCOMPARE(lerpBlend->startClip(), clip.data()); + + // WHEN + lerpBlend.reset(); + clip.reset(); + + // THEN Should not crash when the effect is destroyed (tests for failed removal of destruction helper) + } + } + + void checkEndClipBookkeeping() + { + // GIVEN + QScopedPointer lerpBlend(new Qt3DAnimation::QLerpClipBlend); + { + // WHEN + Qt3DAnimation::QLerpClipBlend clip; + lerpBlend->setEndClip(&clip); + + // THEN + QCOMPARE(clip.parent(), lerpBlend.data()); + QCOMPARE(lerpBlend->endClip(), &clip); + } + // THEN (Should not crash and clip be unset) + QVERIFY(lerpBlend->endClip() == nullptr); + + { + // WHEN + Qt3DAnimation::QLerpClipBlend someOtherLerpBlend; + QScopedPointer clip(new Qt3DAnimation::QLerpClipBlend(&someOtherLerpBlend)); + lerpBlend->setEndClip(clip.data()); + + // THEN + QCOMPARE(clip->parent(), &someOtherLerpBlend); + QCOMPARE(lerpBlend->endClip(), clip.data()); + + // WHEN + lerpBlend.reset(); + clip.reset(); + + // THEN Should not crash when the effect is destroyed (tests for failed removal of destruction helper) + } + } }; QTEST_MAIN(tst_QLerpClipBlend) -- cgit v1.2.3 From 87cf108f5da481d9a4eeb5d0fbb7145ecef4863e Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Thu, 23 Feb 2017 09:27:58 +0000 Subject: Rename blendFactor on QAdditiveClipBlend to additiveFactor Likewise for the backend node. Task-number: QTBUG-58903 Change-Id: I2a2d084f80cf5b36a2ba6c1c03f511a1f74a2f62 Reviewed-by: Kevin Ottens --- .../additiveclipblend/tst_additiveclipblend.cpp | 12 +++++----- .../qadditiveclipblend/tst_qadditiveclipblend.cpp | 26 +++++++++++----------- 2 files changed, 19 insertions(+), 19 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp index 4875d67cc..211da5788 100644 --- a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp +++ b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp @@ -49,7 +49,7 @@ private Q_SLOTS: // THEN QCOMPARE(backendAdditiveBlend.isEnabled(), false); QVERIFY(backendAdditiveBlend.peerId().isNull()); - QCOMPARE(backendAdditiveBlend.blendFactor(), 0.0f); + QCOMPARE(backendAdditiveBlend.additiveFactor(), 0.0f); QCOMPARE(backendAdditiveBlend.blendType(), Qt3DAnimation::Animation::ClipBlendNode::AdditiveBlendType); } @@ -58,7 +58,7 @@ private Q_SLOTS: // GIVEN Qt3DAnimation::QAdditiveClipBlend additiveBlend; Qt3DAnimation::QAnimationClipLoader clip; - additiveBlend.setBlendFactor(0.8f); + additiveBlend.setAdditiveFactor(0.8f); additiveBlend.addClip(&clip); { @@ -69,7 +69,7 @@ private Q_SLOTS: // THEN QCOMPARE(backendAdditiveBlend.isEnabled(), true); QCOMPARE(backendAdditiveBlend.peerId(), additiveBlend.id()); - QCOMPARE(backendAdditiveBlend.blendFactor(), 0.8f); + QCOMPARE(backendAdditiveBlend.additiveFactor(), 0.8f); QCOMPARE(backendAdditiveBlend.clipIds().size(), 1); QCOMPARE(backendAdditiveBlend.clipIds().first(), clip.id()); } @@ -104,12 +104,12 @@ private Q_SLOTS: // WHEN const float newValue = 0.883f; const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("blendFactor"); + change->setPropertyName("additiveFactor"); change->setValue(QVariant::fromValue(newValue)); backendAdditiveBlend.sceneChangeEvent(change); // THEN - QCOMPARE(backendAdditiveBlend.blendFactor(), newValue); + QCOMPARE(backendAdditiveBlend.additiveFactor(), newValue); } } @@ -135,7 +135,7 @@ private Q_SLOTS: Qt3DAnimation::Animation::AdditiveClipBlend addBlend; // WHEN - addBlend.setBlendFactor(blendFactor); + addBlend.setAdditiveFactor(blendFactor); const float computed = addBlend.blend(value1, value2); // THEN diff --git a/tests/auto/animation/qadditiveclipblend/tst_qadditiveclipblend.cpp b/tests/auto/animation/qadditiveclipblend/tst_qadditiveclipblend.cpp index f0e40ca67..cded4b569 100644 --- a/tests/auto/animation/qadditiveclipblend/tst_qadditiveclipblend.cpp +++ b/tests/auto/animation/qadditiveclipblend/tst_qadditiveclipblend.cpp @@ -51,7 +51,7 @@ private Q_SLOTS: Qt3DAnimation::QAdditiveClipBlend addBlend; // THEN - QCOMPARE(addBlend.blendFactor(), 0.0f); + QCOMPARE(addBlend.additiveFactor(), 0.0f); } void checkPropertyChanges() @@ -61,21 +61,21 @@ private Q_SLOTS: { // WHEN - QSignalSpy spy(&addBlend, SIGNAL(blendFactorChanged(float))); + QSignalSpy spy(&addBlend, SIGNAL(additiveFactorChanged(float))); const float newValue = 0.5f; - addBlend.setBlendFactor(newValue); + addBlend.setAdditiveFactor(newValue); // THEN QVERIFY(spy.isValid()); - QCOMPARE(addBlend.blendFactor(), newValue); + QCOMPARE(addBlend.additiveFactor(), newValue); QCOMPARE(spy.count(), 1); // WHEN spy.clear(); - addBlend.setBlendFactor(newValue); + addBlend.setAdditiveFactor(newValue); // THEN - QCOMPARE(addBlend.blendFactor(), newValue); + QCOMPARE(addBlend.additiveFactor(), newValue); QCOMPARE(spy.count(), 0); } } @@ -89,7 +89,7 @@ private Q_SLOTS: addBlend.addClip(&clip1); addBlend.addClip(&clip2); - addBlend.setBlendFactor(0.8f); + addBlend.setAdditiveFactor(0.8f); // WHEN @@ -107,7 +107,7 @@ private Q_SLOTS: const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); const Qt3DAnimation::QAdditiveClipBlendData cloneData = creationChangeData->data; - QCOMPARE(addBlend.blendFactor(), cloneData.blendFactor); + QCOMPARE(addBlend.additiveFactor(), cloneData.additiveFactor); QCOMPARE(addBlend.id(), creationChangeData->subjectId()); QCOMPARE(addBlend.isEnabled(), true); QCOMPARE(addBlend.isEnabled(), creationChangeData->isNodeEnabled()); @@ -133,7 +133,7 @@ private Q_SLOTS: const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); const Qt3DAnimation::QAdditiveClipBlendData cloneData = creationChangeData->data; - QCOMPARE(addBlend.blendFactor(), cloneData.blendFactor); + QCOMPARE(addBlend.additiveFactor(), cloneData.additiveFactor); QCOMPARE(addBlend.id(), creationChangeData->subjectId()); QCOMPARE(addBlend.isEnabled(), false); QCOMPARE(addBlend.isEnabled(), creationChangeData->isNodeEnabled()); @@ -154,14 +154,14 @@ private Q_SLOTS: { // WHEN - addBlend.setBlendFactor(0.4f); + addBlend.setAdditiveFactor(0.4f); QCoreApplication::processEvents(); // THEN QCOMPARE(arbiter.events.size(), 1); auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "blendFactor"); - QCOMPARE(change->value().value(), addBlend.blendFactor()); + QCOMPARE(change->propertyName(), "additiveFactor"); + QCOMPARE(change->value().value(), addBlend.additiveFactor()); QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); arbiter.events.clear(); @@ -169,7 +169,7 @@ private Q_SLOTS: { // WHEN - addBlend.setBlendFactor(0.4f); + addBlend.setAdditiveFactor(0.4f); QCoreApplication::processEvents(); // THEN -- cgit v1.2.3 From 7253d10a1026be03eab83edd628b72455d7bcd28 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Thu, 23 Feb 2017 10:51:33 +0000 Subject: Add baseClip and additiveClip properties to QAdditiveClipBlend Also added corresponding backend node properties. Task-number: QTBUG-58903 Change-Id: I4b441e305c1ddfc062b215b713a6b894960cdd4b Reviewed-by: Kevin Ottens --- .../additiveclipblend/tst_additiveclipblend.cpp | 30 ++++ .../qadditiveclipblend/tst_qadditiveclipblend.cpp | 199 +++++++++++++++++++-- 2 files changed, 218 insertions(+), 11 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp index 211da5788..e6777cd6a 100644 --- a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp +++ b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp @@ -49,6 +49,8 @@ private Q_SLOTS: // THEN QCOMPARE(backendAdditiveBlend.isEnabled(), false); QVERIFY(backendAdditiveBlend.peerId().isNull()); + QCOMPARE(backendAdditiveBlend.baseClipId(), Qt3DCore::QNodeId()); + QCOMPARE(backendAdditiveBlend.additiveClipId(), Qt3DCore::QNodeId()); QCOMPARE(backendAdditiveBlend.additiveFactor(), 0.0f); QCOMPARE(backendAdditiveBlend.blendType(), Qt3DAnimation::Animation::ClipBlendNode::AdditiveBlendType); } @@ -57,7 +59,11 @@ private Q_SLOTS: { // GIVEN Qt3DAnimation::QAdditiveClipBlend additiveBlend; + Qt3DAnimation::QAdditiveClipBlend baseClip; + Qt3DAnimation::QAdditiveClipBlend additiveClip; Qt3DAnimation::QAnimationClipLoader clip; + additiveBlend.setBaseClip(&baseClip); + additiveBlend.setAdditiveClip(&additiveClip); additiveBlend.setAdditiveFactor(0.8f); additiveBlend.addClip(&clip); @@ -69,6 +75,8 @@ private Q_SLOTS: // THEN QCOMPARE(backendAdditiveBlend.isEnabled(), true); QCOMPARE(backendAdditiveBlend.peerId(), additiveBlend.id()); + QCOMPARE(backendAdditiveBlend.baseClipId(), baseClip.id()); + QCOMPARE(backendAdditiveBlend.additiveClipId(), additiveClip.id()); QCOMPARE(backendAdditiveBlend.additiveFactor(), 0.8f); QCOMPARE(backendAdditiveBlend.clipIds().size(), 1); QCOMPARE(backendAdditiveBlend.clipIds().first(), clip.id()); @@ -111,6 +119,28 @@ private Q_SLOTS: // THEN QCOMPARE(backendAdditiveBlend.additiveFactor(), newValue); } + { + // WHEN + const Qt3DAnimation::QAdditiveClipBlend newValue; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("baseClip"); + change->setValue(QVariant::fromValue(newValue.id())); + backendAdditiveBlend.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendAdditiveBlend.baseClipId(), newValue.id()); + } + { + // WHEN + const Qt3DAnimation::QAdditiveClipBlend newValue; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("additiveClip"); + change->setValue(QVariant::fromValue(newValue.id())); + backendAdditiveBlend.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendAdditiveBlend.additiveClipId(), newValue.id()); + } } void checkBlend_data() diff --git a/tests/auto/animation/qadditiveclipblend/tst_qadditiveclipblend.cpp b/tests/auto/animation/qadditiveclipblend/tst_qadditiveclipblend.cpp index cded4b569..536853b1f 100644 --- a/tests/auto/animation/qadditiveclipblend/tst_qadditiveclipblend.cpp +++ b/tests/auto/animation/qadditiveclipblend/tst_qadditiveclipblend.cpp @@ -44,6 +44,10 @@ class tst_QAdditiveClipBlend : public QObject Q_OBJECT private Q_SLOTS: + void initTestCase() + { + qRegisterMetaType(); + } void checkDefaultConstruction() { @@ -52,6 +56,8 @@ private Q_SLOTS: // THEN QCOMPARE(addBlend.additiveFactor(), 0.0f); + QCOMPARE(addBlend.baseClip(), static_cast(nullptr)); + QCOMPARE(addBlend.additiveClip(), static_cast(nullptr)); } void checkPropertyChanges() @@ -78,17 +84,57 @@ private Q_SLOTS: QCOMPARE(addBlend.additiveFactor(), newValue); QCOMPARE(spy.count(), 0); } + + { + // WHEN + QSignalSpy spy(&addBlend, SIGNAL(baseClipChanged(Qt3DAnimation::QAbstractClipBlendNode*))); + auto newValue = new Qt3DAnimation::QAdditiveClipBlend(); + addBlend.setBaseClip(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(addBlend.baseClip(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + addBlend.setBaseClip(newValue); + + // THEN + QCOMPARE(addBlend.baseClip(), newValue); + QCOMPARE(spy.count(), 0); + } + + { + // WHEN + QSignalSpy spy(&addBlend, SIGNAL(additiveClipChanged(Qt3DAnimation::QAbstractClipBlendNode*))); + auto newValue = new Qt3DAnimation::QAdditiveClipBlend(); + addBlend.setAdditiveClip(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(addBlend.additiveClip(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + addBlend.setAdditiveClip(newValue); + + // THEN + QCOMPARE(addBlend.additiveClip(), newValue); + QCOMPARE(spy.count(), 0); + } } void checkCreationData() { // GIVEN Qt3DAnimation::QAdditiveClipBlend addBlend; - Qt3DAnimation::QAnimationClipLoader clip1; - Qt3DAnimation::QAnimationClipLoader clip2; + Qt3DAnimation::QAdditiveClipBlend baseClip; + Qt3DAnimation::QAdditiveClipBlend additiveClip; - addBlend.addClip(&clip1); - addBlend.addClip(&clip2); + addBlend.setBaseClip(&baseClip); + addBlend.setAdditiveClip(&additiveClip); addBlend.setAdditiveFactor(0.8f); @@ -112,9 +158,8 @@ private Q_SLOTS: QCOMPARE(addBlend.isEnabled(), true); QCOMPARE(addBlend.isEnabled(), creationChangeData->isNodeEnabled()); QCOMPARE(addBlend.metaObject(), creationChangeData->metaObject()); - QCOMPARE(creationChangeData->clips().size(), 2); - QCOMPARE(creationChangeData->clips().first(), clip1.id()); - QCOMPARE(creationChangeData->clips().last(), clip2.id()); + QCOMPARE(cloneData.baseClipId, baseClip.id()); + QCOMPARE(cloneData.additiveClipId, additiveClip.id()); QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); } @@ -138,14 +183,13 @@ private Q_SLOTS: QCOMPARE(addBlend.isEnabled(), false); QCOMPARE(addBlend.isEnabled(), creationChangeData->isNodeEnabled()); QCOMPARE(addBlend.metaObject(), creationChangeData->metaObject()); - QCOMPARE(creationChangeData->clips().size(), 2); - QCOMPARE(creationChangeData->clips().first(), clip1.id()); - QCOMPARE(creationChangeData->clips().last(), clip2.id()); + QCOMPARE(cloneData.baseClipId, baseClip.id()); + QCOMPARE(cloneData.additiveClipId, additiveClip.id()); QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); } } - void checkBlendFactorUpdate() + void checkAdditiveFactorUpdate() { // GIVEN TestArbiter arbiter; @@ -178,6 +222,139 @@ private Q_SLOTS: } + void checkBaseClipUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::QAdditiveClipBlend addBlend; + arbiter.setArbiterOnNode(&addBlend); + auto baseClip = new Qt3DAnimation::QAdditiveClipBlend(); + + { + // WHEN + addBlend.setBaseClip(baseClip); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "baseClip"); + QCOMPARE(change->value().value(), addBlend.baseClip()->id()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + addBlend.setBaseClip(baseClip); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + } + + void checkAdditiveClipUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::QAdditiveClipBlend addBlend; + arbiter.setArbiterOnNode(&addBlend); + auto additiveClip = new Qt3DAnimation::QAdditiveClipBlend(); + + { + // WHEN + addBlend.setAdditiveClip(additiveClip); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "additiveClip"); + QCOMPARE(change->value().value(), addBlend.additiveClip()->id()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + addBlend.setAdditiveClip(additiveClip); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + } + + void checkBaseClipBookkeeping() + { + // GIVEN + QScopedPointer additiveBlend(new Qt3DAnimation::QAdditiveClipBlend); + { + // WHEN + Qt3DAnimation::QAdditiveClipBlend clip; + additiveBlend->setBaseClip(&clip); + + // THEN + QCOMPARE(clip.parent(), additiveBlend.data()); + QCOMPARE(additiveBlend->baseClip(), &clip); + } + // THEN (Should not crash and clip be unset) + QVERIFY(additiveBlend->baseClip() == nullptr); + + { + // WHEN + Qt3DAnimation::QAdditiveClipBlend someOtherAdditiveBlend; + QScopedPointer clip(new Qt3DAnimation::QAdditiveClipBlend(&someOtherAdditiveBlend)); + additiveBlend->setBaseClip(clip.data()); + + // THEN + QCOMPARE(clip->parent(), &someOtherAdditiveBlend); + QCOMPARE(additiveBlend->baseClip(), clip.data()); + + // WHEN + additiveBlend.reset(); + clip.reset(); + + // THEN Should not crash when the effect is destroyed (tests for failed removal of destruction helper) + } + } + + void checkAdditiveClipBookkeeping() + { + // GIVEN + QScopedPointer additiveBlend(new Qt3DAnimation::QAdditiveClipBlend); + { + // WHEN + Qt3DAnimation::QAdditiveClipBlend clip; + additiveBlend->setAdditiveClip(&clip); + + // THEN + QCOMPARE(clip.parent(), additiveBlend.data()); + QCOMPARE(additiveBlend->additiveClip(), &clip); + } + // THEN (Should not crash and clip be unset) + QVERIFY(additiveBlend->additiveClip() == nullptr); + + { + // WHEN + Qt3DAnimation::QAdditiveClipBlend someOtherAdditiveBlend; + QScopedPointer clip(new Qt3DAnimation::QAdditiveClipBlend(&someOtherAdditiveBlend)); + additiveBlend->setAdditiveClip(clip.data()); + + // THEN + QCOMPARE(clip->parent(), &someOtherAdditiveBlend); + QCOMPARE(additiveBlend->additiveClip(), clip.data()); + + // WHEN + additiveBlend.reset(); + clip.reset(); + + // THEN Should not crash when the effect is destroyed (tests for failed removal of destruction helper) + } + } }; QTEST_MAIN(tst_QAdditiveClipBlend) -- cgit v1.2.3 From 154c3a9b44082a176a9700b5086a7bc758155a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Fri, 20 Jan 2017 14:27:08 +0200 Subject: Move scene2d to own module and implement conditional plugin loading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add quick3dscene2d module - Add importsscene2d qml module - Modify RenderAspect to load plugins conditionally - change autotests to match the module change Change-Id: If6596472acbd9a377561b2bfd2094a0585c781ac Reviewed-by: Antti Määttä --- tests/auto/render/qscene2d/qscene2d.pro | 2 +- tests/auto/render/qscene2d/tst_qscene2d.cpp | 2 +- tests/auto/render/scene2d/scene2d.pro | 2 +- tests/auto/render/scene2d/tst_scene2d.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/qscene2d/qscene2d.pro b/tests/auto/render/qscene2d/qscene2d.pro index b7458d1c2..b1d4d45a9 100644 --- a/tests/auto/render/qscene2d/qscene2d.pro +++ b/tests/auto/render/qscene2d/qscene2d.pro @@ -2,7 +2,7 @@ TEMPLATE = app TARGET = qscene2d -QT += 3dcore 3dcore-private 3drender 3drender-private testlib 3dquickrender 3dquickrender-private +QT += 3dcore 3dcore-private 3drender 3drender-private testlib 3dquickscene2d 3dquickscene2d-private CONFIG += testcase diff --git a/tests/auto/render/qscene2d/tst_qscene2d.cpp b/tests/auto/render/qscene2d/tst_qscene2d.cpp index 8d27945e4..f0ff2db1e 100644 --- a/tests/auto/render/qscene2d/tst_qscene2d.cpp +++ b/tests/auto/render/qscene2d/tst_qscene2d.cpp @@ -27,7 +27,7 @@ ****************************************************************************/ #include -#include +#include #include #include #include diff --git a/tests/auto/render/scene2d/scene2d.pro b/tests/auto/render/scene2d/scene2d.pro index 8685b0b5b..aacdea3e4 100644 --- a/tests/auto/render/scene2d/scene2d.pro +++ b/tests/auto/render/scene2d/scene2d.pro @@ -2,7 +2,7 @@ TEMPLATE = app TARGET = tst_scene2d -QT += 3dcore 3dcore-private 3drender 3drender-private testlib 3dquickrender 3dquickrender-private +QT += 3dcore 3dcore-private 3drender 3drender-private testlib 3dquickscene2d 3dquickscene2d-private CONFIG += testcase diff --git a/tests/auto/render/scene2d/tst_scene2d.cpp b/tests/auto/render/scene2d/tst_scene2d.cpp index 45ea85b42..b53318e7c 100644 --- a/tests/auto/render/scene2d/tst_scene2d.cpp +++ b/tests/auto/render/scene2d/tst_scene2d.cpp @@ -27,7 +27,7 @@ ****************************************************************************/ #include -#include +#include #include #include #include -- cgit v1.2.3 From 8e1834262da4e7f29b63b8211bbd1419814814c4 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Thu, 23 Feb 2017 16:58:36 +0000 Subject: Add new QClipBlendValue to hold the leaf values of blend trees Will hold a single animation clip to be used as input to a blend tree. Has the advantage of preventing accidentally assigning a blend tree to a simple QClipAnimator in the alternative of making QAbstractClipBlendNode inheriting from QAbstractAnimationClip. Task-number: QTBUG-58901 Change-Id: Id99c1fb4284d0159ec3e520abb650f6595323661 Reviewed-by: Mike Krus --- tests/auto/animation/animation.pro | 3 +- .../animation/qclipblendvalue/qclipblendvalue.pro | 12 ++ .../qclipblendvalue/tst_qclipblendvalue.cpp | 212 +++++++++++++++++++++ 3 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 tests/auto/animation/qclipblendvalue/qclipblendvalue.pro create mode 100644 tests/auto/animation/qclipblendvalue/tst_qclipblendvalue.cpp (limited to 'tests/auto') diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index e756290f7..e4913986a 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -6,7 +6,8 @@ SUBDIRS += \ qclipanimator \ qblendedclipanimator \ qchannelmapping \ - qchannelmapper + qchannelmapper \ + qclipblendvalue qtConfig(private_tests) { SUBDIRS += \ diff --git a/tests/auto/animation/qclipblendvalue/qclipblendvalue.pro b/tests/auto/animation/qclipblendvalue/qclipblendvalue.pro new file mode 100644 index 000000000..b44b387db --- /dev/null +++ b/tests/auto/animation/qclipblendvalue/qclipblendvalue.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_qclipblendvalue + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += \ + tst_qclipblendvalue.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/qclipblendvalue/tst_qclipblendvalue.cpp b/tests/auto/animation/qclipblendvalue/tst_qclipblendvalue.cpp new file mode 100644 index 000000000..6be6970ae --- /dev/null +++ b/tests/auto/animation/qclipblendvalue/tst_qclipblendvalue.cpp @@ -0,0 +1,212 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Paul Lemire +** 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "testpostmanarbiter.h" + +class tst_QClipBlendValue : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void initTestCase() + { + qRegisterMetaType(); + } + + void checkDefaultConstruction() + { + // GIVEN + Qt3DAnimation::QClipBlendValue clipBlendNode; + + // THEN; + QCOMPARE(clipBlendNode.clip(), static_cast(nullptr)); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::QClipBlendValue clipBlendNode; + + { + // WHEN + QSignalSpy spy(&clipBlendNode, SIGNAL(clipChanged(Qt3DAnimation::QAbstractAnimationClip*))); + auto newValue = new Qt3DAnimation::QAnimationClipLoader(); + clipBlendNode.setClip(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(clipBlendNode.clip(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + clipBlendNode.setClip(newValue); + + // THEN + QCOMPARE(clipBlendNode.clip(), newValue); + QCOMPARE(spy.count(), 0); + } + } + + void checkCreationData() + { + // GIVEN + Qt3DAnimation::QClipBlendValue clipBlendNode; + Qt3DAnimation::QAnimationClipLoader clip; + + clipBlendNode.setClip(&clip); + + // WHEN + QVector creationChanges; + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&clipBlendNode); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 2); // 1 + 1 clip + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DAnimation::QClipBlendValueData cloneData = creationChangeData->data; + + QCOMPARE(clipBlendNode.id(), creationChangeData->subjectId()); + QCOMPARE(clipBlendNode.isEnabled(), true); + QCOMPARE(clipBlendNode.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(clipBlendNode.metaObject(), creationChangeData->metaObject()); + QCOMPARE(cloneData.clipId, clip.id()); + QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); + } + + // WHEN + clipBlendNode.setEnabled(false); + + { + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&clipBlendNode); + creationChanges = creationChangeGenerator.creationChanges(); + } + + // THEN + { + QCOMPARE(creationChanges.size(), 2); // 1 + 1 clip + + const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); + const Qt3DAnimation::QClipBlendValueData cloneData = creationChangeData->data; + + QCOMPARE(clipBlendNode.id(), creationChangeData->subjectId()); + QCOMPARE(clipBlendNode.isEnabled(), false); + QCOMPARE(clipBlendNode.isEnabled(), creationChangeData->isNodeEnabled()); + QCOMPARE(clipBlendNode.metaObject(), creationChangeData->metaObject()); + QCOMPARE(cloneData.clipId, clip.id()); + QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); + } + } + + void checkClipUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::QClipBlendValue clipBlendNode; + arbiter.setArbiterOnNode(&clipBlendNode); + auto clip = new Qt3DAnimation::QAnimationClipLoader(); + + { + // WHEN + clipBlendNode.setClip(clip); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "clip"); + QCOMPARE(change->value().value(), clipBlendNode.clip()->id()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + clipBlendNode.setClip(clip); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + } + + void checkStartClipBookkeeping() + { + // GIVEN + QScopedPointer clipBlendNode(new Qt3DAnimation::QClipBlendValue); + { + // WHEN + Qt3DAnimation::QAnimationClipLoader clip; + clipBlendNode->setClip(&clip); + + // THEN + QCOMPARE(clip.parent(), clipBlendNode.data()); + QCOMPARE(clipBlendNode->clip(), &clip); + } + // THEN (Should not crash and clip be unset) + QVERIFY(clipBlendNode->clip() == nullptr); + + { + // WHEN + Qt3DAnimation::QClipBlendValue someOtherNode; + QScopedPointer clip(new Qt3DAnimation::QAnimationClipLoader(&someOtherNode)); + clipBlendNode->setClip(clip.data()); + + // THEN + QCOMPARE(clip->parent(), &someOtherNode); + QCOMPARE(clipBlendNode->clip(), clip.data()); + + // WHEN + clipBlendNode.reset(); + clip.reset(); + + // THEN Should not crash when the effect is destroyed (tests for failed removal of destruction helper) + } + } +}; + +QTEST_MAIN(tst_QClipBlendValue) + +#include "tst_qclipblendvalue.moc" -- cgit v1.2.3 From 58e35c1ea87f5d4ef6a4666623c0f6fa245c4412 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 24 Feb 2017 16:58:08 +0000 Subject: Add ClipBlendValue backend node and test Task-number: QTBUG-58901 Change-Id: Ifa18b6bae2f8db802e6561d23a19435c32fe7559 Reviewed-by: Mike Krus --- tests/auto/animation/animation.pro | 3 +- .../animation/clipblendvalue/clipblendvalue.pro | 12 +++ .../clipblendvalue/tst_clipblendvalue.cpp | 115 +++++++++++++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 tests/auto/animation/clipblendvalue/clipblendvalue.pro create mode 100644 tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp (limited to 'tests/auto') diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index e4913986a..536fb2f21 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -26,5 +26,6 @@ qtConfig(private_tests) { lerpclipblend \ clipblendnodevisitor \ qadditiveclipblend \ - additiveclipblend + additiveclipblend \ + clipblendvalue } diff --git a/tests/auto/animation/clipblendvalue/clipblendvalue.pro b/tests/auto/animation/clipblendvalue/clipblendvalue.pro new file mode 100644 index 000000000..ff50f0bbd --- /dev/null +++ b/tests/auto/animation/clipblendvalue/clipblendvalue.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_clipblendvalue + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += \ + tst_clipblendvalue.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp new file mode 100644 index 000000000..5bed23704 --- /dev/null +++ b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Paul Lemire +** 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 +#include +#include +#include +#include +#include +#include "qbackendnodetester.h" + +class tst_ClipBlendValue : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + void checkInitialState() + { + // GIVEN + Qt3DAnimation::Animation::ClipBlendValue backendClipBlendValue; + + // THEN + QCOMPARE(backendClipBlendValue.isEnabled(), false); + QVERIFY(backendClipBlendValue.peerId().isNull()); + QCOMPARE(backendClipBlendValue.clipId(), Qt3DCore::QNodeId()); + QCOMPARE(backendClipBlendValue.blendType(), Qt3DAnimation::Animation::ClipBlendNode::ValueType); + } + + void checkInitializeFromPeer() + { + // GIVEN + Qt3DAnimation::QClipBlendValue clipBlendValue; + Qt3DAnimation::QAnimationClipLoader clip; + clipBlendValue.setClip(&clip); + + { + // WHEN + Qt3DAnimation::Animation::ClipBlendValue backendClipBlendValue; + simulateInitialization(&clipBlendValue, &backendClipBlendValue); + + // THEN + QCOMPARE(backendClipBlendValue.isEnabled(), true); + QCOMPARE(backendClipBlendValue.peerId(), clipBlendValue.id()); + QCOMPARE(backendClipBlendValue.clipId(), clip.id()); + } + { + // WHEN + Qt3DAnimation::Animation::ClipBlendValue backendClipBlendValue; + clipBlendValue.setEnabled(false); + simulateInitialization(&clipBlendValue, &backendClipBlendValue); + + // THEN + QCOMPARE(backendClipBlendValue.peerId(), clipBlendValue.id()); + QCOMPARE(backendClipBlendValue.isEnabled(), false); + } + } + + void checkSceneChangeEvents() + { + // GIVEN + Qt3DAnimation::Animation::ClipBlendValue backendClipBlendValue; + { + // WHEN + const bool newValue = false; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("enabled"); + change->setValue(newValue); + backendClipBlendValue.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendClipBlendValue.isEnabled(), newValue); + } + { + // WHEN + const Qt3DAnimation::QAnimationClipLoader newValue; + const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); + change->setPropertyName("clip"); + change->setValue(QVariant::fromValue(newValue.id())); + backendClipBlendValue.sceneChangeEvent(change); + + // THEN + QCOMPARE(backendClipBlendValue.clipId(), newValue.id()); + } + } +}; + +QTEST_MAIN(tst_ClipBlendValue) + +#include "tst_clipblendvalue.moc" -- cgit v1.2.3 From 195cb92b8be0159c9fabe672ec67655ea9dad6a6 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Tue, 28 Feb 2017 11:15:12 +0000 Subject: Allow QBackendNodeTester to set peer id of backend nodes This allows to directly create backend nodes without having to create the corresponding frontend node and using simulateInitialization(). Change-Id: I212795f6483f84e3b81e10f92696583841872bb1 Reviewed-by: Mike Krus --- tests/auto/core/common/qbackendnodetester.cpp | 6 ++++++ tests/auto/core/common/qbackendnodetester.h | 1 + 2 files changed, 7 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/core/common/qbackendnodetester.cpp b/tests/auto/core/common/qbackendnodetester.cpp index 8534a05cd..6f87e10d9 100644 --- a/tests/auto/core/common/qbackendnodetester.cpp +++ b/tests/auto/core/common/qbackendnodetester.cpp @@ -47,6 +47,12 @@ QBackendNodeTester::QBackendNodeTester(QObject *parent) { } +void QBackendNodeTester::setPeerId(QBackendNode *backend, QNodeId id) +{ + Q_ASSERT(backend); + backend->setPeerId(id); +} + void QBackendNodeTester::simulateInitialization(QNode *frontend, QBackendNode *backend) { Q_ASSERT(frontend); diff --git a/tests/auto/core/common/qbackendnodetester.h b/tests/auto/core/common/qbackendnodetester.h index fbd6c9581..9f266e40d 100644 --- a/tests/auto/core/common/qbackendnodetester.h +++ b/tests/auto/core/common/qbackendnodetester.h @@ -55,6 +55,7 @@ public: explicit QBackendNodeTester(QObject *parent = 0); // Proxies to allow test classes to call private methods on QBackendNode + void setPeerId(QBackendNode *backend, QNodeId id); void simulateInitialization(QNode *frontend, QBackendNode *backend); void sceneChangeEvent(QBackendNode *backend, const Qt3DCore::QSceneChangePtr &e); }; -- cgit v1.2.3 From 6ad5c82af256c6d2409de451cba166d53c89bbd0 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Tue, 28 Feb 2017 11:18:38 +0000 Subject: Add test for AnimationUtils Will extend in further commits. Change-Id: Idbdd95bdd3cfe0ab3f5d12295d15b32c116bc26b Reviewed-by: Mike Krus --- tests/auto/animation/animation.pro | 3 +- .../animation/animationutils/animationutils.pro | 15 ++++ .../animation/animationutils/animationutils.qrc | 5 ++ tests/auto/animation/animationutils/clip1.json | 48 +++++++++++ .../animationutils/tst_animationutils.cpp | 96 ++++++++++++++++++++++ 5 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 tests/auto/animation/animationutils/animationutils.pro create mode 100644 tests/auto/animation/animationutils/animationutils.qrc create mode 100644 tests/auto/animation/animationutils/clip1.json create mode 100644 tests/auto/animation/animationutils/tst_animationutils.cpp (limited to 'tests/auto') diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index 536fb2f21..a608c6cbb 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -27,5 +27,6 @@ qtConfig(private_tests) { clipblendnodevisitor \ qadditiveclipblend \ additiveclipblend \ - clipblendvalue + clipblendvalue \ + animationutils } diff --git a/tests/auto/animation/animationutils/animationutils.pro b/tests/auto/animation/animationutils/animationutils.pro new file mode 100644 index 000000000..5c7e3c510 --- /dev/null +++ b/tests/auto/animation/animationutils/animationutils.pro @@ -0,0 +1,15 @@ +TEMPLATE = app + +TARGET = tst_animationutils + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += \ + tst_animationutils.cpp + +include(../../core/common/common.pri) + +RESOURCES += \ + animationutils.qrc diff --git a/tests/auto/animation/animationutils/animationutils.qrc b/tests/auto/animation/animationutils/animationutils.qrc new file mode 100644 index 000000000..72234ec64 --- /dev/null +++ b/tests/auto/animation/animationutils/animationutils.qrc @@ -0,0 +1,5 @@ + + + clip1.json + + diff --git a/tests/auto/animation/animationutils/clip1.json b/tests/auto/animation/animationutils/clip1.json new file mode 100644 index 000000000..e54858a2d --- /dev/null +++ b/tests/auto/animation/animationutils/clip1.json @@ -0,0 +1,48 @@ +{ + "animations": [ + { "object": "Cube", + "action": "CubeAction", + "range": [0.0, 60.0], + "groups": [ + { "group": "channelFoo", + "channels": [ + { "name": "x", + "keyframes": [ + { "co": [0.0, 0.0], + "handle_left": [-0.4717472394307454, 0.0], + "handle_right": [0.4717472394307454, 0.0]} + ,{ "co": [1.2083333333333333, 2.430499792098999], + "handle_left": [0.7365860939025879, 1.4711904525756836], + "handle_right": [1.696347713470459, 3.42288875579834]} + ,{ "co": [2.4583333333333335, 5.0], + "handle_left": [1.9703189531962078, 5.0], + "handle_right": [2.9463475545247397, 5.0]} + ]} + ,{ "name": "y", + "keyframes": [ + { "co": [0.0, 0.0], + "handle_left": [-0.4717472394307454, 0.0], + "handle_right": [0.4717472394307454, 0.0]} + ,{ "co": [1.2083333333333333, 3.0], + "handle_left": [0.7365860939025879, 3.0], + "handle_right": [1.696347713470459, 3.0]} + ,{ "co": [2.4583333333333335, 0.0], + "handle_left": [1.9703189531962078, 0.0], + "handle_right": [2.9463475545247397, 0.0]} + ]} + ,{ "name": "z", + "keyframes": [ + { "co": [0.0, 0.0], + "handle_left": [-0.4717472394307454, 0.0], + "handle_right": [0.4717472394307454, 0.0]} + ,{ "co": [1.2083333333333333, 0.0], + "handle_left": [0.7365860939025879, 0.0], + "handle_right": [1.696347713470459, 0.0]} + ,{ "co": [2.4583333333333335, 0.0], + "handle_left": [1.9703189531962078, 0.0], + "handle_right": [2.9463475545247397, 0.0]} + ]} + ]} + ]} + ] +} diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp new file mode 100644 index 000000000..e4170381e --- /dev/null +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** 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: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 +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Qt3DAnimation::Animation; + +class tst_AnimationUtils : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + void checkBuildPropertyMappings() + { + // GIVEN + Handler handler; + + // Create a channel mapping, set properties, and add it to manager + auto channelMappingId = Qt3DCore::QNodeId::createId(); + ChannelMapping *channelMapping = handler.channelMappingManager()->getOrCreateResource(channelMappingId); + setPeerId(channelMapping, channelMappingId); + + auto targetId = Qt3DCore::QNodeId::createId(); + channelMapping->setTargetId(targetId); + channelMapping->setProperty("foo"); + channelMapping->setChannelName("channelFoo"); + channelMapping->setType(static_cast(QVariant::Vector3D)); + + // Create a channel mapper and add mapping to it + auto channelMapperId = Qt3DCore::QNodeId::createId(); + ChannelMapper *channelMapper = handler.channelMapperManager()->getOrCreateResource(channelMapperId); + setPeerId(channelMapper, channelMapperId); + channelMapper->setMappingIds(QVector() << channelMappingId); + + // Create an animation clip + auto clipId = Qt3DCore::QNodeId::createId(); + AnimationClipLoader *clip = handler.animationClipLoaderManager()->getOrCreateResource(clipId); + setPeerId(clip, clipId); + clip->setSource(QUrl("qrc:/clip1.json")); + clip->loadAnimation(); + + // WHEN + // Build the mapping data for the above configuration + QVector mappingData = AnimationUtils::buildPropertyMappings(&handler, clip, channelMapper); + + // THEN + QCOMPARE(mappingData.size(), channelMapper->mappingIds().size()); + for (int i = 0; i < mappingData.size(); ++i) { + const auto mapping = mappingData[i]; + QCOMPARE(mapping.targetId, targetId); + QCOMPARE(mapping.propertyName, channelMapping->propertyName()); + QCOMPARE(mapping.type, channelMapping->type()); + QCOMPARE(mapping.channelIndices.size(), 3); + for (int j = 0; j < 3; ++j) { + QCOMPARE(mapping.channelIndices[j], j); + } + } + } +}; + +QTEST_MAIN(tst_AnimationUtils) + +#include "tst_animationutils.moc" -- cgit v1.2.3 From 7cb291ba90cfb08053bba37ef6ff6b003900b501 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Tue, 28 Feb 2017 17:02:54 +0000 Subject: Update naming of animation building blocks Rename: Groups -> Channels Channels -> ChannelComponents Update function and variable names accordingly. Also updated ChannelComponents to contain not only the component suffix to make them more readable in large files. Replaced animation clip in AnimationUtils unit test and adjusted suffix -> component index mapping code to use upper case. Will update clips in manual test in a follow up commit. Change-Id: If5ed565d57efbed07a4d6771336a14f6a4cddb65 Reviewed-by: Mike Krus --- tests/auto/animation/animationutils/clip1.json | 157 +++++++++++++++------ .../animationutils/tst_animationutils.cpp | 4 +- 2 files changed, 113 insertions(+), 48 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/clip1.json b/tests/auto/animation/animationutils/clip1.json index e54858a2d..8fa382589 100644 --- a/tests/auto/animation/animationutils/clip1.json +++ b/tests/auto/animation/animationutils/clip1.json @@ -1,48 +1,113 @@ { "animations": [ - { "object": "Cube", - "action": "CubeAction", - "range": [0.0, 60.0], - "groups": [ - { "group": "channelFoo", - "channels": [ - { "name": "x", - "keyframes": [ - { "co": [0.0, 0.0], - "handle_left": [-0.4717472394307454, 0.0], - "handle_right": [0.4717472394307454, 0.0]} - ,{ "co": [1.2083333333333333, 2.430499792098999], - "handle_left": [0.7365860939025879, 1.4711904525756836], - "handle_right": [1.696347713470459, 3.42288875579834]} - ,{ "co": [2.4583333333333335, 5.0], - "handle_left": [1.9703189531962078, 5.0], - "handle_right": [2.9463475545247397, 5.0]} - ]} - ,{ "name": "y", - "keyframes": [ - { "co": [0.0, 0.0], - "handle_left": [-0.4717472394307454, 0.0], - "handle_right": [0.4717472394307454, 0.0]} - ,{ "co": [1.2083333333333333, 3.0], - "handle_left": [0.7365860939025879, 3.0], - "handle_right": [1.696347713470459, 3.0]} - ,{ "co": [2.4583333333333335, 0.0], - "handle_left": [1.9703189531962078, 0.0], - "handle_right": [2.9463475545247397, 0.0]} - ]} - ,{ "name": "z", - "keyframes": [ - { "co": [0.0, 0.0], - "handle_left": [-0.4717472394307454, 0.0], - "handle_right": [0.4717472394307454, 0.0]} - ,{ "co": [1.2083333333333333, 0.0], - "handle_left": [0.7365860939025879, 0.0], - "handle_right": [1.696347713470459, 0.0]} - ,{ "co": [2.4583333333333335, 0.0], - "handle_left": [1.9703189531962078, 0.0], - "handle_right": [2.9463475545247397, 0.0]} - ]} - ]} - ]} - ] -} + { + "animationName": "CubeAction", + "channels": [ + { + "channelComponents": [ + { + "channelComponentName": "Location X", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 5.0 + ], + "leftHandle": [ + 1.4985717137654622, + 5.0 + ], + "rightHandle": [ + 3.4180949529012046, + 5.0 + ] + } + ] + }, + { + "channelComponentName": "Location Y", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 0.0 + ], + "leftHandle": [ + 1.4985717137654622, + 0.0 + ], + "rightHandle": [ + 3.4180949529012046, + 0.0 + ] + } + ] + }, + { + "channelComponentName": "Location Z", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 0.0 + ], + "leftHandle": [ + 1.4985717137654622, + 0.0 + ], + "rightHandle": [ + 3.4180949529012046, + 0.0 + ] + } + ] + } + ], + "channelName": "Location" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index e4170381e..0981f2590 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -55,8 +55,8 @@ private Q_SLOTS: auto targetId = Qt3DCore::QNodeId::createId(); channelMapping->setTargetId(targetId); - channelMapping->setProperty("foo"); - channelMapping->setChannelName("channelFoo"); + channelMapping->setProperty("translation"); + channelMapping->setChannelName("Location"); channelMapping->setType(static_cast(QVariant::Vector3D)); // Create a channel mapper and add mapping to it -- cgit v1.2.3 From faa2db2dc1c654616ca5651cec4e57893774015e Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Wed, 1 Mar 2017 12:34:34 +0000 Subject: Factor out some helper functions in AnimationUtils test Will make it easier to write additional tests that create these backend nodes. Change-Id: Ie2ce4427b495847451974b079e513e134d069d11 Reviewed-by: Mike Krus --- .../animationutils/tst_animationutils.cpp | 59 ++++++++++++++++------ 1 file changed, 43 insertions(+), 16 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 0981f2590..a1b9e1e86 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -42,35 +42,62 @@ class tst_AnimationUtils : public Qt3DCore::QBackendNodeTester { Q_OBJECT -private Q_SLOTS: - void checkBuildPropertyMappings() +public: + ChannelMapping *createChannelMapping(Handler &handler, + const QString &channelName, + const Qt3DCore::QNodeId targetId, + const QString &propertyName, + int type) { - // GIVEN - Handler handler; - - // Create a channel mapping, set properties, and add it to manager auto channelMappingId = Qt3DCore::QNodeId::createId(); ChannelMapping *channelMapping = handler.channelMappingManager()->getOrCreateResource(channelMappingId); setPeerId(channelMapping, channelMappingId); - - auto targetId = Qt3DCore::QNodeId::createId(); channelMapping->setTargetId(targetId); - channelMapping->setProperty("translation"); - channelMapping->setChannelName("Location"); - channelMapping->setType(static_cast(QVariant::Vector3D)); + channelMapping->setProperty(propertyName); + channelMapping->setChannelName(channelName); + channelMapping->setType(type); + return channelMapping; + } - // Create a channel mapper and add mapping to it + ChannelMapper *createChannelMapper(Handler &handler, + const QVector &mappingIds) + { auto channelMapperId = Qt3DCore::QNodeId::createId(); ChannelMapper *channelMapper = handler.channelMapperManager()->getOrCreateResource(channelMapperId); setPeerId(channelMapper, channelMapperId); - channelMapper->setMappingIds(QVector() << channelMappingId); + channelMapper->setMappingIds(mappingIds); + return channelMapper; + } - // Create an animation clip + AnimationClipLoader *createAnimationClipLoader(Handler &handler, + const QUrl &source) + { auto clipId = Qt3DCore::QNodeId::createId(); AnimationClipLoader *clip = handler.animationClipLoaderManager()->getOrCreateResource(clipId); setPeerId(clip, clipId); - clip->setSource(QUrl("qrc:/clip1.json")); + clip->setSource(source); clip->loadAnimation(); + return clip; + } + +private Q_SLOTS: + void checkBuildPropertyMappings() + { + // GIVEN + Handler handler; + + // Create a channel mapping... + auto channelMapping = createChannelMapping(handler, + QLatin1String("Location"), + Qt3DCore::QNodeId::createId(), + QLatin1String("translation"), + static_cast(QVariant::Vector3D)); + + // ... a channel mapper... + auto channelMapper = createChannelMapper(handler, QVector() << channelMapping->peerId()); + + // ...and an animation clip + auto clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json")); // WHEN // Build the mapping data for the above configuration @@ -80,7 +107,7 @@ private Q_SLOTS: QCOMPARE(mappingData.size(), channelMapper->mappingIds().size()); for (int i = 0; i < mappingData.size(); ++i) { const auto mapping = mappingData[i]; - QCOMPARE(mapping.targetId, targetId); + QCOMPARE(mapping.targetId, channelMapping->targetId()); QCOMPARE(mapping.propertyName, channelMapping->propertyName()); QCOMPARE(mapping.type, channelMapping->type()); QCOMPARE(mapping.channelIndices.size(), 3); -- cgit v1.2.3 From d024347bc358f8202465374ca3958738df580984 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Thu, 2 Mar 2017 09:28:27 +0000 Subject: Refactor tst_animationutils to be data driven Will allow to easily add more tests for other animation clips and mapping configurations. Change-Id: Ib125106f838d2e36c3ffefe5f5dcdfa869363f19 Reviewed-by: Mike Krus --- .../animationutils/tst_animationutils.cpp | 83 ++++++++++++++++------ 1 file changed, 63 insertions(+), 20 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index a1b9e1e86..1a4c861c5 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -38,42 +38,50 @@ using namespace Qt3DAnimation::Animation; +Q_DECLARE_METATYPE(Qt3DAnimation::Animation::Handler*) +Q_DECLARE_METATYPE(QVector) +Q_DECLARE_METATYPE(ChannelMapper *) +Q_DECLARE_METATYPE(AnimationClipLoader *) +Q_DECLARE_METATYPE(QVector) + class tst_AnimationUtils : public Qt3DCore::QBackendNodeTester { Q_OBJECT public: - ChannelMapping *createChannelMapping(Handler &handler, + ChannelMapping *createChannelMapping(Handler *handler, const QString &channelName, const Qt3DCore::QNodeId targetId, - const QString &propertyName, + const QString &property, + const char *propertyName, int type) { auto channelMappingId = Qt3DCore::QNodeId::createId(); - ChannelMapping *channelMapping = handler.channelMappingManager()->getOrCreateResource(channelMappingId); + ChannelMapping *channelMapping = handler->channelMappingManager()->getOrCreateResource(channelMappingId); setPeerId(channelMapping, channelMappingId); channelMapping->setTargetId(targetId); - channelMapping->setProperty(propertyName); + channelMapping->setProperty(property); + channelMapping->setPropertyName(propertyName); channelMapping->setChannelName(channelName); channelMapping->setType(type); return channelMapping; } - ChannelMapper *createChannelMapper(Handler &handler, + ChannelMapper *createChannelMapper(Handler *handler, const QVector &mappingIds) { auto channelMapperId = Qt3DCore::QNodeId::createId(); - ChannelMapper *channelMapper = handler.channelMapperManager()->getOrCreateResource(channelMapperId); + ChannelMapper *channelMapper = handler->channelMapperManager()->getOrCreateResource(channelMapperId); setPeerId(channelMapper, channelMapperId); channelMapper->setMappingIds(mappingIds); return channelMapper; } - AnimationClipLoader *createAnimationClipLoader(Handler &handler, + AnimationClipLoader *createAnimationClipLoader(Handler *handler, const QUrl &source) { auto clipId = Qt3DCore::QNodeId::createId(); - AnimationClipLoader *clip = handler.animationClipLoaderManager()->getOrCreateResource(clipId); + AnimationClipLoader *clip = handler->animationClipLoaderManager()->getOrCreateResource(clipId); setPeerId(clip, clipId); clip->setSource(source); clip->loadAnimation(); @@ -81,17 +89,23 @@ public: } private Q_SLOTS: - void checkBuildPropertyMappings() + void checkBuildPropertyMappings_data() { - // GIVEN - Handler handler; + QTest::addColumn("handler"); + QTest::addColumn>("channelMappings"); + QTest::addColumn("channelMapper"); + QTest::addColumn("clip"); + QTest::addColumn>("expectedMappingData"); - // Create a channel mapping... + auto handler = new Handler; auto channelMapping = createChannelMapping(handler, QLatin1String("Location"), Qt3DCore::QNodeId::createId(), QLatin1String("translation"), + "translation", static_cast(QVariant::Vector3D)); + QVector channelMappings; + channelMappings.push_back(channelMapping); // ... a channel mapper... auto channelMapper = createChannelMapper(handler, QVector() << channelMapping->peerId()); @@ -99,22 +113,51 @@ private Q_SLOTS: // ...and an animation clip auto clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json")); + QVector mappingData; + AnimationUtils::MappingData mapping; + mapping.targetId = channelMapping->targetId(); + mapping.propertyName = channelMapping->propertyName(); // Location + mapping.type = channelMapping->type(); + mapping.channelIndices = QVector() << 0 << 1 << 2; // Location X, Y, Z + mappingData.push_back(mapping); + + QTest::newRow("clip1.json") << handler + << channelMappings + << channelMapper + << clip + << mappingData; + } + + void checkBuildPropertyMappings() + { + // GIVEN + QFETCH(Handler *, handler); + QFETCH(QVector, channelMappings); + QFETCH(ChannelMapper *, channelMapper); + QFETCH(AnimationClipLoader *, clip); + QFETCH(QVector, expectedMappingData); + // WHEN // Build the mapping data for the above configuration - QVector mappingData = AnimationUtils::buildPropertyMappings(&handler, clip, channelMapper); + QVector mappingData = AnimationUtils::buildPropertyMappings(handler, clip, channelMapper); // THEN - QCOMPARE(mappingData.size(), channelMapper->mappingIds().size()); + QCOMPARE(mappingData.size(), expectedMappingData.size()); for (int i = 0; i < mappingData.size(); ++i) { const auto mapping = mappingData[i]; - QCOMPARE(mapping.targetId, channelMapping->targetId()); - QCOMPARE(mapping.propertyName, channelMapping->propertyName()); - QCOMPARE(mapping.type, channelMapping->type()); - QCOMPARE(mapping.channelIndices.size(), 3); - for (int j = 0; j < 3; ++j) { - QCOMPARE(mapping.channelIndices[j], j); + const auto expectedMapping = expectedMappingData[i]; + + QCOMPARE(mapping.targetId, expectedMapping.targetId); + QCOMPARE(mapping.propertyName, expectedMapping.propertyName); + QCOMPARE(mapping.type, expectedMapping.type); + QCOMPARE(mapping.channelIndices.size(), expectedMapping.channelIndices.size()); + for (int j = 0; j < mapping.channelIndices.size(); ++j) { + QCOMPARE(mapping.channelIndices[j], expectedMapping.channelIndices[j]); } } + + // Cleanup + delete handler; } }; -- cgit v1.2.3 From 84f907017bb4fc72faf86bd70fbf49d629bc93f3 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 3 Mar 2017 09:37:06 +0000 Subject: Remove AnimationUtils class It was stateless, so make the static member functions free functions and export them for auto tests. We're already in the Qt3DAnimation::Animation namespace so this removes some visual clutter. Change-Id: I4e1a72c47d5bd4afb807ce5f6dc80dc0ce4bb213 Reviewed-by: Mike Krus --- tests/auto/animation/animationutils/tst_animationutils.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 1a4c861c5..09ebd595f 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -42,7 +42,7 @@ Q_DECLARE_METATYPE(Qt3DAnimation::Animation::Handler*) Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(ChannelMapper *) Q_DECLARE_METATYPE(AnimationClipLoader *) -Q_DECLARE_METATYPE(QVector) +Q_DECLARE_METATYPE(QVector) class tst_AnimationUtils : public Qt3DCore::QBackendNodeTester { @@ -95,7 +95,7 @@ private Q_SLOTS: QTest::addColumn>("channelMappings"); QTest::addColumn("channelMapper"); QTest::addColumn("clip"); - QTest::addColumn>("expectedMappingData"); + QTest::addColumn>("expectedMappingData"); auto handler = new Handler; auto channelMapping = createChannelMapping(handler, @@ -113,8 +113,8 @@ private Q_SLOTS: // ...and an animation clip auto clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json")); - QVector mappingData; - AnimationUtils::MappingData mapping; + QVector mappingData; + MappingData mapping; mapping.targetId = channelMapping->targetId(); mapping.propertyName = channelMapping->propertyName(); // Location mapping.type = channelMapping->type(); @@ -135,11 +135,11 @@ private Q_SLOTS: QFETCH(QVector, channelMappings); QFETCH(ChannelMapper *, channelMapper); QFETCH(AnimationClipLoader *, clip); - QFETCH(QVector, expectedMappingData); + QFETCH(QVector, expectedMappingData); // WHEN // Build the mapping data for the above configuration - QVector mappingData = AnimationUtils::buildPropertyMappings(handler, clip, channelMapper); + QVector mappingData = buildPropertyMappings(handler, clip, channelMapper); // THEN QCOMPARE(mappingData.size(), expectedMappingData.size()); -- cgit v1.2.3 From 5d68d1b260054b575c32a791117575503bcb00a7 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 3 Mar 2017 10:50:44 +0000 Subject: Add test for localTimeFromGLobalTime helper Change-Id: Icdf6ae7062ba4afc27fc7cd0573029a5c5b32bf5 Reviewed-by: Mike Krus --- .../animationutils/tst_animationutils.cpp | 165 +++++++++++++++++++++ 1 file changed, 165 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 09ebd595f..419bff1fa 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -159,6 +159,171 @@ private Q_SLOTS: // Cleanup delete handler; } + + void checkLocalTimeFromGlobalTime_data() + { + QTest::addColumn("globalTime"); + QTest::addColumn("globalStartTime"); + QTest::addColumn("playbackRate"); + QTest::addColumn("duration"); + QTest::addColumn("loopCount"); + QTest::addColumn("expectedLocalTime"); + QTest::addColumn("expectedCurrentLoop"); + + double globalTime; + double globalStartTime; + double playbackRate; + double duration; + int loopCount; + double expectedLocalTime; + int expectedCurrentLoop; + + globalTime = 0.0; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 1; + expectedLocalTime = 0.0; + expectedCurrentLoop = 0; + QTest::newRow("simple, t_global = 0") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedLocalTime << expectedCurrentLoop; + + globalTime = 0.5; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 1; + expectedLocalTime = 0.5; + expectedCurrentLoop = 0; + QTest::newRow("simple, t_global = 0.5") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedLocalTime << expectedCurrentLoop; + + globalTime = 1.0; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 1; + expectedLocalTime = 1.0; + expectedCurrentLoop = 0; + QTest::newRow("simple, t_global = 1.0") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedLocalTime << expectedCurrentLoop; + + globalTime = -0.5; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 1; + expectedLocalTime = 0.0; + expectedCurrentLoop = 0; + QTest::newRow("simple, t_global = -0.5") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedLocalTime << expectedCurrentLoop; + + globalTime = 1.5; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 1; + expectedLocalTime = 1.0; + expectedCurrentLoop = 0; + QTest::newRow("simple, t_global = 1.5") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedLocalTime << expectedCurrentLoop; + + globalTime = 0.5; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 2; + expectedLocalTime = 0.5; + expectedCurrentLoop = 0; + QTest::newRow("simple, loopCount = 2, t_global = 0.5") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedLocalTime << expectedCurrentLoop; + + globalTime = 1.5; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 2; + expectedLocalTime = 0.5; + expectedCurrentLoop = 1; + QTest::newRow("simple, loopCount = 2, t_global = 1.5") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedLocalTime << expectedCurrentLoop; + + globalTime = 3.5; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 2.0; + loopCount = 2; + expectedLocalTime = 1.5; + expectedCurrentLoop = 1; + QTest::newRow("duration = 2, loopCount = 2, t_global = 3.5") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedLocalTime << expectedCurrentLoop; + + globalTime = 4.5; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 2.0; + loopCount = 2; + expectedLocalTime = 2.0; + expectedCurrentLoop = 1; + QTest::newRow("duration = 2, loopCount = 2, t_global = 4.5") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedLocalTime << expectedCurrentLoop; + + globalTime = 1.5; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 0; + expectedLocalTime = 0.5; + expectedCurrentLoop = 1; + QTest::newRow("simple, loopCount = inf, t_global = 1.5") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedLocalTime << expectedCurrentLoop; + + globalTime = 10.2; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 0; + expectedLocalTime = 0.2; + expectedCurrentLoop = 10; + QTest::newRow("simple, loopCount = inf, t_global = 10.2") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedLocalTime << expectedCurrentLoop; + } + + void checkLocalTimeFromGlobalTime() + { + // GIVEN + QFETCH(double, globalTime); + QFETCH(double, globalStartTime); + QFETCH(double, playbackRate); + QFETCH(double, duration); + QFETCH(int, loopCount); + QFETCH(double, expectedLocalTime); + QFETCH(int, expectedCurrentLoop); + + // WHEN + int actualCurrentLoop = 0; + double actualLocalTime = localTimeFromGlobalTime(globalTime, + globalStartTime, + playbackRate, + duration, + loopCount, + actualCurrentLoop); + + // THEN + QCOMPARE(actualCurrentLoop, expectedCurrentLoop); + QCOMPARE(actualLocalTime, expectedLocalTime); + } }; QTEST_MAIN(tst_AnimationUtils) -- cgit v1.2.3 From e6b0d847c0ef1ffa512b275a817881c6244ef37c Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 3 Mar 2017 12:39:00 +0000 Subject: Extend test to cover preparePropertyChanges helper Change-Id: Ic89792a47ea6ec85924d9d7ba352d98bf86f0469 Reviewed-by: Mike Krus --- .../animationutils/tst_animationutils.cpp | 248 +++++++++++++++++++++ 1 file changed, 248 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 419bff1fa..622990829 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -33,6 +33,12 @@ #include #include #include +#include +#include +#include +#include +#include + #include #include @@ -43,6 +49,7 @@ Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(ChannelMapper *) Q_DECLARE_METATYPE(AnimationClipLoader *) Q_DECLARE_METATYPE(QVector) +Q_DECLARE_METATYPE(QVector) class tst_AnimationUtils : public Qt3DCore::QBackendNodeTester { @@ -324,6 +331,247 @@ private Q_SLOTS: QCOMPARE(actualCurrentLoop, expectedCurrentLoop); QCOMPARE(actualLocalTime, expectedLocalTime); } + + void checkPreparePropertyChanges_data() + { + QTest::addColumn("animatorId"); + QTest::addColumn>("mappingData"); + QTest::addColumn>("channelResults"); + QTest::addColumn("finalFrame"); + QTest::addColumn>("expectedChanges"); + + Qt3DCore::QNodeId animatorId; + QVector mappingData; + QVector channelResults; + bool finalFrame; + QVector expectedChanges; + + // Single property, vec3 + { + animatorId = Qt3DCore::QNodeId::createId(); + MappingData mapping; + mapping.targetId = Qt3DCore::QNodeId::createId(); + mapping.propertyName = "translation"; + mapping.type = static_cast(QVariant::Vector3D); + mapping.channelIndices = QVector() << 0 << 1 << 2; + mappingData.push_back(mapping); + channelResults = QVector() << 1.0f << 2.0f << 3.0f; + finalFrame = false; + + auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(mapping.targetId); + change->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); + change->setPropertyName(mapping.propertyName); + change->setValue(QVariant::fromValue(QVector3D(1.0f, 2.0f, 3.0f))); + expectedChanges.push_back(change); + + QTest::newRow("vec3 translation, final = false") + << animatorId << mappingData << channelResults << finalFrame + << expectedChanges; + + finalFrame = true; + auto animatorChange = Qt3DCore::QPropertyUpdatedChangePtr::create(animatorId); + animatorChange->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); + animatorChange->setPropertyName("running"); + animatorChange->setValue(false); + expectedChanges.push_back(animatorChange); + + QTest::newRow("vec3 translation, final = true") + << animatorId << mappingData << channelResults << finalFrame + << expectedChanges; + + mappingData.clear(); + channelResults.clear(); + expectedChanges.clear(); + } + + // Multiple properties, all vec3 + { + animatorId = Qt3DCore::QNodeId::createId(); + MappingData translationMapping; + translationMapping.targetId = Qt3DCore::QNodeId::createId(); + translationMapping.propertyName = "translation"; + translationMapping.type = static_cast(QVariant::Vector3D); + translationMapping.channelIndices = QVector() << 0 << 1 << 2; + mappingData.push_back(translationMapping); + + MappingData scaleMapping; + scaleMapping.targetId = Qt3DCore::QNodeId::createId(); + scaleMapping.propertyName = "scale"; + scaleMapping.type = static_cast(QVariant::Vector3D); + scaleMapping.channelIndices = QVector() << 3 << 4 << 5; + mappingData.push_back(scaleMapping); + + channelResults = QVector() << 1.0f << 2.0f << 3.0f + << 4.0f << 5.0f << 6.0f; + finalFrame = false; + + auto translationChange = Qt3DCore::QPropertyUpdatedChangePtr::create(translationMapping.targetId); + translationChange->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); + translationChange->setPropertyName(translationMapping.propertyName); + translationChange->setValue(QVariant::fromValue(QVector3D(1.0f, 2.0f, 3.0f))); + expectedChanges.push_back(translationChange); + + auto scaleChange = Qt3DCore::QPropertyUpdatedChangePtr::create(scaleMapping.targetId); + scaleChange->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); + scaleChange->setPropertyName(scaleMapping.propertyName); + scaleChange->setValue(QVariant::fromValue(QVector3D(4.0f, 5.0f, 6.0f))); + expectedChanges.push_back(scaleChange); + + QTest::newRow("vec3 translation, vec3 scale, final = false") + << animatorId << mappingData << channelResults << finalFrame + << expectedChanges; + + finalFrame = true; + auto animatorChange = Qt3DCore::QPropertyUpdatedChangePtr::create(animatorId); + animatorChange->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); + animatorChange->setPropertyName("running"); + animatorChange->setValue(false); + expectedChanges.push_back(animatorChange); + + QTest::newRow("vec3 translation, vec3 scale, final = true") + << animatorId << mappingData << channelResults << finalFrame + << expectedChanges; + + mappingData.clear(); + channelResults.clear(); + expectedChanges.clear(); + } + + // Single property, double + { + animatorId = Qt3DCore::QNodeId::createId(); + MappingData mapping; + mapping.targetId = Qt3DCore::QNodeId::createId(); + mapping.propertyName = "mass"; + mapping.type = static_cast(QVariant::Double); + mapping.channelIndices = QVector() << 0; + mappingData.push_back(mapping); + channelResults = QVector() << 3.5f; + finalFrame = false; + + auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(mapping.targetId); + change->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); + change->setPropertyName(mapping.propertyName); + change->setValue(QVariant::fromValue(3.5f)); + expectedChanges.push_back(change); + + QTest::newRow("double mass") + << animatorId << mappingData << channelResults << finalFrame + << expectedChanges; + + mappingData.clear(); + channelResults.clear(); + expectedChanges.clear(); + } + + // Single property, vec2 + { + animatorId = Qt3DCore::QNodeId::createId(); + MappingData mapping; + mapping.targetId = Qt3DCore::QNodeId::createId(); + mapping.propertyName = "pos"; + mapping.type = static_cast(QVariant::Vector2D); + mapping.channelIndices = QVector() << 0 << 1; + mappingData.push_back(mapping); + channelResults = QVector() << 2.0f << 1.0f; + finalFrame = false; + + auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(mapping.targetId); + change->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); + change->setPropertyName(mapping.propertyName); + change->setValue(QVariant::fromValue(QVector2D(2.0f, 1.0f))); + expectedChanges.push_back(change); + + QTest::newRow("vec2 pos") + << animatorId << mappingData << channelResults << finalFrame + << expectedChanges; + + mappingData.clear(); + channelResults.clear(); + expectedChanges.clear(); + } + + // Single property, vec4 + { + animatorId = Qt3DCore::QNodeId::createId(); + MappingData mapping; + mapping.targetId = Qt3DCore::QNodeId::createId(); + mapping.propertyName = "foo"; + mapping.type = static_cast(QVariant::Vector2D); + mapping.channelIndices = QVector() << 0 << 1 << 2 << 3; + mappingData.push_back(mapping); + channelResults = QVector() << 4.0f << 3.0f << 2.0f << 1.0f; + finalFrame = false; + + auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(mapping.targetId); + change->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); + change->setPropertyName(mapping.propertyName); + change->setValue(QVariant::fromValue(QVector4D(4.0f, 3.0f, 2.0f, 1.0f))); + expectedChanges.push_back(change); + + QTest::newRow("vec4 foo") + << animatorId << mappingData << channelResults << finalFrame + << expectedChanges; + + mappingData.clear(); + channelResults.clear(); + expectedChanges.clear(); + } + + // Single property, quaternion + { + animatorId = Qt3DCore::QNodeId::createId(); + MappingData mapping; + mapping.targetId = Qt3DCore::QNodeId::createId(); + mapping.propertyName = "rotation"; + mapping.type = static_cast(QVariant::Quaternion); + mapping.channelIndices = QVector() << 0 << 1 << 2 << 3; + mappingData.push_back(mapping); + channelResults = QVector() << 1.0f << 0.0f << 0.0f << 1.0f; + finalFrame = false; + + auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(mapping.targetId); + change->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); + change->setPropertyName(mapping.propertyName); + change->setValue(QVariant::fromValue(QQuaternion(1.0f, 0.0f, 0.0f, 1.0f))); + expectedChanges.push_back(change); + + QTest::newRow("quaternion rotation") + << animatorId << mappingData << channelResults << finalFrame + << expectedChanges; + + mappingData.clear(); + channelResults.clear(); + expectedChanges.clear(); + } + } + + void checkPreparePropertyChanges() + { + // GIVEN + QFETCH(Qt3DCore::QNodeId, animatorId); + QFETCH(QVector, mappingData); + QFETCH(QVector, channelResults); + QFETCH(bool, finalFrame); + QFETCH(QVector, expectedChanges); + + // WHEN + QVector actualChanges + = preparePropertyChanges(animatorId, mappingData, channelResults, finalFrame); + + // THEN + QCOMPARE(actualChanges.size(), expectedChanges.size()); + for (int i = 0; i < actualChanges.size(); ++i) { + auto expectedChange = expectedChanges[i]; + auto actualChange + = qSharedPointerCast(expectedChanges[i]); + + QCOMPARE(actualChange->subjectId(), expectedChange->subjectId()); + QCOMPARE(actualChange->deliveryFlags(), expectedChange->deliveryFlags()); + QCOMPARE(actualChange->propertyName(), expectedChange->propertyName()); + QCOMPARE(actualChange->value(), expectedChange->value()); + } + } }; QTEST_MAIN(tst_AnimationUtils) -- cgit v1.2.3 From c8f2258aa24b38326cb576f82f738e242f44cd84 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 3 Mar 2017 13:17:15 +0000 Subject: Extend animation utils test to cover evlaluateClipAtLocalTime() Change-Id: I5fb07fa2f8efe8e89fa33e0af7378d38d2488d00 Reviewed-by: Mike Krus --- .../animation/animationutils/animationutils.qrc | 1 + tests/auto/animation/animationutils/clip2.json | 250 +++++++++++++++++++++ .../animationutils/tst_animationutils.cpp | 119 ++++++++++ 3 files changed, 370 insertions(+) create mode 100644 tests/auto/animation/animationutils/clip2.json (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/animationutils.qrc b/tests/auto/animation/animationutils/animationutils.qrc index 72234ec64..aeb8112f3 100644 --- a/tests/auto/animation/animationutils/animationutils.qrc +++ b/tests/auto/animation/animationutils/animationutils.qrc @@ -1,5 +1,6 @@ clip1.json + clip2.json diff --git a/tests/auto/animation/animationutils/clip2.json b/tests/auto/animation/animationutils/clip2.json new file mode 100644 index 000000000..3faff409c --- /dev/null +++ b/tests/auto/animation/animationutils/clip2.json @@ -0,0 +1,250 @@ +{ + "animations": [ + { + "animationName": "CubeAction", + "channels": [ + { + "channelComponents": [ + { + "channelComponentName": "Location X", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 5.0 + ], + "leftHandle": [ + 1.4985717137654622, + 5.0 + ], + "rightHandle": [ + 3.4180949529012046, + 5.0 + ] + } + ] + }, + { + "channelComponentName": "Location Z", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 0.0 + ], + "leftHandle": [ + 1.4985717137654622, + 0.0 + ], + "rightHandle": [ + 3.4180949529012046, + 0.0 + ] + } + ] + }, + { + "channelComponentName": "Location Y", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 0.0 + ], + "leftHandle": [ + 1.4985717137654622, + 0.0 + ], + "rightHandle": [ + 3.4180949529012046, + 0.0 + ] + } + ] + } + ], + "channelName": "Location" + }, + { + "channelComponents": [ + { + "channelComponentName": "Rotation W", + "keyFrames": [ + { + "coords": [ + 0.0, + 1.0 + ], + "leftHandle": [ + -0.9597616195678711, + 1.0 + ], + "rightHandle": [ + 0.9597616195678711, + 1.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + -4.371138828673793e-08 + ], + "leftHandle": [ + 1.4985717137654622, + -4.371138828673793e-08 + ], + "rightHandle": [ + 3.4180949529012046, + -4.371138828673793e-08 + ] + } + ] + }, + { + "channelComponentName": "Rotation X", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 0.0 + ], + "leftHandle": [ + 1.4985717137654622, + 0.0 + ], + "rightHandle": [ + 3.4180949529012046, + 0.0 + ] + } + ] + }, + { + "channelComponentName": "Rotation Z", + "keyFrames": [ + { + "coords": [ + 0.0, + -0.0 + ], + "leftHandle": [ + -0.9597616195678711, + -0.0 + ], + "rightHandle": [ + 0.9597616195678711, + -0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + -1.0 + ], + "leftHandle": [ + 1.4985717137654622, + -1.0 + ], + "rightHandle": [ + 3.4180949529012046, + -1.0 + ] + } + ] + }, + { + "channelComponentName": "Rotation Y", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 0.0 + ], + "leftHandle": [ + 1.4985717137654622, + 0.0 + ], + "rightHandle": [ + 3.4180949529012046, + 0.0 + ] + } + ] + } + ], + "channelName": "Rotation" + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 622990829..00f857d1d 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -51,6 +51,18 @@ Q_DECLARE_METATYPE(AnimationClipLoader *) Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(QVector) +bool fuzzyCompare(float x1, float x2) +{ + if (qFuzzyIsNull(x1) && qFuzzyIsNull(x2)) { + return true; + } else if (qFuzzyIsNull(x1) && !qFuzzyIsNull(x2) || + !qFuzzyIsNull(x1) && qFuzzyIsNull(x2)) { + return false; + } else { + return qFuzzyCompare(x1, x2); + } +} + class tst_AnimationUtils : public Qt3DCore::QBackendNodeTester { Q_OBJECT @@ -572,6 +584,113 @@ private Q_SLOTS: QCOMPARE(actualChange->value(), expectedChange->value()); } } + + void checkEvaluateClipAtLocalTime_data() + { + QTest::addColumn("handler"); + QTest::addColumn("clip"); + QTest::addColumn("localTime"); + QTest::addColumn>("expectedResults"); + + Handler *handler; + AnimationClipLoader *clip; + float localTime; + QVector expectedResults; + + { + handler = new Handler(); + clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json")); + localTime = 0.0f; + expectedResults = QVector() << 0.0f << 0.0f << 0.0f; + + QTest::newRow("clip1.json, t = 0.0") + << handler << clip << localTime << expectedResults; + expectedResults.clear(); + } + + { + handler = new Handler(); + clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json")); + localTime = clip->duration(); + expectedResults = QVector() << 5.0f << 0.0f << 0.0f; + + QTest::newRow("clip1.json, t = duration") + << handler << clip << localTime << expectedResults; + expectedResults.clear(); + } + + { + handler = new Handler(); + clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json")); + localTime = clip->duration() / 2.0f; + expectedResults = QVector() << 2.5f << 0.0f << 0.0f; + + QTest::newRow("clip1.json, t = duration/2") + << handler << clip << localTime << expectedResults; + expectedResults.clear(); + } + + { + handler = new Handler(); + clip = createAnimationClipLoader(handler, QUrl("qrc:/clip2.json")); + localTime = 0.0f; + expectedResults = QVector() + << 0.0f << 0.0f << 0.0f // Translation + << 1.0f << 0.0f << 0.0f << 0.0f; // Rotation + + QTest::newRow("clip2.json, t = 0.0") + << handler << clip << localTime << expectedResults; + expectedResults.clear(); + } + { + handler = new Handler(); + clip = createAnimationClipLoader(handler, QUrl("qrc:/clip2.json")); + localTime = clip->duration(); + expectedResults = QVector() + << 5.0f << 0.0f << 0.0f // Translation + << 0.0f << 0.0f << -1.0f << 0.0f; // Rotation + + QTest::newRow("clip2.json, t = duration") + << handler << clip << localTime << expectedResults; + expectedResults.clear(); + } + { + handler = new Handler(); + clip = createAnimationClipLoader(handler, QUrl("qrc:/clip2.json")); + localTime = clip->duration() / 2.0f; + expectedResults = QVector() + << 2.5f << 0.0f << 0.0f // Translation + << 0.5f << 0.0f << -0.5f << 0.0f; // Rotation + + QTest::newRow("clip2.json, t = duration/2") + << handler << clip << localTime << expectedResults; + expectedResults.clear(); + } + } + + void checkEvaluateClipAtLocalTime() + { + // GIVEN + QFETCH(Handler *, handler); + QFETCH(AnimationClipLoader *, clip); + QFETCH(float, localTime); + QFETCH(QVector, expectedResults); + + // WHEN + QVector actualResults = evaluateClipAtLocalTime(clip, localTime); + + // THEN + QCOMPARE(actualResults.size(), expectedResults.size()); + for (int i = 0; i < actualResults.size(); ++i) { + auto actual = actualResults[i]; + auto expected = expectedResults[i]; + + QVERIFY(fuzzyCompare(actual, expected) == true); + } + + // Cleanup + delete handler; + } }; QTEST_MAIN(tst_AnimationUtils) -- cgit v1.2.3 From a6a539da453eb50aca665fdd09b53e17b4d395a7 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 3 Mar 2017 16:53:16 +0000 Subject: Extend animation utils test to cover channelComponentsToIndicesHelper Change-Id: I4284d43da48a25dac6ff4c3c7b5f1b30e1b8e74f Reviewed-by: Mike Krus --- .../animationutils/tst_animationutils.cpp | 204 +++++++++++++++++++++ 1 file changed, 204 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 00f857d1d..a69e1114b 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -50,6 +50,7 @@ Q_DECLARE_METATYPE(ChannelMapper *) Q_DECLARE_METATYPE(AnimationClipLoader *) Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(QVector) +Q_DECLARE_METATYPE(Channel) bool fuzzyCompare(float x1, float x2) { @@ -691,6 +692,209 @@ private Q_SLOTS: // Cleanup delete handler; } + + void checkChannelComponentsToIndicesHelper_data() + { + QTest::addColumn("channel"); + QTest::addColumn("dataType"); + QTest::addColumn("offset"); + QTest::addColumn>("suffixes"); + QTest::addColumn>("expectedResults"); + + Channel channel; + int dataType; + int offset; + QVector suffixes; + QVector expectedResults; + + // vec3 with and without offset + { + channel = Channel(); + channel.name = QLatin1String("Location"); + channel.channelComponents.resize(3); + channel.channelComponents[0].name = QLatin1String("Location X"); + channel.channelComponents[1].name = QLatin1String("Location Y"); + channel.channelComponents[2].name = QLatin1String("Location Z"); + + dataType = static_cast(QVariant::Vector3D); + offset = 0; + suffixes = (QVector() << 'X' << 'Y' << 'Z' << 'W'); + expectedResults = (QVector() << 0 << 1 << 2); + + QTest::newRow("vec3 location, offset = 0") + << channel << dataType << offset << suffixes << expectedResults; + + expectedResults.clear(); + + offset = 4; + expectedResults = (QVector() << 4 << 5 << 6); + QTest::newRow("vec3 location, offset = 4") + << channel << dataType << offset << suffixes << expectedResults; + + suffixes.clear(); + expectedResults.clear(); + } + + // vec2 with and without offset + { + channel = Channel(); + channel.name = QLatin1String("pos"); + channel.channelComponents.resize(2); + channel.channelComponents[0].name = QLatin1String("pos X"); + channel.channelComponents[1].name = QLatin1String("pos Y"); + + dataType = static_cast(QVariant::Vector2D); + offset = 0; + suffixes = (QVector() << 'X' << 'Y' << 'Z' << 'W'); + expectedResults = (QVector() << 0 << 1); + + QTest::newRow("vec2 pos, offset = 0") + << channel << dataType << offset << suffixes << expectedResults; + + expectedResults.clear(); + + offset = 2; + expectedResults = (QVector() << 2 << 3); + QTest::newRow("vec2 pos, offset = 2") + << channel << dataType << offset << suffixes << expectedResults; + + suffixes.clear(); + expectedResults.clear(); + } + + // vec4 with and without offset + { + channel = Channel(); + channel.name = QLatin1String("foo"); + channel.channelComponents.resize(4); + channel.channelComponents[0].name = QLatin1String("foo X"); + channel.channelComponents[1].name = QLatin1String("foo Y"); + channel.channelComponents[2].name = QLatin1String("foo Z"); + channel.channelComponents[3].name = QLatin1String("foo W"); + + dataType = static_cast(QVariant::Vector4D); + offset = 0; + suffixes = (QVector() << 'X' << 'Y' << 'Z' << 'W'); + expectedResults = (QVector() << 0 << 1 << 2 << 3); + + QTest::newRow("vec4 foo, offset = 0") + << channel << dataType << offset << suffixes << expectedResults; + + expectedResults.clear(); + + offset = 10; + expectedResults = (QVector() << 10 << 11 << 12 << 13); + QTest::newRow("vec4 foo, offset = 10") + << channel << dataType << offset << suffixes << expectedResults; + + suffixes.clear(); + expectedResults.clear(); + } + + // double with and without offset + { + channel = Channel(); + channel.name = QLatin1String("foo"); + channel.channelComponents.resize(1); + channel.channelComponents[0].name = QLatin1String("Mass X"); + + dataType = static_cast(QVariant::Double); + offset = 0; + suffixes = (QVector() << 'X' << 'Y' << 'Z' << 'W'); + expectedResults = (QVector() << 0); + + QTest::newRow("double Mass, offset = 0") + << channel << dataType << offset << suffixes << expectedResults; + + expectedResults.clear(); + + offset = 5; + expectedResults = (QVector() << 5); + QTest::newRow("double Mass, offset = 5") + << channel << dataType << offset << suffixes << expectedResults; + + suffixes.clear(); + expectedResults.clear(); + } + + // quaternion with and without offset + { + channel = Channel(); + channel.name = QLatin1String("Rotation"); + channel.channelComponents.resize(4); + channel.channelComponents[0].name = QLatin1String("Rotation W"); + channel.channelComponents[1].name = QLatin1String("Rotation X"); + channel.channelComponents[2].name = QLatin1String("Rotation Y"); + channel.channelComponents[3].name = QLatin1String("Rotation Z"); + + dataType = static_cast(QVariant::Quaternion); + offset = 0; + suffixes = (QVector() << 'W' << 'X' << 'Y' << 'Z'); + expectedResults = (QVector() << 0 << 1 << 2 << 3); + + QTest::newRow("quaternion Rotation, offset = 0") + << channel << dataType << offset << suffixes << expectedResults; + + expectedResults.clear(); + + offset = 10; + expectedResults = (QVector() << 10 << 11 << 12 << 13); + QTest::newRow("quaternion Rotation, offset = 10") + << channel << dataType << offset << suffixes << expectedResults; + + suffixes.clear(); + expectedResults.clear(); + } + + // quaternion with and without offset, randomized + { + channel = Channel(); + channel.name = QLatin1String("Rotation"); + channel.channelComponents.resize(4); + channel.channelComponents[0].name = QLatin1String("Rotation X"); + channel.channelComponents[1].name = QLatin1String("Rotation W"); + channel.channelComponents[2].name = QLatin1String("Rotation Z"); + channel.channelComponents[3].name = QLatin1String("Rotation Y"); + + dataType = static_cast(QVariant::Quaternion); + offset = 0; + suffixes = (QVector() << 'W' << 'X' << 'Y' << 'Z'); + expectedResults = (QVector() << 1 << 0 << 3 << 2); + + QTest::newRow("quaternion Rotation, offset = 0, randomized") + << channel << dataType << offset << suffixes << expectedResults; + + expectedResults.clear(); + + offset = 10; + expectedResults = (QVector() << 11 << 10 << 13 << 12); + QTest::newRow("quaternion Rotation, offset = 10, randomized") + << channel << dataType << offset << suffixes << expectedResults; + + suffixes.clear(); + expectedResults.clear(); + } + } + + void checkChannelComponentsToIndicesHelper() + { + // GIVEN + QFETCH(Channel, channel); + QFETCH(int, dataType); + QFETCH(int, offset); + QFETCH(QVector, suffixes); + QFETCH(QVector, expectedResults); + + // WHEN + QVector actualResults + = channelComponentsToIndicesHelper(channel, dataType, offset, suffixes); + + // THEN + QCOMPARE(actualResults.size(), expectedResults.size()); + for (int i = 0; i < actualResults.size(); ++i) { + QCOMPARE(actualResults[i], expectedResults[i]); + } + } }; QTEST_MAIN(tst_AnimationUtils) -- cgit v1.2.3 From 76c7862ec26cad41aa6d30dca684ea09a8423e98 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 3 Mar 2017 17:00:01 +0000 Subject: Extend animation utils test to cover channelComponentsToIndices Change-Id: Iacccdfc052b6739fcc0b8825d7f55b7ce70e6a40 Reviewed-by: Mike Krus --- .../animationutils/tst_animationutils.cpp | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index a69e1114b..ac113b9ab 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -895,6 +895,90 @@ private Q_SLOTS: QCOMPARE(actualResults[i], expectedResults[i]); } } + + void checkChannelComponentsToIndices_data() + { + QTest::addColumn("channel"); + QTest::addColumn("dataType"); + QTest::addColumn("offset"); + QTest::addColumn>("expectedResults"); + + Channel channel; + int dataType; + int offset; + QVector expectedResults; + + // Quaternion + { + channel = Channel(); + channel.name = QLatin1String("Rotation"); + channel.channelComponents.resize(4); + channel.channelComponents[0].name = QLatin1String("Rotation W"); + channel.channelComponents[1].name = QLatin1String("Rotation X"); + channel.channelComponents[2].name = QLatin1String("Rotation Y"); + channel.channelComponents[3].name = QLatin1String("Rotation Z"); + + dataType = static_cast(QVariant::Quaternion); + offset = 0; + expectedResults = (QVector() << 0 << 1 << 2 << 3); + + QTest::newRow("quaternion Rotation, offset = 0") + << channel << dataType << offset << expectedResults; + + expectedResults.clear(); + + offset = 10; + expectedResults = (QVector() << 10 << 11 << 12 << 13); + QTest::newRow("quaternion Rotation, offset = 10") + << channel << dataType << offset << expectedResults; + + expectedResults.clear(); + } + + // vec3 with and without offset + { + channel = Channel(); + channel.name = QLatin1String("Location"); + channel.channelComponents.resize(3); + channel.channelComponents[0].name = QLatin1String("Location X"); + channel.channelComponents[1].name = QLatin1String("Location Y"); + channel.channelComponents[2].name = QLatin1String("Location Z"); + + dataType = static_cast(QVariant::Vector3D); + offset = 0; + expectedResults = (QVector() << 0 << 1 << 2); + + QTest::newRow("vec3 location, offset = 0") + << channel << dataType << offset << expectedResults; + + expectedResults.clear(); + + offset = 4; + expectedResults = (QVector() << 4 << 5 << 6); + QTest::newRow("vec3 location, offset = 4") + << channel << dataType << offset << expectedResults; + + expectedResults.clear(); + } + } + + void checkChannelComponentsToIndices() + { + QFETCH(Channel, channel); + QFETCH(int, dataType); + QFETCH(int, offset); + QFETCH(QVector, expectedResults); + + // WHEN + QVector actualResults + = channelComponentsToIndices(channel, dataType, offset); + + // THEN + QCOMPARE(actualResults.size(), expectedResults.size()); + for (int i = 0; i < actualResults.size(); ++i) { + QCOMPARE(actualResults[i], expectedResults[i]); + } + } }; QTEST_MAIN(tst_AnimationUtils) -- cgit v1.2.3 From 983f66c0a043e0f94b699c5119b7dc2ac91194aa Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 3 Mar 2017 19:26:10 +0000 Subject: Extend animation utils test to cover evaluationDataForClip() Change-Id: I1bdf856404ee20ddd9500e66ae48ed622801bd2e Reviewed-by: Mike Krus --- .../animationutils/tst_animationutils.cpp | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index ac113b9ab..dd9734edf 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -51,6 +51,8 @@ Q_DECLARE_METATYPE(AnimationClipLoader *) Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(Channel) +Q_DECLARE_METATYPE(AnimatorEvaluationData) +Q_DECLARE_METATYPE(ClipEvaluationData) bool fuzzyCompare(float x1, float x2) { @@ -108,6 +110,18 @@ public: return clip; } + ClipAnimator *createClipAnimator(Handler *handler, + qint64 globalStartTimeNS, + int loops) + { + auto animatorId = Qt3DCore::QNodeId::createId(); + ClipAnimator *animator = handler->clipAnimatorManager()->getOrCreateResource(animatorId); + setPeerId(animator, animatorId); + animator->setStartTime(globalStartTimeNS); + animator->setLoops(loops); + return animator; + } + private Q_SLOTS: void checkBuildPropertyMappings_data() { @@ -979,6 +993,123 @@ private Q_SLOTS: QCOMPARE(actualResults[i], expectedResults[i]); } } + + void checkEvaluationDataForClip_data() + { + QTest::addColumn("handler"); + QTest::addColumn("clip"); + QTest::addColumn("animatorData"); + QTest::addColumn("expectedClipData"); + + Handler *handler; + AnimationClipLoader *clip; + AnimatorEvaluationData animatorData; + ClipEvaluationData clipData; + + { + handler = new Handler(); + clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json")); + const qint64 globalStartTimeNS = 0; + const int loops = 1; + auto animator = createClipAnimator(handler, globalStartTimeNS, loops); + const qint64 globalTimeNS = 0; + animatorData = evaluationDataForAnimator(animator, globalTimeNS); // Tested elsewhere + + clipData.localTime = localTimeFromGlobalTime(animatorData.globalTime, + animatorData.startTime, + animatorData.playbackRate, + clip->duration(), + animatorData.loopCount, + clipData.currentLoop); // Tested elsewhere + clipData.isFinalFrame = false; + + QTest::newRow("clip1.json, globalTime = 0") + << handler << clip << animatorData << clipData; + } + + { + handler = new Handler(); + clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json")); + const qint64 globalStartTimeNS = 0; + const int loops = 1; + auto animator = createClipAnimator(handler, globalStartTimeNS, loops); + const qint64 globalTimeNS = (clip->duration() + 1.0) * 1.0e9; // +1 to ensure beyond end of clip + animatorData = evaluationDataForAnimator(animator, globalTimeNS); // Tested elsewhere + + clipData.localTime = localTimeFromGlobalTime(animatorData.globalTime, + animatorData.startTime, + animatorData.playbackRate, + clip->duration(), + animatorData.loopCount, + clipData.currentLoop); // Tested elsewhere + clipData.isFinalFrame = true; + + QTest::newRow("clip1.json, globalTime = duration") + << handler << clip << animatorData << clipData; + } + + { + handler = new Handler(); + clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json")); + const qint64 globalStartTimeNS = 0; + const int loops = 0; // Infinite loops + auto animator = createClipAnimator(handler, globalStartTimeNS, loops); + const qint64 globalTimeNS = 2.0 * clip->duration() * 1.0e9; + animatorData = evaluationDataForAnimator(animator, globalTimeNS); // Tested elsewhere + + clipData.localTime = localTimeFromGlobalTime(animatorData.globalTime, + animatorData.startTime, + animatorData.playbackRate, + clip->duration(), + animatorData.loopCount, + clipData.currentLoop); // Tested elsewhere + clipData.isFinalFrame = false; + + QTest::newRow("clip1.json, globalTime = 2 * duration, loops = infinite") + << handler << clip << animatorData << clipData; + } + + { + handler = new Handler(); + clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json")); + const qint64 globalStartTimeNS = 0; + const int loops = 2; + auto animator = createClipAnimator(handler, globalStartTimeNS, loops); + const qint64 globalTimeNS = (2.0 * clip->duration() + 1.0) * 1.0e9; // +1 to ensure beyond end of clip + animatorData = evaluationDataForAnimator(animator, globalTimeNS); // Tested elsewhere + + clipData.localTime = localTimeFromGlobalTime(animatorData.globalTime, + animatorData.startTime, + animatorData.playbackRate, + clip->duration(), + animatorData.loopCount, + clipData.currentLoop); // Tested elsewhere + clipData.isFinalFrame = true; + + QTest::newRow("clip1.json, globalTime = 2 * duration + 1, loops = 2") + << handler << clip << animatorData << clipData; + } + } + + void checkEvaluationDataForClip() + { + // GIVEN + QFETCH(Handler *, handler); + QFETCH(AnimationClipLoader *, clip); + QFETCH(AnimatorEvaluationData, animatorData); + QFETCH(ClipEvaluationData, expectedClipData); + + // WHEN + ClipEvaluationData actualClipData = evaluationDataForClip(clip, animatorData); + + // THEN + QCOMPARE(actualClipData.currentLoop, expectedClipData.currentLoop); + QVERIFY(fuzzyCompare(actualClipData.localTime, expectedClipData.localTime) == true); + QCOMPARE(actualClipData.isFinalFrame, expectedClipData.isFinalFrame); + + // Cleanup + delete handler; + } }; QTEST_MAIN(tst_AnimationUtils) -- cgit v1.2.3 From e76fabc8f1349d0eddf725453fc188d2ae0bf77e Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 3 Mar 2017 19:56:02 +0000 Subject: Extend animation utils test to cover evaluationDataForAnimator() Change-Id: I537185cb10499562b7d578cd83ff28e2faba78b4 Reviewed-by: Mike Krus --- .../animationutils/tst_animationutils.cpp | 99 ++++++++++++++++++++++ 1 file changed, 99 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index dd9734edf..1f91aedf1 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -53,6 +53,7 @@ Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(Channel) Q_DECLARE_METATYPE(AnimatorEvaluationData) Q_DECLARE_METATYPE(ClipEvaluationData) +Q_DECLARE_METATYPE(ClipAnimator *) bool fuzzyCompare(float x1, float x2) { @@ -1110,6 +1111,104 @@ private Q_SLOTS: // Cleanup delete handler; } + + void checkEvaluationDataForAnimator_data() + { + QTest::addColumn("handler"); + QTest::addColumn("animator"); + QTest::addColumn("globalTimeNS"); + QTest::addColumn("expectedAnimatorData"); + + Handler *handler; + ClipAnimator *animator; + qint64 globalTimeNS; + AnimatorEvaluationData expectedAnimatorData; + + { + handler = new Handler(); + const qint64 globalStartTimeNS = 0; + const int loops = 1; + animator = createClipAnimator(handler, globalStartTimeNS, loops); + globalTimeNS = 0; + + expectedAnimatorData.loopCount = loops; + expectedAnimatorData.playbackRate = 1.0; // hard-wired for now + expectedAnimatorData.startTime = 0.0; + expectedAnimatorData.globalTime = 0.0; + + QTest::newRow("globalStartTime = 0, globalTime = 0, loops = 1") + << handler << animator << globalTimeNS << expectedAnimatorData; + } + + { + handler = new Handler(); + const qint64 globalStartTimeNS = 0; + const int loops = 5; + animator = createClipAnimator(handler, globalStartTimeNS, loops); + globalTimeNS = 0; + + expectedAnimatorData.loopCount = loops; + expectedAnimatorData.playbackRate = 1.0; // hard-wired for now + expectedAnimatorData.startTime = 0.0; + expectedAnimatorData.globalTime = 0.0; + + QTest::newRow("globalStartTime = 0, globalTime = 0, loops = 5") + << handler << animator << globalTimeNS << expectedAnimatorData; + } + + { + handler = new Handler(); + const qint64 globalStartTimeNS = 0; + const int loops = 1; + animator = createClipAnimator(handler, globalStartTimeNS, loops); + globalTimeNS = 5000000000; + + expectedAnimatorData.loopCount = loops; + expectedAnimatorData.playbackRate = 1.0; // hard-wired for now + expectedAnimatorData.startTime = 0.0; + expectedAnimatorData.globalTime = 5.0; + + QTest::newRow("globalStartTime = 0, globalTime = 5, loops = 1") + << handler << animator << globalTimeNS << expectedAnimatorData; + } + + { + handler = new Handler(); + const qint64 globalStartTimeNS = 3000000000; + const int loops = 1; + animator = createClipAnimator(handler, globalStartTimeNS, loops); + globalTimeNS = 5000000000; + + expectedAnimatorData.loopCount = loops; + expectedAnimatorData.playbackRate = 1.0; // hard-wired for now + expectedAnimatorData.startTime = 3.0; + expectedAnimatorData.globalTime = 5.0; + + QTest::newRow("globalStartTime = 3, globalTime = 5, loops = 1") + << handler << animator << globalTimeNS << expectedAnimatorData; + } + } + + void checkEvaluationDataForAnimator() + { + // GIVEN + QFETCH(Handler *, handler); + QFETCH(ClipAnimator *, animator); + QFETCH(qint64, globalTimeNS); + QFETCH(AnimatorEvaluationData, expectedAnimatorData); + + // WHEN + AnimatorEvaluationData actualAnimatorData = evaluationDataForAnimator(animator, globalTimeNS); + + // THEN + QCOMPARE(actualAnimatorData.loopCount, expectedAnimatorData.loopCount); + QVERIFY(fuzzyCompare(actualAnimatorData.playbackRate, expectedAnimatorData.playbackRate) == true); + QVERIFY(fuzzyCompare(actualAnimatorData.startTime, expectedAnimatorData.startTime) == true); + QVERIFY(fuzzyCompare(actualAnimatorData.globalTime, expectedAnimatorData.globalTime) == true); + + // Cleanup + delete handler; + } }; QTEST_MAIN(tst_AnimationUtils) -- cgit v1.2.3 From 9f94d7517c3060d29682f84ca31005ecacf32447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Tue, 28 Feb 2017 18:09:26 +0200 Subject: Cleanup scene2d - remove event forward Remove event forward related stuff as they are no longer necessary after the mouse event changes. Task-number: QTBUG-58876 Change-Id: I2c9c52e41d5af3078d04ac9d5cc66753898e0ad9 Reviewed-by: Kevin Ottens --- tests/auto/render/eventforward/eventforward.pro | 12 - .../auto/render/eventforward/tst_eventforward.cpp | 278 ---------- .../auto/render/objectpicker/tst_objectpicker.cpp | 17 - tests/auto/render/qeventforward/qeventforward.pro | 12 - .../render/qeventforward/tst_qeventforward.cpp | 584 --------------------- .../render/qobjectpicker/tst_qobjectpicker.cpp | 14 - tests/auto/render/render.pro | 2 - 7 files changed, 919 deletions(-) delete mode 100644 tests/auto/render/eventforward/eventforward.pro delete mode 100644 tests/auto/render/eventforward/tst_eventforward.cpp delete mode 100644 tests/auto/render/qeventforward/qeventforward.pro delete mode 100644 tests/auto/render/qeventforward/tst_qeventforward.cpp (limited to 'tests/auto') diff --git a/tests/auto/render/eventforward/eventforward.pro b/tests/auto/render/eventforward/eventforward.pro deleted file mode 100644 index 22b481c77..000000000 --- a/tests/auto/render/eventforward/eventforward.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = app - -TARGET = tst_eventforward - -QT += 3dcore 3dcore-private 3drender 3drender-private testlib - -CONFIG += testcase - -SOURCES += tst_eventforward.cpp - -include(../../core/common/common.pri) -include(../commons/commons.pri) diff --git a/tests/auto/render/eventforward/tst_eventforward.cpp b/tests/auto/render/eventforward/tst_eventforward.cpp deleted file mode 100644 index de86b8ef3..000000000 --- a/tests/auto/render/eventforward/tst_eventforward.cpp +++ /dev/null @@ -1,278 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** 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 -#include -#include -#include -#include -#include -#include -#include "qbackendnodetester.h" -#include "testrenderer.h" -#include "testpostmanarbiter.h" - - -class tst_EventForward : public Qt3DCore::QBackendNodeTester -{ - Q_OBJECT - -private Q_SLOTS: - - void checkInitialState() - { - // GIVEN - Qt3DRender::Render::EventForward backendEventForward; - - // THEN - QCOMPARE(backendEventForward.isEnabled(), false); - QVERIFY(backendEventForward.peerId().isNull()); - QCOMPARE(backendEventForward.coordinateAttribute(), QStringLiteral("")); - QCOMPARE(backendEventForward.coordinateTransform(), QMatrix4x4()); - QCOMPARE(backendEventForward.forwardMouseEvents(), false); - QCOMPARE(backendEventForward.forwardKeyboardEvents(), false); - QCOMPARE(backendEventForward.focus(), false); - } - - void checkCleanupState() - { - // GIVEN - Qt3DRender::Render::EventForward backendEventForward; - QScopedPointer obj(new QObject()); - QMatrix4x4 transform; - transform.scale(1.0f, 2.0f, 3.0f); - - // WHEN - backendEventForward.setEnabled(true); - backendEventForward.setCoordinateAttribute(QStringLiteral("default")); - backendEventForward.setCoordinateTransform(transform); - backendEventForward.setForwardMouseEvents(true); - backendEventForward.setForwardKeyboardEvents(true); - backendEventForward.setFocus(true); - - backendEventForward.cleanup(); - - // THEN - QCOMPARE(backendEventForward.isEnabled(), false); - QCOMPARE(backendEventForward.coordinateAttribute(), QStringLiteral("")); - QCOMPARE(backendEventForward.coordinateTransform(), QMatrix4x4()); - QCOMPARE(backendEventForward.forwardMouseEvents(), false); - QCOMPARE(backendEventForward.forwardKeyboardEvents(), false); - QCOMPARE(backendEventForward.focus(), false); - } - - void checkInitializeFromPeer() - { - // GIVEN - Qt3DRender::QEventForward eventForward; - - { - // WHEN - Qt3DRender::Render::EventForward backendEventForward; - simulateInitialization(&eventForward, &backendEventForward); - - // THEN - QCOMPARE(backendEventForward.isEnabled(), true); - QCOMPARE(backendEventForward.peerId(), eventForward.id()); - QCOMPARE(backendEventForward.coordinateAttribute(), QStringLiteral("default")); - QCOMPARE(backendEventForward.coordinateTransform(), QMatrix4x4()); - QCOMPARE(backendEventForward.forwardMouseEvents(), true); - QCOMPARE(backendEventForward.forwardKeyboardEvents(), false); - QCOMPARE(backendEventForward.focus(), false); - } - { - // WHEN - Qt3DRender::Render::EventForward backendEventForward; - eventForward.setEnabled(false); - eventForward.setFocus(true); - simulateInitialization(&eventForward, &backendEventForward); - - // THEN - QCOMPARE(backendEventForward.peerId(), eventForward.id()); - QCOMPARE(backendEventForward.isEnabled(), false); - QCOMPARE(backendEventForward.focus(), true); - } - } - - void checkSceneChangeEvents() - { - // GIVEN - Qt3DRender::Render::EventForward backendEventForward; - TestRenderer renderer; - backendEventForward.setRenderer(&renderer); - - { - // WHEN - const bool newValue = false; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("enabled"); - change->setValue(newValue); - backendEventForward.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendEventForward.isEnabled(), newValue); - } - { - // WHEN - const QString newValue = QStringLiteral("position"); - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("coordinateAttribute"); - change->setValue(QVariant::fromValue(newValue)); - backendEventForward.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendEventForward.coordinateAttribute(), newValue); - } - { - // WHEN - QMatrix4x4 newValue; - newValue.rotate(2.0f, QVector3D(0, 0, 1.0f)); - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("coordinateTransform"); - change->setValue(QVariant::fromValue(newValue)); - backendEventForward.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendEventForward.coordinateTransform(), newValue); - } - { - // WHEN - const bool newValue = true; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("forwardMouseEvents"); - change->setValue(QVariant::fromValue(newValue)); - backendEventForward.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendEventForward.forwardMouseEvents(), newValue); - } - { - // WHEN - const bool newValue = true; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("forwardKeyboardEvents"); - change->setValue(QVariant::fromValue(newValue)); - backendEventForward.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendEventForward.forwardKeyboardEvents(), newValue); - } - { - // WHEN - const bool newValue = true; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("focus"); - change->setValue(QVariant::fromValue(newValue)); - backendEventForward.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendEventForward.focus(), newValue); - } - } - void checkEventForwarding() - { - Qt3DRender::Render::EventForward backendEventForward; - TestRenderer renderer; - TestArbiter arbiter; - backendEventForward.setRenderer(&renderer); - Qt3DCore::QBackendNodePrivate::get(&backendEventForward)->setArbiter(&arbiter); - - { - // WHEN - const QPointF localPos; - QMouseEvent event = QMouseEvent(QEvent::MouseButtonPress, localPos, - Qt::LeftButton, Qt::LeftButton, 0); - - const QVector4D coordinate; - backendEventForward.forward(event, coordinate); - QCoreApplication::processEvents(); - - // THEN - QVERIFY(arbiter.events.size() == 1); - Qt3DCore::QPropertyUpdatedChangePtr change - = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "events"); - - Qt3DRender::PostEventsToFrontendPtr postedEvents - = change->value().value(); - QVERIFY(postedEvents->events().size() == 1); - - QEvent *receivedEvent = postedEvents->events().first(); - QCOMPARE(receivedEvent->type(), QEvent::MouseButtonPress); - - QMouseEvent *me = static_cast(receivedEvent); - QCOMPARE(me->localPos(), localPos); - QCOMPARE(me->button(), Qt::LeftButton); - QCOMPARE(me->buttons(), Qt::LeftButton); - QCOMPARE(me->modifiers(), 0); - - arbiter.events.clear(); - } - - { - // WHEN - QKeyEvent event1 = QKeyEvent(QEvent::KeyPress, 48, 0); - QKeyEvent event2 = QKeyEvent(QEvent::KeyRelease, 48, 0); - QList eventList; - eventList.push_back(event1); - eventList.push_back(event2); - - backendEventForward.forward(eventList); - QCoreApplication::processEvents(); - - // THEN - QVERIFY(arbiter.events.size() == 1); - Qt3DCore::QPropertyUpdatedChangePtr change - = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "events"); - - Qt3DRender::PostEventsToFrontendPtr postedEvents - = change->value().value(); - QVERIFY(postedEvents->events().size() == 2); - - QEvent *receivedEvent1 = postedEvents->events().first(); - QCOMPARE(receivedEvent1->type(), QEvent::KeyPress); - - QEvent *receivedEvent2 = postedEvents->events().at(1); - QCOMPARE(receivedEvent2->type(), QEvent::KeyRelease); - - QKeyEvent *ke1 = static_cast(receivedEvent1); - QKeyEvent *ke2 = static_cast(receivedEvent2); - QCOMPARE(ke1->key(), 48); - QCOMPARE(ke1->modifiers(), 0); - QCOMPARE(ke2->key(), 48); - QCOMPARE(ke2->modifiers(), 0); - - arbiter.events.clear(); - } - } -}; - -QTEST_MAIN(tst_EventForward) - -#include "tst_eventforward.moc" diff --git a/tests/auto/render/objectpicker/tst_objectpicker.cpp b/tests/auto/render/objectpicker/tst_objectpicker.cpp index 4ba57b0ad..c1b06ccd8 100644 --- a/tests/auto/render/objectpicker/tst_objectpicker.cpp +++ b/tests/auto/render/objectpicker/tst_objectpicker.cpp @@ -46,9 +46,7 @@ private Q_SLOTS: // GIVEN Qt3DRender::Render::ObjectPicker objectPicker; Qt3DRender::QObjectPicker picker; - Qt3DRender::QEventForward eventForward; picker.setHoverEnabled(true); - picker.setEventForward(&eventForward); // WHEN simulateInitialization(&picker, &objectPicker); @@ -56,7 +54,6 @@ private Q_SLOTS: // THEN QVERIFY(!objectPicker.peerId().isNull()); QCOMPARE(objectPicker.isHoverEnabled(), true); - QCOMPARE(objectPicker.eventForward(), eventForward.id()); } void checkInitialAndCleanedUpState() @@ -67,8 +64,6 @@ private Q_SLOTS: // THEN QVERIFY(objectPicker.peerId().isNull()); QCOMPARE(objectPicker.isHoverEnabled(), false); - QCOMPARE(objectPicker.isEventForwardingEnabled(), false); - QCOMPARE(objectPicker.eventForward(), Qt3DCore::QNodeId()); // GIVEN Qt3DRender::QObjectPicker picker; @@ -80,8 +75,6 @@ private Q_SLOTS: // THEN QCOMPARE(objectPicker.isHoverEnabled(), false); - QCOMPARE(objectPicker.isEventForwardingEnabled(), false); - QCOMPARE(objectPicker.eventForward(), Qt3DCore::QNodeId()); } void checkPropertyChanges() @@ -90,7 +83,6 @@ private Q_SLOTS: TestRenderer renderer; { Qt3DRender::Render::ObjectPicker objectPicker; - Qt3DRender::QEventForward eventForward; objectPicker.setRenderer(&renderer); // WHEN @@ -102,15 +94,6 @@ private Q_SLOTS: // THEN QCOMPARE(objectPicker.isHoverEnabled(), true); QVERIFY(renderer.dirtyBits() != 0); - - // WHEN - updateChange->setValue(QVariant::fromValue(eventForward.id())); - updateChange->setPropertyName("eventForward"); - objectPicker.sceneChangeEvent(updateChange); - - // THEN - QCOMPARE(objectPicker.isEventForwardingEnabled(), true); - QCOMPARE(objectPicker.eventForward(), eventForward.id()); } } diff --git a/tests/auto/render/qeventforward/qeventforward.pro b/tests/auto/render/qeventforward/qeventforward.pro deleted file mode 100644 index 2479b038c..000000000 --- a/tests/auto/render/qeventforward/qeventforward.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = app - -TARGET = tst_qeventforward - -QT += 3dcore 3dcore-private 3drender 3drender-private testlib - -CONFIG += testcase - -SOURCES += tst_qeventforward.cpp - -include(../../core/common/common.pri) -include(../commons/commons.pri) diff --git a/tests/auto/render/qeventforward/tst_qeventforward.cpp b/tests/auto/render/qeventforward/tst_qeventforward.cpp deleted file mode 100644 index eeca5b3ea..000000000 --- a/tests/auto/render/qeventforward/tst_qeventforward.cpp +++ /dev/null @@ -1,584 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "testpostmanarbiter.h" - - -class EventReceiver : public QObject -{ -public: - EventReceiver() - : QObject() - { - - } - - ~EventReceiver() - { - - } - - int eventCount() - { - return m_events.size(); - } - - QEvent *eventAt(int index) const - { - return m_events.at(index); - } - bool event(QEvent *event) Q_DECL_OVERRIDE - { - m_events.push_back(event); - return true; - } - - void clearEvents() - { - m_events.clear(); - } - -private: - QVector m_events; -}; - -class TestEventForward : public Qt3DRender::QEventForward -{ - Q_OBJECT -public: - TestEventForward(Qt3DCore::QNode *parent = nullptr) - : Qt3DRender::QEventForward(parent) - {} - - void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) Q_DECL_FINAL - { - Qt3DRender::QEventForward::sceneChangeEvent(change); - } - -private: - friend class tst_QEventForward; - -}; - - -class tst_QEventForward : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - - void checkDefaultConstruction() - { - // GIVEN - Qt3DRender::QEventForward eventForward; - - // THEN - QCOMPARE(eventForward.target(), nullptr); - QCOMPARE(eventForward.forwardMouseEvents(), true); - QCOMPARE(eventForward.forwardKeyboardEvents(), false); - QCOMPARE(eventForward.coordinateTransform(), QMatrix4x4()); - QCOMPARE(eventForward.coordinateAttribute(), QStringLiteral("default")); - QCOMPARE(eventForward.focus(), false); - } - - void checkPropertyChanges() - { - // GIVEN - Qt3DRender::QEventForward eventForward; - - { - // WHEN - QScopedPointer obj(new QObject()); - QSignalSpy spy(&eventForward, SIGNAL(targetChanged(QObject*))); - QObject* newValue = obj.data(); - eventForward.setTarget(newValue); - - // THEN - QVERIFY(spy.isValid()); - QCOMPARE(eventForward.target(), newValue); - QCOMPARE(spy.count(), 1); - - // WHEN - spy.clear(); - eventForward.setTarget(newValue); - - // THEN - QCOMPARE(eventForward.target(), newValue); - QCOMPARE(spy.count(), 0); - } - { - // WHEN - QSignalSpy spy(&eventForward, SIGNAL(forwardMouseEventsChanged(bool))); - const bool newValue = false; - eventForward.setForwardMouseEvents(newValue); - - // THEN - QVERIFY(spy.isValid()); - QCOMPARE(eventForward.forwardMouseEvents(), newValue); - QCOMPARE(spy.count(), 1); - - // WHEN - spy.clear(); - eventForward.setForwardMouseEvents(newValue); - - // THEN - QCOMPARE(eventForward.forwardMouseEvents(), newValue); - QCOMPARE(spy.count(), 0); - } - { - // WHEN - QSignalSpy spy(&eventForward, SIGNAL(forwardKeyboardEventsChanged(bool))); - const bool newValue = true; - eventForward.setForwardKeyboardEvents(newValue); - - // THEN - QVERIFY(spy.isValid()); - QCOMPARE(eventForward.forwardKeyboardEvents(), newValue); - QCOMPARE(spy.count(), 1); - - // WHEN - spy.clear(); - eventForward.setForwardKeyboardEvents(newValue); - - // THEN - QCOMPARE(eventForward.forwardKeyboardEvents(), newValue); - QCOMPARE(spy.count(), 0); - } - { - // WHEN - QSignalSpy spy(&eventForward, SIGNAL(coordinateTransformChanged(QMatrix4x4))); - QMatrix4x4 newValue; - newValue.scale(3.0f); - eventForward.setCoordinateTransform(newValue); - - // THEN - QVERIFY(spy.isValid()); - QCOMPARE(eventForward.coordinateTransform(), newValue); - QCOMPARE(spy.count(), 1); - - // WHEN - spy.clear(); - eventForward.setCoordinateTransform(newValue); - - // THEN - QCOMPARE(eventForward.coordinateTransform(), newValue); - QCOMPARE(spy.count(), 0); - } - { - // WHEN - QSignalSpy spy(&eventForward, SIGNAL(coordinateAttributeChanged(QString))); - const QString newValue = Qt3DRender::QAttribute::defaultColorAttributeName(); - eventForward.setCoordinateAttribute(newValue); - - // THEN - QVERIFY(spy.isValid()); - QCOMPARE(eventForward.coordinateAttribute(), newValue); - QCOMPARE(spy.count(), 1); - - // WHEN - spy.clear(); - eventForward.setCoordinateAttribute(newValue); - - // THEN - QCOMPARE(eventForward.coordinateAttribute(), newValue); - QCOMPARE(spy.count(), 0); - } - { - // WHEN - QSignalSpy spy(&eventForward, SIGNAL(focusChanged(bool))); - const bool newValue = true; - eventForward.setFocus(newValue); - - // THEN - QVERIFY(spy.isValid()); - QCOMPARE(eventForward.focus(), newValue); - QCOMPARE(spy.count(), 1); - - // WHEN - spy.clear(); - eventForward.setFocus(newValue); - - // THEN - QCOMPARE(eventForward.focus(), newValue); - QCOMPARE(spy.count(), 0); - } - } - - void checkCreationData() - { - // GIVEN - Qt3DRender::QEventForward eventForward; - QScopedPointer obj(new QObject()); - QMatrix4x4 transform; - transform.translate(1.0f, 2.0f, 3.0f); - - eventForward.setTarget(obj.data()); - eventForward.setForwardMouseEvents(true); - eventForward.setForwardKeyboardEvents(true); - eventForward.setCoordinateTransform(transform); - eventForward.setCoordinateAttribute(QStringLiteral("position")); - eventForward.setFocus(true); - - // WHEN - QVector creationChanges; - - { - Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&eventForward); - creationChanges = creationChangeGenerator.creationChanges(); - } - - // THEN - { - QCOMPARE(creationChanges.size(), 1); - - const auto creationChangeData - = qSharedPointerCast>(creationChanges.first()); - const Qt3DRender::QEventForwardData cloneData = creationChangeData->data; - - QCOMPARE(eventForward.target(), cloneData.target); - QCOMPARE(eventForward.forwardMouseEvents(), cloneData.forwardMouseEvents); - QCOMPARE(eventForward.forwardKeyboardEvents(), cloneData.forwardKeyboardEvents); - QCOMPARE(eventForward.coordinateTransform(), cloneData.coordinateTransform); - QCOMPARE(eventForward.coordinateAttribute(), cloneData.coordinateAttribute); - QCOMPARE(eventForward.focus(), cloneData.focus); - QCOMPARE(eventForward.id(), creationChangeData->subjectId()); - QCOMPARE(eventForward.isEnabled(), true); - QCOMPARE(eventForward.isEnabled(), creationChangeData->isNodeEnabled()); - QCOMPARE(eventForward.metaObject(), creationChangeData->metaObject()); - } - - // WHEN - eventForward.setEnabled(false); - - { - Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&eventForward); - creationChanges = creationChangeGenerator.creationChanges(); - } - - // THEN - { - QCOMPARE(creationChanges.size(), 1); - - const auto creationChangeData - = qSharedPointerCast>(creationChanges.first()); - const Qt3DRender::QEventForwardData cloneData = creationChangeData->data; - - QCOMPARE(eventForward.target(), cloneData.target); - QCOMPARE(eventForward.forwardMouseEvents(), cloneData.forwardMouseEvents); - QCOMPARE(eventForward.forwardKeyboardEvents(), cloneData.forwardKeyboardEvents); - QCOMPARE(eventForward.coordinateTransform(), cloneData.coordinateTransform); - QCOMPARE(eventForward.coordinateAttribute(), cloneData.coordinateAttribute); - QCOMPARE(eventForward.focus(), cloneData.focus); - QCOMPARE(eventForward.id(), creationChangeData->subjectId()); - QCOMPARE(eventForward.isEnabled(), false); - QCOMPARE(eventForward.isEnabled(), creationChangeData->isNodeEnabled()); - QCOMPARE(eventForward.metaObject(), creationChangeData->metaObject()); - } - } - - void checkTargetUpdate() - { - // GIVEN - TestArbiter arbiter; - QScopedPointer obj(new QObject()); - Qt3DRender::QEventForward eventForward; - arbiter.setArbiterOnNode(&eventForward); - - { - // WHEN - eventForward.setTarget(obj.data()); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "target"); - QCOMPARE(change->value().value(), eventForward.target()); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - - arbiter.events.clear(); - } - - { - // WHEN - eventForward.setTarget(obj.data()); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - } - - } - - void checkForwardMouseEventsUpdate() - { - // GIVEN - TestArbiter arbiter; - Qt3DRender::QEventForward eventForward; - arbiter.setArbiterOnNode(&eventForward); - - { - // WHEN - eventForward.setForwardMouseEvents(false); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "forwardMouseEvents"); - QCOMPARE(change->value().value(), eventForward.forwardMouseEvents()); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - - arbiter.events.clear(); - } - - { - // WHEN - eventForward.setForwardMouseEvents(false); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - } - - } - - void checkForwardKeyboardEventsUpdate() - { - // GIVEN - TestArbiter arbiter; - Qt3DRender::QEventForward eventForward; - arbiter.setArbiterOnNode(&eventForward); - - { - // WHEN - eventForward.setForwardKeyboardEvents(true); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "forwardKeyboardEvents"); - QCOMPARE(change->value().value(), eventForward.forwardKeyboardEvents()); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - - arbiter.events.clear(); - } - - { - // WHEN - eventForward.setForwardKeyboardEvents(true); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - } - - } - - void checkCoordinateTransformUpdate() - { - // GIVEN - TestArbiter arbiter; - QMatrix4x4 transform; - Qt3DRender::QEventForward eventForward; - arbiter.setArbiterOnNode(&eventForward); - transform.translate(2.0f, 1.0f, 4.0f); - - { - // WHEN - eventForward.setCoordinateTransform(transform); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "coordinateTransform"); - QCOMPARE(change->value().value(), eventForward.coordinateTransform()); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - - arbiter.events.clear(); - } - - { - // WHEN - eventForward.setCoordinateTransform(transform); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - } - - } - - void checkCoordinateAttributeUpdate() - { - // GIVEN - TestArbiter arbiter; - Qt3DRender::QEventForward eventForward; - arbiter.setArbiterOnNode(&eventForward); - - { - // WHEN - eventForward.setCoordinateAttribute(QStringLiteral("normal")); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "coordinateAttribute"); - QCOMPARE(change->value().value(), eventForward.coordinateAttribute()); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - - arbiter.events.clear(); - } - - { - // WHEN - eventForward.setCoordinateAttribute(QStringLiteral("normal")); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - } - - } - - void checkFocusUpdate() - { - // GIVEN - TestArbiter arbiter; - Qt3DRender::QEventForward eventForward; - arbiter.setArbiterOnNode(&eventForward); - - { - // WHEN - eventForward.setFocus(true); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "focus"); - QCOMPARE(change->value().toBool(), eventForward.focus()); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - - arbiter.events.clear(); - } - - { - // WHEN - eventForward.setFocus(true); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - } - } - - void checkReceiveEvents() - { - EventReceiver receiver; - TestEventForward eventForward; - eventForward.setTarget(&receiver); - eventForward.setForwardKeyboardEvents(true); - eventForward.setForwardMouseEvents(true); - - { - // WHEN - const QPointF local = QPointF(); - QMouseEvent* mouseEvent - = new QMouseEvent(QEvent::MouseButtonPress, local, local, local, - Qt::LeftButton,0,0, Qt::MouseEventSynthesizedByApplication); - Qt3DRender::PostEventsToFrontendPtr events - = Qt3DRender::PostEventsToFrontendPtr::create(mouseEvent); - - auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); - e->setPropertyName("events"); - e->setValue(QVariant::fromValue(events)); - - eventForward.sceneChangeEvent(e); - - // THEN - QVERIFY(receiver.eventCount() == 1); - QEvent *event = receiver.eventAt(0); - QCOMPARE(event->type(), QEvent::MouseButtonPress); - - QMouseEvent *me = static_cast(receiver.eventAt(0)); - QCOMPARE(me->localPos(), local); - QCOMPARE(me->button(), Qt::LeftButton); - - receiver.clearEvents(); - } - - { - // WHEN - QKeyEvent *event1 = new QKeyEvent(QEvent::KeyPress, 48, 0); - QKeyEvent *event2 = new QKeyEvent(QEvent::KeyRelease, 48, 0); - QVector eventList; - eventList.push_back(event1); - eventList.push_back(event2); - Qt3DRender::PostEventsToFrontendPtr events - = Qt3DRender::PostEventsToFrontendPtr::create(eventList); - - auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); - e->setPropertyName("events"); - e->setValue(QVariant::fromValue(events)); - - eventForward.sceneChangeEvent(e); - - // THEN - QVERIFY(receiver.eventCount() == 2); - QEvent *event = receiver.eventAt(0); - QCOMPARE(event->type(), QEvent::KeyPress); - QCOMPARE(static_cast(event)->key(), 48); - - event = receiver.eventAt(1); - QCOMPARE(event->type(), QEvent::KeyRelease); - QCOMPARE(static_cast(event)->key(), 48); - } - } -}; - -QTEST_MAIN(tst_QEventForward) - -#include "tst_qeventforward.moc" diff --git a/tests/auto/render/qobjectpicker/tst_qobjectpicker.cpp b/tests/auto/render/qobjectpicker/tst_qobjectpicker.cpp index 8cc87ce14..4397954ec 100644 --- a/tests/auto/render/qobjectpicker/tst_qobjectpicker.cpp +++ b/tests/auto/render/qobjectpicker/tst_qobjectpicker.cpp @@ -105,7 +105,6 @@ private Q_SLOTS: // GIVEN TestArbiter arbiter; QScopedPointer objectPicker(new Qt3DRender::QObjectPicker()); - QScopedPointer eventForward(new Qt3DRender::QEventForward()); arbiter.setArbiterOnNode(objectPicker.data()); // WHEN @@ -120,19 +119,6 @@ private Q_SLOTS: QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); arbiter.events.clear(); - - // WHEN - objectPicker->setEventForward(eventForward.data()); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - change = arbiter.events.last().staticCast(); - QCOMPARE(change->propertyName(), "eventForward"); - QCOMPARE(change->value().value(), eventForward->id()); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - - arbiter.events.clear(); } void checkBackendUpdates_data() diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro index fc98cf7da..bf464cf6b 100644 --- a/tests/auto/render/render.pro +++ b/tests/auto/render/render.pro @@ -104,8 +104,6 @@ qtConfig(private_tests) { qmemorybarrier \ memorybarrier \ qshaderprogram \ - qeventforward \ - eventforward \ qscene2d \ scene2d \ coordinatereader -- cgit v1.2.3 From cb0c04ccba8b70f0954cbbd69e322db06330c8a7 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Sat, 4 Mar 2017 10:36:56 +0000 Subject: Typedef QVector as ClipResults Will make it easier to read once we introduce a vector of ClipResults which will be needed shortly. Change-Id: I97c2ae3fcd431b075db96f255fdffcc117529a63 Reviewed-by: Mike Krus --- tests/auto/animation/animationutils/tst_animationutils.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 1f91aedf1..7600f4d91 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -606,12 +606,12 @@ private Q_SLOTS: QTest::addColumn("handler"); QTest::addColumn("clip"); QTest::addColumn("localTime"); - QTest::addColumn>("expectedResults"); + QTest::addColumn("expectedResults"); Handler *handler; AnimationClipLoader *clip; float localTime; - QVector expectedResults; + ClipResults expectedResults; { handler = new Handler(); @@ -690,10 +690,10 @@ private Q_SLOTS: QFETCH(Handler *, handler); QFETCH(AnimationClipLoader *, clip); QFETCH(float, localTime); - QFETCH(QVector, expectedResults); + QFETCH(ClipResults, expectedResults); // WHEN - QVector actualResults = evaluateClipAtLocalTime(clip, localTime); + ClipResults actualResults = evaluateClipAtLocalTime(clip, localTime); // THEN QCOMPARE(actualResults.size(), expectedResults.size()); -- cgit v1.2.3 From d8c5bd3b28c82733212926bc8a2d67fb23cfe820 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Sat, 4 Mar 2017 13:47:06 +0000 Subject: Add ClipResults to ClipBlendNode indexed by animator id A blend tree (or subset of) can be shared between multiple animators. This implies that when evaluating blend trees we need to be able to store and retrieve the results of node evaluations on a per animator basis (as each animator may well have a different start time and therefore map to different local times for the same blend tree). Presently this is done by storing the blend tree node evaluation results within the jobs themselves. Instead, let's delegate this to the blend tree nodes. This is the first step in making the blend tree more general to support more complicated blend operations such as generalised lerps, barycentric lerps, multidimensional lerps etc. Future commits will build up support for this in parallel with the current implementation and then remove the existing implementation when complete. Change-Id: Ife097ec11571c71e9e3d420b3ca67efa2e1639cc Reviewed-by: Mike Krus --- .../animation/clipblendnode/tst_clipblendnode.cpp | 133 +++++++++++++++++++++ 1 file changed, 133 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp index 3e0ebf4f6..7d9345775 100644 --- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -39,6 +39,9 @@ #include #include "qbackendnodetester.h" +#include +#include + namespace { class TestClipBlendNode : public Qt3DAnimation::Animation::ClipBlendNode @@ -49,10 +52,14 @@ public: {} float blend(float , float ) const Q_DECL_FINAL { return 0.0f; } + + using Qt3DAnimation::Animation::ClipBlendNode::setClipResults; }; } // anonymous +Q_DECLARE_METATYPE(TestClipBlendNode *) + class tst_ClipBlendNode : public Qt3DCore::QBackendNodeTester { Q_OBJECT @@ -72,6 +79,7 @@ private Q_SLOTS: QCOMPARE(backendClipBlendNode.childrenIds(), Qt3DCore::QNodeIdVector()); QVERIFY(backendClipBlendNode.clipBlendNodeManager() == nullptr); QCOMPARE(backendClipBlendNode.blendType(), Qt3DAnimation::Animation::ClipBlendNode::LerpBlendType); + QCOMPARE(backendClipBlendNode.clipResults(Qt3DCore::QNodeId()), Qt3DAnimation::Animation::ClipResults()); } void checkInitializeFromPeer() @@ -99,6 +107,7 @@ private Q_SLOTS: QCOMPARE(backendClipBlendNode.childrenIds().size(), 0); QCOMPARE(backendClipBlendNode.clipBlendNodeManager(), &manager); QCOMPARE(backendClipBlendNode.blendType(), Qt3DAnimation::Animation::ClipBlendNode::LerpBlendType); + QCOMPARE(backendClipBlendNode.clipResults(Qt3DCore::QNodeId()), Qt3DAnimation::Animation::ClipResults()); } { // WHEN @@ -220,6 +229,130 @@ private Q_SLOTS: QCOMPARE(backendChildClipBlendNode->childrenIds().size(), 0); } + void checkClipResults_data() + { + QTest::addColumn("blendNode"); + QTest::addColumn>("indexes"); + QTest::addColumn>("animatorIds"); + QTest::addColumn>("expectedClipResults"); + + // Single entry + { + auto blendNode = new TestClipBlendNode; + QVector animatorIds; + QVector expectedClipResults; + + const auto animatorId = Qt3DCore::QNodeId::createId(); + animatorIds.push_back(animatorId); + + Qt3DAnimation::Animation::ClipResults clipResults = { 0.0f, 1.0f, 2.0f }; + expectedClipResults.push_back(clipResults); + + // Set data and indexes + blendNode->setClipResults(animatorId, clipResults); + QVector indexes = QVector() << 0; + + QTest::newRow("single entry") + << blendNode << indexes << animatorIds << expectedClipResults; + } + + // No data + { + auto blendNode = new TestClipBlendNode; + QVector animatorIds; + QVector expectedClipResults; + + auto animatorId = Qt3DCore::QNodeId::createId(); + animatorIds.push_back(animatorId); + + Qt3DAnimation::Animation::ClipResults clipResults; + expectedClipResults.push_back(clipResults); + + // Don't set any data + QVector indexes = QVector() << 0; + + QTest::newRow("no entries") + << blendNode << indexes << animatorIds << expectedClipResults; + } + + // Multiple entries, ordered + { + auto blendNode = new TestClipBlendNode; + QVector animatorIds; + QVector expectedClipResults; + + const int animatorCount = 10; + for (int j = 0; j < animatorCount; ++j) { + auto animatorId = Qt3DCore::QNodeId::createId(); + animatorIds.push_back(animatorId); + + Qt3DAnimation::Animation::ClipResults clipResults; + for (int i = 0; i < j + 5; ++i) + clipResults.push_back(float(i + j)); + expectedClipResults.push_back(clipResults); + + blendNode->setClipResults(animatorId, clipResults); + } + + QVector indexes(animatorCount); + std::iota(indexes.begin(), indexes.end(), 0); + + QTest::newRow("multiple entries, ordered") + << blendNode << indexes << animatorIds << expectedClipResults; + } + + // Multiple entries, unordered + { + auto blendNode = new TestClipBlendNode; + QVector animatorIds; + QVector expectedClipResults; + + const int animatorCount = 10; + for (int j = 0; j < animatorCount; ++j) { + auto animatorId = Qt3DCore::QNodeId::createId(); + animatorIds.push_back(animatorId); + + Qt3DAnimation::Animation::ClipResults clipResults; + for (int i = 0; i < j + 5; ++i) + clipResults.push_back(float(i + j)); + expectedClipResults.push_back(clipResults); + + blendNode->setClipResults(animatorId, clipResults); + } + + // Shuffle the animatorIds to randomise the lookups + QVector indexes(animatorCount); + std::iota(indexes.begin(), indexes.end(), 0); + std::random_device rd; + std::mt19937 generator(rd()); + std::shuffle(indexes.begin(), indexes.end(), generator); + + QTest::newRow("multiple entries, unordered") + << blendNode << indexes << animatorIds << expectedClipResults; + } + } + + void checkClipResults() + { + // GIVEN + QFETCH(TestClipBlendNode *, blendNode); + QFETCH(QVector, indexes); + QFETCH(QVector, animatorIds); + QFETCH(QVector, expectedClipResults); + + for (int i = 0; i < indexes.size(); ++i) { + // WHEN + const int index = indexes[i]; + const Qt3DAnimation::Animation::ClipResults actualClipResults = blendNode->clipResults(animatorIds[index]); + + // THEN + QCOMPARE(actualClipResults.size(), expectedClipResults[index].size()); + for (int j = 0; j < actualClipResults.size(); ++j) + QCOMPARE(actualClipResults[j], expectedClipResults[index][j]); + } + + delete blendNode; + } }; QTEST_MAIN(tst_ClipBlendNode) -- cgit v1.2.3 From a02e859b084c542bba472a4ae6f22acad07b085c Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Sat, 4 Mar 2017 13:58:51 +0000 Subject: Use using namespace Qt3DAnimation::Animation in tst_clipblendnode Reduces visual clutter Change-Id: I807adbdabc2c010f0b33a7ebf89f7aeeaabd5b6d Reviewed-by: Mike Krus --- .../animation/clipblendnode/tst_clipblendnode.cpp | 48 ++++++++++++---------- 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp index 7d9345775..7174dff54 100644 --- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -42,18 +42,20 @@ #include #include +using namespace Qt3DAnimation::Animation; + namespace { -class TestClipBlendNode : public Qt3DAnimation::Animation::ClipBlendNode +class TestClipBlendNode : public ClipBlendNode { public: TestClipBlendNode() - : Qt3DAnimation::Animation::ClipBlendNode(Qt3DAnimation::Animation::ClipBlendNode::LerpBlendType) + : ClipBlendNode(ClipBlendNode::LerpBlendType) {} float blend(float , float ) const Q_DECL_FINAL { return 0.0f; } - using Qt3DAnimation::Animation::ClipBlendNode::setClipResults; + using ClipBlendNode::setClipResults; }; } // anonymous @@ -78,8 +80,8 @@ private Q_SLOTS: QCOMPARE(backendClipBlendNode.parentId(), Qt3DCore::QNodeId()); QCOMPARE(backendClipBlendNode.childrenIds(), Qt3DCore::QNodeIdVector()); QVERIFY(backendClipBlendNode.clipBlendNodeManager() == nullptr); - QCOMPARE(backendClipBlendNode.blendType(), Qt3DAnimation::Animation::ClipBlendNode::LerpBlendType); - QCOMPARE(backendClipBlendNode.clipResults(Qt3DCore::QNodeId()), Qt3DAnimation::Animation::ClipResults()); + QCOMPARE(backendClipBlendNode.blendType(), ClipBlendNode::LerpBlendType); + QCOMPARE(backendClipBlendNode.clipResults(Qt3DCore::QNodeId()), ClipResults()); } void checkInitializeFromPeer() @@ -93,7 +95,7 @@ private Q_SLOTS: { // WHEN - Qt3DAnimation::Animation::ClipBlendNodeManager manager; + ClipBlendNodeManager manager; TestClipBlendNode backendClipBlendNode; backendClipBlendNode.setClipBlendNodeManager(&manager); simulateInitialization(&clipBlendNode, &backendClipBlendNode); @@ -106,12 +108,12 @@ private Q_SLOTS: QCOMPARE(backendClipBlendNode.parentId(), Qt3DCore::QNodeId()); QCOMPARE(backendClipBlendNode.childrenIds().size(), 0); QCOMPARE(backendClipBlendNode.clipBlendNodeManager(), &manager); - QCOMPARE(backendClipBlendNode.blendType(), Qt3DAnimation::Animation::ClipBlendNode::LerpBlendType); - QCOMPARE(backendClipBlendNode.clipResults(Qt3DCore::QNodeId()), Qt3DAnimation::Animation::ClipResults()); + QCOMPARE(backendClipBlendNode.blendType(), ClipBlendNode::LerpBlendType); + QCOMPARE(backendClipBlendNode.clipResults(Qt3DCore::QNodeId()), ClipResults()); } { // WHEN - Qt3DAnimation::Animation::ClipBlendNodeManager manager; + ClipBlendNodeManager manager; TestClipBlendNode backendClipBlendNode; clipBlendNode.setEnabled(false); backendClipBlendNode.setClipBlendNodeManager(&manager); @@ -127,7 +129,7 @@ private Q_SLOTS: { // GIVEN TestClipBlendNode backendClipBlendNode; - Qt3DAnimation::Animation::ClipBlendNodeManager manager; + ClipBlendNodeManager manager; backendClipBlendNode.setClipBlendNodeManager(&manager); { // WHEN @@ -193,7 +195,7 @@ private Q_SLOTS: TestClipBlendNode *backendChildClipBlendNode = new TestClipBlendNode(); Qt3DAnimation::QLerpClipBlend clipBlendParent; Qt3DAnimation::QLerpClipBlend childClipBlend(&clipBlendParent); - Qt3DAnimation::Animation::ClipBlendNodeManager manager; + ClipBlendNodeManager manager; backendClipBlendNode->setClipBlendNodeManager(&manager); backendChildClipBlendNode->setClipBlendNodeManager(&manager); @@ -234,18 +236,20 @@ private Q_SLOTS: QTest::addColumn("blendNode"); QTest::addColumn>("indexes"); QTest::addColumn>("animatorIds"); - QTest::addColumn>("expectedClipResults"); + QTest::addColumn>("expectedClipResults"); // Single entry { auto blendNode = new TestClipBlendNode; QVector animatorIds; - QVector expectedClipResults; + QVector expectedClipResults; const auto animatorId = Qt3DCore::QNodeId::createId(); animatorIds.push_back(animatorId); - Qt3DAnimation::Animation::ClipResults clipResults = { 0.0f, 1.0f, 2.0f }; + ClipResults clipResults = { 0.0f, 1.0f, 2.0f }; + for (int i = 0; i < 3; ++i) + clipResults.push_back(float(i)); expectedClipResults.push_back(clipResults); // Set data and indexes @@ -260,12 +264,12 @@ private Q_SLOTS: { auto blendNode = new TestClipBlendNode; QVector animatorIds; - QVector expectedClipResults; + QVector expectedClipResults; auto animatorId = Qt3DCore::QNodeId::createId(); animatorIds.push_back(animatorId); - Qt3DAnimation::Animation::ClipResults clipResults; + ClipResults clipResults; expectedClipResults.push_back(clipResults); // Don't set any data @@ -279,14 +283,14 @@ private Q_SLOTS: { auto blendNode = new TestClipBlendNode; QVector animatorIds; - QVector expectedClipResults; + QVector expectedClipResults; const int animatorCount = 10; for (int j = 0; j < animatorCount; ++j) { auto animatorId = Qt3DCore::QNodeId::createId(); animatorIds.push_back(animatorId); - Qt3DAnimation::Animation::ClipResults clipResults; + ClipResults clipResults; for (int i = 0; i < j + 5; ++i) clipResults.push_back(float(i + j)); expectedClipResults.push_back(clipResults); @@ -305,14 +309,14 @@ private Q_SLOTS: { auto blendNode = new TestClipBlendNode; QVector animatorIds; - QVector expectedClipResults; + QVector expectedClipResults; const int animatorCount = 10; for (int j = 0; j < animatorCount; ++j) { auto animatorId = Qt3DCore::QNodeId::createId(); animatorIds.push_back(animatorId); - Qt3DAnimation::Animation::ClipResults clipResults; + ClipResults clipResults; for (int i = 0; i < j + 5; ++i) clipResults.push_back(float(i + j)); expectedClipResults.push_back(clipResults); @@ -338,12 +342,12 @@ private Q_SLOTS: QFETCH(TestClipBlendNode *, blendNode); QFETCH(QVector, indexes); QFETCH(QVector, animatorIds); - QFETCH(QVector, expectedClipResults); + QFETCH(QVector, expectedClipResults); for (int i = 0; i < indexes.size(); ++i) { // WHEN const int index = indexes[i]; - const Qt3DAnimation::Animation::ClipResults actualClipResults = blendNode->clipResults(animatorIds[index]); + const ClipResults actualClipResults = blendNode->clipResults(animatorIds[index]); // THEN QCOMPARE(actualClipResults.size(), expectedClipResults[index].size()); -- cgit v1.2.3 From 8256e82d72f17721fb40428df6c7ba397b3e7edd Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Sat, 4 Mar 2017 16:46:30 +0000 Subject: Add virtual to ClipBlendNode to allow querying dependencies This will allow a job to build up a list of clips to be evaluated for the blend tree. This has enough flexibility to allow us to support many types of bend node in the future but still allow us to only evaluate the clips actually needed at any given time and for the current set of blend node states. Change-Id: I6bfff6d18434af4f09764d890af6f8f429996994 Reviewed-by: Mike Krus --- .../additiveclipblend/tst_additiveclipblend.cpp | 28 ++++++++++++++++++++++ .../animation/clipblendnode/tst_clipblendnode.cpp | 5 ++++ .../tst_clipblendnodemanager.cpp | 4 ++++ .../clipblendvalue/tst_clipblendvalue.cpp | 24 +++++++++++++++++++ .../animation/lerpclipblend/tst_lerpclipblend.cpp | 27 +++++++++++++++++++++ 5 files changed, 88 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp index e6777cd6a..bdae53ee3 100644 --- a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp +++ b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp @@ -171,6 +171,34 @@ private Q_SLOTS: // THEN QCOMPARE(computed, result); } + + void checkDependencyIds() + { + // GIVEN + Qt3DAnimation::Animation::AdditiveClipBlend addBlend; + auto baseClipId = Qt3DCore::QNodeId::createId(); + auto additiveClipId = Qt3DCore::QNodeId::createId(); + + // WHEN + addBlend.setBaseClipId(baseClipId); + addBlend.setAdditiveClipId(additiveClipId); + QVector actualIds = addBlend.dependencyIds(); + + // THEN + QCOMPARE(actualIds.size(), 2); + QCOMPARE(actualIds[0], baseClipId); + QCOMPARE(actualIds[1], additiveClipId); + + // WHEN + auto anotherAdditiveClipId = Qt3DCore::QNodeId::createId(); + addBlend.setAdditiveClipId(anotherAdditiveClipId); + actualIds = addBlend.dependencyIds(); + + // THEN + QCOMPARE(actualIds.size(), 2); + QCOMPARE(actualIds[0], baseClipId); + QCOMPARE(actualIds[1], anotherAdditiveClipId); + } }; QTEST_MAIN(tst_AdditiveClipBlend) diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp index 7174dff54..bc736ebb8 100644 --- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -55,6 +55,11 @@ public: float blend(float , float ) const Q_DECL_FINAL { return 0.0f; } + QVector dependencyIds() const Q_DECL_FINAL + { + return QVector(); + } + using ClipBlendNode::setClipResults; }; diff --git a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp index 962813d15..6721401ee 100644 --- a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp +++ b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp @@ -51,6 +51,10 @@ public: float blend(float , float ) const Q_DECL_FINAL { return 0.0f; } + QVector dependencyIds() const Q_DECL_FINAL + { + return QVector(); + } }; } // anonymous diff --git a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp index 5bed23704..48b0f6931 100644 --- a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp +++ b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp @@ -108,6 +108,30 @@ private Q_SLOTS: QCOMPARE(backendClipBlendValue.clipId(), newValue.id()); } } + + void checkDependencyIds() + { + // GIVEN + Qt3DAnimation::Animation::ClipBlendValue clipNode; + auto clipId = Qt3DCore::QNodeId::createId(); + + // WHEN + clipNode.setClipId(clipId); + QVector actualIds = clipNode.dependencyIds(); + + // THEN + QCOMPARE(actualIds.size(), 1); + QCOMPARE(actualIds[0], clipId); + + // WHEN + auto anotherClipId = Qt3DCore::QNodeId::createId(); + clipNode.setClipId(anotherClipId); + actualIds = clipNode.dependencyIds(); + + // THEN + QCOMPARE(actualIds.size(), 1); + QCOMPARE(actualIds[0], anotherClipId); + } }; QTEST_MAIN(tst_ClipBlendValue) diff --git a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp index 18eaa064e..160049da7 100644 --- a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp +++ b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp @@ -142,6 +142,33 @@ private Q_SLOTS: QCOMPARE(computed, result); } + void checkDependencyIds() + { + // GIVEN + Qt3DAnimation::Animation::LerpClipBlend lerpBlend; + auto startClipId = Qt3DCore::QNodeId::createId(); + auto endClipId = Qt3DCore::QNodeId::createId(); + + // WHEN + lerpBlend.setStartClipId(startClipId); + lerpBlend.setEndClipId(endClipId); + QVector actualIds = lerpBlend.dependencyIds(); + + // THEN + QCOMPARE(actualIds.size(), 2); + QCOMPARE(actualIds[0], startClipId); + QCOMPARE(actualIds[1], endClipId); + + // WHEN + auto anotherEndClipId = Qt3DCore::QNodeId::createId(); + lerpBlend.setEndClipId(anotherEndClipId); + actualIds = lerpBlend.dependencyIds(); + + // THEN + QCOMPARE(actualIds.size(), 2); + QCOMPARE(actualIds[0], startClipId); + QCOMPARE(actualIds[1], anotherEndClipId); + } }; QTEST_MAIN(tst_LerpClipBlend) -- cgit v1.2.3 From fd39bbaca2fe8e29bb9b603340ed94c7480b6da5 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Sat, 4 Mar 2017 16:54:10 +0000 Subject: Add using namespace Qt3DAnimation::Animation to some backend tests Reduces visual clutter. Change-Id: I244fdbab32d6f8fb77d5f9bd364fa1f9c8c7ec2c Reviewed-by: Mike Krus --- .../additiveclipblend/tst_additiveclipblend.cpp | 16 +++++++++------- .../auto/animation/clipblendvalue/tst_clipblendvalue.cpp | 14 ++++++++------ tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp | 16 +++++++++------- 3 files changed, 26 insertions(+), 20 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp index bdae53ee3..2cc707fa5 100644 --- a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp +++ b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp @@ -35,6 +35,8 @@ #include #include "qbackendnodetester.h" +using namespace Qt3DAnimation::Animation; + class tst_AdditiveClipBlend : public Qt3DCore::QBackendNodeTester { Q_OBJECT @@ -44,7 +46,7 @@ private Q_SLOTS: void checkInitialState() { // GIVEN - Qt3DAnimation::Animation::AdditiveClipBlend backendAdditiveBlend; + AdditiveClipBlend backendAdditiveBlend; // THEN QCOMPARE(backendAdditiveBlend.isEnabled(), false); @@ -52,7 +54,7 @@ private Q_SLOTS: QCOMPARE(backendAdditiveBlend.baseClipId(), Qt3DCore::QNodeId()); QCOMPARE(backendAdditiveBlend.additiveClipId(), Qt3DCore::QNodeId()); QCOMPARE(backendAdditiveBlend.additiveFactor(), 0.0f); - QCOMPARE(backendAdditiveBlend.blendType(), Qt3DAnimation::Animation::ClipBlendNode::AdditiveBlendType); + QCOMPARE(backendAdditiveBlend.blendType(), ClipBlendNode::AdditiveBlendType); } void checkInitializeFromPeer() @@ -69,7 +71,7 @@ private Q_SLOTS: { // WHEN - Qt3DAnimation::Animation::AdditiveClipBlend backendAdditiveBlend; + AdditiveClipBlend backendAdditiveBlend; simulateInitialization(&additiveBlend, &backendAdditiveBlend); // THEN @@ -83,7 +85,7 @@ private Q_SLOTS: } { // WHEN - Qt3DAnimation::Animation::AdditiveClipBlend backendAdditiveBlend; + AdditiveClipBlend backendAdditiveBlend; additiveBlend.setEnabled(false); simulateInitialization(&additiveBlend, &backendAdditiveBlend); @@ -96,7 +98,7 @@ private Q_SLOTS: void checkSceneChangeEvents() { // GIVEN - Qt3DAnimation::Animation::AdditiveClipBlend backendAdditiveBlend; + AdditiveClipBlend backendAdditiveBlend; { // WHEN const bool newValue = false; @@ -162,7 +164,7 @@ private Q_SLOTS: QFETCH(float, value2); QFETCH(float, blendFactor); QFETCH(float, result); - Qt3DAnimation::Animation::AdditiveClipBlend addBlend; + AdditiveClipBlend addBlend; // WHEN addBlend.setAdditiveFactor(blendFactor); @@ -175,7 +177,7 @@ private Q_SLOTS: void checkDependencyIds() { // GIVEN - Qt3DAnimation::Animation::AdditiveClipBlend addBlend; + AdditiveClipBlend addBlend; auto baseClipId = Qt3DCore::QNodeId::createId(); auto additiveClipId = Qt3DCore::QNodeId::createId(); diff --git a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp index 48b0f6931..c23d98672 100644 --- a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp +++ b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp @@ -35,6 +35,8 @@ #include #include "qbackendnodetester.h" +using namespace Qt3DAnimation::Animation; + class tst_ClipBlendValue : public Qt3DCore::QBackendNodeTester { Q_OBJECT @@ -43,13 +45,13 @@ private Q_SLOTS: void checkInitialState() { // GIVEN - Qt3DAnimation::Animation::ClipBlendValue backendClipBlendValue; + ClipBlendValue backendClipBlendValue; // THEN QCOMPARE(backendClipBlendValue.isEnabled(), false); QVERIFY(backendClipBlendValue.peerId().isNull()); QCOMPARE(backendClipBlendValue.clipId(), Qt3DCore::QNodeId()); - QCOMPARE(backendClipBlendValue.blendType(), Qt3DAnimation::Animation::ClipBlendNode::ValueType); + QCOMPARE(backendClipBlendValue.blendType(), ClipBlendNode::ValueType); } void checkInitializeFromPeer() @@ -61,7 +63,7 @@ private Q_SLOTS: { // WHEN - Qt3DAnimation::Animation::ClipBlendValue backendClipBlendValue; + ClipBlendValue backendClipBlendValue; simulateInitialization(&clipBlendValue, &backendClipBlendValue); // THEN @@ -71,7 +73,7 @@ private Q_SLOTS: } { // WHEN - Qt3DAnimation::Animation::ClipBlendValue backendClipBlendValue; + ClipBlendValue backendClipBlendValue; clipBlendValue.setEnabled(false); simulateInitialization(&clipBlendValue, &backendClipBlendValue); @@ -84,7 +86,7 @@ private Q_SLOTS: void checkSceneChangeEvents() { // GIVEN - Qt3DAnimation::Animation::ClipBlendValue backendClipBlendValue; + ClipBlendValue backendClipBlendValue; { // WHEN const bool newValue = false; @@ -112,7 +114,7 @@ private Q_SLOTS: void checkDependencyIds() { // GIVEN - Qt3DAnimation::Animation::ClipBlendValue clipNode; + ClipBlendValue clipNode; auto clipId = Qt3DCore::QNodeId::createId(); // WHEN diff --git a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp index 160049da7..34c52ff53 100644 --- a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp +++ b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp @@ -35,6 +35,8 @@ #include #include "qbackendnodetester.h" +using namespace Qt3DAnimation::Animation; + class tst_LerpClipBlend : public Qt3DCore::QBackendNodeTester { Q_OBJECT @@ -44,13 +46,13 @@ private Q_SLOTS: void checkInitialState() { // GIVEN - Qt3DAnimation::Animation::LerpClipBlend backendLerpBlend; + LerpClipBlend backendLerpBlend; // THEN QCOMPARE(backendLerpBlend.isEnabled(), false); QVERIFY(backendLerpBlend.peerId().isNull()); QCOMPARE(backendLerpBlend.blendFactor(), 0.0f); - QCOMPARE(backendLerpBlend.blendType(), Qt3DAnimation::Animation::ClipBlendNode::LerpBlendType); + QCOMPARE(backendLerpBlend.blendType(), ClipBlendNode::LerpBlendType); } void checkInitializeFromPeer() @@ -63,7 +65,7 @@ private Q_SLOTS: { // WHEN - Qt3DAnimation::Animation::LerpClipBlend backendLerpBlend; + LerpClipBlend backendLerpBlend; simulateInitialization(&lerpBlend, &backendLerpBlend); // THEN @@ -75,7 +77,7 @@ private Q_SLOTS: } { // WHEN - Qt3DAnimation::Animation::LerpClipBlend backendLerpBlend; + LerpClipBlend backendLerpBlend; lerpBlend.setEnabled(false); simulateInitialization(&lerpBlend, &backendLerpBlend); @@ -88,7 +90,7 @@ private Q_SLOTS: void checkSceneChangeEvents() { // GIVEN - Qt3DAnimation::Animation::LerpClipBlend backendLerpBlend; + LerpClipBlend backendLerpBlend; { // WHEN const bool newValue = false; @@ -132,7 +134,7 @@ private Q_SLOTS: QFETCH(float, value2); QFETCH(float, blendFactor); QFETCH(float, result); - Qt3DAnimation::Animation::LerpClipBlend lerpBlend; + LerpClipBlend lerpBlend; // WHEN lerpBlend.setBlendFactor(blendFactor); @@ -145,7 +147,7 @@ private Q_SLOTS: void checkDependencyIds() { // GIVEN - Qt3DAnimation::Animation::LerpClipBlend lerpBlend; + LerpClipBlend lerpBlend; auto startClipId = Qt3DCore::QNodeId::createId(); auto endClipId = Qt3DCore::QNodeId::createId(); -- cgit v1.2.3 From fb44c0de7226a41c400c73fe33009b0d46f806d3 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Wed, 15 Mar 2017 10:13:00 +0000 Subject: Add function to calculate phase of animation from global time When we come to evaluate animation blend trees, the resulting duration of the blend tree will also be blended. This means that we can't just map from global time to local time of each leaf node clip. Instead we need to evaluate the clips at a consistent phase. This way we can safely blend a 3 second walk animation cycle with a 2 second run animation cycle safely. So long as the animator lines up the foot falls at consistent phases. We will therefore need to be able to calculate the phase from the current global time and the blend tree's duration before we can eventually evaluate the clips at the phase. Change-Id: I7bce231cdc2eee8cb873f2c98c6c8c2e05533c8c Reviewed-by: Mike Krus --- .../animationutils/tst_animationutils.cpp | 165 +++++++++++++++++++++ 1 file changed, 165 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 7600f4d91..c19be320c 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -360,6 +360,171 @@ private Q_SLOTS: QCOMPARE(actualLocalTime, expectedLocalTime); } + void checkPhaseFromGlobalTime_data() + { + QTest::addColumn("globalTime"); + QTest::addColumn("globalStartTime"); + QTest::addColumn("playbackRate"); + QTest::addColumn("duration"); + QTest::addColumn("loopCount"); + QTest::addColumn("expectedPhase"); + QTest::addColumn("expectedCurrentLoop"); + + double globalTime; + double globalStartTime; + double playbackRate; + double duration; + int loopCount; + double expectedPhase; + int expectedCurrentLoop; + + globalTime = 0.0; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 1; + expectedPhase = 0.0; + expectedCurrentLoop = 0; + QTest::newRow("simple, t_global = 0") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedPhase << expectedCurrentLoop; + + globalTime = 0.5; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 1; + expectedPhase = 0.5; + expectedCurrentLoop = 0; + QTest::newRow("simple, t_global = 0.5") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedPhase << expectedCurrentLoop; + + globalTime = 1.0; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 1; + expectedPhase = 1.0; + expectedCurrentLoop = 0; + QTest::newRow("simple, t_global = 1.0") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedPhase << expectedCurrentLoop; + + globalTime = -0.5; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 1; + expectedPhase = 0.0; + expectedCurrentLoop = 0; + QTest::newRow("simple, t_global = -0.5") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedPhase << expectedCurrentLoop; + + globalTime = 1.5; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 1; + expectedPhase = 1.0; + expectedCurrentLoop = 0; + QTest::newRow("simple, t_global = 1.5") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedPhase << expectedCurrentLoop; + + globalTime = 0.5; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 2; + expectedPhase = 0.5; + expectedCurrentLoop = 0; + QTest::newRow("simple, loopCount = 2, t_global = 0.5") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedPhase << expectedCurrentLoop; + + globalTime = 1.5; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 2; + expectedPhase = 0.5; + expectedCurrentLoop = 1; + QTest::newRow("simple, loopCount = 2, t_global = 1.5") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedPhase << expectedCurrentLoop; + + globalTime = 3.5; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 2.0; + loopCount = 2; + expectedPhase = 0.75; + expectedCurrentLoop = 1; + QTest::newRow("duration = 2, loopCount = 2, t_global = 3.5") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedPhase << expectedCurrentLoop; + + globalTime = 4.5; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 2.0; + loopCount = 2; + expectedPhase = 1.0; + expectedCurrentLoop = 1; + QTest::newRow("duration = 2, loopCount = 2, t_global = 4.5") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedPhase << expectedCurrentLoop; + + globalTime = 1.5; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 0; + expectedPhase = 0.5; + expectedCurrentLoop = 1; + QTest::newRow("simple, loopCount = inf, t_global = 1.5") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedPhase << expectedCurrentLoop; + + globalTime = 10.2; + globalStartTime = 0.0; + playbackRate = 1.0; + duration = 1.0; + loopCount = 0; + expectedPhase = 0.2; + expectedCurrentLoop = 10; + QTest::newRow("simple, loopCount = inf, t_global = 10.2") + << globalTime << globalStartTime << playbackRate << duration << loopCount + << expectedPhase << expectedCurrentLoop; + } + + void checkPhaseFromGlobalTime() + { + // GIVEN + QFETCH(double, globalTime); + QFETCH(double, globalStartTime); + QFETCH(double, playbackRate); + QFETCH(double, duration); + QFETCH(int, loopCount); + QFETCH(double, expectedPhase); + QFETCH(int, expectedCurrentLoop); + + // WHEN + int actualCurrentLoop = 0; + double actualPhase = phaseFromGlobalTime(globalTime, + globalStartTime, + playbackRate, + duration, + loopCount, + actualCurrentLoop); + + // THEN + QCOMPARE(actualCurrentLoop, expectedCurrentLoop); + QCOMPARE(actualPhase, expectedPhase); + } + void checkPreparePropertyChanges_data() { QTest::addColumn("animatorId"); -- cgit v1.2.3 From b19e1cf6b03b7236c1c6bac8614eb41da8a915d8 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Wed, 15 Mar 2017 10:28:00 +0000 Subject: Add function to evaluate clip at a given phase This is another piece of the puzzle for evaluating blend trees. Change-Id: If0604125b11bacf0c205a69a59d39f601dd2ebd1 Reviewed-by: Mike Krus --- .../animationutils/tst_animationutils.cpp | 107 +++++++++++++++++++++ 1 file changed, 107 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index c19be320c..7c95b2117 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -873,6 +873,113 @@ private Q_SLOTS: delete handler; } + void checkEvaluateClipAtPhase_data() + { + QTest::addColumn("handler"); + QTest::addColumn("clip"); + QTest::addColumn("phase"); + QTest::addColumn("expectedResults"); + + Handler *handler; + AnimationClipLoader *clip; + float phase; + ClipResults expectedResults; + + { + handler = new Handler(); + clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json")); + phase = 0.0f; + expectedResults = QVector() << 0.0f << 0.0f << 0.0f; + + QTest::newRow("clip1.json, phi = 0.0") + << handler << clip << phase << expectedResults; + expectedResults.clear(); + } + + { + handler = new Handler(); + clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json")); + phase = 1.0f; + expectedResults = QVector() << 5.0f << 0.0f << 0.0f; + + QTest::newRow("clip1.json, phi = 1.0") + << handler << clip << phase << expectedResults; + expectedResults.clear(); + } + + { + handler = new Handler(); + clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json")); + phase = 0.5f; + expectedResults = QVector() << 2.5f << 0.0f << 0.0f; + + QTest::newRow("clip1.json, phi = 0.5") + << handler << clip << phase << expectedResults; + expectedResults.clear(); + } + + { + handler = new Handler(); + clip = createAnimationClipLoader(handler, QUrl("qrc:/clip2.json")); + phase = 0.0f; + expectedResults = QVector() + << 0.0f << 0.0f << 0.0f // Translation + << 1.0f << 0.0f << 0.0f << 0.0f; // Rotation + + QTest::newRow("clip2.json, phi = 0.0") + << handler << clip << phase << expectedResults; + expectedResults.clear(); + } + { + handler = new Handler(); + clip = createAnimationClipLoader(handler, QUrl("qrc:/clip2.json")); + phase = 1.0f; + expectedResults = QVector() + << 5.0f << 0.0f << 0.0f // Translation + << 0.0f << 0.0f << -1.0f << 0.0f; // Rotation + + QTest::newRow("clip2.json, t = 1.0") + << handler << clip << phase << expectedResults; + expectedResults.clear(); + } + { + handler = new Handler(); + clip = createAnimationClipLoader(handler, QUrl("qrc:/clip2.json")); + phase = 0.5f; + expectedResults = QVector() + << 2.5f << 0.0f << 0.0f // Translation + << 0.5f << 0.0f << -0.5f << 0.0f; // Rotation + + QTest::newRow("clip2.json, phi = 0.5") + << handler << clip << phase << expectedResults; + expectedResults.clear(); + } + } + + void checkEvaluateClipAtPhase() + { + // GIVEN + QFETCH(Handler *, handler); + QFETCH(AnimationClipLoader *, clip); + QFETCH(float, phase); + QFETCH(ClipResults, expectedResults); + + // WHEN + ClipResults actualResults = evaluateClipAtPhase(clip, phase); + + // THEN + QCOMPARE(actualResults.size(), expectedResults.size()); + for (int i = 0; i < actualResults.size(); ++i) { + auto actual = actualResults[i]; + auto expected = expectedResults[i]; + + QVERIFY(fuzzyCompare(actual, expected) == true); + } + + // Cleanup + delete handler; + } + void checkChannelComponentsToIndicesHelper_data() { QTest::addColumn("channel"); -- cgit v1.2.3 From b5b0ce0df57fc67c100e64d9cac34dee46d7ae72 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Wed, 15 Mar 2017 18:36:01 +0000 Subject: Add function to find set of leaf blend node ids that need evaluating We should only evaluate the clips that are actually dependencies of the blend tree being evaluated given its current state. At present this will simply be the set of all leaf nodes in the blend tree but in the future when we support generalised lerp nodes etc, this will yield the subset needed for the current state. This involved adding support for pre-order traversal of the blend tree. As a result, extended the visitor to work with both pre and post orders and for all nodes or only the dependencies. Note that we return the ids of the blend tree nodes, not the ids of the clips themsevles. This is so we can then index the results by blend node id in a later commit. Change-Id: Ia13fe90ec3090306c1e8ade316ce0540f36a67fd Reviewed-by: Mike Krus --- .../animationutils/tst_animationutils.cpp | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 7c95b2117..534eb1678 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -31,7 +31,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -123,6 +125,28 @@ public: return animator; } + LerpClipBlend *createLerpClipBlend(Handler *handler) + { + auto lerpId = Qt3DCore::QNodeId::createId(); + LerpClipBlend *lerp = new LerpClipBlend(); + setPeerId(lerp, lerpId); + lerp->setClipBlendNodeManager(handler->clipBlendNodeManager()); + lerp->setHandler(handler); + handler->clipBlendNodeManager()->appendNode(lerpId, lerp); + return lerp; + } + + ClipBlendValue *createClipBlendValue(Handler *handler) + { + auto valueId = Qt3DCore::QNodeId::createId(); + ClipBlendValue *value = new ClipBlendValue(); + setPeerId(value, valueId); + value->setClipBlendNodeManager(handler->clipBlendNodeManager()); + value->setHandler(handler); + handler->clipBlendNodeManager()->appendNode(valueId, value); + return value; + } + private Q_SLOTS: void checkBuildPropertyMappings_data() { @@ -1481,6 +1505,51 @@ private Q_SLOTS: // Cleanup delete handler; } + + void checkGatherValueNodesToEvaluate_data() + { + QTest::addColumn("handler"); + QTest::addColumn("blendTreeRootId"); + QTest::addColumn>("expectedIds"); + + { + Handler *handler = new Handler; + + const auto lerp = createLerpClipBlend(handler); + const auto value1 = createClipBlendValue(handler); + const auto clip1Id = Qt3DCore::QNodeId::createId(); + value1->setClipId(clip1Id); + lerp->setStartClipId(value1->peerId()); + + const auto value2 = createClipBlendValue(handler); + const auto clip2Id = Qt3DCore::QNodeId::createId(); + value2->setClipId(clip2Id); + lerp->setEndClipId(value2->peerId()); + + QVector expectedIds = { value1->peerId(), value2->peerId() }; + + QTest::newRow("simple lerp") << handler << lerp->peerId() << expectedIds; + } + } + + void checkGatherValueNodesToEvaluate() + { + // GIVEN + QFETCH(Handler *, handler); + QFETCH(Qt3DCore::QNodeId, blendTreeRootId); + QFETCH(QVector, expectedIds); + + // WHEN + QVector actualIds = gatherValueNodesToEvaluate(handler, blendTreeRootId); + + // THEN + QCOMPARE(actualIds.size(), expectedIds.size()); + for (int i = 0; i < actualIds.size(); ++i) + QCOMPARE(actualIds[i], expectedIds[i]); + + // Cleanup + delete handler; + } }; QTEST_MAIN(tst_AnimationUtils) -- cgit v1.2.3 From d18d6cb1989cf6925015da3860439e50e57bc30d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Mon, 20 Mar 2017 14:50:32 +0200 Subject: Fix scene2d mouse event coordinate calculation Apply the window size and use correct texture coordinates. Task-number: QTBUG-57253 Change-Id: Ibc5f7ef878baf938b1b3e3b7cfb4eba2cea38ad6 Reviewed-by: Shawn Rutledge Reviewed-by: Sean Harmer --- tests/auto/render/commons/testrenderer.cpp | 1 + tests/auto/render/commons/testrenderer.h | 5 +- tests/auto/render/scene2d/tst_scene2d.cpp | 289 +++++++++++++++++++++++++++++ 3 files changed, 293 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/commons/testrenderer.cpp b/tests/auto/render/commons/testrenderer.cpp index f318797ca..5304ff142 100644 --- a/tests/auto/render/commons/testrenderer.cpp +++ b/tests/auto/render/commons/testrenderer.cpp @@ -32,6 +32,7 @@ QT_BEGIN_NAMESPACE TestRenderer::TestRenderer() : m_changes(0) + , m_managers(nullptr) { } diff --git a/tests/auto/render/commons/testrenderer.h b/tests/auto/render/commons/testrenderer.h index ecbec4aa3..74f529fa0 100644 --- a/tests/auto/render/commons/testrenderer.h +++ b/tests/auto/render/commons/testrenderer.h @@ -43,10 +43,10 @@ public: API api() const Q_DECL_OVERRIDE { return AbstractRenderer::OpenGL; } qint64 time() const Q_DECL_OVERRIDE { return 0; } void setTime(qint64 time) Q_DECL_OVERRIDE { Q_UNUSED(time); } - void setNodeManagers(Qt3DRender::Render::NodeManagers *managers) Q_DECL_OVERRIDE { Q_UNUSED(managers); } + void setNodeManagers(Qt3DRender::Render::NodeManagers *m) Q_DECL_OVERRIDE { m_managers = m; } void setServices(Qt3DCore::QServiceLocator *services) Q_DECL_OVERRIDE { Q_UNUSED(services); } void setSurfaceExposed(bool exposed) Q_DECL_OVERRIDE { Q_UNUSED(exposed); } - Qt3DRender::Render::NodeManagers *nodeManagers() const Q_DECL_OVERRIDE { return nullptr; } + Qt3DRender::Render::NodeManagers *nodeManagers() const Q_DECL_OVERRIDE { return m_managers; } Qt3DCore::QServiceLocator *services() const Q_DECL_OVERRIDE { return nullptr; } void initialize() Q_DECL_OVERRIDE {} void shutdown() Q_DECL_OVERRIDE {} @@ -81,6 +81,7 @@ public: protected: Qt3DRender::Render::AbstractRenderer::BackendNodeDirtySet m_changes; + Qt3DRender::Render::NodeManagers *m_managers; }; QT_END_NAMESPACE diff --git a/tests/auto/render/scene2d/tst_scene2d.cpp b/tests/auto/render/scene2d/tst_scene2d.cpp index b53318e7c..d0bd5ca9d 100644 --- a/tests/auto/render/scene2d/tst_scene2d.cpp +++ b/tests/auto/render/scene2d/tst_scene2d.cpp @@ -30,13 +30,69 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include "testrenderer.h" using namespace Qt3DRender::Quick; +using namespace Qt3DRender::Render; using namespace Qt3DRender::Render::Quick; +bool qFuzzyComparePointF(const QPointF& a, const QPointF& b) { + return qFuzzyCompare(a.x(), b.x()) && qFuzzyCompare(a.y(), b.y()); +} + +class TestWindow : public QQuickWindow +{ + Q_OBJECT +public: + TestWindow() + : QQuickWindow() + { + + } + + bool event(QEvent *e) Q_DECL_OVERRIDE + { + if (e->type() >= QEvent::MouseButtonPress && + e->type() <= QEvent::MouseMove) { + QMouseEvent *me = static_cast(e); + m_eventTypes.push_back(e->type()); + m_mousePoints.push_back(me->localPos()); + } + return QQuickWindow::event(e); + } + + bool verifyEventPos(uint index, QEvent::Type type, const QPointF& pos) + { + if (index >= unsigned(m_eventTypes.size()) || + m_eventTypes[index] != type || + !qFuzzyComparePointF(pos, m_mousePoints[index])) + return false; + return true; + } + + void clear() + { + m_eventTypes.clear(); + m_mousePoints.clear(); + } + +private: + QVector m_eventTypes; + QVector m_mousePoints; +}; + class tst_Scene2D : public Qt3DCore::QBackendNodeTester { Q_OBJECT @@ -154,6 +210,239 @@ private Q_SLOTS: backendScene2d->cleanup(); } + + void testCoordinateCalculation() + { + // GIVEN + QScopedPointer testWindow(new TestWindow()); + Scene2DSharedObjectPtr sharedObject(new Scene2DSharedObject(nullptr)); + QScopedPointer scene2d(new Scene2D()); + QScopedPointer nodeManagers(new NodeManagers()); + Qt3DRender::QGeometry *geometry = new Qt3DRender::QGeometry(); + Qt3DRender::QGeometryRenderer *geometryRenderer = new Qt3DRender::QGeometryRenderer(); + Qt3DRender::QAttribute *positionAttribute = new Qt3DRender::QAttribute(); + Qt3DRender::QAttribute *texcoordAttribute = new Qt3DRender::QAttribute(); + Qt3DRender::QBuffer *dataBuffer =new Qt3DRender::QBuffer(); + QScopedPointer entity(new Qt3DCore::QEntity()); + entity->addComponent(geometryRenderer); + TestRenderer renderer; + renderer.setNodeManagers(nodeManagers.data()); + scene2d->setRenderer(&renderer); + sharedObject->m_quickWindow = testWindow.data(); + scene2d->setSharedObject(sharedObject); + testWindow->setGeometry(0,0,1024,1024); + + QByteArray data; + data.resize(sizeof(float) * 5 * 6); + float *dataPtr = reinterpret_cast(data.data()); + int i = 0; + dataPtr[i++] = -1.0f; + dataPtr[i++] = 1.0f; + dataPtr[i++] = 1.0f; + dataPtr[i++] = 0; + dataPtr[i++] = 0; + + dataPtr[i++] = 1.0f; + dataPtr[i++] = 1.0f; + dataPtr[i++] = 1.0f; + dataPtr[i++] = 1.0f; + dataPtr[i++] = 0; + + dataPtr[i++] = 1.0f; + dataPtr[i++] = -1.0f; + dataPtr[i++] = 1.0f; + dataPtr[i++] = 1.0f; + dataPtr[i++] = 1.0f; + + dataPtr[i++] = -1.0f; + dataPtr[i++] = 1.0f; + dataPtr[i++] = 1.0f; + dataPtr[i++] = 0; + dataPtr[i++] = 0; + + dataPtr[i++] = 1.0f; + dataPtr[i++] = -1.0f; + dataPtr[i++] = 1.0f; + dataPtr[i++] = 1.0f; + dataPtr[i++] = 1.0f; + + dataPtr[i++] = -1.0f; + dataPtr[i++] = -1.0f; + dataPtr[i++] = 1.0f; + dataPtr[i++] = 0.0f; + dataPtr[i++] = 1.0f; + + dataBuffer->setData(data); + Buffer *backendBuffer = nodeManagers->bufferManager()->getOrCreateResource(dataBuffer->id()); + backendBuffer->setRenderer(&renderer); + backendBuffer->setManager(nodeManagers->bufferManager()); + simulateInitialization(dataBuffer, backendBuffer); + + positionAttribute->setBuffer(dataBuffer); + positionAttribute->setName(Qt3DRender::QAttribute::defaultPositionAttributeName()); + positionAttribute->setVertexBaseType(Qt3DRender::QAttribute::Float); + positionAttribute->setVertexSize(3); + positionAttribute->setCount(6); + positionAttribute->setByteStride(sizeof(float) * 5); + positionAttribute->setByteOffset(0); + positionAttribute->setAttributeType(Qt3DRender::QAttribute::VertexAttribute); + geometry->addAttribute(positionAttribute); + + texcoordAttribute->setBuffer(dataBuffer); + texcoordAttribute->setName(Qt3DRender::QAttribute::defaultTextureCoordinateAttributeName()); + texcoordAttribute->setVertexBaseType(Qt3DRender::QAttribute::Float); + texcoordAttribute->setVertexSize(2); + texcoordAttribute->setCount(6); + texcoordAttribute->setByteStride(sizeof(float) * 5); + texcoordAttribute->setByteOffset(sizeof(float) * 3); + texcoordAttribute->setAttributeType(Qt3DRender::QAttribute::VertexAttribute); + geometry->addAttribute(texcoordAttribute); + + geometryRenderer->setGeometry(geometry); + geometryRenderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles); + + Attribute *backendAttribute = nodeManagers->attributeManager()->getOrCreateResource( + positionAttribute->id()); + backendAttribute->setRenderer(&renderer); + simulateInitialization(positionAttribute, backendAttribute); + + Attribute *backendTexcoordAttribute = nodeManagers->attributeManager() + ->getOrCreateResource(texcoordAttribute->id()); + backendTexcoordAttribute->setRenderer(&renderer); + simulateInitialization(texcoordAttribute, backendTexcoordAttribute); + + Geometry *backendGeometry = nodeManagers->geometryManager() + ->getOrCreateResource(geometry->id()); + backendGeometry->setRenderer(&renderer); + simulateInitialization(geometry, backendGeometry); + + GeometryRenderer *backendRenderer = nodeManagers->geometryRendererManager() + ->getOrCreateResource(geometryRenderer->id()); + backendRenderer->setRenderer(&renderer); + backendRenderer->setManager(nodeManagers->geometryRendererManager()); + simulateInitialization(geometryRenderer, backendRenderer); + + Entity *backendEntity = nodeManagers->renderNodesManager()->getOrCreateResource(entity->id()); + backendEntity->setRenderer(&renderer); + backendEntity->setNodeManagers(nodeManagers.data()); + simulateInitialization(entity.data(), backendEntity); + +#define PICK_TRIANGLE(tri, v0, v1, v2, uvw) \ + new Qt3DRender::QPickTriangleEvent(QPointF(), QVector3D(), QVector3D(), 0.0f, \ + tri, v0, v1, v2, Qt3DRender::QPickEvent::LeftButton, Qt::LeftButton, 0, uvw) + + { + // WHEN + QVector3D uvw(1.0, 0.0f, 0.0f); + Qt3DRender::QPickEventPtr ev = Qt3DRender::QPickEventPtr(PICK_TRIANGLE(0, 0, 1, 2, uvw)); + Qt3DRender::QPickEventPrivate::get(ev.data())->m_entity = entity->id(); + scene2d->handlePickEvent(QEvent::MouseButtonPress, ev); + + QCoreApplication::processEvents(); + + // THEN + QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(0,0))); + testWindow->clear(); + } + + { + // WHEN + QVector3D uvw(0.0, 1.0f, 0.0f); + Qt3DRender::QPickEventPtr ev = Qt3DRender::QPickEventPtr(PICK_TRIANGLE(0, 0, 1, 2, uvw)); + Qt3DRender::QPickEventPrivate::get(ev.data())->m_entity = entity->id(); + scene2d->handlePickEvent(QEvent::MouseButtonPress, ev); + + QCoreApplication::processEvents(); + + // THEN + QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(1024,0))); + testWindow->clear(); + } + + { + // WHEN + QVector3D uvw(0.0, 0.0f, 1.0f); + Qt3DRender::QPickEventPtr ev = Qt3DRender::QPickEventPtr(PICK_TRIANGLE(0, 0, 1, 2, uvw)); + Qt3DRender::QPickEventPrivate::get(ev.data())->m_entity = entity->id(); + scene2d->handlePickEvent(QEvent::MouseButtonPress, ev); + + QCoreApplication::processEvents(); + + // THEN + QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(1024,1024))); + testWindow->clear(); + } + + { + // WHEN + QVector3D uvw(1.0, 0.0f, 0.0f); + Qt3DRender::QPickEventPtr ev = Qt3DRender::QPickEventPtr(PICK_TRIANGLE(1, 3, 4, 5, uvw)); + Qt3DRender::QPickEventPrivate::get(ev.data())->m_entity = entity->id(); + scene2d->handlePickEvent(QEvent::MouseButtonPress, ev); + + QCoreApplication::processEvents(); + + // THEN + QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(0,0))); + testWindow->clear(); + } + + { + // WHEN + QVector3D uvw(0.0, 1.0f, 0.0f); + Qt3DRender::QPickEventPtr ev = Qt3DRender::QPickEventPtr(PICK_TRIANGLE(1, 3, 4, 5, uvw)); + Qt3DRender::QPickEventPrivate::get(ev.data())->m_entity = entity->id(); + scene2d->handlePickEvent(QEvent::MouseButtonPress, ev); + + QCoreApplication::processEvents(); + + // THEN + QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(1024,1024))); + testWindow->clear(); + } + + { + // WHEN + QVector3D uvw(0.0, 0.0f, 1.0f); + Qt3DRender::QPickEventPtr ev = Qt3DRender::QPickEventPtr(PICK_TRIANGLE(1, 3, 4, 5, uvw)); + Qt3DRender::QPickEventPrivate::get(ev.data())->m_entity = entity->id(); + scene2d->handlePickEvent(QEvent::MouseButtonPress, ev); + + QCoreApplication::processEvents(); + + // THEN + QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(0,1024))); + testWindow->clear(); + } + + { + // WHEN + QVector3D uvw(0.5f, 0.25f, 0.25f); + Qt3DRender::QPickEventPtr ev = Qt3DRender::QPickEventPtr(PICK_TRIANGLE(0, 0, 1, 2, uvw)); + Qt3DRender::QPickEventPrivate::get(ev.data())->m_entity = entity->id(); + scene2d->handlePickEvent(QEvent::MouseButtonPress, ev); + + QCoreApplication::processEvents(); + + // THEN + QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(512.0f, 256.0f))); + testWindow->clear(); + } + + { + // WHEN + QVector3D uvw(0.875f, 0.09375f, 0.03125f); + Qt3DRender::QPickEventPtr ev = Qt3DRender::QPickEventPtr(PICK_TRIANGLE(1, 3, 4, 5, uvw)); + Qt3DRender::QPickEventPrivate::get(ev.data())->m_entity = entity->id(); + scene2d->handlePickEvent(QEvent::MouseButtonPress, ev); + + QCoreApplication::processEvents(); + + // THEN + QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(96.0f, 128.0f))); + testWindow->clear(); + } + } }; QTEST_MAIN(tst_Scene2D) -- cgit v1.2.3 From c7d15b7c5e044f40167f4a79be8bf4f569c6b8be Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Thu, 16 Mar 2017 13:26:41 +0000 Subject: Add function to recursively calculate duration of a blend tree The resulting duration is independent of which animators the blend tree is associated with so this can be implemented as a simple set of virtual functions in the concrete classes. The value node simply returns the duration of the contained clip; the additive node returns the duration of the base node; and the lerp node lerps the durations of the start and end nodes. Change-Id: Ib6edea3fa495885493fa72d44437fea5a8c5a446 Reviewed-by: Paul Lemire Reviewed-by: Mike Krus --- .../additiveclipblend/tst_additiveclipblend.cpp | 60 +++++++++++++++++++++ .../animation/clipblendnode/tst_clipblendnode.cpp | 2 + .../tst_clipblendnodemanager.cpp | 2 + .../clipblendvalue/tst_clipblendvalue.cpp | 28 ++++++++++ .../animation/lerpclipblend/tst_lerpclipblend.cpp | 62 ++++++++++++++++++++++ 5 files changed, 154 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp index 2cc707fa5..7ec327cdc 100644 --- a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp +++ b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp @@ -37,9 +37,45 @@ using namespace Qt3DAnimation::Animation; +namespace { + +class TestClipBlendNode : public ClipBlendNode +{ +public: + TestClipBlendNode(double duration) + : ClipBlendNode(ClipBlendNode::LerpBlendType) + , m_duration(duration) + {} + + float blend(float, float) const Q_DECL_FINAL { return 0.0f; } + + QVector dependencyIds() const Q_DECL_FINAL + { + return QVector(); + } + + using ClipBlendNode::setClipResults; + + double duration() const Q_DECL_FINAL { return m_duration; } + + double m_duration; +}; + +} // anonymous + class tst_AdditiveClipBlend : public Qt3DCore::QBackendNodeTester { Q_OBJECT +public: + TestClipBlendNode *createTestBlendNode(Handler *handler, + double duration) + { + auto id = Qt3DCore::QNodeId::createId(); + TestClipBlendNode *node = new TestClipBlendNode(duration); + setPeerId(node, id); + handler->clipBlendNodeManager()->appendNode(id, node); + return node; + } private Q_SLOTS: @@ -201,6 +237,30 @@ private Q_SLOTS: QCOMPARE(actualIds[0], baseClipId); QCOMPARE(actualIds[1], anotherAdditiveClipId); } + + void checkDuration() + { + // GIVEN + auto handler = new Handler(); + const double expectedDuration = 123.5; + const double baseNodeDuration = expectedDuration; + const double additiveNodeDuration = 5.0; + + auto baseNode = createTestBlendNode(handler, baseNodeDuration); + auto additiveNode = createTestBlendNode(handler, additiveNodeDuration); + + AdditiveClipBlend blendNode; + blendNode.setHandler(handler); + blendNode.setClipBlendNodeManager(handler->clipBlendNodeManager()); + blendNode.setBaseClipId(baseNode->peerId()); + blendNode.setAdditiveClipId(additiveNode->peerId()); + + // WHEN + double actualDuration = blendNode.duration(); + + // THEN + QCOMPARE(actualDuration, expectedDuration); + } }; QTEST_MAIN(tst_AdditiveClipBlend) diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp index bc736ebb8..22d020c47 100644 --- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -61,6 +61,8 @@ public: } using ClipBlendNode::setClipResults; + + double duration() const Q_DECL_FINAL { return 0.0f; } }; } // anonymous diff --git a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp index 6721401ee..8a3d0972f 100644 --- a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp +++ b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp @@ -55,6 +55,8 @@ public: { return QVector(); } + + double duration() const Q_DECL_FINAL { return 0.0f; } }; } // anonymous diff --git a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp index c23d98672..12eaf1a3c 100644 --- a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp +++ b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp @@ -40,6 +40,16 @@ using namespace Qt3DAnimation::Animation; class tst_ClipBlendValue : public Qt3DCore::QBackendNodeTester { Q_OBJECT +public: + AnimationClipLoader *createAnimationClipLoader(Handler *handler, + double duration) + { + auto clipId = Qt3DCore::QNodeId::createId(); + AnimationClipLoader *clip = handler->animationClipLoaderManager()->getOrCreateResource(clipId); + setPeerId(clip, clipId); + clip->setDuration(duration); + return clip; + } private Q_SLOTS: void checkInitialState() @@ -134,6 +144,24 @@ private Q_SLOTS: QCOMPARE(actualIds.size(), 1); QCOMPARE(actualIds[0], anotherClipId); } + + void checkDuration() + { + // GIVEN + auto handler = new Handler(); + const double expectedDuration = 123.5; + auto clip = createAnimationClipLoader(handler, expectedDuration); + ClipBlendValue clipNode; + clipNode.setHandler(handler); + clipNode.setClipBlendNodeManager(handler->clipBlendNodeManager()); + clipNode.setClipId(clip->peerId()); + + // WHEN + double actualDuration = clipNode.duration(); + + // THEN + QCOMPARE(actualDuration, expectedDuration); + } }; QTEST_MAIN(tst_ClipBlendValue) diff --git a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp index 34c52ff53..6dac3c8d9 100644 --- a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp +++ b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp @@ -37,9 +37,45 @@ using namespace Qt3DAnimation::Animation; +namespace { + +class TestClipBlendNode : public ClipBlendNode +{ +public: + TestClipBlendNode(double duration) + : ClipBlendNode(ClipBlendNode::LerpBlendType) + , m_duration(duration) + {} + + float blend(float, float) const Q_DECL_FINAL { return 0.0f; } + + QVector dependencyIds() const Q_DECL_FINAL + { + return QVector(); + } + + using ClipBlendNode::setClipResults; + + double duration() const Q_DECL_FINAL { return m_duration; } + + double m_duration; +}; + +} // anonymous + class tst_LerpClipBlend : public Qt3DCore::QBackendNodeTester { Q_OBJECT +public: + TestClipBlendNode *createTestBlendNode(Handler *handler, + double duration) + { + auto id = Qt3DCore::QNodeId::createId(); + TestClipBlendNode *node = new TestClipBlendNode(duration); + setPeerId(node, id); + handler->clipBlendNodeManager()->appendNode(id, node); + return node; + } private Q_SLOTS: @@ -171,6 +207,32 @@ private Q_SLOTS: QCOMPARE(actualIds[0], startClipId); QCOMPARE(actualIds[1], anotherEndClipId); } + + void checkDuration() + { + // GIVEN + auto handler = new Handler(); + const double startNodeDuration = 10.0; + const double endNodeDuration = 20.0; + const float blendFactor = 0.25f; + const double expectedDuration = 12.5; + + auto startNode = createTestBlendNode(handler, startNodeDuration); + auto endNode = createTestBlendNode(handler, endNodeDuration); + + LerpClipBlend blendNode; + blendNode.setHandler(handler); + blendNode.setClipBlendNodeManager(handler->clipBlendNodeManager()); + blendNode.setStartClipId(startNode->peerId()); + blendNode.setEndClipId(endNode->peerId()); + blendNode.setBlendFactor(blendFactor); + + // WHEN + double actualDuration = blendNode.duration(); + + // THEN + QCOMPARE(actualDuration, expectedDuration); + } }; QTEST_MAIN(tst_LerpClipBlend) -- cgit v1.2.3 From 1da93b2fcf57dc442952b65d599db4e209faa59f Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Thu, 16 Mar 2017 15:10:25 +0000 Subject: Add missing parentheses in conditional Change-Id: I58dc19a06283a5999dbcd76f74d095daf0a9017d Reviewed-by: Paul Lemire --- tests/auto/animation/animationutils/tst_animationutils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 534eb1678..80d9a4d53 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -61,8 +61,8 @@ bool fuzzyCompare(float x1, float x2) { if (qFuzzyIsNull(x1) && qFuzzyIsNull(x2)) { return true; - } else if (qFuzzyIsNull(x1) && !qFuzzyIsNull(x2) || - !qFuzzyIsNull(x1) && qFuzzyIsNull(x2)) { + } else if ((qFuzzyIsNull(x1) && !qFuzzyIsNull(x2)) || + (!qFuzzyIsNull(x1) && qFuzzyIsNull(x2))) { return false; } else { return qFuzzyCompare(x1, x2); -- cgit v1.2.3 From 6961c308fb9d98006c98654a8131593f390c89a8 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 17 Mar 2017 17:16:06 +0000 Subject: Add virtual doBlend to ClipBlendNode and subclasses This is called by the non virtual performBlend (will be renamed once old implementation is removed). The key here is that all nodes in the blend tree will have the exact same layout for the ClipResults for a given animator. This means we don't need to have a mapping data structure for every node in the tree. This really simplifies the blending implementation and will allow us to parallelise this much better in the future as each blend node could make use of a parallel_for() or map() type operation. To achieve this we will need to perform a gather operation that maps the ClipResults coming straight out of an animation clip to the ClipResults layout used by the blend tree as described above. This will be done in a follow up commit. Change-Id: I389383d3b9197a6ef36b529f44ac89cb5c593023 Reviewed-by: Sean Harmer --- .../additiveclipblend/tst_additiveclipblend.cpp | 194 +++++++++++++++++++++ .../animation/clipblendnode/tst_clipblendnode.cpp | 53 +++++- .../tst_clipblendnodemanager.cpp | 6 + .../animation/lerpclipblend/tst_lerpclipblend.cpp | 194 +++++++++++++++++++++ 4 files changed, 446 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp index 7ec327cdc..5e25cccb9 100644 --- a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp +++ b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp @@ -37,6 +37,9 @@ using namespace Qt3DAnimation::Animation; +Q_DECLARE_METATYPE(Handler *) +Q_DECLARE_METATYPE(AdditiveClipBlend *) + namespace { class TestClipBlendNode : public ClipBlendNode @@ -58,6 +61,10 @@ public: double duration() const Q_DECL_FINAL { return m_duration; } +protected: + ClipResults doBlend(const QVector &) const Q_DECL_FINAL { return ClipResults(); } + +private: double m_duration; }; @@ -73,10 +80,36 @@ public: auto id = Qt3DCore::QNodeId::createId(); TestClipBlendNode *node = new TestClipBlendNode(duration); setPeerId(node, id); + node->setHandler(handler); + node->setClipBlendNodeManager(handler->clipBlendNodeManager()); handler->clipBlendNodeManager()->appendNode(id, node); return node; } + AdditiveClipBlend *createAdditiveClipBlendNode(Handler *handler, const float &blendFactor) + { + auto id = Qt3DCore::QNodeId::createId(); + AdditiveClipBlend *node = new AdditiveClipBlend(); + node->setAdditiveFactor(blendFactor); + setPeerId(node, id); + node->setHandler(handler); + node->setClipBlendNodeManager(handler->clipBlendNodeManager()); + handler->clipBlendNodeManager()->appendNode(id, node); + return node; + } + + BlendedClipAnimator *createBlendedClipAnimator(Handler *handler, + qint64 globalStartTimeNS, + int loops) + { + auto animatorId = Qt3DCore::QNodeId::createId(); + BlendedClipAnimator *animator = handler->blendedClipAnimatorManager()->getOrCreateResource(animatorId); + setPeerId(animator, animatorId); + animator->setStartTime(globalStartTimeNS); + animator->setLoops(loops); + return animator; + } + private Q_SLOTS: void checkInitialState() @@ -261,6 +294,167 @@ private Q_SLOTS: // THEN QCOMPARE(actualDuration, expectedDuration); } + + void checkDoBlend_data() + { + QTest::addColumn("handler"); + QTest::addColumn("blendNode"); + QTest::addColumn("animatorId"); + QTest::addColumn("expectedResults"); + + { + auto handler = new Handler(); + + const qint64 globalStartTimeNS = 0; + const int loopCount = 1; + auto animator = createBlendedClipAnimator(handler, globalStartTimeNS, loopCount); + + const double duration = 1.0; + auto baseNode = createTestBlendNode(handler, duration); + baseNode->setClipResults(animator->peerId(), { 0.0f, 0.0f, 0.0f }); + auto additiveNode = createTestBlendNode(handler, duration); + additiveNode->setClipResults(animator->peerId(), { 1.0f, 1.0f, 1.0f }); + + const float additiveFactor = 0.0f; + auto blendNode = createAdditiveClipBlendNode(handler, additiveFactor); + blendNode->setBaseClipId(baseNode->peerId()); + blendNode->setAdditiveClipId(additiveNode->peerId()); + blendNode->setAdditiveFactor(additiveFactor); + + ClipResults expectedResults = { 0.0f, 0.0f, 0.0f }; + + QTest::addRow("unit additive, beta = 0.0") + << handler << blendNode << animator->peerId() << expectedResults; + } + + { + auto handler = new Handler(); + + const qint64 globalStartTimeNS = 0; + const int loopCount = 1; + auto animator = createBlendedClipAnimator(handler, globalStartTimeNS, loopCount); + + const double duration = 1.0; + auto baseNode = createTestBlendNode(handler, duration); + baseNode->setClipResults(animator->peerId(), { 0.0f, 0.0f, 0.0f }); + auto additiveNode = createTestBlendNode(handler, duration); + additiveNode->setClipResults(animator->peerId(), { 1.0f, 1.0f, 1.0f }); + + const float additiveFactor = 0.5f; + auto blendNode = createAdditiveClipBlendNode(handler, additiveFactor); + blendNode->setBaseClipId(baseNode->peerId()); + blendNode->setAdditiveClipId(additiveNode->peerId()); + blendNode->setAdditiveFactor(additiveFactor); + + ClipResults expectedResults = { 0.5f, 0.5f, 0.5f }; + + QTest::addRow("unit additive, beta = 0.5") + << handler << blendNode << animator->peerId() << expectedResults; + } + + { + auto handler = new Handler(); + + const qint64 globalStartTimeNS = 0; + const int loopCount = 1; + auto animator = createBlendedClipAnimator(handler, globalStartTimeNS, loopCount); + + const double duration = 1.0; + auto baseNode = createTestBlendNode(handler, duration); + baseNode->setClipResults(animator->peerId(), { 0.0f, 0.0f, 0.0f }); + auto additiveNode = createTestBlendNode(handler, duration); + additiveNode->setClipResults(animator->peerId(), { 1.0f, 1.0f, 1.0f }); + + const float additiveFactor = 1.0f; + auto blendNode = createAdditiveClipBlendNode(handler, additiveFactor); + blendNode->setBaseClipId(baseNode->peerId()); + blendNode->setAdditiveClipId(additiveNode->peerId()); + blendNode->setAdditiveFactor(additiveFactor); + + ClipResults expectedResults = { 1.0f, 1.0f, 1.0f }; + + QTest::addRow("unit additive, beta = 1.0") + << handler << blendNode << animator->peerId() << expectedResults; + } + + { + auto handler = new Handler(); + + const qint64 globalStartTimeNS = 0; + const int loopCount = 1; + auto animator = createBlendedClipAnimator(handler, globalStartTimeNS, loopCount); + + const double duration = 1.0; + auto baseNode = createTestBlendNode(handler, duration); + baseNode->setClipResults(animator->peerId(), { 0.0f, 1.0f, 2.0f }); + auto additiveNode = createTestBlendNode(handler, duration); + additiveNode->setClipResults(animator->peerId(), { 1.0f, 2.0f, 3.0f }); + + const float blendFactor = 0.5f; + auto blendNode = createAdditiveClipBlendNode(handler, blendFactor); + blendNode->setBaseClipId(baseNode->peerId()); + blendNode->setAdditiveClipId(additiveNode->peerId()); + blendNode->setAdditiveFactor(blendFactor); + + ClipResults expectedResults = { 0.5f, 2.0f, 3.5f }; + + QTest::addRow("lerp varying data, beta = 0.5") + << handler << blendNode << animator->peerId() << expectedResults; + } + + { + auto handler = new Handler(); + + const qint64 globalStartTimeNS = 0; + const int loopCount = 1; + auto animator = createBlendedClipAnimator(handler, globalStartTimeNS, loopCount); + + const double duration = 1.0; + const int dataCount = 1000; + ClipResults baseData(dataCount); + ClipResults additiveData(dataCount); + ClipResults expectedResults(dataCount); + for (int i = 0; i < dataCount; ++i) { + baseData[i] = float(i); + additiveData[i] = 2.0f * float(i); + expectedResults[i] = 2.0f * float(i); + } + auto baseNode = createTestBlendNode(handler, duration); + baseNode->setClipResults(animator->peerId(), baseData); + auto additiveNode = createTestBlendNode(handler, duration); + additiveNode->setClipResults(animator->peerId(), additiveData); + + const float blendFactor = 0.5f; + auto blendNode = createAdditiveClipBlendNode(handler, blendFactor); + blendNode->setBaseClipId(baseNode->peerId()); + blendNode->setAdditiveClipId(additiveNode->peerId()); + blendNode->setAdditiveFactor(blendFactor); + + QTest::addRow("lerp lots of data, beta = 0.5") + << handler << blendNode << animator->peerId() << expectedResults; + } + } + + void checkDoBlend() + { + // GIVEN + QFETCH(Handler *, handler); + QFETCH(AdditiveClipBlend *, blendNode); + QFETCH(Qt3DCore::QNodeId, animatorId); + QFETCH(ClipResults, expectedResults); + + // WHEN + blendNode->performBlend(animatorId); + + // THEN + const ClipResults actualResults = blendNode->clipResults(animatorId); + QCOMPARE(actualResults.size(), expectedResults.size()); + for (int i = 0; i < actualResults.size(); ++i) + QCOMPARE(actualResults[i], expectedResults[i]); + + // Cleanup + delete handler; + } }; QTEST_MAIN(tst_AdditiveClipBlend) diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp index 22d020c47..c214cea58 100644 --- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -49,8 +49,9 @@ namespace { class TestClipBlendNode : public ClipBlendNode { public: - TestClipBlendNode() + TestClipBlendNode(const ClipResults &clipResults = ClipResults()) : ClipBlendNode(ClipBlendNode::LerpBlendType) + , m_clipResults(clipResults) {} float blend(float , float ) const Q_DECL_FINAL { return 0.0f; } @@ -63,6 +64,15 @@ public: using ClipBlendNode::setClipResults; double duration() const Q_DECL_FINAL { return 0.0f; } + +protected: + ClipResults doBlend(const QVector &) const Q_DECL_FINAL + { + return m_clipResults; + } + +private: + ClipResults m_clipResults; }; } // anonymous @@ -72,6 +82,27 @@ Q_DECLARE_METATYPE(TestClipBlendNode *) class tst_ClipBlendNode : public Qt3DCore::QBackendNodeTester { Q_OBJECT +public: + TestClipBlendNode *createTestClipBlendNode(Handler *handler, const ClipResults &clipResults) + { + auto id = Qt3DCore::QNodeId::createId(); + TestClipBlendNode *node = new TestClipBlendNode(clipResults); + setPeerId(node, id); + handler->clipBlendNodeManager()->appendNode(id, node); + return node; + } + + BlendedClipAnimator *createBlendedClipAnimator(Handler *handler, + qint64 globalStartTimeNS, + int loops) + { + auto animatorId = Qt3DCore::QNodeId::createId(); + BlendedClipAnimator *animator = handler->blendedClipAnimatorManager()->getOrCreateResource(animatorId); + setPeerId(animator, animatorId); + animator->setStartTime(globalStartTimeNS); + animator->setLoops(loops); + return animator; + } private Q_SLOTS: @@ -364,6 +395,26 @@ private Q_SLOTS: delete blendNode; } + + void checkPerformBlend() + { + // GIVEN + auto handler = new Handler(); + ClipResults expectedResults = { 1.0f, 2.0f, 3.0f }; + auto blendNode = createTestClipBlendNode(handler, expectedResults); + const qint64 globalStartTimeNS = 0; + const int loopCount = 1; + auto animator = createBlendedClipAnimator(handler, globalStartTimeNS, loopCount); + + // WHEN + blendNode->performBlend(animator->peerId()); + + // THEN + const ClipResults actualResults = blendNode->clipResults(animator->peerId()); + QCOMPARE(actualResults.size(), expectedResults.size()); + for (int i = 0; i < actualResults.size(); ++i) + QCOMPARE(actualResults[i], expectedResults[i]); + } }; QTEST_MAIN(tst_ClipBlendNode) diff --git a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp index 8a3d0972f..4cf8fe5ce 100644 --- a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp +++ b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp @@ -57,6 +57,12 @@ public: } double duration() const Q_DECL_FINAL { return 0.0f; } + +protected: + Qt3DAnimation::Animation::ClipResults doBlend(const QVector &) const Q_DECL_FINAL + { + return Qt3DAnimation::Animation::ClipResults(); + } }; } // anonymous diff --git a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp index 6dac3c8d9..f9ebfec4e 100644 --- a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp +++ b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp @@ -37,6 +37,9 @@ using namespace Qt3DAnimation::Animation; +Q_DECLARE_METATYPE(Handler *) +Q_DECLARE_METATYPE(LerpClipBlend *) + namespace { class TestClipBlendNode : public ClipBlendNode @@ -58,6 +61,10 @@ public: double duration() const Q_DECL_FINAL { return m_duration; } +protected: + ClipResults doBlend(const QVector &) const Q_DECL_FINAL { return ClipResults(); } + +private: double m_duration; }; @@ -73,10 +80,36 @@ public: auto id = Qt3DCore::QNodeId::createId(); TestClipBlendNode *node = new TestClipBlendNode(duration); setPeerId(node, id); + node->setHandler(handler); + node->setClipBlendNodeManager(handler->clipBlendNodeManager()); handler->clipBlendNodeManager()->appendNode(id, node); return node; } + LerpClipBlend *createLerpClipBlendNode(Handler *handler, const float &blendFactor) + { + auto id = Qt3DCore::QNodeId::createId(); + LerpClipBlend *node = new LerpClipBlend(); + node->setBlendFactor(blendFactor); + setPeerId(node, id); + node->setHandler(handler); + node->setClipBlendNodeManager(handler->clipBlendNodeManager()); + handler->clipBlendNodeManager()->appendNode(id, node); + return node; + } + + BlendedClipAnimator *createBlendedClipAnimator(Handler *handler, + qint64 globalStartTimeNS, + int loops) + { + auto animatorId = Qt3DCore::QNodeId::createId(); + BlendedClipAnimator *animator = handler->blendedClipAnimatorManager()->getOrCreateResource(animatorId); + setPeerId(animator, animatorId); + animator->setStartTime(globalStartTimeNS); + animator->setLoops(loops); + return animator; + } + private Q_SLOTS: void checkInitialState() @@ -233,6 +266,167 @@ private Q_SLOTS: // THEN QCOMPARE(actualDuration, expectedDuration); } + + void checkDoBlend_data() + { + QTest::addColumn("handler"); + QTest::addColumn("blendNode"); + QTest::addColumn("animatorId"); + QTest::addColumn("expectedResults"); + + { + auto handler = new Handler(); + + const qint64 globalStartTimeNS = 0; + const int loopCount = 1; + auto animator = createBlendedClipAnimator(handler, globalStartTimeNS, loopCount); + + const double duration = 1.0; + auto startNode = createTestBlendNode(handler, duration); + startNode->setClipResults(animator->peerId(), { 0.0f, 0.0f, 0.0f }); + auto endNode = createTestBlendNode(handler, duration); + endNode->setClipResults(animator->peerId(), { 1.0f, 1.0f, 1.0f }); + + const float blendFactor = 0.0f; + auto blendNode = createLerpClipBlendNode(handler, blendFactor); + blendNode->setStartClipId(startNode->peerId()); + blendNode->setEndClipId(endNode->peerId()); + blendNode->setBlendFactor(blendFactor); + + ClipResults expectedResults = { 0.0f, 0.0f, 0.0f }; + + QTest::addRow("unit lerp, beta = 0.0") + << handler << blendNode << animator->peerId() << expectedResults; + } + + { + auto handler = new Handler(); + + const qint64 globalStartTimeNS = 0; + const int loopCount = 1; + auto animator = createBlendedClipAnimator(handler, globalStartTimeNS, loopCount); + + const double duration = 1.0; + auto startNode = createTestBlendNode(handler, duration); + startNode->setClipResults(animator->peerId(), { 0.0f, 0.0f, 0.0f }); + auto endNode = createTestBlendNode(handler, duration); + endNode->setClipResults(animator->peerId(), { 1.0f, 1.0f, 1.0f }); + + const float blendFactor = 0.5f; + auto blendNode = createLerpClipBlendNode(handler, blendFactor); + blendNode->setStartClipId(startNode->peerId()); + blendNode->setEndClipId(endNode->peerId()); + blendNode->setBlendFactor(blendFactor); + + ClipResults expectedResults = { 0.5f, 0.5f, 0.5f }; + + QTest::addRow("unit lerp, beta = 0.5") + << handler << blendNode << animator->peerId() << expectedResults; + } + + { + auto handler = new Handler(); + + const qint64 globalStartTimeNS = 0; + const int loopCount = 1; + auto animator = createBlendedClipAnimator(handler, globalStartTimeNS, loopCount); + + const double duration = 1.0; + auto startNode = createTestBlendNode(handler, duration); + startNode->setClipResults(animator->peerId(), { 0.0f, 0.0f, 0.0f }); + auto endNode = createTestBlendNode(handler, duration); + endNode->setClipResults(animator->peerId(), { 1.0f, 1.0f, 1.0f }); + + const float blendFactor = 1.0f; + auto blendNode = createLerpClipBlendNode(handler, blendFactor); + blendNode->setStartClipId(startNode->peerId()); + blendNode->setEndClipId(endNode->peerId()); + blendNode->setBlendFactor(blendFactor); + + ClipResults expectedResults = { 1.0f, 1.0f, 1.0f }; + + QTest::addRow("unit lerp, beta = 1.0") + << handler << blendNode << animator->peerId() << expectedResults; + } + + { + auto handler = new Handler(); + + const qint64 globalStartTimeNS = 0; + const int loopCount = 1; + auto animator = createBlendedClipAnimator(handler, globalStartTimeNS, loopCount); + + const double duration = 1.0; + auto startNode = createTestBlendNode(handler, duration); + startNode->setClipResults(animator->peerId(), { 0.0f, 1.0f, 2.0f }); + auto endNode = createTestBlendNode(handler, duration); + endNode->setClipResults(animator->peerId(), { 1.0f, 2.0f, 3.0f }); + + const float blendFactor = 0.5f; + auto blendNode = createLerpClipBlendNode(handler, blendFactor); + blendNode->setStartClipId(startNode->peerId()); + blendNode->setEndClipId(endNode->peerId()); + blendNode->setBlendFactor(blendFactor); + + ClipResults expectedResults = { 0.5f, 1.5f, 2.5f }; + + QTest::addRow("lerp varying data, beta = 0.5") + << handler << blendNode << animator->peerId() << expectedResults; + } + + { + auto handler = new Handler(); + + const qint64 globalStartTimeNS = 0; + const int loopCount = 1; + auto animator = createBlendedClipAnimator(handler, globalStartTimeNS, loopCount); + + const double duration = 1.0; + const int dataCount = 1000; + ClipResults startData(dataCount); + ClipResults endData(dataCount); + ClipResults expectedResults(dataCount); + for (int i = 0; i < dataCount; ++i) { + startData[i] = float(i); + endData[i] = 2.0f * float(i); + expectedResults[i] = 1.5f * float(i); + } + auto startNode = createTestBlendNode(handler, duration); + startNode->setClipResults(animator->peerId(), startData); + auto endNode = createTestBlendNode(handler, duration); + endNode->setClipResults(animator->peerId(), endData); + + const float blendFactor = 0.5f; + auto blendNode = createLerpClipBlendNode(handler, blendFactor); + blendNode->setStartClipId(startNode->peerId()); + blendNode->setEndClipId(endNode->peerId()); + blendNode->setBlendFactor(blendFactor); + + QTest::addRow("lerp lots of data, beta = 0.5") + << handler << blendNode << animator->peerId() << expectedResults; + } + } + + void checkDoBlend() + { + // GIVEN + QFETCH(Handler *, handler); + QFETCH(LerpClipBlend *, blendNode); + QFETCH(Qt3DCore::QNodeId, animatorId); + QFETCH(ClipResults, expectedResults); + + // WHEN + blendNode->performBlend(animatorId); + + // THEN + const ClipResults actualResults = blendNode->clipResults(animatorId); + QCOMPARE(actualResults.size(), expectedResults.size()); + for (int i = 0; i < actualResults.size(); ++i) + QCOMPARE(actualResults[i], expectedResults[i]); + + // Cleanup + delete handler; + } }; QTEST_MAIN(tst_LerpClipBlend) -- cgit v1.2.3 From 8a5f83749373f5f3dc3490563ee437253ba59414 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Thu, 16 Mar 2017 16:59:51 +0000 Subject: Add function to evaluate a blend tree Turns out with this design, evaluating the blend tree is actually really simple. Visit the tree nodes and call blend on the interior nodes. The leaf nodes will already have their values from an earlier stage. This also makes apparent yet another opportunity for parallelism during the blend tree evaluation. The blend tree may contain independent subtrees that can safely be evaluated in parallel. Once we have the ability for jobs to spawn jobs there are at least 3 ways we can have parallelism in the blend tree evaluation: 1) Each blended clip animator can be processed in its own job. 2) Sub trees of the blend tree can be evaluated in parallel, relying upon dependencies between jobs to do this properly. 3) Within each node's doBlend() there is potential to use a parallel implementation of the map operation like parallel_for in TBB. There are also other opportunities in earlier stages of processing such as when evaluating the actual clips, we then need a gather operation to map the clip results into the layout used by the blend tree. This evaluations could be done in parallel as well as a parallel gather (which is just a map with a random access read operation). This all bodes well for being able to process large numbers of animations each containing large numbers of channels which will be needed when we add support for skeletons. Change-Id: Id81e3a5e563a7ef9b7ac39b90c518c656cf8a3cf Reviewed-by: Paul Lemire Reviewed-by: Mike Krus --- .../animationutils/tst_animationutils.cpp | 335 +++++++++++++++++++++ 1 file changed, 335 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 80d9a4d53..dcdbafdae 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -29,10 +29,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -56,6 +58,53 @@ Q_DECLARE_METATYPE(Channel) Q_DECLARE_METATYPE(AnimatorEvaluationData) Q_DECLARE_METATYPE(ClipEvaluationData) Q_DECLARE_METATYPE(ClipAnimator *) +Q_DECLARE_METATYPE(BlendedClipAnimator *) + +namespace { + +class MeanBlendNode : public ClipBlendNode +{ +public: + MeanBlendNode() + : ClipBlendNode(ClipBlendNode::LerpBlendType) + {} + + float blend(float, float ) const Q_DECL_FINAL { return 0.0f; } + + + void setValueNodeIds(Qt3DCore::QNodeId value1Id, + Qt3DCore::QNodeId value2Id) + { + m_value1Id = value1Id; + m_value2Id = value2Id; + } + + QVector dependencyIds() const Q_DECL_FINAL + { + return QVector() << m_value1Id << m_value2Id; + } + + using ClipBlendNode::setClipResults; + + double duration() const Q_DECL_FINAL { return 0.0f; } + +protected: + ClipResults doBlend(const QVector &blendData) const Q_DECL_FINAL + { + Q_ASSERT(blendData.size() == 2); + const int elementCount = blendData.first().size(); + ClipResults blendResults(elementCount); + + for (int i = 0; i < elementCount; ++i) + blendResults[i] = 0.5f * (blendData[0][i] + blendData[1][i]); + + return blendResults; + } + +private: + Qt3DCore::QNodeId m_value1Id; + Qt3DCore::QNodeId m_value2Id; +}; bool fuzzyCompare(float x1, float x2) { @@ -69,6 +118,9 @@ bool fuzzyCompare(float x1, float x2) } } +} // anonymous + + class tst_AnimationUtils : public Qt3DCore::QBackendNodeTester { Q_OBJECT @@ -125,6 +177,18 @@ public: return animator; } + BlendedClipAnimator *createBlendedClipAnimator(Handler *handler, + qint64 globalStartTimeNS, + int loops) + { + auto animatorId = Qt3DCore::QNodeId::createId(); + BlendedClipAnimator *animator = handler->blendedClipAnimatorManager()->getOrCreateResource(animatorId); + setPeerId(animator, animatorId); + animator->setStartTime(globalStartTimeNS); + animator->setLoops(loops); + return animator; + } + LerpClipBlend *createLerpClipBlend(Handler *handler) { auto lerpId = Qt3DCore::QNodeId::createId(); @@ -136,6 +200,17 @@ public: return lerp; } + AdditiveClipBlend *createAdditiveClipBlend(Handler *handler) + { + auto additiveId = Qt3DCore::QNodeId::createId(); + AdditiveClipBlend *additive = new AdditiveClipBlend(); + setPeerId(additive, additiveId); + additive->setClipBlendNodeManager(handler->clipBlendNodeManager()); + additive->setHandler(handler); + handler->clipBlendNodeManager()->appendNode(additiveId, additive); + return additive; + } + ClipBlendValue *createClipBlendValue(Handler *handler) { auto valueId = Qt3DCore::QNodeId::createId(); @@ -147,6 +222,17 @@ public: return value; } + MeanBlendNode *createMeanBlendNode(Handler *handler) + { + auto id = Qt3DCore::QNodeId::createId(); + MeanBlendNode *node = new MeanBlendNode(); + setPeerId(node, id); + node->setClipBlendNodeManager(handler->clipBlendNodeManager()); + node->setHandler(handler); + handler->clipBlendNodeManager()->appendNode(id, node); + return node; + } + private Q_SLOTS: void checkBuildPropertyMappings_data() { @@ -1550,6 +1636,255 @@ private Q_SLOTS: // Cleanup delete handler; } + + void checkEvaluateBlendTree_data() + { + QTest::addColumn("handler"); + QTest::addColumn("animator"); + QTest::addColumn("blendNodeId"); + QTest::addColumn("expectedResults"); + + { + /* + ValueNode1---- + | + MeanBlendNode + | + ValueNode2---- + */ + + auto handler = new Handler(); + const qint64 globalStartTimeNS = 0; + const int loopCount = 1; + auto animator = createBlendedClipAnimator(handler, globalStartTimeNS, loopCount); + + // Set up the blend node and dependencies (evaluated clip results of the + // dependent nodes in the animator indexed by their ids). + MeanBlendNode *blendNode = createMeanBlendNode(handler); + + // First clip to use in the mean + auto valueNode1 = createClipBlendValue(handler); + ClipResults valueNode1Results = { 0.0f, 0.0f, 0.0f }; + valueNode1->setClipResults(animator->peerId(), valueNode1Results); + + // Second clip to use in the mean + auto valueNode2 = createClipBlendValue(handler); + ClipResults valueNode2Results = { 1.0f, 1.0f, 1.0f }; + valueNode2->setClipResults(animator->peerId(), valueNode2Results); + + blendNode->setValueNodeIds(valueNode1->peerId(), valueNode2->peerId()); + + ClipResults expectedResults = { 0.5f, 0.5f, 0.5f }; + + QTest::newRow("mean node, 1 channel") + << handler << animator << blendNode->peerId() << expectedResults; + } + + { + /* + ValueNode1---- + | + MeanBlendNode + | + ValueNode2---- + */ + + auto handler = new Handler(); + const qint64 globalStartTimeNS = 0; + const int loopCount = 1; + auto animator = createBlendedClipAnimator(handler, globalStartTimeNS, loopCount); + + // Set up the blend node and dependencies (evaluated clip results of the + // dependent nodes in the animator indexed by their ids). + MeanBlendNode *blendNode = createMeanBlendNode(handler); + + // First clip to use in the mean + auto valueNode1 = createClipBlendValue(handler); + ClipResults valueNode1Results = { 0.0f, 0.0f, 0.0f, 1.0f, 2.0f, 3.0f }; + valueNode1->setClipResults(animator->peerId(), valueNode1Results); + + // Second clip to use in the mean + auto valueNode2 = createClipBlendValue(handler); + ClipResults valueNode2Results = { 1.0f, 1.0f, 1.0f, 2.0f, 4.0f, 6.0f }; + valueNode2->setClipResults(animator->peerId(), valueNode2Results); + + blendNode->setValueNodeIds(valueNode1->peerId(), valueNode2->peerId()); + + ClipResults expectedResults = { 0.5f, 0.5f, 0.5f, 1.5f, 3.0f, 4.5f }; + + QTest::newRow("mean node, 2 channels") + << handler << animator << blendNode->peerId() << expectedResults; + } + + { + /* + ValueNode1---- + | + MeanBlendNode1------ + | | + ValueNode2---- | + MeanBlendNode3 + ValueNode3---- | + | | + MeanBlendNode2------ + | + ValueNode4---- + */ + + auto handler = new Handler(); + const qint64 globalStartTimeNS = 0; + const int loopCount = 1; + auto animator = createBlendedClipAnimator(handler, globalStartTimeNS, loopCount); + + // Set up the blend node and dependencies (evaluated clip results of the + // dependent nodes in the animator indexed by their ids). + + // MeanBlendNode1 + MeanBlendNode *meanNode1 = createMeanBlendNode(handler); + + // First clip to use in mean1 + auto valueNode1 = createClipBlendValue(handler); + ClipResults valueNode1Results = { 0.0f, 0.0f, 0.0f }; + valueNode1->setClipResults(animator->peerId(), valueNode1Results); + + // Second clip to use in mean1 + auto valueNode2 = createClipBlendValue(handler); + ClipResults valueNode2Results = { 2.0f, 2.0f, 2.0f }; + valueNode2->setClipResults(animator->peerId(), valueNode2Results); + + meanNode1->setValueNodeIds(valueNode1->peerId(), valueNode2->peerId()); + + + // MeanBlendNode2 + MeanBlendNode *meanNode2 = createMeanBlendNode(handler); + + // First clip to use in mean1 + auto valueNode3 = createClipBlendValue(handler); + ClipResults valueNode3Results = { 10.0f, 10.0f, 10.0f }; + valueNode3->setClipResults(animator->peerId(), valueNode3Results); + + // Second clip to use in mean1 + auto valueNode4 = createClipBlendValue(handler); + ClipResults valueNode4Results = { 20.0f, 20.0f, 20.0f }; + valueNode4->setClipResults(animator->peerId(), valueNode4Results); + + meanNode2->setValueNodeIds(valueNode3->peerId(), valueNode4->peerId()); + + + // MeanBlendNode3 + MeanBlendNode *meanNode3 = createMeanBlendNode(handler); + meanNode3->setValueNodeIds(meanNode1->peerId(), meanNode2->peerId()); + + // Mean1 = 1 + // Mean2 = 15 + // Mean3 = (1 + 15 ) / 2 = 8 + ClipResults expectedResults = { 8.0f, 8.0f, 8.0f }; + + QTest::newRow("3 mean nodes, 1 channel") + << handler << animator << meanNode3->peerId() << expectedResults; + } + + { + /* + ValueNode1---- + | + MeanBlendNode1------ + | | + ValueNode2---- | + MeanBlendNode3--- + ValueNode3---- | | + | | | + MeanBlendNode2------ AdditiveBlendNode1 + | | + ValueNode4---- | + ValueNode5------- + */ + + auto handler = new Handler(); + const qint64 globalStartTimeNS = 0; + const int loopCount = 1; + auto animator = createBlendedClipAnimator(handler, globalStartTimeNS, loopCount); + + // Set up the blend node and dependencies (evaluated clip results of the + // dependent nodes in the animator indexed by their ids). + + // MeanBlendNode1 + MeanBlendNode *meanNode1 = createMeanBlendNode(handler); + + // First clip to use in mean1 + auto valueNode1 = createClipBlendValue(handler); + ClipResults valueNode1Results = { 0.0f, 0.0f, 0.0f }; + valueNode1->setClipResults(animator->peerId(), valueNode1Results); + + // Second clip to use in mean1 + auto valueNode2 = createClipBlendValue(handler); + ClipResults valueNode2Results = { 2.0f, 2.0f, 2.0f }; + valueNode2->setClipResults(animator->peerId(), valueNode2Results); + + meanNode1->setValueNodeIds(valueNode1->peerId(), valueNode2->peerId()); + + + // MeanBlendNode2 + MeanBlendNode *meanNode2 = createMeanBlendNode(handler); + + // First clip to use in mean2 + auto valueNode3 = createClipBlendValue(handler); + ClipResults valueNode3Results = { 10.0f, 10.0f, 10.0f }; + valueNode3->setClipResults(animator->peerId(), valueNode3Results); + + // Second clip to use in mean2 + auto valueNode4 = createClipBlendValue(handler); + ClipResults valueNode4Results = { 20.0f, 20.0f, 20.0f }; + valueNode4->setClipResults(animator->peerId(), valueNode4Results); + + meanNode2->setValueNodeIds(valueNode3->peerId(), valueNode4->peerId()); + + + // MeanBlendNode3 + MeanBlendNode *meanNode3 = createMeanBlendNode(handler); + meanNode3->setValueNodeIds(meanNode1->peerId(), meanNode2->peerId()); + + + // AdditiveBlendNode1 + AdditiveClipBlend *additiveBlendNode1 = createAdditiveClipBlend(handler); + auto valueNode5 = createClipBlendValue(handler); + ClipResults valueNode5Results = { 1.0f, 2.0f, 3.0f }; + valueNode5->setClipResults(animator->peerId(), valueNode5Results); + + additiveBlendNode1->setBaseClipId(meanNode3->peerId()); + additiveBlendNode1->setAdditiveClipId(valueNode5->peerId()); + additiveBlendNode1->setAdditiveFactor(0.5); + + // Mean1 = 1 + // Mean2 = 15 + // Mean3 = (1 + 15 ) / 2 = 8 + // Additive1 = 8 + 0.5 * (1, 2, 3) = (8.5, 9, 9.5) + ClipResults expectedResults = { 8.5f, 9.0f, 9.5f }; + + QTest::newRow("3 mean nodes + additive, 1 channel") + << handler << animator << additiveBlendNode1->peerId() << expectedResults; + } + } + + void checkEvaluateBlendTree() + { + // GIVEN + QFETCH(Handler *, handler); + QFETCH(BlendedClipAnimator *, animator); + QFETCH(Qt3DCore::QNodeId, blendNodeId); + QFETCH(ClipResults, expectedResults); + + // WHEN + const ClipResults actualResults = evaluateBlendTree(handler, animator, blendNodeId); + + // THEN + QCOMPARE(actualResults.size(), expectedResults.size()); + for (int i = 0; i < actualResults.size(); ++i) + QCOMPARE(actualResults[i], expectedResults[i]); + + // Cleanup + delete handler; + } }; QTEST_MAIN(tst_AnimationUtils) -- cgit v1.2.3 From 982ea29558d6374067eb6cc0505b709eb9ecdae3 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Sat, 18 Mar 2017 15:07:11 +0000 Subject: Add methods to set and retrieve format indices for a blend value node In order to have a consistent data layout for all interior nodes of a blend tree, we need a place to convert from whatever data layout a clip produces when evaluated to the format used by the blend tree. We will do this by creating for each value leaf node a vector of indices that can be used to map from the ClipResults layout output by the clip to the ClipResults format used by the blend tree. With this approach, we can do the following: * Evaluate each leaf node in the blend tree * Perform a gather operation using these format indices to reorder the data into a consistent layout for the whole blend tree * Evaluate the blend tree using this consistent layout This completely avoids having to perform complex mappings when evaluating each blend node, which is a significant saving in overhead and allows for more parallellism in the future. Change-Id: Ie534534f9555842d0d0f1a89fc996e25f5c6ce9e Reviewed-by: Paul Lemire Reviewed-by: Mike Krus --- .../clipblendvalue/tst_clipblendvalue.cpp | 130 +++++++++++++++++++++ 1 file changed, 130 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp index 12eaf1a3c..9266161fc 100644 --- a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp +++ b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp @@ -35,8 +35,13 @@ #include #include "qbackendnodetester.h" +#include +#include + using namespace Qt3DAnimation::Animation; +Q_DECLARE_METATYPE(ClipBlendValue *) + class tst_ClipBlendValue : public Qt3DCore::QBackendNodeTester { Q_OBJECT @@ -162,6 +167,131 @@ private Q_SLOTS: // THEN QCOMPARE(actualDuration, expectedDuration); } + + void checkFormatIndices_data() + { + QTest::addColumn("blendNode"); + QTest::addColumn>("indexes"); + QTest::addColumn>("animatorIds"); + QTest::addColumn>("expectedFormatIndices"); + + // Single entry + { + auto blendNode = new ClipBlendValue; + QVector animatorIds; + QVector expectedFormatIndices; + + const auto animatorId = Qt3DCore::QNodeId::createId(); + animatorIds.push_back(animatorId); + + ComponentIndices formatIndices = { 0, 1, 2 }; + expectedFormatIndices.push_back(formatIndices); + + // Set data and indexes + blendNode->setFormatIndices(animatorId, formatIndices); + QVector indexes = QVector() << 0; + + QTest::newRow("single entry") + << blendNode << indexes << animatorIds << expectedFormatIndices; + } + + // No data + { + auto blendNode = new ClipBlendValue; + QVector animatorIds; + QVector expectedFormatIndices; + + auto animatorId = Qt3DCore::QNodeId::createId(); + animatorIds.push_back(animatorId); + + ComponentIndices formatIndices; + expectedFormatIndices.push_back(formatIndices); + + // Don't set any data + QVector indexes = QVector() << 0; + + QTest::newRow("no entries") + << blendNode << indexes << animatorIds << expectedFormatIndices; + } + + // Multiple entries, ordered + { + auto blendNode = new ClipBlendValue; + QVector animatorIds; + QVector expectedFormatIndices; + + const int animatorCount = 10; + for (int j = 0; j < animatorCount; ++j) { + auto animatorId = Qt3DCore::QNodeId::createId(); + animatorIds.push_back(animatorId); + + ComponentIndices formatIndices; + for (int i = 0; i < j + 5; ++i) + formatIndices.push_back(i + j); + expectedFormatIndices.push_back(formatIndices); + + blendNode->setFormatIndices(animatorId, formatIndices); + } + + QVector indexes(animatorCount); + std::iota(indexes.begin(), indexes.end(), 0); + + QTest::newRow("multiple entries, ordered") + << blendNode << indexes << animatorIds << expectedFormatIndices; + } + + // Multiple entries, unordered + { + auto blendNode = new ClipBlendValue; + QVector animatorIds; + QVector expectedFormatIndices; + + const int animatorCount = 10; + for (int j = 0; j < animatorCount; ++j) { + auto animatorId = Qt3DCore::QNodeId::createId(); + animatorIds.push_back(animatorId); + + ComponentIndices formatIndices; + for (int i = 0; i < j + 5; ++i) + formatIndices.push_back(i + j); + expectedFormatIndices.push_back(formatIndices); + + blendNode->setFormatIndices(animatorId, formatIndices); + } + + // Shuffle the animatorIds to randomise the lookups + QVector indexes(animatorCount); + std::iota(indexes.begin(), indexes.end(), 0); + std::random_device rd; + std::mt19937 generator(rd()); + std::shuffle(indexes.begin(), indexes.end(), generator); + + QTest::newRow("multiple entries, unordered") + << blendNode << indexes << animatorIds << expectedFormatIndices; + } + } + + void checkFormatIndices() + { + // GIVEN + QFETCH(ClipBlendValue *, blendNode); + QFETCH(QVector, indexes); + QFETCH(QVector, animatorIds); + QFETCH(QVector, expectedFormatIndices); + + for (int i = 0; i < indexes.size(); ++i) { + // WHEN + const int index = indexes[i]; + const ComponentIndices actualFormatIndices = blendNode->formatIndices(animatorIds[index]); + + // THEN + QCOMPARE(actualFormatIndices.size(), expectedFormatIndices[index].size()); + for (int j = 0; j < actualFormatIndices.size(); ++j) + QCOMPARE(actualFormatIndices[j], expectedFormatIndices[index][j]); + } + + delete blendNode; + } }; QTEST_MAIN(tst_ClipBlendValue) -- cgit v1.2.3 From b18d39153453e6e2cab9e6c75bd2991aa25d0397 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Sat, 18 Mar 2017 15:41:24 +0000 Subject: Add function to format clip results using a gather operation If an index in the format is -1 put a default value of 0 into the formatted results. This will allow clips to not have to provide every channel used anywhere by the blend tree. Change-Id: I9e18d0840e75a959ef680cbd54259a74c9331fa8 Reviewed-by: Paul Lemire --- .../animationutils/tst_animationutils.cpp | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index dcdbafdae..6f0c998e6 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -1885,6 +1885,74 @@ private Q_SLOTS: // Cleanup delete handler; } + + void checkFormatClipResults_data() + { + QTest::addColumn("rawClipResults"); + QTest::addColumn("format"); + QTest::addColumn("expectedResults"); + + { + ClipResults rawClipResults = { 1.0f, 2.0f, 3.0f }; + ComponentIndices format = { 0, 1, 2 }; + ClipResults expectedResults = { 1.0f, 2.0f, 3.0f }; + + QTest::newRow("identity") + << rawClipResults << format << expectedResults; + } + + { + ClipResults rawClipResults = { 1.0f, 2.0f }; + ComponentIndices format = { 1, 0 }; + ClipResults expectedResults = { 2.0f, 1.0f }; + + QTest::newRow("swap") + << rawClipResults << format << expectedResults; + } + + { + ClipResults rawClipResults = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; + ComponentIndices format = { 0, 2, 1, 3, 4 }; + ClipResults expectedResults = { 1.0f, 3.0f, 2.0f, 4.0f, 5.0f }; + + QTest::newRow("swap subset") + << rawClipResults << format << expectedResults; + } + + { + ClipResults rawClipResults = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; + ComponentIndices format = { 4, 3, 2, 1, 0 }; + ClipResults expectedResults = { 5.0f, 4.0f, 3.0f, 2.0f, 1.0f }; + + QTest::newRow("reverse") + << rawClipResults << format << expectedResults; + } + + { + ClipResults rawClipResults = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; + ComponentIndices format = { 0, 1, -1, 3, 4 }; + ClipResults expectedResults = { 1.0f, 2.0f, 0.0f, 4.0f, 5.0f }; + + QTest::newRow("include missing") + << rawClipResults << format << expectedResults; + } + } + + void checkFormatClipResults() + { + // GIVEN + QFETCH(ClipResults, rawClipResults); + QFETCH(ComponentIndices, format); + QFETCH(ClipResults, expectedResults); + + // WHEN + const ClipResults actualResults = formatClipResults(rawClipResults, format); + + // THEN + QCOMPARE(actualResults.size(), expectedResults.size()); + for (int i = 0; i < actualResults.size(); ++i) + QCOMPARE(actualResults[i], expectedResults[i]); + } }; QTEST_MAIN(tst_AnimationUtils) -- cgit v1.2.3 From 1929b3e48c0a327e7a741275d6d4847b72ddf704 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Mon, 20 Mar 2017 13:42:53 +0000 Subject: Add a function to build list of unique channel names and types This will be needed to construct the data layout for blend trees. Change-Id: I0b11076f5ecd55cfad094d864f3f8270841fc62a Reviewed-by: Paul Lemire --- .../animationutils/tst_animationutils.cpp | 126 +++++++++++++++++++++ 1 file changed, 126 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 6f0c998e6..a96f7d2d2 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -59,6 +59,7 @@ Q_DECLARE_METATYPE(AnimatorEvaluationData) Q_DECLARE_METATYPE(ClipEvaluationData) Q_DECLARE_METATYPE(ClipAnimator *) Q_DECLARE_METATYPE(BlendedClipAnimator *) +Q_DECLARE_METATYPE(QVector) namespace { @@ -1953,6 +1954,131 @@ private Q_SLOTS: for (int i = 0; i < actualResults.size(); ++i) QCOMPARE(actualResults[i], expectedResults[i]); } + + void checkBuildRequiredChannelsAndTypes_data() + { + QTest::addColumn("handler"); + QTest::addColumn("mapper"); + QTest::addColumn>("expectedResults"); + + { + auto handler = new Handler(); + auto channelMapping = createChannelMapping(handler, + QLatin1String("Location"), + Qt3DCore::QNodeId::createId(), + QLatin1String("translation"), + "translation", + static_cast(QVariant::Vector3D)); + QVector channelMappings; + channelMappings.push_back(channelMapping); + + auto channelMapper = createChannelMapper(handler, + QVector() << channelMapping->peerId()); + + QVector expectedResults; + expectedResults.push_back({ QLatin1String("Location"), static_cast(QVariant::Vector3D) }); + + QTest::addRow("Location, vec3") << handler << channelMapper << expectedResults; + } + + { + auto handler = new Handler(); + auto channelMapping1 = createChannelMapping(handler, + QLatin1String("Location"), + Qt3DCore::QNodeId::createId(), + QLatin1String("translation"), + "translation", + static_cast(QVariant::Vector3D)); + auto channelMapping2 = createChannelMapping(handler, + QLatin1String("Rotation"), + Qt3DCore::QNodeId::createId(), + QLatin1String("rotatrion"), + "rotation", + static_cast(QVariant::Quaternion)); + QVector channelMappings; + channelMappings.push_back(channelMapping1); + channelMappings.push_back(channelMapping2); + + QVector channelMappingIds + = (QVector() + << channelMapping1->peerId() + << channelMapping2->peerId()); + auto channelMapper = createChannelMapper(handler, channelMappingIds); + + QVector expectedResults; + expectedResults.push_back({ QLatin1String("Location"), static_cast(QVariant::Vector3D) }); + expectedResults.push_back({ QLatin1String("Rotation"), static_cast(QVariant::Quaternion) }); + + QTest::addRow("Multiple unique channels") << handler << channelMapper << expectedResults; + } + + { + auto handler = new Handler(); + auto channelMapping1 = createChannelMapping(handler, + QLatin1String("Location"), + Qt3DCore::QNodeId::createId(), + QLatin1String("translation"), + "translation", + static_cast(QVariant::Vector3D)); + auto channelMapping2 = createChannelMapping(handler, + QLatin1String("Rotation"), + Qt3DCore::QNodeId::createId(), + QLatin1String("rotation"), + "rotation", + static_cast(QVariant::Quaternion)); + auto channelMapping3 = createChannelMapping(handler, + QLatin1String("Location"), + Qt3DCore::QNodeId::createId(), + QLatin1String("translation"), + "translation", + static_cast(QVariant::Vector3D)); + auto channelMapping4 = createChannelMapping(handler, + QLatin1String("Location"), + Qt3DCore::QNodeId::createId(), + QLatin1String("translation"), + "translation", + static_cast(QVariant::Vector3D)); + + QVector channelMappings; + channelMappings.push_back(channelMapping1); + channelMappings.push_back(channelMapping2); + channelMappings.push_back(channelMapping3); + channelMappings.push_back(channelMapping4); + + QVector channelMappingIds + = (QVector() + << channelMapping1->peerId() + << channelMapping2->peerId() + << channelMapping3->peerId() + << channelMapping4->peerId()); + auto channelMapper = createChannelMapper(handler, channelMappingIds); + + QVector expectedResults; + expectedResults.push_back({ QLatin1String("Location"), static_cast(QVariant::Vector3D) }); + expectedResults.push_back({ QLatin1String("Rotation"), static_cast(QVariant::Quaternion) }); + + QTest::addRow("Multiple channels with repeats") << handler << channelMapper << expectedResults; + } + } + + void checkBuildRequiredChannelsAndTypes() + { + // GIVEN + QFETCH(Handler *, handler); + QFETCH(ChannelMapper *, mapper); + QFETCH(QVector, expectedResults); + + // WHEN + const QVector actualResults = buildRequiredChannelsAndTypes(handler, mapper); + + // THEN + QCOMPARE(actualResults.size(), expectedResults.size()); + for (int i = 0; i < actualResults.size(); ++i) + QCOMPARE(actualResults[i], expectedResults[i]); + + // Cleanup + delete handler; + } }; QTEST_MAIN(tst_AnimationUtils) -- cgit v1.2.3 From 6af77603f97cf4f4dc68b3f18e89e930d547afdc Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Mon, 20 Mar 2017 15:13:49 +0000 Subject: Add function assignChannelComponentIndices This iterates through the channel description and assigns channel component indices in ascending order. The next step will be to use this in conjunction with the channel description with the layout of channels in each clip to generate the format indices that will allow us to quickly map from the clip's raw ClipResults to ClipResults formatted in the layotu used by the blend tree/animator. Change-Id: I04dd5a21ca8355529118cfb2b05f4904e43ef0e2 Reviewed-by: Paul Lemire --- .../animationutils/tst_animationutils.cpp | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index a96f7d2d2..0d758d3d3 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -2079,6 +2079,72 @@ private Q_SLOTS: // Cleanup delete handler; } + + void checkAssignChannelComponentIndices_data() + { + QTest::addColumn>("allChannels"); + QTest::addColumn>("expectedResults"); + + { + QVector allChannels; + allChannels.push_back({ QLatin1String("Location"), static_cast(QVariant::Vector3D) }); + + QVector expectedResults; + expectedResults.push_back({ 0, 1, 2 }); + + QTest::newRow("vec3 location") << allChannels << expectedResults; + } + + { + QVector allChannels; + allChannels.push_back({ QLatin1String("Location"), static_cast(QVariant::Vector3D) }); + allChannels.push_back({ QLatin1String("Rotation"), static_cast(QVariant::Quaternion) }); + + QVector expectedResults; + expectedResults.push_back({ 0, 1, 2 }); + expectedResults.push_back({ 3, 4, 5, 6 }); + + QTest::newRow("vec3 location, quaterion rotation") << allChannels << expectedResults; + } + + { + QVector allChannels; + allChannels.push_back({ QLatin1String("Location"), static_cast(QVariant::Vector3D) }); + allChannels.push_back({ QLatin1String("Rotation"), static_cast(QVariant::Quaternion) }); + allChannels.push_back({ QLatin1String("BaseColor"), static_cast(QVariant::Vector3D) }); + allChannels.push_back({ QLatin1String("Metalness"), static_cast(QVariant::Double) }); + allChannels.push_back({ QLatin1String("Roughness"), static_cast(QVariant::Double) }); + + QVector expectedResults; + expectedResults.push_back({ 0, 1, 2 }); + expectedResults.push_back({ 3, 4, 5, 6 }); + expectedResults.push_back({ 7, 8, 9 }); + expectedResults.push_back({ 10 }); + expectedResults.push_back({ 11 }); + + QTest::newRow("vec3 location, quaterion rotation, pbr metal-rough") << allChannels << expectedResults; + } + } + + void checkAssignChannelComponentIndices() + { + // GIVEN + QFETCH(QVector, allChannels); + QFETCH(QVector, expectedResults); + + // WHEN + const QVector actualResults = assignChannelComponentIndices(allChannels); + + // THEN + QCOMPARE(actualResults.size(), expectedResults.size()); + for (int i = 0; i < actualResults.size(); ++i) { + const ComponentIndices &actualResult = actualResults[i]; + const ComponentIndices &expectedResult = expectedResults[i]; + + for (int j = 0; j < actualResult.size(); ++j) + QCOMPARE(actualResult[j], expectedResult[j]); + } + } }; QTEST_MAIN(tst_AnimationUtils) -- cgit v1.2.3 From 37fd551490035a2004e4151857b2f7fd35078b97 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Tue, 21 Mar 2017 14:30:08 +0000 Subject: Add function to generate component indices for blend tree format This generates the format indices required by the formatClipResults() function which performs the gather to reorder the raw results from an animation clip to the format used by the blend tree/animator. Change-Id: I5cd8fbe366792ae9d8317f098699c413450b9b87 Reviewed-by: Mike Krus --- .../animation/animationutils/animationutils.qrc | 1 + tests/auto/animation/animationutils/clip3.json | 430 +++++++++++++++++++++ .../animationutils/tst_animationutils.cpp | 146 +++++++ 3 files changed, 577 insertions(+) create mode 100644 tests/auto/animation/animationutils/clip3.json (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/animationutils.qrc b/tests/auto/animation/animationutils/animationutils.qrc index aeb8112f3..bbcd96524 100644 --- a/tests/auto/animation/animationutils/animationutils.qrc +++ b/tests/auto/animation/animationutils/animationutils.qrc @@ -2,5 +2,6 @@ clip1.json clip2.json + clip3.json diff --git a/tests/auto/animation/animationutils/clip3.json b/tests/auto/animation/animationutils/clip3.json new file mode 100644 index 000000000..ae390590e --- /dev/null +++ b/tests/auto/animation/animationutils/clip3.json @@ -0,0 +1,430 @@ +{ + "animations": [ + { + "animationName": "CubeAction", + "channels": [ + { + "channelComponents": [ + { + "channelComponentName": "Rotation W", + "keyFrames": [ + { + "coords": [ + 0.0, + 1.0 + ], + "leftHandle": [ + -0.9597616195678711, + 1.0 + ], + "rightHandle": [ + 0.9597616195678711, + 1.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + -4.371138828673793e-08 + ], + "leftHandle": [ + 1.4985717137654622, + -4.371138828673793e-08 + ], + "rightHandle": [ + 3.4180949529012046, + -4.371138828673793e-08 + ] + } + ] + }, + { + "channelComponentName": "Rotation X", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 0.0 + ], + "leftHandle": [ + 1.4985717137654622, + 0.0 + ], + "rightHandle": [ + 3.4180949529012046, + 0.0 + ] + } + ] + }, + { + "channelComponentName": "Rotation Z", + "keyFrames": [ + { + "coords": [ + 0.0, + -0.0 + ], + "leftHandle": [ + -0.9597616195678711, + -0.0 + ], + "rightHandle": [ + 0.9597616195678711, + -0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + -1.0 + ], + "leftHandle": [ + 1.4985717137654622, + -1.0 + ], + "rightHandle": [ + 3.4180949529012046, + -1.0 + ] + } + ] + }, + { + "channelComponentName": "Rotation Y", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 0.0 + ], + "leftHandle": [ + 1.4985717137654622, + 0.0 + ], + "rightHandle": [ + 3.4180949529012046, + 0.0 + ] + } + ] + } + ], + "channelName": "Rotation" + }, + { + "channelComponents": [ + { + "channelComponentName": "Location X", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 5.0 + ], + "leftHandle": [ + 1.4985717137654622, + 5.0 + ], + "rightHandle": [ + 3.4180949529012046, + 5.0 + ] + } + ] + }, + { + "channelComponentName": "Location Z", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 0.0 + ], + "leftHandle": [ + 1.4985717137654622, + 0.0 + ], + "rightHandle": [ + 3.4180949529012046, + 0.0 + ] + } + ] + }, + { + "channelComponentName": "Location Y", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 0.0 + ], + "leftHandle": [ + 1.4985717137654622, + 0.0 + ], + "rightHandle": [ + 3.4180949529012046, + 0.0 + ] + } + ] + } + ], + "channelName": "Location" + }, + { + "channelComponents": [ + { + "channelComponentName": "Base Color X", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 5.0 + ], + "leftHandle": [ + 1.4985717137654622, + 5.0 + ], + "rightHandle": [ + 3.4180949529012046, + 5.0 + ] + } + ] + }, + { + "channelComponentName": "Base Color Y", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 0.0 + ], + "leftHandle": [ + 1.4985717137654622, + 0.0 + ], + "rightHandle": [ + 3.4180949529012046, + 0.0 + ] + } + ] + }, + { + "channelComponentName": "Base Color Z", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 0.0 + ], + "leftHandle": [ + 1.4985717137654622, + 0.0 + ], + "rightHandle": [ + 3.4180949529012046, + 0.0 + ] + } + ] + } + ], + "channelName": "Base Color" + }, + { + "channelComponents": [ + { + "channelComponentName": "Metalness X", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 5.0 + ], + "leftHandle": [ + 1.4985717137654622, + 5.0 + ], + "rightHandle": [ + 3.4180949529012046, + 5.0 + ] + } + ] + } + ], + "channelName": "Metalness" + }, + { + "channelComponents": [ + { + "channelComponentName": "Roughness X", + "keyFrames": [ + { + "coords": [ + 0.0, + 0.0 + ], + "leftHandle": [ + -0.9597616195678711, + 0.0 + ], + "rightHandle": [ + 0.9597616195678711, + 0.0 + ] + }, + { + "coords": [ + 2.4583333333333335, + 5.0 + ], + "leftHandle": [ + 1.4985717137654622, + 5.0 + ], + "rightHandle": [ + 3.4180949529012046, + 5.0 + ] + } + ] + } + ], + "channelName": "Roughness" + } + ] + } + ] +} diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 0d758d3d3..e1f8adb0c 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -2145,6 +2145,152 @@ private Q_SLOTS: QCOMPARE(actualResult[j], expectedResult[j]); } } + + void checkGenerateClipFormatIndices_data() + { + QTest::addColumn>("targetChannels"); + QTest::addColumn>("targetIndices"); + QTest::addColumn("clip"); + QTest::addColumn("expectedResults"); + + { + QVector targetChannels; + targetChannels.push_back({ QLatin1String("Rotation"), static_cast(QVariant::Quaternion) }); + targetChannels.push_back({ QLatin1String("Location"), static_cast(QVariant::Vector3D) }); + targetChannels.push_back({ QLatin1String("Base Color"), static_cast(QVariant::Vector3D) }); + targetChannels.push_back({ QLatin1String("Metalness"), static_cast(QVariant::Double) }); + targetChannels.push_back({ QLatin1String("Roughness"), static_cast(QVariant::Double) }); + + QVector targetIndices; + targetIndices.push_back({ 0, 1, 2, 3 }); + targetIndices.push_back({ 4, 5, 6 }); + targetIndices.push_back({ 7, 8, 9 }); + targetIndices.push_back({ 10 }); + targetIndices.push_back({ 11 }); + + auto *clip = new AnimationClipLoader(); + clip->setSource(QUrl("qrc:/clip3.json")); + clip->loadAnimation(); + + ComponentIndices expectedResults = { 0, 1, 2, 3, // Rotation + 4, 5, 6, // Location + 7, 8, 9, // Base Color + 10, // Metalness + 11 }; // Roughness + + QTest::newRow("rotation, location, pbr metal-rough") + << targetChannels << targetIndices << clip << expectedResults; + } + + { + QVector targetChannels; + targetChannels.push_back({ QLatin1String("Location"), static_cast(QVariant::Vector3D) }); + targetChannels.push_back({ QLatin1String("Rotation"), static_cast(QVariant::Quaternion) }); + targetChannels.push_back({ QLatin1String("Base Color"), static_cast(QVariant::Vector3D) }); + targetChannels.push_back({ QLatin1String("Metalness"), static_cast(QVariant::Double) }); + targetChannels.push_back({ QLatin1String("Roughness"), static_cast(QVariant::Double) }); + + QVector targetIndices; + targetIndices.push_back({ 0, 1, 2 }); + targetIndices.push_back({ 3, 4, 5, 6 }); + targetIndices.push_back({ 7, 8, 9 }); + targetIndices.push_back({ 10 }); + targetIndices.push_back({ 11 }); + + auto *clip = new AnimationClipLoader(); + clip->setSource(QUrl("qrc:/clip3.json")); + clip->loadAnimation(); + + ComponentIndices expectedResults = { 4, 5, 6, // Location + 0, 1, 2, 3, // Rotation + 7, 8, 9, // Base Color + 10, // Metalness + 11 }; // Roughness + + QTest::newRow("location, rotation, pbr metal-rough") + << targetChannels << targetIndices << clip << expectedResults; + } + + { + QVector targetChannels; + targetChannels.push_back({ QLatin1String("Rotation"), static_cast(QVariant::Quaternion) }); + targetChannels.push_back({ QLatin1String("Location"), static_cast(QVariant::Vector3D) }); + targetChannels.push_back({ QLatin1String("Albedo"), static_cast(QVariant::Vector3D) }); + targetChannels.push_back({ QLatin1String("Metalness"), static_cast(QVariant::Double) }); + targetChannels.push_back({ QLatin1String("Roughness"), static_cast(QVariant::Double) }); + + QVector targetIndices; + targetIndices.push_back({ 0, 1, 2, 3 }); + targetIndices.push_back({ 4, 5, 6 }); + targetIndices.push_back({ 7, 8, 9 }); + targetIndices.push_back({ 10 }); + targetIndices.push_back({ 11 }); + + auto *clip = new AnimationClipLoader(); + clip->setSource(QUrl("qrc:/clip3.json")); + clip->loadAnimation(); + + ComponentIndices expectedResults = { 0, 1, 2, 3, // Rotation + 4, 5, 6, // Location + -1, -1, -1, // Albedo (missing from clip) + 10, // Metalness + 11 }; // Roughness + + QTest::newRow("rotation, location, albedo (missing), metal-rough") + << targetChannels << targetIndices << clip << expectedResults; + } + + { + QVector targetChannels; + targetChannels.push_back({ QLatin1String("Location"), static_cast(QVariant::Vector3D) }); + targetChannels.push_back({ QLatin1String("Rotation"), static_cast(QVariant::Quaternion) }); + targetChannels.push_back({ QLatin1String("Albedo"), static_cast(QVariant::Vector3D) }); + targetChannels.push_back({ QLatin1String("Metalness"), static_cast(QVariant::Double) }); + targetChannels.push_back({ QLatin1String("Roughness"), static_cast(QVariant::Double) }); + + QVector targetIndices; + targetIndices.push_back({ 0, 1, 2 }); + targetIndices.push_back({ 3, 4, 5, 6 }); + targetIndices.push_back({ 7, 8, 9 }); + targetIndices.push_back({ 10 }); + targetIndices.push_back({ 11 }); + + auto *clip = new AnimationClipLoader(); + clip->setSource(QUrl("qrc:/clip3.json")); + clip->loadAnimation(); + + ComponentIndices expectedResults = { 4, 5, 6, // Location + 0, 1, 2, 3, // Rotation + -1, -1, -1, // Albedo (missing from clip) + 10, // Metalness + 11 }; // Roughness + + QTest::newRow("location, rotation, albedo (missing), metal-rough") + << targetChannels << targetIndices << clip << expectedResults; + } + } + + void checkGenerateClipFormatIndices() + { + // GIVEN + QFETCH(QVector, targetChannels); + QFETCH(QVector, targetIndices); + QFETCH(AnimationClipLoader *, clip); + QFETCH(ComponentIndices, expectedResults); + + // WHEN + const ComponentIndices actualResults = generateClipFormatIndices(targetChannels, + targetIndices, + clip); + + // THEN + QCOMPARE(actualResults.size(), expectedResults.size()); + for (int i = 0; i < actualResults.size(); ++i) + QCOMPARE(actualResults[i], expectedResults[i]); + + // Cleanup + delete clip; + } }; QTEST_MAIN(tst_AnimationUtils) -- cgit v1.2.3 From 63aa2898615bffb37a3d9f949b089b2ac2bf2737 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Thu, 23 Mar 2017 12:25:12 +0000 Subject: Add overload of buildPropertyMappings Eventually we should remove the original form which is currently called by the non-blended animation code path. It will be better to merge the blended and non-blended code paths so we have less code to maintain. Also the blended code path seems more efficient. Change-Id: Ib6aa4006e4b830a32b985527bae900ce6f3facec Reviewed-by: Mike Krus --- .../animationutils/tst_animationutils.cpp | 196 +++++++++++++++++++++ 1 file changed, 196 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index e1f8adb0c..0357d07d6 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -306,6 +306,202 @@ private Q_SLOTS: delete handler; } + void checkBuildPropertyMappings2_data() + { + QTest::addColumn>("channelMappings"); + QTest::addColumn>("channelNamesAndTypes"); + QTest::addColumn>("channelComponentIndices"); + QTest::addColumn>("expectedResults"); + + // Single ChannelMapping + { + auto channelMapping = new ChannelMapping(); + channelMapping->setChannelName("Location"); + channelMapping->setTargetId(Qt3DCore::QNodeId::createId()); + channelMapping->setProperty(QLatin1String("translation")); + channelMapping->setPropertyName("translation"); + channelMapping->setType(static_cast(QVariant::Vector3D)); + + QVector channelMappings = { channelMapping }; + + // Create a few channels in the format description + ChannelNameAndType rotation = { QLatin1String("Rotation"), + static_cast(QVariant::Quaternion) }; + ChannelNameAndType location = { QLatin1String("Location"), + static_cast(QVariant::Vector3D) }; + ChannelNameAndType baseColor = { QLatin1String("BaseColor"), + static_cast(QVariant::Vector3D) }; + ChannelNameAndType metalness = { QLatin1String("Metalness"), + static_cast(QVariant::Double) }; + ChannelNameAndType roughness = { QLatin1String("Roughness"), + static_cast(QVariant::Double) }; + QVector channelNamesAndTypes + = { rotation, location, baseColor, metalness, roughness }; + + // And the matching indices + ComponentIndices rotationIndices = { 0, 1, 2, 3 }; + ComponentIndices locationIndices = { 4, 5, 6 }; + ComponentIndices baseColorIndices = { 7, 8, 9 }; + ComponentIndices metalnessIndices = { 10 }; + ComponentIndices roughnessIndices = { 11 }; + QVector channelComponentIndices + = { rotationIndices, locationIndices, baseColorIndices, + metalnessIndices, roughnessIndices }; + + MappingData expectedMapping; + expectedMapping.targetId = channelMapping->targetId(); + expectedMapping.propertyName = channelMapping->propertyName(); + expectedMapping.type = channelMapping->type(); + expectedMapping.channelIndices = locationIndices; + QVector expectedResults = { expectedMapping }; + + QTest::newRow("single mapping") + << channelMappings + << channelNamesAndTypes + << channelComponentIndices + << expectedResults; + } + + // Multiple ChannelMappings + { + auto locationMapping = new ChannelMapping(); + locationMapping->setChannelName("Location"); + locationMapping->setTargetId(Qt3DCore::QNodeId::createId()); + locationMapping->setProperty(QLatin1String("translation")); + locationMapping->setPropertyName("translation"); + locationMapping->setType(static_cast(QVariant::Vector3D)); + + auto metalnessMapping = new ChannelMapping(); + metalnessMapping->setChannelName("Metalness"); + metalnessMapping->setTargetId(Qt3DCore::QNodeId::createId()); + metalnessMapping->setProperty(QLatin1String("metalness")); + metalnessMapping->setPropertyName("metalness"); + metalnessMapping->setType(static_cast(QVariant::Double)); + + auto baseColorMapping = new ChannelMapping(); + baseColorMapping->setChannelName("BaseColor"); + baseColorMapping->setTargetId(Qt3DCore::QNodeId::createId()); + baseColorMapping->setProperty(QLatin1String("baseColor")); + baseColorMapping->setPropertyName("baseColor"); + baseColorMapping->setType(static_cast(QVariant::Vector3D)); + + auto roughnessMapping = new ChannelMapping(); + roughnessMapping->setChannelName("Roughness"); + roughnessMapping->setTargetId(Qt3DCore::QNodeId::createId()); + roughnessMapping->setProperty(QLatin1String("roughness")); + roughnessMapping->setPropertyName("roughness"); + roughnessMapping->setType(static_cast(QVariant::Double)); + + auto rotationMapping = new ChannelMapping(); + rotationMapping->setChannelName("Rotation"); + rotationMapping->setTargetId(Qt3DCore::QNodeId::createId()); + rotationMapping->setProperty(QLatin1String("rotation")); + rotationMapping->setPropertyName("rotation"); + rotationMapping->setType(static_cast(QVariant::Quaternion)); + + QVector channelMappings + = { locationMapping, metalnessMapping, + baseColorMapping, roughnessMapping, + rotationMapping }; + + // Create a few channels in the format description + ChannelNameAndType rotation = { QLatin1String("Rotation"), + static_cast(QVariant::Quaternion) }; + ChannelNameAndType location = { QLatin1String("Location"), + static_cast(QVariant::Vector3D) }; + ChannelNameAndType baseColor = { QLatin1String("BaseColor"), + static_cast(QVariant::Vector3D) }; + ChannelNameAndType metalness = { QLatin1String("Metalness"), + static_cast(QVariant::Double) }; + ChannelNameAndType roughness = { QLatin1String("Roughness"), + static_cast(QVariant::Double) }; + QVector channelNamesAndTypes + = { rotation, location, baseColor, metalness, roughness }; + + // And the matching indices + ComponentIndices rotationIndices = { 0, 1, 2, 3 }; + ComponentIndices locationIndices = { 4, 5, 6 }; + ComponentIndices baseColorIndices = { 7, 8, 9 }; + ComponentIndices metalnessIndices = { 10 }; + ComponentIndices roughnessIndices = { 11 }; + QVector channelComponentIndices + = { rotationIndices, locationIndices, baseColorIndices, + metalnessIndices, roughnessIndices }; + + MappingData expectedLocationMapping; + expectedLocationMapping.targetId = locationMapping->targetId(); + expectedLocationMapping.propertyName = locationMapping->propertyName(); + expectedLocationMapping.type = locationMapping->type(); + expectedLocationMapping.channelIndices = locationIndices; + + MappingData expectedMetalnessMapping; + expectedMetalnessMapping.targetId = metalnessMapping->targetId(); + expectedMetalnessMapping.propertyName = metalnessMapping->propertyName(); + expectedMetalnessMapping.type = metalnessMapping->type(); + expectedMetalnessMapping.channelIndices = metalnessIndices; + + MappingData expectedBaseColorMapping; + expectedBaseColorMapping.targetId = baseColorMapping->targetId(); + expectedBaseColorMapping.propertyName = baseColorMapping->propertyName(); + expectedBaseColorMapping.type = baseColorMapping->type(); + expectedBaseColorMapping.channelIndices = baseColorIndices; + + MappingData expectedRoughnessMapping; + expectedRoughnessMapping.targetId = roughnessMapping->targetId(); + expectedRoughnessMapping.propertyName = roughnessMapping->propertyName(); + expectedRoughnessMapping.type = roughnessMapping->type(); + expectedRoughnessMapping.channelIndices = roughnessIndices; + + MappingData expectedRotationMapping; + expectedRotationMapping.targetId = rotationMapping->targetId(); + expectedRotationMapping.propertyName = rotationMapping->propertyName(); + expectedRotationMapping.type = rotationMapping->type(); + expectedRotationMapping.channelIndices = rotationIndices; + + QVector expectedResults + = { expectedLocationMapping, + expectedMetalnessMapping, + expectedBaseColorMapping, + expectedRoughnessMapping, + expectedRotationMapping }; + + QTest::newRow("multiple mappings") + << channelMappings + << channelNamesAndTypes + << channelComponentIndices + << expectedResults; + } + } + + void checkBuildPropertyMappings2() + { + // GIVEN + QFETCH(QVector, channelMappings); + QFETCH(QVector, channelNamesAndTypes); + QFETCH(QVector, channelComponentIndices); + QFETCH(QVector, expectedResults); + + // WHEN + const QVector actualResults = buildPropertyMappings(channelMappings, + channelNamesAndTypes, + channelComponentIndices); + + // THEN + QCOMPARE(actualResults.size(), expectedResults.size()); + for (int i = 0; i < actualResults.size(); ++i) { + const auto actualMapping = actualResults[i]; + const auto expectedMapping = expectedResults[i]; + + QCOMPARE(actualMapping.targetId, expectedMapping.targetId); + QCOMPARE(actualMapping.propertyName, expectedMapping.propertyName); + QCOMPARE(actualMapping.type, expectedMapping.type); + QCOMPARE(actualMapping.channelIndices.size(), expectedMapping.channelIndices.size()); + for (int j = 0; j < actualMapping.channelIndices.size(); ++j) { + QCOMPARE(actualMapping.channelIndices[j], expectedMapping.channelIndices[j]); + } + } + } + void checkLocalTimeFromGlobalTime_data() { QTest::addColumn("globalTime"); -- cgit v1.2.3 From 9a5139a2b59ac27afa190caa46ba22138f9dfa6c Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 24 Mar 2017 13:21:25 +0000 Subject: Remove clips property from QAbstractClipBlendNode and friends No longer needed as concrete subclasses each provide their own specific APIs for managing clips or sub trees. Change-Id: I8e090bcf18ad9bf0d19e36128d7556aaa6cd6edf Reviewed-by: Sean Harmer --- .../additiveclipblend/tst_additiveclipblend.cpp | 3 - tests/auto/animation/animation.pro | 1 - .../animation/clipblendnode/tst_clipblendnode.cpp | 110 ------------ .../animation/lerpclipblend/tst_lerpclipblend.cpp | 3 - .../qabstractclipblendnode.pro | 11 -- .../tst_qabstractclipblendnode.cpp | 184 --------------------- .../qadditiveclipblend/tst_qadditiveclipblend.cpp | 2 - .../qclipblendvalue/tst_qclipblendvalue.cpp | 2 - .../qlerpclipblend/tst_qlerpclipblend.cpp | 2 - 9 files changed, 318 deletions(-) delete mode 100644 tests/auto/animation/qabstractclipblendnode/qabstractclipblendnode.pro delete mode 100644 tests/auto/animation/qabstractclipblendnode/tst_qabstractclipblendnode.cpp (limited to 'tests/auto') diff --git a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp index 5e25cccb9..cd77425a0 100644 --- a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp +++ b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp @@ -136,7 +136,6 @@ private Q_SLOTS: additiveBlend.setBaseClip(&baseClip); additiveBlend.setAdditiveClip(&additiveClip); additiveBlend.setAdditiveFactor(0.8f); - additiveBlend.addClip(&clip); { // WHEN @@ -149,8 +148,6 @@ private Q_SLOTS: QCOMPARE(backendAdditiveBlend.baseClipId(), baseClip.id()); QCOMPARE(backendAdditiveBlend.additiveClipId(), additiveClip.id()); QCOMPARE(backendAdditiveBlend.additiveFactor(), 0.8f); - QCOMPARE(backendAdditiveBlend.clipIds().size(), 1); - QCOMPARE(backendAdditiveBlend.clipIds().first(), clip.id()); } { // WHEN diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index a608c6cbb..eeb9a70af 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -12,7 +12,6 @@ SUBDIRS += \ qtConfig(private_tests) { SUBDIRS += \ animationcliploader \ - qabstractclipblendnode \ fcurve \ functionrangefinder \ bezierevaluator \ diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp index c214cea58..c945b6f3f 100644 --- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -114,7 +114,6 @@ private Q_SLOTS: // THEN QCOMPARE(backendClipBlendNode.isEnabled(), false); QVERIFY(backendClipBlendNode.peerId().isNull()); - QCOMPARE(backendClipBlendNode.clipIds(), Qt3DCore::QNodeIdVector()); QCOMPARE(backendClipBlendNode.parentId(), Qt3DCore::QNodeId()); QCOMPARE(backendClipBlendNode.childrenIds(), Qt3DCore::QNodeIdVector()); QVERIFY(backendClipBlendNode.clipBlendNodeManager() == nullptr); @@ -127,7 +126,6 @@ private Q_SLOTS: // GIVEN Qt3DAnimation::QLerpClipBlend clipBlendNode; Qt3DAnimation::QAnimationClipLoader clip; - clipBlendNode.addClip(&clip); QCoreApplication::processEvents(); @@ -141,8 +139,6 @@ private Q_SLOTS: // THEN QCOMPARE(backendClipBlendNode.isEnabled(), true); QCOMPARE(backendClipBlendNode.peerId(), clipBlendNode.id()); - QCOMPARE(backendClipBlendNode.clipIds().size(), 1); - QCOMPARE(backendClipBlendNode.clipIds().first(), clip.id()); QCOMPARE(backendClipBlendNode.parentId(), Qt3DCore::QNodeId()); QCOMPARE(backendClipBlendNode.childrenIds().size(), 0); QCOMPARE(backendClipBlendNode.clipBlendNodeManager(), &manager); @@ -163,112 +159,6 @@ private Q_SLOTS: } } - void checkSceneChangeEvents() - { - // GIVEN - TestClipBlendNode backendClipBlendNode; - ClipBlendNodeManager manager; - backendClipBlendNode.setClipBlendNodeManager(&manager); - { - // WHEN - const bool newValue = false; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("enabled"); - change->setValue(newValue); - backendClipBlendNode.sceneChangeEvent(change); - - // THEN - QCOMPARE(backendClipBlendNode.isEnabled(), newValue); - } - { - // WHEN - Qt3DAnimation::QAnimationClipLoader clip; - // To geneate the type_info in the QNodePrivate of clip - Qt3DCore::QNodeCreatedChangeGenerator generator(&clip); - - const auto addedChange = Qt3DCore::QPropertyNodeAddedChangePtr::create(Qt3DCore::QNodeId(), &clip); - backendClipBlendNode.sceneChangeEvent(addedChange); - - // THEN - QCOMPARE(backendClipBlendNode.clipIds().size(), 1); - QCOMPARE(backendClipBlendNode.clipIds().first(), clip.id()); - - // WHEN - const auto removedChange = Qt3DCore::QPropertyNodeRemovedChangePtr::create(Qt3DCore::QNodeId(), &clip); - backendClipBlendNode.sceneChangeEvent(removedChange); - - // THEN - QCOMPARE(backendClipBlendNode.clipIds().size(), 0); - } - { - // WHEN - Qt3DAnimation::QLerpClipBlend clipBlendChild; - // Will be destroyed when manager is destroyed - TestClipBlendNode *backenChildClipBlendNode = new TestClipBlendNode(); - backendClipBlendNode.setClipBlendNodeManager(&manager); - manager.appendNode(clipBlendChild.id(), backenChildClipBlendNode); - - // To geneate the type_info in the QNodePrivate of clipBlendChild - Qt3DCore::QNodeCreatedChangeGenerator generator(&clipBlendChild); - const auto addChange = Qt3DCore::QPropertyNodeAddedChangePtr::create(Qt3DCore::QNodeId(), &clipBlendChild); - backendClipBlendNode.sceneChangeEvent(addChange); - - // THEN - QCOMPARE(backendClipBlendNode.childrenIds().size(), 1); - QCOMPARE(backendClipBlendNode.childrenIds().first(), clipBlendChild.id()); - - // WHEN - const auto removedChange = Qt3DCore::QPropertyNodeRemovedChangePtr::create(Qt3DCore::QNodeId(), &clipBlendChild); - backendClipBlendNode.sceneChangeEvent(removedChange); - - // THEN - QCOMPARE(backendClipBlendNode.childrenIds().size(), 0); - } - } - - void checkParentInitialization() - { - // GIVEN - TestClipBlendNode *backendClipBlendNode = new TestClipBlendNode(); - TestClipBlendNode *backendChildClipBlendNode = new TestClipBlendNode(); - Qt3DAnimation::QLerpClipBlend clipBlendParent; - Qt3DAnimation::QLerpClipBlend childClipBlend(&clipBlendParent); - ClipBlendNodeManager manager; - backendClipBlendNode->setClipBlendNodeManager(&manager); - backendChildClipBlendNode->setClipBlendNodeManager(&manager); - - // THEN - QCOMPARE(backendClipBlendNode->parentId(), Qt3DCore::QNodeId()); - QCOMPARE(backendClipBlendNode->childrenIds().size(), 0); - QCOMPARE(backendChildClipBlendNode->parentId(), Qt3DCore::QNodeId()); - QCOMPARE(backendChildClipBlendNode->childrenIds().size(), 0); - - // WHEN - manager.appendNode(clipBlendParent.id(), backendClipBlendNode); - manager.appendNode(childClipBlend.id(), backendChildClipBlendNode); - simulateInitialization(&clipBlendParent, backendClipBlendNode); - simulateInitialization(&childClipBlend, backendChildClipBlendNode); - - // THEN - QCOMPARE(backendClipBlendNode->parentId(), Qt3DCore::QNodeId()); - QCOMPARE(backendClipBlendNode->childrenIds().size(), 1); - QCOMPARE(backendClipBlendNode->childrenIds().first(), childClipBlend.id()); - QCOMPARE(backendChildClipBlendNode->parentId(), clipBlendParent.id()); - QCOMPARE(backendChildClipBlendNode->childrenIds().size(), 0); - - // WHEN - // To geneate the type_info in the QNodePrivate of clipBlendChild - Qt3DCore::QNodeCreatedChangeGenerator generator(&childClipBlend); - const auto removedChange = Qt3DCore::QPropertyNodeRemovedChangePtr::create(Qt3DCore::QNodeId(), &childClipBlend); - backendClipBlendNode->sceneChangeEvent(removedChange); - - // THEN - QCOMPARE(backendClipBlendNode->parentId(), Qt3DCore::QNodeId()); - QCOMPARE(backendClipBlendNode->childrenIds().size(), 0); - QCOMPARE(backendChildClipBlendNode->parentId(), Qt3DCore::QNodeId()); - QCOMPARE(backendChildClipBlendNode->childrenIds().size(), 0); - } - void checkClipResults_data() { QTest::addColumn("blendNode"); diff --git a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp index f9ebfec4e..1ff17f9aa 100644 --- a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp +++ b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp @@ -130,7 +130,6 @@ private Q_SLOTS: Qt3DAnimation::QLerpClipBlend lerpBlend; Qt3DAnimation::QAnimationClipLoader clip; lerpBlend.setBlendFactor(0.8f); - lerpBlend.addClip(&clip); { // WHEN @@ -141,8 +140,6 @@ private Q_SLOTS: QCOMPARE(backendLerpBlend.isEnabled(), true); QCOMPARE(backendLerpBlend.peerId(), lerpBlend.id()); QCOMPARE(backendLerpBlend.blendFactor(), 0.8f); - QCOMPARE(backendLerpBlend.clipIds().size(), 1); - QCOMPARE(backendLerpBlend.clipIds().first(), clip.id()); } { // WHEN diff --git a/tests/auto/animation/qabstractclipblendnode/qabstractclipblendnode.pro b/tests/auto/animation/qabstractclipblendnode/qabstractclipblendnode.pro deleted file mode 100644 index 9dff8e7bd..000000000 --- a/tests/auto/animation/qabstractclipblendnode/qabstractclipblendnode.pro +++ /dev/null @@ -1,11 +0,0 @@ -TEMPLATE = app - -TARGET = tst_qabstractclipblendnode - -QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib - -CONFIG += testcase - -SOURCES += tst_qabstractclipblendnode.cpp - -include(../../core/common/common.pri) diff --git a/tests/auto/animation/qabstractclipblendnode/tst_qabstractclipblendnode.cpp b/tests/auto/animation/qabstractclipblendnode/tst_qabstractclipblendnode.cpp deleted file mode 100644 index f5f1e73d4..000000000 --- a/tests/auto/animation/qabstractclipblendnode/tst_qabstractclipblendnode.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Paul Lemire -** 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "testpostmanarbiter.h" - -namespace { - -class TestClipBlendNode : public Qt3DAnimation::QAbstractClipBlendNode -{ -public: - TestClipBlendNode(Qt3DCore::QNode *parent = nullptr) - : Qt3DAnimation::QAbstractClipBlendNode(parent) - {} - - using Qt3DAnimation::QAbstractClipBlendNode::addClip; - using Qt3DAnimation::QAbstractClipBlendNode::removeClip; -}; - -} - -class tst_QAbstractClipBlendNode : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - - void checkDefaultConstruction() - { - // GIVEN - TestClipBlendNode abstractClipBlendNode; - - // THEN - QCOMPARE(abstractClipBlendNode.clips().size(), 0); - } - - void checkPropertyChanges() - { - // GIVEN - TestClipBlendNode abstractClipBlendNode; - - { - // WHEN - Qt3DAnimation::QAnimationClipLoader newValue; - abstractClipBlendNode.addClip(&newValue); - - // THEN - QCOMPARE(abstractClipBlendNode.clips().size(), 1); - - // WHEN - abstractClipBlendNode.addClip(&newValue); - - // THEN - QCOMPARE(abstractClipBlendNode.clips().size(), 1); - - // WHEN - abstractClipBlendNode.removeClip(&newValue); - - // THEN - QCOMPARE(abstractClipBlendNode.clips().size(), 0); - } - } - - void checkClipBookkeeping() - { - // GIVEN - TestClipBlendNode abstractClipBlendNode; - - { - // WHEN - Qt3DAnimation::QAnimationClipLoader clip; - abstractClipBlendNode.addClip(&clip); - - QCOMPARE(abstractClipBlendNode.clips().size(), 1); - } - - // THEN -> should not crash - QCOMPARE(abstractClipBlendNode.clips().size(), 0); - } - - void checkClipUpdate() - { - // GIVEN - TestArbiter arbiter; - TestClipBlendNode abstractClipBlendNode; - Qt3DAnimation::QAnimationClipLoader clip; - arbiter.setArbiterOnNode(&abstractClipBlendNode); - - { - // WHEN - abstractClipBlendNode.addClip(&clip); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "clip"); - QCOMPARE(change->addedNodeId(), clip.id()); - QCOMPARE(change->type(), Qt3DCore::PropertyValueAdded); - - arbiter.events.clear(); - } - - { - // WHEN - abstractClipBlendNode.removeClip(&clip); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "clip"); - QCOMPARE(change->removedNodeId(), clip.id()); - QCOMPARE(change->type(), Qt3DCore::PropertyValueRemoved); - - arbiter.events.clear(); - } - - } - - void checkParentClipBlendNode() - { - // GIVEN - TestClipBlendNode clipNodeLevel0; - TestClipBlendNode clipNodeLevel1_1(&clipNodeLevel0); - TestClipBlendNode clipNodeLevel1_2(&clipNodeLevel0); - TestClipBlendNode clipNodeLevel2_1(&clipNodeLevel1_1); - Qt3DCore::QNode fakeNodeLevel2_2(&clipNodeLevel1_2); - TestClipBlendNode clipNodeLeve3_1(&fakeNodeLevel2_2); - - // THEN - QVERIFY(clipNodeLevel0.parent() == nullptr); - QCOMPARE(clipNodeLevel1_1.parent(), &clipNodeLevel0); - QCOMPARE(clipNodeLevel1_2.parent(), &clipNodeLevel0); - QCOMPARE(clipNodeLevel2_1.parent(), &clipNodeLevel1_1); - QCOMPARE(fakeNodeLevel2_2.parent(), &clipNodeLevel1_2); - QCOMPARE(clipNodeLeve3_1.parent(), &fakeNodeLevel2_2); - - QVERIFY(clipNodeLevel0.parentClipBlendNode() == nullptr); - QCOMPARE(clipNodeLevel1_1.parentClipBlendNode(), &clipNodeLevel0); - QCOMPARE(clipNodeLevel1_2.parentClipBlendNode(), &clipNodeLevel0); - QCOMPARE(clipNodeLevel2_1.parentClipBlendNode(), &clipNodeLevel1_1); - QCOMPARE(clipNodeLeve3_1.parentClipBlendNode(), &clipNodeLevel1_2); - } -}; - -QTEST_MAIN(tst_QAbstractClipBlendNode) - -#include "tst_qabstractclipblendnode.moc" diff --git a/tests/auto/animation/qadditiveclipblend/tst_qadditiveclipblend.cpp b/tests/auto/animation/qadditiveclipblend/tst_qadditiveclipblend.cpp index 536853b1f..c1f01394f 100644 --- a/tests/auto/animation/qadditiveclipblend/tst_qadditiveclipblend.cpp +++ b/tests/auto/animation/qadditiveclipblend/tst_qadditiveclipblend.cpp @@ -160,7 +160,6 @@ private Q_SLOTS: QCOMPARE(addBlend.metaObject(), creationChangeData->metaObject()); QCOMPARE(cloneData.baseClipId, baseClip.id()); QCOMPARE(cloneData.additiveClipId, additiveClip.id()); - QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); } // WHEN @@ -185,7 +184,6 @@ private Q_SLOTS: QCOMPARE(addBlend.metaObject(), creationChangeData->metaObject()); QCOMPARE(cloneData.baseClipId, baseClip.id()); QCOMPARE(cloneData.additiveClipId, additiveClip.id()); - QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); } } diff --git a/tests/auto/animation/qclipblendvalue/tst_qclipblendvalue.cpp b/tests/auto/animation/qclipblendvalue/tst_qclipblendvalue.cpp index 6be6970ae..bdbee9380 100644 --- a/tests/auto/animation/qclipblendvalue/tst_qclipblendvalue.cpp +++ b/tests/auto/animation/qclipblendvalue/tst_qclipblendvalue.cpp @@ -112,7 +112,6 @@ private Q_SLOTS: QCOMPARE(clipBlendNode.isEnabled(), creationChangeData->isNodeEnabled()); QCOMPARE(clipBlendNode.metaObject(), creationChangeData->metaObject()); QCOMPARE(cloneData.clipId, clip.id()); - QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); } // WHEN @@ -135,7 +134,6 @@ private Q_SLOTS: QCOMPARE(clipBlendNode.isEnabled(), creationChangeData->isNodeEnabled()); QCOMPARE(clipBlendNode.metaObject(), creationChangeData->metaObject()); QCOMPARE(cloneData.clipId, clip.id()); - QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); } } diff --git a/tests/auto/animation/qlerpclipblend/tst_qlerpclipblend.cpp b/tests/auto/animation/qlerpclipblend/tst_qlerpclipblend.cpp index d6b449fdb..057f37786 100644 --- a/tests/auto/animation/qlerpclipblend/tst_qlerpclipblend.cpp +++ b/tests/auto/animation/qlerpclipblend/tst_qlerpclipblend.cpp @@ -160,7 +160,6 @@ private Q_SLOTS: QCOMPARE(lerpBlend.metaObject(), creationChangeData->metaObject()); QCOMPARE(cloneData.startClipId, startClip.id()); QCOMPARE(cloneData.endClipId, endClip.id()); - QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); } // WHEN @@ -185,7 +184,6 @@ private Q_SLOTS: QCOMPARE(lerpBlend.metaObject(), creationChangeData->metaObject()); QCOMPARE(cloneData.startClipId, startClip.id()); QCOMPARE(cloneData.endClipId, endClip.id()); - QCOMPARE(creationChangeData->parentClipBlendNodeId(), Qt3DCore::QNodeId()); } } -- cgit v1.2.3 From eec0906106c7367f155f84444703754a9e66f745 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 24 Mar 2017 13:33:50 +0000 Subject: Remove ClipBlendNode::parentId() function No longer needed. The tree is not managed by parent/child relationships any longer. Change-Id: I711e71a4b54491f5713732ea54100b7ce9526527 Reviewed-by: Sean Harmer --- tests/auto/animation/clipblendnode/tst_clipblendnode.cpp | 2 -- .../animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp | 9 --------- 2 files changed, 11 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp index c945b6f3f..b5953251b 100644 --- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -114,7 +114,6 @@ private Q_SLOTS: // THEN QCOMPARE(backendClipBlendNode.isEnabled(), false); QVERIFY(backendClipBlendNode.peerId().isNull()); - QCOMPARE(backendClipBlendNode.parentId(), Qt3DCore::QNodeId()); QCOMPARE(backendClipBlendNode.childrenIds(), Qt3DCore::QNodeIdVector()); QVERIFY(backendClipBlendNode.clipBlendNodeManager() == nullptr); QCOMPARE(backendClipBlendNode.blendType(), ClipBlendNode::LerpBlendType); @@ -139,7 +138,6 @@ private Q_SLOTS: // THEN QCOMPARE(backendClipBlendNode.isEnabled(), true); QCOMPARE(backendClipBlendNode.peerId(), clipBlendNode.id()); - QCOMPARE(backendClipBlendNode.parentId(), Qt3DCore::QNodeId()); QCOMPARE(backendClipBlendNode.childrenIds().size(), 0); QCOMPARE(backendClipBlendNode.clipBlendNodeManager(), &manager); QCOMPARE(backendClipBlendNode.blendType(), ClipBlendNode::LerpBlendType); diff --git a/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp b/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp index 77f835985..9aa3218e9 100644 --- a/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp +++ b/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp @@ -76,15 +76,10 @@ private Q_SLOTS: simulateInitialization(&childBlendNode12, backendChildBlendNode12); // THEN - QVERIFY(backendRootBlendNode->parentId().isNull()); QCOMPARE(backendRootBlendNode->childrenIds().size(), 2); - QCOMPARE(backendChildBlendNode1->parentId(), rootBlendNode.id()); QCOMPARE(backendChildBlendNode1->childrenIds().size(), 2); - QCOMPARE(backendChildBlendNode2->parentId(), rootBlendNode.id()); QCOMPARE(backendChildBlendNode2->childrenIds().size(), 0); - QCOMPARE(backendChildBlendNode11->parentId(), childBlendNode1.id()); QCOMPARE(backendChildBlendNode11->childrenIds().size(), 0); - QCOMPARE(backendChildBlendNode12->parentId(), childBlendNode1.id()); QCOMPARE(backendChildBlendNode12->childrenIds().size(), 0); // WHEN @@ -125,7 +120,6 @@ private Q_SLOTS: simulateInitialization(&rootBlendNode, backendRootBlendNode); // THEN - QVERIFY(backendRootBlendNode->parentId().isNull()); QCOMPARE(backendRootBlendNode->childrenIds().size(), 0); // WHEN @@ -164,11 +158,8 @@ private Q_SLOTS: simulateInitialization(&childBlendNode2, backendChildBlendNode2); // THEN - QVERIFY(backendRootBlendNode->parentId().isNull()); QCOMPARE(backendRootBlendNode->childrenIds().size(), 2); - QCOMPARE(backendChildBlendNode1->parentId(), rootBlendNode.id()); QCOMPARE(backendChildBlendNode1->childrenIds().size(), 0); - QCOMPARE(backendChildBlendNode2->parentId(), rootBlendNode.id()); QCOMPARE(backendChildBlendNode2->childrenIds().size(), 0); // WHEN -- cgit v1.2.3 From 66e842dc6d052293c7ec97e0ba0cfb1d10c7590c Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 24 Mar 2017 13:42:02 +0000 Subject: Remove blend() virtual function from backend blend tree nodes No longer needed as replaced by the more general doBlend() protected virtual. Change-Id: I5f11c068f8a379baa53a033e5ce8ce63ff64d5ba Reviewed-by: Sean Harmer --- .../additiveclipblend/tst_additiveclipblend.cpp | 31 ---------------------- .../animationutils/tst_animationutils.cpp | 3 --- .../animation/clipblendnode/tst_clipblendnode.cpp | 2 -- .../tst_clipblendnodemanager.cpp | 2 -- .../animation/lerpclipblend/tst_lerpclipblend.cpp | 31 ---------------------- 5 files changed, 69 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp index cd77425a0..9b2387ac1 100644 --- a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp +++ b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp @@ -50,8 +50,6 @@ public: , m_duration(duration) {} - float blend(float, float) const Q_DECL_FINAL { return 0.0f; } - QVector dependencyIds() const Q_DECL_FINAL { return QVector(); @@ -211,35 +209,6 @@ private Q_SLOTS: } } - void checkBlend_data() - { - QTest::addColumn("value1"); - QTest::addColumn("value2"); - QTest::addColumn("blendFactor"); - QTest::addColumn("result"); - - QTest::newRow("0_blending") << 8.0f << 5.0f << 0.0f << 8.0f; - QTest::newRow("0.5_blending") << 8.0f << 5.0f << 0.5f << 10.5f; - QTest::newRow("1_blending") << 8.0f << 5.0f << 1.0f << 13.0f; - } - - void checkBlend() - { - // GIVEN - QFETCH(float, value1); - QFETCH(float, value2); - QFETCH(float, blendFactor); - QFETCH(float, result); - AdditiveClipBlend addBlend; - - // WHEN - addBlend.setAdditiveFactor(blendFactor); - const float computed = addBlend.blend(value1, value2); - - // THEN - QCOMPARE(computed, result); - } - void checkDependencyIds() { // GIVEN diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 0357d07d6..d5149b093 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -70,9 +70,6 @@ public: : ClipBlendNode(ClipBlendNode::LerpBlendType) {} - float blend(float, float ) const Q_DECL_FINAL { return 0.0f; } - - void setValueNodeIds(Qt3DCore::QNodeId value1Id, Qt3DCore::QNodeId value2Id) { diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp index b5953251b..3175931a9 100644 --- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -54,8 +54,6 @@ public: , m_clipResults(clipResults) {} - float blend(float , float ) const Q_DECL_FINAL { return 0.0f; } - QVector dependencyIds() const Q_DECL_FINAL { return QVector(); diff --git a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp index 4cf8fe5ce..95b8e2bfe 100644 --- a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp +++ b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp @@ -49,8 +49,6 @@ public: deadCount += 1; } - float blend(float , float ) const Q_DECL_FINAL { return 0.0f; } - QVector dependencyIds() const Q_DECL_FINAL { return QVector(); diff --git a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp index 1ff17f9aa..a817028c3 100644 --- a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp +++ b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp @@ -50,8 +50,6 @@ public: , m_duration(duration) {} - float blend(float, float) const Q_DECL_FINAL { return 0.0f; } - QVector dependencyIds() const Q_DECL_FINAL { return QVector(); @@ -181,35 +179,6 @@ private Q_SLOTS: } } - void checkBlend_data() - { - QTest::addColumn("value1"); - QTest::addColumn("value2"); - QTest::addColumn("blendFactor"); - QTest::addColumn("result"); - - QTest::newRow("0_blending") << 8.0f << 5.0f << 0.0f << 8.0f; - QTest::newRow("0.5_blending") << 8.0f << 5.0f << 0.5f << 6.5f; - QTest::newRow("1_blending") << 8.0f << 5.0f << 1.0f << 5.0f; - } - - void checkBlend() - { - // GIVEN - QFETCH(float, value1); - QFETCH(float, value2); - QFETCH(float, blendFactor); - QFETCH(float, result); - LerpClipBlend lerpBlend; - - // WHEN - lerpBlend.setBlendFactor(blendFactor); - const float computed = lerpBlend.blend(value1, value2); - - // THEN - QCOMPARE(computed, result); - } - void checkDependencyIds() { // GIVEN -- cgit v1.2.3 From 2357c213b61fc4111701cf86b26ca44ab020058b Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 24 Mar 2017 13:49:01 +0000 Subject: Rename QClipBlendNode::performBlend() to blend() Now the old blend() virtual is gone we can give this function a nicer name. Change-Id: I74e427692f9667d52342d5c558bff3e7cf63c652 Reviewed-by: Sean Harmer --- tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp | 2 +- tests/auto/animation/clipblendnode/tst_clipblendnode.cpp | 2 +- tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp index 9b2387ac1..cade61ffb 100644 --- a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp +++ b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp @@ -410,7 +410,7 @@ private Q_SLOTS: QFETCH(ClipResults, expectedResults); // WHEN - blendNode->performBlend(animatorId); + blendNode->blend(animatorId); // THEN const ClipResults actualResults = blendNode->clipResults(animatorId); diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp index 3175931a9..8c1ba0b6c 100644 --- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -293,7 +293,7 @@ private Q_SLOTS: auto animator = createBlendedClipAnimator(handler, globalStartTimeNS, loopCount); // WHEN - blendNode->performBlend(animator->peerId()); + blendNode->blend(animator->peerId()); // THEN const ClipResults actualResults = blendNode->clipResults(animator->peerId()); diff --git a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp index a817028c3..8ed08c563 100644 --- a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp +++ b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp @@ -382,7 +382,7 @@ private Q_SLOTS: QFETCH(ClipResults, expectedResults); // WHEN - blendNode->performBlend(animatorId); + blendNode->blend(animatorId); // THEN const ClipResults actualResults = blendNode->clipResults(animatorId); -- cgit v1.2.3 From d4181254c00086d735ecbf01a03a8129e788e0a5 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 24 Mar 2017 15:53:19 +0000 Subject: Rename dependencyIds() to currentDependencyIds() We need to add another function that returns all potential dependencies rather than just those that are dependencies given the current state (blend value). Make room for that by renaming this to a more descriptive name. Change-Id: I06cdc2e471007e3bd40cd7b687a4a2c21e4b2828 Reviewed-by: Sean Harmer --- tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp | 6 +++--- tests/auto/animation/animationutils/tst_animationutils.cpp | 2 +- tests/auto/animation/clipblendnode/tst_clipblendnode.cpp | 2 +- .../animation/clipblendnodemanager/tst_clipblendnodemanager.cpp | 2 +- tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp | 4 ++-- tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp index cade61ffb..b3b9d98da 100644 --- a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp +++ b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp @@ -50,7 +50,7 @@ public: , m_duration(duration) {} - QVector dependencyIds() const Q_DECL_FINAL + QVector currentDependencyIds() const Q_DECL_FINAL { return QVector(); } @@ -219,7 +219,7 @@ private Q_SLOTS: // WHEN addBlend.setBaseClipId(baseClipId); addBlend.setAdditiveClipId(additiveClipId); - QVector actualIds = addBlend.dependencyIds(); + QVector actualIds = addBlend.currentDependencyIds(); // THEN QCOMPARE(actualIds.size(), 2); @@ -229,7 +229,7 @@ private Q_SLOTS: // WHEN auto anotherAdditiveClipId = Qt3DCore::QNodeId::createId(); addBlend.setAdditiveClipId(anotherAdditiveClipId); - actualIds = addBlend.dependencyIds(); + actualIds = addBlend.currentDependencyIds(); // THEN QCOMPARE(actualIds.size(), 2); diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index d5149b093..7de3d42be 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -77,7 +77,7 @@ public: m_value2Id = value2Id; } - QVector dependencyIds() const Q_DECL_FINAL + QVector currentDependencyIds() const Q_DECL_FINAL { return QVector() << m_value1Id << m_value2Id; } diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp index 8c1ba0b6c..c195b760c 100644 --- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -54,7 +54,7 @@ public: , m_clipResults(clipResults) {} - QVector dependencyIds() const Q_DECL_FINAL + QVector currentDependencyIds() const Q_DECL_FINAL { return QVector(); } diff --git a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp index 95b8e2bfe..b909bb3ad 100644 --- a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp +++ b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp @@ -49,7 +49,7 @@ public: deadCount += 1; } - QVector dependencyIds() const Q_DECL_FINAL + QVector currentDependencyIds() const Q_DECL_FINAL { return QVector(); } diff --git a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp index 9266161fc..eba5c600e 100644 --- a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp +++ b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp @@ -134,7 +134,7 @@ private Q_SLOTS: // WHEN clipNode.setClipId(clipId); - QVector actualIds = clipNode.dependencyIds(); + QVector actualIds = clipNode.currentDependencyIds(); // THEN QCOMPARE(actualIds.size(), 1); @@ -143,7 +143,7 @@ private Q_SLOTS: // WHEN auto anotherClipId = Qt3DCore::QNodeId::createId(); clipNode.setClipId(anotherClipId); - actualIds = clipNode.dependencyIds(); + actualIds = clipNode.currentDependencyIds(); // THEN QCOMPARE(actualIds.size(), 1); diff --git a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp index 8ed08c563..f2d6263ae 100644 --- a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp +++ b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp @@ -50,7 +50,7 @@ public: , m_duration(duration) {} - QVector dependencyIds() const Q_DECL_FINAL + QVector currentDependencyIds() const Q_DECL_FINAL { return QVector(); } @@ -189,7 +189,7 @@ private Q_SLOTS: // WHEN lerpBlend.setStartClipId(startClipId); lerpBlend.setEndClipId(endClipId); - QVector actualIds = lerpBlend.dependencyIds(); + QVector actualIds = lerpBlend.currentDependencyIds(); // THEN QCOMPARE(actualIds.size(), 2); @@ -199,7 +199,7 @@ private Q_SLOTS: // WHEN auto anotherEndClipId = Qt3DCore::QNodeId::createId(); lerpBlend.setEndClipId(anotherEndClipId); - actualIds = lerpBlend.dependencyIds(); + actualIds = lerpBlend.currentDependencyIds(); // THEN QCOMPARE(actualIds.size(), 2); -- cgit v1.2.3 From 57d700a414dd8e6fa301865771b9c738bb7aa8c6 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 24 Mar 2017 16:00:50 +0000 Subject: Add allDependencyIds() pure virtual and overrides to backend nodes This will be used to visit all nodes by the visitor for the purpose of collecting vlaue nodes that should be evaluated. Change-Id: Iff84eed2ee139a0ecd3639994549e5859b5827d0 Reviewed-by: Sean Harmer --- tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp | 5 +++++ tests/auto/animation/animationutils/tst_animationutils.cpp | 5 +++++ tests/auto/animation/clipblendnode/tst_clipblendnode.cpp | 5 +++++ .../auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp | 5 +++++ tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp | 5 +++++ 5 files changed, 25 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp index b3b9d98da..28ab8917a 100644 --- a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp +++ b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp @@ -50,6 +50,11 @@ public: , m_duration(duration) {} + inline QVector allDependencyIds() const Q_DECL_OVERRIDE + { + return currentDependencyIds(); + } + QVector currentDependencyIds() const Q_DECL_FINAL { return QVector(); diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 7de3d42be..17815f5db 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -77,6 +77,11 @@ public: m_value2Id = value2Id; } + inline QVector allDependencyIds() const Q_DECL_OVERRIDE + { + return currentDependencyIds(); + } + QVector currentDependencyIds() const Q_DECL_FINAL { return QVector() << m_value1Id << m_value2Id; diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp index c195b760c..b480a5ab8 100644 --- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -54,6 +54,11 @@ public: , m_clipResults(clipResults) {} + inline QVector allDependencyIds() const Q_DECL_OVERRIDE + { + return currentDependencyIds(); + } + QVector currentDependencyIds() const Q_DECL_FINAL { return QVector(); diff --git a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp index b909bb3ad..7bcef28ae 100644 --- a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp +++ b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp @@ -49,6 +49,11 @@ public: deadCount += 1; } + inline QVector allDependencyIds() const Q_DECL_OVERRIDE + { + return currentDependencyIds(); + } + QVector currentDependencyIds() const Q_DECL_FINAL { return QVector(); diff --git a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp index f2d6263ae..003b1ef53 100644 --- a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp +++ b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp @@ -50,6 +50,11 @@ public: , m_duration(duration) {} + inline QVector allDependencyIds() const Q_DECL_OVERRIDE + { + return currentDependencyIds(); + } + QVector currentDependencyIds() const Q_DECL_FINAL { return QVector(); -- cgit v1.2.3 From 5a7fdcaf649a51be5f18dc3ef1fbea26b0dbdef1 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 24 Mar 2017 16:21:19 +0000 Subject: Make ClipBlendNodeVisitor use allDependencyIds() Instead of childrenIds() which no longer makes sense since we do not use the parent/child relationship to define the tree but rather explicit properties on each node type. Change-Id: Ia2a20a62d5f51acbbb364f6b5bd1ffebdbc8a28c Reviewed-by: Mike Krus --- .../tst_clipblendnodevisitor.cpp | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp b/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp index 9aa3218e9..3f705e713 100644 --- a/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp +++ b/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp @@ -46,8 +46,12 @@ private Q_SLOTS: Qt3DAnimation::QLerpClipBlend rootBlendNode; Qt3DAnimation::QLerpClipBlend childBlendNode1(&rootBlendNode); Qt3DAnimation::QLerpClipBlend childBlendNode2(&rootBlendNode); + rootBlendNode.setStartClip(&childBlendNode1); + rootBlendNode.setEndClip(&childBlendNode2); Qt3DAnimation::QLerpClipBlend childBlendNode11(&childBlendNode1); Qt3DAnimation::QLerpClipBlend childBlendNode12(&childBlendNode1); + childBlendNode1.setStartClip(&childBlendNode11); + childBlendNode1.setEndClip(&childBlendNode12); Qt3DAnimation::Animation::LerpClipBlend *backendRootBlendNode = new Qt3DAnimation::Animation::LerpClipBlend(); Qt3DAnimation::Animation::LerpClipBlend *backendChildBlendNode1 = new Qt3DAnimation::Animation::LerpClipBlend(); @@ -76,11 +80,11 @@ private Q_SLOTS: simulateInitialization(&childBlendNode12, backendChildBlendNode12); // THEN - QCOMPARE(backendRootBlendNode->childrenIds().size(), 2); - QCOMPARE(backendChildBlendNode1->childrenIds().size(), 2); - QCOMPARE(backendChildBlendNode2->childrenIds().size(), 0); - QCOMPARE(backendChildBlendNode11->childrenIds().size(), 0); - QCOMPARE(backendChildBlendNode12->childrenIds().size(), 0); + QCOMPARE(backendRootBlendNode->allDependencyIds().size(), 2); + QCOMPARE(backendChildBlendNode1->allDependencyIds().size(), 2); + QCOMPARE(backendChildBlendNode2->allDependencyIds().size(), 2); + QCOMPARE(backendChildBlendNode11->allDependencyIds().size(), 2); + QCOMPARE(backendChildBlendNode12->allDependencyIds().size(), 2); // WHEN int i = 0; @@ -120,7 +124,7 @@ private Q_SLOTS: simulateInitialization(&rootBlendNode, backendRootBlendNode); // THEN - QCOMPARE(backendRootBlendNode->childrenIds().size(), 0); + QCOMPARE(backendRootBlendNode->allDependencyIds().size(), 2); // WHEN auto childCounter = [] (Qt3DAnimation::Animation::ClipBlendNode *) {}; @@ -136,6 +140,8 @@ private Q_SLOTS: Qt3DAnimation::QLerpClipBlend rootBlendNode; Qt3DAnimation::QLerpClipBlend childBlendNode1(&rootBlendNode); Qt3DAnimation::QLerpClipBlend childBlendNode2(&rootBlendNode); + rootBlendNode.setStartClip(&childBlendNode1); + rootBlendNode.setEndClip(&childBlendNode2); Qt3DAnimation::Animation::LerpClipBlend *backendRootBlendNode = new Qt3DAnimation::Animation::LerpClipBlend(); Qt3DAnimation::Animation::LerpClipBlend *backendChildBlendNode1 = new Qt3DAnimation::Animation::LerpClipBlend(); @@ -158,9 +164,9 @@ private Q_SLOTS: simulateInitialization(&childBlendNode2, backendChildBlendNode2); // THEN - QCOMPARE(backendRootBlendNode->childrenIds().size(), 2); - QCOMPARE(backendChildBlendNode1->childrenIds().size(), 0); - QCOMPARE(backendChildBlendNode2->childrenIds().size(), 0); + QCOMPARE(backendRootBlendNode->allDependencyIds().size(), 2); + QCOMPARE(backendChildBlendNode1->allDependencyIds().size(), 2); + QCOMPARE(backendChildBlendNode2->allDependencyIds().size(), 2); // WHEN int i = 0; -- cgit v1.2.3 From b854233ee924d020ca8dfd30996d1483f04e4e7a Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 24 Mar 2017 16:24:55 +0000 Subject: Remove last vestiges of parent-child data from ClipBlendNode Change-Id: I76c28fc48ee6683f3e86aceffd66e2b579899d5b Reviewed-by: Mike Krus --- tests/auto/animation/clipblendnode/tst_clipblendnode.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp index b480a5ab8..b64e263bf 100644 --- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp +++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp @@ -117,7 +117,6 @@ private Q_SLOTS: // THEN QCOMPARE(backendClipBlendNode.isEnabled(), false); QVERIFY(backendClipBlendNode.peerId().isNull()); - QCOMPARE(backendClipBlendNode.childrenIds(), Qt3DCore::QNodeIdVector()); QVERIFY(backendClipBlendNode.clipBlendNodeManager() == nullptr); QCOMPARE(backendClipBlendNode.blendType(), ClipBlendNode::LerpBlendType); QCOMPARE(backendClipBlendNode.clipResults(Qt3DCore::QNodeId()), ClipResults()); @@ -141,7 +140,6 @@ private Q_SLOTS: // THEN QCOMPARE(backendClipBlendNode.isEnabled(), true); QCOMPARE(backendClipBlendNode.peerId(), clipBlendNode.id()); - QCOMPARE(backendClipBlendNode.childrenIds().size(), 0); QCOMPARE(backendClipBlendNode.clipBlendNodeManager(), &manager); QCOMPARE(backendClipBlendNode.blendType(), ClipBlendNode::LerpBlendType); QCOMPARE(backendClipBlendNode.clipResults(Qt3DCore::QNodeId()), ClipResults()); -- cgit v1.2.3 From 128a9550a587cb8c8a57a565f18f95c13a2d5207 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Wed, 22 Mar 2017 15:56:24 +0100 Subject: Fix ShaderData following texture support changes Change-Id: Ia1ef3fdd796070fa6c5b37be5774babd1eaf2d96 Reviewed-by: Sean Harmer --- .../render/renderviewutils/tst_renderviewutils.cpp | 72 +++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/renderviewutils/tst_renderviewutils.cpp b/tests/auto/render/renderviewutils/tst_renderviewutils.cpp index c38b2795e..fa0dce6af 100644 --- a/tests/auto/render/renderviewutils/tst_renderviewutils.cpp +++ b/tests/auto/render/renderviewutils/tst_renderviewutils.cpp @@ -46,6 +46,7 @@ private Q_SLOTS: void topLevelTextureValueNoUniforms(); void topLevelTextureValue(); void topLevelArrayValue(); + void nestedShaderDataValue(); void topLevelStructValue_data(); void topLevelStructValue(); void topLevelDynamicProperties(); @@ -85,8 +86,8 @@ class ScalarShaderData : public Qt3DRender::QShaderData Q_PROPERTY(float scalar READ scalar WRITE setScalar NOTIFY scalarChanged) public: - ScalarShaderData() - : Qt3DRender::QShaderData() + ScalarShaderData(Qt3DCore::QNode *parent = nullptr) + : Qt3DRender::QShaderData(parent) , m_scalar(0.0f) { } @@ -521,6 +522,73 @@ void tst_RenderViewUtils::topLevelArrayValue() } } +void tst_RenderViewUtils::nestedShaderDataValue() +{ + // GIVEN + QScopedPointer arrayShaderData(new ArrayShaderData()); + QScopedPointer manager(new Qt3DRender::Render::ShaderDataManager()); + QScopedPointer textureManager(new Qt3DRender::Render::TextureManager()); + + QScopedPointer shaderData1(new ScalarShaderData(arrayShaderData.data())); + QScopedPointer shaderData2(new ScalarShaderData(arrayShaderData.data())); + QScopedPointer shaderData3(new ScalarShaderData(arrayShaderData.data())); + + shaderData1->setScalar(883.0f); + shaderData2->setScalar(1200.0f); + shaderData3->setScalar(1340.0f); + QHash scalarValues; + scalarValues[QStringLiteral("MyBlock.array[0].scalar")] = shaderData1->scalar(); + scalarValues[QStringLiteral("MyBlock.array[1].scalar")] = shaderData2->scalar(); + scalarValues[QStringLiteral("MyBlock.array[2].scalar")] = shaderData3->scalar(); + + + const Qt3DCore::QNodeId id1 = shaderData1->id(); + const Qt3DCore::QNodeId id2 = shaderData2->id(); + const Qt3DCore::QNodeId id3 = shaderData3->id(); + + // WHEN + const QVariantList arrayValues = QVariantList() << QVariant::fromValue(id1) << QVariant::fromValue(id2) << QVariant::fromValue(id3); + arrayShaderData->setArray(arrayValues); + initBackendShaderData(arrayShaderData.data(), manager.data()); + + // THEN + Qt3DRender::Render::ShaderData *backendArrayShaderData = manager->lookupResource(arrayShaderData->id()); + Qt3DRender::Render::ShaderData *backendShaderData1 = manager->lookupResource(id1); + Qt3DRender::Render::ShaderData *backendShaderData2 = manager->lookupResource(id2); + Qt3DRender::Render::ShaderData *backendShaderData3 = manager->lookupResource(id3); + QVERIFY(backendArrayShaderData != nullptr); + QVERIFY(backendShaderData1 != nullptr); + QVERIFY(backendShaderData2 != nullptr); + QVERIFY(backendShaderData3 != nullptr); + + // WHEN + Qt3DRender::Render::UniformBlockValueBuilder blockBuilder; + blockBuilder.shaderDataManager = manager.data(); + blockBuilder.textureManager = textureManager.data(); + blockBuilder.updatedPropertiesOnly = false; + blockBuilder.uniforms.insert(QStringLiteral("MyBlock.array[0].scalar"), Qt3DRender::Render::ShaderUniform()); + blockBuilder.uniforms.insert(QStringLiteral("MyBlock.array[1].scalar"), Qt3DRender::Render::ShaderUniform()); + blockBuilder.uniforms.insert(QStringLiteral("MyBlock.array[2].scalar"), Qt3DRender::Render::ShaderUniform()); + // build name-value map + blockBuilder.buildActiveUniformNameValueMapStructHelper(backendArrayShaderData, QStringLiteral("MyBlock")); + + // THEN + QVERIFY(blockBuilder.uniforms.count() == 3); + QCOMPARE(blockBuilder.activeUniformNamesToValue.count(), 3); + + // WHEN + auto it = blockBuilder.uniforms.cbegin(); + const auto end = blockBuilder.uniforms.cend(); + + while (it != end) { + // THEN + const int nameId = Qt3DRender::Render::StringToInt::lookupId(it.key()); + QVERIFY(blockBuilder.activeUniformNamesToValue.contains(nameId)); + QCOMPARE(blockBuilder.activeUniformNamesToValue[nameId], scalarValues.value(it.key())); + ++it; + } +} + void tst_RenderViewUtils::topLevelStructValue_data() { QTest::addColumn("shaderData"); -- cgit v1.2.3 From 31356b4cf548e283a9151c287667e7af971d2d48 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Mon, 27 Mar 2017 11:51:46 +0100 Subject: Add arguments to notify signals in QFirstpersonCameraController Change-Id: Ic7a970bf51e11dde38bbf3ce9b708e957f9fee8e Reviewed-by: Marc Mutz --- .../qfirstpersoncameracontroller/tst_qfirstpersoncameracontroller.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/extras/qfirstpersoncameracontroller/tst_qfirstpersoncameracontroller.cpp b/tests/auto/extras/qfirstpersoncameracontroller/tst_qfirstpersoncameracontroller.cpp index 2cf4d7ba2..ab43ff2e5 100644 --- a/tests/auto/extras/qfirstpersoncameracontroller/tst_qfirstpersoncameracontroller.cpp +++ b/tests/auto/extras/qfirstpersoncameracontroller/tst_qfirstpersoncameracontroller.cpp @@ -124,7 +124,7 @@ private Q_SLOTS: } { // WHEN - QSignalSpy spy(&firstPersonCameraController, SIGNAL(accelerationChanged())); + QSignalSpy spy(&firstPersonCameraController, SIGNAL(accelerationChanged(float))); const float newValue = 0.001f; firstPersonCameraController.setAcceleration(newValue); @@ -143,7 +143,7 @@ private Q_SLOTS: } { // WHEN - QSignalSpy spy(&firstPersonCameraController, SIGNAL(decelerationChanged())); + QSignalSpy spy(&firstPersonCameraController, SIGNAL(decelerationChanged(float))); const float newValue = 0.001f; firstPersonCameraController.setDeceleration(newValue); -- cgit v1.2.3 From e841be3ef9b4ea089265991cb0fe3a5d4ee14224 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Mon, 27 Mar 2017 14:58:40 +0100 Subject: Add Threshold suffix to QLevelOfDetail enum values Change-Id: I70a39b4a2664e2952d9f3cdd1ace1f021b0311dd Reviewed-by: Paul Lemire Reviewed-by: Marc Mutz --- tests/auto/render/levelofdetail/tst_levelofdetail.cpp | 10 +++++----- tests/auto/render/qlevelofdetail/tst_qlevelofdetail.cpp | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/levelofdetail/tst_levelofdetail.cpp b/tests/auto/render/levelofdetail/tst_levelofdetail.cpp index 1446811a8..148c54e58 100644 --- a/tests/auto/render/levelofdetail/tst_levelofdetail.cpp +++ b/tests/auto/render/levelofdetail/tst_levelofdetail.cpp @@ -70,7 +70,7 @@ private Q_SLOTS: // THEN QCOMPARE(renderLod.camera(), Qt3DCore::QNodeId{}); QCOMPARE(renderLod.currentIndex(), 0); - QCOMPARE(renderLod.thresholdType(), Qt3DRender::QLevelOfDetail::DistanceToCamera); + QCOMPARE(renderLod.thresholdType(), Qt3DRender::QLevelOfDetail::DistanceToCameraThreshold); QVERIFY(renderLod.thresholds().empty()); QCOMPARE(renderLod.radius(), 1.f); QCOMPARE(renderLod.center(), QVector3D{}); @@ -78,7 +78,7 @@ private Q_SLOTS: // GIVEN Qt3DRender::QLevelOfDetail lod; - lod.setThresholdType(Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSize); + lod.setThresholdType(Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSizeThreshold); // WHEN renderLod.setRenderer(&renderer); @@ -96,18 +96,18 @@ private Q_SLOTS: renderLod.setRenderer(&renderer); // THEN - QVERIFY(renderLod.thresholdType() != Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSize); + QVERIFY(renderLod.thresholdType() != Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSizeThreshold); QVERIFY(renderLod.camera().isNull()); { // WHEN Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); - updateChange->setValue(static_cast(Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSize)); + updateChange->setValue(static_cast(Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSizeThreshold)); updateChange->setPropertyName("thresholdType"); renderLod.sceneChangeEvent(updateChange); // THEN - QCOMPARE(renderLod.thresholdType(), Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSize); + QCOMPARE(renderLod.thresholdType(), Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSizeThreshold); QVERIFY(renderer.dirtyBits() != 0); } diff --git a/tests/auto/render/qlevelofdetail/tst_qlevelofdetail.cpp b/tests/auto/render/qlevelofdetail/tst_qlevelofdetail.cpp index e2ffdd9da..ba357c8c9 100644 --- a/tests/auto/render/qlevelofdetail/tst_qlevelofdetail.cpp +++ b/tests/auto/render/qlevelofdetail/tst_qlevelofdetail.cpp @@ -89,14 +89,14 @@ private Q_SLOTS: { // WHEN - lod->setThresholdType(Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSize); + lod->setThresholdType(Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSizeThreshold); QCoreApplication::processEvents(); // THEN QCOMPARE(arbiter.events.size(), 1); Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); QCOMPARE(change->propertyName(), "thresholdType"); - QCOMPARE(change->value().value(), static_cast(Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSize)); + QCOMPARE(change->value().value(), static_cast(Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSizeThreshold)); arbiter.events.clear(); } -- cgit v1.2.3 From 0258a5593dab0ee885824fd026031ef6d0fe3ac1 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Mon, 27 Mar 2017 11:23:35 +0100 Subject: Use [setL|l]oopCount in C++ for QAbstractClipAnimator Keep the property name as loops for consistency with Qt Quick. Avoids ambiguity in function name meaning. Change-Id: Icf35f30d3020e77aba9db878c9dbc6e890c898ff Reviewed-by: Marc Mutz Reviewed-by: Paul Lemire --- .../blendedclipanimator/tst_blendedclipanimator.cpp | 2 +- .../auto/animation/clipanimator/tst_clipanimator.cpp | 6 +++--- .../tst_qblendedclipanimator.cpp | 20 ++++++++++---------- .../animation/qclipanimator/tst_qclipanimator.cpp | 20 ++++++++++---------- 4 files changed, 24 insertions(+), 24 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp b/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp index 2b26fbfce..3265de167 100644 --- a/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp +++ b/tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp @@ -103,7 +103,7 @@ private Q_SLOTS: blendedClipAnimator.setRunning(true); blendedClipAnimator.setBlendTree(&blendTree); blendedClipAnimator.setChannelMapper(&mapper); - blendedClipAnimator.setLoops(10); + blendedClipAnimator.setLoopCount(10); { // WHEN diff --git a/tests/auto/animation/clipanimator/tst_clipanimator.cpp b/tests/auto/animation/clipanimator/tst_clipanimator.cpp index b5173e56d..615547405 100644 --- a/tests/auto/animation/clipanimator/tst_clipanimator.cpp +++ b/tests/auto/animation/clipanimator/tst_clipanimator.cpp @@ -52,7 +52,7 @@ private Q_SLOTS: auto clip = new Qt3DAnimation::QAnimationClipLoader(); animator.setClip(clip); - animator.setLoops(10); + animator.setLoopCount(10); // WHEN simulateInitialization(&animator, &backendAnimator); @@ -62,7 +62,7 @@ private Q_SLOTS: QCOMPARE(backendAnimator.isEnabled(), animator.isEnabled()); QCOMPARE(backendAnimator.clipId(), clip->id()); QCOMPARE(backendAnimator.isRunning(), animator.isRunning()); - QCOMPARE(backendAnimator.loops(), animator.loops()); + QCOMPARE(backendAnimator.loops(), animator.loopCount()); } void checkInitialAndCleanedUpState() @@ -84,7 +84,7 @@ private Q_SLOTS: auto clip = new Qt3DAnimation::QAnimationClipLoader(); animator.setClip(clip); animator.setRunning(true); - animator.setLoops(25); + animator.setLoopCount(25); // WHEN simulateInitialization(&animator, &backendAnimator); diff --git a/tests/auto/animation/qblendedclipanimator/tst_qblendedclipanimator.cpp b/tests/auto/animation/qblendedclipanimator/tst_qblendedclipanimator.cpp index 3ab8e007b..d25041886 100644 --- a/tests/auto/animation/qblendedclipanimator/tst_qblendedclipanimator.cpp +++ b/tests/auto/animation/qblendedclipanimator/tst_qblendedclipanimator.cpp @@ -60,7 +60,7 @@ private Q_SLOTS: QVERIFY(blendedClipAnimator.blendTree() == nullptr); QVERIFY(blendedClipAnimator.channelMapper() == nullptr); QCOMPARE(blendedClipAnimator.isRunning(), false); - QCOMPARE(blendedClipAnimator.loops(), 1); + QCOMPARE(blendedClipAnimator.loopCount(), 1); } void checkPropertyChanges() @@ -128,21 +128,21 @@ private Q_SLOTS: { // WHEN - QSignalSpy spy(&blendedClipAnimator, SIGNAL(loopsChanged(int))); + QSignalSpy spy(&blendedClipAnimator, SIGNAL(loopCountChanged(int))); const int newValue = 5; - blendedClipAnimator.setLoops(newValue); + blendedClipAnimator.setLoopCount(newValue); // THEN QVERIFY(spy.isValid()); - QCOMPARE(blendedClipAnimator.loops(), newValue); + QCOMPARE(blendedClipAnimator.loopCount(), newValue); QCOMPARE(spy.count(), 1); // WHEN spy.clear(); - blendedClipAnimator.setLoops(newValue); + blendedClipAnimator.setLoopCount(newValue); // THEN - QCOMPARE(blendedClipAnimator.loops(), newValue); + QCOMPARE(blendedClipAnimator.loopCount(), newValue); QCOMPARE(spy.count(), 0); } } @@ -180,7 +180,7 @@ private Q_SLOTS: QCOMPARE(blendedClipAnimator.isEnabled(), true); QCOMPARE(blendedClipAnimator.isEnabled(), creationChangeData->isNodeEnabled()); QCOMPARE(blendedClipAnimator.metaObject(), creationChangeData->metaObject()); - QCOMPARE(blendedClipAnimator.loops(), cloneData.loops); + QCOMPARE(blendedClipAnimator.loopCount(), cloneData.loops); } // WHEN @@ -352,14 +352,14 @@ private Q_SLOTS: { // WHEN - blendedClipAnimator.setLoops(1584); + blendedClipAnimator.setLoopCount(1584); QCoreApplication::processEvents(); // THEN QCOMPARE(arbiter.events.size(), 1); auto change = arbiter.events.first().staticCast(); QCOMPARE(change->propertyName(), "loops"); - QCOMPARE(change->value().value(), blendedClipAnimator.loops()); + QCOMPARE(change->value().value(), blendedClipAnimator.loopCount()); QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); arbiter.events.clear(); @@ -367,7 +367,7 @@ private Q_SLOTS: { // WHEN - blendedClipAnimator.setLoops(1584); + blendedClipAnimator.setLoopCount(1584); QCoreApplication::processEvents(); // THEN diff --git a/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp b/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp index 084e78809..1177be72a 100644 --- a/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp +++ b/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp @@ -59,7 +59,7 @@ private Q_SLOTS: // THEN QCOMPARE(animator.clip(), static_cast(nullptr)); QCOMPARE(animator.channelMapper(), static_cast(nullptr)); - QCOMPARE(animator.loops(), 1); + QCOMPARE(animator.loopCount(), 1); } void checkPropertyChanges() @@ -111,21 +111,21 @@ private Q_SLOTS: { // WHEN - QSignalSpy spy(&animator, SIGNAL(loopsChanged(int))); + QSignalSpy spy(&animator, SIGNAL(loopCountChanged(int))); const int newValue = 5; - animator.setLoops(newValue); + animator.setLoopCount(newValue); // THEN QVERIFY(spy.isValid()); - QCOMPARE(animator.loops(), newValue); + QCOMPARE(animator.loopCount(), newValue); QCOMPARE(spy.count(), 1); // WHEN spy.clear(); - animator.setLoops(newValue); + animator.setLoopCount(newValue); // THEN - QCOMPARE(animator.loops(), newValue); + QCOMPARE(animator.loopCount(), newValue); QCOMPARE(spy.count(), 0); } } @@ -159,7 +159,7 @@ private Q_SLOTS: QCOMPARE(animator.metaObject(), creationChangeData->metaObject()); QCOMPARE(animator.clip()->id(), data.clipId); QCOMPARE(animator.channelMapper()->id(), data.mapperId); - QCOMPARE(animator.loops(), data.loops); + QCOMPARE(animator.loopCount(), data.loops); } // WHEN @@ -242,7 +242,7 @@ private Q_SLOTS: { // WHEN - animator.setLoops(10); + animator.setLoopCount(10); QCoreApplication::processEvents(); // THEN @@ -250,14 +250,14 @@ private Q_SLOTS: auto change = arbiter.events.first().staticCast(); QCOMPARE(change->propertyName(), "loops"); QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - QCOMPARE(change->value().toInt(), animator.loops()); + QCOMPARE(change->value().toInt(), animator.loopCount()); arbiter.events.clear(); } { // WHEN - animator.setLoops(10); + animator.setLoopCount(10); QCoreApplication::processEvents(); // THEN -- cgit v1.2.3 From 1c153ec7ceae331809b504bed7241739bc60e5b2 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Mon, 27 Mar 2017 14:48:28 +0100 Subject: Remove pointless template member function from QAbstractFunctor Use template free function instead. Change-Id: I1171279423f164b877aaef21926ceda512fcbd2e Reviewed-by: Paul Lemire --- tests/auto/render/buffer/tst_buffer.cpp | 2 +- tests/auto/render/geometryrenderer/tst_geometryrenderer.cpp | 2 +- tests/auto/render/meshfunctors/tst_meshfunctors.cpp | 6 +++--- tests/auto/render/qbuffer/tst_qbuffer.cpp | 2 +- tests/auto/render/qgeometryrenderer/tst_qgeometryrenderer.cpp | 2 +- tests/auto/render/textures/tst_textures.cpp | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/buffer/tst_buffer.cpp b/tests/auto/render/buffer/tst_buffer.cpp index b06425bd7..7f7c0adb9 100644 --- a/tests/auto/render/buffer/tst_buffer.cpp +++ b/tests/auto/render/buffer/tst_buffer.cpp @@ -50,7 +50,7 @@ public: bool operator ==(const Qt3DRender::QBufferDataGenerator &other) const Q_DECL_FINAL { - const TestFunctor *otherFunctor = functor_cast(&other); + const TestFunctor *otherFunctor = Qt3DRender::functor_cast(&other); if (otherFunctor != nullptr) return otherFunctor->m_size == m_size; return false; diff --git a/tests/auto/render/geometryrenderer/tst_geometryrenderer.cpp b/tests/auto/render/geometryrenderer/tst_geometryrenderer.cpp index 7cf70c03c..70fe957c5 100644 --- a/tests/auto/render/geometryrenderer/tst_geometryrenderer.cpp +++ b/tests/auto/render/geometryrenderer/tst_geometryrenderer.cpp @@ -51,7 +51,7 @@ public: bool operator ==(const Qt3DRender::QGeometryFactory &other) const Q_DECL_FINAL { - const TestFactory *otherFactory = functor_cast(&other); + const TestFactory *otherFactory = Qt3DRender::functor_cast(&other); if (otherFactory != nullptr) return otherFactory->m_size == m_size; return false; diff --git a/tests/auto/render/meshfunctors/tst_meshfunctors.cpp b/tests/auto/render/meshfunctors/tst_meshfunctors.cpp index 6aef510ea..bf5f0d55f 100644 --- a/tests/auto/render/meshfunctors/tst_meshfunctors.cpp +++ b/tests/auto/render/meshfunctors/tst_meshfunctors.cpp @@ -46,7 +46,7 @@ public: bool operator ==(const Qt3DRender::QGeometryFactory &other) const Q_DECL_OVERRIDE { - return functor_cast(&other); + return Qt3DRender::functor_cast(&other); } QT3D_FUNCTOR(MeshFunctorA) @@ -68,7 +68,7 @@ public: bool operator ==(const Qt3DRender::QGeometryFactory &other) const Q_DECL_OVERRIDE { - return functor_cast(&other); + return Qt3DRender::functor_cast(&other); } QT3D_FUNCTOR(MeshFunctorB) @@ -85,7 +85,7 @@ public: bool operator ==(const Qt3DRender::QGeometryFactory &other) const Q_DECL_OVERRIDE { - return functor_cast(&other); + return Qt3DRender::functor_cast(&other); } QT3D_FUNCTOR(MeshFunctorASub) diff --git a/tests/auto/render/qbuffer/tst_qbuffer.cpp b/tests/auto/render/qbuffer/tst_qbuffer.cpp index a65f27cb6..fdc25cbca 100644 --- a/tests/auto/render/qbuffer/tst_qbuffer.cpp +++ b/tests/auto/render/qbuffer/tst_qbuffer.cpp @@ -51,7 +51,7 @@ public: bool operator ==(const Qt3DRender::QBufferDataGenerator &other) const Q_DECL_FINAL { - const TestFunctor *otherFunctor = functor_cast(&other); + const TestFunctor *otherFunctor = Qt3DRender::functor_cast(&other); if (otherFunctor != nullptr) return otherFunctor->m_size == m_size; return false; diff --git a/tests/auto/render/qgeometryrenderer/tst_qgeometryrenderer.cpp b/tests/auto/render/qgeometryrenderer/tst_qgeometryrenderer.cpp index 76c3288e3..94f720097 100644 --- a/tests/auto/render/qgeometryrenderer/tst_qgeometryrenderer.cpp +++ b/tests/auto/render/qgeometryrenderer/tst_qgeometryrenderer.cpp @@ -58,7 +58,7 @@ public: bool operator ==(const Qt3DRender::QGeometryFactory &other) const Q_DECL_FINAL { - const TestFactory *otherFactory = functor_cast(&other); + const TestFactory *otherFactory = Qt3DRender::functor_cast(&other); if (otherFactory != nullptr) return otherFactory->m_size == m_size; return false; diff --git a/tests/auto/render/textures/tst_textures.cpp b/tests/auto/render/textures/tst_textures.cpp index 58cb76c94..82c638275 100644 --- a/tests/auto/render/textures/tst_textures.cpp +++ b/tests/auto/render/textures/tst_textures.cpp @@ -57,7 +57,7 @@ public: } bool operator ==(const Qt3DRender::QTextureImageDataGenerator &other) const Q_DECL_OVERRIDE { - const TestImageDataGenerator *otherFunctor = functor_cast(&other); + const TestImageDataGenerator *otherFunctor = Qt3DRender::functor_cast(&other); return (otherFunctor != Q_NULLPTR && otherFunctor->m_id == m_id); } @@ -78,7 +78,7 @@ public: } bool operator ==(const Qt3DRender::QTextureGenerator &other) const Q_DECL_OVERRIDE { - const TestTextureGenerator *otherFunctor = functor_cast(&other); + const TestTextureGenerator *otherFunctor = Qt3DRender::functor_cast(&other); return (otherFunctor != Q_NULLPTR && otherFunctor->m_id == m_id); } -- cgit v1.2.3 From c70a1d339e17c7fa12ee88d40b1455f07b254405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tony=20Saraj=C3=A4rvi?= Date: Thu, 30 Mar 2017 15:40:13 +0300 Subject: Blacklist tst_GraphicsHelperGL3_3::blitFramebuffer on Ubuntu 16.04 Task-number: QTBUG-59828 Change-Id: I5fc74639dc9bffcccdfc42655656ba37822ae07c Reviewed-by: Liang Qi --- tests/auto/render/graphicshelpergl3_3/BLACKLIST | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tests/auto/render/graphicshelpergl3_3/BLACKLIST (limited to 'tests/auto') diff --git a/tests/auto/render/graphicshelpergl3_3/BLACKLIST b/tests/auto/render/graphicshelpergl3_3/BLACKLIST new file mode 100644 index 000000000..1d6233cd7 --- /dev/null +++ b/tests/auto/render/graphicshelpergl3_3/BLACKLIST @@ -0,0 +1,2 @@ +[blitFramebuffer] +ubuntu-16.04 -- cgit v1.2.3 From 4558cfc5e0cfabcebf7f6c153dcc44eff5d7bb61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tony=20Saraj=C3=A4rvi?= Date: Tue, 4 Apr 2017 12:13:00 +0300 Subject: Blacklist tst_GraphicsHelperGL3_2::blitFramebuffer on Ubuntu 16.04 Task-number: QTBUG-59921 Change-Id: I2385f5079adf91d6ced64470dfa90d8f654d0f35 Reviewed-by: Liang Qi --- tests/auto/render/graphicshelpergl3_2/BLACKLIST | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tests/auto/render/graphicshelpergl3_2/BLACKLIST (limited to 'tests/auto') diff --git a/tests/auto/render/graphicshelpergl3_2/BLACKLIST b/tests/auto/render/graphicshelpergl3_2/BLACKLIST new file mode 100644 index 000000000..1d6233cd7 --- /dev/null +++ b/tests/auto/render/graphicshelpergl3_2/BLACKLIST @@ -0,0 +1,2 @@ +[blitFramebuffer] +ubuntu-16.04 -- cgit v1.2.3 From ac79513c9a78be998b150121bd6d3ae26ace7735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tony=20Saraj=C3=A4rvi?= Date: Tue, 4 Apr 2017 14:13:28 +0300 Subject: Blacklist a tst_VSyncFrameAdvanceService test on openSUSE 42.1 Task-number: QTBUG-56576 Change-Id: I7ad2367de7d5dc855a2493832db99dc1b9c4c070 Reviewed-by: Liang Qi --- tests/auto/render/vsyncframeadvanceservice/BLACKLIST | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tests/auto/render/vsyncframeadvanceservice/BLACKLIST (limited to 'tests/auto') diff --git a/tests/auto/render/vsyncframeadvanceservice/BLACKLIST b/tests/auto/render/vsyncframeadvanceservice/BLACKLIST new file mode 100644 index 000000000..34dccc8fe --- /dev/null +++ b/tests/auto/render/vsyncframeadvanceservice/BLACKLIST @@ -0,0 +1,2 @@ +[checkSynchronisation] +opensuse-42.1 -- cgit v1.2.3 From 8eee273390f9b0d91cb805f1fa7cb51be4717c2b Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 7 Apr 2017 14:40:51 +0100 Subject: Use interpolation enum from QKeyFrame No point in duplicating this on the backend just for the sake of it. Change-Id: I1852f7f22d5519b260ed90adce3715ab4257df61 Reviewed-by: Mike Krus --- tests/auto/animation/bezierevaluator/tst_bezierevaluator.cpp | 9 +++++---- tests/auto/animation/fcurve/tst_fcurve.cpp | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/bezierevaluator/tst_bezierevaluator.cpp b/tests/auto/animation/bezierevaluator/tst_bezierevaluator.cpp index 746af8d55..5dc971ab7 100644 --- a/tests/auto/animation/bezierevaluator/tst_bezierevaluator.cpp +++ b/tests/auto/animation/bezierevaluator/tst_bezierevaluator.cpp @@ -35,6 +35,7 @@ Q_DECLARE_METATYPE(Qt3DAnimation::Animation::Keyframe) +using namespace Qt3DAnimation; using namespace Qt3DAnimation::Animation; class tst_BezierEvaluator : public QObject @@ -131,9 +132,9 @@ private Q_SLOTS: QTest::addColumn>("bezierParamters"); float t0 = 0.0f; - Keyframe kf0{0.0f, {-5.0f, 0.0f}, {5.0f, 0.0f}, Keyframe::Bezier}; + Keyframe kf0{0.0f, {-5.0f, 0.0f}, {5.0f, 0.0f}, QKeyFrame::BezierInterpolation}; float t1 = 50.0f; - Keyframe kf1{5.0f, {45.0f, 5.0f}, {55.0f, 5.0f}, Keyframe::Bezier}; + Keyframe kf1{5.0f, {45.0f, 5.0f}, {55.0f, 5.0f}, QKeyFrame::BezierInterpolation}; const int count = 21; QVector times = (QVector() << 0.0f @@ -199,9 +200,9 @@ private Q_SLOTS: QTest::addColumn>("values"); float t0 = 0.0f; - Keyframe kf0{0.0f, {-5.0f, 0.0f}, {5.0f, 0.0f}, Keyframe::Bezier}; + Keyframe kf0{0.0f, {-5.0f, 0.0f}, {5.0f, 0.0f}, QKeyFrame::BezierInterpolation}; float t1 = 50.0f; - Keyframe kf1{5.0f, {45.0f, 5.0f}, {55.0f, 5.0f}, Keyframe::Bezier}; + Keyframe kf1{5.0f, {45.0f, 5.0f}, {55.0f, 5.0f}, QKeyFrame::BezierInterpolation}; QVector times = (QVector() << 0.0f << 1.00375f diff --git a/tests/auto/animation/fcurve/tst_fcurve.cpp b/tests/auto/animation/fcurve/tst_fcurve.cpp index 8cd8b9537..e3e8db50d 100644 --- a/tests/auto/animation/fcurve/tst_fcurve.cpp +++ b/tests/auto/animation/fcurve/tst_fcurve.cpp @@ -29,6 +29,7 @@ #include #include +using namespace Qt3DAnimation; using namespace Qt3DAnimation::Animation; class tst_FCurve : public QObject @@ -53,7 +54,7 @@ private Q_SLOTS: FCurve fcurve; // WHEN - const Keyframe kf0{0.0f, {-5.0f, 0.0f}, {5.0f, 0.0f}, Keyframe::Bezier}; + const Keyframe kf0{0.0f, {-5.0f, 0.0f}, {5.0f, 0.0f}, QKeyFrame::BezierInterpolation}; fcurve.appendKeyframe(0.0f, kf0); // THEN @@ -62,7 +63,7 @@ private Q_SLOTS: QCOMPARE(fcurve.endTime(), 0.0f); // WHEN - const Keyframe kf1{5.0f, {45.0f, 5.0f}, {55.0f, 5.0f}, Keyframe::Bezier}; + const Keyframe kf1{5.0f, {45.0f, 5.0f}, {55.0f, 5.0f}, QKeyFrame::BezierInterpolation}; fcurve.appendKeyframe(50.0f, kf1); // THEN @@ -77,8 +78,8 @@ private Q_SLOTS: { // GIVEN FCurve fcurve; - fcurve.appendKeyframe(0.0f, Keyframe{0.0f, {-5.0f, 0.0f}, {5.0f, 0.0f}, Keyframe::Bezier}); - fcurve.appendKeyframe(50.0f, Keyframe{5.0f, {45.0f, 5.0f}, {55.0f, 5.0f}, Keyframe::Bezier}); + fcurve.appendKeyframe(0.0f, Keyframe{0.0f, {-5.0f, 0.0f}, {5.0f, 0.0f}, QKeyFrame::BezierInterpolation}); + fcurve.appendKeyframe(50.0f, Keyframe{5.0f, {45.0f, 5.0f}, {55.0f, 5.0f}, QKeyFrame::BezierInterpolation}); // WHEN fcurve.clearKeyframes(); -- cgit v1.2.3 From 8c245b73cfacd78c664bc6dd8779b001fa769dfc Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Wed, 12 Apr 2017 09:26:52 +0100 Subject: =?UTF-8?q?Picking:=20don=E2=80=99t=20emit=20click=20if=20mouse=20?= =?UTF-8?q?released=20on=20different=20entity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-59582 Change-Id: I88e49add59d1caa3167576c8f0c014dd61211f29 Reviewed-by: Sean Harmer --- .../render/pickboundingvolumejob/tst_pickboundingvolumejob.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/pickboundingvolumejob/tst_pickboundingvolumejob.cpp b/tests/auto/render/pickboundingvolumejob/tst_pickboundingvolumejob.cpp index 5ebf10338..07055d810 100644 --- a/tests/auto/render/pickboundingvolumejob/tst_pickboundingvolumejob.cpp +++ b/tests/auto/render/pickboundingvolumejob/tst_pickboundingvolumejob.cpp @@ -809,13 +809,13 @@ private Q_SLOTS: QVERIFY(!backendPicker1->isPressed()); QCOMPARE(arbiter.events.count(), 2); change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "clicked"); + QCOMPARE(change->propertyName(), "released"); pickEvent = change->value().value(); QVERIFY(pickEvent); if (pickMethod == Qt3DRender::QPickingSettings::TrianglePicking) QVERIFY(pickEvent.dynamicCast()); change = arbiter.events.last().staticCast(); - QCOMPARE(change->propertyName(), "released"); + QCOMPARE(change->propertyName(), "clicked"); pickEvent = change->value().value(); QVERIFY(pickEvent); if (pickMethod == Qt3DRender::QPickingSettings::TrianglePicking) @@ -1034,9 +1034,9 @@ private Q_SLOTS: QVERIFY(!backendPicker->isPressed()); QCOMPARE(arbiter.events.count(), 2); change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "clicked"); - change = arbiter.events.last().staticCast(); QCOMPARE(change->propertyName(), "released"); + change = arbiter.events.last().staticCast(); + QCOMPARE(change->propertyName(), "clicked"); arbiter.events.clear(); -- cgit v1.2.3 From 90667286d9ab851f6735fc53dd7aaa3881167b3d Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 7 Apr 2017 15:32:04 +0100 Subject: Add a flag to AnimationClipLoader to track where its data comes from Nicer than implicitly tracking it via m_source.isEmpty(). Change-Id: I120cb3728504b2bbc77d5959711a3f94731399ce Reviewed-by: Mike Krus --- tests/auto/animation/animationcliploader/tst_animationcliploader.cpp | 1 + tests/auto/animation/animationutils/tst_animationutils.cpp | 5 +++++ 2 files changed, 6 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp b/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp index 35c0d5e54..09798e7d6 100644 --- a/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp +++ b/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp @@ -97,6 +97,7 @@ private Q_SLOTS: Qt3DAnimation::Animation::AnimationClipLoader backendClip; Qt3DAnimation::Animation::Handler handler; backendClip.setHandler(&handler); + backendClip.setDataType(Qt3DAnimation::Animation::AnimationClipLoader::File); Qt3DCore::QPropertyUpdatedChangePtr updateChange; // WHEN diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 17815f5db..282ceb829 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -163,6 +163,7 @@ public: auto clipId = Qt3DCore::QNodeId::createId(); AnimationClipLoader *clip = handler->animationClipLoaderManager()->getOrCreateResource(clipId); setPeerId(clip, clipId); + clip->setDataType(AnimationClipLoader::File); clip->setSource(source); clip->loadAnimation(); return clip; @@ -2367,6 +2368,7 @@ private Q_SLOTS: targetIndices.push_back({ 11 }); auto *clip = new AnimationClipLoader(); + clip->setDataType(AnimationClipLoader::File); clip->setSource(QUrl("qrc:/clip3.json")); clip->loadAnimation(); @@ -2396,6 +2398,7 @@ private Q_SLOTS: targetIndices.push_back({ 11 }); auto *clip = new AnimationClipLoader(); + clip->setDataType(AnimationClipLoader::File); clip->setSource(QUrl("qrc:/clip3.json")); clip->loadAnimation(); @@ -2425,6 +2428,7 @@ private Q_SLOTS: targetIndices.push_back({ 11 }); auto *clip = new AnimationClipLoader(); + clip->setDataType(AnimationClipLoader::File); clip->setSource(QUrl("qrc:/clip3.json")); clip->loadAnimation(); @@ -2454,6 +2458,7 @@ private Q_SLOTS: targetIndices.push_back({ 11 }); auto *clip = new AnimationClipLoader(); + clip->setDataType(AnimationClipLoader::File); clip->setSource(QUrl("qrc:/clip3.json")); clip->loadAnimation(); -- cgit v1.2.3 From 7fccf4f96efab3daaeef7fceceaeea776b50ff0a Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 7 Apr 2017 16:40:55 +0100 Subject: Rename AnimationClipLoader to AnimationClip It handles both loadign from file and from data constructed using the public API. Change-Id: Ic9e71dc60c36869548323312f7129df6c9edd763 Reviewed-by: Mike Krus --- tests/auto/animation/animation.pro | 2 +- .../auto/animation/animationclip/animationclip.pro | 12 ++ .../animation/animationclip/tst_animationclip.cpp | 190 +++++++++++++++++++++ .../animationcliploader/animationcliploader.pro | 12 -- .../tst_animationcliploader.cpp | 190 --------------------- .../animationutils/tst_animationutils.cpp | 52 +++--- .../clipblendvalue/tst_clipblendvalue.cpp | 4 +- .../animation/qclipanimator/tst_qclipanimator.cpp | 2 +- 8 files changed, 232 insertions(+), 232 deletions(-) create mode 100644 tests/auto/animation/animationclip/animationclip.pro create mode 100644 tests/auto/animation/animationclip/tst_animationclip.cpp delete mode 100644 tests/auto/animation/animationcliploader/animationcliploader.pro delete mode 100644 tests/auto/animation/animationcliploader/tst_animationcliploader.cpp (limited to 'tests/auto') diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index eeb9a70af..969f477e7 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -11,7 +11,7 @@ SUBDIRS += \ qtConfig(private_tests) { SUBDIRS += \ - animationcliploader \ + animationclip \ fcurve \ functionrangefinder \ bezierevaluator \ diff --git a/tests/auto/animation/animationclip/animationclip.pro b/tests/auto/animation/animationclip/animationclip.pro new file mode 100644 index 000000000..09d9f2523 --- /dev/null +++ b/tests/auto/animation/animationclip/animationclip.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_animationclip + +QT += core-private 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += \ + tst_animationclip.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/animationclip/tst_animationclip.cpp b/tests/auto/animation/animationclip/tst_animationclip.cpp new file mode 100644 index 000000000..96a004804 --- /dev/null +++ b/tests/auto/animation/animationclip/tst_animationclip.cpp @@ -0,0 +1,190 @@ +/**************************************************************************** +** +** 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: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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class tst_AnimationClip : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private Q_SLOTS: + void checkPeerPropertyMirroring() + { + // GIVEN + Qt3DAnimation::Animation::AnimationClip backendClip; + Qt3DAnimation::Animation::Handler handler; + backendClip.setHandler(&handler); + Qt3DAnimation::QAnimationClipLoader clip; + + clip.setSource(QUrl::fromLocalFile("walk.qlip")); + + // WHEN + simulateInitialization(&clip, &backendClip); + + // THEN + QCOMPARE(backendClip.peerId(), clip.id()); + QCOMPARE(backendClip.isEnabled(), clip.isEnabled()); + QCOMPARE(backendClip.source(), clip.source()); + } + + void checkInitialAndCleanedUpState() + { + // GIVEN + Qt3DAnimation::Animation::AnimationClip backendClip; + Qt3DAnimation::Animation::Handler handler; + backendClip.setHandler(&handler); + + // THEN + QVERIFY(backendClip.peerId().isNull()); + QCOMPARE(backendClip.isEnabled(), false); + QCOMPARE(backendClip.source(), QUrl()); + QCOMPARE(backendClip.duration(), 0.0f); + QCOMPARE(backendClip.status(), Qt3DAnimation::QAnimationClipLoader::NotReady); + + // GIVEN + Qt3DAnimation::QAnimationClipLoader clip; + clip.setSource(QUrl::fromLocalFile("walk.qlip")); + + // WHEN + simulateInitialization(&clip, &backendClip); + backendClip.setSource(QUrl::fromLocalFile("run.qlip")); + backendClip.cleanup(); + + // THEN + QCOMPARE(backendClip.source(), QUrl()); + QCOMPARE(backendClip.isEnabled(), false); + QCOMPARE(backendClip.duration(), 0.0f); + QCOMPARE(backendClip.status(), Qt3DAnimation::QAnimationClipLoader::NotReady); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::Animation::AnimationClip backendClip; + Qt3DAnimation::Animation::Handler handler; + backendClip.setHandler(&handler); + backendClip.setDataType(Qt3DAnimation::Animation::AnimationClip::File); + Qt3DCore::QPropertyUpdatedChangePtr updateChange; + + // WHEN + updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); + updateChange->setPropertyName("enabled"); + updateChange->setValue(true); + backendClip.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backendClip.isEnabled(), true); + + // WHEN + const QUrl newSource = QUrl::fromLocalFile("fallover.qlip"); + updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); + updateChange->setPropertyName("source"); + updateChange->setValue(newSource); + backendClip.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backendClip.source(), newSource); + } + + void checkDurationPropertyBackendNotification() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::Animation::AnimationClip backendClip; + backendClip.setEnabled(true); + Qt3DCore::QBackendNodePrivate::get(&backendClip)->setArbiter(&arbiter); + + // WHEN + backendClip.setDuration(64.0f); + + // THEN + QCOMPARE(backendClip.duration(), 64.0f); + QCOMPARE(arbiter.events.count(), 1); + Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "duration"); + QCOMPARE(change->value().toFloat(), backendClip.duration()); + QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isIntermediate, + false); + + arbiter.events.clear(); + + // WHEN + backendClip.setDuration(64.0f); + + // THEN + QCOMPARE(backendClip.duration(), 64.0f); + QCOMPARE(arbiter.events.count(), 0); + + arbiter.events.clear(); + } + + void checkStatusPropertyBackendNotification() + { + // GIVEN + TestArbiter arbiter; + Qt3DAnimation::Animation::AnimationClip backendClip; + backendClip.setEnabled(true); + Qt3DCore::QBackendNodePrivate::get(&backendClip)->setArbiter(&arbiter); + + // WHEN + backendClip.setStatus(Qt3DAnimation::QAnimationClipLoader::Error); + + // THEN + QCOMPARE(backendClip.status(), Qt3DAnimation::QAnimationClipLoader::Error); + QCOMPARE(arbiter.events.count(), 1); + Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "status"); + QCOMPARE(change->value().value(), backendClip.status()); + QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isIntermediate, + false); + + arbiter.events.clear(); + + // WHEN + backendClip.setStatus(Qt3DAnimation::QAnimationClipLoader::Error); + + // THEN + QCOMPARE(backendClip.status(), Qt3DAnimation::QAnimationClipLoader::Error); + QCOMPARE(arbiter.events.count(), 0); + + arbiter.events.clear(); + } +}; + +QTEST_APPLESS_MAIN(tst_AnimationClip) + +#include "tst_animationclip.moc" diff --git a/tests/auto/animation/animationcliploader/animationcliploader.pro b/tests/auto/animation/animationcliploader/animationcliploader.pro deleted file mode 100644 index b1bc6dbcc..000000000 --- a/tests/auto/animation/animationcliploader/animationcliploader.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = app - -TARGET = tst_animationcliploader - -QT += core-private 3dcore 3dcore-private 3danimation 3danimation-private testlib - -CONFIG += testcase - -SOURCES += \ - tst_animationcliploader.cpp - -include(../../core/common/common.pri) diff --git a/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp b/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp deleted file mode 100644 index 09798e7d6..000000000 --- a/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/**************************************************************************** -** -** 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: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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class tst_AnimationClipLoader: public Qt3DCore::QBackendNodeTester -{ - Q_OBJECT - -private Q_SLOTS: - void checkPeerPropertyMirroring() - { - // GIVEN - Qt3DAnimation::Animation::AnimationClipLoader backendClip; - Qt3DAnimation::Animation::Handler handler; - backendClip.setHandler(&handler); - Qt3DAnimation::QAnimationClipLoader clip; - - clip.setSource(QUrl::fromLocalFile("walk.qlip")); - - // WHEN - simulateInitialization(&clip, &backendClip); - - // THEN - QCOMPARE(backendClip.peerId(), clip.id()); - QCOMPARE(backendClip.isEnabled(), clip.isEnabled()); - QCOMPARE(backendClip.source(), clip.source()); - } - - void checkInitialAndCleanedUpState() - { - // GIVEN - Qt3DAnimation::Animation::AnimationClipLoader backendClip; - Qt3DAnimation::Animation::Handler handler; - backendClip.setHandler(&handler); - - // THEN - QVERIFY(backendClip.peerId().isNull()); - QCOMPARE(backendClip.isEnabled(), false); - QCOMPARE(backendClip.source(), QUrl()); - QCOMPARE(backendClip.duration(), 0.0f); - QCOMPARE(backendClip.status(), Qt3DAnimation::QAnimationClipLoader::NotReady); - - // GIVEN - Qt3DAnimation::QAnimationClipLoader clip; - clip.setSource(QUrl::fromLocalFile("walk.qlip")); - - // WHEN - simulateInitialization(&clip, &backendClip); - backendClip.setSource(QUrl::fromLocalFile("run.qlip")); - backendClip.cleanup(); - - // THEN - QCOMPARE(backendClip.source(), QUrl()); - QCOMPARE(backendClip.isEnabled(), false); - QCOMPARE(backendClip.duration(), 0.0f); - QCOMPARE(backendClip.status(), Qt3DAnimation::QAnimationClipLoader::NotReady); - } - - void checkPropertyChanges() - { - // GIVEN - Qt3DAnimation::Animation::AnimationClipLoader backendClip; - Qt3DAnimation::Animation::Handler handler; - backendClip.setHandler(&handler); - backendClip.setDataType(Qt3DAnimation::Animation::AnimationClipLoader::File); - Qt3DCore::QPropertyUpdatedChangePtr updateChange; - - // WHEN - updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); - updateChange->setPropertyName("enabled"); - updateChange->setValue(true); - backendClip.sceneChangeEvent(updateChange); - - // THEN - QCOMPARE(backendClip.isEnabled(), true); - - // WHEN - const QUrl newSource = QUrl::fromLocalFile("fallover.qlip"); - updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); - updateChange->setPropertyName("source"); - updateChange->setValue(newSource); - backendClip.sceneChangeEvent(updateChange); - - // THEN - QCOMPARE(backendClip.source(), newSource); - } - - void checkDurationPropertyBackendNotification() - { - // GIVEN - TestArbiter arbiter; - Qt3DAnimation::Animation::AnimationClipLoader backendClip; - backendClip.setEnabled(true); - Qt3DCore::QBackendNodePrivate::get(&backendClip)->setArbiter(&arbiter); - - // WHEN - backendClip.setDuration(64.0f); - - // THEN - QCOMPARE(backendClip.duration(), 64.0f); - QCOMPARE(arbiter.events.count(), 1); - Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "duration"); - QCOMPARE(change->value().toFloat(), backendClip.duration()); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isIntermediate, - false); - - arbiter.events.clear(); - - // WHEN - backendClip.setDuration(64.0f); - - // THEN - QCOMPARE(backendClip.duration(), 64.0f); - QCOMPARE(arbiter.events.count(), 0); - - arbiter.events.clear(); - } - - void checkStatusPropertyBackendNotification() - { - // GIVEN - TestArbiter arbiter; - Qt3DAnimation::Animation::AnimationClipLoader backendClip; - backendClip.setEnabled(true); - Qt3DCore::QBackendNodePrivate::get(&backendClip)->setArbiter(&arbiter); - - // WHEN - backendClip.setStatus(Qt3DAnimation::QAnimationClipLoader::Error); - - // THEN - QCOMPARE(backendClip.status(), Qt3DAnimation::QAnimationClipLoader::Error); - QCOMPARE(arbiter.events.count(), 1); - Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "status"); - QCOMPARE(change->value().value(), backendClip.status()); - QCOMPARE(Qt3DCore::QPropertyUpdatedChangeBasePrivate::get(change.data())->m_isIntermediate, - false); - - arbiter.events.clear(); - - // WHEN - backendClip.setStatus(Qt3DAnimation::QAnimationClipLoader::Error); - - // THEN - QCOMPARE(backendClip.status(), Qt3DAnimation::QAnimationClipLoader::Error); - QCOMPARE(arbiter.events.count(), 0); - - arbiter.events.clear(); - } -}; - -QTEST_APPLESS_MAIN(tst_AnimationClipLoader) - -#include "tst_animationcliploader.moc" diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index 282ceb829..ac4fb6fa0 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -27,7 +27,7 @@ ****************************************************************************/ #include -#include +#include #include #include #include @@ -51,7 +51,7 @@ using namespace Qt3DAnimation::Animation; Q_DECLARE_METATYPE(Qt3DAnimation::Animation::Handler*) Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(ChannelMapper *) -Q_DECLARE_METATYPE(AnimationClipLoader *) +Q_DECLARE_METATYPE(AnimationClip *) Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(Channel) @@ -157,13 +157,13 @@ public: return channelMapper; } - AnimationClipLoader *createAnimationClipLoader(Handler *handler, + AnimationClip *createAnimationClipLoader(Handler *handler, const QUrl &source) { auto clipId = Qt3DCore::QNodeId::createId(); - AnimationClipLoader *clip = handler->animationClipLoaderManager()->getOrCreateResource(clipId); + AnimationClip *clip = handler->animationClipLoaderManager()->getOrCreateResource(clipId); setPeerId(clip, clipId); - clip->setDataType(AnimationClipLoader::File); + clip->setDataType(AnimationClip::File); clip->setSource(source); clip->loadAnimation(); return clip; @@ -243,7 +243,7 @@ private Q_SLOTS: QTest::addColumn("handler"); QTest::addColumn>("channelMappings"); QTest::addColumn("channelMapper"); - QTest::addColumn("clip"); + QTest::addColumn("clip"); QTest::addColumn>("expectedMappingData"); auto handler = new Handler; @@ -283,7 +283,7 @@ private Q_SLOTS: QFETCH(Handler *, handler); QFETCH(QVector, channelMappings); QFETCH(ChannelMapper *, channelMapper); - QFETCH(AnimationClipLoader *, clip); + QFETCH(AnimationClip *, clip); QFETCH(QVector, expectedMappingData); // WHEN @@ -1079,12 +1079,12 @@ private Q_SLOTS: void checkEvaluateClipAtLocalTime_data() { QTest::addColumn("handler"); - QTest::addColumn("clip"); + QTest::addColumn("clip"); QTest::addColumn("localTime"); QTest::addColumn("expectedResults"); Handler *handler; - AnimationClipLoader *clip; + AnimationClip *clip; float localTime; ClipResults expectedResults; @@ -1163,7 +1163,7 @@ private Q_SLOTS: { // GIVEN QFETCH(Handler *, handler); - QFETCH(AnimationClipLoader *, clip); + QFETCH(AnimationClip *, clip); QFETCH(float, localTime); QFETCH(ClipResults, expectedResults); @@ -1186,12 +1186,12 @@ private Q_SLOTS: void checkEvaluateClipAtPhase_data() { QTest::addColumn("handler"); - QTest::addColumn("clip"); + QTest::addColumn("clip"); QTest::addColumn("phase"); QTest::addColumn("expectedResults"); Handler *handler; - AnimationClipLoader *clip; + AnimationClip *clip; float phase; ClipResults expectedResults; @@ -1270,7 +1270,7 @@ private Q_SLOTS: { // GIVEN QFETCH(Handler *, handler); - QFETCH(AnimationClipLoader *, clip); + QFETCH(AnimationClip *, clip); QFETCH(float, phase); QFETCH(ClipResults, expectedResults); @@ -1580,12 +1580,12 @@ private Q_SLOTS: void checkEvaluationDataForClip_data() { QTest::addColumn("handler"); - QTest::addColumn("clip"); + QTest::addColumn("clip"); QTest::addColumn("animatorData"); QTest::addColumn("expectedClipData"); Handler *handler; - AnimationClipLoader *clip; + AnimationClip *clip; AnimatorEvaluationData animatorData; ClipEvaluationData clipData; @@ -1678,7 +1678,7 @@ private Q_SLOTS: { // GIVEN QFETCH(Handler *, handler); - QFETCH(AnimationClipLoader *, clip); + QFETCH(AnimationClip *, clip); QFETCH(AnimatorEvaluationData, animatorData); QFETCH(ClipEvaluationData, expectedClipData); @@ -2349,7 +2349,7 @@ private Q_SLOTS: { QTest::addColumn>("targetChannels"); QTest::addColumn>("targetIndices"); - QTest::addColumn("clip"); + QTest::addColumn("clip"); QTest::addColumn("expectedResults"); { @@ -2367,8 +2367,8 @@ private Q_SLOTS: targetIndices.push_back({ 10 }); targetIndices.push_back({ 11 }); - auto *clip = new AnimationClipLoader(); - clip->setDataType(AnimationClipLoader::File); + auto *clip = new AnimationClip(); + clip->setDataType(AnimationClip::File); clip->setSource(QUrl("qrc:/clip3.json")); clip->loadAnimation(); @@ -2397,8 +2397,8 @@ private Q_SLOTS: targetIndices.push_back({ 10 }); targetIndices.push_back({ 11 }); - auto *clip = new AnimationClipLoader(); - clip->setDataType(AnimationClipLoader::File); + auto *clip = new AnimationClip(); + clip->setDataType(AnimationClip::File); clip->setSource(QUrl("qrc:/clip3.json")); clip->loadAnimation(); @@ -2427,8 +2427,8 @@ private Q_SLOTS: targetIndices.push_back({ 10 }); targetIndices.push_back({ 11 }); - auto *clip = new AnimationClipLoader(); - clip->setDataType(AnimationClipLoader::File); + auto *clip = new AnimationClip(); + clip->setDataType(AnimationClip::File); clip->setSource(QUrl("qrc:/clip3.json")); clip->loadAnimation(); @@ -2457,8 +2457,8 @@ private Q_SLOTS: targetIndices.push_back({ 10 }); targetIndices.push_back({ 11 }); - auto *clip = new AnimationClipLoader(); - clip->setDataType(AnimationClipLoader::File); + auto *clip = new AnimationClip(); + clip->setDataType(AnimationClip::File); clip->setSource(QUrl("qrc:/clip3.json")); clip->loadAnimation(); @@ -2478,7 +2478,7 @@ private Q_SLOTS: // GIVEN QFETCH(QVector, targetChannels); QFETCH(QVector, targetIndices); - QFETCH(AnimationClipLoader *, clip); + QFETCH(AnimationClip *, clip); QFETCH(ComponentIndices, expectedResults); // WHEN diff --git a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp index eba5c600e..6fe2846b8 100644 --- a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp +++ b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp @@ -46,11 +46,11 @@ class tst_ClipBlendValue : public Qt3DCore::QBackendNodeTester { Q_OBJECT public: - AnimationClipLoader *createAnimationClipLoader(Handler *handler, + AnimationClip *createAnimationClipLoader(Handler *handler, double duration) { auto clipId = Qt3DCore::QNodeId::createId(); - AnimationClipLoader *clip = handler->animationClipLoaderManager()->getOrCreateResource(clipId); + AnimationClip *clip = handler->animationClipLoaderManager()->getOrCreateResource(clipId); setPeerId(clip, clipId); clip->setDuration(duration); return clip; diff --git a/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp b/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp index 1177be72a..1ed4b8f13 100644 --- a/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp +++ b/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include -- cgit v1.2.3 From 7b204be06203df2df3c98b7aff9b831aa9f8c59a Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 7 Apr 2017 16:44:06 +0100 Subject: Use using namespace declaration to animation clip unit test Reduces the noise. Change-Id: Icb7eea31b140c4f5380b99ba67f0b9f5519faab6 Reviewed-by: Mike Krus --- .../auto/animation/animationclip/tst_animationclip.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/animationclip/tst_animationclip.cpp b/tests/auto/animation/animationclip/tst_animationclip.cpp index 96a004804..61c55d36e 100644 --- a/tests/auto/animation/animationclip/tst_animationclip.cpp +++ b/tests/auto/animation/animationclip/tst_animationclip.cpp @@ -37,6 +37,8 @@ #include #include +using namespace Qt3DAnimation::Animation; + class tst_AnimationClip : public Qt3DCore::QBackendNodeTester { Q_OBJECT @@ -45,8 +47,8 @@ private Q_SLOTS: void checkPeerPropertyMirroring() { // GIVEN - Qt3DAnimation::Animation::AnimationClip backendClip; - Qt3DAnimation::Animation::Handler handler; + AnimationClip backendClip; + Handler handler; backendClip.setHandler(&handler); Qt3DAnimation::QAnimationClipLoader clip; @@ -64,8 +66,8 @@ private Q_SLOTS: void checkInitialAndCleanedUpState() { // GIVEN - Qt3DAnimation::Animation::AnimationClip backendClip; - Qt3DAnimation::Animation::Handler handler; + AnimationClip backendClip; + Handler handler; backendClip.setHandler(&handler); // THEN @@ -94,8 +96,8 @@ private Q_SLOTS: void checkPropertyChanges() { // GIVEN - Qt3DAnimation::Animation::AnimationClip backendClip; - Qt3DAnimation::Animation::Handler handler; + AnimationClip backendClip; + Handler handler; backendClip.setHandler(&handler); backendClip.setDataType(Qt3DAnimation::Animation::AnimationClip::File); Qt3DCore::QPropertyUpdatedChangePtr updateChange; @@ -124,7 +126,7 @@ private Q_SLOTS: { // GIVEN TestArbiter arbiter; - Qt3DAnimation::Animation::AnimationClip backendClip; + AnimationClip backendClip; backendClip.setEnabled(true); Qt3DCore::QBackendNodePrivate::get(&backendClip)->setArbiter(&arbiter); @@ -156,7 +158,7 @@ private Q_SLOTS: { // GIVEN TestArbiter arbiter; - Qt3DAnimation::Animation::AnimationClip backendClip; + AnimationClip backendClip; backendClip.setEnabled(true); Qt3DCore::QBackendNodePrivate::get(&backendClip)->setArbiter(&arbiter); -- cgit v1.2.3 From ba060af041dc866c80f89b64a2bf87d6085f995f Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 18 Apr 2017 14:34:55 +0200 Subject: tst_GraphicsHelperGL3_3::blitFramebuffer(): check how many samples are supported We can't just generate a multisampled 2D texture with 4 samples per texel; we need to check the implementation-defined maximum amount of samples. Lacking glGetInternalformat*, query GL_MAX_SAMPLES. Since OpenGL does not mandate a minimum, getting 0 is actually allowed; glTexImage2DMultisample however does not accept 0 as number of samples, hence skip the test in that case. Change-Id: Id1b0c9705aed0665093aae44983eac8b656b676f Task-number: QTBUG-59828 Reviewed-by: Sean Harmer --- tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp b/tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp index 293750dbf..58c12fcc9 100644 --- a/tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp +++ b/tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp @@ -1967,6 +1967,11 @@ private Q_SLOTS: if (!m_initializationSuccessful) QSKIP("Initialization failed, OpenGL 3.3 Core functions not supported"); + GLint maxSamples; + m_func->glGetIntegerv(GL_MAX_SAMPLES, &maxSamples); + if (maxSamples < 1) + QSKIP("This test requires an implementation that supports multisampled textures"); + // GIVEN GLuint fbos[2]; GLuint fboTextures[2]; @@ -1975,7 +1980,7 @@ private Q_SLOTS: m_func->glGenTextures(2, fboTextures); m_func->glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, fboTextures[0]); - m_func->glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA8, 10, 10, true); + m_func->glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, maxSamples, GL_RGBA8, 10, 10, true); m_func->glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); m_func->glBindTexture(GL_TEXTURE_2D, fboTextures[1]); -- cgit v1.2.3 From 50712f797527b6519ec22e5f1a4b5a939152c798 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 18 Apr 2017 14:34:55 +0200 Subject: tst_GraphicsHelperGL3_3: remove blacklist of blitFramebuffer Got fixed in the meanwhile. Change-Id: I3efccd988b39b77bebab628bbf637b302a247cef Task-number: QTBUG-59828 Reviewed-by: Sean Harmer --- tests/auto/render/graphicshelpergl3_3/BLACKLIST | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 tests/auto/render/graphicshelpergl3_3/BLACKLIST (limited to 'tests/auto') diff --git a/tests/auto/render/graphicshelpergl3_3/BLACKLIST b/tests/auto/render/graphicshelpergl3_3/BLACKLIST deleted file mode 100644 index 1d6233cd7..000000000 --- a/tests/auto/render/graphicshelpergl3_3/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[blitFramebuffer] -ubuntu-16.04 -- cgit v1.2.3 From 30abb904d42de5423749170c0de6e497d2aaf76e Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 18 Apr 2017 15:40:16 +0200 Subject: tst_GraphicsHelperGL3_2::blitFramebuffer(): check how many samples are supported Apply the same fix as tst_GraphicsHelperGL3_3. Unblacklist the test, since it now passes. Change-Id: I72bde506c3c6c802ed30acf40e10013f01e69de3 Task-number: QTBUG-59921 Reviewed-by: Sean Harmer --- tests/auto/render/graphicshelpergl3_2/BLACKLIST | 2 -- tests/auto/render/graphicshelpergl3_2/tst_graphicshelpergl3_2.cpp | 7 ++++++- 2 files changed, 6 insertions(+), 3 deletions(-) delete mode 100644 tests/auto/render/graphicshelpergl3_2/BLACKLIST (limited to 'tests/auto') diff --git a/tests/auto/render/graphicshelpergl3_2/BLACKLIST b/tests/auto/render/graphicshelpergl3_2/BLACKLIST deleted file mode 100644 index 1d6233cd7..000000000 --- a/tests/auto/render/graphicshelpergl3_2/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[blitFramebuffer] -ubuntu-16.04 diff --git a/tests/auto/render/graphicshelpergl3_2/tst_graphicshelpergl3_2.cpp b/tests/auto/render/graphicshelpergl3_2/tst_graphicshelpergl3_2.cpp index fb0265427..7e24d22c7 100644 --- a/tests/auto/render/graphicshelpergl3_2/tst_graphicshelpergl3_2.cpp +++ b/tests/auto/render/graphicshelpergl3_2/tst_graphicshelpergl3_2.cpp @@ -1867,6 +1867,11 @@ private Q_SLOTS: if (!m_initializationSuccessful) QSKIP("Initialization failed, OpenGL 3.2 Core functions not supported"); + GLint maxSamples; + m_func->glGetIntegerv(GL_MAX_SAMPLES, &maxSamples); + if (maxSamples < 1) + QSKIP("This test requires an implementation that supports multisampled textures"); + // GIVEN GLuint fbos[2]; GLuint fboTextures[2]; @@ -1875,7 +1880,7 @@ private Q_SLOTS: m_func->glGenTextures(2, fboTextures); m_func->glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, fboTextures[0]); - m_func->glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA8, 10, 10, true); + m_func->glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, maxSamples, GL_RGBA8, 10, 10, true); m_func->glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); m_func->glBindTexture(GL_TEXTURE_2D, fboTextures[1]); -- cgit v1.2.3 From a2b7483fa18e109011246fba5e7963338a77af56 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 18 Apr 2017 12:11:01 +0200 Subject: Try to investigate why tst_GraphicsHelperGL3_3::blitFramebuffer() fails Change-Id: Ide10e84479bdcfea71c29cd46b8a29199574d856 Task-number: QTBUG-59828 Reviewed-by: Sean Harmer --- tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp b/tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp index 58c12fcc9..cdca5676b 100644 --- a/tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp +++ b/tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp @@ -1991,13 +1991,13 @@ private Q_SLOTS: m_func->glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, fboTextures[1], 0); GLenum status = m_func->glCheckFramebufferStatus(GL_FRAMEBUFFER); - QVERIFY(status == GL_FRAMEBUFFER_COMPLETE); + QCOMPARE(status, GLenum(GL_FRAMEBUFFER_COMPLETE)); m_func->glBindFramebuffer(GL_FRAMEBUFFER, fbos[0]); m_func->glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, fboTextures[0], 0); status = m_func->glCheckFramebufferStatus(GL_FRAMEBUFFER); - QVERIFY(status == GL_FRAMEBUFFER_COMPLETE); + QCOMPARE(status, GLenum(GL_FRAMEBUFFER_COMPLETE)); m_func->glEnable(GL_MULTISAMPLE); m_func->glClearColor(0.2f, 0.2f, 0.2f, 0.2f); -- cgit v1.2.3 From 5e87e5beee5cfeffaa344ea165fba59ea46f4c57 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Tue, 25 Apr 2017 12:58:13 +0200 Subject: Remove last bits of qsortcriterion QSortCriterion was replaced with QSortPolicy, somehow some files were still around. Change-Id: Ic41fe557eb77c0b8d9d701a875598a7850a92b62 Task-number: QTBUG-55952 Reviewed-by: Kevin Ottens --- .../render/qsortcriterion/tst_qsortcriterion.cpp | 138 --------------------- 1 file changed, 138 deletions(-) delete mode 100644 tests/auto/render/qsortcriterion/tst_qsortcriterion.cpp (limited to 'tests/auto') diff --git a/tests/auto/render/qsortcriterion/tst_qsortcriterion.cpp b/tests/auto/render/qsortcriterion/tst_qsortcriterion.cpp deleted file mode 100644 index bac9fb3e8..000000000 --- a/tests/auto/render/qsortcriterion/tst_qsortcriterion.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the S 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 -#include -#include -#include - -#include -#include - -#include "testpostmanarbiter.h" - -class tst_QSortCriterion: public QObject -{ - Q_OBJECT - -private Q_SLOTS: - - void checkCloning_data() - { - QTest::addColumn("sortCriterion"); - QTest::addColumn("sortType"); - - Qt3DRender::QSortCriterion *defaultConstructed = new Qt3DRender::QSortCriterion(); - QTest::newRow("defaultConstructed") << defaultConstructed << Qt3DRender::QSortCriterion::StateChangeCost; - - Qt3DRender::QSortCriterion *backToFrontSort = new Qt3DRender::QSortCriterion(); - backToFrontSort->setSort(Qt3DRender::QSortCriterion::BackToFront); - QTest::newRow("backToFrontSort") << backToFrontSort << Qt3DRender::QSortCriterion::BackToFront; - - Qt3DRender::QSortCriterion *materialSort = new Qt3DRender::QSortCriterion(); - materialSort->setSort(Qt3DRender::QSortCriterion::Material); - QTest::newRow("materialSort") << materialSort << Qt3DRender::QSortCriterion::Material; - } - - void checkCloning() - { - // GIVEN - QFETCH(Qt3DRender::QSortCriterion *, sortCriterion); - QFETCH(Qt3DRender::QSortCriterion::SortType, sortType); - - // THEN - QCOMPARE(sortCriterion->sort(), sortType); - -// TO DO: Add creation change -// // WHEN -// Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(sortCriterion); -// QVector creationChanges = creationChangeGenerator.creationChanges(); - -// // THEN -// QCOMPARE(creationChanges.size(), 1); - -// const Qt3DCore::QNodeCreatedChangePtr creationChangeData = -// qSharedPointerCast>(creationChanges.first()); -// const Qt3DRender::QCameraSelectorData &cloneData = creationChangeData->data; - - -// // THEN -// QCOMPARE(sortCriterion->id(), creationChangeData->subjectId()); -// QCOMPARE(sortCriterion->isEnabled(), creationChangeData->isNodeEnabled()); -// QCOMPARE(sortCriterion->metaObject(), creationChangeData->metaObject()); -// QCOMPARE(sortCriterion->sort(), cloneData.sort); - - delete sortCriterion; - } - - void checkPropertyUpdates() - { - // GIVEN - QScopedPointer sortCriterion(new Qt3DRender::QSortCriterion()); - TestArbiter arbiter(sortCriterion.data()); - - // WHEN - sortCriterion->setSort(Qt3DRender::QSortCriterion::BackToFront); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - Qt3DCore::QNodePropertyChangePtr change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "sort"); - QCOMPARE(change->subjectId(), sortCriterion->id()); - QCOMPARE(change->value().value(), Qt3DRender::QSortCriterion::BackToFront); - QCOMPARE(change->type(), Qt3DCore::NodeUpdated); - - arbiter.events.clear(); - - // WHEN - sortCriterion->setSort(Qt3DRender::QSortCriterion::BackToFront); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - - // WHEN - sortCriterion->setSort(Qt3DRender::QSortCriterion::Material); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "sort"); - QCOMPARE(change->subjectId(), sortCriterion->id()); - QCOMPARE(change->value().value(), Qt3DRender::QSortCriterion::Material); - QCOMPARE(change->type(), Qt3DCore::NodeUpdated); - - arbiter.events.clear(); - } -}; - -QTEST_MAIN(tst_QSortCriterion) - -#include "tst_qsortcriterion.moc" -- cgit v1.2.3 From 7bddeeef303d0b2c100f2b2a7c01bf311ab07335 Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Mon, 24 Apr 2017 21:36:12 +0100 Subject: Send move events when hover is enabled Change-Id: I3bea4f27361dd4f51f8547c6d9d45c964f4fb5d3 Task-number: QTBUG-58607 Reviewed-by: Kevin Ottens --- tests/auto/render/pickboundingvolumejob/tst_pickboundingvolumejob.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/render/pickboundingvolumejob/tst_pickboundingvolumejob.cpp b/tests/auto/render/pickboundingvolumejob/tst_pickboundingvolumejob.cpp index 07055d810..1d391101e 100644 --- a/tests/auto/render/pickboundingvolumejob/tst_pickboundingvolumejob.cpp +++ b/tests/auto/render/pickboundingvolumejob/tst_pickboundingvolumejob.cpp @@ -1145,7 +1145,10 @@ private Q_SLOTS: change = arbiter1.events.first().staticCast(); QCOMPARE(change->propertyName(), "moved"); } else { + QVERIFY(arbiter2.events.size() > 1); change = arbiter2.events.first().staticCast(); + QCOMPARE(change->propertyName(), "moved"); + change = arbiter2.events.at(1).staticCast(); QCOMPARE(change->propertyName(), "entered"); } -- cgit v1.2.3 From 51c1d5bdfe4da07b9408af2290e2e7b3c9010fcd Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Wed, 26 Apr 2017 10:57:56 +0200 Subject: Add unit tests for FrameGraphVisitor Change-Id: I1ef3c275649fe874d2dc4c6caf81082729aca360 Reviewed-by: Kevin Ottens --- .../render/framegraphvisitor/framegraphvisitor.pro | 13 ++ .../framegraphvisitor/tst_framegraphvisitor.cpp | 174 +++++++++++++++++++++ tests/auto/render/render.pro | 3 +- 3 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 tests/auto/render/framegraphvisitor/framegraphvisitor.pro create mode 100644 tests/auto/render/framegraphvisitor/tst_framegraphvisitor.cpp (limited to 'tests/auto') diff --git a/tests/auto/render/framegraphvisitor/framegraphvisitor.pro b/tests/auto/render/framegraphvisitor/framegraphvisitor.pro new file mode 100644 index 000000000..2c9a0028e --- /dev/null +++ b/tests/auto/render/framegraphvisitor/framegraphvisitor.pro @@ -0,0 +1,13 @@ +TEMPLATE = app + +TARGET = tst_framegraphvisitor + +QT += core-private 3dcore 3dcore-private 3drender 3drender-private testlib + +CONFIG += testcase + +SOURCES += tst_framegraphvisitor.cpp + +CONFIG += useCommonTestAspect + +include(../commons/commons.pri) diff --git a/tests/auto/render/framegraphvisitor/tst_framegraphvisitor.cpp b/tests/auto/render/framegraphvisitor/tst_framegraphvisitor.cpp new file mode 100644 index 000000000..5344d7eb3 --- /dev/null +++ b/tests/auto/render/framegraphvisitor/tst_framegraphvisitor.cpp @@ -0,0 +1,174 @@ +/**************************************************************************** +** +** 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:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include "testaspect.h" + +namespace { + + + +} // anonymous + +using FGIdType = QPair; +using BranchIdsAndTypes = QVector; + +Q_DECLARE_METATYPE(QVector) + +class tst_FrameGraphVisitor : public QObject +{ + Q_OBJECT +private Q_SLOTS: + + void visitFGTree_data() + { + QTest::addColumn("rootEntity"); + QTest::addColumn("fgRoot"); + QTest::addColumn>("fgNodeIdsPerBranch"); + + { + Qt3DCore::QEntity *entity = new Qt3DCore::QEntity(); + Qt3DRender::QTechniqueFilter *techniqueFilter = new Qt3DRender::QTechniqueFilter(entity); + + QTest::newRow("singleNode") << entity + << static_cast(techniqueFilter) + << (QVector() + << (BranchIdsAndTypes() << FGIdType(techniqueFilter->id(), Qt3DRender::Render::FrameGraphNode::TechniqueFilter)) + ); + } + + { + Qt3DCore::QEntity *entity = new Qt3DCore::QEntity(); + Qt3DRender::QTechniqueFilter *techniqueFilter = new Qt3DRender::QTechniqueFilter(entity); + Qt3DRender::QFrustumCulling *frustumCulling = new Qt3DRender::QFrustumCulling(techniqueFilter); + Qt3DRender::QNoDraw *noDraw = new Qt3DRender::QNoDraw(frustumCulling); + + QTest::newRow("singleBranch") << entity + << static_cast(techniqueFilter) + << (QVector() + << (BranchIdsAndTypes() + << FGIdType(noDraw->id(), Qt3DRender::Render::FrameGraphNode::NoDraw) + << FGIdType(frustumCulling->id(), Qt3DRender::Render::FrameGraphNode::FrustumCulling) + << FGIdType(techniqueFilter->id(), Qt3DRender::Render::FrameGraphNode::TechniqueFilter) + ) + ); + } + { + Qt3DCore::QEntity *entity = new Qt3DCore::QEntity(); + Qt3DRender::QTechniqueFilter *techniqueFilter = new Qt3DRender::QTechniqueFilter(entity); + Qt3DRender::QFrustumCulling *frustumCulling = new Qt3DRender::QFrustumCulling(techniqueFilter); + Qt3DRender::QNoDraw *noDraw = new Qt3DRender::QNoDraw(frustumCulling); + Qt3DRender::QViewport *viewPort = new Qt3DRender::QViewport(frustumCulling); + + QTest::newRow("dualBranch") << entity + << static_cast(techniqueFilter) + << (QVector() + << (BranchIdsAndTypes() + << FGIdType(noDraw->id(), Qt3DRender::Render::FrameGraphNode::NoDraw) + << FGIdType(frustumCulling->id(), Qt3DRender::Render::FrameGraphNode::FrustumCulling) + << FGIdType(techniqueFilter->id(), Qt3DRender::Render::FrameGraphNode::TechniqueFilter) + ) + << (BranchIdsAndTypes() + << FGIdType(viewPort->id(), Qt3DRender::Render::FrameGraphNode::Viewport) + << FGIdType(frustumCulling->id(), Qt3DRender::Render::FrameGraphNode::FrustumCulling) + << FGIdType(techniqueFilter->id(), Qt3DRender::Render::FrameGraphNode::TechniqueFilter) + ) + ); + } + + } + + void visitFGTree() + { + // GIVEN + QFETCH(Qt3DCore::QEntity *, rootEntity); + QFETCH(Qt3DRender::QFrameGraphNode *, fgRoot); + QFETCH(QVector, fgNodeIdsPerBranch); + QScopedPointer aspect(new Qt3DRender::TestAspect(rootEntity)); + + // THEN + Qt3DRender::Render::FrameGraphManager *fgManager = aspect->nodeManagers()->frameGraphManager(); + Qt3DRender::Render::FrameGraphNode *backendFGRoot = fgManager->lookupNode(fgRoot->id()); + QVERIFY(backendFGRoot != nullptr); + + + // WHEN + Qt3DRender::Render::FrameGraphVisitor visitor(fgManager); + const QVector fgNodes = visitor.traverse(backendFGRoot); + + // THEN + QCOMPARE(fgNodeIdsPerBranch.size(), fgNodes.size()); + + for (int i = 0; i < fgNodeIdsPerBranch.size(); ++i) { + const BranchIdsAndTypes brandIdsAndTypes = fgNodeIdsPerBranch.at(i); + + Qt3DRender::Render::FrameGraphNode *fgNode = fgNodes.at(i); + for (int j = 0; j < brandIdsAndTypes.size(); ++j) { + const FGIdType idAndType = brandIdsAndTypes.at(j); + QVERIFY(fgNode != nullptr); + QCOMPARE(fgNode->peerId(), idAndType.first); + QCOMPARE(fgNode->nodeType(), idAndType.second); + fgNode = fgNode->parent(); + } + + QVERIFY(fgNode == nullptr); + } + + delete rootEntity; + } +}; + +QTEST_MAIN(tst_FrameGraphVisitor) + +#include "tst_framegraphvisitor.moc" diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro index bf464cf6b..8eea3d032 100644 --- a/tests/auto/render/render.pro +++ b/tests/auto/render/render.pro @@ -106,7 +106,8 @@ qtConfig(private_tests) { qshaderprogram \ qscene2d \ scene2d \ - coordinatereader + coordinatereader \ + framegraphvisitor !macos: SUBDIRS += graphicshelpergl4 } -- cgit v1.2.3 From b5800ac037321e161d31ee362688aef179c8d9d2 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Thu, 27 Apr 2017 10:43:29 +0200 Subject: Renderer: fix OnDemand rendering Note: this is a risky change For some reason the renderer assumed that a RenderQueue would never have a size of 0. This prevented the renderer from calling proceedToNextFrame() on the vsync advance service as it somehow felt that it was a case of rendering with a RenderQueue not yet ready. In the case of OnDemand rendering it is perfectly valid to have a RenderQueue of 0 (nothing has changed that requires rendering) but we still need to call proceedToNextFrame() otherwise syncChanges() is never called and we end up never updating the aspects ever again. The renderer was updated to 1) check if a RenderQueue is complete 2) check if the RenderQueue is empty. (a RenderQueue can be complete but empty (OnDemand case)) 3) Proceed to next frame if RenderQueue is complete or RenderQueue is empty. Change-Id: I27ae778831c9b136db1e1a69892f6fde291fd965 Task-number: QTBUG-59696 Task-number: QTBUG-54900 Reviewed-by: Sean Harmer --- tests/auto/render/renderqueue/tst_renderqueue.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/render/renderqueue/tst_renderqueue.cpp b/tests/auto/render/renderqueue/tst_renderqueue.cpp index 2d25cbe57..163a699c1 100644 --- a/tests/auto/render/renderqueue/tst_renderqueue.cpp +++ b/tests/auto/render/renderqueue/tst_renderqueue.cpp @@ -55,10 +55,14 @@ void tst_RenderQueue::setRenderViewCount() // GIVEN Qt3DRender::Render::RenderQueue renderQueue; + // THEN + QCOMPARE(renderQueue.wasReset(), true); + // WHEN renderQueue.setTargetRenderViewCount(7); // THEN + QCOMPARE(renderQueue.wasReset(), false); QVERIFY(renderQueue.targetRenderViewCount() == 7); QVERIFY(renderQueue.currentRenderViewCount()== 0); } @@ -214,6 +218,7 @@ void tst_RenderQueue::resetQueue() // WHEN renderQueue.setTargetRenderViewCount(5); // THEN + QCOMPARE(renderQueue.wasReset(), false); QVERIFY(renderQueue.currentRenderViewCount() == 0); // WHEN @@ -227,6 +232,7 @@ void tst_RenderQueue::resetQueue() // WHEN renderQueue.reset(); + QCOMPARE(renderQueue.wasReset(), true); // THEN QVERIFY(renderQueue.currentRenderViewCount() == 0); } -- cgit v1.2.3 From 6e5acfcce3c287c30bab4cdc6fc5f7545a15255e Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Thu, 4 May 2017 13:30:43 +0200 Subject: Scene2D: put picking coordinates back in window coordinates We get the picking coordinates in model local tex coords which have a different convention than the mouse events in window coordinates. So flip them vertically to pass them in the right convention. Change-Id: I558cc62c7c820677407730eead8011193a4b967c Reviewed-by: Sean Harmer --- tests/auto/render/scene2d/tst_scene2d.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/scene2d/tst_scene2d.cpp b/tests/auto/render/scene2d/tst_scene2d.cpp index d0bd5ca9d..a4810ce66 100644 --- a/tests/auto/render/scene2d/tst_scene2d.cpp +++ b/tests/auto/render/scene2d/tst_scene2d.cpp @@ -341,7 +341,7 @@ private Q_SLOTS: QCoreApplication::processEvents(); // THEN - QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(0,0))); + QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(0,1024))); testWindow->clear(); } @@ -355,7 +355,7 @@ private Q_SLOTS: QCoreApplication::processEvents(); // THEN - QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(1024,0))); + QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(1024,1024))); testWindow->clear(); } @@ -369,7 +369,7 @@ private Q_SLOTS: QCoreApplication::processEvents(); // THEN - QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(1024,1024))); + QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(1024,0))); testWindow->clear(); } @@ -383,7 +383,7 @@ private Q_SLOTS: QCoreApplication::processEvents(); // THEN - QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(0,0))); + QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(0,1024))); testWindow->clear(); } @@ -397,7 +397,7 @@ private Q_SLOTS: QCoreApplication::processEvents(); // THEN - QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(1024,1024))); + QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(1024,0))); testWindow->clear(); } @@ -411,7 +411,7 @@ private Q_SLOTS: QCoreApplication::processEvents(); // THEN - QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(0,1024))); + QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(0,0))); testWindow->clear(); } @@ -425,7 +425,7 @@ private Q_SLOTS: QCoreApplication::processEvents(); // THEN - QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(512.0f, 256.0f))); + QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(512.0f, 768.0f))); testWindow->clear(); } @@ -439,7 +439,7 @@ private Q_SLOTS: QCoreApplication::processEvents(); // THEN - QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(96.0f, 128.0f))); + QVERIFY(testWindow->verifyEventPos(0, QEvent::MouseButtonPress, QPointF(96.0f, 896.0f))); testWindow->clear(); } } -- cgit v1.2.3 From fc57d48db93830b92fd0b4a3bebfae55081e9d55 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Sat, 6 May 2017 09:33:52 +0100 Subject: Revert to using new window for each test Now that the underlying problem from QTBUG-58107 in the macOS QPA is fixed we can go back to using a fresh window for each test function. Task-number: QTBUG-58107 Change-Id: If77fa7dbcb5b8b1a7e096e262832297ce871313d Reviewed-by: Paul Lemire --- tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp | 4 ++-- tests/auto/render/graphicshelpergl3_2/tst_graphicshelpergl3_2.cpp | 4 ++-- tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp | 4 ++-- tests/auto/render/graphicshelpergl4/tst_graphicshelpergl4.cpp | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp b/tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp index 58e2373f5..473e43d09 100644 --- a/tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp +++ b/tests/auto/render/graphicshelpergl2/tst_graphicshelpergl2.cpp @@ -124,7 +124,7 @@ class tst_GraphicsHelperGL2 : public QObject Q_OBJECT private Q_SLOTS: - void initTestCase() + void init() { m_window.reset(new QWindow); m_window->setSurfaceType(QWindow::OpenGLSurface); @@ -160,7 +160,7 @@ private Q_SLOTS: } } - void cleanupTestCase() + void cleanup() { m_glContext.doneCurrent(); } diff --git a/tests/auto/render/graphicshelpergl3_2/tst_graphicshelpergl3_2.cpp b/tests/auto/render/graphicshelpergl3_2/tst_graphicshelpergl3_2.cpp index 7e24d22c7..b66192835 100644 --- a/tests/auto/render/graphicshelpergl3_2/tst_graphicshelpergl3_2.cpp +++ b/tests/auto/render/graphicshelpergl3_2/tst_graphicshelpergl3_2.cpp @@ -177,7 +177,7 @@ class tst_GraphicsHelperGL3_2 : public QObject Q_OBJECT private Q_SLOTS: - void initTestCase() + void init() { m_window.reset(new QWindow); m_window->setSurfaceType(QWindow::OpenGLSurface); @@ -209,7 +209,7 @@ private Q_SLOTS: } } - void cleanupTestCase() + void cleanup() { m_glContext.doneCurrent(); } diff --git a/tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp b/tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp index cdca5676b..b7cc1cdac 100644 --- a/tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp +++ b/tests/auto/render/graphicshelpergl3_3/tst_graphicshelpergl3_3.cpp @@ -176,7 +176,7 @@ class tst_GraphicsHelperGL3_3 : public QObject Q_OBJECT private Q_SLOTS: - void initTestCase() + void init() { m_window.reset(new QWindow); m_window->setSurfaceType(QWindow::OpenGLSurface); @@ -209,7 +209,7 @@ private Q_SLOTS: } } - void cleanupTestCase() + void cleanup() { m_glContext.doneCurrent(); } diff --git a/tests/auto/render/graphicshelpergl4/tst_graphicshelpergl4.cpp b/tests/auto/render/graphicshelpergl4/tst_graphicshelpergl4.cpp index c6a306910..0ee14841c 100644 --- a/tests/auto/render/graphicshelpergl4/tst_graphicshelpergl4.cpp +++ b/tests/auto/render/graphicshelpergl4/tst_graphicshelpergl4.cpp @@ -201,7 +201,7 @@ class tst_GraphicsHelperGL4 : public QObject { Q_OBJECT private Q_SLOTS: - void initTestCase() + void init() { m_window.reset(new QWindow); m_window->setSurfaceType(QWindow::OpenGLSurface); @@ -234,7 +234,7 @@ private Q_SLOTS: } } - void cleanupTestCase() + void cleanup() { m_glContext.doneCurrent(); } -- cgit v1.2.3 From 4a2d8d6ee54976e3a8e2218bc8e97c857688cdfe Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Thu, 4 May 2017 13:13:23 +0200 Subject: Fix Buffer uploading We used to load buffer data when creating it. This led to cases where we would not take into account immediately buffer updates after creation. This would then results in artifacts that would pop up on screen as actual buffer data and count would be different Change-Id: I5a2fad4fb5d7c1e1542cd0bf87ded16a111bc613 Task-number: QTBUG-60429 Reviewed-by: Oleg Evseev Reviewed-by: Laszlo Agocs --- tests/auto/render/buffer/tst_buffer.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/render/buffer/tst_buffer.cpp b/tests/auto/render/buffer/tst_buffer.cpp index 7f7c0adb9..8049aaf37 100644 --- a/tests/auto/render/buffer/tst_buffer.cpp +++ b/tests/auto/render/buffer/tst_buffer.cpp @@ -89,6 +89,8 @@ private Q_SLOTS: QCOMPARE(renderBuffer.data(), buffer.data()); QCOMPARE(renderBuffer.dataGenerator(), buffer.dataGenerator()); QVERIFY(*renderBuffer.dataGenerator() == *buffer.dataGenerator()); + QCOMPARE(renderBuffer.pendingBufferUpdates().size(), 1); + QCOMPARE(renderBuffer.pendingBufferUpdates().first().offset, -1); } void checkInitialAndCleanedUpState() @@ -195,7 +197,10 @@ private Q_SLOTS: // THEN QCOMPARE(renderBuffer.data(), QByteArrayLiteral("LS9")); QVERIFY(renderBuffer.isDirty()); + QCOMPARE(renderBuffer.pendingBufferUpdates().size(), 1); + QCOMPARE(renderBuffer.pendingBufferUpdates().first().offset, -1); + renderBuffer.pendingBufferUpdates().clear(); renderBuffer.unsetDirty(); QVERIFY(!renderBuffer.isDirty()); @@ -233,8 +238,11 @@ private Q_SLOTS: Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); QCOMPARE(change->propertyName(), "data"); QCOMPARE(change->value().toByteArray(), QByteArrayLiteral("454")); + QCOMPARE(renderBuffer.pendingBufferUpdates().size(), 1); + QCOMPARE(renderBuffer.pendingBufferUpdates().first().offset, -1); arbiter.events.clear(); + renderBuffer.pendingBufferUpdates().clear(); // WHEN updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); @@ -247,6 +255,7 @@ private Q_SLOTS: // THEN QVERIFY(!renderBuffer.pendingBufferUpdates().empty()); + QCOMPARE(renderBuffer.pendingBufferUpdates().first().offset, 2); QVERIFY(renderBuffer.isDirty()); renderBuffer.unsetDirty(); -- cgit v1.2.3 From 540f11b0b3f1639990383e2a4c72f858b0ac01b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A4=C3=A4tt=C3=A4=20Antti?= Date: Wed, 12 Apr 2017 14:26:41 +0300 Subject: Scene2D cleanup - remove qml engine and source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove QQmlEngine constructor and source property. Update unit tests and manual tests accordingly. Task-number: QTBUG-58876 Change-Id: Ide06bb1381f48efa5378f9a008476734a33089c1 Reviewed-by: Sean Harmer Reviewed-by: Antti Määttä --- tests/auto/render/qscene2d/tst_qscene2d.cpp | 55 ----------------------------- 1 file changed, 55 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/qscene2d/tst_qscene2d.cpp b/tests/auto/render/qscene2d/tst_qscene2d.cpp index f0ff2db1e..61ac893e4 100644 --- a/tests/auto/render/qscene2d/tst_qscene2d.cpp +++ b/tests/auto/render/qscene2d/tst_qscene2d.cpp @@ -58,9 +58,7 @@ private Q_SLOTS: // THEN QCOMPARE(scene2d.output(), nullptr); - QCOMPARE(scene2d.source(), QUrl(QStringLiteral(""))); QCOMPARE(scene2d.renderPolicy(), QScene2D::Continuous); - QCOMPARE(scene2d.loaded(), false); QCOMPARE(scene2d.item(), nullptr); } @@ -90,25 +88,6 @@ private Q_SLOTS: QCOMPARE(scene2d.output(), newValue); QCOMPARE(spy.count(), 0); } - { - // WHEN - QSignalSpy spy(&scene2d, SIGNAL(sourceChanged(QUrl))); - const QUrl newValue = QUrl(QStringLiteral("qrc://source.qml")); - scene2d.setSource(newValue); - - // THEN - QVERIFY(spy.isValid()); - QCOMPARE(scene2d.source(), newValue); - QCOMPARE(spy.count(), 1); - - // WHEN - spy.clear(); - scene2d.setSource(newValue); - - // THEN - QCOMPARE(scene2d.source(), newValue); - QCOMPARE(spy.count(), 0); - } { // WHEN QSignalSpy spy(&scene2d, SIGNAL(renderPolicyChanged(QScene2D::RenderPolicy))); @@ -156,7 +135,6 @@ private Q_SLOTS: QScopedPointer output(new Qt3DRender::QRenderTargetOutput()); scene2d.setOutput(output.data()); - scene2d.setSource(QUrl(QStringLiteral("qrc://source.qml"))); scene2d.setRenderPolicy(QScene2D::SingleShot); // WHEN @@ -242,39 +220,6 @@ private Q_SLOTS: } - void checkSourceUpdate() - { - // GIVEN - TestArbiter arbiter; - Qt3DRender::Quick::QScene2D scene2d; - arbiter.setArbiterOnNode(&scene2d); - - { - // WHEN - scene2d.setSource(QUrl(QStringLiteral("qrc://source.qml"))); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 1); - auto change = arbiter.events.first().staticCast(); - QCOMPARE(change->propertyName(), "source"); - QCOMPARE(change->value().value(), scene2d.source()); - QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - - arbiter.events.clear(); - } - - { - // WHEN - scene2d.setSource(QUrl(QStringLiteral("qrc://source.qml"))); - QCoreApplication::processEvents(); - - // THEN - QCOMPARE(arbiter.events.size(), 0); - } - - } - void checkRenderPolicyUpdate() { // GIVEN -- cgit v1.2.3 From 1178d7538bced76d1475b214cd591d86609239f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Wed, 8 Feb 2017 10:20:46 +0200 Subject: Add autotests for new animation classes Change-Id: Id657443693009455c9307b51e862d43f41255f1d Reviewed-by: Sean Harmer --- tests/auto/animation/animation.pro | 12 +- .../qabstractanimation/qabstractanimation.pro | 10 + .../qabstractanimation/tst_qabstractanimation.cpp | 117 ++++++++ .../qanimationcontroller/qanimationcontroller.pro | 10 + .../tst_qanimationcontroller.cpp | 302 ++++++++++++++++++++ .../animation/qanimationgroup/qanimationgroup.pro | 10 + .../qanimationgroup/tst_qanimationgroup.cpp | 100 +++++++ .../qkeyframeanimation/qkeyframeanimation.pro | 10 + .../qkeyframeanimation/tst_qkeyframeanimation.cpp | 285 +++++++++++++++++++ .../qmorphinganimation/qmorphinganimation.pro | 10 + .../qmorphinganimation/tst_qmorphinganimation.cpp | 309 +++++++++++++++++++++ tests/auto/animation/qmorphtarget/qmorphtarget.pro | 10 + .../animation/qmorphtarget/tst_qmorphtarget.cpp | 123 ++++++++ .../qvertexblendanimation.pro | 10 + .../tst_qvertexblendanimation.cpp | 102 +++++++ 15 files changed, 1418 insertions(+), 2 deletions(-) create mode 100644 tests/auto/animation/qabstractanimation/qabstractanimation.pro create mode 100644 tests/auto/animation/qabstractanimation/tst_qabstractanimation.cpp create mode 100644 tests/auto/animation/qanimationcontroller/qanimationcontroller.pro create mode 100644 tests/auto/animation/qanimationcontroller/tst_qanimationcontroller.cpp create mode 100644 tests/auto/animation/qanimationgroup/qanimationgroup.pro create mode 100644 tests/auto/animation/qanimationgroup/tst_qanimationgroup.cpp create mode 100644 tests/auto/animation/qkeyframeanimation/qkeyframeanimation.pro create mode 100644 tests/auto/animation/qkeyframeanimation/tst_qkeyframeanimation.cpp create mode 100644 tests/auto/animation/qmorphinganimation/qmorphinganimation.pro create mode 100644 tests/auto/animation/qmorphinganimation/tst_qmorphinganimation.cpp create mode 100644 tests/auto/animation/qmorphtarget/qmorphtarget.pro create mode 100644 tests/auto/animation/qmorphtarget/tst_qmorphtarget.cpp create mode 100644 tests/auto/animation/qvertexblendanimation/qvertexblendanimation.pro create mode 100644 tests/auto/animation/qvertexblendanimation/tst_qvertexblendanimation.cpp (limited to 'tests/auto') diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index 969f477e7..d3ef37a61 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -7,7 +7,14 @@ SUBDIRS += \ qblendedclipanimator \ qchannelmapping \ qchannelmapper \ - qclipblendvalue + qclipblendvalue \ + qanimationcontroller \ + qanimationgroup \ + qkeyframeanimation \ + qmorphinganimation \ + qmorphtarget \ + qvertexblendanimation \ + qanimationcontroller qtConfig(private_tests) { SUBDIRS += \ @@ -27,5 +34,6 @@ qtConfig(private_tests) { qadditiveclipblend \ additiveclipblend \ clipblendvalue \ - animationutils + animationutils \ + qabstractanimation } diff --git a/tests/auto/animation/qabstractanimation/qabstractanimation.pro b/tests/auto/animation/qabstractanimation/qabstractanimation.pro new file mode 100644 index 000000000..be37677b6 --- /dev/null +++ b/tests/auto/animation/qabstractanimation/qabstractanimation.pro @@ -0,0 +1,10 @@ +TEMPLATE = app + +TARGET = tst_qabstractanimation + +QT += 3dcore 3dcore-private 3drender 3drender-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += tst_qabstractanimation.cpp + diff --git a/tests/auto/animation/qabstractanimation/tst_qabstractanimation.cpp b/tests/auto/animation/qabstractanimation/tst_qabstractanimation.cpp new file mode 100644 index 000000000..90349fb28 --- /dev/null +++ b/tests/auto/animation/qabstractanimation/tst_qabstractanimation.cpp @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** 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 +#include +#include +#include +#include + +#include + +class TestAnimation : public Qt3DAnimation::QAbstractAnimation +{ +public: + explicit TestAnimation(Qt3DCore::QNode *parent = nullptr) + : Qt3DAnimation::QAbstractAnimation( + *new Qt3DAnimation::QAbstractAnimationPrivate( + Qt3DAnimation::QAbstractAnimation::KeyframeAnimation), parent) + { + + } +}; + +class tst_QAbstractAnimation : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void checkDefaultConstruction() + { + // GIVEN + TestAnimation abstractAnimation; + + // THEN + QCOMPARE(abstractAnimation.animationName(), QString()); + QCOMPARE(abstractAnimation.animationType(), + Qt3DAnimation::QAbstractAnimation::KeyframeAnimation); + QCOMPARE(abstractAnimation.position(), 0.0f); + QCOMPARE(abstractAnimation.duration(), 0.0f); + } + + void checkPropertyChanges() + { + // GIVEN + TestAnimation abstractAnimation; + + { + // WHEN + QSignalSpy spy(&abstractAnimation, SIGNAL(animationNameChanged(QString))); + const QString newValue = QString("test"); + abstractAnimation.setAnimationName(newValue); + + // THEN + QCOMPARE(abstractAnimation.animationName(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + abstractAnimation.setAnimationName(newValue); + + // THEN + QCOMPARE(abstractAnimation.animationName(), newValue); + QCOMPARE(spy.count(), 0); + + } + { + // WHEN + QSignalSpy spy(&abstractAnimation, SIGNAL(positionChanged(float))); + const float newValue = 1.0f; + abstractAnimation.setPosition(newValue); + + // THEN + QCOMPARE(abstractAnimation.position(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + abstractAnimation.setPosition(newValue); + + // THEN + QCOMPARE(abstractAnimation.position(), newValue); + QCOMPARE(spy.count(), 0); + + } + } + +}; + +QTEST_APPLESS_MAIN(tst_QAbstractAnimation) + +#include "tst_qabstractanimation.moc" diff --git a/tests/auto/animation/qanimationcontroller/qanimationcontroller.pro b/tests/auto/animation/qanimationcontroller/qanimationcontroller.pro new file mode 100644 index 000000000..ff5348d47 --- /dev/null +++ b/tests/auto/animation/qanimationcontroller/qanimationcontroller.pro @@ -0,0 +1,10 @@ +TEMPLATE = app + +TARGET = tst_qanimationcontroller + +QT += 3dcore 3dcore-private 3drender 3drender-private 3danimation testlib + +CONFIG += testcase + +SOURCES += tst_qanimationcontroller.cpp + diff --git a/tests/auto/animation/qanimationcontroller/tst_qanimationcontroller.cpp b/tests/auto/animation/qanimationcontroller/tst_qanimationcontroller.cpp new file mode 100644 index 000000000..4774dc8ba --- /dev/null +++ b/tests/auto/animation/qanimationcontroller/tst_qanimationcontroller.cpp @@ -0,0 +1,302 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** 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 +#include +#include +#include +#include +#include + +class tst_QAnimationController : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void checkDefaultConstruction() + { + // GIVEN + Qt3DAnimation::QAnimationController animationController; + + // THEN + QCOMPARE(animationController.activeAnimationGroup(), 0); + QCOMPARE(animationController.position(), 0.0f); + QCOMPARE(animationController.positionScale(), 1.0f); + QCOMPARE(animationController.positionOffset(), 0.0f); + QCOMPARE(animationController.entity(), nullptr); + QCOMPARE(animationController.recursive(), true); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::QAnimationController animationController; + + { + // WHEN + QSignalSpy spy(&animationController, SIGNAL(activeAnimationGroupChanged(int))); + const int newValue = 1; + animationController.setActiveAnimationGroup(newValue); + + // THEN + QCOMPARE(animationController.activeAnimationGroup(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + animationController.setActiveAnimationGroup(newValue); + + // THEN + QCOMPARE(animationController.activeAnimationGroup(), newValue); + QCOMPARE(spy.count(), 0); + + } + { + // WHEN + QSignalSpy spy(&animationController, SIGNAL(positionChanged(float))); + const float newValue = 2.0f; + animationController.setPosition(newValue); + + // THEN + QCOMPARE(animationController.position(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + animationController.setPosition(newValue); + + // THEN + QCOMPARE(animationController.position(), newValue); + QCOMPARE(spy.count(), 0); + + } + { + // WHEN + QSignalSpy spy(&animationController, SIGNAL(positionScaleChanged(float))); + const float newValue = 3.0f; + animationController.setPositionScale(newValue); + + // THEN + QCOMPARE(animationController.positionScale(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + animationController.setPositionScale(newValue); + + // THEN + QCOMPARE(animationController.positionScale(), newValue); + QCOMPARE(spy.count(), 0); + + } + { + // WHEN + QSignalSpy spy(&animationController, SIGNAL(positionOffsetChanged(float))); + const float newValue = -1.0f; + animationController.setPositionOffset(newValue); + + // THEN + QCOMPARE(animationController.positionOffset(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + animationController.setPositionOffset(newValue); + + // THEN + QCOMPARE(animationController.positionOffset(), newValue); + QCOMPARE(spy.count(), 0); + + } + { + // WHEN + QScopedPointer entity(new Qt3DCore::QEntity); + QSignalSpy spy(&animationController, SIGNAL(entityChanged(Qt3DCore::QEntity *))); + Qt3DCore::QEntity * newValue = entity.data(); + animationController.setEntity(newValue); + + // THEN + QCOMPARE(animationController.entity(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + animationController.setEntity(newValue); + + // THEN + QCOMPARE(animationController.entity(), newValue); + QCOMPARE(spy.count(), 0); + + } + { + // WHEN + QSignalSpy spy(&animationController, SIGNAL(recursiveChanged(bool))); + const bool newValue = false; + animationController.setRecursive(newValue); + + // THEN + QCOMPARE(animationController.recursive(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + animationController.setRecursive(newValue); + + // THEN + QCOMPARE(animationController.recursive(), newValue); + QCOMPARE(spy.count(), 0); + + } + } + + void testSetEntity() + { + // GIVEN + Qt3DAnimation::QAnimationController animationController; + Qt3DAnimation::QKeyframeAnimation *keyframeAnimation; + Qt3DAnimation::QKeyframeAnimation *keyframeAnimation2; + Qt3DAnimation::QMorphingAnimation *morphingAnimation; + + QScopedPointer entity(new Qt3DCore::QEntity); + keyframeAnimation = new Qt3DAnimation::QKeyframeAnimation(entity.data()); + keyframeAnimation2 = new Qt3DAnimation::QKeyframeAnimation(entity.data()); + morphingAnimation = new Qt3DAnimation::QMorphingAnimation(entity.data()); + + const QString animName1 = QString("animation1"); + const QString animName2 = QString("animation2"); + morphingAnimation->setAnimationName(animName1); + keyframeAnimation->setAnimationName(animName1); + keyframeAnimation2->setAnimationName(animName2); + + { + // WHEN + animationController.setEntity(entity.data()); + + // THEN + QVector list = animationController.animationGroupList(); + QCOMPARE(list.size(), 2); + + QCOMPARE(list.at(0)->name(), animName1); + QCOMPARE(list.at(1)->name(), animName2); + + QCOMPARE(list.at(0)->animationList().size(), 2); + QCOMPARE(list.at(1)->animationList().size(), 1); + } + } + + void testSetEntityRecursive() + { + // GIVEN + Qt3DAnimation::QAnimationController animationController; + Qt3DAnimation::QKeyframeAnimation *keyframeAnimation; + Qt3DAnimation::QMorphingAnimation *morphingAnimation; + + QScopedPointer entity(new Qt3DCore::QEntity); + keyframeAnimation = new Qt3DAnimation::QKeyframeAnimation(entity.data()); + Qt3DCore::QEntity *childEntity = new Qt3DCore::QEntity(entity.data()); + morphingAnimation = new Qt3DAnimation::QMorphingAnimation(childEntity); + + const QString animName1 = QString("animation1"); + const QString animName2 = QString("animation2"); + + keyframeAnimation->setAnimationName(animName1); + morphingAnimation->setAnimationName(animName2); + + { + // WHEN + animationController.setEntity(entity.data()); + + // THEN + QVector list = animationController.animationGroupList(); + QCOMPARE(list.size(), 2); + + QCOMPARE(list.at(0)->name(), animName1); + QCOMPARE(list.at(1)->name(), animName2); + + QCOMPARE(list.at(0)->animationList().size(), 1); + QCOMPARE(list.at(1)->animationList().size(), 1); + + animationController.setEntity(nullptr); + } + + { + // WHEN + animationController.setRecursive(false); + animationController.setEntity(entity.data()); + + // THEN + QVector list = animationController.animationGroupList(); + QCOMPARE(list.size(), 1); + + QCOMPARE(list.at(0)->name(), animName1); + + QCOMPARE(list.at(0)->animationList().size(), 1); + } + } + + + void testPropagatePosition() + { + // GIVEN + Qt3DAnimation::QAnimationController animationController; + Qt3DAnimation::QKeyframeAnimation *keyframeAnimation; + + QScopedPointer entity(new Qt3DCore::QEntity); + keyframeAnimation = new Qt3DAnimation::QKeyframeAnimation(entity.data()); + + const QString animName1 = QString("animation1"); + keyframeAnimation->setAnimationName(animName1); + + { + // WHEN + animationController.setEntity(entity.data()); + animationController.setPosition(2.0f); + + // THEN + QCOMPARE(animationController.animationGroupList().at(0)->position(), 2.0f); + QCOMPARE(keyframeAnimation->position(), 2.0f); + } + + { + // WHEN + animationController.setPositionOffset(1.0); + animationController.setPositionScale(2.0f); + animationController.setPosition(2.0f); + + // THEN + QCOMPARE(animationController.animationGroupList().at(0)->position(), 5.0f); + QCOMPARE(keyframeAnimation->position(), 5.0f); + } + } + +}; + +QTEST_APPLESS_MAIN(tst_QAnimationController) + +#include "tst_qanimationcontroller.moc" diff --git a/tests/auto/animation/qanimationgroup/qanimationgroup.pro b/tests/auto/animation/qanimationgroup/qanimationgroup.pro new file mode 100644 index 000000000..5c39fa539 --- /dev/null +++ b/tests/auto/animation/qanimationgroup/qanimationgroup.pro @@ -0,0 +1,10 @@ +TEMPLATE = app + +TARGET = tst_qanimationgroup + +QT += 3dcore 3dcore-private 3drender 3drender-private 3danimation testlib + +CONFIG += testcase + +SOURCES += tst_qanimationgroup.cpp + diff --git a/tests/auto/animation/qanimationgroup/tst_qanimationgroup.cpp b/tests/auto/animation/qanimationgroup/tst_qanimationgroup.cpp new file mode 100644 index 000000000..0c7a66222 --- /dev/null +++ b/tests/auto/animation/qanimationgroup/tst_qanimationgroup.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** 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 +#include +#include +#include + +class tst_QAnimationGroup : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void checkDefaultConstruction() + { + // GIVEN + Qt3DAnimation::QAnimationGroup animationGroup; + + // THEN + QCOMPARE(animationGroup.name(), QString()); + QCOMPARE(animationGroup.position(), 0.0f); + QCOMPARE(animationGroup.duration(), 0.0f); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::QAnimationGroup animationGroup; + + { + // WHEN + QSignalSpy spy(&animationGroup, SIGNAL(nameChanged(QString))); + const QString newValue = QString("group"); + animationGroup.setName(newValue); + + // THEN + QCOMPARE(animationGroup.name(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + animationGroup.setName(newValue); + + // THEN + QCOMPARE(animationGroup.name(), newValue); + QCOMPARE(spy.count(), 0); + + } + { + // WHEN + QSignalSpy spy(&animationGroup, SIGNAL(positionChanged(float))); + const float newValue = 2.0f; + animationGroup.setPosition(newValue); + + // THEN + QCOMPARE(animationGroup.position(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + animationGroup.setPosition(newValue); + + // THEN + QCOMPARE(animationGroup.position(), newValue); + QCOMPARE(spy.count(), 0); + + } + } + +}; + +QTEST_APPLESS_MAIN(tst_QAnimationGroup) + +#include "tst_qanimationgroup.moc" diff --git a/tests/auto/animation/qkeyframeanimation/qkeyframeanimation.pro b/tests/auto/animation/qkeyframeanimation/qkeyframeanimation.pro new file mode 100644 index 000000000..994d8d0d9 --- /dev/null +++ b/tests/auto/animation/qkeyframeanimation/qkeyframeanimation.pro @@ -0,0 +1,10 @@ +TEMPLATE = app + +TARGET = tst_qkeyframeanimation + +QT += 3dcore 3dcore-private 3drender 3drender-private 3danimation testlib + +CONFIG += testcase + +SOURCES += tst_qkeyframeanimation.cpp + diff --git a/tests/auto/animation/qkeyframeanimation/tst_qkeyframeanimation.cpp b/tests/auto/animation/qkeyframeanimation/tst_qkeyframeanimation.cpp new file mode 100644 index 000000000..33bbebc52 --- /dev/null +++ b/tests/auto/animation/qkeyframeanimation/tst_qkeyframeanimation.cpp @@ -0,0 +1,285 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** 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 +#include +#include +#include + +class tst_QKeyframeAnimation : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void initTestCase() + { + qRegisterMetaType( + "QKeyframeAnimation::RepeatMode"); + } + + void checkDefaultConstruction() + { + // GIVEN + Qt3DAnimation::QKeyframeAnimation keyframeAnimation; + + // THEN + QCOMPARE(keyframeAnimation.target(), nullptr); + QCOMPARE(keyframeAnimation.easing(), QEasingCurve()); + QCOMPARE(keyframeAnimation.targetName(), QString()); + QCOMPARE(keyframeAnimation.startMode(), Qt3DAnimation::QKeyframeAnimation::Constant); + QCOMPARE(keyframeAnimation.endMode(), Qt3DAnimation::QKeyframeAnimation::Constant); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::QKeyframeAnimation keyframeAnimation; + + { + // WHEN + QScopedPointer transform(new Qt3DCore::QTransform); + QSignalSpy spy(&keyframeAnimation, SIGNAL(targetChanged(Qt3DCore::QTransform *))); + Qt3DCore::QTransform * newValue = transform.data(); + keyframeAnimation.setTarget(newValue); + + // THEN + QCOMPARE(keyframeAnimation.target(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + keyframeAnimation.setTarget(newValue); + + // THEN + QCOMPARE(keyframeAnimation.target(), newValue); + QCOMPARE(spy.count(), 0); + + } + { + // WHEN + QSignalSpy spy(&keyframeAnimation, SIGNAL(easingChanged(const QEasingCurve &))); + const QEasingCurve newValue = QEasingCurve(QEasingCurve::CosineCurve); + keyframeAnimation.setEasing(newValue); + + // THEN + QCOMPARE(keyframeAnimation.easing(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + keyframeAnimation.setEasing(newValue); + + // THEN + QCOMPARE(keyframeAnimation.easing(), newValue); + QCOMPARE(spy.count(), 0); + + } + { + // WHEN + QSignalSpy spy(&keyframeAnimation, SIGNAL(targetNameChanged(QString))); + const QString newValue = QString("target"); + keyframeAnimation.setTargetName(newValue); + + // THEN + QCOMPARE(keyframeAnimation.targetName(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + keyframeAnimation.setTargetName(newValue); + + // THEN + QCOMPARE(keyframeAnimation.targetName(), newValue); + QCOMPARE(spy.count(), 0); + + } + { + // WHEN + QSignalSpy spy(&keyframeAnimation, + SIGNAL(startModeChanged(QKeyframeAnimation::RepeatMode))); + const Qt3DAnimation::QKeyframeAnimation::RepeatMode newValue + = Qt3DAnimation::QKeyframeAnimation::Repeat; + keyframeAnimation.setStartMode(newValue); + + // THEN + QCOMPARE(keyframeAnimation.startMode(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + keyframeAnimation.setStartMode(newValue); + + // THEN + QCOMPARE(keyframeAnimation.startMode(), newValue); + QCOMPARE(spy.count(), 0); + + } + { + // WHEN + QSignalSpy spy(&keyframeAnimation, + SIGNAL(endModeChanged(QKeyframeAnimation::RepeatMode))); + const Qt3DAnimation::QKeyframeAnimation::RepeatMode newValue + = Qt3DAnimation::QKeyframeAnimation::Repeat; + keyframeAnimation.setEndMode(newValue); + + // THEN + QCOMPARE(keyframeAnimation.endMode(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + keyframeAnimation.setEndMode(newValue); + + // THEN + QCOMPARE(keyframeAnimation.endMode(), newValue); + QCOMPARE(spy.count(), 0); + + } + } + + void testAnimating() + { + // GIVEN + Qt3DAnimation::QKeyframeAnimation keyframeAnimation; + Qt3DCore::QTransform targetTransform; + keyframeAnimation.setTarget(&targetTransform); + + const float positions[3] = {0.0f, 1.0f, 2.0f}; + + Qt3DCore::QTransform keyframes[3]; + keyframes[0].setScale(1.0f); + keyframes[1].setScale(2.0f); + keyframes[2].setScale(3.0f); + + keyframes[0].setTranslation(QVector3D(0.0f, 0.0f, 0.0f)); + keyframes[1].setTranslation(QVector3D(1.0f, 1.0f, 0.0f)); + keyframes[2].setTranslation(QVector3D(2.0f, 0.0f, 2.0f)); + + keyframes[0].setRotationX(0.0f); + keyframes[1].setRotationY(45.0f); + keyframes[2].setRotationZ(90.0f); + + QVector framePositions; + framePositions.push_back(positions[0]); + framePositions.push_back(positions[1]); + framePositions.push_back(positions[2]); + + QVector frames; + frames.push_back(&keyframes[0]); + frames.push_back(&keyframes[1]); + frames.push_back(&keyframes[2]); + + keyframeAnimation.setFramePositions(framePositions); + keyframeAnimation.setKeyframes(frames); + + { + // WHEN + keyframeAnimation.setPosition(0.0f); + + // THEN + QVERIFY(qFuzzyCompare(targetTransform.scale3D(), QVector3D(1.0f, 1.0f, 1.0f))); + QVERIFY(qFuzzyCompare(targetTransform.translation(), QVector3D(0.0f, 0.0f, 0.0f))); + QVERIFY(qFuzzyCompare(targetTransform.rotation(), + QQuaternion::fromEulerAngles(QVector3D(0.0f, 0.0f, 0.0f)))); + + // WHEN + keyframeAnimation.setPosition(1.0f); + + // THEN + QVERIFY(qFuzzyCompare(targetTransform.scale3D(), QVector3D(2.0f, 2.0f, 2.0f))); + QVERIFY(qFuzzyCompare(targetTransform.translation(), QVector3D(1.0f, 1.0f, 0.0f))); + QVERIFY(qFuzzyCompare(targetTransform.rotation(), + QQuaternion::fromEulerAngles(QVector3D(0.0f, 45.0f, 0.0f)))); + + // WHEN + keyframeAnimation.setPosition(2.0f); + + // THEN + QVERIFY(qFuzzyCompare(targetTransform.scale3D(), QVector3D(3.0f, 3.0f, 3.0f))); + QVERIFY(qFuzzyCompare(targetTransform.translation(), QVector3D(2.0f, 0.0f, 2.0f))); + QVERIFY(qFuzzyCompare(targetTransform.rotation(), + QQuaternion::fromEulerAngles(QVector3D(0.0f, 0.0f, 90.0f)))); + + // WHEN + keyframeAnimation.setPosition(3.0f); + + // THEN + QVERIFY(qFuzzyCompare(targetTransform.scale3D(), QVector3D(3.0f, 3.0f, 3.0f))); + QVERIFY(qFuzzyCompare(targetTransform.translation(), QVector3D(2.0f, 0.0f, 2.0f))); + QVERIFY(qFuzzyCompare(targetTransform.rotation(), + QQuaternion::fromEulerAngles(QVector3D(0.0f, 0.0f, 90.0f)))); + + // WHEN + keyframeAnimation.setStartMode(Qt3DAnimation::QKeyframeAnimation::None); + keyframeAnimation.setEndMode(Qt3DAnimation::QKeyframeAnimation::None); + keyframeAnimation.setPosition(-1.0f); + + // THEN + QVERIFY(qFuzzyCompare(targetTransform.scale3D(), QVector3D(3.0f, 3.0f, 3.0f))); + QVERIFY(qFuzzyCompare(targetTransform.translation(), QVector3D(2.0f, 0.0f, 2.0f))); + QVERIFY(qFuzzyCompare(targetTransform.rotation(), + QQuaternion::fromEulerAngles(QVector3D(0.0f, 0.0f, 90.0f)))); + + // WHEN + keyframeAnimation.setPosition(5.0f); + + // THEN + QVERIFY(qFuzzyCompare(targetTransform.scale3D(), QVector3D(3.0f, 3.0f, 3.0f))); + QVERIFY(qFuzzyCompare(targetTransform.translation(), QVector3D(2.0f, 0.0f, 2.0f))); + QVERIFY(qFuzzyCompare(targetTransform.rotation(), + QQuaternion::fromEulerAngles(QVector3D(0.0f, 0.0f, 90.0f)))); + + // WHEN + keyframeAnimation.setStartMode(Qt3DAnimation::QKeyframeAnimation::Repeat); + keyframeAnimation.setEndMode(Qt3DAnimation::QKeyframeAnimation::Repeat); + keyframeAnimation.setPosition(-1.0f); + + // THEN + QVERIFY(qFuzzyCompare(targetTransform.scale3D(), QVector3D(2.0f, 2.0f, 2.0f))); + QVERIFY(qFuzzyCompare(targetTransform.translation(), QVector3D(1.0f, 1.0f, 0.0f))); + QVERIFY(qFuzzyCompare(targetTransform.rotation(), + QQuaternion::fromEulerAngles(QVector3D(0.0f, 45.0f, 0.0f)))); + + // WHEN + keyframeAnimation.setStartMode(Qt3DAnimation::QKeyframeAnimation::Repeat); + keyframeAnimation.setEndMode(Qt3DAnimation::QKeyframeAnimation::Repeat); + keyframeAnimation.setPosition(4.0f); + + // THEN + QVERIFY(qFuzzyCompare(targetTransform.scale3D(), QVector3D(1.0f, 1.0f, 1.0f))); + QVERIFY(qFuzzyCompare(targetTransform.translation(), QVector3D(0.0f, 0.0f, 0.0f))); + QVERIFY(qFuzzyCompare(targetTransform.rotation(), + QQuaternion::fromEulerAngles(QVector3D(0.0f, 0.0f, 0.0f)))); + } + } +}; + +QTEST_APPLESS_MAIN(tst_QKeyframeAnimation) + +#include "tst_qkeyframeanimation.moc" diff --git a/tests/auto/animation/qmorphinganimation/qmorphinganimation.pro b/tests/auto/animation/qmorphinganimation/qmorphinganimation.pro new file mode 100644 index 000000000..aaad3b763 --- /dev/null +++ b/tests/auto/animation/qmorphinganimation/qmorphinganimation.pro @@ -0,0 +1,10 @@ +TEMPLATE = app + +TARGET = tst_qmorphinganimation + +QT += 3dcore 3dcore-private 3drender 3drender-private 3danimation testlib + +CONFIG += testcase + +SOURCES += tst_qmorphinganimation.cpp + diff --git a/tests/auto/animation/qmorphinganimation/tst_qmorphinganimation.cpp b/tests/auto/animation/qmorphinganimation/tst_qmorphinganimation.cpp new file mode 100644 index 000000000..77ff01851 --- /dev/null +++ b/tests/auto/animation/qmorphinganimation/tst_qmorphinganimation.cpp @@ -0,0 +1,309 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** 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 +#include +#include +#include + +class tst_QMorphingAnimation : public QObject +{ + Q_OBJECT + + bool verifyAttribute(Qt3DRender::QGeometry *geometry, QString name, + Qt3DRender::QAttribute *attribute) + { + const QVector attributes = geometry->attributes(); + for (const Qt3DRender::QAttribute *attr : attributes) { + if (attr->name() == name) { + if (attr == attribute) + return true; + return false; + } + } + return false; + } + +private Q_SLOTS: + + void initTestCase() + { + qRegisterMetaType("QMorphingAnimation::Method"); + } + + void checkDefaultConstruction() + { + // GIVEN + Qt3DAnimation::QMorphingAnimation morphingAnimation; + + // THEN + QCOMPARE(morphingAnimation.interpolator(), 0.0f); + QCOMPARE(morphingAnimation.target(), nullptr); + QCOMPARE(morphingAnimation.targetName(), QString()); + QCOMPARE(morphingAnimation.method(), Qt3DAnimation::QMorphingAnimation::Relative); + QCOMPARE(morphingAnimation.easing(), QEasingCurve()); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::QMorphingAnimation morphingAnimation; + + { + // WHEN + QScopedPointer gr(new Qt3DRender::QGeometryRenderer); + QSignalSpy spy(&morphingAnimation, + SIGNAL(targetChanged(Qt3DRender::QGeometryRenderer *))); + Qt3DRender::QGeometryRenderer *newValue = gr.data(); + morphingAnimation.setTarget(newValue); + + // THEN + QCOMPARE(morphingAnimation.target(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + morphingAnimation.setTarget(newValue); + + // THEN + QCOMPARE(morphingAnimation.target(), newValue); + QCOMPARE(spy.count(), 0); + + } + { + // WHEN + QSignalSpy spy(&morphingAnimation, SIGNAL(targetNameChanged(QString))); + const QString newValue = QString("target"); + morphingAnimation.setTargetName(newValue); + + // THEN + QCOMPARE(morphingAnimation.targetName(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + morphingAnimation.setTargetName(newValue); + + // THEN + QCOMPARE(morphingAnimation.targetName(), newValue); + QCOMPARE(spy.count(), 0); + + } + { + // WHEN + QSignalSpy spy(&morphingAnimation, SIGNAL(methodChanged(QMorphingAnimation::Method))); + const Qt3DAnimation::QMorphingAnimation::Method newValue + = Qt3DAnimation::QMorphingAnimation::Normalized; + morphingAnimation.setMethod(newValue); + + // THEN + QCOMPARE(morphingAnimation.method(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + morphingAnimation.setMethod(newValue); + + // THEN + QCOMPARE(morphingAnimation.method(), newValue); + QCOMPARE(spy.count(), 0); + + } + { + // WHEN + QSignalSpy spy(&morphingAnimation, SIGNAL(easingChanged(QEasingCurve))); + const QEasingCurve newValue = QEasingCurve(QEasingCurve::InBounce); + morphingAnimation.setEasing(newValue); + + // THEN + QCOMPARE(morphingAnimation.easing(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + morphingAnimation.setEasing(newValue); + + // THEN + QCOMPARE(morphingAnimation.easing(), newValue); + QCOMPARE(spy.count(), 0); + + } + } + + void testAnimation() + { + // GIVEN + const QString baseName("position"); + const QString targetName("positionTarget"); + Qt3DAnimation::QMorphingAnimation morphingAnimation; + Qt3DRender::QAttribute *base = new Qt3DRender::QAttribute; + + Qt3DRender::QGeometry *geometry = new Qt3DRender::QGeometry; + Qt3DAnimation::QMorphTarget *mt1 = new Qt3DAnimation::QMorphTarget(&morphingAnimation); + Qt3DAnimation::QMorphTarget *mt2 = new Qt3DAnimation::QMorphTarget(&morphingAnimation); + Qt3DAnimation::QMorphTarget *mt3 = new Qt3DAnimation::QMorphTarget(&morphingAnimation); + Qt3DRender::QAttribute *a1 = new Qt3DRender::QAttribute(geometry); + Qt3DRender::QAttribute *a2 = new Qt3DRender::QAttribute(geometry); + Qt3DRender::QAttribute *a3 = new Qt3DRender::QAttribute(geometry); + Qt3DRender::QGeometryRenderer gr; + + base->setName(baseName); + geometry->addAttribute(base); + gr.setGeometry(geometry); + morphingAnimation.setTarget(&gr); + a1->setName(baseName); + a2->setName(baseName); + a3->setName(baseName); + mt1->addAttribute(a1); + mt2->addAttribute(a2); + mt3->addAttribute(a3); + morphingAnimation.addMorphTarget(mt1); + morphingAnimation.addMorphTarget(mt2); + morphingAnimation.addMorphTarget(mt3); + + QVector positions; + QVector weights; + positions.push_back(0.0f); + positions.push_back(1.0f); + positions.push_back(2.0f); + positions.push_back(3.0f); + positions.push_back(4.0f); + morphingAnimation.setTargetPositions(positions); + + weights.resize(3); + + weights[0] = 1.0f; + weights[1] = 0.0f; + weights[2] = 0.0f; + morphingAnimation.setWeights(0, weights); + weights[0] = 0.0f; + weights[1] = 0.0f; + weights[2] = 0.0f; + morphingAnimation.setWeights(1, weights); + weights[0] = 0.0f; + weights[1] = 1.0f; + weights[2] = 0.0f; + morphingAnimation.setWeights(2, weights); + weights[0] = 0.0f; + weights[1] = 0.0f; + weights[2] = 0.0f; + morphingAnimation.setWeights(3, weights); + weights[0] = 0.0f; + weights[1] = 0.0f; + weights[2] = 1.0f; + morphingAnimation.setWeights(4, weights); + + morphingAnimation.setMethod(Qt3DAnimation::QMorphingAnimation::Relative); + { + // WHEN + morphingAnimation.setPosition(0.0f); + + // THEN + QVERIFY(qFuzzyCompare(morphingAnimation.interpolator(), -1.0f)); + QVERIFY(verifyAttribute(geometry, baseName, base)); + QVERIFY(verifyAttribute(geometry, targetName, a1)); + + // WHEN + morphingAnimation.setPosition(0.5f); + + // THEN + QVERIFY(qFuzzyCompare(morphingAnimation.interpolator(), -0.5f)); + QVERIFY(verifyAttribute(geometry, baseName, base)); + QVERIFY(verifyAttribute(geometry, targetName, a1)); + + // WHEN + morphingAnimation.setPosition(1.0f); + + // THEN + QVERIFY(qFuzzyCompare(morphingAnimation.interpolator(), -0.0f)); + QVERIFY(verifyAttribute(geometry, baseName, base)); + + // WHEN + morphingAnimation.setPosition(1.5f); + + // THEN + QVERIFY(qFuzzyCompare(morphingAnimation.interpolator(), -0.5f)); + QVERIFY(verifyAttribute(geometry, baseName, base)); + QVERIFY(verifyAttribute(geometry, targetName, a2)); + + // WHEN + morphingAnimation.setPosition(4.0f); + + // THEN + QVERIFY(qFuzzyCompare(morphingAnimation.interpolator(), -1.0f)); + QVERIFY(verifyAttribute(geometry, baseName, base)); + QVERIFY(verifyAttribute(geometry, targetName, a3)); + } + + morphingAnimation.setMethod(Qt3DAnimation::QMorphingAnimation::Normalized); + { + // WHEN + morphingAnimation.setPosition(0.0f); + + // THEN + QVERIFY(qFuzzyCompare(morphingAnimation.interpolator(), 1.0f)); + QVERIFY(verifyAttribute(geometry, baseName, base)); + QVERIFY(verifyAttribute(geometry, targetName, a1)); + + // WHEN + morphingAnimation.setPosition(0.5f); + + // THEN + QVERIFY(qFuzzyCompare(morphingAnimation.interpolator(), 0.5f)); + QVERIFY(verifyAttribute(geometry, baseName, base)); + QVERIFY(verifyAttribute(geometry, targetName, a1)); + + // WHEN + morphingAnimation.setPosition(1.0f); + + // THEN + QVERIFY(qFuzzyCompare(morphingAnimation.interpolator(), 0.0f)); + QVERIFY(verifyAttribute(geometry, baseName, base)); + + // WHEN + morphingAnimation.setPosition(1.5f); + + // THEN + QVERIFY(qFuzzyCompare(morphingAnimation.interpolator(), 0.5f)); + QVERIFY(verifyAttribute(geometry, baseName, base)); + QVERIFY(verifyAttribute(geometry, targetName, a2)); + + // WHEN + morphingAnimation.setPosition(4.0f); + + // THEN + QVERIFY(qFuzzyCompare(morphingAnimation.interpolator(), 1.0f)); + QVERIFY(verifyAttribute(geometry, baseName, base)); + QVERIFY(verifyAttribute(geometry, targetName, a3)); + } + } +}; + +QTEST_APPLESS_MAIN(tst_QMorphingAnimation) + +#include "tst_qmorphinganimation.moc" diff --git a/tests/auto/animation/qmorphtarget/qmorphtarget.pro b/tests/auto/animation/qmorphtarget/qmorphtarget.pro new file mode 100644 index 000000000..bb38aad19 --- /dev/null +++ b/tests/auto/animation/qmorphtarget/qmorphtarget.pro @@ -0,0 +1,10 @@ +TEMPLATE = app + +TARGET = tst_qmorphtarget + +QT += 3dcore 3dcore-private 3drender 3drender-private 3danimation testlib + +CONFIG += testcase + +SOURCES += tst_qmorphtarget.cpp + diff --git a/tests/auto/animation/qmorphtarget/tst_qmorphtarget.cpp b/tests/auto/animation/qmorphtarget/tst_qmorphtarget.cpp new file mode 100644 index 000000000..2cba9ba2a --- /dev/null +++ b/tests/auto/animation/qmorphtarget/tst_qmorphtarget.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** 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 +#include +#include +#include + +class tst_QMorphTarget : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void checkDefaultConstruction() + { + // GIVEN + Qt3DAnimation::QMorphTarget morphTarget; + + // THEN + QCOMPARE(morphTarget.attributeNames(), QStringList()); + } + + void testSetAttributes() + { + // GIVEN + Qt3DAnimation::QMorphTarget morphTarget; + Qt3DRender::QAttribute attribute1; + Qt3DRender::QAttribute attribute2; + + attribute1.setName(Qt3DRender::QAttribute::defaultPositionAttributeName()); + attribute2.setName(Qt3DRender::QAttribute::defaultNormalAttributeName()); + + { + // WHEN + morphTarget.addAttribute(&attribute1); + + // THEN + QStringList names = morphTarget.attributeNames(); + QCOMPARE(names.size(), 1); + QCOMPARE(names.at(0), Qt3DRender::QAttribute::defaultPositionAttributeName()); + } + + { + // WHEN + morphTarget.addAttribute(&attribute2); + + // THEN + QStringList names = morphTarget.attributeNames(); + QCOMPARE(names.size(), 2); + QCOMPARE(names.at(1), Qt3DRender::QAttribute::defaultNormalAttributeName()); + } + } + + void testFromGeometry() + { + // GIVEN + Qt3DRender::QGeometry geometry; + Qt3DRender::QAttribute *attribute1 = new Qt3DRender::QAttribute; + Qt3DRender::QAttribute *attribute2 = new Qt3DRender::QAttribute; + attribute1->setName(Qt3DRender::QAttribute::defaultPositionAttributeName()); + attribute2->setName(Qt3DRender::QAttribute::defaultTextureCoordinateAttributeName()); + geometry.addAttribute(attribute1); + geometry.addAttribute(attribute2); + + QStringList attributes; + attributes.push_back(Qt3DRender::QAttribute::defaultPositionAttributeName()); + + { + // WHEN + QScopedPointer morphTarget( + Qt3DAnimation::QMorphTarget::fromGeometry(&geometry, attributes)); + + // THEN + QStringList names = morphTarget->attributeNames(); + QCOMPARE(names.size(), 1); + QCOMPARE(names.at(0), Qt3DRender::QAttribute::defaultPositionAttributeName()); + } + + { + // WHEN + attributes.push_back(Qt3DRender::QAttribute::defaultTextureCoordinateAttributeName()); + QScopedPointer morphTarget( + Qt3DAnimation::QMorphTarget::fromGeometry(&geometry, attributes)); + + // THEN + QStringList names = morphTarget->attributeNames(); + QCOMPARE(names.size(), 2); + QCOMPARE(names.at(0), Qt3DRender::QAttribute::defaultPositionAttributeName()); + QCOMPARE(names.at(1), Qt3DRender::QAttribute::defaultTextureCoordinateAttributeName()); + } + } + +}; + +QTEST_APPLESS_MAIN(tst_QMorphTarget) + +#include "tst_qmorphtarget.moc" diff --git a/tests/auto/animation/qvertexblendanimation/qvertexblendanimation.pro b/tests/auto/animation/qvertexblendanimation/qvertexblendanimation.pro new file mode 100644 index 000000000..8079ebf15 --- /dev/null +++ b/tests/auto/animation/qvertexblendanimation/qvertexblendanimation.pro @@ -0,0 +1,10 @@ +TEMPLATE = app + +TARGET = tst_qvertexblendanimation + +QT += 3dcore 3dcore-private 3drender 3drender-private 3danimation testlib + +CONFIG += testcase + +SOURCES += tst_qvertexblendanimation.cpp + diff --git a/tests/auto/animation/qvertexblendanimation/tst_qvertexblendanimation.cpp b/tests/auto/animation/qvertexblendanimation/tst_qvertexblendanimation.cpp new file mode 100644 index 000000000..dc27e4a7e --- /dev/null +++ b/tests/auto/animation/qvertexblendanimation/tst_qvertexblendanimation.cpp @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** 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 +#include +#include +#include + +class tst_QVertexBlendAnimation : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void checkDefaultConstruction() + { + // GIVEN + Qt3DAnimation::QVertexBlendAnimation vertexBlendAnimation; + + // THEN + QCOMPARE(vertexBlendAnimation.interpolator(), 0.0f); + QCOMPARE(vertexBlendAnimation.target(), nullptr); + QCOMPARE(vertexBlendAnimation.targetName(), QString()); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DAnimation::QVertexBlendAnimation vertexBlendAnimation; + + { + // WHEN + QScopedPointer gm(new Qt3DRender::QGeometryRenderer); + QSignalSpy spy(&vertexBlendAnimation, + SIGNAL(targetChanged(Qt3DRender::QGeometryRenderer *))); + Qt3DRender::QGeometryRenderer *newValue = gm.data(); + vertexBlendAnimation.setTarget(newValue); + + // THEN + QCOMPARE(vertexBlendAnimation.target(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + vertexBlendAnimation.setTarget(newValue); + + // THEN + QCOMPARE(vertexBlendAnimation.target(), newValue); + QCOMPARE(spy.count(), 0); + + } + { + // WHEN + QSignalSpy spy(&vertexBlendAnimation, SIGNAL(targetNameChanged(QString))); + const QString newValue = QString("target"); + vertexBlendAnimation.setTargetName(newValue); + + // THEN + QCOMPARE(vertexBlendAnimation.targetName(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + vertexBlendAnimation.setTargetName(newValue); + + // THEN + QCOMPARE(vertexBlendAnimation.targetName(), newValue); + QCOMPARE(spy.count(), 0); + + } + } + +}; + +QTEST_APPLESS_MAIN(tst_QVertexBlendAnimation) + +#include "tst_qvertexblendanimation.moc" -- cgit v1.2.3 From 337bc59bb3a162d1a64b05d1dc82b5ec4b99049d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Mon, 13 Mar 2017 09:32:53 +0200 Subject: Scene2D cleanup - register pick events when scene is initialized MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current model where mouseGrab is connected to picker signal doesn't work. The pressed event is not sent to scene2d item, because it is already lost when scene2d gets the grabMouse message where it registers to the picker events. This breaks the mouse event sequence (press-move-release) for the quick item. Instead hook to setScene of the node to message scene2d when the scene gets initialized and always register to the picker events. Task-number: QTBUG-58876 Change-Id: Ic9ca4b0899a030336ef20ff2cffbe10b567c36f5 Reviewed-by: Antti Määttä --- tests/auto/render/qscene2d/tst_qscene2d.cpp | 55 +++++++++++++++++++++++++++++ tests/auto/render/scene2d/tst_scene2d.cpp | 20 +++++------ 2 files changed, 65 insertions(+), 10 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/qscene2d/tst_qscene2d.cpp b/tests/auto/render/qscene2d/tst_qscene2d.cpp index 61ac893e4..846207456 100644 --- a/tests/auto/render/qscene2d/tst_qscene2d.cpp +++ b/tests/auto/render/qscene2d/tst_qscene2d.cpp @@ -60,6 +60,7 @@ private Q_SLOTS: QCOMPARE(scene2d.output(), nullptr); QCOMPARE(scene2d.renderPolicy(), QScene2D::Continuous); QCOMPARE(scene2d.item(), nullptr); + QCOMPARE(scene2d.isMouseEnabled(), true); } void checkPropertyChanges() @@ -126,6 +127,26 @@ private Q_SLOTS: QCOMPARE(scene2d.item(), newValue); QCOMPARE(spy.count(), 0); } + + { + // WHEN + QSignalSpy spy(&scene2d, SIGNAL(mouseEnabledChanged(bool))); + bool newValue = false; + scene2d.setMouseEnabled(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(scene2d.isMouseEnabled(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + scene2d.setMouseEnabled(newValue); + + // THEN + QCOMPARE(scene2d.isMouseEnabled(), newValue); + QCOMPARE(spy.count(), 0); + } } void checkCreationData() @@ -159,6 +180,7 @@ private Q_SLOTS: QCOMPARE(scene2d.isEnabled(), true); QCOMPARE(scene2d.isEnabled(), creationChangeData->isNodeEnabled()); QCOMPARE(scene2d.metaObject(), creationChangeData->metaObject()); + QCOMPARE(scene2d.isMouseEnabled(), cloneData.mouseEnabled); } // WHEN @@ -254,6 +276,39 @@ private Q_SLOTS: } + void checkMouseEnabledUpdate() + { + // GIVEN + TestArbiter arbiter; + Qt3DRender::Quick::QScene2D scene2d; + arbiter.setArbiterOnNode(&scene2d); + + { + // WHEN + scene2d.setMouseEnabled(false); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "mouseEnabled"); + QCOMPARE(change->value().toBool(), scene2d.isMouseEnabled()); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } + + { + // WHEN + scene2d.setMouseEnabled(false); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + + } + }; QTEST_MAIN(tst_QScene2D) diff --git a/tests/auto/render/scene2d/tst_scene2d.cpp b/tests/auto/render/scene2d/tst_scene2d.cpp index a4810ce66..a78ed0ab1 100644 --- a/tests/auto/render/scene2d/tst_scene2d.cpp +++ b/tests/auto/render/scene2d/tst_scene2d.cpp @@ -114,6 +114,7 @@ private Q_SLOTS: QCOMPARE(backendScene2d.m_initialized, false); QCOMPARE(backendScene2d.m_renderInitialized, false); QCOMPARE(backendScene2d.m_renderPolicy, QScene2D::Continuous); + QCOMPARE(backendScene2d.m_mouseEnabled, true); backendScene2d.cleanup(); } @@ -135,6 +136,7 @@ private Q_SLOTS: QCOMPARE(backendScene2d->m_outputId, Qt3DCore::QNodeId()); QVERIFY(backendScene2d->m_sharedObject.data() != nullptr); QCOMPARE(backendScene2d->m_renderPolicy, QScene2D::Continuous); + QCOMPARE(backendScene2d->m_mouseEnabled, true); backendScene2d->cleanup(); } { @@ -183,28 +185,25 @@ private Q_SLOTS: } { // WHEN - const QSharedPointer newValue - = QSharedPointer( - new Qt3DRender::Quick::Scene2DSharedObject(nullptr)); + const QScene2D::RenderPolicy newValue = QScene2D::SingleShot; const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("sharedObject"); + change->setPropertyName("renderPolicy"); change->setValue(QVariant::fromValue(newValue)); backendScene2d->sceneChangeEvent(change); // THEN - QCOMPARE(backendScene2d->m_sharedObject, newValue); - QCOMPARE(backendScene2d->m_sharedObject.data(), newValue.data()); + QCOMPARE(backendScene2d->m_renderPolicy, newValue); } { // WHEN - const QScene2D::RenderPolicy newValue = QScene2D::SingleShot; + const bool newValue = false; const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("renderPolicy"); - change->setValue(QVariant::fromValue(newValue)); + change->setPropertyName("mouseEnabled"); + change->setValue(newValue); backendScene2d->sceneChangeEvent(change); // THEN - QCOMPARE(backendScene2d->m_renderPolicy, newValue); + QCOMPARE(backendScene2d->isEnabled(), newValue); } backendScene2d->cleanup(); @@ -228,6 +227,7 @@ private Q_SLOTS: TestRenderer renderer; renderer.setNodeManagers(nodeManagers.data()); scene2d->setRenderer(&renderer); + scene2d->setEnabled(true); sharedObject->m_quickWindow = testWindow.data(); scene2d->setSharedObject(sharedObject); testWindow->setGeometry(0,0,1024,1024); -- cgit v1.2.3 From 2eb53d735488cd2fb609e51c036c5ee3554557c7 Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Tue, 9 May 2017 14:23:24 +0200 Subject: QNode: setParent create creation change only when needed Two cases need to be handled by setParent: 1) Parent already has a backend node and receives a new child -> in which case we need to send the creation event to the backend 2) Parent was created in the frontend, but has no backend (delayed notification sending because a ctor can't call a virtual) -> in that case, when adding a child and setting its parent we shouldn't be sending the creation change. We rather let that be handled when the creation change for the parent is requested Change-Id: I434c7d4e6af785c0314ac6538dc689992d90ed0c Task-number: QTBUG-60612 Reviewed-by: Sean Harmer Reviewed-by: Oleg Evseev --- tests/auto/core/nodes/tst_nodes.cpp | 63 +++++++++++++++++++++- .../core/qchangearbiter/tst_qchangearbiter.cpp | 4 ++ tests/auto/core/qscene/tst_qscene.cpp | 3 ++ 3 files changed, 68 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/core/nodes/tst_nodes.cpp b/tests/auto/core/nodes/tst_nodes.cpp index 89d396931..25c2a6dba 100644 --- a/tests/auto/core/nodes/tst_nodes.cpp +++ b/tests/auto/core/nodes/tst_nodes.cpp @@ -79,6 +79,8 @@ private slots: void appendingChildEntitiesToNode(); void removingChildEntitiesFromNode(); + void checkConstructionSetParentMix(); // QTBUG-60612 + void appendingComponentToEntity(); void appendingParentlessComponentToEntity(); void removingComponentFromEntity(); @@ -204,6 +206,11 @@ public: Qt3DCore::QNodePrivate::get(this)->setArbiter(arbiter); } + void setSimulateBackendCreated(bool created) + { + Qt3DCore::QNodePrivate::get(this)->m_hasBackendNode = created; + } + signals: void customPropertyChanged(); @@ -232,6 +239,11 @@ public: Qt3DCore::QNodePrivate::get(this)->setScene(scene); Qt3DCore::QNodePrivate::get(this)->setArbiter(arbiter); } + + void setSimulateBackendCreated(bool created) + { + Qt3DCore::QNodePrivate::get(this)->m_hasBackendNode = created; + } }; class MyQComponent : public Qt3DCore::QComponent @@ -389,6 +401,8 @@ void tst_Nodes::appendSingleChildNodeToNodeSceneExplicitParenting() QScopedPointer node(new MyQNode()); // WHEN node->setArbiterAndScene(&spy, &scene); + node->setSimulateBackendCreated(true); + // THEN QVERIFY(Qt3DCore::QNodePrivate::get(node.data())->scene() != nullptr); @@ -405,7 +419,7 @@ void tst_Nodes::appendSingleChildNodeToNodeSceneExplicitParenting() // THEN QVERIFY(child->parent() == node.data()); QVERIFY(child->parentNode() == node.data()); - QCOMPARE(spy.events.size(), 2); + QCOMPARE(spy.events.size(), 2); // Created + Child Added QCOMPARE(node->children().count(), 1); QVERIFY(Qt3DCore::QNodePrivate::get(child.data())->scene() != nullptr); @@ -482,6 +496,7 @@ void tst_Nodes::appendMultipleChildNodesToNodeScene() // WHEN node->setArbiterAndScene(&spy, &scene); + node->setSimulateBackendCreated(true); // THEN QVERIFY(Qt3DCore::QNodePrivate::get(node.data())->scene() != nullptr); @@ -664,6 +679,7 @@ void tst_Nodes::removingSingleChildNodeFromNode() // WHEN root->setArbiterAndScene(&spy, &scene); + root->setSimulateBackendCreated(true); child->setParent(root.data()); // Clear any creation event @@ -790,6 +806,47 @@ void tst_Nodes::removingChildEntitiesFromNode() QVERIFY(childEntity->parent() == nullptr); } +void tst_Nodes::checkConstructionSetParentMix() +{ + // GIVEN + ObserverSpy spy; + Qt3DCore::QScene scene; + QScopedPointer 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()); + + for (int i = 0; i < 100; ++i) { + Qt3DCore::QEntity *child = new Qt3DCore::QEntity(); + child->setParent(subTreeRoot); + } + + // THEN + QCoreApplication::processEvents(); + QCOMPARE(root->children().count(), 1); + QCOMPARE(subTreeRoot->children().count(), 100); + QCOMPARE(spy.events.size(), 102); // 1 subTreeRoot creation change, 100 child creation, 1 child added (subTree to root) + + // Ensure first event is subTreeRoot + const Qt3DCore::QNodeCreatedChangeBasePtr firstEvent = spy.events.takeFirst().change().dynamicCast(); + QVERIFY(!firstEvent.isNull()); + QCOMPARE(firstEvent->subjectId(), subTreeRoot->id()); + QCOMPARE(firstEvent->parentId(), root->id()); + + const Qt3DCore::QPropertyNodeAddedChangePtr lastEvent = spy.events.takeLast().change().dynamicCast(); + QVERIFY(!lastEvent.isNull()); + QCOMPARE(lastEvent->subjectId(), root->id()); + QCOMPARE(lastEvent->propertyName(), "children"); + QCOMPARE(lastEvent->addedNodeId(), subTreeRoot->id()); +} + void tst_Nodes::appendingParentlessComponentToEntity() { // GIVEN @@ -798,6 +855,8 @@ void tst_Nodes::appendingParentlessComponentToEntity() { QScopedPointer entity(new MyQEntity()); entity->setArbiterAndScene(&entitySpy); + entity->setSimulateBackendCreated(true); + MyQComponent *comp = new MyQComponent(); comp->setArbiter(&componentSpy); @@ -816,7 +875,7 @@ void tst_Nodes::appendingParentlessComponentToEntity() QVERIFY(comp->parentNode() == entity.data()); QCOMPARE(entitySpy.events.size(), 1); QVERIFY(entitySpy.events.first().wasLocked()); - QCOMPARE(componentSpy.events.size(), 2); // first event is parent being set + QCOMPARE(componentSpy.events.size(), 1); // Note: since QEntity has no scene in this test case, we only have the // ComponentAdded event In theory we should also get the NodeCreated event diff --git a/tests/auto/core/qchangearbiter/tst_qchangearbiter.cpp b/tests/auto/core/qchangearbiter/tst_qchangearbiter.cpp index 061de06fa..faccb6d34 100644 --- a/tests/auto/core/qchangearbiter/tst_qchangearbiter.cpp +++ b/tests/auto/core/qchangearbiter/tst_qchangearbiter.cpp @@ -442,6 +442,7 @@ void tst_QChangeArbiter::registerSceneObserver() tst_Node *root = new tst_Node(); Qt3DCore::QNode *child = new tst_Node(); Qt3DCore::QNodePrivate::get(root)->setScene(scene.data()); + Qt3DCore::QNodePrivate::get(root)->m_hasBackendNode = true; scene->addObservable(root); QList observers; @@ -573,6 +574,7 @@ void tst_QChangeArbiter::unregisterSceneObservers() tst_Node *root = new tst_Node(); Qt3DCore::QNode *child = new tst_Node(); Qt3DCore::QNodePrivate::get(root)->setScene(scene.data()); + Qt3DCore::QNodePrivate::get(root)->m_hasBackendNode = true; scene->addObservable(root); QList observers; @@ -796,6 +798,7 @@ void tst_QChangeArbiter::distributePropertyChanges() // WHEN PropertyTestNode *root = new PropertyTestNode(); Qt3DCore::QNodePrivate::get(root)->setScene(scene.data()); + Qt3DCore::QNodePrivate::get(root)->m_hasBackendNode = true; scene->addObservable(root); tst_SimpleObserver *rootObserver = new tst_SimpleObserver(); @@ -890,6 +893,7 @@ void tst_QChangeArbiter::distributeBackendChanges() // WHEN tst_Node *root = new tst_Node(); Qt3DCore::QNodePrivate::get(root)->setScene(scene.data()); + Qt3DCore::QNodePrivate::get(root)->m_hasBackendNode = true; scene->addObservable(root); tst_BackendObserverObservable *backenObserverObservable = new tst_BackendObserverObservable(); diff --git a/tests/auto/core/qscene/tst_qscene.cpp b/tests/auto/core/qscene/tst_qscene.cpp index f4b04362d..78f17e8fa 100644 --- a/tests/auto/core/qscene/tst_qscene.cpp +++ b/tests/auto/core/qscene/tst_qscene.cpp @@ -297,6 +297,8 @@ void tst_QScene::deleteChildNode() Qt3DCore::QNode *root2 = new tst_Node(); Qt3DCore::QNodePrivate::get(root1)->setScene(scene); Qt3DCore::QNodePrivate::get(root2)->setScene(scene); + Qt3DCore::QNodePrivate::get(root1)->m_hasBackendNode = true; + Qt3DCore::QNodePrivate::get(root2)->m_hasBackendNode = true; // WHEN scene->addObservable(root1); @@ -358,6 +360,7 @@ void tst_QScene::removeChildNode() Qt3DCore::QNode *root = new tst_Node; Qt3DCore::QNodePrivate::get(root)->setScene(scene); + Qt3DCore::QNodePrivate::get(root)->m_hasBackendNode = true; scene->addObservable(root); // WHEN -- cgit v1.2.3 From ac0f074a96fcb980b409a6deb961e6594ee1a9b8 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Thu, 11 May 2017 16:08:48 +0100 Subject: Remove duplicate subdirs target that slipped in MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ia2c5a7ae98d5a3cbf7c0981caeccaa4245a57707 Reviewed-by: Antti Määttä --- tests/auto/animation/animation.pro | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/animation/animation.pro b/tests/auto/animation/animation.pro index d3ef37a61..b48fd347b 100644 --- a/tests/auto/animation/animation.pro +++ b/tests/auto/animation/animation.pro @@ -13,8 +13,7 @@ SUBDIRS += \ qkeyframeanimation \ qmorphinganimation \ qmorphtarget \ - qvertexblendanimation \ - qanimationcontroller + qvertexblendanimation qtConfig(private_tests) { SUBDIRS += \ -- cgit v1.2.3 From a89a2b8bc32c440ee5515911a4a120fe232111a9 Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Tue, 11 Apr 2017 11:26:32 +0100 Subject: Add download service and use for remote meshes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a new QDownloadHelpService. Can be provided with QDownloadRequests which will trigger downloads and return the data in a QByteArray. Downloads are triggered in a separate thread and requests have the opportunity to do long running operations there (it will block other requests though). Implemented for downloading meshes. When the functor is triggered, it checks the url and submits a request for download. When that completes, it’ll save the data in the functor and mark the component as dirty that that a job will run again to complete the parsing. LATER (5.10): - status property, progress maybe Task-number: QTBUG-57614 Change-Id: I05abe9610e12670a368d480b2fb3115987201e6b Reviewed-by: Sean Harmer --- tests/auto/render/qmesh/tst_qmesh.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/qmesh/tst_qmesh.cpp b/tests/auto/render/qmesh/tst_qmesh.cpp index 2122d7eb5..a0278f4e4 100644 --- a/tests/auto/render/qmesh/tst_qmesh.cpp +++ b/tests/auto/render/qmesh/tst_qmesh.cpp @@ -121,7 +121,7 @@ private Q_SLOTS: const auto creationChangeData = qSharedPointerCast>(creationChanges.first()); const Qt3DRender::QGeometryRendererData cloneData = creationChangeData->data; - Qt3DRender::MeshFunctor meshFunctor(mesh.source(), mesh.meshName()); + Qt3DRender::MeshLoaderFunctor meshFunctor(&mesh, nullptr); QVERIFY(meshFunctor == *cloneData.geometryFactory); QCOMPARE(mesh.id(), creationChangeData->subjectId()); @@ -169,7 +169,7 @@ private Q_SLOTS: QCOMPARE(change->propertyName(), "geometryFactory"); QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - Qt3DRender::MeshFunctor meshFunctor(mesh.source()); + Qt3DRender::MeshLoaderFunctor meshFunctor(&mesh, nullptr); Qt3DRender::QGeometryFactoryPtr factory = change->value().value(); QVERIFY(meshFunctor == *factory); @@ -205,7 +205,7 @@ private Q_SLOTS: QCOMPARE(change->propertyName(), "geometryFactory"); QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); - Qt3DRender::MeshFunctor meshFunctor(QUrl(), mesh.meshName()); + Qt3DRender::MeshLoaderFunctor meshFunctor(&mesh, nullptr); Qt3DRender::QGeometryFactoryPtr factory = change->value().value(); QVERIFY(meshFunctor == *factory); -- cgit v1.2.3 From ab0f38728cda3a5c819de6172febb0908c101967 Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Tue, 11 Apr 2017 11:26:32 +0100 Subject: Add support for remote content in SceneLoader Task-number: QTBUG-57614 Change-Id: I687a9620865f5849aaba2aadb5a9c3746afb0b53 Reviewed-by: Sean Harmer --- .../auto/render/loadscenejob/tst_loadscenejob.cpp | 30 +++++++++++++--------- tests/auto/render/sceneloader/tst_sceneloader.cpp | 4 +-- 2 files changed, 20 insertions(+), 14 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/render/loadscenejob/tst_loadscenejob.cpp b/tests/auto/render/loadscenejob/tst_loadscenejob.cpp index 08d1caace..e2e3997af 100644 --- a/tests/auto/render/loadscenejob/tst_loadscenejob.cpp +++ b/tests/auto/render/loadscenejob/tst_loadscenejob.cpp @@ -50,8 +50,14 @@ public: m_source = source; } - bool isFileTypeSupported(const QUrl &) const Q_DECL_OVERRIDE + void setData(const QByteArray& data, const QString &basePath) Q_DECL_OVERRIDE { + + } + + bool areFileTypesSupported(const QStringList &extensions) const + { + Q_UNUSED(extensions); return m_supportsFormat; } @@ -99,7 +105,7 @@ private Q_SLOTS: void checkInitialize() { // GIVEN - const QUrl url(QStringLiteral("URL")); + const QUrl url(QStringLiteral("file:///URL")); const Qt3DCore::QNodeId sceneId = Qt3DCore::QNodeId::createId(); Qt3DRender::Render::NodeManagers nodeManagers; TestSceneImporter fakeImporter(true, true); @@ -120,8 +126,10 @@ private Q_SLOTS: void checkRunValidSourceSupportedFormat() { + QSKIP("Can't test successful loading"); + // GIVEN - const QUrl url(QStringLiteral("URL")); + const QUrl url(QStringLiteral("file:///URL")); TestArbiter arbiter; Qt3DRender::Render::NodeManagers nodeManagers; TestSceneImporter fakeImporter(true, false); @@ -202,8 +210,11 @@ private Q_SLOTS: void checkRunValidSourceUnsupportedFormat() { + // no data is loaded so... + QSKIP("Can't differentiate between no data and unsupported data"); + // GIVEN - const QUrl url(QStringLiteral("URL")); + const QUrl url(QStringLiteral("file:///URL")); TestArbiter arbiter; Qt3DRender::Render::NodeManagers nodeManagers; TestSceneImporter fakeImporter(false, false); @@ -241,7 +252,7 @@ private Q_SLOTS: void checkRunErrorAtLoading() { // GIVEN - const QUrl url(QStringLiteral("URL")); + const QUrl url(QStringLiteral("file:///URL")); TestArbiter arbiter; Qt3DRender::Render::NodeManagers nodeManagers; TestSceneImporter fakeImporter(true, true); @@ -259,7 +270,7 @@ private Q_SLOTS: loadSceneJob.run(); // THEN - QCOMPARE(arbiter.events.count(), 4); + QCOMPARE(arbiter.events.count(), 3); auto change = arbiter.events.at(0).staticCast(); QCOMPARE(change->subjectId(), scene->peerId()); QCOMPARE(change->propertyName(), "status"); @@ -267,16 +278,11 @@ private Q_SLOTS: change = arbiter.events.at(1).staticCast(); QCOMPARE(change->subjectId(), scene->peerId()); - QCOMPARE(change->propertyName(), "status"); - QCOMPARE(change->value().value(), Qt3DRender::QSceneLoader::Loading); - - change = arbiter.events.at(2).staticCast(); - QCOMPARE(change->subjectId(), scene->peerId()); QCOMPARE(change->propertyName(), "scene"); QVERIFY(change->value().value() == nullptr); delete change->value().value(); - change = arbiter.events.at(3).staticCast(); + change = arbiter.events.at(2).staticCast(); QCOMPARE(change->subjectId(), scene->peerId()); QCOMPARE(change->propertyName(), "status"); QCOMPARE(change->value().value(), Qt3DRender::QSceneLoader::Error); diff --git a/tests/auto/render/sceneloader/tst_sceneloader.cpp b/tests/auto/render/sceneloader/tst_sceneloader.cpp index cd6d76a5a..975c2c892 100644 --- a/tests/auto/render/sceneloader/tst_sceneloader.cpp +++ b/tests/auto/render/sceneloader/tst_sceneloader.cpp @@ -79,7 +79,7 @@ private Q_SLOTS: { // GIVEN Qt3DRender::QSceneLoader frontendSceneLoader; - frontendSceneLoader.setSource(QUrl(QStringLiteral("CorvetteMuseum"))); + frontendSceneLoader.setSource(QUrl(QStringLiteral("file:///CorvetteMuseum"))); Qt3DRender::Render::Scene sceneLoader; Qt3DRender::Render::SceneManager sceneManager; @@ -109,7 +109,7 @@ private Q_SLOTS: // WHEN Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); - const QUrl newUrl(QStringLiteral("Bownling_Green_KY")); + const QUrl newUrl(QStringLiteral("file:///Bownling_Green_KY")); updateChange->setValue(newUrl); updateChange->setPropertyName("source"); sceneLoader.sceneChangeEvent(updateChange); -- cgit v1.2.3 From 939b9b4b7591e8a421cf048a0a84ed3e75d81d21 Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Wed, 25 Jan 2017 08:07:42 +0000 Subject: Add support to move the camera so that the entire model is visible Adds QCamera::viewAll(), QCamera::viewEntity() and QCamera::viewSphere() to move and rotate the camera so that the view center is the center of the sphere and the sphere fits inside the viewport Only works in perspective projection. Introduces a job to compute the bounding sphere of the scene excluding the camera. Change-Id: Id9d67787ea91c354009d5358d5db63a1c9480c70 Reviewed-by: Sean Harmer --- tests/auto/render/commons/testrenderer.h | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/auto') diff --git a/tests/auto/render/commons/testrenderer.h b/tests/auto/render/commons/testrenderer.h index 74f529fa0..031ca214b 100644 --- a/tests/auto/render/commons/testrenderer.h +++ b/tests/auto/render/commons/testrenderer.h @@ -60,6 +60,7 @@ public: QVector renderBinJobs() Q_DECL_OVERRIDE { return QVector(); } Qt3DCore::QAspectJobPtr pickBoundingVolumeJob() Q_DECL_OVERRIDE { return Qt3DCore::QAspectJobPtr(); } Qt3DCore::QAspectJobPtr syncTextureLoadingJob() Q_DECL_OVERRIDE { return Qt3DCore::QAspectJobPtr(); } + Qt3DCore::QAspectJobPtr expandBoundingVolumeJob() Q_DECL_OVERRIDE { return Qt3DCore::QAspectJobPtr(); } void setSceneRoot(Qt3DCore::QBackendNodeFactory *factory, Qt3DRender::Render::Entity *root) Q_DECL_OVERRIDE { Q_UNUSED(factory); Q_UNUSED(root); } Qt3DRender::Render::Entity *sceneRoot() const Q_DECL_OVERRIDE { return nullptr; } Qt3DRender::Render::FrameGraphNode *frameGraphRoot() const Q_DECL_OVERRIDE { return nullptr; } -- cgit v1.2.3