diff options
author | Edward Welbourne <edward.welbourne@theqtcompany.com> | 2015-09-24 11:03:38 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@theqtcompany.com> | 2015-09-30 08:25:34 +0000 |
commit | b86efb1ab9daa76965cda5bdebb225c9e3762e8e (patch) | |
tree | 78f04de08960cf5e1d79924411738e78799fcd87 | |
parent | 0ebebeb983d381010fae710aee60d8550d9be4f3 (diff) |
Initialize QFutureWatcherBasePrivate::finished and test
It's accessed by QFutureWatcherBase::isFinished(), potentially before
anything has set it. It gets to be initially true until setFuture()
has given it us unfinished future and set it false.
Add a regression test for matching state in future and watcher.
Task-number: QTBUG-12358
Change-Id: Iae7bdaa434ab80f518afe4d7d55df99c391991a4
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
-rw-r--r-- | src/corelib/thread/qfuturewatcher.cpp | 7 | ||||
-rw-r--r-- | tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp | 13 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/corelib/thread/qfuturewatcher.cpp b/src/corelib/thread/qfuturewatcher.cpp index 3056216f6e..3863a47673 100644 --- a/src/corelib/thread/qfuturewatcher.cpp +++ b/src/corelib/thread/qfuturewatcher.cpp @@ -248,7 +248,7 @@ bool QFutureWatcherBase::isStarted() const /*! \fn bool QFutureWatcher::isFinished() const Returns \c true if the asynchronous computation represented by the future() - has finished; otherwise returns \c false. + has finished, or if no future has been set; otherwise returns \c false. */ bool QFutureWatcherBase::isFinished() const { @@ -379,7 +379,8 @@ void QFutureWatcherBase::disconnectNotify(const QMetaMethod &signal) */ QFutureWatcherBasePrivate::QFutureWatcherBasePrivate() : maximumPendingResultsReady(QThread::idealThreadCount() * 2), - resultAtConnected(0) + resultAtConnected(0), + finished(true) /* the initial m_future is a canceledResult(), with Finished set */ { } /*! @@ -400,7 +401,7 @@ void QFutureWatcherBase::disconnectOutputInterface(bool pendingAssignment) d->pendingResultsReady.store(0); qDeleteAll(d->pendingCallOutEvents); d->pendingCallOutEvents.clear(); - d->finished = false; + d->finished = false; /* May soon be amended, during connectOutputInterface() */ } futureInterface().d->disconnectOutputInterface(d_func()); diff --git a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp index 60a4d749c9..5ec32b1d02 100644 --- a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp +++ b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp @@ -68,6 +68,7 @@ private slots: void incrementalFilterResults(); void qfutureSynchronizer(); void warnRace(); + void matchFlags(); }; void sleeper() @@ -930,5 +931,17 @@ void tst_QFutureWatcher::warnRace() future.waitForFinished(); } +void tst_QFutureWatcher::matchFlags() +{ + /* Regression test: expect a default watcher to be in the same state as a + * default future. */ + QFutureWatcher<int> watcher; + QFuture<int> future; + QCOMPARE(watcher.isStarted(), future.isStarted()); + QCOMPARE(watcher.isCanceled(), future.isCanceled()); + QCOMPARE(watcher.isFinished(), future.isFinished()); +} + + QTEST_MAIN(tst_QFutureWatcher) #include "tst_qfuturewatcher.moc" |