summaryrefslogtreecommitdiffstats
path: root/tests/auto/concurrent/qtconcurrentfilter
diff options
context:
space:
mode:
authorAndreas Buhr <andreas.buhr@qt.io>2020-09-29 10:30:59 +0200
committerAndreas Buhr <andreas.buhr@qt.io>2020-10-07 19:19:30 +0200
commitb5fc1e4e2643e73d3b44c483d159529f8deb8af1 (patch)
tree077e9dabe2c26857a87d247888a65bd0e032b4fe /tests/auto/concurrent/qtconcurrentfilter
parentb7f1915bd237ba82a74531286119fa53866831b6 (diff)
Add unit tests to assure QtConcurrent works on move-only sequences
Unit tests are added to make sure QtConcurrent works on move-only sequences. Change-Id: I1d066f75ceab9cef98832e96c5827103cbfd72a8 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'tests/auto/concurrent/qtconcurrentfilter')
-rw-r--r--tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp163
1 files changed, 124 insertions, 39 deletions
diff --git a/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp b/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp
index a2c5c20740..c7ab64c14c 100644
--- a/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp
+++ b/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp
@@ -222,12 +222,28 @@ void tst_QtConcurrentFilter::filtered()
testFiltered(intList, intListEven, lambdaIsEven);
CHECK_FAIL("lambda");
- // rvalue sequences
- auto future = QtConcurrent::filtered(std::vector { 1, 2, 3, 4 }, keepEvenIntegers);
- QCOMPARE(future.results(), QList<int>({ 2, 4 }));
+ {
+ // rvalue sequences
+ auto future = QtConcurrent::filtered(std::vector { 1, 2, 3, 4 }, keepEvenIntegers);
+ QCOMPARE(future.results(), QList<int>({ 2, 4 }));
+
+ auto result = QtConcurrent::blockingFiltered(std::vector { 1, 2, 3, 4 }, keepEvenIntegers);
+ QCOMPARE(result, std::vector<int>({ 2, 4 }));
+ }
- auto result = QtConcurrent::blockingFiltered(std::vector { 1, 2, 3, 4 }, keepEvenIntegers);
- QCOMPARE(result, std::vector<int>({ 2, 4 }));
+#if 0
+ // does not work yet
+ {
+ // move only types sequences
+ auto future = QtConcurrent::filtered(
+ MoveOnlyVector({ 1, 2, 3, 4 }), keepEvenIntegers);
+ QCOMPARE(future.results(), QList<int>({ 2, 4 }));
+
+ auto result = QtConcurrent::blockingFiltered(
+ MoveOnlyVector({ 1, 2, 3, 4 }), keepEvenIntegers);
+ QCOMPARE(result, std::vector<int>({ 2, 4 }));
+ }
+#endif
}
template <typename SourceObject,
@@ -282,13 +298,30 @@ void tst_QtConcurrentFilter::filteredThreadPool()
testFilteredThreadPool(&pool, intList, intListEven, lambdaIsOdd);
CHECK_FAIL("lambda");
- // rvalue sequences
- auto future = QtConcurrent::filtered(&pool, std::vector { 1, 2, 3, 4 }, keepEvenIntegers);
- QCOMPARE(future.results(), QList<int>({ 2, 4 }));
+ {
+ // rvalue sequences
+ auto future = QtConcurrent::filtered(&pool, std::vector { 1, 2, 3, 4 }, keepEvenIntegers);
+ QCOMPARE(future.results(), QList<int>({ 2, 4 }));
- auto result =
- QtConcurrent::blockingFiltered(&pool, std::vector { 1, 2, 3, 4 }, keepEvenIntegers);
- QCOMPARE(result, std::vector<int>({ 2, 4 }));
+ auto result =
+ QtConcurrent::blockingFiltered(&pool, std::vector { 1, 2, 3, 4 }, keepEvenIntegers);
+ QCOMPARE(result, std::vector<int>({ 2, 4 }));
+ }
+
+#if 0
+ // does not work yet
+ {
+ // move-only sequences
+ auto future = QtConcurrent::filtered(
+ &pool, MoveOnlyVector({ 1, 2, 3, 4 }), keepEvenIntegers);
+ QCOMPARE(future.results(), QList<int>({ 2, 4 }));
+
+ auto result =
+ QtConcurrent::blockingFiltered(
+ &pool, MoveOnlyVector({ 1, 2, 3, 4 }), keepEvenIntegers);
+ QCOMPARE(result, std::vector<int>({ 2, 4 }));
+ }
+#endif
}
template <typename SourceObject,
@@ -425,14 +458,27 @@ void tst_QtConcurrentFilter::filteredReduced()
testFilteredReduced(intList, intSum, lambdaIsEven, lambdaIntSumReduce);
CHECK_FAIL("lambda-lambda");
- // rvalue sequences
- auto future = QtConcurrent::filteredReduced(std::vector { 1, 2, 3, 4 }, keepEvenIntegers,
- intSumReduce);
- QCOMPARE(future, intSum);
+ {
+ // rvalue sequences
+ auto future = QtConcurrent::filteredReduced(std::vector { 1, 2, 3, 4 }, keepEvenIntegers,
+ intSumReduce);
+ QCOMPARE(future, intSum);
+
+ auto result = QtConcurrent::blockingFilteredReduced(std::vector { 1, 2, 3, 4 },
+ keepEvenIntegers, intSumReduce);
+ QCOMPARE(result, intSum);
+ }
- auto result = QtConcurrent::blockingFilteredReduced(std::vector { 1, 2, 3, 4 },
- keepEvenIntegers, intSumReduce);
- QCOMPARE(result, intSum);
+ {
+ // move only sequences
+ auto future = QtConcurrent::filteredReduced(MoveOnlyVector({ 1, 2, 3, 4 }),
+ keepEvenIntegers, intSumReduce);
+ QCOMPARE(future, intSum);
+
+ auto result = QtConcurrent::blockingFilteredReduced(MoveOnlyVector({ 1, 2, 3, 4 }),
+ keepEvenIntegers, intSumReduce);
+ QCOMPARE(result, intSum);
+ }
}
template <typename SourceObject,
@@ -510,14 +556,27 @@ void tst_QtConcurrentFilter::filteredReducedThreadPool()
testFilteredReducedThreadPool(&pool, intList, intSum, lambdaIsOdd, lambdaSumReduce);
CHECK_FAIL("lambda-lambda");
- // rvalue sequences
- auto future = QtConcurrent::filteredReduced(&pool, std::vector { 1, 2, 3, 4 }, keepOddIntegers,
- intSumReduce);
- QCOMPARE(future, intSum);
+ {
+ // rvalue sequences
+ auto future = QtConcurrent::filteredReduced(&pool, std::vector { 1, 2, 3, 4 },
+ keepOddIntegers, intSumReduce);
+ QCOMPARE(future, intSum);
+
+ auto result = QtConcurrent::blockingFilteredReduced(&pool, std::vector { 1, 2, 3, 4 },
+ keepOddIntegers, intSumReduce);
+ QCOMPARE(result, intSum);
+ }
- auto result = QtConcurrent::blockingFilteredReduced(&pool, std::vector { 1, 2, 3, 4 },
- keepOddIntegers, intSumReduce);
- QCOMPARE(result, intSum);
+ {
+ // move only sequences
+ auto future = QtConcurrent::filteredReduced(&pool, MoveOnlyVector({ 1, 2, 3, 4 }),
+ keepOddIntegers, intSumReduce);
+ QCOMPARE(future, intSum);
+
+ auto result = QtConcurrent::blockingFilteredReduced(&pool, MoveOnlyVector({ 1, 2, 3, 4 }),
+ keepOddIntegers, intSumReduce);
+ QCOMPARE(result, intSum);
+ }
}
void tst_QtConcurrentFilter::filteredReducedDifferentType()
@@ -714,14 +773,27 @@ void tst_QtConcurrentFilter::filteredReducedInitialValue()
lambdaIntSumReduce, intInitial);
CHECK_FAIL("lambda-lambda");
- // rvalue sequences
- auto future = QtConcurrent::filteredReduced(std::vector { 1, 2, 3, 4 }, keepEvenIntegers,
- intSumReduce, intInitial);
- QCOMPARE(future, intSum);
+ {
+ // rvalue sequences
+ auto future = QtConcurrent::filteredReduced(std::vector { 1, 2, 3, 4 }, keepEvenIntegers,
+ intSumReduce, intInitial);
+ QCOMPARE(future, intSum);
+
+ auto result = QtConcurrent::blockingFilteredReduced(
+ std::vector { 1, 2, 3, 4 }, keepEvenIntegers, intSumReduce, intInitial);
+ QCOMPARE(result, intSum);
+ }
- auto result = QtConcurrent::blockingFilteredReduced(std::vector { 1, 2, 3, 4 },
- keepEvenIntegers, intSumReduce, intInitial);
- QCOMPARE(result, intSum);
+ {
+ // move only sequences
+ auto future = QtConcurrent::filteredReduced(MoveOnlyVector({ 1, 2, 3, 4 }),
+ keepEvenIntegers, intSumReduce, intInitial);
+ QCOMPARE(future, intSum);
+
+ auto result = QtConcurrent::blockingFilteredReduced(
+ MoveOnlyVector({ 1, 2, 3, 4 }), keepEvenIntegers, intSumReduce, intInitial);
+ QCOMPARE(result, intSum);
+ }
}
template <typename SourceObject,
@@ -811,14 +883,27 @@ void tst_QtConcurrentFilter::filteredReducedInitialValueThreadPool()
lambdaSumReduce, intInitial);
CHECK_FAIL("lambda-lambda");
- // rvalue sequences
- auto future = QtConcurrent::filteredReduced(&pool, std::vector { 1, 2, 3, 4 }, keepOddIntegers,
- intSumReduce, intInitial);
- QCOMPARE(future, intSum);
+ {
+ // rvalue sequences
+ auto future = QtConcurrent::filteredReduced(&pool, std::vector { 1, 2, 3, 4 },
+ keepOddIntegers, intSumReduce, intInitial);
+ QCOMPARE(future, intSum);
+
+ auto result = QtConcurrent::blockingFilteredReduced(
+ &pool, std::vector { 1, 2, 3, 4 }, keepOddIntegers, intSumReduce, intInitial);
+ QCOMPARE(result, intSum);
+ }
- auto result = QtConcurrent::blockingFilteredReduced(&pool, std::vector { 1, 2, 3, 4 },
- keepOddIntegers, intSumReduce, intInitial);
- QCOMPARE(result, intSum);
+ {
+ // move only sequences
+ auto future = QtConcurrent::filteredReduced(&pool, MoveOnlyVector({ 1, 2, 3, 4 }),
+ keepOddIntegers, intSumReduce, intInitial);
+ QCOMPARE(future, intSum);
+
+ auto result = QtConcurrent::blockingFilteredReduced(
+ &pool, MoveOnlyVector({ 1, 2, 3, 4 }), keepOddIntegers, intSumReduce, intInitial);
+ QCOMPARE(result, intSum);
+ }
}
void tst_QtConcurrentFilter::filteredReducedDifferentTypeInitialValue()