0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include <QtTest/QtTest>
|
|
43 |
|
|
44 |
#include <QtCore/qparallelanimationgroup.h>
|
|
45 |
|
|
46 |
//TESTED_CLASS=QParallelAnimationGroup
|
|
47 |
//TESTED_FILES=
|
|
48 |
|
|
49 |
Q_DECLARE_METATYPE(QAbstractAnimation::State)
|
|
50 |
|
|
51 |
class tst_QParallelAnimationGroup : public QObject
|
|
52 |
{
|
|
53 |
Q_OBJECT
|
|
54 |
public:
|
|
55 |
tst_QParallelAnimationGroup();
|
|
56 |
virtual ~tst_QParallelAnimationGroup();
|
|
57 |
|
|
58 |
public Q_SLOTS:
|
|
59 |
void init();
|
|
60 |
void cleanup();
|
|
61 |
|
|
62 |
private slots:
|
|
63 |
void construction();
|
|
64 |
void setCurrentTime();
|
|
65 |
void stateChanged();
|
|
66 |
void clearGroup();
|
|
67 |
void propagateGroupUpdateToChildren();
|
|
68 |
void updateChildrenWithRunningGroup();
|
|
69 |
void deleteChildrenWithRunningGroup();
|
|
70 |
void startChildrenWithStoppedGroup();
|
|
71 |
void stopGroupWithRunningChild();
|
|
72 |
void startGroupWithRunningChild();
|
|
73 |
void zeroDurationAnimation();
|
|
74 |
void stopUncontrolledAnimations();
|
|
75 |
void loopCount_data();
|
|
76 |
void loopCount();
|
|
77 |
void autoAdd();
|
|
78 |
void pauseResume();
|
|
79 |
};
|
|
80 |
|
|
81 |
tst_QParallelAnimationGroup::tst_QParallelAnimationGroup()
|
|
82 |
{
|
|
83 |
}
|
|
84 |
|
|
85 |
tst_QParallelAnimationGroup::~tst_QParallelAnimationGroup()
|
|
86 |
{
|
|
87 |
}
|
|
88 |
|
|
89 |
void tst_QParallelAnimationGroup::init()
|
|
90 |
{
|
|
91 |
qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State");
|
|
92 |
}
|
|
93 |
|
|
94 |
void tst_QParallelAnimationGroup::cleanup()
|
|
95 |
{
|
|
96 |
}
|
|
97 |
|
|
98 |
void tst_QParallelAnimationGroup::construction()
|
|
99 |
{
|
|
100 |
QParallelAnimationGroup animationgroup;
|
|
101 |
}
|
|
102 |
|
|
103 |
class AnimationObject : public QObject
|
|
104 |
{
|
|
105 |
Q_OBJECT
|
|
106 |
Q_PROPERTY(int value READ value WRITE setValue)
|
|
107 |
public:
|
|
108 |
AnimationObject(int startValue = 0)
|
|
109 |
: v(startValue)
|
|
110 |
{ }
|
|
111 |
|
|
112 |
int value() const { return v; }
|
|
113 |
void setValue(int value) { v = value; }
|
|
114 |
|
|
115 |
int v;
|
|
116 |
};
|
|
117 |
|
|
118 |
class TestAnimation : public QVariantAnimation
|
|
119 |
{
|
|
120 |
Q_OBJECT
|
|
121 |
public:
|
|
122 |
virtual void updateCurrentValue(const QVariant &value) { Q_UNUSED(value)};
|
|
123 |
virtual void updateState(QAbstractAnimation::State oldState,
|
|
124 |
QAbstractAnimation::State newState)
|
|
125 |
{
|
|
126 |
Q_UNUSED(oldState)
|
|
127 |
Q_UNUSED(newState)
|
|
128 |
};
|
|
129 |
};
|
|
130 |
|
|
131 |
class TestAnimation2 : public QVariantAnimation
|
|
132 |
{
|
|
133 |
Q_OBJECT
|
|
134 |
public:
|
|
135 |
TestAnimation2(QAbstractAnimation *animation) : QVariantAnimation(animation) {}
|
|
136 |
TestAnimation2(int duration, QAbstractAnimation *animation) : QVariantAnimation(animation), m_duration(duration) {}
|
|
137 |
|
|
138 |
virtual void updateCurrentValue(const QVariant &value) { Q_UNUSED(value)};
|
|
139 |
virtual void updateState(QAbstractAnimation::State oldState,
|
|
140 |
QAbstractAnimation::State newState)
|
|
141 |
{
|
|
142 |
Q_UNUSED(oldState)
|
|
143 |
Q_UNUSED(newState)
|
|
144 |
};
|
|
145 |
|
|
146 |
virtual int duration() const {
|
|
147 |
return m_duration;
|
|
148 |
}
|
|
149 |
private:
|
|
150 |
int m_duration;
|
|
151 |
};
|
|
152 |
|
|
153 |
class UncontrolledAnimation : public QPropertyAnimation
|
|
154 |
{
|
|
155 |
Q_OBJECT
|
|
156 |
public:
|
|
157 |
UncontrolledAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = 0)
|
|
158 |
: QPropertyAnimation(target, propertyName, parent), id(0)
|
|
159 |
{
|
|
160 |
setDuration(250);
|
|
161 |
setEndValue(0);
|
|
162 |
}
|
|
163 |
|
|
164 |
int duration() const { return -1; /* not time driven */ }
|
|
165 |
|
|
166 |
protected:
|
|
167 |
void timerEvent(QTimerEvent *event)
|
|
168 |
{
|
|
169 |
if (event->timerId() == id)
|
|
170 |
stop();
|
|
171 |
}
|
|
172 |
|
|
173 |
void updateRunning(bool running)
|
|
174 |
{
|
|
175 |
if (running) {
|
|
176 |
id = startTimer(500);
|
|
177 |
} else {
|
|
178 |
killTimer(id);
|
|
179 |
id = 0;
|
|
180 |
}
|
|
181 |
}
|
|
182 |
|
|
183 |
private:
|
|
184 |
int id;
|
|
185 |
};
|
|
186 |
|
|
187 |
void tst_QParallelAnimationGroup::setCurrentTime()
|
|
188 |
{
|
|
189 |
AnimationObject p_o1;
|
|
190 |
AnimationObject p_o2;
|
|
191 |
AnimationObject p_o3;
|
|
192 |
AnimationObject t_o1;
|
|
193 |
AnimationObject t_o2;
|
|
194 |
|
|
195 |
// parallel operating on different object/properties
|
|
196 |
QAnimationGroup *parallel = new QParallelAnimationGroup();
|
|
197 |
QVariantAnimation *a1_p_o1 = new QPropertyAnimation(&p_o1, "value");
|
|
198 |
QVariantAnimation *a1_p_o2 = new QPropertyAnimation(&p_o2, "value");
|
|
199 |
QVariantAnimation *a1_p_o3 = new QPropertyAnimation(&p_o3, "value");
|
|
200 |
a1_p_o2->setLoopCount(3);
|
|
201 |
parallel->addAnimation(a1_p_o1);
|
|
202 |
parallel->addAnimation(a1_p_o2);
|
|
203 |
parallel->addAnimation(a1_p_o3);
|
|
204 |
|
|
205 |
UncontrolledAnimation *notTimeDriven = new UncontrolledAnimation(&t_o1, "value");
|
|
206 |
QCOMPARE(notTimeDriven->totalDuration(), -1);
|
|
207 |
|
|
208 |
QVariantAnimation *loopsForever = new QPropertyAnimation(&t_o2, "value");
|
|
209 |
loopsForever->setLoopCount(-1);
|
|
210 |
QCOMPARE(loopsForever->totalDuration(), -1);
|
|
211 |
|
|
212 |
QParallelAnimationGroup group;
|
|
213 |
group.addAnimation(parallel);
|
|
214 |
group.addAnimation(notTimeDriven);
|
|
215 |
group.addAnimation(loopsForever);
|
|
216 |
|
|
217 |
// Current time = 1
|
|
218 |
group.setCurrentTime(1);
|
|
219 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
220 |
QCOMPARE(parallel->state(), QAnimationGroup::Stopped);
|
|
221 |
QCOMPARE(a1_p_o1->state(), QAnimationGroup::Stopped);
|
|
222 |
QCOMPARE(a1_p_o2->state(), QAnimationGroup::Stopped);
|
|
223 |
QCOMPARE(a1_p_o3->state(), QAnimationGroup::Stopped);
|
|
224 |
QCOMPARE(notTimeDriven->state(), QAnimationGroup::Stopped);
|
|
225 |
QCOMPARE(loopsForever->state(), QAnimationGroup::Stopped);
|
|
226 |
|
|
227 |
QCOMPARE(group.currentTime(), 1);
|
|
228 |
QCOMPARE(a1_p_o1->currentTime(), 1);
|
|
229 |
QCOMPARE(a1_p_o2->currentTime(), 1);
|
|
230 |
QCOMPARE(a1_p_o3->currentTime(), 1);
|
|
231 |
QCOMPARE(notTimeDriven->currentTime(), 1);
|
|
232 |
QCOMPARE(loopsForever->currentTime(), 1);
|
|
233 |
|
|
234 |
// Current time = 250
|
|
235 |
group.setCurrentTime(250);
|
|
236 |
QCOMPARE(group.currentTime(), 250);
|
|
237 |
QCOMPARE(a1_p_o1->currentTime(), 250);
|
|
238 |
QCOMPARE(a1_p_o2->currentTime(), 0);
|
|
239 |
QCOMPARE(a1_p_o2->currentLoop(), 1);
|
|
240 |
QCOMPARE(a1_p_o3->currentTime(), 250);
|
|
241 |
QCOMPARE(notTimeDriven->currentTime(), 250);
|
|
242 |
QCOMPARE(loopsForever->currentTime(), 0);
|
|
243 |
QCOMPARE(loopsForever->currentLoop(), 1);
|
|
244 |
|
|
245 |
// Current time = 251
|
|
246 |
group.setCurrentTime(251);
|
|
247 |
QCOMPARE(group.currentTime(), 251);
|
|
248 |
QCOMPARE(a1_p_o1->currentTime(), 250);
|
|
249 |
QCOMPARE(a1_p_o2->currentTime(), 1);
|
|
250 |
QCOMPARE(a1_p_o2->currentLoop(), 1);
|
|
251 |
QCOMPARE(a1_p_o3->currentTime(), 250);
|
|
252 |
QCOMPARE(notTimeDriven->currentTime(), 251);
|
|
253 |
QCOMPARE(loopsForever->currentTime(), 1);
|
|
254 |
}
|
|
255 |
|
|
256 |
void tst_QParallelAnimationGroup::stateChanged()
|
|
257 |
{
|
|
258 |
//this ensures that the correct animations are started when starting the group
|
|
259 |
TestAnimation *anim1 = new TestAnimation;
|
|
260 |
TestAnimation *anim2 = new TestAnimation;
|
|
261 |
TestAnimation *anim3 = new TestAnimation;
|
|
262 |
TestAnimation *anim4 = new TestAnimation;
|
|
263 |
anim1->setDuration(1000);
|
|
264 |
anim2->setDuration(2000);
|
|
265 |
anim3->setDuration(3000);
|
|
266 |
anim4->setDuration(3000);
|
|
267 |
QParallelAnimationGroup group;
|
|
268 |
group.addAnimation(anim1);
|
|
269 |
group.addAnimation(anim2);
|
|
270 |
group.addAnimation(anim3);
|
|
271 |
group.addAnimation(anim4);
|
|
272 |
|
|
273 |
QSignalSpy spy1(anim1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
|
|
274 |
QSignalSpy spy2(anim2, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
|
|
275 |
QSignalSpy spy3(anim3, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
|
|
276 |
QSignalSpy spy4(anim4, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
|
|
277 |
|
|
278 |
//first; let's start forward
|
|
279 |
group.start();
|
|
280 |
//all the animations should be started
|
|
281 |
QCOMPARE(spy1.count(), 1);
|
|
282 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy1.last().at(1)), TestAnimation::Running);
|
|
283 |
QCOMPARE(spy2.count(), 1);
|
|
284 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy2.last().at(1)), TestAnimation::Running);
|
|
285 |
QCOMPARE(spy3.count(), 1);
|
|
286 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy3.last().at(1)), TestAnimation::Running);
|
|
287 |
QCOMPARE(spy4.count(), 1);
|
|
288 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy4.last().at(1)), TestAnimation::Running);
|
|
289 |
|
|
290 |
group.setCurrentTime(1500); //anim1 should be finished
|
|
291 |
QCOMPARE(group.state(), QAnimationGroup::Running);
|
|
292 |
QCOMPARE(spy1.count(), 2);
|
|
293 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy1.last().at(1)), TestAnimation::Stopped);
|
|
294 |
QCOMPARE(spy2.count(), 1); //no change
|
|
295 |
QCOMPARE(spy3.count(), 1); //no change
|
|
296 |
QCOMPARE(spy4.count(), 1); //no change
|
|
297 |
|
|
298 |
group.setCurrentTime(2500); //anim2 should be finished
|
|
299 |
QCOMPARE(group.state(), QAnimationGroup::Running);
|
|
300 |
QCOMPARE(spy1.count(), 2); //no change
|
|
301 |
QCOMPARE(spy2.count(), 2);
|
|
302 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy2.last().at(1)), TestAnimation::Stopped);
|
|
303 |
QCOMPARE(spy3.count(), 1); //no change
|
|
304 |
QCOMPARE(spy4.count(), 1); //no change
|
|
305 |
|
|
306 |
group.setCurrentTime(3500); //everything should be finished
|
|
307 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
308 |
QCOMPARE(spy1.count(), 2); //no change
|
|
309 |
QCOMPARE(spy2.count(), 2); //no change
|
|
310 |
QCOMPARE(spy3.count(), 2);
|
|
311 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy3.last().at(1)), TestAnimation::Stopped);
|
|
312 |
QCOMPARE(spy4.count(), 2);
|
|
313 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy4.last().at(1)), TestAnimation::Stopped);
|
|
314 |
|
|
315 |
//cleanup
|
|
316 |
spy1.clear();
|
|
317 |
spy2.clear();
|
|
318 |
spy3.clear();
|
|
319 |
spy4.clear();
|
|
320 |
|
|
321 |
//now let's try to reverse that
|
|
322 |
group.setDirection(QAbstractAnimation::Backward);
|
|
323 |
group.start();
|
|
324 |
|
|
325 |
//only anim3 and anim4 should be started
|
|
326 |
QCOMPARE(group.state(), QAnimationGroup::Running);
|
|
327 |
QCOMPARE(spy1.count(), 0);
|
|
328 |
QCOMPARE(spy2.count(), 0);
|
|
329 |
QCOMPARE(spy3.count(), 1);
|
|
330 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy3.last().at(1)), TestAnimation::Running);
|
|
331 |
QCOMPARE(spy4.count(), 1);
|
|
332 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy4.last().at(1)), TestAnimation::Running);
|
|
333 |
|
|
334 |
group.setCurrentTime(1500); //anim2 should be started
|
|
335 |
QCOMPARE(group.state(), QAnimationGroup::Running);
|
|
336 |
QCOMPARE(spy1.count(), 0); //no change
|
|
337 |
QCOMPARE(spy2.count(), 1);
|
|
338 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy2.last().at(1)), TestAnimation::Running);
|
|
339 |
QCOMPARE(spy3.count(), 1); //no change
|
|
340 |
QCOMPARE(spy4.count(), 1); //no change
|
|
341 |
|
|
342 |
group.setCurrentTime(500); //anim1 is finally also started
|
|
343 |
QCOMPARE(group.state(), QAnimationGroup::Running);
|
|
344 |
QCOMPARE(spy1.count(), 1);
|
|
345 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy1.last().at(1)), TestAnimation::Running);
|
|
346 |
QCOMPARE(spy2.count(), 1); //no change
|
|
347 |
QCOMPARE(spy3.count(), 1); //no change
|
|
348 |
QCOMPARE(spy4.count(), 1); //no change
|
|
349 |
|
|
350 |
group.setCurrentTime(0); //everything should be stopped
|
|
351 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
352 |
QCOMPARE(spy1.count(), 2);
|
|
353 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy1.last().at(1)), TestAnimation::Stopped);
|
|
354 |
QCOMPARE(spy2.count(), 2);
|
|
355 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy2.last().at(1)), TestAnimation::Stopped);
|
|
356 |
QCOMPARE(spy3.count(), 2);
|
|
357 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy3.last().at(1)), TestAnimation::Stopped);
|
|
358 |
QCOMPARE(spy4.count(), 2);
|
|
359 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy4.last().at(1)), TestAnimation::Stopped);
|
|
360 |
}
|
|
361 |
|
|
362 |
void tst_QParallelAnimationGroup::clearGroup()
|
|
363 |
{
|
|
364 |
QParallelAnimationGroup group;
|
|
365 |
static const int animationCount = 10;
|
|
366 |
|
|
367 |
for (int i = 0; i < animationCount; ++i) {
|
|
368 |
new QParallelAnimationGroup(&group);
|
|
369 |
}
|
|
370 |
|
|
371 |
QCOMPARE(group.animationCount(), animationCount);
|
|
372 |
|
|
373 |
QPointer<QAbstractAnimation> children[animationCount];
|
|
374 |
for (int i = 0; i < animationCount; ++i) {
|
|
375 |
QVERIFY(group.animationAt(i) != 0);
|
|
376 |
children[i] = group.animationAt(i);
|
|
377 |
}
|
|
378 |
|
|
379 |
group.clearAnimations();
|
|
380 |
QCOMPARE(group.animationCount(), 0);
|
|
381 |
QCOMPARE(group.currentTime(), 0);
|
|
382 |
for (int i = 0; i < animationCount; ++i)
|
|
383 |
QVERIFY(children[i].isNull());
|
|
384 |
}
|
|
385 |
|
|
386 |
void tst_QParallelAnimationGroup::propagateGroupUpdateToChildren()
|
|
387 |
{
|
|
388 |
// this test verifies if group state changes are updating its children correctly
|
|
389 |
QParallelAnimationGroup group;
|
|
390 |
|
|
391 |
QObject o;
|
|
392 |
o.setProperty("ole", 42);
|
|
393 |
QCOMPARE(o.property("ole").toInt(), 42);
|
|
394 |
|
|
395 |
QPropertyAnimation anim1(&o, "ole");
|
|
396 |
anim1.setEndValue(43);
|
|
397 |
anim1.setDuration(100);
|
|
398 |
QVERIFY(!anim1.currentValue().isValid());
|
|
399 |
QCOMPARE(anim1.currentValue().toInt(), 0);
|
|
400 |
QCOMPARE(o.property("ole").toInt(), 42);
|
|
401 |
|
|
402 |
TestAnimation anim2;
|
|
403 |
anim2.setStartValue(0);
|
|
404 |
anim2.setEndValue(100);
|
|
405 |
anim2.setDuration(200);
|
|
406 |
|
|
407 |
QVERIFY(anim2.currentValue().isValid());
|
|
408 |
QCOMPARE(anim2.currentValue().toInt(), 0);
|
|
409 |
|
|
410 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
411 |
QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
|
|
412 |
QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
|
|
413 |
|
|
414 |
group.addAnimation(&anim1);
|
|
415 |
group.addAnimation(&anim2);
|
|
416 |
|
|
417 |
group.start();
|
|
418 |
|
|
419 |
QCOMPARE(group.state(), QAnimationGroup::Running);
|
|
420 |
QCOMPARE(anim1.state(), QAnimationGroup::Running);
|
|
421 |
QCOMPARE(anim2.state(), QAnimationGroup::Running);
|
|
422 |
|
|
423 |
group.pause();
|
|
424 |
|
|
425 |
QCOMPARE(group.state(), QAnimationGroup::Paused);
|
|
426 |
QCOMPARE(anim1.state(), QAnimationGroup::Paused);
|
|
427 |
QCOMPARE(anim2.state(), QAnimationGroup::Paused);
|
|
428 |
|
|
429 |
group.stop();
|
|
430 |
|
|
431 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
432 |
QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
|
|
433 |
QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
|
|
434 |
}
|
|
435 |
|
|
436 |
void tst_QParallelAnimationGroup::updateChildrenWithRunningGroup()
|
|
437 |
{
|
|
438 |
// assert that its possible to modify a child's state directly while their group is running
|
|
439 |
QParallelAnimationGroup group;
|
|
440 |
|
|
441 |
TestAnimation anim;
|
|
442 |
anim.setStartValue(0);
|
|
443 |
anim.setEndValue(100);
|
|
444 |
anim.setDuration(200);
|
|
445 |
|
|
446 |
QSignalSpy groupStateChangedSpy(&group, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
|
|
447 |
QSignalSpy childStateChangedSpy(&anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
|
|
448 |
|
|
449 |
QCOMPARE(groupStateChangedSpy.count(), 0);
|
|
450 |
QCOMPARE(childStateChangedSpy.count(), 0);
|
|
451 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
452 |
QCOMPARE(anim.state(), QAnimationGroup::Stopped);
|
|
453 |
|
|
454 |
group.addAnimation(&anim);
|
|
455 |
|
|
456 |
group.start();
|
|
457 |
|
|
458 |
QCOMPARE(group.state(), QAnimationGroup::Running);
|
|
459 |
QCOMPARE(anim.state(), QAnimationGroup::Running);
|
|
460 |
|
|
461 |
QCOMPARE(groupStateChangedSpy.count(), 1);
|
|
462 |
QCOMPARE(childStateChangedSpy.count(), 1);
|
|
463 |
|
|
464 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(0).at(1)),
|
|
465 |
QAnimationGroup::Running);
|
|
466 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(childStateChangedSpy.at(0).at(1)),
|
|
467 |
QAnimationGroup::Running);
|
|
468 |
|
|
469 |
// starting directly a running child will not have any effect
|
|
470 |
anim.start();
|
|
471 |
|
|
472 |
QCOMPARE(groupStateChangedSpy.count(), 1);
|
|
473 |
QCOMPARE(childStateChangedSpy.count(), 1);
|
|
474 |
|
|
475 |
anim.pause();
|
|
476 |
|
|
477 |
QCOMPARE(group.state(), QAnimationGroup::Running);
|
|
478 |
QCOMPARE(anim.state(), QAnimationGroup::Paused);
|
|
479 |
|
|
480 |
// in the animation stops directly, the group will still be running
|
|
481 |
anim.stop();
|
|
482 |
|
|
483 |
QCOMPARE(group.state(), QAnimationGroup::Running);
|
|
484 |
QCOMPARE(anim.state(), QAnimationGroup::Stopped);
|
|
485 |
}
|
|
486 |
|
|
487 |
void tst_QParallelAnimationGroup::deleteChildrenWithRunningGroup()
|
|
488 |
{
|
|
489 |
#if defined(Q_OS_SYMBIAN)
|
|
490 |
// give the Symbian app start event queue time to clear
|
|
491 |
QTest::qWait(1000);
|
|
492 |
#endif
|
|
493 |
// test if children can be activated when their group is stopped
|
|
494 |
QParallelAnimationGroup group;
|
|
495 |
|
|
496 |
QVariantAnimation *anim1 = new TestAnimation;
|
|
497 |
anim1->setStartValue(0);
|
|
498 |
anim1->setEndValue(100);
|
|
499 |
anim1->setDuration(200);
|
|
500 |
group.addAnimation(anim1);
|
|
501 |
|
|
502 |
QCOMPARE(group.duration(), anim1->duration());
|
|
503 |
|
|
504 |
group.start();
|
|
505 |
QCOMPARE(group.state(), QAnimationGroup::Running);
|
|
506 |
QCOMPARE(anim1->state(), QAnimationGroup::Running);
|
|
507 |
|
|
508 |
QTest::qWait(80);
|
|
509 |
QVERIFY(group.currentTime() > 0);
|
|
510 |
|
|
511 |
delete anim1;
|
|
512 |
QVERIFY(group.animationCount() == 0);
|
|
513 |
QCOMPARE(group.duration(), 0);
|
|
514 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
515 |
QCOMPARE(group.currentTime(), 0); //that's the invariant
|
|
516 |
}
|
|
517 |
|
|
518 |
void tst_QParallelAnimationGroup::startChildrenWithStoppedGroup()
|
|
519 |
{
|
|
520 |
// test if children can be activated when their group is stopped
|
|
521 |
QParallelAnimationGroup group;
|
|
522 |
|
|
523 |
TestAnimation anim1;
|
|
524 |
anim1.setStartValue(0);
|
|
525 |
anim1.setEndValue(100);
|
|
526 |
anim1.setDuration(200);
|
|
527 |
|
|
528 |
TestAnimation anim2;
|
|
529 |
anim2.setStartValue(0);
|
|
530 |
anim2.setEndValue(100);
|
|
531 |
anim2.setDuration(200);
|
|
532 |
|
|
533 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
534 |
QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
|
|
535 |
QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
|
|
536 |
|
|
537 |
group.addAnimation(&anim1);
|
|
538 |
group.addAnimation(&anim2);
|
|
539 |
|
|
540 |
group.stop();
|
|
541 |
|
|
542 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
543 |
QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
|
|
544 |
QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
|
|
545 |
|
|
546 |
anim1.start();
|
|
547 |
anim2.start();
|
|
548 |
anim2.pause();
|
|
549 |
|
|
550 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
551 |
QCOMPARE(anim1.state(), QAnimationGroup::Running);
|
|
552 |
QCOMPARE(anim2.state(), QAnimationGroup::Paused);
|
|
553 |
}
|
|
554 |
|
|
555 |
void tst_QParallelAnimationGroup::stopGroupWithRunningChild()
|
|
556 |
{
|
|
557 |
// children that started independently will not be affected by a group stop
|
|
558 |
QParallelAnimationGroup group;
|
|
559 |
|
|
560 |
TestAnimation anim1;
|
|
561 |
anim1.setStartValue(0);
|
|
562 |
anim1.setEndValue(100);
|
|
563 |
anim1.setDuration(200);
|
|
564 |
|
|
565 |
TestAnimation anim2;
|
|
566 |
anim2.setStartValue(0);
|
|
567 |
anim2.setEndValue(100);
|
|
568 |
anim2.setDuration(200);
|
|
569 |
|
|
570 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
571 |
QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
|
|
572 |
QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
|
|
573 |
|
|
574 |
group.addAnimation(&anim1);
|
|
575 |
group.addAnimation(&anim2);
|
|
576 |
|
|
577 |
anim1.start();
|
|
578 |
anim2.start();
|
|
579 |
anim2.pause();
|
|
580 |
|
|
581 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
582 |
QCOMPARE(anim1.state(), QAnimationGroup::Running);
|
|
583 |
QCOMPARE(anim2.state(), QAnimationGroup::Paused);
|
|
584 |
|
|
585 |
group.stop();
|
|
586 |
|
|
587 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
588 |
QCOMPARE(anim1.state(), QAnimationGroup::Running);
|
|
589 |
QCOMPARE(anim2.state(), QAnimationGroup::Paused);
|
|
590 |
|
|
591 |
anim1.stop();
|
|
592 |
anim2.stop();
|
|
593 |
|
|
594 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
595 |
QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
|
|
596 |
QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
|
|
597 |
}
|
|
598 |
|
|
599 |
void tst_QParallelAnimationGroup::startGroupWithRunningChild()
|
|
600 |
{
|
|
601 |
// as the group has precedence over its children, starting a group will restart all the children
|
|
602 |
QParallelAnimationGroup group;
|
|
603 |
|
|
604 |
TestAnimation anim1;
|
|
605 |
anim1.setStartValue(0);
|
|
606 |
anim1.setEndValue(100);
|
|
607 |
anim1.setDuration(200);
|
|
608 |
|
|
609 |
TestAnimation anim2;
|
|
610 |
anim2.setStartValue(0);
|
|
611 |
anim2.setEndValue(100);
|
|
612 |
anim2.setDuration(200);
|
|
613 |
|
|
614 |
QSignalSpy stateChangedSpy1(&anim1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
|
|
615 |
QSignalSpy stateChangedSpy2(&anim2, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
|
|
616 |
|
|
617 |
QCOMPARE(stateChangedSpy1.count(), 0);
|
|
618 |
QCOMPARE(stateChangedSpy2.count(), 0);
|
|
619 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
620 |
QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
|
|
621 |
QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
|
|
622 |
|
|
623 |
group.addAnimation(&anim1);
|
|
624 |
group.addAnimation(&anim2);
|
|
625 |
|
|
626 |
anim1.start();
|
|
627 |
anim2.start();
|
|
628 |
anim2.pause();
|
|
629 |
|
|
630 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(0).at(1)),
|
|
631 |
QAnimationGroup::Running);
|
|
632 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy2.at(0).at(1)),
|
|
633 |
QAnimationGroup::Running);
|
|
634 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy2.at(1).at(1)),
|
|
635 |
QAnimationGroup::Paused);
|
|
636 |
|
|
637 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
638 |
QCOMPARE(anim1.state(), QAnimationGroup::Running);
|
|
639 |
QCOMPARE(anim2.state(), QAnimationGroup::Paused);
|
|
640 |
|
|
641 |
group.start();
|
|
642 |
|
|
643 |
QCOMPARE(stateChangedSpy1.count(), 3);
|
|
644 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(1).at(1)),
|
|
645 |
QAnimationGroup::Stopped);
|
|
646 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(2).at(1)),
|
|
647 |
QAnimationGroup::Running);
|
|
648 |
|
|
649 |
QCOMPARE(stateChangedSpy2.count(), 4);
|
|
650 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy2.at(2).at(1)),
|
|
651 |
QAnimationGroup::Stopped);
|
|
652 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy2.at(3).at(1)),
|
|
653 |
QAnimationGroup::Running);
|
|
654 |
|
|
655 |
QCOMPARE(group.state(), QAnimationGroup::Running);
|
|
656 |
QCOMPARE(anim1.state(), QAnimationGroup::Running);
|
|
657 |
QCOMPARE(anim2.state(), QAnimationGroup::Running);
|
|
658 |
}
|
|
659 |
|
|
660 |
void tst_QParallelAnimationGroup::zeroDurationAnimation()
|
|
661 |
{
|
|
662 |
QParallelAnimationGroup group;
|
|
663 |
|
|
664 |
TestAnimation anim1;
|
|
665 |
anim1.setStartValue(0);
|
|
666 |
anim1.setEndValue(100);
|
|
667 |
anim1.setDuration(0);
|
|
668 |
|
|
669 |
TestAnimation anim2;
|
|
670 |
anim2.setStartValue(0);
|
|
671 |
anim2.setEndValue(100);
|
|
672 |
anim2.setDuration(100);
|
|
673 |
|
|
674 |
TestAnimation anim3;
|
|
675 |
anim3.setStartValue(0);
|
|
676 |
anim3.setEndValue(100);
|
|
677 |
anim3.setDuration(10);
|
|
678 |
|
|
679 |
QSignalSpy stateChangedSpy1(&anim1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
|
|
680 |
QSignalSpy finishedSpy1(&anim1, SIGNAL(finished()));
|
|
681 |
|
|
682 |
QSignalSpy stateChangedSpy2(&anim2, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
|
|
683 |
QSignalSpy finishedSpy2(&anim2, SIGNAL(finished()));
|
|
684 |
|
|
685 |
QSignalSpy stateChangedSpy3(&anim3, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
|
|
686 |
QSignalSpy finishedSpy3(&anim3, SIGNAL(finished()));
|
|
687 |
|
|
688 |
group.addAnimation(&anim1);
|
|
689 |
group.addAnimation(&anim2);
|
|
690 |
group.addAnimation(&anim3);
|
|
691 |
QCOMPARE(stateChangedSpy1.count(), 0);
|
|
692 |
group.start();
|
|
693 |
QCOMPARE(stateChangedSpy1.count(), 2);
|
|
694 |
QCOMPARE(finishedSpy1.count(), 1);
|
|
695 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(0).at(1)),
|
|
696 |
QAnimationGroup::Running);
|
|
697 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(1).at(1)),
|
|
698 |
QAnimationGroup::Stopped);
|
|
699 |
|
|
700 |
QCOMPARE(stateChangedSpy2.count(), 1);
|
|
701 |
QCOMPARE(finishedSpy2.count(), 0);
|
|
702 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(0).at(1)),
|
|
703 |
QAnimationGroup::Running);
|
|
704 |
|
|
705 |
QCOMPARE(stateChangedSpy3.count(), 1);
|
|
706 |
QCOMPARE(finishedSpy3.count(), 0);
|
|
707 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy3.at(0).at(1)),
|
|
708 |
QAnimationGroup::Running);
|
|
709 |
|
|
710 |
|
|
711 |
QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
|
|
712 |
QCOMPARE(anim2.state(), QAnimationGroup::Running);
|
|
713 |
QCOMPARE(anim3.state(), QAnimationGroup::Running);
|
|
714 |
QCOMPARE(group.state(), QAnimationGroup::Running);
|
|
715 |
|
|
716 |
|
|
717 |
group.stop();
|
|
718 |
group.setLoopCount(4);
|
|
719 |
stateChangedSpy1.clear();
|
|
720 |
stateChangedSpy2.clear();
|
|
721 |
stateChangedSpy3.clear();
|
|
722 |
|
|
723 |
group.start();
|
|
724 |
QCOMPARE(stateChangedSpy1.count(), 2);
|
|
725 |
QCOMPARE(stateChangedSpy2.count(), 1);
|
|
726 |
QCOMPARE(stateChangedSpy3.count(), 1);
|
|
727 |
group.setCurrentTime(50);
|
|
728 |
QCOMPARE(stateChangedSpy1.count(), 2);
|
|
729 |
QCOMPARE(stateChangedSpy2.count(), 1);
|
|
730 |
QCOMPARE(stateChangedSpy3.count(), 2);
|
|
731 |
group.setCurrentTime(150);
|
|
732 |
QCOMPARE(stateChangedSpy1.count(), 4);
|
|
733 |
QCOMPARE(stateChangedSpy2.count(), 3);
|
|
734 |
QCOMPARE(stateChangedSpy3.count(), 4);
|
|
735 |
group.setCurrentTime(50);
|
|
736 |
QCOMPARE(stateChangedSpy1.count(), 6);
|
|
737 |
QCOMPARE(stateChangedSpy2.count(), 5);
|
|
738 |
QCOMPARE(stateChangedSpy3.count(), 6);
|
|
739 |
|
|
740 |
}
|
|
741 |
|
|
742 |
void tst_QParallelAnimationGroup::stopUncontrolledAnimations()
|
|
743 |
{
|
|
744 |
QParallelAnimationGroup group;
|
|
745 |
|
|
746 |
TestAnimation anim1;
|
|
747 |
anim1.setStartValue(0);
|
|
748 |
anim1.setEndValue(100);
|
|
749 |
anim1.setDuration(0);
|
|
750 |
|
|
751 |
AnimationObject o1;
|
|
752 |
UncontrolledAnimation notTimeDriven(&o1, "value");
|
|
753 |
QCOMPARE(notTimeDriven.totalDuration(), -1);
|
|
754 |
|
|
755 |
TestAnimation loopsForever;
|
|
756 |
loopsForever.setStartValue(0);
|
|
757 |
loopsForever.setEndValue(100);
|
|
758 |
loopsForever.setDuration(100);
|
|
759 |
loopsForever.setLoopCount(-1);
|
|
760 |
|
|
761 |
QSignalSpy stateChangedSpy(&anim1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
|
|
762 |
|
|
763 |
group.addAnimation(&anim1);
|
|
764 |
group.addAnimation(¬TimeDriven);
|
|
765 |
group.addAnimation(&loopsForever);
|
|
766 |
|
|
767 |
group.start();
|
|
768 |
|
|
769 |
QCOMPARE(stateChangedSpy.count(), 2);
|
|
770 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy.at(0).at(1)),
|
|
771 |
QAnimationGroup::Running);
|
|
772 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy.at(1).at(1)),
|
|
773 |
QAnimationGroup::Stopped);
|
|
774 |
|
|
775 |
QCOMPARE(group.state(), QAnimationGroup::Running);
|
|
776 |
QCOMPARE(notTimeDriven.state(), QAnimationGroup::Running);
|
|
777 |
QCOMPARE(loopsForever.state(), QAnimationGroup::Running);
|
|
778 |
QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
|
|
779 |
|
|
780 |
notTimeDriven.stop();
|
|
781 |
|
|
782 |
QCOMPARE(group.state(), QAnimationGroup::Running);
|
|
783 |
QCOMPARE(notTimeDriven.state(), QAnimationGroup::Stopped);
|
|
784 |
QCOMPARE(loopsForever.state(), QAnimationGroup::Running);
|
|
785 |
|
|
786 |
loopsForever.stop();
|
|
787 |
|
|
788 |
QCOMPARE(group.state(), QAnimationGroup::Stopped);
|
|
789 |
QCOMPARE(notTimeDriven.state(), QAnimationGroup::Stopped);
|
|
790 |
QCOMPARE(loopsForever.state(), QAnimationGroup::Stopped);
|
|
791 |
}
|
|
792 |
|
|
793 |
struct AnimState {
|
|
794 |
AnimState(int time = -1) : time(time), state(-1) {}
|
|
795 |
AnimState(int time, int state) : time(time), state(state) {}
|
|
796 |
int time;
|
|
797 |
int state;
|
|
798 |
};
|
|
799 |
|
|
800 |
#define Running QAbstractAnimation::Running
|
|
801 |
#define Stopped QAbstractAnimation::Stopped
|
|
802 |
|
|
803 |
Q_DECLARE_METATYPE(AnimState)
|
|
804 |
void tst_QParallelAnimationGroup::loopCount_data()
|
|
805 |
{
|
|
806 |
QTest::addColumn<bool>("directionBackward");
|
|
807 |
QTest::addColumn<int>("setLoopCount");
|
|
808 |
QTest::addColumn<int>("initialGroupTime");
|
|
809 |
QTest::addColumn<int>("currentGroupTime");
|
|
810 |
QTest::addColumn<AnimState>("expected1");
|
|
811 |
QTest::addColumn<AnimState>("expected2");
|
|
812 |
QTest::addColumn<AnimState>("expected3");
|
|
813 |
|
|
814 |
// D U R A T I O N
|
|
815 |
// 100 60*2 0
|
|
816 |
// direction = Forward
|
|
817 |
QTest::newRow("50") << false << 3 << 0 << 50 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
818 |
QTest::newRow("100") << false << 3 << 0 << 100 << AnimState(100 ) << AnimState( 40, Running) << AnimState( 0, Stopped);
|
|
819 |
QTest::newRow("110") << false << 3 << 0 << 110 << AnimState(100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
820 |
QTest::newRow("120") << false << 3 << 0 << 120 << AnimState( 0, Running) << AnimState( 0, Running) << AnimState( 0, Stopped);
|
|
821 |
|
|
822 |
QTest::newRow("170") << false << 3 << 0 << 170 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
823 |
QTest::newRow("220") << false << 3 << 0 << 220 << AnimState(100 ) << AnimState( 40, Running) << AnimState( 0, Stopped);
|
|
824 |
QTest::newRow("230") << false << 3 << 0 << 230 << AnimState(100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
825 |
QTest::newRow("240") << false << 3 << 0 << 240 << AnimState( 0, Running) << AnimState( 0, Running) << AnimState( 0, Stopped);
|
|
826 |
|
|
827 |
QTest::newRow("290") << false << 3 << 0 << 290 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
828 |
QTest::newRow("340") << false << 3 << 0 << 340 << AnimState(100 ) << AnimState( 40, Running) << AnimState( 0, Stopped);
|
|
829 |
QTest::newRow("350") << false << 3 << 0 << 350 << AnimState(100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
830 |
QTest::newRow("360") << false << 3 << 0 << 360 << AnimState(100, Stopped) << AnimState( 60 ) << AnimState( 0, Stopped);
|
|
831 |
|
|
832 |
QTest::newRow("410") << false << 3 << 0 << 410 << AnimState(100, Stopped) << AnimState( 60, Stopped) << AnimState( 0, Stopped);
|
|
833 |
QTest::newRow("460") << false << 3 << 0 << 460 << AnimState(100, Stopped) << AnimState( 60, Stopped) << AnimState( 0, Stopped);
|
|
834 |
QTest::newRow("470") << false << 3 << 0 << 470 << AnimState(100, Stopped) << AnimState( 60, Stopped) << AnimState( 0, Stopped);
|
|
835 |
QTest::newRow("480") << false << 3 << 0 << 480 << AnimState(100, Stopped) << AnimState( 60, Stopped) << AnimState( 0, Stopped);
|
|
836 |
|
|
837 |
// direction = Forward, rewind
|
|
838 |
QTest::newRow("120-110") << false << 3 << 120 << 110 << AnimState( 0, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
839 |
QTest::newRow("120-50") << false << 3 << 120 << 50 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
840 |
QTest::newRow("120-0") << false << 3 << 120 << 0 << AnimState( 0, Running) << AnimState( 0, Running) << AnimState( 0, Stopped);
|
|
841 |
QTest::newRow("300-110") << false << 3 << 300 << 110 << AnimState( 0, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
842 |
QTest::newRow("300-50") << false << 3 << 300 << 50 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
843 |
QTest::newRow("300-0") << false << 3 << 300 << 0 << AnimState( 0, Running) << AnimState( 0, Running) << AnimState( 0, Stopped);
|
|
844 |
QTest::newRow("115-105") << false << 3 << 115 << 105 << AnimState( 42, Stopped) << AnimState( 45, Running) << AnimState( 0, Stopped);
|
|
845 |
|
|
846 |
// direction = Backward
|
|
847 |
QTest::newRow("b120-120") << true << 3 << 120 << 120 << AnimState( 42, Stopped) << AnimState( 60, Running) << AnimState( 0, Stopped);
|
|
848 |
QTest::newRow("b120-110") << true << 3 << 120 << 110 << AnimState( 42, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
849 |
QTest::newRow("b120-100") << true << 3 << 120 << 100 << AnimState(100, Running) << AnimState( 40, Running) << AnimState( 0, Stopped);
|
|
850 |
QTest::newRow("b120-50") << true << 3 << 120 << 50 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
851 |
QTest::newRow("b120-0") << true << 3 << 120 << 0 << AnimState( 0, Stopped) << AnimState( 0, Stopped) << AnimState( 0, Stopped);
|
|
852 |
QTest::newRow("b360-170") << true << 3 << 360 << 170 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
853 |
QTest::newRow("b360-220") << true << 3 << 360 << 220 << AnimState(100, Running) << AnimState( 40, Running) << AnimState( 0, Stopped);
|
|
854 |
QTest::newRow("b360-210") << true << 3 << 360 << 210 << AnimState( 90, Running) << AnimState( 30, Running) << AnimState( 0, Stopped);
|
|
855 |
QTest::newRow("b360-120") << true << 3 << 360 << 120 << AnimState( 0, Stopped) << AnimState( 60, Running) << AnimState( 0, Stopped);
|
|
856 |
|
|
857 |
// rewind, direction = Backward
|
|
858 |
QTest::newRow("b50-110") << true << 3 << 50 << 110 << AnimState(100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
859 |
QTest::newRow("b50-120") << true << 3 << 50 << 120 << AnimState(100, Stopped) << AnimState( 60, Running) << AnimState( 0, Stopped);
|
|
860 |
QTest::newRow("b50-140") << true << 3 << 50 << 140 << AnimState( 20, Running) << AnimState( 20, Running) << AnimState( 0, Stopped);
|
|
861 |
QTest::newRow("b50-240") << true << 3 << 50 << 240 << AnimState(100, Stopped) << AnimState( 60, Running) << AnimState( 0, Stopped);
|
|
862 |
QTest::newRow("b50-260") << true << 3 << 50 << 260 << AnimState( 20, Running) << AnimState( 20, Running) << AnimState( 0, Stopped);
|
|
863 |
QTest::newRow("b50-350") << true << 3 << 50 << 350 << AnimState(100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
864 |
|
|
865 |
// infinite looping
|
|
866 |
QTest::newRow("inf1220") << false << -1 << 0 << 1220 << AnimState( 20, Running) << AnimState( 20, Running) << AnimState( 0, Stopped);
|
|
867 |
QTest::newRow("inf1310") << false << -1 << 0 << 1310 << AnimState( 100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
868 |
// infinite looping, direction = Backward (will only loop once)
|
|
869 |
QTest::newRow("b.inf120-120") << true << -1 << 120 << 120 << AnimState( 42, Stopped) << AnimState( 60, Running) << AnimState( 0, Stopped);
|
|
870 |
QTest::newRow("b.inf120-20") << true << -1 << 120 << 20 << AnimState( 20, Running) << AnimState( 20, Running) << AnimState( 0, Stopped);
|
|
871 |
QTest::newRow("b.inf120-110") << true << -1 << 120 << 110 << AnimState( 42, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
|
|
872 |
|
|
873 |
|
|
874 |
}
|
|
875 |
|
|
876 |
void tst_QParallelAnimationGroup::loopCount()
|
|
877 |
{
|
|
878 |
QFETCH(bool, directionBackward);
|
|
879 |
QFETCH(int, setLoopCount);
|
|
880 |
QFETCH(int, initialGroupTime);
|
|
881 |
QFETCH(int, currentGroupTime);
|
|
882 |
QFETCH(AnimState, expected1);
|
|
883 |
QFETCH(AnimState, expected2);
|
|
884 |
QFETCH(AnimState, expected3);
|
|
885 |
|
|
886 |
QParallelAnimationGroup group;
|
|
887 |
|
|
888 |
TestAnimation anim1;
|
|
889 |
anim1.setStartValue(0);
|
|
890 |
anim1.setEndValue(100);
|
|
891 |
anim1.setDuration(100);
|
|
892 |
|
|
893 |
TestAnimation anim2;
|
|
894 |
anim2.setStartValue(0);
|
|
895 |
anim2.setEndValue(100);
|
|
896 |
anim2.setDuration(60); //total 120
|
|
897 |
anim2.setLoopCount(2);
|
|
898 |
|
|
899 |
TestAnimation anim3;
|
|
900 |
anim3.setStartValue(0);
|
|
901 |
anim3.setEndValue(100);
|
|
902 |
anim3.setDuration(0);
|
|
903 |
|
|
904 |
group.addAnimation(&anim1);
|
|
905 |
group.addAnimation(&anim2);
|
|
906 |
group.addAnimation(&anim3);
|
|
907 |
|
|
908 |
group.setLoopCount(setLoopCount);
|
|
909 |
if (initialGroupTime >= 0)
|
|
910 |
group.setCurrentTime(initialGroupTime);
|
|
911 |
if (directionBackward)
|
|
912 |
group.setDirection(QAbstractAnimation::Backward);
|
|
913 |
|
|
914 |
group.start();
|
|
915 |
if (initialGroupTime >= 0)
|
|
916 |
group.setCurrentTime(initialGroupTime);
|
|
917 |
|
|
918 |
anim1.setCurrentTime(42); // 42 is "untouched"
|
|
919 |
anim2.setCurrentTime(42);
|
|
920 |
|
|
921 |
group.setCurrentTime(currentGroupTime);
|
|
922 |
|
|
923 |
QCOMPARE(anim1.currentTime(), expected1.time);
|
|
924 |
QCOMPARE(anim2.currentTime(), expected2.time);
|
|
925 |
QCOMPARE(anim3.currentTime(), expected3.time);
|
|
926 |
|
|
927 |
if (expected1.state >=0)
|
|
928 |
QCOMPARE(int(anim1.state()), expected1.state);
|
|
929 |
if (expected2.state >=0)
|
|
930 |
QCOMPARE(int(anim2.state()), expected2.state);
|
|
931 |
if (expected3.state >=0)
|
|
932 |
QCOMPARE(int(anim3.state()), expected3.state);
|
|
933 |
|
|
934 |
}
|
|
935 |
|
|
936 |
void tst_QParallelAnimationGroup::autoAdd()
|
|
937 |
{
|
|
938 |
QParallelAnimationGroup group;
|
|
939 |
QCOMPARE(group.duration(), 0);
|
|
940 |
TestAnimation2 *test = new TestAnimation2(250, &group); // 0, duration = 250;
|
|
941 |
QCOMPARE(test->group(), static_cast<QAnimationGroup*>(&group));
|
|
942 |
QCOMPARE(test->duration(), 250);
|
|
943 |
QCOMPARE(group.duration(), 250);
|
|
944 |
|
|
945 |
test = new TestAnimation2(750, &group); // 1
|
|
946 |
QCOMPARE(test->group(), static_cast<QAnimationGroup*>(&group));
|
|
947 |
QCOMPARE(group.duration(), 750);
|
|
948 |
test = new TestAnimation2(500, &group); // 2
|
|
949 |
QCOMPARE(test->group(), static_cast<QAnimationGroup*>(&group));
|
|
950 |
QCOMPARE(group.duration(), 750);
|
|
951 |
|
|
952 |
delete group.animationAt(1); // remove the one with duration = 750
|
|
953 |
QCOMPARE(group.duration(), 500);
|
|
954 |
|
|
955 |
delete group.animationAt(1); // remove the one with duration = 500
|
|
956 |
QCOMPARE(group.duration(), 250);
|
|
957 |
|
|
958 |
test = static_cast<TestAnimation2*>(group.animationAt(0));
|
|
959 |
test->setParent(0); // remove the last one (with duration = 250)
|
|
960 |
QCOMPARE(test->group(), static_cast<QAnimationGroup*>(0));
|
|
961 |
QCOMPARE(group.duration(), 0);
|
|
962 |
}
|
|
963 |
|
|
964 |
void tst_QParallelAnimationGroup::pauseResume()
|
|
965 |
{
|
|
966 |
QParallelAnimationGroup group;
|
|
967 |
TestAnimation2 *anim = new TestAnimation2(250, &group); // 0, duration = 250;
|
|
968 |
QSignalSpy spy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
|
|
969 |
QCOMPARE(group.duration(), 250);
|
|
970 |
group.start();
|
|
971 |
QTest::qWait(100);
|
|
972 |
QCOMPARE(group.state(), QAnimationGroup::Running);
|
|
973 |
QCOMPARE(anim->state(), QAnimationGroup::Running);
|
|
974 |
QCOMPARE(spy.count(), 1);
|
|
975 |
spy.clear();
|
|
976 |
const int currentTime = group.currentTime();
|
|
977 |
QCOMPARE(anim->currentTime(), currentTime);
|
|
978 |
|
|
979 |
group.pause();
|
|
980 |
QCOMPARE(group.state(), QAnimationGroup::Paused);
|
|
981 |
QCOMPARE(group.currentTime(), currentTime);
|
|
982 |
QCOMPARE(anim->state(), QAnimationGroup::Paused);
|
|
983 |
QCOMPARE(anim->currentTime(), currentTime);
|
|
984 |
QCOMPARE(spy.count(), 1);
|
|
985 |
spy.clear();
|
|
986 |
|
|
987 |
group.resume();
|
|
988 |
QCOMPARE(group.state(), QAnimationGroup::Running);
|
|
989 |
QCOMPARE(group.currentTime(), currentTime);
|
|
990 |
QCOMPARE(anim->state(), QAnimationGroup::Running);
|
|
991 |
QCOMPARE(anim->currentTime(), currentTime);
|
|
992 |
QCOMPARE(spy.count(), 1);
|
|
993 |
|
|
994 |
group.stop();
|
|
995 |
spy.clear();
|
|
996 |
new TestAnimation2(500, &group);
|
|
997 |
group.start();
|
|
998 |
QCOMPARE(spy.count(), 1); //the animation should have been started
|
|
999 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy.last().at(1)), TestAnimation::Running);
|
|
1000 |
group.setCurrentTime(250); //end of first animation
|
|
1001 |
QCOMPARE(spy.count(), 2); //the animation should have been stopped
|
|
1002 |
QCOMPARE(qVariantValue<QAbstractAnimation::State>(spy.last().at(1)), TestAnimation::Stopped);
|
|
1003 |
group.pause();
|
|
1004 |
QCOMPARE(spy.count(), 2); //this shouldn't have changed
|
|
1005 |
group.resume();
|
|
1006 |
QCOMPARE(spy.count(), 2); //this shouldn't have changed
|
|
1007 |
|
|
1008 |
|
|
1009 |
|
|
1010 |
}
|
|
1011 |
|
|
1012 |
|
|
1013 |
QTEST_MAIN(tst_QParallelAnimationGroup)
|
|
1014 |
#include "tst_qparallelanimationgroup.moc"
|