aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickanimatedsprite
diff options
context:
space:
mode:
authorJan Arve Saether <jan-arve.saether@digia.com>2014-09-04 17:11:08 +0200
committerJan Arve Sæther <jan-arve.saether@digia.com>2014-10-06 13:35:44 +0200
commit1670097fa2b0a549a9509ba4c8be13924bd25c4c (patch)
tree6cd5cf65165bdec0583e0b7da698fe298c950cf2 /tests/auto/quick/qquickanimatedsprite
parent367fd6dd2860fe8c6a4f1a4f50b04de56450c76c (diff)
Fixed AnimatedSprite to respect 'loops' properly
Previously, AnimatedSprite could stop before it had performed its desired number of loops. Task-number: QTBUG-36338 Change-Id: I9485886681f55d410786f27b4f6afdc72a058202 Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'tests/auto/quick/qquickanimatedsprite')
-rw-r--r--tests/auto/quick/qquickanimatedsprite/data/largeAnimation.qml63
-rw-r--r--tests/auto/quick/qquickanimatedsprite/qquickanimatedsprite.pro3
-rw-r--r--tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp113
3 files changed, 179 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickanimatedsprite/data/largeAnimation.qml b/tests/auto/quick/qquickanimatedsprite/data/largeAnimation.qml
new file mode 100644
index 0000000000..adcbaeb74f
--- /dev/null
+++ b/tests/auto/quick/qquickanimatedsprite/data/largeAnimation.qml
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+Rectangle {
+ color: "white"
+ width: 512
+ height: 320
+
+ AnimatedSprite {
+ anchors.centerIn: parent
+ objectName: "sprite"
+ source: "image://test/largeAnimation.png"
+ frameCount: 40
+ loops: 3
+ frameSync: true
+ running: false
+ width: 512
+ height: 64
+ frameWidth: 512
+ frameHeight: 64
+
+ }
+}
diff --git a/tests/auto/quick/qquickanimatedsprite/qquickanimatedsprite.pro b/tests/auto/quick/qquickanimatedsprite/qquickanimatedsprite.pro
index dd56991812..3e47844feb 100644
--- a/tests/auto/quick/qquickanimatedsprite/qquickanimatedsprite.pro
+++ b/tests/auto/quick/qquickanimatedsprite/qquickanimatedsprite.pro
@@ -12,3 +12,6 @@ CONFIG += parallel_test
QT += core-private gui-private qml-private quick-private network testlib
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
+
+OTHER_FILES += \
+ data/largeAnimation.qml
diff --git a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp
index cc5d8274d4..ed97123644 100644
--- a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp
+++ b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp
@@ -35,6 +35,7 @@
#include <QtQuick/qquickview.h>
#include <private/qabstractanimation_p.h>
#include <private/qquickanimatedsprite_p.h>
+#include <QtGui/qpainter.h>
class tst_qquickanimatedsprite : public QQmlDataTest
{
@@ -47,6 +48,8 @@ private slots:
void test_properties();
void test_runningChangedSignal();
void test_frameChangedSignal();
+ void test_largeAnimation_data();
+ void test_largeAnimation();
};
void tst_qquickanimatedsprite::initTestCase()
@@ -103,6 +106,13 @@ void tst_qquickanimatedsprite::test_runningChangedSignal()
delete window;
}
+template <typename T>
+static bool isWithinRange(T min, T value, T max)
+{
+ Q_ASSERT(min < max);
+ return min <= value && value <= max;
+}
+
void tst_qquickanimatedsprite::test_frameChangedSignal()
{
QQuickView *window = new QQuickView(0);
@@ -146,6 +156,109 @@ void tst_qquickanimatedsprite::test_frameChangedSignal()
delete window;
}
+void tst_qquickanimatedsprite::test_largeAnimation_data()
+{
+ QTest::addColumn<bool>("frameSync");
+
+ QTest::newRow("frameSync") << true;
+ QTest::newRow("no_frameSync") << false;
+
+}
+
+class AnimationImageProvider : public QQuickImageProvider
+{
+public:
+ AnimationImageProvider()
+ : QQuickImageProvider(QQuickImageProvider::Pixmap)
+ {
+ }
+
+ QPixmap requestPixmap(const QString &/*id*/, QSize *size, const QSize &requestedSize)
+ {
+ if (requestedSize.isValid())
+ qWarning() << "requestPixmap called with requestedSize of" << requestedSize;
+ // 40 frames.
+ const int nFrames = 40; // 40 is good for texture max width of 4096, 64 is good for 16384
+
+ const int frameWidth = 512;
+ const int frameHeight = 64;
+
+ const QSize pixSize(frameWidth, nFrames * frameHeight);
+ QPixmap pixmap(pixSize);
+ pixmap.fill();
+
+ for (int i = 0; i < nFrames; ++i) {
+ QImage frame(frameWidth, frameHeight, QImage::Format_ARGB32_Premultiplied);
+ frame.fill(Qt::white);
+ QPainter p1(&frame);
+ p1.setRenderHint(QPainter::Antialiasing, true);
+ QRect r(0,0, frameWidth, frameHeight);
+ p1.setBrush(QBrush(Qt::red, Qt::SolidPattern));
+ p1.drawPie(r, i*360*16/nFrames, 90*16);
+ p1.drawText(r, QString::number(i));
+ p1.end();
+
+ QPainter p2(&pixmap);
+ p2.drawImage(0, i * frameHeight, frame);
+ }
+
+ if (size)
+ *size = pixSize;
+ return pixmap;
+ }
+};
+
+void tst_qquickanimatedsprite::test_largeAnimation()
+{
+ QFETCH(bool, frameSync);
+
+ QQuickView *window = new QQuickView(0);
+ window->engine()->addImageProvider(QLatin1String("test"), new AnimationImageProvider);
+ window->setSource(testFileUrl("largeAnimation.qml"));
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ QVERIFY(window->rootObject());
+ QQuickAnimatedSprite* sprite = window->rootObject()->findChild<QQuickAnimatedSprite*>("sprite");
+
+ QVERIFY(sprite);
+
+ QVERIFY(!sprite->running());
+ QVERIFY(!sprite->paused());
+ QCOMPARE(sprite->loops(), 3);
+ QCOMPARE(sprite->frameCount(), 40);
+ sprite->setProperty("frameSync", frameSync);
+ if (!frameSync)
+ sprite->setProperty("frameDuration", 30);
+
+ QSignalSpy frameChangedSpy(sprite, SIGNAL(currentFrameChanged(int)));
+ sprite->setRunning(true);
+ QTRY_VERIFY_WITH_TIMEOUT(!sprite->running(), 100000 /* make sure we wait until its done*/ );
+ if (frameSync)
+ QVERIFY(isWithinRange(3*40, frameChangedSpy.count(), 3*40 + 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;
+ }
+ int maxTextureSize;
+ ::glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
+ maxTextureSize /= 512;
+ QVERIFY(maxFrame > maxTextureSize); // make sure we go beyond the texture width limitation
+ QCOMPARE(loopCounter, sprite->loops());
+ delete window;
+}
+
+
QTEST_MAIN(tst_qquickanimatedsprite)
#include "tst_qquickanimatedsprite.moc"