diff options
author | Liang Qi <liang.qi@qt.io> | 2017-01-26 00:37:14 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2017-01-26 00:37:14 +0000 |
commit | 398a7e736cb42ac42f0887989585b1121b7e6e62 (patch) | |
tree | 916854b706b9b057fa1483f76dd48998a8aa28a0 /tests/auto/network | |
parent | 4d3a35f63788fa5ff7a11a5bb7bd6176bd2ac70e (diff) | |
parent | 318b58562ae89453fb98e8145cd0440e14ba60b0 (diff) |
Merge "Merge remote-tracking branch 'origin/5.8' into dev" into refs/staging/dev
Diffstat (limited to 'tests/auto/network')
6 files changed, 98 insertions, 98 deletions
diff --git a/tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp b/tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp index 6ca881d38a..9c49e0c173 100644 --- a/tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp +++ b/tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp @@ -115,7 +115,7 @@ void tst_QNetworkConfiguration::comparison() QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); //initiate scans - QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete + QTRY_VERIFY_WITH_TIMEOUT(spy.count() >= 1, TestTimeOut); //wait for scan to complete QList<QNetworkConfiguration> configs = manager.allConfigurations(QNetworkConfiguration::Discovered); QVERIFY(configs.count()); @@ -162,7 +162,7 @@ void tst_QNetworkConfiguration::isRoamingAvailable() //force update to get maximum list QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); //initiate scans - QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete + QTRY_VERIFY_WITH_TIMEOUT(spy.count() >= 1, TestTimeOut); //wait for scan to complete foreach(QNetworkConfiguration c, configs) { diff --git a/tests/auto/network/bearer/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp b/tests/auto/network/bearer/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp index 838612f638..b251a65420 100644 --- a/tests/auto/network/bearer/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp +++ b/tests/auto/network/bearer/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp @@ -68,7 +68,7 @@ void tst_QNetworkConfigurationManager::allConfigurations() QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); //initiate scans - QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete + QTRY_VERIFY_WITH_TIMEOUT(spy.count() >= 1, TestTimeOut); //wait for scan to complete QList<QNetworkConfiguration> configs = manager.allConfigurations(); @@ -145,7 +145,7 @@ void tst_QNetworkConfigurationManager::defaultConfiguration() QNetworkConfigurationManager manager; QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); //initiate scans - QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete + QTRY_VERIFY_WITH_TIMEOUT(spy.count() >= 1, TestTimeOut); //wait for scan to complete QList<QNetworkConfiguration> configs = manager.allConfigurations(); QNetworkConfiguration defaultConfig = manager.defaultConfiguration(); @@ -175,7 +175,7 @@ void tst_QNetworkConfigurationManager::configurationFromIdentifier() //force an update to get maximum number of configs QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); //initiate scans - QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete + QTRY_VERIFY_WITH_TIMEOUT(spy.count() >= 1, TestTimeOut); //wait for scan to complete QList<QNetworkConfiguration> configs = manager.allConfigurations(); @@ -203,7 +203,7 @@ protected: preScanConfigs = manager.allConfigurations(); QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); //initiate scans - QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete + QTRY_VERIFY_WITH_TIMEOUT(spy.count() >= 1, TestTimeOut); //wait for scan to complete configs = manager.allConfigurations(); } public: @@ -229,7 +229,7 @@ void tst_QNetworkConfigurationManager::usedInThread() QList<QNetworkConfiguration> preScanConfigs = manager.allConfigurations(); QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); //initiate scans - QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); //wait for scan to complete + QTRY_VERIFY_WITH_TIMEOUT(spy.count() >= 1, TestTimeOut); //wait for scan to complete QList<QNetworkConfiguration> configs = manager.allConfigurations(); QCOMPARE(thread.configs, configs); //Don't compare pre scan configs, because these may be cached and therefore give different results diff --git a/tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp b/tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp index 4ae511cf54..138a0859cd 100644 --- a/tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp +++ b/tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp @@ -106,7 +106,7 @@ void tst_QNetworkSession::initTestCase() QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); - QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); + QTRY_VERIFY_WITH_TIMEOUT(spy.count() >= 1, TestTimeOut); lackeyDir = QFINDTESTDATA("lackey"); QVERIFY2(!lackeyDir.isEmpty(), qPrintable( @@ -1007,7 +1007,7 @@ QNetworkConfiguration suitableConfiguration(QString bearerType, QNetworkConfigur QSignalSpy updateSpy(&mgr, SIGNAL(updateCompleted())); mgr.updateConfigurations(); - QTRY_NOOP(updateSpy.count() == 1); + QTRY_NOOP(updateSpy.count() >= 1); if (updateSpy.count() != 1) { qDebug("tst_QNetworkSession::suitableConfiguration() failure: unable to update configurations"); return QNetworkConfiguration(); @@ -1052,7 +1052,7 @@ void updateConfigurations() QNetworkConfigurationManager mgr; QSignalSpy updateSpy(&mgr, SIGNAL(updateCompleted())); mgr.updateConfigurations(); - QTRY_NOOP(updateSpy.count() == 1); + QTRY_NOOP(updateSpy.count() >= 1); } // A convenience-function: updates and prints all available confiurations and their states diff --git a/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp b/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp index 364e435d3d..a715c38f32 100644 --- a/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp +++ b/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp @@ -271,6 +271,7 @@ void tst_QHostAddress::specialAddresses() //check special address equal to itself (QTBUG-22898), note two overloads of operator== QVERIFY(QHostAddress(address) == QHostAddress(address)); QVERIFY(QHostAddress(address) == address); + QVERIFY(address == QHostAddress(address)); QVERIFY(!(QHostAddress(address) != QHostAddress(address))); QVERIFY(!(QHostAddress(address) != address)); diff --git a/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp b/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp index c945d77cda..18da122000 100644 --- a/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp +++ b/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp @@ -54,7 +54,6 @@ class tst_QSocks5SocketEngine : public QObject, public QAbstractSocketEngineRece private slots: void initTestCase(); - void init(); void construction(); void errorTest_data(); void errorTest(); @@ -74,13 +73,6 @@ private slots: void incomplete(); protected slots: - void tcpSocketNonBlocking_hostFound(); - void tcpSocketNonBlocking_connected(); - void tcpSocketNonBlocking_closed(); - void tcpSocketNonBlocking_readyRead(); - void tcpSocketNonBlocking_bytesWritten(qint64); - void exitLoopSlot(); - void downloadBigFileSlot(); void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth); private: @@ -89,11 +81,6 @@ private: void closeNotification() { } void exceptionNotification() { } void connectionNotification() { } - QTcpSocket *tcpSocketNonBlocking_socket; - QStringList tcpSocketNonBlocking_data; - qint64 tcpSocketNonBlocking_totalWritten; - QTcpSocket *tmpSocket; - qint64 bytesAvailable; }; class MiniSocks5ResponseHandler : public QObject @@ -153,12 +140,6 @@ void tst_QSocks5SocketEngine::initTestCase() QVERIFY(QtNetworkSettings::verifyTestNetworkSettings()); } -void tst_QSocks5SocketEngine::init() -{ - tmpSocket = 0; - bytesAvailable = 0; -} - //--------------------------------------------------------------------------- void tst_QSocks5SocketEngine::construction() { @@ -631,13 +612,27 @@ void tst_QSocks5SocketEngine::tcpSocketNonBlockingTest() { QSocks5SocketEngineHandler socks5; + qint64 tcpSocketNonBlocking_totalWritten = 0; + QStringList tcpSocketNonBlocking_data; QTcpSocket socket; - connect(&socket, SIGNAL(hostFound()), SLOT(tcpSocketNonBlocking_hostFound())); - connect(&socket, SIGNAL(connected()), SLOT(tcpSocketNonBlocking_connected())); - connect(&socket, SIGNAL(disconnected()), SLOT(tcpSocketNonBlocking_closed())); - connect(&socket, SIGNAL(bytesWritten(qint64)), SLOT(tcpSocketNonBlocking_bytesWritten(qint64))); - connect(&socket, SIGNAL(readyRead()), SLOT(tcpSocketNonBlocking_readyRead())); - tcpSocketNonBlocking_socket = &socket; + connect(&socket, &QAbstractSocket::hostFound, + &QTestEventLoop::instance(), &QTestEventLoop::exitLoop); + connect(&socket, &QAbstractSocket::connected, + &QTestEventLoop::instance(), &QTestEventLoop::exitLoop); + connect(&socket, &QIODevice::bytesWritten, + [&tcpSocketNonBlocking_totalWritten] (qint64 written) + { + tcpSocketNonBlocking_totalWritten += written; + QTestEventLoop::instance().exitLoop(); + }); + + connect(&socket, &QIODevice::readyRead, + [&tcpSocketNonBlocking_data, &socket] () + { + while (socket.canReadLine()) + tcpSocketNonBlocking_data.append(socket.readLine()); + QTestEventLoop::instance().exitLoop(); + }); // Connect socket.connectToHost(QtNetworkSettings::serverName(), 143); @@ -725,62 +720,50 @@ void tst_QSocks5SocketEngine::tcpSocketNonBlockingTest() QCOMPARE(socket.state(), QTcpSocket::UnconnectedState); } -void tst_QSocks5SocketEngine::tcpSocketNonBlocking_hostFound() -{ - QTestEventLoop::instance().exitLoop(); -} - -void tst_QSocks5SocketEngine::tcpSocketNonBlocking_connected() -{ - QTestEventLoop::instance().exitLoop(); -} - -void tst_QSocks5SocketEngine::tcpSocketNonBlocking_readyRead() -{ - while (tcpSocketNonBlocking_socket->canReadLine()) - tcpSocketNonBlocking_data.append(tcpSocketNonBlocking_socket->readLine()); - - QTestEventLoop::instance().exitLoop(); -} - -void tst_QSocks5SocketEngine::tcpSocketNonBlocking_bytesWritten(qint64 written) -{ - tcpSocketNonBlocking_totalWritten += written; - QTestEventLoop::instance().exitLoop(); -} - -void tst_QSocks5SocketEngine::tcpSocketNonBlocking_closed() -{ -} - //---------------------------------------------------------------------------------- void tst_QSocks5SocketEngine::downloadBigFile() { QSocks5SocketEngineHandler socks5; - if (tmpSocket) - delete tmpSocket; - tmpSocket = new QTcpSocket; - - connect(tmpSocket, SIGNAL(connected()), SLOT(exitLoopSlot())); - connect(tmpSocket, SIGNAL(readyRead()), SLOT(downloadBigFileSlot())); - - tmpSocket->connectToHost(QtNetworkSettings::serverName(), 80); + QTcpSocket socket; + qint64 bytesAvailable = 0; + connect(&socket, &QAbstractSocket::connected, + &QTestEventLoop::instance(), &QTestEventLoop::exitLoop); + connect(&socket, &QIODevice::readyRead, + [&socket, &bytesAvailable] () + { + const QByteArray tmp = socket.readAll(); + int correction = tmp.indexOf(char(0), 0); //skip header + if (correction == -1) + correction = 0; + bytesAvailable += (tmp.size() - correction); + if (bytesAvailable >= 10000000) + QTestEventLoop::instance().exitLoop(); + }); + + connect(&socket, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error), + [&socket] (QAbstractSocket::SocketError errorCode) + { + qWarning().noquote().nospace() << QTest::currentTestFunction() + << ": error " << errorCode << ": " << socket.errorString(); + }); + + socket.connectToHost(QtNetworkSettings::serverName(), 80); QTestEventLoop::instance().enterLoop(30); if (QTestEventLoop::instance().timeout()) QFAIL("Network operation timed out"); QByteArray hostName = QtNetworkSettings::serverName().toLatin1(); - QCOMPARE(tmpSocket->state(), QAbstractSocket::ConnectedState); - QVERIFY(tmpSocket->write("GET /qtest/mediumfile HTTP/1.0\r\n") > 0); - QVERIFY(tmpSocket->write("HOST: ") > 0); - QVERIFY(tmpSocket->write(hostName.data()) > 0); - QVERIFY(tmpSocket->write("\r\n") > 0); - QVERIFY(tmpSocket->write("\r\n") > 0); + QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); + QVERIFY(socket.write("GET /qtest/mediumfile HTTP/1.0\r\n") > 0); + QVERIFY(socket.write("HOST: ") > 0); + QVERIFY(socket.write(hostName.data()) > 0); + QVERIFY(socket.write("\r\n") > 0); + QVERIFY(socket.write("\r\n") > 0); + - bytesAvailable = 0; QTime stopWatch; stopWatch.start(); @@ -791,31 +774,12 @@ void tst_QSocks5SocketEngine::downloadBigFile() QCOMPARE(bytesAvailable, qint64(10000000)); - QCOMPARE(tmpSocket->state(), QAbstractSocket::ConnectedState); + QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); /*qDebug("\t\t%.1fMB/%.1fs: %.1fMB/s", bytesAvailable / (1024.0 * 1024.0), stopWatch.elapsed() / 1024.0, (bytesAvailable / (stopWatch.elapsed() / 1000.0)) / (1024 * 1024));*/ - - delete tmpSocket; - tmpSocket = 0; -} - -void tst_QSocks5SocketEngine::exitLoopSlot() -{ - QTestEventLoop::instance().exitLoop(); -} - - -void tst_QSocks5SocketEngine::downloadBigFileSlot() -{ - QByteArray tmp=tmpSocket->readAll(); - int correction=tmp.indexOf((char)0,0); //skip header - if (correction==-1) correction=0; - bytesAvailable += (tmp.size()-correction); - if (bytesAvailable >= 10000000) - QTestEventLoop::instance().exitLoop(); } void tst_QSocks5SocketEngine::passwordAuth() diff --git a/tests/auto/network/ssl/qssldiffiehellmanparameters/tst_qssldiffiehellmanparameters.cpp b/tests/auto/network/ssl/qssldiffiehellmanparameters/tst_qssldiffiehellmanparameters.cpp index f3b9003fbb..ddf503eed6 100644 --- a/tests/auto/network/ssl/qssldiffiehellmanparameters/tst_qssldiffiehellmanparameters.cpp +++ b/tests/auto/network/ssl/qssldiffiehellmanparameters/tst_qssldiffiehellmanparameters.cpp @@ -42,6 +42,13 @@ #include <QSslSocket> #include <QByteArray> +// Default DH parameters, exported by qssldiffiehellmanparameters.cpp. +QT_BEGIN_NAMESPACE +extern Q_AUTOTEST_EXPORT const char *qssl_dhparams_default_base64; +QT_END_NAMESPACE + +QT_USE_NAMESPACE + class tst_QSslDiffieHellmanParameters : public QObject { Q_OBJECT @@ -54,6 +61,7 @@ private Q_SLOTS: void constructionPEM(); void unsafe512Bits(); void unsafeNonPrime(); + void defaultIsValid(); #endif }; @@ -157,6 +165,33 @@ void tst_QSslDiffieHellmanParameters::unsafeNonPrime() #endif } +void tst_QSslDiffieHellmanParameters::defaultIsValid() +{ + // The QSslDiffieHellmanParameters::defaultParameters() method takes a shortcut, + // by not verifying the passed-in parameters. Instead, it simply assigns the default + // DH parameters to the derData field of QSslDiffieHellmanParametersPrivate. + // + // This test ensures that our default parameters pass the internal verification tests + // by constructing, using fromEncoded(), a QSslDiffieHellmanParameters instance that + // we expect to be equivalent to the one returned by defaultParameters(). By using + // fromEncoded() we go through the internal verification mechanisms. Finally, to ensure + // the two instances are equivalent, we compare them. + + const auto dh = QSslDiffieHellmanParameters::fromEncoded( + QByteArray::fromBase64(QByteArray(qssl_dhparams_default_base64)), + QSsl::Der + ); + + const auto defaultdh = QSslDiffieHellmanParameters::defaultParameters(); + +#ifndef QT_NO_OPENSSL + QCOMPARE(dh.isEmpty(), false); + QCOMPARE(dh.isValid(), true); + QCOMPARE(dh.error(), QSslDiffieHellmanParameters::NoError); + QCOMPARE(dh, defaultdh); +#endif +} + #endif // QT_NO_SSL QTEST_MAIN(tst_QSslDiffieHellmanParameters) |