summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2012-01-10 10:13:55 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-10 19:54:03 +0100
commitdc5ea809634560e836d2847f42f66beb43db7924 (patch)
tree5a80b2e483451e19da23af36f706c95bc102416c /tests/auto
parent00d4b151123b5df415db9cd49d4683ac485cf1e7 (diff)
Tests: Remove duplicate QTRY_VERIFY/QTRY_COMPARE macros in bearer.
Introduce QTRY_VERIFY_WITH_TIMEOUT and QTRY_COMPARE_WITH_TIMEOUT to be able to specify a timeout value. Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com> Change-Id: Iaeaa4938eb14f2c431537055f626510cba183ce3 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/network/bearer/qbearertestcommon.h18
-rw-r--r--tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp4
-rw-r--r--tests/auto/network/bearer/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp12
-rw-r--r--tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp60
4 files changed, 42 insertions, 52 deletions
diff --git a/tests/auto/network/bearer/qbearertestcommon.h b/tests/auto/network/bearer/qbearertestcommon.h
index 4b73b51d15..6279dbb1ef 100644
--- a/tests/auto/network/bearer/qbearertestcommon.h
+++ b/tests/auto/network/bearer/qbearertestcommon.h
@@ -42,6 +42,10 @@
#ifndef QBEARERTESTCOMMON_H
#define QBEARERTESTCOMMON_H
+#include <QtTest/qtestcase.h>
+
+enum { TestTimeOut = 90000 };
+
// Wait for __expr to happen, while still allowing events to be processed.
#define QTRY_NOOP(__expr) \
do { \
@@ -55,18 +59,4 @@
} \
} while(0)
-// Will try to wait for the condition while allowing event processing
-#define QTRY_VERIFY(__expr) \
- do { \
- const int __step = 50; \
- const int __timeout = 90000; \
- if (!(__expr)) { \
- QTest::qWait(0); \
- } \
- for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \
- QTest::qWait(__step); \
- } \
- QVERIFY(__expr); \
- } while(0)
-
#endif
diff --git a/tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp b/tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp
index 6efcfe3b7a..f4dd6191b2 100644
--- a/tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp
+++ b/tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp
@@ -121,7 +121,7 @@ void tst_QNetworkConfiguration::comparison()
QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
manager.updateConfigurations(); //initiate scans
- QTRY_VERIFY(spy.count() == 1); //wait for scan to complete
+ QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete
QList<QNetworkConfiguration> configs = manager.allConfigurations(QNetworkConfiguration::Discovered);
QVERIFY(configs.count());
@@ -168,7 +168,7 @@ void tst_QNetworkConfiguration::isRoamingAvailable()
//force update to get maximum list
QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
manager.updateConfigurations(); //initiate scans
- QTRY_VERIFY(spy.count() == 1); //wait for scan to complete
+ QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete
foreach(QNetworkConfiguration c, configs)
{
diff --git a/tests/auto/network/bearer/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp b/tests/auto/network/bearer/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp
index 77e16161e6..7366e0adc1 100644
--- a/tests/auto/network/bearer/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp
+++ b/tests/auto/network/bearer/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp
@@ -76,7 +76,7 @@ void tst_QNetworkConfigurationManager::allConfigurations()
QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
manager.updateConfigurations(); //initiate scans
- QTRY_VERIFY(spy.count() == 1); //wait for scan to complete
+ QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete
QList<QNetworkConfiguration> configs = manager.allConfigurations();
@@ -153,7 +153,7 @@ void tst_QNetworkConfigurationManager::defaultConfiguration()
QNetworkConfigurationManager manager;
QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
manager.updateConfigurations(); //initiate scans
- QTRY_VERIFY(spy.count() == 1); //wait for scan to complete
+ QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete
QList<QNetworkConfiguration> configs = manager.allConfigurations();
QNetworkConfiguration defaultConfig = manager.defaultConfiguration();
@@ -183,7 +183,7 @@ void tst_QNetworkConfigurationManager::configurationFromIdentifier()
//force an update to get maximum number of configs
QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
manager.updateConfigurations(); //initiate scans
- QTRY_VERIFY(spy.count() == 1); //wait for scan to complete
+ QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete
QList<QNetworkConfiguration> configs = manager.allConfigurations();
@@ -211,7 +211,7 @@ protected:
preScanConfigs = manager.allConfigurations();
QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
manager.updateConfigurations(); //initiate scans
- QTRY_VERIFY(spy.count() == 1); //wait for scan to complete
+ QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete
configs = manager.allConfigurations();
}
public:
@@ -228,7 +228,7 @@ void tst_QNetworkConfigurationManager::usedInThread()
QNCMTestThread thread;
connect(&thread, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
thread.start();
- QTestEventLoop::instance().enterLoop(100); //QTRY_VERIFY could take ~90 seconds to time out in the thread
+ QTestEventLoop::instance().enterLoop(100); //QTRY_VERIFY_WITH_TIMEOUT could take ~90 seconds to time out in the thread
QVERIFY(!QTestEventLoop::instance().timeout());
qDebug() << "prescan:" << thread.preScanConfigs.count();
qDebug() << "postscan:" << thread.configs.count();
@@ -237,7 +237,7 @@ void tst_QNetworkConfigurationManager::usedInThread()
QList<QNetworkConfiguration> preScanConfigs = manager.allConfigurations();
QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
manager.updateConfigurations(); //initiate scans
- QTRY_VERIFY(spy.count() == 1); //wait for scan to complete
+ QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete
QList<QNetworkConfiguration> configs = manager.allConfigurations();
QCOMPARE(thread.configs, configs);
//Don't compare pre scan configs, because these may be cached and therefore give different results
diff --git a/tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp b/tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp
index 76fbac3368..ceedd17064 100644
--- a/tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp
+++ b/tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp
@@ -110,7 +110,7 @@ void tst_QNetworkSession::initTestCase()
QSignalSpy spy(&manager, SIGNAL(updateCompleted()));
manager.updateConfigurations();
- QTRY_VERIFY(spy.count() == 1);
+ QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut);
}
void tst_QNetworkSession::cleanupTestCase()
@@ -172,7 +172,7 @@ void tst_QNetworkSession::sessionClosing()
session.close();
// Sooner or later session must end in Disconnected state,
// no matter what the phase was.
- QTRY_VERIFY(session.state() == QNetworkSession::Disconnected);
+ QTRY_VERIFY_WITH_TIMEOUT(session.state() == QNetworkSession::Disconnected, TestTimeOut);
QTest::qWait(200); // Give platform a breathe, otherwise we'll be catching other errors
}
}
@@ -420,7 +420,7 @@ void tst_QNetworkSession::userChoiceSession()
QVERIFY(errorSpy.isEmpty());
if (expectStateChange)
- QTRY_VERIFY(!stateChangedSpy.isEmpty());
+ QTRY_VERIFY_WITH_TIMEOUT(!stateChangedSpy.isEmpty(), TestTimeOut);
QVERIFY(session.state() == QNetworkSession::Connected);
#ifndef QT_NO_NETWORKINTERFACE
@@ -524,7 +524,7 @@ void tst_QNetworkSession::sessionOpenCloseStop()
// Wait until the configuration is uptodate as well, it may be signaled 'connected'
// bit later than the session
- QTRY_VERIFY(configuration.state() == QNetworkConfiguration::Active);
+ QTRY_VERIFY_WITH_TIMEOUT(configuration.state() == QNetworkConfiguration::Active, TestTimeOut);
if (session.isOpen())
QVERIFY(!sessionOpenedSpy.isEmpty() || !errorSpy.isEmpty());
@@ -558,7 +558,7 @@ void tst_QNetworkSession::sessionOpenCloseStop()
QVERIFY(errorSpy.isEmpty());
if (expectStateChange) {
- QTRY_VERIFY(stateChangedSpy.count() >= 2);
+ QTRY_VERIFY_WITH_TIMEOUT(stateChangedSpy.count() >= 2, TestTimeOut);
QNetworkSession::State state =
qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(0).at(0));
@@ -598,7 +598,7 @@ void tst_QNetworkSession::sessionOpenCloseStop()
session2.open();
- QTRY_VERIFY(!sessionOpenedSpy2.isEmpty() || !errorSpy2.isEmpty());
+ QTRY_VERIFY_WITH_TIMEOUT(!sessionOpenedSpy2.isEmpty() || !errorSpy2.isEmpty(), TestTimeOut);
if (errorSpy2.isEmpty()) {
QVERIFY(session2.isOpen());
@@ -625,13 +625,13 @@ void tst_QNetworkSession::sessionOpenCloseStop()
// QNetworkSession::stop() must result either closed() signal
// or error() signal
- QTRY_VERIFY(!sessionClosedSpy2.isEmpty() || !errorSpy2.isEmpty());
+ QTRY_VERIFY_WITH_TIMEOUT(!sessionClosedSpy2.isEmpty() || !errorSpy2.isEmpty(), TestTimeOut);
QVERIFY(!session2.isOpen());
if (!errorSpy2.isEmpty()) {
// QNetworkSession::stop() resulted error() signal for session2
// => also session should emit error() signal
- QTRY_VERIFY(!errorSpy.isEmpty());
+ QTRY_VERIFY_WITH_TIMEOUT(!errorSpy.isEmpty(), TestTimeOut);
// check for SessionAbortedError
QNetworkSession::SessionError error =
@@ -656,7 +656,7 @@ void tst_QNetworkSession::sessionOpenCloseStop()
QTRY_NOOP(session2.state() == QNetworkSession::Disconnected);
if (expectStateChange)
- QTRY_VERIFY(stateChangedSpy2.count() >= 1 || !errorSpy2.isEmpty());
+ QTRY_VERIFY_WITH_TIMEOUT(stateChangedSpy2.count() >= 1 || !errorSpy2.isEmpty(), TestTimeOut);
if (!errorSpy2.isEmpty()) {
QVERIFY(session2.state() == previousState);
@@ -708,11 +708,11 @@ void tst_QNetworkSession::sessionOpenCloseStop()
QFAIL("Unexpected amount of state changes when roaming.");
}
- QTRY_VERIFY(session.state() == QNetworkSession::Roaming ||
+ QTRY_VERIFY_WITH_TIMEOUT(session.state() == QNetworkSession::Roaming ||
session.state() == QNetworkSession::Connected ||
- session.state() == QNetworkSession::Disconnected);
+ session.state() == QNetworkSession::Disconnected, TestTimeOut);
- QTRY_VERIFY(stateChangedSpy.count() > 0);
+ QTRY_VERIFY_WITH_TIMEOUT(stateChangedSpy.count() > 0, TestTimeOut);
state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(stateChangedSpy.count() - 1).at(0));
for (int i = 0; i < stateChangedSpy.count(); i++) {
@@ -723,19 +723,19 @@ void tst_QNetworkSession::sessionOpenCloseStop()
}
if (state == QNetworkSession::Roaming) {
- QTRY_VERIFY(session.state() == QNetworkSession::Connected);
- QTRY_VERIFY(session2.state() == QNetworkSession::Connected);
+ QTRY_VERIFY_WITH_TIMEOUT(session.state() == QNetworkSession::Connected, TestTimeOut);
+ QTRY_VERIFY_WITH_TIMEOUT(session2.state() == QNetworkSession::Connected, TestTimeOut);
roamedSuccessfully = true;
} else if (state == QNetworkSession::Closing) {
- QTRY_VERIFY(session2.state() == QNetworkSession::Disconnected);
- QTRY_VERIFY(session.state() == QNetworkSession::Connected ||
- session.state() == QNetworkSession::Disconnected);
+ QTRY_VERIFY_WITH_TIMEOUT(session2.state() == QNetworkSession::Disconnected, TestTimeOut);
+ QTRY_VERIFY_WITH_TIMEOUT(session.state() == QNetworkSession::Connected ||
+ session.state() == QNetworkSession::Disconnected, TestTimeOut );
roamedSuccessfully = false;
} else if (state == QNetworkSession::Disconnected) {
- QTRY_VERIFY(!errorSpy.isEmpty());
- QTRY_VERIFY(session2.state() == QNetworkSession::Disconnected);
+ QTRY_VERIFY_WITH_TIMEOUT(!errorSpy.isEmpty(), TestTimeOut);
+ QTRY_VERIFY_WITH_TIMEOUT(session2.state() == QNetworkSession::Disconnected, TestTimeOut);
} else if (state == QNetworkSession::Connected) {
- QTRY_VERIFY(errorSpy.isEmpty());
+ QTRY_VERIFY_WITH_TIMEOUT(errorSpy.isEmpty(),TestTimeOut);
if (stateChangedSpy.count() > 1) {
state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(stateChangedSpy.count() - 2).at(0));
@@ -757,7 +757,7 @@ void tst_QNetworkSession::sessionOpenCloseStop()
if (session.isOpen())
QVERIFY(!sessionOpenedSpy3.isEmpty() || !errorSpy3.isEmpty());
session.stop();
- QTRY_VERIFY(session.state() == QNetworkSession::Disconnected);
+ QTRY_VERIFY_WITH_TIMEOUT(session.state() == QNetworkSession::Disconnected, TestTimeOut);
}
if (!roamedSuccessfully)
QVERIFY(!errorSpy.isEmpty());
@@ -786,8 +786,8 @@ void tst_QNetworkSession::sessionOpenCloseStop()
}
}
- QTRY_VERIFY(!sessionClosedSpy.isEmpty());
- QTRY_VERIFY(session.state() == QNetworkSession::Disconnected);
+ QTRY_VERIFY_WITH_TIMEOUT(!sessionClosedSpy.isEmpty(), TestTimeOut);
+ QTRY_VERIFY_WITH_TIMEOUT(session.state() == QNetworkSession::Disconnected, TestTimeOut);
}
QVERIFY(errorSpy2.isEmpty());
@@ -808,7 +808,7 @@ void tst_QNetworkSession::sessionOpenCloseStop()
int stateChangedCountBeforeClose = stateChangedSpy2.count();
session2.close();
- QTRY_VERIFY(!sessionClosedSpy2.isEmpty());
+ QTRY_VERIFY_WITH_TIMEOUT(!sessionClosedSpy2.isEmpty(), TestTimeOut);
QVERIFY(stateChangedSpy2.count() == stateChangedCountBeforeClose);
QVERIFY(sessionClosedSpy.isEmpty());
@@ -833,12 +833,12 @@ void tst_QNetworkSession::sessionOpenCloseStop()
session.close();
- QTRY_VERIFY(!sessionClosedSpy.isEmpty() || !errorSpy.isEmpty());
+ QTRY_VERIFY_WITH_TIMEOUT(!sessionClosedSpy.isEmpty() || !errorSpy.isEmpty(), TestTimeOut);
QVERIFY(!session.isOpen());
if (expectStateChange)
- QTRY_VERIFY(!stateChangedSpy.isEmpty() || !errorSpy.isEmpty());
+ QTRY_VERIFY_WITH_TIMEOUT(!stateChangedSpy.isEmpty() || !errorSpy.isEmpty(), TestTimeOut);
if (!errorSpy.isEmpty()) {
QNetworkSession::SessionError error =
@@ -867,7 +867,7 @@ void tst_QNetworkSession::sessionOpenCloseStop()
QVERIFY(errorSpy.isEmpty());
if (expectStateChange)
- QTRY_VERIFY(session.state() == QNetworkSession::Disconnected);
+ QTRY_VERIFY_WITH_TIMEOUT(session.state() == QNetworkSession::Disconnected, TestTimeOut);
++inProcessSessionManagementCount;
} else {
@@ -929,7 +929,7 @@ void tst_QNetworkSession::outOfProcessSession()
QNetworkConfiguration changed;
do {
- QTRY_VERIFY(!spy.isEmpty());
+ QTRY_VERIFY_WITH_TIMEOUT(!spy.isEmpty(), TestTimeOut);
changed = qvariant_cast<QNetworkConfiguration>(spy.takeFirst().at(0));
} while (changed.identifier() != identifier);
@@ -949,7 +949,7 @@ void tst_QNetworkSession::outOfProcessSession()
oopSocket->waitForBytesWritten();
do {
- QTRY_VERIFY(!spy.isEmpty());
+ QTRY_VERIFY_WITH_TIMEOUT(!spy.isEmpty(), TestTimeOut);
changed = qvariant_cast<QNetworkConfiguration>(spy.takeFirst().at(0));
} while (changed.identifier() != identifier);
@@ -1236,7 +1236,7 @@ void tst_QNetworkSession::sessionAutoClose()
// set session to auto close at next polling interval.
session.setSessionProperty(QLatin1String("AutoCloseSessionTimeout"), 0);
- QTRY_VERIFY(!closeSpy.isEmpty());
+ QTRY_VERIFY_WITH_TIMEOUT(!closeSpy.isEmpty(), TestTimeOut);
QCOMPARE(session.state(), QNetworkSession::Connected);