Fix pauseEvents() test to test what should be true, not what is.

If the future is finished when a watcher starts watching it, it is
perfectly reasonable for the watcher to get the finished message
promptly.  If you pause the watcher before any message loops get to
run, the message presently won't get through until the watcher is
resumed, but there is no reason to guarantee that; indeed, one could
consider it somewhat perverse behavior.

So move the reportFinished() calls to after the pause()s.
Also eliminate a used-once local variable and use QTRY_VERIFY() in one
place where qWait() was used before.

Change-Id: I4bc6091fd7437a4d341be511b7a140f3d72d850e
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
bb10
Edward Welbourne 2015-10-27 12:02:54 +01:00
parent ada4b4aaa5
commit ab1a5f1003
1 changed files with 8 additions and 10 deletions

View File

@ -677,11 +677,6 @@ void tst_QFutureWatcher::pauseEvents()
QFutureInterface<int> iface;
iface.reportStarted();
QFuture<int> a = iface.future();
int value = 0;
iface.reportFinished(&value);
QFutureWatcher<int> watcher;
SignalSlotObject object;
@ -689,14 +684,17 @@ void tst_QFutureWatcher::pauseEvents()
QSignalSpy resultReadySpy(&watcher, &QFutureWatcher<int>::resultReadyAt);
QVERIFY(resultReadySpy.isValid());
watcher.setFuture(a);
watcher.setFuture(iface.future());
watcher.pause();
int value = 0;
iface.reportFinished(&value);
QTest::qWait(10);
QCOMPARE(resultReadySpy.count(), 0);
watcher.resume();
QTest::qWait(10);
QTRY_VERIFY2(!resultReadySpy.isEmpty(), "Result didn't arrive");
QCOMPARE(resultReadySpy.count(), 1);
}
{
@ -705,9 +703,6 @@ void tst_QFutureWatcher::pauseEvents()
QFuture<int> a = iface.future();
int value = 0;
iface.reportFinished(&value);
QFutureWatcher<int> watcher;
SignalSlotObject object;
@ -718,6 +713,9 @@ void tst_QFutureWatcher::pauseEvents()
watcher.setFuture(a);
a.pause();
int value = 0;
iface.reportFinished(&value);
QFuture<int> b;
watcher.setFuture(b); // If we watch b instead, resuming a
a.resume(); // should give us no results.