diff options
Diffstat (limited to 'tests/auto/network')
4 files changed, 151 insertions, 120 deletions
diff --git a/tests/auto/network/access/qnetworkreply/test/test.pro b/tests/auto/network/access/qnetworkreply/test/test.pro index 45a5734305..8aeec88fd2 100644 --- a/tests/auto/network/access/qnetworkreply/test/test.pro +++ b/tests/auto/network/access/qnetworkreply/test/test.pro @@ -1,6 +1,6 @@ CONFIG += testcase testcase.timeout = 600 # this test is slow -CONFIG -= app_bundle debug_and_release_target +CONFIG -= debug_and_release_target SOURCES += ../tst_qnetworkreply.cpp TARGET = ../tst_qnetworkreply diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index 649278d48b..b3c8a4f66b 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -104,10 +104,10 @@ class tst_QNetworkReply: public QObject Q_OBJECT #ifndef QT_NO_NETWORKPROXY - struct ProxyData { + struct ProxyData + { ProxyData(const QNetworkProxy &p, const QByteArray &t, bool auth) - : tag(t), proxy(p), requiresAuthentication(auth) - { } + : tag(t), proxy(p), requiresAuthentication(auth) {} QByteArray tag; QNetworkProxy proxy; bool requiresAuthentication; @@ -115,7 +115,8 @@ class tst_QNetworkReply: public QObject #endif // !QT_NO_NETWORKPROXY static bool seedCreated; - static QString createUniqueExtension() { + static QString createUniqueExtension() + { if (!seedCreated) { qsrand(QTime(0,0,0).msecsTo(QTime::currentTime()) + QCoreApplication::applicationPid()); seedCreated = true; // not thread-safe, but who cares @@ -495,7 +496,7 @@ bool tst_QNetworkReply::seedCreated = false; QString errorMsg = call; \ if (!errorMsg.isEmpty()) \ QFAIL(qPrintable(errorMsg)); \ - } while (0); + } while (0) #ifndef QT_NO_SSL static void setupSslServer(QSslSocket* serverSocket) @@ -507,6 +508,7 @@ static void setupSslServer(QSslSocket* serverSocket) serverSocket->setProtocol(QSsl::AnyProtocol); serverSocket->setLocalCertificate(testDataDir + "/certs/server.pem"); serverSocket->setPrivateKey(testDataDir + "/certs/server.key"); + serverSocket->startServerEncryption(); } #endif @@ -553,31 +555,30 @@ protected: void incomingConnection(qintptr socketDescriptor) { //qDebug() << "incomingConnection" << socketDescriptor << "doSsl:" << doSsl << "ipv6:" << ipv6; - if (!doSsl) { - client = new QTcpSocket; - client->setSocketDescriptor(socketDescriptor); - connectSocketSignals(); - } else { #ifndef QT_NO_SSL - QSslSocket *serverSocket = new QSslSocket; - serverSocket->setParent(this); - if (serverSocket->setSocketDescriptor(socketDescriptor)) { - connect(serverSocket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(slotSslErrors(QList<QSslError>))); - setupSslServer(serverSocket); - serverSocket->startServerEncryption(); - client = serverSocket; - connectSocketSignals(); - } else { + if (doSsl) { + QSslSocket *serverSocket = new QSslSocket(this); + if (!serverSocket->setSocketDescriptor(socketDescriptor)) { delete serverSocket; return; } + connect(serverSocket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(slotSslErrors(QList<QSslError>))); + // connect(serverSocket, &QSslSocket::encrypted, this, &SslServer::ready); ? + setupSslServer(serverSocket); + client = serverSocket; + } else #endif + { + client = new QTcpSocket; + client->setSocketDescriptor(socketDescriptor); } + connectSocketSignals(); client->setParent(this); ++totalConnections; } - virtual void reply() { + virtual void reply() + { Q_ASSERT(!client.isNull()); // we need to emulate the bytesWrittenSlot call if the data is empty. if (dataToTransmit.size() == 0) { @@ -634,7 +635,8 @@ public slots: } } - void bytesWrittenSlot() { + void bytesWrittenSlot() + { Q_ASSERT(!client.isNull()); // Disconnect and delete in next cycle (else Windows clients will fail with RemoteHostClosedError). if (doClose && client->bytesToWrite() == 0) { @@ -879,7 +881,8 @@ class BlockingTcpServer : public QTcpServer public: BlockingTcpServer(bool ssl) : doSsl(ssl), sslSocket(0) {} - QTcpSocket* waitForNextConnectionSocket() { + QTcpSocket* waitForNextConnectionSocket() + { waitForNewConnection(-1); if (doSsl) { if (!sslSocket) @@ -900,7 +903,6 @@ public: serverSocket->setSocketDescriptor(socketDescriptor); connect(serverSocket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(slotSslErrors(QList<QSslError>))); setupSslServer(serverSocket); - serverSocket->startServerEncryption(); sslSocket = serverSocket; } else #endif @@ -1381,14 +1383,12 @@ static QByteArray msgWaitForFinished(QNetworkReplyPtr &reply) QString result; QDebug debug(&result); debug << reply->url(); - if (reply->isFinished()) { - if (reply->error() == QNetworkReply::NoError) - debug << "finished."; - else - debug << "failed: #" << reply->error() << reply->errorString(); - } else { + if (!reply->isFinished()) debug << "timed out."; - } + else if (reply->error() == QNetworkReply::NoError) + debug << "finished."; + else + debug << "failed: #" << reply->error() << reply->errorString(); return result.toLocal8Bit(); } @@ -1403,7 +1403,7 @@ int tst_QNetworkReply::waitForFinish(QNetworkReplyPtr &reply) QSignalSpy spy(reply.data(), SIGNAL(downloadProgress(qint64,qint64))); while (!reply->isFinished()) { QTimer::singleShot(5000, loop, SLOT(quit())); - if ( loop->exec() == Timeout && count == spy.count() && !reply->isFinished()) { + if (loop->exec() == Timeout && count == spy.count() && !reply->isFinished()) { returnCode = Timeout; break; } @@ -1417,12 +1417,14 @@ int tst_QNetworkReply::waitForFinish(QNetworkReplyPtr &reply) void tst_QNetworkReply::finished() { - loop->exit(returnCode = Success); + if (loop) + loop->exit(returnCode = Success); } void tst_QNetworkReply::gotError() { - loop->exit(returnCode = Failure); + if (loop) + loop->exit(returnCode = Failure); disconnect(QObject::sender(), SIGNAL(finished()), this, 0); } @@ -4725,11 +4727,13 @@ void tst_QNetworkReply::ioPostToHttpNoBufferFlag() } #ifndef QT_NO_SSL -class SslServer : public QTcpServer { +class SslServer : public QTcpServer +{ Q_OBJECT public: SslServer() : socket(0), m_ssl(true) {} - void incomingConnection(qintptr socketDescriptor) { + void incomingConnection(qintptr socketDescriptor) + { QSslSocket *serverSocket = new QSslSocket; serverSocket->setParent(this); @@ -4739,16 +4743,9 @@ public: emit newPlainConnection(serverSocket); return; } - QString testDataDir = QFileInfo(QFINDTESTDATA("rfc3252.txt")).absolutePath(); - if (testDataDir.isEmpty()) - testDataDir = QCoreApplication::applicationDirPath(); - connect(serverSocket, SIGNAL(encrypted()), this, SLOT(encryptedSlot())); - serverSocket->setProtocol(QSsl::AnyProtocol); connect(serverSocket, SIGNAL(sslErrors(QList<QSslError>)), serverSocket, SLOT(ignoreSslErrors())); - serverSocket->setLocalCertificate(testDataDir + "/certs/server.pem"); - serverSocket->setPrivateKey(testDataDir + "/certs/server.key"); - serverSocket->startServerEncryption(); + setupSslServer(serverSocket); } else { delete serverSocket; } @@ -4757,11 +4754,13 @@ signals: void newEncryptedConnection(QSslSocket *s); void newPlainConnection(QSslSocket *s); public slots: - void encryptedSlot() { + void encryptedSlot() + { socket = (QSslSocket*) sender(); emit newEncryptedConnection(socket); } - void readyReadSlot() { + void readyReadSlot() + { // for the incoming sockets, not the server socket //qDebug() << static_cast<QSslSocket*>(sender())->bytesAvailable() << static_cast<QSslSocket*>(sender())->encryptedBytesAvailable(); } @@ -4807,7 +4806,7 @@ void tst_QNetworkReply::ioPostToHttpsUploadProgress() disconnect(&server, SIGNAL(newEncryptedConnection(QSslSocket*)), &QTestEventLoop::instance(), SLOT(exitLoop())); - incomingSocket->setReadBufferSize(1*1024); + incomingSocket->setReadBufferSize(1024); // some progress should have been made QTRY_VERIFY(!spy.isEmpty()); QList<QVariant> args = spy.last(); @@ -4911,7 +4910,7 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp() QCOMPARE(reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(), (qint64)testData.size()); if (reader.data.size() < testData.size()) { // oops? - QCOMPARE(reader.data, testData.mid(0, reader.data.size())); + QCOMPARE(reader.data, testData.left(reader.data.size())); qDebug() << "The data is incomplete, the last" << testData.size() - reader.data.size() << "bytes are missing"; } QCOMPARE(reader.data.size(), testData.size()); @@ -4958,7 +4957,7 @@ void tst_QNetworkReply::ioPostToHttpUploadProgress() QVERIFY(incomingSocket); disconnect(&server, SIGNAL(newConnection()), &QTestEventLoop::instance(), SLOT(exitLoop())); - incomingSocket->setReadBufferSize(1*1024); + incomingSocket->setReadBufferSize(1024); QTestEventLoop::instance().enterLoop(5); // some progress should have been made QVERIFY(!spy.isEmpty()); @@ -5660,12 +5659,14 @@ void tst_QNetworkReply::httpProxyCommands() QCOMPARE(uaheader, QByteArray("User-Agent: QNetworkReplyAutoTest/1.0")); } -class ProxyChangeHelper : public QObject { +class ProxyChangeHelper : public QObject +{ Q_OBJECT public: ProxyChangeHelper() : QObject(), signalCount(0) {}; public slots: - void finishedSlot() { + void finishedSlot() + { signalCount++; if (signalCount == 2) QMetaObject::invokeMethod(&QTestEventLoop::instance(), "exitLoop", Qt::QueuedConnection); @@ -5911,7 +5912,8 @@ void tst_QNetworkReply::httpReUsingConnectionSequential() reply2->deleteLater(); } -class HttpReUsingConnectionFromFinishedSlot : public QObject { +class HttpReUsingConnectionFromFinishedSlot : public QObject +{ Q_OBJECT public: QNetworkReply* reply1; @@ -5919,7 +5921,8 @@ public: QUrl url; QNetworkAccessManager manager; public slots: - void finishedSlot() { + void finishedSlot() + { QVERIFY(!reply1->error()); QFETCH(bool, doDeleteLater); @@ -5967,7 +5970,8 @@ void tst_QNetworkReply::httpReUsingConnectionFromFinishedSlot() QCOMPARE(server.totalConnections, 1); } -class HttpRecursiveCreationHelper : public QObject { +class HttpRecursiveCreationHelper : public QObject +{ Q_OBJECT public: @@ -5983,7 +5987,8 @@ public: int requestsStartedCount_readyRead; int requestsFinishedCount; public slots: - void finishedSlot() { + void finishedSlot() + { requestsFinishedCount++; QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); @@ -6002,7 +6007,8 @@ public slots: reply->deleteLater(); } - void readyReadSlot() { + void readyReadSlot() + { QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); QVERIFY(!reply->error()); @@ -6011,7 +6017,8 @@ public slots: requestsStartedCount_readyRead++; } } - void startOne() { + void startOne() + { QUrl url = "http://" + QtNetworkSettings::serverName() + "/qtest/fluke.gif"; QNetworkRequest request(url); QNetworkReply *reply = manager.get(request); @@ -6380,7 +6387,8 @@ void tst_QNetworkReply::getFromHttpIntoBuffer() } // FIXME we really need to consolidate all those server implementations -class GetFromHttpIntoBuffer2Server : QObject { +class GetFromHttpIntoBuffer2Server : QObject +{ Q_OBJECT qint64 dataSize; qint64 dataSent; @@ -6390,26 +6398,28 @@ class GetFromHttpIntoBuffer2Server : QObject { bool chunkedEncoding; public: - GetFromHttpIntoBuffer2Server (qint64 ds, bool sscl, bool ce) : dataSize(ds), dataSent(0), - client(0), serverSendsContentLength(sscl), chunkedEncoding(ce) { + GetFromHttpIntoBuffer2Server (qint64 ds, bool sscl, bool ce) + : dataSize(ds), dataSent(0), client(0), + serverSendsContentLength(sscl), chunkedEncoding(ce) + { server.listen(); connect(&server, SIGNAL(newConnection()), this, SLOT(newConnectionSlot())); } - int serverPort() { - return server.serverPort(); - } + int serverPort() { return server.serverPort(); } public slots: - void newConnectionSlot() { + void newConnectionSlot() + { client = server.nextPendingConnection(); client->setParent(this); connect(client, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); connect(client, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWrittenSlot(qint64))); } - void readyReadSlot() { + void readyReadSlot() + { client->readAll(); client->write("HTTP/1.0 200 OK\n"); if (serverSendsContentLength) @@ -6419,7 +6429,8 @@ public slots: client->write("Connection: close\n\n"); } - void bytesWrittenSlot(qint64 amount) { + void bytesWrittenSlot(qint64 amount) + { Q_UNUSED(amount); if (dataSent == dataSize && client) { // close eventually @@ -6453,7 +6464,8 @@ public slots: } }; -class GetFromHttpIntoBuffer2Client : QObject { +class GetFromHttpIntoBuffer2Client : QObject +{ Q_OBJECT private: bool useDownloadBuffer; @@ -6470,7 +6482,8 @@ public: } public slots: - void metaDataChangedSlot() { + void metaDataChangedSlot() + { if (useDownloadBuffer) { QSharedPointer<char> sharedPointer = qvariant_cast<QSharedPointer<char> >(reply->attribute(QNetworkRequest::DownloadBufferAttribute)); QVERIFY(!sharedPointer.isNull()); // It will be 0 if it failed @@ -6480,7 +6493,8 @@ public: QVERIFY(bytesAvailableList.isEmpty()); } - void readyReadSlot() { + void readyReadSlot() + { QVERIFY(!reply->isFinished()); qint64 bytesAvailable = reply->bytesAvailable(); @@ -6502,7 +6516,8 @@ public: // Add bytesAvailable to a list an parse } - void finishedSlot() { + void finishedSlot() + { // We should have already received all readyRead QVERIFY(!bytesAvailableList.isEmpty()); QCOMPARE(bytesAvailableList.last(), uploadSize); @@ -6908,17 +6923,17 @@ void tst_QNetworkReply::authenticationWithDifferentRealm() } #endif // !QT_NO_NETWORKPROXY -class QtBug13431Helper : public QObject { +class QtBug13431Helper : public QObject +{ Q_OBJECT public: QNetworkReply* m_reply; QTimer m_dlTimer; public slots: - void replyFinished(QNetworkReply*) { - QTestEventLoop::instance().exitLoop(); - } + void replyFinished(QNetworkReply*) { QTestEventLoop::instance().exitLoop(); } - void onReadAndReschedule() { + void onReadAndReschedule() + { const qint64 bytesReceived = m_reply->bytesAvailable(); if (bytesReceived && m_reply->readBufferSize()) { QByteArray data = m_reply->read(bytesReceived); @@ -7066,7 +7081,8 @@ void tst_QNetworkReply::qtbug22660gzipNoContentLengthEmptyContent() QCOMPARE(reply->readAll(), QByteArray()); } -class QtBug27161Helper : public QObject { +class QtBug27161Helper : public QObject +{ Q_OBJECT public: QtBug27161Helper(MiniHttpServer & server, const QByteArray & data): @@ -7076,16 +7092,19 @@ public: connect(&m_server, SIGNAL(newConnection()), this, SLOT(newConnectionSlot())); } public slots: - void newConnectionSlot(){ + void newConnectionSlot() + { connect(m_server.client, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWrittenSlot())); } - void bytesWrittenSlot(){ + void bytesWrittenSlot() + { disconnect(m_server.client, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWrittenSlot())); m_Timer.singleShot(100, this, SLOT(timeoutSlot())); } - void timeoutSlot(){ + void timeoutSlot() + { m_server.doClose = true; // we need to emulate the bytesWrittenSlot call if the data is empty. if (m_data.size() == 0) @@ -7514,10 +7533,12 @@ void tst_QNetworkReply::httpUserAgent() void tst_QNetworkReply::synchronousAuthenticationCache() { - class MiniAuthServer : public MiniHttpServer { + class MiniAuthServer : public MiniHttpServer + { public: - MiniAuthServer(QThread *thread) : MiniHttpServer(QByteArray(), false, thread) {}; - virtual void reply() { + MiniAuthServer(QThread *thread) : MiniHttpServer(QByteArray(), false, thread) {} + virtual void reply() + { dataToTransmit = "HTTP/1.0 401 Unauthorized\r\n" @@ -7929,7 +7950,8 @@ public: qint64 bandwidthQuota; QTimer timer; - RateLimitedUploadDevice(QByteArray d) : QIODevice(),data(d),read(0),bandwidthQuota(0) { + RateLimitedUploadDevice(QByteArray d) : QIODevice(),data(d),read(0),bandwidthQuota(0) + { buffer.setData(data); buffer.open(QIODevice::ReadOnly); timer.setInterval(200); @@ -7937,12 +7959,14 @@ public: timer.start(); } - virtual qint64 writeData(const char* , qint64 ) { + virtual qint64 writeData(const char* , qint64 ) + { Q_ASSERT(false); return 0; } - virtual qint64 readData(char* data, qint64 maxlen) { + virtual qint64 readData(char* data, qint64 maxlen) + { //qDebug() << Q_FUNC_INFO << maxlen << bandwidthQuota; maxlen = qMin(maxlen, buffer.bytesAvailable()); maxlen = qMin(maxlen, bandwidthQuota); @@ -7959,24 +7983,17 @@ public: //qDebug() << Q_FUNC_INFO << maxlen << bandwidthQuota << read << ret << buffer.bytesAvailable(); return ret; } - virtual bool atEnd() const { - return buffer.atEnd(); - } - virtual qint64 size() const{ - return data.length(); - } + virtual bool atEnd() const { return buffer.atEnd(); } + virtual qint64 size() const { return data.length(); } qint64 bytesAvailable() const { return buffer.bytesAvailable() + QIODevice::bytesAvailable(); } - virtual bool isSequential() const{ // random access, we can seek - return false; - } - virtual bool seek ( qint64 pos ) { - return buffer.seek(pos); - } + virtual bool isSequential() const { return false; } // random access, we can seek + virtual bool seek (qint64 pos) { return buffer.seek(pos); } protected slots: - void timeoutSlot() { + void timeoutSlot() + { //qDebug() << Q_FUNC_INFO; bandwidthQuota = 8*1024; // fill quota emit readyRead(); @@ -8166,9 +8183,7 @@ signals: void corruptFileUploadReceived(); public slots: - void closeDelayed() { - m_socket->close(); - } + void closeDelayed() { m_socket->close(); } void readyReadSlot() { @@ -8193,17 +8208,18 @@ public slots: // We had received some data but it is corrupt! qDebug() << "CORRUPT" << m_receivedData.count(); - // Use this to track down the pattern of the corruption and conclude the source -// QFile a("/tmp/corrupt"); -// a.open(QIODevice::WriteOnly); -// a.write(m_receivedData); -// a.close(); +#if 0 // Use this to track down the pattern of the corruption and conclude the source + QFile a("/tmp/corrupt"); + a.open(QIODevice::WriteOnly); + a.write(m_receivedData); + a.close(); -// QFile b("/tmp/correct"); -// b.open(QIODevice::WriteOnly); -// b.write(m_expectedData); -// b.close(); + QFile b("/tmp/correct"); + b.open(QIODevice::WriteOnly); + b.write(m_expectedData); + b.close(); //exit(1); +#endif emit corruptFileUploadReceived(); } else { emit correctFileUploadReceived(); @@ -8220,26 +8236,26 @@ public: int m_repliesFinished; int m_expectedReplies; QByteArray m_expectedData; - PutWithServerClosingConnectionImmediatelyServer() : SslServer(), m_correctUploads(0), m_corruptUploads(0), m_repliesFinished(0), m_expectedReplies(0) + PutWithServerClosingConnectionImmediatelyServer() + : SslServer(), m_correctUploads(0), m_corruptUploads(0), + m_repliesFinished(0), m_expectedReplies(0) { QObject::connect(this, SIGNAL(newEncryptedConnection(QSslSocket*)), this, SLOT(createHandlerForConnection(QSslSocket*))); QObject::connect(this, SIGNAL(newPlainConnection(QSslSocket*)), this, SLOT(createHandlerForConnection(QSslSocket*))); } public slots: - void createHandlerForConnection(QSslSocket* s) { + void createHandlerForConnection(QSslSocket* s) + { PutWithServerClosingConnectionImmediatelyHandler *handler = new PutWithServerClosingConnectionImmediatelyHandler(s, m_expectedData); handler->setParent(this); QObject::connect(handler, SIGNAL(correctFileUploadReceived()), this, SLOT(increaseCorrect())); QObject::connect(handler, SIGNAL(corruptFileUploadReceived()), this, SLOT(increaseCorrupt())); } - void increaseCorrect() { - m_correctUploads++; - } - void increaseCorrupt() { - m_corruptUploads++; - } - void replyFinished() { + void increaseCorrect() { m_correctUploads++; } + void increaseCorrupt() { m_corruptUploads++; } + void replyFinished() + { m_repliesFinished++; if (m_repliesFinished == m_expectedReplies) { QTestEventLoop::instance().exitLoop(); diff --git a/tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp b/tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp index 0a52dd0388..6ca881d38a 100644 --- a/tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp +++ b/tests/auto/network/bearer/qnetworkconfiguration/tst_qnetworkconfiguration.cpp @@ -53,6 +53,7 @@ private slots: void comparison(); void children(); void isRoamingAvailable(); + void connectTimeout(); #endif }; @@ -181,6 +182,21 @@ void tst_QNetworkConfiguration::isRoamingAvailable() } } } + +void tst_QNetworkConfiguration::connectTimeout() +{ + QNetworkConfigurationManager manager; + QList<QNetworkConfiguration> configs = manager.allConfigurations(); + + foreach (QNetworkConfiguration networkConfiguration, configs) { + QCOMPARE(networkConfiguration.connectTimeout(), 30000); + + bool result = networkConfiguration.setConnectTimeout(100); + QVERIFY(result); + + QCOMPARE(networkConfiguration.connectTimeout(), 100); + } +} #endif QTEST_MAIN(tst_QNetworkConfiguration) diff --git a/tests/auto/network/kernel/qnetworkdatagram/qnetworkdatagram.pro b/tests/auto/network/kernel/qnetworkdatagram/qnetworkdatagram.pro index a2fe44060e..23d57f3fbf 100644 --- a/tests/auto/network/kernel/qnetworkdatagram/qnetworkdatagram.pro +++ b/tests/auto/network/kernel/qnetworkdatagram/qnetworkdatagram.pro @@ -1,5 +1,4 @@ CONFIG += testcase console -CONFIG -= app_bundle TARGET = tst_qnetworkdatagram SOURCES += tst_qnetworkdatagram.cpp QT = core network testlib |