223 QTest::ignoreMessage(QtWarningMsg, "QVariantAnimation::setDuration: cannot set a negative duration"); |
223 QTest::ignoreMessage(QtWarningMsg, "QVariantAnimation::setDuration: cannot set a negative duration"); |
224 animation.setDuration(duration); |
224 animation.setDuration(duration); |
225 animation.setLoopCount(loopCount); |
225 animation.setLoopCount(loopCount); |
226 animation.setCurrentTime(currentTime); |
226 animation.setCurrentTime(currentTime); |
227 |
227 |
228 QCOMPARE(animation.currentTime(), testCurrentTime); |
228 QCOMPARE(animation.currentLoopTime(), testCurrentTime); |
229 QCOMPARE(animation.currentLoop(), testCurrentLoop); |
229 QCOMPARE(animation.currentLoop(), testCurrentLoop); |
230 } |
230 } |
231 |
231 |
232 void tst_QPropertyAnimation::statesAndSignals_data() |
232 void tst_QPropertyAnimation::statesAndSignals_data() |
233 { |
233 { |
278 |
278 |
279 anim->stop(); |
279 anim->stop(); |
280 QCOMPARE(anim->state(), QAnimationGroup::Stopped); |
280 QCOMPARE(anim->state(), QAnimationGroup::Stopped); |
281 QCOMPARE(runningSpy.count(), 1); //anim must have stopped |
281 QCOMPARE(runningSpy.count(), 1); //anim must have stopped |
282 QCOMPARE(finishedSpy.count(), 0); |
282 QCOMPARE(finishedSpy.count(), 0); |
283 QCOMPARE(anim->currentTime(), 0); |
283 QCOMPARE(anim->currentLoopTime(), 0); |
284 QCOMPARE(anim->currentLoop(), 0); |
284 QCOMPARE(anim->currentLoop(), 0); |
285 QCOMPARE(currentLoopSpy.count(), 2); |
285 QCOMPARE(currentLoopSpy.count(), 2); |
286 runningSpy.clear(); |
286 runningSpy.clear(); |
287 |
287 |
288 anim->start(); |
288 anim->start(); |
289 QTest::qWait(1000); |
289 QTest::qWait(1000); |
290 QCOMPARE(anim->state(), QAnimationGroup::Stopped); |
290 QCOMPARE(anim->state(), QAnimationGroup::Stopped); |
291 QCOMPARE(runningSpy.count(), 2); //started and stopped again |
291 QCOMPARE(runningSpy.count(), 2); //started and stopped again |
292 runningSpy.clear(); |
292 runningSpy.clear(); |
293 QCOMPARE(finishedSpy.count(), 1); |
293 QCOMPARE(finishedSpy.count(), 1); |
294 QCOMPARE(anim->currentTime(), 100); |
294 QCOMPARE(anim->currentLoopTime(), 100); |
295 QCOMPARE(anim->currentLoop(), 2); |
295 QCOMPARE(anim->currentLoop(), 2); |
296 QCOMPARE(currentLoopSpy.count(), 4); |
296 QCOMPARE(currentLoopSpy.count(), 4); |
297 |
297 |
298 anim->start(); // auto-rewinds |
298 anim->start(); // auto-rewinds |
299 QCOMPARE(anim->state(), QAnimationGroup::Running); |
299 QCOMPARE(anim->state(), QAnimationGroup::Running); |
310 QCOMPARE(currentLoopSpy.count(), 7); |
310 QCOMPARE(currentLoopSpy.count(), 7); |
311 QCOMPARE(anim->state(), QAnimationGroup::Stopped); |
311 QCOMPARE(anim->state(), QAnimationGroup::Stopped); |
312 QCOMPARE(anim->currentLoop(), 2); |
312 QCOMPARE(anim->currentLoop(), 2); |
313 QCOMPARE(runningSpy.count(), 1); // anim has stopped |
313 QCOMPARE(runningSpy.count(), 1); // anim has stopped |
314 QCOMPARE(finishedSpy.count(), 2); |
314 QCOMPARE(finishedSpy.count(), 2); |
315 QCOMPARE(anim->currentTime(), 100); |
315 QCOMPARE(anim->currentLoopTime(), 100); |
316 |
316 |
317 delete anim; |
317 delete anim; |
318 } |
318 } |
319 |
319 |
320 void tst_QPropertyAnimation::deletion1() |
320 void tst_QPropertyAnimation::deletion1() |
493 //normal case: the animation finishes and is deleted |
493 //normal case: the animation finishes and is deleted |
494 QPointer<QVariantAnimation> anim = new QPropertyAnimation(&o, "ole"); |
494 QPointer<QVariantAnimation> anim = new QPropertyAnimation(&o, "ole"); |
495 anim->setEndValue(100); |
495 anim->setEndValue(100); |
496 QSignalSpy runningSpy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State))); |
496 QSignalSpy runningSpy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State))); |
497 anim->start(QVariantAnimation::DeleteWhenStopped); |
497 anim->start(QVariantAnimation::DeleteWhenStopped); |
498 QTest::qWait(anim->duration() + 50); |
498 QTest::qWait(anim->duration() + 100); |
499 QCOMPARE(runningSpy.count(), 2); //started and then stopped |
499 QCOMPARE(runningSpy.count(), 2); //started and then stopped |
500 QVERIFY(!anim); |
500 QVERIFY(!anim); |
501 } |
501 } |
502 |
502 |
503 { |
503 { |
657 |
657 |
658 QPropertyAnimation anim(&o, "ole"); |
658 QPropertyAnimation anim(&o, "ole"); |
659 anim.setStartValue(0); |
659 anim.setStartValue(0); |
660 anim.setEndValue(100); |
660 anim.setEndValue(100); |
661 anim.start(); |
661 anim.start(); |
662 QTest::qWait(anim.duration() + 50); |
662 QTest::qWait(anim.duration() + 100); |
663 QCOMPARE(anim.state(), QAbstractAnimation::Stopped); |
663 QCOMPARE(anim.state(), QAbstractAnimation::Stopped); |
664 QCOMPARE(anim.currentTime(), anim.duration()); |
664 QCOMPARE(anim.currentTime(), anim.duration()); |
665 |
665 |
666 //the animation is at the end |
666 //the animation is at the end |
667 anim.setDirection(QVariantAnimation::Backward); |
667 anim.setDirection(QVariantAnimation::Backward); |
668 anim.start(); |
668 anim.start(); |
669 QCOMPARE(anim.state(), QAbstractAnimation::Running); |
669 QCOMPARE(anim.state(), QAbstractAnimation::Running); |
670 QTest::qWait(anim.duration() + 50); |
670 QTest::qWait(anim.duration() + 100); |
671 QCOMPARE(anim.state(), QAbstractAnimation::Stopped); |
671 QCOMPARE(anim.state(), QAbstractAnimation::Stopped); |
672 QCOMPARE(anim.currentTime(), 0); |
672 QCOMPARE(anim.currentTime(), 0); |
673 |
673 |
674 //the direction is backward |
674 //the direction is backward |
675 //restarting should jump to the end |
675 //restarting should jump to the end |
676 anim.start(); |
676 anim.start(); |
677 QCOMPARE(anim.state(), QAbstractAnimation::Running); |
677 QCOMPARE(anim.state(), QAbstractAnimation::Running); |
678 QCOMPARE(anim.currentTime(), anim.duration()); |
678 QCOMPARE(anim.currentTime(), anim.duration()); |
679 QTest::qWait(anim.duration() + 50); |
679 QTest::qWait(anim.duration() + 100); |
680 QCOMPARE(anim.state(), QAbstractAnimation::Stopped); |
680 QCOMPARE(anim.state(), QAbstractAnimation::Stopped); |
681 QCOMPARE(anim.currentTime(), 0); |
681 QCOMPARE(anim.currentTime(), 0); |
682 } |
682 } |
683 |
683 |
684 struct Number |
684 struct Number |
862 QCOMPARE(spy.count(), 2); |
862 QCOMPARE(spy.count(), 2); |
863 |
863 |
864 //let's check the first state change |
864 //let's check the first state change |
865 const QVariantList firstChange = spy.first(); |
865 const QVariantList firstChange = spy.first(); |
866 //old state |
866 //old state |
867 QCOMPARE(qVariantValue<QAbstractAnimation::State>(firstChange.first()), QAbstractAnimation::Stopped); |
867 QCOMPARE(qVariantValue<QAbstractAnimation::State>(firstChange.last()), QAbstractAnimation::Stopped); |
868 //new state |
868 //new state |
869 QCOMPARE(qVariantValue<QAbstractAnimation::State>(firstChange.last()), QAbstractAnimation::Running); |
869 QCOMPARE(qVariantValue<QAbstractAnimation::State>(firstChange.first()), QAbstractAnimation::Running); |
870 |
870 |
871 //let's check the first state change |
871 //let's check the first state change |
872 const QVariantList secondChange = spy.last(); |
872 const QVariantList secondChange = spy.last(); |
873 //old state |
873 //old state |
874 QCOMPARE(qVariantValue<QAbstractAnimation::State>(secondChange.first()), QAbstractAnimation::Running); |
874 QCOMPARE(qVariantValue<QAbstractAnimation::State>(secondChange.last()), QAbstractAnimation::Running); |
875 //new state |
875 //new state |
876 QCOMPARE(qVariantValue<QAbstractAnimation::State>(secondChange.last()), QAbstractAnimation::Stopped); |
876 QCOMPARE(qVariantValue<QAbstractAnimation::State>(secondChange.first()), QAbstractAnimation::Stopped); |
877 } |
877 } |
878 |
878 |
879 #define Pause 1 |
879 #define Pause 1 |
880 #define Start 2 |
880 #define Start 2 |
881 #define Resume 3 |
881 #define Resume 3 |
1091 anim.setEndValue(5); |
1091 anim.setEndValue(5); |
1092 anim.setDuration(1000); |
1092 anim.setDuration(1000); |
1093 QSignalSpy spy(&anim, SIGNAL(valueChanged(QVariant))); |
1093 QSignalSpy spy(&anim, SIGNAL(valueChanged(QVariant))); |
1094 anim.start(); |
1094 anim.start(); |
1095 |
1095 |
1096 QTest::qWait(anim.duration() + 50); |
1096 QTest::qWait(anim.duration() + 100); |
1097 |
1097 |
1098 QCOMPARE(anim.state(), QAbstractAnimation::Stopped); |
1098 QCOMPARE(anim.state(), QAbstractAnimation::Stopped); |
1099 QCOMPARE(anim.currentTime(), anim.duration()); |
1099 QCOMPARE(anim.currentTime(), anim.duration()); |
1100 |
1100 |
1101 //let's check that the values go forward |
1101 //let's check that the values go forward |
1142 &o1, SLOT(checkAnimationFinished()), Qt::QueuedConnection); |
1142 &o1, SLOT(checkAnimationFinished()), Qt::QueuedConnection); |
1143 |
1143 |
1144 o1.anim.start(); |
1144 o1.anim.start(); |
1145 o2.anim.start(); |
1145 o2.anim.start(); |
1146 |
1146 |
1147 QTest::qWait(o1.anim.duration() + 50); |
1147 QTest::qWait(o1.anim.duration() + 100); |
1148 QCOMPARE(o1.anim.state(), QAbstractAnimation::Stopped); |
1148 QCOMPARE(o1.anim.state(), QAbstractAnimation::Stopped); |
1149 QCOMPARE(o2.anim.state(), QAbstractAnimation::Stopped); |
1149 QCOMPARE(o2.anim.state(), QAbstractAnimation::Stopped); |
1150 |
1150 |
1151 QCOMPARE(o1.ole(), 1000); |
1151 QCOMPARE(o1.ole(), 1000); |
1152 QCOMPARE(o2.ole(), 1000); |
1152 QCOMPARE(o2.ole(), 1000); |
1169 { |
1169 { |
1170 QPropertyAnimation::start(); |
1170 QPropertyAnimation::start(); |
1171 innerAnim->start(); |
1171 innerAnim->start(); |
1172 } |
1172 } |
1173 |
1173 |
1174 void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState) |
1174 void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) |
1175 { |
1175 { |
1176 QPropertyAnimation::updateState(oldState, newState); |
1176 QPropertyAnimation::updateState(newState, oldState); |
1177 if (newState == QAbstractAnimation::Stopped) |
1177 if (newState == QAbstractAnimation::Stopped) |
1178 delete innerAnim; |
1178 delete innerAnim; |
1179 } |
1179 } |
1180 |
1180 |
1181 public: |
1181 public: |
1192 o.setRealValue(0.0); |
1192 o.setRealValue(0.0); |
1193 |
1193 |
1194 MyComposedAnimation composedAnimation(&o, "value", "realValue"); |
1194 MyComposedAnimation composedAnimation(&o, "value", "realValue"); |
1195 composedAnimation.start(); |
1195 composedAnimation.start(); |
1196 QCOMPARE(composedAnimation.state(), QAbstractAnimation::Running); |
1196 QCOMPARE(composedAnimation.state(), QAbstractAnimation::Running); |
1197 QTest::qWait(composedAnimation.duration() + 50); |
1197 QTest::qWait(composedAnimation.duration() + 100); |
1198 |
1198 |
1199 QCOMPARE(composedAnimation.state(), QAbstractAnimation::Stopped); |
1199 QCOMPARE(composedAnimation.state(), QAbstractAnimation::Stopped); |
1200 QCOMPARE(o.value(), 1000); |
1200 QCOMPARE(o.value(), 1000); |
1201 } |
1201 } |
1202 |
1202 |