diff options
Diffstat (limited to 'tests/auto/gui/text/qtexttable')
-rw-r--r-- | tests/auto/gui/text/qtexttable/CMakeLists.txt | 13 | ||||
-rw-r--r-- | tests/auto/gui/text/qtexttable/tst_qtexttable.cpp | 98 |
2 files changed, 93 insertions, 18 deletions
diff --git a/tests/auto/gui/text/qtexttable/CMakeLists.txt b/tests/auto/gui/text/qtexttable/CMakeLists.txt index 94d33d3530..e83a38f087 100644 --- a/tests/auto/gui/text/qtexttable/CMakeLists.txt +++ b/tests/auto/gui/text/qtexttable/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qtexttable.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtexttable Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtexttable LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtexttable SOURCES tst_qtexttable.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate ) @@ -16,6 +23,6 @@ qt_internal_add_test(tst_qtexttable ##################################################################### qt_internal_extend_target(tst_qtexttable CONDITION TARGET Qt::Widgets - PUBLIC_LIBRARIES + LIBRARIES Qt::Widgets ) diff --git a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp index bfead23d4d..d0e1e1cd74 100644 --- a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp +++ b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -75,6 +75,8 @@ private slots: #endif void checkBorderAttributes_data(); void checkBorderAttributes(); + void checkTableBorderAttributes_data(); + void checkTableBorderAttributes(); #ifndef QT_NO_WIDGETS void columnWidthWithSpans(); @@ -121,7 +123,7 @@ void tst_QTextTable::variousTableModifications() QTextTableFormat tableFmt; QTextTable *tab = cursor.insertTable(2, 2, tableFmt); - QCOMPARE(doc->toPlainText().length(), 5); + QCOMPARE(doc->toPlainText().size(), 5); QCOMPARE(tab, cursor.currentTable()); QCOMPARE(tab->columns(), 2); QCOMPARE(tab->rows(), 2); @@ -176,14 +178,14 @@ void tst_QTextTable::variousTableModifications() cursor.movePosition(QTextCursor::NextBlock); QCOMPARE(cursor.position(), 1); cursor.deleteChar(); - QCOMPARE(doc->toPlainText().length(), 5); + QCOMPARE(doc->toPlainText().size(), 5); cursor.movePosition(QTextCursor::NextBlock); QCOMPARE(cursor.position(), 2); cursor.deleteChar(); - QCOMPARE(doc->toPlainText().length(), 5); + QCOMPARE(doc->toPlainText().size(), 5); cursor.deletePreviousChar(); QCOMPARE(cursor.position(), 2); - QCOMPARE(doc->toPlainText().length(), 5); + QCOMPARE(doc->toPlainText().size(), 5); QTextTable *table = cursor.currentTable(); QCOMPARE(table->rows(), 2); @@ -192,16 +194,16 @@ void tst_QTextTable::variousTableModifications() table->insertRows(2, 1); QCOMPARE(table->rows(), 3); QCOMPARE(table->columns(), 2); - QCOMPARE(doc->toPlainText().length(), 7); + QCOMPARE(doc->toPlainText().size(), 7); table->insertColumns(2, 2); QCOMPARE(table->rows(), 3); QCOMPARE(table->columns(), 4); - QCOMPARE(doc->toPlainText().length(), 13); + QCOMPARE(doc->toPlainText().size(), 13); table->resize(4, 5); QCOMPARE(table->rows(), 4); QCOMPARE(table->columns(), 5); - QCOMPARE(doc->toPlainText().length(), 21); + QCOMPARE(doc->toPlainText().size(), 21); } void tst_QTextTable::tableShrinking() @@ -209,7 +211,7 @@ void tst_QTextTable::tableShrinking() QTextTableFormat tableFmt; cursor.insertTable(3, 4, tableFmt); - QCOMPARE(doc->toPlainText().length(), 13); + QCOMPARE(doc->toPlainText().size(), 13); QTextTable *table = cursor.currentTable(); QCOMPARE(table->rows(), 3); @@ -218,16 +220,16 @@ void tst_QTextTable::tableShrinking() table->removeRows(1, 1); QCOMPARE(table->rows(), 2); QCOMPARE(table->columns(), 4); - QCOMPARE(doc->toPlainText().length(), 9); + QCOMPARE(doc->toPlainText().size(), 9); table->removeColumns(1, 2); QCOMPARE(table->rows(), 2); QCOMPARE(table->columns(), 2); - QCOMPARE(doc->toPlainText().length(), 5); + QCOMPARE(doc->toPlainText().size(), 5); table->resize(1, 1); QCOMPARE(table->rows(), 1); QCOMPARE(table->columns(), 1); - QCOMPARE(doc->toPlainText().length(), 2); + QCOMPARE(doc->toPlainText().size(), 2); } void tst_QTextTable::spans() @@ -252,7 +254,7 @@ void tst_QTextTable::variousModifications2() QTextTableFormat tableFmt; cursor.insertTable(2, 5, tableFmt); - QCOMPARE(doc->toPlainText().length(), 11); + QCOMPARE(doc->toPlainText().size(), 11); QTextTable *table = cursor.currentTable(); QCOMPARE(cursor.position(), 1); QCOMPARE(table->rows(), 2); @@ -1148,8 +1150,8 @@ void tst_QTextTable::QTBUG31330_renderBackground() doc.print(&paintDevice); QVERIFY(paintDevice.pages >= 2); - QCOMPARE(engine.rects.count(), paintDevice.pages); - for (int i = 0; i < engine.rects.count(); ++i) { + QCOMPARE(engine.rects.size(), paintDevice.pages); + for (int i = 0; i < engine.rects.size(); ++i) { QRectF rect = engine.rects[i]; QVERIFY(rect.top() > 0); QVERIFY(rect.bottom() < 1000); @@ -1261,6 +1263,72 @@ void tst_QTextTable::checkBorderAttributes() } } +void tst_QTextTable::checkTableBorderAttributes_data() +{ + QTest::addColumn<QString>("html"); + QTest::addColumn<qreal>("tableBorderWidth"); + QTest::addColumn<QTextFrameFormat::BorderStyle>("tableBorderStyle"); + QTest::addColumn<QBrush>("tableBorderBrush"); + + const QString tableHtmlStart = QStringLiteral("<html><head><style>"); + const QString tableHtmlEnd1 = QStringLiteral("</style></head><body>" + "<table><tr><td>One</td><td>Two</td></tr></table>" + "</body></html>"); + const QString tableHtmlEnd2 = QStringLiteral("</style></head><body>" + "<table border=10><tr><td>One</td><td>Two</td></tr></table>" + "</body></html>"); + + QTest::newRow("table-border-attributes-shorthand") + << QString("%1" + "table {" + "border: 2px solid red;" + "}" + "%2").arg(tableHtmlStart).arg(tableHtmlEnd1) + << 2.0 << QTextFrameFormat::BorderStyle_Solid << QBrush(Qt::red); + + QTest::newRow("table-border-attributes-explicit") + << QString("%1" + "table {" + "border-width: 2px;" + "border-color: red;" + "border-style: dashed;" + "}" + "%2").arg(tableHtmlStart).arg(tableHtmlEnd1) + << 2.0 << QTextFrameFormat::BorderStyle_Dashed << QBrush(Qt::red); + + QTest::newRow("table-border-override") + << QString("%1" + "table {" + "border: 2px solid red;" + "}" + "%2").arg(tableHtmlStart).arg(tableHtmlEnd2) + << 2.0 << QTextFrameFormat::BorderStyle_Solid << QBrush(Qt::red); + + QTest::newRow("table-border-default") + << QString("%1" + "%2").arg(tableHtmlStart).arg(tableHtmlEnd2) + << 10.0 << QTextFrameFormat::BorderStyle_Outset << QBrush(Qt::darkGray); +} + +void tst_QTextTable::checkTableBorderAttributes() +{ + QFETCH(QString, html); + QFETCH(qreal, tableBorderWidth); + QFETCH(QTextFrameFormat::BorderStyle, tableBorderStyle); + QFETCH(QBrush, tableBorderBrush); + + QTextDocument doc; + doc.setHtml(html); + QTextCursor cursor(doc.firstBlock()); + cursor.movePosition(QTextCursor::Right); + + QTextTable *currentTable = cursor.currentTable(); + QVERIFY(currentTable); + QCOMPARE(currentTable->format().border(), tableBorderWidth); + QCOMPARE(currentTable->format().borderStyle(), tableBorderStyle); + QCOMPARE(currentTable->format().borderBrush(), tableBorderBrush); +} + #ifndef QT_NO_WIDGETS void tst_QTextTable::columnWidthWithSpans() { |