Fix sanity check of network test server
authorJason McDonald <jason.mcdonald@nokia.com>
Fri, 25 Nov 2011 07:04:12 +0000 (17:04 +1000)
committerQt by Nokia <qt-info@nokia.com>
Mon, 28 Nov 2011 07:13:41 +0000 (08:13 +0100)
Some of Qt's autotests depend on access to a test server.  For each test
that used the test server, tests/auto/network-settings.h created a
global object to verify at startup that host lookups to the test server
will succeed (and abort the test otherwise).

There are two problems with that approach:

First, the sanity check happens before main(), and thus before the test
framework has started logging test results.  This means that if the
sanity check aborts the test, the failure message will not be visible in
the test output if logging to a file or will cause the output to be
malformed if logging to the console in XML format.

Second, since Qt 4.7, the host lookup uses a class that connects to the
QCoreApplication instance, which doesn't exist before main(), and this
caused all tests that included network-settings.h to output an error
message from QObject::connect() at the beginning of the test.

Both of these problems are solved by removing the global object from
network-settings.h and instead performing the sanity check in the
initTestCase() function of each test.

Task-number: QTBUG-22876
Change-Id: Id49c1826906327bf571686cc11527f0265e5af44
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
26 files changed:
tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp
tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp
tests/auto/integrationtests/networkselftest/tst_networkselftest.cpp
tests/auto/integrationtests/qnetworkaccessmanager_and_qprogressdialog/tst_qnetworkaccessmanager_and_qprogressdialog.cpp
tests/auto/network-settings.h
tests/auto/network/access/qabstractnetworkcache/tst_qabstractnetworkcache.cpp
tests/auto/network/access/qftp/tst_qftp.cpp
tests/auto/network/access/qhttp/tst_qhttp.cpp
tests/auto/network/access/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp
tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp
tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp
tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp
tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp
tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
tests/auto/network/ssl/qsslsocket_onDemandCertificates_member/tst_qsslsocket_onDemandCertificates_member.cpp
tests/auto/network/ssl/qsslsocket_onDemandCertificates_static/tst_qsslsocket_onDemandCertificates_static.cpp
tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp
tests/benchmarks/network/socket/qtcpserver/tst_qtcpserver.cpp
tests/benchmarks/network/ssl/qsslsocket/tst_qsslsocket.cpp
tests/manual/network_stresstest/tst_network_stresstest.cpp
tests/manual/qnetworkreply/main.cpp

index a30a2d0..bb9751f 100644 (file)
@@ -53,6 +53,7 @@ class tst_QIODevice : public QObject
     Q_OBJECT
 
 private slots:
+    void initTestCase();
     void getSetCheck();
     void constructing_QTcpSocket();
     void constructing_QFile();
@@ -70,6 +71,11 @@ private slots:
     void peekBug();
 };
 
+void tst_QIODevice::initTestCase()
+{
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+}
+
 // Testing get/set functions
 void tst_QIODevice::getSetCheck()
 {
index a2e8006..c8bc826 100644 (file)
@@ -76,6 +76,7 @@ class tst_QTextStream : public QObject
     Q_OBJECT
 
 public slots:
+    void initTestCase();
     void cleanup();
 
 private slots:
@@ -243,6 +244,11 @@ private:
     void generateRealNumbersDataWrite();
 };
 
