From 3bd3b82a2f6e61bb9f5bcc095ef96b39d8e19b80 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 9 Dec 2011 12:39:53 +1000 Subject: Fix possible jump in animation timer. If both a stop and start happen within an event loop, ensure they are processed in order. Based on a patch from Charles Yin. Task-number: QTBUG-22865 Change-Id: I6131bd43a6ba5ad4fa37c863a9f4598bf2ac0e01 Reviewed-by: Leonardo Sobral Cunha Reviewed-by: Martin Jones --- .../qabstractanimation/tst_qabstractanimation.cpp | 46 +++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp b/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp index 8fd5237606..083324bdd8 100644 --- a/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp +++ b/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp @@ -58,6 +58,8 @@ private slots: void loopCount(); void state(); void totalDuration(); + void avoidJumpAtStart(); + void avoidJumpAtStartWithStop(); }; class TestableQAbstractAnimation : public QAbstractAnimation @@ -65,10 +67,15 @@ class TestableQAbstractAnimation : public QAbstractAnimation Q_OBJECT public: + TestableQAbstractAnimation() : m_duration(10) {} virtual ~TestableQAbstractAnimation() {}; - int duration() const { return 10; } + int duration() const { return m_duration; } virtual void updateCurrentTime(int) {} + + void setDuration(int duration) { m_duration = duration; } +private: + int m_duration; }; class DummyQAnimationGroup : public QAnimationGroup @@ -150,6 +157,43 @@ void tst_QAbstractAnimation::totalDuration() QCOMPARE(anim.totalDuration(), 50); } +void tst_QAbstractAnimation::avoidJumpAtStart() +{ + TestableQAbstractAnimation anim; + anim.setDuration(1000); + + /* + the timer shouldn't actually start until we hit the event loop, + so the sleep should have no effect + */ + anim.start(); + QTest::qSleep(300); + QCoreApplication::processEvents(); + QVERIFY(anim.currentTime() < 50); +} + +void tst_QAbstractAnimation::avoidJumpAtStartWithStop() +{ + TestableQAbstractAnimation anim; + anim.setDuration(1000); + + TestableQAbstractAnimation anim2; + anim2.setDuration(1000); + + anim.start(); + QTest::qWait(300); + anim.stop(); + + /* + same test as avoidJumpAtStart, but after there is a + running animation that is stopped + */ + anim2.start(); + QTest::qSleep(300); + QCoreApplication::processEvents(); + QVERIFY(anim2.currentTime() < 50); +} + QTEST_MAIN(tst_QAbstractAnimation) #include "tst_qabstractanimation.moc" -- cgit v1.2.3