From 1edf8bc46542ad302085b9e957c8c3c31c7db9da Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 4 Jan 2020 16:03:35 +0100 Subject: QObject: Replace more 0 and NULL with nullptr ... in docs, comments, and warnings. Also adopt some occurrences around there and in the snippets. Change-Id: Icc0aa0868cadd8ec2270dda794bf83cd7ab84160 Reviewed-by: Christian Ehrlicher --- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index a805bfb747..21615d6ec4 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -6719,16 +6719,16 @@ void tst_QObject::connectWarnings() ReceiverObject r1; r1.reset(); - QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SenderObject, ReceiverObject): invalid null parameter"); + QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SenderObject, ReceiverObject): invalid nullptr parameter"); connect(static_cast(nullptr), &SubSender::signal1, &r1, &ReceiverObject::slot1); - QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SubSender, Unknown): invalid null parameter"); + QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SubSender, Unknown): invalid nullptr parameter"); connect(&sub, &SubSender::signal1, static_cast(nullptr), &ReceiverObject::slot1); - QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SenderObject, ReceiverObject): invalid null parameter"); + QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SenderObject, ReceiverObject): invalid nullptr parameter"); connect(static_cast(nullptr), &SenderObject::signal1, &r1, &ReceiverObject::slot1); - QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SenderObject, Unknown): invalid null parameter"); + QTest::ignoreMessage(QtWarningMsg, "QObject::connect(SenderObject, Unknown): invalid nullptr parameter"); connect(&obj, &SenderObject::signal1, static_cast(nullptr), &ReceiverObject::slot1); } -- cgit v1.2.3 From bcc8cf5e3b7c139c762d957b02ddfcf75707bde0 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 8 Jan 2020 11:30:35 +0100 Subject: Fix encoding inconsistency between tst_QNoDebug and QTestLog Fix tst_QNoDebug::streaming() to use toLocal8Bit(), to match QTestLog::ignoreMessage(), which uses fromLocal8Bit(). Change-Id: I65f7b995a582aeab7b7ba61781a229fecd1ed3c3 Reviewed-by: Thiago Macieira Reviewed-by: David Faure --- tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp b/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp index b05c89a8bb..cf2079a407 100644 --- a/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp +++ b/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -65,7 +65,7 @@ void tst_QNoDebug::noDebugOutput() const void tst_QNoDebug::streaming() const { QDateTime dt(QDate(1,2,3),QTime(4,5,6)); - const QByteArray debugString = dt.toString(u"yyyy-MM-dd HH:mm:ss.zzz t").toLatin1(); + const QByteArray debugString = dt.toString(u"yyyy-MM-dd HH:mm:ss.zzz t").toLocal8Bit(); const QByteArray message = "QDateTime(" + debugString + " Qt::LocalTime)"; QTest::ignoreMessage(QtWarningMsg, message.constData()); qWarning() << dt; -- cgit v1.2.3 From 70d484b5df6211546e17f336782f83a3f856965d Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 8 Jan 2020 17:05:15 +0100 Subject: Fix encoding expected by tst_qmessagehandler::qMessagePattern() The actual logging code, qt_message_print(), uses toLocal8Bit(), so testing by comaring with toUtf8() isn't robust. Change-Id: I7d6614e4af8c679674dbbf4ff47a88b2b75fc2dc Reviewed-by: Thiago Macieira --- tests/auto/corelib/global/qlogging/tst_qlogging.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp index 17d0f86728..3af637d13a 100644 --- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp +++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2014 Olivier Goffart ** Contact: https://www.qt.io/licensing/ ** @@ -767,18 +767,18 @@ void tst_qmessagehandler::qMessagePattern_data() QTest::qWait(10000); QTest::newRow("time") << "/%{time yyyy - MM - d}/%{message}" << true << (QList() - << ('/' + QDateTime::currentDateTime().toString("yyyy - MM - d").toUtf8() + "/qDebug")); + << ('/' + QDateTime::currentDateTime().toString("yyyy - MM - d").toLocal8Bit() + "/qDebug")); QTest::newRow("time-time") << "/%{time yyyy - MM - d}/%{time dd-MM-yy}/%{message}" << true << (QList() - << ('/' + QDateTime::currentDateTime().toString("yyyy - MM - d").toUtf8() - + '/' + QDateTime::currentDateTime().toString("dd-MM-yy").toUtf8() + << ('/' + QDateTime::currentDateTime().toString("yyyy - MM - d").toLocal8Bit() + + '/' + QDateTime::currentDateTime().toString("dd-MM-yy").toLocal8Bit() + "/qDebug")); QTest::newRow("skipped-time-shown-time") << "/%{if-warning}%{time yyyy - MM - d}%{endif}%{if-debug}%{time dd-MM-yy}%{endif}/%{message}" << true << (QList() - << ('/' + QDateTime::currentDateTime().toString("dd-MM-yy").toUtf8() + "/qDebug")); + << ('/' + QDateTime::currentDateTime().toString("dd-MM-yy").toLocal8Bit() + "/qDebug")); // %{time} should have a padding of 6 so if it takes less than 10 seconds to show // the first message, there should be 5 spaces -- cgit v1.2.3 From 94b3dd77f29a00ebbd1efdc66d75f57e1c75b152 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Thu, 9 Jan 2020 11:58:34 +0100 Subject: QAbstractSocket: deprecate 'error' member-function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The one that is a getter for the last error found. This is to disambiguate the expression '&QAbstractSocket::error'. Introduce a new member-function socketError as a replacement. [ChangeLog][Deprecation Notice] QAbstractSocket::error() (the getter) is deprecated; superseded by socketError(). Task-number: QTBUG-80369 Change-Id: Ia2e3d108657aaa7929ab0810babe2ede309740ba Reviewed-by: Mårten Nordheim --- tests/auto/network-settings.h | 2 +- .../access/qnetworkreply/tst_qnetworkreply.cpp | 6 +-- .../qhttpsocketengine/tst_qhttpsocketengine.cpp | 2 +- .../tst_qsocks5socketengine.cpp | 4 +- .../network/socket/qtcpsocket/tst_qtcpsocket.cpp | 44 +++++++++++----------- .../network/socket/qudpsocket/tst_qudpsocket.cpp | 14 +++---- tests/auto/network/ssl/qocsp/tst_qocsp.cpp | 2 +- .../auto/network/ssl/qsslsocket/tst_qsslsocket.cpp | 28 +++++++------- .../other/networkselftest/tst_networkselftest.cpp | 4 +- tests/baselineserver/shared/baselineprotocol.cpp | 2 +- 10 files changed, 54 insertions(+), 54 deletions(-) (limited to 'tests') diff --git a/tests/auto/network-settings.h b/tests/auto/network-settings.h index 77298342af..65d4bb5cea 100644 --- a/tests/auto/network-settings.h +++ b/tests/auto/network-settings.h @@ -174,7 +174,7 @@ public: if (!s.peerAddress().isNull()) debug << ", peer=" << s.peerAddress().toString() << ':' << s.peerPort(); debug << ", type=" << s.socketType() << ", state=" << s.state() - << ", error=" << s.error() << ": " << s.errorString(); + << ", error=" << s.socketError() << ": " << s.errorString(); return result.toLocal8Bit(); } #endif // QT_NETWORK_LIB diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index c523b0c20e..36f19c1582 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -1111,7 +1111,7 @@ protected: // get the "request" packet if (!client->waitForReadyRead(2000)) { - qDebug() << "FastSender:" << client->error() << "waiting for \"request\" packet"; + qDebug() << "FastSender:" << client->socketError() << "waiting for \"request\" packet"; return; } client->readAll(); // we're not interested in the actual contents (e.g. HTTP request) @@ -1148,7 +1148,7 @@ protected: while (client->bytesToWrite() > 0) { qDebug() << "Still having" << client->bytesToWrite() << "bytes to write, doing that now"; if (!client->waitForBytesWritten(10000)) { - qDebug() << "ERROR: FastSender:" << client->error() << "cleaning up residue"; + qDebug() << "ERROR: FastSender:" << client->socketError() << "cleaning up residue"; return; } } @@ -1168,7 +1168,7 @@ protected: while (client->bytesToWrite() > 0) { if (!client->waitForBytesWritten(10000)) { - qDebug() << "ERROR: FastSender:" << client->error() << "during blocking write"; + qDebug() << "ERROR: FastSender:" << client->socketError() << "during blocking write"; return; } } diff --git a/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp b/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp index 64241014d7..a3d93609c1 100644 --- a/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp +++ b/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp @@ -274,7 +274,7 @@ void tst_QHttpSocketEngine::errorTest() QTestEventLoop::instance().enterLoop(30); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(int(socket.error()), expectedError); + QCOMPARE(int(socket.socketError()), expectedError); } //--------------------------------------------------------------------------- diff --git a/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp b/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp index 464054f8a6..8ac9f56de8 100644 --- a/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp +++ b/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp @@ -287,7 +287,7 @@ void tst_QSocks5SocketEngine::errorTest() QTestEventLoop::instance().enterLoop(10); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(int(socket.error()), expectedError); + QCOMPARE(int(socket.socketError()), expectedError); } //--------------------------------------------------------------------------- @@ -1010,7 +1010,7 @@ void tst_QSocks5SocketEngine::incomplete() QTestEventLoop::instance().enterLoop(70); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(socket.error(), QAbstractSocket::ProxyConnectionClosedError); + QCOMPARE(socket.socketError(), QAbstractSocket::ProxyConnectionClosedError); } //---------------------------------------------------------------------------------- diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp index 75b9b23259..42efb465bd 100644 --- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp +++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp @@ -492,7 +492,7 @@ void tst_QTcpSocket::constructing() QCOMPARE(socket->peerAddress(), QHostAddress()); QCOMPARE(socket->readChannelCount(), 0); QCOMPARE(socket->writeChannelCount(), 0); - QCOMPARE(socket->error(), QTcpSocket::UnknownSocketError); + QCOMPARE(socket->socketError(), QTcpSocket::UnknownSocketError); QCOMPARE(socket->errorString(), QString("Unknown error")); // Check the state of the socket layer? @@ -596,7 +596,7 @@ void tst_QTcpSocket::bind() } bool bindSuccess = socket->bind(addr, port); - if (!bindSuccess && randomPort && socket->error() == QTcpSocket::AddressInUseError) { + if (!bindSuccess && randomPort && socket->socketError() == QTcpSocket::AddressInUseError) { // we may have been unlucky and hit an already open port, so try another --attemptsLeft; continue; @@ -708,7 +708,7 @@ void tst_QTcpSocket::setInvalidSocketDescriptor() QVERIFY(!socket->setSocketDescriptor(-5, QTcpSocket::UnconnectedState)); QCOMPARE(socket->socketDescriptor(), (qintptr)-1); - QCOMPARE(socket->error(), QTcpSocket::UnsupportedSocketOperationError); + QCOMPARE(socket->socketError(), QTcpSocket::UnsupportedSocketOperationError); delete socket; } @@ -871,7 +871,7 @@ void tst_QTcpSocket::hostNotFound() "when we expect 404", Continue); } #endif - QCOMPARE(int(socket->error()), int(QTcpSocket::HostNotFoundError)); + QCOMPARE(int(socket->socketError()), int(QTcpSocket::HostNotFoundError)); delete socket; } @@ -897,7 +897,7 @@ void tst_QTcpSocket::timeoutConnect() QVERIFY(timer.elapsed() < 150); QVERIFY(!socket->waitForConnected(1000)); //200ms is too short when using SOCKS proxy authentication QCOMPARE(socket->state(), QTcpSocket::UnconnectedState); - QCOMPARE(int(socket->error()), int(QTcpSocket::SocketTimeoutError)); + QCOMPARE(int(socket->socketError()), int(QTcpSocket::SocketTimeoutError)); QCOMPARE(socket->readChannelCount(), 0); QCOMPARE(socket->writeChannelCount(), 0); @@ -1216,7 +1216,7 @@ void tst_QTcpSocket::openCloseOpenClose() QCOMPARE(socket->localAddress(), QHostAddress()); QCOMPARE((int) socket->peerPort(), 0); QCOMPARE(socket->peerAddress(), QHostAddress()); - QCOMPARE(socket->error(), QTcpSocket::UnknownSocketError); + QCOMPARE(socket->socketError(), QTcpSocket::UnknownSocketError); QCOMPARE(socket->errorString(), QString("Unknown error")); QCOMPARE(socket->state(), QTcpSocket::UnconnectedState); @@ -1370,7 +1370,7 @@ protected: while (!quit) { if (socket->waitForDisconnected(500)) break; - if (socket->error() != QAbstractSocket::SocketTimeoutError) + if (socket->socketError() != QAbstractSocket::SocketTimeoutError) return; } @@ -1606,8 +1606,8 @@ void tst_QTcpSocket::readLine() QVERIFY(!socket->waitForReadyRead(100)); QCOMPARE(socket->readLine(buffer, sizeof(buffer)), qint64(0)); - QVERIFY(socket->error() == QAbstractSocket::SocketTimeoutError - || socket->error() == QAbstractSocket::RemoteHostClosedError); + QVERIFY(socket->socketError() == QAbstractSocket::SocketTimeoutError + || socket->socketError() == QAbstractSocket::RemoteHostClosedError); QCOMPARE(socket->bytesAvailable(), qint64(0)); socket->close(); @@ -1756,11 +1756,11 @@ void tst_QTcpSocket::dontCloseOnTimeout() QTcpSocket *socket = newSocket(); socket->connectToHost(serverAddress, server.serverPort()); QVERIFY(!socket->waitForReadyRead(100)); - QCOMPARE(socket->error(), QTcpSocket::SocketTimeoutError); + QCOMPARE(socket->socketError(), QTcpSocket::SocketTimeoutError); QVERIFY(socket->isOpen()); QVERIFY(!socket->waitForDisconnected(100)); - QCOMPARE(socket->error(), QTcpSocket::SocketTimeoutError); + QCOMPARE(socket->socketError(), QTcpSocket::SocketTimeoutError); QVERIFY(socket->isOpen()); delete socket; @@ -2012,7 +2012,7 @@ void tst_QTcpSocket::remoteCloseError() QCOMPARE(disconnectedSpy.count(), 1); QCOMPARE(errorSpy.count(), 1); - QCOMPARE(clientSocket->error(), QAbstractSocket::RemoteHostClosedError); + QCOMPARE(clientSocket->socketError(), QAbstractSocket::RemoteHostClosedError); delete serverSocket; @@ -2380,7 +2380,7 @@ void tst_QTcpSocket::zeroAndMinusOneReturns() socket->write("GET / HTTP/1.0\r\n\r\n"); QVERIFY(socket->waitForDisconnected(15000)); - QCOMPARE(socket->error(), QAbstractSocket::RemoteHostClosedError); + QCOMPARE(socket->socketError(), QAbstractSocket::RemoteHostClosedError); QCOMPARE(socket->write("BLUBBER"), qint64(-1)); QVERIFY(socket->getChar(c)); @@ -2429,7 +2429,7 @@ void tst_QTcpSocket::connectionRefused() QVERIFY2(!timeout(), "Network timeout"); QCOMPARE(socket->state(), QAbstractSocket::UnconnectedState); - QCOMPARE(socket->error(), QAbstractSocket::ConnectionRefusedError); + QCOMPARE(socket->socketError(), QAbstractSocket::ConnectionRefusedError); QCOMPARE(stateSpy.count(), 3); QCOMPARE(qvariant_cast(stateSpy.at(0).at(0)), QAbstractSocket::HostLookupState); @@ -2552,7 +2552,7 @@ void tst_QTcpSocket::connectToMultiIP() socket->connectToHost("multi.dev.qt-project.org", 81); QVERIFY(!socket->waitForConnected(2000)); QVERIFY(stopWatch.elapsed() < 2000); - QCOMPARE(socket->error(), QAbstractSocket::SocketTimeoutError); + QCOMPARE(socket->socketError(), QAbstractSocket::SocketTimeoutError); delete socket; #endif @@ -2738,7 +2738,7 @@ void tst_QTcpSocket::taskQtBug5799ConnectionErrorWaitForConnected() socket.waitForConnected(10000); QVERIFY2(timer.elapsed() < 9900, "Connection to closed port timed out instead of refusing, something is wrong"); QVERIFY2(socket.state() == QAbstractSocket::UnconnectedState, "Socket connected unexpectedly!"); - QVERIFY2(socket.error() == QAbstractSocket::ConnectionRefusedError, + QVERIFY2(socket.socketError() == QAbstractSocket::ConnectionRefusedError, QString("Could not reach server: %1").arg(socket.errorString()).toLocal8Bit()); } @@ -2757,7 +2757,7 @@ void tst_QTcpSocket::taskQtBug5799ConnectionErrorEventLoop() QTestEventLoop::instance().enterLoop(10); QVERIFY2(!QTestEventLoop::instance().timeout(), "Connection to closed port timed out instead of refusing, something is wrong"); QVERIFY2(socket.state() == QAbstractSocket::UnconnectedState, "Socket connected unexpectedly!"); - QVERIFY2(socket.error() == QAbstractSocket::ConnectionRefusedError, + QVERIFY2(socket.socketError() == QAbstractSocket::ConnectionRefusedError, QString("Could not reach server: %1").arg(socket.errorString()).toLocal8Bit()); } @@ -2767,12 +2767,12 @@ void tst_QTcpSocket::taskQtBug7054TimeoutErrorResetting() socket->connectToHost(QtNetworkSettings::httpServerName(), 443); QVERIFY(socket->waitForConnected(5*1000)); - QCOMPARE(socket->error(), QAbstractSocket::UnknownSocketError); + QCOMPARE(socket->socketError(), QAbstractSocket::UnknownSocketError); // We connected to the HTTPS port. Wait two seconds to receive data. We will receive // nothing because we would need to start the SSL handshake QVERIFY(!socket->waitForReadyRead(2*1000)); - QCOMPARE(socket->error(), QAbstractSocket::SocketTimeoutError); + QCOMPARE(socket->socketError(), QAbstractSocket::SocketTimeoutError); // Now write some crap to make the server disconnect us. 4 lines are enough. socket->write("a\r\nb\r\nc\r\nd\r\n"); @@ -2782,7 +2782,7 @@ void tst_QTcpSocket::taskQtBug7054TimeoutErrorResetting() // should get a better error since the server disconnected us QVERIFY(!socket->waitForReadyRead(2*1000)); // It must NOT be the SocketTimeoutError that had been set before - QCOMPARE(socket->error(), QAbstractSocket::RemoteHostClosedError); + QCOMPARE(socket->socketError(), QAbstractSocket::RemoteHostClosedError); } #ifndef QT_NO_NETWORKPROXY @@ -2840,7 +2840,7 @@ void tst_QTcpSocket::invalidProxy() // note: the following test is not a hard failure. // Sometimes, error codes change for the better - QTEST(int(socket->error()), "expectedError"); + QTEST(int(socket->socketError()), "expectedError"); delete socket; } @@ -2960,7 +2960,7 @@ void tst_QTcpSocket::proxyFactory() // note: the following test is not a hard failure. // Sometimes, error codes change for the better - QTEST(int(socket->error()), "expectedError"); + QTEST(int(socket->socketError()), "expectedError"); delete socket; } diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp index 0f419e9de4..88898cd8a8 100644 --- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -337,7 +337,7 @@ void tst_QUdpSocket::constructing() QCOMPARE(socket.canReadLine(), false); QCOMPARE(socket.readLine(), QByteArray()); QCOMPARE(socket.socketDescriptor(), (qintptr)-1); - QCOMPARE(socket.error(), QUdpSocket::UnknownSocketError); + QCOMPARE(socket.socketError(), QUdpSocket::UnknownSocketError); QCOMPARE(socket.errorString(), QString("Unknown error")); // Check the state of the socket api @@ -575,7 +575,7 @@ void tst_QUdpSocket::ipv6Loop() int paulPort; if (!peter.bind(QHostAddress(QHostAddress::LocalHostIPv6), 0)) { - QCOMPARE(peter.error(), QUdpSocket::UnsupportedSocketOperationError); + QCOMPARE(peter.socketError(), QUdpSocket::UnsupportedSocketOperationError); return; } @@ -897,7 +897,7 @@ void tst_QUdpSocket::writeDatagram() QCOMPARE(errorspy.count(), 1); QCOMPARE(*static_cast(errorspy.at(0).at(0).constData()), int(QUdpSocket::DatagramTooLargeError)); - QCOMPARE(client.error(), QUdpSocket::DatagramTooLargeError); + QCOMPARE(client.socketError(), QUdpSocket::DatagramTooLargeError); break; } QCOMPARE(bytesspy.count(), 1); @@ -1054,14 +1054,14 @@ void tst_QUdpSocket::writeToNonExistingPeer() // the second one should fail! QTest::qSleep(1000); // do not process events QCOMPARE(sConnected.write("", 1), qint64(-1)); - QCOMPARE(int(sConnected.error()), int(QUdpSocket::ConnectionRefusedError)); + QCOMPARE(int(sConnected.socketError()), int(QUdpSocket::ConnectionRefusedError)); // the third one will succeed... QCOMPARE(sConnected.write("", 1), qint64(1)); QTestEventLoop::instance().enterLoop(1); QCOMPARE(sConnectedReadyReadSpy.count(), 0); QCOMPARE(sConnectedErrorSpy.count(), 1); - QCOMPARE(int(sConnected.error()), int(QUdpSocket::ConnectionRefusedError)); + QCOMPARE(int(sConnected.socketError()), int(QUdpSocket::ConnectionRefusedError)); // we should now get a read error QCOMPARE(sConnected.write("", 1), qint64(1)); @@ -1071,12 +1071,12 @@ void tst_QUdpSocket::writeToNonExistingPeer() QCOMPARE(sConnected.bytesAvailable(), Q_INT64_C(0)); QCOMPARE(sConnected.pendingDatagramSize(), Q_INT64_C(-1)); QCOMPARE(sConnected.readDatagram(buf, 2), Q_INT64_C(-1)); - QCOMPARE(int(sConnected.error()), int(QUdpSocket::ConnectionRefusedError)); + QCOMPARE(int(sConnected.socketError()), int(QUdpSocket::ConnectionRefusedError)); QCOMPARE(sConnected.write("", 1), qint64(1)); QTest::qSleep(1000); // do not process events QCOMPARE(sConnected.read(buf, 2), Q_INT64_C(0)); - QCOMPARE(int(sConnected.error()), int(QUdpSocket::ConnectionRefusedError)); + QCOMPARE(int(sConnected.socketError()), int(QUdpSocket::ConnectionRefusedError)); // we should still be connected QCOMPARE(int(sConnected.state()), int(QUdpSocket::ConnectedState)); diff --git a/tests/auto/network/ssl/qocsp/tst_qocsp.cpp b/tests/auto/network/ssl/qocsp/tst_qocsp.cpp index 9716c04bbb..4c0f6e251a 100644 --- a/tests/auto/network/ssl/qocsp/tst_qocsp.cpp +++ b/tests/auto/network/ssl/qocsp/tst_qocsp.cpp @@ -606,7 +606,7 @@ void tst_QOcsp::malformedResponse() loop.enterLoopMSecs(handshakeTimeoutMS); QVERIFY(!clientSocket.isEncrypted()); - QCOMPARE(clientSocket.error(), QAbstractSocket::SslHandshakeFailedError); + QCOMPARE(clientSocket.socketError(), QAbstractSocket::SslHandshakeFailedError); } void tst_QOcsp::expiredResponse_data() diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp index 5a643c11a2..871d1c065f 100644 --- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp @@ -526,7 +526,7 @@ void tst_QSslSocket::constructing() QCOMPARE(socket.write(0, 0), qint64(-1)); QTest::ignoreMessage(QtWarningMsg, writeNotOpenMessage); QCOMPARE(socket.write(QByteArray()), qint64(-1)); - QCOMPARE(socket.error(), QAbstractSocket::UnknownSocketError); + QCOMPARE(socket.socketError(), QAbstractSocket::UnknownSocketError); QVERIFY(!socket.flush()); QVERIFY(!socket.isValid()); QCOMPARE(socket.localAddress(), QHostAddress()); @@ -1389,16 +1389,16 @@ void tst_QSslSocket::protocolServerSide() QAbstractSocket::SocketState expectedState = (works) ? QAbstractSocket::ConnectedState : QAbstractSocket::UnconnectedState; // Determine whether the client or the server caused the event loop // to quit due to a socket error, and investigate the culprit. - if (client.error() != QAbstractSocket::UnknownSocketError) { + if (client.socketError() != QAbstractSocket::UnknownSocketError) { // It can happen that the client, after TCP connection established, before // incomingConnection() slot fired, hits TLS initialization error and stops // the loop, so the server socket is not created yet. if (server.socket) - QVERIFY(server.socket->error() == QAbstractSocket::UnknownSocketError); + QVERIFY(server.socket->socketError() == QAbstractSocket::UnknownSocketError); QCOMPARE(client.state(), expectedState); - } else if (server.socket->error() != QAbstractSocket::UnknownSocketError) { - QVERIFY(client.error() == QAbstractSocket::UnknownSocketError); + } else if (server.socket->socketError() != QAbstractSocket::UnknownSocketError) { + QVERIFY(client.socketError() == QAbstractSocket::UnknownSocketError); QCOMPARE(server.socket->state(), expectedState); } @@ -2010,7 +2010,7 @@ void tst_QSslSocket::setEmptyKey() QTestEventLoop::instance().enterLoop(2); QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); - QCOMPARE(socket.error(), QAbstractSocket::UnknownSocketError); + QCOMPARE(socket.socketError(), QAbstractSocket::UnknownSocketError); } void tst_QSslSocket::spontaneousWrite() @@ -2782,11 +2782,11 @@ void tst_QSslSocket::writeBigChunk() // no better way to do this right now since the error is the same as the default error. if (socket->errorString().startsWith(QLatin1String("Unable to write data"))) { - qWarning() << socket->error() << socket->errorString(); + qWarning() << socket->socketError() << socket->errorString(); QFAIL("Error while writing! Check if the OpenSSL BIO size is limited?!"); } // also check the error string. If another error (than UnknownError) occurred, it should be different than before - QVERIFY2(errorBefore == errorAfter || socket->error() == QAbstractSocket::RemoteHostClosedError, + QVERIFY2(errorBefore == errorAfter || socket->socketError() == QAbstractSocket::RemoteHostClosedError, QByteArray("unexpected error: ").append(qPrintable(errorAfter))); // check that everything has been written to OpenSSL @@ -2981,7 +2981,7 @@ void tst_QSslSocket::resume() QCOMPARE(encryptedSpy.count(), 0); QVERIFY(!socket.isEncrypted()); QCOMPARE(errorSpy.count(), 1); - QCOMPARE(socket.error(), QAbstractSocket::SslHandshakeFailedError); + QCOMPARE(socket.socketError(), QAbstractSocket::SslHandshakeFailedError); } } @@ -4346,9 +4346,9 @@ void tst_QSslSocket::disabledProtocols() // early, preventing any real connection from ever starting. QSslSocket socket; socket.setProtocol(disabledProtocol); - QCOMPARE(socket.error(), QAbstractSocket::UnknownSocketError); + QCOMPARE(socket.socketError(), QAbstractSocket::UnknownSocketError); socket.connectToHostEncrypted(QStringLiteral("doesnotmatter.org"), 1010); - QCOMPARE(socket.error(), QAbstractSocket::SslInvalidUserDataError); + QCOMPARE(socket.socketError(), QAbstractSocket::SslInvalidUserDataError); QCOMPARE(socket.state(), QAbstractSocket::UnconnectedState); } { @@ -4358,14 +4358,14 @@ void tst_QSslSocket::disabledProtocols() QVERIFY(server.listen()); QSslSocket socket; - QCOMPARE(socket.error(), QAbstractSocket::UnknownSocketError); + QCOMPARE(socket.socketError(), QAbstractSocket::UnknownSocketError); socket.connectToHost(QHostAddress::LocalHost, server.serverPort()); QVERIFY(socket.waitForConnected(timeoutMS)); socket.setProtocol(disabledProtocol); socket.startClientEncryption(); - QCOMPARE(socket.error(), QAbstractSocket::SslInvalidUserDataError); + QCOMPARE(socket.socketError(), QAbstractSocket::SslInvalidUserDataError); } { // 2. waitForEncrypted: client-side, blocking API plus requires from us @@ -4389,7 +4389,7 @@ void tst_QSslSocket::disabledProtocols() loop.enterLoopMSecs(timeoutMS); QVERIFY(!loop.timeout()); QVERIFY(server.socket); - QCOMPARE(server.socket->error(), QAbstractSocket::SslInvalidUserDataError); + QCOMPARE(server.socket->socketError(), QAbstractSocket::SslInvalidUserDataError); } } diff --git a/tests/auto/other/networkselftest/tst_networkselftest.cpp b/tests/auto/other/networkselftest/tst_networkselftest.cpp index 396e23da0c..0f50718328 100644 --- a/tests/auto/other/networkselftest/tst_networkselftest.cpp +++ b/tests/auto/other/networkselftest/tst_networkselftest.cpp @@ -428,7 +428,7 @@ void tst_NetworkSelfTest::serverReachability() QVERIFY2(timer.elapsed() < 9900, "Connection to closed port timed out instead of refusing, something is wrong"); QVERIFY2(socket.state() == QAbstractSocket::UnconnectedState, "Socket connected unexpectedly!"); - QVERIFY2(socket.error() == QAbstractSocket::ConnectionRefusedError, + QVERIFY2(socket.socketError() == QAbstractSocket::ConnectionRefusedError, QString("Could not reach server: %1").arg(socket.errorString()).toLocal8Bit()); } @@ -458,7 +458,7 @@ void tst_NetworkSelfTest::remotePortsOpen() socket.connectToHost(QtNetworkSettings::serverName(), portNumber); if (!socket.waitForConnected(10000)) { - if (socket.error() == QAbstractSocket::SocketTimeoutError) + if (socket.socketError() == QAbstractSocket::SocketTimeoutError) QFAIL(QString("Network timeout connecting to the server on port %1").arg(portNumber).toLocal8Bit()); else QFAIL(QString("Error connecting to server on port %1: %2").arg(portNumber).arg(socket.errorString()).toLocal8Bit()); diff --git a/tests/baselineserver/shared/baselineprotocol.cpp b/tests/baselineserver/shared/baselineprotocol.cpp index aa496d6c54..9e5321cb1b 100644 --- a/tests/baselineserver/shared/baselineprotocol.cpp +++ b/tests/baselineserver/shared/baselineprotocol.cpp @@ -545,7 +545,7 @@ bool BaselineProtocol::receiveBlock(Command *cmd, QByteArray *block) QString BaselineProtocol::errorMessage() { QString ret = errMsg; - if (socket.error() >= 0) + if (socket.socketError() >= 0) ret += QLS(" Socket state: ") + socket.errorString(); return ret; } -- cgit v1.2.3 From 0de6c26ac17c90f513329fdbe87ef036fc25925a Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 7 Jan 2020 13:32:02 +0100 Subject: QLocalSocket - deprecate ambiguous 'error' overloads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QLocalSocket::error is overloaded as a signal and an accessor (for the error reported by the signal). This means connecting to the signal using a pointer to member function would require ambiguity resolution. We deprecate the old accessor (to be removed in Qt 6) and introduce a new one - 'socketError'. [ChangeLog][Deprecation Notice] QLocalSocket::error() (the getter) is deprecated; superseded by socketError(). Task-number: QTBUG-80369 Change-Id: Iab346f7b4cd1024dee9e5ef71b4b7e09f6d95b12 Reviewed-by: Mårten Nordheim --- tests/auto/network/socket/qlocalsocket/socketprocess/main.cpp | 8 ++++---- tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/socket/qlocalsocket/socketprocess/main.cpp b/tests/auto/network/socket/qlocalsocket/socketprocess/main.cpp index 272e837ac5..6355fea6ab 100644 --- a/tests/auto/network/socket/qlocalsocket/socketprocess/main.cpp +++ b/tests/auto/network/socket/qlocalsocket/socketprocess/main.cpp @@ -65,8 +65,8 @@ bool runServer(int numberOfConnections) return false; } printf("server: data written\n"); - if (socket->error() != QLocalSocket::UnknownSocketError) { - fprintf(stderr, "server: socket error %d\n", socket->error()); + if (socket->socketError() != QLocalSocket::UnknownSocketError) { + fprintf(stderr, "server: socket error %d\n", socket->socketError()); return false; } } @@ -83,8 +83,8 @@ bool runClient() socket.connectToServer(serverName, QLocalSocket::ReadWrite); if (socket.waitForConnected()) break; - if (socket.error() == QLocalSocket::ServerNotFoundError - || socket.error() == QLocalSocket::ConnectionRefusedError) { + if (socket.socketError() == QLocalSocket::ServerNotFoundError + || socket.socketError() == QLocalSocket::ConnectionRefusedError) { if (connectTimer.elapsed() > 5000) { fprintf(stderr, "client: server not found or connection refused. Giving up.\n"); return false; diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp index 732f7eef00..0c1536bd59 100644 --- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -195,7 +195,7 @@ private slots: void slotError(QLocalSocket::LocalSocketError newError) { QVERIFY(errorString() != QLatin1String("Unknown error")); - QCOMPARE(error(), newError); + QCOMPARE(socketError(), newError); } void slotStateChanged(QLocalSocket::LocalSocketState newState) { @@ -256,7 +256,7 @@ void tst_QLocalSocket::socket_basic() QCOMPARE(socket.canReadLine(), false); socket.close(); socket.disconnectFromServer(); - QCOMPARE(QLocalSocket::UnknownSocketError, socket.error()); + QCOMPARE(QLocalSocket::UnknownSocketError, socket.socketError()); QVERIFY(!socket.errorString().isEmpty()); QCOMPARE(socket.flush(), false); QCOMPARE(socket.isValid(), false); @@ -375,13 +375,13 @@ void tst_QLocalSocket::listenAndConnect() QVERIFY(socket->waitForConnected()); QVERIFY(socket->isValid()); QCOMPARE(socket->errorString(), QString("Unknown error")); - QCOMPARE(socket->error(), QLocalSocket::UnknownSocketError); + QCOMPARE(socket->socketError(), QLocalSocket::UnknownSocketError); QCOMPARE(socket->state(), QLocalSocket::ConnectedState); //QVERIFY(socket->socketDescriptor() != -1); QCOMPARE(spyError.count(), 0); } else { QVERIFY(!socket->errorString().isEmpty()); - QVERIFY(socket->error() != QLocalSocket::UnknownSocketError); + QVERIFY(socket->socketError() != QLocalSocket::UnknownSocketError); QCOMPARE(socket->state(), QLocalSocket::UnconnectedState); //QCOMPARE(socket->socketDescriptor(), -1); QCOMPARE(qvariant_cast(spyError.first()[0]), -- cgit v1.2.3 From 76c4c5d5581b2cd36a043234eb167dd55041301d Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Fri, 10 Jan 2020 11:32:40 +0100 Subject: QSslSocket: deprecate sslErrors() getter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To disambiguate &QSslSocket::sslErrors() expression. Add a new getter - sslHandshakeErrors(). [ChangeLog][Deprecation Notice] QSslSocket::sslErrors() (the getter) was deprecated and superseded by sslHandshakeErrors() Task-number: QTBUG-80369 Change-Id: I9dcca3c8499800c122db230753dc19b07654f8a2 Reviewed-by: Mårten Nordheim --- tests/auto/network/ssl/qocsp/tst_qocsp.cpp | 8 ++++---- tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/ssl/qocsp/tst_qocsp.cpp b/tests/auto/network/ssl/qocsp/tst_qocsp.cpp index 4c0f6e251a..94d206ac83 100644 --- a/tests/auto/network/ssl/qocsp/tst_qocsp.cpp +++ b/tests/auto/network/ssl/qocsp/tst_qocsp.cpp @@ -431,14 +431,14 @@ private: }; #define QCOMPARE_SINGLE_ERROR(sslSocket, expectedError) \ - const auto &tlsErrors = sslSocket.sslErrors(); \ + const auto &tlsErrors = sslSocket.sslHandshakeErrors(); \ QCOMPARE(tlsErrors.size(), 1); \ QCOMPARE(tlsErrors[0].error(), expectedError) #define QVERIFY_HANDSHAKE_WITHOUT_ERRORS(sslSocket) \ QVERIFY(sslSocket.isEncrypted()); \ QCOMPARE(sslSocket.state(), QAbstractSocket::ConnectedState); \ - QVERIFY(sslSocket.sslErrors().isEmpty()) + QVERIFY(sslSocket.sslHandshakeErrors().isEmpty()) #define QDECLARE_CHAIN(object, chainFileName) \ CertificateChain object = QSslCertificate::fromPath(certDirPath + QLatin1String(chainFileName)); \ @@ -722,7 +722,7 @@ void tst_QOcsp::wrongCertificateInResponse() loop.enterLoopMSecs(handshakeTimeoutMS); QVERIFY(!clientSocket.isEncrypted()); - QVERIFY(containsError(clientSocket.sslErrors(), expectedError)); + QVERIFY(containsError(clientSocket.sslHandshakeErrors(), expectedError)); } void tst_QOcsp::untrustedResponder() @@ -747,7 +747,7 @@ void tst_QOcsp::untrustedResponder() loop.enterLoopMSecs(handshakeTimeoutMS); QVERIFY(!clientSocket.isEncrypted()); - QVERIFY(containsError(clientSocket.sslErrors(), expectedError)); + QVERIFY(containsError(clientSocket.sslHandshakeErrors(), expectedError)); } void tst_QOcsp::setupOcspClient(QSslSocket &clientSocket, const CertificateChain &caCerts, const QString &name) diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp index 871d1c065f..a98790843a 100644 --- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp @@ -732,7 +732,7 @@ void tst_QSslSocket::sslErrors() // check the SSL errors contain HostNameMismatch and an error due to // the certificate being self-signed SslErrorList sslErrors; - const auto socketSslErrors = socket->sslErrors(); + const auto socketSslErrors = socket->sslHandshakeErrors(); for (const QSslError &err : socketSslErrors) sslErrors << err.error(); std::sort(sslErrors.begin(), sslErrors.end()); @@ -2432,7 +2432,7 @@ void tst_QSslSocket::verifyMode() QList expectedErrors = QList() << QSslError(FLUKE_CERTIFICATE_ERROR, socket.peerCertificate()); - QCOMPARE(socket.sslErrors(), expectedErrors); + QCOMPARE(socket.sslHandshakeErrors(), expectedErrors); socket.abort(); VerifyServer server; @@ -2448,7 +2448,7 @@ void tst_QSslSocket::verifyMode() loop.exec(); QVERIFY(clientSocket.isEncrypted()); - QVERIFY(server.socket->sslErrors().isEmpty()); + QVERIFY(server.socket->sslHandshakeErrors().isEmpty()); } void tst_QSslSocket::verifyDepth() @@ -2825,7 +2825,7 @@ void tst_QSslSocket::blacklistedCertificates() connect(receiver, SIGNAL(sslErrors(QList)), SLOT(exitLoop())); connect(receiver, SIGNAL(encrypted()), SLOT(exitLoop())); enterLoop(1); - QList sslErrors = receiver->sslErrors(); + QList sslErrors = receiver->sslHandshakeErrors(); QVERIFY(sslErrors.count() > 0); // there are more errors (self signed cert and hostname mismatch), but we only care about the blacklist error QCOMPARE(sslErrors.at(0).error(), QSslError::CertificateBlacklisted); -- cgit v1.2.3