summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@accenture.com>2011-03-01 16:22:33 (GMT)
committerShane Kearns <shane.kearns@accenture.com>2011-03-08 18:48:48 (GMT)
commit9530b97c6024ac69011ceb70dde06f5c71bd31d9 (patch)
tree91609c0e034685a5f6cd3202ed20539281773b42 /tests
parent5a488f8022626e71681ae42662aa9d4785ce6027 (diff)
downloadQt-9530b97c6024ac69011ceb70dde06f5c71bd31d9.zip
Qt-9530b97c6024ac69011ceb70dde06f5c71bd31d9.tar.gz
Qt-9530b97c6024ac69011ceb70dde06f5c71bd31d9.tar.bz2
QTcpSocket autotest fixes
1. Don't crash if qt-test-server isn't found, fail instead 2. symbian: 200ms is too short for the timeout test when using proxies, extended to 1000ms 3. Don't crash when the disconnectWhileConnectingNoEventLoop fails used a QScopedPointer with custom cleanup to shutdown the thread tidily. 4. Fast fail for downloadBigFile test if the connection is lost before the download is complete. This uses the disconnected signal to exit the event loop early. Previously on this type of failure it took 10 minutes for the event loop to time out. Reviewed-by: Markus Goetz
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qtcpsocket/tst_qtcpsocket.cpp33
1 files changed, 21 insertions, 12 deletions
diff --git a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
index 21092c4..b0ecbda 100644
--- a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
@@ -336,7 +336,9 @@ void tst_QTcpSocket::init()
QFETCH_GLOBAL(bool, setProxy);
if (setProxy) {
QFETCH_GLOBAL(int, proxyType);
- QString fluke = QHostInfo::fromName(QtNetworkSettings::serverName()).addresses().first().toString();
+ QList<QHostAddress> addresses = QHostInfo::fromName(QtNetworkSettings::serverName()).addresses();
+ QVERIFY2(addresses.count() > 0, "failed to get ip address for test server");
+ QString fluke = addresses.first().toString();
QNetworkProxy proxy;
switch (proxyType) {
@@ -606,7 +608,7 @@ void tst_QTcpSocket::timeoutConnect()
// Port 1357 is configured to drop packets on the test server
socket->connectToHost(address, 1357);
QVERIFY(timer.elapsed() < 50);
- QVERIFY(!socket->waitForConnected(200));
+ QVERIFY(!socket->waitForConnected(1000)); //200ms is too short when using SOCKS proxy authentication
QCOMPARE(socket->state(), QTcpSocket::UnconnectedState);
QCOMPARE(int(socket->error()), int(QTcpSocket::SocketTimeoutError));
@@ -1035,7 +1037,7 @@ public:
: server(0), ok(false), quit(false)
{ }
- ~ReceiverThread() { /*delete server;*/ terminate(); wait(); }
+ ~ReceiverThread() { }
bool listen()
{
@@ -1047,6 +1049,14 @@ public:
return true;
}
+ static void cleanup(void *ptr)
+ {
+ ReceiverThread* self = reinterpret_cast<ReceiverThread*>(ptr);
+ self->quit = true;
+ self->wait(30000);
+ delete self;
+ }
+
protected:
void run()
{
@@ -1093,18 +1103,16 @@ void tst_QTcpSocket::disconnectWhileConnectingNoEventLoop()
{
QFETCH(QByteArray, data);
- ReceiverThread thread;
- QVERIFY(thread.listen());
- thread.start();
+ QScopedPointer<ReceiverThread, ReceiverThread> thread (new ReceiverThread);
+ QVERIFY(thread->listen());
+ thread->start();
// proceed to the connect-write-disconnect
QTcpSocket *socket = newSocket();
- socket->connectToHost("127.0.0.1", thread.serverPort);
+ socket->connectToHost("127.0.0.1", thread->serverPort);
if (!data.isEmpty())
socket->write(data);
if (socket->state() == QAbstractSocket::ConnectedState) {
- thread.quit = true;
- thread.wait();
QSKIP("localhost connections are immediate, test case is invalid", SkipSingle);
}
@@ -1130,9 +1138,9 @@ void tst_QTcpSocket::disconnectWhileConnectingNoEventLoop()
delete socket;
// check if the other side received everything ok
- QVERIFY(thread.wait(30000));
- QVERIFY(thread.ok);
- QCOMPARE(thread.receivedData, data);
+ QVERIFY(thread->wait(30000));
+ QVERIFY(thread->ok);
+ QCOMPARE(thread->receivedData, data);
}
//----------------------------------------------------------------------------------
@@ -1194,6 +1202,7 @@ void tst_QTcpSocket::downloadBigFile()
connect(tmpSocket, SIGNAL(connected()), SLOT(exitLoopSlot()));
connect(tmpSocket, SIGNAL(readyRead()), SLOT(downloadBigFileSlot()));
+ connect(tmpSocket, SIGNAL(disconnected()), SLOT(exitLoopSlot()));
tmpSocket->connectToHost(QtNetworkSettings::serverName(), 80);