author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
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 <qabstractnetworkcache.h> |
|
45 |
||
46 |
#define EXAMPLE_URL "http://user:pass@www.example.com/#foo" |
|
47 |
||
48 |
class tst_QNetworkCacheMetaData : public QObject |
|
49 |
{ |
|
50 |
Q_OBJECT |
|
51 |
||
52 |
public slots: |
|
53 |
void initTestCase(); |
|
54 |
void cleanupTestCase(); |
|
55 |
void init(); |
|
56 |
void cleanup(); |
|
57 |
||
58 |
private slots: |
|
59 |
void qnetworkcachemetadata_data(); |
|
60 |
void qnetworkcachemetadata(); |
|
61 |
||
62 |
void expirationDate_data(); |
|
63 |
void expirationDate(); |
|
64 |
void isValid_data(); |
|
65 |
void isValid(); |
|
66 |
void lastModified_data(); |
|
67 |
void lastModified(); |
|
68 |
void operatorEqual_data(); |
|
69 |
void operatorEqual(); |
|
70 |
void operatorEqualEqual_data(); |
|
71 |
void operatorEqualEqual(); |
|
72 |
void rawHeaders_data(); |
|
73 |
void rawHeaders(); |
|
74 |
void saveToDisk_data(); |
|
75 |
void saveToDisk(); |
|
76 |
void url_data(); |
|
77 |
void url(); |
|
78 |
||
79 |
void stream(); |
|
80 |
}; |
|
81 |
||
82 |
// Subclass that exposes the protected functions. |
|
83 |
class SubQNetworkCacheMetaData : public QNetworkCacheMetaData |
|
84 |
{ |
|
85 |
public:}; |
|
86 |
||
87 |
// This will be called before the first test function is executed. |
|
88 |
// It is only called once. |
|
89 |
void tst_QNetworkCacheMetaData::initTestCase() |
|
90 |
{ |
|
91 |
} |
|
92 |
||
93 |
// This will be called after the last test function is executed. |
|
94 |
// It is only called once. |
|
95 |
void tst_QNetworkCacheMetaData::cleanupTestCase() |
|
96 |
{ |
|
97 |
} |
|
98 |
||
99 |
// This will be called before each test function is executed. |
|
100 |
void tst_QNetworkCacheMetaData::init() |
|
101 |
{ |
|
102 |
} |
|
103 |
||
104 |
// This will be called after every test function. |
|
105 |
void tst_QNetworkCacheMetaData::cleanup() |
|
106 |
{ |
|
107 |
} |
|
108 |
||
109 |
void tst_QNetworkCacheMetaData::qnetworkcachemetadata_data() |
|
110 |
{ |
|
111 |
} |
|
112 |
||
113 |
void tst_QNetworkCacheMetaData::qnetworkcachemetadata() |
|
114 |
{ |
|
115 |
QNetworkCacheMetaData data; |
|
116 |
QCOMPARE(data.expirationDate(), QDateTime()); |
|
117 |
QCOMPARE(data.isValid(), false); |
|
118 |
QCOMPARE(data.lastModified(), QDateTime()); |
|
119 |
QCOMPARE(data.operator!=(QNetworkCacheMetaData()), false); |
|
120 |
QNetworkCacheMetaData metaData; |
|
121 |
QCOMPARE(data.operator=(metaData), QNetworkCacheMetaData()); |
|
122 |
QCOMPARE(data.operator==(QNetworkCacheMetaData()), true); |
|
123 |
QCOMPARE(data.rawHeaders(), QNetworkCacheMetaData::RawHeaderList()); |
|
124 |
QCOMPARE(data.saveToDisk(), true); |
|
125 |
QCOMPARE(data.url(), QUrl()); |
|
126 |
data.setExpirationDate(QDateTime()); |
|
127 |
data.setLastModified(QDateTime()); |
|
128 |
data.setRawHeaders(QNetworkCacheMetaData::RawHeaderList()); |
|
129 |
data.setSaveToDisk(false); |
|
130 |
data.setUrl(QUrl()); |
|
131 |
} |
|
132 |
||
133 |
void tst_QNetworkCacheMetaData::expirationDate_data() |
|
134 |
{ |
|
135 |
QTest::addColumn<QDateTime>("expirationDate"); |
|
136 |
QTest::newRow("null") << QDateTime(); |
|
137 |
QTest::newRow("now") << QDateTime::currentDateTime(); |
|
138 |
} |
|
139 |
||
140 |
// public QDateTime expirationDate() const |
|
141 |
void tst_QNetworkCacheMetaData::expirationDate() |
|
142 |
{ |
|
143 |
QFETCH(QDateTime, expirationDate); |
|
144 |
||
145 |
SubQNetworkCacheMetaData data; |
|
146 |
||
147 |
data.setExpirationDate(expirationDate); |
|
148 |
QCOMPARE(data.expirationDate(), expirationDate); |
|
149 |
} |
|
150 |
||
151 |
Q_DECLARE_METATYPE(QNetworkCacheMetaData) |
|
152 |
void tst_QNetworkCacheMetaData::isValid_data() |
|
153 |
{ |
|
154 |
QTest::addColumn<QNetworkCacheMetaData>("data"); |
|
155 |
QTest::addColumn<bool>("isValid"); |
|
156 |
||
157 |
QNetworkCacheMetaData metaData; |
|
158 |
QTest::newRow("null") << metaData << false; |
|
159 |
||
160 |
QNetworkCacheMetaData data1; |
|
161 |
data1.setUrl(QUrl(EXAMPLE_URL)); |
|
162 |
QTest::newRow("valid-1") << data1 << true; |
|
163 |
||
164 |
QNetworkCacheMetaData data2; |
|
165 |
QNetworkCacheMetaData::RawHeaderList headers; |
|
166 |
headers.append(QNetworkCacheMetaData::RawHeader("foo", "Bar")); |
|
167 |
data2.setRawHeaders(headers); |
|
168 |
QTest::newRow("valid-2") << data2 << true; |
|
169 |
||
170 |
QNetworkCacheMetaData data3; |
|
171 |
data3.setLastModified(QDateTime::currentDateTime()); |
|
172 |
QTest::newRow("valid-3") << data3 << true; |
|
173 |
||
174 |
QNetworkCacheMetaData data4; |
|
175 |
data4.setExpirationDate(QDateTime::currentDateTime()); |
|
176 |
QTest::newRow("valid-4") << data4 << true; |
|
177 |
||
178 |
QNetworkCacheMetaData data5; |
|
179 |
data5.setSaveToDisk(false); |
|
180 |
QTest::newRow("valid-5") << data5 << true; |
|
181 |
} |
|
182 |
||
183 |
// public bool isValid() const |
|
184 |
void tst_QNetworkCacheMetaData::isValid() |
|
185 |
{ |
|
186 |
QFETCH(QNetworkCacheMetaData, data); |
|
187 |
QFETCH(bool, isValid); |
|
188 |
||
189 |
QCOMPARE(data.isValid(), isValid); |
|
190 |
} |
|
191 |
||
192 |
void tst_QNetworkCacheMetaData::lastModified_data() |
|
193 |
{ |
|
194 |
QTest::addColumn<QDateTime>("lastModified"); |
|
195 |
QTest::newRow("null") << QDateTime(); |
|
196 |
QTest::newRow("now") << QDateTime::currentDateTime(); |
|
197 |
} |
|
198 |
||
199 |
// public QDateTime lastModified() const |
|
200 |
void tst_QNetworkCacheMetaData::lastModified() |
|
201 |
{ |
|
202 |
QFETCH(QDateTime, lastModified); |
|
203 |
||
204 |
SubQNetworkCacheMetaData data; |
|
205 |
||
206 |
data.setLastModified(lastModified); |
|
207 |
QCOMPARE(data.lastModified(), lastModified); |
|
208 |
} |
|
209 |
||
210 |
void tst_QNetworkCacheMetaData::operatorEqual_data() |
|
211 |
{ |
|
212 |
QTest::addColumn<QNetworkCacheMetaData>("other"); |
|
213 |
QTest::newRow("null") << QNetworkCacheMetaData(); |
|
214 |
||
215 |
QNetworkCacheMetaData data; |
|
216 |
data.setUrl(QUrl(EXAMPLE_URL)); |
|
217 |
QNetworkCacheMetaData::RawHeaderList headers; |
|
218 |
headers.append(QNetworkCacheMetaData::RawHeader("foo", "Bar")); |
|
219 |
data.setRawHeaders(headers); |
|
220 |
data.setLastModified(QDateTime::currentDateTime()); |
|
221 |
data.setExpirationDate(QDateTime::currentDateTime()); |
|
222 |
data.setSaveToDisk(false); |
|
223 |
QTest::newRow("valid") << data; |
|
224 |
} |
|
225 |
||
226 |
// public QNetworkCacheMetaData& operator=(QNetworkCacheMetaData const& other) |
|
227 |
void tst_QNetworkCacheMetaData::operatorEqual() |
|
228 |
{ |
|
229 |
QFETCH(QNetworkCacheMetaData, other); |
|
230 |
||
231 |
QNetworkCacheMetaData data = other; |
|
232 |
||
233 |
QCOMPARE(data, other); |
|
234 |
} |
|
235 |
||
236 |
void tst_QNetworkCacheMetaData::operatorEqualEqual_data() |
|
237 |
{ |
|
238 |
QTest::addColumn<QNetworkCacheMetaData>("a"); |
|
239 |
QTest::addColumn<QNetworkCacheMetaData>("b"); |
|
240 |
QTest::addColumn<bool>("operatorEqualEqual"); |
|
241 |
QTest::newRow("null") << QNetworkCacheMetaData() << QNetworkCacheMetaData() << true; |
|
242 |
||
243 |
QNetworkCacheMetaData data1; |
|
244 |
data1.setUrl(QUrl(EXAMPLE_URL)); |
|
245 |
QTest::newRow("valid-1-1") << data1 << QNetworkCacheMetaData() << false; |
|
246 |
QTest::newRow("valid-1-2") << data1 << data1 << true; |
|
247 |
||
248 |
QNetworkCacheMetaData data2; |
|
249 |
QNetworkCacheMetaData::RawHeaderList headers; |
|
250 |
headers.append(QNetworkCacheMetaData::RawHeader("foo", "Bar")); |
|
251 |
data2.setRawHeaders(headers); |
|
252 |
QTest::newRow("valid-2-1") << data2 << QNetworkCacheMetaData() << false; |
|
253 |
QTest::newRow("valid-2-2") << data2 << data2 << true; |
|
254 |
QTest::newRow("valid-2-3") << data2 << data1 << false; |
|
255 |
||
256 |
QNetworkCacheMetaData data3; |
|
257 |
data3.setLastModified(QDateTime::currentDateTime()); |
|
258 |
QTest::newRow("valid-3-1") << data3 << QNetworkCacheMetaData() << false; |
|
259 |
QTest::newRow("valid-3-2") << data3 << data3 << true; |
|
260 |
QTest::newRow("valid-3-3") << data3 << data1 << false; |
|
261 |
QTest::newRow("valid-3-4") << data3 << data2 << false; |
|
262 |
||
263 |
QNetworkCacheMetaData data4; |
|
264 |
data4.setExpirationDate(QDateTime::currentDateTime()); |
|
265 |
QTest::newRow("valid-4-1") << data4 << QNetworkCacheMetaData() << false; |
|
266 |
QTest::newRow("valid-4-2") << data4 << data4 << true; |
|
267 |
QTest::newRow("valid-4-3") << data4 << data1 << false; |
|
268 |
QTest::newRow("valid-4-4") << data4 << data2 << false; |
|
269 |
QTest::newRow("valid-4-5") << data4 << data3 << false; |
|
270 |
||
271 |
QNetworkCacheMetaData data5; |
|
272 |
data5.setSaveToDisk(false); |
|
273 |
QTest::newRow("valid-5-1") << data5 << QNetworkCacheMetaData() << false; |
|
274 |
QTest::newRow("valid-5-2") << data5 << data5 << true; |
|
275 |
QTest::newRow("valid-5-3") << data5 << data1 << false; |
|
276 |
QTest::newRow("valid-5-4") << data5 << data2 << false; |
|
277 |
QTest::newRow("valid-5-5") << data5 << data3 << false; |
|
278 |
QTest::newRow("valid-5-6") << data5 << data4 << false; |
|
279 |
} |
|
280 |
||
281 |
// public bool operator==(QNetworkCacheMetaData const& other) const |
|
282 |
void tst_QNetworkCacheMetaData::operatorEqualEqual() |
|
283 |
{ |
|
284 |
QFETCH(QNetworkCacheMetaData, a); |
|
285 |
QFETCH(QNetworkCacheMetaData, b); |
|
286 |
QFETCH(bool, operatorEqualEqual); |
|
287 |
||
288 |
QCOMPARE(a == b, operatorEqualEqual); |
|
289 |
} |
|
290 |
||
291 |
Q_DECLARE_METATYPE(QNetworkCacheMetaData::RawHeaderList) |
|
292 |
void tst_QNetworkCacheMetaData::rawHeaders_data() |
|
293 |
{ |
|
294 |
QTest::addColumn<QNetworkCacheMetaData::RawHeaderList>("rawHeaders"); |
|
295 |
QTest::newRow("null") << QNetworkCacheMetaData::RawHeaderList(); |
|
296 |
QNetworkCacheMetaData::RawHeaderList headers; |
|
297 |
headers.append(QNetworkCacheMetaData::RawHeader("foo", "Bar")); |
|
298 |
QTest::newRow("valie") << headers; |
|
299 |
} |
|
300 |
||
301 |
// public QNetworkCacheMetaData::RawHeaderList rawHeaders() const |
|
302 |
void tst_QNetworkCacheMetaData::rawHeaders() |
|
303 |
{ |
|
304 |
QFETCH(QNetworkCacheMetaData::RawHeaderList, rawHeaders); |
|
305 |
||
306 |
SubQNetworkCacheMetaData data; |
|
307 |
||
308 |
data.setRawHeaders(rawHeaders); |
|
309 |
QCOMPARE(data.rawHeaders(), rawHeaders); |
|
310 |
} |
|
311 |
||
312 |
void tst_QNetworkCacheMetaData::saveToDisk_data() |
|
313 |
{ |
|
314 |
QTest::addColumn<bool>("saveToDisk"); |
|
315 |
QTest::newRow("false") << false; |
|
316 |
QTest::newRow("true") << true; |
|
317 |
} |
|
318 |
||
319 |
// public bool saveToDisk() const |
|
320 |
void tst_QNetworkCacheMetaData::saveToDisk() |
|
321 |
{ |
|
322 |
QFETCH(bool, saveToDisk); |
|
323 |
||
324 |
SubQNetworkCacheMetaData data; |
|
325 |
||
326 |
data.setSaveToDisk(saveToDisk); |
|
327 |
QCOMPARE(data.saveToDisk(), saveToDisk); |
|
328 |
} |
|
329 |
||
330 |
void tst_QNetworkCacheMetaData::url_data() |
|
331 |
{ |
|
332 |
QTest::addColumn<QUrl>("url"); |
|
333 |
QTest::addColumn<QUrl>("expected"); |
|
334 |
QTest::newRow("null") << QUrl() << QUrl(); |
|
335 |
QTest::newRow("valid") << QUrl(EXAMPLE_URL) << QUrl("http://user@www.example.com/"); |
|
336 |
} |
|
337 |
||
338 |
// public QUrl url() const |
|
339 |
void tst_QNetworkCacheMetaData::url() |
|
340 |
{ |
|
341 |
QFETCH(QUrl, url); |
|
342 |
QFETCH(QUrl, expected); |
|
343 |
||
344 |
SubQNetworkCacheMetaData data; |
|
345 |
data.setUrl(url); |
|
346 |
QCOMPARE(data.url(), expected); |
|
347 |
} |
|
348 |
||
349 |
void tst_QNetworkCacheMetaData::stream() |
|
350 |
{ |
|
351 |
QNetworkCacheMetaData data; |
|
352 |
data.setUrl(QUrl(EXAMPLE_URL)); |
|
353 |
QNetworkCacheMetaData::RawHeaderList headers; |
|
354 |
headers.append(QNetworkCacheMetaData::RawHeader("foo", "Bar")); |
|
355 |
data.setRawHeaders(headers); |
|
356 |
data.setLastModified(QDateTime::currentDateTime()); |
|
357 |
data.setExpirationDate(QDateTime::currentDateTime()); |
|
358 |
data.setSaveToDisk(false); |
|
359 |
||
360 |
QBuffer buffer; |
|
361 |
buffer.open(QIODevice::ReadWrite); |
|
362 |
QDataStream stream(&buffer); |
|
363 |
stream << data; |
|
364 |
||
365 |
buffer.seek(0); |
|
366 |
QNetworkCacheMetaData data2; |
|
367 |
stream >> data2; |
|
368 |
QCOMPARE(data2, data); |
|
369 |
} |
|
370 |
||
371 |
QTEST_MAIN(tst_QNetworkCacheMetaData) |
|
372 |
#include "tst_qnetworkcachemetadata.moc" |
|
373 |