Debian Codegraph @

tests/auto/animation/blendedclipanimator/tst_blendedclipanimator.cpp

raw symbols SCIP
1 // Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #include <QtTest/QTest>
5 #include <Qt3DAnimation/private/blendedclipanimator_p.h>
6 #include <Qt3DAnimation/qanimationcliploader.h>
7 #include <Qt3DAnimation/qadditiveclipblend.h>
8 #include <Qt3DAnimation/qblendedclipanimator.h>
9 #include <Qt3DCore/private/qnode_p.h>
10 #include <Qt3DCore/private/qscene_p.h>
11 #include <Qt3DCore/private/qbackendnode_p.h>
12 #include <qbackendnodetester.h>
13 #include <testarbiter.h>
14
15 #include <QtTest/QTest>
16 #include <Qt3DAnimation/qblendedclipanimator.h>
17 #include <Qt3DAnimation/qlerpclipblend.h>
18 #include <Qt3DAnimation/qchannelmapper.h>
19 #include <Qt3DAnimation/private/qblendedclipanimator_p.h>
20 #include <Qt3DAnimation/private/blendedclipanimator_p.h>
21
22 class tst_BlendedClipAnimator : public Qt3DCore::QBackendNodeTester
23 {
24 Q_OBJECT
25
26 private Q_SLOTS:
27
28 void checkInitialState()
29 {
30 // GIVEN
31 Qt3DAnimation::Animation::BlendedClipAnimator backendBlendedClipAnimator;
32
33 // THEN
34 QCOMPARE(backendBlendedClipAnimator.isEnabled(), false);
35 QVERIFY(backendBlendedClipAnimator.peerId().isNull());
36 QCOMPARE(backendBlendedClipAnimator.blendTreeRootId(), Qt3DCore::QNodeId());
37 QCOMPARE(backendBlendedClipAnimator.mapperId(), Qt3DCore::QNodeId());
38 QCOMPARE(backendBlendedClipAnimator.isRunning(), false);
39 QCOMPARE(backendBlendedClipAnimator.lastLocalTime(), 0.0);
40 QCOMPARE(backendBlendedClipAnimator.nsSincePreviousFrame(0), 0);
41 QCOMPARE(backendBlendedClipAnimator.currentLoop(), 0);
42 QCOMPARE(backendBlendedClipAnimator.loops(), 1);
43
44 }
45
46 void checkCleanupState()
47 {
48 // GIVEN
49 Qt3DAnimation::Animation::BlendedClipAnimator backendBlendedClipAnimator;
50 Qt3DAnimation::Animation::Handler handler;
51 backendBlendedClipAnimator.setHandler(&handler);
52
53 // WHEN
54 backendBlendedClipAnimator.setEnabled(true);
55 backendBlendedClipAnimator.setBlendTreeRootId(Qt3DCore::QNodeId::createId());
56 backendBlendedClipAnimator.setMapperId(Qt3DCore::QNodeId::createId());
57 backendBlendedClipAnimator.setRunning(true);
58 backendBlendedClipAnimator.setStartTime(28);
59 backendBlendedClipAnimator.setLastLocalTime(0.28);
60 backendBlendedClipAnimator.cleanup();
61
62 // THEN
63 QCOMPARE(backendBlendedClipAnimator.isEnabled(), false);
64 QCOMPARE(backendBlendedClipAnimator.blendTreeRootId(), Qt3DCore::QNodeId());
65 QCOMPARE(backendBlendedClipAnimator.mapperId(), Qt3DCore::QNodeId());
66 QCOMPARE(backendBlendedClipAnimator.isRunning(), false);
67 QCOMPARE(backendBlendedClipAnimator.lastLocalTime(), 0.0);
68 QCOMPARE(backendBlendedClipAnimator.nsSincePreviousFrame(0), 0);
69 QCOMPARE(backendBlendedClipAnimator.currentLoop(), 0);
70 QCOMPARE(backendBlendedClipAnimator.loops(), 1);
71 }
72
73 void checkInitializeFromPeer()
74 {
75 // GIVEN
76 Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator;
77 Qt3DAnimation::QChannelMapper mapper;
78 Qt3DAnimation::QLerpClipBlend blendTree;
79 blendedClipAnimator.setRunning(true);
80 blendedClipAnimator.setBlendTree(&blendTree);
81 blendedClipAnimator.setChannelMapper(&mapper);
82 blendedClipAnimator.setLoopCount(10);
83
84 {
85 // WHEN
86 Qt3DAnimation::Animation::BlendedClipAnimator backendBlendedClipAnimator;
87 Qt3DAnimation::Animation::Handler handler;
88 backendBlendedClipAnimator.setHandler(&handler);
89
90 simulateInitializationSync(&blendedClipAnimator, &backendBlendedClipAnimator);
91
92 // THEN
93 QCOMPARE(backendBlendedClipAnimator.isEnabled(), true);
94 QCOMPARE(backendBlendedClipAnimator.peerId(), blendedClipAnimator.id());
95 QCOMPARE(backendBlendedClipAnimator.blendTreeRootId(), blendTree.id());
96 QCOMPARE(backendBlendedClipAnimator.mapperId(), mapper.id());
97 QCOMPARE(backendBlendedClipAnimator.isRunning(), true);
98 QCOMPARE(backendBlendedClipAnimator.loops(), 10);
99 }
100 {
101 // WHEN
102 Qt3DAnimation::Animation::BlendedClipAnimator backendBlendedClipAnimator;
103 Qt3DAnimation::Animation::Handler handler;
104 backendBlendedClipAnimator.setHandler(&handler);
105
106 blendedClipAnimator.setEnabled(false);
107 simulateInitializationSync(&blendedClipAnimator, &backendBlendedClipAnimator);
108
109 // THEN
110 QCOMPARE(backendBlendedClipAnimator.peerId(), blendedClipAnimator.id());
111 QCOMPARE(backendBlendedClipAnimator.isEnabled(), false);
112 }
113 }
114
115 void checkSceneChangeEvents()
116 {
117 // GIVEN
118 Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator;
119 Qt3DAnimation::Animation::BlendedClipAnimator backendBlendedClipAnimator;
120 Qt3DAnimation::Animation::Handler handler;
121 backendBlendedClipAnimator.setHandler(&handler);
122 simulateInitializationSync(&blendedClipAnimator, &backendBlendedClipAnimator);
123
124 {
125 // WHEN
126 const bool newValue = false;
127 blendedClipAnimator.setEnabled(newValue);
128 backendBlendedClipAnimator.syncFromFrontEnd(&blendedClipAnimator, false);
129
130 // THEN
131 QCOMPARE(backendBlendedClipAnimator.isEnabled(), newValue);
132 }
133 {
134 // WHEN
135 auto blendTree = new Qt3DAnimation::QAdditiveClipBlend();
136 blendedClipAnimator.setBlendTree(blendTree);
137 backendBlendedClipAnimator.syncFromFrontEnd(&blendedClipAnimator, false);
138
139 // THEN
140 QCOMPARE(backendBlendedClipAnimator.blendTreeRootId(), blendTree->id());
141 }
142 {
143 // WHEN
144 auto channelMapper = new Qt3DAnimation::QChannelMapper();
145 blendedClipAnimator.setChannelMapper(channelMapper);
146 backendBlendedClipAnimator.syncFromFrontEnd(&blendedClipAnimator, false);
147
148 // THEN
149 QCOMPARE(backendBlendedClipAnimator.mapperId(), channelMapper->id());
150 }
151 {
152 // WHEN
153 const bool newValue = true;
154 blendedClipAnimator.setRunning(newValue);
155 backendBlendedClipAnimator.syncFromFrontEnd(&blendedClipAnimator, false);
156
157 // THEN
158 QCOMPARE(backendBlendedClipAnimator.isRunning(), newValue);
159 }
160 {
161 // WHEN
162 const int newValue = 883;
163 blendedClipAnimator.setLoopCount(newValue);
164 backendBlendedClipAnimator.syncFromFrontEnd(&blendedClipAnimator, false);
165
166 // THEN
167 QCOMPARE(backendBlendedClipAnimator.loops(), newValue);
168 }
169 }
170
171 };
172
173 QTEST_APPLESS_MAIN(tst_BlendedClipAnimator)
174
175 #include "tst_blendedclipanimator.moc"