diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2012-02-21 14:58:57 +0100 |
---|---|---|
committer | João Abecasis <joao.abecasis@nokia.com> | 2012-02-21 14:58:57 +0100 |
commit | 31a0358afb4fde998d1eeeaa80fc32e4420266c7 (patch) | |
tree | 938455353474196c1f49b0529b5b644e19c21f3e /tests/auto/network | |
parent | 4c8a4058c359c8d163c643120426079fc80c8214 (diff) | |
parent | 69da8588d41bbf5ab785f5ad7c1fce76deefc7d0 (diff) |
Merge remote-tracking branch 'gerrit/master' into containers
Conflicts:
src/corelib/tools/qbytearray.h
Change-Id: I03b1f3e05c9b7a45130887c522fcd9b7aa387129
Diffstat (limited to 'tests/auto/network')
20 files changed, 619 insertions, 481 deletions
diff --git a/tests/auto/network/access/qabstractnetworkcache/qabstractnetworkcache.pro b/tests/auto/network/access/qabstractnetworkcache/qabstractnetworkcache.pro index 719c34f286..ef47a4b458 100644 --- a/tests/auto/network/access/qabstractnetworkcache/qabstractnetworkcache.pro +++ b/tests/auto/network/access/qabstractnetworkcache/qabstractnetworkcache.pro @@ -4,10 +4,6 @@ QT += network testlib QT -= gui SOURCES += tst_qabstractnetworkcache.cpp -wince* { - testFiles.files = tests - testFiles.path = . - DEPLOYMENT += testFiles -} +TESTDATA += tests/* CONFIG += insignificant_test # QTBUG-20686; note, assumed unstable on all platforms diff --git a/tests/auto/network/access/qnetworkcookie/tst_qnetworkcookie.cpp b/tests/auto/network/access/qnetworkcookie/tst_qnetworkcookie.cpp index 7c27973b56..bcd9cbdff7 100644 --- a/tests/auto/network/access/qnetworkcookie/tst_qnetworkcookie.cpp +++ b/tests/auto/network/access/qnetworkcookie/tst_qnetworkcookie.cpp @@ -165,11 +165,11 @@ void tst_QNetworkCookie::parseSingleCookie_data() QTest::newRow("with-value2") << " a=b" << cookie; QTest::newRow("with-value3") << "a=b " << cookie; QTest::newRow("with-value4") << " a=b " << cookie; - QTest::newRow("with-value4") << " a=b ;" << cookie; - QTest::newRow("with-value5") << "a =b" << cookie; - QTest::newRow("with-value6") << "a= b" << cookie; - QTest::newRow("with-value7") << "a = b" << cookie; - QTest::newRow("with-value8") << "a = b " << cookie; + QTest::newRow("with-value5") << " a=b ;" << cookie; + QTest::newRow("with-value6") << "a =b" << cookie; + QTest::newRow("with-value7") << "a= b" << cookie; + QTest::newRow("with-value8") << "a = b" << cookie; + QTest::newRow("with-value9") << "a = b " << cookie; cookie.setValue("\",\""); QTest::newRow("with-value-with-special1") << "a = \",\" " << cookie; @@ -376,31 +376,31 @@ void tst_QNetworkCookie::parseSingleCookie_data() // extra offsets cookie.setExpirationDate(QDateTime(QDate(1989, 1, 2), QTime(0, 0), Qt::UTC)); - QTest::newRow("zoneoffset-14") << "a=b;expires=Jan 1 89 15:0 JST+1" << cookie; + QTest::newRow("zoneoffset-15") << "a=b;expires=Jan 1 89 15:0 JST+1" << cookie; cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 0), Qt::UTC)); - QTest::newRow("zoneoffset-15") << "a=b;expires=Jan 1 89 0:0 GMT+1" << cookie; + QTest::newRow("zoneoffset-16") << "a=b;expires=Jan 1 89 0:0 GMT+1" << cookie; cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); - QTest::newRow("zoneoffset-15b") << "a=b;expires=Jan 1 89 1:0 GMT-1" << cookie; + QTest::newRow("zoneoffset-17") << "a=b;expires=Jan 1 89 1:0 GMT-1" << cookie; cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 0), Qt::UTC)); - QTest::newRow("zoneoffset-16") << "a=b;expires=Jan 1 89 0:0 GMT+01" << cookie; + QTest::newRow("zoneoffset-18") << "a=b;expires=Jan 1 89 0:0 GMT+01" << cookie; cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 5), Qt::UTC)); - QTest::newRow("zoneoffset-17") << "a=b;expires=Jan 1 89 0:0 GMT+0105" << cookie; + QTest::newRow("zoneoffset-19") << "a=b;expires=Jan 1 89 0:0 GMT+0105" << cookie; cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); - QTest::newRow("zoneoffset-18") << "a=b;expires=Jan 1 89 0:0 GMT+015" << cookie; + QTest::newRow("zoneoffset-20") << "a=b;expires=Jan 1 89 0:0 GMT+015" << cookie; cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); - QTest::newRow("zoneoffset-19") << "a=b;expires=Jan 1 89 0:0 GM" << cookie; + QTest::newRow("zoneoffset-21") << "a=b;expires=Jan 1 89 0:0 GM" << cookie; cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); - QTest::newRow("zoneoffset-19b") << "a=b;expires=Jan 1 89 0:0 GMT" << cookie; + QTest::newRow("zoneoffset-22") << "a=b;expires=Jan 1 89 0:0 GMT" << cookie; // offsets from gmt cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 0), Qt::UTC)); - QTest::newRow("zoneoffset-20") << "a=b;expires=Jan 1 89 0:0 +1" << cookie; + QTest::newRow("zoneoffset-23") << "a=b;expires=Jan 1 89 0:0 +1" << cookie; cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 0), Qt::UTC)); - QTest::newRow("zoneoffset-21") << "a=b;expires=Jan 1 89 0:0 +01" << cookie; + QTest::newRow("zoneoffset-24") << "a=b;expires=Jan 1 89 0:0 +01" << cookie; cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 1), Qt::UTC)); - QTest::newRow("zoneoffset-22") << "a=b;expires=Jan 1 89 0:0 +0101" << cookie; + QTest::newRow("zoneoffset-25") << "a=b;expires=Jan 1 89 0:0 +0101" << cookie; cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); - QTest::newRow("zoneoffset-23") << "a=b;expires=Jan 1 89 1:0 -1" << cookie; + QTest::newRow("zoneoffset-26") << "a=b;expires=Jan 1 89 1:0 -1" << cookie; // Y2k cookie.setExpirationDate(QDateTime(QDate(2000, 1, 1), QTime(0, 0), Qt::UTC)); diff --git a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp index 73d0a4a650..0e046ad6f9 100644 --- a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp +++ b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp @@ -284,7 +284,7 @@ void tst_QNetworkCookieJar::cookiesForUrl_data() QTest::newRow("match-2") << allCookies << "http://nokia.com/web/" << result; QTest::newRow("match-3") << allCookies << "http://nokia.com/web/content" << result; QTest::newRow("match-4") << allCookies << "http://qt.nokia.com/web" << result; - QTest::newRow("match-4") << allCookies << "http://qt.nokia.com/web/" << result; + QTest::newRow("match-5") << allCookies << "http://qt.nokia.com/web/" << result; QTest::newRow("match-6") << allCookies << "http://qt.nokia.com/web/content" << result; cookie.setPath("/web/wiki"); @@ -295,7 +295,7 @@ void tst_QNetworkCookieJar::cookiesForUrl_data() QTest::newRow("one-match-2") << allCookies << "http://nokia.com/web/" << result; QTest::newRow("one-match-3") << allCookies << "http://nokia.com/web/content" << result; QTest::newRow("one-match-4") << allCookies << "http://qt.nokia.com/web" << result; - QTest::newRow("one-match-4") << allCookies << "http://qt.nokia.com/web/" << result; + QTest::newRow("one-match-5") << allCookies << "http://qt.nokia.com/web/" << result; QTest::newRow("one-match-6") << allCookies << "http://qt.nokia.com/web/content" << result; result.prepend(cookie); // longer path, it must match first @@ -317,7 +317,7 @@ void tst_QNetworkCookieJar::cookiesForUrl_data() QTest::newRow("exp-match-2") << allCookies << "http://nokia.com/web/" << result; QTest::newRow("exp-match-3") << allCookies << "http://nokia.com/web/content" << result; QTest::newRow("exp-match-4") << allCookies << "http://qt.nokia.com/web" << result; - QTest::newRow("exp-match-4") << allCookies << "http://qt.nokia.com/web/" << result; + QTest::newRow("exp-match-5") << allCookies << "http://qt.nokia.com/web/" << result; QTest::newRow("exp-match-6") << allCookies << "http://qt.nokia.com/web/content" << result; // path matching diff --git a/tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp b/tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp index 533108e76b..8a3c52cf72 100644 --- a/tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp +++ b/tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp @@ -306,7 +306,7 @@ void tst_QNetworkDiskCache::data_data() QNetworkCacheMetaData::RawHeaderList headers; headers.append(QNetworkCacheMetaData::RawHeader("type", "bin")); metaData.setRawHeaders(headers); - QTest::newRow("null") << metaData; + QTest::newRow("non-null") << metaData; } // public QIODevice* data(QUrl const& url) diff --git a/tests/auto/network/access/qnetworkreply/echo/main.cpp b/tests/auto/network/access/qnetworkreply/echo/main.cpp index 8e6811d2ff..90217e4923 100644 --- a/tests/auto/network/access/qnetworkreply/echo/main.cpp +++ b/tests/auto/network/access/qnetworkreply/echo/main.cpp @@ -39,8 +39,7 @@ ** ****************************************************************************/ - -#include <QtCore> +#include <QtCore/QFile> int main(int argc, char **) { diff --git a/tests/auto/network/access/qnetworkreply/qnetworkreply.pro b/tests/auto/network/access/qnetworkreply/qnetworkreply.pro index 0bcf067c4f..885e7f15b6 100644 --- a/tests/auto/network/access/qnetworkreply/qnetworkreply.pro +++ b/tests/auto/network/access/qnetworkreply/qnetworkreply.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs -SUBDIRS = test !wince*:SUBDIRS += echo +test.depends += $$SUBDIRS +SUBDIRS += test diff --git a/tests/auto/network/access/qnetworkreply/test/test.pro b/tests/auto/network/access/qnetworkreply/test/test.pro index 1dfd67a1c8..f267b09631 100644 --- a/tests/auto/network/access/qnetworkreply/test/test.pro +++ b/tests/auto/network/access/qnetworkreply/test/test.pro @@ -5,26 +5,13 @@ TARGET = ../tst_qnetworkreply contains(QT_CONFIG,xcb): CONFIG+=insignificant_test # unstable, QTBUG-21102 -win32 { - CONFIG(debug, debug|release) { - TARGET = ../../debug/tst_qnetworkreply -} else { - TARGET = ../../release/tst_qnetworkreply - } -} - -DEFINES += SRCDIR=\\\"$$PWD/..\\\" - QT = core-private network-private testlib RESOURCES += ../qnetworkreply.qrc -wince* { - # For cross compiled targets, reference data files need to be deployed - addFiles.files = ../empty ../rfc3252.txt ../resource ../bigfile ../*.jpg - addFiles.path = . - DEPLOYMENT += addFiles +contains(QT_CONFIG,ipv6ifname): DEFINES += HAVE_IPV6 +TESTDATA += ../empty ../rfc3252.txt ../resource ../bigfile ../*.jpg ../certs \ + ../index.html ../smb-file.txt - certFiles.files = ../certs - certFiles.path = . - DEPLOYMENT += certFiles -} +win32:CONFIG += insignificant_test # QTBUG-24226 +load(testcase) # for target.path and installTestHelperApp() +installTestHelperApp("../echo/echo",echo,echo) diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index 959250acb4..279570b547 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -135,6 +135,7 @@ class tst_QNetworkReply: public QObject enum RunSimpleRequestReturn { Timeout = 0, Success, Failure }; int returnCode; QString testFileName; + QString echoProcessDir; #if !defined Q_OS_WIN QString wronlyFileName; #endif @@ -162,6 +163,7 @@ public: QString runCustomRequest(const QNetworkRequest &request, QNetworkReplyPtr &reply, const QByteArray &verb, QIODevice *data); + int waitForFinish(QNetworkReplyPtr &reply); public Q_SLOTS: void finished(); @@ -391,8 +393,13 @@ private Q_SLOTS: void synchronousAuthenticationCache(); void pipelining(); + void closeDuringDownload_data(); + void closeDuringDownload(); + // NOTE: This test must be last! void parentingRepliesToTheApp(); +private: + QString testDataDir; }; bool tst_QNetworkReply::seedCreated = false; @@ -446,9 +453,13 @@ QT_END_NAMESPACE #ifndef QT_NO_OPENSSL static void setupSslServer(QSslSocket* serverSocket) { + QString testDataDir = QFileInfo(QFINDTESTDATA("rfc3252.txt")).absolutePath(); + if (testDataDir.isEmpty()) + testDataDir = QCoreApplication::applicationDirPath(); + serverSocket->setProtocol(QSsl::AnyProtocol); - serverSocket->setLocalCertificate(SRCDIR "/certs/server.pem"); - serverSocket->setPrivateKey(SRCDIR "/certs/server.key"); + serverSocket->setLocalCertificate(testDataDir + "/certs/server.pem"); + serverSocket->setPrivateKey(testDataDir + "/certs/server.key"); } #endif @@ -1231,9 +1242,18 @@ QString tst_QNetworkReply::runSimpleRequest(QNetworkAccessManager::Operation op, connect(reply, SIGNAL(finished()), SLOT(finished())); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(gotError())); + int count = 0; loop = new QEventLoop; - QTimer::singleShot(20000, loop, SLOT(quit())); - code = returnCode == Timeout ? loop->exec() : returnCode; + QSignalSpy spy(reply, SIGNAL(downloadProgress(qint64,qint64))); + while (!reply->isFinished()) { + QTimer::singleShot(20000, loop, SLOT(quit())); + code = loop->exec(); + if (count == spy.count() && !reply->isFinished()) { + code = Timeout; + break; + } + count = spy.count(); + } delete loop; loop = 0; } @@ -1273,6 +1293,31 @@ QString tst_QNetworkReply::runCustomRequest(const QNetworkRequest &request, return QString(); } +int tst_QNetworkReply::waitForFinish(QNetworkReplyPtr &reply) +{ + int code = Success; + int count = 0; + + connect(reply, SIGNAL(finished()), SLOT(finished())); + connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(gotError())); + + loop = new QEventLoop; + QSignalSpy spy(reply, SIGNAL(downloadProgress(qint64,qint64))); + while (!reply->isFinished()) { + QTimer::singleShot(10000, loop, SLOT(quit())); + code = loop->exec(); + if (count == spy.count() && !reply->isFinished()) { + code = Timeout; + break; + } + count = spy.count(); + } + delete loop; + loop = 0; + + return code; +} + void tst_QNetworkReply::finished() { loop->exit(returnCode = Success); @@ -1286,16 +1331,20 @@ void tst_QNetworkReply::gotError() void tst_QNetworkReply::initTestCase() { + testDataDir = QFileInfo(QFINDTESTDATA("rfc3252.txt")).absolutePath(); + if (testDataDir.isEmpty()) + testDataDir = QCoreApplication::applicationDirPath(); + QVERIFY(QtNetworkSettings::verifyTestNetworkSettings()); #if !defined Q_OS_WIN - wronlyFileName = QDir::currentPath() + "/write-only"; + wronlyFileName = testDataDir + "/write-only"; QFile wr(wronlyFileName); QVERIFY(wr.open(QIODevice::WriteOnly | QIODevice::Truncate)); wr.setPermissions(QFile::WriteOwner | QFile::WriteUser); wr.close(); #endif - QDir::setSearchPaths("srcdir", QStringList() << SRCDIR); + QDir::setSearchPaths("testdata", QStringList() << testDataDir); #ifndef QT_NO_OPENSSL QSslSocket::defaultCaCertificates(); //preload certificates #endif @@ -1308,6 +1357,10 @@ void tst_QNetworkReply::initTestCase() QVERIFY(networkSession->waitForOpened(30000)); } #endif + + echoProcessDir = QFINDTESTDATA("echo"); + QVERIFY2(!echoProcessDir.isEmpty(), qPrintable( + QString::fromLatin1("Couldn't find echo dir starting from %1.").arg(QDir::currentPath()))); } void tst_QNetworkReply::cleanupTestCase() @@ -1528,10 +1581,10 @@ void tst_QNetworkReply::getFromFileSpecial_data() QTest::addColumn<QString>("url"); QTest::newRow("resource") << ":/resource" << "qrc:/resource"; - QTest::newRow("search-path") << "srcdir:/rfc3252.txt" << "srcdir:/rfc3252.txt"; - QTest::newRow("bigfile-path") << "srcdir:/bigfile" << "srcdir:/bigfile"; + QTest::newRow("search-path") << "testdata:/rfc3252.txt" << "testdata:/rfc3252.txt"; + QTest::newRow("bigfile-path") << "testdata:/bigfile" << "testdata:/bigfile"; #ifdef Q_OS_WIN - QTest::newRow("smb-path") << "srcdir:/smb-file.txt" << "file://" + QtNetworkSettings::winServerName() + "/testshare/test.pri"; + QTest::newRow("smb-path") << "testdata:/smb-file.txt" << "file://" + QtNetworkSettings::winServerName() + "/testshare/test.pri"; #endif } @@ -1561,8 +1614,8 @@ void tst_QNetworkReply::getFromFtp_data() QTest::addColumn<QString>("referenceName"); QTest::addColumn<QString>("url"); - QTest::newRow("rfc3252.txt") << SRCDIR "/rfc3252.txt" << "ftp://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt"; - QTest::newRow("bigfile") << SRCDIR "/bigfile" << "ftp://" + QtNetworkSettings::serverName() + "/qtest/bigfile"; + QTest::newRow("rfc3252.txt") << (testDataDir + "/rfc3252.txt") << "ftp://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt"; + QTest::newRow("bigfile") << (testDataDir + "/bigfile") << "ftp://" + QtNetworkSettings::serverName() + "/qtest/bigfile"; } void tst_QNetworkReply::getFromFtp() @@ -1589,9 +1642,9 @@ void tst_QNetworkReply::getFromHttp_data() QTest::addColumn<QString>("referenceName"); QTest::addColumn<QString>("url"); - QTest::newRow("success-internal") << SRCDIR "/rfc3252.txt" << "http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt"; - QTest::newRow("success-external") << SRCDIR "/rfc3252.txt" << "http://www.ietf.org/rfc/rfc3252.txt"; - QTest::newRow("bigfile-internal") << SRCDIR "/bigfile" << "http://" + QtNetworkSettings::serverName() + "/qtest/bigfile"; + QTest::newRow("success-internal") << (testDataDir + "/rfc3252.txt") << "http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt"; + QTest::newRow("success-external") << (testDataDir + "/rfc3252.txt") << "http://www.ietf.org/rfc/rfc3252.txt"; + QTest::newRow("bigfile-internal") << (testDataDir + "/bigfile") << "http://" + QtNetworkSettings::serverName() + "/qtest/bigfile"; } void tst_QNetworkReply::getFromHttp() @@ -1628,9 +1681,9 @@ void tst_QNetworkReply::headFromHttp_data() QTest::addColumn<QString>("contentType"); QTest::addColumn<QNetworkProxy>("proxy"); - qint64 rfcsize = QFileInfo(SRCDIR "/rfc3252.txt").size(); - qint64 bigfilesize = QFileInfo(SRCDIR "/bigfile").size(); - qint64 indexsize = QFileInfo(SRCDIR "/index.html").size(); + qint64 rfcsize = QFileInfo(testDataDir + "/rfc3252.txt").size(); + qint64 bigfilesize = QFileInfo(testDataDir + "/bigfile").size(); + qint64 indexsize = QFileInfo(testDataDir + "/index.html").size(); //testing proxies, mainly for the 407 response from http proxy for (int i = 0; i < proxies.count(); ++i) { @@ -1689,7 +1742,7 @@ void tst_QNetworkReply::getErrors_data() // empties QTest::newRow("empty-url") << QString() << int(QNetworkReply::ProtocolUnknownError) << 0 << true; - QTest::newRow("empty-scheme-host") << SRCDIR "/rfc3252.txt" << int(QNetworkReply::ProtocolUnknownError) << 0 << true; + QTest::newRow("empty-scheme-host") << (testDataDir + "/rfc3252.txt") << int(QNetworkReply::ProtocolUnknownError) << 0 << true; QTest::newRow("empty-scheme") << "//" + QtNetworkSettings::winServerName() + "/testshare/test.pri" << int(QNetworkReply::ProtocolUnknownError) << 0 << true; @@ -1742,6 +1795,14 @@ void tst_QNetworkReply::getErrors() QFETCH(QString, url); QNetworkRequest request(url); +#ifdef Q_OS_UNIX + if ((qstrcmp(QTest::currentDataTag(), "file-is-wronly") == 0) || + (qstrcmp(QTest::currentDataTag(), "file-permissions") == 0)) { + if (::getuid() == 0) + QSKIP("Running this test as root doesn't make sense"); + } +#endif + QNetworkReplyPtr reply = manager.get(request); reply->setParent(this); // we have expect-fails @@ -1749,11 +1810,7 @@ void tst_QNetworkReply::getErrors() QCOMPARE(reply->error(), QNetworkReply::NoError); // now run the request: - connect(reply, SIGNAL(finished()), - &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); - //qDebug() << reply->errorString(); + QVERIFY(waitForFinish(reply) != Timeout); QFETCH(int, error); QEXPECT_FAIL("ftp-is-dir", "QFtp cannot provide enough detail", Abort); @@ -1859,8 +1916,15 @@ void tst_QNetworkReply::putToFtp() QNetworkReply *r = qnam.get(req); QObject::connect(r, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QObject::disconnect(r, SIGNAL(finished(bool)), &QTestEventLoop::instance(), SLOT(exitLoop())); + int count = 0; + QSignalSpy spy(r, SIGNAL(downloadProgress(qint64,qint64))); + while (!r->isFinished()) { + QTestEventLoop::instance().enterLoop(10); + if (count == spy.count() && !r->isFinished()) + break; + count = spy.count(); + } + QObject::disconnect(r, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); QByteArray uploaded = r->readAll(); QCOMPARE(uploaded.size(), data.size()); @@ -2103,7 +2167,7 @@ void tst_QNetworkReply::postToHttpMultipart_data() imagePart11.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"testImage\"")); imagePart11.setRawHeader("Content-Location", "http://my.test.location.tld"); imagePart11.setRawHeader("Content-ID", "my@id.tld"); - QFile *file11 = new QFile(SRCDIR "/image1.jpg"); + QFile *file11 = new QFile(testDataDir + "/image1.jpg"); file11->open(QIODevice::ReadOnly); imagePart11.setBodyDevice(file11); QHttpMultiPart *imageMultiPart1 = new QHttpMultiPart(QHttpMultiPart::FormDataType); @@ -2117,7 +2181,7 @@ void tst_QNetworkReply::postToHttpMultipart_data() imagePart21.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"testImage1\"")); imagePart21.setRawHeader("Content-Location", "http://my.test.location.tld"); imagePart21.setRawHeader("Content-ID", "my@id.tld"); - QFile *file21 = new QFile(SRCDIR "/image1.jpg"); + QFile *file21 = new QFile(testDataDir + "/image1.jpg"); file21->open(QIODevice::ReadOnly); imagePart21.setBodyDevice(file21); QHttpMultiPart *imageMultiPart2 = new QHttpMultiPart(); @@ -2128,7 +2192,7 @@ void tst_QNetworkReply::postToHttpMultipart_data() QHttpPart imagePart22; imagePart22.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); imagePart22.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"testImage2\"")); - QFile *file22 = new QFile(SRCDIR "/image2.jpg"); + QFile *file22 = new QFile(testDataDir + "/image2.jpg"); file22->open(QIODevice::ReadOnly); imagePart22.setBodyDevice(file22); imageMultiPart2->append(imagePart22); @@ -2144,7 +2208,7 @@ void tst_QNetworkReply::postToHttpMultipart_data() imagePart31.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"testImage1\"")); imagePart31.setRawHeader("Content-Location", "http://my.test.location.tld"); imagePart31.setRawHeader("Content-ID", "my@id.tld"); - QFile *file31 = new QFile(SRCDIR "/image1.jpg"); + QFile *file31 = new QFile(testDataDir + "/image1.jpg"); file31->open(QIODevice::ReadOnly); imagePart31.setBodyDevice(file31); QHttpMultiPart *imageMultiPart3 = new QHttpMultiPart(QHttpMultiPart::FormDataType); @@ -2153,7 +2217,7 @@ void tst_QNetworkReply::postToHttpMultipart_data() QHttpPart imagePart32; imagePart32.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); imagePart32.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"testImage2\"")); - QFile *file32 = new QFile(SRCDIR "/image2.jpg"); + QFile *file32 = new QFile(testDataDir + "/image2.jpg"); file32->open(QIODevice::ReadOnly); imagePart32.setBodyDevice(file31); // check that resetting works imagePart32.setBodyDevice(file32); @@ -2162,7 +2226,7 @@ void tst_QNetworkReply::postToHttpMultipart_data() QHttpPart imagePart33; imagePart33.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); imagePart33.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"testImage3\"")); - QFile *file33 = new QFile(SRCDIR "/image3.jpg"); + QFile *file33 = new QFile(testDataDir + "/image3.jpg"); file33->open(QIODevice::ReadOnly); imagePart33.setBodyDevice(file33); imageMultiPart3->append(imagePart33); @@ -2177,7 +2241,7 @@ void tst_QNetworkReply::postToHttpMultipart_data() // QHttpPart imagePart41; // imagePart41.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); -// QFile *file41 = new QFile(SRCDIR "/image1.jpg"); +// QFile *file41 = new QFile(testDataDir + "/image1.jpg"); // file41->open(QIODevice::ReadOnly); // imagePart41.setBodyDevice(file41); // @@ -2211,7 +2275,7 @@ void tst_QNetworkReply::postToHttpMultipart_data() QHttpPart imagePart51; imagePart51.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); imagePart51.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"testImage\"")); - QFile *file51 = new QFile(SRCDIR "/image1.jpg"); + QFile *file51 = new QFile(testDataDir + "/image1.jpg"); file51->open(QIODevice::ReadOnly); QByteArray imageData = file51->readAll(); file51->close(); @@ -2418,6 +2482,10 @@ void tst_QNetworkReply::connectToIPv6Address() QFETCH(QByteArray, dataToSend); QFETCH(QByteArray, hostfield); +#if !defined(HAVE_IPV6) && defined(Q_OS_UNIX) + QSKIP("system doesn't support ipv6!"); +#endif + QByteArray httpResponse = QByteArray("HTTP/1.0 200 OK\r\nContent-Length: "); httpResponse += QByteArray::number(dataToSend.size()); httpResponse += "\r\n\r\n"; @@ -2430,9 +2498,7 @@ void tst_QNetworkReply::connectToIPv6Address() QNetworkRequest request(url); QNetworkReplyPtr reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); QByteArray content = reply->readAll(); //qDebug() << server.receivedData; QByteArray hostinfo = "\r\nHost: " + hostfield + ":" + QByteArray::number(server.serverPort()) + "\r\n"; @@ -2599,7 +2665,7 @@ void tst_QNetworkReply::ioGetFromFtp_data() QTest::newRow("bigfile") << "bigfile" << Q_INT64_C(519240); - QFile file(SRCDIR "/rfc3252.txt"); + QFile file(testDataDir + "/rfc3252.txt"); QTest::newRow("rfc3252.txt") << "rfc3252.txt" << file.size(); } @@ -2613,9 +2679,7 @@ void tst_QNetworkReply::ioGetFromFtp() QNetworkReplyPtr reply = manager.get(request); DataReader reader(reply); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->url(), request.url()); QCOMPARE(reply->error(), QNetworkReply::NoError); @@ -2630,7 +2694,7 @@ void tst_QNetworkReply::ioGetFromFtp() void tst_QNetworkReply::ioGetFromFtpWithReuse() { - QString fileName = SRCDIR "/rfc3252.txt"; + QString fileName = testDataDir + "/rfc3252.txt"; QFile reference(fileName); reference.open(QIODevice::ReadOnly); @@ -2643,14 +2707,8 @@ void tst_QNetworkReply::ioGetFromFtpWithReuse() DataReader reader2(reply2); QSignalSpy spy(reply1, SIGNAL(finished())); - connect(reply2, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); - if (spy.count() == 0) { - connect(reply1, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); - } + QVERIFY(waitForFinish(reply1) == Success); + QVERIFY(waitForFinish(reply2) == Success); QCOMPARE(reply1->url(), request.url()); QCOMPARE(reply2->url(), request.url()); @@ -2669,16 +2727,14 @@ void tst_QNetworkReply::ioGetFromFtpWithReuse() void tst_QNetworkReply::ioGetFromHttp() { - QFile reference(SRCDIR "/rfc3252.txt"); + QFile reference(testDataDir + "/rfc3252.txt"); QVERIFY(reference.open(QIODevice::ReadOnly)); QNetworkRequest request(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt")); QNetworkReplyPtr reply = manager.get(request); DataReader reader(reply); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->url(), request.url()); QCOMPARE(reply->error(), QNetworkReply::NoError); @@ -2692,7 +2748,7 @@ void tst_QNetworkReply::ioGetFromHttp() void tst_QNetworkReply::ioGetFromHttpWithReuseParallel() { - QFile reference(SRCDIR "/rfc3252.txt"); + QFile reference(testDataDir + "/rfc3252.txt"); QVERIFY(reference.open(QIODevice::ReadOnly)); QNetworkRequest request(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt")); @@ -2702,14 +2758,8 @@ void tst_QNetworkReply::ioGetFromHttpWithReuseParallel() DataReader reader2(reply2); QSignalSpy spy(reply1, SIGNAL(finished())); - connect(reply2, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); - if (spy.count() == 0) { - connect(reply1, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); - } + QVERIFY(waitForFinish(reply2) == Success); + QVERIFY(waitForFinish(reply1) == Success); QCOMPARE(reply1->url(), request.url()); QCOMPARE(reply2->url(), request.url()); @@ -2730,7 +2780,7 @@ void tst_QNetworkReply::ioGetFromHttpWithReuseParallel() void tst_QNetworkReply::ioGetFromHttpWithReuseSequential() { - QFile reference(SRCDIR "/rfc3252.txt"); + QFile reference(testDataDir + "/rfc3252.txt"); QVERIFY(reference.open(QIODevice::ReadOnly)); QNetworkRequest request(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt")); @@ -2738,9 +2788,7 @@ void tst_QNetworkReply::ioGetFromHttpWithReuseSequential() QNetworkReplyPtr reply = manager.get(request); DataReader reader(reply); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->url(), request.url()); QCOMPARE(reply->error(), QNetworkReply::NoError); @@ -2758,9 +2806,7 @@ void tst_QNetworkReply::ioGetFromHttpWithReuseSequential() QNetworkReplyPtr reply = manager.get(request); DataReader reader(reply); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->url(), request.url()); QCOMPARE(reply->error(), QNetworkReply::NoError); @@ -2777,12 +2823,21 @@ void tst_QNetworkReply::ioGetFromHttpWithAuth_data() { QTest::addColumn<QUrl>("url"); QTest::addColumn<QByteArray>("expectedData"); + QTest::addColumn<int>("expectedAuth"); - QFile reference(SRCDIR "/rfc3252.txt"); + QFile reference(testDataDir + "/rfc3252.txt"); reference.open(QIODevice::ReadOnly); QByteArray referenceData = reference.readAll(); - QTest::newRow("basic") << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfcs-auth/rfc3252.txt") << referenceData; - QTest::newRow("digest") << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/auth-digest/") << QByteArray("digest authentication successful\n"); + QTest::newRow("basic") << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfcs-auth/rfc3252.txt") << referenceData << 1; + QTest::newRow("digest") << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/auth-digest/") << QByteArray("digest authentication successful\n") << 1; + //if url contains username & password, then it should be used + QTest::newRow("basic-in-url") << QUrl("http://httptest:httptest@" + QtNetworkSettings::serverName() + "/qtest/rfcs-auth/rfc3252.txt") << referenceData << 0; + QTest::newRow("digest-in-url") << QUrl("http://httptest:httptest@" + QtNetworkSettings::serverName() + "/qtest/auth-digest/") << QByteArray("digest authentication successful\n") << 0; + // if url contains incorrect credentials, expect QNAM to ask for good ones (even if cached - matches behaviour of browsers) + QTest::newRow("basic-bad-user-in-url") << QUrl("http://baduser:httptest@" + QtNetworkSettings::serverName() + "/qtest/rfcs-auth/rfc3252.txt") << referenceData << 3; + QTest::newRow("basic-bad-password-in-url") << QUrl("http://httptest:wrong@" + QtNetworkSettings::serverName() + "/qtest/rfcs-auth/rfc3252.txt") << referenceData << 3; + QTest::newRow("digest-bad-user-in-url") << QUrl("http://baduser:httptest@" + QtNetworkSettings::serverName() + "/qtest/auth-digest/") << QByteArray("digest authentication successful\n") << 3; + QTest::newRow("digest-bad-password-in-url") << QUrl("http://httptest:wrong@" + QtNetworkSettings::serverName() + "/qtest/auth-digest/") << QByteArray("digest authentication successful\n") << 3; } void tst_QNetworkReply::ioGetFromHttpWithAuth() @@ -2793,6 +2848,7 @@ void tst_QNetworkReply::ioGetFromHttpWithAuth() QFETCH(QUrl, url); QFETCH(QByteArray, expectedData); + QFETCH(int, expectedAuth); QNetworkRequest request(url); { QNetworkReplyPtr reply1 = manager.get(request); @@ -2805,14 +2861,9 @@ void tst_QNetworkReply::ioGetFromHttpWithAuth() connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); - connect(reply2, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); - if (finishedspy.count() == 0) { - connect(reply1, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); - } + QVERIFY(waitForFinish(reply2) == Success); + QVERIFY(waitForFinish(reply1) == Success); + manager.disconnect(SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); @@ -2821,7 +2872,8 @@ void tst_QNetworkReply::ioGetFromHttpWithAuth() QCOMPARE(reader1.data, expectedData); QCOMPARE(reader2.data, expectedData); - QCOMPARE(authspy.count(), 1); + QCOMPARE(authspy.count(), (expectedAuth ? 1 : 0)); + expectedAuth = qMax(0, expectedAuth - 1); } // rinse and repeat: @@ -2832,16 +2884,17 @@ void tst_QNetworkReply::ioGetFromHttpWithAuth() QSignalSpy authspy(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*))); connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + + QVERIFY(waitForFinish(reply) == Success); + manager.disconnect(SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); QCOMPARE(reader.data, expectedData); - QCOMPARE(authspy.count(), 0); + QCOMPARE(authspy.count(), (expectedAuth ? 1 : 0)); + expectedAuth = qMax(0, expectedAuth - 1); } // now check with synchronous calls: @@ -2853,14 +2906,45 @@ void tst_QNetworkReply::ioGetFromHttpWithAuth() QSignalSpy authspy(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*))); QNetworkReplyPtr replySync = manager.get(request); QVERIFY(replySync->isFinished()); // synchronous - QCOMPARE(authspy.count(), 0); + if (expectedAuth) { + // bad credentials in a synchronous request should just fail + QCOMPARE(replySync->error(), QNetworkReply::AuthenticationRequiredError); + } else { + QCOMPARE(authspy.count(), 0); - // we cannot use a data reader here, since that connects to the readyRead signal, - // just use readAll() + // we cannot use a data reader here, since that connects to the readyRead signal, + // just use readAll() - // the only thing we check here is that the auth cache was used when using synchronous requests - QCOMPARE(replySync->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); - QCOMPARE(replySync->readAll(), expectedData); + // the only thing we check here is that the auth cache was used when using synchronous requests + QCOMPARE(replySync->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); + QCOMPARE(replySync->readAll(), expectedData); + } + } + + // check that credentials are used from cache if the same url is requested without credentials + { + url.setUserInfo(QString()); + request.setUrl(url); + request.setAttribute( + QNetworkRequest::SynchronousRequestAttribute, + true); + + QSignalSpy authspy(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*))); + QNetworkReplyPtr replySync = manager.get(request); + QVERIFY(replySync->isFinished()); // synchronous + if (expectedAuth) { + // bad credentials in a synchronous request should just fail + QCOMPARE(replySync->error(), QNetworkReply::AuthenticationRequiredError); + } else { + QCOMPARE(authspy.count(), 0); + + // we cannot use a data reader here, since that connects to the readyRead signal, + // just use readAll() + + // the only thing we check here is that the auth cache was used when using synchronous requests + QCOMPARE(replySync->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); + QCOMPARE(replySync->readAll(), expectedData); + } } } @@ -2890,7 +2974,7 @@ void tst_QNetworkReply::ioGetFromHttpWithProxyAuth() // This test sends three requests // The first two in parallel // The third after the first two finished - QFile reference(SRCDIR "/rfc3252.txt"); + QFile reference(testDataDir + "/rfc3252.txt"); QVERIFY(reference.open(QIODevice::ReadOnly)); QNetworkProxy proxy(QNetworkProxy::HttpCachingProxy, QtNetworkSettings::serverName(), 3129); @@ -2909,14 +2993,9 @@ void tst_QNetworkReply::ioGetFromHttpWithProxyAuth() connect(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); - connect(reply2, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); - if (finishedspy.count() == 0) { - connect(reply1, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); - } + QVERIFY(waitForFinish(reply2) == Success); + QVERIFY(waitForFinish(reply1) == Success); + manager.disconnect(SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this, SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); @@ -2940,9 +3019,9 @@ void tst_QNetworkReply::ioGetFromHttpWithProxyAuth() QSignalSpy authspy(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); connect(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + + QVERIFY(waitForFinish(reply) == Success); + manager.disconnect(SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this, SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); @@ -3002,7 +3081,7 @@ void tst_QNetworkReply::ioGetFromHttpWithSocksProxy() qRegisterMetaType<QNetworkProxy>(); // for QSignalSpy qRegisterMetaType<QAuthenticator *>(); - QFile reference(SRCDIR "/rfc3252.txt"); + QFile reference(testDataDir + "/rfc3252.txt"); QVERIFY(reference.open(QIODevice::ReadOnly)); QNetworkProxy proxy(QNetworkProxy::Socks5Proxy, QtNetworkSettings::serverName(), 1080); @@ -3016,9 +3095,9 @@ void tst_QNetworkReply::ioGetFromHttpWithSocksProxy() QSignalSpy authspy(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); connect(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + + QVERIFY(waitForFinish(reply) == Success); + manager.disconnect(SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this, SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); @@ -3039,9 +3118,9 @@ void tst_QNetworkReply::ioGetFromHttpWithSocksProxy() QSignalSpy authspy(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); connect(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + + QVERIFY(waitForFinish(reply) == Failure); + manager.disconnect(SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this, SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); @@ -3062,7 +3141,7 @@ void tst_QNetworkReply::ioGetFromHttpsWithSslErrors() qRegisterMetaType<QNetworkReply*>(); // for QSignalSpy qRegisterMetaType<QList<QSslError> >(); - QFile reference(SRCDIR "/rfc3252.txt"); + QFile reference(testDataDir + "/rfc3252.txt"); QVERIFY(reference.open(QIODevice::ReadOnly)); QNetworkRequest request(QUrl("https://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt")); @@ -3074,9 +3153,8 @@ void tst_QNetworkReply::ioGetFromHttpsWithSslErrors() SLOT(sslErrors(QNetworkReply*,QList<QSslError>))); connect(reply, SIGNAL(metaDataChanged()), SLOT(storeSslConfiguration())); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); + manager.disconnect(SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SLOT(sslErrors(QNetworkReply*,QList<QSslError>))); @@ -3097,7 +3175,7 @@ void tst_QNetworkReply::ioGetFromHttpsWithIgnoreSslErrors() qRegisterMetaType<QNetworkReply*>(); // for QSignalSpy qRegisterMetaType<QList<QSslError> >(); - QFile reference(SRCDIR "/rfc3252.txt"); + QFile reference(testDataDir + "/rfc3252.txt"); QVERIFY(reference.open(QIODevice::ReadOnly)); QNetworkRequest request(QUrl("https://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt")); @@ -3108,9 +3186,8 @@ void tst_QNetworkReply::ioGetFromHttpsWithIgnoreSslErrors() QSignalSpy sslspy(&manager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>))); connect(reply, SIGNAL(metaDataChanged()), SLOT(storeSslConfiguration())); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); QCOMPARE(reader.data, reference.readAll()); @@ -3126,7 +3203,7 @@ void tst_QNetworkReply::ioGetFromHttpsWithSslHandshakeError() qRegisterMetaType<QNetworkReply*>(); // for QSignalSpy qRegisterMetaType<QList<QSslError> >(); - QFile reference(SRCDIR "/rfc3252.txt"); + QFile reference(testDataDir + "/rfc3252.txt"); QVERIFY(reference.open(QIODevice::ReadOnly)); QNetworkRequest request(QUrl("https://" + QtNetworkSettings::serverName() + ":80")); @@ -3137,9 +3214,8 @@ void tst_QNetworkReply::ioGetFromHttpsWithSslHandshakeError() QSignalSpy sslspy(&manager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>))); connect(reply, SIGNAL(metaDataChanged()), SLOT(storeSslConfiguration())); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + + QVERIFY(waitForFinish(reply) == Failure); QCOMPARE(reply->error(), QNetworkReply::SslHandshakeFailedError); QCOMPARE(sslspy.count(), 0); @@ -3197,10 +3273,7 @@ void tst_QNetworkReply::ioGetFromHttpBrokenServer() QNetworkReplyPtr reply = manager.get(request); QSignalSpy spy(reply, SIGNAL(error(QNetworkReply::NetworkError))); - - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Failure); QCOMPARE(reply->url(), request.url()); QCOMPARE(spy.count(), 1); @@ -3230,9 +3303,7 @@ void tst_QNetworkReply::ioGetFromHttpStatus100() QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort()))); QNetworkReplyPtr reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->url(), request.url()); QCOMPARE(reply->error(), QNetworkReply::NoError); @@ -3255,9 +3326,7 @@ void tst_QNetworkReply::ioGetFromHttpNoHeaders() QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort()))); QNetworkReplyPtr reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->url(), request.url()); QCOMPARE(reply->error(), QNetworkReply::NoError); @@ -3426,9 +3495,7 @@ void tst_QNetworkReply::ioGetFromHttpWithCache() QNetworkReplyPtr reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) != Timeout); QTEST(reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute).toBool(), "loadedFromCache"); QTEST(server.totalConnections > 0, "networkUsed"); @@ -3641,7 +3708,7 @@ void tst_QNetworkReply::ioGetWithManyProxies() qRegisterMetaType<QNetworkProxy>(); // for QSignalSpy qRegisterMetaType<QAuthenticator *>(); - QFile reference(SRCDIR "/rfc3252.txt"); + QFile reference(testDataDir + "/rfc3252.txt"); QVERIFY(reference.open(QIODevice::ReadOnly)); // set the proxy factory: @@ -3659,13 +3726,12 @@ void tst_QNetworkReply::ioGetWithManyProxies() QSignalSpy authspy(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); connect(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); #ifndef QT_NO_OPENSSL connect(&manager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), SLOT(sslErrors(QNetworkReply*,QList<QSslError>))); #endif - QTestEventLoop::instance().enterLoop(15); - QVERIFY(!QTestEventLoop::instance().timeout()); + + QVERIFY(waitForFinish(reply) != Timeout); manager.disconnect(SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this, SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); @@ -3706,10 +3772,10 @@ void tst_QNetworkReply::ioPutToFileFromFile_data() { QTest::addColumn<QString>("fileName"); - QTest::newRow("empty") << SRCDIR "/empty"; - QTest::newRow("real-file") << SRCDIR "/rfc3252.txt"; + QTest::newRow("empty") << (testDataDir + "/empty"); + QTest::newRow("real-file") << (testDataDir + "/rfc3252.txt"); QTest::newRow("resource") << ":/resource"; - QTest::newRow("search-path") << "srcdir:/rfc3252.txt"; + QTest::newRow("search-path") << "testdata:/rfc3252.txt"; } void tst_QNetworkReply::ioPutToFileFromFile() @@ -3724,9 +3790,7 @@ void tst_QNetworkReply::ioPutToFileFromFile() QNetworkRequest request(url); QNetworkReplyPtr reply = manager.put(request, &sourceFile); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->url(), url); QCOMPARE(reply->error(), QNetworkReply::NoError); @@ -3762,10 +3826,8 @@ void tst_QNetworkReply::ioPutToFileFromSocket() QNetworkReplyPtr reply = manager.put(QNetworkRequest(url), socketpair.endPoints[1]); socketpair.endPoints[0]->close(); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->error(), QNetworkReply::NoError); - QVERIFY(!QTestEventLoop::instance().timeout()); QCOMPARE(reply->url(), url); QCOMPARE(reply->error(), QNetworkReply::NoError); @@ -3808,10 +3870,8 @@ void tst_QNetworkReply::ioPutToFileFromLocalSocket() QNetworkReplyPtr reply = manager.put(QNetworkRequest(url), passive); passive->setParent(reply); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->error(), QNetworkReply::NoError); - QVERIFY(!QTestEventLoop::instance().timeout()); QCOMPARE(reply->url(), url); QCOMPARE(reply->error(), QNetworkReply::NoError); @@ -3849,15 +3909,16 @@ void tst_QNetworkReply::ioPutToFileFromProcess() QFETCH(QByteArray, data); QProcess process; - process.start("echo/echo all"); + QString echoExe = echoProcessDir + "/echo"; + process.start(echoExe, QStringList("all")); + QVERIFY2(process.waitForStarted(), qPrintable( + QString::fromLatin1("Could not start %1: %2").arg(echoExe, process.errorString()))); process.write(data); process.closeWriteChannel(); QNetworkReplyPtr reply = manager.put(QNetworkRequest(url), &process); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->url(), url); QCOMPARE(reply->error(), QNetworkReply::NoError); @@ -3891,9 +3952,7 @@ void tst_QNetworkReply::ioPutToFtpFromFile() QNetworkRequest request(url); QNetworkReplyPtr reply = manager.put(request, &sourceFile); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->url(), url); QCOMPARE(reply->error(), QNetworkReply::NoError); @@ -3911,7 +3970,7 @@ void tst_QNetworkReply::ioPutToFtpFromFile() QObject::connect(r, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); QTestEventLoop::instance().enterLoop(3); - QObject::disconnect(r, SIGNAL(finished(bool)), &QTestEventLoop::instance(), SLOT(exitLoop())); + QObject::disconnect(r, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); QByteArray uploaded = r->readAll(); QCOMPARE(qint64(uploaded.size()), sourceFile.size()); @@ -3942,9 +4001,7 @@ void tst_QNetworkReply::ioPutToHttpFromFile() QNetworkRequest request(url); QNetworkReplyPtr reply = manager.put(request, &sourceFile); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->url(), url); QCOMPARE(reply->error(), QNetworkReply::NoError); @@ -3958,9 +4015,8 @@ void tst_QNetworkReply::ioPutToHttpFromFile() // download the file again from HTTP to make sure it was uploaded // correctly reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->url(), url); QCOMPARE(reply->error(), QNetworkReply::NoError); @@ -3986,9 +4042,7 @@ void tst_QNetworkReply::ioPostToHttpFromFile() QNetworkReplyPtr reply = manager.post(request, &sourceFile); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->url(), url); QCOMPARE(reply->error(), QNetworkReply::NoError); @@ -4066,7 +4120,6 @@ void tst_QNetworkReply::ioPostToHttpFromSocket() QNetworkReplyPtr reply = manager.post(request, socketpair.endPoints[1]); socketpair.endPoints[0]->close(); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); connect(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), @@ -4075,13 +4128,13 @@ void tst_QNetworkReply::ioPostToHttpFromSocket() QSignalSpy authenticationRequiredSpy(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*))); QSignalSpy proxyAuthenticationRequiredSpy(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); - QTestEventLoop::instance().enterLoop(12); + QVERIFY(waitForFinish(reply) == Success); + disconnect(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), this, SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*))); disconnect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); QCOMPARE(reply->error(), QNetworkReply::NoError); - QVERIFY(!QTestEventLoop::instance().timeout()); QCOMPARE(reply->url(), url); QCOMPARE(reply->error(), QNetworkReply::NoError); @@ -4159,7 +4212,7 @@ void tst_QNetworkReply::ioPostToHttpFromSocketSynchronous() // worked. void tst_QNetworkReply::ioPostToHttpFromMiddleOfFileToEnd() { - QFile sourceFile(SRCDIR "/rfc3252.txt"); + QFile sourceFile(testDataDir + "/rfc3252.txt"); QVERIFY(sourceFile.open(QIODevice::ReadOnly)); // seeking to the middle sourceFile.seek(sourceFile.size() / 2); @@ -4169,14 +4222,13 @@ void tst_QNetworkReply::ioPostToHttpFromMiddleOfFileToEnd() request.setRawHeader("Content-Type", "application/octet-stream"); QNetworkReplyPtr reply = manager.post(request, &sourceFile); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); - QTestEventLoop::instance().enterLoop(2); + QVERIFY(waitForFinish(reply) == Success); + disconnect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); - QVERIFY(!QTestEventLoop::instance().timeout()); // compare half data sourceFile.seek(sourceFile.size() / 2); @@ -4186,7 +4238,7 @@ void tst_QNetworkReply::ioPostToHttpFromMiddleOfFileToEnd() void tst_QNetworkReply::ioPostToHttpFromMiddleOfFileFiveBytes() { - QFile sourceFile(SRCDIR "/rfc3252.txt"); + QFile sourceFile(testDataDir + "/rfc3252.txt"); QVERIFY(sourceFile.open(QIODevice::ReadOnly)); // seeking to the middle sourceFile.seek(sourceFile.size() / 2); @@ -4199,14 +4251,13 @@ void tst_QNetworkReply::ioPostToHttpFromMiddleOfFileFiveBytes() QVERIFY(request.header(QNetworkRequest::ContentLengthHeader).isValid()); QNetworkReplyPtr reply = manager.post(request, &sourceFile); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); - QTestEventLoop::instance().enterLoop(2); + QVERIFY(waitForFinish(reply) == Success); + disconnect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); - QVERIFY(!QTestEventLoop::instance().timeout()); // compare half data sourceFile.seek(sourceFile.size() / 2); @@ -4228,14 +4279,13 @@ void tst_QNetworkReply::ioPostToHttpFromMiddleOfQBufferFiveBytes() request.setRawHeader("Content-Type", "application/octet-stream"); QNetworkReplyPtr reply = manager.post(request, &uploadBuffer); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); - QTestEventLoop::instance().enterLoop(2); + QVERIFY(waitForFinish(reply) == Success); + disconnect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); - QVERIFY(!QTestEventLoop::instance().timeout()); // compare half data uploadBuffer.seek(5); @@ -4262,11 +4312,11 @@ void tst_QNetworkReply::ioPostToHttpNoBufferFlag() QNetworkReplyPtr reply = manager.post(request, socketpair.endPoints[1]); socketpair.endPoints[0]->close(); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); - QTestEventLoop::instance().enterLoop(2); + QVERIFY(waitForFinish(reply) == Failure); + disconnect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*))); @@ -4284,12 +4334,16 @@ public: serverSocket->setParent(this); if (serverSocket->setSocketDescriptor(socketDescriptor)) { + QString testDataDir = QFileInfo(QFINDTESTDATA("rfc3252.txt")).absolutePath(); + if (testDataDir.isEmpty()) + testDataDir = QCoreApplication::applicationDirPath(); + connect(serverSocket, SIGNAL(encrypted()), this, SLOT(encryptedSlot())); connect(serverSocket, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); serverSocket->setProtocol(QSsl::AnyProtocol); connect(serverSocket, SIGNAL(sslErrors(const QList<QSslError>&)), serverSocket, SLOT(ignoreSslErrors())); - serverSocket->setLocalCertificate(SRCDIR "/certs/server.pem"); - serverSocket->setPrivateKey(SRCDIR "/certs/server.key"); + serverSocket->setLocalCertificate(testDataDir + "/certs/server.pem"); + serverSocket->setPrivateKey(testDataDir + "/certs/server.key"); serverSocket->startServerEncryption(); } else { delete serverSocket; @@ -4314,7 +4368,7 @@ public: // very similar to ioPostToHttpUploadProgress but for SSL void tst_QNetworkReply::ioPostToHttpsUploadProgress() { - //QFile sourceFile(SRCDIR "/bigfile"); + //QFile sourceFile(testDataDir + "/bigfile"); //QVERIFY(sourceFile.open(QIODevice::ReadOnly)); qint64 wantedSize = 2*1024*1024; // 2 MB QByteArray sourceFile; @@ -4366,13 +4420,11 @@ void tst_QNetworkReply::ioPostToHttpsUploadProgress() QCOMPARE(args3.at(0).toLongLong(), qint64(sourceFile.size())); // after sending this, the QNAM should emit finished() - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); incomingSocket->write("HTTP/1.0 200 OK\r\n"); incomingSocket->write("Content-Length: 0\r\n"); incomingSocket->write("\r\n"); - QTestEventLoop::instance().enterLoop(10); - // not timeouted -> finished() was emitted - QVERIFY(!QTestEventLoop::instance().timeout()); + + QVERIFY(waitForFinish(reply) == Success); incomingSocket->close(); server.close(); @@ -4429,10 +4481,11 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp() const int rate = 200; // in kB per sec RateControlledReader reader(server, reply, rate, bufferSize); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); QTime loopTime; loopTime.start(); - QTestEventLoop::instance().enterLoop(30); + + QVERIFY(waitForFinish(reply) == Success); + const int elapsedTime = loopTime.elapsed(); server.wait(); reader.wrapUp(); @@ -4441,8 +4494,6 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp() qDebug() << "receive rate:" << reader.totalBytesRead * 1000 / elapsedTime << "(it received" << reader.totalBytesRead << "bytes in" << elapsedTime << "ms)"; - QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(reply->url(), request.url()); QCOMPARE(reply->error(), QNetworkReply::NoError); QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200); @@ -4472,7 +4523,7 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp() void tst_QNetworkReply::ioPostToHttpUploadProgress() { - QFile sourceFile(SRCDIR "/bigfile"); + QFile sourceFile(testDataDir + "/bigfile"); QVERIFY(sourceFile.open(QIODevice::ReadOnly)); // emulate a minimal http server @@ -4577,16 +4628,15 @@ void tst_QNetworkReply::ioPostToHttpEmptyUploadProgress() void tst_QNetworkReply::lastModifiedHeaderForFile() { - QFileInfo fileInfo(SRCDIR "/bigfile"); + QFileInfo fileInfo(testDataDir + "/bigfile"); QVERIFY(fileInfo.exists()); QUrl url = QUrl::fromLocalFile(fileInfo.filePath()); QNetworkRequest request(url); QNetworkReplyPtr reply = manager.head(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + + QVERIFY(waitForFinish(reply) == Success); QDateTime header = reply->header(QNetworkRequest::LastModifiedHeader).toDateTime(); QCOMPARE(header, fileInfo.lastModified()); @@ -4599,9 +4649,8 @@ void tst_QNetworkReply::lastModifiedHeaderForHttp() QNetworkRequest request(url); QNetworkReplyPtr reply = manager.head(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + + QVERIFY(waitForFinish(reply) == Success); QDateTime header = reply->header(QNetworkRequest::LastModifiedHeader).toDateTime(); QDateTime realDate = QDateTime::fromString("2007-05-22T12:04:57", Qt::ISODate); @@ -4615,9 +4664,8 @@ void tst_QNetworkReply::httpCanReadLine() QNetworkRequest request(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt")); QNetworkReplyPtr reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); + QCOMPARE(reply->error(), QNetworkReply::NoError); QVERIFY(reply->canReadLine()); @@ -4645,13 +4693,16 @@ void tst_QNetworkReply::rateControl() // faster than the data is being consumed. QFETCH(int, rate); +#if !defined(QT_BUILD_INTERNAL) + QSKIP("backend for testing not available!"); +#endif + // ask for 20 seconds worth of data FastSender sender(20 * rate * 1024); QNetworkRequest request("debugpipe://localhost:" + QString::number(sender.serverPort())); QNetworkReplyPtr reply = manager.get(request); reply->setReadBufferSize(32768); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError"); QSignalSpy errorSpy(reply, SIGNAL(error(QNetworkReply::NetworkError))); @@ -4660,7 +4711,9 @@ void tst_QNetworkReply::rateControl() // this test is designed to run for 25 seconds at most QTime loopTime; loopTime.start(); - QTestEventLoop::instance().enterLoop(40); + + QVERIFY(waitForFinish(reply) == Success); + int elapsedTime = loopTime.elapsed(); if (!errorSpy.isEmpty()) { @@ -4672,7 +4725,6 @@ void tst_QNetworkReply::rateControl() << "(it received" << reader.totalBytesRead << "bytes in" << elapsedTime << "ms)"; sender.wait(); - QVERIFY(!QTestEventLoop::instance().timeout()); QCOMPARE(reply->url(), request.url()); QCOMPARE(reply->error(), QNetworkReply::NoError); @@ -4695,6 +4747,9 @@ void tst_QNetworkReply::downloadProgress_data() void tst_QNetworkReply::downloadProgress() { +#if !defined(QT_BUILD_INTERNAL) + QSKIP("backend for testing not available!"); +#endif QTcpServer server; QVERIFY(server.listen()); @@ -4758,6 +4813,9 @@ void tst_QNetworkReply::uploadProgress_data() void tst_QNetworkReply::uploadProgress() { QFETCH(QByteArray, data); +#if !defined(QT_BUILD_INTERNAL) + QSKIP("backend for testing not available!"); +#endif QTcpServer server; QVERIFY(server.listen()); @@ -4776,9 +4834,7 @@ void tst_QNetworkReply::uploadProgress() QTcpSocket *receiver = server.nextPendingConnection(); if (finished.count() == 0) { // it's not finished yet, so wait for it to be - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(2); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); } delete receiver; @@ -4814,9 +4870,7 @@ void tst_QNetworkReply::chaining() request.setUrl(url); QNetworkReplyPtr putReply = manager.put(request, getReply); - connect(putReply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(putReply) == Success); QCOMPARE(getReply->url(), QUrl::fromLocalFile(sourceFile.fileName())); QCOMPARE(getReply->error(), QNetworkReply::NoError); @@ -5097,11 +5151,7 @@ void tst_QNetworkReply::httpProxyCommands() //manager.setProxy(QNetworkProxy()); // wait for the finished signal - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - - QTestEventLoop::instance().enterLoop(15); - - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) != Timeout); //qDebug() << reply->error() << reply->errorString(); //qDebug() << proxyServer.receivedData; @@ -5234,9 +5284,8 @@ void tst_QNetworkReply::proxyChange() manager.setProxy(dummyProxy); QNetworkReplyPtr reply3 = manager.get(req); - connect(reply3, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(5); - QVERIFY(!QTestEventLoop::instance().timeout()); + + QVERIFY(waitForFinish(reply3) == Failure); QVERIFY(int(reply3->error()) > 0); } @@ -5272,10 +5321,7 @@ void tst_QNetworkReply::authorizationError() QSignalSpy errorSpy(reply, SIGNAL(error(QNetworkReply::NetworkError))); QSignalSpy finishedSpy(reply, SIGNAL(finished())); // now run the request: - connect(reply, SIGNAL(finished()), - &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Failure); QFETCH(int, errorSignalCount); QCOMPARE(errorSpy.count(), errorSignalCount); @@ -5501,8 +5547,7 @@ void tst_QNetworkReply::ignoreSslErrorsList_data() QTest::addColumn<QNetworkReply::NetworkError>("expectedNetworkError"); QList<QSslError> expectedSslErrors; - // apparently, because of some weird behaviour of SRCDIR, the file name below needs to start with a slash - QList<QSslCertificate> certs = QSslCertificate::fromPath(QLatin1String(SRCDIR "/certs/qt-test-server-cacert.pem")); + QList<QSslCertificate> certs = QSslCertificate::fromPath(testDataDir + "/certs/qt-test-server-cacert.pem"); QSslError rightError(QSslError::SelfSignedCertificate, certs.at(0)); QSslError wrongError(QSslError::SelfSignedCertificate); @@ -5526,9 +5571,7 @@ void tst_QNetworkReply::ignoreSslErrorsList() QFETCH(QList<QSslError>, expectedSslErrors); reply->ignoreSslErrors(expectedSslErrors); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) != Timeout); QFETCH(QNetworkReply::NetworkError, expectedNetworkError); QCOMPARE(reply->error(), expectedNetworkError); @@ -5559,9 +5602,7 @@ void tst_QNetworkReply::ignoreSslErrorsListWithSlot() this, SLOT(ignoreSslErrorListSlot(QNetworkReply *, const QList<QSslError> &))); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) != Timeout); QFETCH(QNetworkReply::NetworkError, expectedNetworkError); QCOMPARE(reply->error(), expectedNetworkError); @@ -5575,7 +5616,7 @@ void tst_QNetworkReply::sslConfiguration_data() QTest::newRow("empty") << QSslConfiguration() << false; QSslConfiguration conf = QSslConfiguration::defaultConfiguration(); QTest::newRow("default") << conf << false; // does not contain test server cert - QList<QSslCertificate> testServerCert = QSslCertificate::fromPath(SRCDIR "/certs/qt-test-server-cacert.pem"); + QList<QSslCertificate> testServerCert = QSslCertificate::fromPath(testDataDir + "/certs/qt-test-server-cacert.pem"); conf.setCaCertificates(testServerCert); QTest::newRow("set-root-cert") << conf << true; conf.setProtocol(QSsl::SecureProtocols); @@ -5589,9 +5630,7 @@ void tst_QNetworkReply::sslConfiguration() request.setSslConfiguration(configuration); QNetworkReplyPtr reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) != Timeout); QFETCH(bool, works); QNetworkReply::NetworkError expectedError = works ? QNetworkReply::NoError : QNetworkReply::SslHandshakeFailedError; @@ -5675,12 +5714,11 @@ void tst_QNetworkReply::getFromHttpIntoBuffer() QNetworkAccessManager manager; QNetworkReply *reply = manager.get(request); connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); QVERIFY(!QTestEventLoop::instance().timeout()); QVERIFY(reply->isFinished()); - QFile reference(SRCDIR "/rfc3252.txt"); + QFile reference(testDataDir + "/rfc3252.txt"); QVERIFY(reference.open(QIODevice::ReadOnly)); QCOMPARE(reference.bytesAvailable(), reply->bytesAvailable()); @@ -5850,7 +5888,7 @@ void tst_QNetworkReply::getFromHttpIntoBuffer2() QFETCH(bool, useDownloadBuffer); // On my Linux Desktop the results are already visible with 128 kB, however we use this to have good results. -#if defined(Q_WS_WINCE_WM) +#if defined(Q_OS_WINCE_WM) // Show some mercy to non-desktop platform/s enum {UploadSize = 4*1024*1024}; // 4 MB #else @@ -5886,9 +5924,7 @@ void tst_QNetworkReply::getFromHttpIntoBufferCanReadLine() request.setAttribute(QNetworkRequest::MaximumDownloadBufferSizeAttribute, 1024*1024*128); // 128 MB is max allowed QNetworkReplyPtr reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->error(), QNetworkReply::NoError); QVERIFY(reply->canReadLine()); @@ -5912,9 +5948,7 @@ void tst_QNetworkReply::ioGetFromHttpWithoutContentLength() QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort()))); QNetworkReplyPtr reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->url(), request.url()); QVERIFY(reply->isFinished()); @@ -5962,9 +5996,7 @@ void tst_QNetworkReply::qtbug12908compressedHttpReply() QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort()))); QNetworkReplyPtr reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); QCOMPARE(reply->error(), QNetworkReply::NoError); QCOMPARE(reply->size(), qint64(16384)); @@ -5987,9 +6019,7 @@ void tst_QNetworkReply::compressedHttpReplyBrokenGzip() QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort()))); QNetworkReplyPtr reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Failure); QCOMPARE(reply->error(), QNetworkReply::ProtocolFailure); } @@ -6002,9 +6032,7 @@ void tst_QNetworkReply::getFromUnreachableIp() QNetworkRequest request(QUrl("http://255.255.255.255/42/23/narf/narf/narf")); QNetworkReplyPtr reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Failure); QVERIFY(reply->error() != QNetworkReply::NoError); } @@ -6337,9 +6365,8 @@ void tst_QNetworkReply::qtbug15311doubleContentLength() QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort()))); QNetworkReplyPtr reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); + QVERIFY(reply->isFinished()); QCOMPARE(reply->error(), QNetworkReply::NoError); QCOMPARE(reply->size(), qint64(3)); @@ -6357,9 +6384,8 @@ void tst_QNetworkReply::qtbug18232gzipContentLengthZero() QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort()))); QNetworkReplyPtr reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); + QVERIFY(reply->isFinished()); QCOMPARE(reply->error(), QNetworkReply::NoError); QCOMPARE(reply->size(), qint64(0)); @@ -6379,9 +6405,8 @@ void tst_QNetworkReply::qtbug22660gzipNoContentLengthEmptyContent() QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort()))); QNetworkReplyPtr reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); + QVERIFY(reply->isFinished()); QCOMPARE(reply->error(), QNetworkReply::NoError); QCOMPARE(reply->size(), qint64(0)); @@ -6400,13 +6425,13 @@ void tst_QNetworkReply::synchronousRequest_data() QTest::newRow("http") << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt") - << QString("file:" SRCDIR "/rfc3252.txt") + << QString("file:" + testDataDir + "/rfc3252.txt") << true << QString("text/plain"); QTest::newRow("http-gzip") << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/deflate/rfc3252.txt") - << QString("file:" SRCDIR "/rfc3252.txt") + << QString("file:" + testDataDir + "/rfc3252.txt") << false // don't check content length, because it's gzip encoded // ### we would need to enflate (un-deflate) the file content and compare the sizes << QString("text/plain"); @@ -6414,7 +6439,7 @@ void tst_QNetworkReply::synchronousRequest_data() #ifndef QT_NO_OPENSSL QTest::newRow("https") << QUrl("https://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt") - << QString("file:" SRCDIR "/rfc3252.txt") + << QString("file:" + testDataDir + "/rfc3252.txt") << true << QString("text/plain"); #endif @@ -6426,8 +6451,8 @@ void tst_QNetworkReply::synchronousRequest_data() << QString("text/plain"); QTest::newRow("simple-file") - << QUrl::fromLocalFile(SRCDIR "/rfc3252.txt") - << QString("file:" SRCDIR "/rfc3252.txt") + << QUrl::fromLocalFile(testDataDir + "/rfc3252.txt") + << QString("file:" + testDataDir + "/rfc3252.txt") << true << QString(); } @@ -6449,7 +6474,7 @@ void tst_QNetworkReply::synchronousRequest() // QNetworkRequest, see http://bugreports.qt.nokia.com/browse/QTBUG-14774 if (url.scheme() == "https") { QSslConfiguration sslConf; - QList<QSslCertificate> certs = QSslCertificate::fromPath(SRCDIR "/certs/qt-test-server-cacert.pem"); + QList<QSslCertificate> certs = QSslCertificate::fromPath(testDataDir + "/certs/qt-test-server-cacert.pem"); sslConf.setCaCertificates(certs); request.setSslConfiguration(sslConf); } @@ -6559,8 +6584,9 @@ void tst_QNetworkReply::httpAbort() // Abort after the finished() QNetworkRequest request3("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt"); QNetworkReplyPtr reply3 = manager.get(request3); - connect(reply3, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); + + QVERIFY(waitForFinish(reply3) == Success); + QVERIFY(reply3->isFinished()); reply3->abort(); QCOMPARE(reply3->error(), QNetworkReply::NoError); @@ -6590,9 +6616,7 @@ void tst_QNetworkReply::dontInsertPartialContentIntoTheCache() QNetworkReplyPtr reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); QVERIFY(server.totalConnections > 0); QCOMPARE(reply->readAll().constData(), "load"); @@ -6609,9 +6633,8 @@ void tst_QNetworkReply::httpUserAgent() request.setHeader(QNetworkRequest::UserAgentHeader, "abcDEFghi"); QNetworkReplyPtr reply = manager.get(request); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(waitForFinish(reply) == Success); + QVERIFY(reply->isFinished()); QCOMPARE(reply->error(), QNetworkReply::NoError); QVERIFY(server.receivedData.contains("\r\nUser-Agent: abcDEFghi\r\n")); @@ -6728,6 +6751,27 @@ void tst_QNetworkReply::pipeliningHelperSlot() { } } +void tst_QNetworkReply::closeDuringDownload_data() +{ + QTest::addColumn<QUrl>("url"); + QTest::newRow("http") << QUrl("http://" + QtNetworkSettings::serverName() + "/bigfile"); + QTest::newRow("ftp") << QUrl("ftp://" + QtNetworkSettings::serverName() + "/qtest/bigfile"); +} + +void tst_QNetworkReply::closeDuringDownload() +{ + QFETCH(QUrl, url); + QNetworkRequest request(url); + QNetworkReply* reply = manager.get(request); + connect(reply, SIGNAL(readyRead()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + reply->close(); + reply->deleteLater(); + QTest::qWait(1000); //cancelling ftp takes some time, this avoids a warning caused by test's cleanup() destroying the connection cache before the abort is finished +} + // NOTE: This test must be last testcase in tst_qnetworkreply! void tst_QNetworkReply::parentingRepliesToTheApp() { diff --git a/tests/auto/network/bearer/qnetworksession/qnetworksession.pro b/tests/auto/network/bearer/qnetworksession/qnetworksession.pro index a85925bc17..f1cb47d14e 100644 --- a/tests/auto/network/bearer/qnetworksession/qnetworksession.pro +++ b/tests/auto/network/bearer/qnetworksession/qnetworksession.pro @@ -1,2 +1,4 @@ TEMPLATE = subdirs -SUBDIRS = lackey test +SUBDIRS = lackey +test.depends = $$SUBDIRS +SUBDIRS += test diff --git a/tests/auto/network/bearer/qnetworksession/test/test.pro b/tests/auto/network/bearer/qnetworksession/test/test.pro index 5567e35b02..2f1a9ba6ea 100644 --- a/tests/auto/network/bearer/qnetworksession/test/test.pro +++ b/tests/auto/network/bearer/qnetworksession/test/test.pro @@ -14,3 +14,6 @@ CONFIG(debug_and_release) { } else { DESTDIR = .. } + +load(testcase) # for target.path and installTestHelperApp() +installTestHelperApp("../lackey/lackey",lackey,lackey) diff --git a/tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp b/tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp index a51b4e5632..27e1e7f013 100644 --- a/tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp +++ b/tests/auto/network/bearer/qnetworksession/test/tst_qnetworksession.cpp @@ -96,6 +96,7 @@ private slots: private: QNetworkConfigurationManager manager; int inProcessSessionManagementCount; + QString lackeyDir; #endif }; @@ -117,6 +118,10 @@ void tst_QNetworkSession::initTestCase() QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); QTRY_VERIFY_WITH_TIMEOUT(spy.count() == 1, TestTimeOut); + + lackeyDir = QFINDTESTDATA("lackey"); + QVERIFY2(!lackeyDir.isEmpty(), qPrintable( + QString::fromLatin1("Couldn't find lackey dir starting from %1.").arg(QDir::currentPath()))); } void tst_QNetworkSession::cleanupTestCase() @@ -916,10 +921,10 @@ void tst_QNetworkSession::outOfProcessSession() oopServer.listen("tst_qnetworksession"); QProcess lackey; - lackey.start("lackey/lackey"); - qDebug() << lackey.error() << lackey.errorString(); - QVERIFY(lackey.waitForStarted()); - + QString lackeyExe = lackeyDir + "/lackey"; + lackey.start(lackeyExe); + QVERIFY2(lackey.waitForStarted(), qPrintable( + QString::fromLatin1("Could not start %1: %2").arg(lackeyExe, lackey.errorString()))); QVERIFY(oopServer.waitForNewConnection(-1)); QLocalSocket *oopSocket = oopServer.nextPendingConnection(); diff --git a/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp b/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp index 9b8391d6be..43b1f225c4 100644 --- a/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp +++ b/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp @@ -294,7 +294,7 @@ void tst_QHttpSocketEngine::errorTest() connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(5); + QTestEventLoop::instance().enterLoop(30); QVERIFY(!QTestEventLoop::instance().timeout()); QCOMPARE(int(socket.error()), expectedError); @@ -371,7 +371,7 @@ void tst_QHttpSocketEngine::simpleErrorsAndStates() QVERIFY(socketDevice.state() == QAbstractSocket::UnconnectedState); QVERIFY(!socketDevice.connectToHost(QHostAddress(QtNetworkSettings::serverName()), 8088)); QVERIFY(socketDevice.state() == QAbstractSocket::ConnectingState); - if (socketDevice.waitForWrite(15000)) { + if (socketDevice.waitForWrite(30000)) { QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState || socketDevice.state() == QAbstractSocket::UnconnectedState); } else { @@ -425,7 +425,7 @@ void tst_QHttpSocketEngine::tcpLoopbackPerformance() QTime timer; timer.start(); qlonglong readBytes = 0; - while (timer.elapsed() < 5000) { + while (timer.elapsed() < 30000) { qlonglong written = serverSocket.write(message1.data(), message1.size()); while (written > 0) { client.waitForRead(); @@ -458,7 +458,7 @@ void tst_QHttpSocketEngine::tcpSocketBlockingTest() QCOMPARE(socket.state(), QTcpSocket::ConnectedState); // Read greeting - QVERIFY(socket.waitForReadyRead(5000)); + QVERIFY(socket.waitForReadyRead(30000)); QString s = socket.readLine(); QVERIFY2(QtNetworkSettings::compareReplyIMAP(s.toLatin1()), qPrintable(s)); @@ -466,7 +466,7 @@ void tst_QHttpSocketEngine::tcpSocketBlockingTest() QCOMPARE((int) socket.write("1 NOOP\r\n", 8), 8); if (!socket.canReadLine()) - QVERIFY(socket.waitForReadyRead(5000)); + QVERIFY(socket.waitForReadyRead(30000)); // Read response s = socket.readLine(); @@ -476,14 +476,14 @@ void tst_QHttpSocketEngine::tcpSocketBlockingTest() QCOMPARE((int) socket.write("2 LOGOUT\r\n", 10), 10); if (!socket.canReadLine()) - QVERIFY(socket.waitForReadyRead(5000)); + QVERIFY(socket.waitForReadyRead(30000)); // Read two lines of respose s = socket.readLine(); QCOMPARE(s.toLatin1().constData(), "* BYE LOGOUT received\r\n"); if (!socket.canReadLine()) - QVERIFY(socket.waitForReadyRead(5000)); + QVERIFY(socket.waitForReadyRead(30000)); s = socket.readLine(); QCOMPARE(s.toLatin1().constData(), "2 OK Completed\r\n"); diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp index 221ef602a1..72fa9f74a4 100644 --- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -46,17 +46,21 @@ #include <QtNetwork/qlocalsocket.h> #include <QtNetwork/qlocalserver.h> +#ifdef Q_OS_UNIX +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#endif + Q_DECLARE_METATYPE(QLocalSocket::LocalSocketError) Q_DECLARE_METATYPE(QLocalSocket::LocalSocketState) +Q_DECLARE_METATYPE(QLocalServer::SocketOption) +Q_DECLARE_METATYPE(QFile::Permissions) class tst_QLocalSocket : public QObject { Q_OBJECT -public: - tst_QLocalSocket(); - virtual ~tst_QLocalSocket(); - public Q_SLOTS: void init(); void cleanup(); @@ -108,26 +112,21 @@ private slots: void bytesWrittenSignal(); void syncDisconnectNotify(); void asyncDisconnectNotify(); -}; -tst_QLocalSocket::tst_QLocalSocket() -{ - if (!QFile::exists("lackey/lackey" -#ifdef Q_OS_WIN - ".exe" -#endif - )) - qWarning() << "lackey executable doesn't exists!"; -} + void verifySocketOptions(); + void verifySocketOptions_data(); -tst_QLocalSocket::~tst_QLocalSocket() -{ -} + void verifyListenWithDescriptor(); + void verifyListenWithDescriptor_data(); + +}; void tst_QLocalSocket::init() { qRegisterMetaType<QLocalSocket::LocalSocketState>("QLocalSocket::LocalSocketState"); qRegisterMetaType<QLocalSocket::LocalSocketError>("QLocalSocket::LocalSocketError"); + qRegisterMetaType<QLocalServer::SocketOption>("QLocalServer::SocketOption"); + qRegisterMetaType<QFile::Permissions>("QFile::Permissions"); } void tst_QLocalSocket::cleanup() @@ -749,6 +748,16 @@ void tst_QLocalSocket::processConnection_data() */ void tst_QLocalSocket::processConnection() { +#ifdef Q_OS_WIN +# define EXE_SUFFIX ".exe" +#else +# define EXE_SUFFIX +#endif + +// ### lackey is currently not build + QEXPECT_FAIL("", "lackey is currently not built due to qscript dependency, QTBUG-24142", Abort); + QVERIFY(QFile::exists("lackey/lackey" EXE_SUFFIX)); + QFETCH(int, processes); QStringList serverArguments = QStringList() << SRCDIR "lackey/scripts/server.js" << QString::number(processes); QProcess producer; @@ -758,7 +767,7 @@ void tst_QLocalSocket::processConnection() #endif QList<QProcess*> consumers; producer.start("lackey/lackey", serverArguments); - QVERIFY(producer.waitForStarted(-1)); + QVERIFY2(producer.waitForStarted(-1), qPrintable(producer.errorString())); QTest::qWait(2000); for (int i = 0; i < processes; ++i) { QStringList arguments = QStringList() << SRCDIR "lackey/scripts/client.js"; @@ -1018,6 +1027,140 @@ void tst_QLocalSocket::asyncDisconnectNotify() QTRY_VERIFY(!disconnectedSpy.isEmpty()); } +void tst_QLocalSocket::verifySocketOptions_data() +{ +#ifdef Q_OS_LINUX + QTest::addColumn<QString>("service"); + QTest::addColumn<QLocalServer::SocketOption>("opts"); + QTest::addColumn<QFile::Permissions>("perms"); + + QFile::Permissions p = QFile::ExeOwner|QFile::WriteOwner|QFile::ReadOwner | + QFile::ExeUser|QFile::WriteUser|QFile::ReadUser; + QTest::newRow("user") << "userPerms" << QLocalServer::UserAccessOption << p; + + p = QFile::ExeGroup|QFile::WriteGroup|QFile::ReadGroup; + QTest::newRow("group") << "groupPerms" << QLocalServer::GroupAccessOption << p; + + p = QFile::ExeOther|QFile::WriteOther|QFile::ReadOther; + QTest::newRow("other") << "otherPerms" << QLocalServer::OtherAccessOption << p; + + p = QFile::ExeOwner|QFile::WriteOwner|QFile::ReadOwner| + QFile::ExeUser|QFile::WriteUser|QFile::ReadUser | + QFile::ExeGroup|QFile::WriteGroup|QFile::ReadGroup| + QFile::ExeOther|QFile::WriteOther|QFile::ReadOther; + QTest::newRow("all") << "worldPerms" << QLocalServer::WorldAccessOption << p; +#endif +} + +void tst_QLocalSocket::verifySocketOptions() +{ + // These are only guaranteed to be useful on linux at this time +#ifdef Q_OS_LINUX + QFETCH(QString, service); + QFETCH(QLocalServer::SocketOption, opts); + QFETCH(QFile::Permissions, perms); + + + QLocalServer::removeServer(service); + QLocalServer server; + server.setSocketOptions(opts); + QVERIFY2(server.listen(service), "service failed to start listening"); + + // find the socket + QString fullServerPath = QDir::cleanPath(QDir::tempPath()); + fullServerPath += QLatin1Char('/') + service; + + QFile socketFile(fullServerPath); + QVERIFY2(perms == socketFile.permissions(), "permissions on the socket don't match"); +#endif +} + +void tst_QLocalSocket::verifyListenWithDescriptor() +{ +#ifdef Q_OS_UNIX + QFETCH(QString, path); + QFETCH(bool, abstract); + QFETCH(bool, bound); + + qDebug() << "socket" << path << abstract; + + int listenSocket; + + if (bound) { + // create the unix socket + listenSocket = ::socket(PF_UNIX, SOCK_STREAM, 0); + QVERIFY2(listenSocket != -1, "failed to create test socket"); + + // Construct the unix address + struct ::sockaddr_un addr; + addr.sun_family = PF_UNIX; + + QVERIFY2(sizeof(addr.sun_path) > ((uint)path.size() + 1), "path to large to create socket"); + + ::memset(addr.sun_path, 0, sizeof(addr.sun_path)); + if (abstract) + ::memcpy(addr.sun_path+1, path.toLatin1().data(), path.toLatin1().size()); + else + ::memcpy(addr.sun_path, path.toLatin1().data(), path.toLatin1().size()); + + if (path.startsWith(QLatin1Char('/'))) { + ::unlink(path.toLatin1()); + } + + QVERIFY2(-1 != ::bind(listenSocket, (sockaddr *)&addr, sizeof(sockaddr_un)), "failed to bind test socket to address"); + + // listen for connections + QVERIFY2(-1 != ::listen(listenSocket, 50), "failed to call listen on test socket"); + } else { + int fds[2]; + QVERIFY2(-1 != ::socketpair(PF_UNIX, SOCK_STREAM, 0, fds), "failed to create socket pair"); + + listenSocket = fds[0]; + close(fds[1]); + } + + QLocalServer server; + QVERIFY2(server.listen(listenSocket), "failed to start create QLocalServer with local socket"); + +#ifdef Q_OS_LINUX + if (!bound) { + QVERIFY(server.serverName().at(0) == QLatin1Char('@')); + QVERIFY(server.fullServerName().at(0) == QLatin1Char('@')); + } else if (abstract) { + QVERIFY2(server.fullServerName().at(0) == QLatin1Char('@'), "abstract sockets should start with a '@'"); + } else { + QVERIFY2(server.fullServerName() == path, "full server path doesn't match patch provided"); + if (path.contains(QLatin1String("/"))) { + QVERIFY2(server.serverName() == path.mid(path.lastIndexOf(QLatin1Char('/'))+1), "server name invalid short name"); + } else { + QVERIFY2(server.serverName() == path, "servier name doesn't match the path provided"); + } + } +#else + QVERIFY(server.serverName().isEmpty()); + QVERIFY(server.fullServerName().isEmpty()); +#endif + + +#endif +} + +void tst_QLocalSocket::verifyListenWithDescriptor_data() +{ +#ifdef Q_OS_UNIX + QTest::addColumn<QString>("path"); + QTest::addColumn<bool>("abstract"); + QTest::addColumn<bool>("bound"); + + QTest::newRow("normal") << QDir::tempPath() + QLatin1Literal("/testsocket") << false << true; + QTest::newRow("absrtact") << QString::fromLatin1("abstractsocketname") << true << true; + QTest::newRow("abstractwithslash") << QString::fromLatin1("abstractsocketwitha/inthename") << true << true; + QTest::newRow("no path") << QString::fromLatin1("/invalid/no path name speficied") << true << false; + +#endif + +} + QTEST_MAIN(tst_QLocalSocket) #include "tst_qlocalsocket.moc" diff --git a/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp b/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp index 941e0b2142..ac27a621bb 100644 --- a/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp +++ b/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp @@ -119,6 +119,7 @@ private: #ifndef QT_NO_BEARERMANAGEMENT QNetworkSession *networkSession; #endif + QString crashingServerDir; }; // Testing get/set functions @@ -150,6 +151,10 @@ void tst_QTcpServer::initTestCase_data() QTest::newRow("WithoutProxy") << false << 0; QTest::newRow("WithSocks5Proxy") << true << int(QNetworkProxy::Socks5Proxy); + + crashingServerDir = QFINDTESTDATA("crashingServer"); + QVERIFY2(!crashingServerDir.isEmpty(), qPrintable( + QString::fromLatin1("Couldn't find crashingServer dir starting from %1.").arg(QDir::currentPath()))); } void tst_QTcpServer::initTestCase() @@ -538,7 +543,10 @@ void tst_QTcpServer::addressReusable() QFile::remove(signalName); // The crashingServer process will crash once it gets a connection. QProcess process; - process.start("crashingServer/crashingServer"); + QString processExe = crashingServerDir + "/crashingServer"; + process.start(processExe); + QVERIFY2(process.waitForStarted(), qPrintable( + QString::fromLatin1("Could not start %1: %2").arg(processExe, process.errorString()))); int waitCount = 5; while (waitCount-- && !QFile::exists(signalName)) QTest::qWait(1000); @@ -547,7 +555,10 @@ void tst_QTcpServer::addressReusable() #else // The crashingServer process will crash once it gets a connection. QProcess process; - process.start("crashingServer/crashingServer"); + QString processExe = crashingServerDir + "/crashingServer"; + process.start(processExe); + QVERIFY2(process.waitForStarted(), qPrintable( + QString::fromLatin1("Could not start %1: %2").arg(processExe, process.errorString()))); QVERIFY(process.waitForReadyRead(5000)); #endif diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp index 829ddd2054..abeb1ed06d 100644 --- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp +++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp @@ -246,6 +246,7 @@ private: SocketPair *earlyConstructedSockets; int earlyBytesWrittenCount; int earlyReadyReadCount; + QString stressTestDir; }; enum ProxyTests { @@ -340,6 +341,10 @@ void tst_QTcpSocket::initTestCase_data() QTest::newRow("WithHttpProxyBasicAuth SSL") << true << int(HttpProxy | AuthBasic) << true; // QTest::newRow("WithHttpProxyNtlmAuth SSL") << true << int(HttpProxy | AuthNtlm) << true; #endif + + stressTestDir = QFINDTESTDATA("stressTest"); + QVERIFY2(!stressTestDir.isEmpty(), qPrintable( + QString::fromLatin1("Couldn't find stressTest dir starting from %1.").arg(QDir::currentPath()))); } void tst_QTcpSocket::initTestCase() @@ -2225,11 +2230,14 @@ void tst_QTcpSocket::suddenRemoteDisconnect() if (ssl) return; + QString processExe = stressTestDir + "/stressTest"; + // Start server QProcess serverProcess; serverProcess.setReadChannel(QProcess::StandardError); - serverProcess.start(QString::fromLatin1("stressTest/stressTest %1").arg(server), - QIODevice::ReadWrite | QIODevice::Text); + serverProcess.start(processExe, QStringList(server), QIODevice::ReadWrite | QIODevice::Text); + QVERIFY2(serverProcess.waitForStarted(), qPrintable( + QString::fromLatin1("Could not start %1: %2").arg(processExe, serverProcess.errorString()))); while (!serverProcess.canReadLine()) QVERIFY(serverProcess.waitForReadyRead(10000)); QCOMPARE(serverProcess.readLine().data(), (server.toLatin1() + "\n").data()); @@ -2237,8 +2245,9 @@ void tst_QTcpSocket::suddenRemoteDisconnect() // Start client QProcess clientProcess; clientProcess.setReadChannel(QProcess::StandardError); - clientProcess.start(QString::fromLatin1("stressTest/stressTest %1").arg(client), - QIODevice::ReadWrite | QIODevice::Text); + clientProcess.start(processExe, QStringList(client), QIODevice::ReadWrite | QIODevice::Text); + QVERIFY2(clientProcess.waitForStarted(), qPrintable( + QString::fromLatin1("Could not start %1: %2").arg(processExe, clientProcess.errorString()))); while (!clientProcess.canReadLine()) QVERIFY(clientProcess.waitForReadyRead(10000)); QCOMPARE(clientProcess.readLine().data(), (client.toLatin1() + "\n").data()); diff --git a/tests/auto/network/ssl/qsslcertificate/qsslcertificate.pro b/tests/auto/network/ssl/qsslcertificate/qsslcertificate.pro index 7e2abac3f8..60ad3cbfd1 100644 --- a/tests/auto/network/ssl/qsslcertificate/qsslcertificate.pro +++ b/tests/auto/network/ssl/qsslcertificate/qsslcertificate.pro @@ -6,19 +6,4 @@ QT = core network testlib TARGET = tst_qsslcertificate -win32 { - CONFIG(debug, debug|release) { - DESTDIR = debug -} else { - DESTDIR = release - } -} - -wince* { - certFiles.files = certificates more-certificates - certFiles.path = . - DEPLOYMENT += certFiles - DEFINES += SRCDIR=\\\".\\\" -} else { - DEFINES += SRCDIR=\\\"$$PWD/\\\" -} +TESTDATA += certificates/* more-certificates/* verify-certs/* diff --git a/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp b/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp index 8003ad1932..da2dd989c7 100644 --- a/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp +++ b/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp @@ -71,14 +71,10 @@ class tst_QSslCertificate : public QObject #endif QString oldCurrentDir; -public: - tst_QSslCertificate(); - virtual ~tst_QSslCertificate(); public slots: - void initTestCase_data(); - void init(); - void cleanup(); + void initTestCase(); + void cleanupTestCase(); #ifndef QT_NO_OPENSSL private slots: @@ -120,11 +116,23 @@ private slots: // ### add tests for certificate bundles (multiple certificates concatenated into a single // structure); both PEM and DER formatted #endif +private: + QString testDataDir; }; -tst_QSslCertificate::tst_QSslCertificate() +void tst_QSslCertificate::initTestCase() { - QDir dir(SRCDIR + QLatin1String("/certificates")); + testDataDir = QFileInfo(QFINDTESTDATA("certificates")).absolutePath(); + if (testDataDir.isEmpty()) + testDataDir = QCoreApplication::applicationDirPath(); + + if (QDir::current().absolutePath() != testDataDir) { + oldCurrentDir = QDir::current().absolutePath(); + QVERIFY2(QDir::setCurrent(testDataDir), + qPrintable(QString("Cannot change directory to %1").arg(testDataDir))); + } + + QDir dir(testDataDir + "/certificates"); QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::Readable); QRegExp rxCert(QLatin1String("^.+\\.(pem|der)$")); QRegExp rxSan(QLatin1String("^(.+\\.(?:pem|der))\\.san$")); @@ -148,29 +156,11 @@ tst_QSslCertificate::tst_QSslCertificate() } } -tst_QSslCertificate::~tst_QSslCertificate() -{ -} - -void tst_QSslCertificate::initTestCase_data() -{ -} - -void tst_QSslCertificate::init() -{ - QString srcdir(QLatin1String(SRCDIR)); - if (!srcdir.isEmpty()) { - oldCurrentDir = QDir::current().absolutePath(); - QDir::setCurrent(srcdir); - } -} - -void tst_QSslCertificate::cleanup() +void tst_QSslCertificate::cleanupTestCase() { if (!oldCurrentDir.isEmpty()) { QDir::setCurrent(oldCurrentDir); } - } static QByteArray readFile(const QString &absFilePath) @@ -569,7 +559,7 @@ void tst_QSslCertificate::fromPath_data() QTest::newRow("\"d.*/c.*.pem\" wildcard pem") << QString("d.*/c.*.pem") << int(QRegExp::Wildcard) << true << 0; QTest::newRow("\"d.*/c.*.pem\" wildcard der") << QString("d.*/c.*.pem") << int(QRegExp::Wildcard) << false << 0; #ifdef Q_OS_LINUX - QTest::newRow("absolute path wildcard pem") << QString(QDir::currentPath() + "/certificates/*.pem") << int(QRegExp::Wildcard) << true << 5; + QTest::newRow("absolute path wildcard pem") << (testDataDir + "/certificates/*.pem") << int(QRegExp::Wildcard) << true << 5; #endif QTest::newRow("trailing-whitespace") << QString("more-certificates/trailing-whitespace.pem") << int(QRegExp::FixedString) << true << 1; @@ -783,7 +773,7 @@ void tst_QSslCertificate::task256066toPem() void tst_QSslCertificate::nulInCN() { QList<QSslCertificate> certList = - QSslCertificate::fromPath(SRCDIR "more-certificates/badguy-nul-cn.crt"); + QSslCertificate::fromPath(testDataDir + "/more-certificates/badguy-nul-cn.crt"); QCOMPARE(certList.size(), 1); const QSslCertificate &cert = certList.at(0); @@ -799,7 +789,7 @@ void tst_QSslCertificate::nulInCN() void tst_QSslCertificate::nulInSan() { QList<QSslCertificate> certList = - QSslCertificate::fromPath(SRCDIR "more-certificates/badguy-nul-san.crt"); + QSslCertificate::fromPath(testDataDir + "/more-certificates/badguy-nul-san.crt"); QCOMPARE(certList.size(), 1); const QSslCertificate &cert = certList.at(0); @@ -819,7 +809,7 @@ void tst_QSslCertificate::nulInSan() void tst_QSslCertificate::largeSerialNumber() { QList<QSslCertificate> certList = - QSslCertificate::fromPath(SRCDIR "more-certificates/cert-large-serial-number.pem"); + QSslCertificate::fromPath(testDataDir + "/more-certificates/cert-large-serial-number.pem"); QCOMPARE(certList.size(), 1); @@ -831,7 +821,7 @@ void tst_QSslCertificate::largeSerialNumber() void tst_QSslCertificate::largeExpirationDate() // QTBUG-12489 { QList<QSslCertificate> certList = - QSslCertificate::fromPath(SRCDIR "more-certificates/cert-large-expiration-date.pem"); + QSslCertificate::fromPath(testDataDir + "/more-certificates/cert-large-expiration-date.pem"); QCOMPARE(certList.size(), 1); @@ -854,18 +844,18 @@ void tst_QSslCertificate::blacklistedCertificates() void tst_QSslCertificate::toText() { QList<QSslCertificate> certList = - QSslCertificate::fromPath(SRCDIR "more-certificates/cert-large-expiration-date.pem"); + QSslCertificate::fromPath(testDataDir + "/more-certificates/cert-large-expiration-date.pem"); QCOMPARE(certList.size(), 1); const QSslCertificate &cert = certList.at(0); // Openssl's cert dump method changed slightly between 0.9.8 and 1.0.0 versions, so we want it to match any output - QFile fOld(SRCDIR "more-certificates/cert-large-expiration-date.txt.0.9.8"); + QFile fOld(testDataDir + "/more-certificates/cert-large-expiration-date.txt.0.9.8"); QVERIFY(fOld.open(QIODevice::ReadOnly | QFile::Text)); QByteArray txtOld = fOld.readAll(); - QFile fNew(SRCDIR "more-certificates/cert-large-expiration-date.txt.1.0.0"); + QFile fNew(testDataDir + "/more-certificates/cert-large-expiration-date.txt.1.0.0"); QVERIFY(fNew.open(QIODevice::ReadOnly | QFile::Text)); QByteArray txtNew = fNew.readAll(); QVERIFY(txtOld == cert.toText() || txtNew == cert.toText()); @@ -874,7 +864,7 @@ void tst_QSslCertificate::toText() void tst_QSslCertificate::multipleCommonNames() { QList<QSslCertificate> certList = - QSslCertificate::fromPath(SRCDIR "more-certificates/test-cn-two-cns-cert.pem"); + QSslCertificate::fromPath(testDataDir + "/more-certificates/test-cn-two-cns-cert.pem"); QVERIFY2(certList.count() > 0, "Please run this test from the source directory"); QStringList commonNames = certList[0].subjectInfo(QSslCertificate::CommonName); @@ -885,14 +875,14 @@ void tst_QSslCertificate::multipleCommonNames() void tst_QSslCertificate::subjectAndIssuerAttributes() { QList<QSslCertificate> certList = - QSslCertificate::fromPath(SRCDIR "more-certificates/test-cn-with-drink-cert.pem"); + QSslCertificate::fromPath(testDataDir + "/more-certificates/test-cn-with-drink-cert.pem"); QVERIFY2(certList.count() > 0, "Please run this test from the source directory"); QList<QByteArray> attributes = certList[0].subjectInfoAttributes(); QVERIFY(attributes.contains(QByteArray("favouriteDrink"))); attributes.clear(); - certList = QSslCertificate::fromPath(SRCDIR "more-certificates/natwest-banking.pem"); + certList = QSslCertificate::fromPath(testDataDir + "/more-certificates/natwest-banking.pem"); QVERIFY2(certList.count() > 0, "Please run this test from the source directory"); attributes = certList[0].subjectInfoAttributes(); @@ -917,17 +907,17 @@ void tst_QSslCertificate::verify() errors.clear(); // Verify a valid cert signed by a CA - QList<QSslCertificate> caCerts = QSslCertificate::fromPath(SRCDIR "verify-certs/cacert.pem"); + QList<QSslCertificate> caCerts = QSslCertificate::fromPath(testDataDir + "/verify-certs/cacert.pem"); QSslSocket::addDefaultCaCertificate(caCerts.first()); - toVerify = QSslCertificate::fromPath(SRCDIR "verify-certs/test-ocsp-good-cert.pem"); + toVerify = QSslCertificate::fromPath(testDataDir + "/verify-certs/test-ocsp-good-cert.pem"); errors = QSslCertificate::verify(toVerify); VERIFY_VERBOSE(errors.count() == 0); errors.clear(); // Test a blacklisted certificate - toVerify = QSslCertificate::fromPath(SRCDIR "verify-certs/test-addons-mozilla-org-cert.pem"); + toVerify = QSslCertificate::fromPath(testDataDir + "/verify-certs/test-addons-mozilla-org-cert.pem"); errors = QSslCertificate::verify(toVerify); bool foundBlack = false; foreach (const QSslError &error, errors) { @@ -940,7 +930,7 @@ void tst_QSslCertificate::verify() errors.clear(); // This one is expired and untrusted - toVerify = QSslCertificate::fromPath(SRCDIR "more-certificates/cert-large-serial-number.pem"); + toVerify = QSslCertificate::fromPath(testDataDir + "/more-certificates/cert-large-serial-number.pem"); errors = QSslCertificate::verify(toVerify); VERIFY_VERBOSE(errors.contains(QSslError(QSslError::SelfSignedCertificate, toVerify[0]))); VERIFY_VERBOSE(errors.contains(QSslError(QSslError::CertificateExpired, toVerify[0]))); @@ -948,15 +938,15 @@ void tst_QSslCertificate::verify() toVerify.clear(); // This one is signed by a valid cert, but the signer is not a valid CA - toVerify << QSslCertificate::fromPath(SRCDIR "verify-certs/test-intermediate-not-ca-cert.pem").first(); - toVerify << QSslCertificate::fromPath(SRCDIR "verify-certs/test-ocsp-good-cert.pem").first(); + toVerify << QSslCertificate::fromPath(testDataDir + "/verify-certs/test-intermediate-not-ca-cert.pem").first(); + toVerify << QSslCertificate::fromPath(testDataDir + "/verify-certs/test-ocsp-good-cert.pem").first(); errors = QSslCertificate::verify(toVerify); VERIFY_VERBOSE(errors.contains(QSslError(QSslError::InvalidCaCertificate, toVerify[1]))); toVerify.clear(); // This one is signed by a valid cert, and the signer is a valid CA - toVerify << QSslCertificate::fromPath(SRCDIR "verify-certs/test-intermediate-is-ca-cert.pem").first(); - toVerify << QSslCertificate::fromPath(SRCDIR "verify-certs/test-intermediate-ca-cert.pem").first(); + toVerify << QSslCertificate::fromPath(testDataDir + "/verify-certs/test-intermediate-is-ca-cert.pem").first(); + toVerify << QSslCertificate::fromPath(testDataDir + "/verify-certs/test-intermediate-ca-cert.pem").first(); errors = QSslCertificate::verify(toVerify); VERIFY_VERBOSE(errors.count() == 0); @@ -986,7 +976,7 @@ QString tst_QSslCertificate::toString(const QList<QSslError>& errors) void tst_QSslCertificate::extensions() { QList<QSslCertificate> certList = - QSslCertificate::fromPath(SRCDIR "more-certificates/natwest-banking.pem"); + QSslCertificate::fromPath(testDataDir + "/more-certificates/natwest-banking.pem"); QVERIFY2(certList.count() > 0, "Please run this test from the source directory"); QSslCertificate cert = certList[0]; diff --git a/tests/auto/network/ssl/qsslkey/qsslkey.pro b/tests/auto/network/ssl/qsslkey/qsslkey.pro index 4af35487cd..d794c0faf0 100644 --- a/tests/auto/network/ssl/qsslkey/qsslkey.pro +++ b/tests/auto/network/ssl/qsslkey/qsslkey.pro @@ -6,23 +6,4 @@ QT = core network testlib TARGET = tst_qsslkey -win32 { - CONFIG(debug, debug|release) { - DESTDIR = debug -} else { - DESTDIR = release - } -} - -wince* { - keyFiles.files = keys - keyFiles.path = . - - passphraseFiles.files = rsa-without-passphrase.pem rsa-with-passphrase.pem - passphraseFiles.path = . - - DEPLOYMENT += keyFiles passphraseFiles - DEFINES += SRCDIR=\\\".\\\" -} else { - DEFINES+= SRCDIR=\\\"$$PWD\\\" -} +TESTDATA += keys/* rsa-without-passphrase.pem rsa-with-passphrase.pem diff --git a/tests/auto/network/ssl/qsslkey/tst_qsslkey.cpp b/tests/auto/network/ssl/qsslkey/tst_qsslkey.cpp index f59f0bb5a9..e8941a2642 100644 --- a/tests/auto/network/ssl/qsslkey/tst_qsslkey.cpp +++ b/tests/auto/network/ssl/qsslkey/tst_qsslkey.cpp @@ -68,14 +68,8 @@ class tst_QSslKey : public QObject void createPlainTestRows(); -public: - tst_QSslKey(); - virtual ~tst_QSslKey(); - public slots: - void initTestCase_data(); - void init(); - void cleanup(); + void initTestCase(); #ifndef QT_NO_OPENSSL @@ -95,16 +89,17 @@ private slots: void passphraseChecks(); #endif +private: + QString testDataDir; }; -tst_QSslKey::tst_QSslKey() +void tst_QSslKey::initTestCase() { -#ifdef Q_OS_MAC - // applicationDirPath() points to a path inside the app bundle on Mac. - QDir dir(qApp->applicationDirPath() + QLatin1String("/../../../keys")); -#else - QDir dir(SRCDIR + QLatin1String("/keys")); // prefer this way to avoid ifdeffery and support shadow builds? -#endif + testDataDir = QFileInfo(QFINDTESTDATA("rsa-without-passphrase.pem")).absolutePath(); + if (testDataDir.isEmpty()) + testDataDir = QCoreApplication::applicationDirPath(); + + QDir dir(testDataDir + "/keys"); QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::Readable); QRegExp rx(QLatin1String("^(rsa|dsa)-(pub|pri)-(\\d+)\\.(pem|der)$")); foreach (QFileInfo fileInfo, fileInfoList) { @@ -118,22 +113,6 @@ tst_QSslKey::tst_QSslKey() } } -tst_QSslKey::~tst_QSslKey() -{ -} - -void tst_QSslKey::initTestCase_data() -{ -} - -void tst_QSslKey::init() -{ -} - -void tst_QSslKey::cleanup() -{ -} - static QByteArray readFile(const QString &absFilePath) { QFile file(absFilePath); @@ -295,10 +274,11 @@ void tst_QSslKey::toEncryptedPemOrDer_data() << "aAzZ`1234567890-=~!@#$%^&*()_+[]{}\\|;:'\",.<>/?"; // ### add more (?) foreach (KeyInfo keyInfo, keyInfoList) { foreach (QString password, passwords) { - QString testName = QString("%1-%2-%3-%4").arg(keyInfo.fileInfo.fileName()) + QString testName = QString("%1-%2-%3-%4-%5").arg(keyInfo.fileInfo.fileName()) .arg(keyInfo.algorithm == QSsl::Rsa ? "RSA" : "DSA") .arg(keyInfo.type == QSsl::PrivateKey ? "PrivateKey" : "PublicKey") - .arg(keyInfo.format == QSsl::Pem ? "PEM" : "DER"); + .arg(keyInfo.format == QSsl::Pem ? "PEM" : "DER") + .arg(password); QTest::newRow(testName.toLatin1()) << keyInfo.fileInfo.absoluteFilePath() << keyInfo.algorithm << keyInfo.type << keyInfo.format << password; @@ -367,7 +347,7 @@ void tst_QSslKey::toEncryptedPemOrDer() void tst_QSslKey::passphraseChecks() { { - QString fileName(SRCDIR "/rsa-with-passphrase.pem"); + QString fileName(testDataDir + "/rsa-with-passphrase.pem"); QFile keyFile(fileName); QVERIFY(keyFile.exists()); { @@ -406,7 +386,7 @@ void tst_QSslKey::passphraseChecks() { // be sure and check a key without passphrase too - QString fileName(SRCDIR "/rsa-without-passphrase.pem"); + QString fileName(testDataDir + "/rsa-without-passphrase.pem"); QFile keyFile(fileName); { if (!keyFile.isOpen()) diff --git a/tests/auto/network/ssl/qsslsocket/qsslsocket.pro b/tests/auto/network/ssl/qsslsocket/qsslsocket.pro index a8763d69af..bb04e0b9c4 100644 --- a/tests/auto/network/ssl/qsslsocket/qsslsocket.pro +++ b/tests/auto/network/ssl/qsslsocket/qsslsocket.pro @@ -35,3 +35,5 @@ wince* { linux-*:system(". /etc/lsb-release && [ $DISTRIB_CODENAME = oneiric ]"):DEFINES+=UBUNTU_ONEIRIC requires(contains(QT_CONFIG,private_tests)) + +win32:CONFIG += insignificant_test # QTBUG-24234 |