author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
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 <QtCore/QUrl> |
|
45 |
#include <QtNetwork/QNetworkRequest> |
|
46 |
#include <QtNetwork/QNetworkCookie> |
|
47 |
||
48 |
Q_DECLARE_METATYPE(QList<QByteArray>) |
|
49 |
Q_DECLARE_METATYPE(QNetworkRequest::KnownHeaders) |
|
50 |
Q_DECLARE_METATYPE(QVariant) |
|
51 |
||
52 |
class tst_QNetworkRequest: public QObject |
|
53 |
{ |
|
54 |
Q_OBJECT |
|
55 |
||
56 |
private slots: |
|
57 |
void ctor_data(); |
|
58 |
void ctor(); |
|
59 |
void setUrl_data(); |
|
60 |
void setUrl(); |
|
61 |
void setRawHeader_data(); |
|
62 |
void setRawHeader(); |
|
63 |
void rawHeaderList_data(); |
|
64 |
void rawHeaderList(); |
|
65 |
void setHeader_data(); |
|
66 |
void setHeader(); |
|
67 |
void rawHeaderParsing_data(); |
|
68 |
void rawHeaderParsing(); |
|
69 |
void originatingObject(); |
|
70 |
||
71 |
void removeHeader(); |
|
72 |
}; |
|
73 |
||
74 |
QT_BEGIN_NAMESPACE |
|
75 |
||
76 |
namespace QTest { |
|
77 |
template<> |
|
78 |
char *toString(const QNetworkCookie &cookie) |
|
79 |
{ |
|
80 |
return qstrdup(cookie.toRawForm()); |
|
81 |
} |
|
82 |
||
83 |
template<> |
|
84 |
char *toString(const QList<QNetworkCookie> &list) |
|
85 |
{ |
|
86 |
QString result = "QList("; |
|
87 |
bool first = true; |
|
88 |
foreach (QNetworkCookie cookie, list) { |
|
89 |
if (!first) |
|
90 |
result += ", "; |
|
91 |
first = false; |
|
92 |
result += QString::fromLatin1("QNetworkCookie(%1)").arg(QLatin1String(cookie.toRawForm())); |
|
93 |
} |
|
94 |
||
95 |
return qstrdup(result.append(')').toLocal8Bit()); |
|
96 |
} |
|
97 |
} |
|
98 |
||
99 |
QT_END_NAMESPACE |
|
100 |
||
101 |
void tst_QNetworkRequest::ctor_data() |
|
102 |
{ |
|
103 |
QTest::addColumn<QUrl>("url"); |
|
104 |
||
105 |
QTest::newRow("nothing") << QUrl(); |
|
106 |
QTest::newRow("empty") << QUrl(); |
|
107 |
QTest::newRow("http") << QUrl("http://qt.nokia.com"); |
|
108 |
} |
|
109 |
||
110 |
void tst_QNetworkRequest::ctor() |
|
111 |
{ |
|
112 |
QFETCH(QUrl, url); |
|
113 |
||
114 |
if (qstrcmp(QTest::currentDataTag(), "nothing") == 0) { |
|
115 |
QNetworkRequest request; |
|
116 |
QCOMPARE(request.url(), url); |
|
117 |
} else { |
|
118 |
QNetworkRequest request(url); |
|
119 |
QCOMPARE(request.url(), url); |
|
120 |
} |
|
121 |
} |
|
122 |
||
123 |
void tst_QNetworkRequest::setUrl_data() |
|
124 |
{ |
|
125 |
ctor_data(); |
|
126 |
} |
|
127 |
||
128 |
void tst_QNetworkRequest::setUrl() |
|
129 |
{ |
|
130 |
QFETCH(QUrl, url); |
|
131 |
QNetworkRequest request; |
|
132 |
||
133 |
if (qstrcmp(QTest::currentDataTag(), "nothing") != 0) |
|
134 |
request.setUrl(url); |
|
135 |
||
136 |
QCOMPARE(request.url(), url); |
|
137 |
} |
|
138 |
||
139 |
void tst_QNetworkRequest::setRawHeader_data() |
|
140 |
{ |
|
141 |
QTest::addColumn<QByteArray>("header"); |
|
142 |
QTest::addColumn<QByteArray>("value"); |
|
143 |
QTest::addColumn<QByteArray>("headerToGet"); |
|
144 |
QTest::addColumn<QByteArray>("expectedValue"); |
|
145 |
QTest::addColumn<bool>("hasHeader"); |
|
146 |
||
147 |
QTest::newRow("null-header") << QByteArray() << QByteArray("abc") |
|
148 |
<< QByteArray() << QByteArray() << false; |
|
149 |
QTest::newRow("empty-header") << QByteArray("") << QByteArray("abc") |
|
150 |
<< QByteArray("") << QByteArray() << false; |
|
151 |
QTest::newRow("null-value") << QByteArray("foo") << QByteArray() |
|
152 |
<< QByteArray("foo") << QByteArray() << false; |
|
153 |
QTest::newRow("empty-value") << QByteArray("foo") << QByteArray("") |
|
154 |
<< QByteArray("foo") << QByteArray("") << true; |
|
155 |
QTest::newRow("empty-value-vs-null") << QByteArray("foo") << QByteArray("") |
|
156 |
<< QByteArray("foo") << QByteArray() << true; |
|
157 |
||
158 |
QTest::newRow("UPPER-UPPER") << QByteArray("FOO") << QByteArray("abc") |
|
159 |
<< QByteArray("FOO") << QByteArray("abc") << true; |
|
160 |
QTest::newRow("UPPER-Mixed") << QByteArray("FOO") << QByteArray("abc") |
|
161 |
<< QByteArray("Foo") << QByteArray("abc") << true; |
|
162 |
QTest::newRow("UPPER-lower") << QByteArray("FOO") << QByteArray("abc") |
|
163 |
<< QByteArray("foo") << QByteArray("abc") << true; |
|
164 |
QTest::newRow("Mixed-UPPER") << QByteArray("Foo") << QByteArray("abc") |
|
165 |
<< QByteArray("FOO") << QByteArray("abc") << true; |
|
166 |
QTest::newRow("Mixed-Mixed") << QByteArray("Foo") << QByteArray("abc") |
|
167 |
<< QByteArray("Foo") << QByteArray("abc") << true; |
|
168 |
QTest::newRow("Mixed-lower") << QByteArray("Foo") << QByteArray("abc") |
|
169 |
<< QByteArray("foo") << QByteArray("abc") << true; |
|
170 |
QTest::newRow("lower-UPPER") << QByteArray("foo") << QByteArray("abc") |
|
171 |
<< QByteArray("FOO") << QByteArray("abc") << true; |
|
172 |
QTest::newRow("lower-Mixed") << QByteArray("foo") << QByteArray("abc") |
|
173 |
<< QByteArray("Foo") << QByteArray("abc") << true; |
|
174 |
QTest::newRow("lower-lower") << QByteArray("foo") << QByteArray("abc") |
|
175 |
<< QByteArray("foo") << QByteArray("abc") << true; |
|
176 |
} |
|
177 |
||
178 |
void tst_QNetworkRequest::setRawHeader() |
|
179 |
{ |
|
180 |
QFETCH(QByteArray, header); |
|
181 |
QFETCH(QByteArray, value); |
|
182 |
QFETCH(QByteArray, headerToGet); |
|
183 |
QFETCH(QByteArray, expectedValue); |
|
184 |
QFETCH(bool, hasHeader); |
|
185 |
||
186 |
QNetworkRequest request; |
|
187 |
request.setRawHeader(header, value); |
|
188 |
||
189 |
QCOMPARE(request.hasRawHeader(headerToGet), hasHeader); |
|
190 |
QCOMPARE(request.rawHeader(headerToGet), expectedValue); |
|
191 |
} |
|
192 |
||
193 |
void tst_QNetworkRequest::rawHeaderList_data() |
|
194 |
{ |
|
195 |
QTest::addColumn<QList<QByteArray> >("set"); |
|
196 |
QTest::addColumn<QList<QByteArray> >("expected"); |
|
197 |
||
198 |
QTest::newRow("empty") << QList<QByteArray>() << QList<QByteArray>(); |
|
199 |
||
200 |
QList<QByteArray> set; |
|
201 |
QList<QByteArray> expected; |
|
202 |
||
203 |
set << "foo"; |
|
204 |
expected = set; |
|
205 |
QTest::newRow("one") << set << expected; |
|
206 |
||
207 |
set << "bar"; |
|
208 |
expected = set; |
|
209 |
QTest::newRow("two") << set << expected; |
|
210 |
||
211 |
set.clear(); |
|
212 |
expected.clear(); |
|
213 |
set << "foo" << "foo"; |
|
214 |
expected << "foo"; |
|
215 |
QTest::newRow("repeated") << set << expected; |
|
216 |
||
217 |
set.clear(); |
|
218 |
expected.clear(); |
|
219 |
set << "foo" << "bar" << "foo"; |
|
220 |
expected << "bar" << "foo"; |
|
221 |
QTest::newRow("repeated-interleaved") << set << expected; |
|
222 |
} |
|
223 |
||
224 |
void tst_QNetworkRequest::rawHeaderList() |
|
225 |
{ |
|
226 |
QFETCH(QList<QByteArray>, set); |
|
227 |
QFETCH(QList<QByteArray>, expected); |
|
228 |
||
229 |
QNetworkRequest request; |
|
230 |
foreach (QByteArray header, set) |
|
231 |
request.setRawHeader(header, "a value"); |
|
232 |
||
233 |
QList<QByteArray> got = request.rawHeaderList(); |
|
234 |
QCOMPARE(got.size(), expected.size()); |
|
235 |
for (int i = 0; i < got.size(); ++i) |
|
236 |
QCOMPARE(got.at(i), expected.at(i)); |
|
237 |
} |
|
238 |
||
239 |
void tst_QNetworkRequest::setHeader_data() |
|
240 |
{ |
|
241 |
QTest::addColumn<QNetworkRequest::KnownHeaders>("cookedHeader"); |
|
242 |
QTest::addColumn<QVariant>("cookedValue"); |
|
243 |
QTest::addColumn<bool>("success"); |
|
244 |
QTest::addColumn<QString>("rawHeader"); |
|
245 |
QTest::addColumn<QString>("rawValue"); |
|
246 |
||
247 |
QTest::newRow("Content-Type-Null") << QNetworkRequest::ContentTypeHeader << QVariant() |
|
248 |
<< false << "Content-Type" << ""; |
|
249 |
QTest::newRow("Content-Type-String") << QNetworkRequest::ContentTypeHeader << QVariant("text/html") |
|
250 |
<< true |
|
251 |
<< "Content-Type" << "text/html"; |
|
252 |
QTest::newRow("Content-Type-ByteArray") << QNetworkRequest::ContentTypeHeader |
|
253 |
<< QVariant("text/html") << true |
|
254 |
<< "Content-Type" << "text/html"; |
|
255 |
||
256 |
QTest::newRow("Content-Length-Int") << QNetworkRequest::ContentLengthHeader << QVariant(1) |
|
257 |
<< true << "Content-Length" << "1"; |
|
258 |
QTest::newRow("Content-Length-Int64") << QNetworkRequest::ContentLengthHeader << QVariant(qint64(1)) |
|
259 |
<< true << "Content-Length" << "1"; |
|
260 |
||
261 |
QTest::newRow("Location-String") << QNetworkRequest::LocationHeader << QVariant("http://foo/with space") |
|
262 |
<< true << "Location" << "http://foo/with space"; |
|
263 |
QTest::newRow("Location-ByteArray") << QNetworkRequest::LocationHeader |
|
264 |
<< QVariant("http://foo/with space") |
|
265 |
<< true << "Location" << "http://foo/with space"; |
|
266 |
QTest::newRow("Location-Url") << QNetworkRequest::LocationHeader |
|
267 |
<< QVariant(QUrl("http://foo/with space")) |
|
268 |
<< true << "Location" << "http://foo/with%20space"; |
|
269 |
||
270 |
QTest::newRow("Last-Modified-Date") << QNetworkRequest::LastModifiedHeader |
|
271 |
<< QVariant(QDate(2007, 11, 01)) |
|
272 |
<< true << "Last-Modified" |
|
273 |
<< "Thu, 01 Nov 2007 00:00:00 GMT"; |
|
274 |
QTest::newRow("Last-Modified-DateTime") << QNetworkRequest::LastModifiedHeader |
|
275 |
<< QVariant(QDateTime(QDate(2007, 11, 01), |
|
276 |
QTime(18, 8, 30), |
|
277 |
Qt::UTC)) |
|
278 |
<< true << "Last-Modified" |
|
279 |
<< "Thu, 01 Nov 2007 18:08:30 GMT"; |
|
280 |
||
281 |
QNetworkCookie cookie; |
|
282 |
cookie.setName("a"); |
|
283 |
cookie.setValue("b"); |
|
284 |
QTest::newRow("Cookie-1") << QNetworkRequest::CookieHeader |
|
285 |
<< qVariantFromValue(QList<QNetworkCookie>() << cookie) |
|
286 |
<< true << "Cookie" |
|
287 |
<< "a=b"; |
|
288 |
QTest::newRow("SetCookie-1") << QNetworkRequest::SetCookieHeader |
|
289 |
<< qVariantFromValue(QList<QNetworkCookie>() << cookie) |
|
290 |
<< true << "Set-Cookie" |
|
291 |
<< "a=b"; |
|
292 |
||
293 |
cookie.setPath("/"); |
|
294 |
QTest::newRow("Cookie-2") << QNetworkRequest::CookieHeader |
|
295 |
<< qVariantFromValue(QList<QNetworkCookie>() << cookie) |
|
296 |
<< true << "Cookie" |
|
297 |
<< "a=b"; |
|
298 |
QTest::newRow("SetCookie-2") << QNetworkRequest::SetCookieHeader |
|
299 |
<< qVariantFromValue(QList<QNetworkCookie>() << cookie) |
|
300 |
<< true << "Set-Cookie" |
|
301 |
<< "a=b; path=/"; |
|
302 |
||
303 |
QNetworkCookie cookie2; |
|
304 |
cookie2.setName("c"); |
|
305 |
cookie2.setValue("d"); |
|
306 |
QTest::newRow("Cookie-3") << QNetworkRequest::CookieHeader |
|
307 |
<< qVariantFromValue(QList<QNetworkCookie>() << cookie << cookie2) |
|
308 |
<< true << "Cookie" |
|
309 |
<< "a=b; c=d"; |
|
310 |
QTest::newRow("SetCookie-3") << QNetworkRequest::SetCookieHeader |
|
311 |
<< qVariantFromValue(QList<QNetworkCookie>() << cookie << cookie2) |
|
312 |
<< true << "Set-Cookie" |
|
313 |
<< "a=b; path=/, c=d"; |
|
314 |
} |
|
315 |
||
316 |
void tst_QNetworkRequest::setHeader() |
|
317 |
{ |
|
318 |
QFETCH(QNetworkRequest::KnownHeaders, cookedHeader); |
|
319 |
QFETCH(QVariant, cookedValue); |
|
320 |
QFETCH(bool, success); |
|
321 |
QFETCH(QString, rawHeader); |
|
322 |
QFETCH(QString, rawValue); |
|
323 |
||
324 |
QNetworkRequest request; |
|
325 |
request.setHeader(cookedHeader, cookedValue); |
|
326 |
||
327 |
QCOMPARE(request.header(cookedHeader).isNull(), !success); |
|
328 |
QCOMPARE(request.hasRawHeader(rawHeader.toLatin1()), success); |
|
329 |
QCOMPARE(request.rawHeader(rawHeader.toLatin1()).isEmpty(), !success); |
|
330 |
||
331 |
if (success) { |
|
332 |
QCOMPARE(request.header(cookedHeader), cookedValue); |
|
333 |
QCOMPARE(QString(request.rawHeader(rawHeader.toLatin1())), rawValue); |
|
334 |
} |
|
335 |
} |
|
336 |
||
337 |
void tst_QNetworkRequest::rawHeaderParsing_data() |
|
338 |
{ |
|
339 |
QTest::addColumn<QNetworkRequest::KnownHeaders>("cookedHeader"); |
|
340 |
QTest::addColumn<QVariant>("cookedValue"); |
|
341 |
QTest::addColumn<bool>("success"); |
|
342 |
QTest::addColumn<QString>("rawHeader"); |
|
343 |
QTest::addColumn<QString>("rawValue"); |
|
344 |
||
345 |
QTest::newRow("Content-Type") << QNetworkRequest::ContentTypeHeader << QVariant("text/html") |
|
346 |
<< true |
|
347 |
<< "Content-Type" << "text/html"; |
|
348 |
QTest::newRow("Content-Length") << QNetworkRequest::ContentLengthHeader << QVariant(qint64(1)) |
|
349 |
<< true << "Content-Length" << " 1 "; |
|
350 |
QTest::newRow("Location") << QNetworkRequest::LocationHeader |
|
351 |
<< QVariant(QUrl("http://foo/with space")) |
|
352 |
<< true << "Location" << "http://foo/with%20space"; |
|
353 |
QTest::newRow("Last-Modified-RFC1123") << QNetworkRequest::LastModifiedHeader |
|
354 |
<< QVariant(QDateTime(QDate(1994, 11, 06), |
|
355 |
QTime(8, 49, 37), |
|
356 |
Qt::UTC)) |
|
357 |
<< true << "Last-Modified" |
|
358 |
<< "Sun, 06 Nov 1994 08:49:37 GMT"; |
|
359 |
QTest::newRow("Last-Modified-RFC850") << QNetworkRequest::LastModifiedHeader |
|
360 |
<< QVariant(QDateTime(QDate(1994, 11, 06), |
|
361 |
QTime(8, 49, 37), |
|
362 |
Qt::UTC)) |
|
363 |
<< true << "Last-Modified" |
|
364 |
<< "Sunday, 06-Nov-94 08:49:37 GMT"; |
|
365 |
QTest::newRow("Last-Modified-asctime") << QNetworkRequest::LastModifiedHeader |
|
366 |
<< QVariant(QDateTime(QDate(1994, 11, 06), |
|
367 |
QTime(8, 49, 37), |
|
368 |
Qt::UTC)) |
|
369 |
<< true << "Last-Modified" |
|
370 |
<< "Sun Nov 6 08:49:37 1994"; |
|
371 |
||
372 |
QTest::newRow("Content-Length-invalid1") << QNetworkRequest::ContentLengthHeader << QVariant() |
|
373 |
<< false << "Content-Length" << "1a"; |
|
374 |
QTest::newRow("Content-Length-invalid2") << QNetworkRequest::ContentLengthHeader << QVariant() |
|
375 |
<< false << "Content-Length" << "a"; |
|
376 |
||
377 |
||
378 |
QTest::newRow("Location-invalid1") << QNetworkRequest::LocationHeader << QVariant() << false |
|
379 |
<< "Location" << "abc"; |
|
380 |
QTest::newRow("Location-invalid2") << QNetworkRequest::LocationHeader << QVariant() << false |
|
381 |
<< "Location" << "1http://foo"; |
|
382 |
QTest::newRow("Location-invalid3") << QNetworkRequest::LocationHeader << QVariant() << false |
|
383 |
<< "Location" << "http://foo/%gg"; |
|
384 |
||
385 |
// don't test for invalid dates because we may want to support broken servers in the future |
|
386 |
||
387 |
QNetworkCookie cookie; |
|
388 |
cookie.setName("a"); |
|
389 |
cookie.setValue("b"); |
|
390 |
QTest::newRow("Cookie-1") << QNetworkRequest::CookieHeader |
|
391 |
<< qVariantFromValue(QList<QNetworkCookie>() << cookie) |
|
392 |
<< true << "Cookie" |
|
393 |
<< "a=b"; |
|
394 |
QTest::newRow("SetCookie-1") << QNetworkRequest::SetCookieHeader |
|
395 |
<< qVariantFromValue(QList<QNetworkCookie>() << cookie) |
|
396 |
<< true << "Set-Cookie" |
|
397 |
<< "a=b"; |
|
398 |
||
399 |
cookie.setPath("/"); |
|
400 |
QTest::newRow("SetCookie-2") << QNetworkRequest::SetCookieHeader |
|
401 |
<< qVariantFromValue(QList<QNetworkCookie>() << cookie) |
|
402 |
<< true << "Set-Cookie" |
|
403 |
<< "a=b; path=/"; |
|
404 |
||
405 |
QNetworkCookie cookie2; |
|
406 |
cookie.setPath(""); |
|
407 |
cookie2.setName("c"); |
|
408 |
cookie2.setValue("d"); |
|
409 |
QTest::newRow("Cookie-3") << QNetworkRequest::CookieHeader |
|
410 |
<< qVariantFromValue(QList<QNetworkCookie>() << cookie << cookie2) |
|
411 |
<< true << "Cookie" |
|
412 |
<< "a=b; c=d"; |
|
413 |
cookie.setPath("/"); |
|
414 |
QTest::newRow("SetCookie-3") << QNetworkRequest::SetCookieHeader |
|
415 |
<< qVariantFromValue(QList<QNetworkCookie>() << cookie << cookie2) |
|
416 |
<< true << "Set-Cookie" |
|
417 |
<< "a=b; path=/, c=d"; |
|
418 |
} |
|
419 |
||
420 |
void tst_QNetworkRequest::rawHeaderParsing() |
|
421 |
{ |
|
422 |
QFETCH(QNetworkRequest::KnownHeaders, cookedHeader); |
|
423 |
QFETCH(QVariant, cookedValue); |
|
424 |
QFETCH(bool, success); |
|
425 |
QFETCH(QString, rawHeader); |
|
426 |
QFETCH(QString, rawValue); |
|
427 |
||
428 |
QNetworkRequest request; |
|
429 |
request.setRawHeader(rawHeader.toLatin1(), rawValue.toLatin1()); |
|
430 |
||
431 |
// even if it doesn't parse, it's as a raw header |
|
432 |
QVERIFY(request.hasRawHeader(rawHeader.toLatin1())); |
|
433 |
QVERIFY(request.hasRawHeader(rawHeader.toLower().toLatin1())); |
|
434 |
QCOMPARE(QString(request.rawHeader(rawHeader.toLatin1())), rawValue); |
|
435 |
||
436 |
QCOMPARE(request.header(cookedHeader).isNull(), !success); |
|
437 |
if (cookedValue.type() != QVariant::UserType) |
|
438 |
QCOMPARE(request.header(cookedHeader), cookedValue); |
|
439 |
else if (cookedValue.userType() == qMetaTypeId<QList<QNetworkCookie> >()) |
|
440 |
QCOMPARE(qvariant_cast<QList<QNetworkCookie> >(request.header(cookedHeader)), |
|
441 |
qvariant_cast<QList<QNetworkCookie> >(cookedValue)); |
|
442 |
} |
|
443 |
||
444 |
void tst_QNetworkRequest::removeHeader() |
|
445 |
{ |
|
446 |
QNetworkRequest request; |
|
447 |
||
448 |
request.setRawHeader("Foo", "1"); |
|
449 |
QVERIFY(request.hasRawHeader("Foo")); |
|
450 |
QVERIFY(request.hasRawHeader("foo")); |
|
451 |
request.setRawHeader("Foo", QByteArray()); |
|
452 |
QVERIFY(!request.hasRawHeader("Foo")); |
|
453 |
||
454 |
// same, but remove with different capitalisation |
|
455 |
request.setRawHeader("Foo", "1"); |
|
456 |
QVERIFY(request.hasRawHeader("Foo")); |
|
457 |
QVERIFY(request.hasRawHeader("foo")); |
|
458 |
request.setRawHeader("foo", QByteArray()); |
|
459 |
QVERIFY(!request.hasRawHeader("Foo")); |
|
460 |
||
461 |
// same, but not the first |
|
462 |
request.setRawHeader("Bar", "2"); |
|
463 |
request.setRawHeader("Foo", "1"); |
|
464 |
QVERIFY(request.hasRawHeader("Foo")); |
|
465 |
QVERIFY(request.hasRawHeader("foo")); |
|
466 |
request.setRawHeader("foo", QByteArray()); |
|
467 |
QVERIFY(!request.hasRawHeader("Foo")); |
|
468 |
QVERIFY(request.hasRawHeader("bar")); |
|
469 |
||
470 |
// same, but not the first nor last |
|
471 |
request.setRawHeader("Foo", "1"); |
|
472 |
request.setRawHeader("Bar", "3"); |
|
473 |
QVERIFY(request.hasRawHeader("Foo")); |
|
474 |
QVERIFY(request.hasRawHeader("foo")); |
|
475 |
request.setRawHeader("foo", QByteArray()); |
|
476 |
QVERIFY(!request.hasRawHeader("Foo")); |
|
477 |
QVERIFY(request.hasRawHeader("bar")); |
|
478 |
} |
|
479 |
||
480 |
void tst_QNetworkRequest::originatingObject() |
|
481 |
{ |
|
482 |
QNetworkRequest request; |
|
483 |
||
484 |
QVERIFY(!request.originatingObject()); |
|
485 |
||
486 |
{ |
|
487 |
QObject dummy; |
|
488 |
request.setOriginatingObject(&dummy); |
|
489 |
QCOMPARE(request.originatingObject(), &dummy); |
|
490 |
} |
|
491 |
||
492 |
QVERIFY(!request.originatingObject()); |
|
493 |
} |
|
494 |
||
495 |
QTEST_MAIN(tst_QNetworkRequest) |
|
496 |
#include "tst_qnetworkrequest.moc" |