diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2017-10-08 10:59:02 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2018-01-19 14:24:17 +0000 |
commit | 44aeb43834675a4d6b19bee88e267464ca7ad1f4 (patch) | |
tree | 5edced239bbd6795e2102a3d769b10c0192a9c60 /tests/auto/animation | |
parent | 16d1c5d08e3c1bbcc2990d0331389eed5a304b21 (diff) |
Add a function to calculate the default value for missing channels
Change-Id: Ic7bee59324da81fe2e467fd940029706297fc286
Reviewed-by: Christian Stromme <christian.stromme@qt.io>
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'tests/auto/animation')
-rw-r--r-- | tests/auto/animation/animationutils/tst_animationutils.cpp | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp index d6b6f3c81..e5c077657 100644 --- a/tests/auto/animation/animationutils/tst_animationutils.cpp +++ b/tests/auto/animation/animationutils/tst_animationutils.cpp @@ -66,6 +66,7 @@ Q_DECLARE_METATYPE(BlendedClipAnimator *) Q_DECLARE_METATYPE(QVector<ChannelNameAndType>) Q_DECLARE_METATYPE(QVector<AnimationCallbackAndValue>) Q_DECLARE_METATYPE(ClipFormat) +Q_DECLARE_METATYPE(ChannelNameAndType) namespace { @@ -2884,6 +2885,169 @@ private Q_SLOTS: // Cleanup delete clip; } + + void checkDefaultValueForChannel_data() + { + QTest::addColumn<Handler *>("handler"); + QTest::addColumn<ChannelNameAndType>("channelDescription"); + QTest::addColumn<QVector<float>>("expectedResults"); + + { + auto handler = new Handler(); + auto channelMapping = createChannelMapping(handler, + QLatin1String("Location"), + Qt3DCore::QNodeId::createId(), + QLatin1String("translation"), + "translation", + static_cast<int>(QVariant::Vector3D)); + ChannelNameAndType channelDescription; + channelDescription.mappingId = channelMapping->peerId(); + channelDescription.type = static_cast<int>(QVariant::Vector3D); + channelDescription.name = QLatin1String("translation"); + const QVector<float> expectedResults = { 0.0f, 0.0f, 0.0f }; + QTest::newRow("translation") << handler << channelDescription << expectedResults; + } + + { + auto handler = new Handler(); + auto channelMapping = createChannelMapping(handler, + QLatin1String("Rotation"), + Qt3DCore::QNodeId::createId(), + QLatin1String("rotation"), + "rotation", + static_cast<int>(QVariant::Quaternion)); + ChannelNameAndType channelDescription; + channelDescription.mappingId = channelMapping->peerId(); + channelDescription.type = static_cast<int>(QVariant::Quaternion); + channelDescription.name = QLatin1String("rotation"); + const QVector<float> expectedResults = { 1.0f, 0.0f, 0.0f, 0.0f }; + QTest::newRow("rotation") << handler << channelDescription << expectedResults; + } + + { + auto handler = new Handler(); + auto channelMapping = createChannelMapping(handler, + QLatin1String("Scale"), + Qt3DCore::QNodeId::createId(), + QLatin1String("scale"), + "scale", + static_cast<int>(QVariant::Vector3D)); + ChannelNameAndType channelDescription; + channelDescription.mappingId = channelMapping->peerId(); + channelDescription.type = static_cast<int>(QVariant::Vector3D); + channelDescription.name = QLatin1String("scale"); + const QVector<float> expectedResults = { 1.0f, 1.0f, 1.0f }; + QTest::newRow("scale") << handler << channelDescription << expectedResults; + } + + // Test skeleton cases + { + auto handler = new Handler(); + auto skeleton = createSkeleton(handler, 2); + skeleton->setJointScale(0, QVector3D(2.0f, 3.0f, 4.0f)); + + auto channelMapping = createChannelMapping(handler, skeleton->peerId()); + ChannelNameAndType channelDescription; + channelDescription.mappingId = channelMapping->peerId(); + channelDescription.type = static_cast<int>(QVariant::Vector3D); + channelDescription.jointIndex = 0; + channelDescription.jointTransformComponent = Scale; + const QVector<float> expectedResults = { 2.0f, 3.0f, 4.0f }; + QTest::newRow("joint 0 scale") << handler << channelDescription << expectedResults; + } + + { + auto handler = new Handler(); + auto skeleton = createSkeleton(handler, 2); + skeleton->setJointRotation(0, QQuaternion(1.0f, 0.0f, 0.0f, 0.0f)); + + auto channelMapping = createChannelMapping(handler, skeleton->peerId()); + ChannelNameAndType channelDescription; + channelDescription.mappingId = channelMapping->peerId(); + channelDescription.type = static_cast<int>(QVariant::Vector3D); + channelDescription.jointIndex = 0; + channelDescription.jointTransformComponent = Rotation; + const QVector<float> expectedResults = { 1.0f, 0.0f, 0.0f, 0.0f }; + QTest::newRow("joint 0 rotation") << handler << channelDescription << expectedResults; + } + + { + auto handler = new Handler(); + auto skeleton = createSkeleton(handler, 2); + skeleton->setJointTranslation(0, QVector3D(2.0f, 3.0f, 4.0f)); + + auto channelMapping = createChannelMapping(handler, skeleton->peerId()); + ChannelNameAndType channelDescription; + channelDescription.mappingId = channelMapping->peerId(); + channelDescription.type = static_cast<int>(QVariant::Vector3D); + channelDescription.jointIndex = 0; + channelDescription.jointTransformComponent = Translation; + const QVector<float> expectedResults = { 2.0f, 3.0f, 4.0f }; + QTest::newRow("joint 0 translation") << handler << channelDescription << expectedResults; + } + + { + auto handler = new Handler(); + auto skeleton = createSkeleton(handler, 2); + skeleton->setJointScale(1, QVector3D(20.0f, 30.0f, 40.0f)); + + auto channelMapping = createChannelMapping(handler, skeleton->peerId()); + ChannelNameAndType channelDescription; + channelDescription.mappingId = channelMapping->peerId(); + channelDescription.type = static_cast<int>(QVariant::Vector3D); + channelDescription.jointIndex = 1; + channelDescription.jointTransformComponent = Scale; + const QVector<float> expectedResults = { 20.0f, 30.0f, 40.0f }; + QTest::newRow("joint 1 scale") << handler << channelDescription << expectedResults; + } + + { + auto handler = new Handler(); + auto skeleton = createSkeleton(handler, 2); + skeleton->setJointRotation(1, QQuaternion(1.0f, 0.0f, 0.0f, 0.0f)); + + auto channelMapping = createChannelMapping(handler, skeleton->peerId()); + ChannelNameAndType channelDescription; + channelDescription.mappingId = channelMapping->peerId(); + channelDescription.type = static_cast<int>(QVariant::Vector3D); + channelDescription.jointIndex = 1; + channelDescription.jointTransformComponent = Rotation; + const QVector<float> expectedResults = { 1.0f, 0.0f, 0.0f, 0.0f }; + QTest::newRow("joint 1 rotation") << handler << channelDescription << expectedResults; + } + + { + auto handler = new Handler(); + auto skeleton = createSkeleton(handler, 2); + skeleton->setJointTranslation(1, QVector3D(4.0f, 5.0f, 6.0f)); + + auto channelMapping = createChannelMapping(handler, skeleton->peerId()); + ChannelNameAndType channelDescription; + channelDescription.mappingId = channelMapping->peerId(); + channelDescription.type = static_cast<int>(QVariant::Vector3D); + channelDescription.jointIndex = 1; + channelDescription.jointTransformComponent = Translation; + const QVector<float> expectedResults = { 4.0f, 5.0f, 6.0f }; + QTest::newRow("joint 1 translation") << handler << channelDescription << expectedResults; + } + } + + void checkDefaultValueForChannel() + { + // GIVEN + QFETCH(Handler *, handler); + QFETCH(ChannelNameAndType, channelDescription); + QFETCH(QVector<float>, expectedResults); + + // WHEN + auto actualResults = defaultValueForChannel(handler, channelDescription); + + // THEN + QCOMPARE(actualResults.size(), expectedResults.size()); + for (int i = 0; i < actualResults.size(); ++i) { + QCOMPARE(actualResults[i], expectedResults[i]); + } + } }; QTEST_MAIN(tst_AnimationUtils) |