/tests/auto/qtconcurrentmap/tst_qtconcurrentmap.cpp
https://bitbucket.org/ultra_iter/qt-vtl · C++ · 2445 lines · 1935 code · 370 blank · 140 comment · 29 complexity · e9a655d6e5d260378eae82bdec3fabe1 MD5 · raw file
Large files are truncated click here to view the full file
- /****************************************************************************
- **
- ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
- ** All rights reserved.
- ** Contact: Nokia Corporation (qt-info@nokia.com)
- **
- ** This file is part of the test suite of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** GNU Lesser General Public License Usage
- ** This file may be used under the terms of the GNU Lesser General Public
- ** License version 2.1 as published by the Free Software Foundation and
- ** appearing in the file LICENSE.LGPL included in the packaging of this
- ** file. Please review the following information to ensure the GNU Lesser
- ** General Public License version 2.1 requirements will be met:
- ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
- **
- ** In addition, as a special exception, Nokia gives you certain additional
- ** rights. These rights are described in the Nokia Qt LGPL Exception
- ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU General
- ** Public License version 3.0 as published by the Free Software Foundation
- ** and appearing in the file LICENSE.GPL included in the packaging of this
- ** file. Please review the following information to ensure the GNU General
- ** Public License version 3.0 requirements will be met:
- ** http://www.gnu.org/copyleft/gpl.html.
- **
- ** Other Usage
- ** Alternatively, this file may be used in accordance with the terms and
- ** conditions contained in a signed written agreement between you and Nokia.
- **
- **
- **
- **
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
- #include <qtconcurrentmap.h>
- #include <qtconcurrentexception.h>
- #include <qdebug.h>
- #include <QThread>
- #include <QtTest/QtTest>
- #include "functions.h"
- #include "../qfuture/versioncheck.h"
- Q_DECLARE_METATYPE(QVector<int>);
- Q_DECLARE_METATYPE(QVector<double>);
- Q_DECLARE_METATYPE(QVector<QString>);
- Q_DECLARE_METATYPE(QList<int>);
- Q_DECLARE_METATYPE(QList<double>);
- Q_DECLARE_METATYPE(QList<QString>);
- class tst_QtConcurrentMap: public QObject
- {
- Q_OBJECT
- private slots:
- void map();
- void blocking_map();
- void mapped();
- void blocking_mapped();
- void mappedReduced();
- void blocking_mappedReduced();
- void assignResult();
- void functionOverloads();
- #ifndef QT_NO_EXCEPTIONS
- void exceptions();
- #endif
- void incrementalResults();
- void noDetatch();
- void stlContainers();
- void qFutureAssignmentLeak();
- void stressTest();
- public slots:
- void throttling();
- };
- #if !defined (QT_NO_CONCURRENT_TEST) && !defined(QT_NO_CONCURRENT_MAP)
- using namespace QtConcurrent;
- void multiplyBy2Immutable(int x)
- {
- x *= 2;
- }
- class MultiplyBy2Immutable
- {
- public:
- void operator()(int x)
- {
- x *= 2;
- }
- };
- void multiplyBy2InPlace(int &x)
- {
- x *= 2;
- }
- class MultiplyBy2InPlace
- {
- public:
- void operator()(int &x)
- {
- x *= 2;
- }
- };
- Q_DECLARE_METATYPE(QList<Number>);
- void tst_QtConcurrentMap::map()
- {
- // functors take arguments by reference, modifying the sequence in place
- {
- QList<int> list;
- list << 1 << 2 << 3;
- // functor
- QtConcurrent::map(list, MultiplyBy2InPlace()).waitForFinished();
- QCOMPARE(list, QList<int>() << 2 << 4 << 6);
- QtConcurrent::map(list.begin(), list.end(), MultiplyBy2InPlace()).waitForFinished();
- QCOMPARE(list, QList<int>() << 4 << 8 << 12);
- // function
- QtConcurrent::map(list, multiplyBy2InPlace).waitForFinished();
- QCOMPARE(list, QList<int>() << 8 << 16 << 24);
- QtConcurrent::map(list.begin(), list.end(), multiplyBy2InPlace).waitForFinished();
- QCOMPARE(list, QList<int>() << 16 << 32 << 48);
- // bound function
- QtConcurrent::map(list, multiplyBy2InPlace).waitForFinished();
- QCOMPARE(list, QList<int>() << 32 << 64 << 96);
- QtConcurrent::map(list.begin(), list.end(), multiplyBy2InPlace).waitForFinished();
- QCOMPARE(list, QList<int>() << 64 << 128 << 192);
- // member function
- QList<Number> numberList;
- numberList << 1 << 2 << 3;
- QtConcurrent::map(numberList, &Number::multiplyBy2).waitForFinished();
- QCOMPARE(numberList, QList<Number>() << 2 << 4 << 6);
- QtConcurrent::map(numberList.begin(), numberList.end(), &Number::multiplyBy2).waitForFinished();
- QCOMPARE(numberList, QList<Number>() << 4 << 8 << 12);
- #ifdef Q_COMPILER_LAMBDA
- // lambda
- QtConcurrent::map(list, [](int &x){x *= 2;}).waitForFinished();
- QCOMPARE(list, QList<int>() << 128 << 256 << 384);
- QtConcurrent::map(list.begin(), list.end(), [](int &x){x *= 2;}).waitForFinished();
- QCOMPARE(list, QList<int>() << 256 << 512 << 768);
- #endif
- }
- // functors don't take arguments by reference, making these no-ops
- {
- QList<int> list;
- list << 1 << 2 << 3;
- // functor
- QtConcurrent::map(list, MultiplyBy2Immutable()).waitForFinished();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QtConcurrent::map(list.begin(), list.end(), MultiplyBy2Immutable()).waitForFinished();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- // function
- QtConcurrent::map(list, multiplyBy2Immutable).waitForFinished();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QtConcurrent::map(list.begin(), list.end(), multiplyBy2Immutable).waitForFinished();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- // bound function
- QtConcurrent::map(list, multiplyBy2Immutable).waitForFinished();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QtConcurrent::map(list.begin(), list.end(), multiplyBy2Immutable).waitForFinished();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- #ifdef Q_COMPILER_LAMBDA
- // lambda
- QtConcurrent::map(list, [](int x){x *= 2;}).waitForFinished();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QtConcurrent::map(list.begin(), list.end(), [](int x){x *= 2;}).waitForFinished();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- #endif
- }
- // Linked lists and forward iterators
- {
- QLinkedList<int> list;
- list << 1 << 2 << 3;
- // functor
- QtConcurrent::map(list, MultiplyBy2InPlace()).waitForFinished();
- QCOMPARE(list, QLinkedList<int>() << 2 << 4 << 6);
- QtConcurrent::map(list.begin(), list.end(), MultiplyBy2InPlace()).waitForFinished();
- QCOMPARE(list, QLinkedList<int>() << 4 << 8 << 12);
- // function
- QtConcurrent::map(list, multiplyBy2InPlace).waitForFinished();
- QCOMPARE(list, QLinkedList<int>() << 8 << 16 << 24);
- QtConcurrent::map(list.begin(), list.end(), multiplyBy2InPlace).waitForFinished();
- QCOMPARE(list, QLinkedList<int>() << 16 << 32 << 48);
- // bound function
- QtConcurrent::map(list, multiplyBy2InPlace).waitForFinished();
- QCOMPARE(list, QLinkedList<int>() << 32 << 64 << 96);
- QtConcurrent::map(list.begin(), list.end(), multiplyBy2InPlace).waitForFinished();
- QCOMPARE(list, QLinkedList<int>() << 64 << 128 << 192);
- // member function
- QLinkedList<Number> numberList;
- numberList << 1 << 2 << 3;
- QtConcurrent::map(numberList, &Number::multiplyBy2).waitForFinished();
- QCOMPARE(numberList, QLinkedList<Number>() << 2 << 4 << 6);
- QtConcurrent::map(numberList.begin(), numberList.end(), &Number::multiplyBy2).waitForFinished();
- QCOMPARE(numberList, QLinkedList<Number>() << 4 << 8 << 12);
- }
- #if 0
- // not allowed: map() with immutable sequences makes no sense
- {
- const QList<int> list = QList<int>() << 1 << 2 << 3;
- QtConcurrent::map(list, MultiplyBy2Immutable());
- QtConcurrent::map(list, multiplyBy2Immutable);
- QtConcurrent::map(list, multiplyBy2Immutable);
- }
- #endif
- #if 0
- // not allowed: in place modification of a temp copy (since temp copy goes out of scope)
- {
- QList<int> list;
- list << 1 << 2 << 3;
- QtConcurrent::map(QList<int>(list), MultiplyBy2InPlace());
- QtConcurrent::map(QList<int>(list), multiplyBy2);
- QtConcurrent::map(QList<int>(list), multiplyBy2InPlace);
- QList<Number> numberList;
- numberList << 1 << 2 << 3;
- QtConcurrent::map(QList<Number>(numberList), &Number::multiplyBy2);
- }
- #endif
- #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;;
- QtConcurrent::map(list, MultiplyBy2InPlace());
- QtConcurrent::map(list, multiplyBy2InPlace);
- QtConcurrent::map(list, multiplyBy2InPlace);
- const QList<Number> numberList = QList<Number>() << 1 << 2 << 3;
- QtConcurrent::map(numberList, &Number::multiplyBy2);
- }
- #endif
- }
- void tst_QtConcurrentMap::blocking_map()
- {
- // functors take arguments by reference, modifying the sequence in place
- {
- QList<int> list;
- list << 1 << 2 << 3;
- // functor
- QtConcurrent::blockingMap(list, MultiplyBy2InPlace());
- QCOMPARE(list, QList<int>() << 2 << 4 << 6);
- QtConcurrent::blockingMap(list.begin(), list.end(), MultiplyBy2InPlace());
- QCOMPARE(list, QList<int>() << 4 << 8 << 12);
- // function
- QtConcurrent::blockingMap(list, multiplyBy2InPlace);
- QCOMPARE(list, QList<int>() << 8 << 16 << 24);
- QtConcurrent::blockingMap(list.begin(), list.end(), multiplyBy2InPlace);
- QCOMPARE(list, QList<int>() << 16 << 32 << 48);
- // bound function
- QtConcurrent::blockingMap(list, multiplyBy2InPlace);
- QCOMPARE(list, QList<int>() << 32 << 64 << 96);
- QtConcurrent::blockingMap(list.begin(), list.end(), multiplyBy2InPlace);
- QCOMPARE(list, QList<int>() << 64 << 128 << 192);
- // member function
- QList<Number> numberList;
- numberList << 1 << 2 << 3;
- QtConcurrent::blockingMap(numberList, &Number::multiplyBy2);
- QCOMPARE(numberList, QList<Number>() << 2 << 4 << 6);
- QtConcurrent::blockingMap(numberList.begin(), numberList.end(), &Number::multiplyBy2);
- QCOMPARE(numberList, QList<Number>() << 4 << 8 << 12);
- }
- // functors don't take arguments by reference, making these no-ops
- {
- QList<int> list;
- list << 1 << 2 << 3;
- // functor
- QtConcurrent::blockingMap(list, MultiplyBy2Immutable());
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QtConcurrent::blockingMap(list.begin(), list.end(), MultiplyBy2Immutable());
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- // function
- QtConcurrent::blockingMap(list, multiplyBy2Immutable);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QtConcurrent::blockingMap(list.begin(), list.end(), multiplyBy2Immutable);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- // bound function
- QtConcurrent::blockingMap(list, multiplyBy2Immutable);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QtConcurrent::blockingMap(list.begin(), list.end(), multiplyBy2Immutable);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- }
- // Linked lists and forward iterators
- {
- QLinkedList<int> list;
- list << 1 << 2 << 3;
- // functor
- QtConcurrent::blockingMap(list, MultiplyBy2InPlace());
- QCOMPARE(list, QLinkedList<int>() << 2 << 4 << 6);
- QtConcurrent::blockingMap(list.begin(), list.end(), MultiplyBy2InPlace());
- QCOMPARE(list, QLinkedList<int>() << 4 << 8 << 12);
- // function
- QtConcurrent::blockingMap(list, multiplyBy2InPlace);
- QCOMPARE(list, QLinkedList<int>() << 8 << 16 << 24);
- QtConcurrent::blockingMap(list.begin(), list.end(), multiplyBy2InPlace);
- QCOMPARE(list, QLinkedList<int>() << 16 << 32 << 48);
- // bound function
- QtConcurrent::blockingMap(list, multiplyBy2InPlace);
- QCOMPARE(list, QLinkedList<int>() << 32 << 64 << 96);
- QtConcurrent::blockingMap(list.begin(), list.end(), multiplyBy2InPlace);
- QCOMPARE(list, QLinkedList<int>() << 64 << 128 << 192);
- // member function
- QLinkedList<Number> numberList;
- numberList << 1 << 2 << 3;
- QtConcurrent::blockingMap(numberList, &Number::multiplyBy2);
- QCOMPARE(numberList, QLinkedList<Number>() << 2 << 4 << 6);
- QtConcurrent::blockingMap(numberList.begin(), numberList.end(), &Number::multiplyBy2);
- QCOMPARE(numberList, QLinkedList<Number>() << 4 << 8 << 12);
- }
- #if 0
- // not allowed: map() with immutable sequences makes no sense
- {
- const QList<int> list = QList<int>() << 1 << 2 << 3;
- QtConcurrent::blockingMap(list, MultiplyBy2Immutable());
- QtConcurrent::blockkng::map(list, multiplyBy2Immutable);
- QtConcurrent::blockingMap(list, multiplyBy2Immutable);
- }
- #endif
- #if 0
- // not allowed: in place modification of a temp copy (since temp copy goes out of scope)
- {
- QList<int> list;
- list << 1 << 2 << 3;
- QtConcurrent::blockingMap(QList<int>(list), MultiplyBy2InPlace());
- QtConcurrent::blockingMap(QList<int>(list), multiplyBy2);
- QtConcurrent::blockingMap(QList<int>(list), multiplyBy2InPlace);
- QList<Number> numberList;
- numberList << 1 << 2 << 3;
- QtConcurrent::blockingMap(QList<Number>(numberList), &Number::multiplyBy2);
- }
- #endif
- #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;;
- QtConcurrent::blockingMap(list, MultiplyBy2InPlace());
- QtConcurrent::blockingMap(list, multiplyBy2InPlace);
- QtConcurrent::blockingMap(list, multiplyBy2InPlace);
- const QList<Number> numberList = QList<Number>() << 1 << 2 << 3;
- QtConcurrent::blockingMap(numberList, &Number::multiplyBy2);
- }
- #endif
- }
- int multiplyBy2(int x)
- {
- int y = x * 2;
- return y;
- }
- class MultiplyBy2
- {
- public:
- typedef int result_type;
- int operator()(int x) const
- {
- int y = x * 2;
- return y;
- }
- };
- double intToDouble(int x)
- {
- return double(x);
- }
- class IntToDouble
- {
- public:
- typedef double result_type;
- double operator()(int x) const
- {
- return double(x);
- }
- };
- int stringToInt(const QString &string)
- {
- return string.toInt();
- }
- class StringToInt
- {
- public:
- typedef int result_type;
- int operator()(const QString &string) const
- {
- return string.toInt();
- }
- };
- void tst_QtConcurrentMap::mapped()
- {
- QList<int> list;
- list << 1 << 2 << 3;
- QLinkedList<int> linkedList;
- linkedList << 1 << 2 << 3;
- QList<Number> numberList;
- numberList << 1 << 2 << 3;
- QLinkedList<Number> numberLinkedList;
- numberLinkedList << 1 << 2 << 3;
- // functor
- {
- QList<int> list2 = QtConcurrent::mapped(list, MultiplyBy2()).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<int>() << 2 << 4 << 6);
- QList<int> list3 = QtConcurrent::mapped(list.constBegin(),
- list.constEnd(),
- MultiplyBy2()).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<int>() << 2 << 4 << 6);
- QList<int> list4 = QtConcurrent::mapped(QList<int>(list), MultiplyBy2()).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<int>() << 2 << 4 << 6);
- }
- {
- QList<int> list2 = QtConcurrent::mapped(linkedList, MultiplyBy2()).results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<int>() << 2 << 4 << 6);
- QList<int> list3 = QtConcurrent::mapped(linkedList.constBegin(),
- linkedList.constEnd(),
- MultiplyBy2()).results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<int>() << 2 << 4 << 6);
- QList<int> list4 =
- QtConcurrent::mapped(QLinkedList<int>(linkedList), MultiplyBy2()).results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<int>() << 2 << 4 << 6);
- }
- // function
- {
- QList<int> list2 = QtConcurrent::mapped(list, multiplyBy2).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<int>() << 2 << 4 << 6);
- QList<int> list3 = QtConcurrent::mapped(list.constBegin(),
- list.constEnd(),
- multiplyBy2).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<int>() << 2 << 4 << 6);
- QList<int> list4 = QtConcurrent::mapped(QList<int>(list), multiplyBy2).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<int>() << 2 << 4 << 6);
- }
- {
- QList<int> list2 = QtConcurrent::mapped(linkedList, multiplyBy2).results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<int>() << 2 << 4 << 6);
- QList<int> list3 = QtConcurrent::mapped(linkedList.constBegin(),
- linkedList.constEnd(),
- multiplyBy2).results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<int>() << 2 << 4 << 6);
- QList<int> list4 =
- QtConcurrent::mapped(QLinkedList<int>(linkedList), multiplyBy2).results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<int>() << 2 << 4 << 6);
- }
- // bound function
- {
- QList<int> list2 = QtConcurrent::mapped(list, multiplyBy2).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<int>() << 2 << 4 << 6);
- QList<int> list3 = QtConcurrent::mapped(list.constBegin(),
- list.constEnd(),
- multiplyBy2).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<int>() << 2 << 4 << 6);
- QList<int> list4 = QtConcurrent::mapped(QList<int>(list), multiplyBy2).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<int>() << 2 << 4 << 6);
- }
- {
- QList<int> list2 = QtConcurrent::mapped(linkedList, multiplyBy2).results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<int>() << 2 << 4 << 6);
- QList<int> list3 = QtConcurrent::mapped(linkedList.constBegin(),
- linkedList.constEnd(),
- multiplyBy2)
- .results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<int>() << 2 << 4 << 6);
- QList<int> list4 = QtConcurrent::mapped(QLinkedList<int>(linkedList), multiplyBy2)
- .results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<int>() << 2 << 4 << 6);
- }
- // const member function
- {
- QList<Number> numberList2 = QtConcurrent::mapped(numberList, &Number::multipliedBy2)
- .results();
- QCOMPARE(numberList, QList<Number>() << 1 << 2 << 3);
- QCOMPARE(numberList2, QList<Number>() << 2 << 4 << 6);
- QList<Number> numberList3 = QtConcurrent::mapped(numberList.constBegin(),
- numberList.constEnd(),
- &Number::multipliedBy2)
- .results();
- QCOMPARE(numberList, QList<Number>() << 1 << 2 << 3);
- QCOMPARE(numberList3, QList<Number>() << 2 << 4 << 6);
- QList<Number> numberList4 = QtConcurrent::mapped(QList<Number>(numberList),
- &Number::multipliedBy2)
- .results();
- QCOMPARE(numberList, QList<Number>() << 1 << 2 << 3);
- QCOMPARE(numberList4, QList<Number>() << 2 << 4 << 6);
- }
- {
- QList<Number> numberList2 = QtConcurrent::mapped(numberLinkedList, &Number::multipliedBy2)
- .results();
- QCOMPARE(numberLinkedList, QLinkedList<Number>() << 1 << 2 << 3);
- QCOMPARE(numberList2, QList<Number>() << 2 << 4 << 6);
- QList<Number> numberList3 = QtConcurrent::mapped(numberLinkedList.constBegin(),
- numberLinkedList.constEnd(),
- &Number::multipliedBy2)
- .results();
- QCOMPARE(numberLinkedList, QLinkedList<Number>() << 1 << 2 << 3);
- QCOMPARE(numberList3, QList<Number>() << 2 << 4 << 6);
- QList<Number> numberList4 = QtConcurrent::mapped(QLinkedList<Number>(numberLinkedList),
- &Number::multipliedBy2)
- .results();
- QCOMPARE(numberLinkedList, QLinkedList<Number>() << 1 << 2 << 3);
- QCOMPARE(numberList4, QList<Number>() << 2 << 4 << 6);
- }
- // change the value_type, same container
- // functor
- {
- QList<double> list2 = QtConcurrent::mapped(list, IntToDouble()).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list3 = QtConcurrent::mapped(list.constBegin(),
- list.constEnd(),
- IntToDouble())
- .results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list4 = QtConcurrent::mapped(QList<int>(list),
- IntToDouble())
- .results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0);
- }
- {
- QList<double> list2 = QtConcurrent::mapped(linkedList, IntToDouble()).results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list3 = QtConcurrent::mapped(linkedList.constBegin(),
- linkedList.constEnd(),
- IntToDouble())
- .results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list4 = QtConcurrent::mapped(QLinkedList<int>(linkedList),
- IntToDouble())
- .results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0);
- }
- // function
- {
- QList<double> list2 = QtConcurrent::mapped(list, intToDouble).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list3 = QtConcurrent::mapped(list.constBegin(),
- list.constEnd(),
- intToDouble)
- .results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list4 = QtConcurrent::mapped(QList<int>(list), intToDouble).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0);
- }
- {
- QList<double> list2 = QtConcurrent::mapped(linkedList, intToDouble).results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list3 = QtConcurrent::mapped(linkedList.constBegin(),
- linkedList.constEnd(),
- intToDouble)
- .results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list4 = QtConcurrent::mapped(QLinkedList<int>(linkedList), intToDouble)
- .results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0);
- }
- // bound function
- {
- QList<double> list2 = QtConcurrent::mapped(list, intToDouble).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list3 = QtConcurrent::mapped(list.constBegin(),
- list.constEnd(),
- intToDouble)
- .results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list4 = QtConcurrent::mapped(QList<int>(list),
- intToDouble)
- .results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0);
- }
- {
- QList<double> list2 = QtConcurrent::mapped(linkedList, intToDouble).results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list3 = QtConcurrent::mapped(linkedList.constBegin(),
- linkedList.constEnd(),
- intToDouble)
- .results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list4 = QtConcurrent::mapped(QLinkedList<int>(linkedList),
- intToDouble)
- .results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0);
- }
- // const member function
- {
- QList<QString> list2 = QtConcurrent::mapped(numberList, &Number::toString).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<QString>() << "1" << "2" << "3");
- QList<QString> list3 = QtConcurrent::mapped(numberList.constBegin(),
- numberList.constEnd(),
- &Number::toString)
- .results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<QString>() << "1" << "2" << "3");
- QList<QString> list4 = QtConcurrent::mapped(QList<Number>(numberList), &Number::toString)
- .results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<QString>() << "1" << "2" << "3");
- }
- {
- QList<QString> list2 = QtConcurrent::mapped(numberLinkedList, &Number::toString).results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<QString>() << "1" << "2" << "3");
- QList<QString> list3 = QtConcurrent::mapped(numberLinkedList.constBegin(),
- numberLinkedList.constEnd(),
- &Number::toString)
- .results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<QString>() << "1" << "2" << "3");
- QList<QString> list4 = QtConcurrent::mapped(QLinkedList<Number>(numberLinkedList),
- &Number::toString)
- .results();
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<QString>() << "1" << "2" << "3");
- }
- // change the value_type
- {
- QList<QString> strings = QStringList() << "1" << "2" << "3";
- QList<int> list = QtConcurrent::mapped(strings, StringToInt()).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QList<int> list2 = QtConcurrent::mapped(strings.constBegin(),
- strings.constEnd(),
- StringToInt())
- .results();
- QCOMPARE(list2, QList<int>() << 1 << 2 << 3);
- }
- {
- QList<QString> strings = QStringList() << "1" << "2" << "3";
- QList<int> list = QtConcurrent::mapped(strings, stringToInt).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QList<int> list2 = QtConcurrent::mapped(strings.constBegin(),
- strings.constEnd(),
- stringToInt).results();
- QCOMPARE(list2, QList<int>() << 1 << 2 << 3);
- }
- {
- QList<int> numberList2 = QtConcurrent::mapped(numberList, &Number::toInt).results();
- QCOMPARE(numberList2, QList<int>() << 1 << 2 << 3);
- QList<int> numberList3 = QtConcurrent::mapped(numberList.constBegin(),
- numberList.constEnd(),
- &Number::toInt)
- .results();
- QCOMPARE(numberList3, QList<int>() << 1 << 2 << 3);
- }
- // change the value_type from QStringList
- {
- QStringList strings = QStringList() << "1" << "2" << "3";
- QList<int> list = QtConcurrent::mapped(strings, StringToInt()).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QList<int> list2 = QtConcurrent::mapped(strings.constBegin(),
- strings.constEnd(),
- StringToInt())
- .results();
- QCOMPARE(list2, QList<int>() << 1 << 2 << 3);
- }
- {
- QStringList strings = QStringList() << "1" << "2" << "3";
- QList<int> list = QtConcurrent::mapped(strings, stringToInt).results();
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QList<int> list2 = QtConcurrent::mapped(strings.constBegin(),
- strings.constEnd(),
- stringToInt)
- .results();
- QCOMPARE(list2, QList<int>() << 1 << 2 << 3);
- }
- }
- void tst_QtConcurrentMap::blocking_mapped()
- {
- QList<int> list;
- list << 1 << 2 << 3;
- QLinkedList<int> linkedList;
- linkedList << 1 << 2 << 3;
- QList<Number> numberList;
- numberList << 1 << 2 << 3;
- QLinkedList<Number> numberLinkedList;
- numberLinkedList << 1 << 2 << 3;
- // functor
- {
- QList<int> list2 = QtConcurrent::blockingMapped(list, MultiplyBy2());
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<int>() << 2 << 4 << 6);
- QList<int> list3 = QtConcurrent::blockingMapped<QList<int> >(list.constBegin(),
- list.constEnd(),
- MultiplyBy2());
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<int>() << 2 << 4 << 6);
- QList<int> list4 = QtConcurrent::blockingMapped(QList<int>(list), MultiplyBy2());
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<int>() << 2 << 4 << 6);
- }
- {
- QLinkedList<int> linkedList2 = QtConcurrent::blockingMapped(linkedList, MultiplyBy2());
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList2, QLinkedList<int>() << 2 << 4 << 6);
- QLinkedList<int> linkedList3 = QtConcurrent::blockingMapped<QLinkedList<int> >(linkedList.constBegin(),
- linkedList.constEnd(),
- MultiplyBy2());
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList3, QLinkedList<int>() << 2 << 4 << 6);
- QLinkedList<int> linkedList4 = QtConcurrent::blockingMapped(QLinkedList<int>(linkedList), MultiplyBy2());
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList4, QLinkedList<int>() << 2 << 4 << 6);
- }
- // function
- {
- QList<int> list2 = QtConcurrent::blockingMapped(list, multiplyBy2);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<int>() << 2 << 4 << 6);
- QList<int> list3 = QtConcurrent::blockingMapped<QList<int> >(list.constBegin(),
- list.constEnd(),
- multiplyBy2);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<int>() << 2 << 4 << 6);
- QList<int> list4 = QtConcurrent::blockingMapped(QList<int>(list), multiplyBy2);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<int>() << 2 << 4 << 6);
- }
- {
- QLinkedList<int> linkedList2 = QtConcurrent::blockingMapped(linkedList, multiplyBy2);
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList2, QLinkedList<int>() << 2 << 4 << 6);
- QLinkedList<int> linkedList3 = QtConcurrent::blockingMapped<QLinkedList<int> >(linkedList.constBegin(),
- linkedList.constEnd(),
- multiplyBy2);
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList3, QLinkedList<int>() << 2 << 4 << 6);
- QLinkedList<int> linkedList4 = QtConcurrent::blockingMapped(QLinkedList<int>(linkedList), multiplyBy2);
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList4, QLinkedList<int>() << 2 << 4 << 6);
- }
- // bound function
- {
- QList<int> list2 = QtConcurrent::blockingMapped(list, multiplyBy2);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<int>() << 2 << 4 << 6);
- QList<int> list3 = QtConcurrent::blockingMapped<QList<int> >(list.constBegin(),
- list.constEnd(),
- multiplyBy2);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<int>() << 2 << 4 << 6);
- QList<int> list4 = QtConcurrent::blockingMapped(QList<int>(list), multiplyBy2);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<int>() << 2 << 4 << 6);
- }
- {
- QLinkedList<int> linkedList2 = QtConcurrent::blockingMapped(linkedList, multiplyBy2);
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList2, QLinkedList<int>() << 2 << 4 << 6);
- QLinkedList<int> linkedList3 = QtConcurrent::blockingMapped<QLinkedList<int> >(linkedList.constBegin(),
- linkedList.constEnd(),
- multiplyBy2);
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList3, QLinkedList<int>() << 2 << 4 << 6);
- QLinkedList<int> linkedList4 = QtConcurrent::blockingMapped(QLinkedList<int>(linkedList), multiplyBy2);
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList4, QLinkedList<int>() << 2 << 4 << 6);
- }
- // const member function
- {
- QList<Number> numberList2 = QtConcurrent::blockingMapped(numberList, &Number::multipliedBy2);
- QCOMPARE(numberList, QList<Number>() << 1 << 2 << 3);
- QCOMPARE(numberList2, QList<Number>() << 2 << 4 << 6);
- QList<Number> numberList3 = QtConcurrent::blockingMapped<QList<Number> >(numberList.constBegin(),
- numberList.constEnd(),
- &Number::multipliedBy2);
- QCOMPARE(numberList, QList<Number>() << 1 << 2 << 3);
- QCOMPARE(numberList3, QList<Number>() << 2 << 4 << 6);
- QList<Number> numberList4 = QtConcurrent::blockingMapped(QList<Number>(numberList),
- &Number::multipliedBy2);
- QCOMPARE(numberList, QList<Number>() << 1 << 2 << 3);
- QCOMPARE(numberList4, QList<Number>() << 2 << 4 << 6);
- }
- {
- QLinkedList<Number> numberLinkedList2 = QtConcurrent::blockingMapped(numberLinkedList, &Number::multipliedBy2);
- QCOMPARE(numberLinkedList, QLinkedList<Number>() << 1 << 2 << 3);
- QCOMPARE(numberLinkedList2, QLinkedList<Number>() << 2 << 4 << 6);
- QLinkedList<Number> numberLinkedList3 = QtConcurrent::blockingMapped<QLinkedList<Number> >(numberLinkedList.constBegin(),
- numberLinkedList.constEnd(),
- &Number::multipliedBy2);
- QCOMPARE(numberLinkedList, QLinkedList<Number>() << 1 << 2 << 3);
- QCOMPARE(numberLinkedList3, QLinkedList<Number>() << 2 << 4 << 6);
- QLinkedList<Number> numberLinkedList4 = QtConcurrent::blockingMapped(QLinkedList<Number>(numberLinkedList),
- &Number::multipliedBy2);
- QCOMPARE(numberLinkedList, QLinkedList<Number>() << 1 << 2 << 3);
- QCOMPARE(numberLinkedList4, QLinkedList<Number>() << 2 << 4 << 6);
- }
- // change the value_type, same container
- // functor
- {
- QList<double> list2 = QtConcurrent::blockingMapped<QList<double> >(list, IntToDouble());
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list3 = QtConcurrent::blockingMapped<QList<double> >(list.constBegin(),
- list.constEnd(),
- IntToDouble());
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list4 = QtConcurrent::blockingMapped<QList<double> >(QList<int>(list),
- IntToDouble());
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0);
- }
- {
- QLinkedList<double> linkedList2 = QtConcurrent::blockingMapped<QLinkedList<double> >(linkedList, IntToDouble());
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList2, QLinkedList<double>() << 1.0 << 2.0 << 3.0);
- QLinkedList<double> linkedList3 = QtConcurrent::blockingMapped<QLinkedList<double> >(linkedList.constBegin(),
- linkedList.constEnd(),
- IntToDouble());
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList3, QLinkedList<double>() << 1.0 << 2.0 << 3.0);
- QLinkedList<double> linkedList4 = QtConcurrent::blockingMapped<QLinkedList<double> >(QLinkedList<int>(linkedList),
- IntToDouble());
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList4, QLinkedList<double>() << 1.0 << 2.0 << 3.0);
- }
- // function
- {
- QList<double> list2 = QtConcurrent::blockingMapped<QList<double> >(list, intToDouble);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list3 = QtConcurrent::blockingMapped<QList<double> >(list.constBegin(),
- list.constEnd(),
- intToDouble);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list4 = QtConcurrent::blockingMapped<QList<double> >(QList<int>(list), intToDouble);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0);
- }
- {
- QLinkedList<double> linkedList2 = QtConcurrent::blockingMapped<QLinkedList<double> >(linkedList, intToDouble);
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList2, QLinkedList<double>() << 1.0 << 2.0 << 3.0);
- QLinkedList<double> linkedList3 = QtConcurrent::blockingMapped<QLinkedList<double> >(linkedList.constBegin(),
- linkedList.constEnd(),
- intToDouble);
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList3, QLinkedList<double>() << 1.0 << 2.0 << 3.0);
- QLinkedList<double> linkedList4 = QtConcurrent::blockingMapped<QLinkedList<double> >(QLinkedList<int>(linkedList), intToDouble);
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList4, QLinkedList<double>() << 1.0 << 2.0 << 3.0);
- }
- // bound function
- {
- QList<double> list2 = QtConcurrent::blockingMapped<QList<double> >(list, intToDouble);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list3 = QtConcurrent::blockingMapped<QList<double> >(list.constBegin(),
- list.constEnd(),
- intToDouble);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0);
- QList<double> list4 = QtConcurrent::blockingMapped<QList<double> >(QList<int>(list),
- intToDouble);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0);
- }
- {
- QLinkedList<double> linkedList2 = QtConcurrent::blockingMapped<QLinkedList<double> >(linkedList, intToDouble);
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList2, QLinkedList<double>() << 1.0 << 2.0 << 3.0);
- QLinkedList<double> linkedList3 = QtConcurrent::blockingMapped<QLinkedList<double> >(linkedList.constBegin(),
- linkedList.constEnd(),
- intToDouble);
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList3, QLinkedList<double>() << 1.0 << 2.0 << 3.0);
- QLinkedList<double> linkedList4 = QtConcurrent::blockingMapped<QLinkedList<double> >(QLinkedList<int>(linkedList),
- intToDouble);
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList4, QLinkedList<double>() << 1.0 << 2.0 << 3.0);
- }
- // const member function
- {
- QList<QString> list2 =
- QtConcurrent::blockingMapped<QList<QString> >(numberList, &Number::toString);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QList<QString>() << "1" << "2" << "3");
- QList<QString> list3 = QtConcurrent::blockingMapped<QList<QString> >(numberList.constBegin(),
- numberList.constEnd()
- , &Number::toString);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list3, QList<QString>() << "1" << "2" << "3");
- QList<QString> list4 =
- QtConcurrent::blockingMapped<QList<QString> >(QList<Number>(numberList), &Number::toString);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list4, QList<QString>() << "1" << "2" << "3");
- }
- {
- QLinkedList<QString> linkedList2 =
- QtConcurrent::blockingMapped<QLinkedList<QString> >(numberLinkedList, &Number::toString);
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList2, QLinkedList<QString>() << "1" << "2" << "3");
- QLinkedList<QString> linkedList3 = QtConcurrent::blockingMapped<QLinkedList<QString> >(numberLinkedList.constBegin(),
- numberLinkedList.constEnd()
- , &Number::toString);
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList3, QLinkedList<QString>() << "1" << "2" << "3");
- QLinkedList<QString> linkedList4 =
- QtConcurrent::blockingMapped<QLinkedList<QString> >(QLinkedList<Number>(numberLinkedList), &Number::toString);
- QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3);
- QCOMPARE(linkedList4, QLinkedList<QString>() << "1" << "2" << "3");
- }
- // change the value_type
- {
- QList<QString> strings = QStringList() << "1" << "2" << "3";
- QList<int> list = QtConcurrent::blockingMapped(strings, StringToInt());
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QList<int> list2 = QtConcurrent::blockingMapped<QList<int> >(strings.constBegin(),
- strings.constEnd(),
- StringToInt());
- QCOMPARE(list2, QList<int>() << 1 << 2 << 3);
- }
- {
- QList<QString> strings = QStringList() << "1" << "2" << "3";
- QList<int> list = QtConcurrent::blockingMapped(strings, stringToInt);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QList<int> list2 = QtConcurrent::blockingMapped<QList<int> >(strings.constBegin(),
- strings.constEnd(),
- stringToInt);
- QCOMPARE(list2, QList<int>() << 1 << 2 << 3);
- }
- {
- QList<int> numberList2 = QtConcurrent::blockingMapped(numberList, &Number::toInt);
- QCOMPARE(numberList2, QList<int>() << 1 << 2 << 3);
- QList<int> numberList3 = QtConcurrent::blockingMapped<QList<int> >(numberList.constBegin(),
- numberList.constEnd(),
- &Number::toInt);
- QCOMPARE(numberList3, QList<int>() << 1 << 2 << 3);
- }
- // change the value_type from QStringList
- {
- QStringList strings = QStringList() << "1" << "2" << "3";
- QList<int> list = QtConcurrent::blockingMapped(strings, StringToInt());
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QList<int> list2 = QtConcurrent::blockingMapped<QList<int> >(strings.constBegin(),
- strings.constEnd(),
- StringToInt());
- QCOMPARE(list2, QList<int>() << 1 << 2 << 3);
- }
- {
- QStringList strings = QStringList() << "1" << "2" << "3";
- QList<int> list = QtConcurrent::blockingMapped(strings, stringToInt);
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QList<int> list2 = QtConcurrent::blockingMapped<QList<int> >(strings.constBegin(),
- strings.constEnd(),
- stringToInt);
- QCOMPARE(list2, QList<int>() << 1 << 2 << 3);
- }
- // functor
- {
- QVector<double> list2 = QtConcurrent::blockingMapped<QVector<double> >(list, IntToDouble());
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPARE(list2, QVector<double>() << 1.0 << 2.0 << 3.0);
- QVector<double> list3 = QtConcurrent::blockingMapped<QVector<double> >(list.constBegin(),
- list.constEnd(),
- IntToDouble());
- QCOMPARE(list, QList<int>() << 1 << 2 << 3);
- QCOMPA…