From e8843b56103c5f296fb8dfe8684071ea60ee20da Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Wed, 16 Sep 2020 16:49:45 +0200 Subject: [PATCH] Remove a leftover of qlinkedlist test Change-Id: I5f64ef8fc6134e0670606771a48d6f392c0fa223 Reviewed-by: Jarek Kobus Reviewed-by: Andrei Golubev --- .../tools/qlinkedlist/tst_qlinkedlist.cpp | 1148 ----------------- 1 file changed, 1148 deletions(-) delete mode 100644 tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp diff --git a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp deleted file mode 100644 index 8d4f6ce3fb..0000000000 --- a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp +++ /dev/null @@ -1,1148 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#include -#include - -#if QT_DEPRECATED_SINCE(5, 15) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - -struct Movable -{ - Movable(char input = 'j') : i(input), state(Constructed) - { - ++liveCount; - } - Movable(const Movable &other) - : i(other.i) - , state(Constructed) - { - check(other.state, Constructed); - ++liveCount; - } - - ~Movable() - { - check(state, Constructed); - i = 0; - --liveCount; - state = Destructed; - } - - bool operator ==(const Movable &other) const - { - check(state, Constructed); - check(other.state, Constructed); - return i == other.i; - } - - Movable &operator=(const Movable &other) - { - check(state, Constructed); - check(other.state, Constructed); - i = other.i; - return *this; - } - char i; - - static int getLiveCount() { return liveCount; } -private: - static int liveCount; - - enum State { Constructed = 106, Destructed = 110 }; - State state; - - static void check(const State state1, const State state2) - { - QCOMPARE(int(state1), int(state2)); - } -}; - -int Movable::liveCount = 0; - -QT_BEGIN_NAMESPACE -Q_DECLARE_TYPEINFO(Movable, Q_MOVABLE_TYPE); -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(Movable); - -Q_DECLARE_METATYPE(QLinkedList); - - -int qHash(const Movable& movable) -{ - return qHash(movable.i); -} - -struct Complex -{ - Complex(int val = 0) - : value(val) - , checkSum(this) - { - ++liveCount; - } - - Complex(Complex const &other) - : value(other.value) - , checkSum(this) - { - ++liveCount; - } - - Complex &operator=(Complex const &other) - { - check(); other.check(); - - value = other.value; - return *this; - } - - ~Complex() - { - --liveCount; - check(); - } - - operator int() const { return value; } - - bool operator==(Complex const &other) const - { - check(); other.check(); - return value == other.value; - } - - void check() const - { - QVERIFY(this == checkSum); - } - - static int getLiveCount() { return liveCount; } -private: - static int liveCount; - - int value; - void *checkSum; -}; - -int Complex::liveCount = 0; - -Q_DECLARE_METATYPE(Complex); - -// Tests depend on the fact that: -static_assert(!QTypeInfo::isStatic); -static_assert(!QTypeInfo::isComplex); -static_assert(!QTypeInfo::isStatic); -static_assert(QTypeInfo::isComplex); -static_assert(QTypeInfo::isStatic); -static_assert(QTypeInfo::isComplex); - -class tst_QLinkedList : public QObject -{ - Q_OBJECT -private slots: - void eraseValidIteratorsOnSharedList() const; - void insertWithIteratorsOnSharedList() const; - void lengthInt() const; - void lengthMovable() const; - void lengthComplex() const; - void lengthSignature() const; - void firstInt() const; - void firstMovable() const; - void firstComplex() const; - void lastInt() const; - void lastMovable() const; - void lastComplex() const; - void beginInt() const; - void beginMovable() const; - void beginComplex() const; - void endInt() const; - void endMovable() const; - void endComplex() const; - void containsInt() const; - void containsMovable() const; - void containsComplex() const; - void countInt() const; - void countMovable() const; - void countComplex() const; - void cpp17ctad() const; - void emptyInt() const; - void emptyMovable() const; - void emptyComplex() const; - void endsWithInt() const; - void endsWithMovable() const; - void endsWithComplex() const; - void removeAllInt() const; - void removeAllMovable() const; - void removeAllComplex() const; - void removeOneInt() const; - void removeOneMovable() const; - void removeOneComplex() const; - void reverseIterators() const; - void startsWithInt() const; - void startsWithMovable() const; - void startsWithComplex() const; - void takeFirstInt() const; - void takeFirstMovable() const; - void takeFirstComplex() const; - void takeLastInt() const; - void takeLastMovable() const; - void takeLastComplex() const; - void toStdListInt() const; - void toStdListMovable() const; - void toStdListComplex() const; - void testOperatorsInt() const; - void testOperatorsMovable() const; - void testOperatorsComplex() const; - void testSTLIteratorsInt() const; - void testSTLIteratorsMovable() const; - void testSTLIteratorsComplex() const; - - void initializeList() const; - - void constSharedNullInt() const; - void constSharedNullMovable() const; - void constSharedNullComplex() const; - - void setSharableInt() const; -private: - template void length() const; - template void first() const; - template void last() const; - template void begin() const; - template void end() const; - template void contains() const; - template void count() const; - template void empty() const; - template void endsWith() const; - template void move() const; - template void removeAll() const; - template void removeOne() const; - template void startsWith() const; - template void swap() const; - template void takeFirst() const; - template void takeLast() const; - template void toStdList() const; - template void value() const; - - template void testOperators() const; - template void testSTLIterators() const; - - template void constSharedNull() const; - - int dummyForGuard; -}; - -template struct SimpleValue -{ - static T at(int index) - { - return values[index % maxSize]; - } - static const uint maxSize = 7; - static const T values[maxSize]; -}; - -template<> -const int SimpleValue::values[] = { 10, 20, 30, 40, 100, 101, 102 }; -template<> -const Movable SimpleValue::values[] = { 10, 20, 30, 40, 100, 101, 102 }; -template<> -const Complex SimpleValue::values[] = { 10, 20, 30, 40, 100, 101, 102 }; - -// Make some macros for the tests to use in order to be slightly more readable... -#define T_FOO SimpleValue::at(0) -#define T_BAR SimpleValue::at(1) -#define T_BAZ SimpleValue::at(2) -#define T_CAT SimpleValue::at(3) -#define T_DOG SimpleValue::at(4) -#define T_BLAH SimpleValue::at(5) -#define T_WEEE SimpleValue::at(6) - -template -void tst_QLinkedList::length() const -{ - /* Empty list. */ - { - const QLinkedList list; - QCOMPARE(list.size(), 0); - } - - /* One entry. */ - { - QLinkedList list; - list.append(T_FOO); - QCOMPARE(list.size(), 1); - } - - /* Two entries. */ - { - QLinkedList list; - list.append(T_FOO); - list.append(T_BAR); - QCOMPARE(list.size(), 2); - } - - /* Three entries. */ - { - QLinkedList list; - list.append(T_FOO); - list.append(T_BAR); - list.append(T_BAZ); - QCOMPARE(list.size(), 3); - } -} - -void tst_QLinkedList::eraseValidIteratorsOnSharedList() const -{ - QLinkedList a, b; - a.append(5); - a.append(10); - a.append(20); - a.append(20); - a.append(20); - a.append(20); - a.append(30); - - QLinkedList::iterator i = a.begin(); - ++i; - ++i; - ++i; - b = a; - QLinkedList::iterator r = a.erase(i); - QCOMPARE(b.size(), 7); - QCOMPARE(a.size(), 6); - --r; - --r; - QCOMPARE(*r, 10); // Ensure that number 2 instance was removed; -} - -void tst_QLinkedList::insertWithIteratorsOnSharedList() const -{ - QLinkedList a, b; - a.append(5); - a.append(10); - a.append(20); - QLinkedList::iterator i = a.begin(); - ++i; - ++i; - b = a; - - QLinkedList::iterator i2 = a.insert(i, 15); - QCOMPARE(b.size(), 3); - QCOMPARE(a.size(), 4); - --i2; - QCOMPARE(*i2, 10); -} - -void tst_QLinkedList::lengthInt() const -{ - length(); -} - -void tst_QLinkedList::lengthMovable() const -{ - const int liveCount = Movable::getLiveCount(); - length(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::lengthComplex() const -{ - const int liveCount = Complex::getLiveCount(); - length(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -void tst_QLinkedList::lengthSignature() const -{ - /* Constness. */ - { - const QLinkedList list; - /* The function should be const. */ - list.size(); - } -} - -template -void tst_QLinkedList::first() const -{ - QLinkedList list; - list << T_FOO << T_BAR; - - QCOMPARE(list.first(), T_FOO); - - // remove an item, make sure it still works - list.pop_front(); - QVERIFY(list.size() == 1); - QCOMPARE(list.first(), T_BAR); -} - -void tst_QLinkedList::firstInt() const -{ - first(); -} - -void tst_QLinkedList::firstMovable() const -{ - const int liveCount = Movable::getLiveCount(); - first(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::firstComplex() const -{ - const int liveCount = Complex::getLiveCount(); - first(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QLinkedList::last() const -{ - QLinkedList list; - list << T_FOO << T_BAR; - - QCOMPARE(list.last(), T_BAR); - - // remove an item, make sure it still works - list.pop_back(); - QVERIFY(list.size() == 1); - QCOMPARE(list.last(), T_FOO); -} - -void tst_QLinkedList::lastInt() const -{ - last(); -} - -void tst_QLinkedList::lastMovable() const -{ - const int liveCount = Movable::getLiveCount(); - last(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::lastComplex() const -{ - const int liveCount = Complex::getLiveCount(); - last(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QLinkedList::begin() const -{ - QLinkedList list; - list << T_FOO << T_BAR; - - QCOMPARE(*list.begin(), T_FOO); - - // remove an item, make sure it still works - list.pop_front(); - QVERIFY(list.size() == 1); - QCOMPARE(*list.begin(), T_BAR); -} - -void tst_QLinkedList::beginInt() const -{ - begin(); -} - -void tst_QLinkedList::beginMovable() const -{ - const int liveCount = Movable::getLiveCount(); - begin(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::beginComplex() const -{ - const int liveCount = Complex::getLiveCount(); - begin(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QLinkedList::end() const -{ - QLinkedList list; - list << T_FOO << T_BAR; - - QCOMPARE(*--list.end(), T_BAR); - - // remove an item, make sure it still works - list.pop_back(); - QVERIFY(list.size() == 1); - QCOMPARE(*--list.end(), T_FOO); -} - -void tst_QLinkedList::endInt() const -{ - end(); -} - -void tst_QLinkedList::endMovable() const -{ - const int liveCount = Movable::getLiveCount(); - end(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::endComplex() const -{ - const int liveCount = Complex::getLiveCount(); - end(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QLinkedList::contains() const -{ - QLinkedList list; - list << T_FOO << T_BAR << T_BAZ; - - QVERIFY(list.contains(T_FOO)); - QVERIFY(list.contains(T_BLAH) != true); - - // add it and make sure it matches - list.append(T_BLAH); - QVERIFY(list.contains(T_BLAH)); -} - -void tst_QLinkedList::containsInt() const -{ - contains(); -} - -void tst_QLinkedList::containsMovable() const -{ - const int liveCount = Movable::getLiveCount(); - contains(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::containsComplex() const -{ - const int liveCount = Complex::getLiveCount(); - contains(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QLinkedList::count() const -{ - QLinkedList list; - - // starts empty - QVERIFY(list.count() == 0); - - // goes up - list.append(T_FOO); - QVERIFY(list.count() == 1); - - // and up - list.append(T_BAR); - QVERIFY(list.count() == 2); - - // and down - list.pop_back(); - QVERIFY(list.count() == 1); - - // and empty. :) - list.pop_back(); - QVERIFY(list.count() == 0); -} - -void tst_QLinkedList::countInt() const -{ - count(); -} - -void tst_QLinkedList::countMovable() const -{ - const int liveCount = Movable::getLiveCount(); - count(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::countComplex() const -{ - const int liveCount = Complex::getLiveCount(); - count(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -void tst_QLinkedList::cpp17ctad() const -{ -#ifdef __cpp_deduction_guides -#define QVERIFY_IS_LIST_OF(obj, Type) \ - QVERIFY2((std::is_same>::value), \ - QMetaType::typeName(qMetaTypeId())) -#define CHECK(Type, One, Two, Three) \ - do { \ - const Type v[] = {One, Two, Three}; \ - QLinkedList v1 = {One, Two, Three}; \ - QVERIFY_IS_LIST_OF(v1, Type); \ - QLinkedList v2(v1.begin(), v1.end()); \ - QVERIFY_IS_LIST_OF(v2, Type); \ - QLinkedList v3(std::begin(v), std::end(v)); \ - QVERIFY_IS_LIST_OF(v3, Type); \ - } while (false) \ - /*end*/ - CHECK(int, 1, 2, 3); - CHECK(double, 1.0, 2.0, 3.0); - CHECK(QString, QStringLiteral("one"), QStringLiteral("two"), QStringLiteral("three")); -#undef QVERIFY_IS_LIST_OF -#undef CHECK -#else - QSKIP("This test requires C++17 Constructor Template Argument Deduction support enabled in the compiler."); -#endif -} - -template -void tst_QLinkedList::empty() const -{ - QLinkedList list; - - // make sure it starts empty - QVERIFY(list.empty()); - - // and doesn't stay empty - list.append(T_FOO); - QVERIFY(!list.empty()); - - // and goes back to being empty - list.pop_back(); - QVERIFY(list.empty()); -} - -void tst_QLinkedList::emptyInt() const -{ - empty(); -} - -void tst_QLinkedList::emptyMovable() const -{ - const int liveCount = Movable::getLiveCount(); - empty(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::emptyComplex() const -{ - const int liveCount = Complex::getLiveCount(); - empty(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QLinkedList::endsWith() const -{ - QLinkedList list; - list << T_FOO << T_BAR << T_BAZ; - - // test it returns correctly in both cases - QVERIFY(list.endsWith(T_BAZ)); - QVERIFY(!list.endsWith(T_BAR)); - - // remove an item and make sure the end item changes - list.pop_back(); - QVERIFY(list.endsWith(T_BAR)); -} - -void tst_QLinkedList::endsWithInt() const -{ - endsWith(); -} - -void tst_QLinkedList::endsWithMovable() const -{ - const int liveCount = Movable::getLiveCount(); - endsWith(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::endsWithComplex() const -{ - const int liveCount = Complex::getLiveCount(); - endsWith(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QLinkedList::removeAll() const -{ - QLinkedList list; - list << T_FOO << T_BAR << T_BAZ; - - // remove one instance - list.removeAll(T_BAR); - QCOMPARE(list, QLinkedList() << T_FOO << T_BAZ); - - // many instances - list << T_FOO << T_BAR << T_BAZ << T_FOO << T_BAR << T_BAZ << T_FOO << T_BAR << T_BAZ; - list.removeAll(T_BAR); - QCOMPARE(list, QLinkedList() << T_FOO << T_BAZ << T_FOO << T_BAZ << T_FOO << T_BAZ << T_FOO << T_BAZ); - - // try remove something that doesn't exist - list.removeAll(T_WEEE); - QCOMPARE(list, QLinkedList() << T_FOO << T_BAZ << T_FOO << T_BAZ << T_FOO << T_BAZ << T_FOO << T_BAZ); -} - -void tst_QLinkedList::removeAllInt() const -{ - removeAll(); -} - -void tst_QLinkedList::removeAllMovable() const -{ - const int liveCount = Movable::getLiveCount(); - removeAll(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::removeAllComplex() const -{ - const int liveCount = Complex::getLiveCount(); - removeAll(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QLinkedList::removeOne() const -{ - QLinkedList list; - list << T_FOO << T_BAR << T_BAZ; - - // middle - list.removeOne(T_BAR); - QCOMPARE(list, QLinkedList() << T_FOO << T_BAZ); - - // start - list.removeOne(T_FOO); - QCOMPARE(list, QLinkedList() << T_BAZ); - - // last - list.removeOne(T_BAZ); - QCOMPARE(list, QLinkedList()); - - // make sure it really only removes one :) - list << T_FOO << T_FOO; - list.removeOne(T_FOO); - QCOMPARE(list, QLinkedList() << T_FOO); - - // try remove something that doesn't exist - list.removeOne(T_WEEE); - QCOMPARE(list, QLinkedList() << T_FOO); -} - -void tst_QLinkedList::removeOneInt() const -{ - removeOne(); -} - -void tst_QLinkedList::removeOneMovable() const -{ - const int liveCount = Movable::getLiveCount(); - removeOne(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::removeOneComplex() const -{ - const int liveCount = Complex::getLiveCount(); - removeOne(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -void tst_QLinkedList::reverseIterators() const -{ - QLinkedList l; - l << 1 << 2 << 3 << 4; - QLinkedList lr = l; - std::reverse(lr.begin(), lr.end()); - const QLinkedList &clr = lr; - QVERIFY(std::equal(l.begin(), l.end(), lr.rbegin())); - QVERIFY(std::equal(l.begin(), l.end(), lr.crbegin())); - QVERIFY(std::equal(l.begin(), l.end(), clr.rbegin())); - QVERIFY(std::equal(lr.rbegin(), lr.rend(), l.begin())); - QVERIFY(std::equal(lr.crbegin(), lr.crend(), l.begin())); - QVERIFY(std::equal(clr.rbegin(), clr.rend(), l.begin())); -} - -template -void tst_QLinkedList::startsWith() const -{ - QLinkedList list; - list << T_FOO << T_BAR << T_BAZ; - - // make sure it starts ok - QVERIFY(list.startsWith(T_FOO)); - - // remove an item - list.removeFirst(); - QVERIFY(list.startsWith(T_BAR)); -} - -void tst_QLinkedList::startsWithInt() const -{ - startsWith(); -} - -void tst_QLinkedList::startsWithMovable() const -{ - const int liveCount = Movable::getLiveCount(); - startsWith(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::startsWithComplex() const -{ - const int liveCount = Complex::getLiveCount(); - startsWith(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QLinkedList::takeFirst() const -{ - QLinkedList list; - list << T_FOO << T_BAR << T_BAZ; - - QCOMPARE(list.takeFirst(), T_FOO); - QVERIFY(list.size() == 2); - QCOMPARE(list.takeFirst(), T_BAR); - QVERIFY(list.size() == 1); - QCOMPARE(list.takeFirst(), T_BAZ); - QVERIFY(list.size() == 0); -} - -void tst_QLinkedList::takeFirstInt() const -{ - takeFirst(); -} - -void tst_QLinkedList::takeFirstMovable() const -{ - const int liveCount = Movable::getLiveCount(); - takeFirst(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::takeFirstComplex() const -{ - const int liveCount = Complex::getLiveCount(); - takeFirst(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QLinkedList::takeLast() const -{ - QLinkedList list; - list << T_FOO << T_BAR << T_BAZ; - - QCOMPARE(list.takeLast(), T_BAZ); - QCOMPARE(list.takeLast(), T_BAR); - QCOMPARE(list.takeLast(), T_FOO); -} - -void tst_QLinkedList::takeLastInt() const -{ - takeLast(); -} - -void tst_QLinkedList::takeLastMovable() const -{ - const int liveCount = Movable::getLiveCount(); - takeLast(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::takeLastComplex() const -{ - const int liveCount = Complex::getLiveCount(); - takeLast(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QLinkedList::toStdList() const -{ - QLinkedList list; - list << T_FOO << T_BAR << T_BAZ; - - // yuck. - std::list slist; - slist.push_back(T_FOO); - slist.push_back(T_BAR); - slist.push_back(T_BAZ); - - QCOMPARE(list.toStdList(), slist); - QCOMPARE(list, QLinkedList() << T_FOO << T_BAR << T_BAZ); -} - -void tst_QLinkedList::toStdListInt() const -{ - toStdList(); -} - -void tst_QLinkedList::toStdListMovable() const -{ - const int liveCount = Movable::getLiveCount(); - toStdList(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::toStdListComplex() const -{ - const int liveCount = Complex::getLiveCount(); - toStdList(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QLinkedList::testOperators() const -{ - QLinkedList list; - list << T_FOO << T_BAR << T_BAZ; - - QLinkedList listtwo; - listtwo << T_FOO << T_BAR << T_BAZ; - - // test equal - QVERIFY(list == listtwo); - - // not equal - listtwo.append(T_CAT); - QVERIFY(list != listtwo); - - // += - list += listtwo; - QVERIFY(list.size() == 7); - QVERIFY(listtwo.size() == 4); - QCOMPARE(list, QLinkedList() << T_FOO << T_BAR << T_BAZ - << T_FOO << T_BAR << T_BAZ << T_CAT); - - // = - list = listtwo; - QCOMPARE(list, listtwo); - QCOMPARE(list, QLinkedList() << T_FOO << T_BAR << T_BAZ << T_CAT); -} - -void tst_QLinkedList::testOperatorsInt() const -{ - testOperators(); -} - -void tst_QLinkedList::testOperatorsMovable() const -{ - const int liveCount = Movable::getLiveCount(); - testOperators(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::testOperatorsComplex() const -{ - const int liveCount = Complex::getLiveCount(); - testOperators(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -template -void tst_QLinkedList::testSTLIterators() const -{ - QLinkedList list; - - // create a list - list << T_FOO << T_BAR << T_BAZ; - typename QLinkedList::iterator it = list.begin(); - QCOMPARE(*it, T_FOO); it++; - QCOMPARE(*it, T_BAR); it++; - QCOMPARE(*it, T_BAZ); it++; - QCOMPARE(it, list.end()); it--; - - // walk backwards - QCOMPARE(*it, T_BAZ); it--; - QCOMPARE(*it, T_BAR); it--; - QCOMPARE(*it, T_FOO); - - // test erase - it = list.erase(it); - QVERIFY(list.size() == 2); - QCOMPARE(*it, T_BAR); - - // test multiple erase - it = list.erase(it, it + 2); - QVERIFY(list.size() == 0); - QCOMPARE(it, list.end()); - - // insert again - it = list.insert(it, T_FOO); - QVERIFY(list.size() == 1); - QCOMPARE(*it, T_FOO); - - // insert again - it = list.insert(it, T_BAR); - QVERIFY(list.size() == 2); - QCOMPARE(*it++, T_BAR); - QCOMPARE(*it, T_FOO); -} - -void tst_QLinkedList::testSTLIteratorsInt() const -{ - testSTLIterators(); -} - -void tst_QLinkedList::testSTLIteratorsMovable() const -{ - const int liveCount = Movable::getLiveCount(); - testSTLIterators(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::testSTLIteratorsComplex() const -{ - const int liveCount = Complex::getLiveCount(); - testSTLIterators(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - -void tst_QLinkedList::initializeList() const -{ - QLinkedList v1 { 2, 3, 4 }; - QCOMPARE(v1, QLinkedList() << 2 << 3 << 4); - QCOMPARE(v1, (QLinkedList { 2, 3, 4})); - - QLinkedList> v2{ v1, { 1 }, QLinkedList(), { 2, 3, 4 } }; - QLinkedList> v3; - v3 << v1 << (QLinkedList() << 1) << QLinkedList() << v1; - QCOMPARE(v3, v2); -} - - -template -void tst_QLinkedList::constSharedNull() const -{ - QLinkedList list2; -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QLinkedList list1; - list1.setSharable(false); - QVERIFY(list1.isDetached()); - - list2.setSharable(true); -#endif - QVERIFY(!list2.isDetached()); -} - -void tst_QLinkedList::constSharedNullInt() const -{ - constSharedNull(); -} - -void tst_QLinkedList::constSharedNullMovable() const -{ - const int liveCount = Movable::getLiveCount(); - constSharedNull(); - QCOMPARE(liveCount, Movable::getLiveCount()); -} - -void tst_QLinkedList::constSharedNullComplex() const -{ - const int liveCount = Complex::getLiveCount(); - constSharedNull(); - QCOMPARE(liveCount, Complex::getLiveCount()); -} - - -void tst_QLinkedList::setSharableInt() const -{ -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QLinkedList orglist; - orglist << 0 << 1 << 2 << 3 << 4 << 5; - int size = 6; - - QLinkedList list; - list = orglist; - - QVERIFY(!list.isDetached()); - list.setSharable(true); - - QCOMPARE(list.size(), size); - - { - QLinkedList copy(list); - QVERIFY(!copy.isDetached()); - QVERIFY(copy.isSharedWith(list)); - } - - list.setSharable(false); - QVERIFY(list.isDetached() || list.isSharedWith(QLinkedList())); - - { - QLinkedList copy(list); - - QVERIFY(copy.isDetached() || copy.isSharedWith(QLinkedList())); - QCOMPARE(copy.size(), size); - QCOMPARE(copy, list); - } - - list.setSharable(true); - - { - QLinkedList copy(list); - - QVERIFY(!copy.isDetached()); - QVERIFY(copy.isSharedWith(list)); - } - - QLinkedList::const_iterator it = list.constBegin(); - for (int i = 0; i < list.size(); ++i) { - QCOMPARE(int(*it), i); - ++it; - } - - QCOMPARE(list.size(), size); -#endif -} - -QT_WARNING_POP -#else -class tst_QLinkedList : public QObject -{ - Q_OBJECT -private slots: - void initTestCase() { QSKIP("Deprecated APIs are disabled, skipping this test."); } -}; - -#endif // QT_DEPRECATED_SINCE(5, 15) - -QTEST_APPLESS_MAIN(tst_QLinkedList) -#include "tst_qlinkedlist.moc"