summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-03-16 13:26:41 +0000
committerSean Harmer <sean.harmer@kdab.com>2017-03-25 08:07:15 +0000
commitc7d15b7c5e044f40167f4a79be8bf4f569c6b8be (patch)
tree6379fbcb58408b2b7657081d3545a320148f966b /tests
parentb2a274103eff2a684f0aa91c7f18ee8b358d6dd1 (diff)
Add function to recursively calculate duration of a blend tree
The resulting duration is independent of which animators the blend tree is associated with so this can be implemented as a simple set of virtual functions in the concrete classes. The value node simply returns the duration of the contained clip; the additive node returns the duration of the base node; and the lerp node lerps the durations of the start and end nodes. Change-Id: Ib6edea3fa495885493fa72d44437fea5a8c5a446 Reviewed-by: Paul Lemire <paul.lemire@kdab.com> Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp60
-rw-r--r--tests/auto/animation/clipblendnode/tst_clipblendnode.cpp2
-rw-r--r--tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp2
-rw-r--r--tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp28
-rw-r--r--tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp62
5 files changed, 154 insertions, 0 deletions
diff --git a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp
index 2cc707fa5..7ec327cdc 100644
--- a/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp
+++ b/tests/auto/animation/additiveclipblend/tst_additiveclipblend.cpp
@@ -37,9 +37,45 @@
using namespace Qt3DAnimation::Animation;
+namespace {
+
+class TestClipBlendNode : public ClipBlendNode
+{
+public:
+ TestClipBlendNode(double duration)
+ : ClipBlendNode(ClipBlendNode::LerpBlendType)
+ , m_duration(duration)
+ {}
+
+ float blend(float, float) const Q_DECL_FINAL { return 0.0f; }
+
+ QVector<Qt3DCore::QNodeId> dependencyIds() const Q_DECL_FINAL
+ {
+ return QVector<Qt3DCore::QNodeId>();
+ }
+
+ using ClipBlendNode::setClipResults;
+
+ double duration() const Q_DECL_FINAL { return m_duration; }
+
+ double m_duration;
+};
+
+} // anonymous
+
class tst_AdditiveClipBlend : public Qt3DCore::QBackendNodeTester
{
Q_OBJECT
+public:
+ TestClipBlendNode *createTestBlendNode(Handler *handler,
+ double duration)
+ {
+ auto id = Qt3DCore::QNodeId::createId();
+ TestClipBlendNode *node = new TestClipBlendNode(duration);
+ setPeerId(node, id);
+ handler->clipBlendNodeManager()->appendNode(id, node);
+ return node;
+ }
private Q_SLOTS:
@@ -201,6 +237,30 @@ private Q_SLOTS:
QCOMPARE(actualIds[0], baseClipId);
QCOMPARE(actualIds[1], anotherAdditiveClipId);
}
+
+ void checkDuration()
+ {
+ // GIVEN
+ auto handler = new Handler();
+ const double expectedDuration = 123.5;
+ const double baseNodeDuration = expectedDuration;
+ const double additiveNodeDuration = 5.0;
+
+ auto baseNode = createTestBlendNode(handler, baseNodeDuration);
+ auto additiveNode = createTestBlendNode(handler, additiveNodeDuration);
+
+ AdditiveClipBlend blendNode;
+ blendNode.setHandler(handler);
+ blendNode.setClipBlendNodeManager(handler->clipBlendNodeManager());
+ blendNode.setBaseClipId(baseNode->peerId());
+ blendNode.setAdditiveClipId(additiveNode->peerId());
+
+ // WHEN
+ double actualDuration = blendNode.duration();
+
+ // THEN
+ QCOMPARE(actualDuration, expectedDuration);
+ }
};
QTEST_MAIN(tst_AdditiveClipBlend)
diff --git a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp
index bc736ebb8..22d020c47 100644
--- a/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp
+++ b/tests/auto/animation/clipblendnode/tst_clipblendnode.cpp
@@ -61,6 +61,8 @@ public:
}
using ClipBlendNode::setClipResults;
+
+ double duration() const Q_DECL_FINAL { return 0.0f; }
};
} // anonymous
diff --git a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp
index 6721401ee..8a3d0972f 100644
--- a/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp
+++ b/tests/auto/animation/clipblendnodemanager/tst_clipblendnodemanager.cpp
@@ -55,6 +55,8 @@ public:
{
return QVector<Qt3DCore::QNodeId>();
}
+
+ double duration() const Q_DECL_FINAL { return 0.0f; }
};
} // anonymous
diff --git a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp
index c23d98672..12eaf1a3c 100644
--- a/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp
+++ b/tests/auto/animation/clipblendvalue/tst_clipblendvalue.cpp
@@ -40,6 +40,16 @@ using namespace Qt3DAnimation::Animation;
class tst_ClipBlendValue : public Qt3DCore::QBackendNodeTester
{
Q_OBJECT
+public:
+ AnimationClipLoader *createAnimationClipLoader(Handler *handler,
+ double duration)
+ {
+ auto clipId = Qt3DCore::QNodeId::createId();
+ AnimationClipLoader *clip = handler->animationClipLoaderManager()->getOrCreateResource(clipId);
+ setPeerId(clip, clipId);
+ clip->setDuration(duration);
+ return clip;
+ }
private Q_SLOTS:
void checkInitialState()
@@ -134,6 +144,24 @@ private Q_SLOTS:
QCOMPARE(actualIds.size(), 1);
QCOMPARE(actualIds[0], anotherClipId);
}
+
+ void checkDuration()
+ {
+ // GIVEN
+ auto handler = new Handler();
+ const double expectedDuration = 123.5;
+ auto clip = createAnimationClipLoader(handler, expectedDuration);
+ ClipBlendValue clipNode;
+ clipNode.setHandler(handler);
+ clipNode.setClipBlendNodeManager(handler->clipBlendNodeManager());
+ clipNode.setClipId(clip->peerId());
+
+ // WHEN
+ double actualDuration = clipNode.duration();
+
+ // THEN
+ QCOMPARE(actualDuration, expectedDuration);
+ }
};
QTEST_MAIN(tst_ClipBlendValue)
diff --git a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp
index 34c52ff53..6dac3c8d9 100644
--- a/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp
+++ b/tests/auto/animation/lerpclipblend/tst_lerpclipblend.cpp
@@ -37,9 +37,45 @@
using namespace Qt3DAnimation::Animation;
+namespace {
+
+class TestClipBlendNode : public ClipBlendNode
+{
+public:
+ TestClipBlendNode(double duration)
+ : ClipBlendNode(ClipBlendNode::LerpBlendType)
+ , m_duration(duration)
+ {}
+
+ float blend(float, float) const Q_DECL_FINAL { return 0.0f; }
+
+ QVector<Qt3DCore::QNodeId> dependencyIds() const Q_DECL_FINAL
+ {
+ return QVector<Qt3DCore::QNodeId>();
+ }
+
+ using ClipBlendNode::setClipResults;
+
+ double duration() const Q_DECL_FINAL { return m_duration; }
+
+ double m_duration;
+};
+
+} // anonymous
+
class tst_LerpClipBlend : public Qt3DCore::QBackendNodeTester
{
Q_OBJECT
+public:
+ TestClipBlendNode *createTestBlendNode(Handler *handler,
+ double duration)
+ {
+ auto id = Qt3DCore::QNodeId::createId();
+ TestClipBlendNode *node = new TestClipBlendNode(duration);
+ setPeerId(node, id);
+ handler->clipBlendNodeManager()->appendNode(id, node);
+ return node;
+ }
private Q_SLOTS:
@@ -171,6 +207,32 @@ private Q_SLOTS:
QCOMPARE(actualIds[0], startClipId);
QCOMPARE(actualIds[1], anotherEndClipId);
}
+
+ void checkDuration()
+ {
+ // GIVEN
+ auto handler = new Handler();
+ const double startNodeDuration = 10.0;
+ const double endNodeDuration = 20.0;
+ const float blendFactor = 0.25f;
+ const double expectedDuration = 12.5;
+
+ auto startNode = createTestBlendNode(handler, startNodeDuration);
+ auto endNode = createTestBlendNode(handler, endNodeDuration);
+
+ LerpClipBlend blendNode;
+ blendNode.setHandler(handler);
+ blendNode.setClipBlendNodeManager(handler->clipBlendNodeManager());
+ blendNode.setStartClipId(startNode->peerId());
+ blendNode.setEndClipId(endNode->peerId());
+ blendNode.setBlendFactor(blendFactor);
+
+ // WHEN
+ double actualDuration = blendNode.duration();
+
+ // THEN
+ QCOMPARE(actualDuration, expectedDuration);
+ }
};
QTEST_MAIN(tst_LerpClipBlend)