Debian Codegraph @

tests/auto/animation/qclipanimator/tst_qclipanimator.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/qanimationcliploader.h>
7 #include <Qt3DAnimation/qchannelmapper.h>
8 #include <Qt3DAnimation/qclock.h>
9 #include <Qt3DAnimation/qclipanimator.h>
10 #include <Qt3DAnimation/private/qanimationclip_p.h>
11 #include <Qt3DAnimation/private/qclipanimator_p.h>
12 #include <QObject>
13 #include <QSignalSpy>
14 #include <testarbiter.h>
15
16 class tst_QClipAnimator : public QObject
17 {
18 Q_OBJECT
19
20 private Q_SLOTS:
21 void initTestCase()
22 {
23 qRegisterMetaType<Qt3DAnimation::QAbstractAnimationClip*>();
24 qRegisterMetaType<Qt3DAnimation::QChannelMapper*>();
25 qRegisterMetaType<Qt3DAnimation::QClock*>();
26 }
27
28 void checkDefaultConstruction()
29 {
30 // GIVEN
31 Qt3DAnimation::QClipAnimator animator;
32
33 // THEN
34 QCOMPARE(animator.clip(), static_cast<Qt3DAnimation::QAbstractAnimationClip *>(nullptr));
35 QCOMPARE(animator.channelMapper(), static_cast<Qt3DAnimation::QChannelMapper *>(nullptr));
36 QCOMPARE(animator.clock(), static_cast<Qt3DAnimation::QClock*>(nullptr));
37 QCOMPARE(animator.loopCount(), 1);
38 QCOMPARE(animator.normalizedTime(), 0.0f);
39 }
40
41 void checkPropertyChanges()
42 {
43 // GIVEN
44 Qt3DAnimation::QClipAnimator animator;
45
46 {
47 // WHEN
48 QSignalSpy spy(&animator, SIGNAL(clipChanged(Qt3DAnimation::QAbstractAnimationClip*)));
49 auto newValue = new Qt3DAnimation::QAnimationClipLoader();
50 animator.setClip(newValue);
51
52 // THEN
53 QVERIFY(spy.isValid());
54 QCOMPARE(animator.clip(), newValue);
55 QCOMPARE(newValue->parent(), &animator);
56 QCOMPARE(spy.size(), 1);
57
58 // WHEN
59 spy.clear();
60 animator.setClip(newValue);
61
62 // THEN
63 QCOMPARE(animator.clip(), newValue);
64 QCOMPARE(spy.size(), 0);
65 }
66
67 {
68 // WHEN
69 QSignalSpy spy(&animator, SIGNAL(channelMapperChanged(Qt3DAnimation::QChannelMapper*)));
70 auto newValue = new Qt3DAnimation::QChannelMapper();
71 animator.setChannelMapper(newValue);
72
73 // THEN
74 QVERIFY(spy.isValid());
75 QCOMPARE(animator.channelMapper(), newValue);
76 QCOMPARE(newValue->parent(), &animator);
77 QCOMPARE(spy.size(), 1);
78
79 // WHEN
80 spy.clear();
81 animator.setChannelMapper(newValue);
82
83 // THEN
84 QCOMPARE(animator.channelMapper(), newValue);
85 QCOMPARE(spy.size(), 0);
86 }
87
88 {
89 // WHEN
90 QSignalSpy spy(&animator, SIGNAL(clockChanged(Qt3DAnimation::QClock*)));
91 auto clock = new Qt3DAnimation::QClock();
92 animator.setClock(clock);
93
94 // THEN
95 QVERIFY(spy.isValid());
96 QCOMPARE(animator.clock(), clock);
97 QCOMPARE(clock->parent(), &animator);
98 QCOMPARE(spy.size(), 1);
99
100 // WHEN
101 spy.clear();
102 animator.setClock(clock);
103
104 // THEN
105 QCOMPARE(animator.clock(), clock);
106 QCOMPARE(spy.size(), 0);
107 }
108
109 {
110 // WHEN
111 QSignalSpy spy(&animator, SIGNAL(loopCountChanged(int)));
112 const int newValue = 5;
113 animator.setLoopCount(newValue);
114
115 // THEN
116 QVERIFY(spy.isValid());
117 QCOMPARE(animator.loopCount(), newValue);
118 QCOMPARE(spy.size(), 1);
119
120 // WHEN
121 spy.clear();
122 animator.setLoopCount(newValue);
123
124 // THEN
125 QCOMPARE(animator.loopCount(), newValue);
126 QCOMPARE(spy.size(), 0);
127 }
128 }
129
130 void checkRunning()
131 {
132 // GIVEN
133 Qt3DAnimation::QClipAnimator animator;
134 animator.stop();
135
136 {
137 // WHEN
138 animator.setRunning(true);
139
140 // THEN
141 QCOMPARE(animator.isRunning(), false);
142 }
143
144 {
145 // WHEN
146 Qt3DAnimation::QChannelMapper *mapper = new Qt3DAnimation::QChannelMapper;
147 Qt3DAnimation::QAnimationClip *clip = new Qt3DAnimation::QAnimationClip;
148 animator.setClip(clip);
149 animator.setChannelMapper(mapper);
150 animator.setRunning(true);
151
152 // THEN
153 QCOMPARE(animator.isRunning(), true);
154 }
155 }
156
157 void checkPropertyUpdate()
158 {
159 // GIVEN
160 TestArbiter arbiter;
161 Qt3DAnimation::QClipAnimator animator;
162 auto clip = new Qt3DAnimation::QAnimationClipLoader();
163 arbiter.setArbiterOnNode(&animator);
164
165 {
166 // WHEN
167 animator.setClip(clip);
168
169 // THEN
170 QCOMPARE(arbiter.dirtyNodes().size(), 1);
171 QCOMPARE(arbiter.dirtyNodes().front(), &animator);
172
173 arbiter.clear();
174 }
175
176 {
177 // WHEN
178 animator.setClip(clip);
179
180 // THEN
181 QCOMPARE(arbiter.dirtyNodes().size(), 0);
182 }
183
184 // GIVEN
185 auto mapper = new Qt3DAnimation::QChannelMapper;
186 {
187 // WHEN
188 animator.setChannelMapper(mapper);
189
190 // THEN
191 QCOMPARE(arbiter.dirtyNodes().size(), 1);
192 QCOMPARE(arbiter.dirtyNodes().front(), &animator);
193
194 arbiter.clear();
195 }
196
197 {
198 // WHEN
199 animator.setChannelMapper(mapper);
200
201 // THEN
202 QCOMPARE(arbiter.dirtyNodes().size(), 0);
203 }
204
205 // GIVEN
206 auto clock = new Qt3DAnimation::QClock;
207 {
208 // WHEN
209 animator.setClock(clock);
210
211 // THEN
212 QCOMPARE(arbiter.dirtyNodes().size(), 1);
213 QCOMPARE(arbiter.dirtyNodes().front(), &animator);
214
215 arbiter.clear();
216 }
217
218 {
219 // WHEN
220 animator.setClock(clock);
221
222 // THEN
223 QCOMPARE(arbiter.dirtyNodes().size(), 0);
224 }
225
226 {
227 // WHEN
228 animator.setLoopCount(10);
229
230 // THEN
231 QCOMPARE(arbiter.dirtyNodes().size(), 1);
232 QCOMPARE(arbiter.dirtyNodes().front(), &animator);
233
234 arbiter.clear();
235 }
236
237 {
238 // WHEN
239 animator.setLoopCount(10);
240
241 // THEN
242 QCOMPARE(arbiter.dirtyNodes().size(), 0);
243 }
244
245 }
246 };
247
248 QTEST_MAIN(tst_QClipAnimator)
249
250 #include "tst_qclipanimator.moc"