diff options
author | Liang Qi <liang.qi@qt.io> | 2017-11-20 13:18:51 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-11-20 15:05:51 +0100 |
commit | 534ed7ddbe86c58dc7d59c5c693b027ed8f18737 (patch) | |
tree | b5fe6e7deec116c213f7eadc5a3b142600bb2a1b /tests/auto | |
parent | f7c5b8fce9517b3062eeab0ec7e8e46867d1f977 (diff) | |
parent | 57e1ebecf0e9e1fbc23f7fe32a90c63e242e692b (diff) | |
download | qtwebsockets-534ed7ddbe86c58dc7d59c5c693b027ed8f18737.tar.gz |
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts:
src/websockets/qwebsocket_p.cpp
tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp
Change-Id: I40922fab198a09a3fbba1b2f11b42f2d40e53720
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp | 57 |
1 files changed, 24 insertions, 33 deletions
diff --git a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp index 45394bc..8a3760d 100644 --- a/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp +++ b/tests/auto/websockets/qwebsocketserver/tst_qwebsocketserver.cpp @@ -31,9 +31,9 @@ #include <QTcpServer> #ifndef QT_NO_OPENSSL #include <QtNetwork/qsslpresharedkeyauthenticator.h> -#include <QtNetwork/qsslcipher.h> #endif #ifndef QT_NO_SSL +#include <QtNetwork/qsslcipher.h> #include <QtNetwork/qsslkey.h> #endif #include <QtWebSockets/QWebSocketServer> @@ -301,7 +301,7 @@ void tst_QWebSocketServer::tst_listening() QVERIFY(server.isListening()); QCOMPARE(serverClosedSpy.count(), 0); server.close(); - QVERIFY(serverClosedSpy.wait(1000)); + QTRY_COMPARE(serverClosedSpy.count(), 1); QVERIFY(!server.isListening()); QCOMPARE(serverErrorSpy.count(), 0); @@ -347,8 +347,7 @@ void tst_QWebSocketServer::tst_connectivity() socket.open(server.serverUrl().toString()); - if (socketConnectedSpy.count() == 0) - QVERIFY(socketConnectedSpy.wait()); + QTRY_COMPARE(socketConnectedSpy.count(), 1); QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); QCOMPARE(serverConnectionSpy.count(), 1); QCOMPARE(corsAuthenticationSpy.count(), 1); @@ -357,8 +356,7 @@ void tst_QWebSocketServer::tst_connectivity() server.close(); - QVERIFY(serverClosedSpy.wait()); - QCOMPARE(serverClosedSpy.count(), 1); + QTRY_COMPARE(serverClosedSpy.count(), 1); #ifndef QT_NO_SSL QCOMPARE(peerVerifyErrorSpy.count(), 0); QCOMPARE(sslErrorsSpy.count(), 0); @@ -429,8 +427,7 @@ void tst_QWebSocketServer::tst_preSharedKey() socket.open(server.serverUrl().toString()); - if (socketConnectedSpy.count() == 0) - QVERIFY(socketConnectedSpy.wait()); + QTRY_COMPARE(socketConnectedSpy.count(), 1); QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); QCOMPARE(serverConnectionSpy.count(), 1); QCOMPARE(serverPskRequiredSpy.count(), 1); @@ -440,8 +437,7 @@ void tst_QWebSocketServer::tst_preSharedKey() server.close(); - QVERIFY(serverClosedSpy.wait()); - QCOMPARE(serverClosedSpy.count(), 1); + QTRY_COMPARE(serverClosedSpy.count(), 1); QCOMPARE(sslErrorsSpy.count(), 0); QCOMPARE(serverErrorSpy.count(), 0); #endif @@ -480,20 +476,18 @@ void tst_QWebSocketServer::tst_maxPendingConnections() socket1.open(server.serverUrl().toString()); - if (socket1ConnectedSpy.count() == 0) - QVERIFY(socket1ConnectedSpy.wait()); + QTRY_COMPARE(socket1ConnectedSpy.count(), 1); QCOMPARE(socket1.state(), QAbstractSocket::ConnectedState); QCOMPARE(serverConnectionSpy.count(), 1); QCOMPARE(corsAuthenticationSpy.count(), 1); socket2.open(server.serverUrl().toString()); - if (socket2ConnectedSpy.count() == 0) - QVERIFY(socket2ConnectedSpy.wait()); + QTRY_COMPARE(socket2ConnectedSpy.count(), 1); QCOMPARE(socket2.state(), QAbstractSocket::ConnectedState); QCOMPARE(serverConnectionSpy.count(), 2); QCOMPARE(corsAuthenticationSpy.count(), 2); socket3.open(server.serverUrl().toString()); - if (socket3ConnectedSpy.count() == 0) - QVERIFY(!socket3ConnectedSpy.wait(250)); + QVERIFY(!socket3ConnectedSpy.wait(250)); + QCOMPARE(socket3ConnectedSpy.count(), 0); QCOMPARE(socket3.state(), QAbstractSocket::UnconnectedState); QCOMPARE(serverConnectionSpy.count(), 2); QCOMPARE(corsAuthenticationSpy.count(), 2); @@ -519,8 +513,7 @@ void tst_QWebSocketServer::tst_maxPendingConnections() server.close(); - QVERIFY(serverClosedSpy.wait()); - QCOMPARE(serverClosedSpy.count(), 1); + QTRY_COMPARE(serverClosedSpy.count(), 1); #ifndef QT_NO_SSL QCOMPARE(peerVerifyErrorSpy.count(), 0); QCOMPARE(sslErrorsSpy.count(), 0); @@ -550,8 +543,7 @@ void tst_QWebSocketServer::tst_serverDestroyedWhileSocketConnected() socket.open(server->serverUrl().toString()); - if (socketConnectedSpy.count() == 0) - QVERIFY(socketConnectedSpy.wait()); + QTRY_COMPARE(socketConnectedSpy.count(), 1); QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); QCOMPARE(serverConnectionSpy.count(), 1); QCOMPARE(corsAuthenticationSpy.count(), 1); @@ -560,9 +552,7 @@ void tst_QWebSocketServer::tst_serverDestroyedWhileSocketConnected() delete server; - if (socketDisconnectedSpy.count() == 0) - QVERIFY(socketDisconnectedSpy.wait()); - QCOMPARE(socketDisconnectedSpy.count(), 1); + QTRY_COMPARE(socketDisconnectedSpy.count(), 1); } void tst_QWebSocketServer::tst_scheme() @@ -578,8 +568,7 @@ void tst_QWebSocketServer::tst_scheme() QWebSocket plainSocket; plainSocket.open(plainServer.serverUrl().toString()); - if (plainServerConnectionSpy.count() == 0) - QVERIFY(plainServerConnectionSpy.wait()); + QTRY_COMPARE(plainServerConnectionSpy.count(), 1); QScopedPointer<QWebSocket> plainServerSocket(plainServer.nextPendingConnection()); QVERIFY(!plainServerSocket.isNull()); QCOMPARE(plainServerSocket->requestUrl().scheme(), QStringLiteral("ws")); @@ -605,17 +594,21 @@ void tst_QWebSocketServer::tst_scheme() QVERIFY(secureServer.listen()); + QSslCipher sessionCipher; QWebSocket secureSocket; connect(&secureSocket, &QWebSocket::sslErrors, - &secureSocket, QOverload<>::of(&QWebSocket::ignoreSslErrors)); + &secureSocket, [&] { + secureSocket.ignoreSslErrors(); + sessionCipher = secureSocket.sslConfiguration().sessionCipher(); + }); secureSocket.open(secureServer.serverUrl().toString()); - if (secureServerConnectionSpy.count() == 0) - QVERIFY(secureServerConnectionSpy.wait()); + QTRY_COMPARE(secureServerConnectionSpy.count(), 1); QScopedPointer<QWebSocket> secureServerSocket(secureServer.nextPendingConnection()); QVERIFY(!secureServerSocket.isNull()); QCOMPARE(secureServerSocket->requestUrl().scheme(), QStringLiteral("wss")); secureServer.close(); + QVERIFY(!sessionCipher.isNull()); #endif } @@ -634,19 +627,17 @@ void tst_QWebSocketServer::tst_handleConnection() QWebSocket webSocket; QSignalSpy wsConnectedSpy(&webSocket, &QWebSocket::connected); webSocket.open(QStringLiteral("ws://localhost:%1").arg(tcpServer.serverPort())); - QVERIFY(wsConnectedSpy.wait()); + QTRY_COMPARE(wsConnectedSpy.count(), 1); - if (wsServerConnectionSpy.isEmpty()) - QVERIFY(wsServerConnectionSpy.wait()); + QTRY_COMPARE(wsServerConnectionSpy.count(), 1); QScopedPointer<QWebSocket> webServerSocket(wsServer.nextPendingConnection()); QVERIFY(!webServerSocket.isNull()); QSignalSpy wsMessageReceivedSpy(webServerSocket.data(), &QWebSocket::textMessageReceived); webSocket.sendTextMessage("dummy"); - wsMessageReceivedSpy.wait(); - QCOMPARE(wsMessageReceivedSpy.count(), 1); + QTRY_COMPARE(wsMessageReceivedSpy.count(), 1); QList<QVariant> arguments = wsMessageReceivedSpy.takeFirst(); QCOMPARE(arguments.first().toString(), QString("dummy")); } |