diff options
author | Shawn Rutledge <[email protected]> | 2024-06-27 11:07:57 -0700 |
---|---|---|
committer | Shawn Rutledge <[email protected]> | 2024-06-28 19:59:43 -0700 |
commit | 428f64a12ed7e71cffd0d394d1560bb4e7e701c4 (patch) | |
tree | 878c48be3dfc37988ece62c467bd56df21ecdde2 /tests/auto/quick/qquicktext/tst_qquicktext.cpp | |
parent | 0debcf3ed3f62416be1c172454f420119df0587e (diff) |
Text: load inline images from resources the same as local files
QQuickText::loadResource() now loads resource images with QFile
rather than creating a QQuickPixmap "job". connectFinished() was
complaining, presumably because loading happens instantly, and we don't
need async notification when it gets done.
Fixes: QTBUG-125526
Pick-to: 6.7 6.8
Change-Id: I80f19bec82ae50e4373e64d46c0a9ad0db30a94d
Reviewed-by: Oliver Eftevaag <[email protected]>
Diffstat (limited to 'tests/auto/quick/qquicktext/tst_qquicktext.cpp')
-rw-r--r-- | tests/auto/quick/qquicktext/tst_qquicktext.cpp | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index b731f1b069..0007680962 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -2168,22 +2168,28 @@ void tst_qquicktext::embeddedImages_data() QTest::addColumn<QUrl>("qmlfile"); QTest::addColumn<QString>("error"); - QTest::newRow("local") << testFileUrl("embeddedImagesLocal.qml") << ""; + QTest::addColumn<QSize>("expectedImageSize"); + + QTest::newRow("local") << testFileUrl("embeddedImagesLocal.qml") << "" << QSize(100, 100); QTest::newRow("local-error") << testFileUrl("embeddedImagesLocalError.qml") - << testFileUrl("embeddedImagesLocalError.qml").toString()+":3:1: QML Text: Cannot open: " + testFileUrl("http/notexists.png").toString(); - QTest::newRow("local-relative") << testFileUrl("embeddedImagesLocalRelative.qml") << ""; - QTest::newRow("remote") << testFileUrl("embeddedImagesRemote.qml") << ""; + << testFileUrl("embeddedImagesLocalError.qml").toString()+":3:1: QML Text: Cannot open: " + testFileUrl("http/notexists.png").toString() + << QSize(); + QTest::newRow("local-relative") << testFileUrl("embeddedImagesLocalRelative.qml") << "" << QSize(100, 100); + QTest::newRow("remote") << testFileUrl("embeddedImagesRemote.qml") << "" << QSize(100, 100); QTest::newRow("remote-error") << testFileUrl("embeddedImagesRemoteError.qml") - << testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML Text: Error transferring {{ServerBaseUrl}}/notexists.png - server replied: Not found"; - QTest::newRow("remote-relative") << testFileUrl("embeddedImagesRemoteRelative.qml") << ""; + << testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML Text: Error transferring {{ServerBaseUrl}}/notexists.png - server replied: Not found" + << QSize(); + QTest::newRow("remote-relative") << testFileUrl("embeddedImagesRemoteRelative.qml") << "" << QSize(100, 100); + QTest::newRow("resource") << testFileUrl("embeddedImageResource.qml") << "" << QSize(16, 16); } void tst_qquicktext::embeddedImages() { - // Tests QTBUG-9900 + // Tests QTBUG-9900, QTBUG-125526 QFETCH(QUrl, qmlfile); QFETCH(QString, error); + QFETCH(QSize, expectedImageSize); TestHTTPServer server; QVERIFY2(server.listen(), qPrintable(server.errorString())); @@ -2201,14 +2207,24 @@ void tst_qquicktext::embeddedImages() QVERIFY(textObject != nullptr); QTRY_COMPARE(textObject->resourcesLoading(), 0); - QPixmap pm(testFile("http/exists.png")); - if (error.isEmpty()) { - QCOMPARE(textObject->width(), double(pm.width())); - QCOMPARE(textObject->height(), double(pm.height())); + if (expectedImageSize.isValid()) { + QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject); + QVERIFY(textPrivate != nullptr); + QVERIFY(textPrivate->extra.isAllocated()); + QTextDocument *doc = textPrivate->extra->doc; + QVERIFY(doc); + const auto formats = doc->allFormats(); + const auto it = std::find_if(formats.begin(), formats.end(), [](const auto &format){ + return format.objectType() == QTextFormat::ImageObject; + }); + QCOMPARE_NE(it, formats.end()); + const QTextImageFormat format = (*it).toImageFormat(); + QImage image = doc->resource(QTextDocument::ImageResource, format.name()).value<QImage>(); + qCDebug(lcTests) << "found image?" << format.name() << image; + QCOMPARE(image.size(), expectedImageSize); } else { - QVERIFY(16 != pm.width()); // check test is effective - QCOMPARE(textObject->width(), 16.0); // default size of QTextDocument broken image icon - QCOMPARE(textObject->height(), 16.0); + QCOMPARE(textObject->width(), 16); // default size of QTextDocument broken image icon + QCOMPARE(textObject->height(), 16); } // QTextDocument images are cached in QTextDocumentPrivate::cachedResources, |