diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2017-01-27 15:44:25 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-01-29 09:39:45 +0000 |
commit | 98399b24b778af6c26c8c73736805083ce614df5 (patch) | |
tree | ba0bfdcd0c316afaa20cf7729f3fc96b456afb01 /tests/auto/animation/clipblendnodevisitor | |
parent | c576a24d4fac9cdbd05aa264bf75050ca2ef0a94 (diff) |
Add ClipBlendNodeVisitor
Will allow to make the several tree traversals required to properly execute
blend trees
Change-Id: If9989ed4b46743bba0f1f30d08ff4eb8398aeacc
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests/auto/animation/clipblendnodevisitor')
-rw-r--r-- | tests/auto/animation/clipblendnodevisitor/clipblendnodevisitor.pro | 11 | ||||
-rw-r--r-- | tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp | 189 |
2 files changed, 200 insertions, 0 deletions
diff --git a/tests/auto/animation/clipblendnodevisitor/clipblendnodevisitor.pro b/tests/auto/animation/clipblendnodevisitor/clipblendnodevisitor.pro new file mode 100644 index 000000000..d08226a2f --- /dev/null +++ b/tests/auto/animation/clipblendnodevisitor/clipblendnodevisitor.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +TARGET = tst_clipblendnodevisitor + +QT += 3dcore 3dcore-private 3danimation 3danimation-private testlib + +CONFIG += testcase + +SOURCES += tst_clipblendnodevisitor.cpp + +include(../../core/common/common.pri) diff --git a/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp b/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp new file mode 100644 index 000000000..6c6723920 --- /dev/null +++ b/tests/auto/animation/clipblendnodevisitor/tst_clipblendnodevisitor.cpp @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Paul Lemire <paul.lemire350@gmail.com> +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QTest> +#include <QObject> +#include <QSignalSpy> +#include <Qt3DAnimation/private/managers_p.h> +#include <Qt3DAnimation/private/clipblendnodevisitor_p.h> +#include <Qt3DAnimation/private/lerpblend_p.h> +#include <Qt3DAnimation/qlerpblend.h> +#include "qbackendnodetester.h" + +class tst_ClipBlendNodeVisitor : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +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::Animation::ClipBlendNodeManager manager; + backendRootBlendNode->setClipBlendNodeManager(&manager); + backendChildBlendNode1->setClipBlendNodeManager(&manager); + backendChildBlendNode2->setClipBlendNodeManager(&manager); + backendChildBlendNode11->setClipBlendNodeManager(&manager); + backendChildBlendNode12->setClipBlendNodeManager(&manager); + + manager.appendNode(rootBlendNode.id(), backendRootBlendNode); + manager.appendNode(childBlendNode1.id(), backendChildBlendNode1); + manager.appendNode(childBlendNode2.id(), backendChildBlendNode2); + manager.appendNode(childBlendNode11.id(), backendChildBlendNode11); + manager.appendNode(childBlendNode12.id(), backendChildBlendNode12); + + // WHEN + simulateInitialization(&rootBlendNode, backendRootBlendNode); + simulateInitialization(&childBlendNode1, backendChildBlendNode1); + simulateInitialization(&childBlendNode2, backendChildBlendNode2); + simulateInitialization(&childBlendNode11, backendChildBlendNode11); + 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 + int i = 0; + auto childCounter = [&] (Qt3DAnimation::Animation::ClipBlendNode *node) { + if (i == 0) + QCOMPARE(node, backendRootBlendNode); + else if (i == 1) + QCOMPARE(node, backendChildBlendNode1); + else if (i == 2) + QCOMPARE(node, backendChildBlendNode11); + else if (i == 3) + QCOMPARE(node, backendChildBlendNode12); + else if (i == 4) + QCOMPARE(node, backendChildBlendNode2); + ++i; + }; + + // THEN -> no comparison failure + Qt3DAnimation::Animation::ClipBlendNodeVisitor visitor(&manager); + visitor.traverse(rootBlendNode.id(), childCounter); + } + + void checkDoesntCrashIfRootNodeIsNotFound() + { + // GIVEN + Qt3DAnimation::QLerpBlend rootBlendNode; + + Qt3DAnimation::Animation::LerpBlend *backendRootBlendNode = new Qt3DAnimation::Animation::LerpBlend(); + + Qt3DAnimation::Animation::ClipBlendNodeManager manager; + backendRootBlendNode->setClipBlendNodeManager(&manager); + + // We purposely forgot the to do: manager.appendNode(rootBlendNode.id(), backendRootBlendNode); + + // WHEN + simulateInitialization(&rootBlendNode, backendRootBlendNode); + + // THEN + QVERIFY(backendRootBlendNode->parentId().isNull()); + QCOMPARE(backendRootBlendNode->childrenIds().size(), 0); + + // WHEN + auto childCounter = [] (Qt3DAnimation::Animation::ClipBlendNode *) {}; + + // THEN -> shouldn't crash + Qt3DAnimation::Animation::ClipBlendNodeVisitor visitor(&manager); + visitor.traverse(rootBlendNode.id(), childCounter); + } + + void checkDoesntCrashIfChildNodeIsNotFound() + { + // GIVEN + Qt3DAnimation::QLerpBlend rootBlendNode; + Qt3DAnimation::QLerpBlend childBlendNode1(&rootBlendNode); + Qt3DAnimation::QLerpBlend 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::ClipBlendNodeManager manager; + backendRootBlendNode->setClipBlendNodeManager(&manager); + backendChildBlendNode1->setClipBlendNodeManager(&manager); + backendChildBlendNode2->setClipBlendNodeManager(&manager); + + manager.appendNode(rootBlendNode.id(), backendRootBlendNode); + // We purposely forgot the to do: + // manager.appendNode(childBlendNode1.id(), backendChildBlendNode1); + // manager.appendNode(childBlendNode2.id(), backendChildBlendNode2); + + + // WHEN + simulateInitialization(&rootBlendNode, backendRootBlendNode); + simulateInitialization(&childBlendNode1, backendChildBlendNode1); + 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 + int i = 0; + auto childCounter = [&] (Qt3DAnimation::Animation::ClipBlendNode *) { + ++i; + }; + + // THEN -> shouldn't crash + Qt3DAnimation::Animation::ClipBlendNodeVisitor visitor(&manager); + visitor.traverse(rootBlendNode.id(), childCounter); + QCOMPARE(i, 1); + } + +}; + +QTEST_MAIN(tst_ClipBlendNodeVisitor) + +#include "tst_clipblendnodevisitor.moc" |