Remove QtWidgets dependency from QTcpSocket autotest

QMessageBox was being used to test nested event loops. This has been
changed to use QEventLoop directly.
Also, there was an unnecessary use of QPushButton to trigger a test
case, which has been removed.

As a result, 3 test cases can be run on VXWORKS, and one more test case
on Windows that were previously skipped.

Change-Id: Ic65ed441cd37d242f89df3ef3b8638a1458d9cf3
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
This commit is contained in:
Shane Kearns 2011-12-08 15:04:45 +00:00 committed by Qt by Nokia
parent 002cb5d2c8
commit 2c4879a767
3 changed files with 12 additions and 33 deletions

View File

@ -1,6 +1,6 @@
HEADERS += Test.h
SOURCES += main.cpp Test.cpp
QT += network
QT = core network testlib
CONFIG -= app_bundle
CONFIG += console

View File

@ -1,7 +1,6 @@
CONFIG += testcase
QT += widgets testlib
QT += core-private network-private
QT = core-private network-private testlib
SOURCES += ../tst_qtcpsocket.cpp
win32: {
wince*: {
@ -10,8 +9,6 @@ wince*: {
LIBS += -lws2_32
}
}
QT += network
vxworks:QT -= gui
TARGET = tst_qtcpsocket

View File

@ -63,10 +63,6 @@
#include <QHostAddress>
#include <QHostInfo>
#include <QMap>
#ifndef Q_OS_VXWORKS
#include <QMessageBox>
#include <QPushButton>
#endif
#include <QPointer>
#include <QProcess>
#include <QStringList>
@ -175,7 +171,7 @@ private slots:
void socketsInThreads();
void waitForReadyReadInASlot();
void remoteCloseError();
void openMessageBoxInErrorSlot();
void nestedEventLoopInErrorSlot();
#ifndef Q_OS_WIN
void connectToLocalHostNoService();
#endif
@ -217,7 +213,7 @@ protected slots:
void downloadBigFileSlot();
void recursiveReadyReadSlot();
void waitForReadyReadInASlotSlot();
void messageBoxSlot();
void enterLoopSlot();
void hostLookupSlot();
void abortiveClose_abortSlot();
void remoteCloseErrorSlot();
@ -1829,35 +1825,29 @@ void tst_QTcpSocket::remoteCloseErrorSlot()
static_cast<QTcpSocket *>(sender())->close();
}
void tst_QTcpSocket::messageBoxSlot()
void tst_QTcpSocket::enterLoopSlot()
{
#if !defined(Q_OS_VXWORKS) // no gui
QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
socket->deleteLater();
QMessageBox box;
QTimer::singleShot(100, &box, SLOT(close()));
// This should not delete the socket
box.exec();
// enter nested event loop
QEventLoop loop;
QTimer::singleShot(100, &loop, SLOT(quit()));
loop.exec();
// Fire a non-0 singleshot to leave time for the delete
QTimer::singleShot(250, this, SLOT(exitLoopSlot()));
#endif
}
//----------------------------------------------------------------------------------
void tst_QTcpSocket::openMessageBoxInErrorSlot()
void tst_QTcpSocket::nestedEventLoopInErrorSlot()
{
#if defined(Q_OS_VXWORKS) // no gui
QSKIP("no default gui available on VxWorks");
#else
QTcpSocket *socket = newSocket();
QPointer<QTcpSocket> p(socket);
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(messageBoxSlot()));
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(enterLoopSlot()));
socket->connectToHost("hostnotfoundhostnotfound.troll.no", 9999); // Host not found, fyi
enterLoop(30);
QVERIFY(!p);
#endif
}
//----------------------------------------------------------------------------------
@ -1981,16 +1971,9 @@ public slots:
//----------------------------------------------------------------------------------
void tst_QTcpSocket::waitForConnectedInHostLookupSlot2()
{
#if defined(Q_OS_WIN) || defined(Q_OS_VXWORKS)
QSKIP("waitForConnectedInHostLookupSlot2 is not run on Windows and VxWorks");
#else
Foo foo;
QPushButton top("Go", 0);
top.show();
connect(&top, SIGNAL(clicked()), &foo, SLOT(doIt()));
QTimer::singleShot(100, &top, SLOT(animateClick()));
QTimer::singleShot(100, &foo, SLOT(doIt()));
QTimer::singleShot(5000, &foo, SLOT(exitLoop()));
enterLoop(30);
@ -1999,7 +1982,6 @@ void tst_QTcpSocket::waitForConnectedInHostLookupSlot2()
QVERIFY(foo.attemptedToConnect);
QCOMPARE(foo.count, 1);
#endif
}
//----------------------------------------------------------------------------------