+void tst_QTextStream::initTestCase()
+{
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+}
+
 // Testing get/set functions
 void tst_QTextStream::getSetCheck()
 {
index 1cf2060..c768a29 100644 (file)
@@ -363,6 +363,7 @@ QHostAddress tst_NetworkSelfTest::serverIpAddress()
 
 void tst_NetworkSelfTest::initTestCase()
 {
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
 #ifndef QT_NO_BEARERMANAGEMENT
     netConfMan = new QNetworkConfigurationManager(this);
     networkConfiguration = netConfMan->defaultConfiguration();
index abf5aa5..63506fe 100644 (file)
@@ -58,6 +58,7 @@ class tst_QNetworkAccessManager_And_QProgressDialog : public QObject
 public:
     tst_QNetworkAccessManager_And_QProgressDialog();
 private slots:
+    void initTestCase();
     void downloadCheck();
     void downloadCheck_data();
 };
@@ -125,6 +126,11 @@ tst_QNetworkAccessManager_And_QProgressDialog::tst_QNetworkAccessManager_And_QPr
 {
 }
 
+void tst_QNetworkAccessManager_And_QProgressDialog::initTestCase()
+{
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+}
+
 void tst_QNetworkAccessManager_And_QProgressDialog::downloadCheck_data()
 {
     QTest::addColumn<bool>("useZeroCopy");
index 77bcfe0..5cf32d3 100644 (file)
@@ -143,20 +143,18 @@ public:
 
         return false;
     }
-};
 
 #ifdef QT_NETWORK_LIB
