diff options
author | Kimmo Karvinen <kkarvinen@broadsoft.com> | 2015-03-31 17:14:33 +0300 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-04-08 06:54:53 +0000 |
commit | 5b469aa3c4d6b9c68feb9cf92d03614077518894 (patch) | |
tree | 8d0889cd7eb6a389052e6a02978805a2f8092725 /tests | |
parent | 8a370cead2f493ee961c814af96192a8db3e18e3 (diff) | |
download | qtwebsockets-5.4.2.tar.gz |
Lifetime of incoming QTcpSocket/QSslSocket are managed by the
QTcpServer/QSslServer and thus the QWebSocketPrivate should clear the
pointer to the socket when the socket is destroyed.
Added auto test for the crash.
Task-number: QTBUG-45331
Change-Id: I6e30e7cdcca22aa810ccc1a1d4d7d77c7cb2c349
Reviewed-by: Steven Ceuppens <steven.ceuppens@icloud.com>
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qwebsocketserver/tst_qwebsocketserver.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/qwebsocketserver/tst_qwebsocketserver.cpp b/tests/auto/qwebsocketserver/tst_qwebsocketserver.cpp index f585620..8ee0a36 100644 --- a/tests/auto/qwebsocketserver/tst_qwebsocketserver.cpp +++ b/tests/auto/qwebsocketserver/tst_qwebsocketserver.cpp @@ -64,6 +64,7 @@ private Q_SLOTS: void tst_listening(); void tst_connectivity(); void tst_maxPendingConnections(); + void tst_serverDestroyedWhileSocketConnected(); }; tst_QWebSocketServer::tst_QWebSocketServer() @@ -350,6 +351,39 @@ void tst_QWebSocketServer::tst_maxPendingConnections() QCOMPARE(serverAcceptErrorSpy.count(), 0); } +void tst_QWebSocketServer::tst_serverDestroyedWhileSocketConnected() +{ + QWebSocketServer * server = new QWebSocketServer(QString(), QWebSocketServer::NonSecureMode); + QSignalSpy serverConnectionSpy(server, SIGNAL(newConnection())); + QSignalSpy corsAuthenticationSpy(server, + SIGNAL(originAuthenticationRequired(QWebSocketCorsAuthenticator*))); + QSignalSpy serverClosedSpy(server, SIGNAL(closed())); + + QWebSocket socket; + QSignalSpy socketConnectedSpy(&socket, SIGNAL(connected())); + QSignalSpy socketDisconnectedSpy(&socket, SIGNAL(disconnected())); + + QVERIFY(server->listen()); + QCOMPARE(server->serverAddress(), QHostAddress(QHostAddress::Any)); + QCOMPARE(server->serverUrl(), QUrl(QStringLiteral("ws://") + QHostAddress(QHostAddress::LocalHost).toString() + + QStringLiteral(":").append(QString::number(server->serverPort())))); + + socket.open(server->serverUrl().toString()); + + if (socketConnectedSpy.count() == 0) + QVERIFY(socketConnectedSpy.wait()); + QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); + QCOMPARE(serverConnectionSpy.count(), 1); + QCOMPARE(corsAuthenticationSpy.count(), 1); + + QCOMPARE(serverClosedSpy.count(), 0); + + delete server; + + if (socketDisconnectedSpy.count() == 0) + QVERIFY(socketDisconnectedSpy.wait()); + QCOMPARE(socketDisconnectedSpy.count(), 1); +} QTEST_MAIN(tst_QWebSocketServer) |