diff options
Diffstat (limited to 'tests/auto/concurrent')
20 files changed, 131 insertions, 27 deletions
diff --git a/tests/auto/concurrent/qtconcurrentfilter/CMakeLists.txt b/tests/auto/concurrent/qtconcurrentfilter/CMakeLists.txt index a7da94d018..3c00393d39 100644 --- a/tests/auto/concurrent/qtconcurrentfilter/CMakeLists.txt +++ b/tests/auto/concurrent/qtconcurrentfilter/CMakeLists.txt @@ -5,6 +5,12 @@ ## tst_qtconcurrentfilter Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtconcurrentfilter LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtconcurrentfilter SOURCES tst_qtconcurrentfilter.cpp diff --git a/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp b/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp index 854059e7e7..e19a596d5d 100644 --- a/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp +++ b/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.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 <qtconcurrentfilter.h> #include <QCoreApplication> #include <QList> diff --git a/tests/auto/concurrent/qtconcurrentfiltermapgenerated/CMakeLists.txt b/tests/auto/concurrent/qtconcurrentfiltermapgenerated/CMakeLists.txt index 938dbb418c..12545702eb 100644 --- a/tests/auto/concurrent/qtconcurrentfiltermapgenerated/CMakeLists.txt +++ b/tests/auto/concurrent/qtconcurrentfiltermapgenerated/CMakeLists.txt @@ -5,6 +5,12 @@ ## tst_qtconcurrentfiltermapgenerated Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtconcurrentfiltermapgenerated LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtconcurrentfiltermapgenerated SOURCES tst_qtconcurrent_selected_tests.cpp diff --git a/tests/auto/concurrent/qtconcurrentfiltermapgenerated/generation_helpers.h b/tests/auto/concurrent/qtconcurrentfiltermapgenerated/generation_helpers.h index 4ce901e34b..aaa0d85002 100644 --- a/tests/auto/concurrent/qtconcurrentfiltermapgenerated/generation_helpers.h +++ b/tests/auto/concurrent/qtconcurrentfiltermapgenerated/generation_helpers.h @@ -1,5 +1,5 @@ // Copyright (C) 2020 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 #ifndef QTBASE_GENERATION_HELPERS_H #define QTBASE_GENERATION_HELPERS_H @@ -131,10 +131,7 @@ public: bool operator()(const T &el) { - if (!movedFrom) - return el.isOdd(); - else - return -1; + return movedFrom || el.isOdd(); } }; diff --git a/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrent_selected_tests.cpp b/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrent_selected_tests.cpp index f0d69bf25d..edb7cce4c9 100644 --- a/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrent_selected_tests.cpp +++ b/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrent_selected_tests.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2020 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 "tst_qtconcurrentfiltermapgenerated.h" diff --git a/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrentfiltermapgenerated.cpp b/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrentfiltermapgenerated.cpp index 6dc51e1797..089ca3f867 100644 --- a/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrentfiltermapgenerated.cpp +++ b/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrentfiltermapgenerated.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2020 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 <qtconcurrentfilter.h> #include <qtconcurrentmap.h> #include <QCoreApplication> diff --git a/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrentfiltermapgenerated.h b/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrentfiltermapgenerated.h index e1c1a8070a..31b62ac4fd 100644 --- a/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrentfiltermapgenerated.h +++ b/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrentfiltermapgenerated.h @@ -1,5 +1,5 @@ // Copyright (C) 2020 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 <qtconcurrentfilter.h> #include <qtconcurrentmap.h> #include <QTest> diff --git a/tests/auto/concurrent/qtconcurrentiteratekernel/CMakeLists.txt b/tests/auto/concurrent/qtconcurrentiteratekernel/CMakeLists.txt index 02f1db9ce8..2eea340795 100644 --- a/tests/auto/concurrent/qtconcurrentiteratekernel/CMakeLists.txt +++ b/tests/auto/concurrent/qtconcurrentiteratekernel/CMakeLists.txt @@ -5,6 +5,12 @@ ## tst_qtconcurrentiteratekernel Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtconcurrentiteratekernel LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtconcurrentiteratekernel SOURCES tst_qtconcurrentiteratekernel.cpp diff --git a/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp b/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp index 52406e4a62..27113ad8b7 100644 --- a/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp +++ b/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.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 <QThread> #include <QSet> diff --git a/tests/auto/concurrent/qtconcurrentmap/CMakeLists.txt b/tests/auto/concurrent/qtconcurrentmap/CMakeLists.txt index 20a3a1b9a7..62b434a25f 100644 --- a/tests/auto/concurrent/qtconcurrentmap/CMakeLists.txt +++ b/tests/auto/concurrent/qtconcurrentmap/CMakeLists.txt @@ -5,6 +5,12 @@ ## 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 diff --git a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp index 94248404da..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> @@ -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); @@ -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() diff --git a/tests/auto/concurrent/qtconcurrentmedian/CMakeLists.txt b/tests/auto/concurrent/qtconcurrentmedian/CMakeLists.txt index 2a1523e28e..63f0135467 100644 --- a/tests/auto/concurrent/qtconcurrentmedian/CMakeLists.txt +++ b/tests/auto/concurrent/qtconcurrentmedian/CMakeLists.txt @@ -5,6 +5,12 @@ ## tst_qtconcurrentmedian Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtconcurrentmedian LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtconcurrentmedian SOURCES tst_qtconcurrentmedian.cpp diff --git a/tests/auto/concurrent/qtconcurrentmedian/tst_qtconcurrentmedian.cpp b/tests/auto/concurrent/qtconcurrentmedian/tst_qtconcurrentmedian.cpp index d02856b93f..7eea013c8b 100644 --- a/tests/auto/concurrent/qtconcurrentmedian/tst_qtconcurrentmedian.cpp +++ b/tests/auto/concurrent/qtconcurrentmedian/tst_qtconcurrentmedian.cpp @@ -1,5 +1,6 @@ // 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 <qtconcurrentmedian.h> #include <QTest> @@ -48,11 +49,11 @@ void tst_QtConcurrentMedian::median_data() void tst_QtConcurrentMedian::median() { - QFETCH(QList<double> , values); + QFETCH(const QList<double> , values); QFETCH(double, expectedMedian); QtConcurrent::Median m; - foreach (double value, values) + for (double value : values) m.addValue(value); QCOMPARE(m.median(), expectedMedian); } diff --git a/tests/auto/concurrent/qtconcurrentrun/CMakeLists.txt b/tests/auto/concurrent/qtconcurrentrun/CMakeLists.txt index d199df7e11..a8b6792570 100644 --- a/tests/auto/concurrent/qtconcurrentrun/CMakeLists.txt +++ b/tests/auto/concurrent/qtconcurrentrun/CMakeLists.txt @@ -5,6 +5,12 @@ ## tst_qtconcurrentrun Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtconcurrentrun LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtconcurrentrun SOURCES tst_qtconcurrentrun.cpp diff --git a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp index fa03854400..0bc2961903 100644 --- a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp +++ b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.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 <qtconcurrentrun.h> #include <QFuture> #include <QMutex> @@ -666,10 +666,10 @@ void tst_QtConcurrentRun::implicitConvertibleTypes() { QThreadPool pool; - double d; + double d = 0.0; run(doubleFunction, d).waitForFinished(); run(&pool, doubleFunction, d).waitForFinished(); - int i; + int i = 0; run(doubleFunction, d).waitForFinished(); run(&pool, doubleFunction, d).waitForFinished(); run(doubleFunction, i).waitForFinished(); @@ -1089,12 +1089,25 @@ void report3(QPromise<int> &promise) promise.addResult(1); } +static void staticReport3(QPromise<int> &promise) +{ + promise.addResult(0); + promise.addResult(2); + promise.addResult(1); +} + void reportN(QPromise<double> &promise, int n) { for (int i = 0; i < n; ++i) promise.addResult(0); } +static void staticReportN(QPromise<double> &promise, int n) +{ + for (int i = 0; i < n; ++i) + promise.addResult(0); +} + void reportString1(QPromise<QString> &promise, const QString &s) { promise.addResult(s); @@ -1168,11 +1181,21 @@ void tst_QtConcurrentRun::withPromise() QCOMPARE(run(report3).results(), QList<int>({0, 2, 1})); - QCOMPARE(run(reportN, 4).results(), - QList<double>({0, 0, 0, 0})); + QCOMPARE(run(&staticReport3).results(), + QList<int>({0, 2, 1})); + QCOMPARE(run(staticReport3).results(), + QList<int>({0, 2, 1})); + + QCOMPARE(run(&reportN, 2).results(), + QList<double>({0, 0})); QCOMPARE(run(reportN, 2).results(), QList<double>({0, 0})); + QCOMPARE(run(&staticReportN, 2).results(), + QList<double>({0, 0})); + QCOMPARE(run(staticReportN, 2).results(), + QList<double>({0, 0})); + QString s = QLatin1String("string"); const QString &crs = QLatin1String("cr string"); const QString cs = QLatin1String("c string"); @@ -1259,11 +1282,21 @@ void tst_QtConcurrentRun::withPromiseInThreadPool() QCOMPARE(run(pool.data(), report3).results(), QList<int>({0, 2, 1})); - QCOMPARE(run(pool.data(), reportN, 4).results(), - QList<double>({0, 0, 0, 0})); + QCOMPARE(run(pool.data(), &staticReport3).results(), + QList<int>({0, 2, 1})); + QCOMPARE(run(pool.data(), staticReport3).results(), + QList<int>({0, 2, 1})); + + QCOMPARE(run(pool.data(), &reportN, 2).results(), + QList<double>({0, 0})); QCOMPARE(run(pool.data(), reportN, 2).results(), QList<double>({0, 0})); + QCOMPARE(run(pool.data(), &staticReportN, 2).results(), + QList<double>({0, 0})); + QCOMPARE(run(pool.data(), staticReportN, 2).results(), + QList<double>({0, 0})); + QString s = QLatin1String("string"); const QString &crs = QLatin1String("cr string"); const QString cs = QLatin1String("c string"); diff --git a/tests/auto/concurrent/qtconcurrenttask/CMakeLists.txt b/tests/auto/concurrent/qtconcurrenttask/CMakeLists.txt index 21f5625606..89226eaacc 100644 --- a/tests/auto/concurrent/qtconcurrenttask/CMakeLists.txt +++ b/tests/auto/concurrent/qtconcurrenttask/CMakeLists.txt @@ -5,6 +5,12 @@ ## tst_qtconcurrenttask Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtconcurrenttask LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtconcurrenttask SOURCES tst_qtconcurrenttask.cpp diff --git a/tests/auto/concurrent/qtconcurrenttask/tst_qtconcurrenttask.cpp b/tests/auto/concurrent/qtconcurrenttask/tst_qtconcurrenttask.cpp index 114d899e1d..d570b0f974 100644 --- a/tests/auto/concurrent/qtconcurrenttask/tst_qtconcurrenttask.cpp +++ b/tests/auto/concurrent/qtconcurrenttask/tst_qtconcurrenttask.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2020 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 <qtconcurrenttask.h> @@ -32,7 +32,7 @@ void tst_QtConcurrentTask::taskWithFreeFunction() { QVariant value(42); - auto result = task(&qvariant_cast<int>) + auto result = task([](const QVariant &var){ return qvariant_cast<int>(var); }) .withArguments(value) .spawn() .result(); diff --git a/tests/auto/concurrent/qtconcurrentthreadengine/CMakeLists.txt b/tests/auto/concurrent/qtconcurrentthreadengine/CMakeLists.txt index c2f067c3ff..c3c8c9ea59 100644 --- a/tests/auto/concurrent/qtconcurrentthreadengine/CMakeLists.txt +++ b/tests/auto/concurrent/qtconcurrentthreadengine/CMakeLists.txt @@ -5,6 +5,12 @@ ## tst_qtconcurrentthreadengine Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtconcurrentthreadengine LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtconcurrentthreadengine SOURCES tst_qtconcurrentthreadengine.cpp diff --git a/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp b/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp index 51a2273f9d..0151b13693 100644 --- a/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp +++ b/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp @@ -1,5 +1,8 @@ // 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 + +#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses + #include <qtconcurrentthreadengine.h> #include <qexception.h> #include <QThread> diff --git a/tests/auto/concurrent/testhelper_functions.h b/tests/auto/concurrent/testhelper_functions.h index b2c435bc39..88c2e28910 100644 --- a/tests/auto/concurrent/testhelper_functions.h +++ b/tests/auto/concurrent/testhelper_functions.h @@ -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 #ifndef FUNCTIONS_H #define FUNCTIONS_H |