diff options
Diffstat (limited to 'tests/auto/qtquick1/qdeclarativeimage')
16 files changed, 0 insertions, 924 deletions
diff --git a/tests/auto/qtquick1/qdeclarativeimage/data/aspectratio.qml b/tests/auto/qtquick1/qdeclarativeimage/data/aspectratio.qml deleted file mode 100644 index cd092bc760..0000000000 --- a/tests/auto/qtquick1/qdeclarativeimage/data/aspectratio.qml +++ /dev/null @@ -1,10 +0,0 @@ -import QtQuick 1.0 - -Image { - property int widthChange: 0 - property int heightChange: 0 - source: "heart.png" - fillMode: Image.PreserveAspectFit; - onWidthChanged: widthChange += 1 - onHeightChanged: heightChange += 1 -} diff --git a/tests/auto/qtquick1/qdeclarativeimage/data/big.jpeg b/tests/auto/qtquick1/qdeclarativeimage/data/big.jpeg Binary files differdeleted file mode 100644 index bed7bd65c3..0000000000 --- a/tests/auto/qtquick1/qdeclarativeimage/data/big.jpeg +++ /dev/null diff --git a/tests/auto/qtquick1/qdeclarativeimage/data/big256.png b/tests/auto/qtquick1/qdeclarativeimage/data/big256.png Binary files differdeleted file mode 100644 index 1dc1596d03..0000000000 --- a/tests/auto/qtquick1/qdeclarativeimage/data/big256.png +++ /dev/null diff --git a/tests/auto/qtquick1/qdeclarativeimage/data/colors.png b/tests/auto/qtquick1/qdeclarativeimage/data/colors.png Binary files differdeleted file mode 100644 index dfb62f3d64..0000000000 --- a/tests/auto/qtquick1/qdeclarativeimage/data/colors.png +++ /dev/null diff --git a/tests/auto/qtquick1/qdeclarativeimage/data/colors1.png b/tests/auto/qtquick1/qdeclarativeimage/data/colors1.png Binary files differdeleted file mode 100644 index dfb62f3d64..0000000000 --- a/tests/auto/qtquick1/qdeclarativeimage/data/colors1.png +++ /dev/null diff --git a/tests/auto/qtquick1/qdeclarativeimage/data/green.png b/tests/auto/qtquick1/qdeclarativeimage/data/green.png Binary files differdeleted file mode 100644 index 0a2e153ba1..0000000000 --- a/tests/auto/qtquick1/qdeclarativeimage/data/green.png +++ /dev/null diff --git a/tests/auto/qtquick1/qdeclarativeimage/data/heart-win32.png b/tests/auto/qtquick1/qdeclarativeimage/data/heart-win32.png Binary files differdeleted file mode 100644 index 351da13772..0000000000 --- a/tests/auto/qtquick1/qdeclarativeimage/data/heart-win32.png +++ /dev/null diff --git a/tests/auto/qtquick1/qdeclarativeimage/data/heart.png b/tests/auto/qtquick1/qdeclarativeimage/data/heart.png Binary files differdeleted file mode 100644 index abe97fee4b..0000000000 --- a/tests/auto/qtquick1/qdeclarativeimage/data/heart.png +++ /dev/null diff --git a/tests/auto/qtquick1/qdeclarativeimage/data/heart.svg b/tests/auto/qtquick1/qdeclarativeimage/data/heart.svg deleted file mode 100644 index 8c982cd93c..0000000000 --- a/tests/auto/qtquick1/qdeclarativeimage/data/heart.svg +++ /dev/null @@ -1,55 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<!-- Created with Inkscape (http://www.inkscape.org/) --><svg viewBox="100 200 550 500" height="841.88976pt" id="svg1" inkscape:version="0.40+cvs" sodipodi:docbase="C:\Documents and Settings\Jon Phillips\My Documents\projects\clipart-project\submissions" sodipodi:docname="heart-left-highlight.svg" sodipodi:version="0.32" width="595.27559pt" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sodipodi="http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:svg="http://www.w3.org/2000/svg"> -<metadata> -<rdf:RDF xmlns:cc="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> -<cc:Work rdf:about=""> -<dc:title>Heart Left-Highlight</dc:title> -<dc:description>This is a normal valentines day heart.</dc:description> -<dc:subject> -<rdf:Bag> -<rdf:li>holiday</rdf:li> -<rdf:li>valentines</rdf:li> -<rdf:li></rdf:li> -<rdf:li>valentine</rdf:li> -<rdf:li>hash(0x8a091c0)</rdf:li> -<rdf:li>hash(0x8a0916c)</rdf:li> -<rdf:li>signs_and_symbols</rdf:li> -<rdf:li>hash(0x8a091f0)</rdf:li> -<rdf:li>day</rdf:li> -</rdf:Bag> -</dc:subject> -<dc:publisher> -<cc:Agent rdf:about="http://www.openclipart.org"> -<dc:title>Jon Phillips</dc:title> -</cc:Agent> -</dc:publisher> -<dc:creator> -<cc:Agent> -<dc:title>Jon Phillips</dc:title> -</cc:Agent> -</dc:creator> -<dc:rights> -<cc:Agent> -<dc:title>Jon Phillips</dc:title> -</cc:Agent> -</dc:rights> -<dc:date></dc:date> -<dc:format>image/svg+xml</dc:format> -<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/> -<cc:license rdf:resource="http://web.resource.org/cc/PublicDomain"/> -<dc:language>en</dc:language> -</cc:Work> -<cc:License rdf:about="http://web.resource.org/cc/PublicDomain"> -<cc:permits rdf:resource="http://web.resource.org/cc/Reproduction"/> -<cc:permits rdf:resource="http://web.resource.org/cc/Distribution"/> -<cc:permits rdf:resource="http://web.resource.org/cc/DerivativeWorks"/> -</cc:License> -</rdf:RDF> -</metadata> -<defs id="defs3"/> -<sodipodi:namedview bordercolor="#666666" borderopacity="1.0" id="base" inkscape:current-layer="layer1" inkscape:cx="549.40674" inkscape:cy="596.00159" inkscape:document-units="px" inkscape:guide-bbox="true" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:window-height="615" inkscape:window-width="866" inkscape:window-x="88" inkscape:window-y="116" inkscape:zoom="0.35000000" pagecolor="#ffffff" showguides="true"/> -<g id="layer1" inkscape:groupmode="layer" inkscape:label="Layer 1"> -<path d="M 263.41570,235.14588 C 197.17570,235.14588 143.41575,288.90587 143.41575,355.14588 C 143.41575,489.90139 279.34890,525.23318 371.97820,658.45392 C 459.55244,526.05056 600.54070,485.59932 600.54070,355.14588 C 600.54070,288.90588 546.78080,235.14587 480.54070,235.14588 C 432.49280,235.14588 391.13910,263.51631 371.97820,304.33338 C 352.81740,263.51630 311.46370,235.14587 263.41570,235.14588 z " id="path7" sodipodi:nodetypes="ccccccc" style="fill:#e60000;fill-opacity:1.0000000;stroke:#000000;stroke-width:18.700001;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000"/> -<path d="M 265.00000,253.59375 C 207.04033,253.59375 160.00000,300.63407 160.00000,358.59375 C 160.00000,476.50415 278.91857,507.43251 359.96875,624.00000 C 366.52868,614.08205 220.00000,478.47309 220.00000,378.59375 C 220.00000,320.63407 267.04033,273.59375 325.00000,273.59375 C 325.50453,273.59375 325.99718,273.64912 326.50000,273.65625 C 309.22436,261.07286 288.00557,253.59374 265.00000,253.59375 z " id="path220" sodipodi:nodetypes="ccccccc" style="fill:#e6e6e6;fill-opacity:0.64556962;stroke:none;stroke-width:18.700001;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000"/> -</g> -</svg> diff --git a/tests/auto/qtquick1/qdeclarativeimage/data/heart200-win32.png b/tests/auto/qtquick1/qdeclarativeimage/data/heart200-win32.png Binary files differdeleted file mode 100644 index 4976ff98ba..0000000000 --- a/tests/auto/qtquick1/qdeclarativeimage/data/heart200-win32.png +++ /dev/null diff --git a/tests/auto/qtquick1/qdeclarativeimage/data/heart200.png b/tests/auto/qtquick1/qdeclarativeimage/data/heart200.png Binary files differdeleted file mode 100644 index 7fbb13c5bb..0000000000 --- a/tests/auto/qtquick1/qdeclarativeimage/data/heart200.png +++ /dev/null diff --git a/tests/auto/qtquick1/qdeclarativeimage/data/qtbug_16389.qml b/tests/auto/qtquick1/qdeclarativeimage/data/qtbug_16389.qml deleted file mode 100644 index 29fba400ef..0000000000 --- a/tests/auto/qtquick1/qdeclarativeimage/data/qtbug_16389.qml +++ /dev/null @@ -1,30 +0,0 @@ -import QtQuick 1.0 -Rectangle { - width: 400 - height: 400 - - Item { - anchors.top: parent.top - anchors.left: parent.left - anchors.bottom: blueHandle.top - anchors.right: blueHandle.left - - Image { - id: iconImage - objectName: "iconImage" - anchors.top: parent.top - anchors.bottom: parent.bottom - source: "heart200.png" - fillMode: Image.PreserveAspectFit - smooth: true - } - } - - Rectangle { - id: blueHandle - objectName: "blueHandle" - color: "blue" - width: 25 - height: 25 - } -} diff --git a/tests/auto/qtquick1/qdeclarativeimage/data/rect.png b/tests/auto/qtquick1/qdeclarativeimage/data/rect.png Binary files differdeleted file mode 100644 index d564a2d5a5..0000000000 --- a/tests/auto/qtquick1/qdeclarativeimage/data/rect.png +++ /dev/null diff --git a/tests/auto/qtquick1/qdeclarativeimage/data/tiling.qml b/tests/auto/qtquick1/qdeclarativeimage/data/tiling.qml deleted file mode 100644 index 49715ab3e7..0000000000 --- a/tests/auto/qtquick1/qdeclarativeimage/data/tiling.qml +++ /dev/null @@ -1,16 +0,0 @@ -import QtQuick 1.0 - -Rectangle { - width: 800; height: 600 - - Image { - objectName: "vTiling"; height: 550; width: 200 - source: "green.png"; fillMode: Image.TileVertically - } - - Image { - objectName: "hTiling"; x: 225; height: 250; width: 550 - source: "green.png"; fillMode: Image.TileHorizontally - } -} - diff --git a/tests/auto/qtquick1/qdeclarativeimage/qdeclarativeimage.pro b/tests/auto/qtquick1/qdeclarativeimage/qdeclarativeimage.pro deleted file mode 100644 index 28570ab093..0000000000 --- a/tests/auto/qtquick1/qdeclarativeimage/qdeclarativeimage.pro +++ /dev/null @@ -1,12 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdeclarativeimage -macx:CONFIG -= app_bundle - -HEADERS += ../../shared/testhttpserver.h -SOURCES += tst_qdeclarativeimage.cpp ../../shared/testhttpserver.cpp - -DEFINES += SRCDIR=\\\"$$PWD\\\" - -CONFIG += parallel_test - -QT += core-private gui-private widgets-private declarative-private qtquick1-private network testlib diff --git a/tests/auto/qtquick1/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/qtquick1/qdeclarativeimage/tst_qdeclarativeimage.cpp deleted file mode 100644 index 990bf7754c..0000000000 --- a/tests/auto/qtquick1/qdeclarativeimage/tst_qdeclarativeimage.cpp +++ /dev/null @@ -1,801 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** 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 <QTextDocument> -#include <QTcpServer> -#include <QTcpSocket> -#include <QDir> - -#include <QtDeclarative/qdeclarativeengine.h> -#include <QtDeclarative/qdeclarativecomponent.h> -#include <QtQuick1/qdeclarativeview.h> -#include <QtQuick1/private/qdeclarativeimage_p.h> -#include <QtQuick1/private/qdeclarativeimagebase_p.h> -#include <QtQuick1/private/qdeclarativeloader_p.h> -#include <QtDeclarative/qdeclarativecontext.h> -#include <QtDeclarative/qdeclarativeexpression.h> -#include <QtTest/QSignalSpy> - -#include "../../shared/testhttpserver.h" - -#define SERVER_PORT 14451 -#define SERVER_ADDR "http://127.0.0.1:14451" - -class tst_qdeclarativeimage : public QObject -{ - Q_OBJECT -public: - tst_qdeclarativeimage(); - -private slots: - void noSource(); - void imageSource(); - void imageSource_data(); - void clearSource(); - void resized(); - void preserveAspectRatio(); - void smooth(); - void mirror(); - void mirror_data(); - void svg(); - void geometry(); - void geometry_data(); - void big(); - void tiling_QTBUG_6716(); - void noLoading(); - void paintedWidthHeight(); - void sourceSize_QTBUG_14303(); - void sourceSize_QTBUG_16389(); - void nullPixmapPaint(); - void resetSourceSize(); - void testQtQuick11Attributes(); - void testQtQuick11Attributes_data(); - -private: - template<typename T> - T *findItem(QGraphicsObject *parent, const QString &id, int index=-1); - - QDeclarativeEngine engine; -}; - -tst_qdeclarativeimage::tst_qdeclarativeimage() -{ -} - -void tst_qdeclarativeimage::noSource() -{ - QString componentStr = "import QtQuick 1.0\nImage { source: \"\" }"; - QDeclarativeComponent component(&engine); - component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QDeclarative1Image *obj = qobject_cast<QDeclarative1Image*>(component.create()); - QVERIFY(obj != 0); - QCOMPARE(obj->source(), QUrl()); - QVERIFY(obj->status() == QDeclarative1Image::Null); - QCOMPARE(obj->width(), 0.); - QCOMPARE(obj->height(), 0.); - QCOMPARE(obj->fillMode(), QDeclarative1Image::Stretch); - QCOMPARE(obj->progress(), 0.0); - - delete obj; -} - -void tst_qdeclarativeimage::imageSource_data() -{ - QTest::addColumn<QString>("source"); - QTest::addColumn<double>("width"); - QTest::addColumn<double>("height"); - QTest::addColumn<bool>("remote"); - QTest::addColumn<bool>("async"); - QTest::addColumn<bool>("cache"); - QTest::addColumn<QString>("error"); - - QTest::newRow("local") << QUrl::fromLocalFile(SRCDIR "/data/colors.png").toString() << 120.0 << 120.0 << false << false << true << ""; - QTest::newRow("local no cache") << QUrl::fromLocalFile(SRCDIR "/data/colors.png").toString() << 120.0 << 120.0 << false << false << false << ""; - QTest::newRow("local async") << QUrl::fromLocalFile(SRCDIR "/data/colors1.png").toString() << 120.0 << 120.0 << false << true << true << ""; - QTest::newRow("local not found") << QUrl::fromLocalFile(SRCDIR "/data/no-such-file.png").toString() << 0.0 << 0.0 << false - << false << true << "file::2:1: QML Image: Cannot open: " + QUrl::fromLocalFile(SRCDIR "/data/no-such-file.png").toString(); - QTest::newRow("local async not found") << QUrl::fromLocalFile(SRCDIR "/data/no-such-file-1.png").toString() << 0.0 << 0.0 << false - << true << true << "file::2:1: QML Image: Cannot open: " + QUrl::fromLocalFile(SRCDIR "/data/no-such-file-1.png").toString(); - QTest::newRow("remote") << SERVER_ADDR "/colors.png" << 120.0 << 120.0 << true << false << true << ""; - QTest::newRow("remote redirected") << SERVER_ADDR "/oldcolors.png" << 120.0 << 120.0 << true << false << false << ""; - QTest::newRow("remote svg") << SERVER_ADDR "/heart.svg" << 550.0 << 500.0 << true << false << false << ""; - QTest::newRow("remote not found") << SERVER_ADDR "/no-such-file.png" << 0.0 << 0.0 << true - << false << true << "file::2:1: QML Image: Error downloading " SERVER_ADDR "/no-such-file.png - server replied: Not found"; - -} - -void tst_qdeclarativeimage::imageSource() -{ - QFETCH(QString, source); - QFETCH(double, width); - QFETCH(double, height); - QFETCH(bool, remote); - QFETCH(bool, async); - QFETCH(bool, cache); - QFETCH(QString, error); - - TestHTTPServer server(SERVER_PORT); - if (remote) { - QVERIFY(server.isValid()); - server.serveDirectory(SRCDIR "/data"); - server.addRedirect("oldcolors.png", SERVER_ADDR "/colors.png"); - } - - if (!error.isEmpty()) - QTest::ignoreMessage(QtWarningMsg, error.toUtf8()); - - QString componentStr = "import QtQuick 1.1\nImage { source: \"" + source + "\"; asynchronous: " - + (async ? QLatin1String("true") : QLatin1String("false")) + "; cache: " - + (cache ? QLatin1String("true") : QLatin1String("false")) + " }"; - QDeclarativeComponent component(&engine); - component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QDeclarative1Image *obj = qobject_cast<QDeclarative1Image*>(component.create()); - QVERIFY(obj != 0); - - if (async) - QVERIFY(obj->asynchronous() == true); - else - QVERIFY(obj->asynchronous() == false); - - if (cache) - QVERIFY(obj->cache() == true); - else - QVERIFY(obj->cache() == false); - - if (remote || async) - QTRY_VERIFY(obj->status() == QDeclarative1Image::Loading); - - QCOMPARE(obj->source(), remote ? source : QUrl(source)); - - if (error.isEmpty()) { - QTRY_VERIFY(obj->status() == QDeclarative1Image::Ready); - QCOMPARE(obj->width(), qreal(width)); - QCOMPARE(obj->height(), qreal(height)); - QCOMPARE(obj->fillMode(), QDeclarative1Image::Stretch); - QCOMPARE(obj->progress(), 1.0); - } else { - QTRY_VERIFY(obj->status() == QDeclarative1Image::Error); - } - - delete obj; -} - -void tst_qdeclarativeimage::clearSource() -{ - QString componentStr = "import QtQuick 1.0\nImage { source: srcImage }"; - QDeclarativeContext *ctxt = engine.rootContext(); - ctxt->setContextProperty("srcImage", QUrl::fromLocalFile(SRCDIR "/data/colors.png")); - QDeclarativeComponent component(&engine); - component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QDeclarative1Image *obj = qobject_cast<QDeclarative1Image*>(component.create()); - QVERIFY(obj != 0); - QVERIFY(obj->status() == QDeclarative1Image::Ready); - QCOMPARE(obj->width(), 120.); - QCOMPARE(obj->height(), 120.); - QCOMPARE(obj->progress(), 1.0); - - ctxt->setContextProperty("srcImage", ""); - QVERIFY(obj->source().isEmpty()); - QVERIFY(obj->status() == QDeclarative1Image::Null); - QCOMPARE(obj->width(), 0.); - QCOMPARE(obj->height(), 0.); - QCOMPARE(obj->progress(), 0.0); - - delete obj; -} - -void tst_qdeclarativeimage::resized() -{ - QString componentStr = "import QtQuick 1.0\nImage { source: \"" SRCDIR "/data/colors.png\"; width: 300; height: 300 }"; - QDeclarativeComponent component(&engine); - component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QDeclarative1Image *obj = qobject_cast<QDeclarative1Image*>(component.create()); - QVERIFY(obj != 0); - QCOMPARE(obj->width(), 300.); - QCOMPARE(obj->height(), 300.); - QCOMPARE(obj->fillMode(), QDeclarative1Image::Stretch); - delete obj; -} - - -void tst_qdeclarativeimage::preserveAspectRatio() -{ - QDeclarativeView *canvas = new QDeclarativeView(0); - canvas->show(); - - canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/aspectratio.qml")); - QDeclarative1Image *image = qobject_cast<QDeclarative1Image*>(canvas->rootObject()); - QVERIFY(image != 0); - QCOMPARE(image->property("widthChange").toInt(), 1); - QCOMPARE(image->property("heightChange").toInt(), 1); - image->setWidth(80.0); - QCOMPARE(image->property("widthChange").toInt(), 2); - QCOMPARE(image->property("heightChange").toInt(), 2); - QCOMPARE(image->width(), 80.); - QCOMPARE(image->height(), 80.); - - canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/aspectratio.qml")); - image = qobject_cast<QDeclarative1Image*>(canvas->rootObject()); - QVERIFY(image != 0); - QCOMPARE(image->property("widthChange").toInt(), 1); - QCOMPARE(image->property("heightChange").toInt(), 1); - image->setHeight(60.0); - QCOMPARE(image->property("widthChange").toInt(), 2); - QCOMPARE(image->property("heightChange").toInt(), 2); - QCOMPARE(image->height(), 60.); - QCOMPARE(image->width(), 60.); - delete canvas; -} - -void tst_qdeclarativeimage::smooth() -{ - QString componentStr = "import QtQuick 1.0\nImage { source: \"" SRCDIR "/data/colors.png\"; smooth: true; width: 300; height: 300 }"; - QDeclarativeComponent component(&engine); - component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QDeclarative1Image *obj = qobject_cast<QDeclarative1Image*>(component.create()); - QVERIFY(obj != 0); - QCOMPARE(obj->width(), 300.); - QCOMPARE(obj->height(), 300.); - QCOMPARE(obj->smooth(), true); - QCOMPARE(obj->fillMode(), QDeclarative1Image::Stretch); - - delete obj; -} - -void tst_qdeclarativeimage::mirror() -{ - QFETCH(int, fillMode); - - qreal width = 300; - qreal height = 250; - - QString src = QUrl::fromLocalFile(SRCDIR "/data/heart200.png").toString(); - QString componentStr = "import QtQuick 1.1\nImage { source: \"" + src + "\"; }"; - - QDeclarativeComponent component(&engine); - component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QDeclarative1Image *obj = qobject_cast<QDeclarative1Image*>(component.create()); - QVERIFY(obj != 0); - - obj->setProperty("width", width); - obj->setProperty("height", height); - obj->setFillMode((QDeclarative1Image::FillMode)fillMode); - obj->setProperty("mirror", true); - - QGraphicsScene scene; - scene.addItem(qobject_cast<QGraphicsObject *>(obj)); - QPixmap screenshot(width, height); - screenshot.fill(); - QPainter p_screenshot(&screenshot); - scene.render(&p_screenshot, QRect(0, 0, width, height), QRect(0, 0, width, height)); - - QPixmap srcPixmap; - QVERIFY(srcPixmap.load(SRCDIR "/data/heart200.png")); - - QPixmap expected(width, height); - expected.fill(); - QPainter p_e(&expected); - QTransform transform; - transform.translate(width, 0).scale(-1, 1.0); - p_e.setTransform(transform); - - switch (fillMode) { - case QDeclarative1Image::Stretch: - p_e.drawPixmap(QRect(0, 0, width, height), srcPixmap, QRect(0, 0, srcPixmap.width(), srcPixmap.height())); - break; - case QDeclarative1Image::PreserveAspectFit: - QEXPECT_FAIL("", "QTBUG-19538", Continue); - p_e.drawPixmap(QRect(25, 0, width / (width/height), height), srcPixmap, QRect(0, 0, srcPixmap.width(), srcPixmap.height())); - break; - case QDeclarative1Image::PreserveAspectCrop: - { - qreal ratio = width/srcPixmap.width(); // width is the longer side - QRect rect(0, 0, srcPixmap.width()*ratio, srcPixmap.height()*ratio); - rect.moveCenter(QRect(0, 0, width, height).center()); - p_e.drawPixmap(rect, srcPixmap, QRect(0, 0, srcPixmap.width(), srcPixmap.height())); - break; - } - case QDeclarative1Image::Tile: - p_e.drawTiledPixmap(QRect(0, 0, width, height), srcPixmap); - break; - case QDeclarative1Image::TileVertically: - transform.scale(width / srcPixmap.width(), 1.0); - p_e.setTransform(transform); - p_e.drawTiledPixmap(QRect(0, 0, width, height), srcPixmap); - break; - case QDeclarative1Image::TileHorizontally: - transform.scale(1.0, height / srcPixmap.height()); - p_e.setTransform(transform); - p_e.drawTiledPixmap(QRect(0, 0, width, height), srcPixmap); - break; - } - - QCOMPARE(screenshot, expected); - - delete obj; -} - -void tst_qdeclarativeimage::mirror_data() -{ - QTest::addColumn<int>("fillMode"); - - QTest::newRow("Stretch") << int(QDeclarative1Image::Stretch); - QTest::newRow("PreserveAspectFit") << int(QDeclarative1Image::PreserveAspectFit); - QTest::newRow("PreserveAspectCrop") << int(QDeclarative1Image::PreserveAspectCrop); - QTest::newRow("Tile") << int(QDeclarative1Image::Tile); - QTest::newRow("TileVertically") << int(QDeclarative1Image::TileVertically); - QTest::newRow("TileHorizontally") << int(QDeclarative1Image::TileHorizontally); -} - -void tst_qdeclarativeimage::svg() -{ - QString src = QUrl::fromLocalFile(SRCDIR "/data/heart.svg").toString(); - QString componentStr = "import QtQuick 1.0\nImage { source: \"" + src + "\"; sourceSize.width: 300; sourceSize.height: 300 }"; - QDeclarativeComponent component(&engine); - component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QDeclarative1Image *obj = qobject_cast<QDeclarative1Image*>(component.create()); - QVERIFY(obj != 0); - QCOMPARE(obj->pixmap().width(), 300); - QCOMPARE(obj->pixmap().height(), 300); - QCOMPARE(obj->width(), 300.0); - QCOMPARE(obj->height(), 300.0); -#if defined(Q_OS_LINUX) - QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart.png")); -#elif defined(Q_OS_WIN32) - QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart-win32.png")); -#endif - - obj->setSourceSize(QSize(200,200)); - - QCOMPARE(obj->pixmap().width(), 200); - QCOMPARE(obj->pixmap().height(), 200); - QCOMPARE(obj->width(), 200.0); - QCOMPARE(obj->height(), 200.0); -#if defined(Q_OS_LINUX) - QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart200.png")); -#elif defined(Q_OS_WIN32) - QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart200-win32.png")); -#endif - delete obj; -} - -void tst_qdeclarativeimage::geometry_data() -{ - QTest::addColumn<QString>("fillMode"); - QTest::addColumn<bool>("explicitWidth"); - QTest::addColumn<bool>("explicitHeight"); - QTest::addColumn<double>("itemWidth"); - QTest::addColumn<double>("paintedWidth"); - QTest::addColumn<double>("boundingWidth"); - QTest::addColumn<double>("itemHeight"); - QTest::addColumn<double>("paintedHeight"); - QTest::addColumn<double>("boundingHeight"); - - // tested image has width 200, height 100 - - // bounding rect and item rect are equal with fillMode PreserveAspectFit, painted rect may be smaller if the aspect ratio doesn't match - QTest::newRow("PreserveAspectFit") << "PreserveAspectFit" << false << false << 200.0 << 200.0 << 200.0 << 100.0 << 100.0 << 100.0; - QTest::newRow("PreserveAspectFit explicit width 300") << "PreserveAspectFit" << true << false << 300.0 << 200.0 << 300.0 << 100.0 << 100.0 << 100.0; - QTest::newRow("PreserveAspectFit explicit height 400") << "PreserveAspectFit" << false << true << 200.0 << 200.0 << 200.0 << 400.0 << 100.0 << 400.0; - QTest::newRow("PreserveAspectFit explicit width 300, height 400") << "PreserveAspectFit" << true << true << 300.0 << 300.0 << 300.0 << 400.0 << 150.0 << 400.0; - - // bounding rect and painted rect are equal with fillMode PreserveAspectCrop, item rect may be smaller if the aspect ratio doesn't match - QTest::newRow("PreserveAspectCrop") << "PreserveAspectCrop" << false << false << 200.0 << 200.0 << 200.0 << 100.0 << 100.0 << 100.0; - QTest::newRow("PreserveAspectCrop explicit width 300") << "PreserveAspectCrop" << true << false << 300.0 << 300.0 << 300.0 << 100.0 << 150.0 << 150.0; - QTest::newRow("PreserveAspectCrop explicit height 400") << "PreserveAspectCrop" << false << true << 200.0 << 800.0 << 800.0 << 400.0 << 400.0 << 400.0; - QTest::newRow("PreserveAspectCrop explicit width 300, height 400") << "PreserveAspectCrop" << true << true << 300.0 << 800.0 << 800.0 << 400.0 << 400.0 << 400.0; - - // bounding rect, painted rect and item rect are equal in stretching and tiling images - QStringList fillModes; - fillModes << "Stretch" << "Tile" << "TileVertically" << "TileHorizontally"; - foreach (QString fillMode, fillModes) { - QTest::newRow(fillMode.toLatin1()) << fillMode << false << false << 200.0 << 200.0 << 200.0 << 100.0 << 100.0 << 100.0; - QTest::newRow(QString(fillMode + " explicit width 300").toLatin1()) << fillMode << true << false << 300.0 << 300.0 << 300.0 << 100.0 << 100.0 << 100.0; - QTest::newRow(QString(fillMode + " explicit height 400").toLatin1()) << fillMode << false << true << 200.0 << 200.0 << 200.0 << 400.0 << 400.0 << 400.0; - QTest::newRow(QString(fillMode + " explicit width 300, height 400").toLatin1()) << fillMode << true << true << 300.0 << 300.0 << 300.0 << 400.0 << 400.0 << 400.0; - } -} - -void tst_qdeclarativeimage::geometry() -{ - QFETCH(QString, fillMode); - QFETCH(bool, explicitWidth); - QFETCH(bool, explicitHeight); - QFETCH(double, itemWidth); - QFETCH(double, itemHeight); - QFETCH(double, paintedWidth); - QFETCH(double, paintedHeight); - QFETCH(double, boundingWidth); - QFETCH(double, boundingHeight); - - QString src = QUrl::fromLocalFile(SRCDIR "/data/rect.png").toString(); - QString componentStr = "import QtQuick 1.0\nImage { source: \"" + src + "\"; fillMode: Image." + fillMode + "; "; - - if (explicitWidth) - componentStr.append("width: 300; "); - if (explicitHeight) - componentStr.append("height: 400; "); - componentStr.append("}"); - QDeclarativeComponent component(&engine); - component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QDeclarative1Image *obj = qobject_cast<QDeclarative1Image*>(component.create()); - QVERIFY(obj != 0); - - QCOMPARE(obj->width(), itemWidth); - QCOMPARE(obj->paintedWidth(), paintedWidth); - QCOMPARE(obj->boundingRect().width(), boundingWidth); - - QCOMPARE(obj->height(), itemHeight); - QCOMPARE(obj->paintedHeight(), paintedHeight); - QCOMPARE(obj->boundingRect().height(), boundingHeight); - delete obj; -} - -void tst_qdeclarativeimage::big() -{ - // If the JPEG loader does not implement scaling efficiently, it would - // have to build a 400 MB image. That would be a bug in the JPEG loader. - - QString src = QUrl::fromLocalFile(SRCDIR "/data/big.jpeg").toString(); - QString componentStr = "import QtQuick 1.0\nImage { source: \"" + src + "\"; width: 100; sourceSize.height: 256 }"; - - QDeclarativeComponent component(&engine); - component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QDeclarative1Image *obj = qobject_cast<QDeclarative1Image*>(component.create()); - QVERIFY(obj != 0); - QCOMPARE(obj->pixmap().width(), 256); - QCOMPARE(obj->pixmap().height(), 256); - QCOMPARE(obj->width(), 100.0); - QCOMPARE(obj->height(), 256.0); - QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/big256.png")); - - delete obj; -} - -void tst_qdeclarativeimage::tiling_QTBUG_6716() -{ - QDeclarativeView *canvas = new QDeclarativeView(0); - canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/tiling.qml")); - canvas->show(); - qApp->processEvents(); - - QDeclarative1Image *vTiling = findItem<QDeclarative1Image>(canvas->rootObject(), "vTiling"); - QDeclarative1Image *hTiling = findItem<QDeclarative1Image>(canvas->rootObject(), "hTiling"); - - QVERIFY(vTiling != 0); - QVERIFY(hTiling != 0); - - { - QPixmap pm(vTiling->width(), vTiling->height()); - QPainter p(&pm); - vTiling->paint(&p, 0, 0); - - QImage img = pm.toImage(); - for (int x = 0; x < vTiling->width(); ++x) { - for (int y = 0; y < vTiling->height(); ++y) { - QVERIFY(img.pixel(x, y) == qRgb(0, 255, 0)); - } - } - } - - { - QPixmap pm(hTiling->width(), hTiling->height()); - QPainter p(&pm); - hTiling->paint(&p, 0, 0); - - QImage img = pm.toImage(); - for (int x = 0; x < hTiling->width(); ++x) { - for (int y = 0; y < hTiling->height(); ++y) { - QVERIFY(img.pixel(x, y) == qRgb(0, 255, 0)); - } - } - } - - delete canvas; -} - -void tst_qdeclarativeimage::noLoading() -{ - TestHTTPServer server(SERVER_PORT); - QVERIFY(server.isValid()); - server.serveDirectory(SRCDIR "/data"); - server.addRedirect("oldcolors.png", SERVER_ADDR "/colors.png"); - - QString componentStr = "import QtQuick 1.1\nImage { source: srcImage; cache: true }"; - QDeclarativeContext *ctxt = engine.rootContext(); - ctxt->setContextProperty("srcImage", QUrl::fromLocalFile(SRCDIR "/data/heart.png")); - QDeclarativeComponent component(&engine); - component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QDeclarative1Image *obj = qobject_cast<QDeclarative1Image*>(component.create()); - QVERIFY(obj != 0); - QVERIFY(obj->status() == QDeclarative1Image::Ready); - - QSignalSpy sourceSpy(obj, SIGNAL(sourceChanged(const QUrl &))); - QSignalSpy progressSpy(obj, SIGNAL(progressChanged(qreal))); - QSignalSpy statusSpy(obj, SIGNAL(statusChanged(QDeclarative1ImageBase::Status))); - - // Loading local file - ctxt->setContextProperty("srcImage", QUrl::fromLocalFile(SRCDIR "/data/green.png")); - QTRY_VERIFY(obj->status() == QDeclarative1Image::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", QString(SERVER_ADDR) + "/rect.png"); - QTRY_VERIFY(obj->status() == QDeclarative1Image::Loading); - QTRY_VERIFY(obj->progress() == 0.0); - QTRY_VERIFY(obj->status() == QDeclarative1Image::Ready); - QTRY_VERIFY(obj->progress() == 1.0); - QTRY_COMPARE(sourceSpy.count(), 2); - QTRY_COMPARE(progressSpy.count(), 2); - QTRY_COMPARE(statusSpy.count(), 2); - - // Loading remote file again - should not go through 'Loading' state. - ctxt->setContextProperty("srcImage", QUrl::fromLocalFile(SRCDIR "/data/green.png")); - ctxt->setContextProperty("srcImage", QString(SERVER_ADDR) + "/rect.png"); - QTRY_VERIFY(obj->status() == QDeclarative1Image::Ready); - QTRY_VERIFY(obj->progress() == 1.0); - QTRY_COMPARE(sourceSpy.count(), 4); - QTRY_COMPARE(progressSpy.count(), 2); - QTRY_COMPARE(statusSpy.count(), 2); - - delete obj; -} - -void tst_qdeclarativeimage::paintedWidthHeight() -{ - { - QString src = QUrl::fromLocalFile(SRCDIR "/data/heart.png").toString(); - QString componentStr = "import QtQuick 1.0\nImage { source: \"" + src + "\"; width: 200; height: 25; fillMode: Image.PreserveAspectFit }"; - - QDeclarativeComponent component(&engine); - component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QDeclarative1Image *obj = qobject_cast<QDeclarative1Image*>(component.create()); - QVERIFY(obj != 0); - QCOMPARE(obj->pixmap().width(), 300); - QCOMPARE(obj->pixmap().height(), 300); - QCOMPARE(obj->width(), 200.0); - QCOMPARE(obj->height(), 25.0); - QCOMPARE(obj->paintedWidth(), 25.0); - QCOMPARE(obj->paintedHeight(), 25.0); - QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart.png")); - - delete obj; - } - - { - QString src = QUrl::fromLocalFile(SRCDIR "/data/heart.png").toString(); - QString componentStr = "import QtQuick 1.0\nImage { source: \"" + src + "\"; width: 26; height: 175; fillMode: Image.PreserveAspectFit }"; - QDeclarativeComponent component(&engine); - component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QDeclarative1Image *obj = qobject_cast<QDeclarative1Image*>(component.create()); - QVERIFY(obj != 0); - QCOMPARE(obj->pixmap().width(), 300); - QCOMPARE(obj->pixmap().height(), 300); - QCOMPARE(obj->width(), 26.0); - QCOMPARE(obj->height(), 175.0); - QCOMPARE(obj->paintedWidth(), 26.0); - QCOMPARE(obj->paintedHeight(), 26.0); - QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart.png")); - - delete obj; - } -} - -void tst_qdeclarativeimage::sourceSize_QTBUG_14303() -{ - QString componentStr = "import QtQuick 1.0\nImage { source: srcImage }"; - QDeclarativeContext *ctxt = engine.rootContext(); - ctxt->setContextProperty("srcImage", QUrl::fromLocalFile(SRCDIR "/data/heart200.png")); - QDeclarativeComponent component(&engine); - component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QDeclarative1Image *obj = qobject_cast<QDeclarative1Image*>(component.create()); - - QSignalSpy sourceSizeSpy(obj, SIGNAL(sourceSizeChanged())); - - QTRY_VERIFY(obj != 0); - QTRY_VERIFY(obj->status() == QDeclarative1Image::Ready); - - QTRY_COMPARE(obj->sourceSize().width(), 200); - QTRY_COMPARE(obj->sourceSize().height(), 200); - QTRY_COMPARE(sourceSizeSpy.count(), 0); - - ctxt->setContextProperty("srcImage", QUrl::fromLocalFile(SRCDIR "/data/colors.png")); - QTRY_COMPARE(obj->sourceSize().width(), 120); - QTRY_COMPARE(obj->sourceSize().height(), 120); - QTRY_COMPARE(sourceSizeSpy.count(), 1); - - ctxt->setContextProperty("srcImage", QUrl::fromLocalFile(SRCDIR "/data/heart200.png")); - QTRY_COMPARE(obj->sourceSize().width(), 200); - QTRY_COMPARE(obj->sourceSize().height(), 200); - QTRY_COMPARE(sourceSizeSpy.count(), 2); - - delete obj; -} - -void tst_qdeclarativeimage::sourceSize_QTBUG_16389() -{ - QDeclarativeView *canvas = new QDeclarativeView(0); - canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/qtbug_16389.qml")); - canvas->show(); - qApp->processEvents(); - - QDeclarative1Image *image = findItem<QDeclarative1Image>(canvas->rootObject(), "iconImage"); - QDeclarativeItem *handle = findItem<QDeclarativeItem>(canvas->rootObject(), "blueHandle"); - - QCOMPARE(image->sourceSize().width(), 200); - QCOMPARE(image->sourceSize().height(), 200); - QCOMPARE(image->paintedWidth(), 0.0); - QCOMPARE(image->paintedHeight(), 0.0); - - handle->setY(20); - - QCOMPARE(image->sourceSize().width(), 200); - QCOMPARE(image->sourceSize().height(), 200); - QCOMPARE(image->paintedWidth(), 20.0); - QCOMPARE(image->paintedHeight(), 20.0); -} - -static int numberOfWarnings = 0; -static void checkWarnings(QtMsgType, const char *) -{ - numberOfWarnings++; -} - -// QTBUG-15690 -void tst_qdeclarativeimage::nullPixmapPaint() -{ - QString componentStr = QString("import QtQuick 1.0\nImage { width: 10; height:10; fillMode: Image.PreserveAspectFit; source: \"") - + SERVER_ADDR + QString("/no-such-file.png\" }"); - QDeclarativeComponent component(&engine); - component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QDeclarative1Image *image = qobject_cast<QDeclarative1Image*>(component.create()); - - QTRY_VERIFY(image != 0); - - QtMsgHandler previousMsgHandler = qInstallMsgHandler(checkWarnings); - - QPixmap pm(100, 100); - QPainter p(&pm); - - // used to print "QTransform::translate with NaN called" - image->paint(&p, 0, 0); - qInstallMsgHandler(previousMsgHandler); - QVERIFY(numberOfWarnings == 0); - delete image; -} - -void tst_qdeclarativeimage::resetSourceSize() -{ - QString src = QUrl::fromLocalFile(SRCDIR "/data/heart200.png").toString(); - QString componentStr = "import QtQuick 1.1\nImage { function reset() { sourceSize = undefined }\nsource: \"" + src + "\"; sourceSize: Qt.size(100,100) }"; - - QDeclarativeComponent component(&engine); - component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); - QDeclarative1Image *obj = qobject_cast<QDeclarative1Image*>(component.create()); - QVERIFY(obj != 0); - QCOMPARE(obj->pixmap().width(), 100); - QCOMPARE(obj->pixmap().height(), 100); - QCOMPARE(obj->sourceSize().height(), 100); - QCOMPARE(obj->sourceSize().width(), 100); - - QMetaObject::invokeMethod(obj, "reset"); - QCOMPARE(obj->pixmap().width(), 200); - QCOMPARE(obj->pixmap().height(), 200); - QCOMPARE(obj->sourceSize().height(), 200); - QCOMPARE(obj->sourceSize().width(), 200); -} - -void tst_qdeclarativeimage::testQtQuick11Attributes() -{ - QFETCH(QString, code); - QFETCH(QString, warning); - QFETCH(QString, error); - - QDeclarativeEngine engine; - QObject *obj; - - QDeclarativeComponent valid(&engine); - valid.setData("import QtQuick 1.1; Image { " + code.toUtf8() + " }", QUrl("")); - obj = valid.create(); - QVERIFY(obj); - QVERIFY(valid.errorString().isEmpty()); - delete obj; - - QDeclarativeComponent invalid(&engine); - invalid.setData("import QtQuick 1.0; Image { " + code.toUtf8() + " }", QUrl("")); - QTest::ignoreMessage(QtWarningMsg, warning.toUtf8()); - obj = invalid.create(); - QCOMPARE(invalid.errorString(), error); - delete obj; -} - -void tst_qdeclarativeimage::testQtQuick11Attributes_data() -{ - QTest::addColumn<QString>("code"); - QTest::addColumn<QString>("warning"); - QTest::addColumn<QString>("error"); - - QTest::newRow("mirror") << "mirror: true" - << "QDeclarativeComponent: Component is not ready" - << ":1 \"Image.mirror\" is not available in QtQuick 1.0.\n"; - - QTest::newRow("cache") << "cache: true" - << "QDeclarativeComponent: Component is not ready" - << ":1 \"Image.cache\" is not available in QtQuick 1.0.\n"; -} - -/* - Find an item with the specified objectName. If index is supplied then the - item must also evaluate the {index} expression equal to index -*/ -template<typename T> -T *tst_qdeclarativeimage::findItem(QGraphicsObject *parent, const QString &objectName, int index) -{ - const QMetaObject &mo = T::staticMetaObject; - //qDebug() << parent->childItems().count() << "children"; - for (int i = 0; i < parent->childItems().count(); ++i) { - QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(parent->childItems().at(i)); - if(!item) - continue; - //qDebug() << "try" << item; - if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { - if (index != -1) { - QDeclarativeExpression e(qmlContext(item), item, "index"); - if (e.evaluate().toInt() == index) - return static_cast<T*>(item); - } else { - return static_cast<T*>(item); - } - } - item = findItem<T>(item, objectName, index); - if (item) - return static_cast<T*>(item); - } - - return 0; -} - -QTEST_MAIN(tst_qdeclarativeimage) - -#include "tst_qdeclarativeimage.moc" |