diff options
author | Olivier Goffart <olivier.goffart@nokia.com> | 2010-08-23 14:49:06 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2010-08-23 15:14:04 (GMT) |
commit | b7fd2930986a9be5dd6115bfc4a5c5c517344371 (patch) | |
tree | 48d4c43c0c2ea67fe48ca7370a520837ed3b1ddd /tests | |
parent | dae23694cb89b853785a5772cc7e0477f65ac5bf (diff) | |
download | Qt-b7fd2930986a9be5dd6115bfc4a5c5c517344371.zip Qt-b7fd2930986a9be5dd6115bfc4a5c5c517344371.tar.gz Qt-b7fd2930986a9be5dd6115bfc4a5c5c517344371.tar.bz2 |
QFutureWatcher: display a warning when connecting after calling setFuture()
Reviewed-by: brad
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp b/tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp index c53c67a..8b52761 100644 --- a/tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp +++ b/tests/auto/qfuturewatcher/tst_qfuturewatcher.cpp @@ -81,6 +81,7 @@ private slots: void incrementalMapResults(); void incrementalFilterResults(); void qfutureSynchornizer(); + void warnRace(); }; QTEST_MAIN(tst_QFutureWatcher) @@ -466,12 +467,12 @@ void tst_QFutureWatcher::toMuchProgress() ProgressObject o; QFutureWatcher<void> f; - f.setFuture((new ProgressEmitterTask())->start()); QObject::connect(&f, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); #ifdef PRINT QObject::connect(&f, SIGNAL(progressValueChanged(int)), &o, SLOT(printProgress(int))); #endif QObject::connect(&f, SIGNAL(progressValueChanged(int)), &o, SLOT(registerProgress(int))); + f.setFuture((new ProgressEmitterTask())->start()); QTestEventLoop::instance().enterLoop(5); QVERIFY(!QTestEventLoop::instance().timeout()); @@ -886,6 +887,27 @@ void tst_QFutureWatcher::qfutureSynchornizer() QVERIFY(t.elapsed() < taskCount * 10); } +class DummyObject : public QObject { + Q_OBJECT +public slots: + void dummySlot() {} +}; + +void tst_QFutureWatcher::warnRace() +{ +#ifndef QT_NO_DEBUG + QTest::ignoreMessage(QtWarningMsg, "QFutureWatcher::connect: connecting after calling setFuture() is likely to produce race"); +#endif + QFutureWatcher<void> watcher; + DummyObject object; + + QFuture<void> future = QtConcurrent::run(sleeper); + watcher.setFuture(future); + connect(&watcher, SIGNAL(finished()), &object, SLOT(dummySlot())); + future.waitForFinished(); +} + + #include "tst_qfuturewatcher.moc" #else |