From 4698e02579a4427c7a4ff7d59b1e37ba28ebc8e0 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Thu, 13 May 2010 14:54:34 +0200 Subject: QNAM HTTP: More testcases --- .../tst_qhttpnetworkconnection.cpp | 44 ++++++++++++++++++++ tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 47 ++++++++++++++++++++++ 2 files changed, 91 insertions(+) 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("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("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() { -- cgit v0.12