summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@accenture.com>2011-04-07 14:10:31 (GMT)
committerShane Kearns <shane.kearns@accenture.com>2011-04-08 15:25:33 (GMT)
commit847df81a5680fe4d71196d0afe5e68e41ae49700 (patch)
tree6568afeb603433649d7e22f023535cb98cf2f887 /tests/auto
parenta951fb79139498774d021759d0466b4b2ff50e68 (diff)
downloadQt-847df81a5680fe4d71196d0afe5e68e41ae49700.zip
Qt-847df81a5680fe4d71196d0afe5e68e41ae49700.tar.gz
Qt-847df81a5680fe4d71196d0afe5e68e41ae49700.tar.bz2
Implement support for sockets started before the event loop
If there is no event loop when a socket notification is enabled, then invoke the method via a queued connection so that it is run again when the event loop is started. This covers sockets created and having an asynchronous API called before calling QCoreApplication::exec(). Reviewed-by: Markus Goetz
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qtcpsocket/tst_qtcpsocket.cpp45
1 files changed, 44 insertions, 1 deletions
diff --git a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
index 6852e29..623e02b 100644
--- a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
@@ -106,6 +106,7 @@ Q_DECLARE_METATYPE(QList<QNetworkProxy>)
//TESTED_FILES=
QT_FORWARD_DECLARE_CLASS(QTcpSocket)
+QT_FORWARD_DECLARE_CLASS(SocketPair)
class tst_QTcpSocket : public QObject
{
@@ -138,6 +139,7 @@ public slots:
void init();
void cleanup();
private slots:
+ void socketsConstructedBeforeEventLoop();
void constructing();
void setInvalidSocketDescriptor();
void setSocketDescriptor();
@@ -221,6 +223,8 @@ protected slots:
void abortiveClose_abortSlot();
void remoteCloseErrorSlot();
void proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *auth);
+ void earlySocketBytesSent(qint64 bytes);
+ void earlySocketReadyRead();
private:
QByteArray expectedReplyIMAP();
@@ -243,6 +247,10 @@ private:
bool gotClosedSignal;
int numConnections;
static int loopLevel;
+
+ SocketPair *earlyConstructedSockets;
+ int earlyBytesWrittenCount;
+ int earlyReadyReadCount;
};
enum ProxyTests {
@@ -296,8 +304,16 @@ public:
tst_QTcpSocket::tst_QTcpSocket()
{
- Q_SET_DEFAULT_IAP
tmpSocket = 0;
+
+ //This code relates to the socketsConstructedBeforeEventLoop test case
+ earlyConstructedSockets = new SocketPair;
+ QVERIFY(earlyConstructedSockets->create());
+ earlyBytesWrittenCount = 0;
+ earlyReadyReadCount = 0;
+ connect(earlyConstructedSockets->endPoints[0], SIGNAL(readyRead()), this, SLOT(earlySocketReadyRead()));
+ connect(earlyConstructedSockets->endPoints[1], SIGNAL(bytesWritten(qint64)), this, SLOT(earlySocketBytesSent(qint64)));
+ earlyConstructedSockets->endPoints[1]->write("hello work");
}
tst_QTcpSocket::~tst_QTcpSocket()
@@ -399,6 +415,33 @@ void tst_QTcpSocket::proxyAuthenticationRequired(const QNetworkProxy &, QAuthent
//----------------------------------------------------------------------------------
+void tst_QTcpSocket::socketsConstructedBeforeEventLoop()
+{
+ QFETCH_GLOBAL(bool, setProxy);
+ QFETCH_GLOBAL(bool, ssl);
+ if (setProxy || ssl)
+ return;
+ //This test checks that sockets constructed before QCoreApplication::exec() still emit signals
+ //see construction code in the tst_QTcpSocket constructor
+ enterLoop(3);
+ QCOMPARE(earlyBytesWrittenCount, 1);
+ QCOMPARE(earlyReadyReadCount, 1);
+ earlyConstructedSockets->endPoints[0]->close();
+ earlyConstructedSockets->endPoints[1]->close();
+}
+
+void tst_QTcpSocket::earlySocketBytesSent(qint64 bytes)
+{
+ earlyBytesWrittenCount++;
+}
+
+void tst_QTcpSocket::earlySocketReadyRead()
+{
+ earlyReadyReadCount++;
+}
+
+//----------------------------------------------------------------------------------
+
void tst_QTcpSocket::constructing()
{
QTcpSocket *socket = newSocket();