summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/socket/qhttpsocketengine
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2016-01-26 11:27:37 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2016-01-26 11:27:37 +0000
commit0a1af55a9b69f7fd58dbce43a0d4c1faf0143838 (patch)
tree26da168e740734d168be37803abec2f8739b213d /tests/auto/network/socket/qhttpsocketengine
parentb8fb0ee999d32401157be8d86e5a03185aadbb9e (diff)
parent158a3a4159bdc5a49caecd63e021dacbc06cf23c (diff)
Merge "Merge remote-tracking branch 'origin/5.6' into dev" into refs/staging/dev
Diffstat (limited to 'tests/auto/network/socket/qhttpsocketengine')
-rw-r--r--tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp b/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp
index b534b249da..7237542e5c 100644
--- a/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp
+++ b/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp
@@ -60,6 +60,7 @@ private slots:
void downloadBigFile();
// void tcpLoopbackPerformance();
void passwordAuth();
+ void ensureEofTriggersNotification();
protected slots:
void tcpSocketNonBlocking_hostFound();
@@ -715,5 +716,51 @@ void tst_QHttpSocketEngine::passwordAuth()
//----------------------------------------------------------------------------------
+void tst_QHttpSocketEngine::ensureEofTriggersNotification()
+{
+ QList<QByteArray> serverData;
+ // Set the handshake and server response data
+ serverData << "HTTP/1.0 200 Connection established\r\n\r\n" << "0";
+ MiniHttpServer server(serverData);
+
+ QTcpSocket socket;
+ connect(&socket, SIGNAL(connected()), SLOT(exitLoopSlot()));
+ socket.setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, server.serverAddress().toString(),
+ server.serverPort()));
+ socket.connectToHost("0.1.2.3", 12345);
+
+ QTestEventLoop::instance().enterLoop(5);
+ if (QTestEventLoop::instance().timeout())
+ QFAIL("Connect timed out");
+
+ QCOMPARE(socket.state(), QTcpSocket::ConnectedState);
+ // Disable read notification on server response
+ socket.setReadBufferSize(1);
+ socket.putChar(0);
+
+ // Wait for the response
+ connect(&socket, SIGNAL(readyRead()), SLOT(exitLoopSlot()));
+ QTestEventLoop::instance().enterLoop(5);
+ if (QTestEventLoop::instance().timeout())
+ QFAIL("Read timed out");
+
+ QCOMPARE(socket.state(), QTcpSocket::ConnectedState);
+ QCOMPARE(socket.bytesAvailable(), 1);
+ // Trigger a read notification
+ socket.readAll();
+ // Check for pending EOF at input
+ QCOMPARE(socket.bytesAvailable(), 0);
+ QCOMPARE(socket.state(), QTcpSocket::ConnectedState);
+
+ // Try to read EOF
+ connect(&socket, SIGNAL(disconnected()), SLOT(exitLoopSlot()));
+ QTestEventLoop::instance().enterLoop(5);
+ if (QTestEventLoop::instance().timeout())
+ QFAIL("Disconnect timed out");
+
+ // Check that it's closed
+ QCOMPARE(socket.state(), QTcpSocket::UnconnectedState);
+}
+
QTEST_MAIN(tst_QHttpSocketEngine)
#include "tst_qhttpsocketengine.moc"