diff options
author | Markus Goetz <Markus.Goetz@nokia.com> | 2010-10-06 11:46:15 (GMT) |
---|---|---|
committer | Markus Goetz <Markus.Goetz@nokia.com> | 2010-10-06 11:46:49 (GMT) |
commit | 83b4cad278e2c3b0ca16affc76a82ddce9d6149a (patch) | |
tree | bebee452460a8a2f0562bf90dd24070b5033df48 /tests/auto/qtcpserver | |
parent | ccd3f663c8c96e266b173a6f825bccec830007e1 (diff) | |
download | Qt-83b4cad278e2c3b0ca16affc76a82ddce9d6149a.zip Qt-83b4cad278e2c3b0ca16affc76a82ddce9d6149a.tar.gz Qt-83b4cad278e2c3b0ca16affc76a82ddce9d6149a.tar.bz2 |
tst_qtcpserver: Another attempt to reproduce QTBUG-14268
The test (un)fortunately passes :-)
Task-number: QTBUG-14268
Diffstat (limited to 'tests/auto/qtcpserver')
-rw-r--r-- | tests/auto/qtcpserver/tst_qtcpserver.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/auto/qtcpserver/tst_qtcpserver.cpp b/tests/auto/qtcpserver/tst_qtcpserver.cpp index b2151b9..ab2a32d 100644 --- a/tests/auto/qtcpserver/tst_qtcpserver.cpp +++ b/tests/auto/qtcpserver/tst_qtcpserver.cpp @@ -105,6 +105,8 @@ private slots: void invalidProxy(); void proxyFactory_data(); void proxyFactory(); + + void qtbug14268_peek(); }; // Testing get/set functions @@ -662,5 +664,56 @@ void tst_QTcpServer::proxyFactory() QTEST(int(server.serverError()), "expectedError"); } +class Qtbug14268Helper : public QObject +{ + Q_OBJECT +public: + QByteArray lastDataPeeked; +public slots: + void newConnection() { + QTcpServer* server=static_cast<QTcpServer*>(sender()); + QTcpSocket* s=server->nextPendingConnection(); + connect(s,SIGNAL(readyRead()),this,SLOT(onServerReadyRead())); + } + void onServerReadyRead() { + QTcpSocket* clientSocket=static_cast<QTcpSocket*>(sender()); + lastDataPeeked = clientSocket->peek(128*1024).toHex(); + QTestEventLoop::instance().exitLoop(); + } +}; + +// there is a similar test inside tst_qtcpsocket that uses the waitFor* functions instead +void tst_QTcpServer::qtbug14268_peek() +{ + QFETCH_GLOBAL(bool, setProxy); + if (setProxy) + return; + + QTcpServer server; + server.listen(); + + Qtbug14268Helper helper; + QObject::connect(&server, SIGNAL(newConnection()), &helper, SLOT(newConnection())); + + QTcpSocket client; + client.connectToHost(QHostAddress::LocalHost, server.serverPort()); + QVERIFY(client.waitForConnected(2000)); + + client.write("abc\n"); + QTestEventLoop::instance().enterLoop(5); + QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(helper.lastDataPeeked == QByteArray("6162630a")); + + client.write("def\n"); + QTestEventLoop::instance().enterLoop(5); + QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(helper.lastDataPeeked == QByteArray("6162630a6465660a")); + + client.write("ghi\n"); + QTestEventLoop::instance().enterLoop(5); + QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(helper.lastDataPeeked == QByteArray("6162630a6465660a6768690a")); +} + QTEST_MAIN(tst_QTcpServer) #include "tst_qtcpserver.moc" |