From 7b7a6050e7f033d232de3afa77c33bbf0580b093 Mon Sep 17 00:00:00 2001 From: Andrei Golubev Date: Fri, 16 Apr 2021 11:38:22 +0200 Subject: Inline test cases in tst_qlist QList tests have mostly a scheme of: void opInt() { op(); } void opMovable() { op(); } void opCustom() { op(); } As a drive by, move the leak checking into a separate struct/macro Change-Id: I7cdda3a6c2aa324968aa26594da9f9eafbd49a0a Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qlist/tst_qlist.cpp | 755 ++++++--------------------- 1 file changed, 157 insertions(+), 598 deletions(-) (limited to 'tests/auto/corelib/tools') diff --git a/tests/auto/corelib/tools/qlist/tst_qlist.cpp b/tests/auto/corelib/tools/qlist/tst_qlist.cpp index d6ff25b830..323c1f5136 100644 --- a/tests/auto/corelib/tools/qlist/tst_qlist.cpp +++ b/tests/auto/corelib/tools/qlist/tst_qlist.cpp @@ -212,81 +212,95 @@ static_assert(QTypeInfo::isComplex); static_assert(!QTypeInfo::isRelocatable); static_assert(QTypeInfo::isComplex); +// leak checking utility: +template +struct LeakChecker +{ + int instancesCount; + LeakChecker() : instancesCount(T::counter.loadAcquire()) { } + ~LeakChecker() { QCOMPARE(instancesCount, T::counter.loadAcquire()); } +}; +template<> struct LeakChecker{}; +template<> struct LeakChecker{}; +#define TST_QLIST_CHECK_LEAKS(Type) \ + LeakChecker checker; \ + Q_UNUSED(checker); class tst_QList : public QObject { Q_OBJECT + private slots: void constructors_empty() const; void constructors_emptyReserveZero() const; void constructors_emptyReserve() const; void constructors_reserveAndInitialize() const; - void copyConstructorInt() const; - void copyConstructorMovable() const; - void copyConstructorCustom() const; - void assignmentInt() const; - void assignmentMovable() const; - void assignmentCustom() const; - void assignFromInitializerListInt() const; - void assignFromInitializerListMovable() const; - void assignFromInitializerListCustom() const; - void addInt() const; - void addMovable() const; - void addCustom() const; - void appendInt() const; - void appendMovable() const; - void appendCustom() const; + void copyConstructorInt() const { copyConstructor(); } + void copyConstructorMovable() const { copyConstructor(); } + void copyConstructorCustom() const { copyConstructor(); } + void assignmentInt() const { testAssignment(); } + void assignmentMovable() const { testAssignment(); } + void assignmentCustom() const { testAssignment(); } + void assignFromInitializerListInt() const { assignFromInitializerList(); } + void assignFromInitializerListMovable() const { assignFromInitializerList(); } + void assignFromInitializerListCustom() const { assignFromInitializerList(); } + void addInt() const { add(); } + void addMovable() const { add(); } + void addCustom() const { add(); } + void appendInt() const { append(); } + void appendMovable() const { append(); } + void appendCustom() const { append(); } void appendRvalue() const; void appendList() const; void at() const; - void capacityInt() const; - void capacityMovable() const; - void capacityCustom() const; - void clearInt() const; - void clearMovable() const; - void clearCustom() const; + void capacityInt() const { capacity(); } + void capacityMovable() const { capacity(); } + void capacityCustom() const { capacity(); } + void clearInt() const { clear(); } + void clearMovable() const { clear(); } + void clearCustom() const { clear(); } void constData() const; void constFirst() const; void constLast() const; void contains() const; - void countInt() const; - void countMovable() const; - void countCustom() const; + void countInt() const { count(); } + void countMovable() const { count(); } + void countCustom() const { count(); } void cpp17ctad() const; void data() const; - void emptyInt() const; - void emptyMovable() const; - void emptyCustom() const; + void emptyInt() const { empty(); } + void emptyMovable() const { empty(); } + void emptyCustom() const { empty(); } void endsWith() const; - void eraseEmptyInt() const; - void eraseEmptyMovable() const; - void eraseEmptyCustom() const; - void eraseEmptyReservedInt() const; - void eraseEmptyReservedMovable() const; - void eraseEmptyReservedCustom() const; - void eraseInt() const; - void eraseIntShared() const; - void eraseMovable() const; - void eraseMovableShared() const; - void eraseCustom() const; - void eraseCustomShared() const; - void eraseReservedInt() const; - void eraseReservedMovable() const; - void eraseReservedCustom() const; - void fillInt() const; - void fillMovable() const; - void fillCustom() const; - void fillDetachInt() const; - void fillDetachMovable() const; - void fillDetachCustom() const; + void eraseEmptyInt() const { eraseEmpty(); } + void eraseEmptyMovable() const { eraseEmpty(); } + void eraseEmptyCustom() const { eraseEmpty(); } + void eraseEmptyReservedInt() const { eraseEmptyReserved(); } + void eraseEmptyReservedMovable() const { eraseEmptyReserved(); } + void eraseEmptyReservedCustom() const { eraseEmptyReserved(); } + void eraseInt() const { erase(false); } + void eraseIntShared() const { erase(true); } + void eraseMovable() const { erase(false); } + void eraseMovableShared() const { erase(true); } + void eraseCustom() const { erase(false); } + void eraseCustomShared() const { erase(true); } + void eraseReservedInt() const { eraseReserved(); } + void eraseReservedMovable() const { eraseReserved(); } + void eraseReservedCustom() const { eraseReserved(); } + void fillInt() const { fill(); } + void fillMovable() const { fill(); } + void fillCustom() const { fill(); } + void fillDetachInt() const { fillDetach(); } + void fillDetachMovable() const { fillDetach(); } + void fillDetachCustom() const { fillDetach(); } void first() const; - void fromListInt() const; - void fromListMovable() const; - void fromListCustom() const; + void fromListInt() const { fromList(); } + void fromListMovable() const { fromList(); } + void fromListCustom() const { fromList(); } void indexOf() const; - void insertInt() const; - void insertMovable() const; - void insertCustom() const; + void insertInt() const { insert(); } + void insertMovable() const { insert(); } + void insertCustom() const { insert(); } void insertZeroCount_data(); void insertZeroCount() const; void isEmpty() const; @@ -294,19 +308,19 @@ private slots: void lastIndexOf() const; void mid() const; void sliced() const; - void moveInt() const; - void moveMovable() const; - void moveCustom() const; - void prependInt() const; - void prependMovable() const; - void prependCustom() const; + void moveInt() const { move(); } + void moveMovable() const { move(); } + void moveCustom() const { move(); } + void prependInt() const { prepend(); } + void prependMovable() const { prepend(); } + void prependCustom() const { prepend(); } void qhashInt() const { qhash(); } void qhashMovable() const { qhash(); } void qhashCustom() const { qhash(); } void removeAllWithAlias() const; - void removeInt() const; - void removeMovable() const; - void removeCustom() const; + void removeInt() const { remove(); } + void removeMovable() const { remove(); } + void removeCustom() const { remove(); } void removeFirstLast() const; void resizePOD_data() const; void resizePOD() const; @@ -319,60 +333,52 @@ private slots: void resizeToTheSameSize_data(); void resizeToTheSameSize() const; void reverseIterators() const; - void sizeInt() const; - void sizeMovable() const; - void sizeCustom() const; + void sizeInt() const { size(); } + void sizeMovable() const { size(); } + void sizeCustom() const { size(); } void startsWith() const; - void swapInt() const; - void swapMovable() const; - void swapCustom() const; + void swapInt() const { swap(); } + void swapMovable() const { swap(); } + void swapCustom() const { swap(); } void toList() const; #if QT_VERSION < QT_VERSION_CHECK(6,0,0) void fromStdVector() const; void toStdVector() const; #endif void value() const; - void testOperators() const; - void reserve(); void reserveZero(); - void initializeListInt(); - void initializeListMovable(); - void initializeListCustom(); - + void initializeListInt() { initializeList(); } + void initializeListMovable() { initializeList(); } + void initializeListCustom() { initializeList(); } void const_shared_null(); - - void detachInt() const; - void detachMovable() const; - void detachCustom() const; + void detachInt() const { detach(); } + void detachMovable() const { detach(); } + void detachCustom() const { detach(); } void detachThreadSafetyInt() const; void detachThreadSafetyMovable() const; void detachThreadSafetyCustom() const; - void insertMove() const; - void swapItemsAt() const; - - void emplaceInt(); - void emplaceCustom(); - void emplaceMovable(); - void emplaceConsistentWithStdVectorInt(); - void emplaceConsistentWithStdVectorCustom(); - void emplaceConsistentWithStdVectorMovable(); - void emplaceConsistentWithStdVectorQString(); + void emplaceInt() { emplaceImpl(); } + void emplaceCustom() { emplaceImpl(); } + void emplaceMovable() { emplaceImpl(); } + void emplaceConsistentWithStdVectorInt() { emplaceConsistentWithStdVectorImpl(); } + void emplaceConsistentWithStdVectorCustom() { emplaceConsistentWithStdVectorImpl(); } + void emplaceConsistentWithStdVectorMovable() { emplaceConsistentWithStdVectorImpl(); } + void emplaceConsistentWithStdVectorQString() { emplaceConsistentWithStdVectorImpl(); } void emplaceReturnsIterator(); void emplaceBack(); void emplaceBackReturnsRef(); void emplaceWithElementFromTheSameContainer(); void emplaceWithElementFromTheSameContainer_data(); - void fromReadOnlyData() const; - void reallocateCustomAlignedType_qtbug90359() const; private: template void copyConstructor() const; + template void testAssignment() const; template void add() const; template void append() const; template void assignFromInitializerList() const; @@ -489,6 +495,8 @@ void tst_QList::constructors_reserveAndInitialize() const template void tst_QList::copyConstructor() const { + TST_QLIST_CHECK_LEAKS(T) + T value1(SimpleValue::at(0)); T value2(SimpleValue::at(1)); T value3(SimpleValue::at(2)); @@ -506,28 +514,11 @@ void tst_QList::copyConstructor() const } } -void tst_QList::copyConstructorInt() const -{ - copyConstructor(); -} - -void tst_QList::copyConstructorMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - copyConstructor(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::copyConstructorCustom() const +template +void tst_QList::testAssignment() const { - const int instancesCount = Custom::counter.loadAcquire(); - copyConstructor(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} + TST_QLIST_CHECK_LEAKS(T) -template -static inline void testAssignment() -{ QList v1(5); QCOMPARE(v1.size(), 5); QVERIFY(v1.isDetached()); @@ -556,24 +547,11 @@ static inline void testAssignment() QCOMPARE((void *)v2.constData(), data2); } -void tst_QList::assignmentInt() const -{ - testAssignment(); -} - -void tst_QList::assignmentMovable() const -{ - testAssignment(); -} - -void tst_QList::assignmentCustom() const -{ - testAssignment(); -} - template void tst_QList::assignFromInitializerList() const { + TST_QLIST_CHECK_LEAKS(T) + T val1(SimpleValue::at(1)); T val2(SimpleValue::at(2)); T val3(SimpleValue::at(3)); @@ -586,28 +564,11 @@ void tst_QList::assignFromInitializerList() const QCOMPARE(v1.size(), 0); } -void tst_QList::assignFromInitializerListInt() const -{ - assignFromInitializerList(); -} - -void tst_QList::assignFromInitializerListMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - assignFromInitializerList(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::assignFromInitializerListCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - assignFromInitializerList(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - template void tst_QList::add() const { + TST_QLIST_CHECK_LEAKS(T) + { QList empty1; QList empty2; @@ -636,28 +597,11 @@ void tst_QList::add() const } } -void tst_QList::addInt() const -{ - add(); -} - -void tst_QList::addMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - add(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::addCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - add(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - template void tst_QList::append() const { + TST_QLIST_CHECK_LEAKS(T) + { QList myvec; myvec.append(SimpleValue::at(0)); @@ -698,25 +642,6 @@ void tst_QList::append() const } } -void tst_QList::appendInt() const -{ - append(); -} - -void tst_QList::appendMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - append(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::appendCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - append(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - void tst_QList::appendRvalue() const { QList v; @@ -951,6 +876,8 @@ void tst_QList::at() const template void tst_QList::capacity() const { + TST_QLIST_CHECK_LEAKS(T) + QList myvec; // TODO: is this guaranteed? seems a safe assumption, but I suppose preallocation of a @@ -978,28 +905,11 @@ void tst_QList::capacity() const QVERIFY(myvec.capacity() == 0); } -void tst_QList::capacityInt() const -{ - capacity(); -} - -void tst_QList::capacityMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - capacity(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::capacityCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - capacity(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - template void tst_QList::clear() const { + TST_QLIST_CHECK_LEAKS(T) + QList myvec; myvec << SimpleValue::at(0) << SimpleValue::at(1) << SimpleValue::at(2); @@ -1010,25 +920,6 @@ void tst_QList::clear() const QCOMPARE(myvec.capacity(), oldCapacity); } -void tst_QList::clearInt() const -{ - clear(); -} - -void tst_QList::clearMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - clear(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::clearCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - clear(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - void tst_QList::constData() const { int arr[] = { 42, 43, 44 }; @@ -1056,6 +947,8 @@ void tst_QList::contains() const template void tst_QList::count() const { + TST_QLIST_CHECK_LEAKS(T) + // total size { // zero size @@ -1094,25 +987,6 @@ void tst_QList::count() const } } -void tst_QList::countInt() const -{ - count(); -} - -void tst_QList::countMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - count(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::countCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - count(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - void tst_QList::cpp17ctad() const { #ifdef __cpp_deduction_guides @@ -1161,6 +1035,8 @@ void tst_QList::data() const template void tst_QList::empty() const { + TST_QLIST_CHECK_LEAKS(T) + QList myvec; // starts empty @@ -1175,25 +1051,6 @@ void tst_QList::empty() const QVERIFY(myvec.empty()); } -void tst_QList::emptyInt() const -{ - empty(); -} - -void tst_QList::emptyMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - empty(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::emptyCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - empty(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - void tst_QList::endsWith() const { QList myvec; @@ -1217,58 +1074,24 @@ void tst_QList::endsWith() const template void tst_QList::eraseEmpty() const { + TST_QLIST_CHECK_LEAKS(T) + QList v; v.erase(v.begin(), v.end()); QCOMPARE(v.size(), 0); } -void tst_QList::eraseEmptyInt() const -{ - eraseEmpty(); -} - -void tst_QList::eraseEmptyMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - eraseEmpty(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::eraseEmptyCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - eraseEmpty(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - template void tst_QList::eraseEmptyReserved() const { + TST_QLIST_CHECK_LEAKS(T) + QList v; v.reserve(10); v.erase(v.begin(), v.end()); QCOMPARE(v.size(), 0); } -void tst_QList::eraseEmptyReservedInt() const -{ - eraseEmptyReserved(); -} - -void tst_QList::eraseEmptyReservedMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - eraseEmptyReserved(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::eraseEmptyReservedCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - eraseEmptyReserved(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - template struct SharedVectorChecker { @@ -1299,10 +1122,12 @@ struct SharedVectorChecker template void tst_QList::erase(bool shared) const { - // note: remove() is actually more efficient, and more dangerous, because it uses the non-detaching - // begin() / end() internally. you can also use constBegin() and constEnd() with erase(), but only - // using reinterpret_cast... because both iterator types are really just pointers. - // so we use a mix of erase() and remove() to cover more cases. + TST_QLIST_CHECK_LEAKS(T) + + // note: remove() is actually more efficient, and more dangerous, because it uses the + // non-detaching begin() / end() internally. you can also use constBegin() and constEnd() with + // erase(), but only using reinterpret_cast... because both iterator types are really just + // pointers. so we use a mix of erase() and remove() to cover more cases. { QList v = SimpleValue::vector(12); SharedVectorChecker svc(v, shared); @@ -1356,46 +1181,11 @@ void tst_QList::erase(bool shared) const } } -void tst_QList::eraseInt() const -{ - erase(false); -} - -void tst_QList::eraseIntShared() const -{ - erase(true); -} - -void tst_QList::eraseMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - erase(false); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::eraseMovableShared() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - erase(true); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::eraseCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - erase(false); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - -void tst_QList::eraseCustomShared() const +template +void tst_QList::eraseReserved() const { - const int instancesCount = Custom::counter.loadAcquire(); - erase(true); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} + TST_QLIST_CHECK_LEAKS(T) -template void tst_QList::eraseReserved() const -{ { QList v(12); v.reserve(16); @@ -1428,28 +1218,11 @@ template void tst_QList::eraseReserved() const } } -void tst_QList::eraseReservedInt() const -{ - eraseReserved(); -} - -void tst_QList::eraseReservedMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - eraseReserved(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::eraseReservedCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - eraseReserved(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - template void tst_QList::fill() const { + TST_QLIST_CHECK_LEAKS(T) + QList myvec; // resize @@ -1472,28 +1245,11 @@ void tst_QList::fill() const QCOMPARE(myvec, QList() << SimpleValue::at(3) << SimpleValue::at(3)); } -void tst_QList::fillInt() const -{ - fill(); -} - -void tst_QList::fillMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - fill(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::fillCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - fill(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - template void tst_QList::fillDetach() const { + TST_QLIST_CHECK_LEAKS(T) + // detaches to the same size { QList original = { SimpleValue::at(1), SimpleValue::at(1), SimpleValue::at(1) }; @@ -1531,25 +1287,6 @@ void tst_QList::fillDetach() const } } -void tst_QList::fillDetachInt() const -{ - fillDetach(); -} - -void tst_QList::fillDetachMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - fillDetach(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::fillDetachCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - fillDetach(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - void tst_QList::first() const { QList myvec; @@ -1647,6 +1384,8 @@ void tst_QList::constFirst() const template void tst_QList::fromList() const { + TST_QLIST_CHECK_LEAKS(T) + QList list; list << SimpleValue::at(0) << SimpleValue::at(1) << SimpleValue::at(2) << SimpleValue::at(3); @@ -1658,25 +1397,6 @@ void tst_QList::fromList() const QCOMPARE(list, QList() << SimpleValue::at(0) << SimpleValue::at(1) << SimpleValue::at(2) << SimpleValue::at(3)); } -void tst_QList::fromListInt() const -{ - fromList(); -} - -void tst_QList::fromListMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - fromList(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::fromListCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - fromList(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - #if QT_VERSION < QT_VERSION_CHECK(6,0,0) void tst_QList::fromStdVector() const { @@ -1720,6 +1440,8 @@ void tst_QList::indexOf() const template void tst_QList::insert() const { + TST_QLIST_CHECK_LEAKS(T) + QList myvec; const T tA = SimpleValue::at(0), @@ -1785,21 +1507,6 @@ void tst_QList::insert() const QCOMPARE(myvec2, myvec); } -void tst_QList::insertInt() const -{ - insert(); -} - -void tst_QList::insertMovable() const -{ - insert(); -} - -void tst_QList::insertCustom() const -{ - insert(); -} - void tst_QList::insertZeroCount_data() { QTest::addColumn("pos"); @@ -1981,6 +1688,8 @@ void tst_QList::sliced() const template void tst_QList::qhash() const { + TST_QLIST_CHECK_LEAKS(T) + QList l1, l2; QCOMPARE(qHash(l1), qHash(l2)); l1 << SimpleValue::at(0); @@ -1991,6 +1700,8 @@ void tst_QList::qhash() const template void tst_QList::move() const { + TST_QLIST_CHECK_LEAKS(T) + QList list; list << T_FOO << T_BAR << T_BAZ; @@ -2007,28 +1718,11 @@ void tst_QList::move() const QCOMPARE(list, QList() << T_BAR << T_FOO << T_BAZ); } -void tst_QList::moveInt() const -{ - move(); -} - -void tst_QList::moveMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - move(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::moveCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - move(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - template void tst_QList::prepend() const { + TST_QLIST_CHECK_LEAKS(T) + QList myvec; T val1 = SimpleValue::at(0); T val2 = SimpleValue::at(1); @@ -2062,25 +1756,6 @@ void tst_QList::prepend() const QCOMPARE(myvec.at(0), val5); } -void tst_QList::prependInt() const -{ - prepend(); -} - -void tst_QList::prependMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - prepend(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::prependCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - prepend(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - void tst_QList::removeAllWithAlias() const { QList strings; @@ -2091,6 +1766,8 @@ void tst_QList::removeAllWithAlias() const template void tst_QList::remove() const { + TST_QLIST_CHECK_LEAKS(T) + QList myvec; T val1 = SimpleValue::at(1); T val2 = SimpleValue::at(2); @@ -2127,25 +1804,6 @@ void tst_QList::remove() const QCOMPARE(myvec, QList()); } -void tst_QList::removeInt() const -{ - remove(); -} - -void tst_QList::removeMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - remove(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::removeCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - remove(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - struct RemoveLastTestClass { RemoveLastTestClass() { other = 0; deleted = false; } @@ -2472,6 +2130,8 @@ void tst_QList::reverseIterators() const template void tst_QList::size() const { + TST_QLIST_CHECK_LEAKS(T) + // zero size QList myvec; QVERIFY(myvec.size() == 0); @@ -2489,25 +2149,6 @@ void tst_QList::size() const QVERIFY(myvec.size() == 0); } -void tst_QList::sizeInt() const -{ - size(); -} - -void tst_QList::sizeMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - size(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::sizeCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - size(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - // ::squeeze() is tested in ::capacity(). void tst_QList::startsWith() const @@ -2533,6 +2174,8 @@ void tst_QList::startsWith() const template void tst_QList::swap() const { + TST_QLIST_CHECK_LEAKS(T) + QList v1, v2; T val1 = SimpleValue::at(0); T val2 = SimpleValue::at(1); @@ -2548,25 +2191,6 @@ void tst_QList::swap() const QCOMPARE(v2,QList() << val1 << val2 << val3); } -void tst_QList::swapInt() const -{ - swap(); -} - -void tst_QList::swapMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - swap(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::swapCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - swap(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - void tst_QList::toList() const { QList myvec; @@ -2716,6 +2340,8 @@ void tst_QList::reserveZero() template void tst_QList::initializeList() { + TST_QLIST_CHECK_LEAKS(T) + T val1(SimpleValue::at(1)); T val2(SimpleValue::at(2)); T val3(SimpleValue::at(3)); @@ -2734,25 +2360,6 @@ void tst_QList::initializeList() QCOMPARE(v4.size(), 0); } -void tst_QList::initializeListInt() -{ - initializeList(); -} - -void tst_QList::initializeListMovable() -{ - const int instancesCount = Movable::counter.loadAcquire(); - initializeList(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::initializeListCustom() -{ - const int instancesCount = Custom::counter.loadAcquire(); - initializeList(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - void tst_QList::const_shared_null() { QList v2; @@ -2762,6 +2369,8 @@ void tst_QList::const_shared_null() template void tst_QList::detach() const { + TST_QLIST_CHECK_LEAKS(T) + { // detach an empty vector QList v; @@ -2856,25 +2465,6 @@ void tst_QList::detach() const } } -void tst_QList::detachInt() const -{ - detach(); -} - -void tst_QList::detachMovable() const -{ - const int instancesCount = Movable::counter.loadAcquire(); - detach(); - QCOMPARE(instancesCount, Movable::counter.loadAcquire()); -} - -void tst_QList::detachCustom() const -{ - const int instancesCount = Custom::counter.loadAcquire(); - detach(); - QCOMPARE(instancesCount, Custom::counter.loadAcquire()); -} - static QAtomicPointer > detachThreadSafetyDataInt; static QAtomicPointer > detachThreadSafetyDataMovable; static QAtomicPointer > detachThreadSafetyDataCustom; @@ -3023,41 +2613,6 @@ void tst_QList::swapItemsAt() const QCOMPARE(copy.at(2), 2); } -void tst_QList::emplaceInt() -{ - emplaceImpl(); -} - -void tst_QList::emplaceCustom() -{ - emplaceImpl(); -} - -void tst_QList::emplaceMovable() -{ - emplaceImpl(); -} - -void tst_QList::emplaceConsistentWithStdVectorInt() -{ - emplaceConsistentWithStdVectorImpl(); -} - -void tst_QList::emplaceConsistentWithStdVectorCustom() -{ - emplaceConsistentWithStdVectorImpl(); -} - -void tst_QList::emplaceConsistentWithStdVectorMovable() -{ - emplaceConsistentWithStdVectorImpl(); -} - -void tst_QList::emplaceConsistentWithStdVectorQString() -{ - emplaceConsistentWithStdVectorImpl(); -} - void tst_QList::emplaceReturnsIterator() { QList vec; @@ -3126,6 +2681,8 @@ void tst_QList::emplaceWithElementFromTheSameContainer_data() template void tst_QList::emplaceImpl() const { + TST_QLIST_CHECK_LEAKS(T) + QList vec {'a', 'b', 'c', 'd'}; vec.emplace(2, 'k'); @@ -3150,6 +2707,8 @@ static void squeezeVec(QList &qVec, std::vector &stdVec) template void tst_QList::emplaceConsistentWithStdVectorImpl() const { + TST_QLIST_CHECK_LEAKS(T) + // fast-patch to make QString work with the old logic const auto convert = [] (char i) { if constexpr (std::is_same_v) { -- cgit v1.2.3