summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/network/access/qhttpnetworkreply.cpp3
-rw-r--r--tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp44
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp47
3 files changed, 94 insertions, 0 deletions
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp
index 338236e..108ba8a 100644
--- a/src/network/access/qhttpnetworkreply.cpp
+++ b/src/network/access/qhttpnetworkreply.cpp
@@ -179,6 +179,9 @@ qint64 QHttpNetworkReply::bytesAvailableNextBlock() const
QByteArray QHttpNetworkReply::readAny()
{
Q_D(QHttpNetworkReply);
+ if (d->responseData.bufferCount() == 0)
+ return QByteArray();
+
// we'll take the last buffer, so schedule another read from http
if (d->downstreamLimited && d->responseData.bufferCount() == 1)
d->connection->d_func()->readMoreLater(this);
diff --git a/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp b/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
index 21f228a..89f608e 100644
--- a/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
+++ b/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
@@ -109,6 +109,9 @@ private Q_SLOTS:
void getMultipleWithPriorities();
void getEmptyWithPipelining();
+
+ void getAndThenDeleteObject();
+ void getAndThenDeleteObject_data();
};
tst_QHttpNetworkConnection::tst_QHttpNetworkConnection()
@@ -1033,6 +1036,47 @@ void tst_QHttpNetworkConnection::getEmptyWithPipelining()
qDeleteAll(replies);
}
+void tst_QHttpNetworkConnection::getAndThenDeleteObject_data()
+{
+ QTest::addColumn<bool>("replyFirst");
+
+ QTest::newRow("delete-reply-first") << true;
+ QTest::newRow("delete-connection-first") << false;
+}
+
+void tst_QHttpNetworkConnection::getAndThenDeleteObject()
+{
+ // yes, this will leak if the testcase fails. I don't care. It must not fail then :P
+ QHttpNetworkConnection *connection = new QHttpNetworkConnection(QtNetworkSettings::serverName());
+ QHttpNetworkRequest request("http://" + QtNetworkSettings::serverName() + "/qtest/bigfile");
+ QHttpNetworkReply *reply = connection->sendRequest(request);
+ reply->setDownstreamLimited(true);
+
+ QTime stopWatch;
+ stopWatch.start();
+ forever {
+ QCoreApplication::instance()->processEvents();
+ if (reply->bytesAvailable())
+ break;
+ if (stopWatch.elapsed() >= 30000)
+ break;
+ }
+
+ QVERIFY(reply->bytesAvailable());
+ QCOMPARE(reply->statusCode() ,200);
+ QVERIFY(!reply->isFinished()); // must not be finished
+
+ QFETCH(bool, replyFirst);
+
+ if (replyFirst) {
+ delete reply;
+ delete connection;
+ } else {
+ delete connection;
+ delete reply;
+ }
+}
+
QTEST_MAIN(tst_QHttpNetworkConnection)
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index 038610d..74ed7fc 100644
--- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
@@ -276,6 +276,9 @@ private Q_SLOTS:
void ignoreSslErrorsListWithSlot();
#endif
+ void getAndThenDeleteObject_data();
+ void getAndThenDeleteObject();
+
// NOTE: This test must be last!
void parentingRepliesToTheApp();
};
@@ -4108,6 +4111,50 @@ void tst_QNetworkReply::ignoreSslErrorsListWithSlot()
#endif // QT_NO_OPENSSL
+void tst_QNetworkReply::getAndThenDeleteObject_data()
+{
+ QTest::addColumn<bool>("replyFirst");
+
+ QTest::newRow("delete-reply-first") << true;
+ QTest::newRow("delete-qnam-first") << false;
+}
+
+void tst_QNetworkReply::getAndThenDeleteObject()
+{
+ // yes, this will leak if the testcase fails. I don't care. It must not fail then :P
+ QNetworkAccessManager *manager = new QNetworkAccessManager();
+ QNetworkRequest request("http://" + QtNetworkSettings::serverName() + "/qtest/bigfile");
+ QNetworkReply *reply = manager->get(request);
+ reply->setReadBufferSize(1);
+ reply->setParent((QObject*)0); // must be 0 because else it is the manager
+
+ QTime stopWatch;
+ stopWatch.start();
+ forever {
+ QCoreApplication::instance()->processEvents();
+ if (reply->bytesAvailable())
+ break;
+ if (stopWatch.elapsed() >= 30000)
+ break;
+ }
+
+ QVERIFY(reply->bytesAvailable());
+ QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200);
+ QVERIFY(!reply->isFinished()); // must not be finished
+
+ QFETCH(bool, replyFirst);
+
+ if (replyFirst) {
+ delete reply;
+ delete manager;
+ } else {
+ delete manager;
+ delete reply;
+ }
+}
+
+
+
// NOTE: This test must be last testcase in tst_qnetworkreply!
void tst_QNetworkReply::parentingRepliesToTheApp()
{