diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-08-07 03:00:18 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-08-07 03:00:18 +0200 |
commit | edf368405a26cb4c68913abb77a2a3614e79b4f8 (patch) | |
tree | b793317458bc0c307fdeb892380937e41139c042 /tests/auto | |
parent | b8c8bb67342b83091a4066ba6f45e150330cb0ac (diff) | |
parent | cf41cd16a1f156d68f9cb4a84dd77230f29d739f (diff) | |
download | qtwebsockets-edf368405a26cb4c68913abb77a2a3614e79b4f8.tar.gz |
Merge remote-tracking branch 'origin/5.11' into dev
Change-Id: Iffe66da51d3b7b38d04ca3c185b3b003b157f886
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp b/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp index e80eeb1..4dc60c7 100644 --- a/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp +++ b/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp @@ -143,6 +143,7 @@ private Q_SLOTS: #ifndef QT_NO_NETWORKPROXY void tst_setProxy(); #endif + void overlongCloseReason(); }; tst_QWebSocket::tst_QWebSocket() @@ -732,6 +733,34 @@ void tst_QWebSocket::tst_setProxy() socket.setProxy(proxy); QCOMPARE(socket.proxy(), proxy); } + +void tst_QWebSocket::overlongCloseReason() +{ + EchoServer echoServer; + + QWebSocket socket; + + //should return 0 because socket is not open yet + QCOMPARE(socket.sendTextMessage(QStringLiteral("1234")), 0); + + QSignalSpy socketConnectedSpy(&socket, SIGNAL(connected())); + QSignalSpy socketDisconnectedSpy(&socket, SIGNAL(disconnected())); + QSignalSpy serverConnectedSpy(&echoServer, SIGNAL(newConnection(QUrl))); + + QUrl url = QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() + + QStringLiteral(":") + QString::number(echoServer.port())); + socket.open(url); + QTRY_COMPARE(socketConnectedSpy.count(), 1); + QTRY_COMPARE(serverConnectedSpy.count(), 1); + + const QString reason(200, QChar::fromLatin1('a')); + socket.close(QWebSocketProtocol::CloseCodeGoingAway, reason); + QCOMPARE(socket.closeCode(), QWebSocketProtocol::CloseCodeGoingAway); + // Max length of a control frame is 125, but 2 bytes are used for the close code: + QCOMPARE(socket.closeReason().length(), 123); + QCOMPARE(socket.closeReason(), reason.leftRef(123)); + QTRY_COMPARE(socketDisconnectedSpy.count(), 1); +} #endif // QT_NO_NETWORKPROXY QTEST_MAIN(tst_QWebSocket) |