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/qpauseanimation.h>
|
|
45 |
#include <QtCore/qpropertyanimation.h>
|
|
46 |
#include <QtCore/qsequentialanimationgroup.h>
|
|
47 |
|
|
48 |
#include <private/qabstractanimation_p.h>
|
|
49 |
|
|
50 |
//TESTED_CLASS=QPauseAnimation
|
|
51 |
//TESTED_FILES=
|
|
52 |
|
|
53 |
class TestablePauseAnimation : public QPauseAnimation
|
|
54 |
{
|
|
55 |
Q_OBJECT
|
|
56 |
public:
|
|
57 |
TestablePauseAnimation(QObject *parent = 0)
|
|
58 |
: QPauseAnimation(parent),
|
|
59 |
m_updateCurrentTimeCount(0)
|
|
60 |
{
|
|
61 |
}
|
|
62 |
|
|
63 |
int m_updateCurrentTimeCount;
|
|
64 |
protected:
|
|
65 |
void updateCurrentTime(int currentTime)
|
|
66 |
{
|
|
67 |
//qDebug() << this << "update current time: " << currentTime;
|
|
68 |
QPauseAnimation::updateCurrentTime(currentTime);
|
|
69 |
++m_updateCurrentTimeCount;
|
|
70 |
}
|
|
71 |
};
|
|
72 |
|
|
73 |
class EnableConsistentTiming
|
|
74 |
{
|
|
75 |
public:
|
|
76 |
EnableConsistentTiming()
|
|
77 |
{
|
|
78 |
QUnifiedTimer *timer = QUnifiedTimer::instance();
|
|
79 |
timer->setConsistentTiming(true);
|
|
80 |
}
|
|
81 |
~EnableConsistentTiming()
|
|
82 |
{
|
|
83 |
QUnifiedTimer *timer = QUnifiedTimer::instance();
|
|
84 |
timer->setConsistentTiming(false);
|
|
85 |
}
|
|
86 |
};
|
|
87 |
|
|
88 |
class tst_QPauseAnimation : public QObject
|
|
89 |
{
|
|
90 |
Q_OBJECT
|
|
91 |
public:
|
|
92 |
tst_QPauseAnimation();
|
|
93 |
virtual ~tst_QPauseAnimation();
|
|
94 |
|
|
95 |
public Q_SLOTS:
|
|
96 |
void init();
|
|
97 |
void cleanup();
|
|
98 |
|
|
99 |
private slots:
|
|
100 |
void changeDirectionWhileRunning();
|
|
101 |
void noTimerUpdates_data();
|
|
102 |
void noTimerUpdates();
|
|
103 |
void mulitplePauseAnimations();
|
|
104 |
void pauseAndPropertyAnimations();
|
|
105 |
void pauseResume();
|
|
106 |
void sequentialPauseGroup();
|
|
107 |
void sequentialGroupWithPause();
|
|
108 |
void multipleSequentialGroups();
|
|
109 |
void zeroDuration();
|
|
110 |
};
|
|
111 |
|
|
112 |
tst_QPauseAnimation::tst_QPauseAnimation()
|
|
113 |
{
|
|
114 |
}
|
|
115 |
|
|
116 |
tst_QPauseAnimation::~tst_QPauseAnimation()
|
|
117 |
{
|
|
118 |
}
|
|
119 |
|
|
120 |
void tst_QPauseAnimation::init()
|
|
121 |
{
|
|
122 |
qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State");
|
|
123 |
qRegisterMetaType<QAbstractAnimation::DeletionPolicy>("QAbstractAnimation::DeletionPolicy");
|
|
124 |
}
|
|
125 |
|
|
126 |
void tst_QPauseAnimation::cleanup()
|
|
127 |
{
|
|
128 |
}
|
|
129 |
|
|
130 |
void tst_QPauseAnimation::changeDirectionWhileRunning()
|
|
131 |
{
|
|
132 |
QUnifiedTimer *timer = QUnifiedTimer::instance();
|
|
133 |
timer->setConsistentTiming(true);
|
|
134 |
|
|
135 |
TestablePauseAnimation animation;
|
|
136 |
animation.setDuration(400);
|
|
137 |
animation.start();
|
|
138 |
QTest::qWait(100);
|
|
139 |
QVERIFY(animation.state() == QAbstractAnimation::Running);
|
|
140 |
animation.setDirection(QAbstractAnimation::Backward);
|
|
141 |
QTest::qWait(animation.totalDuration() + 50);
|
|
142 |
QVERIFY(animation.state() == QAbstractAnimation::Stopped);
|
|
143 |
|
|
144 |
timer->setConsistentTiming(false);
|
|
145 |
}
|
|
146 |
|
|
147 |
void tst_QPauseAnimation::noTimerUpdates_data()
|
|
148 |
{
|
|
149 |
QTest::addColumn<int>("duration");
|
|
150 |
QTest::addColumn<int>("loopCount");
|
|
151 |
|
|
152 |
QTest::newRow("0") << 200 << 1;
|
|
153 |
QTest::newRow("1") << 160 << 1;
|
|
154 |
QTest::newRow("2") << 160 << 2;
|
|
155 |
QTest::newRow("3") << 200 << 3;
|
|
156 |
}
|
|
157 |
|
|
158 |
void tst_QPauseAnimation::noTimerUpdates()
|
|
159 |
{
|
|
160 |
QUnifiedTimer *timer = QUnifiedTimer::instance();
|
|
161 |
timer->setConsistentTiming(true);
|
|
162 |
|
|
163 |
QFETCH(int, duration);
|
|
164 |
QFETCH(int, loopCount);
|
|
165 |
|
|
166 |
TestablePauseAnimation animation;
|
|
167 |
animation.setDuration(duration);
|
|
168 |
animation.setLoopCount(loopCount);
|
|
169 |
animation.start();
|
|
170 |
QTest::qWait(animation.totalDuration() + 100);
|
|
171 |
QVERIFY(animation.state() == QAbstractAnimation::Stopped);
|
|
172 |
QCOMPARE(animation.m_updateCurrentTimeCount, 1 + loopCount);
|
|
173 |
|
|
174 |
timer->setConsistentTiming(false);
|
|
175 |
}
|
|
176 |
|
|
177 |
void tst_QPauseAnimation::mulitplePauseAnimations()
|
|
178 |
{
|
|
179 |
QUnifiedTimer *timer = QUnifiedTimer::instance();
|
|
180 |
timer->setConsistentTiming(true);
|
|
181 |
|
|
182 |
TestablePauseAnimation animation;
|
|
183 |
animation.setDuration(200);
|
|
184 |
|
|
185 |
TestablePauseAnimation animation2;
|
|
186 |
animation2.setDuration(800);
|
|
187 |
|
|
188 |
animation.start();
|
|
189 |
animation2.start();
|
|
190 |
QTest::qWait(animation.totalDuration() + 100);
|
|
191 |
QVERIFY(animation.state() == QAbstractAnimation::Stopped);
|
|
192 |
QVERIFY(animation2.state() == QAbstractAnimation::Running);
|
|
193 |
QCOMPARE(animation.m_updateCurrentTimeCount, 2);
|
|
194 |
QCOMPARE(animation2.m_updateCurrentTimeCount, 2);
|
|
195 |
|
|
196 |
QTest::qWait(550);
|
|
197 |
QVERIFY(animation2.state() == QAbstractAnimation::Stopped);
|
|
198 |
QCOMPARE(animation2.m_updateCurrentTimeCount, 3);
|
|
199 |
|
|
200 |
timer->setConsistentTiming(false);
|
|
201 |
}
|
|
202 |
|
|
203 |
void tst_QPauseAnimation::pauseAndPropertyAnimations()
|
|
204 |
{
|
|
205 |
EnableConsistentTiming enabled;
|
|
206 |
|
|
207 |
TestablePauseAnimation pause;
|
|
208 |
pause.setDuration(200);
|
|
209 |
|
|
210 |
QObject o;
|
|
211 |
o.setProperty("ole", 42);
|
|
212 |
|
|
213 |
QPropertyAnimation animation(&o, "ole");
|
|
214 |
animation.setEndValue(43);
|
|
215 |
|
|
216 |
pause.start();
|
|
217 |
|
|
218 |
QTest::qWait(100);
|
|
219 |
animation.start();
|
|
220 |
|
|
221 |
QVERIFY(animation.state() == QAbstractAnimation::Running);
|
|
222 |
QVERIFY(pause.state() == QAbstractAnimation::Running);
|
|
223 |
QCOMPARE(pause.m_updateCurrentTimeCount, 2);
|
|
224 |
|
|
225 |
QTest::qWait(animation.totalDuration() + 100);
|
|
226 |
|
|
227 |
#ifdef Q_OS_WIN
|
|
228 |
if (animation.state() != QAbstractAnimation::Stopped)
|
|
229 |
QEXPECT_FAIL("", "On windows, consistent timing is not working properly due to bad timer resolution", Abort);
|
|
230 |
#endif
|
|
231 |
QVERIFY(animation.state() == QAbstractAnimation::Stopped);
|
|
232 |
QVERIFY(pause.state() == QAbstractAnimation::Stopped);
|
|
233 |
QVERIFY(pause.m_updateCurrentTimeCount > 3);
|
|
234 |
}
|
|
235 |
|
|
236 |
void tst_QPauseAnimation::pauseResume()
|
|
237 |
{
|
|
238 |
TestablePauseAnimation animation;
|
|
239 |
animation.setDuration(400);
|
|
240 |
animation.start();
|
|
241 |
QVERIFY(animation.state() == QAbstractAnimation::Running);
|
|
242 |
QTest::qWait(200);
|
|
243 |
animation.pause();
|
|
244 |
QVERIFY(animation.state() == QAbstractAnimation::Paused);
|
|
245 |
animation.start();
|
|
246 |
QTest::qWait(250);
|
|
247 |
QVERIFY(animation.state() == QAbstractAnimation::Stopped);
|
|
248 |
QCOMPARE(animation.m_updateCurrentTimeCount, 3);
|
|
249 |
}
|
|
250 |
|
|
251 |
void tst_QPauseAnimation::sequentialPauseGroup()
|
|
252 |
{
|
|
253 |
QSequentialAnimationGroup group;
|
|
254 |
|
|
255 |
TestablePauseAnimation animation1(&group);
|
|
256 |
animation1.setDuration(200);
|
|
257 |
TestablePauseAnimation animation2(&group);
|
|
258 |
animation2.setDuration(200);
|
|
259 |
TestablePauseAnimation animation3(&group);
|
|
260 |
animation3.setDuration(200);
|
|
261 |
|
|
262 |
group.start();
|
|
263 |
|
|
264 |
QVERIFY(group.state() == QAbstractAnimation::Running);
|
|
265 |
QVERIFY(animation1.state() == QAbstractAnimation::Running);
|
|
266 |
QVERIFY(animation2.state() == QAbstractAnimation::Stopped);
|
|
267 |
QVERIFY(animation3.state() == QAbstractAnimation::Stopped);
|
|
268 |
|
|
269 |
group.setCurrentTime(250);
|
|
270 |
|
|
271 |
QVERIFY(group.state() == QAbstractAnimation::Running);
|
|
272 |
QVERIFY(animation1.state() == QAbstractAnimation::Stopped);
|
|
273 |
QCOMPARE(&animation2, group.currentAnimation());
|
|
274 |
QVERIFY(animation2.state() == QAbstractAnimation::Running);
|
|
275 |
QVERIFY(animation3.state() == QAbstractAnimation::Stopped);
|
|
276 |
|
|
277 |
group.setCurrentTime(500);
|
|
278 |
|
|
279 |
QVERIFY(group.state() == QAbstractAnimation::Running);
|
|
280 |
QVERIFY(animation1.state() == QAbstractAnimation::Stopped);
|
|
281 |
QVERIFY(animation2.state() == QAbstractAnimation::Stopped);
|
|
282 |
QCOMPARE(&animation3, group.currentAnimation());
|
|
283 |
QVERIFY(animation3.state() == QAbstractAnimation::Running);
|
|
284 |
|
|
285 |
group.setCurrentTime(750);
|
|
286 |
|
|
287 |
QVERIFY(group.state() == QAbstractAnimation::Stopped);
|
|
288 |
QVERIFY(animation1.state() == QAbstractAnimation::Stopped);
|
|
289 |
QVERIFY(animation2.state() == QAbstractAnimation::Stopped);
|
|
290 |
QVERIFY(animation3.state() == QAbstractAnimation::Stopped);
|
|
291 |
|
|
292 |
QCOMPARE(animation1.m_updateCurrentTimeCount, 2);
|
|
293 |
QCOMPARE(animation2.m_updateCurrentTimeCount, 2);
|
|
294 |
QCOMPARE(animation3.m_updateCurrentTimeCount, 2);
|
|
295 |
}
|
|
296 |
|
|
297 |
void tst_QPauseAnimation::sequentialGroupWithPause()
|
|
298 |
{
|
|
299 |
QSequentialAnimationGroup group;
|
|
300 |
|
|
301 |
QObject o;
|
|
302 |
o.setProperty("ole", 42);
|
|
303 |
|
|
304 |
QPropertyAnimation animation(&o, "ole", &group);
|
|
305 |
animation.setEndValue(43);
|
|
306 |
TestablePauseAnimation pause(&group);
|
|
307 |
pause.setDuration(250);
|
|
308 |
|
|
309 |
group.start();
|
|
310 |
|
|
311 |
QVERIFY(group.state() == QAbstractAnimation::Running);
|
|
312 |
QVERIFY(animation.state() == QAbstractAnimation::Running);
|
|
313 |
QVERIFY(pause.state() == QAbstractAnimation::Stopped);
|
|
314 |
|
|
315 |
group.setCurrentTime(300);
|
|
316 |
|
|
317 |
QVERIFY(group.state() == QAbstractAnimation::Running);
|
|
318 |
QVERIFY(animation.state() == QAbstractAnimation::Stopped);
|
|
319 |
QCOMPARE(&pause, group.currentAnimation());
|
|
320 |
QVERIFY(pause.state() == QAbstractAnimation::Running);
|
|
321 |
|
|
322 |
group.setCurrentTime(600);
|
|
323 |
|
|
324 |
QVERIFY(group.state() == QAbstractAnimation::Stopped);
|
|
325 |
QVERIFY(animation.state() == QAbstractAnimation::Stopped);
|
|
326 |
QVERIFY(pause.state() == QAbstractAnimation::Stopped);
|
|
327 |
|
|
328 |
QCOMPARE(pause.m_updateCurrentTimeCount, 2);
|
|
329 |
}
|
|
330 |
|
|
331 |
void tst_QPauseAnimation::multipleSequentialGroups()
|
|
332 |
{
|
|
333 |
EnableConsistentTiming enabled;
|
|
334 |
|
|
335 |
QParallelAnimationGroup group;
|
|
336 |
group.setLoopCount(2);
|
|
337 |
|
|
338 |
QSequentialAnimationGroup subgroup1(&group);
|
|
339 |
|
|
340 |
QObject o;
|
|
341 |
o.setProperty("ole", 42);
|
|
342 |
|
|
343 |
QPropertyAnimation animation(&o, "ole", &subgroup1);
|
|
344 |
animation.setEndValue(43);
|
|
345 |
animation.setDuration(300);
|
|
346 |
TestablePauseAnimation pause(&subgroup1);
|
|
347 |
pause.setDuration(200);
|
|
348 |
|
|
349 |
QSequentialAnimationGroup subgroup2(&group);
|
|
350 |
|
|
351 |
o.setProperty("ole2", 42);
|
|
352 |
QPropertyAnimation animation2(&o, "ole2", &subgroup2);
|
|
353 |
animation2.setEndValue(43);
|
|
354 |
animation2.setDuration(200);
|
|
355 |
TestablePauseAnimation pause2(&subgroup2);
|
|
356 |
pause2.setDuration(250);
|
|
357 |
|
|
358 |
QSequentialAnimationGroup subgroup3(&group);
|
|
359 |
|
|
360 |
TestablePauseAnimation pause3(&subgroup3);
|
|
361 |
pause3.setDuration(400);
|
|
362 |
|
|
363 |
o.setProperty("ole3", 42);
|
|
364 |
QPropertyAnimation animation3(&o, "ole3", &subgroup3);
|
|
365 |
animation3.setEndValue(43);
|
|
366 |
animation3.setDuration(200);
|
|
367 |
|
|
368 |
QSequentialAnimationGroup subgroup4(&group);
|
|
369 |
|
|
370 |
TestablePauseAnimation pause4(&subgroup4);
|
|
371 |
pause4.setDuration(310);
|
|
372 |
|
|
373 |
TestablePauseAnimation pause5(&subgroup4);
|
|
374 |
pause5.setDuration(60);
|
|
375 |
|
|
376 |
group.start();
|
|
377 |
|
|
378 |
QVERIFY(group.state() == QAbstractAnimation::Running);
|
|
379 |
QVERIFY(subgroup1.state() == QAbstractAnimation::Running);
|
|
380 |
QVERIFY(subgroup2.state() == QAbstractAnimation::Running);
|
|
381 |
QVERIFY(subgroup3.state() == QAbstractAnimation::Running);
|
|
382 |
QVERIFY(subgroup4.state() == QAbstractAnimation::Running);
|
|
383 |
|
|
384 |
QTest::qWait(group.totalDuration() + 100);
|
|
385 |
|
|
386 |
#ifdef Q_OS_WIN
|
|
387 |
if (group.state() != QAbstractAnimation::Stopped)
|
|
388 |
QEXPECT_FAIL("", "On windows, consistent timing is not working properly due to bad timer resolution", Abort);
|
|
389 |
#endif
|
|
390 |
QVERIFY(group.state() == QAbstractAnimation::Stopped);
|
|
391 |
QVERIFY(subgroup1.state() == QAbstractAnimation::Stopped);
|
|
392 |
QVERIFY(subgroup2.state() == QAbstractAnimation::Stopped);
|
|
393 |
QVERIFY(subgroup3.state() == QAbstractAnimation::Stopped);
|
|
394 |
QVERIFY(subgroup4.state() == QAbstractAnimation::Stopped);
|
|
395 |
|
|
396 |
QCOMPARE(pause5.m_updateCurrentTimeCount, 4);
|
|
397 |
}
|
|
398 |
|
|
399 |
void tst_QPauseAnimation::zeroDuration()
|
|
400 |
{
|
|
401 |
TestablePauseAnimation animation;
|
|
402 |
animation.setDuration(0);
|
|
403 |
animation.start();
|
|
404 |
QTest::qWait(animation.totalDuration() + 100);
|
|
405 |
QVERIFY(animation.state() == QAbstractAnimation::Stopped);
|
|
406 |
QCOMPARE(animation.m_updateCurrentTimeCount, 1);
|
|
407 |
}
|
|
408 |
|
|
409 |
QTEST_MAIN(tst_QPauseAnimation)
|
|
410 |
#include "tst_qpauseanimation.moc"
|