aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qtquick2/qquickanimatedimage
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qtquick2/qquickanimatedimage')
-rw-r--r--tests/auto/qtquick2/qquickanimatedimage/data/colors.gifbin0 -> 505 bytes
-rw-r--r--tests/auto/qtquick2/qquickanimatedimage/data/colors.qml5
-rw-r--r--tests/auto/qtquick2/qquickanimatedimage/data/hearts.gifbin0 -> 6524 bytes
-rw-r--r--tests/auto/qtquick2/qquickanimatedimage/data/hearts.qml6
-rw-r--r--tests/auto/qtquick2/qquickanimatedimage/data/qmldir1
-rw-r--r--tests/auto/qtquick2/qquickanimatedimage/data/qtbug-16520.qml17
-rw-r--r--tests/auto/qtquick2/qquickanimatedimage/data/stickman.gifbin0 -> 164923 bytes
-rw-r--r--tests/auto/qtquick2/qquickanimatedimage/data/stickman.qml5
-rw-r--r--tests/auto/qtquick2/qquickanimatedimage/data/stickmanerror1.qml6
-rw-r--r--tests/auto/qtquick2/qquickanimatedimage/data/stickmanpause.qml7
-rw-r--r--tests/auto/qtquick2/qquickanimatedimage/data/stickmanscaled.qml7
-rw-r--r--tests/auto/qtquick2/qquickanimatedimage/data/stickmanstopped.qml6
-rw-r--r--tests/auto/qtquick2/qquickanimatedimage/qquickanimatedimage.pro13
-rw-r--r--tests/auto/qtquick2/qquickanimatedimage/tst_qquickanimatedimage.cpp378
14 files changed, 451 insertions, 0 deletions
diff --git a/tests/auto/qtquick2/qquickanimatedimage/data/colors.gif b/tests/auto/qtquick2/qquickanimatedimage/data/colors.gif
new file mode 100644
index 0000000000..1270bfaa79
--- /dev/null
+++ b/tests/auto/qtquick2/qquickanimatedimage/data/colors.gif
Binary files differ
diff --git a/tests/auto/qtquick2/qquickanimatedimage/data/colors.qml b/tests/auto/qtquick2/qquickanimatedimage/data/colors.qml
new file mode 100644
index 0000000000..5ccc0148dd
--- /dev/null
+++ b/tests/auto/qtquick2/qquickanimatedimage/data/colors.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+AnimatedImage {
+ source: "colors.gif"
+}
diff --git a/tests/auto/qtquick2/qquickanimatedimage/data/hearts.gif b/tests/auto/qtquick2/qquickanimatedimage/data/hearts.gif
new file mode 100644
index 0000000000..cfb55f27f5
--- /dev/null
+++ b/tests/auto/qtquick2/qquickanimatedimage/data/hearts.gif
Binary files differ
diff --git a/tests/auto/qtquick2/qquickanimatedimage/data/hearts.qml b/tests/auto/qtquick2/qquickanimatedimage/data/hearts.qml
new file mode 100644
index 0000000000..717bab430b
--- /dev/null
+++ b/tests/auto/qtquick2/qquickanimatedimage/data/hearts.qml
@@ -0,0 +1,6 @@
+import QtQuick 2.0
+
+AnimatedImage {
+ source: "hearts.gif"
+ playing: false
+}
diff --git a/tests/auto/qtquick2/qquickanimatedimage/data/qmldir b/tests/auto/qtquick2/qquickanimatedimage/data/qmldir
new file mode 100644
index 0000000000..ef7c1f44f3
--- /dev/null
+++ b/tests/auto/qtquick2/qquickanimatedimage/data/qmldir
@@ -0,0 +1 @@
+# No local types
diff --git a/tests/auto/qtquick2/qquickanimatedimage/data/qtbug-16520.qml b/tests/auto/qtquick2/qquickanimatedimage/data/qtbug-16520.qml
new file mode 100644
index 0000000000..da77a4063b
--- /dev/null
+++ b/tests/auto/qtquick2/qquickanimatedimage/data/qtbug-16520.qml
@@ -0,0 +1,17 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 500
+ height: 500
+
+ AnimatedImage {
+ objectName: "anim"
+ anchors.centerIn: parent
+ asynchronous: true
+ opacity: status == AnimatedImage.Ready ? 1 : 0
+
+ Behavior on opacity {
+ NumberAnimation { duration: 1000 }
+ }
+ }
+}
diff --git a/tests/auto/qtquick2/qquickanimatedimage/data/stickman.gif b/tests/auto/qtquick2/qquickanimatedimage/data/stickman.gif
new file mode 100644
index 0000000000..7c4cd18687
--- /dev/null
+++ b/tests/auto/qtquick2/qquickanimatedimage/data/stickman.gif
Binary files differ
diff --git a/tests/auto/qtquick2/qquickanimatedimage/data/stickman.qml b/tests/auto/qtquick2/qquickanimatedimage/data/stickman.qml
new file mode 100644
index 0000000000..a47924de21
--- /dev/null
+++ b/tests/auto/qtquick2/qquickanimatedimage/data/stickman.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+AnimatedImage {
+ source: "stickman.gif"
+}
diff --git a/tests/auto/qtquick2/qquickanimatedimage/data/stickmanerror1.qml b/tests/auto/qtquick2/qquickanimatedimage/data/stickmanerror1.qml
new file mode 100644
index 0000000000..4f823b3d70
--- /dev/null
+++ b/tests/auto/qtquick2/qquickanimatedimage/data/stickmanerror1.qml
@@ -0,0 +1,6 @@
+import QtQuick 2.0
+
+AnimatedImage {
+ sourceSize: "240x180"
+ source: "stickman.gif"
+}
diff --git a/tests/auto/qtquick2/qquickanimatedimage/data/stickmanpause.qml b/tests/auto/qtquick2/qquickanimatedimage/data/stickmanpause.qml
new file mode 100644
index 0000000000..ef771ed56f
--- /dev/null
+++ b/tests/auto/qtquick2/qquickanimatedimage/data/stickmanpause.qml
@@ -0,0 +1,7 @@
+import QtQuick 2.0
+
+AnimatedImage {
+ source: "stickman.gif"
+ paused: true
+ currentFrame: 2
+}
diff --git a/tests/auto/qtquick2/qquickanimatedimage/data/stickmanscaled.qml b/tests/auto/qtquick2/qquickanimatedimage/data/stickmanscaled.qml
new file mode 100644
index 0000000000..1ef1f95165
--- /dev/null
+++ b/tests/auto/qtquick2/qquickanimatedimage/data/stickmanscaled.qml
@@ -0,0 +1,7 @@
+import QtQuick 2.0
+
+AnimatedImage {
+ width: 240
+ height: 180
+ source: "stickman.gif"
+}
diff --git a/tests/auto/qtquick2/qquickanimatedimage/data/stickmanstopped.qml b/tests/auto/qtquick2/qquickanimatedimage/data/stickmanstopped.qml
new file mode 100644
index 0000000000..0bf80b8972
--- /dev/null
+++ b/tests/auto/qtquick2/qquickanimatedimage/data/stickmanstopped.qml
@@ -0,0 +1,6 @@
+import QtQuick 2.0
+
+AnimatedImage {
+ source: "stickman.gif"
+ playing: false
+}
diff --git a/tests/auto/qtquick2/qquickanimatedimage/qquickanimatedimage.pro b/tests/auto/qtquick2/qquickanimatedimage/qquickanimatedimage.pro
new file mode 100644
index 0000000000..56394592b8
--- /dev/null
+++ b/tests/auto/qtquick2/qquickanimatedimage/qquickanimatedimage.pro
@@ -0,0 +1,13 @@
+CONFIG += testcase
+TARGET = tst_qquickanimatedimage
+HEADERS += ../../shared/testhttpserver.h
+SOURCES += tst_qquickanimatedimage.cpp ../../shared/testhttpserver.cpp
+macx:CONFIG -= app_bundle
+
+testDataFiles.files = data
+testDataFiles.path = .
+DEPLOYMENT += testDataFiles
+
+CONFIG += parallel_test
+
+QT += core-private gui-private declarative-private quick-private network testlib
diff --git a/tests/auto/qtquick2/qquickanimatedimage/tst_qquickanimatedimage.cpp b/tests/auto/qtquick2/qquickanimatedimage/tst_qquickanimatedimage.cpp
new file mode 100644
index 0000000000..bf1017fe21
--- /dev/null
+++ b/tests/auto/qtquick2/qquickanimatedimage/tst_qquickanimatedimage.cpp
@@ -0,0 +1,378 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <qtest.h>
+#include <QtDeclarative/qdeclarativeengine.h>
+#include <QtDeclarative/qdeclarativecomponent.h>
+#include <QtQuick/qquickview.h>
+#include <QtQuick/private/qquickrectangle_p.h>
+#include <private/qquickimage_p.h>
+#include <private/qquickanimatedimage_p.h>
+#include <QSignalSpy>
+#include <QtDeclarative/qdeclarativecontext.h>
+
+#include "../../shared/testhttpserver.h"
+#include "../../shared/util.h"
+
+Q_DECLARE_METATYPE(QQuickImageBase::Status)
+
+class tst_qquickanimatedimage : public QObject
+{
+ Q_OBJECT
+public:
+ tst_qquickanimatedimage() {}
+
+private slots:
+ void play();
+ void pause();
+ void stopped();
+ void setFrame();
+ void frameCount();
+ void mirror_running();
+ void mirror_notRunning();
+ void mirror_notRunning_data();
+ void remote();
+ void remote_data();
+ void sourceSize();
+ void sourceSizeReadOnly();
+ void invalidSource();
+ void qtbug_16520();
+ void progressAndStatusChanges();
+
+};
+
+void tst_qquickanimatedimage::play()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(TESTDATA("stickman.qml")));
+ QQuickAnimatedImage *anim = qobject_cast<QQuickAnimatedImage *>(component.create());
+ QVERIFY(anim);
+ QVERIFY(anim->isPlaying());
+
+ delete anim;
+}
+
+void tst_qquickanimatedimage::pause()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(TESTDATA("stickmanpause.qml")));
+ QQuickAnimatedImage *anim = qobject_cast<QQuickAnimatedImage *>(component.create());
+ QVERIFY(anim);
+ QVERIFY(anim->isPlaying());
+ QVERIFY(anim->isPaused());
+
+ delete anim;
+}
+
+void tst_qquickanimatedimage::stopped()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(TESTDATA("stickmanstopped.qml")));
+ QQuickAnimatedImage *anim = qobject_cast<QQuickAnimatedImage *>(component.create());
+ QVERIFY(anim);
+ QVERIFY(!anim->isPlaying());
+ QCOMPARE(anim->currentFrame(), 0);
+
+ delete anim;
+}
+
+void tst_qquickanimatedimage::setFrame()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(TESTDATA("stickmanpause.qml")));
+ QQuickAnimatedImage *anim = qobject_cast<QQuickAnimatedImage *>(component.create());
+ QVERIFY(anim);
+ QVERIFY(anim->isPlaying());
+ QCOMPARE(anim->currentFrame(), 2);
+
+ delete anim;
+}
+
+void tst_qquickanimatedimage::frameCount()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(TESTDATA("colors.qml")));
+ QQuickAnimatedImage *anim = qobject_cast<QQuickAnimatedImage *>(component.create());
+ QVERIFY(anim);
+ QVERIFY(anim->isPlaying());
+ QCOMPARE(anim->frameCount(), 3);
+
+ delete anim;
+}
+
+void tst_qquickanimatedimage::mirror_running()
+{
+ // test where mirror is set to true after animation has started
+
+ QQuickView *canvas = new QQuickView;
+ canvas->show();
+
+ canvas->setSource(QUrl::fromLocalFile(TESTDATA("hearts.qml")));
+ QQuickAnimatedImage *anim = qobject_cast<QQuickAnimatedImage *>(canvas->rootObject());
+ QVERIFY(anim);
+
+ int width = anim->property("width").toInt();
+
+ QCOMPARE(anim->currentFrame(), 0);
+ QPixmap frame0 = QPixmap::fromImage(canvas->grabFrameBuffer());
+
+ anim->setCurrentFrame(1);
+ QPixmap frame1 = QPixmap::fromImage(canvas->grabFrameBuffer());
+
+ anim->setCurrentFrame(0);
+
+ QSignalSpy spy(anim, SIGNAL(frameChanged()));
+ anim->setPlaying(true);
+
+ QTRY_VERIFY(spy.count() == 1); spy.clear();
+ anim->setProperty("mirror", true);
+
+ QCOMPARE(anim->currentFrame(), 1);
+ QPixmap frame1_flipped = QPixmap::fromImage(canvas->grabFrameBuffer());
+
+ QTRY_VERIFY(spy.count() == 1); spy.clear();
+ QCOMPARE(anim->currentFrame(), 0); // animation only has 2 frames, should cycle back to first
+ QPixmap frame0_flipped = QPixmap::fromImage(canvas->grabFrameBuffer());
+
+ QSKIP("Skip while QTBUG-19351 and QTBUG-19252 are not resolved");
+
+ QTransform transform;
+ transform.translate(width, 0).scale(-1, 1.0);
+ QPixmap frame0_expected = frame0.transformed(transform);
+ QPixmap frame1_expected = frame1.transformed(transform);
+
+ QCOMPARE(frame0_flipped, frame0_expected);
+ QCOMPARE(frame1_flipped, frame1_expected);
+
+ delete canvas;
+}
+
+void tst_qquickanimatedimage::mirror_notRunning()
+{
+ QFETCH(QUrl, fileUrl);
+
+ QQuickView *canvas = new QQuickView;
+ canvas->show();
+
+ canvas->setSource(fileUrl);
+ QQuickAnimatedImage *anim = qobject_cast<QQuickAnimatedImage *>(canvas->rootObject());
+ QVERIFY(anim);
+
+ int width = anim->property("width").toInt();
+ QPixmap screenshot = QPixmap::fromImage(canvas->grabFrameBuffer());
+
+ QTransform transform;
+ transform.translate(width, 0).scale(-1, 1.0);
+ QPixmap expected = screenshot.transformed(transform);
+
+ int frame = anim->currentFrame();
+ bool playing = anim->isPlaying();
+ bool paused = anim->isPlaying();
+
+ anim->setProperty("mirror", true);
+ screenshot = QPixmap::fromImage(canvas->grabFrameBuffer());
+
+ QSKIP("Skip while QTBUG-19351 and QTBUG-19252 are not resolved");
+ QCOMPARE(screenshot, expected);
+
+ // mirroring should not change the current frame or playing status
+ QCOMPARE(anim->currentFrame(), frame);
+ QCOMPARE(anim->isPlaying(), playing);
+ QCOMPARE(anim->isPaused(), paused);
+
+ delete canvas;
+}
+
+void tst_qquickanimatedimage::mirror_notRunning_data()
+{
+ QTest::addColumn<QUrl>("fileUrl");
+
+ QTest::newRow("paused") << QUrl::fromLocalFile(TESTDATA("stickmanpause.qml"));
+ QTest::newRow("stopped") << QUrl::fromLocalFile(TESTDATA("stickmanstopped.qml"));
+}
+
+void tst_qquickanimatedimage::remote()
+{
+ QFETCH(QString, fileName);
+ QFETCH(bool, paused);
+
+ TestHTTPServer server(14449);
+ QVERIFY(server.isValid());
+ server.serveDirectory(TESTDATA(""));
+
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl("http://127.0.0.1:14449/" + fileName));
+ QTRY_VERIFY(component.isReady());
+
+ QQuickAnimatedImage *anim = qobject_cast<QQuickAnimatedImage *>(component.create());
+ QVERIFY(anim);
+
+ QTRY_VERIFY(anim->isPlaying());
+ if (paused) {
+ QTRY_VERIFY(anim->isPaused());
+ QCOMPARE(anim->currentFrame(), 2);
+ }
+ QVERIFY(anim->status() != QQuickAnimatedImage::Error);
+
+ delete anim;
+}
+
+void tst_qquickanimatedimage::sourceSize()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(TESTDATA("stickmanscaled.qml")));
+ QQuickAnimatedImage *anim = qobject_cast<QQuickAnimatedImage *>(component.create());
+ QVERIFY(anim);
+ QCOMPARE(anim->width(),240.0);
+ QCOMPARE(anim->height(),180.0);
+ QCOMPARE(anim->sourceSize(),QSize(160,120));
+
+ delete anim;
+}
+
+void tst_qquickanimatedimage::sourceSizeReadOnly()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(TESTDATA("stickmanerror1.qml")));
+ QVERIFY(component.isError());
+ QCOMPARE(component.errors().at(0).description(), QString("Invalid property assignment: \"sourceSize\" is a read-only property"));
+}
+
+void tst_qquickanimatedimage::remote_data()
+{
+ QTest::addColumn<QString>("fileName");
+ QTest::addColumn<bool>("paused");
+
+ QTest::newRow("playing") << "stickman.qml" << false;
+ QTest::newRow("paused") << "stickmanpause.qml" << true;
+}
+
+void tst_qquickanimatedimage::invalidSource()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine);
+ component.setData("import QtQuick 2.0\n AnimatedImage { source: \"no-such-file.gif\" }", QUrl::fromLocalFile(""));
+ QVERIFY(component.isReady());
+
+ QTest::ignoreMessage(QtWarningMsg, "file::2:2: QML AnimatedImage: Error Reading Animated Image File file:no-such-file.gif");
+
+ QQuickAnimatedImage *anim = qobject_cast<QQuickAnimatedImage *>(component.create());
+ QVERIFY(anim);
+
+ QVERIFY(!anim->isPlaying());
+ QVERIFY(!anim->isPaused());
+ QCOMPARE(anim->currentFrame(), 0);
+ QCOMPARE(anim->frameCount(), 0);
+ QTRY_VERIFY(anim->status() == 3);
+}
+
+void tst_qquickanimatedimage::qtbug_16520()
+{
+ TestHTTPServer server(14449);
+ QVERIFY(server.isValid());
+ server.serveDirectory(TESTDATA(""));
+
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine, QUrl::fromLocalFile(TESTDATA("qtbug-16520.qml")));
+ QTRY_VERIFY(component.isReady());
+
+ QQuickRectangle *root = qobject_cast<QQuickRectangle *>(component.create());
+ QVERIFY(root);
+ QQuickAnimatedImage *anim = root->findChild<QQuickAnimatedImage*>("anim");
+
+ anim->setProperty("source", "http://127.0.0.1:14449/stickman.gif");
+
+ QTRY_VERIFY(anim->opacity() == 0);
+ QTRY_VERIFY(anim->opacity() == 1);
+
+ delete anim;
+}
+
+void tst_qquickanimatedimage::progressAndStatusChanges()
+{
+ TestHTTPServer server(14449);
+ QVERIFY(server.isValid());
+ server.serveDirectory(TESTDATA(""));
+
+ QDeclarativeEngine engine;
+ QString componentStr = "import QtQuick 2.0\nAnimatedImage { source: srcImage }";
+ QDeclarativeContext *ctxt = engine.rootContext();
+ ctxt->setContextProperty("srcImage", QUrl::fromLocalFile(TESTDATA("stickman.gif")));
+ QDeclarativeComponent component(&engine);
+ component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QQuickImage *obj = qobject_cast<QQuickImage*>(component.create());
+ QVERIFY(obj != 0);
+ QVERIFY(obj->status() == QQuickImage::Ready);
+ QTRY_VERIFY(obj->progress() == 1.0);
+
+ qRegisterMetaType<QQuickImageBase::Status>();
+ QSignalSpy sourceSpy(obj, SIGNAL(sourceChanged(const QUrl &)));
+ QSignalSpy progressSpy(obj, SIGNAL(progressChanged(qreal)));
+ QSignalSpy statusSpy(obj, SIGNAL(statusChanged(QQuickImageBase::Status)));
+
+ // Loading local file
+ ctxt->setContextProperty("srcImage", QUrl::fromLocalFile(TESTDATA("colors.gif")));
+ QTRY_VERIFY(obj->status() == QQuickImage::Ready);
+ QTRY_VERIFY(obj->progress() == 1.0);
+ QTRY_COMPARE(sourceSpy.count(), 1);
+ QTRY_COMPARE(progressSpy.count(), 0);
+ QTRY_COMPARE(statusSpy.count(), 0);
+
+ // Loading remote file
+ ctxt->setContextProperty("srcImage", "http://127.0.0.1:14449/stickman.gif");
+ QTRY_VERIFY(obj->status() == QQuickImage::Loading);
+ QTRY_VERIFY(obj->progress() == 0.0);
+ QTRY_VERIFY(obj->status() == QQuickImage::Ready);
+ QTRY_VERIFY(obj->progress() == 1.0);
+ QTRY_COMPARE(sourceSpy.count(), 2);
+ QTRY_VERIFY(progressSpy.count() > 1);
+ QTRY_COMPARE(statusSpy.count(), 2);
+
+ ctxt->setContextProperty("srcImage", "");
+ QTRY_VERIFY(obj->status() == QQuickImage::Null);
+ QTRY_VERIFY(obj->progress() == 0.0);
+ QTRY_COMPARE(sourceSpy.count(), 3);
+ QTRY_VERIFY(progressSpy.count() > 2);
+ QTRY_COMPARE(statusSpy.count(), 3);
+}
+
+QTEST_MAIN(tst_qquickanimatedimage)
+
+#include "tst_qquickanimatedimage.moc"