diff options
author | Markus Goetz <Markus.Goetz@nokia.com> | 2010-02-18 14:11:10 (GMT) |
---|---|---|
committer | Markus Goetz <Markus.Goetz@nokia.com> | 2010-02-18 15:46:20 (GMT) |
commit | 9d8614d8dcd1ae8389842aa4c48d8c77ae69bf27 (patch) | |
tree | 0778f2d7486d6ae6fb0e9c6e6138a1e1d68ad376 /tests/auto | |
parent | 90c3e1d2110c47ad36e05c04c874d6d932dd772f (diff) | |
download | Qt-9d8614d8dcd1ae8389842aa4c48d8c77ae69bf27.zip Qt-9d8614d8dcd1ae8389842aa4c48d8c77ae69bf27.tar.gz Qt-9d8614d8dcd1ae8389842aa4c48d8c77ae69bf27.tar.bz2 |
tst_qnetworkreply: Add another testcase
Reviewed-by: Peter Hartmann
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 5fecc86..049bbb8 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -257,6 +257,8 @@ private Q_SLOTS: void httpConnectionCount(); + void httpRecursiveCreation(); + #ifndef QT_NO_OPENSSL void ioPostToHttpsUploadProgress(); void ignoreSslErrorsList_data(); @@ -3788,6 +3790,70 @@ void tst_QNetworkReply::httpConnectionCount() #endif } +class HttpRecursiveCreationHelper : public QObject { + Q_OBJECT +public: + + HttpRecursiveCreationHelper(): + QObject(0), + requestsStartedCount_finished(0), + requestsStartedCount_readyRead(0), + requestsFinishedCount(0) + { + } + QNetworkAccessManager manager; + int requestsStartedCount_finished; + int requestsStartedCount_readyRead; + int requestsFinishedCount; +public slots: + void finishedSlot() { + requestsFinishedCount++; + + QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); + QVERIFY(!reply->error()); + QVERIFY(reply->bytesAvailable() == 27906); + + if (requestsFinishedCount == 60) { + QTestEventLoop::instance().exitLoop(); + return; + } + + if (requestsStartedCount_finished < 30) { + startOne(); + requestsStartedCount_finished++; + } + + reply->deleteLater(); + } + void readyReadSlot() { + QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); + QVERIFY(!reply->error()); + + if (requestsStartedCount_readyRead < 30 && reply->bytesAvailable() > 27906/2) { + startOne(); + requestsStartedCount_readyRead++; + } + } + void startOne() { + QUrl url = "http://" + QtNetworkSettings::serverName() + "/gif/fluke.gif"; + QNetworkRequest request(url); + QNetworkReply *reply = manager.get(request); + reply->setParent(this); + connect(reply, SIGNAL(finished()), this, SLOT(finishedSlot())); + connect(reply, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); + } +}; + +void tst_QNetworkReply::httpRecursiveCreation() +{ + // this test checks if creation of new requests to the same host properly works + // from readyRead() and finished() signals + HttpRecursiveCreationHelper helper; + helper.startOne(); + QTestEventLoop::instance().enterLoop(30); + QVERIFY(!QTestEventLoop::instance().timeout()); +} + #ifndef QT_NO_OPENSSL void tst_QNetworkReply::ignoreSslErrorsList_data() { |