summaryrefslogtreecommitdiffstats
path: root/tests/auto/qnetworkreply
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2010-11-05 13:11:30 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2010-11-05 13:15:54 (GMT)
commitd4cad3c2f3fdbf6a1bda926582fb8ad4b6f08666 (patch)
tree7358134bd134c5d0f327af4b20d1cc207613823e /tests/auto/qnetworkreply
parentc791b300b288635ed018d50c5e6e28859b374b5e (diff)
downloadQt-d4cad3c2f3fdbf6a1bda926582fb8ad4b6f08666.zip
Qt-d4cad3c2f3fdbf6a1bda926582fb8ad4b6f08666.tar.gz
Qt-d4cad3c2f3fdbf6a1bda926582fb8ad4b6f08666.tar.bz2
tst_qnetworkreply: One more HTTP test using setReadBufferSize()
Task-number: QTBUG-13431
Diffstat (limited to 'tests/auto/qnetworkreply')
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index d21428b..bef1e7e6 100644
--- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
@@ -297,6 +297,8 @@ private Q_SLOTS:
void qtbug4121unknownAuthentication();
+ void qtbug13431replyThrottling();
+
// NOTE: This test must be last!
void parentingRepliesToTheApp();
};
@@ -4643,6 +4645,56 @@ void tst_QNetworkReply::qtbug4121unknownAuthentication()
QCOMPARE(reply->error(), QNetworkReply::AuthenticationRequiredError);
}
+class QtBug13431Helper : public QObject {
+ Q_OBJECT
+public:
+ QNetworkReply* m_reply;
+ QTimer m_dlTimer;
+public slots:
+ void replyFinished(QNetworkReply*) {
+ QTestEventLoop::instance().exitLoop();
+ }
+
+ void onReadAndReschedule() {
+ const qint64 bytesReceived = m_reply->bytesAvailable();
+ if (bytesReceived) {
+ QByteArray data = m_reply->read(bytesReceived);
+ // reschedule read
+ const int millisecDelay = static_cast<int>(bytesReceived * 1000 / m_reply->readBufferSize());
+ m_dlTimer.start(millisecDelay);
+ }
+ else {
+ // reschedule read
+ m_dlTimer.start(200);
+ }
+ }
+};
+
+void tst_QNetworkReply::qtbug13431replyThrottling()
+{
+ QtBug13431Helper helper;
+
+ QNetworkAccessManager nam;
+ connect(&nam, SIGNAL(finished(QNetworkReply*)), &helper, SLOT(replyFinished(QNetworkReply*)));
+
+ // Download a bigger file
+ QNetworkRequest netRequest(QUrl("http://qt-test-server/qtest/bigfile"));
+ helper.m_reply = nam.get(netRequest);
+ // Set the throttle
+ helper.m_reply->setReadBufferSize(36000);
+
+ // Schedule a timer that tries to read
+
+ connect(&helper.m_dlTimer, SIGNAL(timeout()), &helper, SLOT(onReadAndReschedule()));
+ helper.m_dlTimer.setSingleShot(true);
+ helper.m_dlTimer.start(0);
+
+ QTestEventLoop::instance().enterLoop(30);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ QVERIFY(helper.m_reply->isFinished());
+ QCOMPARE(helper.m_reply->error(), QNetworkReply::NoError);
+}
+
// NOTE: This test must be last testcase in tst_qnetworkreply!