From 6c4c5709a3f6150c4e37f38c7e7fd980ab359a53 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Tue, 14 Feb 2012 20:12:42 +0000 Subject: Abort FTP download, not the whole application An old coding error meant that the C runtime abort() function was being called instead of QFtp::abort() when cancelling an FTP download using QNetworkReply::close() Task-number: QTBUG-22820 Change-Id: Ib97fda9769b2b55a08c042c66c4444cb6216d2b1 Reviewed-by: Thiago Macieira --- src/network/access/qnetworkaccessftpbackend.cpp | 6 +----- tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/network/access/qnetworkaccessftpbackend.cpp b/src/network/access/qnetworkaccessftpbackend.cpp index 7b7ebb5..6b9ce50 100644 --- a/src/network/access/qnetworkaccessftpbackend.cpp +++ b/src/network/access/qnetworkaccessftpbackend.cpp @@ -179,11 +179,7 @@ void QNetworkAccessFtpBackend::closeDownstreamChannel() { state = Disconnecting; if (operation() == QNetworkAccessManager::GetOperation) -#ifndef Q_OS_WINCE - abort(); -#else - exit(3); -#endif + ftp->abort(); } void QNetworkAccessFtpBackend::downstreamReadyWrite() diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index b6a0196..53835d8 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -386,6 +386,9 @@ private Q_SLOTS: void synchronousAuthenticationCache(); void pipelining(); + void closeDuringDownload_data(); + void closeDuringDownload(); + // NOTE: This test must be last! void parentingRepliesToTheApp(); }; @@ -6703,6 +6706,27 @@ void tst_QNetworkReply::pipeliningHelperSlot() { } } +void tst_QNetworkReply::closeDuringDownload_data() +{ + QTest::addColumn("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() { -- cgit v0.12