summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRohan McGovern <rohan.mcgovern@nokia.com>2011-01-06 03:39:14 (GMT)
committerShane Kearns <shane.kearns@accenture.com>2011-01-25 14:08:58 (GMT)
commit44d0d663d4972b2d8a0248e4ea3222a46942ff0e (patch)
treea29876e13ac1e87f084256d9d4b8a83bf2a545e0 /tests
parent226aeef6f0fa1155a94171f2a4c531ad49c3ea00 (diff)
downloadQt-44d0d663d4972b2d8a0248e4ea3222a46942ff0e.zip
Qt-44d0d663d4972b2d8a0248e4ea3222a46942ff0e.tar.gz
Qt-44d0d663d4972b2d8a0248e4ea3222a46942ff0e.tar.bz2
network tests: make IMAP, FTP testdata more flexible.
Move all hardcoded IMAP/FTP fixtures into network-settings.h. Make it work with new and old network test server. Reviewed-by: Markus Goetz Task: QTBUG-15114
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/network-settings.h79
-rw-r--r--tests/auto/qhttpsocketengine/tst_qhttpsocketengine.cpp10
-rw-r--r--tests/auto/qnativesocketengine/tst_qnativesocketengine.cpp2
-rw-r--r--tests/auto/qsocks5socketengine/tst_qsocks5socketengine.cpp12
-rw-r--r--tests/auto/qsslsocket/tst_qsslsocket.cpp3
-rw-r--r--tests/auto/qtcpsocket/tst_qtcpsocket.cpp87
6 files changed, 142 insertions, 51 deletions
diff --git a/tests/auto/network-settings.h b/tests/auto/network-settings.h
index 6730946..0cb8e3a 100644
--- a/tests/auto/network-settings.h
+++ b/tests/auto/network-settings.h
@@ -64,6 +64,7 @@
//#define SYMBIAN_WINSOCK_CONNECTIVITY
#endif // Q_CC_NOKIAX86
+// FIXME: any reason we do this for symbian only, and not other platforms?
class QtNetworkSettingsRecord {
public:
QtNetworkSettingsRecord() { }
@@ -128,7 +129,6 @@ public:
static QString wildcardServerName()
{
return "qt-test-server.wildcard.dev." + serverDomainName();
- //return "qttest.wildcard.dev." + serverDomainName();
}
#ifdef QT_NETWORK_LIB
@@ -149,8 +149,10 @@ public:
}
#endif
- static QByteArray expectedReplyIMAP()
+ static bool compareReplyIMAP(QByteArray const& actual)
{
+ QList<QByteArray> expected;
+
#ifdef Q_OS_SYMBIAN
loadTestSettings();
@@ -160,17 +162,35 @@ public:
imapExpectedReply = entry->recordValue().toAscii();
imapExpectedReply.append('\r').append('\n');
}
- return imapExpectedReply.data();
+ expected << imapExpectedReply.data();
}
#endif
- QByteArray expected( "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] " );
- expected = expected.append(QtNetworkSettings::serverName().toAscii());
- expected = expected.append(" Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
- return expected;
+
+ // Mandriva; old test server
+ expected << QByteArray( "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] " )
+ .append(QtNetworkSettings::serverName().toAscii())
+ .append(" Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
+
+ // Ubuntu 10.04; new test server
+ expected << QByteArray( "* OK " )
+ .append(QtNetworkSettings::serverLocalName().toAscii())
+ .append(" Cyrus IMAP4 v2.2.13-Debian-2.2.13-19 server ready\r\n");
+
+ // Feel free to add more as needed
+
+ Q_FOREACH (QByteArray const& ba, expected) {
+ if (ba == actual) {
+ return true;
+ }
+ }
+
+ return false;
}
- static QByteArray expectedReplySSL()
+ static bool compareReplyIMAPSSL(QByteArray const& actual)
{
+ QList<QByteArray> expected;
+
#ifdef Q_OS_SYMBIAN
loadTestSettings();
@@ -180,19 +200,46 @@ public:
imapExpectedReplySsl = entry->recordValue().toAscii();
imapExpectedReplySsl.append('\r').append('\n');
}
- return imapExpectedReplySsl.data();
+ expected << imapExpectedReplySsl.data();
}
#endif
- QByteArray expected( "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID AUTH=PLAIN SASL-IR] " );
- expected = expected.append(QtNetworkSettings::serverName().toAscii());
- expected = expected.append(" Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
- return expected;
+ // Mandriva; old test server
+ expected << QByteArray( "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID AUTH=PLAIN SASL-IR] " )
+ .append(QtNetworkSettings::serverName().toAscii())
+ .append(" Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
+
+ // Ubuntu 10.04; new test server
+ expected << QByteArray( "* OK " )
+ .append(QtNetworkSettings::serverLocalName().toAscii())
+ .append(" Cyrus IMAP4 v2.2.13-Debian-2.2.13-19 server ready\r\n");
+
+ // Feel free to add more as needed
+
+ Q_FOREACH (QByteArray const& ba, expected) {
+ if (ba == actual) {
+ return true;
+ }
+ }
+
+ return false;
}
- static QByteArray expectedReplyFtp()
+ static bool compareReplyFtp(QByteArray const& actual)
{
- QByteArray expected( "220 (vsFTPd 2.0.5)\r\n221 Goodbye.\r\n" );
- return expected;
+ QList<QByteArray> expected;
+
+ // A few different vsFTPd versions.
+ // Feel free to add more as needed
+ expected << QByteArray( "220 (vsFTPd 2.0.5)\r\n221 Goodbye.\r\n" );
+ expected << QByteArray( "220 (vsFTPd 2.2.2)\r\n221 Goodbye.\r\n" );
+
+ Q_FOREACH (QByteArray const& ba, expected) {
+ if (ba == actual) {
+ return true;
+ }
+ }
+
+ return false;
}
#ifdef Q_OS_SYMBIAN
diff --git a/tests/auto/qhttpsocketengine/tst_qhttpsocketengine.cpp b/tests/auto/qhttpsocketengine/tst_qhttpsocketengine.cpp
index f86ba63..972185b 100644
--- a/tests/auto/qhttpsocketengine/tst_qhttpsocketengine.cpp
+++ b/tests/auto/qhttpsocketengine/tst_qhttpsocketengine.cpp
@@ -325,7 +325,7 @@ void tst_QHttpSocketEngine::simpleConnectToIMAP()
QVERIFY(socketDevice.read(array.data(), array.size()) == available);
// Check that the greeting is what we expect it to be
- QCOMPARE(array.constData(), QtNetworkSettings::expectedReplyIMAP().constData());
+ QVERIFY2(QtNetworkSettings::compareReplyIMAP(array), array.constData());
// Write a logout message
@@ -455,7 +455,7 @@ void tst_QHttpSocketEngine::tcpSocketBlockingTest()
// Read greeting
QVERIFY(socket.waitForReadyRead(5000));
QString s = socket.readLine();
- QCOMPARE(s.toLatin1().constData(), QtNetworkSettings::expectedReplyIMAP().constData());
+ QVERIFY2(QtNetworkSettings::compareReplyIMAP(s.toLatin1()), qPrintable(s));
// Write NOOP
QCOMPARE((int) socket.write("1 NOOP\r\n", 8), 8);
@@ -530,8 +530,8 @@ void tst_QHttpSocketEngine::tcpSocketNonBlockingTest()
// Read greeting
QVERIFY(!tcpSocketNonBlocking_data.isEmpty());
- QCOMPARE(tcpSocketNonBlocking_data.at(0).toLatin1().constData(),
- QtNetworkSettings::expectedReplyIMAP().constData());
+ QByteArray data = tcpSocketNonBlocking_data.at(0).toLatin1();
+ QVERIFY2(QtNetworkSettings::compareReplyIMAP(data), data.constData());
tcpSocketNonBlocking_data.clear();
@@ -713,7 +713,7 @@ void tst_QHttpSocketEngine::passwordAuth()
QVERIFY(socketDevice.read(array.data(), array.size()) == available);
// Check that the greeting is what we expect it to be
- QCOMPARE(array.constData(), QtNetworkSettings::expectedReplyIMAP().constData());
+ QVERIFY2(QtNetworkSettings::compareReplyIMAP(array), array.constData());
// Write a logout message
diff --git a/tests/auto/qnativesocketengine/tst_qnativesocketengine.cpp b/tests/auto/qnativesocketengine/tst_qnativesocketengine.cpp
index 2b0b632..782c2f0 100644
--- a/tests/auto/qnativesocketengine/tst_qnativesocketengine.cpp
+++ b/tests/auto/qnativesocketengine/tst_qnativesocketengine.cpp
@@ -173,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(), QtNetworkSettings::expectedReplyIMAP().constData());
+ QVERIFY2(QtNetworkSettings::compareReplyIMAP(array), array.constData());
// Write a logout message
QByteArray array2 = "ZZZ LOGOUT\r\n";
diff --git a/tests/auto/qsocks5socketengine/tst_qsocks5socketengine.cpp b/tests/auto/qsocks5socketengine/tst_qsocks5socketengine.cpp
index 8f0cbc3..9da7197 100644
--- a/tests/auto/qsocks5socketengine/tst_qsocks5socketengine.cpp
+++ b/tests/auto/qsocks5socketengine/tst_qsocks5socketengine.cpp
@@ -336,7 +336,7 @@ void tst_QSocks5SocketEngine::simpleConnectToIMAP()
QVERIFY(socketDevice.read(array.data(), array.size()) == available);
// Check that the greeting is what we expect it to be
- QCOMPARE(array.constData(), QtNetworkSettings::expectedReplyIMAP().constData());
+ QVERIFY2(QtNetworkSettings::compareReplyIMAP(array), array.constData());
// Write a logout message
QByteArray array2 = "XXXX LOGOUT\r\n";
@@ -596,7 +596,7 @@ void tst_QSocks5SocketEngine::tcpSocketBlockingTest()
// Read greeting
QVERIFY(socket.waitForReadyRead(5000));
QString s = socket.readLine();
- QCOMPARE(s.toLatin1().constData(), QtNetworkSettings::expectedReplyIMAP().constData());
+ QVERIFY2(QtNetworkSettings::compareReplyIMAP(s.toLatin1()), s.toLatin1().constData());
// Write NOOP
QCOMPARE((int) socket.write("1 NOOP\r\n", 8), 8);
@@ -671,8 +671,8 @@ void tst_QSocks5SocketEngine::tcpSocketNonBlockingTest()
// Read greeting
QVERIFY(!tcpSocketNonBlocking_data.isEmpty());
- QCOMPARE(tcpSocketNonBlocking_data.at(0).toLatin1().constData(),
- QtNetworkSettings::expectedReplyIMAP().constData());
+ QByteArray data = tcpSocketNonBlocking_data.at(0).toLatin1();
+ QVERIFY2(QtNetworkSettings::compareReplyIMAP(data), data.constData());
tcpSocketNonBlocking_data.clear();
@@ -859,7 +859,7 @@ void tst_QSocks5SocketEngine::passwordAuth()
QVERIFY(socketDevice.read(array.data(), array.size()) == available);
// Check that the greeting is what we expect it to be
- QCOMPARE(array.constData(), QtNetworkSettings::expectedReplyIMAP().constData());
+ QVERIFY2(QtNetworkSettings::compareReplyIMAP(array), array.constData());
// Write a logout message
QByteArray array2 = "XXXX LOGOUT\r\n";
@@ -927,7 +927,7 @@ void tst_QSocks5SocketEngine::passwordAuth2()
QVERIFY(socketDevice.read(array.data(), array.size()) == available);
// Check that the greeting is what we expect it to be
- QCOMPARE(array.constData(), QtNetworkSettings::expectedReplyIMAP().constData());
+ QVERIFY2(QtNetworkSettings::compareReplyIMAP(array), array.constData());
// 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 d6a7a01..3223006 100644
--- a/tests/auto/qsslsocket/tst_qsslsocket.cpp
+++ b/tests/auto/qsslsocket/tst_qsslsocket.cpp
@@ -502,8 +502,9 @@ void tst_QSslSocket::simpleConnectWithIgnore()
if (!socket.canReadLine())
enterLoop(10);
- QCOMPARE(socket.readAll(), QtNetworkSettings::expectedReplySSL());
+ QByteArray data = socket.readAll();
socket.disconnectFromHost();
+ QVERIFY2(QtNetworkSettings::compareReplyIMAPSSL(data), data.constData());
}
void tst_QSslSocket::sslErrors_data()
diff --git a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
index 2dbe5b7..86069cd 100644
--- a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
@@ -95,6 +95,7 @@
#include "private/qhostinfo_p.h"
#include "../network-settings.h"
+#include "../../shared/util.h"
Q_DECLARE_METATYPE(QAbstractSocket::SocketError)
Q_DECLARE_METATYPE(QAbstractSocket::SocketState)
@@ -222,6 +223,8 @@ protected slots:
void proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *auth);
private:
+ QByteArray expectedReplyIMAP();
+ void fetchExpectedReplyIMAP();
QTcpSocket *newSocket() const;
QTcpSocket *nonBlockingIMAP_socket;
QStringList nonBlockingIMAP_data;
@@ -233,6 +236,8 @@ private:
bool readingBody;
QTime timer;
+ QByteArray expectedReplyIMAP_cached;
+
mutable int proxyAuthCalled;
bool gotClosedSignal;
@@ -658,8 +663,6 @@ void tst_QTcpSocket::nonBlockingIMAP()
// Read greeting
QVERIFY(!nonBlockingIMAP_data.isEmpty());
-// QCOMPARE(nonBlockingIMAP_data.at(0).toLatin1().constData(),
-// "* OK fluke Cyrus IMAP4 v2.2.12 server ready\r\n");
QCOMPARE(nonBlockingIMAP_data.at(0).left(4).toLatin1().constData(), "* OK");
nonBlockingIMAP_data.clear();
@@ -787,6 +790,36 @@ void tst_QTcpSocket::delayedClose()
delete socket;
}
+
+//----------------------------------------------------------------------------------
+
+QByteArray tst_QTcpSocket::expectedReplyIMAP()
+{
+ if (expectedReplyIMAP_cached.isEmpty()) {
+ fetchExpectedReplyIMAP();
+ }
+
+ return expectedReplyIMAP_cached;
+}
+
+// Figure out how the current IMAP server responds
+void tst_QTcpSocket::fetchExpectedReplyIMAP()
+{
+ QTcpSocket *socket = newSocket();
+ socket->connectToHost(QtNetworkSettings::serverName(), 143);
+ QVERIFY2(socket->waitForConnected(10000), qPrintable(socket->errorString()));
+ QVERIFY2(socket->state() == QTcpSocket::ConnectedState, qPrintable(socket->errorString()));
+
+ QTRY_VERIFY(socket->canReadLine());
+
+ QByteArray greeting = socket->readLine();
+ delete socket;
+
+ QVERIFY2(QtNetworkSettings::compareReplyIMAP(greeting), greeting.constData());
+
+ expectedReplyIMAP_cached = greeting;
+}
+
//----------------------------------------------------------------------------------
void tst_QTcpSocket::partialRead()
@@ -797,8 +830,8 @@ void tst_QTcpSocket::partialRead()
QVERIFY(socket->state() == QTcpSocket::ConnectedState);
char buf[512];
-// QByteArray greeting = "* OK fluke Cyrus IMAP4 v2.2.12 server ready";
- QByteArray greeting = "* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE";
+ QByteArray greeting = expectedReplyIMAP();
+ QVERIFY(!greeting.isEmpty());
for (int i = 0; i < 10; i += 2) {
while (socket->bytesAvailable() < 2)
@@ -821,8 +854,8 @@ void tst_QTcpSocket::unget()
QVERIFY(socket->state() == QTcpSocket::ConnectedState);
char buf[512];
-// QByteArray greeting = "* OK fluke Cyrus IMAP4 v2.2.12 server ready";
- QByteArray greeting = "* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE";
+ QByteArray greeting = expectedReplyIMAP();
+ QVERIFY(!greeting.isEmpty());
for (int i = 0; i < 10; i += 2) {
while (socket->bytesAvailable() < 2)
@@ -1244,13 +1277,17 @@ void tst_QTcpSocket::readLine()
QVERIFY(socket->waitForReadyRead(10000));
char buffer[1024];
- int expectedReplySize = QtNetworkSettings::expectedReplyIMAP().size();
- Q_ASSERT(expectedReplySize >= 3);
- QCOMPARE(socket->readLine(buffer, sizeof(buffer)), qint64(expectedReplySize));
- QCOMPARE((int) buffer[expectedReplySize-2], (int) '\r');
- QCOMPARE((int) buffer[expectedReplySize-1], (int) '\n');
- QCOMPARE((int) buffer[expectedReplySize], (int) '\0');
+ qint64 linelen = socket->readLine(buffer, sizeof(buffer));
+ QVERIFY(linelen >= 3);
+ QVERIFY(linelen < 1024);
+
+ QByteArray reply = QByteArray::fromRawData(buffer, linelen);
+ QCOMPARE((int) buffer[linelen-2], (int) '\r');
+ QCOMPARE((int) buffer[linelen-1], (int) '\n');
+ QCOMPARE((int) buffer[linelen], (int) '\0');
+
+ QVERIFY2(QtNetworkSettings::compareReplyIMAP(reply), reply.constData());
QCOMPARE(socket->write("1 NOOP\r\n"), qint64(8));
@@ -1282,13 +1319,11 @@ void tst_QTcpSocket::readLine()
void tst_QTcpSocket::readLineString()
{
QTcpSocket *socket = newSocket();
-// QByteArray expected("* OK fluke Cyrus IMAP4 v2.2.12 server ready\r\n");
- QByteArray expected("* 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");
socket->connectToHost(QtNetworkSettings::serverName(), 143);
QVERIFY(socket->waitForReadyRead(10000));
QByteArray arr = socket->readLine();
- QCOMPARE(arr, QtNetworkSettings::expectedReplyIMAP());
+ QVERIFY2(QtNetworkSettings::compareReplyIMAP(arr), arr.constData());
delete socket;
}
@@ -1456,8 +1491,11 @@ void tst_QTcpSocket::atEnd()
QVERIFY(!stream.atEnd());
QString greeting = stream.readLine();
QVERIFY(stream.atEnd());
-// QCOMPARE(greeting, QString("220 (vsFTPd 2.0.4)"));
- QCOMPARE(greeting, QString("220 (vsFTPd 2.0.5)"));
+
+ // Test server must use some vsFTPd 2.x.x version
+ QVERIFY2(greeting.length() == sizeof("220 (vsFTPd 2.x.x)")-1, qPrintable(greeting));
+ QVERIFY2(greeting.startsWith("220 (vsFTPd 2."), qPrintable(greeting));
+ QVERIFY2(greeting.endsWith(")"), qPrintable(greeting));
delete socket;
}
@@ -1522,7 +1560,8 @@ void tst_QTcpSocket::socketInAThread()
TestThread thread;
thread.start();
QVERIFY(thread.wait(15000));
- QCOMPARE(thread.data(), QtNetworkSettings::expectedReplyFtp());
+ QByteArray data = thread.data();
+ QVERIFY2(QtNetworkSettings::compareReplyFtp(data), data.constData());
}
}
@@ -1542,9 +1581,13 @@ void tst_QTcpSocket::socketsInThreads()
QVERIFY(thread3.wait(15000));
QVERIFY(thread1.wait(15000));
- QCOMPARE(thread1.data(),QtNetworkSettings::expectedReplyFtp());
- QCOMPARE(thread2.data(),QtNetworkSettings::expectedReplyFtp());
- QCOMPARE(thread3.data(),QtNetworkSettings::expectedReplyFtp());
+ QByteArray data1 = thread1.data();
+ QByteArray data2 = thread2.data();
+ QByteArray data3 = thread3.data();
+
+ QVERIFY2(QtNetworkSettings::compareReplyFtp(data1), data1.constData());
+ QVERIFY2(QtNetworkSettings::compareReplyFtp(data2), data2.constData());
+ QVERIFY2(QtNetworkSettings::compareReplyFtp(data3), data3.constData());
}
}
@@ -1846,7 +1889,7 @@ void tst_QTcpSocket::readyReadSignalsAfterWaitForReadyRead()
QCOMPARE(readyReadSpy.count(), 1);
QString s = socket->readLine();
- QCOMPARE(s.toLatin1().constData(), QtNetworkSettings::expectedReplyIMAP().constData());
+ QVERIFY2(QtNetworkSettings::compareReplyIMAP(s.toLatin1()), s.toLatin1().constData());
QCOMPARE(socket->bytesAvailable(), qint64(0));
QCoreApplication::instance()->processEvents();