summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2011-12-09 12:39:53 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-13 02:23:42 +0100
commit3bd3b82a2f6e61bb9f5bcc095ef96b39d8e19b80 (patch)
tree50b547e7caae17f13068d457c4bc06a422a72389 /tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp
parent309cdc358ec646090a1e5809c3817df8af1f531f (diff)
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 <leo.cunha@nokia.com> Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp')
-rw-r--r--tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp46
1 files changed, 45 insertions, 1 deletions
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"