From 938ba08e7bf90063127b298da25a124441659e89 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Thu, 1 Oct 2009 13:42:15 +0200 Subject: tst_qhttpnetworkconnection: Add a priority test Add a testcase that checks that high priority requests are actually high priority. Reviewed-by: Peter Hartmann --- .../tst_qhttpnetworkconnection.cpp | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) 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 requests; + QList 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" -- cgit v0.12