summaryrefslogtreecommitdiffstats
path: root/tests/auto/concurrent/qtconcurrentmap
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/concurrent/qtconcurrentmap')
-rw-r--r--tests/auto/concurrent/qtconcurrentmap/CMakeLists.txt11
-rw-r--r--tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp44
2 files changed, 42 insertions, 13 deletions
diff --git a/tests/auto/concurrent/qtconcurrentmap/CMakeLists.txt b/tests/auto/concurrent/qtconcurrentmap/CMakeLists.txt
index 20ccbdf374..62b434a25f 100644
--- a/tests/auto/concurrent/qtconcurrentmap/CMakeLists.txt
+++ b/tests/auto/concurrent/qtconcurrentmap/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qtconcurrentmap.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtconcurrentmap Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtconcurrentmap LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtconcurrentmap
SOURCES
tst_qtconcurrentmap.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Concurrent
)
diff --git a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp
index a6c73777a1..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()
@@ -1956,7 +1978,7 @@ void tst_QtConcurrentMap::incrementalResults()
QCOMPARE(future.isFinished(), true);
QCOMPARE(future.resultCount(), count);
- QCOMPARE(future.results().count(), count);
+ QCOMPARE(future.results().size(), count);
}
/*
@@ -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)