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