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/auto/handshakerequest | |
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/auto/handshakerequest')
-rw-r--r-- | tests/auto/handshakerequest/tst_handshakerequest.cpp | 91 |
1 files changed, 50 insertions, 41 deletions
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); |