diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-10-15 16:40:37 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-10-15 16:40:52 +0200 |
commit | 539d5597491893c939c7a05ff4d45261e949e9ce (patch) | |
tree | 7c3aaeec1f082b3269f54ef2dc436ac704b3fc8f /tests/auto/websockets | |
parent | 432b75517cba65e8ab633a2fe0d53f18abd59426 (diff) | |
parent | c2b7d3dc209fe6652571f1dcdd78fb92155e7b8b (diff) | |
download | qtwebsockets-539d5597491893c939c7a05ff4d45261e949e9ce.tar.gz |
Merge remote-tracking branch 'origin/dev' into wip/cmake
Removed dependencies.yaml.
Change-Id: Ie799709d6a94054ca937c70a73fd979efb9619f7
Diffstat (limited to 'tests/auto/websockets')
4 files changed, 112 insertions, 12 deletions
diff --git a/tests/auto/websockets/dataprocessor/tst_dataprocessor.cpp b/tests/auto/websockets/dataprocessor/tst_dataprocessor.cpp index f9a91d5..5390ff0 100644 --- a/tests/auto/websockets/dataprocessor/tst_dataprocessor.cpp +++ b/tests/auto/websockets/dataprocessor/tst_dataprocessor.cpp @@ -193,7 +193,7 @@ private: //sequences void nonCharacterSequence(const char *sequence); - void doTest(); + void doTest(int timeout = 0); void doCloseFrameTest(); QString opCodeToString(quint8 opCode); @@ -744,6 +744,7 @@ void tst_DataProcessor::frameTooSmall() dataProcessor.process(&buffer); + QTRY_VERIFY_WITH_TIMEOUT(errorSpy.count(), 7000); QCOMPARE(errorSpy.count(), 1); QCOMPARE(closeSpy.count(), 0); QCOMPARE(pingMessageSpy.count(), 0); @@ -776,6 +777,7 @@ void tst_DataProcessor::frameTooSmall() dataProcessor.process(&buffer); + QTRY_VERIFY_WITH_TIMEOUT(errorSpy.count(), 7000); QCOMPARE(errorSpy.count(), 1); QCOMPARE(closeSpy.count(), 0); QCOMPARE(pingMessageSpy.count(), 0); @@ -808,6 +810,24 @@ void tst_DataProcessor::frameTooSmall() dataProcessor.process(&buffer); + QTRY_VERIFY_WITH_TIMEOUT(errorSpy.count(), 7000); + QCOMPARE(errorSpy.count(), 1); + QCOMPARE(closeSpy.count(), 0); + QCOMPARE(pingMessageSpy.count(), 0); + QCOMPARE(pongMessageSpy.count(), 0); + QCOMPARE(textMessageSpy.count(), 0); + QCOMPARE(binaryMessageSpy.count(), 0); + QCOMPARE(textFrameSpy.count(), 1); + QCOMPARE(binaryFrameSpy.count(), 0); + + errorSpy.clear(); + closeSpy.clear(); + pingMessageSpy.clear(); + pongMessageSpy.clear(); + textMessageSpy.clear(); + binaryMessageSpy.clear(); + textFrameSpy.clear(); + binaryFrameSpy.clear(); buffer.close(); data.clear(); @@ -816,17 +836,16 @@ void tst_DataProcessor::frameTooSmall() //meaning the socket will be closed buffer.setData(data); buffer.open(QIODevice::ReadOnly); - QSignalSpy errorSpy(&dataProcessor, - SIGNAL(errorEncountered(QWebSocketProtocol::CloseCode,QString))); dataProcessor.process(&buffer); + QTRY_VERIFY_WITH_TIMEOUT(errorSpy.count(), 7000); QCOMPARE(errorSpy.count(), 1); QCOMPARE(closeSpy.count(), 0); QCOMPARE(pingMessageSpy.count(), 0); QCOMPARE(pongMessageSpy.count(), 0); QCOMPARE(textMessageSpy.count(), 0); QCOMPARE(binaryMessageSpy.count(), 0); - QCOMPARE(textFrameSpy.count(), 1); + QCOMPARE(textFrameSpy.count(), 0); QCOMPARE(binaryFrameSpy.count(), 0); QList<QVariant> arguments = errorSpy.takeFirst(); @@ -849,6 +868,7 @@ void tst_DataProcessor::frameTooSmall() buffer.open(QIODevice::ReadOnly); dataProcessor.process(&buffer); + QTRY_VERIFY_WITH_TIMEOUT(errorSpy.count(), 7000); QCOMPARE(errorSpy.count(), 1); QCOMPARE(closeSpy.count(), 0); QCOMPARE(pingMessageSpy.count(), 0); @@ -877,6 +897,7 @@ void tst_DataProcessor::frameTooSmall() buffer.open(QIODevice::ReadOnly); dataProcessor.process(&buffer); + QTRY_VERIFY_WITH_TIMEOUT(errorSpy.count(), 7000); QCOMPARE(errorSpy.count(), 1); QCOMPARE(closeSpy.count(), 0); QCOMPARE(pingMessageSpy.count(), 0); @@ -1400,7 +1421,7 @@ void tst_DataProcessor::incompletePayload_data() void tst_DataProcessor::incompletePayload() { - doTest(); + doTest(7000); } void tst_DataProcessor::incompleteSizeField_data() @@ -1430,13 +1451,13 @@ void tst_DataProcessor::incompleteSizeField_data() void tst_DataProcessor::incompleteSizeField() { - doTest(); + doTest(7000); } ////////////////////////////////////////////////////////////////////////////////////////// /// HELPER FUNCTIONS ////////////////////////////////////////////////////////////////////////////////////////// -void tst_DataProcessor::doTest() +void tst_DataProcessor::doTest(int timeout) { QFETCH(quint8, firstByte); QFETCH(quint8, secondByte); @@ -1465,6 +1486,7 @@ void tst_DataProcessor::doTest() buffer.setData(data); buffer.open(QIODevice::ReadOnly); dataProcessor.process(&buffer); + QTRY_VERIFY_WITH_TIMEOUT(errorSpy.count(), timeout); QCOMPARE(errorSpy.count(), 1); QCOMPARE(textMessageSpy.count(), 0); QCOMPARE(binaryMessageSpy.count(), 0); diff --git a/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp b/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp index 2bb5d16..71e1262 100644 --- a/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp +++ b/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp @@ -457,12 +457,46 @@ void tst_QWebSocket::tst_sendTextMessage() QVERIFY(isLastFrame); socket.close(); + socketConnectedSpy.clear(); + textMessageReceived.clear(); + textFrameReceived.clear(); - //QTBUG-36762: QWebSocket emits multiplied signals when socket was reopened + // QTBUG-74464 QWebsocket doesn't receive text (binary) message with size > 32 kb + socket.open(url); + + QTRY_COMPARE(socketConnectedSpy.count(), 1); + QCOMPARE(socketError.count(), 0); + QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); + arguments = serverConnectedSpy.takeFirst(); + urlConnected = arguments.at(0).toUrl(); + QCOMPARE(urlConnected, url); + QCOMPARE(socket.bytesToWrite(), 0); + + // transmit a long text message with 1 MB + QString longString(0x100000, 'a'); + socket.sendTextMessage(longString); + QVERIFY(socket.bytesToWrite() > longString.length()); + QVERIFY(textMessageReceived.wait()); + QCOMPARE(socket.bytesToWrite(), 0); + + QCOMPARE(textMessageReceived.count(), 1); + QCOMPARE(binaryMessageReceived.count(), 0); + QCOMPARE(binaryFrameReceived.count(), 0); + arguments = textMessageReceived.takeFirst(); + messageReceived = arguments.at(0).toString(); + QCOMPARE(messageReceived.length(), longString.length()); + QCOMPARE(messageReceived, longString); + + arguments = textFrameReceived.takeLast(); + isLastFrame = arguments.at(1).toBool(); + QVERIFY(isLastFrame); + + socket.close(); socketConnectedSpy.clear(); textMessageReceived.clear(); textFrameReceived.clear(); + //QTBUG-36762: QWebSocket emits multiplied signals when socket was reopened socket.open(QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() + QStringLiteral(":") + QString::number(echoServer.port()))); diff --git a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp index 442196b..c40bb01 100644 --- a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp +++ b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp @@ -116,6 +116,7 @@ private Q_SLOTS: void tst_scheme(); // qtbug-55927 void tst_handleConnection(); void tst_handshakeTimeout(); // qtbug-63312, qtbug-57026 + void multipleFrames(); private: bool m_shouldSkipUnsupportedIpv6Test; @@ -293,6 +294,18 @@ void tst_QWebSocketServer::tst_settersAndGetters() QCOMPARE(sslServer.sslConfiguration(), sslConfiguration); QVERIFY(sslServer.sslConfiguration() != QSslConfiguration::defaultConfiguration()); #endif + + server.setHandshakeTimeout(64); + QCOMPARE(server.handshakeTimeoutMS(), 64); +#if QT_HAS_INCLUDE(<chrono>) + auto expected = std::chrono::milliseconds(64); + QCOMPARE(server.handshakeTimeout(), expected); + + expected = std::chrono::milliseconds(242); + server.setHandshakeTimeout(expected); + QCOMPARE(server.handshakeTimeoutMS(), 242); + QCOMPARE(server.handshakeTimeout(), expected); +#endif } void tst_QWebSocketServer::tst_listening() @@ -823,6 +836,33 @@ void tst_QWebSocketServer::tst_handshakeTimeout() } } +void tst_QWebSocketServer::multipleFrames() +{ + QWebSocketServer server(QString(), QWebSocketServer::NonSecureMode); + QSignalSpy serverConnectionSpy(&server, &QWebSocketServer::newConnection); + QVERIFY(server.listen()); + + QWebSocket socket; + QSignalSpy socketConnectedSpy(&socket, &QWebSocket::connected); + QSignalSpy messageReceivedSpy(&socket, &QWebSocket::binaryMessageReceived); + socket.open(server.serverUrl().toString()); + + QVERIFY(serverConnectionSpy.wait()); + QVERIFY(socketConnectedSpy.wait()); + + auto serverSocket = std::unique_ptr<QWebSocket>(server.nextPendingConnection()); + QVERIFY(serverSocket); + for (int i = 0; i < 10; i++) + serverSocket->sendBinaryMessage(QByteArray("abc")); + if (serverSocket->bytesToWrite()) + QVERIFY(serverSocket->flush()); + + QVERIFY(messageReceivedSpy.wait()); + // Since there's no guarantee the operating system will fit all 10 websocket frames into 1 tcp + // frame, let's just assume it will do at least 2. EXCEPT_FAIL any which doesn't merge any. + QVERIFY2(messageReceivedSpy.count() > 1, "Received only 1 message in the TCP frame!"); +} + QTEST_MAIN(tst_QWebSocketServer) #include "tst_qwebsocketserver.moc" diff --git a/tests/auto/websockets/websocketframe/tst_websocketframe.cpp b/tests/auto/websockets/websocketframe/tst_websocketframe.cpp index 5614df8..6b9aaaf 100644 --- a/tests/auto/websockets/websocketframe/tst_websocketframe.cpp +++ b/tests/auto/websockets/websocketframe/tst_websocketframe.cpp @@ -197,7 +197,8 @@ void tst_WebSocketFrame::tst_copyConstructorAndAssignment() QBuffer buffer(&payload); buffer.open(QIODevice::ReadOnly); - QWebSocketFrame frame = QWebSocketFrame::readFrame(&buffer); + QWebSocketFrame frame; + frame.readFrame(&buffer); buffer.close(); { @@ -330,7 +331,8 @@ void tst_WebSocketFrame::tst_goodFrames() QBuffer buffer; buffer.setData(wireRepresentation); buffer.open(QIODevice::ReadOnly); - QWebSocketFrame frame = QWebSocketFrame::readFrame(&buffer); + QWebSocketFrame frame; + frame.readFrame(&buffer); buffer.close(); QVERIFY(frame.isValid()); QCOMPARE(frame.rsv1(), rsv1); @@ -495,7 +497,8 @@ void tst_WebSocketFrame::tst_invalidFrames() QBuffer buffer; buffer.setData(wireRepresentation); buffer.open(QIODevice::ReadOnly); - QWebSocketFrame frame = QWebSocketFrame::readFrame(&buffer); + QWebSocketFrame frame; + frame.readFrame(&buffer); buffer.close(); QVERIFY(!frame.isValid()); @@ -606,7 +609,8 @@ void tst_WebSocketFrame::tst_malformedFrames() QBuffer buffer; buffer.setData(payload); buffer.open(QIODevice::ReadOnly); - QWebSocketFrame frame = QWebSocketFrame::readFrame(&buffer); + QWebSocketFrame frame; + frame.readFrame(&buffer); buffer.close(); QVERIFY(!frame.isValid()); |