summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp')
-rw-r--r--tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp95
1 files changed, 62 insertions, 33 deletions
diff --git a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
index c0c52b5c04..f2c3b36dcd 100644
--- a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
+++ b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -41,6 +16,8 @@
#include <qtextcursor.h>
+using namespace Qt::StringLiterals;
+
QT_FORWARD_DECLARE_CLASS(QTextDocument)
class tst_QTextDocumentFragment : public QObject
@@ -100,6 +77,7 @@ private slots:
void inheritAlignment();
void dontEmitEmptyNodeWhenEmptyTagIsFollowedByCloseTag();
void toPlainText();
+ void toRawText();
void copyTableRow();
void copyTableColumn();
void copySubTable();
@@ -120,6 +98,7 @@ private slots:
void html_thCentered();
void orderedListNumbering();
void html_blockAfterList();
+ void html_listStartAttribute();
void html_subAndSuperScript();
void html_cssColors();
void obeyFragmentMarkersInImport();
@@ -268,6 +247,7 @@ private slots:
void html_fromFirefox();
void html_emptyInlineInsideBlock();
void css_fontAndWordSpacing();
+ void html_brWithWhitespaceAfterList();
private:
inline void setHtml(const QString &html)
@@ -1094,6 +1074,14 @@ void tst_QTextDocumentFragment::toPlainText()
QCOMPARE(doc->blockCount(), 3);
}
+void tst_QTextDocumentFragment::toRawText()
+{
+ // Make sure nbsp, line separator, paragraph separator is preserved
+ doc->setPlainText("Hello\u0A00\u2028\u2029World");
+
+ QCOMPARE(QTextDocumentFragment(doc).toRawText(), "Hello\u0A00\u2028\u2029World");
+}
+
void tst_QTextDocumentFragment::copyTableRow()
{
QTextDocumentFragment frag;
@@ -1191,7 +1179,7 @@ void tst_QTextDocumentFragment::copySubTable()
table->cellAt(row, col).firstCursorPosition().insertText(rowS + QString::number(col));
}
- QCOMPARE(table->format().columnWidthConstraints().count(), table->columns());
+ QCOMPARE(table->format().columnWidthConstraints().size(), table->columns());
// select 2x2 subtable
cursor = table->cellAt(1, 1).firstCursorPosition();
@@ -1487,6 +1475,22 @@ void tst_QTextDocumentFragment::html_blockAfterList()
QCOMPARE(cursor.blockFormat().indent(), 0);
}
+void tst_QTextDocumentFragment::html_listStartAttribute()
+{
+ const char html[] = "<ol start=-1><li>Foo</ol><ol><li>Bar</ol>";
+ cursor.insertFragment(QTextDocumentFragment::fromHtml(html));
+
+ cursor.movePosition(QTextCursor::Start);
+
+ QVERIFY(cursor.currentList());
+ QCOMPARE(cursor.currentList()->format().start(), -1);
+
+ QVERIFY(cursor.movePosition(QTextCursor::NextBlock));
+
+ QVERIFY(cursor.currentList());
+ QCOMPARE(cursor.currentList()->format().start(), 1);
+}
+
void tst_QTextDocumentFragment::html_subAndSuperScript()
{
const char subHtml[] = "<sub>Subby</sub>";
@@ -2251,7 +2255,7 @@ void tst_QTextDocumentFragment::html_frameImport()
cursor.insertFragment(frag);
QList<QTextFrame *> childFrames = doc->rootFrame()->childFrames();
- QCOMPARE(childFrames.count(), 1);
+ QCOMPARE(childFrames.size(), 1);
QTextFrame *frame = childFrames.first();
QCOMPARE(frame->frameFormat().margin(), ffmt.margin());
QCOMPARE(frame->frameFormat().border(), ffmt.border());
@@ -2279,7 +2283,7 @@ void tst_QTextDocumentFragment::html_frameImport2()
cursor.insertFragment(frag);
QList<QTextFrame *> childFrames = doc->rootFrame()->childFrames();
- QCOMPARE(childFrames.count(), 1);
+ QCOMPARE(childFrames.size(), 1);
QTextFrame *frame = childFrames.first();
QCOMPARE(frame->frameFormat().topMargin(), ffmt.topMargin());
QCOMPARE(frame->frameFormat().bottomMargin(), ffmt.bottomMargin());
@@ -2294,7 +2298,7 @@ void tst_QTextDocumentFragment::html_dontAddMarginsAcrossTableCells()
cursor.insertFragment(QTextDocumentFragment::fromHtml(QString::fromLatin1(html)));
QList<QTextFrame *> childFrames = doc->rootFrame()->childFrames();
- QCOMPARE(childFrames.count(), 1);
+ QCOMPARE(childFrames.size(), 1);
QTextFrame *frame = childFrames.first();
cursor = frame->firstCursorPosition();
QCOMPARE(cursor.blockFormat().leftMargin(), qreal(50.0));
@@ -2776,7 +2780,7 @@ void tst_QTextDocumentFragment::html_columnWidths()
QTextTableFormat fmt = table->format();
const QList<QTextLength> columnWidths = fmt.columnWidthConstraints();
- QCOMPARE(columnWidths.count(), 2);
+ QCOMPARE(columnWidths.size(), 2);
QCOMPARE(columnWidths.at(0).type(), QTextLength::VariableLength);
QCOMPARE(columnWidths.at(1).type(), QTextLength::PercentageLength);
QCOMPARE(columnWidths.at(1).rawValue(), qreal(1));
@@ -3499,6 +3503,12 @@ void tst_QTextDocumentFragment::html_hr()
doc->setHtml("<hr />");
QCOMPARE(doc->blockCount(), 1);
QVERIFY(doc->begin().blockFormat().hasProperty(QTextFormat::BlockTrailingHorizontalRulerWidth));
+ doc->setHtml("<hr style=\"background-color:green;\"/>");
+ QCOMPARE(doc->blockCount(), 1);
+ QVERIFY(doc->begin().blockFormat().hasProperty(QTextFormat::BlockTrailingHorizontalRulerWidth));
+ QVERIFY(doc->begin().blockFormat().hasProperty(QTextFormat::BackgroundBrush));
+ const auto brush = qvariant_cast<QBrush>(doc->begin().blockFormat().property(QTextFormat::BackgroundBrush));
+ QCOMPARE(brush.color(), QColor("green"));
}
void tst_QTextDocumentFragment::html_hrMargins()
@@ -4178,7 +4188,7 @@ void tst_QTextDocumentFragment::html_entities()
setHtml(html);
QCOMPARE(doc->blockCount(), 1);
QString txt = doc->begin().text();
- QCOMPARE(txt.length(), 1);
+ QCOMPARE(txt.size(), 1);
QCOMPARE(txt.at(0).unicode(), code);
}
@@ -4313,5 +4323,24 @@ void tst_QTextDocumentFragment::css_fontAndWordSpacing()
}
}
+void tst_QTextDocumentFragment::html_brWithWhitespaceAfterList() // QTBUG-81662
+{
+ setHtml(QString::fromLatin1("<ul><li>one</li><li>two</li></ul>\n <br/>\nhello"));
+
+ QCOMPARE(doc->blockCount(), 3);
+
+ QTextBlock block = doc->begin();
+ QVERIFY(block.textList());
+
+ block = block.next();
+ QVERIFY(block.textList());
+
+ block = block.next();
+ QCOMPARE(block.text(), u"\u2028hello"_s);
+
+ block = block.next();
+ QVERIFY(block.text().isEmpty());
+}
+
QTEST_MAIN(tst_QTextDocumentFragment)
#include "tst_qtextdocumentfragment.moc"