summaryrefslogtreecommitdiffstats
path: root/tests/baseline/text
diff options
context:
space:
mode:
Diffstat (limited to 'tests/baseline/text')
-rw-r--r--tests/baseline/text/CMakeLists.txt20
-rw-r--r--tests/baseline/text/data/colored_list.html68
-rw-r--r--tests/baseline/text/data/empty.html0
-rw-r--r--tests/baseline/text/data/list_items_with_code.html8
-rw-r--r--tests/baseline/text/tst_baseline_text.cpp119
5 files changed, 215 insertions, 0 deletions
diff --git a/tests/baseline/text/CMakeLists.txt b/tests/baseline/text/CMakeLists.txt
new file mode 100644
index 0000000000..74d01337cb
--- /dev/null
+++ b/tests/baseline/text/CMakeLists.txt
@@ -0,0 +1,20 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+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
+ LIBRARIES
+ Qt::Gui
+ Qt::Widgets
+ Qt::WidgetsPrivate
+ Qt::Network
+ TESTDATA ${test_data}
+)
diff --git a/tests/baseline/text/data/colored_list.html b/tests/baseline/text/data/colored_list.html
new file mode 100644
index 0000000000..d1cca94460
--- /dev/null
+++ b/tests/baseline/text/data/colored_list.html
@@ -0,0 +1,68 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+<html>
+<head>
+<style type="text/css">
+p, li { white-space: pre-wrap; }
+hr { height: 1px; border-width: 0; }
+li.unchecked::marker { content: "\2610"; }
+li.checked::marker { content: "\2612"; }
+body { background-color: #111155; color: #ffffff; }
+</style>
+</head>
+<body>
+
+<ul>
+<li>disc</li>
+<li style=" color:#a58d47;">bronze</li>
+<li style=" color:red;"><span style=" color:#ffcdb9;">red bullet, pink text</span></li>
+<li style=" color:#dddddd;" class="checked">checked</li>
+<li style=" color:#dddddd;" class="unchecked">unchecked</li>
+</ul>
+
+<ul type="circle">
+<li>circle</li>
+<li style=" color:#dddddd;">silver</li>
+<li style=" color:lightgrey;"><span style=" color:#ffcdb9;">grey bullet, pink text</span></li>
+<li style=" color:#dddddd;" class="checked">checked</li>
+<li style=" color:#dddddd;" class="unchecked">unchecked</li>
+</ul>
+
+<ul type="square">
+<li style=" color:#ffffff;">square</li>
+<li style=" color:#fceebb;">gold</li>
+<li style=" color:yellow;"><span style=" color:#ffcdb9;">yellow bullet, pink text</span></li>
+<li style=" color:#dddddd;" class="checked">checked</li>
+<li style=" color:#dddddd;" class="unchecked">unchecked</li>
+</ul>
+
+<ol>
+<li>decimal</li>
+<li style=" color:#a58d47;">bronze decimal</li>
+<li style=" color:red;"><span style=" color:#ffcdb9;">red number, pink text</span></li>
+</ol>
+
+<ol type="A">
+<li>uppercase</li>
+<li style=" color:#a58d47;">bronze uppercase</li>
+<li style=" color:red;"><span style=" color:#ffcdb9;">red letter, pink text</span></li>
+</ol>
+
+<ol type="a">
+<li>lowercase</li>
+<li style=" color:#a58d47;">bronze lowercase</li>
+<li style=" color:red;"><span style=" color:#ffcdb9;">red letter, pink text</span></li>
+</ol>
+
+<ol type="i">
+<li>lower roman</li>
+<li style=" color:#a58d47;">bronze roman</li>
+<li style=" color:red;"><span style=" color:#ffcdb9;">red number, pink text</span></li>
+</ol>
+
+<ol type="I">
+<li>upper roman</li>
+<li style=" color:#a58d47;">bronze roman</li>
+<li style=" color:red;"><span style=" color:#ffcdb9;">red number, pink text</span></li>
+</ol>
+</body>
+</html>
diff --git a/tests/baseline/text/data/empty.html b/tests/baseline/text/data/empty.html
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/baseline/text/data/empty.html
diff --git a/tests/baseline/text/data/list_items_with_code.html b/tests/baseline/text/data/list_items_with_code.html
new file mode 100644
index 0000000000..f2823c8065
--- /dev/null
+++ b/tests/baseline/text/data/list_items_with_code.html
@@ -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>
diff --git a/tests/baseline/text/tst_baseline_text.cpp b/tests/baseline/text/tst_baseline_text.cpp
new file mode 100644
index 0000000000..59a5f478a5
--- /dev/null
+++ b/tests/baseline/text/tst_baseline_text.cpp
@@ -0,0 +1,119 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#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();
+ void tst_differentScriptsBackgrounds();
+
+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);
+ QVERIFY(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);
+}
+
+void tst_Text::tst_differentScriptsBackgrounds()
+{
+ QTextDocument textDocument;
+ textDocument.setPageSize(QSizeF(800, 600));
+ textDocument.setHtml(QString::fromUtf8("<i><font style=\"font-size:72px\"><font style=\"background:#FFFF00\">イ雨エ</font></font></i>"));
+
+ 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_CHECK(image, "tst_differentScriptsBackgrounds");
+}
+
+
+#define main _realmain
+QTEST_MAIN(tst_Text)
+#undef main
+
+int main(int argc, char *argv[])
+{
+ // Avoid rendering variations caused by QHash randomization
+ QHashSeed::setDeterministicGlobalSeed();
+
+ QBaselineTest::handleCmdLineArgs(&argc, &argv);
+ return _realmain(argc, argv);
+}
+
+#include "tst_baseline_text.moc"