diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2017-02-28 11:18:38 +0000 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-03-02 18:46:02 +0000 |
commit | 6ad5c82af256c6d2409de451cba166d53c89bbd0 (patch) | |
tree | e6c68b2b466565af814bb586aba68536a1ad366d /tests/auto/animation | |
parent | 4abd7bbfdb33200346c67b5d3af0f743793a3a39 (diff) |
Add test for AnimationUtils
Will extend in further commits.
Change-Id: Idbdd95bdd3cfe0ab3f5d12295d15b32c116bc26b
Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'tests/auto/animation')
-rw-r--r-- | tests/auto/animation/animation.pro | 3 | ||||
-rw-r--r-- | tests/auto/animation/animationutils/animationutils.pro | 15 | ||||
-rw-r--r-- | tests/auto/animation/animationutils/animationutils.qrc | 5 | ||||
-rw-r--r-- | tests/auto/animation/animationutils/clip1.json | 48 | ||||
-rw-r--r-- | tests/auto/animation/animationutils/tst_animationutils.cpp | 96 |
5 files changed, 166 insertions, 1 deletions
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 @@ +<RCC> + <qresource prefix="/"> + <file>clip1.json</file> + </qresource> +</RCC> 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 <QtTest/QTest> +#include <Qt3DAnimation/private/animationcliploader_p.h> +#include <Qt3DAnimation/private/animationutils_p.h> +#include <Qt3DAnimation/private/channelmapper_p.h> +#include <Qt3DAnimation/private/channelmapping_p.h> +#include <Qt3DAnimation/private/handler_p.h> +#include <Qt3DAnimation/private/managers_p.h> +#include <qbackendnodetester.h> +#include <testpostmanarbiter.h> + +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<int>(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<Qt3DCore::QNodeId>() << 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<AnimationUtils::MappingData> 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" |