diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/websockets/dataprocessor/tst_dataprocessor.cpp | 2 | ||||
-rw-r--r-- | tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp | 46 |
2 files changed, 35 insertions, 13 deletions
diff --git a/tests/auto/websockets/dataprocessor/tst_dataprocessor.cpp b/tests/auto/websockets/dataprocessor/tst_dataprocessor.cpp index 660d8eb..c1dd9a1 100644 --- a/tests/auto/websockets/dataprocessor/tst_dataprocessor.cpp +++ b/tests/auto/websockets/dataprocessor/tst_dataprocessor.cpp @@ -329,7 +329,7 @@ void tst_DataProcessor::goodTextFrame_data() //error C2308: concatenating mismatched strings QTest::newRow((QStringLiteral("Text frame containing Hello-") + QStringLiteral("\xC2\xB5\x40\xC3\x9F\xC3\xB6\xC3\xA4\xC3\xBC\xC3\xA0") + - QStringLiteral("\xC3\xA1-UTF-8!!")).toLatin1().constData()) + QStringLiteral("\xC3\xA1-UTF-8!!")).toUtf8().constData()) << QByteArray::fromHex("48656c6c6f2dc2b540c39fc3b6c3a4c3bcc3a0c3a12d5554462d382121") << 22; } diff --git a/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp b/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp index aca25d0..f993f84 100644 --- a/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp +++ b/tests/auto/websockets/qwebsocket/tst_qwebsocket.cpp @@ -52,6 +52,7 @@ public: Q_SIGNALS: void newConnection(QUrl requestUrl); + void newConnection(QNetworkRequest request); private Q_SLOTS: void onNewConnection(); @@ -87,6 +88,7 @@ void EchoServer::onNewConnection() QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection(); Q_EMIT newConnection(pSocket->requestUrl()); + Q_EMIT newConnection(pSocket->request()); connect(pSocket, SIGNAL(textMessageReceived(QString)), this, SLOT(processTextMessage(QString))); connect(pSocket, SIGNAL(binaryMessageReceived(QByteArray)), this, SLOT(processBinaryMessage(QByteArray))); @@ -140,6 +142,7 @@ private Q_SLOTS: void tst_sendTextMessage(); void tst_sendBinaryMessage(); void tst_errorString(); + void tst_openRequest(); #ifndef QT_NO_NETWORKPROXY void tst_setProxy(); #endif @@ -425,11 +428,9 @@ void tst_QWebSocket::tst_sendTextMessage() socket.open(url); - if (socketConnectedSpy.count() == 0) - QVERIFY(socketConnectedSpy.wait(500)); + QTRY_COMPARE(socketConnectedSpy.count(), 1); QCOMPARE(socketError.count(), 0); QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); - QCOMPARE(serverConnectedSpy.count(), 1); QList<QVariant> arguments = serverConnectedSpy.takeFirst(); QUrl urlConnected = arguments.at(0).toUrl(); QCOMPARE(urlConnected, url); @@ -461,8 +462,7 @@ void tst_QWebSocket::tst_sendTextMessage() socket.open(QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() + QStringLiteral(":") + QString::number(echoServer.port()))); - if (socketConnectedSpy.count() == 0) - QVERIFY(socketConnectedSpy.wait(500)); + QTRY_COMPARE(socketConnectedSpy.count(), 1); QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); socket.sendTextMessage(QStringLiteral("Hello world!")); @@ -506,8 +506,7 @@ void tst_QWebSocket::tst_sendBinaryMessage() socket.open(QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() + QStringLiteral(":") + QString::number(echoServer.port()))); - if (socketConnectedSpy.count() == 0) - QVERIFY(socketConnectedSpy.wait(500)); + QTRY_COMPARE(socketConnectedSpy.count(), 1); QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); socket.sendBinaryMessage(QByteArrayLiteral("Hello world!")); @@ -537,8 +536,7 @@ void tst_QWebSocket::tst_sendBinaryMessage() socket.open(QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() + QStringLiteral(":") + QString::number(echoServer.port()))); - if (socketConnectedSpy.count() == 0) - QVERIFY(socketConnectedSpy.wait(500)); + QTRY_COMPARE(socketConnectedSpy.count(), 1); QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); socket.sendBinaryMessage(QByteArrayLiteral("Hello world!")); @@ -571,9 +569,7 @@ void tst_QWebSocket::tst_errorString() socket.open(QUrl(QStringLiteral("ws://someserver.on.mars:9999"))); - if (errorSpy.count() == 0) - errorSpy.wait(500); - QCOMPARE(errorSpy.count(), 1); + QTRY_COMPARE(errorSpy.count(), 1); QList<QVariant> arguments = errorSpy.takeFirst(); QAbstractSocket::SocketError socketError = qvariant_cast<QAbstractSocket::SocketError>(arguments.at(0)); @@ -581,6 +577,32 @@ void tst_QWebSocket::tst_errorString() QCOMPARE(socket.errorString(), QStringLiteral("Host not found")); } +void tst_QWebSocket::tst_openRequest() +{ + EchoServer echoServer; + + QWebSocket socket; + + QSignalSpy socketConnectedSpy(&socket, SIGNAL(connected())); + QSignalSpy serverRequestSpy(&echoServer, SIGNAL(newConnection(QNetworkRequest))); + + QUrl url = QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() + + QLatin1Char(':') + QString::number(echoServer.port())); + url.addQueryItem("queryitem", "with encoded characters"); + QNetworkRequest req(url); + req.setRawHeader("X-Custom-Header", "A custom header"); + socket.open(req); + + QTRY_COMPARE(socketConnectedSpy.count(), 1); + QTRY_COMPARE(serverRequestSpy.count(), 1); + QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); + QList<QVariant> arguments = serverRequestSpy.takeFirst(); + QNetworkRequest requestConnected = arguments.at(0).value<QNetworkRequest>(); + QCOMPARE(requestConnected.url(), req.url()); + QCOMPARE(requestConnected.rawHeader("X-Custom-Header"), req.rawHeader("X-Custom-Header")); + socket.close(); +} + #ifndef QT_NO_NETWORKPROXY void tst_QWebSocket::tst_setProxy() { |