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>
This commit is contained in:
Edward Welbourne 2015-09-24 11:03:38 +02:00
parent 0ebebeb983
commit b86efb1ab9
2 changed files with 17 additions and 3 deletions

View File

@ -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());

View File

@ -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"