From 0547598a28c3c1dd5c5f4c3ec9888b0de499199b Mon Sep 17 00:00:00 2001 From: Holger Ihrig Date: Wed, 24 Aug 2011 10:51:34 +0200 Subject: [PATCH] Moving relevant tests to corelib/concurrent Adding tests for QFutureSynchronizer and QtConcurrentResultStore Added minor things in QFutureSynchronizer and QtConcurrentResultStore and removed tests for destruction Task-number: QTBUG-21066 Change-Id: I9f088b89463340f339c914bcb37fb2f9d3b62057 Reviewed-on: http://codereview.qt.nokia.com/3477 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern Reviewed-by: Jason McDonald --- tests/auto/corelib.pro | 15 - tests/auto/corelib/concurrent/concurrent.pro | 19 + .../{ => corelib/concurrent}/qfuture/.gitignore | 0 .../{ => corelib/concurrent}/qfuture/qfuture.pro | 0 .../concurrent}/qfuture/tst_qfuture.cpp | 0 .../concurrent}/qfuture/versioncheck.h | 0 .../qfuturesynchronizer/qfuturesynchronizer.pro | 5 + .../tst_qfuturesynchronizer.cpp | 158 +++++++ .../concurrent}/qfuturewatcher/.gitignore | 0 .../concurrent}/qfuturewatcher/qfuturewatcher.pro | 0 .../qfuturewatcher/tst_qfuturewatcher.cpp | 2 +- .../concurrent}/qtconcurrentfilter/.gitignore | 0 .../qtconcurrentfilter/qtconcurrentfilter.pro | 0 .../qtconcurrentfilter/tst_qtconcurrentfilter.cpp | 0 .../qtconcurrentiteratekernel/.gitignore | 0 .../qtconcurrentiteratekernel.pro | 0 .../tst_qtconcurrentiteratekernel.cpp | 0 .../concurrent}/qtconcurrentmap/.gitignore | 0 .../concurrent}/qtconcurrentmap/functions.h | 0 .../qtconcurrentmap/qtconcurrentmap.pro | 0 .../qtconcurrentmap/tst_qtconcurrentmap.cpp | 0 .../qtconcurrentresultstore.pro | 5 + .../tst_qtconcurrentresultstore.cpp | 491 +++++++++++++++++++++ .../concurrent}/qtconcurrentrun/.gitignore | 0 .../qtconcurrentrun/qtconcurrentrun.pro | 0 .../qtconcurrentrun/tst_qtconcurrentrun.cpp | 0 .../qtconcurrentthreadengine/.gitignore | 0 .../qtconcurrentthreadengine.pro | 0 .../tst_qtconcurrentthreadengine.cpp | 0 .../concurrent}/qthreadpool/.gitignore | 0 .../concurrent}/qthreadpool/qthreadpool.pro | 0 .../concurrent}/qthreadpool/tst_qthreadpool.cpp | 0 tests/auto/corelib/corelib.pro | 3 +- 33 files changed, 681 insertions(+), 17 deletions(-) create mode 100644 tests/auto/corelib/concurrent/concurrent.pro rename tests/auto/{ => corelib/concurrent}/qfuture/.gitignore (100%) rename tests/auto/{ => corelib/concurrent}/qfuture/qfuture.pro (100%) rename tests/auto/{ => corelib/concurrent}/qfuture/tst_qfuture.cpp (100%) rename tests/auto/{ => corelib/concurrent}/qfuture/versioncheck.h (100%) create mode 100644 tests/auto/corelib/concurrent/qfuturesynchronizer/qfuturesynchronizer.pro create mode 100644 tests/auto/corelib/concurrent/qfuturesynchronizer/tst_qfuturesynchronizer.cpp rename tests/auto/{ => corelib/concurrent}/qfuturewatcher/.gitignore (100%) rename tests/auto/{ => corelib/concurrent}/qfuturewatcher/qfuturewatcher.pro (100%) rename tests/auto/{ => corelib/concurrent}/qfuturewatcher/tst_qfuturewatcher.cpp (99%) rename tests/auto/{ => corelib/concurrent}/qtconcurrentfilter/.gitignore (100%) rename tests/auto/{ => corelib/concurrent}/qtconcurrentfilter/qtconcurrentfilter.pro (100%) rename tests/auto/{ => corelib/concurrent}/qtconcurrentfilter/tst_qtconcurrentfilter.cpp (100%) rename tests/auto/{ => corelib/concurrent}/qtconcurrentiteratekernel/.gitignore (100%) rename tests/auto/{ => corelib/concurrent}/qtconcurrentiteratekernel/qtconcurrentiteratekernel.pro (100%) rename tests/auto/{ => corelib/concurrent}/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp (100%) rename tests/auto/{ => corelib/concurrent}/qtconcurrentmap/.gitignore (100%) rename tests/auto/{ => corelib/concurrent}/qtconcurrentmap/functions.h (100%) rename tests/auto/{ => corelib/concurrent}/qtconcurrentmap/qtconcurrentmap.pro (100%) rename tests/auto/{ => corelib/concurrent}/qtconcurrentmap/tst_qtconcurrentmap.cpp (100%) create mode 100644 tests/auto/corelib/concurrent/qtconcurrentresultstore/qtconcurrentresultstore.pro create mode 100644 tests/auto/corelib/concurrent/qtconcurrentresultstore/tst_qtconcurrentresultstore.cpp rename tests/auto/{ => corelib/concurrent}/qtconcurrentrun/.gitignore (100%) rename tests/auto/{ => corelib/concurrent}/qtconcurrentrun/qtconcurrentrun.pro (100%) rename tests/auto/{ => corelib/concurrent}/qtconcurrentrun/tst_qtconcurrentrun.cpp (100%) rename tests/auto/{ => corelib/concurrent}/qtconcurrentthreadengine/.gitignore (100%) rename tests/auto/{ => corelib/concurrent}/qtconcurrentthreadengine/qtconcurrentthreadengine.pro (100%) rename tests/auto/{ => corelib/concurrent}/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp (100%) rename tests/auto/{ => corelib/concurrent}/qthreadpool/.gitignore (100%) rename tests/auto/{ => corelib/concurrent}/qthreadpool/qthreadpool.pro (100%) rename tests/auto/{ => corelib/concurrent}/qthreadpool/tst_qthreadpool.cpp (100%) diff --git a/tests/auto/corelib.pro b/tests/auto/corelib.pro index f9434d5..927d439 100644 --- a/tests/auto/corelib.pro +++ b/tests/auto/corelib.pro @@ -27,8 +27,6 @@ SUBDIRS=\ qfilesystemwatcher \ qflags \ qfreelist \ - qfuture \ - qfuturewatcher \ qgetputenv \ qglobal \ qhash \ @@ -73,16 +71,10 @@ SUBDIRS=\ qstringlist \ qstringmatcher \ qstringref \ - qtconcurrentfilter \ - qtconcurrentiteratekernel \ - qtconcurrentmap \ - qtconcurrentrun \ - qtconcurrentthreadengine \ qtemporaryfile \ qtextboundaryfinder \ qthread \ qthreadonce \ - qthreadpool \ qthreadstorage \ qtime \ qtimeline \ @@ -101,13 +93,6 @@ SUBDIRS=\ qfilesystementry \ qabstractfileengine -symbian:SUBDIRS -= \ - qtconcurrentfilter \ - qtconcurrentiteratekernel \ - qtconcurrentmap \ - qtconcurrentrun \ - qtconcurrentthreadengine \ - !contains(QT_CONFIG, private_tests): SUBDIRS -= \ qfileinfo \ diff --git a/tests/auto/corelib/concurrent/concurrent.pro b/tests/auto/corelib/concurrent/concurrent.pro new file mode 100644 index 0000000..6d7850b --- /dev/null +++ b/tests/auto/corelib/concurrent/concurrent.pro @@ -0,0 +1,19 @@ +TEMPLATE=subdirs +SUBDIRS=\ + qfuture \ + qfuturesynchronizer \ + qfuturewatcher \ + qtconcurrentfilter \ + qtconcurrentiteratekernel \ + qtconcurrentmap \ + qtconcurrentresultstore \ + qtconcurrentrun \ + qtconcurrentthreadengine \ + qthreadpool + +symbian:SUBDIRS -= \ + qtconcurrentfilter \ + qtconcurrentiteratekernel \ + qtconcurrentmap \ + qtconcurrentrun \ + qtconcurrentthreadengine \ diff --git a/tests/auto/qfuture/.gitignore b/tests/auto/corelib/concurrent/qfuture/.gitignore similarity index 100% rename from tests/auto/qfuture/.gitignore rename to tests/auto/corelib/concurrent/qfuture/.gitignore diff --git a/tests/auto/qfuture/qfuture.pro b/tests/auto/corelib/concurrent/qfuture/qfuture.pro similarity index 100% rename from tests/auto/qfuture/qfuture.pro rename to tests/auto/corelib/concurrent/qfuture/qfuture.pro diff --git a/tests/auto/qfuture/tst_qfuture.cpp b/tests/auto/corelib/concurrent/qfuture/tst_qfuture.cpp similarity index 100% rename from tests/auto/qfuture/tst_qfuture.cpp rename to tests/auto/corelib/concurrent/qfuture/tst_qfuture.cpp diff --git a/tests/auto/qfuture/versioncheck.h b/tests/auto/corelib/concurrent/qfuture/versioncheck.h similarity index 100% rename from tests/auto/qfuture/versioncheck.h rename to tests/auto/corelib/concurrent/qfuture/versioncheck.h diff --git a/tests/auto/corelib/concurrent/qfuturesynchronizer/qfuturesynchronizer.pro b/tests/auto/corelib/concurrent/qfuturesynchronizer/qfuturesynchronizer.pro new file mode 100644 index 0000000..11012cc --- /dev/null +++ b/tests/auto/corelib/concurrent/qfuturesynchronizer/qfuturesynchronizer.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +QT = core +SOURCES += tst_qfuturesynchronizer.cpp \ + +CONFIG += parallel_test diff --git a/tests/auto/corelib/concurrent/qfuturesynchronizer/tst_qfuturesynchronizer.cpp b/tests/auto/corelib/concurrent/qfuturesynchronizer/tst_qfuturesynchronizer.cpp new file mode 100644 index 0000000..5aced3f --- /dev/null +++ b/tests/auto/corelib/concurrent/qfuturesynchronizer/tst_qfuturesynchronizer.cpp @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2011 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 + +#include +#include + +class tst_QFutureSynchronizer : public QObject +{ + Q_OBJECT + + +private Q_SLOTS: + void construction(); + void addFuture(); + void cancelOnWait(); + void clearFutures(); + void futures(); + void setFuture(); + void waitForFinished(); +}; + + +void tst_QFutureSynchronizer::construction() +{ + + QFuture future; + QFutureSynchronizer synchronizer; + QFutureSynchronizer synchronizerWithFuture(future); + + QCOMPARE(synchronizer.futures().size(), 0); + QCOMPARE(synchronizerWithFuture.futures().size(), 1); +} + +void tst_QFutureSynchronizer::addFuture() +{ + QFutureSynchronizer synchronizer; + + synchronizer.addFuture(QFuture()); + QFuture future; + synchronizer.addFuture(future); + synchronizer.addFuture(future); + + QCOMPARE(synchronizer.futures().size(), 3); +} + +void tst_QFutureSynchronizer::cancelOnWait() +{ + QFutureSynchronizer synchronizer; + QVERIFY(!synchronizer.cancelOnWait()); + synchronizer.setCancelOnWait(true); + QVERIFY(synchronizer.cancelOnWait()); + synchronizer.setCancelOnWait(false); + QVERIFY(!synchronizer.cancelOnWait()); + synchronizer.setCancelOnWait(true); + QVERIFY(synchronizer.cancelOnWait()); +} + +void tst_QFutureSynchronizer::clearFutures() +{ + QFutureSynchronizer synchronizer; + synchronizer.clearFutures(); + QVERIFY(synchronizer.futures().isEmpty()); + + synchronizer.addFuture(QFuture()); + QFuture future; + synchronizer.addFuture(future); + synchronizer.addFuture(future); + synchronizer.clearFutures(); + QVERIFY(synchronizer.futures().isEmpty()); +} + +void tst_QFutureSynchronizer::futures() +{ + QFutureSynchronizer synchronizer; + + QList > futures; + for (int i=0; i<100; i++) { + QFuture future; + futures.append(future); + synchronizer.addFuture(future); + } + + QCOMPARE(futures, synchronizer.futures()); +} + +void tst_QFutureSynchronizer::setFuture() +{ + QFutureSynchronizer synchronizer; + + for (int i=0; i<100; i++) { + synchronizer.addFuture(QFuture()); + } + QCOMPARE(synchronizer.futures().size(), 100); + + QFuture future; + synchronizer.setFuture(future); + QCOMPARE(synchronizer.futures().size(), 1); + QCOMPARE(synchronizer.futures().first(), future); +} + +void tst_QFutureSynchronizer::waitForFinished() +{ + QFutureSynchronizer synchronizer; + + for (int i=0; i<100; i++) { + synchronizer.addFuture(QFuture()); + } + synchronizer.waitForFinished(); + const QList > futures = synchronizer.futures(); + + for (int i=0; i<100; i++) { + QVERIFY(futures.at(i).isFinished()); + } +} + +QTEST_MAIN(tst_QFutureSynchronizer) + +#include "tst_qfuturesynchronizer.moc" diff --git a/tests/auto/qfuturewatcher/.gitignore b/tests/auto/corelib/concurrent/qfuturewatcher/.gitignore similarity index 100% rename from tests/auto/qfuturewatcher/.gitignore rename to tests/auto/corelib/concurrent/qfuturewatcher/.gitignore diff --git a/tests/auto/qfuturewatcher/qfuturewatcher.pro b/tests/auto/corelib/concurrent/qfuturewatcher/qfuturewatcher.pro similarity index 100% rename from tests/auto/qfuturewatcher/qfuturewatcher.pro rename to tests/auto/corelib/concurrent/qfuturewatcher/qfuturewatcher.pro diff --git a/tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp b/tests/auto/corelib/concurrent/qfuturewatcher/tst_qfuturewatcher.cpp similarity index 99% rename from tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp rename to tests/auto/corelib/concurrent/qfuturewatcher/tst_qfuturewatcher.cpp index f45bd9f..d8fa223 100644 --- a/tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp +++ b/tests/auto/corelib/concurrent/qfuturewatcher/tst_qfuturewatcher.cpp @@ -47,7 +47,7 @@ #include #include #include -#include "../../shared/util.h" +#include "../../../../shared/util.h" #ifndef QT_NO_CONCURRENT_TEST #include diff --git a/tests/auto/qtconcurrentfilter/.gitignore b/tests/auto/corelib/concurrent/qtconcurrentfilter/.gitignore similarity index 100% rename from tests/auto/qtconcurrentfilter/.gitignore rename to tests/auto/corelib/concurrent/qtconcurrentfilter/.gitignore diff --git a/tests/auto/qtconcurrentfilter/qtconcurrentfilter.pro b/tests/auto/corelib/concurrent/qtconcurrentfilter/qtconcurrentfilter.pro similarity index 100% rename from tests/auto/qtconcurrentfilter/qtconcurrentfilter.pro rename to tests/auto/corelib/concurrent/qtconcurrentfilter/qtconcurrentfilter.pro diff --git a/tests/auto/qtconcurrentfilter/tst_qtconcurrentfilter.cpp b/tests/auto/corelib/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp similarity index 100% rename from tests/auto/qtconcurrentfilter/tst_qtconcurrentfilter.cpp rename to tests/auto/corelib/concurrent/qtconcurrentfilter/tst_qtconcurrentfilter.cpp diff --git a/tests/auto/qtconcurrentiteratekernel/.gitignore b/tests/auto/corelib/concurrent/qtconcurrentiteratekernel/.gitignore similarity index 100% rename from tests/auto/qtconcurrentiteratekernel/.gitignore rename to tests/auto/corelib/concurrent/qtconcurrentiteratekernel/.gitignore diff --git a/tests/auto/qtconcurrentiteratekernel/qtconcurrentiteratekernel.pro b/tests/auto/corelib/concurrent/qtconcurrentiteratekernel/qtconcurrentiteratekernel.pro similarity index 100% rename from tests/auto/qtconcurrentiteratekernel/qtconcurrentiteratekernel.pro rename to tests/auto/corelib/concurrent/qtconcurrentiteratekernel/qtconcurrentiteratekernel.pro diff --git a/tests/auto/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp b/tests/auto/corelib/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp similarity index 100% rename from tests/auto/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp rename to tests/auto/corelib/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp diff --git a/tests/auto/qtconcurrentmap/.gitignore b/tests/auto/corelib/concurrent/qtconcurrentmap/.gitignore similarity index 100% rename from tests/auto/qtconcurrentmap/.gitignore rename to tests/auto/corelib/concurrent/qtconcurrentmap/.gitignore diff --git a/tests/auto/qtconcurrentmap/functions.h b/tests/auto/corelib/concurrent/qtconcurrentmap/functions.h similarity index 100% rename from tests/auto/qtconcurrentmap/functions.h rename to tests/auto/corelib/concurrent/qtconcurrentmap/functions.h diff --git a/tests/auto/qtconcurrentmap/qtconcurrentmap.pro b/tests/auto/corelib/concurrent/qtconcurrentmap/qtconcurrentmap.pro similarity index 100% rename from tests/auto/qtconcurrentmap/qtconcurrentmap.pro rename to tests/auto/corelib/concurrent/qtconcurrentmap/qtconcurrentmap.pro diff --git a/tests/auto/qtconcurrentmap/tst_qtconcurrentmap.cpp b/tests/auto/corelib/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp similarity index 100% rename from tests/auto/qtconcurrentmap/tst_qtconcurrentmap.cpp rename to tests/auto/corelib/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp diff --git a/tests/auto/corelib/concurrent/qtconcurrentresultstore/qtconcurrentresultstore.pro b/tests/auto/corelib/concurrent/qtconcurrentresultstore/qtconcurrentresultstore.pro new file mode 100644 index 0000000..8bc20c3 --- /dev/null +++ b/tests/auto/corelib/concurrent/qtconcurrentresultstore/qtconcurrentresultstore.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +DEFINES += QT_STRICT_ITERATORS +SOURCES += tst_qtconcurrentresultstore.cpp +QT = core core-private +CONFIG += parallel_test diff --git a/tests/auto/corelib/concurrent/qtconcurrentresultstore/tst_qtconcurrentresultstore.cpp b/tests/auto/corelib/concurrent/qtconcurrentresultstore/tst_qtconcurrentresultstore.cpp new file mode 100644 index 0000000..1728be6 --- /dev/null +++ b/tests/auto/corelib/concurrent/qtconcurrentresultstore/tst_qtconcurrentresultstore.cpp @@ -0,0 +1,491 @@ +/**************************************************************************** +** +** Copyright (C) 2011 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 + +#include + +using namespace QtConcurrent; + +class tst_QtConcurrentResultStore : public QObject +{ + Q_OBJECT +public slots: + void init(); +private slots: + void construction(); + void iterators(); + void addResult(); + void addResults(); + void resultIndex(); + void resultAt(); + void contains(); + void filterMode(); + void addCanceledResult(); + void count(); +private: + int int0; + int int1; + int int2; + QVector vec0; + QVector vec1; +}; + +void tst_QtConcurrentResultStore::init() +{ + int0 = 0; + int1 = 1; + int2 = 2; + vec0 = QVector() << 2 << 3; + vec1 = QVector() << 4 << 5; +} + +void tst_QtConcurrentResultStore::construction() +{ + ResultStore store; + QCOMPARE(store.count(), 0); +} + +void tst_QtConcurrentResultStore::iterators() +{ + { + ResultStore store; + ResultIteratorBase it = store.begin(); + QVERIFY(store.begin() == store.end()); + QVERIFY(store.resultAt(0) == store.end()); + QVERIFY(store.resultAt(1) == store.end()); + } + { + ResultStoreBase storebase; + storebase.addResult(-1, &int0); // note to self: adding a pointer to the stack here is ok since + storebase.addResult(1, &int1); // ResultStoreBase does not take ownership, only ResultStore<> does. + ResultIteratorBase it = storebase.begin(); + QCOMPARE(it.resultIndex(), 0); + QVERIFY(it == storebase.begin()); + QVERIFY(it != storebase.end()); + + ++it; + QCOMPARE(it.resultIndex(), 1); + QVERIFY(it != storebase.begin()); + QVERIFY(it != storebase.end()); + + ++it; + QVERIFY(it != storebase.begin()); + QVERIFY(it == storebase.end()); + } +} + +void tst_QtConcurrentResultStore::addResult() +{ + { + // test addResult return value + ResultStore store; + store.setFilterMode(true); + + QCOMPARE(store.addResult(0, &int0), 0); + QCOMPARE(store.count(), 1); // result 0 becomes available + QCOMPARE(store.contains(0), true); + + QCOMPARE(store.addResult(2, &int0), 2); + QCOMPARE(store.count(), 1); + QCOMPARE(store.contains(2), false); + + QCOMPARE(store.addCanceledResult(1), 1); + QCOMPARE(store.count(), 2); // result 2 is renamed to 1 and becomes available + + QCOMPARE(store.contains(0), true); + QCOMPARE(store.contains(1), true); + QCOMPARE(store.contains(2), false); + + QCOMPARE(store.addResult(3, &int0), 3); + QCOMPARE(store.count(), 3); + QCOMPARE(store.contains(2), true); + + QCOMPARE(store.addResult(6, &int0), 6); + QCOMPARE(store.count(), 3); + QCOMPARE(store.addResult(7, &int0), 7); + QCOMPARE(store.count(), 3); + QCOMPARE(store.contains(3), false); + + QCOMPARE(store.addCanceledResult(4), 4); + QCOMPARE(store.addCanceledResult(5), 5); + QCOMPARE(store.count(), 5); // 6 and 7 is renamed to 3 and 4 and becomes available + + QCOMPARE(store.contains(3), true); + QCOMPARE(store.contains(4), true); + + QCOMPARE(store.addResult(8, &int0), 8); + QCOMPARE(store.contains(5), true); + QCOMPARE(store.count(), 6); + + QCOMPARE(store.contains(6), false); + QCOMPARE(store.contains(7), false); + } +} + +void tst_QtConcurrentResultStore::addResults() +{ + + ResultStoreBase store; + store.addResults(-1, &vec0, 2, 2); + store.addResults(-1, &vec1, 2, 2); + ResultIteratorBase it = store.begin(); + QCOMPARE(it.resultIndex(), 0); + QVERIFY(it == store.begin()); + QVERIFY(it != store.end()); + + ++it; + QCOMPARE(it.resultIndex(), 1); + QVERIFY(it != store.begin()); + QVERIFY(it != store.end()); + + ++it; + QCOMPARE(it.resultIndex(), 2); + + ++it; + QCOMPARE(it.resultIndex(), 3); + + ++it; + QVERIFY(it == store.end()); +} + +void tst_QtConcurrentResultStore::resultIndex() +{ + ResultStore store; + store.addResult(-1, &int0); + store.addResults(-1, &vec0); + store.addResult(-1, &int1); + + ResultIteratorBase it = store.begin(); + QCOMPARE(it.resultIndex(), 0); + QVERIFY(it == store.begin()); + QVERIFY(it != store.end()); + + ++it; + QCOMPARE(it.resultIndex(), 1); + QVERIFY(it != store.begin()); + QVERIFY(it != store.end()); + + ++it; + QCOMPARE(it.resultIndex(), 2); + QVERIFY(it != store.end()); + ++it; + QCOMPARE(it.resultIndex(), 3); + QVERIFY(it != store.end()); + ++it; + QVERIFY(it == store.end()); + + QCOMPARE(store.resultAt(0).value(), int0); + QCOMPARE(store.resultAt(1).value(), vec0[0]); + QCOMPARE(store.resultAt(2).value(), vec0[1]); + QCOMPARE(store.resultAt(3).value(), int1); +} + +void tst_QtConcurrentResultStore::resultAt() +{ + { + ResultStore store; + store.addResult(-1, &int0); + store.addResults(-1, &vec0); + store.addResult(200, &int1); + + QCOMPARE(store.resultAt(0).value(), int0); + QCOMPARE(store.resultAt(1).value(), vec0[0]); + QCOMPARE(store.resultAt(2).value(), vec0[1]); + QCOMPARE(store.resultAt(200).value(), int1); + } + { + ResultStore store; + store.addResult(1, &int1); + store.addResult(0, &int0); + store.addResult(-1, &int2); + + QCOMPARE(store.resultAt(0).value(), int0); + QCOMPARE(store.resultAt(1).value(), int1); + QCOMPARE(store.resultAt(2).value(), int2); + } +} + +void tst_QtConcurrentResultStore::contains() +{ + { + ResultStore store; + QCOMPARE(store.contains(0), false); + QCOMPARE(store.contains(1), false); + QCOMPARE(store.contains(INT_MAX), false); + store.addResult(1, &int1); + QVERIFY(store.contains(int1)); + store.addResult(0, &int0); + QVERIFY(store.contains(int0)); + store.addResult(-1, &int2); + QVERIFY(store.contains(int2)); + } + { + ResultStore store; + store.addResult(1, &int0); + store.addResult(3, &int0); + store.addResults(6, &vec0); + QCOMPARE(store.contains(0), false); + QCOMPARE(store.contains(1), true); + QCOMPARE(store.contains(2), false); + QCOMPARE(store.contains(3), true); + QCOMPARE(store.contains(4), false); + QCOMPARE(store.contains(5), false); + QCOMPARE(store.contains(6), true); + QCOMPARE(store.contains(7), true); + } + + { + ResultStore store; + store.setFilterMode(true); + store.addResult(1, &int0); + store.addResult(3, &int0); + store.addResults(6, &vec0); + QCOMPARE(store.contains(0), false); + QCOMPARE(store.contains(1), false); + QCOMPARE(store.contains(2), false); + QCOMPARE(store.contains(3), false); + QCOMPARE(store.contains(4), false); + QCOMPARE(store.contains(5), false); + QCOMPARE(store.contains(6), false); + QCOMPARE(store.contains(7), false); + + store.addCanceledResult(0); + store.addCanceledResult(2); + store.addCanceledResults(4, 2); + + QCOMPARE(store.contains(0), true); + QCOMPARE(store.contains(1), true); + QCOMPARE(store.contains(2), true); + QCOMPARE(store.contains(3), true); + QCOMPARE(store.contains(4), false); + QCOMPARE(store.contains(5), false); + QCOMPARE(store.contains(6), false); + QCOMPARE(store.contains(7), false); + } + { + ResultStore store; + store.setFilterMode(true); + store.addCanceledResult(0); + QCOMPARE(store.contains(0), false); + + store.addResult(1, &int0); + QCOMPARE(store.contains(0), true); + QCOMPARE(store.contains(1), false); + } +} + +void tst_QtConcurrentResultStore::filterMode() +{ + // Test filter mode, where "gaps" in the result array aren't allowed. + ResultStore store; + QCOMPARE(store.filterMode(), false); + store.setFilterMode(true); + QVERIFY(store.filterMode()); + + store.addResult(0, &int0); + QCOMPARE(store.contains(0), true); + + store.addResult(2, &int2); // add result at index 2 + QCOMPARE(store.contains(2), false); // but 1 is missing, so this 2 won't be reported yet. + + store.addResult(1, &int1); + QCOMPARE(store.contains(1), true); + QCOMPARE(store.contains(2), true); // 2 should be visible now. + + store.addResult(4, &int0); + store.addResult(5, &int0); + store.addResult(7, &int0); + QCOMPARE(store.contains(4), false); + QCOMPARE(store.contains(5), false); + QCOMPARE(store.contains(7), false); + + store.addResult(3, &int0); // adding 3 makes 4 and 5 visible + QCOMPARE(store.contains(4), true); + QCOMPARE(store.contains(5), true); + QCOMPARE(store.contains(7), false); + + store.addResult(6, &int0); // adding 6 makes 7 visible + + QCOMPARE(store.contains(6), true); + QCOMPARE(store.contains(7), true); + QCOMPARE(store.contains(8), false); +} + +void tst_QtConcurrentResultStore::addCanceledResult() +{ + // test canceled results + ResultStore store; + store.setFilterMode(true); + + store.addResult(0, &int0); + QCOMPARE(store.contains(0), true); + + store.addResult(2, &int0); + QCOMPARE(store.contains(2), false); + + store.addCanceledResult(1); // report no result at 1 + + QCOMPARE(store.contains(0), true); + QCOMPARE(store.contains(1), true); // 2 gets renamed to 1 + QCOMPARE(store.contains(2), false); + + store.addResult(3, &int0); + QCOMPARE(store.contains(2), true); //3 gets renamed to 2 + + store.addResult(6, &int0); + store.addResult(7, &int0); + QCOMPARE(store.contains(3), false); + + store.addCanceledResult(4); + store.addCanceledResult(5); + + QCOMPARE(store.contains(3), true); //6 gets renamed to 3 + QCOMPARE(store.contains(4), true); //7 gets renamed to 4 + + store.addResult(8, &int0); + QCOMPARE(store.contains(5), true); //8 gets renamed to 4 + + QCOMPARE(store.contains(6), false); + QCOMPARE(store.contains(7), false); +} + +void tst_QtConcurrentResultStore::count() +{ + { + // test resultCount in non-filtered mode. It should always be possible + // to iterate through the results 0 to resultCount. + ResultStore store; + store.addResult(0, &int0); + + QCOMPARE(store.count(), 1); + + store.addResult(2, &int0); + + QCOMPARE(store.count(), 1); + + store.addResult(1, &int0); + QCOMPARE(store.count(), 3); + } + + { + ResultStore store; + store.addResult(2, &int0); + QCOMPARE(store.count(), 0); + + store.addResult(1, &int0); + QCOMPARE(store.count(), 0); + + store.addResult(0, &int0); + QCOMPARE(store.count(), 3); + } + + { + ResultStore store; + store.addResults(2, &vec1); + QCOMPARE(store.count(), 0); + + store.addResult(1, &int0); + QCOMPARE(store.count(), 0); + + store.addResult(0, &int0); + QCOMPARE(store.count(), 4); + } + + { + ResultStore store; + store.addResults(2, &vec1); + QCOMPARE(store.count(), 0); + + store.addResults(0, &vec0); + QCOMPARE(store.count(), 4); + } + { + ResultStore store; + store.addResults(3, &vec1); + QCOMPARE(store.count(), 0); + + store.addResults(0, &vec0); + QCOMPARE(store.count(), 2); + + store.addResult(2, &int0); + QCOMPARE(store.count(), 5); + } + + { + ResultStore store; + store.setFilterMode(true); + store.addResults(3, &vec1); + QCOMPARE(store.count(), 0); + + store.addResults(0, &vec0); + QCOMPARE(store.count(), 2); + + store.addCanceledResult(2); + QCOMPARE(store.count(), 4); + } + + { + ResultStore store; + store.setFilterMode(true); + store.addResults(3, &vec1); + QCOMPARE(store.count(), 0); + + store.addCanceledResults(0, 3); + QCOMPARE(store.count(), 2); + } + + { + ResultStore store; + store.setFilterMode(true); + store.addResults(3, &vec1); + QCOMPARE(store.count(), 0); + + store.addCanceledResults(0, 3); + QCOMPARE(store.count(), 2); // results at 3 and 4 become available at index 0, 1 + + store.addResult(5, &int0); + QCOMPARE(store.count(), 3);// result 5 becomes available at index 2 + } +} + +QTEST_MAIN(tst_QtConcurrentResultStore) +#include "tst_qtconcurrentresultstore.moc" diff --git a/tests/auto/qtconcurrentrun/.gitignore b/tests/auto/corelib/concurrent/qtconcurrentrun/.gitignore similarity index 100% rename from tests/auto/qtconcurrentrun/.gitignore rename to tests/auto/corelib/concurrent/qtconcurrentrun/.gitignore diff --git a/tests/auto/qtconcurrentrun/qtconcurrentrun.pro b/tests/auto/corelib/concurrent/qtconcurrentrun/qtconcurrentrun.pro similarity index 100% rename from tests/auto/qtconcurrentrun/qtconcurrentrun.pro rename to tests/auto/corelib/concurrent/qtconcurrentrun/qtconcurrentrun.pro diff --git a/tests/auto/qtconcurrentrun/tst_qtconcurrentrun.cpp b/tests/auto/corelib/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp similarity index 100% rename from tests/auto/qtconcurrentrun/tst_qtconcurrentrun.cpp rename to tests/auto/corelib/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp diff --git a/tests/auto/qtconcurrentthreadengine/.gitignore b/tests/auto/corelib/concurrent/qtconcurrentthreadengine/.gitignore similarity index 100% rename from tests/auto/qtconcurrentthreadengine/.gitignore rename to tests/auto/corelib/concurrent/qtconcurrentthreadengine/.gitignore diff --git a/tests/auto/qtconcurrentthreadengine/qtconcurrentthreadengine.pro b/tests/auto/corelib/concurrent/qtconcurrentthreadengine/qtconcurrentthreadengine.pro similarity index 100% rename from tests/auto/qtconcurrentthreadengine/qtconcurrentthreadengine.pro rename to tests/auto/corelib/concurrent/qtconcurrentthreadengine/qtconcurrentthreadengine.pro diff --git a/tests/auto/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp b/tests/auto/corelib/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp similarity index 100% rename from tests/auto/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp rename to tests/auto/corelib/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp diff --git a/tests/auto/qthreadpool/.gitignore b/tests/auto/corelib/concurrent/qthreadpool/.gitignore similarity index 100% rename from tests/auto/qthreadpool/.gitignore rename to tests/auto/corelib/concurrent/qthreadpool/.gitignore diff --git a/tests/auto/qthreadpool/qthreadpool.pro b/tests/auto/corelib/concurrent/qthreadpool/qthreadpool.pro similarity index 100% rename from tests/auto/qthreadpool/qthreadpool.pro rename to tests/auto/corelib/concurrent/qthreadpool/qthreadpool.pro diff --git a/tests/auto/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/concurrent/qthreadpool/tst_qthreadpool.cpp similarity index 100% rename from tests/auto/qthreadpool/tst_qthreadpool.cpp rename to tests/auto/corelib/concurrent/qthreadpool/tst_qthreadpool.cpp diff --git a/tests/auto/corelib/corelib.pro b/tests/auto/corelib/corelib.pro index 4c84fbb..122c834 100644 --- a/tests/auto/corelib/corelib.pro +++ b/tests/auto/corelib/corelib.pro @@ -1,4 +1,5 @@ TEMPLATE=subdirs SUBDIRS=\ animation \ - codecs + codecs \ + concurrent -- 2.7.4