diff options
author | Martin Jones <martin.jones@nokia.com> | 2011-05-31 15:25:44 +1000 |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2011-05-31 15:25:44 +1000 |
commit | 766521d62a4cf4598326a510186b080a91bde6dd (patch) | |
tree | 5cf89c1338f42122c370c649b73c8193ca079268 /tests/auto/declarative/qsganimatedimage | |
parent | a91b8a041966f8aea4bf01fdcb1d5006547f3902 (diff) | |
parent | e7fef9d6115d1a9193c112d8fd4249ae9396dae3 (diff) |
Merge branch 'qtquick2'
Conflicts:
demos/declarative/flickr/common/Progress.qml
demos/declarative/flickr/common/RssModel.qml
demos/declarative/flickr/common/ScrollBar.qml
demos/declarative/flickr/common/Slider.qml
demos/declarative/flickr/mobile/Button.qml
demos/declarative/flickr/mobile/GridDelegate.qml
demos/declarative/flickr/mobile/ImageDetails.qml
demos/declarative/flickr/mobile/ListDelegate.qml
demos/declarative/flickr/mobile/TitleBar.qml
demos/declarative/flickr/mobile/ToolBar.qml
demos/declarative/webbrowser/content/Button.qml
demos/declarative/webbrowser/content/FlickableWebView.qml
demos/declarative/webbrowser/content/Header.qml
demos/declarative/webbrowser/content/ScrollBar.qml
demos/declarative/webbrowser/content/UrlInput.qml
demos/declarative/webbrowser/webbrowser.qml
doc/src/snippets/declarative/mousearea/mousearea-snippet.qml
examples/declarative/modelviews/webview/newwindows/qml/alerts.html
examples/declarative/modelviews/webview/newwindows/qml/content/Mapping/map.html
examples/declarative/modelviews/webview/newwindows/qml/content/pics/cancel.png
examples/declarative/modelviews/webview/newwindows/qml/content/pics/ok.png
examples/declarative/modelviews/webview/newwindows/qml/newwindows.html
src/declarative/graphicsitems/qdeclarativetextinput.cpp
src/declarative/qml/qdeclarativecompiledbindings.cpp
src/declarative/qml/qdeclarativecompiledbindings_p.h
src/declarative/qml/qdeclarativedom.cpp
src/declarative/qml/qdeclarativedom_p.h
src/declarative/qml/qdeclarativedom_p_p.h
src/declarative/qml/qdeclarativeengine.cpp
src/declarative/qml/qdeclarativetypeloader.cpp
src/imports/particles/particles.cpp
tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp
tests/auto/declarative/qmlvisual/qdeclarativeflickable/data/flickable-horizontal.4.png
tests/auto/declarative/qmlvisual/qdeclarativepathview/data/test-pathview.6.png
tests/auto/declarative/qmlvisual/qdeclarativepositioners/data/usingRepeater.0.png
tests/auto/declarative/qmlvisual/qdeclarativespringanimation/data/follow.0.png
tests/auto/declarative/qmlvisual/qdeclarativespringanimation/data/follow.1.png
tests/auto/declarative/qmlvisual/qdeclarativespringanimation/data/follow.2.png
tests/auto/declarative/qmlvisual/qdeclarativespringanimation/data/follow.3.png
tests/auto/declarative/qmlvisual/qdeclarativespringanimation/data/follow.4.png
tests/auto/declarative/qmlvisual/qdeclarativespringanimation/data/follow.5.png
tests/auto/declarative/qmlvisual/qdeclarativespringanimation/data/follow.6.png
tests/auto/declarative/qmlvisual/qdeclarativespringanimation/data/follow.7.png
tests/auto/declarative/qmlvisual/qdeclarativetext/align/data-MAC/multilineAlign.0.png
tests/auto/declarative/qmlvisual/qdeclarativetext/align/data-X11/multilineAlign.0.png
tests/auto/declarative/qmlvisual/qdeclarativetext/baseline/data-X11/parentanchor.0.png
tests/auto/declarative/qmlvisual/qdeclarativetext/data-MAC/qtbug_14865.0.png
tests/auto/declarative/qmlvisual/qdeclarativetext/data-MAC/qtbug_14865.1.png
tests/auto/declarative/qmlvisual/qdeclarativetext/data-X11/qtbug_14865.0.png
tests/auto/declarative/qmlvisual/qdeclarativetext/data-X11/qtbug_14865.1.png
tests/auto/declarative/qmlvisual/qdeclarativetext/elide/data-X11/elide.1.png
tests/auto/declarative/qmlvisual/qdeclarativetext/elide/data-X11/elide2.0.png
tests/auto/declarative/qmlvisual/qdeclarativetext/elide/data-X11/elide2.1.png
tests/auto/declarative/qmlvisual/qdeclarativetext/elide/data-X11/multilength.1.png
tests/auto/declarative/qmlvisual/qdeclarativetext/elide/data-X11/multilength.2.png
tests/auto/declarative/qmlvisual/qdeclarativetext/elide/data-X11/multilength.3.png
tests/auto/declarative/qmlvisual/qdeclarativetext/elide/data-X11/multilength.4.png
tests/auto/declarative/qmlvisual/qdeclarativetext/elide/data-X11/multilength.5.png
tests/auto/declarative/qmlvisual/qdeclarativetext/font/data-MAC/plaintext2.0.png
tests/auto/declarative/qmlvisual/qdeclarativetext/font/data-MAC/plaintext3.0.png
tests/auto/declarative/qmlvisual/qdeclarativetext/font/data-X11/plaintext.0.png
tests/auto/declarative/qmlvisual/qdeclarativetext/font/data-X11/plaintext2.0.png
tests/auto/declarative/qmlvisual/qdeclarativetext/font/data-X11/richtext.0.png
tests/auto/declarative/qmlvisual/qdeclarativetext/font/data-X11/richtext2.0.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.0.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.1.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.10.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.11.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.2.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.3.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.4.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.5.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.6.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.7.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.8.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.9.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/wrap.0.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/wrap.1.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/wrap.2.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/wrap.3.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/wrap.4.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/wrap.5.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/wrap.6.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/qt-669.0.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/qt-669.1.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/qt-669.2.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/qt-669.3.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/qt-669.4.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/usingMultilineEdit.10.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/usingMultilineEdit.11.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/usingMultilineEdit.12.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/usingMultilineEdit.7.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/usingMultilineEdit.9.png
tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/wrap.7.png
tests/auto/declarative/qmlvisual/qdeclarativetextinput/data-MAC/echoMode.0.png
tests/auto/declarative/qmlvisual/qdeclarativetextinput/data-MAC/echoMode.1.png
tests/auto/declarative/qmlvisual/qdeclarativetextinput/data-MAC/echoMode.2.png
tests/auto/declarative/qmlvisual/qdeclarativetextinput/data-X11/usingLineEdit.11.png
tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp
Change-Id: I40df8a9403a58a6c03a0f1734f16a5cbed6c85ff
Diffstat (limited to 'tests/auto/declarative/qsganimatedimage')
14 files changed, 457 insertions, 0 deletions
diff --git a/tests/auto/declarative/qsganimatedimage/data/colors.gif b/tests/auto/declarative/qsganimatedimage/data/colors.gif Binary files differnew file mode 100644 index 0000000000..1270bfaa79 --- /dev/null +++ b/tests/auto/declarative/qsganimatedimage/data/colors.gif diff --git a/tests/auto/declarative/qsganimatedimage/data/colors.qml b/tests/auto/declarative/qsganimatedimage/data/colors.qml new file mode 100644 index 0000000000..5ccc0148dd --- /dev/null +++ b/tests/auto/declarative/qsganimatedimage/data/colors.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +AnimatedImage { + source: "colors.gif" +} diff --git a/tests/auto/declarative/qsganimatedimage/data/hearts.gif b/tests/auto/declarative/qsganimatedimage/data/hearts.gif Binary files differnew file mode 100644 index 0000000000..cfb55f27f5 --- /dev/null +++ b/tests/auto/declarative/qsganimatedimage/data/hearts.gif diff --git a/tests/auto/declarative/qsganimatedimage/data/hearts.qml b/tests/auto/declarative/qsganimatedimage/data/hearts.qml new file mode 100644 index 0000000000..717bab430b --- /dev/null +++ b/tests/auto/declarative/qsganimatedimage/data/hearts.qml @@ -0,0 +1,6 @@ +import QtQuick 2.0 + +AnimatedImage { + source: "hearts.gif" + playing: false +} diff --git a/tests/auto/declarative/qsganimatedimage/data/qmldir b/tests/auto/declarative/qsganimatedimage/data/qmldir new file mode 100644 index 0000000000..ef7c1f44f3 --- /dev/null +++ b/tests/auto/declarative/qsganimatedimage/data/qmldir @@ -0,0 +1 @@ +# No local types diff --git a/tests/auto/declarative/qsganimatedimage/data/qtbug-16520.qml b/tests/auto/declarative/qsganimatedimage/data/qtbug-16520.qml new file mode 100644 index 0000000000..da77a4063b --- /dev/null +++ b/tests/auto/declarative/qsganimatedimage/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/declarative/qsganimatedimage/data/stickman.gif b/tests/auto/declarative/qsganimatedimage/data/stickman.gif Binary files differnew file mode 100644 index 0000000000..7c4cd18687 --- /dev/null +++ b/tests/auto/declarative/qsganimatedimage/data/stickman.gif diff --git a/tests/auto/declarative/qsganimatedimage/data/stickman.qml b/tests/auto/declarative/qsganimatedimage/data/stickman.qml new file mode 100644 index 0000000000..a47924de21 --- /dev/null +++ b/tests/auto/declarative/qsganimatedimage/data/stickman.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +AnimatedImage { + source: "stickman.gif" +} diff --git a/tests/auto/declarative/qsganimatedimage/data/stickmanerror1.qml b/tests/auto/declarative/qsganimatedimage/data/stickmanerror1.qml new file mode 100644 index 0000000000..4f823b3d70 --- /dev/null +++ b/tests/auto/declarative/qsganimatedimage/data/stickmanerror1.qml @@ -0,0 +1,6 @@ +import QtQuick 2.0 + +AnimatedImage { + sourceSize: "240x180" + source: "stickman.gif" +} diff --git a/tests/auto/declarative/qsganimatedimage/data/stickmanpause.qml b/tests/auto/declarative/qsganimatedimage/data/stickmanpause.qml new file mode 100644 index 0000000000..ef771ed56f --- /dev/null +++ b/tests/auto/declarative/qsganimatedimage/data/stickmanpause.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 + +AnimatedImage { + source: "stickman.gif" + paused: true + currentFrame: 2 +} diff --git a/tests/auto/declarative/qsganimatedimage/data/stickmanscaled.qml b/tests/auto/declarative/qsganimatedimage/data/stickmanscaled.qml new file mode 100644 index 0000000000..1ef1f95165 --- /dev/null +++ b/tests/auto/declarative/qsganimatedimage/data/stickmanscaled.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 + +AnimatedImage { + width: 240 + height: 180 + source: "stickman.gif" +} diff --git a/tests/auto/declarative/qsganimatedimage/data/stickmanstopped.qml b/tests/auto/declarative/qsganimatedimage/data/stickmanstopped.qml new file mode 100644 index 0000000000..0bf80b8972 --- /dev/null +++ b/tests/auto/declarative/qsganimatedimage/data/stickmanstopped.qml @@ -0,0 +1,6 @@ +import QtQuick 2.0 + +AnimatedImage { + source: "stickman.gif" + playing: false +} diff --git a/tests/auto/declarative/qsganimatedimage/qsganimatedimage.pro b/tests/auto/declarative/qsganimatedimage/qsganimatedimage.pro new file mode 100644 index 0000000000..c1a3f00aff --- /dev/null +++ b/tests/auto/declarative/qsganimatedimage/qsganimatedimage.pro @@ -0,0 +1,18 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative network +HEADERS += ../shared/testhttpserver.h +SOURCES += tst_qsganimatedimage.cpp ../shared/testhttpserver.cpp +macx:CONFIG -= app_bundle + +symbian: { + importFiles.files = data + importFiles.path = . + DEPLOYMENT += importFiles +} else { + DEFINES += SRCDIR=\\\"$$PWD\\\" +} + +CONFIG += parallel_test + +QT += core-private gui-private declarative-private +QT += script-private diff --git a/tests/auto/declarative/qsganimatedimage/tst_qsganimatedimage.cpp b/tests/auto/declarative/qsganimatedimage/tst_qsganimatedimage.cpp new file mode 100644 index 0000000000..d7e87eb181 --- /dev/null +++ b/tests/auto/declarative/qsganimatedimage/tst_qsganimatedimage.cpp @@ -0,0 +1,379 @@ +/**************************************************************************** +** +** 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$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <qtest.h> +#include <QtDeclarative/qdeclarativeengine.h> +#include <QtDeclarative/qdeclarativecomponent.h> +#include <QtDeclarative/qsgview.h> +#include <private/qsgrectangle_p.h> +#include <private/qsgimage_p.h> +#include <private/qsganimatedimage_p.h> +#include <QSignalSpy> +#include <QtDeclarative/qdeclarativecontext.h> + +#include "../shared/testhttpserver.h" +#include "../../../shared/util.h" + +#ifdef Q_OS_SYMBIAN +// In Symbian OS test data is located in applications private dir +#define SRCDIR "." +#endif + +class tst_qsganimatedimage : public QObject +{ + Q_OBJECT +public: + tst_qsganimatedimage() {} + +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_qsganimatedimage::play() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/stickman.qml")); + QSGAnimatedImage *anim = qobject_cast<QSGAnimatedImage *>(component.create()); + QVERIFY(anim); + QVERIFY(anim->isPlaying()); + + delete anim; +} + +void tst_qsganimatedimage::pause() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/stickmanpause.qml")); + QSGAnimatedImage *anim = qobject_cast<QSGAnimatedImage *>(component.create()); + QVERIFY(anim); + QVERIFY(anim->isPlaying()); + QVERIFY(anim->isPaused()); + + delete anim; +} + +void tst_qsganimatedimage::stopped() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/stickmanstopped.qml")); + QSGAnimatedImage *anim = qobject_cast<QSGAnimatedImage *>(component.create()); + QVERIFY(anim); + QVERIFY(!anim->isPlaying()); + QCOMPARE(anim->currentFrame(), 0); + + delete anim; +} + +void tst_qsganimatedimage::setFrame() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/stickmanpause.qml")); + QSGAnimatedImage *anim = qobject_cast<QSGAnimatedImage *>(component.create()); + QVERIFY(anim); + QVERIFY(anim->isPlaying()); + QCOMPARE(anim->currentFrame(), 2); + + delete anim; +} + +void tst_qsganimatedimage::frameCount() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/colors.qml")); + QSGAnimatedImage *anim = qobject_cast<QSGAnimatedImage *>(component.create()); + QVERIFY(anim); + QVERIFY(anim->isPlaying()); + QCOMPARE(anim->frameCount(), 3); + + delete anim; +} + +void tst_qsganimatedimage::mirror_running() +{ + // test where mirror is set to true after animation has started + + QSGView *canvas = new QSGView; + canvas->show(); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/hearts.qml")); + QSGAnimatedImage *anim = qobject_cast<QSGAnimatedImage *>(canvas->rootObject()); + QVERIFY(anim); + + int width = anim->property("width").toInt(); + + QCOMPARE(anim->currentFrame(), 0); + QPixmap frame0 = canvas->renderPixmap(); + anim->setCurrentFrame(1); + QPixmap frame1 = canvas->renderPixmap(); + + 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 = canvas->renderPixmap(); + + QTRY_VERIFY(spy.count() == 1); spy.clear(); + QCOMPARE(anim->currentFrame(), 0); // animation only has 2 frames, should cycle back to first + QPixmap frame0_flipped = canvas->renderPixmap(); + + QSKIP("Skip while QTBUG-19351 and QTBUG-19252 are not resolved", SkipSingle); + + 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_qsganimatedimage::mirror_notRunning() +{ + QFETCH(QUrl, fileUrl); + + QSGView *canvas = new QSGView; + canvas->show(); + + canvas->setSource(fileUrl); + QSGAnimatedImage *anim = qobject_cast<QSGAnimatedImage *>(canvas->rootObject()); + QVERIFY(anim); + + int width = anim->property("width").toInt(); + QPixmap screenshot = canvas->renderPixmap(); + + 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 = canvas->renderPixmap(); + + QSKIP("Skip while QTBUG-19351 and QTBUG-19252 are not resolved", SkipSingle); + 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_qsganimatedimage::mirror_notRunning_data() +{ + QTest::addColumn<QUrl>("fileUrl"); + + QTest::newRow("paused") << QUrl::fromLocalFile(SRCDIR "/data/stickmanpause.qml"); + QTest::newRow("stopped") << QUrl::fromLocalFile(SRCDIR "/data/stickmanstopped.qml"); +} + +void tst_qsganimatedimage::remote() +{ + QFETCH(QString, fileName); + QFETCH(bool, paused); + + TestHTTPServer server(14449); + QVERIFY(server.isValid()); + server.serveDirectory(SRCDIR "/data"); + + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, QUrl("http://127.0.0.1:14449/" + fileName)); + QTRY_VERIFY(component.isReady()); + + QSGAnimatedImage *anim = qobject_cast<QSGAnimatedImage *>(component.create()); + QVERIFY(anim); + + QTRY_VERIFY(anim->isPlaying()); + if (paused) { + QTRY_VERIFY(anim->isPaused()); + QCOMPARE(anim->currentFrame(), 2); + } + QVERIFY(anim->status() != QSGAnimatedImage::Error); + + delete anim; +} + +void tst_qsganimatedimage::sourceSize() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/stickmanscaled.qml")); + QSGAnimatedImage *anim = qobject_cast<QSGAnimatedImage *>(component.create()); + QVERIFY(anim); + QCOMPARE(anim->width(),240.0); + QCOMPARE(anim->height(),180.0); + QCOMPARE(anim->sourceSize(),QSize(160,120)); + + delete anim; +} + +void tst_qsganimatedimage::sourceSizeReadOnly() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/stickmanerror1.qml")); + QVERIFY(component.isError()); + QCOMPARE(component.errors().at(0).description(), QString("Invalid property assignment: \"sourceSize\" is a read-only property")); +} + +void tst_qsganimatedimage::remote_data() +{ + QTest::addColumn<QString>("fileName"); + QTest::addColumn<bool>("paused"); + + QTest::newRow("playing") << "stickman.qml" << false; + QTest::newRow("paused") << "stickmanpause.qml" << true; +} + +void tst_qsganimatedimage::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"); + + QSGAnimatedImage *anim = qobject_cast<QSGAnimatedImage *>(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_qsganimatedimage::qtbug_16520() +{ + TestHTTPServer server(14449); + QVERIFY(server.isValid()); + server.serveDirectory(SRCDIR "/data"); + + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/qtbug-16520.qml")); + QTRY_VERIFY(component.isReady()); + + QSGRectangle *root = qobject_cast<QSGRectangle *>(component.create()); + QVERIFY(root); + QSGAnimatedImage *anim = root->findChild<QSGAnimatedImage*>("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_qsganimatedimage::progressAndStatusChanges() +{ + TestHTTPServer server(14449); + QVERIFY(server.isValid()); + server.serveDirectory(SRCDIR "/data"); + + QDeclarativeEngine engine; + QString componentStr = "import QtQuick 2.0\nAnimatedImage { source: srcImage }"; + QDeclarativeContext *ctxt = engine.rootContext(); + ctxt->setContextProperty("srcImage", QUrl::fromLocalFile(SRCDIR "/data/stickman.gif")); + QDeclarativeComponent component(&engine); + component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QSGImage *obj = qobject_cast<QSGImage*>(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->status() == QSGImage::Ready); + QTRY_VERIFY(obj->progress() == 1.0); + + QSignalSpy sourceSpy(obj, SIGNAL(sourceChanged(const QUrl &))); + QSignalSpy progressSpy(obj, SIGNAL(progressChanged(qreal))); + QSignalSpy statusSpy(obj, SIGNAL(statusChanged(QSGImageBase::Status))); + + // Loading local file + ctxt->setContextProperty("srcImage", QUrl::fromLocalFile(SRCDIR "/data/colors.gif")); + QTRY_VERIFY(obj->status() == QSGImage::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() == QSGImage::Loading); + QTRY_VERIFY(obj->progress() == 0.0); + QTRY_VERIFY(obj->status() == QSGImage::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() == QSGImage::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_qsganimatedimage) + +#include "tst_qsganimatedimage.moc" |