Fix sanity check of network test server
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>
This commit is contained in:
parent
cbcdb5f4cf
commit
e15548d3e4
@ -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()
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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();
|
||||
|
@ -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");
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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();
|
||||
|
@ -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()));
|
||||
|
@ -209,6 +209,7 @@ void tst_QHttp::initTestCase_data()
|
||||
|
||||
void tst_QHttp::initTestCase()
|
||||
{
|
||||
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
|
||||
}
|
||||
|
||||
void tst_QHttp::cleanupTestCase()
|
||||
|
@ -122,6 +122,7 @@ tst_QHttpNetworkConnection::tst_QHttpNetworkConnection()
|
||||
|
||||
void tst_QHttpNetworkConnection::initTestCase()
|
||||
{
|
||||
QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
|
||||
}
|
||||
|
||||
void tst_QHttpNetworkConnection::cleanupTestCase()
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -54,10 +54,10 @@
|
||||
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");
|
||||
|
Loading…
Reference in New Issue
Block a user