summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/concurrent
diff options
context:
space:
mode:
authorJason McDonald <jason.mcdonald@nokia.com>2011-12-22 17:16:48 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-28 04:48:11 +0100
commitea415e20607016651f3cef02dff109235d84eb4d (patch)
tree8c954afe7d078b0ca742a1f2249ccc5a9ddf1b82 /tests/auto/corelib/concurrent
parent1e7296f3f2e7346f52e8f70d4e531405a248aa8b (diff)
Cleanup corelib autotests.
When using QSignalSpy, always verify that the signal spy is valid. This will cause the test to give a meaningful failure when spying on a non-existant signal. Without this change, tests that spy on a signal to ensure that it is not emitted (i.e. by comparing the spy count to zero) could pass erroneously if something went wrong when creating the signal spy, as an invalid QSignalSpy will always return a count of zero. Change-Id: I41f4a63d9f0de9190a86de237662dc96be802446 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
Diffstat (limited to 'tests/auto/corelib/concurrent')
-rw-r--r--tests/auto/corelib/concurrent/qfuturewatcher/tst_qfuturewatcher.cpp36
1 files changed, 30 insertions, 6 deletions
diff --git a/tests/auto/corelib/concurrent/qfuturewatcher/tst_qfuturewatcher.cpp b/tests/auto/corelib/concurrent/qfuturewatcher/tst_qfuturewatcher.cpp
index c7e35e2b75..ca0816eca1 100644
--- a/tests/auto/corelib/concurrent/qfuturewatcher/tst_qfuturewatcher.cpp
+++ b/tests/auto/corelib/concurrent/qfuturewatcher/tst_qfuturewatcher.cpp
@@ -90,17 +90,20 @@ void tst_QFutureWatcher::startFinish()
{
QFutureWatcher<void> futureWatcher;
- QSignalSpy started(&futureWatcher, SIGNAL(started()));
- QSignalSpy finished(&futureWatcher, SIGNAL(finished()));
+ QSignalSpy startedSpy(&futureWatcher, SIGNAL(started()));
+ QSignalSpy finishedSpy(&futureWatcher, SIGNAL(finished()));
+
+ QVERIFY(startedSpy.isValid());
+ QVERIFY(finishedSpy.isValid());
futureWatcher.setFuture(QtConcurrent::run(sleeper));
QTest::qWait(10); // spin the event loop to deliver queued signals.
- QCOMPARE(started.count(), 1);
- QCOMPARE(finished.count(), 0);
+ QCOMPARE(startedSpy.count(), 1);
+ QCOMPARE(finishedSpy.count(), 0);
futureWatcher.future().waitForFinished();
QTest::qWait(10);
- QCOMPARE(started.count(), 1);
- QCOMPARE(finished.count(), 1);
+ QCOMPARE(startedSpy.count(), 1);
+ QCOMPARE(finishedSpy.count(), 1);
}
void mapSleeper(int &)
@@ -323,6 +326,7 @@ void tst_QFutureWatcher::futureSignals()
f.setFuture(a.future());
QSignalSpy progressSpy(&f, SIGNAL(progressValueChanged(int)));
+ QVERIFY(progressSpy.isValid());
const int progress = 1;
a.setProgressValue(progress);
QTest::qWait(10);
@@ -333,6 +337,9 @@ void tst_QFutureWatcher::futureSignals()
QSignalSpy finishedSpy(&f, SIGNAL(finished()));
QSignalSpy resultReadySpy(&f, SIGNAL(resultReadyAt(int)));
+ QVERIFY(finishedSpy.isValid());
+ QVERIFY(resultReadySpy.isValid());
+
const int result = 10;
a.reportResult(&result);
QTest::qWait(10);
@@ -375,6 +382,11 @@ void tst_QFutureWatcher::watchFinishedFuture()
QSignalSpy resultReadySpy(&watcher, SIGNAL(resultReadyAt(int)));
QSignalSpy canceledSpy(&watcher, SIGNAL(canceled()));
+ QVERIFY(startedSpy.isValid());
+ QVERIFY(finishedSpy.isValid());
+ QVERIFY(resultReadySpy.isValid());
+ QVERIFY(canceledSpy.isValid());
+
watcher.setFuture(f);
QTest::qWait(10);
@@ -404,6 +416,11 @@ void tst_QFutureWatcher::watchCanceledFuture()
QSignalSpy resultReadySpy(&watcher, SIGNAL(resultReadyAt(int)));
QSignalSpy canceledSpy(&watcher, SIGNAL(canceled()));
+ QVERIFY(startedSpy.isValid());
+ QVERIFY(finishedSpy.isValid());
+ QVERIFY(resultReadySpy.isValid());
+ QVERIFY(canceledSpy.isValid());
+
watcher.setFuture(f);
QTest::qWait(10);
@@ -428,6 +445,9 @@ void tst_QFutureWatcher::disconnectRunningFuture()
QSignalSpy finishedSpy(watcher, SIGNAL(finished()));
QSignalSpy resultReadySpy(watcher, SIGNAL(resultReadyAt(int)));
+ QVERIFY(finishedSpy.isValid());
+ QVERIFY(resultReadySpy.isValid());
+
const int result = 10;
a.reportResult(&result);
QTest::qWait(10);
@@ -618,6 +638,7 @@ void tst_QFutureWatcher::changeFuture()
SignalSlotObject object;
connect(&watcher, SIGNAL(resultReadyAt(int)), &object, SLOT(resultReadyAt(int)));
QSignalSpy resultReadySpy(&watcher, SIGNAL(resultReadyAt(int)));
+ QVERIFY(resultReadySpy.isValid());
watcher.setFuture(a); // Watch 'a' which will genere a resultReady event.
watcher.setFuture(b); // But oh no! we're switching to another future
@@ -649,6 +670,7 @@ void tst_QFutureWatcher::cancelEvents()
SignalSlotObject object;
connect(&watcher, SIGNAL(resultReadyAt(int)), &object, SLOT(resultReadyAt(int)));
QSignalSpy resultReadySpy(&watcher, SIGNAL(resultReadyAt(int)));
+ QVERIFY(resultReadySpy.isValid());
watcher.setFuture(a);
watcher.cancel();
@@ -676,6 +698,7 @@ void tst_QFutureWatcher::pauseEvents()
SignalSlotObject object;
connect(&watcher, SIGNAL(resultReadyAt(int)), &object, SLOT(resultReadyAt(int)));
QSignalSpy resultReadySpy(&watcher, SIGNAL(resultReadyAt(int)));
+ QVERIFY(resultReadySpy.isValid());
watcher.setFuture(a);
watcher.pause();
@@ -701,6 +724,7 @@ void tst_QFutureWatcher::pauseEvents()
SignalSlotObject object;
connect(&watcher, SIGNAL(resultReadyAt(int)), &object, SLOT(resultReadyAt(int)));
QSignalSpy resultReadySpy(&watcher, SIGNAL(resultReadyAt(int)));
+ QVERIFY(resultReadySpy.isValid());
watcher.setFuture(a);
a.pause();