summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp')
-rw-r--r--tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp60
1 files changed, 26 insertions, 34 deletions
diff --git a/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp b/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp
index d5dde13770..5311aa6f2b 100644
--- a/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp
+++ b/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
- **
- ** Copyright (C) 2020 The Qt Company Ltd.
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the test suite of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 3 as published by the Free Software
- ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -42,6 +17,7 @@ private slots:
void init();
void cleanup();
void cleanupTestCase();
+ void loadAtNImages_data();
void loadAtNImages();
};
@@ -61,24 +37,40 @@ void tst_QTextImageHandler::cleanupTestCase()
{
}
+void tst_QTextImageHandler::loadAtNImages_data()
+{
+ QTest::addColumn<QString>("imageFile");
+
+ QTest::addRow("file") << QFINDTESTDATA("data/image.png");
+ QTest::addRow("file_url") << QUrl::fromLocalFile(QFINDTESTDATA("data/image.png")).toString();
+ QTest::addRow("resource") << ":/data/image.png";
+ QTest::addRow("qrc_url") << "qrc:/data/image.png";
+}
+
void tst_QTextImageHandler::loadAtNImages()
{
+ QFETCH(QString, imageFile);
+
QTextDocument doc;
QTextCursor c(&doc);
- c.insertHtml("<img src=\"data/image.png\">");
+ c.insertHtml("<img src=\"" + imageFile + "\">");
+ const auto formats = doc.allFormats();
+ const auto it = std::find_if(formats.begin(), formats.end(), [](const auto &format){
+ return format.objectType() == QTextFormat::ImageObject;
+ });
+ QVERIFY(it != formats.end());
+ const QTextImageFormat format = (*it).toImageFormat();
QTextImageHandler handler;
- QTextImageFormat fmt;
- fmt.setName("data/image.png");
- for (int i = 1; i < 3; ++i) {
+ for (const auto &dpr : {1, 2}) {
QImage img(20, 20, QImage::Format_ARGB32_Premultiplied);
img.fill(Qt::white);
- img.setDevicePixelRatio(i);
+ img.setDevicePixelRatio(dpr);
QPainter p(&img);
- handler.drawObject(&p, QRect(0, 0, 20, 20), &doc, 0, fmt);
+ handler.drawObject(&p, QRect(0, 0, 20, 20), &doc, 0, format);
p.end();
QVERIFY(!img.isNull());
- const auto expectedColor = i == 1 ? Qt::red : Qt::green;
+ const auto expectedColor = dpr == 1 ? Qt::red : Qt::green;
QCOMPARE(img.pixelColor(0, 0), expectedColor);
}
}