diff options
Diffstat (limited to 'tests/auto/quick/qquickimage/tst_qquickimage.cpp')
-rw-r--r-- | tests/auto/quick/qquickimage/tst_qquickimage.cpp | 108 |
1 files changed, 75 insertions, 33 deletions
diff --git a/tests/auto/quick/qquickimage/tst_qquickimage.cpp b/tests/auto/quick/qquickimage/tst_qquickimage.cpp index 89b20c3131..d19c99de82 100644 --- a/tests/auto/quick/qquickimage/tst_qquickimage.cpp +++ b/tests/auto/quick/qquickimage/tst_qquickimage.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qtest.h> #include <QTextDocument> #include <QTcpServer> @@ -24,10 +24,13 @@ #include <QtQuickTestUtils/private/qmlutils_p.h> #include <QtQuickTestUtils/private/testhttpserver_p.h> +#include <QtQuickTestUtils/private/viewtestutils_p.h> #include <QtQuickTestUtils/private/visualtestutils_p.h> // #define DEBUG_WRITE_OUTPUT +Q_LOGGING_CATEGORY(lcTests, "qt.quick.tests") + using namespace QQuickVisualTestUtils; Q_DECLARE_METATYPE(QQuickImageBase::Status) @@ -68,6 +71,7 @@ private slots: void sourceClipRect_data(); void sourceClipRect(); void progressAndStatusChanges(); + void progressAndChangeSignalOrder(); void sourceSizeChanges(); void correctStatus(); void highdpi(); @@ -131,41 +135,49 @@ void tst_qquickimage::imageSource_data() QTest::addColumn<bool>("async"); QTest::addColumn<bool>("cache"); QTest::addColumn<QString>("error"); + QTest::addColumn<bool>("retainWhileLoading"); - QTest::newRow("local") << testFileUrl("colors.png").toString() << 120.0 << 120.0 << false << false << true << ""; - QTest::newRow("local no cache") << testFileUrl("colors.png").toString() << 120.0 << 120.0 << false << false << false << ""; - QTest::newRow("local async") << testFileUrl("colors1.png").toString() << 120.0 << 120.0 << false << true << true << ""; + QTest::newRow("local") << testFileUrl("colors.png").toString() << 120.0 << 120.0 << false << false << true << "" << false; + QTest::newRow("local no cache") << testFileUrl("colors.png").toString() << 120.0 << 120.0 << false << false << false << "" << false; + QTest::newRow("local async") << testFileUrl("colors1.png").toString() << 120.0 << 120.0 << false << true << true << "" << false; + QTest::newRow("local async retain") << testFileUrl("colors1.png").toString() << 120.0 << 120.0 << false << true << true << "" << true; QTest::newRow("local not found") << testFileUrl("no-such-file.png").toString() << 0.0 << 0.0 << false - << false << true << "<Unknown File>:2:1: QML Image: Cannot open: " + testFileUrl("no-such-file.png").toString(); + << false << true << "<Unknown File>:2:1: QML Image: Cannot open: " + testFileUrl("no-such-file.png").toString() << false; QTest::newRow("local async not found") << testFileUrl("no-such-file-1.png").toString() << 0.0 << 0.0 << false - << true << true << "<Unknown File>:2:1: QML Image: Cannot open: " + testFileUrl("no-such-file-1.png").toString(); - QTest::newRow("remote") << "/colors.png" << 120.0 << 120.0 << true << false << true << ""; - QTest::newRow("remote redirected") << "/oldcolors.png" << 120.0 << 120.0 << true << false << false << ""; + << true << true << "<Unknown File>:2:1: QML Image: Cannot open: " + testFileUrl("no-such-file-1.png").toString() << false; + QTest::newRow("local async retain not found") << testFileUrl("no-such-file-1.png").toString() << 0.0 << 0.0 << false + << true << true << "<Unknown File>:2:1: QML Image: Cannot open: " + testFileUrl("no-such-file-1.png").toString() << true; + QTest::newRow("remote") << "/colors.png" << 120.0 << 120.0 << true << false << true << "" << false; + QTest::newRow("remote retain") << "/colors.png" << 120.0 << 120.0 << true << false << true << "" << true; + QTest::newRow("remote redirected") << "/oldcolors.png" << 120.0 << 120.0 << true << false << false << "" << false; if (QImageReader::supportedImageFormats().contains("svg")) - QTest::newRow("remote svg") << "/heart.svg" << 595.0 << 841.0 << true << false << false << ""; + QTest::newRow("remote svg") << "/heart.svg" << 595.0 << 841.0 << true << false << false << "" << false; if (QImageReader::supportedImageFormats().contains("svgz")) - QTest::newRow("remote svgz") << "/heart.svgz" << 595.0 << 841.0 << true << false << false << ""; + QTest::newRow("remote svgz") << "/heart.svgz" << 595.0 << 841.0 << true << false << false << "" << false; if (graphicsApi != QSGRendererInterface::Software) { - QTest::newRow("texturefile pkm format") << testFileUrl("logo.pkm").toString() << 256.0 << 256.0 << false << false << true << ""; - QTest::newRow("texturefile ktx format") << testFileUrl("car.ktx").toString() << 146.0 << 80.0 << false << false << true << ""; - QTest::newRow("texturefile async") << testFileUrl("logo.pkm").toString() << 256.0 << 256.0 << false << true << true << ""; - QTest::newRow("texturefile remote") << "/logo.pkm" << 256.0 << 256.0 << true << false << true << ""; + QTest::newRow("texturefile pkm format") << testFileUrl("logo.pkm").toString() << 256.0 << 256.0 << false << false << true << "" << false; + QTest::newRow("texturefile ktx format") << testFileUrl("car.ktx").toString() << 146.0 << 80.0 << false << false << true << "" << false; + QTest::newRow("texturefile async") << testFileUrl("logo.pkm").toString() << 256.0 << 256.0 << false << true << true << "" << false; + QTest::newRow("texturefile async retain") << testFileUrl("logo.pkm").toString() << 256.0 << 256.0 << false << true << true << "" << true; + QTest::newRow("texturefile remote") << "/logo.pkm" << 256.0 << 256.0 << true << false << true << "" << false; + QTest::newRow("texturefile remote retain") << "/logo.pkm" << 256.0 << 256.0 << true << false << true << "" << true; } QTest::newRow("remote not found") << "/no-such-file.png" << 0.0 << 0.0 << true - << false << true << "<Unknown File>:2:1: QML Image: Error transferring {{ServerBaseUrl}}/no-such-file.png - server replied: Not found"; - QTest::newRow("extless") << testFileUrl("colors").toString() << 120.0 << 120.0 << false << false << true << ""; - QTest::newRow("extless no cache") << testFileUrl("colors").toString() << 120.0 << 120.0 << false << false << false << ""; - QTest::newRow("extless async") << testFileUrl("colors1").toString() << 120.0 << 120.0 << false << true << true << ""; + << false << true << "<Unknown File>:2:1: QML Image: Error transferring {{ServerBaseUrl}}/no-such-file.png - server replied: Not found" << false; + QTest::newRow("extless") << testFileUrl("colors").toString() << 120.0 << 120.0 << false << false << true << "" << false; + QTest::newRow("extless no cache") << testFileUrl("colors").toString() << 120.0 << 120.0 << false << false << false << "" << false; + QTest::newRow("extless async") << testFileUrl("colors1").toString() << 120.0 << 120.0 << false << true << true << "" << false; + QTest::newRow("extless async retain") << testFileUrl("colors1").toString() << 120.0 << 120.0 << false << true << true << "" << true; QTest::newRow("extless not found") << testFileUrl("no-such-file").toString() << 0.0 << 0.0 << false - << false << true << "<Unknown File>:2:1: QML Image: Cannot open: " + testFileUrl("no-such-file").toString(); + << false << true << "<Unknown File>:2:1: QML Image: Cannot open: " + testFileUrl("no-such-file").toString() << false; // Test that texture file is preferred over image file, when supported. // Since pattern.pkm has different size than pattern.png, these tests verify that the right file has been loaded if (graphicsApi != QSGRendererInterface::Software) { - QTest::newRow("extless prefer-tex") << testFileUrl("pattern").toString() << 64.0 << 64.0 << false << false << true << ""; - QTest::newRow("extless prefer-tex async") << testFileUrl("pattern").toString() << 64.0 << 64.0 << false << true << true << ""; + QTest::newRow("extless prefer-tex") << testFileUrl("pattern").toString() << 64.0 << 64.0 << false << false << true << "" << false; + QTest::newRow("extless prefer-tex async") << testFileUrl("pattern").toString() << 64.0 << 64.0 << false << true << true << "" << false; } else { - QTest::newRow("extless ignore-tex") << testFileUrl("pattern").toString() << 200.0 << 200.0 << false << false << true << ""; - QTest::newRow("extless ignore-tex async") << testFileUrl("pattern").toString() << 200.0 << 200.0 << false << true << true << ""; + QTest::newRow("extless ignore-tex") << testFileUrl("pattern").toString() << 200.0 << 200.0 << false << false << true << "" << false; + QTest::newRow("extless ignore-tex async") << testFileUrl("pattern").toString() << 200.0 << 200.0 << false << true << true << "" << false; } } @@ -179,6 +191,7 @@ void tst_qquickimage::imageSource() QFETCH(bool, async); QFETCH(bool, cache); QFETCH(QString, error); + QFETCH(bool, retainWhileLoading); TestHTTPServer server; if (remote) { @@ -192,9 +205,10 @@ void tst_qquickimage::imageSource() if (!error.isEmpty()) QTest::ignoreMessage(QtWarningMsg, error.toUtf8()); - QString componentStr = "import QtQuick 2.0\nImage { source: \"" + source + "\"; asynchronous: " + QString componentStr = "import QtQuick\nImage { source: \"" + source + "\"; asynchronous: " + (async ? QLatin1String("true") : QLatin1String("false")) + "; cache: " - + (cache ? QLatin1String("true") : QLatin1String("false")) + " }"; + + (cache ? QLatin1String("true") : QLatin1String("false")) + "; retainWhileLoading: " + + (retainWhileLoading ? QLatin1String("true") : QLatin1String("false")) + " }"; QQmlComponent component(&engine); component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickImage *obj = qobject_cast<QQuickImage*>(component.create()); @@ -205,6 +219,8 @@ void tst_qquickimage::imageSource() else QVERIFY(!obj->asynchronous()); + QCOMPARE(obj->retainWhileLoading(), retainWhileLoading); + if (cache) QVERIFY(obj->cache()); else @@ -308,15 +324,19 @@ void tst_qquickimage::mirror() QSKIP("Skipping due to grabWindow not functional on minimal platforms"); QMap<QQuickImage::FillMode, QImage> screenshots; - QList<QQuickImage::FillMode> fillModes; - fillModes << QQuickImage::Stretch << QQuickImage::PreserveAspectFit << QQuickImage::PreserveAspectCrop - << QQuickImage::Tile << QQuickImage::TileVertically << QQuickImage::TileHorizontally << QQuickImage::Pad; + const QList<QQuickImage::FillMode> fillModes{QQuickImage::Stretch, + QQuickImage::PreserveAspectFit, + QQuickImage::PreserveAspectCrop, + QQuickImage::Tile, + QQuickImage::TileVertically, + QQuickImage::TileHorizontally, + QQuickImage::Pad}; qreal width = 300; qreal height = 250; qreal devicePixelRatio = 1.0; - foreach (QQuickImage::FillMode fillMode, fillModes) { + for (QQuickImage::FillMode fillMode : fillModes) { QScopedPointer<QQuickView> window(new QQuickView); window->setSource(testFileUrl("mirror.qml")); @@ -333,7 +353,7 @@ void tst_qquickimage::mirror() devicePixelRatio = window->devicePixelRatio(); } - foreach (QQuickImage::FillMode fillMode, fillModes) { + for (QQuickImage::FillMode fillMode : fillModes) { QPixmap srcPixmap; QVERIFY(srcPixmap.load(testFile("pattern.png"))); @@ -453,9 +473,8 @@ void tst_qquickimage::geometry_data() 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) { + QStringList fillModes{"Stretch", "Tile", "TileVertically", "TileHorizontally"}; + for (const auto &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; @@ -975,6 +994,28 @@ void tst_qquickimage::progressAndStatusChanges() delete obj; } +void tst_qquickimage::progressAndChangeSignalOrder() +{ + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("statusChanged.qml"))); + QQuickImage *image = qmlobject_cast<QQuickImage *>(window.rootObject()); + QVERIFY(image); + + QTRY_COMPARE(image->status(), QQuickImageBase::Ready); + // QTBUG-120205: implicitSize should be correct when status changes to Ready + QCOMPARE(image->property("statusChangedFirstImplicitSize").toSize(), QSize(300, 300)); + QCOMPARE(image->property("statusChanges").toList().size(), 1); // just Ready + const QStringList signalOrder = image->property("changeSignals").toStringList(); + const QStringList expectedOrder = {"progress", "paintedHeight", "paintedWidth", + "implicitWidth", "implicitHeight", + "paintedHeight", "paintedWidth", + "status", "sourceSize", "frameCount"}; + qCDebug(lcTests) << "signal order" << signalOrder; + // exact order may not be critical, and repeated signals may be silly; + // but this way we'll find out when it changes + QCOMPARE(signalOrder, expectedOrder); +} + class TestQImageProvider : public QQuickImageProvider { public: @@ -1179,6 +1220,7 @@ void tst_qquickimage::multiFrame_data() QTest::addRow("default") << "multiframe.qml" << false; QTest::addRow("async") << "multiframeAsync.qml" << true; + QTest::addRow("async retain") << "multiframeAsyncRetain.qml" << true; } void tst_qquickimage::multiFrame() |