summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-03-03 19:26:10 +0000
committerSean Harmer <sean.harmer@kdab.com>2017-03-06 17:20:00 +0000
commit983f66c0a043e0f94b699c5119b7dc2ac91194aa (patch)
tree29b4dd4bde1be9b4f33698b5d0082109604d0028 /tests
parentbb8bd77fbbb70be9237fbe8ac127087162ca0b65 (diff)
Extend animation utils test to cover evaluationDataForClip()
Change-Id: I1bdf856404ee20ddd9500e66ae48ed622801bd2e Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/animation/animationutils/tst_animationutils.cpp131
1 files changed, 131 insertions, 0 deletions
diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp
index ac113b9ab..dd9734edf 100644
--- a/tests/auto/animation/animationutils/tst_animationutils.cpp
+++ b/tests/auto/animation/animationutils/tst_animationutils.cpp
@@ -51,6 +51,8 @@ Q_DECLARE_METATYPE(AnimationClipLoader *)
Q_DECLARE_METATYPE(QVector<MappingData>)
Q_DECLARE_METATYPE(QVector<Qt3DCore::QPropertyUpdatedChangePtr>)
Q_DECLARE_METATYPE(Channel)
+Q_DECLARE_METATYPE(AnimatorEvaluationData)
+Q_DECLARE_METATYPE(ClipEvaluationData)
bool fuzzyCompare(float x1, float x2)
{
@@ -108,6 +110,18 @@ public:
return clip;
}
+ ClipAnimator *createClipAnimator(Handler *handler,
+ qint64 globalStartTimeNS,
+ int loops)
+ {
+ auto animatorId = Qt3DCore::QNodeId::createId();
+ ClipAnimator *animator = handler->clipAnimatorManager()->getOrCreateResource(animatorId);
+ setPeerId(animator, animatorId);
+ animator->setStartTime(globalStartTimeNS);
+ animator->setLoops(loops);
+ return animator;
+ }
+
private Q_SLOTS:
void checkBuildPropertyMappings_data()
{
@@ -979,6 +993,123 @@ private Q_SLOTS:
QCOMPARE(actualResults[i], expectedResults[i]);
}
}
+
+ void checkEvaluationDataForClip_data()
+ {
+ QTest::addColumn<Handler *>("handler");
+ QTest::addColumn<AnimationClipLoader *>("clip");
+ QTest::addColumn<AnimatorEvaluationData>("animatorData");
+ QTest::addColumn<ClipEvaluationData>("expectedClipData");
+
+ Handler *handler;
+ AnimationClipLoader *clip;
+ AnimatorEvaluationData animatorData;
+ ClipEvaluationData clipData;
+
+ {
+ handler = new Handler();
+ clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json"));
+ const qint64 globalStartTimeNS = 0;
+ const int loops = 1;
+ auto animator = createClipAnimator(handler, globalStartTimeNS, loops);
+ const qint64 globalTimeNS = 0;
+ animatorData = evaluationDataForAnimator(animator, globalTimeNS); // Tested elsewhere
+
+ clipData.localTime = localTimeFromGlobalTime(animatorData.globalTime,
+ animatorData.startTime,
+ animatorData.playbackRate,
+ clip->duration(),
+ animatorData.loopCount,
+ clipData.currentLoop); // Tested elsewhere
+ clipData.isFinalFrame = false;
+
+ QTest::newRow("clip1.json, globalTime = 0")
+ << handler << clip << animatorData << clipData;
+ }
+
+ {
+ handler = new Handler();
+ clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json"));
+ const qint64 globalStartTimeNS = 0;
+ const int loops = 1;
+ auto animator = createClipAnimator(handler, globalStartTimeNS, loops);
+ const qint64 globalTimeNS = (clip->duration() + 1.0) * 1.0e9; // +1 to ensure beyond end of clip
+ animatorData = evaluationDataForAnimator(animator, globalTimeNS); // Tested elsewhere
+
+ clipData.localTime = localTimeFromGlobalTime(animatorData.globalTime,
+ animatorData.startTime,
+ animatorData.playbackRate,
+ clip->duration(),
+ animatorData.loopCount,
+ clipData.currentLoop); // Tested elsewhere
+ clipData.isFinalFrame = true;
+
+ QTest::newRow("clip1.json, globalTime = duration")
+ << handler << clip << animatorData << clipData;
+ }
+
+ {
+ handler = new Handler();
+ clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json"));
+ const qint64 globalStartTimeNS = 0;
+ const int loops = 0; // Infinite loops
+ auto animator = createClipAnimator(handler, globalStartTimeNS, loops);
+ const qint64 globalTimeNS = 2.0 * clip->duration() * 1.0e9;
+ animatorData = evaluationDataForAnimator(animator, globalTimeNS); // Tested elsewhere
+
+ clipData.localTime = localTimeFromGlobalTime(animatorData.globalTime,
+ animatorData.startTime,
+ animatorData.playbackRate,
+ clip->duration(),
+ animatorData.loopCount,
+ clipData.currentLoop); // Tested elsewhere
+ clipData.isFinalFrame = false;
+
+ QTest::newRow("clip1.json, globalTime = 2 * duration, loops = infinite")
+ << handler << clip << animatorData << clipData;
+ }
+
+ {
+ handler = new Handler();
+ clip = createAnimationClipLoader(handler, QUrl("qrc:/clip1.json"));
+ const qint64 globalStartTimeNS = 0;
+ const int loops = 2;
+ auto animator = createClipAnimator(handler, globalStartTimeNS, loops);
+ const qint64 globalTimeNS = (2.0 * clip->duration() + 1.0) * 1.0e9; // +1 to ensure beyond end of clip
+ animatorData = evaluationDataForAnimator(animator, globalTimeNS); // Tested elsewhere
+
+ clipData.localTime = localTimeFromGlobalTime(animatorData.globalTime,
+ animatorData.startTime,
+ animatorData.playbackRate,
+ clip->duration(),
+ animatorData.loopCount,
+ clipData.currentLoop); // Tested elsewhere
+ clipData.isFinalFrame = true;
+
+ QTest::newRow("clip1.json, globalTime = 2 * duration + 1, loops = 2")
+ << handler << clip << animatorData << clipData;
+ }
+ }
+
+ void checkEvaluationDataForClip()
+ {
+ // GIVEN
+ QFETCH(Handler *, handler);
+ QFETCH(AnimationClipLoader *, clip);
+ QFETCH(AnimatorEvaluationData, animatorData);
+ QFETCH(ClipEvaluationData, expectedClipData);
+
+ // WHEN
+ ClipEvaluationData actualClipData = evaluationDataForClip(clip, animatorData);
+
+ // THEN
+ QCOMPARE(actualClipData.currentLoop, expectedClipData.currentLoop);
+ QVERIFY(fuzzyCompare(actualClipData.localTime, expectedClipData.localTime) == true);
+ QCOMPARE(actualClipData.isFinalFrame, expectedClipData.isFinalFrame);
+
+ // Cleanup
+ delete handler;
+ }
};
QTEST_MAIN(tst_AnimationUtils)