diff options
author | Jan Arve Saether <jan-arve.saether@digia.com> | 2014-09-03 11:15:25 +0200 |
---|---|---|
committer | Jan Arve Sæther <jan-arve.saether@digia.com> | 2014-09-12 14:06:17 +0200 |
commit | 404640392b28d253c24330eb8acc0c30d838af92 (patch) | |
tree | 9d3901fdaa8be186c5b0d9084dcb27fa0f6453a8 /tests/auto/quick/qquickanimatedsprite | |
parent | 7d03dfe4192f164e837df2c5652b83ffe04840d6 (diff) |
Made emission of AnimatedSprite currentFrameChanges consistent.
Both the order was wrong and sometimes the currentFrame property
did not correspond to the 'arg' argument that was carried by the signal.
The order was sometimes like this:
[window got exposed, m_running == false]
currentFrame: 1, arg: 1 <== Unexpected, its not running
[start() got called, m_running == true]
currentFrame: 1, arg: 0 <== Unexpected, they are inequal
currentFrame: 2, arg: 2 <== Not sure what to expect here
The root of the problem was that we would enter prepareNextFrame on
startup (due to QQuickWindow::exposeEvent) even if we were in the
stopped state. Getting rid of the first invalid emission solved
the issue.
Change-Id: Iba002ee91d4d1acafcf4fd0911c28c93a4bc6fd5
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Diffstat (limited to 'tests/auto/quick/qquickanimatedsprite')
-rw-r--r-- | tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp index b1b02d5d69..cc5d8274d4 100644 --- a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp +++ b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp @@ -109,21 +109,39 @@ void tst_qquickanimatedsprite::test_frameChangedSignal() window->setSource(testFileUrl("frameChange.qml")); window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window)); QVERIFY(window->rootObject()); QQuickAnimatedSprite* sprite = window->rootObject()->findChild<QQuickAnimatedSprite*>("sprite"); + QSignalSpy frameChangedSpy(sprite, SIGNAL(currentFrameChanged(int))); QVERIFY(sprite); + QVERIFY(QTest::qWaitForWindowExposed(window)); QVERIFY(!sprite->running()); QVERIFY(!sprite->paused()); QCOMPARE(sprite->loops(), 3); QCOMPARE(sprite->frameCount(), 6); + QCOMPARE(frameChangedSpy.count(), 0); - QSignalSpy frameChangedSpy(sprite, SIGNAL(currentFrameChanged(int))); + frameChangedSpy.clear(); sprite->setRunning(true); - QTRY_COMPARE(frameChangedSpy.count(), 3*6); QTRY_VERIFY(!sprite->running()); + QCOMPARE(frameChangedSpy.count(), 3*6 + 1); + + int prevFrame = -1; + int loopCounter = 0; + int maxFrame = 0; + while (!frameChangedSpy.isEmpty()) { + QList<QVariant> args = frameChangedSpy.takeFirst(); + int frame = args.first().toInt(); + if (frame < prevFrame) { + ++loopCounter; + } else { + QVERIFY(frame > prevFrame); + } + maxFrame = qMax(frame, maxFrame); + prevFrame = frame; + } + QCOMPARE(loopCounter, 3); delete window; } |