-class QtNetworkSettingsInitializerCode {
-public:
-    QtNetworkSettingsInitializerCode() {
+    static bool verifyTestNetworkSettings()
+    {
         QHostInfo testServerResult = QHostInfo::fromName(QtNetworkSettings::serverName());
         if (testServerResult.error() != QHostInfo::NoError) {
             qWarning() << "Could not lookup" << QtNetworkSettings::serverName();
             qWarning() << "Please configure the test environment!";
             qWarning() << "See /etc/hosts or network-settings.h";
-            qFatal("Exiting");
+            return false;
         }
+        return true;
     }
-};
-QtNetworkSettingsInitializerCode qtNetworkSettingsInitializer;
 #endif
+};
index 614096d..59a9c55 100644 (file)
@@ -137,6 +137,7 @@ Q_DECLARE_METATYPE(QNetworkRequest::CacheLoadControl)
 
 void tst_QAbstractNetworkCache::initTestCase()
 {
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
 #ifndef QT_NO_BEARERMANAGEMENT
     netConfMan = new QNetworkConfigurationManager(this);
     networkConfiguration = netConfMan->defaultConfiguration();
index 87a4dbf..6caa98b 100644 (file)
@@ -216,6 +216,7 @@ void tst_QFtp::initTestCase_data()
 
 void tst_QFtp::initTestCase()
 {
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
 #ifndef QT_NO_BEARERMANAGEMENT
     QNetworkConfigurationManager manager;
     networkSessionImplicit = QSharedPointer<QNetworkSession>(new QNetworkSession(manager.defaultConfiguration()));
index 7150400..7ef0614 100644 (file)
@@ -209,6 +209,7 @@ void tst_QHttp::initTestCase_data()
 
 void tst_QHttp::initTestCase()
 {
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
 }
 
 void tst_QHttp::cleanupTestCase()
index bbc1d21..b4c0e2c 100644 (file)
@@ -122,6 +122,7 @@ tst_QHttpNetworkConnection::tst_QHttpNetworkConnection()
 
 void tst_QHttpNetworkConnection::initTestCase()
 {
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
 }
 
 void tst_QHttpNetworkConnection::cleanupTestCase()
index 6d7cce5..d3b92ea 100644 (file)
@@ -1275,6 +1275,7 @@ void tst_QNetworkReply::gotError()
 
 void tst_QNetworkReply::initTestCase()
 {
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
 #if !defined Q_OS_WIN
     wronlyFileName = QDir::currentPath() + "/write-only";
     QFile wr(wronlyFileName);
index fbf4144..217a46a 100644 (file)
@@ -194,6 +194,7 @@ tst_QHostInfo::~tst_QHostInfo()
 
 void tst_QHostInfo::initTestCase()
 {
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
 #ifndef QT_NO_BEARERMANAGEMENT
     //start the default network
     netConfMan = new QNetworkConfigurationManager(this);
index 7a2f0e5..06dd62e 100644 (file)
@@ -87,6 +87,7 @@ tst_QNetworkInterface::~tst_QNetworkInterface()
 
 void tst_QNetworkInterface::initTestCase()
 {
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
 #ifndef QT_NO_BEARERMANAGEMENT
     netConfMan = new QNetworkConfigurationManager(this);
     networkConfiguration = netConfMan->defaultConfiguration();
index 103ea13..bf3e2f2 100644 (file)
@@ -78,6 +78,7 @@ public:
 
 
 public slots:
+    void initTestCase();
     void init();
     void cleanup();
 private slots:
@@ -106,6 +107,11 @@ tst_PlatformSocketEngine::~tst_PlatformSocketEngine()
 {
 }
 
+void tst_PlatformSocketEngine::initTestCase()
+{
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+}
+
 void tst_PlatformSocketEngine::init()
 {
 }
index 92da0e8..93344a3 100644 (file)
@@ -66,6 +66,7 @@ public:
 
 
 public slots:
+    void initTestCase();
     void init();
     void cleanup();
 private slots:
@@ -147,6 +148,10 @@ tst_QHttpSocketEngine::~tst_QHttpSocketEngine()
 {
 }
 
+void tst_QHttpSocketEngine::initTestCase()
+{
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+}
 
 void tst_QHttpSocketEngine::init()
 {
index d738926..8c600c5 100644 (file)
@@ -73,6 +73,7 @@ public:
 
 
 public slots:
+    void initTestCase();
     void init();
     void cleanup();
 private slots:
@@ -157,6 +158,11 @@ tst_QSocks5SocketEngine::~tst_QSocks5SocketEngine()
 {
 }
 
+void tst_QSocks5SocketEngine::initTestCase()
+{
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+}
+
 void tst_QSocks5SocketEngine::init()
 {
     tmpSocket = 0;
index f96ad27..0cdd3a7 100644 (file)
@@ -155,6 +155,7 @@ void tst_QTcpServer::initTestCase_data()
 
 void tst_QTcpServer::initTestCase()
 {
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
 #ifndef QT_NO_BEARERMANAGEMENT
     QNetworkConfigurationManager man;
     networkSession = new QNetworkSession(man.defaultConfiguration(), this);
index 3fb4333..9c87ac0 100644 (file)
@@ -133,6 +133,7 @@ public:
 
 public slots:
     void initTestCase_data();
+    void initTestCase();
     void init();
     void cleanup();
 private slots:
@@ -348,6 +349,11 @@ void tst_QTcpSocket::initTestCase_data()
 #endif
 }
 
+void tst_QTcpSocket::initTestCase()
+{
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+}
+
 void tst_QTcpSocket::init()
 {
     QFETCH_GLOBAL(bool, setProxy);
index f737b94..786714a 100644 (file)
@@ -80,6 +80,7 @@ public:
 
 public slots:
     void initTestCase_data();
+    void initTestCase();
     void init();
     void cleanup();
 private slots:
@@ -159,6 +160,11 @@ void tst_QUdpSocket::initTestCase_data()
 #endif
 }
 
+void tst_QUdpSocket::initTestCase()
+{
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+}
+
 void tst_QUdpSocket::init()
 {
     QFETCH_GLOBAL(bool, setProxy);
index 3e81c1f..e742c22 100644 (file)
@@ -118,6 +118,7 @@ public:
 
 public slots:
     void initTestCase_data();
+    void initTestCase();
     void init();
     void cleanup();
     void proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *auth);
@@ -270,6 +271,11 @@ void tst_QSslSocket::initTestCase_data()
 //    QTest::newRow("WithHttpProxyNtlmAuth") << true << int(HttpProxy | AuthNtlm);
 }
 
+void tst_QSslSocket::initTestCase()
+{
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+}
+
 void tst_QSslSocket::init()
 {
     QFETCH_GLOBAL(bool, setProxy);
index 881ec36..7e9c427 100644 (file)
@@ -78,6 +78,7 @@ public:
 
 public slots:
     void initTestCase_data();
+    void initTestCase();
     void init();
     void cleanup();
     void proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *auth);
@@ -126,6 +127,11 @@ void tst_QSslSocket_onDemandCertificates_member::initTestCase_data()
 //    QTest::newRow("WithHttpProxyNtlmAuth") << true << int(HttpProxy | AuthNtlm);
 }
 
+void tst_QSslSocket_onDemandCertificates_member::initTestCase()
+{
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+}
+
 void tst_QSslSocket_onDemandCertificates_member::init()
 {
     QFETCH_GLOBAL(bool, setProxy);
index bbbfb3e..5989424 100644 (file)
@@ -78,6 +78,7 @@ public:
 
 public slots:
     void initTestCase_data();
+    void initTestCase();
     void init();
     void cleanup();
     void proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *auth);
@@ -126,6 +127,11 @@ void tst_QSslSocket_onDemandCertificates_static::initTestCase_data()
 //    QTest::newRow("WithHttpProxyNtlmAuth") << true << int(HttpProxy | AuthNtlm);
 }
 
+void tst_QSslSocket_onDemandCertificates_static::initTestCase()
+{
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+}
+
 void tst_QSslSocket_onDemandCertificates_static::init()
 {
     QFETCH_GLOBAL(bool, setProxy);
index 565bdd7..9fc6147 100644 (file)
@@ -454,6 +454,7 @@ class tst_qnetworkreply : public QObject
 
     QNetworkAccessManager manager;
 private slots:
+    void initTestCase();
     void httpLatency();
 
 #ifndef QT_NO_OPENSSL
@@ -472,6 +473,11 @@ private slots:
     void httpsRequestChain();
 };
 
+void tst_qnetworkreply::initTestCase()
+{
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+}
+
 void tst_qnetworkreply::httpLatency()
 {
     QNetworkAccessManager manager;
index b7106ed..7f6ded8 100644 (file)
@@ -70,6 +70,7 @@ public:
 
 public slots:
     void initTestCase_data();
+    void initTestCase();
     void init();
     void cleanup();
 private slots:
@@ -95,6 +96,11 @@ void tst_QTcpServer::initTestCase_data()
     QTest::newRow("WithSocks5Proxy") << true << int(QNetworkProxy::Socks5Proxy);
 }
 
+void tst_QTcpServer::initTestCase()
+{
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+}
+
 void tst_QTcpServer::init()
 {
     QFETCH_GLOBAL(bool, setProxy);
index aa4d014..9f0a694 100644 (file)
@@ -61,7 +61,7 @@ public:
 
 
 public slots:
-    void initTestCase_data();
+    void initTestCase();
     void init();
     void cleanup();
 private slots:
@@ -77,8 +77,9 @@ tst_QSslSocket::~tst_QSslSocket()
 {
 }
 
-void tst_QSslSocket::initTestCase_data()
+void tst_QSslSocket::initTestCase()
 {
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
 }
 
 void tst_QSslSocket::init()
index ca5486e..8337118 100644 (file)
@@ -93,6 +93,7 @@ private:
 
 public slots:
     void initTestCase_data();
+    void initTestCase();
     void init();
 
     void slotReadAll() { byteCounter += static_cast<QIODevice *>(sender())->readAll().size(); }
@@ -133,6 +134,11 @@ void tst_NetworkStressTest::initTestCase_data()
     QTest::newRow("remote") << false << QtNetworkSettings::serverName() << 80;
 }
 
+void tst_NetworkStressTest::initTestCase()
+{
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+}
+
 void tst_NetworkStressTest::init()
 {
     // clear the internal cache
index 56f3260..8033251 100644 (file)
 class tst_qnetworkreply : public QObject
 {
     Q_OBJECT
-    private slots:
+private slots:
+    void initTestCase();
     void limiting_data();
     void limiting();
-
 };
 
 QNetworkReply *reply;
@@ -90,6 +90,11 @@ protected:
     QTime stopwatch;
 };
 
+void tst_qnetworkreply::initTestCase()
+{
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+}
+
 void tst_qnetworkreply::limiting_data()
 {
     QTest::addColumn<QUrl>("url");