summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2010-10-06 10:46:45 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2010-10-06 10:47:45 (GMT)
commite98962aab2db1c3760b324d6640fa8b510b7e04c (patch)
treeeed971c00dde3b49f593ba723b4d59c7b5f5fb8f /tests
parent8ae162d2cffc1f220cb59df5f6417204e04da2c3 (diff)
downloadQt-e98962aab2db1c3760b324d6640fa8b510b7e04c.zip
Qt-e98962aab2db1c3760b324d6640fa8b510b7e04c.tar.gz
Qt-e98962aab2db1c3760b324d6640fa8b510b7e04c.tar.bz2
tst_qtcpsocket: Attempt to reproduce QTBUG-14268
The test (un)fortunately passes :-) Task-number: QTBUG-14268
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qtcpsocket/tst_qtcpsocket.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
index 31cae40..5b77006 100644
--- a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp
@@ -201,6 +201,9 @@ private slots:
void proxyFactory_data();
void proxyFactory();
+ void qtbug14268_peek();
+
+
protected slots:
void nonBlockingIMAP_hostFound();
void nonBlockingIMAP_connected();
@@ -251,6 +254,41 @@ enum ProxyTests {
int tst_QTcpSocket::loopLevel = 0;
+class SocketPair: public QObject
+{
+ Q_OBJECT
+public:
+ QTcpSocket *endPoints[2];
+
+ SocketPair(QObject *parent = 0)
+ : QObject(parent)
+ {
+ endPoints[0] = endPoints[1] = 0;
+ }
+
+ bool create()
+ {
+ QTcpServer server;
+ server.listen();
+
+ QTcpSocket *active = new QTcpSocket(this);
+ active->connectToHost("127.0.0.1", server.serverPort());
+
+ if (!active->waitForConnected(1000))
+ return false;
+
+ if (!server.waitForNewConnection(1000))
+ return false;
+
+ QTcpSocket *passive = server.nextPendingConnection();
+ passive->setParent(this);
+
+ endPoints[0] = active;
+ endPoints[1] = passive;
+ return true;
+ }
+};
+
tst_QTcpSocket::tst_QTcpSocket()
{
Q_SET_DEFAULT_IAP
@@ -2467,6 +2505,39 @@ void tst_QTcpSocket::proxyFactory()
delete socket;
}
+void tst_QTcpSocket::qtbug14268_peek()
+{
+ QFETCH_GLOBAL(bool, setProxy);
+ if (setProxy)
+ return;
+
+ SocketPair socketPair;
+ QVERIFY(socketPair.create());
+ QTcpSocket *outgoing = socketPair.endPoints[0];
+ QTcpSocket *incoming = socketPair.endPoints[1];
+
+ QVERIFY(incoming->state() == QTcpSocket::ConnectedState);
+ QVERIFY(outgoing->state() == QTcpSocket::ConnectedState);
+
+ outgoing->write("abc");
+ QVERIFY(outgoing->waitForBytesWritten(2000));
+ QVERIFY(incoming->waitForReadyRead(2000));
+ QVERIFY(incoming->peek(128*1024) == QByteArray("abc"));
+
+ outgoing->write("def");
+ QVERIFY(outgoing->waitForBytesWritten(2000));
+ QVERIFY(incoming->waitForReadyRead(2000));
+ QVERIFY(incoming->peek(128*1024) == QByteArray("abcdef"));
+
+ outgoing->write("ghi");
+ QVERIFY(outgoing->waitForBytesWritten(2000));
+ QVERIFY(incoming->waitForReadyRead(2000));
+ QVERIFY(incoming->peek(128*1024) == QByteArray("abcdefghi"));
+
+ QVERIFY(incoming->read(128*1024) == QByteArray("abcdefghi"));
+}
+
+
QTEST_MAIN(tst_QTcpSocket)
#include "tst_qtcpsocket.moc"