From 35a099243403ee0521474f9c53678c6f4420969c Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 6 Feb 2014 18:02:04 +0100 Subject: [PATCH] Fix tst_QWebSocket::tst_invalidOpen for catch-all DNS setups. Instead of relying on a hostname which might still be resolved in some DNS setups (i.e. always forward to google search or intranet), we now try to connect to localhost port 1 which should yield a ConnectionRefusedError. This way, the test passes for me on my setup. Change-Id: I025824796e94e718a42c4999706f647a72b37659 Reviewed-by: Kurt Pattyn --- tests/auto/qwebsocket/tst_qwebsocket.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/auto/qwebsocket/tst_qwebsocket.cpp b/tests/auto/qwebsocket/tst_qwebsocket.cpp index 773e824..d1ad0a9 100644 --- a/tests/auto/qwebsocket/tst_qwebsocket.cpp +++ b/tests/auto/qwebsocket/tst_qwebsocket.cpp @@ -171,7 +171,7 @@ void tst_QWebSocket::tst_invalidOpen() QSignalSpy pongSpy(&socket, SIGNAL(pong(quint64,QByteArray))); QSignalSpy bytesWrittenSpy(&socket, SIGNAL(bytesWritten(qint64))); - socket.open(QUrl(QStringLiteral("ws://SomeNonExistingWebSocketServer/")), true); + socket.open(QUrl(QStringLiteral("ws://127.0.0.1:1/")), true); QVERIFY(socket.origin().isEmpty()); QCOMPARE(socket.version(), QWebSocketProtocol::VersionLatest); @@ -185,23 +185,23 @@ void tst_QWebSocket::tst_invalidOpen() QCOMPARE(socket.pauseMode(), QAbstractSocket::PauseNever); QVERIFY(socket.peerAddress().isNull()); QCOMPARE(socket.peerPort(), quint16(0)); - QCOMPARE(socket.peerName(), QStringLiteral("somenonexistingwebsocketserver")); + QCOMPARE(socket.peerName(), QStringLiteral("127.0.0.1")); QCOMPARE(socket.state(), QAbstractSocket::ConnectingState); QCOMPARE(socket.readBufferSize(), 0); QCOMPARE(socket.resourceName(), QStringLiteral("/")); - QCOMPARE(socket.requestUrl(), QUrl(QStringLiteral("ws://SomeNonExistingWebSocketServer/"))); + QCOMPARE(socket.requestUrl(), QUrl(QStringLiteral("ws://127.0.0.1:1/"))); QCOMPARE(socket.closeCode(), QWebSocketProtocol::CloseCodeNormal); QVERIFY(socket.closeReason().isEmpty()); QVERIFY(!socket.flush()); //flush should fail if socket is in connecting state QCOMPARE(socket.sendTextMessage(QStringLiteral("A text message")), 0); QCOMPARE(socket.sendBinaryMessage(QByteArrayLiteral("A text message")), 0); - errorSpy.wait(); + QVERIFY(errorSpy.wait()); QCOMPARE(errorSpy.count(), 1); QList arguments = errorSpy.takeFirst(); QAbstractSocket::SocketError socketError = qvariant_cast(arguments.at(0)); - QCOMPARE(socketError, QAbstractSocket::HostNotFoundError); + QCOMPARE(socketError, QAbstractSocket::ConnectionRefusedError); QCOMPARE(aboutToCloseSpy.count(), 0); QCOMPARE(connectedSpy.count(), 0); QCOMPARE(disconnectedSpy.count(), 1); -- 2.7.4