summaryrefslogtreecommitdiffstats
path: root/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qtcpsocket/tst_qtcpsocket.cpp')
-rw-r--r--tests/auto/qtcpsocket/tst_qtcpsocket.cpp79
1 files changed, 54 insertions, 25 deletions
diff --git a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
index 1e7cc48..da3f19a 100644
--- a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
@@ -40,7 +40,10 @@
****************************************************************************/
-#ifdef _WIN32
+// Just to get Q_OS_SYMBIAN
+#include <qglobal.h>
+
+#if defined(_WIN32) && !defined(Q_OS_SYMBIAN)
#include <winsock2.h>
#else
#include <sys/types.h>
@@ -76,9 +79,10 @@
#include <QTimer>
#include <QDebug>
#ifndef TEST_QNETWORK_PROXY
-#define TEST_QNETWORK_PROXY
+//#define TEST_QNETWORK_PROXY
#endif
-#ifdef TEST_QNETWORK_PROXY
+#if defined(TEST_QNETWORK_PROXY) || defined (Q_CC_RVCT)
+// RVCT compiles also unused inline methods
# include <QNetworkProxy>
#endif
@@ -247,6 +251,7 @@ int tst_QTcpSocket::loopLevel = 0;
tst_QTcpSocket::tst_QTcpSocket()
{
+ Q_SET_DEFAULT_IAP
tmpSocket = 0;
}
@@ -899,8 +904,12 @@ void tst_QTcpSocket::disconnectWhileConnecting()
socket->disconnectFromHost();
}
- connect(socket, SIGNAL(disconnected()), SLOT(exitLoopSlot()));
+ connect(socket, SIGNAL(disconnected()), SLOT(exitLoopSlot()));
+#ifndef Q_OS_SYMBIAN
enterLoop(10);
+#else
+ enterLoop(30);
+#endif
QVERIFY2(!timeout(), "Network timeout");
QVERIFY(socket->state() == QAbstractSocket::UnconnectedState);
if (!closeDirectly) {
@@ -935,7 +944,7 @@ public:
: server(0), ok(false), quit(false)
{ }
- ~ReceiverThread() { wait(); delete server; }
+ ~ReceiverThread() { /*delete server;*/ terminate(); wait(); }
bool listen()
{
@@ -960,7 +969,11 @@ protected:
QTcpSocket *socket = server->nextPendingConnection();
while (!quit) {
+#ifndef Q_OS_SYMBIAN
if (socket->waitForDisconnected(500))
+#else
+ if (socket->waitForDisconnected(1000))
+#endif
break;
if (socket->error() != QAbstractSocket::SocketTimeoutError)
return;
@@ -1008,7 +1021,11 @@ void tst_QTcpSocket::disconnectWhileConnectingNoEventLoop()
socket->disconnectFromHost();
}
+#ifndef Q_OS_SYMBIAN
QVERIFY2(socket->waitForDisconnected(10000), "Network timeout");
+#else
+ QVERIFY2(socket->waitForDisconnected(20000), "Network timeout");
+#endif
QVERIFY(socket->state() == QAbstractSocket::UnconnectedState);
if (!closeDirectly) {
QCOMPARE(int(socket->openMode()), int(QIODevice::ReadWrite));
@@ -1054,7 +1071,11 @@ void tst_QTcpSocket::disconnectWhileLookingUp()
// let anything queued happen
QEventLoop loop;
+#ifndef Q_OS_SYMBIAN
QTimer::singleShot(50, &loop, SLOT(quit()));
+#else
+ QTimer::singleShot(500, &loop, SLOT(quit()));
+#endif
loop.exec();
// recheck
@@ -1159,13 +1180,13 @@ void tst_QTcpSocket::readLine()
QVERIFY(socket->waitForReadyRead(10000));
char buffer[1024];
- QCOMPARE(socket->readLine(buffer, sizeof(buffer)), qint64(161));
+ int expectedReplySize = QtNetworkSettings::expectedReplyIMAP().size();
+ ASSERT(expectedReplySize >= 3);
+ QCOMPARE(socket->readLine(buffer, sizeof(buffer)), qint64(expectedReplySize));
- // * OK fluke Cyrus IMAP4 v2.2.12 server ready__
-// // 01234567890123456789012345678901234567890123456789
- QCOMPARE((int) buffer[159], (int) '\r');
- QCOMPARE((int) buffer[160], (int) '\n');
- QCOMPARE((int) buffer[161], (int) '\0');
+ QCOMPARE((int) buffer[expectedReplySize-2], (int) '\r');
+ QCOMPARE((int) buffer[expectedReplySize-1], (int) '\n');
+ QCOMPARE((int) buffer[expectedReplySize], (int) '\0');
QCOMPARE(socket->write("1 NOOP\r\n"), qint64(8));
@@ -1203,7 +1224,7 @@ void tst_QTcpSocket::readLineString()
QVERIFY(socket->waitForReadyRead(10000));
QByteArray arr = socket->readLine();
- QCOMPARE(arr, expected);
+ QCOMPARE(arr, QtNetworkSettings::expectedReplyIMAP());
delete socket;
}
@@ -1431,9 +1452,7 @@ void tst_QTcpSocket::socketInAThread()
TestThread thread;
thread.start();
QVERIFY(thread.wait(15000));
- QCOMPARE(thread.data(),
-// QByteArray("220 (vsFTPd 2.0.4)\r\n221 Goodbye.\r\n"));
- QByteArray("220 (vsFTPd 2.0.5)\r\n221 Goodbye.\r\n"));
+ QCOMPARE(thread.data(), QtNetworkSettings::expectedReplyFtp());
}
}
@@ -1453,12 +1472,9 @@ void tst_QTcpSocket::socketsInThreads()
QVERIFY(thread3.wait(15000));
QVERIFY(thread1.wait(15000));
- QCOMPARE(thread1.data(),
- QByteArray("220 (vsFTPd 2.0.5)\r\n221 Goodbye.\r\n"));
- QCOMPARE(thread2.data(),
- QByteArray("220 (vsFTPd 2.0.5)\r\n221 Goodbye.\r\n"));
- QCOMPARE(thread3.data(),
- QByteArray("220 (vsFTPd 2.0.5)\r\n221 Goodbye.\r\n"));
+ QCOMPARE(thread1.data(),QtNetworkSettings::expectedReplyFtp());
+ QCOMPARE(thread2.data(),QtNetworkSettings::expectedReplyFtp());
+ QCOMPARE(thread3.data(),QtNetworkSettings::expectedReplyFtp());
}
}
@@ -1715,7 +1731,6 @@ public slots:
#ifndef Q_OS_WIN
void tst_QTcpSocket::waitForConnectedInHostLookupSlot2()
{
-
Foo foo;
QPushButton top("Go", 0);
top.show();
@@ -1729,7 +1744,7 @@ void tst_QTcpSocket::waitForConnectedInHostLookupSlot2()
QFAIL("Network timeout");
QVERIFY(foo.attemptedToConnect);
- QCOMPARE(foo.count, 1);
+ QCOMPARE(foo.count, 1);
}
#endif
@@ -1749,7 +1764,16 @@ void tst_QTcpSocket::readyReadSignalsAfterWaitForReadyRead()
QCOMPARE(readyReadSpy.count(), 1);
QString s = socket->readLine();
- 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");
+#ifdef TEST_QNETWORK_PROXY
+ QNetworkProxy::ProxyType proxyType = QNetworkProxy::applicationProxy().type();
+ if(proxyType == QNetworkProxy::NoProxy) {
+ QCOMPARE(s.toLatin1().constData(), "* OK [CAPABILITY IMAP4REV1] aspiriniks Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
+ } else {
+ QCOMPARE(s.toLatin1().constData(), "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] aspiriniks Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
+ }
+#else
+ QCOMPARE(s.toLatin1().constData(), QtNetworkSettings::expectedReplyIMAP().constData());
+#endif
QCOMPARE(socket->bytesAvailable(), qint64(0));
QCoreApplication::instance()->processEvents();
@@ -1967,6 +1991,8 @@ void tst_QTcpSocket::suddenRemoteDisconnect()
{
#if defined(Q_OS_WINCE)
QSKIP("stressTest subprocess needs Qt3Support", SkipAll);
+#elif defined( Q_OS_SYMBIAN )
+ QSKIP("Symbian: QProcess IO is not yet supported, fix when supported", SkipAll);
#else
QFETCH(QString, client);
QFETCH(QString, server);
@@ -2181,11 +2207,13 @@ void tst_QTcpSocket::invalidProxy_data()
QTest::newRow("no-such-host-http") << int(QNetworkProxy::HttpProxy)
<< "this-host-will-never-exist.troll.no" << 3128 << false
<< int(QAbstractSocket::ProxyNotFoundError);
-
+#if !defined(Q_OS_SYMBIAN)
+ //QSKIP("On Symbian Emulator not clear what to expect + server settings", SkipAll);
QTest::newRow("http-on-socks5") << int(QNetworkProxy::HttpProxy) << fluke << 1080 << false
<< int(QAbstractSocket::ProxyConnectionClosedError);
QTest::newRow("socks5-on-http") << int(QNetworkProxy::Socks5Proxy) << fluke << 3128 << false
<< int(QAbstractSocket::SocketTimeoutError);
+#endif
}
void tst_QTcpSocket::invalidProxy()
@@ -2341,5 +2369,6 @@ void tst_QTcpSocket::proxyFactory()
}
#endif
+
QTEST_MAIN(tst_QTcpSocket)
#include "tst_qtcpsocket.moc"