Fix sanity check of network test server
authorJason McDonald <jason.mcdonald@nokia.com>
Mon, 28 Nov 2011 06:43:55 +0000 (16:43 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 29 Nov 2011 23:56:40 +0000 (00:56 +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: I1ae004cf7a10a02d34d7ec517ef5515eb722aecf
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
tests/auto/network-settings.h
tests/auto/qxmlquery/tst_qxmlquery.cpp
tests/auto/xmlpatterns/tst_xmlpatterns.cpp
tests/auto/xmlpatterns/xmlpatterns.pro

index 171a94d..5cf32d3 100644 (file)
@@ -72,7 +72,7 @@ public:
 #ifdef QT_NETWORK_LIB
     static QHostAddress serverIP()
     {
-    return QHostInfo::fromName(serverName()).addresses().first();
+        return QHostInfo::fromName(serverName()).addresses().first();
     }
 #endif
 
@@ -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 241a43a..fd56c36 100644 (file)
@@ -96,6 +96,7 @@ public:
     }
 
 private Q_SLOTS:
+    void initTestCase();
     void defaultConstructor() const;
     void copyConstructor() const;
     void constructorQXmlNamePool() const;
@@ -257,6 +258,11 @@ private:
     const bool m_testNetwork;
 };
 
+void tst_QXmlQuery::initTestCase()
+{
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+}
+
 void tst_QXmlQuery::checkBaseURI(const QUrl &baseURI, const QString &candidate)
 {
     /* The use of QFileInfo::canonicalFilePath() takes into account that drive letters
index adb8111..d8559dc 100644 (file)
@@ -108,6 +108,8 @@ tst_XmlPatterns::tst_XmlPatterns() : m_generatedTests(0)
 
 void tst_XmlPatterns::initTestCase()
 {
+    QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
+
     QVERIFY(m_normalizeTestName.isValid());
     QVERIFY(m_filenameInStderr.isValid());
 
index 74678c3..8716b9a 100644 (file)
@@ -1,6 +1,6 @@
 TARGET = tst_xmlpatterns
 CONFIG += testcase
-QT += testlib
+QT += network testlib
 SOURCES += tst_xmlpatterns.cpp \
            ../qxmlquery/TestFundament.cpp