author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
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 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
||
45 |
#include <qtimeline.h> |
|
46 |
||
47 |
//TESTED_CLASS= |
|
48 |
//TESTED_FILES= |
|
49 |
||
50 |
class tst_QTimeLine : public QObject { |
|
51 |
Q_OBJECT |
|
52 |
||
53 |
public: |
|
54 |
tst_QTimeLine(); |
|
55 |
virtual ~tst_QTimeLine(); |
|
56 |
||
57 |
public Q_SLOTS: |
|
58 |
void init(); |
|
59 |
void cleanup(); |
|
60 |
||
61 |
private slots: |
|
62 |
void range(); |
|
63 |
void currentTime(); |
|
64 |
void duration(); |
|
65 |
void frameRate(); |
|
66 |
void value(); |
|
67 |
void currentFrame(); |
|
68 |
void loopCount(); |
|
69 |
void interpolation(); |
|
70 |
void reverse_data(); |
|
71 |
void reverse(); |
|
72 |
//void toggle(); |
|
73 |
//void reset(); ### todo |
|
74 |
void frameChanged(); |
|
75 |
void stopped(); |
|
76 |
void finished(); |
|
77 |
void isRunning(); |
|
78 |
void multipleTimeLines(); |
|
79 |
void sineCurve(); |
|
80 |
void cosineCurve(); |
|
81 |
void outOfRange(); |
|
82 |
void stateInFinishedSignal(); |
|
83 |
void resume(); |
|
84 |
void restart(); |
|
85 |
||
86 |
protected slots: |
|
87 |
void finishedSlot(); |
|
88 |
||
89 |
protected: |
|
90 |
QTimeLine::State state; |
|
91 |
QTimeLine * view; |
|
92 |
}; |
|
93 |
||
94 |
tst_QTimeLine::tst_QTimeLine() |
|
95 |
{ |
|
96 |
} |
|
97 |
||
98 |
tst_QTimeLine::~tst_QTimeLine() |
|
99 |
{ |
|
100 |
} |
|
101 |
||
102 |
void tst_QTimeLine::init() |
|
103 |
{ |
|
104 |
} |
|
105 |
||
106 |
void tst_QTimeLine::cleanup() |
|
107 |
{ |
|
108 |
} |
|
109 |
#include <qdebug.h> |
|
110 |
||
111 |
void tst_QTimeLine::range() |
|
112 |
{ |
|
113 |
#ifdef Q_OS_WINCE //On WinCE timer resolution is bad - using longer times instead |
|
114 |
QTimeLine timeLine(2000); |
|
115 |
#else |
|
116 |
QTimeLine timeLine(200); |
|
117 |
#endif |
|
118 |
QCOMPARE(timeLine.startFrame(), 0); |
|
119 |
QCOMPARE(timeLine.endFrame(), 0); |
|
120 |
timeLine.setFrameRange(0, 1); |
|
121 |
QCOMPARE(timeLine.startFrame(), 0); |
|
122 |
QCOMPARE(timeLine.endFrame(), 1); |
|
123 |
timeLine.setFrameRange(10, 20); |
|
124 |
QCOMPARE(timeLine.startFrame(), 10); |
|
125 |
QCOMPARE(timeLine.endFrame(), 20); |
|
126 |
||
127 |
timeLine.setStartFrame(6); |
|
128 |
QCOMPARE(timeLine.startFrame(), 6); |
|
129 |
timeLine.setEndFrame(16); |
|
130 |
QCOMPARE(timeLine.endFrame(), 16); |
|
131 |
||
132 |
// Verify that you can change the range in the timeLine |
|
133 |
timeLine.setFrameRange(10, 20); |
|
134 |
QSignalSpy spy(&timeLine, SIGNAL(frameChanged(int))); |
|
135 |
timeLine.start(); |
|
136 |
#ifdef Q_OS_WINCE |
|
137 |
QTest::qWait(1000); |
|
138 |
#else |
|
139 |
QTest::qWait(100); |
|
140 |
#endif |
|
141 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
142 |
int oldValue = timeLine.currentFrame(); |
|
143 |
timeLine.setFrameRange(0, 5); |
|
144 |
QVERIFY(timeLine.currentFrame() < oldValue); |
|
145 |
timeLine.setEndFrame(100); |
|
146 |
timeLine.setStartFrame(50); |
|
147 |
QVERIFY(timeLine.currentFrame() > oldValue); |
|
148 |
timeLine.setFrameRange(0, 5); |
|
149 |
#ifdef Q_OS_WINCE |
|
150 |
QTest::qWait(500); |
|
151 |
#else |
|
152 |
QTest::qWait(50); |
|
153 |
#endif |
|
154 |
QVERIFY(spy.count() > 1); |
|
155 |
QVERIFY(timeLine.currentFrame() < oldValue); |
|
156 |
} |
|
157 |
||
158 |
void tst_QTimeLine::currentTime() |
|
159 |
{ |
|
160 |
QTimeLine timeLine(2000); |
|
161 |
timeLine.setUpdateInterval((timeLine.duration()/2) / 33); |
|
162 |
qRegisterMetaType<qreal>("qreal"); |
|
163 |
QSignalSpy spy(&timeLine, SIGNAL(valueChanged(qreal))); |
|
164 |
timeLine.setFrameRange(10, 20); |
|
165 |
QCOMPARE(timeLine.currentTime(), 0); |
|
166 |
timeLine.start(); |
|
167 |
QTest::qWait(timeLine.duration()/2); |
|
168 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
169 |
QVERIFY(timeLine.currentTime() > timeLine.duration()/2 - timeLine.duration()/10); |
|
170 |
QVERIFY(timeLine.currentTime() < timeLine.duration()/2 + timeLine.duration()/10); |
|
171 |
QTest::qWait(timeLine.duration()/4 + timeLine.duration()); |
|
172 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
173 |
QCOMPARE(timeLine.currentTime(), timeLine.duration()); |
|
174 |
||
175 |
spy.clear(); |
|
176 |
timeLine.setCurrentTime(timeLine.duration()/2); |
|
177 |
timeLine.setCurrentTime(timeLine.duration()/2); |
|
178 |
QCOMPARE(spy.count(), 1); |
|
179 |
spy.clear(); |
|
180 |
QCOMPARE(timeLine.currentTime(), timeLine.duration()/2); |
|
181 |
timeLine.resume(); |
|
182 |
// Let it update on its own |
|
183 |
QTest::qWait(timeLine.duration()/4); |
|
184 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
185 |
QVERIFY(timeLine.currentTime() > timeLine.duration()/2); |
|
186 |
QVERIFY(timeLine.currentTime() < timeLine.duration()); |
|
187 |
QTest::qWait(timeLine.duration()/4 + timeLine.duration()); |
|
188 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
189 |
QVERIFY(timeLine.currentTime() == timeLine.duration()); |
|
190 |
||
191 |
// Reverse should decrease the currentTime |
|
192 |
timeLine.setCurrentTime(timeLine.duration()/2); |
|
193 |
timeLine.start(); |
|
194 |
// Let it update on its own |
|
195 |
QTest::qWait(timeLine.duration()/4); |
|
196 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
197 |
int currentTime = timeLine.currentTime(); |
|
198 |
timeLine.setDirection(QTimeLine::Backward); |
|
199 |
QTest::qWait(timeLine.duration()/4); |
|
200 |
QVERIFY(timeLine.currentTime() < currentTime); |
|
201 |
timeLine.stop(); |
|
202 |
} |
|
203 |
||
204 |
void tst_QTimeLine::duration() |
|
205 |
{ |
|
206 |
QTimeLine timeLine(200); |
|
207 |
timeLine.setFrameRange(10, 20); |
|
208 |
QCOMPARE(timeLine.duration(), 200); |
|
209 |
timeLine.setDuration(1000); |
|
210 |
QCOMPARE(timeLine.duration(), 1000); |
|
211 |
||
212 |
timeLine.start(); |
|
213 |
QTest::qWait(999); |
|
214 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
215 |
QVERIFY(timeLine.currentTime() > 0.9); |
|
216 |
QTest::qWait(50); |
|
217 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
218 |
// The duration shouldn't change |
|
219 |
QCOMPARE(timeLine.duration(), 1000); |
|
220 |
} |
|
221 |
||
222 |
void tst_QTimeLine::frameRate() |
|
223 |
{ |
|
224 |
QTimeLine timeLine; |
|
225 |
timeLine.setFrameRange(10, 20); |
|
226 |
QCOMPARE(timeLine.updateInterval(), 1000 / 25); |
|
227 |
timeLine.setUpdateInterval(1000 / 60); |
|
228 |
QCOMPARE(timeLine.updateInterval(), 1000 / 60); |
|
229 |
||
230 |
// Default speed |
|
231 |
timeLine.setUpdateInterval(1000 / 33); |
|
232 |
QSignalSpy spy(&timeLine, SIGNAL(frameChanged(int))); |
|
233 |
timeLine.start(); |
|
234 |
QTest::qWait(timeLine.duration()*2); |
|
235 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
236 |
int slowCount = spy.count(); |
|
237 |
||
238 |
// Faster!! |
|
239 |
timeLine.setUpdateInterval(1000 / 100); |
|
240 |
spy.clear(); |
|
241 |
timeLine.setCurrentTime(0); |
|
242 |
timeLine.start(); |
|
243 |
QTest::qWait(timeLine.duration()*2); |
|
244 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
245 |
QVERIFY(slowCount < spy.count()); |
|
246 |
} |
|
247 |
||
248 |
void tst_QTimeLine::value() |
|
249 |
{ |
|
250 |
#ifdef Q_OS_WINCE //On WinCE timer resolution is bad - use longer times |
|
251 |
QTimeLine timeLine(2000); |
|
252 |
#else |
|
253 |
QTimeLine timeLine(200); |
|
254 |
#endif |
|
255 |
QVERIFY(timeLine.currentValue() == 0.0); |
|
256 |
||
257 |
// Default speed |
|
258 |
qRegisterMetaType<qreal>("qreal"); |
|
259 |
QSignalSpy spy(&timeLine, SIGNAL(valueChanged(qreal))); |
|
260 |
timeLine.start(); |
|
261 |
QTest::qWait(timeLine.duration()/3); |
|
262 |
QVERIFY(timeLine.currentValue() > 0); |
|
263 |
QTest::qWait(timeLine.duration()); |
|
264 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
265 |
qreal currentValue = timeLine.currentValue(); |
|
266 |
QVERIFY(currentValue == 1); |
|
267 |
QVERIFY(spy.count() > 0); |
|
268 |
||
269 |
// Reverse should decrease the value |
|
270 |
timeLine.setCurrentTime(100); |
|
271 |
timeLine.start(); |
|
272 |
// Let it update on its own |
|
273 |
#ifdef Q_OS_WINCE |
|
274 |
QTest::qWait(500); |
|
275 |
#else |
|
276 |
QTest::qWait(50); |
|
277 |
#endif |
|
278 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
279 |
qreal value = timeLine.currentValue(); |
|
280 |
timeLine.setDirection(QTimeLine::Backward); |
|
281 |
#ifdef Q_OS_WINCE |
|
282 |
QTest::qWait(1000); |
|
283 |
#else |
|
284 |
QTest::qWait(100); |
|
285 |
#endif |
|
286 |
QVERIFY(timeLine.currentValue() < value); |
|
287 |
timeLine.stop(); |
|
288 |
} |
|
289 |
||
290 |
void tst_QTimeLine::currentFrame() |
|
291 |
{ |
|
292 |
QTimeLine timeLine(2000); |
|
293 |
timeLine.setFrameRange(10, 20); |
|
294 |
QCOMPARE(timeLine.currentFrame(), 10); |
|
295 |
||
296 |
// Default speed |
|
297 |
QSignalSpy spy(&timeLine, SIGNAL(frameChanged(int))); |
|
298 |
timeLine.start(); |
|
299 |
QTest::qWait(timeLine.duration()/3); |
|
300 |
QVERIFY(timeLine.currentFrame() > 10); |
|
301 |
QTest::qWait(timeLine.duration()); |
|
302 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
303 |
QCOMPARE(timeLine.currentFrame(), 20); |
|
304 |
||
305 |
// Reverse should decrease the value |
|
306 |
timeLine.setCurrentTime(timeLine.duration()/2); |
|
307 |
timeLine.start(); |
|
308 |
// Let it update on its own |
|
309 |
QTest::qWait(timeLine.duration()/4); |
|
310 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
311 |
int value = timeLine.currentFrame(); |
|
312 |
timeLine.setDirection(QTimeLine::Backward); |
|
313 |
QTest::qWait(timeLine.duration()/2); |
|
314 |
QVERIFY(timeLine.currentFrame() < value); |
|
315 |
timeLine.stop(); |
|
316 |
} |
|
317 |
||
318 |
void tst_QTimeLine::loopCount() |
|
319 |
{ |
|
320 |
QTimeLine timeLine(200); |
|
321 |
QCOMPARE(timeLine.loopCount(), 1); |
|
322 |
timeLine.setFrameRange(10, 20); |
|
323 |
QCOMPARE(timeLine.loopCount(), 1); |
|
324 |
timeLine.setLoopCount(0); |
|
325 |
QCOMPARE(timeLine.loopCount(), 0); |
|
326 |
||
327 |
// Default speed infiniti looping |
|
328 |
QSignalSpy spy(&timeLine, SIGNAL(frameChanged(int))); |
|
329 |
timeLine.start(); |
|
330 |
QTest::qWait(timeLine.duration()); |
|
331 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
332 |
//QCOMPARE(timeLine.currentFrame(), 20); |
|
333 |
QTest::qWait(timeLine.duration()*6); |
|
334 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
335 |
QVERIFY(timeLine.currentTime() >= 0); |
|
336 |
QVERIFY(timeLine.currentFrame() >= 10); |
|
337 |
QVERIFY(timeLine.currentFrame() <= 20); |
|
338 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
339 |
timeLine.stop(); |
|
340 |
||
341 |
timeLine.setDuration(2500); // ### some platforms have a very low resolution timer |
|
342 |
timeLine.setFrameRange(0, 2); |
|
343 |
timeLine.setLoopCount(4); |
|
344 |
||
345 |
QSignalSpy finishedSpy(&timeLine, SIGNAL(finished())); |
|
346 |
QSignalSpy frameChangedSpy(&timeLine, SIGNAL(frameChanged(int))); |
|
347 |
QEventLoop loop; |
|
348 |
connect(&timeLine, SIGNAL(finished()), &loop, SLOT(quit())); |
|
349 |
||
350 |
||
351 |
for(int i=0;i<2;i++) { |
|
352 |
||
353 |
timeLine.start(); |
|
354 |
//we clear te list after the start so we don't catch |
|
355 |
//a frameChanged signal for the frame 0 at the beginning |
|
356 |
finishedSpy.clear(); |
|
357 |
frameChangedSpy.clear(); |
|
358 |
||
359 |
loop.exec(); |
|
360 |
||
361 |
QCOMPARE(finishedSpy.count(), 1); |
|
362 |
QCOMPARE(frameChangedSpy.count(), 11); |
|
363 |
for (int i = 0; i < 11; ++i) { |
|
364 |
QCOMPARE(frameChangedSpy.at(i).at(0).toInt(), (i+1) % 3); |
|
365 |
} |
|
366 |
} |
|
367 |
||
368 |
timeLine.setDirection(QTimeLine::Backward); |
|
369 |
timeLine.start(); |
|
370 |
loop.exec(); |
|
371 |
||
372 |
QCOMPARE(finishedSpy.count(), 2); |
|
373 |
QCOMPARE(frameChangedSpy.count(), 22); |
|
374 |
for (int i = 11; i < 22; ++i) { |
|
375 |
QCOMPARE(frameChangedSpy.at(i).at(0).toInt(), 2 - (i+2) % 3); |
|
376 |
} |
|
377 |
} |
|
378 |
||
379 |
void tst_QTimeLine::interpolation() |
|
380 |
{ |
|
381 |
QTimeLine timeLine(400); |
|
382 |
QCOMPARE(timeLine.curveShape(), QTimeLine::EaseInOutCurve); |
|
383 |
timeLine.setFrameRange(100, 200); |
|
384 |
timeLine.setCurveShape(QTimeLine::LinearCurve); |
|
385 |
QCOMPARE(timeLine.curveShape(), QTimeLine::LinearCurve); |
|
386 |
||
387 |
// smooth |
|
388 |
timeLine.setCurveShape(QTimeLine::EaseInOutCurve); |
|
389 |
timeLine.start(); |
|
390 |
QTest::qWait(100); |
|
391 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
392 |
int firstValue = timeLine.currentFrame(); |
|
393 |
QTest::qWait(200); |
|
394 |
int endValue = timeLine.currentFrame(); |
|
395 |
timeLine.stop(); // ### todo reset? |
|
396 |
timeLine.setCurrentTime(0); // ### todo reset? |
|
397 |
||
398 |
// linear |
|
399 |
timeLine.setCurveShape(QTimeLine::LinearCurve); |
|
400 |
timeLine.start(); |
|
401 |
QTest::qWait(100); |
|
402 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
403 |
||
404 |
// Smooth accellerates slowly so in the beginning so it is farther behind |
|
405 |
QVERIFY(firstValue < timeLine.currentFrame()); |
|
406 |
QTest::qWait(200); |
|
407 |
QVERIFY(endValue > timeLine.currentFrame()); |
|
408 |
timeLine.stop(); |
|
409 |
} |
|
410 |
||
411 |
void tst_QTimeLine::reverse_data() |
|
412 |
{ |
|
413 |
QTest::addColumn<int>("duration"); |
|
414 |
QTest::addColumn<int>("start"); |
|
415 |
QTest::addColumn<int>("end"); |
|
416 |
QTest::addColumn<int>("direction"); |
|
417 |
QTest::addColumn<int>("direction2"); |
|
418 |
QTest::addColumn<int>("direction3"); |
|
419 |
QTest::addColumn<int>("startTime"); |
|
420 |
QTest::addColumn<int>("currentFrame"); |
|
421 |
QTest::addColumn<qreal>("currentValue"); |
|
422 |
QTest::addColumn<int>("wait"); |
|
423 |
QTest::addColumn<int>("state"); |
|
424 |
QTest::addColumn<int>("wait2"); |
|
425 |
||
426 |
QTest::newRow("start at end") << 200 << 1000 << 2000 << (int)QTimeLine::Backward << (int)QTimeLine::Forward << (int)QTimeLine::Backward << 200 << 2000 << qreal(1.0) << 40 << (int)QTimeLine::Running << 140; |
|
427 |
QTest::newRow("start at half") << 200 << 1000 << 2000 << (int)QTimeLine::Backward << (int)QTimeLine::Forward << (int)QTimeLine::Backward << 100 << 1500 << qreal(0.5) << 40 << (int)QTimeLine::Running << 140; |
|
428 |
QTest::newRow("start at quarter") << 200 << 1000 << 2000 << (int)QTimeLine::Backward << (int)QTimeLine::Forward << (int)QTimeLine::Backward << 50 << 1250 << qreal(0.25) << 40 << (int)QTimeLine::Running << 140; |
|
429 |
} |
|
430 |
||
431 |
void tst_QTimeLine::reverse() |
|
432 |
{ |
|
433 |
QFETCH(int, duration); |
|
434 |
QFETCH(int, start); |
|
435 |
QFETCH(int, end); |
|
436 |
QFETCH(int, direction); |
|
437 |
QFETCH(int, direction2); |
|
438 |
QFETCH(int, direction3); |
|
439 |
QFETCH(int, startTime); |
|
440 |
QFETCH(int, currentFrame); |
|
441 |
QFETCH(qreal, currentValue); |
|
442 |
QFETCH(int, wait); |
|
443 |
QFETCH(int, state); |
|
444 |
QFETCH(int, wait2); |
|
445 |
||
446 |
QTimeLine timeLine(duration); |
|
447 |
timeLine.setCurveShape(QTimeLine::LinearCurve); |
|
448 |
timeLine.setFrameRange(start, end); |
|
449 |
||
450 |
timeLine.setDirection((QTimeLine::Direction)direction); |
|
451 |
timeLine.setDirection((QTimeLine::Direction)direction2); |
|
452 |
timeLine.setDirection((QTimeLine::Direction)direction3); |
|
453 |
QCOMPARE(timeLine.direction(), ((QTimeLine::Direction)direction)); |
|
454 |
||
455 |
timeLine.setCurrentTime(startTime); |
|
456 |
timeLine.setDirection((QTimeLine::Direction)direction); |
|
457 |
timeLine.setDirection((QTimeLine::Direction)direction2); |
|
458 |
timeLine.setDirection((QTimeLine::Direction)direction3); |
|
459 |
||
460 |
QCOMPARE(timeLine.currentFrame(), currentFrame); |
|
461 |
QCOMPARE(timeLine.currentValue(), currentValue); |
|
462 |
timeLine.start(); |
|
463 |
||
464 |
QTest::qWait(wait); |
|
465 |
QCOMPARE(timeLine.state(), (QTimeLine::State)state); |
|
466 |
int firstValue = timeLine.currentFrame(); |
|
467 |
timeLine.setDirection((QTimeLine::Direction)direction2); |
|
468 |
timeLine.setDirection((QTimeLine::Direction)direction3); |
|
469 |
timeLine.setDirection((QTimeLine::Direction)direction2); |
|
470 |
timeLine.setDirection((QTimeLine::Direction)direction3); |
|
471 |
QTest::qWait(wait2); |
|
472 |
int endValue = timeLine.currentFrame(); |
|
473 |
QVERIFY(endValue < firstValue); |
|
474 |
||
475 |
||
476 |
} |
|
477 |
||
478 |
/* |
|
479 |
void tst_QTimeLine::toggle() |
|
480 |
{ |
|
481 |
QTimeLine timeLine; |
|
482 |
QCOMPARE(timeLine.isReverse(), false); |
|
483 |
timeLine.toggle(); |
|
484 |
QCOMPARE(timeLine.isReverse(), true); |
|
485 |
timeLine.toggle(); |
|
486 |
QCOMPARE(timeLine.isReverse(), false); |
|
487 |
} |
|
488 |
*/ |
|
489 |
/* |
|
490 |
void tst_QTimeLine::reset() |
|
491 |
{ |
|
492 |
QTimeLine timeLine; |
|
493 |
timeLine.setFrameRange(10,100); |
|
494 |
||
495 |
timeLine.setLoopCount(-1); |
|
496 |
QSignalSpy spy(&timeLine, SIGNAL(frameChanged(int))); |
|
497 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
498 |
timeLine.start(); |
|
499 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
500 |
int wait = timeLine.duration()*5/3; |
|
501 |
QTest::qWait(wait); |
|
502 |
QVERIFY(spy.count() >= 1 ); |
|
503 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
504 |
timeLine.setDirection(QTimeLine::Backward); |
|
505 |
QVERIFY(timeLine.currentFrame() != 10); |
|
506 |
QVERIFY(timeLine.currentTime() != 0); |
|
507 |
QVERIFY(timeLine.state() != QTimeLine::Forward); |
|
508 |
QVERIFY(timeLine.loopCount() != 0); |
|
509 |
||
510 |
timeLine.reset(); |
|
511 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
512 |
QCOMPARE(timeLine.currentFrame(), timeLine.startFrame()); |
|
513 |
QCOMPARE(timeLine.currentTime(), 0); |
|
514 |
timeLine.setDirection(QTimeLine::Backward); |
|
515 |
QCOMPARE(timeLine.loopCount(), 1); |
|
516 |
QCOMPARE(timeLine.startFrame(), 10); |
|
517 |
QCOMPARE(timeLine.endFrame(), 100); |
|
518 |
} |
|
519 |
*/ |
|
520 |
void tst_QTimeLine::frameChanged() |
|
521 |
{ |
|
522 |
QTimeLine timeLine; |
|
523 |
timeLine.setFrameRange(0,9); |
|
524 |
timeLine.setUpdateInterval(1000); |
|
525 |
QSignalSpy spy(&timeLine, SIGNAL(frameChanged(int))); |
|
526 |
timeLine.start(); |
|
527 |
QTest::qWait(timeLine.duration()*2); |
|
528 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
529 |
// Probably 10 |
|
530 |
QVERIFY(spy.count() <= 10 && spy.count() > 0); |
|
531 |
||
532 |
//timeLine.reset(); ### todo |
|
533 |
timeLine.setUpdateInterval(5); |
|
534 |
spy.clear(); |
|
535 |
timeLine.setCurrentTime(0); |
|
536 |
timeLine.start(); |
|
537 |
QTest::qWait(timeLine.duration()*2); |
|
538 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
539 |
// Probably 1 |
|
540 |
QVERIFY(spy.count() <= 10 && spy.count() > 0); |
|
541 |
} |
|
542 |
||
543 |
void tst_QTimeLine::stopped() |
|
544 |
{ |
|
545 |
QTimeLine timeLine; |
|
546 |
timeLine.setFrameRange(0, 9); |
|
547 |
qRegisterMetaType<QTimeLine::State>("QTimeLine::State"); |
|
548 |
QSignalSpy spy(&timeLine, SIGNAL(stateChanged(QTimeLine::State))); |
|
549 |
timeLine.start(); |
|
550 |
QTest::qWait(timeLine.duration()*2); |
|
551 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
552 |
QCOMPARE(spy.count(), 2); |
|
553 |
// timeLine.reset(); ### todo |
|
554 |
spy.clear(); |
|
555 |
//int currentFrame = timeLine.currentFrame(); |
|
556 |
//int currentCurrentTime = timeLine.currentTime(); |
|
557 |
timeLine.start(); |
|
558 |
timeLine.stop(); |
|
559 |
QCOMPARE(spy.count(), 2); |
|
560 |
//QCOMPARE(timeLine.currentFrame(), currentFrame); ### Behavioral change |
|
561 |
//QCOMPARE(timeLine.currentTime(), currentCurrentTime); |
|
562 |
timeLine.setDirection(QTimeLine::Backward); |
|
563 |
QCOMPARE(timeLine.loopCount(), 1); |
|
564 |
} |
|
565 |
||
566 |
void tst_QTimeLine::finished() |
|
567 |
{ |
|
568 |
QTimeLine timeLine; |
|
569 |
timeLine.setFrameRange(0,9); |
|
570 |
QSignalSpy spy(&timeLine, SIGNAL(finished())); |
|
571 |
timeLine.start(); |
|
572 |
QTest::qWait(timeLine.duration()*2); |
|
573 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
574 |
QCOMPARE(spy.count(), 1); |
|
575 |
||
576 |
spy.clear(); |
|
577 |
timeLine.start(); |
|
578 |
timeLine.stop(); |
|
579 |
QCOMPARE(spy.count(), 0); |
|
580 |
} |
|
581 |
||
582 |
void tst_QTimeLine::isRunning() |
|
583 |
{ |
|
584 |
QTimeLine timeLine; |
|
585 |
timeLine.setFrameRange(0,9); |
|
586 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
587 |
timeLine.start(); |
|
588 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
589 |
timeLine.stop(); |
|
590 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
591 |
||
592 |
timeLine.start(); |
|
593 |
QTest::qWait(timeLine.duration()*2); |
|
594 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
595 |
} |
|
596 |
||
597 |
void tst_QTimeLine::multipleTimeLines() |
|
598 |
{ |
|
599 |
// Stopping a timer shouldn't affect the other timers |
|
600 |
QTimeLine timeLine(200); |
|
601 |
timeLine.setFrameRange(0,99); |
|
602 |
QSignalSpy spy(&timeLine, SIGNAL(finished())); |
|
603 |
||
604 |
QTimeLine timeLineKiller; |
|
605 |
timeLineKiller.setFrameRange(0,99); |
|
606 |
||
607 |
timeLineKiller.start(); |
|
608 |
timeLine.start(); |
|
609 |
timeLineKiller.stop(); |
|
610 |
QTest::qWait(timeLine.duration()*2); |
|
611 |
QCOMPARE(spy.count(), 1); |
|
612 |
} |
|
613 |
||
614 |
void tst_QTimeLine::sineCurve() |
|
615 |
{ |
|
616 |
QTimeLine timeLine(1000); |
|
617 |
timeLine.setCurveShape(QTimeLine::SineCurve); |
|
618 |
QCOMPARE(timeLine.valueForTime(0), qreal(0)); |
|
619 |
QCOMPARE(timeLine.valueForTime(250), qreal(0.5)); |
|
620 |
QCOMPARE(timeLine.valueForTime(500), qreal(1)); |
|
621 |
QCOMPARE(timeLine.valueForTime(750), qreal(0.5)); |
|
622 |
QCOMPARE(timeLine.valueForTime(1000), qreal(0)); |
|
623 |
} |
|
624 |
||
625 |
void tst_QTimeLine::cosineCurve() |
|
626 |
{ |
|
627 |
QTimeLine timeLine(1000); |
|
628 |
timeLine.setCurveShape(QTimeLine::CosineCurve); |
|
629 |
QCOMPARE(timeLine.valueForTime(0), qreal(0.5)); |
|
630 |
QCOMPARE(timeLine.valueForTime(250), qreal(1)); |
|
631 |
QCOMPARE(timeLine.valueForTime(500), qreal(0.5)); |
|
632 |
QCOMPARE(timeLine.valueForTime(750), qreal(0)); |
|
633 |
QCOMPARE(timeLine.valueForTime(1000), qreal(0.5)); |
|
634 |
} |
|
635 |
||
636 |
void tst_QTimeLine::outOfRange() |
|
637 |
{ |
|
638 |
QTimeLine timeLine(1000); |
|
639 |
QCOMPARE(timeLine.valueForTime(-100), qreal(0)); |
|
640 |
QCOMPARE(timeLine.valueForTime(2000), qreal(1)); |
|
641 |
||
642 |
timeLine.setCurveShape(QTimeLine::SineCurve); |
|
643 |
QCOMPARE(timeLine.valueForTime(2000), qreal(0)); |
|
644 |
} |
|
645 |
||
646 |
void tst_QTimeLine::stateInFinishedSignal() |
|
647 |
{ |
|
648 |
QTimeLine timeLine(50); |
|
649 |
||
650 |
connect(&timeLine, SIGNAL(finished()), this, SLOT(finishedSlot())); |
|
651 |
state = QTimeLine::State(-1); |
|
652 |
||
653 |
timeLine.start(); |
|
654 |
QTest::qWait(250); |
|
655 |
||
656 |
QCOMPARE(state, QTimeLine::NotRunning); |
|
657 |
} |
|
658 |
||
659 |
void tst_QTimeLine::finishedSlot() |
|
660 |
{ |
|
661 |
QTimeLine *timeLine = qobject_cast<QTimeLine *>(sender()); |
|
662 |
if (timeLine) |
|
663 |
state = timeLine->state(); |
|
664 |
} |
|
665 |
||
666 |
void tst_QTimeLine::resume() |
|
667 |
{ |
|
668 |
QTimeLine timeLine(1000); |
|
669 |
{ |
|
670 |
QCOMPARE(timeLine.currentTime(), 0); |
|
671 |
timeLine.start(); |
|
672 |
QTest::qWait(250); |
|
673 |
timeLine.stop(); |
|
674 |
int oldCurrentTime = timeLine.currentTime(); |
|
675 |
QVERIFY(oldCurrentTime > 0); |
|
676 |
QVERIFY(oldCurrentTime < 1000); |
|
677 |
timeLine.resume(); |
|
678 |
QTest::qWait(250); |
|
679 |
timeLine.stop(); |
|
680 |
int currentTime = timeLine.currentTime(); |
|
681 |
QVERIFY(currentTime > oldCurrentTime); |
|
682 |
QVERIFY(currentTime < 1000); |
|
683 |
} |
|
684 |
timeLine.setDirection(QTimeLine::Backward); |
|
685 |
{ |
|
686 |
timeLine.setCurrentTime(1000); |
|
687 |
QCOMPARE(timeLine.currentTime(), 1000); |
|
688 |
timeLine.start(); |
|
689 |
QTest::qWait(250); |
|
690 |
timeLine.stop(); |
|
691 |
int oldCurrentTime = timeLine.currentTime(); |
|
692 |
QVERIFY(oldCurrentTime < 1000); |
|
693 |
QVERIFY(oldCurrentTime > 0); |
|
694 |
timeLine.resume(); |
|
695 |
QTest::qWait(250); |
|
696 |
timeLine.stop(); |
|
697 |
int currentTime = timeLine.currentTime(); |
|
698 |
QVERIFY(currentTime < oldCurrentTime); |
|
699 |
QVERIFY(currentTime > 0); |
|
700 |
} |
|
701 |
} |
|
702 |
||
703 |
void tst_QTimeLine::restart() |
|
704 |
{ |
|
705 |
QTimeLine timeLine(100); |
|
706 |
timeLine.setFrameRange(0,9); |
|
707 |
||
708 |
timeLine.start(); |
|
709 |
QTest::qWait(timeLine.duration()*2); |
|
710 |
QCOMPARE(timeLine.currentFrame(), timeLine.endFrame()); |
|
711 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
712 |
||
713 |
// A restart with the same duration |
|
714 |
timeLine.start(); |
|
715 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
716 |
QCOMPARE(timeLine.currentFrame(), timeLine.startFrame()); |
|
717 |
QCOMPARE(timeLine.currentTime(), 0); |
|
718 |
QTest::qWait(250); |
|
719 |
QCOMPARE(timeLine.currentFrame(), timeLine.endFrame()); |
|
720 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
721 |
||
722 |
// Set a smaller duration and restart |
|
723 |
timeLine.setDuration(50); |
|
724 |
timeLine.start(); |
|
725 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
726 |
QCOMPARE(timeLine.currentFrame(), timeLine.startFrame()); |
|
727 |
QCOMPARE(timeLine.currentTime(), 0); |
|
728 |
QTest::qWait(250); |
|
729 |
QCOMPARE(timeLine.currentFrame(), timeLine.endFrame()); |
|
730 |
QCOMPARE(timeLine.state(), QTimeLine::NotRunning); |
|
731 |
||
732 |
// Set a longer duration and restart |
|
733 |
timeLine.setDuration(150); |
|
734 |
timeLine.start(); |
|
735 |
QCOMPARE(timeLine.state(), QTimeLine::Running); |
|
736 |
QCOMPARE(timeLine.currentFrame(), timeLine.startFrame()); |
|
737 |
QCOMPARE(timeLine.currentTime(), 0); |
|
738 |
} |
|
739 |
||
740 |
QTEST_MAIN(tst_QTimeLine) |
|
741 |
||
742 |
#include "tst_qtimeline.moc" |