summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/text')
-rw-r--r--tests/auto/gui/text/qfont/tst_qfont.cpp7
-rw-r--r--tests/auto/gui/text/qfontdatabase/testdata.qrc1
-rw-r--r--tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp29
-rw-r--r--tests/auto/gui/text/qsyntaxhighlighter/qsyntaxhighlighter.pro2
-rw-r--r--tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp65
-rw-r--r--tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp38
-rw-r--r--tests/auto/gui/text/qtextdocumentlayout/qtextdocumentlayout.pro2
-rw-r--r--tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp99
-rw-r--r--tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp9
-rw-r--r--tests/auto/gui/text/qtexttable/tst_qtexttable.cpp2
10 files changed, 250 insertions, 4 deletions
diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp
index d722856366..9487436336 100644
--- a/tests/auto/gui/text/qfont/tst_qfont.cpp
+++ b/tests/auto/gui/text/qfont/tst_qfont.cpp
@@ -301,6 +301,13 @@ void tst_QFont::resolve()
font5.setFamilies(fontFamilies);
font6 = font6.resolve(font5);
QCOMPARE(font6.families(), fontFamilies);
+
+ QFont font7, font8;
+ font7.setFamily(QLatin1String("Helvetica"));
+ font8.setFamilies(fontFamilies);
+ font7 = font7.resolve(font8);
+ QCOMPARE(font7.families(), QStringList({"Helvetica", "Arial"}));
+ QCOMPARE(font7.family(), "Helvetica");
}
#ifndef QT_NO_WIDGETS
diff --git a/tests/auto/gui/text/qfontdatabase/testdata.qrc b/tests/auto/gui/text/qfontdatabase/testdata.qrc
index 224e845601..a590099b20 100644
--- a/tests/auto/gui/text/qfontdatabase/testdata.qrc
+++ b/tests/auto/gui/text/qfontdatabase/testdata.qrc
@@ -4,5 +4,6 @@
<file alias="testfont.ttf">../../../shared/resources/testfont.ttf</file>
<file alias="testfont_condensed.ttf">../../../shared/resources/testfont_condensed.ttf</file>
<file alias="testfont_italic.ttf">../../../shared/resources/testfont_italic.ttf</file>
+ <file alias="testfont_open.otf">../../../shared/resources/testfont_open.otf</file>
</qresource>
</RCC>
diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
index 2b69801b59..12e8083622 100644
--- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
+++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
@@ -76,6 +76,9 @@ private slots:
void rasterFonts();
void smoothFonts();
+ void registerOpenTypePreferredNamesSystem();
+ void registerOpenTypePreferredNamesApplication();
+
private:
QString m_ledFont;
QString m_testFont;
@@ -440,5 +443,31 @@ void tst_QFontDatabase::smoothFonts()
QVERIFY(!QFontDatabase().isBitmapScalable(font.family()));
}
+void tst_QFontDatabase::registerOpenTypePreferredNamesSystem()
+{
+ QFontDatabase db;
+ // This font family was picked because it was the only one I had installed which showcased the
+ // problem
+ if (!db.hasFamily(QString::fromLatin1("Source Code Pro ExtraLight")))
+ QSKIP("Source Code Pro ExtraLight is not installed");
+
+ QStringList styles = db.styles(QString::fromLatin1("Source Code Pro"));
+ QVERIFY(styles.contains(QLatin1String("ExtraLight")));
+}
+
+void tst_QFontDatabase::registerOpenTypePreferredNamesApplication()
+{
+ QFontDatabase db;
+
+ int id = QFontDatabase::addApplicationFont(QString::fromLatin1(":/testfont_open.otf"));
+ if (id == -1)
+ QSKIP("Skip the test since app fonts are not supported on this system");
+
+ QStringList styles = db.styles(QString::fromLatin1("QtBidiTestFont"));
+ QVERIFY(styles.contains(QLatin1String("Open")));
+
+ QFontDatabase::removeApplicationFont(id);
+}
+
QTEST_MAIN(tst_QFontDatabase)
#include "tst_qfontdatabase.moc"
diff --git a/tests/auto/gui/text/qsyntaxhighlighter/qsyntaxhighlighter.pro b/tests/auto/gui/text/qsyntaxhighlighter/qsyntaxhighlighter.pro
index a78c429433..c91eaad944 100644
--- a/tests/auto/gui/text/qsyntaxhighlighter/qsyntaxhighlighter.pro
+++ b/tests/auto/gui/text/qsyntaxhighlighter/qsyntaxhighlighter.pro
@@ -2,4 +2,4 @@ CONFIG += testcase
TARGET = tst_qsyntaxhighlighter
SOURCES += tst_qsyntaxhighlighter.cpp
QT += testlib
-qtHaveModule(widgets) QT += widgets
+qtHaveModule(widgets): QT += widgets
diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
index 52e56feb5a..10a627bb82 100644
--- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
+++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
@@ -125,6 +125,7 @@ private slots:
void clonePreservesResources();
void clonePreservesUserStates();
void clonePreservesIndentWidth();
+ void clonePreservesFormatsWhenEmpty();
void blockCount();
void defaultStyleSheet();
@@ -193,6 +194,8 @@ private slots:
void fontTagFace();
void clearUndoRedoStacks();
+ void mergeFontFamilies();
+
private:
void backgroundImage_checkExpectedHtml(const QTextDocument &doc);
void buildRegExpData();
@@ -1793,6 +1796,12 @@ void tst_QTextDocument::toHtml()
QCOMPARE(output, expectedOutput);
QDomDocument document;
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ QEXPECT_FAIL("charfmt-for-list-item",
+ "The attribute \"style\" is redefined in the generated HTML, which is not valid "
+ "according to XML standard. The new QDomDocument implementation follows the XML "
+ "standard.", Continue);
+#endif
QVERIFY2(document.setContent(output), "Output was not valid XML");
}
@@ -2342,6 +2351,32 @@ void tst_QTextDocument::clonePreservesIndentWidth()
delete clone;
}
+void tst_QTextDocument::clonePreservesFormatsWhenEmpty()
+{
+ QTextDocument document;
+ QTextCursor cursor(&document);
+
+ // Change a few char format attributes
+ QTextCharFormat charFormat;
+ charFormat.setFontPointSize(charFormat.fontPointSize() + 1);
+ charFormat.setFontWeight(charFormat.fontWeight() + 1);
+ cursor.setBlockCharFormat(charFormat);
+
+ // Change a few block format attributes
+ QTextBlockFormat blockFormat;
+ blockFormat.setAlignment(Qt::AlignRight); // The default is Qt::AlignLeft
+ blockFormat.setIndent(blockFormat.indent() + 1);
+ cursor.setBlockFormat(blockFormat);
+
+ auto clone = document.clone();
+ QTextCursor cloneCursor(clone);
+
+ QCOMPARE(cloneCursor.blockCharFormat().fontPointSize(), charFormat.fontPointSize());
+ QCOMPARE(cloneCursor.blockCharFormat().fontWeight(), charFormat.fontWeight());
+ QCOMPARE(cloneCursor.blockFormat().alignment(), blockFormat.alignment());
+ QCOMPARE(cloneCursor.blockFormat().indent(), blockFormat.indent());
+}
+
void tst_QTextDocument::blockCount()
{
QCOMPARE(doc->blockCount(), 1);
@@ -3552,6 +3587,36 @@ void tst_QTextDocument::fontTagFace()
}
}
+void tst_QTextDocument::mergeFontFamilies()
+{
+ QTextDocument td;
+ td.setHtml(QLatin1String(
+ "<html><body>"
+ "<span style=\" font-family:'MS Shell Dlg 2';\">Hello world</span>"
+ "</body></html>"));
+
+ QTextCharFormat newFormat;
+ newFormat.setFontFamily(QLatin1String("Jokerman"));
+
+ QTextCursor cursor = QTextCursor(&td);
+ cursor.setPosition(0);
+ cursor.setPosition(QByteArray("Hello World").length(), QTextCursor::KeepAnchor);
+ cursor.mergeCharFormat(newFormat);
+
+ QVERIFY(td.toHtml().contains(QLatin1String("font-family:'MS Shell Dlg 2','Jokerman';")));
+
+ QTextCharFormat newFormatFamilies;
+ newFormatFamilies.setFontFamilies({ QLatin1String("Arial"), QLatin1String("Helvetica") });
+ cursor.mergeCharFormat(newFormatFamilies);
+
+ QVERIFY(td.toHtml().contains(QLatin1String("font-family:'Arial','Helvetica','Jokerman'")));
+
+ newFormatFamilies.setFontFamilies({ QLatin1String("Arial"), QLatin1String("Jokerman"), QLatin1String("Helvetica") });
+ cursor.mergeCharFormat(newFormatFamilies);
+
+ QVERIFY(td.toHtml().contains(QLatin1String("font-family:'Arial','Jokerman','Helvetica'")));
+}
+
void tst_QTextDocument::clearUndoRedoStacks()
{
QTextDocument doc;
diff --git a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
index b6917f1208..2f5936cf74 100644
--- a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
+++ b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
@@ -182,6 +182,8 @@ private slots:
void css_bodyBackground();
void css_tableCellBackground();
void css_tableCellBorder();
+ void css_tableCellBorderWidthOneValue();
+ void css_tableCellBorderWidthTwoValues();
void css_tableCellBorderShorthand();
void css_tableCellAllBordersShorthand();
void css_tableCellOverrideOneBorder();
@@ -1787,6 +1789,42 @@ void tst_QTextDocumentFragment::css_tableCellBorder()
QCOMPARE(cellFormat.topBorderStyle(), QTextFrameFormat::BorderStyle_Groove);
}
+void tst_QTextDocumentFragment::css_tableCellBorderWidthOneValue() // QTBUG-80496
+{
+ const char html[] = "<head><style type=\"text/css\"> body, td { border-width: 2px; }</style></head> <body> <table> <tr> <td></td> </tr> </table> </body> </html>";
+ doc->setHtml(html);
+
+ cursor.movePosition(QTextCursor::Start);
+ cursor.movePosition(QTextCursor::NextBlock);
+ QTextTable *table = cursor.currentTable();
+ QVERIFY(table);
+
+ QTextTableCell cell = table->cellAt(0, 0);
+ QTextTableCellFormat cellFormat = cell.format().toTableCellFormat();
+ QCOMPARE(cellFormat.leftBorder(), qreal(2));
+ QCOMPARE(cellFormat.rightBorder(), qreal(2));
+ QCOMPARE(cellFormat.bottomBorder(), qreal(2));
+ QCOMPARE(cellFormat.topBorder(), qreal(2));
+}
+
+void tst_QTextDocumentFragment::css_tableCellBorderWidthTwoValues() // QTBUG-80496
+{
+ const char html[] = "<head><style type=\"text/css\"> body, td { border-width: 2px 3px; }</style></head> <body> <table> <tr> <td></td> </tr> </table> </body> </html>";
+ doc->setHtml(html);
+
+ cursor.movePosition(QTextCursor::Start);
+ cursor.movePosition(QTextCursor::NextBlock);
+ QTextTable *table = cursor.currentTable();
+ QVERIFY(table);
+
+ QTextTableCell cell = table->cellAt(0, 0);
+ QTextTableCellFormat cellFormat = cell.format().toTableCellFormat();
+ QCOMPARE(cellFormat.leftBorder(), qreal(3));
+ QCOMPARE(cellFormat.rightBorder(), qreal(3));
+ QCOMPARE(cellFormat.bottomBorder(), qreal(2));
+ QCOMPARE(cellFormat.topBorder(), qreal(2));
+}
+
void tst_QTextDocumentFragment::css_tableCellBorderShorthand()
{
const char html[] = "<body><table><tr><td style=\"border-left:1px solid green;border-right:2px dashed red;border-bottom:3px dotted yellow;border-top:4px dot-dash blue\">Foo</td></tr></table></body>";
diff --git a/tests/auto/gui/text/qtextdocumentlayout/qtextdocumentlayout.pro b/tests/auto/gui/text/qtextdocumentlayout/qtextdocumentlayout.pro
index 5d31ee3930..322690e4cc 100644
--- a/tests/auto/gui/text/qtextdocumentlayout/qtextdocumentlayout.pro
+++ b/tests/auto/gui/text/qtextdocumentlayout/qtextdocumentlayout.pro
@@ -1,7 +1,7 @@
CONFIG += testcase
TARGET = tst_qtextdocumentlayout
QT += testlib
-qtHaveModule(widgets) QT += widgets
+qtHaveModule(widgets): QT += widgets
SOURCES += tst_qtextdocumentlayout.cpp
diff --git a/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp b/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
index 8f51a7a474..39a1370f6f 100644
--- a/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
+++ b/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
@@ -53,12 +53,15 @@ class tst_QTextMarkdownImporter : public QObject
private slots:
void headingBulletsContinuations();
void thematicBreaks();
+ void lists_data();
+ void lists();
+ void avoidBlankLineAtBeginning_data();
+ void avoidBlankLineAtBeginning();
};
void tst_QTextMarkdownImporter::headingBulletsContinuations()
{
const QStringList expectedBlocks = QStringList() <<
- "" << // we could do without this blank line before the heading, but currently it happens
"heading" <<
"bullet 1 continuation line 1, indented via tab" <<
"bullet 2 continuation line 2, indented via 4 spaces" <<
@@ -159,5 +162,99 @@ void tst_QTextMarkdownImporter::thematicBreaks()
#endif
}
+void tst_QTextMarkdownImporter::lists_data()
+{
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<int>("expectedItemCount");
+ QTest::addColumn<bool>("expectedEmptyItems");
+ QTest::addColumn<QString>("rewrite");
+
+ // Some of these cases show odd behavior, which is subject to change
+ // as the importer and the writer are tweaked to fix bugs over time.
+ QTest::newRow("dot newline") << ".\n" << 0 << true << ".\n\n";
+ QTest::newRow("number dot newline") << "1.\n" << 1 << true << "1. \n";
+ QTest::newRow("star newline") << "*\n" << 1 << true << "* \n";
+ QTest::newRow("hyphen newline") << "-\n" << 1 << true << "- \n";
+ QTest::newRow("hyphen space newline") << "- \n" << 1 << true << "- \n";
+ QTest::newRow("hyphen space letter newline") << "- a\n" << 1 << false << "- a\n";
+ QTest::newRow("hyphen nbsp newline") <<
+ QString::fromUtf8("-\u00A0\n") << 0 << true << "-\u00A0\n\n";
+ QTest::newRow("nested empty lists") << "*\n *\n *\n" << 1 << true << " * \n";
+ QTest::newRow("list nested in empty list") << "-\n * a\n" << 2 << false << "- \n * a\n";
+ QTest::newRow("lists nested in empty lists")
+ << "-\n * a\n * b\n- c\n *\n + d\n" << 5 << false
+ << "- \n * a\n * b\n- c *\n + d\n";
+ QTest::newRow("numeric lists nested in empty lists")
+ << "- \n 1. a\n 2. b\n- c\n 1.\n + d\n" << 4 << false
+ << "- \n 1. a\n 2. b\n- c 1. + d\n";
+}
+
+void tst_QTextMarkdownImporter::lists()
+{
+ QFETCH(QString, input);
+ QFETCH(int, expectedItemCount);
+ QFETCH(bool, expectedEmptyItems);
+ QFETCH(QString, rewrite);
+
+ QTextDocument doc;
+ doc.setMarkdown(input); // QTBUG-78870 : don't crash
+ QTextFrame::iterator iterator = doc.rootFrame()->begin();
+ QTextFrame *currentFrame = iterator.currentFrame();
+ int i = 0;
+ int itemCount = 0;
+ bool emptyItems = true;
+ while (!iterator.atEnd()) {
+ // There are no child frames
+ QCOMPARE(iterator.currentFrame(), currentFrame);
+ // Check whether the block is text or a horizontal rule
+ QTextBlock block = iterator.currentBlock();
+ if (block.textList()) {
+ ++itemCount;
+ if (!block.text().isEmpty())
+ emptyItems = false;
+ }
+ qCDebug(lcTests, "%d %s%s", i,
+ (block.textList() ? "<li>" : "<p>"), qPrintable(block.text()));
+ ++iterator;
+ ++i;
+ }
+ QCOMPARE(itemCount, expectedItemCount);
+ QCOMPARE(emptyItems, expectedEmptyItems);
+ QCOMPARE(doc.toMarkdown(), rewrite);
+}
+
+void tst_QTextMarkdownImporter::avoidBlankLineAtBeginning_data()
+{
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<int>("expectedNumberOfParagraphs");
+
+ QTest::newRow("Text block") << QString("Markdown text") << 1;
+ QTest::newRow("Headline") << QString("Markdown text\n============") << 1;
+ QTest::newRow("Code block") << QString(" Markdown text") << 2;
+ QTest::newRow("Unordered list") << QString("* Markdown text") << 1;
+ QTest::newRow("Ordered list") << QString("1. Markdown text") << 1;
+ QTest::newRow("Blockquote") << QString("> Markdown text") << 1;
+}
+
+void tst_QTextMarkdownImporter::avoidBlankLineAtBeginning() // QTBUG-81060
+{
+ QFETCH(QString, input);
+ QFETCH(int, expectedNumberOfParagraphs);
+
+ QTextDocument doc;
+ QTextMarkdownImporter(QTextMarkdownImporter::DialectGitHub).import(&doc, input);
+ QTextFrame::iterator iterator = doc.rootFrame()->begin();
+ int i = 0;
+ while (!iterator.atEnd()) {
+ QTextBlock block = iterator.currentBlock();
+ // Make sure there is no empty paragraph at the beginning of the document
+ if (i == 0)
+ QVERIFY(!block.text().isEmpty());
+ ++iterator;
+ ++i;
+ }
+ QCOMPARE(i, expectedNumberOfParagraphs);
+}
+
QTEST_MAIN(tst_QTextMarkdownImporter)
#include "tst_qtextmarkdownimporter.moc"
diff --git a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp
index 1e6c354f17..d15e856a20 100644
--- a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp
+++ b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp
@@ -50,6 +50,7 @@ private slots:
void testWriteParagraph_data();
void testWriteParagraph();
void testWriteList();
+ void testWriteEmptyList();
void testWriteNestedBulletLists_data();
void testWriteNestedBulletLists();
void testWriteNestedNumericLists();
@@ -124,6 +125,14 @@ void tst_QTextMarkdownWriter::testWriteList()
"- ListItem 1\n- ListItem 2\n"));
}
+void tst_QTextMarkdownWriter::testWriteEmptyList()
+{
+ QTextCursor cursor(document);
+ cursor.createList(QTextListFormat::ListDisc);
+
+ QCOMPARE(documentToUnixMarkdown(), QString::fromLatin1("- \n"));
+}
+
void tst_QTextMarkdownWriter::testWriteNestedBulletLists_data()
{
QTest::addColumn<bool>("checkbox");
diff --git a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
index 7b2ff4cc10..474079037b 100644
--- a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
+++ b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
@@ -1041,7 +1041,7 @@ public:
QList<QRectF> rects;
PaintEngine()
- : QPaintEngine(0)
+ : QPaintEngine(QPaintEngine::PaintEngineFeatures{ })
{}
virtual Type type() const
{