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