summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2010-10-06 11:46:15 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2010-10-06 11:46:49 (GMT)
commit83b4cad278e2c3b0ca16affc76a82ddce9d6149a (patch)
treebebee452460a8a2f0562bf90dd24070b5033df48 /tests/auto
parentccd3f663c8c96e266b173a6f825bccec830007e1 (diff)
downloadQt-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')
-rw-r--r--tests/auto/qtcpserver/tst_qtcpserver.cpp53
-rw-r--r--tests/auto/qtcpsocket/tst_qtcpsocket.cpp15
2 files changed, 61 insertions, 7 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"
diff --git a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
index 5b77006..2dbe5b7 100644
--- a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
@@ -2505,6 +2505,7 @@ void tst_QTcpSocket::proxyFactory()
delete socket;
}
+// there is a similar test inside tst_qtcpserver that uses the event loop instead
void tst_QTcpSocket::qtbug14268_peek()
{
QFETCH_GLOBAL(bool, setProxy);
@@ -2519,22 +2520,22 @@ void tst_QTcpSocket::qtbug14268_peek()
QVERIFY(incoming->state() == QTcpSocket::ConnectedState);
QVERIFY(outgoing->state() == QTcpSocket::ConnectedState);
- outgoing->write("abc");
+ outgoing->write("abc\n");
QVERIFY(outgoing->waitForBytesWritten(2000));
QVERIFY(incoming->waitForReadyRead(2000));
- QVERIFY(incoming->peek(128*1024) == QByteArray("abc"));
+ QVERIFY(incoming->peek(128*1024) == QByteArray("abc\n"));
- outgoing->write("def");
+ outgoing->write("def\n");
QVERIFY(outgoing->waitForBytesWritten(2000));
QVERIFY(incoming->waitForReadyRead(2000));
- QVERIFY(incoming->peek(128*1024) == QByteArray("abcdef"));
+ QVERIFY(incoming->peek(128*1024) == QByteArray("abc\ndef\n"));
- outgoing->write("ghi");
+ outgoing->write("ghi\n");
QVERIFY(outgoing->waitForBytesWritten(2000));
QVERIFY(incoming->waitForReadyRead(2000));
- QVERIFY(incoming->peek(128*1024) == QByteArray("abcdefghi"));
+ QVERIFY(incoming->peek(128*1024) == QByteArray("abc\ndef\nghi\n"));
- QVERIFY(incoming->read(128*1024) == QByteArray("abcdefghi"));
+ QVERIFY(incoming->read(128*1024) == QByteArray("abc\ndef\nghi\n"));
}