diff options
author | Kurt Pattyn <pattyn.kurt@gmail.com> | 2013-12-22 18:24:21 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-12-23 19:26:09 +0100 |
commit | 23ccec8ce246634799b06f55b85478b3fbbb356d (patch) | |
tree | 7144ceb793362636931c4d26f9cc5f1561672fda /tests | |
parent | 19d8d19af44b9075f745790380c3fe663d8e7fd0 (diff) | |
download | qtwebsockets-23ccec8ce246634799b06f55b85478b3fbbb356d.tar.gz |
Add optimizations
Change-Id: Icd293f832e2d7a6272d4953c1994065d16222375
Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/dataprocessor/tst_dataprocessor.cpp | 350 | ||||
-rw-r--r-- | tests/auto/handshakerequest/tst_handshakerequest.cpp | 91 | ||||
-rw-r--r-- | tests/auto/websocketframe/tst_websocketframe.cpp | 74 | ||||
-rw-r--r-- | tests/auto/websocketprotocol/tst_websocketprotocol.cpp | 19 | ||||
-rw-r--r-- | tests/manual/compliance/tst_compliance.cpp | 2 |
5 files changed, 333 insertions, 203 deletions
diff --git a/tests/auto/dataprocessor/tst_dataprocessor.cpp b/tests/auto/dataprocessor/tst_dataprocessor.cpp index f8c3f77..f99a569 100644 --- a/tests/auto/dataprocessor/tst_dataprocessor.cpp +++ b/tests/auto/dataprocessor/tst_dataprocessor.cpp @@ -47,6 +47,7 @@ #include "private/qwebsocketdataprocessor_p.h" #include "private/qwebsocketprotocol_p.h" +#include "QtWebSockets/qwebsocketprotocol.h" const quint8 FIN = 0x80; const quint8 RSV1 = 0x40; @@ -98,7 +99,11 @@ private Q_SLOTS: void goodCloseFrame(); void goodCloseFrame_data(); - //void goodHeaders(); //test all valid opcodes + /*! + * \brief Test all valid opcodes + */ + void goodOpcodes(); + void goodOpcodes_data(); /*! Tests the QWebSocketDataProcessor for the correct handling of non-charactercodes @@ -226,11 +231,14 @@ void tst_DataProcessor::goodBinaryFrame_data() QTest::addColumn<QByteArray>("payload"); for (int i = 0; i < (65536 + 256); i += 128) //be sure to get small (< 126 bytes), large (> 125 bytes & < 64K) and big (>64K) frames { - QTest::newRow(QString("Binary frame with %1 bytes").arg(i).toStdString().data()) << QByteArray(i, char(1)); + QTest::newRow(QStringLiteral("Binary frame with %1 bytes").arg(i).toLatin1().constData()) + << QByteArray(i, char(1)); } for (int i = 0; i < 256; ++i) //test all possible bytes in the payload { - QTest::newRow(QString("Binary frame containing byte: '0x%1'").arg(QByteArray(1, char(i)).toHex().constData()).toStdString().data()) << QByteArray(i, char(1)); + QTest::newRow(QStringLiteral("Binary frame containing byte: '0x%1'") + .arg(QByteArray(1, char(i)).toHex().constData()).toLatin1().constData()) + << QByteArray(i, char(1)); } } @@ -296,19 +304,23 @@ void tst_DataProcessor::goodTextFrame_data() //test frames with small (< 126), large ( < 65536) and big ( > 65535) payloads for (int i = 0; i < (65536 + 256); i += 128) { - QTest::newRow(QString("Text frame with %1 ASCII characters").arg(i).toStdString().data()) << QByteArray(i, 'a') << i; + QTest::newRow(QStringLiteral("Text frame with %1 ASCII characters").arg(i).toLatin1().constData()) + << QByteArray(i, 'a') << i; } //test all valid ASCII characters for (int i = 0; i < 128; ++i) { - QTest::newRow(QString("Text frame with containing ASCII character '0x%1'").arg(QByteArray(1, char(i)).toHex().constData()).toStdString().data()) << QByteArray(1, char(i)) << 1; + QTest::newRow(QStringLiteral("Text frame with containing ASCII character '0x%1'") + .arg(QByteArray(1, char(i)).toHex().constData()).toLatin1().constData()) + << QByteArray(1, char(i)) << 1; } - //UC 6.2 //the text string reads: Text frame containing Hello-µ@ßöäüàá-UTF-8!! //Visual Studio doesn't like UTF-8 in source code, so we use escape codes for the string //The number 22 refers to the length of the string; the length was incorrectly calculated on Visual Studio - QTest::newRow(QStringLiteral("Text frame containing Hello-\xC2\xB5\x40\xC3\x9F\xC3\xB6\xC3\xA4\xC3\xBC\xC3\xA0\xC3\xA1-UTF-8!!").toStdString().data()) << QByteArray::fromHex("48656c6c6f2dc2b540c39fc3b6c3a4c3bcc3a0c3a12d5554462d382121") << 22; + QTest::newRow(QStringLiteral("Text frame containing Hello-\xC2\xB5\x40\xC3\x9F\xC3\xB6\xC3\xA4\xC3\xBC\xC3\xA0\xC3\xA1-UTF-8!!").toLatin1().constData()) + << QByteArray::fromHex("48656c6c6f2dc2b540c39fc3b6c3a4c3bcc3a0c3a12d5554462d382121") + << 22; } void tst_DataProcessor::goodTextFrame() @@ -424,11 +436,14 @@ void tst_DataProcessor::goodCloseFrame_data() //control frame data cannot exceed 125 bytes; smaller than 124, because we also need a 2 byte close code for (int i = 0; i < 124; ++i) { - QTest::newRow(QString("Close frame with %1 ASCII characters").arg(i).toStdString().data()) << QString(i, 'a') << QWebSocketProtocol::CC_NORMAL; + QTest::newRow(QStringLiteral("Close frame with %1 ASCII characters").arg(i).toLatin1().constData()) + << QString(i, 'a') << QWebSocketProtocol::CC_NORMAL; } for (int i = 0; i < 126; ++i) { - QTest::newRow(QString("Text frame with containing ASCII character '0x%1'").arg(QByteArray(1, char(i)).toHex().constData()).toStdString().data()) << QString(1, char(i)) << QWebSocketProtocol::CC_NORMAL; + QTest::newRow(QStringLiteral("Text frame with containing ASCII character '0x%1'") + .arg(QByteArray(1, char(i)).toHex().constData()).toLatin1().constData()) + << QString(1, char(i)) << QWebSocketProtocol::CC_NORMAL; } QTest::newRow("Close frame with close code NORMAL") << QString(1, 'a') << QWebSocketProtocol::CC_NORMAL; QTest::newRow("Close frame with close code BAD OPERATION") << QString(1, 'a') << QWebSocketProtocol::CC_BAD_OPERATION; @@ -462,6 +477,53 @@ void tst_DataProcessor::goodCloseFrame_data() QTest::newRow("Close frame with no close code and no reason") << QString() << QWebSocketProtocol::CloseCode(0); } +void tst_DataProcessor::goodOpcodes_data() +{ + QTest::addColumn<QWebSocketProtocol::OpCode>("opCode"); + + QTest::newRow("Frame with PING opcode") << QWebSocketProtocol::OC_PING; + QTest::newRow("Frame with PONG opcode") << QWebSocketProtocol::OC_PONG; + QTest::newRow("Frame with TEXT opcode") << QWebSocketProtocol::OC_TEXT; + QTest::newRow("Frame with BINARY opcode") << QWebSocketProtocol::OC_BINARY; + QTest::newRow("Frame with CLOSE opcode") << QWebSocketProtocol::OC_CLOSE; +} + +void tst_DataProcessor::goodOpcodes() +{ + QByteArray data; + QBuffer buffer; + QWebSocketDataProcessor dataProcessor; + QFETCH(QWebSocketProtocol::OpCode, opCode); + + data.append((char)(FIN | opCode)); + data.append(char(0)); //zero length + + buffer.setData(data); + buffer.open(QIODevice::ReadOnly); + + QSignalSpy errorReceivedSpy(&dataProcessor, SIGNAL(errorEncountered(QWebSocketProtocol::CloseCode,QString))); + QSignalSpy closeReceivedSpy(&dataProcessor, SIGNAL(closeReceived(QWebSocketProtocol::CloseCode,QString))); + QSignalSpy pingReceivedSpy(&dataProcessor, SIGNAL(pingReceived(QByteArray))); + QSignalSpy pongReceivedSpy(&dataProcessor, SIGNAL(pongReceived(QByteArray))); + QSignalSpy textFrameReceivedSpy(&dataProcessor, SIGNAL(textFrameReceived(QString,bool))); + QSignalSpy textMessageReceivedSpy(&dataProcessor, SIGNAL(textMessageReceived(QString))); + QSignalSpy binaryFrameReceivedSpy(&dataProcessor, SIGNAL(binaryFrameReceived(QByteArray,bool))); + QSignalSpy binaryMessageReceivedSpy(&dataProcessor, SIGNAL(binaryMessageReceived(QByteArray))); + + dataProcessor.process(&buffer); + + QCOMPARE(errorReceivedSpy.count(), 0); + QCOMPARE(pingReceivedSpy.count(), opCode == QWebSocketProtocol::OC_PING ? 1 : 0); + QCOMPARE(pongReceivedSpy.count(), opCode == QWebSocketProtocol::OC_PONG ? 1 : 0); + QCOMPARE(closeReceivedSpy.count(), opCode == QWebSocketProtocol::OC_CLOSE ? 1 : 0); + QCOMPARE(textFrameReceivedSpy.count(), opCode == QWebSocketProtocol::OC_TEXT ? 1 : 0); + QCOMPARE(textMessageReceivedSpy.count(), opCode == QWebSocketProtocol::OC_TEXT ? 1 : 0); + QCOMPARE(binaryFrameReceivedSpy.count(), opCode == QWebSocketProtocol::OC_BINARY ? 1 : 0); + QCOMPARE(binaryMessageReceivedSpy.count(), opCode == QWebSocketProtocol::OC_BINARY ? 1 : 0); + + buffer.close(); +} + void tst_DataProcessor::goodCloseFrame() { QByteArray data; @@ -857,18 +919,41 @@ void tst_DataProcessor::invalidControlFrame_data() QTest::newRow("Close control frame with payload size 126") - << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << quint8(126) << QByteArray() << false << QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_CLOSE) + << quint8(126) + << QByteArray() + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("Ping control frame with payload size 126") - << quint8(FIN | QWebSocketProtocol::OC_PING) << quint8(126) << QByteArray() << false << QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_PING) + << quint8(126) + << QByteArray() + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("Close control frame with payload size 126") - << quint8(FIN | QWebSocketProtocol::OC_PONG) << quint8(126) << QByteArray() << false << QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_PONG) + << quint8(126) + << QByteArray() + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("Non-final close control frame (fragmented)") - << quint8(QWebSocketProtocol::OC_CLOSE) << quint8(32) << QByteArray() << false << QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(QWebSocketProtocol::OC_CLOSE) + << quint8(32) + << QByteArray() + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("Non-final ping control frame (fragmented)") - << quint8(QWebSocketProtocol::OC_PING) << quint8(32) << QByteArray() << false << QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(QWebSocketProtocol::OC_PING) + << quint8(32) << QByteArray() + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("Non-final pong control frame (fragmented)") - << quint8(QWebSocketProtocol::OC_PONG) << quint8(32) << QByteArray() << false << QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(QWebSocketProtocol::OC_PONG) + << quint8(32) + << QByteArray() + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; } void tst_DataProcessor::invalidControlFrame() @@ -885,123 +970,127 @@ void tst_DataProcessor::invalidCloseFrame_data() QTest::addColumn<QWebSocketProtocol::CloseCode>("expectedCloseCode"); QTest::newRow("Close control frame with payload size 1") - << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << quint8(1) << QByteArray(1, 'a') << false << QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_CLOSE) + << quint8(1) + << QByteArray(1, 'a') + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; quint16 swapped = qToBigEndian<quint16>(QWebSocketProtocol::CC_ABNORMAL_DISCONNECTION); const char *wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped)); //Not allowed per RFC 6455 (see para 7.4.1) QTest::newRow("Close control frame close code ABNORMAL DISCONNECTION") - << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << - quint8(2) << - QByteArray(wireRepresentation, 2) << - false << - QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_CLOSE) + << quint8(2) + << QByteArray(wireRepresentation, 2) + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; swapped = qToBigEndian<quint16>(QWebSocketProtocol::CC_MISSING_STATUS_CODE); wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped)); //Not allowed per RFC 6455 (see para 7.4.1) QTest::newRow("Close control frame close code MISSING STATUS CODE") - << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << - quint8(2) << - QByteArray(wireRepresentation, 2) << - false << - QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_CLOSE) + << quint8(2) + << QByteArray(wireRepresentation, 2) + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; swapped = qToBigEndian<quint16>(1004); wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped)); QTest::newRow("Close control frame close code 1004") - << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << - quint8(2) << - QByteArray(wireRepresentation, 2) << - false << - QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_CLOSE) + << quint8(2) + << QByteArray(wireRepresentation, 2) + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; swapped = qToBigEndian<quint16>(QWebSocketProtocol::CC_TLS_HANDSHAKE_FAILED); wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped)); //Not allowed per RFC 6455 (see para 7.4.1) QTest::newRow("Close control frame close code TLS HANDSHAKE FAILED") - << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << - quint8(2) << - QByteArray(wireRepresentation, 2) << - false << - QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_CLOSE) + << quint8(2) + << QByteArray(wireRepresentation, 2) + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; swapped = qToBigEndian<quint16>(0); wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped)); QTest::newRow("Close control frame close code 0") - << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << - quint8(2) << - QByteArray(wireRepresentation, 2) << - false << - QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_CLOSE) + << quint8(2) + << QByteArray(wireRepresentation, 2) + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; swapped = qToBigEndian<quint16>(999); wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped)); QTest::newRow("Close control frame close code 999") - << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << - quint8(2) << - QByteArray(wireRepresentation, 2) << - false << - QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_CLOSE) + << quint8(2) + << QByteArray(wireRepresentation, 2) + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; swapped = qToBigEndian<quint16>(1012); wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped)); QTest::newRow("Close control frame close code 1012") - << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << - quint8(2) << - QByteArray(wireRepresentation, 2) << - false << - QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_CLOSE) + << quint8(2) + << QByteArray(wireRepresentation, 2) + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; swapped = qToBigEndian<quint16>(1013); wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped)); QTest::newRow("Close control frame close code 1013") - << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << - quint8(2) << - QByteArray(wireRepresentation, 2) << - false << - QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_CLOSE) + << quint8(2) + << QByteArray(wireRepresentation, 2) + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; swapped = qToBigEndian<quint16>(1014); wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped)); QTest::newRow("Close control frame close code 1014") - << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << - quint8(2) << - QByteArray(wireRepresentation, 2) << - false << - QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_CLOSE) + << quint8(2) + << QByteArray(wireRepresentation, 2) + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; swapped = qToBigEndian<quint16>(1100); wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped)); QTest::newRow("Close control frame close code 1100") - << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << - quint8(2) << - QByteArray(wireRepresentation, 2) << - false << - QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_CLOSE) + << quint8(2) + << QByteArray(wireRepresentation, 2) + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; swapped = qToBigEndian<quint16>(2000); wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped)); QTest::newRow("Close control frame close code 2000") - << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << - quint8(2) << - QByteArray(wireRepresentation, 2) << - false << - QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_CLOSE) + << quint8(2) + << QByteArray(wireRepresentation, 2) + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; swapped = qToBigEndian<quint16>(2999); wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped)); QTest::newRow("Close control frame close code 2999") - << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << - quint8(2) << - QByteArray(wireRepresentation, 2) << - false << - QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_CLOSE) + << quint8(2) + << QByteArray(wireRepresentation, 2) + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; swapped = qToBigEndian<quint16>(5000); wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped)); QTest::newRow("Close control frame close code 5000") - << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << - quint8(2) << - QByteArray(wireRepresentation, 2) << - false << - QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_CLOSE) + << quint8(2) + << QByteArray(wireRepresentation, 2) + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; swapped = qToBigEndian<quint16>(65535u); wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped)); QTest::newRow("Close control frame close code 65535") - << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << - quint8(2) << - QByteArray(wireRepresentation, 2) << - false << - QWebSocketProtocol::CC_PROTOCOL_ERROR; + << quint8(FIN | QWebSocketProtocol::OC_CLOSE) + << quint8(2) + << QByteArray(wireRepresentation, 2) + << false + << QWebSocketProtocol::CC_PROTOCOL_ERROR; } void tst_DataProcessor::invalidCloseFrame() @@ -1243,15 +1332,11 @@ void tst_DataProcessor::incompleteSizeField_data() QTest::addColumn<bool>("isContinuationFrame"); QTest::addColumn<QWebSocketProtocol::CloseCode>("expectedCloseCode"); - ////////////////////////////////////////////////////////////////////////////////////////////////// //for a frame length value of 126, there should be 2 bytes following to form a 16-bit frame length - ////////////////////////////////////////////////////////////////////////////////////////////////// insertIncompleteSizeFieldTest(126, 0); insertIncompleteSizeFieldTest(126, 1); - ////////////////////////////////////////////////////////////////////////////////////////////////// //for a frame length value of 127, there should be 8 bytes following to form a 64-bit frame length - ////////////////////////////////////////////////////////////////////////////////////////////////// insertIncompleteSizeFieldTest(127, 0); insertIncompleteSizeFieldTest(127, 1); insertIncompleteSizeFieldTest(127, 2); @@ -1351,82 +1436,82 @@ QString tst_DataProcessor::opCodeToString(quint8 opCode) { case QWebSocketProtocol::OC_BINARY: { - frameType = "Binary"; + frameType = QStringLiteral("Binary"); break; } case QWebSocketProtocol::OC_TEXT: { - frameType = "Text"; + frameType = QStringLiteral("Text"); break; } case QWebSocketProtocol::OC_PING: { - frameType = "Ping"; + frameType = QStringLiteral("Ping"); break; } case QWebSocketProtocol::OC_PONG: { - frameType = "Pong"; + frameType = QStringLiteral("Pong"); break; } case QWebSocketProtocol::OC_CLOSE: { - frameType = "Close"; + frameType = QStringLiteral("Close"); break; } case QWebSocketProtocol::OC_CONTINUE: { - frameType = "Continuation"; + frameType = QStringLiteral("Continuation"); break; } case QWebSocketProtocol::OC_RESERVED_3: { - frameType = "Reserved3"; + frameType = QStringLiteral("Reserved3"); break; } case QWebSocketProtocol::OC_RESERVED_4: { - frameType = "Reserved5"; + frameType = QStringLiteral("Reserved5"); break; } case QWebSocketProtocol::OC_RESERVED_5: { - frameType = "Reserved5"; + frameType = QStringLiteral("Reserved5"); break; } case QWebSocketProtocol::OC_RESERVED_6: { - frameType = "Reserved6"; + frameType = QStringLiteral("Reserved6"); break; } case QWebSocketProtocol::OC_RESERVED_7: { - frameType = "Reserved7"; + frameType = QStringLiteral("Reserved7"); break; } case QWebSocketProtocol::OC_RESERVED_B: { - frameType = "ReservedB"; + frameType = QStringLiteral("ReservedB"); break; } case QWebSocketProtocol::OC_RESERVED_C: { - frameType = "ReservedC"; + frameType = QStringLiteral("ReservedC"); break; } case QWebSocketProtocol::OC_RESERVED_D: { - frameType = "ReservedD"; + frameType = QStringLiteral("ReservedD"); break; } case QWebSocketProtocol::OC_RESERVED_E: { - frameType = "ReservedE"; + frameType = QStringLiteral("ReservedE"); break; } case QWebSocketProtocol::OC_RESERVED_F: { - frameType = "ReservedF"; + frameType = QStringLiteral("ReservedF"); break; } default: @@ -1442,19 +1527,22 @@ void tst_DataProcessor::minimumSize16Bit(quint16 sizeInBytes) { quint16 swapped16 = qToBigEndian<quint16>(sizeInBytes); const char *wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped16)); - QTest::newRow(QString("Text frame with payload size %1, represented in 2 bytes").arg(sizeInBytes).toStdString().data()) + QTest::newRow(QStringLiteral("Text frame with payload size %1, represented in 2 bytes") + .arg(sizeInBytes).toLatin1().constData()) << quint8(FIN | QWebSocketProtocol::OC_TEXT) << quint8(126) << QByteArray(wireRepresentation, 2) << false << QWebSocketProtocol::CC_PROTOCOL_ERROR; - QTest::newRow(QString("Binary frame with payload size %1, represented in 2 bytes").arg(sizeInBytes).toStdString().data()) + QTest::newRow(QStringLiteral("Binary frame with payload size %1, represented in 2 bytes") + .arg(sizeInBytes).toLatin1().constBegin()) << quint8(FIN | QWebSocketProtocol::OC_BINARY) << quint8(126) << QByteArray(wireRepresentation, 2) << false << QWebSocketProtocol::CC_PROTOCOL_ERROR; - QTest::newRow(QString("Continuation frame with payload size %1, represented in 2 bytes").arg(sizeInBytes).toStdString().data()) + QTest::newRow(QStringLiteral("Continuation frame with payload size %1, represented in 2 bytes") + .arg(sizeInBytes).toLatin1().constData()) << quint8(FIN | QWebSocketProtocol::OC_CONTINUE) << quint8(126) << QByteArray(wireRepresentation, 2) @@ -1467,21 +1555,24 @@ void tst_DataProcessor::minimumSize64Bit(quint64 sizeInBytes) quint64 swapped64 = qToBigEndian<quint64>(sizeInBytes); const char *wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped64)); - QTest::newRow(QString("Text frame with payload size %1, represented in 8 bytes").arg(sizeInBytes).toStdString().data()) + QTest::newRow(QStringLiteral("Text frame with payload size %1, represented in 8 bytes") + .arg(sizeInBytes).toLatin1().constData()) << quint8(FIN | QWebSocketProtocol::OC_TEXT) << quint8(127) << QByteArray(wireRepresentation, 8) << false << QWebSocketProtocol::CC_PROTOCOL_ERROR; - QTest::newRow(QString("Binary frame with payload size %1, represented in 8 bytes").arg(sizeInBytes).toStdString().data()) + QTest::newRow(QStringLiteral("Binary frame with payload size %1, represented in 8 bytes") + .arg(sizeInBytes).toLatin1().constData()) << quint8(FIN | QWebSocketProtocol::OC_BINARY) << quint8(127) << QByteArray(wireRepresentation, 8) << false << QWebSocketProtocol::CC_PROTOCOL_ERROR; - QTest::newRow(QString("Continuation frame with payload size %1, represented in 8 bytes").arg(sizeInBytes).toStdString().data()) + QTest::newRow(QStringLiteral("Continuation frame with payload size %1, represented in 8 bytes") + .arg(sizeInBytes).toLatin1().constData()) << quint8(FIN | QWebSocketProtocol::OC_CONTINUE) << quint8(127) << QByteArray(wireRepresentation, 8) @@ -1497,7 +1588,8 @@ void tst_DataProcessor::invalidUTF8(const char *dataTag, const char *utf8Sequenc { quint16 closeCode = qToBigEndian<quint16>(QWebSocketProtocol::CC_NORMAL); const char *wireRepresentation = static_cast<const char *>(static_cast<const void *>(&closeCode)); - QTest::newRow(QString("Close frame with invalid UTF8-sequence: %1").arg(dataTag).toStdString().data()) + QTest::newRow(QStringLiteral("Close frame with invalid UTF8-sequence: %1") + .arg(dataTag).toLatin1().constData()) << quint8(FIN | QWebSocketProtocol::OC_CLOSE) << quint8(payload.length() + 2) << QByteArray(wireRepresentation, 2).append(payload) @@ -1506,14 +1598,16 @@ void tst_DataProcessor::invalidUTF8(const char *dataTag, const char *utf8Sequenc } else { - QTest::newRow(QString("Text frame with invalid UTF8-sequence: %1").arg(dataTag).toStdString().data()) + QTest::newRow(QStringLiteral("Text frame with invalid UTF8-sequence: %1") + .arg(dataTag).toLatin1().constData()) << quint8(FIN | QWebSocketProtocol::OC_TEXT) << quint8(payload.length()) << payload << false << QWebSocketProtocol::CC_WRONG_DATATYPE; - QTest::newRow(QString("Continuation text frame with invalid UTF8-sequence: %1").arg(dataTag).toStdString().data()) + QTest::newRow(QStringLiteral("Continuation text frame with invalid UTF8-sequence: %1") + .arg(dataTag).toLatin1().constData()) << quint8(FIN | QWebSocketProtocol::OC_CONTINUE) << quint8(payload.length()) << payload @@ -1529,7 +1623,7 @@ void tst_DataProcessor::invalidField(const char *dataTag, quint8 invalidFieldVal << QByteArray() << false << QWebSocketProtocol::CC_PROTOCOL_ERROR; - QTest::newRow(QString(dataTag).append(" with continuation frame").toStdString().data()) + QTest::newRow(QString::fromLatin1(dataTag).append(" with continuation frame").toLatin1().constData()) << quint8(FIN | invalidFieldValue) << quint8(0x00) << QByteArray() @@ -1547,7 +1641,8 @@ void tst_DataProcessor::incompleteFrame(quint8 controlCode, quint64 indicatedSiz if (indicatedSize < 126) { - QTest::newRow(frameType.append(QString(" frame with payload size %1, but only %2 bytes of data").arg(indicatedSize).arg(actualPayloadSize)).toStdString().data()) + QTest::newRow(frameType.append(QStringLiteral(" frame with payload size %1, but only %2 bytes of data") + .arg(indicatedSize).arg(actualPayloadSize)).toLatin1().constData()) << quint8(FIN | controlCode) << quint8(indicatedSize) << firstFrame.append(QByteArray(actualPayloadSize, 'a')) @@ -1558,7 +1653,8 @@ void tst_DataProcessor::incompleteFrame(quint8 controlCode, quint64 indicatedSiz { quint16 swapped16 = qToBigEndian<quint16>(static_cast<quint16>(indicatedSize)); const char *wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped16)); - QTest::newRow(frameType.append(QString(" frame with payload size %1, but only %2 bytes of data").arg(indicatedSize).arg(actualPayloadSize)).toStdString().data()) + QTest::newRow(frameType.append(QStringLiteral(" frame with payload size %1, but only %2 bytes of data") + .arg(indicatedSize).arg(actualPayloadSize)).toLatin1().constData()) << quint8(FIN | controlCode) << quint8(126) << firstFrame.append(QByteArray(wireRepresentation, 2).append(QByteArray(actualPayloadSize, 'a'))) @@ -1569,7 +1665,8 @@ void tst_DataProcessor::incompleteFrame(quint8 controlCode, quint64 indicatedSiz { quint64 swapped64 = qToBigEndian<quint64>(indicatedSize); const char *wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped64)); - QTest::newRow(frameType.append(QString(" frame with payload size %1, but only %2 bytes of data").arg(indicatedSize).arg(actualPayloadSize)).toStdString().data()) + QTest::newRow(frameType.append(QStringLiteral(" frame with payload size %1, but only %2 bytes of data") + .arg(indicatedSize).arg(actualPayloadSize)).toLatin1().constData()) << quint8(FIN | controlCode) << quint8(127) << firstFrame.append(QByteArray(wireRepresentation, 8).append(QByteArray(actualPayloadSize, 'a'))) @@ -1582,13 +1679,15 @@ void tst_DataProcessor::nonCharacterSequence(const char *sequence) { QByteArray utf8Sequence = QByteArray::fromHex(sequence); - QTest::newRow(QString("Text frame with payload containing the non-control character sequence 0x%1").arg(QString(sequence)).toLatin1().constData()) + QTest::newRow(QStringLiteral("Text frame with payload containing the non-control character sequence 0x%1") + .arg(QString::fromLocal8Bit(sequence)).toLatin1().constData()) << quint8(FIN | QWebSocketProtocol::OC_TEXT) << quint8(utf8Sequence.size()) << utf8Sequence << false; - QTest::newRow(QString("Continuation frame with payload containing the non-control character sequence 0x%1").arg(QString(sequence)).toLatin1().constData()) + QTest::newRow(QStringLiteral("Continuation frame with payload containing the non-control character sequence 0x%1") + .arg(QString::fromLocal8Bit(sequence)).toLatin1().constData()) << quint8(FIN | QWebSocketProtocol::OC_CONTINUE) << quint8(utf8Sequence.size()) << utf8Sequence @@ -1597,19 +1696,22 @@ void tst_DataProcessor::nonCharacterSequence(const char *sequence) void tst_DataProcessor::insertIncompleteSizeFieldTest(quint8 payloadCode, quint8 numBytesFollowing) { - QTest::newRow(QString("Text frame with payload size %1, with %2 bytes following.").arg(payloadCode).arg(numBytesFollowing).toStdString().data()) + QTest::newRow(QStringLiteral("Text frame with payload size %1, with %2 bytes following.") + .arg(payloadCode).arg(numBytesFollowing).toLatin1().constData()) << quint8(FIN | QWebSocketProtocol::OC_TEXT) << quint8(payloadCode) << QByteArray(numBytesFollowing, quint8(1)) << false << QWebSocketProtocol::CC_GOING_AWAY; - QTest::newRow(QString("Binary frame with payload size %1, with %2 bytes following.").arg(payloadCode).arg(numBytesFollowing).toStdString().data()) + QTest::newRow(QStringLiteral("Binary frame with payload size %1, with %2 bytes following.") + .arg(payloadCode).arg(numBytesFollowing).toLatin1().constData()) << quint8(FIN | QWebSocketProtocol::OC_BINARY) << quint8(payloadCode) << QByteArray(numBytesFollowing, quint8(1)) << false << QWebSocketProtocol::CC_GOING_AWAY; - QTest::newRow(QString("Continuation frame with payload size %1, with %2 bytes following.").arg(payloadCode).arg(numBytesFollowing).toStdString().data()) + QTest::newRow(QStringLiteral("Continuation frame with payload size %1, with %2 bytes following.") + .arg(payloadCode).arg(numBytesFollowing).toLatin1().constData()) << quint8(FIN | QWebSocketProtocol::OC_CONTINUE) << quint8(payloadCode) << QByteArray(numBytesFollowing, quint8(1)) diff --git a/tests/auto/handshakerequest/tst_handshakerequest.cpp b/tests/auto/handshakerequest/tst_handshakerequest.cpp index 3ee5587..8b9133c 100644 --- a/tests/auto/handshakerequest/tst_handshakerequest.cpp +++ b/tests/auto/handshakerequest/tst_handshakerequest.cpp @@ -148,42 +148,51 @@ void tst_HandshakeRequest::tst_invalidStream_data() { QTest::addColumn<QString>("dataStream"); - QTest::newRow("garbage on 2 lines") << "foofoofoo\r\nfoofoo\r\n\r\n"; - QTest::newRow("garbage on 1 line") << "foofoofoofoofoo"; - QTest::newRow("Correctly formatted but invalid fields") << "VERB RESOURCE PROTOCOL"; + QTest::newRow("garbage on 2 lines") << QStringLiteral("foofoofoo\r\nfoofoo\r\n\r\n"); + QTest::newRow("garbage on 1 line") << QStringLiteral("foofoofoofoofoo"); + QTest::newRow("Correctly formatted but invalid fields") << QStringLiteral("VERB RESOURCE PROTOCOL"); //internally the fields are parsed and indexes are used to convert to a http version for instance //this test checks if there doesn't occur an out-of-bounds exception - QTest::newRow("Correctly formatted but invalid short fields") << "V R P"; - QTest::newRow("Invalid \\0 character in header") << "V R\0 P"; - QTest::newRow("Invalid http version in header") << "V R HTTP/invalid"; - QTest::newRow("Empty header field") << "GET . HTTP/1.1\r\nHEADER: "; - QTest::newRow("All zeros") << QString(QByteArray(10, char(0))); + QTest::newRow("Correctly formatted but invalid short fields") << QStringLiteral("V R P"); + QTest::newRow("Invalid \\0 character in header") << QStringLiteral("V R\0 P"); + QTest::newRow("Invalid http version in header") << QStringLiteral("V R HTTP/invalid"); + QTest::newRow("Empty header field") << QStringLiteral("GET . HTTP/1.1\r\nHEADER: "); + QTest::newRow("All zeros") << QString::fromUtf8(QByteArray(10, char(0))); QTest::newRow("Invalid hostname") << "GET . HTTP/1.1\r\nHost: \xFF\xFF"; - QTest::newRow("Complete heaer - Invalid websocket version") << "GET . HTTP/1.1\r\nHost: foo\r\nSec-WebSocket-Version: \xFF\xFF\r\n" \ - "Sec-WebSocket-Key: AVDFBDDFF\r\n" \ - "Upgrade: websocket\r\n" \ - "Connection: Upgrade\r\n\r\n"; - QTest::newRow("Complete header - Invalid verb") << "XXX . HTTP/1.1\r\nHost: foo\r\nSec-WebSocket-Version: 13\r\n" \ - "Sec-WebSocket-Key: AVDFBDDFF\r\n" \ - "Upgrade: websocket\r\n" \ - "Connection: Upgrade\r\n\r\n"; - QTest::newRow("Complete header - Invalid http version") << "GET . HTTP/a.1\r\nHost: foo\r\nSec-WebSocket-Version: 13\r\n" \ - "Sec-WebSocket-Key: AVDFBDDFF\r\n" \ - "Upgrade: websocket\r\n" \ - "Connection: Upgrade\r\n\r\n"; - QTest::newRow("Complete header - Invalid connection") << "GET . HTTP/1.1\r\nHost: foo\r\nSec-WebSocket-Version: 13\r\n" \ - "Sec-WebSocket-Key: AVDFBDDFF\r\n" \ - "Upgrade: websocket\r\n" \ - "Connection: xxxxxxx\r\n\r\n"; - QTest::newRow("Complete header - Invalid upgrade") << "GET . HTTP/1.1\r\nHost: foo\r\nSec-WebSocket-Version: 13\r\n" \ - "Sec-WebSocket-Key: AVDFBDDFF\r\n" \ - "Upgrade: wabsocket\r\n" \ - "Connection: Upgrade\r\n\r\n"; - QTest::newRow("Complete header - Upgrade contains too many values") << "GET . HTTP/1.1\r\nHost: foo\r\nSec-WebSocket-Version: 13\r\n" \ - "Sec-WebSocket-Key: AVDFBDDFF\r\n" \ - "Upgrade: websocket,ftp\r\n" \ - "Connection: Upgrade\r\n\r\n"; + //doing extensive QStringLiteral concatenations here, because + //MSVC 2010 complains when using concatenation literal strings about + //concatenation of wide and narrow strings (error C2308) + QTest::newRow("Complete header - Invalid websocket version") + << QStringLiteral("GET . HTTP/1.1\r\nHost: foo\r\nSec-WebSocket-Version: \xFF\xFF\r\n") + + QStringLiteral("Sec-WebSocket-Key: AVDFBDDFF\r\n") + + QStringLiteral("Upgrade: websocket\r\n") + + QStringLiteral("Connection: Upgrade\r\n\r\n"); + QTest::newRow("Complete header - Invalid verb") + << QStringLiteral("XXX . HTTP/1.1\r\nHost: foo\r\nSec-WebSocket-Version: 13\r\n") + + QStringLiteral("Sec-WebSocket-Key: AVDFBDDFF\r\n") + + QStringLiteral("Upgrade: websocket\r\n") + + QStringLiteral("Connection: Upgrade\r\n\r\n"); + QTest::newRow("Complete header - Invalid http version") + << QStringLiteral("GET . HTTP/a.1\r\nHost: foo\r\nSec-WebSocket-Version: 13\r\n") + + QStringLiteral("Sec-WebSocket-Key: AVDFBDDFF\r\n") + + QStringLiteral("Upgrade: websocket\r\n") + + QStringLiteral("Connection: Upgrade\r\n\r\n"); + QTest::newRow("Complete header - Invalid connection") + << QStringLiteral("GET . HTTP/1.1\r\nHost: foo\r\nSec-WebSocket-Version: 13\r\n") + + QStringLiteral("Sec-WebSocket-Key: AVDFBDDFF\r\n") + + QStringLiteral("Upgrade: websocket\r\n") + + QStringLiteral("Connection: xxxxxxx\r\n\r\n"); + QTest::newRow("Complete header - Invalid upgrade") + << QStringLiteral("GET . HTTP/1.1\r\nHost: foo\r\nSec-WebSocket-Version: 13\r\n") + + QStringLiteral("Sec-WebSocket-Key: AVDFBDDFF\r\n") + + QStringLiteral("Upgrade: wabsocket\r\n") + + QStringLiteral("Connection: Upgrade\r\n\r\n"); + QTest::newRow("Complete header - Upgrade contains too many values") + << QStringLiteral("GET . HTTP/1.1\r\nHost: foo\r\nSec-WebSocket-Version: 13\r\n") + + QStringLiteral("Sec-WebSocket-Key: AVDFBDDFF\r\n") + + QStringLiteral("Upgrade: websocket,ftp\r\n") + + QStringLiteral("Connection: Upgrade\r\n\r\n"); } void tst_HandshakeRequest::tst_invalidStream() @@ -218,10 +227,10 @@ void tst_HandshakeRequest::tst_invalidStream() */ void tst_HandshakeRequest::tst_multipleValuesInConnectionHeader() { - QString header = "GET /test HTTP/1.1\r\nHost: foo.com\r\nSec-WebSocket-Version: 13\r\n" \ - "Sec-WebSocket-Key: AVDFBDDFF\r\n" \ - "Upgrade: websocket\r\n" \ - "Connection: Upgrade,keepalive\r\n\r\n"; + QString header = QStringLiteral("GET /test HTTP/1.1\r\nHost: foo.com\r\nSec-WebSocket-Version: 13\r\n") + + QStringLiteral("Sec-WebSocket-Key: AVDFBDDFF\r\n") + + QStringLiteral("Upgrade: websocket\r\n") + + QStringLiteral("Connection: Upgrade,keepalive\r\n\r\n"); QByteArray data; QTextStream textStream(&data); QWebSocketHandshakeRequest request(80, false); @@ -247,11 +256,11 @@ void tst_HandshakeRequest::tst_multipleValuesInConnectionHeader() void tst_HandshakeRequest::tst_multipleVersions() { - QString header = "GET /test HTTP/1.1\r\nHost: foo.com\r\n" \ - "Sec-WebSocket-Version: 4, 5, 6, 7, 8, 13\r\n" \ - "Sec-WebSocket-Key: AVDFBDDFF\r\n" \ - "Upgrade: websocket\r\n" \ - "Connection: Upgrade,keepalive\r\n\r\n"; + QString header = QStringLiteral("GET /test HTTP/1.1\r\nHost: foo.com\r\n") + + QStringLiteral("Sec-WebSocket-Version: 4, 5, 6, 7, 8, 13\r\n") + + QStringLiteral("Sec-WebSocket-Key: AVDFBDDFF\r\n") + + QStringLiteral("Upgrade: websocket\r\n") + + QStringLiteral("Connection: Upgrade,keepalive\r\n\r\n"); QByteArray data; QTextStream textStream(&data); QWebSocketHandshakeRequest request(80, false); diff --git a/tests/auto/websocketframe/tst_websocketframe.cpp b/tests/auto/websocketframe/tst_websocketframe.cpp index 1cdd201..e3f3e12 100644 --- a/tests/auto/websocketframe/tst_websocketframe.cpp +++ b/tests/auto/websocketframe/tst_websocketframe.cpp @@ -118,7 +118,7 @@ QByteArray FrameHelper::wireRepresentation() quint16 swapped = qToBigEndian<quint16>(static_cast<quint16>(payloadLength)); wireRep.append(static_cast<const char *>(static_cast<const void *>(&swapped)), 2); } - else if (payloadLength <= 0x7FFFFFFFFFFFFFFFULL) + else { byte |= 127; wireRep.append(static_cast<char>(byte)); @@ -264,54 +264,54 @@ void tst_WebSocketFrame::tst_goodFrames_data() QTest::newRow("Non masked final text frame with small payload") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_TEXT - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << false << true << false; QTest::newRow("Non masked final binary frame with small payload") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_BINARY - << true << QByteArray("\x00\x01\x02\x03\x04") + << true << QByteArrayLiteral("\x00\x01\x02\x03\x04") << false << true << false; QTest::newRow("Non masked final text frame with no payload") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_TEXT - << true << QByteArray() + << true << QByteArrayLiteral("") << false << true << false; QTest::newRow("Non masked final binary frame with no payload") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_BINARY - << true << QByteArray() + << true << QByteArrayLiteral("") << false << true << false; QTest::newRow("Non masked final close frame with small payload") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_CLOSE - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << true << false << false; QTest::newRow("Non masked final close frame with no payload") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_CLOSE - << true << QByteArray() + << true << QByteArrayLiteral("") << true << false << false; QTest::newRow("Non masked final ping frame with small payload") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_PING - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << true << false << false; QTest::newRow("Non masked final pong frame with no payload") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_PONG - << true << QByteArray() + << true << QByteArrayLiteral("") << true << false << false; QTest::newRow("Non masked final continuation frame with small payload") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_CONTINUE - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << false << true << true; QTest::newRow("Non masked non-final continuation frame with small payload") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_CONTINUE - << false << QString("Hello world!").toUtf8() + << false << QStringLiteral("Hello world!").toUtf8() << false << true << true; } @@ -371,83 +371,83 @@ void tst_WebSocketFrame::tst_invalidFrames_data() QTest::newRow("RSV1 != 0") << 1 << 0 << 0 << 0U << QWebSocketProtocol::OC_TEXT - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("RSV2 != 0") << 0 << 1 << 0 << 0U << QWebSocketProtocol::OC_TEXT - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("RSV3 != 0") << 0 << 0 << 1 << 0U << QWebSocketProtocol::OC_TEXT - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("RSV1 != 0 and RSV2 != 0") << 1 << 1 << 0 << 0U << QWebSocketProtocol::OC_TEXT - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("RSV1 != 0 and RSV3 != 0") << 1 << 0 << 1 << 0U << QWebSocketProtocol::OC_TEXT - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("RSV2 != 0 and RSV3 != 0") << 0 << 1 << 1 << 0U << QWebSocketProtocol::OC_TEXT - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("Reserved OpCode 3") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_RESERVED_3 - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("Reserved OpCode 4") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_RESERVED_4 - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("Reserved OpCode 5") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_RESERVED_5 - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("Reserved OpCode 6") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_RESERVED_6 - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("Reserved OpCode 7") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_RESERVED_7 - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("Reserved OpCode B") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_RESERVED_B - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("Reserved OpCode C") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_RESERVED_C - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("Reserved OpCode D") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_RESERVED_D - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("Reserved OpCode E") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_RESERVED_E - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("Reserved OpCode F") << 0 << 0 << 0 << 0U << QWebSocketProtocol::OC_RESERVED_F - << true << QString("Hello world!").toUtf8() + << true << QStringLiteral("Hello world!").toUtf8() << QWebSocketProtocol::CC_PROTOCOL_ERROR; QTest::newRow("Close Frame with payload > 125 bytes") @@ -546,7 +546,9 @@ void tst_WebSocketFrame::tst_malformedFrames_data() //header + payload should be 12 bytes for non-masked payloads < 126 bytes for (int i = 1; i < 12; ++i) { - QTest::newRow(QString("Header too small - %1 byte(s)").arg(i).toLatin1().constData()) << wireRep.left(i) << QWebSocketProtocol::CC_GOING_AWAY; + QTest::newRow(QStringLiteral("Header too small - %1 byte(s)").arg(i).toLatin1().constData()) + << wireRep.left(i) + << QWebSocketProtocol::CC_GOING_AWAY; } //too much data { @@ -558,6 +560,22 @@ void tst_WebSocketFrame::tst_malformedFrames_data() << wireRep.left(1).append(bigpayloadIndicator).append(reinterpret_cast<char *>(swapped), 8) << QWebSocketProtocol::CC_TOO_MUCH_DATA; } + //invalid size field + { + const char bigpayloadIndicator = char(127); + quint64 payloadSize = quint64(1) << 63; + uchar swapped[8] = {0}; + qToBigEndian<quint64>(payloadSize, swapped); + QTest::newRow("Highest bit of payload length is set") + << wireRep.left(1).append(bigpayloadIndicator).append(reinterpret_cast<char *>(swapped), 8) + << QWebSocketProtocol::CC_PROTOCOL_ERROR; + + payloadSize = 256; + qToBigEndian<quint64>(payloadSize, swapped); + QTest::newRow("Overlong 64-bit size field; should be 16-bit") + << wireRep.left(1).append(bigpayloadIndicator).append(reinterpret_cast<char *>(swapped), 8) + << QWebSocketProtocol::CC_PROTOCOL_ERROR; + } //overlong size field { const char largepayloadIndicator = char(126); diff --git a/tests/auto/websocketprotocol/tst_websocketprotocol.cpp b/tests/auto/websocketprotocol/tst_websocketprotocol.cpp index 8e73921..433d53a 100644 --- a/tests/auto/websocketprotocol/tst_websocketprotocol.cpp +++ b/tests/auto/websocketprotocol/tst_websocketprotocol.cpp @@ -101,10 +101,11 @@ void tst_WebSocketProtocol::tst_validMasks_data() QTest::addColumn<QString>("inputdata"); QTest::addColumn<QByteArray>("result"); - QTest::newRow("Empty payload") << 0x12345678u << QString("") << QByteArray(""); - QTest::newRow("ASCII payload of 8 characters") << 0x12345678u << QString("abcdefgh") << QByteArray("\x73\x56\x35\x1C\x77\x52\x31\x10"); - QTest::newRow("ASCII payload of 9 characters") << 0x12345678u << QString("abcdefghi") << QByteArray("\x73\x56\x35\x1C\x77\x52\x31\x10\x7B"); - QTest::newRow("UTF-8 payload") << 0x12345678u << QString("∫∂ƒ©øØ") << QByteArray("\x2D\x0B\x69\xD1\xEA\xEC"); + QTest::newRow("Empty payload") << 0x12345678u << QStringLiteral("") << QByteArrayLiteral(""); + QTest::newRow("ASCII payload of 8 characters") << 0x12345678u << QStringLiteral("abcdefgh") << QByteArrayLiteral("\x73\x56\x35\x1C\x77\x52\x31\x10"); + QTest::newRow("ASCII payload of 9 characters") << 0x12345678u << QStringLiteral("abcdefghi") << QByteArrayLiteral("\x73\x56\x35\x1C\x77\x52\x31\x10\x7B"); + //MSVC doesn't like UTF-8 in source code; the following text is represented in the string below: ∫∂ƒ©øØ + QTest::newRow("UTF-8 payload") << 0x12345678u << QString::fromUtf8("\xE2\x88\xAB\xE2\x88\x82\xC6\x92\xC2\xA9\xC3\xB8\xC3\x98") << QByteArrayLiteral("\x2D\x0B\x69\xD1\xEA\xEC"); } void tst_WebSocketProtocol::tst_validMasks() @@ -162,12 +163,12 @@ void tst_WebSocketProtocol::tst_closeCodes_data() for (int i = 0; i < 1000; ++i) { - QTest::newRow(QString("Close code %1").arg(i).toLatin1().constData()) << i << false; + QTest::newRow(QStringLiteral("Close code %1").arg(i).toLatin1().constData()) << i << false; } for (int i = 1000; i < 1004; ++i) { - QTest::newRow(QString("Close code %1").arg(i).toLatin1().constData()) << i << true; + QTest::newRow(QStringLiteral("Close code %1").arg(i).toLatin1().constData()) << i << true; } QTest::newRow("Close code 1004") << 1004 << false; @@ -176,17 +177,17 @@ void tst_WebSocketProtocol::tst_closeCodes_data() for (int i = 1007; i < 1012; ++i) { - QTest::newRow(QString("Close code %1").arg(i).toLatin1().constData()) << i << true; + QTest::newRow(QStringLiteral("Close code %1").arg(i).toLatin1().constData()) << i << true; } for (int i = 1013; i < 3000; ++i) { - QTest::newRow(QString("Close code %1").arg(i).toLatin1().constData()) << i << false; + QTest::newRow(QStringLiteral("Close code %1").arg(i).toLatin1().constData()) << i << false; } for (int i = 3000; i < 5000; ++i) { - QTest::newRow(QString("Close code %1").arg(i).toLatin1().constData()) << i << true; + QTest::newRow(QStringLiteral("Close code %1").arg(i).toLatin1().constData()) << i << true; } QTest::newRow("Close code 5000") << 1004 << false; diff --git a/tests/manual/compliance/tst_compliance.cpp b/tests/manual/compliance/tst_compliance.cpp index bd4f120..a5216b2 100644 --- a/tests/manual/compliance/tst_compliance.cpp +++ b/tests/manual/compliance/tst_compliance.cpp @@ -152,7 +152,7 @@ void tst_ComplianceTest::autobahnTest() url.setPath("/updateReports?"); QUrlQuery query; - query.addQueryItem("agent", "QWebSockets"); + query.addQueryItem("agent", "QtWebSockets"); url.setQuery(query); pWebSocket->open(url); spy.wait(60000); |