-/***************************************************************************
- * Copyright (C) 2013 by Frank Reininghaus <frank78ac@googlemail.com> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2013 Frank Reininghaus <frank78ac@googlemail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
#include "kitemviews/kitemset.h"
+#include <QStandardPaths>
#include <QTest>
-#include <QVector>
-Q_DECLARE_METATYPE(KItemRangeList);
+Q_DECLARE_METATYPE(KItemRangeList)
/**
* Converts a KItemRangeList to a KItemSet.
*/
-KItemSet KItemRangeList2KItemSet(const KItemRangeList& itemRanges)
+KItemSet KItemRangeList2KItemSet(const KItemRangeList &itemRanges)
{
KItemSet result;
- foreach (const KItemRange& range, itemRanges) {
+ for (const KItemRange &range : itemRanges) {
for (int i = range.index; i < range.index + range.count; ++i) {
result.insert(i);
}
/**
* Converts a KItemRangeList to a QSet<int>.
*/
-QSet<int> KItemRangeList2QSet(const KItemRangeList& itemRanges)
+QSet<int> KItemRangeList2QSet(const KItemRangeList &itemRanges)
{
QSet<int> result;
- foreach (const KItemRange& range, itemRanges) {
+ for (const KItemRange &range : itemRanges) {
for (int i = range.index; i < range.index + range.count; ++i) {
result.insert(i);
}
/**
* Converts a KItemRangeList to a QVector<int>.
*/
-QVector<int> KItemRangeList2QVector(const KItemRangeList& itemRanges)
+QVector<int> KItemRangeList2QVector(const KItemRangeList &itemRanges)
{
QVector<int> result;
- foreach (const KItemRange& range, itemRanges) {
+ for (const KItemRange &range : itemRanges) {
for (int i = range.index; i < range.index + range.count; ++i) {
result.append(i);
}
/**
* Converts a KItemSet to a QSet<int>.
*/
-static QSet<int> KItemSet2QSet(const KItemSet& itemSet)
+static QSet<int> KItemSet2QSet(const KItemSet &itemSet)
{
QSet<int> result;
- foreach (int i, itemSet) {
+ for (int i : itemSet) {
result.insert(i);
}
// Check that the conversion was successful.
Q_ASSERT(itemSet.count() == result.count());
- foreach (int i, itemSet) {
+ for (int i : std::as_const(itemSet)) {
Q_ASSERT(result.contains(i));
}
- foreach (int i, result) {
+ for (int i : std::as_const(result)) {
Q_ASSERT(itemSet.contains(i));
}
return result;
}
-
/**
* The main test class.
*/
{
Q_OBJECT
-private slots:
+private Q_SLOTS:
void initTestCase();
void testConstruction_data();
void testSymmetricDifference();
private:
- QHash<const char*, KItemRangeList> m_testCases;
+ QHash<const char *, KItemRangeList> m_testCases;
};
void KItemSetTest::initTestCase()
{
+ QStandardPaths::setTestModeEnabled(true);
+
m_testCases.insert("empty", KItemRangeList());
m_testCases.insert("[0]", KItemRangeList() << KItemRange(0, 1));
m_testCases.insert("[1]", KItemRangeList() << KItemRange(1, 1));
m_testCases.insert("[1, 2] [4, 5]", KItemRangeList() << KItemRange(1, 2) << KItemRange(4, 2));
m_testCases.insert("[1, 5]", KItemRangeList() << KItemRange(1, 5));
m_testCases.insert("[1, 2] [4, 5] [7] [9, 10] [13] [20, 25] [30]",
- KItemRangeList() << KItemRange(1, 2) << KItemRange(4, 2) << KItemRange(7, 1) << KItemRange(9, 2) << KItemRange(20, 6) << KItemRange(30, 1));
+ KItemRangeList() << KItemRange(1, 2) << KItemRange(4, 2) << KItemRange(7, 1) << KItemRange(9, 2) << KItemRange(20, 6)
+ << KItemRange(30, 1));
m_testCases.insert("[-10, -1]", KItemRangeList() << KItemRange(-10, 10));
m_testCases.insert("[-10, 0]", KItemRangeList() << KItemRange(-10, 11));
m_testCases.insert("[-10, 1]", KItemRangeList() << KItemRange(-10, 12));
{
QTest::addColumn<KItemRangeList>("itemRanges");
- QHash<const char*, KItemRangeList>::const_iterator it = m_testCases.constBegin();
- const QHash<const char*, KItemRangeList>::const_iterator end = m_testCases.constEnd();
+ QHash<const char *, KItemRangeList>::const_iterator it = m_testCases.constBegin();
+ const QHash<const char *, KItemRangeList>::const_iterator end = m_testCases.constEnd();
while (it != end) {
QTest::newRow(it.key()) << it.value();
{
QTest::addColumn<KItemRangeList>("itemRanges");
- QHash<const char*, KItemRangeList>::const_iterator it = m_testCases.constBegin();
- const QHash<const char*, KItemRangeList>::const_iterator end = m_testCases.constEnd();
+ QHash<const char *, KItemRangeList>::const_iterator it = m_testCases.constBegin();
+ const QHash<const char *, KItemRangeList>::const_iterator end = m_testCases.constEnd();
while (it != end) {
QTest::newRow(it.key()) << it.value();
QVERIFY(itemSet.isValid());
QVERIFY(itemSet.count() == itemsQVector.count());
- if (itemSet.count() == 0) {
+ if (itemSet.isEmpty()) {
QVERIFY(itemSet.isEmpty());
QVERIFY(itemSet.begin() == itemSet.end());
QVERIFY(itemSet.constBegin() == itemSet.constEnd());
QCOMPARE(testQVector, itemsQVector);
testQVector.clear();
- foreach (int i, itemSet) {
+ for (int i : itemSet) {
testQVector.append(i);
}
QCOMPARE(testQVector, itemsQVector);
{
QTest::addColumn<KItemRangeList>("itemRanges");
- QHash<const char*, KItemRangeList>::const_iterator it = m_testCases.constBegin();
- const QHash<const char*, KItemRangeList>::const_iterator end = m_testCases.constEnd();
+ QHash<const char *, KItemRangeList>::const_iterator it = m_testCases.constBegin();
+ const QHash<const char *, KItemRangeList>::const_iterator end = m_testCases.constEnd();
while (it != end) {
QTest::newRow(it.key()) << it.value();
/**
* Test all functions that find items:
- * contais(int), find(int), constFind(int)
+ * contains(int), find(int), constFind(int)
*/
void KItemSetTest::testFind()
{
int min;
int max;
- if (itemSet.count() == 0) {
+ if (itemSet.isEmpty()) {
// Use some arbitrary values for the upcoming tests.
min = 0;
max = 5;
{
QTest::addColumn<KItemRangeList>("itemRanges");
- QHash<const char*, KItemRangeList>::const_iterator it = m_testCases.constBegin();
- const QHash<const char*, KItemRangeList>::const_iterator end = m_testCases.constEnd();
+ QHash<const char *, KItemRangeList>::const_iterator it = m_testCases.constBegin();
+ const QHash<const char *, KItemRangeList>::const_iterator end = m_testCases.constEnd();
while (it != end) {
QTest::newRow(it.key()) << it.value();
int min;
int max;
- if (itemSet.count() == 0) {
+ if (itemSet.isEmpty()) {
// Use some arbitrary values for the upcoming tests.
min = 0;
max = 5;
// Test insert(int), remove(int), and erase(KItemSet::iterator)
// for items between min - 2 and max + 2.
for (int i = min - 2; i <= max + 2; ++i) {
-
// Test insert(int).
{
KItemSet tmp(itemSet);
QCOMPARE(tmp.end(), tmp.find(i));
QCOMPARE(tmp.constEnd(), tmp.constFind(i));
- // Check the returen value, now contained in 'it'.
+ // Check the returned value, now contained in 'it'.
if (i == max) {
QCOMPARE(it, tmp.end());
} else {
QTest::addColumn<KItemRangeList>("itemRanges1");
QTest::addColumn<KItemRangeList>("itemRanges2");
- QHash<const char*, KItemRangeList>::const_iterator it1 = m_testCases.constBegin();
- const QHash<const char*, KItemRangeList>::const_iterator end = m_testCases.constEnd();
+ QHash<const char *, KItemRangeList>::const_iterator it1 = m_testCases.constBegin();
+ const QHash<const char *, KItemRangeList>::const_iterator end = m_testCases.constEnd();
while (it1 != end) {
- QHash<const char*, KItemRangeList>::const_iterator it2 = m_testCases.constBegin();
+ QHash<const char *, KItemRangeList>::const_iterator it2 = m_testCases.constBegin();
while (it2 != end) {
QByteArray name = it1.key() + QByteArray(" + ") + it2.key();
QTest::addColumn<KItemRangeList>("itemRanges1");
QTest::addColumn<KItemRangeList>("itemRanges2");
- QHash<const char*, KItemRangeList>::const_iterator it1 = m_testCases.constBegin();
- const QHash<const char*, KItemRangeList>::const_iterator end = m_testCases.constEnd();
+ QHash<const char *, KItemRangeList>::const_iterator it1 = m_testCases.constBegin();
+ const QHash<const char *, KItemRangeList>::const_iterator end = m_testCases.constEnd();
while (it1 != end) {
- QHash<const char*, KItemRangeList>::const_iterator it2 = m_testCases.constBegin();
+ QHash<const char *, KItemRangeList>::const_iterator it2 = m_testCases.constBegin();
while (it2 != end) {
QByteArray name = it1.key() + QByteArray(" ^ ") + it2.key();
QCOMPARE(itemSet2 ^ symmetricDifference, itemSet1);
}
-
QTEST_GUILESS_MAIN(KItemSetTest)
#include "kitemsettest.moc"