author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 13 | c0432d11811c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include "private/qhttpnetworkconnection_p.h" |
|
45 |
#include "private/qnoncontiguousbytedevice_p.h" |
|
46 |
#include <QAuthenticator> |
|
47 |
||
48 |
#include "../network-settings.h" |
|
49 |
||
50 |
class tst_QHttpNetworkConnection: public QObject |
|
51 |
{ |
|
52 |
Q_OBJECT |
|
53 |
||
54 |
public: |
|
55 |
tst_QHttpNetworkConnection(); |
|
56 |
||
57 |
public Q_SLOTS: |
|
58 |
void finishedReply(); |
|
59 |
void finishedWithError(QNetworkReply::NetworkError errorCode, const QString &detail); |
|
60 |
void challenge401(const QHttpNetworkRequest &request, QAuthenticator *authenticator, const QHttpNetworkConnection *connection); |
|
61 |
#ifndef QT_NO_OPENSSL |
|
62 |
void sslErrors(const QList<QSslError> &errors); |
|
63 |
#endif |
|
64 |
private: |
|
65 |
bool finishedCalled; |
|
66 |
bool finishedWithErrorCalled; |
|
67 |
QNetworkReply::NetworkError netErrorCode; |
|
68 |
||
69 |
private Q_SLOTS: |
|
70 |
void init(); |
|
71 |
void cleanup(); |
|
72 |
void initTestCase(); |
|
73 |
void cleanupTestCase(); |
|
74 |
||
75 |
void options_data(); |
|
76 |
void options(); |
|
77 |
void get_data(); |
|
78 |
void get(); |
|
79 |
void head_data(); |
|
80 |
void head(); |
|
81 |
void post_data(); |
|
82 |
void post(); |
|
83 |
void put_data(); |
|
84 |
void put(); |
|
85 |
void _delete_data(); |
|
86 |
void _delete(); |
|
87 |
void trace_data(); |
|
88 |
void trace(); |
|
89 |
void _connect_data(); |
|
90 |
void _connect(); |
|
91 |
#ifndef QT_NO_COMPRESS |
|
92 |
void compression_data(); |
|
93 |
void compression(); |
|
94 |
#endif |
|
95 |
#ifndef QT_NO_OPENSSL |
|
96 |
void ignoresslerror_data(); |
|
97 |
void ignoresslerror(); |
|
98 |
#endif |
|
99 |
#ifdef QT_NO_OPENSSL |
|
100 |
void nossl_data(); |
|
101 |
void nossl(); |
|
102 |
#endif |
|
103 |
void get401_data(); |
|
104 |
void get401(); |
|
105 |
||
106 |
void getMultiple_data(); |
|
107 |
void getMultiple(); |
|
108 |
void getMultipleWithPipeliningAndMultiplePriorities(); |
|
109 |
void getMultipleWithPriorities(); |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
110 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
111 |
void getEmptyWithPipelining(); |
0 | 112 |
}; |
113 |
||
114 |
tst_QHttpNetworkConnection::tst_QHttpNetworkConnection() |
|
115 |
{ |
|
116 |
Q_SET_DEFAULT_IAP |
|
117 |
} |
|
118 |
||
119 |
void tst_QHttpNetworkConnection::initTestCase() |
|
120 |
{ |
|
121 |
} |
|
122 |
||
123 |
void tst_QHttpNetworkConnection::cleanupTestCase() |
|
124 |
{ |
|
125 |
} |
|
126 |
||
127 |
void tst_QHttpNetworkConnection::init() |
|
128 |
{ |
|
129 |
} |
|
130 |
||
131 |
void tst_QHttpNetworkConnection::cleanup() |
|
132 |
{ |
|
133 |
} |
|
134 |
||
135 |
void tst_QHttpNetworkConnection::options_data() |
|
136 |
{ |
|
137 |
// not tested yet |
|
138 |
} |
|
139 |
||
140 |
void tst_QHttpNetworkConnection::options() |
|
141 |
{ |
|
142 |
QEXPECT_FAIL("", "not tested yet", Continue); |
|
143 |
QVERIFY(false); |
|
144 |
} |
|
145 |
||
146 |
void tst_QHttpNetworkConnection::head_data() |
|
147 |
{ |
|
148 |
QTest::addColumn<QString>("protocol"); |
|
149 |
QTest::addColumn<QString>("host"); |
|
150 |
QTest::addColumn<QString>("path"); |
|
151 |
QTest::addColumn<ushort>("port"); |
|
152 |
QTest::addColumn<bool>("encrypt"); |
|
153 |
QTest::addColumn<int>("statusCode"); |
|
154 |
QTest::addColumn<QString>("statusString"); |
|
155 |
QTest::addColumn<int>("contentLength"); |
|
156 |
||
157 |
QTest::newRow("success-internal") << "http://" << QtNetworkSettings::serverName() << "/qtest/rfc3252.txt" << ushort(80) << false << 200 << "OK" << 25962; |
|
158 |
QTest::newRow("success-external") << "http://" << "www.ietf.org" << "/rfc/rfc3252.txt" << ushort(80) << false << 200 << "OK" << 25962; |
|
159 |
||
160 |
QTest::newRow("failure-path") << "http://" << QtNetworkSettings::serverName() << "/t" << ushort(80) << false << 404 << "Not Found" << -1; |
|
161 |
QTest::newRow("failure-protocol") << "" << QtNetworkSettings::serverName() << "/qtest/rfc3252.txt" << ushort(80) << false << 400 << "Bad Request" << -1; |
|
162 |
} |
|
163 |
||
164 |
void tst_QHttpNetworkConnection::head() |
|
165 |
{ |
|
166 |
QFETCH(QString, protocol); |
|
167 |
QFETCH(QString, host); |
|
168 |
QFETCH(QString, path); |
|
169 |
QFETCH(ushort, port); |
|
170 |
QFETCH(bool, encrypt); |
|
171 |
QFETCH(int, statusCode); |
|
172 |
QFETCH(QString, statusString); |
|
173 |
QFETCH(int, contentLength); |
|
174 |
||
175 |
QHttpNetworkConnection connection(host); |
|
176 |
QCOMPARE(connection.port(), port); |
|
177 |
QCOMPARE(connection.hostName(), host); |
|
178 |
if (encrypt) |
|
179 |
connection.enableEncryption(); |
|
180 |
QCOMPARE(connection.isEncrypted(), encrypt); |
|
181 |
||
182 |
QHttpNetworkRequest request(protocol + host + path, QHttpNetworkRequest::Head); |
|
183 |
QHttpNetworkReply *reply = connection.sendRequest(request); |
|
184 |
||
185 |
QTime stopWatch; |
|
186 |
stopWatch.start(); |
|
187 |
do { |
|
188 |
QCoreApplication::instance()->processEvents(); |
|
189 |
if (stopWatch.elapsed() >= 30000) |
|
190 |
break; |
|
191 |
} while (!reply->isFinished()); |
|
192 |
||
193 |
QCOMPARE(reply->statusCode(), statusCode); |
|
194 |
QCOMPARE(reply->reasonPhrase(), statusString); |
|
195 |
// only check it if it is set |
|
196 |
if (reply->contentLength() != -1) |
|
197 |
QCOMPARE(reply->contentLength(), qint64(contentLength)); |
|
198 |
||
199 |
QVERIFY(reply->isFinished()); |
|
200 |
||
201 |
delete reply; |
|
202 |
} |
|
203 |
||
204 |
void tst_QHttpNetworkConnection::get_data() |
|
205 |
{ |
|
206 |
QTest::addColumn<QString>("protocol"); |
|
207 |
QTest::addColumn<QString>("host"); |
|
208 |
QTest::addColumn<QString>("path"); |
|
209 |
QTest::addColumn<ushort>("port"); |
|
210 |
QTest::addColumn<bool>("encrypt"); |
|
211 |
QTest::addColumn<int>("statusCode"); |
|
212 |
QTest::addColumn<QString>("statusString"); |
|
213 |
QTest::addColumn<int>("contentLength"); |
|
214 |
QTest::addColumn<int>("downloadSize"); |
|
215 |
||
216 |
QTest::newRow("success-internal") << "http://" << QtNetworkSettings::serverName() << "/qtest/rfc3252.txt" << ushort(80) << false << 200 << "OK" << 25962 << 25962; |
|
217 |
QTest::newRow("success-external") << "http://" << "www.ietf.org" << "/rfc/rfc3252.txt" << ushort(80) << false << 200 << "OK" << 25962 << 25962; |
|
218 |
||
219 |
QTest::newRow("failure-path") << "http://" << QtNetworkSettings::serverName() << "/t" << ushort(80) << false << 404 << "Not Found" << -1 << 997 + QtNetworkSettings::serverName().size(); |
|
220 |
QTest::newRow("failure-protocol") << "" << QtNetworkSettings::serverName() << "/qtest/rfc3252.txt" << ushort(80) << false << 400 << "Bad Request" << -1 << 930 + QtNetworkSettings::serverName().size(); |
|
221 |
} |
|
222 |
||
223 |
void tst_QHttpNetworkConnection::get() |
|
224 |
{ |
|
225 |
QFETCH(QString, protocol); |
|
226 |
QFETCH(QString, host); |
|
227 |
QFETCH(QString, path); |
|
228 |
QFETCH(ushort, port); |
|
229 |
QFETCH(bool, encrypt); |
|
230 |
QFETCH(int, statusCode); |
|
231 |
QFETCH(QString, statusString); |
|
232 |
QFETCH(int, contentLength); |
|
233 |
QFETCH(int, downloadSize); |
|
234 |
||
235 |
QHttpNetworkConnection connection(host); |
|
236 |
QCOMPARE(connection.port(), port); |
|
237 |
QCOMPARE(connection.hostName(), host); |
|
238 |
if (encrypt) |
|
239 |
connection.enableEncryption(); |
|
240 |
QCOMPARE(connection.isEncrypted(), encrypt); |
|
241 |
||
242 |
QHttpNetworkRequest request(protocol + host + path); |
|
243 |
QHttpNetworkReply *reply = connection.sendRequest(request); |
|
244 |
||
245 |
QTime stopWatch; |
|
246 |
stopWatch.start(); |
|
247 |
forever { |
|
248 |
QCoreApplication::instance()->processEvents(); |
|
249 |
if (reply->bytesAvailable()) |
|
250 |
break; |
|
251 |
if (stopWatch.elapsed() >= 30000) |
|
252 |
break; |
|
253 |
} |
|
254 |
||
255 |
QCOMPARE(reply->statusCode(), statusCode); |
|
256 |
QCOMPARE(reply->reasonPhrase(), statusString); |
|
257 |
// only check it if it is set |
|
258 |
if (reply->contentLength() != -1) |
|
259 |
QCOMPARE(reply->contentLength(), qint64(contentLength)); |
|
260 |
||
261 |
stopWatch.start(); |
|
262 |
QByteArray ba; |
|
263 |
do { |
|
264 |
QCoreApplication::instance()->processEvents(); |
|
265 |
while (reply->bytesAvailable()) |
|
266 |
ba += reply->readAny(); |
|
267 |
if (stopWatch.elapsed() >= 30000) |
|
268 |
break; |
|
269 |
} while (!reply->isFinished()); |
|
270 |
||
271 |
QVERIFY(reply->isFinished()); |
|
272 |
QCOMPARE(ba.size(), downloadSize); |
|
273 |
||
274 |
delete reply; |
|
275 |
} |
|
276 |
||
277 |
void tst_QHttpNetworkConnection::finishedReply() |
|
278 |
{ |
|
279 |
finishedCalled = true; |
|
280 |
} |
|
281 |
||
282 |
void tst_QHttpNetworkConnection::finishedWithError(QNetworkReply::NetworkError errorCode, const QString &detail) |
|
283 |
{ |
|
284 |
Q_UNUSED(detail) |
|
285 |
finishedWithErrorCalled = true; |
|
286 |
netErrorCode = errorCode; |
|
287 |
} |
|
288 |
||
289 |
void tst_QHttpNetworkConnection::put_data() |
|
290 |
{ |
|
291 |
||
292 |
QTest::addColumn<QString>("protocol"); |
|
293 |
QTest::addColumn<QString>("host"); |
|
294 |
QTest::addColumn<QString>("path"); |
|
295 |
QTest::addColumn<ushort>("port"); |
|
296 |
QTest::addColumn<bool>("encrypt"); |
|
297 |
QTest::addColumn<QString>("data"); |
|
298 |
QTest::addColumn<bool>("succeed"); |
|
299 |
||
300 |
QTest::newRow("success-internal") << "http://" << QtNetworkSettings::serverName() << "/dav/file1.txt" << ushort(80) << false << "Hello World\nEnd of file\n"<<true; |
|
301 |
QTest::newRow("fail-internal") << "http://" << QtNetworkSettings::serverName() << "/dav2/file1.txt" << ushort(80) << false << "Hello World\nEnd of file\n"<<false; |
|
302 |
QTest::newRow("fail-host") << "http://" << "fluke-nosuchhost.troll.no" << "/dav2/file1.txt" << ushort(80) << false << "Hello World\nEnd of file\n"<<false; |
|
303 |
} |
|
304 |
||
305 |
void tst_QHttpNetworkConnection::put() |
|
306 |
{ |
|
307 |
QFETCH(QString, protocol); |
|
308 |
QFETCH(QString, host); |
|
309 |
QFETCH(QString, path); |
|
310 |
QFETCH(ushort, port); |
|
311 |
QFETCH(bool, encrypt); |
|
312 |
QFETCH(QString, data); |
|
313 |
QFETCH(bool, succeed); |
|
314 |
||
315 |
QHttpNetworkConnection connection(host); |
|
316 |
QCOMPARE(connection.port(), port); |
|
317 |
QCOMPARE(connection.hostName(), host); |
|
318 |
if (encrypt) |
|
319 |
connection.enableEncryption(); |
|
320 |
QCOMPARE(connection.isEncrypted(), encrypt); |
|
321 |
||
322 |
QHttpNetworkRequest request(protocol + host + path, QHttpNetworkRequest::Put); |
|
323 |
||
324 |
QByteArray array = data.toLatin1(); |
|
325 |
QNonContiguousByteDevice *bd = QNonContiguousByteDeviceFactory::create(&array); |
|
326 |
bd->setParent(this); |
|
327 |
request.setUploadByteDevice(bd); |
|
328 |
||
329 |
finishedCalled = false; |
|
330 |
finishedWithErrorCalled = false; |
|
331 |
||
332 |
QHttpNetworkReply *reply = connection.sendRequest(request); |
|
333 |
connect(reply, SIGNAL(finished()), SLOT(finishedReply())); |
|
334 |
connect(reply, SIGNAL(finishedWithError(QNetworkReply::NetworkError, const QString &)), |
|
335 |
SLOT(finishedWithError(QNetworkReply::NetworkError, const QString &))); |
|
336 |
connect(&connection, SIGNAL(error(QNetworkReply::NetworkError, const QString &)), |
|
337 |
SLOT(finishedWithError(QNetworkReply::NetworkError, const QString &))); |
|
338 |
||
339 |
QTime stopWatch; |
|
340 |
stopWatch.start(); |
|
341 |
do { |
|
342 |
QCoreApplication::instance()->processEvents(); |
|
343 |
if (stopWatch.elapsed() >= 30000) |
|
344 |
break; |
|
345 |
} while (!reply->isFinished() && !finishedCalled && !finishedWithErrorCalled); |
|
346 |
||
347 |
if (reply->isFinished()) { |
|
348 |
QByteArray ba; |
|
349 |
while (reply->bytesAvailable()) |
|
350 |
ba += reply->readAny(); |
|
351 |
} else if(finishedWithErrorCalled) { |
|
352 |
if(!succeed) { |
|
353 |
delete reply; |
|
354 |
return; |
|
355 |
} else { |
|
356 |
QFAIL("Error in PUT"); |
|
357 |
} |
|
358 |
} else { |
|
359 |
QFAIL("PUT timed out"); |
|
360 |
} |
|
361 |
||
362 |
int status = reply->statusCode(); |
|
363 |
if (status != 200 && status != 201 && status != 204) { |
|
364 |
if (succeed) { |
|
365 |
qDebug()<<"PUT failed, Status Code:" <<status; |
|
366 |
QFAIL("Error in PUT"); |
|
367 |
} |
|
368 |
} else { |
|
369 |
if (!succeed) { |
|
370 |
qDebug()<<"PUT Should fail, Status Code:" <<status; |
|
371 |
QFAIL("Error in PUT"); |
|
372 |
} |
|
373 |
} |
|
374 |
delete reply; |
|
375 |
} |
|
376 |
||
377 |
void tst_QHttpNetworkConnection::post_data() |
|
378 |
{ |
|
379 |
QTest::addColumn<QString>("protocol"); |
|
380 |
QTest::addColumn<QString>("host"); |
|
381 |
QTest::addColumn<QString>("path"); |
|
382 |
QTest::addColumn<ushort>("port"); |
|
383 |
QTest::addColumn<bool>("encrypt"); |
|
384 |
QTest::addColumn<QString>("data"); |
|
385 |
QTest::addColumn<int>("statusCode"); |
|
386 |
QTest::addColumn<QString>("statusString"); |
|
387 |
QTest::addColumn<int>("contentLength"); |
|
388 |
QTest::addColumn<int>("downloadSize"); |
|
389 |
||
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
390 |
QTest::newRow("success-internal") << "http://" << QtNetworkSettings::serverName() << "/qtest/cgi-bin/echo.cgi" << ushort(80) << false << "7 bytes" << 200 << "OK" << 7 << 7; |
0 | 391 |
QTest::newRow("failure-internal") << "http://" << QtNetworkSettings::serverName() << "/t" << ushort(80) << false << "Hello World" << 404 << "Not Found" << -1 << 997 + QtNetworkSettings::serverName().size(); |
392 |
} |
|
393 |
||
394 |
void tst_QHttpNetworkConnection::post() |
|
395 |
{ |
|
396 |
QFETCH(QString, protocol); |
|
397 |
QFETCH(QString, host); |
|
398 |
QFETCH(QString, path); |
|
399 |
QFETCH(ushort, port); |
|
400 |
QFETCH(bool, encrypt); |
|
401 |
QFETCH(QString, data); |
|
402 |
QFETCH(int, statusCode); |
|
403 |
QFETCH(QString, statusString); |
|
404 |
QFETCH(int, contentLength); |
|
405 |
QFETCH(int, downloadSize); |
|
406 |
||
407 |
QHttpNetworkConnection connection(host); |
|
408 |
QCOMPARE(connection.port(), port); |
|
409 |
QCOMPARE(connection.hostName(), host); |
|
410 |
if (encrypt) |
|
411 |
connection.enableEncryption(); |
|
412 |
QCOMPARE(connection.isEncrypted(), encrypt); |
|
413 |
||
414 |
QHttpNetworkRequest request(protocol + host + path, QHttpNetworkRequest::Post); |
|
415 |
||
416 |
QByteArray array = data.toLatin1(); |
|
417 |
QNonContiguousByteDevice *bd = QNonContiguousByteDeviceFactory::create(&array); |
|
418 |
bd->setParent(this); |
|
419 |
request.setUploadByteDevice(bd); |
|
420 |
||
421 |
QHttpNetworkReply *reply = connection.sendRequest(request); |
|
422 |
||
423 |
QTime stopWatch; |
|
424 |
stopWatch.start(); |
|
425 |
forever { |
|
426 |
QCoreApplication::instance()->processEvents(); |
|
427 |
if (reply->bytesAvailable()) |
|
428 |
break; |
|
429 |
if (stopWatch.elapsed() >= 30000) |
|
430 |
break; |
|
431 |
} |
|
432 |
||
433 |
QCOMPARE(reply->statusCode(), statusCode); |
|
434 |
QCOMPARE(reply->reasonPhrase(), statusString); |
|
435 |
||
436 |
qint64 cLen = reply->contentLength(); |
|
437 |
if (cLen==-1) { |
|
438 |
// HTTP 1.1 server may respond with chunked encoding and in that |
|
439 |
// case contentLength is not present in reply -> verify that it is the case |
|
440 |
QByteArray transferEnc = reply->headerField("Transfer-Encoding"); |
|
441 |
QCOMPARE(transferEnc, QByteArray("chunked")); |
|
442 |
} else { |
|
443 |
QCOMPARE(cLen, qint64(contentLength)); |
|
444 |
} |
|
445 |
||
446 |
stopWatch.start(); |
|
447 |
QByteArray ba; |
|
448 |
do { |
|
449 |
QCoreApplication::instance()->processEvents(); |
|
450 |
while (reply->bytesAvailable()) |
|
451 |
ba += reply->readAny(); |
|
452 |
if (stopWatch.elapsed() >= 30000) |
|
453 |
break; |
|
454 |
} while (!reply->isFinished()); |
|
455 |
||
456 |
QVERIFY(reply->isFinished()); |
|
457 |
QCOMPARE(ba.size(), downloadSize); |
|
458 |
||
459 |
delete reply; |
|
460 |
} |
|
461 |
||
462 |
void tst_QHttpNetworkConnection::_delete_data() |
|
463 |
{ |
|
464 |
// not tested yet |
|
465 |
} |
|
466 |
||
467 |
void tst_QHttpNetworkConnection::_delete() |
|
468 |
{ |
|
469 |
QEXPECT_FAIL("", "not tested yet", Continue); |
|
470 |
QVERIFY(false); |
|
471 |
} |
|
472 |
||
473 |
void tst_QHttpNetworkConnection::trace_data() |
|
474 |
{ |
|
475 |
// not tested yet |
|
476 |
} |
|
477 |
||
478 |
void tst_QHttpNetworkConnection::trace() |
|
479 |
{ |
|
480 |
QEXPECT_FAIL("", "not tested yet", Continue); |
|
481 |
QVERIFY(false); |
|
482 |
} |
|
483 |
||
484 |
void tst_QHttpNetworkConnection::_connect_data() |
|
485 |
{ |
|
486 |
// not tested yet |
|
487 |
} |
|
488 |
||
489 |
void tst_QHttpNetworkConnection::_connect() |
|
490 |
{ |
|
491 |
QEXPECT_FAIL("", "not tested yet", Continue); |
|
492 |
QVERIFY(false); |
|
493 |
} |
|
494 |
||
495 |
void tst_QHttpNetworkConnection::challenge401(const QHttpNetworkRequest &request, |
|
496 |
QAuthenticator *authenticator, |
|
497 |
const QHttpNetworkConnection *connection) |
|
498 |
{ |
|
499 |
Q_UNUSED(request) |
|
500 |
Q_UNUSED(connection) |
|
501 |
||
502 |
QHttpNetworkConnection *c = qobject_cast<QHttpNetworkConnection*>(sender()); |
|
503 |
if (connection) { |
|
504 |
QVariant val = c->property("setCredentials"); |
|
505 |
if (val.toBool()) { |
|
506 |
QVariant user = c->property("username"); |
|
507 |
QVariant password = c->property("password"); |
|
508 |
authenticator->setUser(user.toString()); |
|
509 |
authenticator->setPassword(password.toString()); |
|
510 |
c->setProperty("setCredentials", false); |
|
511 |
} |
|
512 |
} |
|
513 |
} |
|
514 |
||
515 |
void tst_QHttpNetworkConnection::get401_data() |
|
516 |
{ |
|
517 |
QTest::addColumn<QString>("protocol"); |
|
518 |
QTest::addColumn<QString>("host"); |
|
519 |
QTest::addColumn<QString>("path"); |
|
520 |
QTest::addColumn<ushort>("port"); |
|
521 |
QTest::addColumn<bool>("encrypt"); |
|
522 |
QTest::addColumn<bool>("setCredentials"); |
|
523 |
QTest::addColumn<QString>("username"); |
|
524 |
QTest::addColumn<QString>("password"); |
|
525 |
QTest::addColumn<int>("statusCode"); |
|
526 |
||
527 |
QTest::newRow("no-credentials") << "http://" << QtNetworkSettings::serverName() << "/qtest/rfcs-auth/index.html" << ushort(80) << false << false << "" << ""<<401; |
|
528 |
QTest::newRow("invalid-credentials") << "http://" << QtNetworkSettings::serverName() << "/qtest/rfcs-auth/index.html" << ushort(80) << false << true << "test" << "test"<<401; |
|
529 |
QTest::newRow("valid-credentials") << "http://" << QtNetworkSettings::serverName() << "/qtest/rfcs-auth/index.html" << ushort(80) << false << true << "httptest" << "httptest"<<200; |
|
530 |
QTest::newRow("digest-authentication-invalid") << "http://" << QtNetworkSettings::serverName() << "/qtest/auth-digest/index.html" << ushort(80) << false << true << "wrong" << "wrong"<<401; |
|
531 |
QTest::newRow("digest-authentication-valid") << "http://" << QtNetworkSettings::serverName() << "/qtest/auth-digest/index.html" << ushort(80) << false << true << "httptest" << "httptest"<<200; |
|
532 |
} |
|
533 |
||
534 |
void tst_QHttpNetworkConnection::get401() |
|
535 |
{ |
|
536 |
QFETCH(QString, protocol); |
|
537 |
QFETCH(QString, host); |
|
538 |
QFETCH(QString, path); |
|
539 |
QFETCH(ushort, port); |
|
540 |
QFETCH(bool, encrypt); |
|
541 |
QFETCH(bool, setCredentials); |
|
542 |
QFETCH(QString, username); |
|
543 |
QFETCH(QString, password); |
|
544 |
QFETCH(int, statusCode); |
|
545 |
||
546 |
QHttpNetworkConnection connection(host, port, encrypt); |
|
547 |
QCOMPARE(connection.port(), port); |
|
548 |
QCOMPARE(connection.hostName(), host); |
|
549 |
if (encrypt) |
|
550 |
connection.enableEncryption(); |
|
551 |
QCOMPARE(connection.isEncrypted(), encrypt); |
|
552 |
connect(&connection, SIGNAL(authenticationRequired(const QHttpNetworkRequest&, QAuthenticator *, const QHttpNetworkConnection*)), |
|
553 |
SLOT(challenge401(const QHttpNetworkRequest&, QAuthenticator *, const QHttpNetworkConnection*))); |
|
554 |
connection.setProperty("setCredentials", setCredentials); |
|
555 |
connection.setProperty("username", username); |
|
556 |
connection.setProperty("password", password); |
|
557 |
||
558 |
QHttpNetworkRequest request(protocol + host + path); |
|
559 |
QHttpNetworkReply *reply = connection.sendRequest(request); |
|
560 |
||
561 |
finishedCalled = false; |
|
562 |
finishedWithErrorCalled = false; |
|
563 |
||
564 |
connect(reply, SIGNAL(finished()), SLOT(finishedReply())); |
|
565 |
connect(reply, SIGNAL(finishedWithError(QNetworkReply::NetworkError, const QString &)), |
|
566 |
SLOT(finishedWithError(QNetworkReply::NetworkError, const QString &))); |
|
567 |
||
568 |
QTime stopWatch; |
|
569 |
stopWatch.start(); |
|
570 |
forever { |
|
571 |
QCoreApplication::instance()->processEvents(); |
|
572 |
if (finishedCalled) |
|
573 |
break; |
|
574 |
if (finishedWithErrorCalled) |
|
575 |
break; |
|
576 |
if (stopWatch.elapsed() >= 30000) |
|
577 |
break; |
|
578 |
} |
|
579 |
QCOMPARE(reply->statusCode(), statusCode); |
|
580 |
delete reply; |
|
581 |
} |
|
582 |
||
583 |
#ifndef QT_NO_COMPRESS |
|
584 |
void tst_QHttpNetworkConnection::compression_data() |
|
585 |
{ |
|
586 |
QTest::addColumn<QString>("protocol"); |
|
587 |
QTest::addColumn<QString>("host"); |
|
588 |
QTest::addColumn<QString>("path"); |
|
589 |
QTest::addColumn<ushort>("port"); |
|
590 |
QTest::addColumn<bool>("encrypt"); |
|
591 |
QTest::addColumn<int>("statusCode"); |
|
592 |
QTest::addColumn<QString>("statusString"); |
|
593 |
QTest::addColumn<int>("contentLength"); |
|
594 |
QTest::addColumn<int>("downloadSize"); |
|
595 |
QTest::addColumn<bool>("autoCompress"); |
|
596 |
QTest::addColumn<QString>("contentCoding"); |
|
597 |
||
598 |
QTest::newRow("success-autogzip-temp") << "http://" << QtNetworkSettings::serverName() << "/qtest/rfcs/rfc2616.html" << ushort(80) << false << 200 << "OK" << -1 << 418321 << true << ""; |
|
599 |
QTest::newRow("success-nogzip-temp") << "http://" << QtNetworkSettings::serverName() << "/qtest/rfcs/rfc2616.html" << ushort(80) << false << 200 << "OK" << 418321 << 418321 << false << "identity"; |
|
600 |
QTest::newRow("success-manualgzip-temp") << "http://" << QtNetworkSettings::serverName() << "/qtest/deflate/rfc2616.html" << ushort(80) << false << 200 << "OK" << 119124 << 119124 << false << "gzip"; |
|
601 |
||
602 |
} |
|
603 |
||
604 |
void tst_QHttpNetworkConnection::compression() |
|
605 |
{ |
|
606 |
QFETCH(QString, protocol); |
|
607 |
QFETCH(QString, host); |
|
608 |
QFETCH(QString, path); |
|
609 |
QFETCH(ushort, port); |
|
610 |
QFETCH(bool, encrypt); |
|
611 |
QFETCH(int, statusCode); |
|
612 |
QFETCH(QString, statusString); |
|
613 |
QFETCH(int, contentLength); |
|
614 |
QFETCH(int, downloadSize); |
|
615 |
QFETCH(bool, autoCompress); |
|
616 |
QFETCH(QString, contentCoding); |
|
617 |
||
618 |
QHttpNetworkConnection connection(host); |
|
619 |
QCOMPARE(connection.port(), port); |
|
620 |
QCOMPARE(connection.hostName(), host); |
|
621 |
if (encrypt) |
|
622 |
connection.enableEncryption(); |
|
623 |
QCOMPARE(connection.isEncrypted(), encrypt); |
|
624 |
||
625 |
QHttpNetworkRequest request(protocol + host + path); |
|
626 |
if (!autoCompress) |
|
627 |
request.setHeaderField("Accept-Encoding", contentCoding.toLatin1()); |
|
628 |
QHttpNetworkReply *reply = connection.sendRequest(request); |
|
629 |
QTime stopWatch; |
|
630 |
stopWatch.start(); |
|
631 |
forever { |
|
632 |
QCoreApplication::instance()->processEvents(); |
|
633 |
if (reply->bytesAvailable()) |
|
634 |
break; |
|
635 |
if (stopWatch.elapsed() >= 30000) |
|
636 |
break; |
|
637 |
} |
|
638 |
||
639 |
QCOMPARE(reply->statusCode(), statusCode); |
|
640 |
QCOMPARE(reply->reasonPhrase(), statusString); |
|
641 |
bool isLengthOk = (reply->contentLength() == qint64(contentLength) |
|
642 |
|| reply->contentLength() == qint64(downloadSize)); |
|
643 |
||
644 |
QVERIFY(isLengthOk); |
|
645 |
||
646 |
stopWatch.start(); |
|
647 |
QByteArray ba; |
|
648 |
do { |
|
649 |
QCoreApplication::instance()->processEvents(); |
|
650 |
while (reply->bytesAvailable()) |
|
651 |
ba += reply->readAny(); |
|
652 |
if (stopWatch.elapsed() >= 30000) |
|
653 |
break; |
|
654 |
} while (!reply->isFinished()); |
|
655 |
||
656 |
QVERIFY(reply->isFinished()); |
|
657 |
QCOMPARE(ba.size(), downloadSize); |
|
658 |
||
659 |
delete reply; |
|
660 |
} |
|
661 |
#endif |
|
662 |
||
663 |
#ifndef QT_NO_OPENSSL |
|
664 |
void tst_QHttpNetworkConnection::sslErrors(const QList<QSslError> &errors) |
|
665 |
{ |
|
666 |
Q_UNUSED(errors) |
|
667 |
||
668 |
QHttpNetworkConnection *connection = qobject_cast<QHttpNetworkConnection*>(sender()); |
|
669 |
if (connection) { |
|
670 |
QVariant val = connection->property("ignoreFromSignal"); |
|
671 |
if (val.toBool()) |
|
672 |
connection->ignoreSslErrors(); |
|
673 |
finishedWithErrorCalled = true; |
|
674 |
} |
|
675 |
} |
|
676 |
||
677 |
void tst_QHttpNetworkConnection::ignoresslerror_data() |
|
678 |
{ |
|
679 |
QTest::addColumn<QString>("protocol"); |
|
680 |
QTest::addColumn<QString>("host"); |
|
681 |
QTest::addColumn<QString>("path"); |
|
682 |
QTest::addColumn<ushort>("port"); |
|
683 |
QTest::addColumn<bool>("encrypt"); |
|
684 |
QTest::addColumn<bool>("ignoreInit"); |
|
685 |
QTest::addColumn<bool>("ignoreFromSignal"); |
|
686 |
QTest::addColumn<int>("statusCode"); |
|
687 |
||
688 |
// This test will work only if the website has ssl errors. |
|
689 |
// fluke's certificate is signed by a non-standard authority. |
|
690 |
// Since we don't introduce that CA into the SSL verification chain, |
|
691 |
// connecting should fail. |
|
692 |
QTest::newRow("success-init") << "https://" << QtNetworkSettings::serverName() << "/" << ushort(443) << true << true << false << 200; |
|
693 |
QTest::newRow("success-fromSignal") << "https://" << QtNetworkSettings::serverName() << "/" << ushort(443) << true << false << true << 200; |
|
694 |
QTest::newRow("failure") << "https://" << QtNetworkSettings::serverName() << "/" << ushort(443) << true << false << false << 100; |
|
695 |
} |
|
696 |
||
697 |
void tst_QHttpNetworkConnection::ignoresslerror() |
|
698 |
{ |
|
699 |
QFETCH(QString, protocol); |
|
700 |
QFETCH(QString, host); |
|
701 |
QFETCH(QString, path); |
|
702 |
QFETCH(ushort, port); |
|
703 |
QFETCH(bool, encrypt); |
|
704 |
QFETCH(bool, ignoreInit); |
|
705 |
QFETCH(bool, ignoreFromSignal); |
|
706 |
QFETCH(int, statusCode); |
|
707 |
||
708 |
QHttpNetworkConnection connection(host, port, encrypt); |
|
709 |
QCOMPARE(connection.port(), port); |
|
710 |
QCOMPARE(connection.hostName(), host); |
|
711 |
if (encrypt) |
|
712 |
connection.enableEncryption(); |
|
713 |
if (ignoreInit) |
|
714 |
connection.ignoreSslErrors(); |
|
715 |
QCOMPARE(connection.isEncrypted(), encrypt); |
|
716 |
connect(&connection, SIGNAL(sslErrors(const QList<QSslError>&)), |
|
717 |
SLOT(sslErrors(const QList<QSslError>&))); |
|
718 |
connection.setProperty("ignoreFromSignal", ignoreFromSignal); |
|
719 |
||
720 |
QHttpNetworkRequest request(protocol + host + path); |
|
721 |
QHttpNetworkReply *reply = connection.sendRequest(request); |
|
722 |
||
723 |
finishedWithErrorCalled = false; |
|
724 |
||
725 |
connect(reply, SIGNAL(finished()), SLOT(finishedReply())); |
|
726 |
||
727 |
QTime stopWatch; |
|
728 |
stopWatch.start(); |
|
729 |
forever { |
|
730 |
QCoreApplication::instance()->processEvents(); |
|
731 |
if (reply->bytesAvailable()) |
|
732 |
break; |
|
733 |
if (statusCode == 100 && finishedWithErrorCalled) |
|
734 |
break; |
|
735 |
if (stopWatch.elapsed() >= 30000) |
|
736 |
break; |
|
737 |
} |
|
738 |
QCOMPARE(reply->statusCode(), statusCode); |
|
739 |
delete reply; |
|
740 |
} |
|
741 |
#endif |
|
742 |
||
743 |
#ifdef QT_NO_OPENSSL |
|
744 |
Q_DECLARE_METATYPE(QNetworkReply::NetworkError) |
|
745 |
void tst_QHttpNetworkConnection::nossl_data() |
|
746 |
{ |
|
747 |
QTest::addColumn<QString>("protocol"); |
|
748 |
QTest::addColumn<QString>("host"); |
|
749 |
QTest::addColumn<QString>("path"); |
|
750 |
QTest::addColumn<ushort>("port"); |
|
751 |
QTest::addColumn<bool>("encrypt"); |
|
752 |
QTest::addColumn<QNetworkReply::NetworkError>("networkError"); |
|
753 |
||
754 |
QTest::newRow("protocol-error") << "https://" << QtNetworkSettings::serverName() << "/" << ushort(443) << true <<QNetworkReply::ProtocolUnknownError; |
|
755 |
} |
|
756 |
||
757 |
void tst_QHttpNetworkConnection::nossl() |
|
758 |
{ |
|
759 |
QFETCH(QString, protocol); |
|
760 |
QFETCH(QString, host); |
|
761 |
QFETCH(QString, path); |
|
762 |
QFETCH(ushort, port); |
|
763 |
QFETCH(bool, encrypt); |
|
764 |
QFETCH(QNetworkReply::NetworkError, networkError); |
|
765 |
||
766 |
QHttpNetworkConnection connection(host, port, encrypt); |
|
767 |
QCOMPARE(connection.port(), port); |
|
768 |
QCOMPARE(connection.hostName(), host); |
|
769 |
if (encrypt) |
|
770 |
connection.enableEncryption(); |
|
771 |
||
772 |
QHttpNetworkRequest request(protocol + host + path); |
|
773 |
QHttpNetworkReply *reply = connection.sendRequest(request); |
|
774 |
||
775 |
finishedWithErrorCalled = false; |
|
776 |
netErrorCode = QNetworkReply::NoError; |
|
777 |
||
778 |
connect(reply, SIGNAL(finished()), SLOT(finishedReply())); |
|
779 |
connect(reply, SIGNAL(finishedWithError(QNetworkReply::NetworkError, const QString &)), |
|
780 |
SLOT(finishedWithError(QNetworkReply::NetworkError, const QString &))); |
|
781 |
||
782 |
QTime stopWatch; |
|
783 |
stopWatch.start(); |
|
784 |
forever { |
|
785 |
QCoreApplication::instance()->processEvents(); |
|
786 |
if (finishedWithErrorCalled) |
|
787 |
break; |
|
788 |
if (stopWatch.elapsed() >= 30000) |
|
789 |
break; |
|
790 |
} |
|
791 |
QCOMPARE(netErrorCode, networkError); |
|
792 |
delete reply; |
|
793 |
} |
|
794 |
#endif |
|
795 |
||
796 |
||
797 |
void tst_QHttpNetworkConnection::getMultiple_data() |
|
798 |
{ |
|
799 |
QTest::addColumn<quint16>("connectionCount"); |
|
800 |
QTest::addColumn<bool>("pipeliningAllowed"); |
|
801 |
// send 100 requests. apache will usually force-close after 100 requests in a single tcp connection |
|
802 |
QTest::addColumn<int>("requestCount"); |
|
803 |
||
804 |
QTest::newRow("6 connections, no pipelining, 100 requests") << quint16(6) << false << 100; |
|
805 |
QTest::newRow("1 connection, no pipelining, 100 requests") << quint16(1) << false << 100; |
|
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
806 |
QTest::newRow("6 connections, pipelining allowed, 100 requests") << quint16(6) << true << 100; |
0 | 807 |
QTest::newRow("1 connection, pipelining allowed, 100 requests") << quint16(1) << true << 100; |
808 |
} |
|
809 |
||
810 |
void tst_QHttpNetworkConnection::getMultiple() |
|
811 |
{ |
|
812 |
QFETCH(quint16, connectionCount); |
|
813 |
QFETCH(bool, pipeliningAllowed); |
|
814 |
QFETCH(int, requestCount); |
|
815 |
||
816 |
QHttpNetworkConnection connection(connectionCount, QtNetworkSettings::serverName()); |
|
817 |
||
818 |
QList<QHttpNetworkRequest*> requests; |
|
819 |
QList<QHttpNetworkReply*> replies; |
|
820 |
||
821 |
for (int i = 0; i < requestCount; i++) { |
|
822 |
// depending on what you use the results will vary. |
|
823 |
// for the "real" results, use a URL that has "internet latency" for you. Then (6 connections, pipelining) will win. |
|
824 |
// for LAN latency, you will possibly get that (1 connection, no pipelining) is the fastest |
|
825 |
QHttpNetworkRequest *request = new QHttpNetworkRequest("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt"); |
|
826 |
// located in Berlin: |
|
827 |
//QHttpNetworkRequest *request = new QHttpNetworkRequest(QUrl("http://klinsmann.nokia.trolltech.de/~berlin/qtcreatorad.gif")); |
|
828 |
if (pipeliningAllowed) |
|
829 |
request->setPipeliningAllowed(true); |
|
830 |
requests.append(request); |
|
831 |
QHttpNetworkReply *reply = connection.sendRequest(*request); |
|
832 |
replies.append(reply); |
|
833 |
} |
|
834 |
||
835 |
QTime stopWatch; |
|
836 |
stopWatch.start(); |
|
837 |
int finishedCount = 0; |
|
838 |
do { |
|
839 |
QCoreApplication::instance()->processEvents(); |
|
840 |
if (stopWatch.elapsed() >= 60000) |
|
841 |
break; |
|
842 |
||
843 |
finishedCount = 0; |
|
844 |
for (int i = 0; i < replies.length(); i++) |
|
845 |
if (replies.at(i)->isFinished()) |
|
846 |
finishedCount++; |
|
847 |
||
848 |
} while (finishedCount != replies.length()); |
|
849 |
||
850 |
// redundant |
|
851 |
for (int i = 0; i < replies.length(); i++) |
|
852 |
QVERIFY(replies.at(i)->isFinished()); |
|
853 |
||
854 |
qDebug() << "===" << stopWatch.elapsed() << "msec ==="; |
|
855 |
||
856 |
qDeleteAll(requests); |
|
857 |
qDeleteAll(replies); |
|
858 |
} |
|
859 |
||
860 |
void tst_QHttpNetworkConnection::getMultipleWithPipeliningAndMultiplePriorities() |
|
861 |
{ |
|
862 |
quint16 requestCount = 100; |
|
863 |
||
864 |
// use 2 connections. |
|
865 |
QHttpNetworkConnection connection(2, QtNetworkSettings::serverName()); |
|
866 |
||
867 |
QList<QHttpNetworkRequest*> requests; |
|
868 |
QList<QHttpNetworkReply*> replies; |
|
869 |
||
870 |
for (int i = 0; i < requestCount; i++) { |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
871 |
QHttpNetworkRequest *request = 0; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
872 |
if (i % 3) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
873 |
request = new QHttpNetworkRequest("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt", QHttpNetworkRequest::Get); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
874 |
else |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
875 |
request = new QHttpNetworkRequest("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt", QHttpNetworkRequest::Head); |
0 | 876 |
|
877 |
if (i % 2 || i % 3) |
|
878 |
request->setPipeliningAllowed(true); |
|
879 |
||
880 |
if (i % 3) |
|
881 |
request->setPriority(QHttpNetworkRequest::HighPriority); |
|
882 |
else if (i % 5) |
|
883 |
request->setPriority(QHttpNetworkRequest::NormalPriority); |
|
884 |
else if (i % 7) |
|
885 |
request->setPriority(QHttpNetworkRequest::LowPriority); |
|
886 |
||
887 |
requests.append(request); |
|
888 |
QHttpNetworkReply *reply = connection.sendRequest(*request); |
|
889 |
replies.append(reply); |
|
890 |
} |
|
891 |
||
892 |
QTime stopWatch; |
|
893 |
stopWatch.start(); |
|
894 |
int finishedCount = 0; |
|
895 |
do { |
|
896 |
QCoreApplication::instance()->processEvents(); |
|
897 |
if (stopWatch.elapsed() >= 60000) |
|
898 |
break; |
|
899 |
||
900 |
finishedCount = 0; |
|
901 |
for (int i = 0; i < replies.length(); i++) |
|
902 |
if (replies.at(i)->isFinished()) |
|
903 |
finishedCount++; |
|
904 |
||
905 |
} while (finishedCount != replies.length()); |
|
906 |
||
907 |
int pipelinedCount = 0; |
|
908 |
for (int i = 0; i < replies.length(); i++) { |
|
909 |
QVERIFY(replies.at(i)->isFinished()); |
|
910 |
QVERIFY (!(replies.at(i)->request().isPipeliningAllowed() == false |
|
911 |
&& replies.at(i)->isPipeliningUsed())); |
|
912 |
||
913 |
if (replies.at(i)->isPipeliningUsed()) |
|
914 |
pipelinedCount++; |
|
915 |
} |
|
916 |
||
917 |
// We allow pipelining for every 2nd,3rd,4th,6th,8th,9th,10th etc request. |
|
918 |
// Assume that half of the requests had been pipelined. |
|
919 |
// (this is a very relaxed condition, when last measured 79 of 100 |
|
920 |
// requests had been pipelined) |
|
921 |
QVERIFY(pipelinedCount >= requestCount / 2); |
|
922 |
||
923 |
qDebug() << "===" << stopWatch.elapsed() << "msec ==="; |
|
924 |
||
925 |
qDeleteAll(requests); |
|
926 |
qDeleteAll(replies); |
|
927 |
} |
|
928 |
||
929 |
class GetMultipleWithPrioritiesReceiver : public QObject |
|
930 |
{ |
|
931 |
Q_OBJECT |
|
932 |
public: |
|
933 |
int highPrioReceived; |
|
934 |
int lowPrioReceived; |
|
935 |
int requestCount; |
|
936 |
GetMultipleWithPrioritiesReceiver(int rq) : highPrioReceived(0), lowPrioReceived(0), requestCount(rq) { } |
|
937 |
public Q_SLOTS: |
|
938 |
void finishedSlot() { |
|
939 |
QHttpNetworkReply *reply = (QHttpNetworkReply*) sender(); |
|
940 |
if (reply->request().priority() == QHttpNetworkRequest::HighPriority) |
|
941 |
highPrioReceived++; |
|
942 |
else if (reply->request().priority() == QHttpNetworkRequest::LowPriority) |
|
943 |
lowPrioReceived++; |
|
944 |
else |
|
945 |
QFAIL("Wrong priority!?"); |
|
946 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
947 |
QVERIFY(highPrioReceived + 7 >= lowPrioReceived); |
0 | 948 |
|
949 |
if (highPrioReceived + lowPrioReceived == requestCount) |
|
950 |
QTestEventLoop::instance().exitLoop(); |
|
951 |
} |
|
952 |
}; |
|
953 |
||
954 |
void tst_QHttpNetworkConnection::getMultipleWithPriorities() |
|
955 |
{ |
|
956 |
quint16 requestCount = 100; |
|
957 |
// use 2 connections. |
|
958 |
QHttpNetworkConnection connection(2, QtNetworkSettings::serverName()); |
|
959 |
GetMultipleWithPrioritiesReceiver receiver(requestCount); |
|
960 |
QUrl url("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt"); |
|
961 |
QList<QHttpNetworkRequest*> requests; |
|
962 |
QList<QHttpNetworkReply*> replies; |
|
963 |
||
964 |
for (int i = 0; i < requestCount; i++) { |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
965 |
QHttpNetworkRequest *request = 0; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
966 |
if (i % 3) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
967 |
request = new QHttpNetworkRequest(url, QHttpNetworkRequest::Get); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
968 |
else |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
969 |
request = new QHttpNetworkRequest(url, QHttpNetworkRequest::Head); |
0 | 970 |
|
971 |
if (i % 2) |
|
972 |
request->setPriority(QHttpNetworkRequest::HighPriority); |
|
973 |
else |
|
974 |
request->setPriority(QHttpNetworkRequest::LowPriority); |
|
975 |
||
976 |
requests.append(request); |
|
977 |
QHttpNetworkReply *reply = connection.sendRequest(*request); |
|
978 |
connect(reply, SIGNAL(finished()), &receiver, SLOT(finishedSlot())); |
|
979 |
replies.append(reply); |
|
980 |
} |
|
981 |
||
982 |
QTestEventLoop::instance().enterLoop(40); |
|
983 |
QVERIFY(!QTestEventLoop::instance().timeout()); |
|
984 |
||
985 |
qDeleteAll(requests); |
|
986 |
qDeleteAll(replies); |
|
987 |
} |
|
988 |
||
989 |
||
13
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
990 |
class GetEmptyWithPipeliningReceiver : public QObject |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
991 |
{ |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
992 |
Q_OBJECT |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
993 |
public: |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
994 |
int receivedCount; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
995 |
int requestCount; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
996 |
GetEmptyWithPipeliningReceiver(int rq) : receivedCount(0),requestCount(rq) { } |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
997 |
public Q_SLOTS: |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
998 |
void finishedSlot() { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
999 |
QHttpNetworkReply *reply = (QHttpNetworkReply*) sender(); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1000 |
receivedCount++; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1001 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1002 |
if (receivedCount == requestCount) |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1003 |
QTestEventLoop::instance().exitLoop(); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1004 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1005 |
}; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1006 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1007 |
void tst_QHttpNetworkConnection::getEmptyWithPipelining() |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1008 |
{ |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1009 |
quint16 requestCount = 50; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1010 |
// use 2 connections. |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1011 |
QHttpNetworkConnection connection(2, QtNetworkSettings::serverName()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1012 |
GetEmptyWithPipeliningReceiver receiver(requestCount); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1013 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1014 |
QUrl url("http://" + QtNetworkSettings::serverName() + "/cgi-bin/echo.cgi"); // a get on this = getting an empty file |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1015 |
QList<QHttpNetworkRequest*> requests; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1016 |
QList<QHttpNetworkReply*> replies; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1017 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1018 |
for (int i = 0; i < requestCount; i++) { |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1019 |
QHttpNetworkRequest *request = 0; |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1020 |
request = new QHttpNetworkRequest(url, QHttpNetworkRequest::Get); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1021 |
request->setPipeliningAllowed(true); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1022 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1023 |
requests.append(request); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1024 |
QHttpNetworkReply *reply = connection.sendRequest(*request); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1025 |
connect(reply, SIGNAL(finished()), &receiver, SLOT(finishedSlot())); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1026 |
replies.append(reply); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1027 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1028 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1029 |
QTestEventLoop::instance().enterLoop(20); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1030 |
QVERIFY(!QTestEventLoop::instance().timeout()); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1031 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1032 |
qDeleteAll(requests); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1033 |
qDeleteAll(replies); |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1034 |
} |
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1035 |
|
c0432d11811c
eb175c3290cd7ea85da4a590db9461504a4904bc
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1036 |
|
0 | 1037 |
|
1038 |
QTEST_MAIN(tst_QHttpNetworkConnection) |
|
1039 |
#include "tst_qhttpnetworkconnection.moc" |