diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-11-02 21:39:34 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-11-08 11:49:54 +0100 |
commit | b14b1c99f8d122c7988cd6e59b0f3fef15923da4 (patch) | |
tree | c876d2428f7be32a73a1d066fa2d703b59708a1e /tests/auto/gui/painting | |
parent | 8bf36025f5602e3067448941ee4d0ccca3928a40 (diff) |
Rename QRangeCollection to QPageRanges, make it a proper value type
The type is specific about printing, so give it a name in line with
QPageLayout and QPageSize.
As per API review comment, it's not clear why this type should not be a
regular, copyable and movable value type. It stores a list of intervals.
Give it value-type semantics, as an implicitly shared class.
Convert the parse method into a static factory function.
Add a Range type and use it instead of the semantic-free QPair.
Move QPrinter getter into QPagedPainteDevice, make it return a copy
rather than a pointer, and add a setter.
Extend test case to cover all members and more merge cases. Fix bugs
found that way.
Fixes: QTBUG-88113
Change-Id: If17ea4d410d49f16b097e88b7979db5d72add820
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/gui/painting')
-rw-r--r-- | tests/auto/gui/painting/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/auto/gui/painting/painting.pro | 2 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpageranges/CMakeLists.txt (renamed from tests/auto/gui/painting/qrangecollection/CMakeLists.txt) | 8 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpageranges/qpageranges.pro | 6 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp | 183 | ||||
-rw-r--r-- | tests/auto/gui/painting/qrangecollection/qrangecollection.pro | 6 | ||||
-rw-r--r-- | tests/auto/gui/painting/qrangecollection/tst_qrangecollection.cpp | 75 |
7 files changed, 195 insertions, 87 deletions
diff --git a/tests/auto/gui/painting/CMakeLists.txt b/tests/auto/gui/painting/CMakeLists.txt index 682fc487c2..4f933139ca 100644 --- a/tests/auto/gui/painting/CMakeLists.txt +++ b/tests/auto/gui/painting/CMakeLists.txt @@ -6,12 +6,12 @@ add_subdirectory(qcolor) add_subdirectory(qbrush) add_subdirectory(qregion) add_subdirectory(qpagelayout) +add_subdirectory(qpageranges) add_subdirectory(qpagesize) add_subdirectory(qpainter) add_subdirectory(qpdfwriter) add_subdirectory(qpen) add_subdirectory(qpaintengine) -add_subdirectory(qrangecollection) add_subdirectory(qtransform) add_subdirectory(qpolygon) # QTBUG-87669 # special case diff --git a/tests/auto/gui/painting/painting.pro b/tests/auto/gui/painting/painting.pro index f99fc6c4e8..9c24b8e5ed 100644 --- a/tests/auto/gui/painting/painting.pro +++ b/tests/auto/gui/painting/painting.pro @@ -7,13 +7,13 @@ SUBDIRS=\ qbrush \ qregion \ qpagelayout \ + qpageranges \ qpagesize \ qpainter \ qpathclipper \ qpdfwriter \ qpen \ qpaintengine \ - qrangecollection \ qtransform \ qpolygon \ diff --git a/tests/auto/gui/painting/qrangecollection/CMakeLists.txt b/tests/auto/gui/painting/qpageranges/CMakeLists.txt index d4aa7986a7..660d4b4336 100644 --- a/tests/auto/gui/painting/qrangecollection/CMakeLists.txt +++ b/tests/auto/gui/painting/qpageranges/CMakeLists.txt @@ -1,12 +1,12 @@ -# Generated from qrangecollection.pro. +# Generated from qpageranges.pro. ##################################################################### -## tst_qrangecollection Test: +## tst_qpageranges Test: ##################################################################### -qt_internal_add_test(tst_qrangecollection +qt_internal_add_test(tst_qpageranges SOURCES - tst_qrangecollection.cpp + tst_qpageranges.cpp PUBLIC_LIBRARIES Qt::CorePrivate Qt::Gui diff --git a/tests/auto/gui/painting/qpageranges/qpageranges.pro b/tests/auto/gui/painting/qpageranges/qpageranges.pro new file mode 100644 index 0000000000..9062a58ea3 --- /dev/null +++ b/tests/auto/gui/painting/qpageranges/qpageranges.pro @@ -0,0 +1,6 @@ +CONFIG += testcase +TARGET = tst_qpageranges + +QT += testlib gui-private core-private + +SOURCES += tst_qpageranges.cpp diff --git a/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp b/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp new file mode 100644 index 0000000000..953f1c472a --- /dev/null +++ b/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp @@ -0,0 +1,183 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <qpageranges.h> + +typedef QList<QPageRanges::Range> PageRangeList; + +class tst_QPageRanges : public QObject +{ + Q_OBJECT + +private slots: + void basics(); + + void addPage_data(); + void addPage(); + + void addRange_data(); + void addRange(); + + void fromToString_data(); + void fromToString(); +}; + +void tst_QPageRanges::basics() +{ + QPageRanges empty; + QVERIFY(empty.isEmpty()); + QVERIFY(!empty.contains(0)); + QCOMPARE(empty.firstPage(), 0); + QCOMPARE(empty.lastPage(), 0); + + QPageRanges single; + single.addPage(1); + + QVERIFY(!single.isEmpty()); + QVERIFY(single.contains(1)); + QCOMPARE(single.firstPage(), 1); + QCOMPARE(single.firstPage(), 1); + + QPageRanges copy(single); + QCOMPARE(copy, single); + + QPageRanges moved(std::move(copy)); + QCOMPARE(moved, single); + QVERIFY(copy.isEmpty()); + + single.clear(); + QVERIFY(single.isEmpty()); + QVERIFY(!moved.isEmpty()); +} + +void tst_QPageRanges::addPage_data() +{ + QTest::addColumn<QList<int>>("pageNumbers"); + QTest::addColumn<PageRangeList>("expected"); + + QTest::newRow("single") << QList<int>{5} << PageRangeList{{5, 5}}; + QTest::newRow("duplicate") << QList<int>{5, 5} << PageRangeList{{5, 5}}; + QTest::newRow("adjacent") << QList<int>{5, 6, 7} << PageRangeList{{5, 7}}; + QTest::newRow("separate") << QList<int>{1, 3, 5} << PageRangeList{{1, 1}, {3, 3}, {5, 5}}; + QTest::newRow("unsorted") << QList<int>{5, 3, 4, 1} << PageRangeList{{1, 1}, {3, 5}}; + QTest::newRow("invalid") << QList<int>{-1} << PageRangeList{}; +} + +void tst_QPageRanges::addPage() +{ + QFETCH(QList<int>, pageNumbers); + QFETCH(PageRangeList, expected); + + QPageRanges result; + for (int pageNumber : qAsConst(pageNumbers)) { + if (QByteArrayView(QTest::currentDataTag()) == "invalid") + QTest::ignoreMessage(QtWarningMsg, "QPageRanges::addPage: 'pageNumber' must be greater than 0"); + result.addPage(pageNumber); + } + + QCOMPARE(result.toRangeList(), expected); +} + +void tst_QPageRanges::addRange_data() +{ + QTest::addColumn<PageRangeList>("ranges"); + QTest::addColumn<PageRangeList>("expected"); + + QTest::newRow("single") << PageRangeList{{5, 5}} + << PageRangeList{{5, 5}}; + QTest::newRow("duplicate") << PageRangeList{{5, 5}, {5, 5}} + << PageRangeList{{5, 5}}; + QTest::newRow("adjacent") << PageRangeList{{1, 3}, {4, 6}, {7, 10}} + << PageRangeList{{1, 10}}; + QTest::newRow("separate") << PageRangeList{{1, 2}, {4, 5}, {7, 8}} + << PageRangeList{{1, 2}, {4, 5}, {7, 8}}; + QTest::newRow("overlap") << PageRangeList{{1, 5}, {4, 8}, {8, 10}} + << PageRangeList{{1, 10}}; + QTest::newRow("included") << PageRangeList{{1, 5}, {2, 3}, {8, 9}, {7, 10}} + << PageRangeList{{1, 5}, {7, 10}}; + QTest::newRow("unsorted") << PageRangeList{{7, 8}, {1, 4}, {9, 10}} + << PageRangeList{{1, 4}, {7, 10}}; + QTest::newRow("flipped") << PageRangeList{{5, 1}} + << PageRangeList{{1, 5}}; + QTest::newRow("invalid1") << PageRangeList{{-1, 2}} + << PageRangeList{}; + QTest::newRow("invalid2") << PageRangeList{{0, -1}} + << PageRangeList{}; +} + +void tst_QPageRanges::addRange() +{ + QFETCH(PageRangeList, ranges); + QFETCH(PageRangeList, expected); + + QPageRanges result; + for (const auto &range : qAsConst(ranges)) { + const QByteArrayView testdata(QTest::currentDataTag()); + if (testdata.startsWith("invalid")) + QTest::ignoreMessage(QtWarningMsg, "QPageRanges::addRange: 'from' and 'to' must be greater than 0"); + + result.addRange(range.from, range.to); + } + + QCOMPARE(result.toRangeList(), expected); +} + +void tst_QPageRanges::fromToString_data() +{ + QTest::addColumn<QString>("fromString"); + QTest::addColumn<PageRangeList>("rangeList"); + QTest::addColumn<QString>("toString"); + + QTest::newRow("invalid") << QString(",-8") + << PageRangeList{} + << QString(); + + QTest::newRow("overlapping") << QString("1-3,5-9,6-7,8-11") + << PageRangeList{{1, 3}, {5, 11}} + << QString("1-3,5-11"); + + QTest::newRow("spacy") << QString("1 -2, 3- 4 ,\t5-6\t,7 - 8 ,\n9 - 10") + << PageRangeList{{1, 10}} + << QString("1-10"); +} + +void tst_QPageRanges::fromToString() +{ + QFETCH(QString, fromString); + QFETCH(PageRangeList, rangeList); + QFETCH(QString, toString); + + QPageRanges ranges = QPageRanges::fromString(fromString); + QCOMPARE(ranges.toRangeList(), rangeList); + QCOMPARE(ranges.toString(), toString); +} + +QTEST_APPLESS_MAIN(tst_QPageRanges) + +#include "tst_qpageranges.moc" diff --git a/tests/auto/gui/painting/qrangecollection/qrangecollection.pro b/tests/auto/gui/painting/qrangecollection/qrangecollection.pro deleted file mode 100644 index 782e8ee59c..0000000000 --- a/tests/auto/gui/painting/qrangecollection/qrangecollection.pro +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG += testcase -TARGET = tst_qrangecollection - -QT += testlib gui-private core-private - -SOURCES += tst_qrangecollection.cpp diff --git a/tests/auto/gui/painting/qrangecollection/tst_qrangecollection.cpp b/tests/auto/gui/painting/qrangecollection/tst_qrangecollection.cpp deleted file mode 100644 index 826b2fe38b..0000000000 --- a/tests/auto/gui/painting/qrangecollection/tst_qrangecollection.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include <qrangecollection.h> - -typedef QList<QPair<int, int>> PageRangeList; - -class tst_QRangeCollection : public QObject -{ - Q_OBJECT - -private slots: - void parseFromString_data(); - void parseFromString(); -}; - -void tst_QRangeCollection::parseFromString_data() -{ - QTest::addColumn<QString>("rangeString"); - QTest::addColumn<QList<QPair<int, int>>>("rangeList"); - - QList<QPair<int, int>> invalid; - QTest::newRow("invalid") << QString(",-8") - << invalid; - - QList<QPair<int, int>> overlapping; - overlapping << qMakePair(1, 3) - << qMakePair(5, 11); - QTest::newRow("overlapping") << QString("1-3,5-9,6-7,8-11") - << overlapping; -} - -void tst_QRangeCollection::parseFromString() -{ - QFETCH(QString, rangeString); - QFETCH(PageRangeList, rangeList); - - QRangeCollection rangeCollection; - rangeCollection.parse(rangeString); - QList<QPair<int, int>> result = rangeCollection.toList(); - QCOMPARE(result.length(), rangeList.length()); - for (const QPair<int, int> &pair : result) { - QVERIFY(rangeList.contains(pair)); - } -} - -QTEST_APPLESS_MAIN(tst_QRangeCollection) - -#include "tst_qrangecollection.moc" |