diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2017-04-26 10:57:56 +0200 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2017-04-27 06:13:03 +0000 |
commit | 51c1d5bdfe4da07b9408af2290e2e7b3c9010fcd (patch) | |
tree | 24092c56c050a916881fea309c2533bf1d56a8dd /tests/auto | |
parent | 5110969b84bf82f8b218762b7c409f3c4ee54707 (diff) |
Add unit tests for FrameGraphVisitor
Change-Id: I1ef3c275649fe874d2dc4c6caf81082729aca360
Reviewed-by: Kevin Ottens <kevin.ottens@kdab.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/render/framegraphvisitor/framegraphvisitor.pro | 13 | ||||
-rw-r--r-- | tests/auto/render/framegraphvisitor/tst_framegraphvisitor.cpp | 174 | ||||
-rw-r--r-- | tests/auto/render/render.pro | 3 |
3 files changed, 189 insertions, 1 deletions
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 <QtTest/QTest> +#include <Qt3DCore/qentity.h> + +#include <Qt3DRender/private/nodemanagers_p.h> +#include <Qt3DRender/private/managers_p.h> +#include <Qt3DRender/private/entity_p.h> + +#include <Qt3DRender/private/framegraphnode_p.h> +#include <Qt3DRender/private/framegraphvisitor_p.h> + +#include <Qt3DRender/qtechniquefilter.h> +#include <Qt3DRender/qnodraw.h> +#include <Qt3DRender/qfrustumculling.h> +#include <Qt3DRender/qviewport.h> + +#include "testaspect.h" + +namespace { + + + +} // anonymous + +using FGIdType = QPair<Qt3DCore::QNodeId, Qt3DRender::Render::FrameGraphNode::FrameGraphNodeType>; +using BranchIdsAndTypes = QVector<FGIdType>; + +Q_DECLARE_METATYPE(QVector<BranchIdsAndTypes>) + +class tst_FrameGraphVisitor : public QObject +{ + Q_OBJECT +private Q_SLOTS: + + void visitFGTree_data() + { + QTest::addColumn<Qt3DCore::QEntity *>("rootEntity"); + QTest::addColumn<Qt3DRender::QFrameGraphNode *>("fgRoot"); + QTest::addColumn<QVector<BranchIdsAndTypes>>("fgNodeIdsPerBranch"); + + { + Qt3DCore::QEntity *entity = new Qt3DCore::QEntity(); + Qt3DRender::QTechniqueFilter *techniqueFilter = new Qt3DRender::QTechniqueFilter(entity); + + QTest::newRow("singleNode") << entity + << static_cast<Qt3DRender::QFrameGraphNode *>(techniqueFilter) + << (QVector<BranchIdsAndTypes>() + << (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<Qt3DRender::QFrameGraphNode *>(techniqueFilter) + << (QVector<BranchIdsAndTypes>() + << (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<Qt3DRender::QFrameGraphNode *>(techniqueFilter) + << (QVector<BranchIdsAndTypes>() + << (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<BranchIdsAndTypes>, fgNodeIdsPerBranch); + QScopedPointer<Qt3DRender::TestAspect> 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<Qt3DRender::Render::FrameGraphNode *> 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 } |