From 249a2e3271c3cc36edb88c993d277d93de2cf1c0 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Wed, 4 Mar 2020 15:21:40 +0100 Subject: Disable warnings for the deprecated QLinkedList QLinkedList has been deprecated, but we still need to test it. Suppress the warnings for QLinkedList used in tests. Note, that I had to move some of the test code, to avoid repeating QT_WARNING_PUSH/QT_WARNING_POP everywhere. Change-Id: I4203b3ef50045c4f45475a08638dbdc60f68761d Reviewed-by: Lars Knoll --- .../qtconcurrentfilter/tst_qtconcurrentfilter.cpp | 108 +- .../qtconcurrentmap/tst_qtconcurrentmap.cpp | 1427 +++++++++++--------- .../auto/corelib/kernel/qvariant/tst_qvariant.cpp | 5 + .../serialization/qdatastream/tst_qdatastream.cpp | 87 +- .../corelib/tools/collections/tst_collections.cpp | 52 + .../tst_containerapisymmetry.cpp | 50 +- .../corelib/tools/qlinkedlist/tst_qlinkedlist.cpp | 15 + 7 files changed, 1021 insertions(+), 723 deletions(-) diff --git a/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp b/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp index 84ebd46886..bd55446515 100644 --- a/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp +++ b/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp @@ -62,18 +62,6 @@ void tst_QtConcurrentFilter::filter() QtConcurrent::blockingFilter(list, KeepEvenIntegers()); QCOMPARE(list, QList() << 2 << 4); } - { - QLinkedList linkedList; - linkedList << 1 << 2 << 3 << 4; - QtConcurrent::filter(linkedList, KeepEvenIntegers()).waitForFinished(); - QCOMPARE(linkedList, QLinkedList() << 2 << 4); - } - { - QLinkedList linkedList; - linkedList << 1 << 2 << 3 << 4; - QtConcurrent::blockingFilter(linkedList, KeepEvenIntegers()); - QCOMPARE(linkedList, QLinkedList() << 2 << 4); - } { QVector vector; vector << 1 << 2 << 3 << 4; @@ -100,18 +88,6 @@ void tst_QtConcurrentFilter::filter() QtConcurrent::blockingFilter(list, keepEvenIntegers); QCOMPARE(list, QList() << 2 << 4); } - { - QLinkedList linkedList; - linkedList << 1 << 2 << 3 << 4; - QtConcurrent::filter(linkedList, keepEvenIntegers).waitForFinished(); - QCOMPARE(linkedList, QLinkedList() << 2 << 4); - } - { - QLinkedList linkedList; - linkedList << 1 << 2 << 3 << 4; - QtConcurrent::blockingFilter(linkedList, keepEvenIntegers); - QCOMPARE(linkedList, QLinkedList() << 2 << 4); - } // bound function { @@ -126,6 +102,40 @@ void tst_QtConcurrentFilter::filter() QtConcurrent::blockingFilter(list, keepEvenIntegers); QCOMPARE(list, QList() << 2 << 4); } + + // member + { + QList list; + list << 1 << 2 << 3 << 4; + QtConcurrent::filter(list, &Number::isEven).waitForFinished(); + QCOMPARE(list, QList() << 2 << 4); + } + { + QList list; + list << 1 << 2 << 3 << 4; + QtConcurrent::blockingFilter(list, &Number::isEven); + QCOMPARE(list, QList() << 2 << 4); + } + +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + + // functor + { + QLinkedList linkedList; + linkedList << 1 << 2 << 3 << 4; + QtConcurrent::filter(linkedList, KeepEvenIntegers()).waitForFinished(); + QCOMPARE(linkedList, QLinkedList() << 2 << 4); + } + { + QLinkedList linkedList; + linkedList << 1 << 2 << 3 << 4; + QtConcurrent::blockingFilter(linkedList, KeepEvenIntegers()); + QCOMPARE(linkedList, QLinkedList() << 2 << 4); + } + + // function { QLinkedList linkedList; linkedList << 1 << 2 << 3 << 4; @@ -139,19 +149,21 @@ void tst_QtConcurrentFilter::filter() QCOMPARE(linkedList, QLinkedList() << 2 << 4); } - // member + // bound function { - QList list; - list << 1 << 2 << 3 << 4; - QtConcurrent::filter(list, &Number::isEven).waitForFinished(); - QCOMPARE(list, QList() << 2 << 4); + QLinkedList linkedList; + linkedList << 1 << 2 << 3 << 4; + QtConcurrent::filter(linkedList, keepEvenIntegers).waitForFinished(); + QCOMPARE(linkedList, QLinkedList() << 2 << 4); } { - QList list; - list << 1 << 2 << 3 << 4; - QtConcurrent::blockingFilter(list, &Number::isEven); - QCOMPARE(list, QList() << 2 << 4); + QLinkedList linkedList; + linkedList << 1 << 2 << 3 << 4; + QtConcurrent::blockingFilter(linkedList, keepEvenIntegers); + QCOMPARE(linkedList, QLinkedList() << 2 << 4); } + + // member { QLinkedList linkedList; linkedList << 1 << 2 << 3 << 4; @@ -164,6 +176,9 @@ void tst_QtConcurrentFilter::filter() QtConcurrent::blockingFilter(linkedList, &Number::isEven); QCOMPARE(linkedList, QLinkedList() << 2 << 4); } + +QT_WARNING_POP +#endif } void tst_QtConcurrentFilter::filtered() @@ -219,19 +234,6 @@ void tst_QtConcurrentFilter::filtered() QCOMPARE(f.results(), QList() << 2 << 4); } - { - QLinkedList linkedList; - linkedList << 1 << 2 << 3 << 4; - QLinkedList linkedList2 = QtConcurrent::blockingFiltered(linkedList, KeepEvenIntegers()); - QCOMPARE(linkedList2, QLinkedList() << 2 << 4); - } - { - QLinkedList linkedList; - linkedList << 1 << 2 << 3 << 4; - QFuture f = QtConcurrent::filtered(linkedList, KeepEvenIntegers()); - QCOMPARE(f.results(), QList() << 2 << 4); - } - // function { QFuture f = QtConcurrent::filtered(list, keepEvenIntegers); @@ -352,6 +354,10 @@ void tst_QtConcurrentFilter::filtered() QCOMPARE(list2, QList() << 2 << 4); } +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + // same thing on linked lists QLinkedList linkedList; @@ -517,6 +523,9 @@ void tst_QtConcurrentFilter::filtered() &Number::isEven); QCOMPARE(linkedList2, QLinkedList() << 2 << 4); } + +QT_WARNING_POP +#endif } void tst_QtConcurrentFilter::filteredReduced() @@ -952,6 +961,10 @@ void tst_QtConcurrentFilter::filteredReduced() QCOMPARE(sum, 6); } +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + // same as above on linked lists QLinkedList linkedList; linkedList << 1 << 2 << 3 << 4; @@ -1378,6 +1391,9 @@ void tst_QtConcurrentFilter::filteredReduced() QCOMPARE(sum, 6); } +QT_WARNING_POP +#endif + // ### the same as above, with an initial result value } diff --git a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp index 383de0b2ce..ad62f6cdf1 100644 --- a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp +++ b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp @@ -164,6 +164,9 @@ void tst_QtConcurrentMap::map() QCOMPARE(list, QList() << 1 << 2 << 3); } +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED // Linked lists and forward iterators { QLinkedList list; @@ -195,6 +198,8 @@ void tst_QtConcurrentMap::map() QtConcurrent::map(numberList.begin(), numberList.end(), &Number::multiplyBy2).waitForFinished(); QCOMPARE(numberList, QLinkedList() << 4 << 8 << 12); } +QT_WARNING_POP +#endif #if 0 // not allowed: map() with immutable sequences makes no sense @@ -296,6 +301,9 @@ void tst_QtConcurrentMap::blocking_map() QCOMPARE(list, QList() << 1 << 2 << 3); } +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED // Linked lists and forward iterators { QLinkedList list; @@ -327,6 +335,8 @@ void tst_QtConcurrentMap::blocking_map() QtConcurrent::blockingMap(numberList.begin(), numberList.end(), &Number::multiplyBy2); QCOMPARE(numberList, QLinkedList() << 4 << 8 << 12); } +QT_WARNING_POP +#endif #if 0 // not allowed: map() with immutable sequences makes no sense @@ -424,12 +434,8 @@ void tst_QtConcurrentMap::mapped() { QList list; list << 1 << 2 << 3; - QLinkedList linkedList; - linkedList << 1 << 2 << 3; QList numberList; numberList << 1 << 2 << 3; - QLinkedList numberLinkedList; - numberLinkedList << 1 << 2 << 3; // functor { @@ -447,22 +453,6 @@ void tst_QtConcurrentMap::mapped() QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 2 << 4 << 6); } - { - QList list2 = QtConcurrent::mapped(linkedList, MultiplyBy2()).results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list2, QList() << 2 << 4 << 6); - - QList list3 = QtConcurrent::mapped(linkedList.constBegin(), - linkedList.constEnd(), - MultiplyBy2()).results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list3, QList() << 2 << 4 << 6); - - QList list4 = - QtConcurrent::mapped(QLinkedList(linkedList), MultiplyBy2()).results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list4, QList() << 2 << 4 << 6); - } // function { @@ -480,22 +470,6 @@ void tst_QtConcurrentMap::mapped() QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 2 << 4 << 6); } - { - QList list2 = QtConcurrent::mapped(linkedList, multiplyBy2).results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list2, QList() << 2 << 4 << 6); - - QList list3 = QtConcurrent::mapped(linkedList.constBegin(), - linkedList.constEnd(), - multiplyBy2).results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list3, QList() << 2 << 4 << 6); - - QList list4 = - QtConcurrent::mapped(QLinkedList(linkedList), multiplyBy2).results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list4, QList() << 2 << 4 << 6); - } // bound function { @@ -513,23 +487,6 @@ void tst_QtConcurrentMap::mapped() QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 2 << 4 << 6); } - { - QList list2 = QtConcurrent::mapped(linkedList, multiplyBy2).results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list2, QList() << 2 << 4 << 6); - - QList list3 = QtConcurrent::mapped(linkedList.constBegin(), - linkedList.constEnd(), - multiplyBy2) - .results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list3, QList() << 2 << 4 << 6); - - QList list4 = QtConcurrent::mapped(QLinkedList(linkedList), multiplyBy2) - .results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list4, QList() << 2 << 4 << 6); - } // const member function { @@ -551,25 +508,6 @@ void tst_QtConcurrentMap::mapped() QCOMPARE(numberList, QList() << 1 << 2 << 3); QCOMPARE(numberList4, QList() << 2 << 4 << 6); } - { - QList numberList2 = QtConcurrent::mapped(numberLinkedList, &Number::multipliedBy2) - .results(); - QCOMPARE(numberLinkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(numberList2, QList() << 2 << 4 << 6); - - QList numberList3 = QtConcurrent::mapped(numberLinkedList.constBegin(), - numberLinkedList.constEnd(), - &Number::multipliedBy2) - .results(); - QCOMPARE(numberLinkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(numberList3, QList() << 2 << 4 << 6); - - QList numberList4 = QtConcurrent::mapped(QLinkedList(numberLinkedList), - &Number::multipliedBy2) - .results(); - QCOMPARE(numberLinkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(numberList4, QList() << 2 << 4 << 6); - } // change the value_type, same container @@ -592,24 +530,6 @@ void tst_QtConcurrentMap::mapped() QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 1.0 << 2.0 << 3.0); } - { - QList list2 = QtConcurrent::mapped(linkedList, IntToDouble()).results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list2, QList() << 1.0 << 2.0 << 3.0); - - QList list3 = QtConcurrent::mapped(linkedList.constBegin(), - linkedList.constEnd(), - IntToDouble()) - .results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list3, QList() << 1.0 << 2.0 << 3.0); - - QList list4 = QtConcurrent::mapped(QLinkedList(linkedList), - IntToDouble()) - .results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list4, QList() << 1.0 << 2.0 << 3.0); - } // function { @@ -628,23 +548,6 @@ void tst_QtConcurrentMap::mapped() QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 1.0 << 2.0 << 3.0); } - { - QList list2 = QtConcurrent::mapped(linkedList, intToDouble).results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list2, QList() << 1.0 << 2.0 << 3.0); - - QList list3 = QtConcurrent::mapped(linkedList.constBegin(), - linkedList.constEnd(), - intToDouble) - .results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list3, QList() << 1.0 << 2.0 << 3.0); - - QList list4 = QtConcurrent::mapped(QLinkedList(linkedList), intToDouble) - .results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list4, QList() << 1.0 << 2.0 << 3.0); - } // bound function { @@ -666,25 +569,6 @@ void tst_QtConcurrentMap::mapped() QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 1.0 << 2.0 << 3.0); } - { - QList list2 = QtConcurrent::mapped(linkedList, intToDouble).results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list2, QList() << 1.0 << 2.0 << 3.0); - - QList list3 = QtConcurrent::mapped(linkedList.constBegin(), - linkedList.constEnd(), - intToDouble) - .results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list3, QList() << 1.0 << 2.0 << 3.0); - - - QList list4 = QtConcurrent::mapped(QLinkedList(linkedList), - intToDouble) - .results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list4, QList() << 1.0 << 2.0 << 3.0); - } // const member function { @@ -704,24 +588,6 @@ void tst_QtConcurrentMap::mapped() QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << "1" << "2" << "3"); } - { - QList list2 = QtConcurrent::mapped(numberLinkedList, &Number::toString).results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list2, QList() << "1" << "2" << "3"); - - QList list3 = QtConcurrent::mapped(numberLinkedList.constBegin(), - numberLinkedList.constEnd(), - &Number::toString) - .results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list3, QList() << "1" << "2" << "3"); - - QList list4 = QtConcurrent::mapped(QLinkedList(numberLinkedList), - &Number::toString) - .results(); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(list4, QList() << "1" << "2" << "3"); - } // change the value_type { @@ -780,84 +646,202 @@ void tst_QtConcurrentMap::mapped() .results(); QCOMPARE(list2, QList() << 1 << 2 << 3); } -} -void tst_QtConcurrentMap::blocking_mapped() -{ - QList list; - list << 1 << 2 << 3; +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + QLinkedList linkedList; linkedList << 1 << 2 << 3; - QList numberList; - numberList << 1 << 2 << 3; QLinkedList numberLinkedList; numberLinkedList << 1 << 2 << 3; // functor { - QList list2 = QtConcurrent::blockingMapped(list, MultiplyBy2()); - QCOMPARE(list, QList() << 1 << 2 << 3); + QList list2 = QtConcurrent::mapped(linkedList, MultiplyBy2()).results(); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); QCOMPARE(list2, QList() << 2 << 4 << 6); - QList list3 = QtConcurrent::blockingMapped >(list.constBegin(), - list.constEnd(), - MultiplyBy2()); - QCOMPARE(list, QList() << 1 << 2 << 3); + QList list3 = QtConcurrent::mapped(linkedList.constBegin(), + linkedList.constEnd(), + MultiplyBy2()).results(); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); QCOMPARE(list3, QList() << 2 << 4 << 6); - QList list4 = QtConcurrent::blockingMapped(QList(list), MultiplyBy2()); - QCOMPARE(list, QList() << 1 << 2 << 3); + QList list4 = + QtConcurrent::mapped(QLinkedList(linkedList), MultiplyBy2()).results(); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 2 << 4 << 6); } + + // function { - QLinkedList linkedList2 = QtConcurrent::blockingMapped(linkedList, MultiplyBy2()); + QList list2 = QtConcurrent::mapped(linkedList, multiplyBy2).results(); QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList2, QLinkedList() << 2 << 4 << 6); + QCOMPARE(list2, QList() << 2 << 4 << 6); - QLinkedList linkedList3 = QtConcurrent::blockingMapped >(linkedList.constBegin(), - linkedList.constEnd(), - MultiplyBy2()); + QList list3 = QtConcurrent::mapped(linkedList.constBegin(), + linkedList.constEnd(), + multiplyBy2).results(); QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList3, QLinkedList() << 2 << 4 << 6); + QCOMPARE(list3, QList() << 2 << 4 << 6); - QLinkedList linkedList4 = QtConcurrent::blockingMapped(QLinkedList(linkedList), MultiplyBy2()); + QList list4 = + QtConcurrent::mapped(QLinkedList(linkedList), multiplyBy2).results(); QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList4, QLinkedList() << 2 << 4 << 6); + QCOMPARE(list4, QList() << 2 << 4 << 6); } - // function + // bound function { - QList list2 = QtConcurrent::blockingMapped(list, multiplyBy2); - QCOMPARE(list, QList() << 1 << 2 << 3); + QList list2 = QtConcurrent::mapped(linkedList, multiplyBy2).results(); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); QCOMPARE(list2, QList() << 2 << 4 << 6); - QList list3 = QtConcurrent::blockingMapped >(list.constBegin(), - list.constEnd(), - multiplyBy2); - QCOMPARE(list, QList() << 1 << 2 << 3); + QList list3 = QtConcurrent::mapped(linkedList.constBegin(), + linkedList.constEnd(), + multiplyBy2) + .results(); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); QCOMPARE(list3, QList() << 2 << 4 << 6); - QList list4 = QtConcurrent::blockingMapped(QList(list), multiplyBy2); - QCOMPARE(list, QList() << 1 << 2 << 3); + QList list4 = QtConcurrent::mapped(QLinkedList(linkedList), multiplyBy2) + .results(); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 2 << 4 << 6); } + + // const member function { - QLinkedList linkedList2 = QtConcurrent::blockingMapped(linkedList, multiplyBy2); + QList numberList2 = QtConcurrent::mapped(numberLinkedList, &Number::multipliedBy2) + .results(); + QCOMPARE(numberLinkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(numberList2, QList() << 2 << 4 << 6); + + QList numberList3 = QtConcurrent::mapped(numberLinkedList.constBegin(), + numberLinkedList.constEnd(), + &Number::multipliedBy2) + .results(); + QCOMPARE(numberLinkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(numberList3, QList() << 2 << 4 << 6); + + QList numberList4 = QtConcurrent::mapped(QLinkedList(numberLinkedList), + &Number::multipliedBy2) + .results(); + QCOMPARE(numberLinkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(numberList4, QList() << 2 << 4 << 6); + } + + // change the value_type, same container + + // functor + { + QList list2 = QtConcurrent::mapped(linkedList, IntToDouble()).results(); QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList2, QLinkedList() << 2 << 4 << 6); + QCOMPARE(list2, QList() << 1.0 << 2.0 << 3.0); - QLinkedList linkedList3 = QtConcurrent::blockingMapped >(linkedList.constBegin(), - linkedList.constEnd(), - multiplyBy2); + QList list3 = QtConcurrent::mapped(linkedList.constBegin(), + linkedList.constEnd(), + IntToDouble()) + .results(); QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList3, QLinkedList() << 2 << 4 << 6); + QCOMPARE(list3, QList() << 1.0 << 2.0 << 3.0); - QLinkedList linkedList4 = QtConcurrent::blockingMapped(QLinkedList(linkedList), multiplyBy2); + QList list4 = QtConcurrent::mapped(QLinkedList(linkedList), + IntToDouble()) + .results(); QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList4, QLinkedList() << 2 << 4 << 6); + QCOMPARE(list4, QList() << 1.0 << 2.0 << 3.0); } - // bound function + // function + { + QList list2 = QtConcurrent::mapped(linkedList, intToDouble).results(); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(list2, QList() << 1.0 << 2.0 << 3.0); + + QList list3 = QtConcurrent::mapped(linkedList.constBegin(), + linkedList.constEnd(), + intToDouble) + .results(); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(list3, QList() << 1.0 << 2.0 << 3.0); + + QList list4 = QtConcurrent::mapped(QLinkedList(linkedList), intToDouble) + .results(); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(list4, QList() << 1.0 << 2.0 << 3.0); + } + + // bound function + { + QList list2 = QtConcurrent::mapped(linkedList, intToDouble).results(); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(list2, QList() << 1.0 << 2.0 << 3.0); + + QList list3 = QtConcurrent::mapped(linkedList.constBegin(), + linkedList.constEnd(), + intToDouble) + .results(); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(list3, QList() << 1.0 << 2.0 << 3.0); + + + QList list4 = QtConcurrent::mapped(QLinkedList(linkedList), + intToDouble) + .results(); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(list4, QList() << 1.0 << 2.0 << 3.0); + } + + // const member function + { + QList list2 = QtConcurrent::mapped(numberLinkedList, &Number::toString).results(); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(list2, QList() << "1" << "2" << "3"); + + QList list3 = QtConcurrent::mapped(numberLinkedList.constBegin(), + numberLinkedList.constEnd(), + &Number::toString) + .results(); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(list3, QList() << "1" << "2" << "3"); + + QList list4 = QtConcurrent::mapped(QLinkedList(numberLinkedList), + &Number::toString) + .results(); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(list4, QList() << "1" << "2" << "3"); + } +QT_WARNING_POP +#endif +} + +void tst_QtConcurrentMap::blocking_mapped() +{ + QList list; + list << 1 << 2 << 3; + QList numberList; + numberList << 1 << 2 << 3; + + // functor + { + QList list2 = QtConcurrent::blockingMapped(list, MultiplyBy2()); + QCOMPARE(list, QList() << 1 << 2 << 3); + QCOMPARE(list2, QList() << 2 << 4 << 6); + + QList list3 = QtConcurrent::blockingMapped >(list.constBegin(), + list.constEnd(), + MultiplyBy2()); + QCOMPARE(list, QList() << 1 << 2 << 3); + QCOMPARE(list3, QList() << 2 << 4 << 6); + + QList list4 = QtConcurrent::blockingMapped(QList(list), MultiplyBy2()); + QCOMPARE(list, QList() << 1 << 2 << 3); + QCOMPARE(list4, QList() << 2 << 4 << 6); + } + + // function { QList list2 = QtConcurrent::blockingMapped(list, multiplyBy2); QCOMPARE(list, QList() << 1 << 2 << 3); @@ -873,20 +857,22 @@ void tst_QtConcurrentMap::blocking_mapped() QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 2 << 4 << 6); } + + // bound function { - QLinkedList linkedList2 = QtConcurrent::blockingMapped(linkedList, multiplyBy2); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList2, QLinkedList() << 2 << 4 << 6); + QList list2 = QtConcurrent::blockingMapped(list, multiplyBy2); + QCOMPARE(list, QList() << 1 << 2 << 3); + QCOMPARE(list2, QList() << 2 << 4 << 6); - QLinkedList linkedList3 = QtConcurrent::blockingMapped >(linkedList.constBegin(), - linkedList.constEnd(), + QList list3 = QtConcurrent::blockingMapped >(list.constBegin(), + list.constEnd(), multiplyBy2); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList3, QLinkedList() << 2 << 4 << 6); + QCOMPARE(list, QList() << 1 << 2 << 3); + QCOMPARE(list3, QList() << 2 << 4 << 6); - QLinkedList linkedList4 = QtConcurrent::blockingMapped(QLinkedList(linkedList), multiplyBy2); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList4, QLinkedList() << 2 << 4 << 6); + QList list4 = QtConcurrent::blockingMapped(QList(list), multiplyBy2); + QCOMPARE(list, QList() << 1 << 2 << 3); + QCOMPARE(list4, QList() << 2 << 4 << 6); } // const member function @@ -906,22 +892,6 @@ void tst_QtConcurrentMap::blocking_mapped() QCOMPARE(numberList, QList() << 1 << 2 << 3); QCOMPARE(numberList4, QList() << 2 << 4 << 6); } - { - QLinkedList numberLinkedList2 = QtConcurrent::blockingMapped(numberLinkedList, &Number::multipliedBy2); - QCOMPARE(numberLinkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(numberLinkedList2, QLinkedList() << 2 << 4 << 6); - - QLinkedList numberLinkedList3 = QtConcurrent::blockingMapped >(numberLinkedList.constBegin(), - numberLinkedList.constEnd(), - &Number::multipliedBy2); - QCOMPARE(numberLinkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(numberLinkedList3, QLinkedList() << 2 << 4 << 6); - - QLinkedList numberLinkedList4 = QtConcurrent::blockingMapped(QLinkedList(numberLinkedList), - &Number::multipliedBy2); - QCOMPARE(numberLinkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(numberLinkedList4, QLinkedList() << 2 << 4 << 6); - } // change the value_type, same container @@ -942,22 +912,6 @@ void tst_QtConcurrentMap::blocking_mapped() QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 1.0 << 2.0 << 3.0); } - { - QLinkedList linkedList2 = QtConcurrent::blockingMapped >(linkedList, IntToDouble()); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList2, QLinkedList() << 1.0 << 2.0 << 3.0); - - QLinkedList linkedList3 = QtConcurrent::blockingMapped >(linkedList.constBegin(), - linkedList.constEnd(), - IntToDouble()); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList3, QLinkedList() << 1.0 << 2.0 << 3.0); - - QLinkedList linkedList4 = QtConcurrent::blockingMapped >(QLinkedList(linkedList), - IntToDouble()); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList4, QLinkedList() << 1.0 << 2.0 << 3.0); - } // function { @@ -975,21 +929,6 @@ void tst_QtConcurrentMap::blocking_mapped() QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 1.0 << 2.0 << 3.0); } - { - QLinkedList linkedList2 = QtConcurrent::blockingMapped >(linkedList, intToDouble); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList2, QLinkedList() << 1.0 << 2.0 << 3.0); - - QLinkedList linkedList3 = QtConcurrent::blockingMapped >(linkedList.constBegin(), - linkedList.constEnd(), - intToDouble); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList3, QLinkedList() << 1.0 << 2.0 << 3.0); - - QLinkedList linkedList4 = QtConcurrent::blockingMapped >(QLinkedList(linkedList), intToDouble); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList4, QLinkedList() << 1.0 << 2.0 << 3.0); - } // bound function { @@ -1009,23 +948,6 @@ void tst_QtConcurrentMap::blocking_mapped() QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 1.0 << 2.0 << 3.0); } - { - QLinkedList linkedList2 = QtConcurrent::blockingMapped >(linkedList, intToDouble); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList2, QLinkedList() << 1.0 << 2.0 << 3.0); - - QLinkedList linkedList3 = QtConcurrent::blockingMapped >(linkedList.constBegin(), - linkedList.constEnd(), - intToDouble); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList3, QLinkedList() << 1.0 << 2.0 << 3.0); - - - QLinkedList linkedList4 = QtConcurrent::blockingMapped >(QLinkedList(linkedList), - intToDouble); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList4, QLinkedList() << 1.0 << 2.0 << 3.0); - } // const member function { @@ -1045,23 +967,6 @@ void tst_QtConcurrentMap::blocking_mapped() QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << "1" << "2" << "3"); } - { - QLinkedList linkedList2 = - QtConcurrent::blockingMapped >(numberLinkedList, &Number::toString); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList2, QLinkedList() << "1" << "2" << "3"); - - QLinkedList linkedList3 = QtConcurrent::blockingMapped >(numberLinkedList.constBegin(), - numberLinkedList.constEnd() - , &Number::toString); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList3, QLinkedList() << "1" << "2" << "3"); - - QLinkedList linkedList4 = - QtConcurrent::blockingMapped >(QLinkedList(numberLinkedList), &Number::toString); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList4, QLinkedList() << "1" << "2" << "3"); - } // change the value_type { @@ -1218,86 +1123,213 @@ void tst_QtConcurrentMap::blocking_mapped() QCOMPARE(list5, QVector() << 1 << 2 << 3); #endif } -} - -int intSquare(int x) -{ - return x * x; -} - -class IntSquare -{ -public: - typedef int result_type; - int operator()(int x) - { - return x * x; - } -}; +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED -void tst_QtConcurrentMap::mappedReduced() -{ - QList list; - list << 1 << 2 << 3; QLinkedList linkedList; linkedList << 1 << 2 << 3; - QList numberList; - numberList << 1 << 2 << 3; QLinkedList numberLinkedList; numberLinkedList << 1 << 2 << 3; - // test Q_DECLARE_OPERATORS_FOR_FLAGS - QtConcurrent::ReduceOptions opt = (QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce); - QVERIFY(opt); - - // functor-functor + // functor { - int sum = QtConcurrent::mappedReduced(list, IntSquare(), IntSumReduce()); - QCOMPARE(sum, 14); - int sum2 = QtConcurrent::mappedReduced(list.constBegin(), - list.constEnd(), - IntSquare(), - IntSumReduce()); - QCOMPARE(sum2, 14); - - int sum3 = QtConcurrent::mappedReduced(QList(list), IntSquare(), IntSumReduce()); - QCOMPARE(sum3, 14); + QLinkedList linkedList2 = QtConcurrent::blockingMapped(linkedList, MultiplyBy2()); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList2, QLinkedList() << 2 << 4 << 6); - int sum4 = QtConcurrent::mappedReduced(list, intSquare, intSumReduce); - QCOMPARE(sum4, 14); - int sum5 = QtConcurrent::mappedReduced(list.constBegin(), - list.constEnd(), - intSquare, - intSumReduce); - QCOMPARE(sum5, 14); + QLinkedList linkedList3 = QtConcurrent::blockingMapped >(linkedList.constBegin(), + linkedList.constEnd(), + MultiplyBy2()); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList3, QLinkedList() << 2 << 4 << 6); - int sum6 = QtConcurrent::mappedReduced(QList(list), - intSquare, - intSumReduce); - QCOMPARE(sum6, 14); + QLinkedList linkedList4 = QtConcurrent::blockingMapped(QLinkedList(linkedList), MultiplyBy2()); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList4, QLinkedList() << 2 << 4 << 6); } + + // function { - int sum = QtConcurrent::mappedReduced(linkedList, IntSquare(), IntSumReduce()); - QCOMPARE(sum, 14); - int sum2 = QtConcurrent::mappedReduced(linkedList.constBegin(), - linkedList.constEnd(), - IntSquare(), + QLinkedList linkedList2 = QtConcurrent::blockingMapped(linkedList, multiplyBy2); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList2, QLinkedList() << 2 << 4 << 6); + + QLinkedList linkedList3 = QtConcurrent::blockingMapped >(linkedList.constBegin(), + linkedList.constEnd(), + multiplyBy2); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList3, QLinkedList() << 2 << 4 << 6); + + QLinkedList linkedList4 = QtConcurrent::blockingMapped(QLinkedList(linkedList), multiplyBy2); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList4, QLinkedList() << 2 << 4 << 6); + } + + // bound function + { + QLinkedList linkedList2 = QtConcurrent::blockingMapped(linkedList, multiplyBy2); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList2, QLinkedList() << 2 << 4 << 6); + + QLinkedList linkedList3 = QtConcurrent::blockingMapped >(linkedList.constBegin(), + linkedList.constEnd(), + multiplyBy2); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList3, QLinkedList() << 2 << 4 << 6); + + QLinkedList linkedList4 = QtConcurrent::blockingMapped(QLinkedList(linkedList), multiplyBy2); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList4, QLinkedList() << 2 << 4 << 6); + } + + // const member function + { + QLinkedList numberLinkedList2 = QtConcurrent::blockingMapped(numberLinkedList, &Number::multipliedBy2); + QCOMPARE(numberLinkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(numberLinkedList2, QLinkedList() << 2 << 4 << 6); + + QLinkedList numberLinkedList3 = QtConcurrent::blockingMapped >(numberLinkedList.constBegin(), + numberLinkedList.constEnd(), + &Number::multipliedBy2); + QCOMPARE(numberLinkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(numberLinkedList3, QLinkedList() << 2 << 4 << 6); + + QLinkedList numberLinkedList4 = QtConcurrent::blockingMapped(QLinkedList(numberLinkedList), + &Number::multipliedBy2); + QCOMPARE(numberLinkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(numberLinkedList4, QLinkedList() << 2 << 4 << 6); + } + + // change the value_type, same container + + // functor + { + QLinkedList linkedList2 = QtConcurrent::blockingMapped >(linkedList, IntToDouble()); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList2, QLinkedList() << 1.0 << 2.0 << 3.0); + + QLinkedList linkedList3 = QtConcurrent::blockingMapped >(linkedList.constBegin(), + linkedList.constEnd(), + IntToDouble()); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList3, QLinkedList() << 1.0 << 2.0 << 3.0); + + QLinkedList linkedList4 = QtConcurrent::blockingMapped >(QLinkedList(linkedList), + IntToDouble()); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList4, QLinkedList() << 1.0 << 2.0 << 3.0); + } + + // function + { + QLinkedList linkedList2 = QtConcurrent::blockingMapped >(linkedList, intToDouble); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList2, QLinkedList() << 1.0 << 2.0 << 3.0); + + QLinkedList linkedList3 = QtConcurrent::blockingMapped >(linkedList.constBegin(), + linkedList.constEnd(), + intToDouble); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList3, QLinkedList() << 1.0 << 2.0 << 3.0); + + QLinkedList linkedList4 = QtConcurrent::blockingMapped >(QLinkedList(linkedList), intToDouble); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList4, QLinkedList() << 1.0 << 2.0 << 3.0); + } + + // bound function + { + QLinkedList linkedList2 = QtConcurrent::blockingMapped >(linkedList, intToDouble); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList2, QLinkedList() << 1.0 << 2.0 << 3.0); + + QLinkedList linkedList3 = QtConcurrent::blockingMapped >(linkedList.constBegin(), + linkedList.constEnd(), + intToDouble); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList3, QLinkedList() << 1.0 << 2.0 << 3.0); + + + QLinkedList linkedList4 = QtConcurrent::blockingMapped >(QLinkedList(linkedList), + intToDouble); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList4, QLinkedList() << 1.0 << 2.0 << 3.0); + } + + // const member function + { + QLinkedList linkedList2 = + QtConcurrent::blockingMapped >(numberLinkedList, &Number::toString); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList2, QLinkedList() << "1" << "2" << "3"); + + QLinkedList linkedList3 = QtConcurrent::blockingMapped >(numberLinkedList.constBegin(), + numberLinkedList.constEnd() + , &Number::toString); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList3, QLinkedList() << "1" << "2" << "3"); + + QLinkedList linkedList4 = + QtConcurrent::blockingMapped >(QLinkedList(numberLinkedList), &Number::toString); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList4, QLinkedList() << "1" << "2" << "3"); + } + +QT_WARNING_POP +#endif +} + +int intSquare(int x) +{ + return x * x; +} + +class IntSquare +{ +public: + typedef int result_type; + + int operator()(int x) + { + return x * x; + } +}; + +void tst_QtConcurrentMap::mappedReduced() +{ + QList list; + list << 1 << 2 << 3; + QList numberList; + numberList << 1 << 2 << 3; + + // test Q_DECLARE_OPERATORS_FOR_FLAGS + QtConcurrent::ReduceOptions opt = (QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce); + QVERIFY(opt); + + // functor-functor + { + int sum = QtConcurrent::mappedReduced(list, IntSquare(), IntSumReduce()); + QCOMPARE(sum, 14); + int sum2 = QtConcurrent::mappedReduced(list.constBegin(), + list.constEnd(), + IntSquare(), IntSumReduce()); QCOMPARE(sum2, 14); - int sum3 = QtConcurrent::mappedReduced(QLinkedList(linkedList), IntSquare(), IntSumReduce()); + int sum3 = QtConcurrent::mappedReduced(QList(list), IntSquare(), IntSumReduce()); QCOMPARE(sum3, 14); - int sum4 = QtConcurrent::mappedReduced(linkedList, intSquare, intSumReduce); + int sum4 = QtConcurrent::mappedReduced(list, intSquare, intSumReduce); QCOMPARE(sum4, 14); - int sum5 = QtConcurrent::mappedReduced(linkedList.constBegin(), - linkedList.constEnd(), + int sum5 = QtConcurrent::mappedReduced(list.constBegin(), + list.constEnd(), intSquare, intSumReduce); QCOMPARE(sum5, 14); - int sum6 = QtConcurrent::mappedReduced(QLinkedList(linkedList), + int sum6 = QtConcurrent::mappedReduced(QList(list), intSquare, intSumReduce); QCOMPARE(sum6, 14); @@ -1316,18 +1348,6 @@ void tst_QtConcurrentMap::mappedReduced() int sum3 = QtConcurrent::mappedReduced(QList(list), intSquare, IntSumReduce()); QCOMPARE(sum3, 14); } - { - int sum = QtConcurrent::mappedReduced(linkedList, intSquare, IntSumReduce()); - QCOMPARE(sum, 14); - int sum2 = QtConcurrent::mappedReduced(linkedList.constBegin(), - linkedList.constEnd(), - intSquare, - IntSumReduce()); - QCOMPARE(sum2, 14); - - int sum3 = QtConcurrent::mappedReduced(QLinkedList(linkedList), intSquare, IntSumReduce()); - QCOMPARE(sum3, 14); - } // functor-function { @@ -1342,18 +1362,6 @@ void tst_QtConcurrentMap::mappedReduced() int sum3 = QtConcurrent::mappedReduced(QList(list), IntSquare(), intSumReduce); QCOMPARE(sum3, 14); } - { - int sum = QtConcurrent::mappedReduced(linkedList, IntSquare(), intSumReduce); - QCOMPARE(sum, 14); - int sum2 = QtConcurrent::mappedReduced(linkedList.constBegin(), - linkedList.constEnd(), - IntSquare(), - intSumReduce); - QCOMPARE(sum2, 14); - - int sum3 = QtConcurrent::mappedReduced(QLinkedList(linkedList), IntSquare(), intSumReduce); - QCOMPARE(sum3, 14); - } // function-function { @@ -1368,18 +1376,6 @@ void tst_QtConcurrentMap::mappedReduced() int sum3 = QtConcurrent::mappedReduced(QList(list), intSquare, intSumReduce); QCOMPARE(sum3, 14); } - { - int sum = QtConcurrent::mappedReduced(linkedList, intSquare, intSumReduce); - QCOMPARE(sum, 14); - int sum2 = QtConcurrent::mappedReduced(linkedList.constBegin(), - linkedList.constEnd(), - intSquare, - intSumReduce); - QCOMPARE(sum2, 14); - - int sum3 = QtConcurrent::mappedReduced(QLinkedList(linkedList), intSquare, intSumReduce); - QCOMPARE(sum3, 14); - } // functor-member { @@ -1405,29 +1401,6 @@ void tst_QtConcurrentMap::mappedReduced() QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 1 << 4 << 9); } - { - QLinkedList linkedList2 = QtConcurrent::mappedReduced(linkedList, - IntSquare(), - &QLinkedList::push_back, - OrderedReduce); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList2, QLinkedList() << 1 << 4 << 9); - - QLinkedList linkedList3 = QtConcurrent::mappedReduced(linkedList.constBegin(), - linkedList.constEnd(), - IntSquare(), - &QLinkedList::push_back, - OrderedReduce); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList3, QLinkedList() << 1 << 4 << 9); - - QLinkedList linkedList4 = QtConcurrent::mappedReduced(QLinkedList(linkedList), - IntSquare(), - &QLinkedList::push_back, - OrderedReduce); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList4, QLinkedList() << 1 << 4 << 9); - } // member-functor { @@ -1444,20 +1417,6 @@ void tst_QtConcurrentMap::mappedReduced() IntSumReduce()); QCOMPARE(sum3, 6); } - { - int sum = QtConcurrent::mappedReduced(numberLinkedList, &Number::toInt, IntSumReduce()); - QCOMPARE(sum, 6); - int sum2 = QtConcurrent::mappedReduced(numberLinkedList.constBegin(), - numberLinkedList.constEnd(), - &Number::toInt, - IntSumReduce()); - QCOMPARE(sum2, 6); - - int sum3 = QtConcurrent::mappedReduced(QLinkedList(numberLinkedList), - &Number::toInt, - IntSumReduce()); - QCOMPARE(sum3, 6); - } // member-member { @@ -1479,12 +1438,176 @@ void tst_QtConcurrentMap::mappedReduced() &QList::push_back, OrderedReduce); QCOMPARE(list4, QList() << 1 << 2 << 3); } + + // function-member { - QLinkedList linkedList2 = QtConcurrent::mappedReduced(numberLinkedList, - &Number::toInt, - &QLinkedList::push_back, + QList list2 = QtConcurrent::mappedReduced(list, + intSquare, + &QList::push_back, OrderedReduce); - QCOMPARE(linkedList2, QLinkedList() << 1 << 2 << 3); + QCOMPARE(list, QList() << 1 << 2 << 3); + QCOMPARE(list2, QList() << 1 << 4 << 9); + + QList list3 = QtConcurrent::mappedReduced(list.constBegin(), + list.constEnd(), + intSquare, + &QList::push_back, + OrderedReduce); + QCOMPARE(list, QList() << 1 << 2 << 3); + QCOMPARE(list3, QList() << 1 << 4 << 9); + + QList list4 = QtConcurrent::mappedReduced(QList(list), + intSquare, + &QList::push_back, + OrderedReduce); + QCOMPARE(list, QList() << 1 << 2 << 3); + QCOMPARE(list4, QList() << 1 << 4 << 9); + } + + // member-function + { + int sum = QtConcurrent::mappedReduced(numberList, + &Number::toInt, + intSumReduce); + QCOMPARE(sum, 6); + int sum2 = QtConcurrent::mappedReduced(numberList.constBegin(), + numberList.constEnd(), + &Number::toInt, + intSumReduce); + QCOMPARE(sum2, 6); + + int sum3 = QtConcurrent::mappedReduced(QList(numberList), + &Number::toInt, + intSumReduce); + QCOMPARE(sum3, 6); + } + +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + + QLinkedList linkedList; + linkedList << 1 << 2 << 3; + QLinkedList numberLinkedList; + numberLinkedList << 1 << 2 << 3; + + // functor-functor + { + int sum = QtConcurrent::mappedReduced(linkedList, IntSquare(), IntSumReduce()); + QCOMPARE(sum, 14); + int sum2 = QtConcurrent::mappedReduced(linkedList.constBegin(), + linkedList.constEnd(), + IntSquare(), + IntSumReduce()); + QCOMPARE(sum2, 14); + + int sum3 = QtConcurrent::mappedReduced(QLinkedList(linkedList), IntSquare(), IntSumReduce()); + QCOMPARE(sum3, 14); + + int sum4 = QtConcurrent::mappedReduced(linkedList, intSquare, intSumReduce); + QCOMPARE(sum4, 14); + int sum5 = QtConcurrent::mappedReduced(linkedList.constBegin(), + linkedList.constEnd(), + intSquare, + intSumReduce); + QCOMPARE(sum5, 14); + + int sum6 = QtConcurrent::mappedReduced(QLinkedList(linkedList), + intSquare, + intSumReduce); + QCOMPARE(sum6, 14); + } + + // function-functor + { + int sum = QtConcurrent::mappedReduced(linkedList, intSquare, IntSumReduce()); + QCOMPARE(sum, 14); + int sum2 = QtConcurrent::mappedReduced(linkedList.constBegin(), + linkedList.constEnd(), + intSquare, + IntSumReduce()); + QCOMPARE(sum2, 14); + + int sum3 = QtConcurrent::mappedReduced(QLinkedList(linkedList), intSquare, IntSumReduce()); + QCOMPARE(sum3, 14); + } + + // functor-function + { + int sum = QtConcurrent::mappedReduced(linkedList, IntSquare(), intSumReduce); + QCOMPARE(sum, 14); + int sum2 = QtConcurrent::mappedReduced(linkedList.constBegin(), + linkedList.constEnd(), + IntSquare(), + intSumReduce); + QCOMPARE(sum2, 14); + + int sum3 = QtConcurrent::mappedReduced(QLinkedList(linkedList), IntSquare(), intSumReduce); + QCOMPARE(sum3, 14); + } + + // function-function + { + int sum = QtConcurrent::mappedReduced(linkedList, intSquare, intSumReduce); + QCOMPARE(sum, 14); + int sum2 = QtConcurrent::mappedReduced(linkedList.constBegin(), + linkedList.constEnd(), + intSquare, + intSumReduce); + QCOMPARE(sum2, 14); + + int sum3 = QtConcurrent::mappedReduced(QLinkedList(linkedList), intSquare, intSumReduce); + QCOMPARE(sum3, 14); + } + + // functor-member + { + QLinkedList linkedList2 = QtConcurrent::mappedReduced(linkedList, + IntSquare(), + &QLinkedList::push_back, + OrderedReduce); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList2, QLinkedList() << 1 << 4 << 9); + + QLinkedList linkedList3 = QtConcurrent::mappedReduced(linkedList.constBegin(), + linkedList.constEnd(), + IntSquare(), + &QLinkedList::push_back, + OrderedReduce); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList3, QLinkedList() << 1 << 4 << 9); + + QLinkedList linkedList4 = QtConcurrent::mappedReduced(QLinkedList(linkedList), + IntSquare(), + &QLinkedList::push_back, + OrderedReduce); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList4, QLinkedList() << 1 << 4 << 9); + } + + // member-functor + { + int sum = QtConcurrent::mappedReduced(numberLinkedList, &Number::toInt, IntSumReduce()); + QCOMPARE(sum, 6); + int sum2 = QtConcurrent::mappedReduced(numberLinkedList.constBegin(), + numberLinkedList.constEnd(), + &Number::toInt, + IntSumReduce()); + QCOMPARE(sum2, 6); + + int sum3 = QtConcurrent::mappedReduced(QLinkedList(numberLinkedList), + &Number::toInt, + IntSumReduce()); + QCOMPARE(sum3, 6); + } + + // member-member + { + QLinkedList linkedList2 = QtConcurrent::mappedReduced(numberLinkedList, + &Number::toInt, + &QLinkedList::push_back, + OrderedReduce); + QCOMPARE(linkedList2, QLinkedList() << 1 << 2 << 3); QLinkedList linkedList3 = QtConcurrent::mappedReduced(numberLinkedList.constBegin(), numberLinkedList.constEnd(), @@ -1495,20 +1618,242 @@ void tst_QtConcurrentMap::mappedReduced() QLinkedList linkedList4 = QtConcurrent::mappedReduced(QLinkedList(numberLinkedList), &Number::toInt, - &QLinkedList::push_back, OrderedReduce); - QCOMPARE(linkedList4, QLinkedList() << 1 << 2 << 3); + &QLinkedList::push_back, OrderedReduce); + QCOMPARE(linkedList4, QLinkedList() << 1 << 2 << 3); + } + + // function-member + { + QLinkedList linkedList2 = QtConcurrent::mappedReduced(linkedList, + intSquare, + &QLinkedList::append, + OrderedReduce); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList2, QLinkedList() << 1 << 4 << 9); + + QLinkedList linkedList3 = QtConcurrent::mappedReduced(linkedList.constBegin(), + linkedList.constEnd(), + intSquare, + &QLinkedList::append, + OrderedReduce); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList3, QLinkedList() << 1 << 4 << 9); + + QLinkedList linkedList4 = QtConcurrent::mappedReduced(QLinkedList(linkedList), + intSquare, + &QLinkedList::append, + OrderedReduce); + QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); + QCOMPARE(linkedList4, QLinkedList() << 1 << 4 << 9); + } + + // member-function + { + int sum = QtConcurrent::mappedReduced(numberLinkedList, + &Number::toInt, + intSumReduce); + QCOMPARE(sum, 6); + int sum2 = QtConcurrent::mappedReduced(numberLinkedList.constBegin(), + numberLinkedList.constEnd(), + &Number::toInt, + intSumReduce); + QCOMPARE(sum2, 6); + + int sum3 = QtConcurrent::mappedReduced(QLinkedList(numberLinkedList), + &Number::toInt, + intSumReduce); + QCOMPARE(sum3, 6); + } + + // linked lists + { + + QLinkedList list; + list << 1 << 2 << 3; + + QLinkedList numberList; + numberList << 1 << 2 << 3; + + int sum = QtConcurrent::mappedReduced(list, IntSquare(), IntSumReduce()); + QCOMPARE(sum, 14); + int sum2 = QtConcurrent::mappedReduced(list.constBegin(), + list.constEnd(), + IntSquare(), + IntSumReduce()); + QCOMPARE(sum2, 14); + + int sum3 = QtConcurrent::mappedReduced(QLinkedList(list), IntSquare(), IntSumReduce()); + QCOMPARE(sum3, 14); + + int sum4 = QtConcurrent::mappedReduced(list, intSquare, intSumReduce); + QCOMPARE(sum4, 14); + int sum5 = QtConcurrent::mappedReduced(list.constBegin(), + list.constEnd(), + intSquare, + intSumReduce); + QCOMPARE(sum5, 14); + + int sum6 = QtConcurrent::mappedReduced(QLinkedList(list), + intSquare, + intSumReduce); + QCOMPARE(sum6, 14); + } + +QT_WARNING_POP +#endif + + // ### the same as above, with an initial result value +} + +void tst_QtConcurrentMap::blocking_mappedReduced() +{ + QList list; + list << 1 << 2 << 3; + QList numberList; + numberList << 1 << 2 << 3; + + // functor-functor + { + int sum = QtConcurrent::blockingMappedReduced(list, IntSquare(), IntSumReduce()); + QCOMPARE(sum, 14); + int sum2 = QtConcurrent::blockingMappedReduced(list.constBegin(), + list.constEnd(), + IntSquare(), + IntSumReduce()); + QCOMPARE(sum2, 14); + + int sum3 = QtConcurrent::blockingMappedReduced(QList(list), IntSquare(), IntSumReduce()); + QCOMPARE(sum3, 14); + + int sum4 = QtConcurrent::blockingMappedReduced(list, intSquare, intSumReduce); + QCOMPARE(sum4, 14); + int sum5 = QtConcurrent::blockingMappedReduced(list.constBegin(), + list.constEnd(), + intSquare, + intSumReduce); + QCOMPARE(sum5, 14); + + int sum6 = QtConcurrent::blockingMappedReduced(QList(list), + intSquare, + intSumReduce); + QCOMPARE(sum6, 14); + } + + // function-functor + { + int sum = QtConcurrent::blockingMappedReduced(list, intSquare, IntSumReduce()); + QCOMPARE(sum, 14); + int sum2 = QtConcurrent::blockingMappedReduced(list.constBegin(), + list.constEnd(), + intSquare, + IntSumReduce()); + QCOMPARE(sum2, 14); + + int sum3 = QtConcurrent::blockingMappedReduced(QList(list), intSquare, IntSumReduce()); + QCOMPARE(sum3, 14); + } + + // functor-function + { + int sum = QtConcurrent::blockingMappedReduced(list, IntSquare(), intSumReduce); + QCOMPARE(sum, 14); + int sum2 = QtConcurrent::blockingMappedReduced(list.constBegin(), + list.constEnd(), + IntSquare(), + intSumReduce); + QCOMPARE(sum2, 14); + + int sum3 = QtConcurrent::blockingMappedReduced(QList(list), IntSquare(), intSumReduce); + QCOMPARE(sum3, 14); + } + + // function-function + { + int sum = QtConcurrent::blockingMappedReduced(list, intSquare, intSumReduce); + QCOMPARE(sum, 14); + int sum2 = QtConcurrent::blockingMappedReduced(list.constBegin(), + list.constEnd(), + intSquare, + intSumReduce); + QCOMPARE(sum2, 14); + + int sum3 = QtConcurrent::blockingMappedReduced(QList(list), intSquare, intSumReduce); + QCOMPARE(sum3, 14); + } + + // functor-member + { + QList list2 = QtConcurrent::blockingMappedReduced(list, + IntSquare(), + &QList::push_back, + OrderedReduce); + QCOMPARE(list, QList() << 1 << 2 << 3); + QCOMPARE(list2, QList() << 1 << 4 << 9); + + QList list3 = QtConcurrent::blockingMappedReduced(list.constBegin(), + list.constEnd(), + IntSquare(), + &QList::push_back, + OrderedReduce); + QCOMPARE(list, QList() << 1 << 2 << 3); + QCOMPARE(list3, QList() << 1 << 4 << 9); + + QList list4 = QtConcurrent::blockingMappedReduced(QList(list), + IntSquare(), + &QList::push_back, + OrderedReduce); + QCOMPARE(list, QList() << 1 << 2 << 3); + QCOMPARE(list4, QList() << 1 << 4 << 9); + } + + // member-functor + { + int sum = QtConcurrent::blockingMappedReduced(numberList, &Number::toInt, + IntSumReduce()); + QCOMPARE(sum, 6); + int sum2 = QtConcurrent::blockingMappedReduced(numberList.constBegin(), + numberList.constEnd(), + &Number::toInt, + IntSumReduce()); + QCOMPARE(sum2, 6); + + int sum3 = QtConcurrent::blockingMappedReduced(QList(numberList), + &Number::toInt, + IntSumReduce()); + QCOMPARE(sum3, 6); + } + + // member-member + { + QList list2 = QtConcurrent::blockingMappedReduced(numberList, + &Number::toInt, + &QList::push_back, + OrderedReduce); + QCOMPARE(list2, QList() << 1 << 2 << 3); + + QList list3 = QtConcurrent::blockingMappedReduced(numberList.constBegin(), + numberList.constEnd(), + &Number::toInt, + &QList::push_back, + OrderedReduce); + QCOMPARE(list3, QList() << 1 << 2 << 3); + + QList list4 = QtConcurrent::blockingMappedReduced(QList(numberList), + &Number::toInt, + &QList::push_back, OrderedReduce); + QCOMPARE(list4, QList() << 1 << 2 << 3); } // function-member { - QList list2 = QtConcurrent::mappedReduced(list, + QList list2 = QtConcurrent::blockingMappedReduced(list, intSquare, &QList::push_back, OrderedReduce); QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list2, QList() << 1 << 4 << 9); - QList list3 = QtConcurrent::mappedReduced(list.constBegin(), + QList list3 = QtConcurrent::blockingMappedReduced(list.constBegin(), list.constEnd(), intSquare, &QList::push_back, @@ -1516,145 +1861,42 @@ void tst_QtConcurrentMap::mappedReduced() QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list3, QList() << 1 << 4 << 9); - QList list4 = QtConcurrent::mappedReduced(QList(list), + QList list4 = QtConcurrent::blockingMappedReduced(QList(list), intSquare, &QList::push_back, OrderedReduce); QCOMPARE(list, QList() << 1 << 2 << 3); QCOMPARE(list4, QList() << 1 << 4 << 9); } - { - QLinkedList linkedList2 = QtConcurrent::mappedReduced(linkedList, - intSquare, - &QLinkedList::append, - OrderedReduce); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList2, QLinkedList() << 1 << 4 << 9); - - QLinkedList linkedList3 = QtConcurrent::mappedReduced(linkedList.constBegin(), - linkedList.constEnd(), - intSquare, - &QLinkedList::append, - OrderedReduce); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList3, QLinkedList() << 1 << 4 << 9); - - QLinkedList linkedList4 = QtConcurrent::mappedReduced(QLinkedList(linkedList), - intSquare, - &QLinkedList::append, - OrderedReduce); - QCOMPARE(linkedList, QLinkedList() << 1 << 2 << 3); - QCOMPARE(linkedList4, QLinkedList() << 1 << 4 << 9); - } // member-function { - int sum = QtConcurrent::mappedReduced(numberList, + int sum = QtConcurrent::blockingMappedReduced(numberList, &Number::toInt, intSumReduce); QCOMPARE(sum, 6); - int sum2 = QtConcurrent::mappedReduced(numberList.constBegin(), + int sum2 = QtConcurrent::blockingMappedReduced(numberList.constBegin(), numberList.constEnd(), &Number::toInt, intSumReduce); QCOMPARE(sum2, 6); - int sum3 = QtConcurrent::mappedReduced(QList(numberList), - &Number::toInt, - intSumReduce); - QCOMPARE(sum3, 6); - } - { - int sum = QtConcurrent::mappedReduced(numberLinkedList, - &Number::toInt, - intSumReduce); - QCOMPARE(sum, 6); - int sum2 = QtConcurrent::mappedReduced(numberLinkedList.constBegin(), - numberLinkedList.constEnd(), - &Number::toInt, - intSumReduce); - QCOMPARE(sum2, 6); - - int sum3 = QtConcurrent::mappedReduced(QLinkedList(numberLinkedList), + int sum3 = QtConcurrent::blockingMappedReduced(QList(numberList), &Number::toInt, intSumReduce); QCOMPARE(sum3, 6); } - // linked lists - { - - QLinkedList list; - list << 1 << 2 << 3; - - QLinkedList numberList; - numberList << 1 << 2 << 3; - - int sum = QtConcurrent::mappedReduced(list, IntSquare(), IntSumReduce()); - QCOMPARE(sum, 14); - int sum2 = QtConcurrent::mappedReduced(list.constBegin(), - list.constEnd(), - IntSquare(), - IntSumReduce()); - QCOMPARE(sum2, 14); - - int sum3 = QtConcurrent::mappedReduced(QLinkedList(list), IntSquare(), IntSumReduce()); - QCOMPARE(sum3, 14); - - int sum4 = QtConcurrent::mappedReduced(list, intSquare, intSumReduce); - QCOMPARE(sum4, 14); - int sum5 = QtConcurrent::mappedReduced(list.constBegin(), - list.constEnd(), - intSquare, - intSumReduce); - QCOMPARE(sum5, 14); - - int sum6 = QtConcurrent::mappedReduced(QLinkedList(list), - intSquare, - intSumReduce); - QCOMPARE(sum6, 14); - } - - // ### the same as above, with an initial result value -} +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED -void tst_QtConcurrentMap::blocking_mappedReduced() -{ - QList list; - list << 1 << 2 << 3; QLinkedList linkedList; linkedList << 1 << 2 << 3; - QList numberList; - numberList << 1 << 2 << 3; QLinkedList numberLinkedList; numberLinkedList << 1 << 2 << 3; // functor-functor - { - int sum = QtConcurrent::blockingMappedReduced(list, IntSquare(), IntSumReduce()); - QCOMPARE(sum, 14); - int sum2 = QtConcurrent::blockingMappedReduced(list.constBegin(), - list.constEnd(), - IntSquare(), - IntSumReduce()); - QCOMPARE(sum2, 14); - - int sum3 = QtConcurrent::blockingMappedReduced(QList(list), IntSquare(), IntSumReduce()); - QCOMPARE(sum3, 14); - - int sum4 = QtConcurrent::blockingMappedReduced(list, intSquare, intSumReduce); - QCOMPARE(sum4, 14); - int sum5 = QtConcurrent::blockingMappedReduced(list.constBegin(), - list.constEnd(), - intSquare, - intSumReduce); - QCOMPARE(sum5, 14); - - int sum6 = QtConcurrent::blockingMappedReduced(QList(list), - intSquare, - intSumReduce); - QCOMPARE(sum6, 14); - } { int sum = QtConcurrent::blockingMappedReduced(linkedList, IntSquare(), IntSumReduce()); QCOMPARE(sum, 14); @@ -1682,18 +1924,6 @@ void tst_QtConcurrentMap::blocking_mappedReduced() } // function-functor - { - int sum = QtConcurrent::blockingMappedReduced(list, intSquare, IntSumReduce()); - QCOMPARE(sum, 14); - int sum2 = QtConcurrent::blockingMappedReduced(list.constBegin(), - list.constEnd(), - intSquare, - IntSumReduce()); - QCOMPARE(sum2, 14); - - int sum3 = QtConcurrent::blockingMappedReduced(QList(list), intSquare, IntSumReduce()); - QCOMPARE(sum3, 14); - } { int sum = QtConcurrent::blockingMappedReduced(linkedList, intSquare, IntSumReduce()); QCOMPARE(sum, 14); @@ -1708,18 +1938,6 @@ void tst_QtConcurrentMap::blocking_mappedReduced() } // functor-function - { - int sum = QtConcurrent::blockingMappedReduced(list, IntSquare(), intSumReduce); - QCOMPARE(sum, 14); - int sum2 = QtConcurrent::blockingMappedReduced(list.constBegin(), - list.constEnd(), - IntSquare(), - intSumReduce); - QCOMPARE(sum2, 14); - - int sum3 = QtConcurrent::blockingMappedReduced(QList(list), IntSquare(), intSumReduce); - QCOMPARE(sum3, 14); - } { int sum = QtConcurrent::blockingMappedReduced(linkedList, IntSquare(), intSumReduce); QCOMPARE(sum, 14); @@ -1734,18 +1952,6 @@ void tst_QtConcurrentMap::blocking_mappedReduced() } // function-function - { - int sum = QtConcurrent::blockingMappedReduced(list, intSquare, intSumReduce); - QCOMPARE(sum, 14); - int sum2 = QtConcurrent::blockingMappedReduced(list.constBegin(), - list.constEnd(), - intSquare, - intSumReduce); - QCOMPARE(sum2, 14); - - int sum3 = QtConcurrent::blockingMappedReduced(QList(list), intSquare, intSumReduce); - QCOMPARE(sum3, 14); - } { int sum = QtConcurrent::blockingMappedReduced(linkedList, intSquare, intSumReduce); QCOMPARE(sum, 14); @@ -1760,29 +1966,6 @@ void tst_QtConcurrentMap::blocking_mappedReduced() } // functor-member - { - QList list2 = QtConcurrent::blockingMappedReduced(list, - IntSquare(), - &QList::push_back, - OrderedReduce); - QCOMPARE(list, QList() << 1 << 2 << 3); - QCOMPARE(list2, QList() << 1 << 4 << 9); - - QList list3 = QtConcurrent::blockingMappedReduced(list.constBegin(), - list.constEnd(), - IntSquare(), - &QList::push_back, - OrderedReduce); - QCOMPARE(list, QList() << 1 << 2 << 3); - QCOMPARE(list3, QList() << 1 << 4 << 9); - - QList list4 = QtConcurrent::blockingMappedReduced(QList(list), - IntSquare(), - &QList::push_back, - OrderedReduce); - QCOMPARE(list, QList() << 1 << 2 << 3); - QCOMPARE(list4, QList() << 1 << 4 << 9); - } { QLinkedList linkedList2 = QtConcurrent::blockingMappedReduced(linkedList, IntSquare(), @@ -1808,21 +1991,6 @@ void tst_QtConcurrentMap::blocking_mappedReduced() } // member-functor - { - int sum = QtConcurrent::blockingMappedReduced(numberList, &Number::toInt, - IntSumReduce()); - QCOMPARE(sum, 6); - int sum2 = QtConcurrent::blockingMappedReduced(numberList.constBegin(), - numberList.constEnd(), - &Number::toInt, - IntSumReduce()); - QCOMPARE(sum2, 6); - - int sum3 = QtConcurrent::blockingMappedReduced(QList(numberList), - &Number::toInt, - IntSumReduce()); - QCOMPARE(sum3, 6); - } { int sum = QtConcurrent::blockingMappedReduced(numberLinkedList, &Number::toInt, IntSumReduce()); QCOMPARE(sum, 6); @@ -1839,25 +2007,6 @@ void tst_QtConcurrentMap::blocking_mappedReduced() } // member-member - { - QList list2 = QtConcurrent::blockingMappedReduced(numberList, - &Number::toInt, - &QList::push_back, - OrderedReduce); - QCOMPARE(list2, QList() << 1 << 2 << 3); - - QList list3 = QtConcurrent::blockingMappedReduced(numberList.constBegin(), - numberList.constEnd(), - &Number::toInt, - &QList::push_back, - OrderedReduce); - QCOMPARE(list3, QList() << 1 << 2 << 3); - - QList list4 = QtConcurrent::blockingMappedReduced(QList(numberList), - &Number::toInt, - &QList::push_back, OrderedReduce); - QCOMPARE(list4, QList() << 1 << 2 << 3); - } { QLinkedList linkedList2 = QtConcurrent::blockingMappedReduced(numberLinkedList, &Number::toInt, @@ -1879,29 +2028,6 @@ void tst_QtConcurrentMap::blocking_mappedReduced() } // function-member - { - QList list2 = QtConcurrent::blockingMappedReduced(list, - intSquare, - &QList::push_back, - OrderedReduce); - QCOMPARE(list, QList() << 1 << 2 << 3); - QCOMPARE(list2, QList() << 1 << 4 << 9); - - QList list3 = QtConcurrent::blockingMappedReduced(list.constBegin(), - list.constEnd(), - intSquare, - &QList::push_back, - OrderedReduce); - QCOMPARE(list, QList() << 1 << 2 << 3); - QCOMPARE(list3, QList() << 1 << 4 << 9); - - QList list4 = QtConcurrent::blockingMappedReduced(QList(list), - intSquare, - &QList::push_back, - OrderedReduce); - QCOMPARE(list, QList() << 1 << 2 << 3); - QCOMPARE(list4, QList() << 1 << 4 << 9); - } { QLinkedList linkedList2 = QtConcurrent::blockingMappedReduced(linkedList, intSquare, @@ -1927,22 +2053,6 @@ void tst_QtConcurrentMap::blocking_mappedReduced() } // member-function - { - int sum = QtConcurrent::blockingMappedReduced(numberList, - &Number::toInt, - intSumReduce); - QCOMPARE(sum, 6); - int sum2 = QtConcurrent::blockingMappedReduced(numberList.constBegin(), - numberList.constEnd(), - &Number::toInt, - intSumReduce); - QCOMPARE(sum2, 6); - - int sum3 = QtConcurrent::blockingMappedReduced(QList(numberList), - &Number::toInt, - intSumReduce); - QCOMPARE(sum3, 6); - } { int sum = QtConcurrent::blockingMappedReduced(numberLinkedList, &Number::toInt, @@ -1994,6 +2104,9 @@ void tst_QtConcurrentMap::blocking_mappedReduced() QCOMPARE(sum6, 14); } +QT_WARNING_POP +#endif + // ### the same as above, with an initial result value } diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 5af1353a0f..70bda1a0ef 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -3885,12 +3885,17 @@ void tst_QVariant::moreCustomTypes() PLAY_WITH_VARIANT(data, false, QString(), 0, false); } +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED { QList > data; PLAY_WITH_VARIANT(data, false, QString(), 0, false); data << (QLinkedList() << 42); PLAY_WITH_VARIANT(data, false, QString(), 0, false); } +QT_WARNING_POP +#endif } void tst_QVariant::movabilityTest() diff --git a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp index aed84cb14e..ff2e98e730 100644 --- a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp @@ -3064,39 +3064,45 @@ void tst_QDataStream::status_QHash_QMap() } \ } \ { \ - LinkedList expectedLinkedList; \ + Vector expectedVector; \ for (int i = 0; i < expectedList.count(); ++i) \ - expectedLinkedList << expectedList.at(i); \ + expectedVector << expectedList.at(i); \ QByteArray ba = byteArray; \ QDataStream stream(&ba, QIODevice::ReadOnly); \ if (inTransaction) \ stream.startTransaction(); \ stream.setStatus(initialStatus); \ - stream >> linkedList; \ + stream >> vector; \ QCOMPARE((int)stream.status(), (int)expectedStatus); \ if (!inTransaction || stream.commitTransaction()) { \ - QCOMPARE(linkedList.size(), expectedLinkedList.size()); \ - QCOMPARE(linkedList, expectedLinkedList); \ + QCOMPARE(vector.size(), expectedVector.size()); \ + QCOMPARE(vector, expectedVector); \ } else { \ - QVERIFY(linkedList.isEmpty()); \ + QVERIFY(vector.isEmpty()); \ } \ } \ + if (inTransaction) \ + break; \ + } + +#define LINKED_LIST_TEST(byteArray, initialStatus, expectedStatus, expectedList) \ + for (bool inTransaction = false;; inTransaction = true) { \ { \ - Vector expectedVector; \ + LinkedList expectedLinkedList; \ for (int i = 0; i < expectedList.count(); ++i) \ - expectedVector << expectedList.at(i); \ + expectedLinkedList << expectedList.at(i); \ QByteArray ba = byteArray; \ QDataStream stream(&ba, QIODevice::ReadOnly); \ if (inTransaction) \ stream.startTransaction(); \ stream.setStatus(initialStatus); \ - stream >> vector; \ + stream >> linkedList; \ QCOMPARE((int)stream.status(), (int)expectedStatus); \ if (!inTransaction || stream.commitTransaction()) { \ - QCOMPARE(vector.size(), expectedVector.size()); \ - QCOMPARE(vector, expectedVector); \ + QCOMPARE(linkedList.size(), expectedLinkedList.size()); \ + QCOMPARE(linkedList, expectedLinkedList); \ } else { \ - QVERIFY(vector.isEmpty()); \ + QVERIFY(linkedList.isEmpty()); \ } \ } \ if (inTransaction) \ @@ -3105,10 +3111,8 @@ void tst_QDataStream::status_QHash_QMap() void tst_QDataStream::status_QLinkedList_QList_QVector() { - typedef QLinkedList LinkedList; typedef QList List; typedef QVector Vector; - LinkedList linkedList; List list; Vector vector; @@ -3155,6 +3159,61 @@ void tst_QDataStream::status_QLinkedList_QList_QVector() LIST_TEST(QByteArray("\x00\x00\x00\x01", 4), QDataStream::ReadCorruptData, QDataStream::ReadCorruptData, List()); LIST_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x01", 8), QDataStream::ReadPastEnd, QDataStream::ReadPastEnd, List()); } + +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + // The same as above with QLinkedList + + typedef QLinkedList LinkedList; + LinkedList linkedList; + + // ok + { + List listWithEmptyString; + listWithEmptyString.append(""); + + List someList; + someList.append("J"); + someList.append("MN"); + + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x00", 4), QDataStream::Ok, QDataStream::Ok, List()); + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x00", 8), QDataStream::Ok, QDataStream::Ok, listWithEmptyString); + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x02\x00\x00\x00\x02\x00J" + "\x00\x00\x00\x04\x00M\x00N", 18), QDataStream::Ok, QDataStream::Ok, someList); + } + + // past end + { + LINKED_LIST_TEST(QByteArray(), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + LINKED_LIST_TEST(QByteArray("\x00", 1), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + LINKED_LIST_TEST(QByteArray("\x00\x00", 2), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + LINKED_LIST_TEST(QByteArray("\x00\x00\x00", 3), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x01", 4), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + for (int i = 4; i < 12; ++i) { + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00", i), QDataStream::Ok, QDataStream::ReadPastEnd, List()); + } + } + + // corrupt data + { + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x01", 8), QDataStream::Ok, QDataStream::ReadCorruptData, List()); + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x02\x00\x00\x00\x01\x00J" + "\x00\x00\x00\x02\x00M\x00N", 18), QDataStream::Ok, QDataStream::ReadCorruptData, List()); + } + + // test the previously latched error status is not affected by reading + { + List listWithEmptyString; + listWithEmptyString.append(""); + + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x00", 8), QDataStream::ReadPastEnd, QDataStream::ReadPastEnd, listWithEmptyString); + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x01", 4), QDataStream::ReadCorruptData, QDataStream::ReadCorruptData, List()); + LINKED_LIST_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x01", 8), QDataStream::ReadPastEnd, QDataStream::ReadPastEnd, List()); + } + +QT_WARNING_POP +#endif } void tst_QDataStream::streamToAndFromQByteArray() diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp index e79a4dba29..ec519ad362 100644 --- a/tests/auto/corelib/tools/collections/tst_collections.cpp +++ b/tests/auto/corelib/tools/collections/tst_collections.cpp @@ -96,7 +96,9 @@ private slots: void typeinfo(); void qstring(); void list(); +#if QT_DEPRECATED_SINCE(5, 15) void linkedList(); +#endif void vector(); void byteArray(); void stack(); @@ -109,7 +111,9 @@ private slots: #endif void pair(); void sharableQList(); +#if QT_DEPRECATED_SINCE(5, 15) void sharableQLinkedList(); +#endif void sharableQVector(); void sharableQMap(); void sharableQHash(); @@ -121,8 +125,10 @@ private slots: void vector_stl(); void list_stl_data(); void list_stl(); +#if QT_DEPRECATED_SINCE(5, 15) void linkedlist_stl_data(); void linkedlist_stl(); +#endif void q_init(); void pointersize(); void containerInstantiation(); @@ -736,8 +742,11 @@ void tst_Collections::list() } } +#if QT_DEPRECATED_SINCE(5, 15) void tst_Collections::linkedList() { +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED { QLinkedList list; QVERIFY(list.isEmpty()); @@ -955,7 +964,9 @@ void tst_Collections::linkedList() QCOMPARE(a.endsWith(1), false); QCOMPARE(a.endsWith(2), true); } +QT_WARNING_POP }; +#endif void tst_Collections::vector() @@ -2330,11 +2341,16 @@ void populate(QList &container) container << 1 << 2 << 4 << 8; } +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED template <> void populate(QLinkedList &container) { container << 1 << 2 << 4 << 8; } +QT_WARNING_POP +#endif template <> void populate(QVector &container) @@ -2431,10 +2447,15 @@ void tst_Collections::sharableQList() TEST_SEQUENTIAL_CONTAINER(List); } +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED void tst_Collections::sharableQLinkedList() { TEST_SEQUENTIAL_CONTAINER(LinkedList); } +QT_WARNING_POP +#endif void tst_Collections::sharableQVector() { @@ -2755,7 +2776,12 @@ void tst_Collections::constAndNonConstStlIterators() { testListLikeStlIterators >(); testListLikeStlIterators(); +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED testLinkedListLikeStlIterators >(); +QT_WARNING_POP +#endif testListLikeStlIterators >(); testMapLikeStlIterators >(); testMapLikeStlIterators >(); @@ -2798,6 +2824,7 @@ void tst_Collections::vector_stl() QCOMPARE(QVector(stdVector.begin(), stdVector.end()), vector); } +#if QT_DEPRECATED_SINCE(5, 15) void tst_Collections::linkedlist_stl_data() { list_stl_data(); @@ -2805,6 +2832,8 @@ void tst_Collections::linkedlist_stl_data() void tst_Collections::linkedlist_stl() { +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED QFETCH(QStringList, elements); QLinkedList list; @@ -2821,7 +2850,9 @@ void tst_Collections::linkedlist_stl() QCOMPARE(*it, *it2); QCOMPARE(QLinkedList::fromStdList(stdList), list); +QT_WARNING_POP } +#endif void tst_Collections::list_stl_data() { @@ -3070,6 +3101,10 @@ void tst_Collections::containerInstantiation() typedef QSet Set; instantiateAssociative(); +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + //Instantiate QLinkedList member functions. typedef QLinkedList LinkedList; instantiateSequence (); @@ -3078,6 +3113,8 @@ void tst_Collections::containerInstantiation() LinkedList list; list.removeAll(value); } +QT_WARNING_POP +#endif //Instantiate QList member functions. typedef QList List; @@ -3185,7 +3222,12 @@ void tst_Collections::containerTypedefs() testContainerTypedefs(QVector()); testContainerTypedefs(QStack()); testContainerTypedefs(QList()); +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED testContainerTypedefs(QLinkedList()); +QT_WARNING_POP +#endif testContainerTypedefs(QQueue()); testPairAssociativeContainerTypedefs(QMap()); @@ -3207,7 +3249,12 @@ void tst_Collections::forwardDeclared() { typedef QMultiMap C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) } { typedef QPair C; C *x = 0; Q_UNUSED(x) } { typedef QList C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) } +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED { typedef QLinkedList C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) } +QT_WARNING_POP +#endif { typedef QVector C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) Q_UNUSED(i) Q_UNUSED(j) } { typedef QStack C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) Q_UNUSED(i) Q_UNUSED(j) } { typedef QQueue C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) } @@ -3441,7 +3488,12 @@ void tst_Collections::QTBUG13079_collectionInsideCollection() QTBUG13079_collectionInsideCollectionImpl(); QTBUG13079_collectionInsideCollectionImpl(); QTBUG13079_collectionInsideCollectionImpl(); +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED QTBUG13079_collectionInsideCollectionImpl(); +QT_WARNING_POP +#endif QTBUG13079_collectionInsideCollectionImpl(); { diff --git a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp index 88c0c5055c..2c7c8f6514 100644 --- a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp +++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp @@ -324,11 +324,12 @@ private Q_SLOTS: #endif } - void ranged_ctor_QLinkedList_int() { ranged_ctor_non_associative_impl>(); } - void ranged_ctor_QLinkedList_Movable() { ranged_ctor_non_associative_impl>(); } - void ranged_ctor_QLinkedList_Complex() { ranged_ctor_non_associative_impl>(); } - void ranged_ctor_QLinkedList_duplicates_strategy() { non_associative_container_duplicates_strategy(); } - +#if QT_DEPRECATED_SINCE(5, 15) + void ranged_ctor_QLinkedList_int(); + void ranged_ctor_QLinkedList_Movable(); + void ranged_ctor_QLinkedList_Complex(); + void ranged_ctor_QLinkedList_duplicates_strategy(); +#endif void ranged_ctor_std_set_int() { ranged_ctor_non_associative_impl>(); } void ranged_ctor_std_set_Movable() { ranged_ctor_non_associative_impl>(); } void ranged_ctor_std_set_Complex() { ranged_ctor_non_associative_impl>(); } @@ -482,7 +483,9 @@ private Q_SLOTS: void front_back_std_vector() { front_back_impl>(); } void front_back_QVector() { front_back_impl>(); } void front_back_QList() { front_back_impl>(); } - void front_back_QLinkedList() { front_back_impl>(); } +#if QT_DEPRECATED_SINCE(5, 15) + void front_back_QLinkedList(); +#endif void front_back_QVarLengthArray() { front_back_impl>(); } void front_back_QString() { front_back_impl(); } void front_back_QStringRef() { front_back_impl(); } @@ -590,8 +593,13 @@ template struct ContainerDuplicatedValuesStrategy> : ContainerAcceptsDuplicateValues {}; #endif +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED template struct ContainerDuplicatedValuesStrategy> : ContainerAcceptsDuplicateValues {}; +QT_WARNING_POP +#endif // assuming https://cplusplus.github.io/LWG/lwg-active.html#2844 resolution template @@ -819,5 +827,35 @@ void tst_ContainerApiSymmetry::front_back_impl() const QCOMPARE(clean(qAsConst(c2).back()), V(2)); } +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED +void tst_ContainerApiSymmetry::ranged_ctor_QLinkedList_int() +{ + ranged_ctor_non_associative_impl>(); +} + +void tst_ContainerApiSymmetry::ranged_ctor_QLinkedList_Movable() +{ + ranged_ctor_non_associative_impl>(); +} + +void tst_ContainerApiSymmetry::ranged_ctor_QLinkedList_Complex() +{ + ranged_ctor_non_associative_impl>(); +} + +void tst_ContainerApiSymmetry::ranged_ctor_QLinkedList_duplicates_strategy() +{ + non_associative_container_duplicates_strategy(); +} + +void tst_ContainerApiSymmetry::front_back_QLinkedList() +{ + front_back_impl>(); +} +QT_WARNING_POP +#endif + QTEST_APPLESS_MAIN(tst_ContainerApiSymmetry) #include "tst_containerapisymmetry.moc" diff --git a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp index df42b5dea9..b681676d09 100644 --- a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp +++ b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp @@ -29,6 +29,10 @@ #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) @@ -1129,5 +1133,16 @@ void tst_QLinkedList::setSharableInt() const #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" -- cgit v1.2.3