Add baseline test for text rendering
Data-driven test case that renders the HTML files into an 800x600 image for baseline comparison. Task-number: QTBUG-99148 Pick-to: 6.3 Change-Id: I9ccc0cd21a1e94ff68d23bb82b84e1da46d6335a Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
parent
24572fccae
commit
be8792d4fe
@ -4,4 +4,5 @@ endif()
|
||||
if(TARGET Qt::Network AND TARGET Qt::Widgets)
|
||||
add_subdirectory(widgets)
|
||||
add_subdirectory(stylesheet)
|
||||
add_subdirectory(text)
|
||||
endif()
|
||||
|
16
tests/baseline/text/CMakeLists.txt
Normal file
16
tests/baseline/text/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
list(APPEND test_data "./data")
|
||||
|
||||
qt_internal_add_test(tst_baseline_text
|
||||
SOURCES
|
||||
../shared/baselineprotocol.cpp ../shared/baselineprotocol.h ../shared/lookup3.cpp
|
||||
../shared/qbaselinetest.cpp ../shared/qbaselinetest.h
|
||||
../shared/qwidgetbaselinetest.cpp ../shared/qwidgetbaselinetest.h
|
||||
tst_baseline_text.cpp
|
||||
INCLUDE_DIRECTORIES
|
||||
../shared
|
||||
PUBLIC_LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::Widgets
|
||||
Qt::Network
|
||||
TESTDATA ${test_data}
|
||||
)
|
0
tests/baseline/text/data/empty.html
Normal file
0
tests/baseline/text/data/empty.html
Normal file
8
tests/baseline/text/data/list_items_with_code.html
Normal file
8
tests/baseline/text/data/list_items_with_code.html
Normal file
@ -0,0 +1,8 @@
|
||||
<!-- QTBUG-99148 -->
|
||||
<h1>Header</h1>
|
||||
<ol>
|
||||
<li><p>Something (<code>this is code</code> something else)</p></li>
|
||||
<li><p>Maybe <code>this is code</code> or not?</p></li>
|
||||
<li><p><code>this is code</code> and it seems to break</p></li>
|
||||
<li><p>This has no code</p></li>
|
||||
</ol>
|
122
tests/baseline/text/tst_baseline_text.cpp
Normal file
122
tests/baseline/text/tst_baseline_text.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2021 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$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <qbaselinetest.h>
|
||||
#include <qwidgetbaselinetest.h>
|
||||
#include <QtWidgets>
|
||||
|
||||
class tst_Text : public QWidgetBaselineTest
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
tst_Text();
|
||||
|
||||
void loadTestFiles();
|
||||
|
||||
private slots:
|
||||
void tst_render_data();
|
||||
void tst_render();
|
||||
|
||||
private:
|
||||
QDir htmlDir;
|
||||
};
|
||||
|
||||
tst_Text::tst_Text()
|
||||
{
|
||||
QString baseDir = QFINDTESTDATA("data/empty.html");
|
||||
htmlDir = QDir(QFileInfo(baseDir).path());
|
||||
}
|
||||
|
||||
void tst_Text::loadTestFiles()
|
||||
{
|
||||
QTest::addColumn<QString>("html");
|
||||
|
||||
QStringList htmlFiles;
|
||||
// first add generic test files
|
||||
for (const auto &qssFile : htmlDir.entryList({QStringLiteral("*.html")}, QDir::Files | QDir::Readable))
|
||||
htmlFiles << htmlDir.absoluteFilePath(qssFile);
|
||||
|
||||
// then test-function specific files
|
||||
const QString testFunction = QString(QTest::currentTestFunction()).remove("tst_").toLower();
|
||||
if (htmlDir.cd(testFunction)) {
|
||||
for (const auto &htmlFile : htmlDir.entryList({QStringLiteral("*.html")}, QDir::Files | QDir::Readable))
|
||||
htmlFiles << htmlDir.absoluteFilePath(htmlFile);
|
||||
htmlDir.cdUp();
|
||||
}
|
||||
|
||||
for (const auto &htmlFile : htmlFiles) {
|
||||
QFileInfo fileInfo(htmlFile);
|
||||
QFile file(htmlFile);
|
||||
file.open(QFile::ReadOnly);
|
||||
QString html = QString::fromUtf8(file.readAll());
|
||||
QBaselineTest::newRow(fileInfo.baseName().toUtf8()) << html;
|
||||
}
|
||||
}
|
||||
|
||||
void tst_Text::tst_render_data()
|
||||
{
|
||||
loadTestFiles();
|
||||
}
|
||||
|
||||
void tst_Text::tst_render()
|
||||
{
|
||||
QFETCH(QString, html);
|
||||
|
||||
QTextDocument textDocument;
|
||||
textDocument.setPageSize(QSizeF(800, 600));
|
||||
textDocument.setHtml(html);
|
||||
|
||||
QImage image(800, 600, QImage::Format_ARGB32);
|
||||
image.fill(Qt::white);
|
||||
|
||||
{
|
||||
QPainter painter(&image);
|
||||
|
||||
QAbstractTextDocumentLayout::PaintContext context;
|
||||
context.palette.setColor(QPalette::Text, Qt::black);
|
||||
textDocument.documentLayout()->draw(&painter, context);
|
||||
}
|
||||
|
||||
QBASELINE_TEST(image);
|
||||
}
|
||||
|
||||
|
||||
#define main _realmain
|
||||
QTEST_MAIN(tst_Text)
|
||||
#undef main
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
qSetGlobalQHashSeed(0); // Avoid rendering variations caused by QHash randomization
|
||||
|
||||
QBaselineTest::handleCmdLineArgs(&argc, &argv);
|
||||
return _realmain(argc, argv);
|
||||
}
|
||||
|
||||
#include "tst_baseline_text.moc"
|
Loading…
Reference in New Issue
Block a user