diff options
Diffstat (limited to 'tests/auto/concurrent')
-rw-r--r-- | tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp index c50e3839b5..b6bc5b085b 100644 --- a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp +++ b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp @@ -43,6 +43,7 @@ #include <qdebug.h> #include <QThread> +#include <QMutex> #include <QtTest/QtTest> @@ -75,6 +76,7 @@ private slots: void stlContainers(); void qFutureAssignmentLeak(); void stressTest(); + void persistentResultTest(); public slots: void throttling(); }; @@ -2395,5 +2397,46 @@ void tst_QtConcurrentMap::stressTest() } } +struct LockedCounter +{ + LockedCounter(QMutex *mutex, QAtomicInt *ai) + : mtx(mutex), + ref(ai) {} + + typedef int result_type; + int operator()(int x) + { + QMutexLocker locker(mtx); + ref->ref(); + return ++x; + } + + QMutex *mtx; + QAtomicInt *ref; +}; + +// The Thread engine holds the last reference +// to the QFuture, so this should not leak +// or fail. +void tst_QtConcurrentMap::persistentResultTest() +{ + QFuture<void> voidFuture; + QMutex mtx; + QAtomicInt ref; + LockedCounter lc(&mtx, &ref); + QList<int> list; + { + list << 1 << 2 << 3; + mtx.lock(); + QFuture<int> future = QtConcurrent::mapped(list + ,lc); + voidFuture = future; + } + QCOMPARE(ref.loadAcquire(), 0); + mtx.unlock(); // Unblock + voidFuture.waitForFinished(); + QCOMPARE(ref.loadAcquire(), 3); +} + QTEST_MAIN(tst_QtConcurrentMap) #include "tst_qtconcurrentmap.moc" |