qt5base-lts/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp
David Skoland 27d96b4789 Replace QtTest headers with QTest
Complete search and replace of QtTest and QtTest/QtTest with QTest, as
QtTest includes the whole module. Replace all such instances with
correct header includes. See Jira task for more discussion.

Fixes: QTBUG-88831
Change-Id: I981cfae18a1cabcabcabee376016b086d9d01f44
Pick-to: 6.0
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-12-22 15:20:30 +01:00

184 lines
6.1 KiB
C++

/****************************************************************************
**
** 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 <QTest>
#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"