summaryrefslogtreecommitdiffstats
path: root/tests/auto/qhttpnetworkconnection
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2009-10-01 11:42:15 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2009-10-01 12:10:57 (GMT)
commit938ba08e7bf90063127b298da25a124441659e89 (patch)
tree04a19fb29b4ec2fc258f199c380a6f19715147a2 /tests/auto/qhttpnetworkconnection
parent276496e9f646be3c442d46fda4298e00330763c2 (diff)
downloadQt-938ba08e7bf90063127b298da25a124441659e89.zip
Qt-938ba08e7bf90063127b298da25a124441659e89.tar.gz
Qt-938ba08e7bf90063127b298da25a124441659e89.tar.bz2
tst_qhttpnetworkconnection: Add a priority test
Add a testcase that checks that high priority requests are actually high priority. Reviewed-by: Peter Hartmann
Diffstat (limited to 'tests/auto/qhttpnetworkconnection')
-rw-r--r--tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp b/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
index 470e57f..6036a14 100644
--- a/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
+++ b/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
@@ -106,6 +106,7 @@ private Q_SLOTS:
void getMultiple_data();
void getMultiple();
void getMultipleWithPipeliningAndMultiplePriorities();
+ void getMultipleWithPriorities();
};
tst_QHttpNetworkConnection::tst_QHttpNetworkConnection()
@@ -908,5 +909,63 @@ void tst_QHttpNetworkConnection::getMultipleWithPipeliningAndMultiplePriorities(
qDeleteAll(replies);
}
+class GetMultipleWithPrioritiesReceiver : public QObject
+{
+ Q_OBJECT
+public:
+ int highPrioReceived;
+ int lowPrioReceived;
+ int requestCount;
+ GetMultipleWithPrioritiesReceiver(int rq) : highPrioReceived(0), lowPrioReceived(0), requestCount(rq) { }
+public Q_SLOTS:
+ void finishedSlot() {
+ QHttpNetworkReply *reply = (QHttpNetworkReply*) sender();
+ if (reply->request().priority() == QHttpNetworkRequest::HighPriority)
+ highPrioReceived++;
+ else if (reply->request().priority() == QHttpNetworkRequest::LowPriority)
+ lowPrioReceived++;
+ else
+ QFAIL("Wrong priority!?");
+
+ QVERIFY(highPrioReceived >= lowPrioReceived);
+
+ if (highPrioReceived + lowPrioReceived == requestCount)
+ QTestEventLoop::instance().exitLoop();
+ }
+};
+
+void tst_QHttpNetworkConnection::getMultipleWithPriorities()
+{
+ quint16 requestCount = 100;
+ // use 2 connections.
+ QHttpNetworkConnection connection(2, QtNetworkSettings::serverName());
+ GetMultipleWithPrioritiesReceiver receiver(requestCount);
+ QUrl url("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt");
+ QList<QHttpNetworkRequest*> requests;
+ QList<QHttpNetworkReply*> replies;
+
+ for (int i = 0; i < requestCount; i++) {
+ QHttpNetworkRequest *request = new QHttpNetworkRequest(url);;
+
+ if (i % 2)
+ request->setPriority(QHttpNetworkRequest::HighPriority);
+ else
+ request->setPriority(QHttpNetworkRequest::LowPriority);
+
+ requests.append(request);
+ QHttpNetworkReply *reply = connection.sendRequest(*request);
+ connect(reply, SIGNAL(finished()), &receiver, SLOT(finishedSlot()));
+ replies.append(reply);
+ }
+
+ QTestEventLoop::instance().enterLoop(40);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ qDeleteAll(requests);
+ qDeleteAll(replies);
+}
+
+
+
QTEST_MAIN(tst_QHttpNetworkConnection)
#include "tst_qhttpnetworkconnection.moc"