summaryrefslogtreecommitdiffstats
path: root/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp')
-rw-r--r--tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp83
1 files changed, 55 insertions, 28 deletions
diff --git a/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp b/tests/auto/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp
index f9e68bd5f6..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();
@@ -1362,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);
@@ -1407,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()