mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-06 17:25:24 +08:00
qt 6.5.1 original
This commit is contained in:
23
tests/auto/gui/text/qtextimagehandler/CMakeLists.txt
Normal file
23
tests/auto/gui/text/qtextimagehandler/CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
list(APPEND test_data "data/image.png")
|
||||
list(APPEND test_data "data/image@2x.png")
|
||||
|
||||
qt_internal_add_test(tst_qtextimagehandler
|
||||
SOURCES
|
||||
tst_qtextimagehandler.cpp
|
||||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::Gui
|
||||
Qt::GuiPrivate
|
||||
TESTDATA
|
||||
${test_data}
|
||||
)
|
||||
|
||||
qt_internal_add_resource(tst_qtextimagehandler "qtextimagehandler"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
${test_data}
|
||||
)
|
BIN
tests/auto/gui/text/qtextimagehandler/data/image.png
Normal file
BIN
tests/auto/gui/text/qtextimagehandler/data/image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 101 B |
BIN
tests/auto/gui/text/qtextimagehandler/data/image@2x.png
Normal file
BIN
tests/auto/gui/text/qtextimagehandler/data/image@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 102 B |
@ -0,0 +1,79 @@
|
||||
// Copyright (C) 2022 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QTest>
|
||||
|
||||
#include <QPainter>
|
||||
#include <private/qtextimagehandler_p.h>
|
||||
|
||||
class tst_QTextImageHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
tst_QTextImageHandler();
|
||||
|
||||
private slots:
|
||||
void init();
|
||||
void cleanup();
|
||||
void cleanupTestCase();
|
||||
void loadAtNImages_data();
|
||||
void loadAtNImages();
|
||||
};
|
||||
|
||||
tst_QTextImageHandler::tst_QTextImageHandler()
|
||||
{
|
||||
}
|
||||
|
||||
void tst_QTextImageHandler::init()
|
||||
{
|
||||
}
|
||||
|
||||
void tst_QTextImageHandler::cleanup()
|
||||
{
|
||||
}
|
||||
|
||||
void tst_QTextImageHandler::cleanupTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void tst_QTextImageHandler::loadAtNImages_data()
|
||||
{
|
||||
QTest::addColumn<QString>("imageFile");
|
||||
|
||||
QTest::addRow("file") << QFINDTESTDATA("data/image.png");
|
||||
QTest::addRow("file_url") << QString("file:/") + QFINDTESTDATA("data/image.png");
|
||||
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=\"" + 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;
|
||||
|
||||
for (const auto &dpr : {1, 2}) {
|
||||
QImage img(20, 20, QImage::Format_ARGB32_Premultiplied);
|
||||
img.fill(Qt::white);
|
||||
img.setDevicePixelRatio(dpr);
|
||||
QPainter p(&img);
|
||||
handler.drawObject(&p, QRect(0, 0, 20, 20), &doc, 0, format);
|
||||
p.end();
|
||||
QVERIFY(!img.isNull());
|
||||
const auto expectedColor = dpr == 1 ? Qt::red : Qt::green;
|
||||
QCOMPARE(img.pixelColor(0, 0), expectedColor);
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QTextImageHandler)
|
||||
#include "tst_qtextimagehandler.moc"
|
Reference in New Issue
Block a user