diff options
Diffstat (limited to 'tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp')
-rw-r--r-- | tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp | 186 |
1 files changed, 158 insertions, 28 deletions
diff --git a/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp b/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp index 1a1ad6251a..e19a596d5d 100644 --- a/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp +++ b/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp @@ -1,34 +1,10 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qtconcurrentfilter.h> #include <QCoreApplication> #include <QList> #include <QTest> +#include <QSet> #include "../testhelper_functions.h" @@ -51,6 +27,7 @@ private slots: void filteredReducedInitialValueThreadPool(); void filteredReducedInitialValueWithMoveOnlyCallables(); void filteredReducedDifferentTypeInitialValue(); + void filteredReduceOptionConvertableToResultType(); void resultAt(); void incrementalResults(); void noDetach(); @@ -102,6 +79,19 @@ void tst_QtConcurrentFilter::filter() CHECK_FAIL("member"); testFilter(intList, intListEven, lambdaIsEven); CHECK_FAIL("lambda"); + + // non-template sequences + { + + NonTemplateSequence list({ 1, 2, 3, 4 }); + QtConcurrent::filter(list, keepEvenNumbers).waitForFinished(); + QCOMPARE(list, NonTemplateSequence({ 2, 4 })); + } + { + NonTemplateSequence list({ 1, 2, 3, 4 }); + QtConcurrent::blockingFilter(list, keepEvenNumbers); + QCOMPARE(list, NonTemplateSequence({ 2, 4 })); + } } static QSemaphore semaphore(1); @@ -179,6 +169,19 @@ void tst_QtConcurrentFilter::filterThreadPool() CHECK_FAIL("function"); testFilterThreadPool(&pool, intList, intListEven, lambdaIsOdd); CHECK_FAIL("lambda"); + + // non-template sequences + { + + NonTemplateSequence list({ 1, 2, 3, 4 }); + QtConcurrent::filter(list, keepEvenIntegers).waitForFinished(); + QCOMPARE(list, NonTemplateSequence({ 2, 4 })); + } + { + NonTemplateSequence list({ 1, 2, 3, 4 }); + QtConcurrent::blockingFilter(list, keepEvenIntegers); + QCOMPARE(list, NonTemplateSequence({ 2, 4 })); + } } void tst_QtConcurrentFilter::filterWithMoveOnlyCallable() @@ -254,6 +257,18 @@ void tst_QtConcurrentFilter::filtered() testFiltered(intList, intListEven, lambdaIsEven); CHECK_FAIL("lambda"); + // non-template sequences + { + NonTemplateSequence list({ 1, 2, 3, 4 }); + auto future = QtConcurrent::filtered(list, keepEvenIntegers); + QCOMPARE(future.results(), QList({ 2, 4 })); + } + { + NonTemplateSequence list({ 1, 2, 3, 4 }); + auto result = QtConcurrent::blockingFiltered(list, keepEvenIntegers); + QCOMPARE(result, NonTemplateSequence({ 2, 4 })); + } + { // rvalue sequences auto future = QtConcurrent::filtered(std::vector { 1, 2, 3, 4 }, keepEvenIntegers); @@ -329,6 +344,18 @@ void tst_QtConcurrentFilter::filteredThreadPool() testFilteredThreadPool(&pool, intList, intListEven, lambdaIsOdd); CHECK_FAIL("lambda"); + // non-template sequences + { + NonTemplateSequence list({ 1, 2, 3, 4 }); + auto future = QtConcurrent::filtered(&pool, list, keepEvenIntegers); + QCOMPARE(future.results(), QList({ 2, 4 })); + } + { + NonTemplateSequence list({ 1, 2, 3, 4 }); + auto result = QtConcurrent::blockingFiltered(&pool, list, keepEvenIntegers); + QCOMPARE(result, NonTemplateSequence({ 2, 4 })); + } + { // rvalue sequences auto future = QtConcurrent::filtered(&pool, std::vector { 1, 2, 3, 4 }, keepEvenIntegers); @@ -561,6 +588,18 @@ void tst_QtConcurrentFilter::filteredReduced() testFilteredReduced(intList, intSum, lambdaIsEven, lambdaIntSumReduce); CHECK_FAIL("lambda-lambda"); + // non-template sequences + { + NonTemplateSequence list({ 1, 2, 3, 4 }); + auto future = QtConcurrent::filteredReduced(list, keepEvenIntegers, intSumReduce); + QCOMPARE(future.result(), intSum); + } + { + NonTemplateSequence list({ 1, 2, 3, 4 }); + auto result = QtConcurrent::blockingFilteredReduced(list, keepEvenIntegers, intSumReduce); + QCOMPARE(result, intSum); + } + { // rvalue sequences auto future = QtConcurrent::filteredReduced(std::vector { 1, 2, 3, 4 }, keepEvenIntegers, @@ -689,6 +728,19 @@ void tst_QtConcurrentFilter::filteredReducedThreadPool() testFilteredReducedThreadPool(&pool, intList, intSum, lambdaIsOdd, lambdaSumReduce); CHECK_FAIL("lambda-lambda"); + // non-template sequences + { + NonTemplateSequence list({ 1, 2, 3, 4 }); + auto future = QtConcurrent::filteredReduced(&pool, list, keepOddIntegers, intSumReduce); + QCOMPARE(future.result(), intSum); + } + { + NonTemplateSequence list({ 1, 2, 3, 4 }); + auto result = + QtConcurrent::blockingFilteredReduced(&pool, list, keepOddIntegers, intSumReduce); + QCOMPARE(result, intSum); + } + { // rvalue sequences auto future = QtConcurrent::filteredReduced(&pool, std::vector { 1, 2, 3, 4 }, @@ -987,6 +1039,20 @@ void tst_QtConcurrentFilter::filteredReducedInitialValue() lambdaIntSumReduce, intInitial); CHECK_FAIL("lambda-lambda"); + // non-template sequences + { + NonTemplateSequence list({ 1, 2, 3, 4 }); + auto future = + QtConcurrent::filteredReduced(list, keepEvenIntegers, intSumReduce, intInitial); + QCOMPARE(future.result(), intSum); + } + { + NonTemplateSequence list({ 1, 2, 3, 4 }); + auto result = QtConcurrent::blockingFilteredReduced(list, keepEvenIntegers, intSumReduce, + intInitial); + QCOMPARE(result, intSum); + } + { // rvalue sequences auto future = QtConcurrent::filteredReduced(std::vector { 1, 2, 3, 4 }, keepEvenIntegers, @@ -1127,6 +1193,20 @@ void tst_QtConcurrentFilter::filteredReducedInitialValueThreadPool() lambdaSumReduce, intInitial); CHECK_FAIL("lambda-lambda"); + // non-template sequences + { + NonTemplateSequence list({ 1, 2, 3, 4 }); + auto future = + QtConcurrent::filteredReduced(list, keepOddIntegers, intSumReduce, intInitial); + QCOMPARE(future.result(), intSum); + } + { + NonTemplateSequence list({ 1, 2, 3, 4 }); + auto result = QtConcurrent::blockingFilteredReduced(list, keepOddIntegers, intSumReduce, + intInitial); + QCOMPARE(result, intSum); + } + { // rvalue sequences auto future = QtConcurrent::filteredReduced(&pool, std::vector { 1, 2, 3, 4 }, @@ -1259,6 +1339,56 @@ void tst_QtConcurrentFilter::filteredReducedDifferentTypeInitialValue() CHECK_FAIL("lambda-lambda"); } +void tst_QtConcurrentFilter::filteredReduceOptionConvertableToResultType() +{ + const QList<int> intList { 1, 2, 3 }; + const int sum = 4; + QThreadPool p; + ReduceOption ro = OrderedReduce; + + // With container + QCOMPARE(QtConcurrent::filteredReduced(intList, keepOddIntegers, intSumReduce, ro).result(), + sum); + QCOMPARE(QtConcurrent::blockingFilteredReduced(intList, keepOddIntegers, intSumReduce, ro), + sum); + + // With iterators + QCOMPARE(QtConcurrent::filteredReduced(intList.begin(), intList.end(), keepOddIntegers, + intSumReduce, ro).result(), sum); + QCOMPARE(QtConcurrent::blockingFilteredReduced(intList.begin(), intList.end(), keepOddIntegers, + intSumReduce, ro), sum); + + // With custom QThreadPool; + QCOMPARE(QtConcurrent::filteredReduced(&p, intList, keepOddIntegers, intSumReduce, ro).result(), + sum); + QCOMPARE(QtConcurrent::blockingFilteredReduced(&p, intList, keepOddIntegers, intSumReduce, ro), + sum); + QCOMPARE(QtConcurrent::filteredReduced(&p, intList.begin(), intList.end(), keepOddIntegers, + intSumReduce, ro).result(), sum); + QCOMPARE(QtConcurrent::blockingFilteredReduced(&p, intList.begin(), intList.end(), + keepOddIntegers, intSumReduce, ro), sum); + + // The same as above, but specify the result type explicitly (this invokes different overloads) + QCOMPARE(QtConcurrent::filteredReduced<int>(intList, keepOddIntegers, intSumReduce, + ro).result(), sum); + QCOMPARE(QtConcurrent::blockingFilteredReduced<int>(intList, keepOddIntegers, intSumReduce, ro), + sum); + + QCOMPARE(QtConcurrent::filteredReduced<int>(intList.begin(), intList.end(), keepOddIntegers, + intSumReduce, ro).result(), sum); + QCOMPARE(QtConcurrent::blockingFilteredReduced<int>(intList.begin(), intList.end(), + keepOddIntegers, intSumReduce, ro), sum); + + QCOMPARE(QtConcurrent::filteredReduced<int>(&p, intList, keepOddIntegers, intSumReduce, + ro).result(), sum); + QCOMPARE(QtConcurrent::blockingFilteredReduced<int>(&p, intList, keepOddIntegers, intSumReduce, + ro), sum); + QCOMPARE(QtConcurrent::filteredReduced<int>(&p, intList.begin(), intList.end(), keepOddIntegers, + intSumReduce, ro).result(),sum); + QCOMPARE(QtConcurrent::blockingFilteredReduced<int>(&p, intList.begin(), intList.end(), + keepOddIntegers, intSumReduce, ro), sum); +} + bool filterfn(int i) { return (i % 2); @@ -1304,7 +1434,7 @@ void tst_QtConcurrentFilter::incrementalResults() QCOMPARE(future.isFinished(), true); QCOMPARE(future.resultCount(), count / 2); - QCOMPARE(future.results().count(), count / 2); + QCOMPARE(future.results().size(), count / 2); } void tst_QtConcurrentFilter::noDetach() |