diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2017-03-01 12:34:34 +0000 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-03-02 21:03:18 +0000 |
commit | faa2db2dc1c654616ca5651cec4e57893774015e (patch) | |
tree | dd7e65afb8756bcc3190535b56fa73d3201ae358 /tests/auto/animation | |
parent | f2b06f224127b9f0291084e3010cc5b5d03c4487 (diff) |
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 <mike.krus@kdab.com>
Diffstat (limited to 'tests/auto/animation')
-rw-r--r-- | tests/auto/animation/animationutils/tst_animationutils.cpp | 59 |
1 files changed, 43 insertions, 16 deletions
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<int>(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<Qt3DCore::QNodeId> &mappingIds) + { auto channelMapperId = Qt3DCore::QNodeId::createId(); ChannelMapper *channelMapper = handler.channelMapperManager()->getOrCreateResource(channelMapperId); setPeerId(channelMapper, channelMapperId); - channelMapper->setMappingIds(QVector<Qt3DCore::QNodeId>() << 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<int>(QVariant::Vector3D)); + + // ... a channel mapper... + auto channelMapper = createChannelMapper(handler, QVector<Qt3DCore::QNodeId>() << 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); |