Debian Codegraph @

tests/auto/animation/qblendedclipanimator/tst_qblendedclipanimator.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
5 #include <QtTest/QTest>
6 #include <Qt3DAnimation/qblendedclipanimator.h>
7 #include <Qt3DAnimation/private/qblendedclipanimator_p.h>
8 #include <Qt3DAnimation/qlerpclipblend.h>
9 #include <Qt3DAnimation/qchannelmapper.h>
10 #include <QObject>
11 #include <QSignalSpy>
12 #include <testarbiter.h>
13
14 class tst_QBlendedClipAnimator : public QObject
15 {
16 Q_OBJECT
17
18 private Q_SLOTS:
19
20 void initTestCase()
21 {
22 qRegisterMetaType<Qt3DAnimation::QChannelMapper*>("QChannelMapper *");
23 qRegisterMetaType<Qt3DAnimation::QAbstractClipBlendNode*>("QAbstractClipBlendNode *");
24 }
25
26 void checkDefaultConstruction()
27 {
28 // GIVEN
29 Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator;
30
31 // THEN
32 QVERIFY(blendedClipAnimator.blendTree() == nullptr);
33 QVERIFY(blendedClipAnimator.channelMapper() == nullptr);
34 QCOMPARE(blendedClipAnimator.isRunning(), false);
35 QCOMPARE(blendedClipAnimator.loopCount(), 1);
36 }
37
38 void checkPropertyChanges()
39 {
40 // GIVEN
41 Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator;
42
43 {
44 // WHEN
45 QSignalSpy spy(&blendedClipAnimator, SIGNAL(blendTreeChanged(QAbstractClipBlendNode*)));
46 Qt3DAnimation::QLerpClipBlend newValue;
47 blendedClipAnimator.setBlendTree(&newValue);
48
49 // THEN
50 QVERIFY(spy.isValid());
51 QCOMPARE(blendedClipAnimator.blendTree(), &newValue);
52 QCOMPARE(spy.size(), 1);
53
54 // WHEN
55 spy.clear();
56 blendedClipAnimator.setBlendTree(&newValue);
57
58 // THEN
59 QCOMPARE(blendedClipAnimator.blendTree(), &newValue);
60 QCOMPARE(spy.size(), 0);
61 }
62 {
63 // WHEN
64 QSignalSpy spy(&blendedClipAnimator, SIGNAL(channelMapperChanged(QChannelMapper*)));
65 Qt3DAnimation::QChannelMapper newValue;
66 blendedClipAnimator.setChannelMapper(&newValue);
67
68 // THEN
69 QVERIFY(spy.isValid());
70 QCOMPARE(blendedClipAnimator.channelMapper(), &newValue);
71 QCOMPARE(spy.size(), 1);
72
73 // WHEN
74 spy.clear();
75 blendedClipAnimator.setChannelMapper(&newValue);
76
77 // THEN
78 QCOMPARE(blendedClipAnimator.channelMapper(), &newValue);
79 QCOMPARE(spy.size(), 0);
80 }
81 {
82 // WHEN
83 QSignalSpy spy(&blendedClipAnimator, SIGNAL(runningChanged(bool)));
84 const bool newValue = true;
85 blendedClipAnimator.setRunning(newValue);
86
87 // THEN
88 QVERIFY(spy.isValid());
89 QCOMPARE(blendedClipAnimator.isRunning(), newValue);
90 QCOMPARE(spy.size(), 1);
91
92 // WHEN
93 spy.clear();
94 blendedClipAnimator.setRunning(newValue);
95
96 // THEN
97 QCOMPARE(blendedClipAnimator.isRunning(), newValue);
98 QCOMPARE(spy.size(), 0);
99 }
100
101 {
102 // WHEN
103 QSignalSpy spy(&blendedClipAnimator, SIGNAL(loopCountChanged(int)));
104 const int newValue = 5;
105 blendedClipAnimator.setLoopCount(newValue);
106
107 // THEN
108 QVERIFY(spy.isValid());
109 QCOMPARE(blendedClipAnimator.loopCount(), newValue);
110 QCOMPARE(spy.size(), 1);
111
112 // WHEN
113 spy.clear();
114 blendedClipAnimator.setLoopCount(newValue);
115
116 // THEN
117 QCOMPARE(blendedClipAnimator.loopCount(), newValue);
118 QCOMPARE(spy.size(), 0);
119 }
120
121 {
122 // WHEN
123 QSignalSpy spy(&blendedClipAnimator, SIGNAL(normalizedTimeChanged(float)));
124 const float newValue = 0.5;
125 blendedClipAnimator.setNormalizedTime(newValue);
126
127 // THEN
128 QVERIFY(spy.isValid());
129 QCOMPARE(blendedClipAnimator.normalizedTime(), newValue);
130 QCOMPARE(spy.size(), 1);
131
132 // WHEN
133 spy.clear();
134 blendedClipAnimator.setNormalizedTime(newValue);
135
136 // THEN
137 QCOMPARE(blendedClipAnimator.normalizedTime(), newValue);
138 QCOMPARE(spy.size(), 0);
139 }
140
141 {
142 // WHEN
143 QSignalSpy spy(&blendedClipAnimator, SIGNAL(normalizedTimeChanged(float)));
144 const float newValue = -0.01f; // Invalid
145 blendedClipAnimator.setNormalizedTime(newValue);
146 const float oldValue = blendedClipAnimator.normalizedTime();
147
148 // THEN
149 QVERIFY(spy.isValid());
150 QCOMPARE(blendedClipAnimator.normalizedTime(), oldValue);
151 QCOMPARE(spy.size(), 0);
152
153 // WHEN
154 spy.clear();
155 blendedClipAnimator.setNormalizedTime(1.01f); // Invalid
156
157 // THEN
158 QCOMPARE(blendedClipAnimator.normalizedTime(), oldValue);
159 QCOMPARE(spy.size(), 0);
160 }
161 }
162
163 void checkBlendTreeUpdate()
164 {
165 // GIVEN
166 TestArbiter arbiter;
167 Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator;
168 arbiter.setArbiterOnNode(&blendedClipAnimator);
169 Qt3DAnimation::QLerpClipBlend blendRoot;
170
171 {
172 // WHEN
173 blendedClipAnimator.setBlendTree(&blendRoot);
174
175 // THEN
176 QCOMPARE(arbiter.dirtyNodes().size(), 1);
177 QCOMPARE(arbiter.dirtyNodes().front(), &blendedClipAnimator);
178
179 arbiter.clear();
180 }
181
182 {
183 // WHEN
184 blendedClipAnimator.setBlendTree(&blendRoot);
185
186 // THEN
187 QCOMPARE(arbiter.dirtyNodes().size(), 0);
188 }
189
190 }
191
192 void checkBlendTreeBookkeeping()
193 {
194 // GIVEN
195 Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator;
196
197 {
198 // WHEN
199 Qt3DAnimation::QLerpClipBlend blendRoot;
200 blendedClipAnimator.setBlendTree(&blendRoot);
201
202 QCOMPARE(blendedClipAnimator.blendTree(), &blendRoot);
203 }
204
205 // THEN -> should not crash
206 QVERIFY(blendedClipAnimator.blendTree() == nullptr);
207 }
208
209 void checkChannelMapperUpdate()
210 {
211 // GIVEN
212 TestArbiter arbiter;
213 Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator;
214 arbiter.setArbiterOnNode(&blendedClipAnimator);
215
216 Qt3DAnimation::QChannelMapper channelMapper;
217 {
218 // WHEN
219 blendedClipAnimator.setChannelMapper(&channelMapper);
220
221 // THEN
222 QCOMPARE(arbiter.dirtyNodes().size(), 1);
223 QCOMPARE(arbiter.dirtyNodes().front(), &blendedClipAnimator);
224
225 arbiter.clear();
226 }
227
228 {
229 // WHEN
230 blendedClipAnimator.setChannelMapper(&channelMapper);
231
232 // THEN
233 QCOMPARE(arbiter.dirtyNodes().size(), 0);
234 }
235
236 }
237
238 void checkChannelMapperBookkeeping()
239 {
240 // GIVEN
241 Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator;
242
243 {
244 // WHEN
245 Qt3DAnimation::QChannelMapper channelMapper;
246 blendedClipAnimator.setChannelMapper(&channelMapper);
247
248 QCOMPARE(blendedClipAnimator.channelMapper(), &channelMapper);
249 }
250
251 // THEN -> should not crash
252 QVERIFY(blendedClipAnimator.channelMapper() == nullptr);
253 }
254
255 void checkRunningUpdate()
256 {
257 // GIVEN
258 TestArbiter arbiter;
259 Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator;
260 arbiter.setArbiterOnNode(&blendedClipAnimator);
261
262 {
263 // WHEN
264 blendedClipAnimator.setRunning(true);
265
266 // THEN
267 QCOMPARE(arbiter.dirtyNodes().size(), 1);
268 QCOMPARE(arbiter.dirtyNodes().front(), &blendedClipAnimator);
269
270 arbiter.clear();
271 }
272
273 {
274 // WHEN
275 blendedClipAnimator.setRunning(true);
276
277 // THEN
278 QCOMPARE(arbiter.dirtyNodes().size(), 0);
279 }
280
281 }
282
283 void checkLoopsUpdate()
284 {
285 // GIVEN
286 TestArbiter arbiter;
287 Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator;
288 arbiter.setArbiterOnNode(&blendedClipAnimator);
289
290 {
291 // WHEN
292 blendedClipAnimator.setLoopCount(1584);
293
294 // THEN
295 QCOMPARE(arbiter.dirtyNodes().size(), 1);
296 QCOMPARE(arbiter.dirtyNodes().front(), &blendedClipAnimator);
297
298 arbiter.clear();
299 }
300
301 {
302 // WHEN
303 blendedClipAnimator.setLoopCount(1584);
304
305 // THEN
306 QCOMPARE(arbiter.dirtyNodes().size(), 0);
307 }
308
309 }
310
311 void checkNormalizedTimeUpdate()
312 {
313 // GIVEN
314 TestArbiter arbiter;
315 Qt3DAnimation::QBlendedClipAnimator blendedClipAnimator;
316 arbiter.setArbiterOnNode(&blendedClipAnimator);
317
318 {
319 // WHEN
320 blendedClipAnimator.setNormalizedTime(0.5f);
321
322 // THEN
323 QCOMPARE(arbiter.dirtyNodes().size(), 1);
324 QCOMPARE(arbiter.dirtyNodes().front(), &blendedClipAnimator);
325
326 arbiter.clear();
327 }
328
329 {
330 // WHEN
331 blendedClipAnimator.setNormalizedTime(0.5f);
332
333 // THEN
334 QCOMPARE(arbiter.dirtyNodes().size(), 0);
335 }
336
337 }
338 };
339
340 QTEST_MAIN(tst_QBlendedClipAnimator)
341
342 #include "tst_qblendedclipanimator.moc"