summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text
diff options
context:
space:
mode:
authorOliver Eftevaag <oliver.eftevaag@qt.io>2021-05-03 20:25:25 +0200
committerOliver Eftevaag <oliver.eftevaag@qt.io>2021-05-05 16:28:54 +0200
commit38f4e1f3e75c4761daf0bf0473c6805e5170fb17 (patch)
treee9b0428a759ff2ddfc5bd90bf58aafc342d71e10 /tests/auto/gui/text
parent720defd2caee5225527fa0b154fa68b738fb967b (diff)
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 <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/gui/text')
-rw-r--r--tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp57
1 files changed, 57 insertions, 0 deletions
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("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" "
+ "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
+ "<html><head><meta name=\"qrichtext\" content=\"1\" />"
+ "<meta charset=\"utf-8\" /><style type=\"text/css\">\n"
+ "p, li { white-space: pre-wrap; }\n"
+ "</style></head>"
+ "<body style=\" font-family:'%1'; font-size:%2; "
+ "font-weight:%3; font-style:%4; text-decoration: underline;\">\n"
+ "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
+ "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Some text</p>"
+ "</body></html>");
+
+ 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("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" "
+ "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
+ "<html><head><meta name=\"qrichtext\" content=\"1\" />"
+ "<meta charset=\"utf-8\" /><style type=\"text/css\">\n"
+ "p, li { white-space: pre-wrap; }\n"
+ "</style></head>"
+ "<body style=\" font-family:'%1'; font-size:%2; "
+ "font-weight:%3; font-style:%4; text-decoration: underline;\">\n"
+ "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
+ "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
+ "<span style=\" text-decoration:none;\">Some text</span></p>"
+ "</body></html>");
+
+ 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");