From 38f4e1f3e75c4761daf0bf0473c6805e5170fb17 Mon Sep 17 00:00:00 2001 From: Oliver Eftevaag Date: Mon, 3 May 2021 20:25:25 +0200 Subject: [PATCH] Unit test for checking text-decoration in html export This unit test is related to the parent commit. Html export used to omit the text-decoration for the default font, this unit test ensures that this property is added to the exported html. Fixes: QTBUG-91171 Change-Id: Ib68bec27f9963cdcac5c553b2c07557717b1c22e Reviewed-by: Allan Sandfeld Jensen --- .../text/qtextdocument/tst_qtextdocument.cpp | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index a0489e287c..43278d4d26 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -103,6 +103,7 @@ private slots: void toHtmlRootFrameProperties(); void toHtmlLineHeightProperties(); void toHtmlDefaultFontSpacingProperties(); + void toHtmlTextDecorationUnderline(); void capitalizationHtmlInExport(); void wordspacingHtmlExport(); @@ -1993,6 +1994,62 @@ void tst_QTextDocument::toHtmlDefaultFontSpacingProperties() QCOMPARE(doc.toHtml(), expectedOutput); } +void tst_QTextDocument::toHtmlTextDecorationUnderline() +{ + CREATE_DOC_AND_CURSOR(); + + cursor.insertText("Some text"); + QFont fnt = doc.defaultFont(); + fnt.setUnderline(true); + doc.setDefaultFont(fnt); + + QString expectedOutput = + QString("\n" + "" + "" + "\n" + "

Some text

" + ""); + + expectedOutput = expectedOutput.arg(doc.defaultFont().family()) + .arg(cssFontSizeString(doc.defaultFont())) + .arg(doc.defaultFont().weight()) + .arg((doc.defaultFont().italic() ? "italic" : "normal")); + + QCOMPARE(doc.toHtml(), expectedOutput); + + QTextCharFormat format; + format.setFontUnderline(false); + cursor.select(QTextCursor::Document); + cursor.mergeCharFormat(format); + + QString expectedOutput2 = + QString("\n" + "" + "" + "\n" + "

" + "Some text

" + ""); + + expectedOutput2 = expectedOutput2.arg(doc.defaultFont().family()) + .arg(cssFontSizeString(doc.defaultFont())) + .arg(doc.defaultFont().weight()) + .arg((doc.defaultFont().italic() ? "italic" : "normal")); + + QCOMPARE(doc.toHtml(), expectedOutput2); +} + void tst_QTextDocument::capitalizationHtmlInExport() { doc->setPlainText("Test");