summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrans Englich <frans.englich@nokia.com>2009-05-19 13:06:46 (GMT)
committerFrans Englich <frans.englich@nokia.com>2009-05-19 13:09:27 (GMT)
commit70429c33f0687afd489e1055bc0e1f1f340e13b9 (patch)
tree4917de9c58c45bab4d7561a560cc11c469a6ff98
parentac70ce3f2598f0f3aae64c2e39c580375fd62df0 (diff)
downloadQt-70429c33f0687afd489e1055bc0e1f1f340e13b9.zip
Qt-70429c33f0687afd489e1055bc0e1f1f340e13b9.tar.gz
Qt-70429c33f0687afd489e1055bc0e1f1f340e13b9.tar.bz2
Adpot more code to use QtNetworkSettings instead of hard coded names.
Reviewed-By: Peter Hartmann
-rw-r--r--tests/auto/network-settings.h9
-rw-r--r--tests/auto/q3socketdevice/tst_q3socketdevice.cpp7
-rw-r--r--tests/auto/qhttpsocketengine/tst_qhttpsocketengine.cpp23
-rw-r--r--tests/auto/qnativesocketengine/tst_qnativesocketengine.cpp16
-rw-r--r--tests/auto/qsocks5socketengine/tst_qsocks5socketengine.cpp31
-rw-r--r--tests/auto/qsslsocket/tst_qsslsocket.cpp33
6 files changed, 59 insertions, 60 deletions
diff --git a/tests/auto/network-settings.h b/tests/auto/network-settings.h
index b2a449a..5a2f9c3 100644
--- a/tests/auto/network-settings.h
+++ b/tests/auto/network-settings.h
@@ -39,6 +39,7 @@
**
****************************************************************************/
#include <QString>
+#include <QtNetwork/QHostInfo>
class QtNetworkSettings
{
@@ -63,4 +64,12 @@ public:
{
return "qt-test-server.wildcard.dev." + serverDomainName();
}
+
+#ifdef QT_NETWORK_LIB
+ static QHostAddress serverIP()
+ {
+ return QHostInfo::fromName(serverName()).addresses().first();
+ }
+#endif
+
};
diff --git a/tests/auto/q3socketdevice/tst_q3socketdevice.cpp b/tests/auto/q3socketdevice/tst_q3socketdevice.cpp
index 2b0c606..6255aee 100644
--- a/tests/auto/q3socketdevice/tst_q3socketdevice.cpp
+++ b/tests/auto/q3socketdevice/tst_q3socketdevice.cpp
@@ -45,6 +45,8 @@
#include <q3socketdevice.h>
+#include "../network-settings.h"
+
//TESTED_CLASS=
//TESTED_FILES=
@@ -97,8 +99,7 @@ void tst_Q3SocketDevice::readNull()
int attempts = 10;
while (attempts--) {
- // connect to imap.troll.no
- if (device.connect(QHostAddress("62.70.27.18"), 143))
+ if (device.connect(QtNetworkSettings::serverIP(), 143))
break;
}
@@ -117,7 +118,7 @@ void tst_Q3SocketDevice::readNull()
#endif
QCOMPARE(device.peerPort(), quint16(143));
QCOMPARE(device.peerAddress().toString(),
- QHostAddress("62.70.27.18").toString());
+ QtNetworkSettings::serverIP().toString());
QCOMPARE(device.error(), Q3SocketDevice::NoError);
// write a logout notice
diff --git a/tests/auto/qhttpsocketengine/tst_qhttpsocketengine.cpp b/tests/auto/qhttpsocketengine/tst_qhttpsocketengine.cpp
index 9ef8f9a..4c92119 100644
--- a/tests/auto/qhttpsocketengine/tst_qhttpsocketengine.cpp
+++ b/tests/auto/qhttpsocketengine/tst_qhttpsocketengine.cpp
@@ -137,8 +137,6 @@ public slots:
}
};
-static const char *IMAP_IP = "62.70.27.18";
-
tst_QHttpSocketEngine::tst_QHttpSocketEngine()
{
}
@@ -307,12 +305,11 @@ void tst_QHttpSocketEngine::simpleConnectToIMAP()
socketDevice.setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, QtNetworkSettings::serverName(), 3128));
- // Connect to imap.trolltech.com's IP
- QVERIFY(!socketDevice.connectToHost(QHostAddress(IMAP_IP), 143));
+ QVERIFY(!socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143));
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectingState);
QVERIFY(socketDevice.waitForWrite());
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState);
- QVERIFY(socketDevice.peerAddress() == QHostAddress(IMAP_IP));
+ QVERIFY(socketDevice.peerAddress() == QtNetworkSettings::serverIP());
QVERIFY(!socketDevice.localAddress().isNull());
QVERIFY(socketDevice.localPort() > 0);
@@ -328,7 +325,7 @@ void tst_QHttpSocketEngine::simpleConnectToIMAP()
// Check that the greeting is what we expect it to be
QCOMPARE(array.constData(),
- "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
// Write a logout message
QByteArray array2 = "XXXX LOGOUT\r\n";
@@ -369,7 +366,6 @@ void tst_QHttpSocketEngine::simpleErrorsAndStates()
QVERIFY(!socketDevice.connectToHost(QHostAddress(QtNetworkSettings::serverName()), 8088));
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectingState);
if (socketDevice.waitForWrite(15000)) {
- qDebug() << socketDevice.state();
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState ||
socketDevice.state() == QAbstractSocket::UnconnectedState);
} else {
@@ -451,14 +447,14 @@ void tst_QHttpSocketEngine::tcpSocketBlockingTest()
QTcpSocket socket;
// Connect
- socket.connectToHost("imap.troll.no", 143);
+ socket.connectToHost(QtNetworkSettings::serverName(), 143);
QVERIFY(socket.waitForConnected());
QCOMPARE(socket.state(), QTcpSocket::ConnectedState);
// Read greeting
QVERIFY(socket.waitForReadyRead(5000));
QString s = socket.readLine();
- QCOMPARE(s.toLatin1().constData(), "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ QCOMPARE(s.toLatin1().constData(), "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
// Write NOOP
QCOMPARE((int) socket.write("1 NOOP\r\n", 8), 8);
@@ -508,7 +504,7 @@ void tst_QHttpSocketEngine::tcpSocketNonBlockingTest()
tcpSocketNonBlocking_socket = &socket;
// Connect
- socket.connectToHost("imap.troll.no", 143);
+ socket.connectToHost(QtNetworkSettings::serverName(), 143);
QCOMPARE(socket.state(), QTcpSocket::HostLookupState);
QTestEventLoop::instance().enterLoop(30);
@@ -696,12 +692,11 @@ void tst_QHttpSocketEngine::passwordAuth()
socketDevice.setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, QtNetworkSettings::serverName(), 3128, "qsockstest", "password"));
- // Connect to imap.trolltech.com's IP
- QVERIFY(!socketDevice.connectToHost(QHostAddress(IMAP_IP), 143));
+ QVERIFY(!socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143));
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectingState);
QVERIFY(socketDevice.waitForWrite());
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState);
- QVERIFY(socketDevice.peerAddress() == QHostAddress(IMAP_IP));
+ QVERIFY(socketDevice.peerAddress() == QtNetworkSettings::serverIP());
// Wait for the greeting
QVERIFY(socketDevice.waitForRead());
@@ -715,7 +710,7 @@ void tst_QHttpSocketEngine::passwordAuth()
// Check that the greeting is what we expect it to be
QCOMPARE(array.constData(),
- "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
// Write a logout message
QByteArray array2 = "XXXX LOGOUT\r\n";
diff --git a/tests/auto/qnativesocketengine/tst_qnativesocketengine.cpp b/tests/auto/qnativesocketengine/tst_qnativesocketengine.cpp
index 68ec414..90276f2 100644
--- a/tests/auto/qnativesocketengine/tst_qnativesocketengine.cpp
+++ b/tests/auto/qnativesocketengine/tst_qnativesocketengine.cpp
@@ -100,8 +100,6 @@ private slots:
void receiveUrgentData();
};
-static const char *IMAP_IP = "62.70.27.18";
-
tst_QNativeSocketEngine::tst_QNativeSocketEngine()
{
}
@@ -155,15 +153,14 @@ void tst_QNativeSocketEngine::simpleConnectToIMAP()
QVERIFY(socketDevice.initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv4Protocol));
QVERIFY(socketDevice.state() == QAbstractSocket::UnconnectedState);
- // Connect to imap.trolltech.com's IP
- bool connected = socketDevice.connectToHost(QHostAddress(IMAP_IP), 143);
- if (!connected) {
+ const bool isConnected = socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143);
+ if (!isConnected) {
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectingState);
QVERIFY(socketDevice.waitForWrite());
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState);
}
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState);
- QVERIFY(socketDevice.peerAddress() == QHostAddress(IMAP_IP));
+ QVERIFY(socketDevice.peerAddress() == QtNetworkSettings::serverIP());
// Wait for the greeting
QVERIFY(socketDevice.waitForRead());
@@ -176,7 +173,7 @@ void tst_QNativeSocketEngine::simpleConnectToIMAP()
QVERIFY(socketDevice.read(array.data(), array.size()) == available);
// Check that the greeting is what we expect it to be
- QCOMPARE(array.constData(), "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ QCOMPARE(array.constData(), "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
// Write a logout message
QByteArray array2 = "ZZZ LOGOUT\r\n";
@@ -580,9 +577,8 @@ void tst_QNativeSocketEngine::networkError()
QVERIFY(client.initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv4Protocol));
- // Connect to imap.trolltech.com's IP
- bool connected = client.connectToHost(QHostAddress(IMAP_IP), 143);
- if (!connected) {
+ const bool isConnected = client.connectToHost(QHostAddress(QtNetworkSettings::serverIP()), 143);
+ if (!isConnected) {
QVERIFY(client.state() == QAbstractSocket::ConnectingState);
QVERIFY(client.waitForWrite());
QVERIFY(client.state() == QAbstractSocket::ConnectedState);
diff --git a/tests/auto/qsocks5socketengine/tst_qsocks5socketengine.cpp b/tests/auto/qsocks5socketengine/tst_qsocks5socketengine.cpp
index 86333e0..470f897 100644
--- a/tests/auto/qsocks5socketengine/tst_qsocks5socketengine.cpp
+++ b/tests/auto/qsocks5socketengine/tst_qsocks5socketengine.cpp
@@ -145,8 +145,6 @@ private slots:
}
};
-static const char *IMAP_IP = "62.70.27.18";
-
tst_QSocks5SocketEngine::tst_QSocks5SocketEngine()
{
}
@@ -321,12 +319,11 @@ void tst_QSocks5SocketEngine::simpleConnectToIMAP()
socketDevice.setProxy(QNetworkProxy(QNetworkProxy::Socks5Proxy, QtNetworkSettings::serverName(), 1080));
- // Connect to imap.trolltech.com's IP
- QVERIFY(!socketDevice.connectToHost(QHostAddress(IMAP_IP), 143));
+ QVERIFY(!socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143));
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectingState);
QVERIFY(socketDevice.waitForWrite());
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState);
- QVERIFY(socketDevice.peerAddress() == QHostAddress(IMAP_IP));
+ QVERIFY(socketDevice.peerAddress() == QtNetworkSettings::serverIP());
// Wait for the greeting
QVERIFY(socketDevice.waitForRead());
@@ -340,7 +337,7 @@ void tst_QSocks5SocketEngine::simpleConnectToIMAP()
// Check that the greeting is what we expect it to be
QCOMPARE(array.constData(),
- "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
// Write a logout message
QByteArray array2 = "XXXX LOGOUT\r\n";
@@ -589,7 +586,7 @@ void tst_QSocks5SocketEngine::tcpSocketBlockingTest()
QTcpSocket socket;
// Connect
- socket.connectToHost("imap.troll.no", 143);
+ socket.connectToHost(QtNetworkSettings::serverName(), 143);
QVERIFY(socket.waitForConnected());
QCOMPARE(socket.state(), QTcpSocket::ConnectedState);
@@ -646,7 +643,7 @@ void tst_QSocks5SocketEngine::tcpSocketNonBlockingTest()
tcpSocketNonBlocking_socket = &socket;
// Connect
- socket.connectToHost("imap.troll.no", 143);
+ socket.connectToHost(QtNetworkSettings::serverName(), 143);
QCOMPARE(socket.state(), QTcpSocket::HostLookupState);
QTestEventLoop::instance().enterLoop(30);
@@ -834,15 +831,14 @@ void tst_QSocks5SocketEngine::passwordAuth()
socketDevice.setProxy(QNetworkProxy(QNetworkProxy::Socks5Proxy, QtNetworkSettings::serverName(), 1080, "qsockstest", "password"));
- // Connect to imap.trolltech.com's IP
- QVERIFY(!socketDevice.connectToHost(QHostAddress(IMAP_IP), 143));
+ QVERIFY(!socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143));
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectingState);
QVERIFY(socketDevice.waitForWrite());
- if (!socketDevice.connectToHost(QHostAddress(IMAP_IP), 143)) {
+ if (!socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143)) {
qDebug("%d, %s", socketDevice.error(), socketDevice.errorString().toLatin1().constData());
}
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState);
- QVERIFY(socketDevice.peerAddress() == QHostAddress(IMAP_IP));
+ QVERIFY(socketDevice.peerAddress() == QtNetworkSettings::serverIP());
// Wait for the greeting
QVERIFY(socketDevice.waitForRead());
@@ -856,7 +852,7 @@ void tst_QSocks5SocketEngine::passwordAuth()
// Check that the greeting is what we expect it to be
QCOMPARE(array.constData(),
- "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
// Write a logout message
QByteArray array2 = "XXXX LOGOUT\r\n";
@@ -902,17 +898,16 @@ void tst_QSocks5SocketEngine::passwordAuth2()
socketDevice.setProxy(QNetworkProxy(QNetworkProxy::Socks5Proxy, QtNetworkSettings::serverName(), 1081));
socketDevice.setReceiver(this);
- // Connect to imap.trolltech.com's IP
- QVERIFY(!socketDevice.connectToHost(QHostAddress(IMAP_IP), 143));
+ QVERIFY(!socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143));
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectingState);
while (socketDevice.state() == QAbstractSocket::ConnectingState) {
QVERIFY(socketDevice.waitForWrite());
- socketDevice.connectToHost(QHostAddress(IMAP_IP), 143);
+ socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143);
}
if (socketDevice.state() != QAbstractSocket::ConnectedState)
qDebug("%d, %s", socketDevice.error(), socketDevice.errorString().toLatin1().constData());
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState);
- QVERIFY(socketDevice.peerAddress() == QHostAddress(IMAP_IP));
+ QVERIFY(socketDevice.peerAddress() == QtNetworkSettings::serverIP());
// Wait for the greeting
QVERIFY(socketDevice.waitForRead());
@@ -926,7 +921,7 @@ void tst_QSocks5SocketEngine::passwordAuth2()
// Check that the greeting is what we expect it to be
QCOMPARE(array.constData(),
- "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
// Write a logout message
QByteArray array2 = "XXXX LOGOUT\r\n";
diff --git a/tests/auto/qsslsocket/tst_qsslsocket.cpp b/tests/auto/qsslsocket/tst_qsslsocket.cpp
index 79fbf1b..d87ab7b 100644
--- a/tests/auto/qsslsocket/tst_qsslsocket.cpp
+++ b/tests/auto/qsslsocket/tst_qsslsocket.cpp
@@ -499,36 +499,39 @@ void tst_QSslSocket::sslErrors_data()
{
QTest::addColumn<QString>("host");
QTest::addColumn<int>("port");
- QTest::addColumn<SslErrorList>("errors");
-
- QTest::newRow("imap.troll.no") << "imap.troll.no" << 993
- << (SslErrorList()
- << QSslError::HostNameMismatch
- << QSslError::SelfSignedCertificateInChain);
- QTest::newRow("imap.trolltech.com") << "imap.trolltech.com" << 993
- << (SslErrorList()
- << QSslError::SelfSignedCertificateInChain);
+ QTest::addColumn<SslErrorList>("expected");
+
+ QTest::newRow(qPrintable(QtNetworkSettings::serverLocalName()))
+ << QtNetworkSettings::serverLocalName()
+ << 993
+ << (SslErrorList() << QSslError::HostNameMismatch
+ << QSslError::SelfSignedCertificate);
+
+ QTest::newRow("imap.trolltech.com")
+ << "imap.trolltech.com"
+ << 993
+ << (SslErrorList() << QSslError::SelfSignedCertificateInChain);
}
void tst_QSslSocket::sslErrors()
{
QFETCH(QString, host);
QFETCH(int, port);
- QFETCH(SslErrorList, errors);
+ QFETCH(SslErrorList, expected);
QSslSocketPtr socket = newSocket();
socket->connectToHostEncrypted(host, port);
socket->waitForEncrypted(5000);
- SslErrorList list;
+ SslErrorList output;
foreach (QSslError error, socket->sslErrors())
- list << error.error();
+ output << error.error();
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND
- if (list.last() == QSslError::CertificateUntrusted)
- list.takeLast();
+ if (output.last() == QSslError::CertificateUntrusted)
+ output.takeLast();
#endif
- QCOMPARE(list, errors);
+ QCOMPARE(output, expected);
}
void tst_QSslSocket::addCaCertificate()