summaryrefslogtreecommitdiffstats
path: root/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp')
-rw-r--r--tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp42
1 files changed, 32 insertions, 10 deletions
diff --git a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp
index d872702567..3e3165013f 100644
--- a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp
+++ b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qtconcurrentmap.h>
#include <qexception.h>
#include <qdebug.h>
@@ -50,7 +50,7 @@ public slots:
using namespace QtConcurrent;
-void multiplyBy2Immutable(int x)
+void multiplyBy2Immutable([[maybe_unused]] int x)
{
x *= 2;
}
@@ -58,7 +58,7 @@ void multiplyBy2Immutable(int x)
class MultiplyBy2Immutable
{
public:
- void operator()(int x)
+ void operator()([[maybe_unused]] int x)
{
x *= 2;
}
@@ -163,9 +163,9 @@ void tst_QtConcurrentMap::map()
QCOMPARE(list, QList<int>() << 1 << 2 << 3);
// lambda
- QtConcurrent::map(list, [](int x){x *= 2;}).waitForFinished();
+ QtConcurrent::map(list, []([[maybe_unused]] int x){x *= 2;}).waitForFinished();
QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QtConcurrent::map(list.begin(), list.end(), [](int x){x *= 2;}).waitForFinished();
+ QtConcurrent::map(list.begin(), list.end(), []([[maybe_unused]] int x){x *= 2;}).waitForFinished();
QCOMPARE(list, QList<int>() << 1 << 2 << 3);
}
@@ -185,6 +185,17 @@ void tst_QtConcurrentMap::map()
QCOMPARE(list, NonTemplateSequence({ 2, 4, 6 }));
}
+ // custom pool with invalid number of threads
+ {
+ QList<int> list;
+ list << 1 << 2 << 3;
+ QThreadPool pool;
+ pool.setMaxThreadCount(0); // explicitly set incorrect value
+ // This should not crash
+ QtConcurrent::map(&pool, list, MultiplyBy2InPlace()).waitForFinished();
+ QCOMPARE(list, QList<int>() << 2 << 4 << 6);
+ }
+
#if 0
// not allowed: map() with immutable sequences makes no sense
{
@@ -215,7 +226,7 @@ void tst_QtConcurrentMap::map()
#if 0
// not allowed: map() on a const list, where functors try to modify the items in the list
{
- const QList<int> list = QList<int>() << 1 << 2 << 3;;
+ const QList<int> list = QList<int>() << 1 << 2 << 3;
QtConcurrent::map(list, MultiplyBy2InPlace());
QtConcurrent::map(list, multiplyBy2InPlace);
@@ -309,9 +320,9 @@ void tst_QtConcurrentMap::blockingMap()
QCOMPARE(list, QList<int>() << 1 << 2 << 3);
// lambda
- QtConcurrent::blockingMap(list, [](int x) { x *= 2; });
+ QtConcurrent::blockingMap(list, []([[maybe_unused]] int x) { x *= 2; });
QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QtConcurrent::blockingMap(list.begin(), list.end(), [](int x) { x *= 2; });
+ QtConcurrent::blockingMap(list.begin(), list.end(), []([[maybe_unused]] int x) { x *= 2; });
QCOMPARE(list, QList<int>() << 1 << 2 << 3);
}
@@ -352,7 +363,7 @@ void tst_QtConcurrentMap::blockingMap()
#if 0
// not allowed: map() on a const list, where functors try to modify the items in the list
{
- const QList<int> list = QList<int>() << 1 << 2 << 3;;
+ const QList<int> list = QList<int>() << 1 << 2 << 3;
QtConcurrent::blockingMap(list, MultiplyBy2InPlace());
QtConcurrent::blockingMap(list, multiplyBy2InPlace);
@@ -1075,6 +1086,17 @@ void tst_QtConcurrentMap::mappedReducedThreadPool()
intCube, intSumReduce);
QCOMPARE(result, sumOfCubes);
}
+
+ {
+ // pool with invalid number of threads
+ QThreadPool pool;
+ pool.setMaxThreadCount(0); // explicitly set incorrect value
+
+ // This should not crash
+ NonTemplateSequence list { 1, 2, 3 };
+ auto future = QtConcurrent::mappedReduced(&pool, list, multiplyBy2, intSumReduce);
+ QCOMPARE(future.result(), 12);
+ }
}
void tst_QtConcurrentMap::mappedReducedWithMoveOnlyCallable()
@@ -2047,7 +2069,7 @@ void tst_QtConcurrentMap::stlContainersLambda()
QtConcurrent::mapped(list, [](const int &i) { return mapper(i); }).waitForFinished();
- QtConcurrent::blockingMap(list, [](int x) { x *= 2; });
+ QtConcurrent::blockingMap(list, []([[maybe_unused]] int x) { x *= 2; });
}
InstanceCounter ic_fn(const InstanceCounter & ic)