|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
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/QDebug> |
|
45 |
|
46 #include <qcoreapplication.h> |
|
47 |
|
48 #include <qfileinfo.h> |
|
49 #include <qurl.h> |
|
50 #include <qtextcodec.h> |
|
51 #include <qmap.h> |
|
52 |
|
53 // For testsuites |
|
54 #define IDNA_ACE_PREFIX "xn--" |
|
55 #define IDNA_SUCCESS 1 |
|
56 #define STRINGPREP_NO_UNASSIGNED 1 |
|
57 #define STRINGPREP_CONTAINS_UNASSIGNED 2 |
|
58 #define STRINGPREP_CONTAINS_PROHIBITED 3 |
|
59 #define STRINGPREP_BIDI_BOTH_L_AND_RAL 4 |
|
60 #define STRINGPREP_BIDI_LEADTRAIL_NOT_RAL 5 |
|
61 |
|
62 struct ushortarray { |
|
63 ushortarray(unsigned short *array = 0) |
|
64 { |
|
65 if (array) |
|
66 memcpy(points, array, sizeof(points)); |
|
67 } |
|
68 |
|
69 unsigned short points[100]; |
|
70 }; |
|
71 |
|
72 Q_DECLARE_METATYPE(ushortarray) |
|
73 Q_DECLARE_METATYPE(QUrl::FormattingOptions) |
|
74 |
|
75 //TESTED_CLASS= |
|
76 //TESTED_FILES= |
|
77 |
|
78 class tst_QUrl : public QObject |
|
79 { |
|
80 Q_OBJECT |
|
81 |
|
82 public: |
|
83 tst_QUrl(); |
|
84 virtual ~tst_QUrl(); |
|
85 |
|
86 |
|
87 public slots: |
|
88 void init(); |
|
89 void cleanup(); |
|
90 private slots: |
|
91 void getSetCheck(); |
|
92 void constructing(); |
|
93 void assignment(); |
|
94 void comparison(); |
|
95 void copying(); |
|
96 void setUrl(); |
|
97 void i18n_data(); |
|
98 void i18n(); |
|
99 void punycode_data(); |
|
100 void punycode(); |
|
101 void resolving_data(); |
|
102 void resolving(); |
|
103 void toString_data(); |
|
104 void toString(); |
|
105 void toString_constructed_data(); |
|
106 void toString_constructed(); |
|
107 void isParentOf_data(); |
|
108 void isParentOf(); |
|
109 void toLocalFile_data(); |
|
110 void toLocalFile(); |
|
111 void fromLocalFile_data(); |
|
112 void fromLocalFile(); |
|
113 void relative(); |
|
114 void compat_legacy(); |
|
115 void compat_constructor_01_data(); |
|
116 void compat_constructor_01(); |
|
117 void compat_constructor_02_data(); |
|
118 void compat_constructor_02(); |
|
119 void compat_constructor_03_data(); |
|
120 void compat_constructor_03(); |
|
121 void compat_isValid_01_data(); |
|
122 void compat_isValid_01(); |
|
123 void compat_isValid_02_data(); |
|
124 void compat_isValid_02(); |
|
125 void compat_path_data(); |
|
126 void compat_path(); |
|
127 void compat_fileName_data(); |
|
128 void compat_fileName(); |
|
129 void compat_decode_data(); |
|
130 void compat_decode(); |
|
131 void compat_encode_data(); |
|
132 void compat_encode(); |
|
133 void percentEncoding_data(); |
|
134 void percentEncoding(); |
|
135 void symmetry(); |
|
136 void ipv6_data(); |
|
137 void ipv6(); |
|
138 void ipv6_2_data(); |
|
139 void ipv6_2(); |
|
140 void moreIpv6(); |
|
141 void toPercentEncoding_data(); |
|
142 void toPercentEncoding(); |
|
143 void isRelative_data(); |
|
144 void isRelative(); |
|
145 void queryItems(); |
|
146 void hasQuery_data(); |
|
147 void hasQuery(); |
|
148 void hasQueryItem_data(); |
|
149 void hasQueryItem(); |
|
150 void nameprep(); |
|
151 void isValid(); |
|
152 void schemeValidator_data(); |
|
153 void schemeValidator(); |
|
154 void invalidSchemeValidator(); |
|
155 void tolerantParser(); |
|
156 void correctEncodedMistakes_data(); |
|
157 void correctEncodedMistakes(); |
|
158 void correctDecodedMistakes_data(); |
|
159 void correctDecodedMistakes(); |
|
160 void idna_testsuite_data(); |
|
161 void idna_testsuite(); |
|
162 void nameprep_testsuite_data(); |
|
163 void nameprep_testsuite(); |
|
164 void ace_testsuite_data(); |
|
165 void ace_testsuite(); |
|
166 void std3violations_data(); |
|
167 void std3violations(); |
|
168 void tldRestrictions_data(); |
|
169 void tldRestrictions(); |
|
170 void emptyQueryOrFragment(); |
|
171 void hasFragment_data(); |
|
172 void hasFragment(); |
|
173 void setEncodedFragment_data(); |
|
174 void setEncodedFragment(); |
|
175 void fromEncoded(); |
|
176 void stripTrailingSlash(); |
|
177 void hosts_data(); |
|
178 void hosts(); |
|
179 void setPort(); |
|
180 void toEncoded_data(); |
|
181 void toEncoded(); |
|
182 void setAuthority_data(); |
|
183 void setAuthority(); |
|
184 void errorString(); |
|
185 void clear(); |
|
186 void resolvedWithAbsoluteSchemes() const; |
|
187 void resolvedWithAbsoluteSchemes_data() const; |
|
188 void binaryData_data(); |
|
189 void binaryData(); |
|
190 void fromUserInput_data(); |
|
191 void fromUserInput(); |
|
192 void task_199967(); |
|
193 void task_240612(); |
|
194 |
|
195 #ifdef QT3_SUPPORT |
|
196 void dirPath(); |
|
197 #endif |
|
198 }; |
|
199 |
|
200 // Testing get/set functions |
|
201 void tst_QUrl::getSetCheck() |
|
202 { |
|
203 QUrl obj1; |
|
204 // int QUrl::port() |
|
205 // void QUrl::setPort(int) |
|
206 obj1.setPort(0); |
|
207 QCOMPARE(0, obj1.port()); |
|
208 |
|
209 QTest::ignoreMessage(QtWarningMsg, "QUrl::setPort: Out of range"); |
|
210 obj1.setPort(INT_MIN); |
|
211 QCOMPARE(-1, obj1.port()); // Out of range, -1 |
|
212 |
|
213 QTest::ignoreMessage(QtWarningMsg, "QUrl::setPort: Out of range"); |
|
214 obj1.setPort(INT_MAX); |
|
215 QCOMPARE(-1, obj1.port()); // Out of range, -1 |
|
216 |
|
217 obj1.setPort(1234); |
|
218 QCOMPARE(1234, obj1.port()); |
|
219 |
|
220 // static QStringList QUrl::idnWhitelist() |
|
221 // static void QUrl::setIdnWhitelist(QStringList) |
|
222 QStringList original = QUrl::idnWhitelist(); // save for later |
|
223 |
|
224 QUrl::setIdnWhitelist(QStringList()); |
|
225 QCOMPARE(QUrl::idnWhitelist(), QStringList()); |
|
226 |
|
227 QStringList norway; norway << "no"; |
|
228 QUrl::setIdnWhitelist(norway); |
|
229 QCOMPARE(QUrl::idnWhitelist(), norway); |
|
230 |
|
231 QStringList modified = original; |
|
232 modified << "foo"; |
|
233 QUrl::setIdnWhitelist(modified); |
|
234 QCOMPARE(QUrl::idnWhitelist(), modified); |
|
235 |
|
236 // reset to the original |
|
237 QUrl::setIdnWhitelist(original); |
|
238 QCOMPARE(QUrl::idnWhitelist(), original); |
|
239 } |
|
240 |
|
241 tst_QUrl::tst_QUrl() |
|
242 { |
|
243 } |
|
244 |
|
245 tst_QUrl::~tst_QUrl() |
|
246 { |
|
247 |
|
248 } |
|
249 |
|
250 void tst_QUrl::init() |
|
251 { |
|
252 } |
|
253 |
|
254 void tst_QUrl::cleanup() |
|
255 { |
|
256 } |
|
257 |
|
258 void tst_QUrl::constructing() |
|
259 { |
|
260 QUrl url; |
|
261 QVERIFY(!url.isValid()); |
|
262 QVERIFY(url.isEmpty()); |
|
263 QCOMPARE(url.port(), -1); |
|
264 QCOMPARE(url.toString(), QString()); |
|
265 |
|
266 QList<QPair<QString, QString> > query; |
|
267 query += qMakePair(QString("type"), QString("login")); |
|
268 query += qMakePair(QString("name"), QString("åge nissemannsen")); |
|
269 query += qMakePair(QString("ole&du"), QString("anne+jørgen=sant")); |
|
270 query += qMakePair(QString("prosent"), QString("%")); |
|
271 url.setQueryItems(query); |
|
272 QVERIFY(!url.isEmpty()); |
|
273 |
|
274 QCOMPARE(url.encodedQuery().constData(), |
|
275 QByteArray("type=login&name=%C3%A5ge%20nissemannsen&ole%26du=" |
|
276 "anne+j%C3%B8rgen%3Dsant&prosent=%25").constData()); |
|
277 |
|
278 url.setQueryDelimiters('>', '/'); |
|
279 url.setQueryItems(query); |
|
280 |
|
281 QCOMPARE(url.encodedQuery(), |
|
282 QByteArray("type>login/name>%C3%A5ge%20nissemannsen/ole&du>" |
|
283 "anne+j%C3%B8rgen=sant/prosent>%25")); |
|
284 |
|
285 url.setFragment(QString::fromLatin1("top")); |
|
286 QCOMPARE(url.fragment(), QString::fromLatin1("top")); |
|
287 |
|
288 url.setScheme("http"); |
|
289 url.setHost("qt.nokia.com"); |
|
290 |
|
291 QCOMPARE(url.toString(), |
|
292 QString::fromLatin1("http://qt.nokia.com?type>login/name>åge nissemannsen" |
|
293 "/ole&du>anne+jørgen=sant/prosent>%#top")); |
|
294 |
|
295 QUrl justHost("qt.nokia.com"); |
|
296 QVERIFY(!justHost.isEmpty()); |
|
297 QVERIFY(justHost.host().isEmpty()); |
|
298 QCOMPARE(justHost.path(), QString::fromLatin1("qt.nokia.com")); |
|
299 |
|
300 QUrl hostWithSlashes("//qt.nokia.com"); |
|
301 QVERIFY(hostWithSlashes.path().isEmpty()); |
|
302 QCOMPARE(hostWithSlashes.host(), QString::fromLatin1("qt.nokia.com")); |
|
303 |
|
304 |
|
305 QUrl withHashInPath; |
|
306 withHashInPath.setPath(QString::fromLatin1("hi#mum.txt")); |
|
307 QCOMPARE(withHashInPath.path(), QString::fromLatin1("hi#mum.txt")); |
|
308 QCOMPARE(withHashInPath.toEncoded(), QByteArray("hi%23mum.txt")); |
|
309 QUrl fromHashInPath = QUrl::fromEncoded(withHashInPath.toEncoded()); |
|
310 QVERIFY(withHashInPath == fromHashInPath); |
|
311 |
|
312 |
|
313 QUrl buildUNC; |
|
314 buildUNC.setHost(QString::fromLatin1("somehost")); |
|
315 buildUNC.setPath(QString::fromLatin1("somepath")); |
|
316 QCOMPARE(buildUNC.toLocalFile(), QString::fromLatin1("//somehost/somepath")); |
|
317 buildUNC.toEncoded(); |
|
318 QVERIFY(!buildUNC.isEmpty()); |
|
319 } |
|
320 |
|
321 void tst_QUrl::assignment() |
|
322 { |
|
323 QUrl url("http://qt.nokia.com/"); |
|
324 QVERIFY(url.isValid()); |
|
325 |
|
326 QUrl copy; |
|
327 copy = url; |
|
328 |
|
329 QVERIFY(url == copy); |
|
330 } |
|
331 |
|
332 void tst_QUrl::comparison() |
|
333 { |
|
334 QUrl url1("http://qt.nokia.com/"); |
|
335 QVERIFY(url1.isValid()); |
|
336 |
|
337 QUrl url2("http://qt.nokia.com/"); |
|
338 QVERIFY(url2.isValid()); |
|
339 |
|
340 QVERIFY(url1 == url2); |
|
341 |
|
342 // 6.2.2 Syntax-based Normalization |
|
343 QUrl url3 = QUrl::fromEncoded("example://a/b/c/%7Bfoo%7D"); |
|
344 QUrl url4 = QUrl::fromEncoded("eXAMPLE://a/./b/../b/%63/%7bfoo%7d"); |
|
345 QVERIFY(url3 == url4); |
|
346 |
|
347 // 6.2.2.1 Make sure hexdecimal characters in percent encoding are |
|
348 // treated case-insensitively |
|
349 QUrl url5; |
|
350 url5.setEncodedQuery("a=%2a"); |
|
351 QUrl url6; |
|
352 url6.setEncodedQuery("a=%2A"); |
|
353 QVERIFY(url5 == url6); |
|
354 |
|
355 // ensure that encoded characters in the query do not match |
|
356 QUrl url7; |
|
357 url7.setEncodedQuery("a=%63"); |
|
358 QUrl url8; |
|
359 url8.setEncodedQuery("a=c"); |
|
360 QVERIFY(url7 != url8); |
|
361 } |
|
362 |
|
363 void tst_QUrl::copying() |
|
364 { |
|
365 QUrl url("http://qt.nokia.com/"); |
|
366 QVERIFY(url.isValid()); |
|
367 |
|
368 QUrl copy(url); |
|
369 |
|
370 QVERIFY(url == copy); |
|
371 } |
|
372 |
|
373 void tst_QUrl::setUrl() |
|
374 { |
|
375 { |
|
376 QUrl url("http://0.foo.com"); |
|
377 QVERIFY(url.isValid()); |
|
378 QCOMPARE(url.scheme(), QString::fromLatin1("http")); |
|
379 QCOMPARE(url.path(), QString()); |
|
380 QCOMPARE(url.host(), QString::fromLatin1("0.foo.com")); |
|
381 } |
|
382 |
|
383 { |
|
384 QUrl url("file:/"); |
|
385 QVERIFY(url.isValid()); |
|
386 QCOMPARE(url.scheme(), QString::fromLatin1("file")); |
|
387 QCOMPARE(url.path(), QString::fromLatin1("/")); |
|
388 QVERIFY(url.encodedQuery().isEmpty()); |
|
389 QVERIFY(url.userInfo().isEmpty()); |
|
390 QVERIFY(url.authority().isEmpty()); |
|
391 QVERIFY(url.fragment().isEmpty()); |
|
392 QCOMPARE(url.port(), -1); |
|
393 } |
|
394 |
|
395 { |
|
396 QUrl url("hTTp://www.foo.bar:80"); |
|
397 QVERIFY(url.isValid()); |
|
398 QCOMPARE(url.scheme(), QString::fromLatin1("hTTp")); |
|
399 QCOMPARE(url.path(), QString()); |
|
400 QVERIFY(url.encodedQuery().isEmpty()); |
|
401 QVERIFY(url.userInfo().isEmpty()); |
|
402 QVERIFY(url.fragment().isEmpty()); |
|
403 QCOMPARE(url.host(), QString::fromLatin1("www.foo.bar")); |
|
404 QCOMPARE(url.authority(), QString::fromLatin1("www.foo.bar:80")); |
|
405 QCOMPARE(url.port(), 80); |
|
406 |
|
407 QUrl url2("//www1.foo.bar"); |
|
408 QCOMPARE(url.resolved(url2).toString(), QString::fromLatin1("hTTp://www1.foo.bar")); |
|
409 } |
|
410 |
|
411 { |
|
412 QUrl url("http://user:pass@[56::56:56:56:127.0.0.1]:99"); |
|
413 QVERIFY(url.isValid()); |
|
414 QCOMPARE(url.scheme(), QString::fromLatin1("http")); |
|
415 QCOMPARE(url.path(), QString()); |
|
416 QVERIFY(url.encodedQuery().isEmpty()); |
|
417 QCOMPARE(url.userInfo(), QString::fromLatin1("user:pass")); |
|
418 QVERIFY(url.fragment().isEmpty()); |
|
419 QCOMPARE(url.host(), QString::fromLatin1("56::56:56:56:127.0.0.1")); |
|
420 QCOMPARE(url.authority(), QString::fromLatin1("user:pass@[56::56:56:56:127.0.0.1]:99")); |
|
421 QCOMPARE(url.port(), 99); |
|
422 } |
|
423 |
|
424 { |
|
425 QUrl url("http://www.foo.bar"); |
|
426 QVERIFY(url.isValid()); |
|
427 |
|
428 QUrl url2("/top//test/../test1/file.html"); |
|
429 QCOMPARE(url.resolved(url2).toString(), QString::fromLatin1("http://www.foo.bar/top//test1/file.html")); |
|
430 } |
|
431 |
|
432 { |
|
433 QUrl url("http://www.foo.bar"); |
|
434 QVERIFY(url.isValid()); |
|
435 |
|
436 QUrl url2("/top//test/../test1/file.html"); |
|
437 QCOMPARE(url.resolved(url2).toString(), QString::fromLatin1("http://www.foo.bar/top//test1/file.html")); |
|
438 } |
|
439 |
|
440 { |
|
441 QUrl url("http://www.foo.bar/top//test2/file2.html"); |
|
442 QVERIFY(url.isValid()); |
|
443 |
|
444 QCOMPARE(url.toString(), QString::fromLatin1("http://www.foo.bar/top//test2/file2.html")); |
|
445 } |
|
446 |
|
447 { |
|
448 QUrl url("http://www.foo.bar/top//test2/file2.html"); |
|
449 QVERIFY(url.isValid()); |
|
450 |
|
451 QCOMPARE(url.toString(), QString::fromLatin1("http://www.foo.bar/top//test2/file2.html")); |
|
452 } |
|
453 |
|
454 { |
|
455 QUrl url("file:/usr/local/src/kde2/////kdelibs/kio"); |
|
456 QVERIFY(url.isValid()); |
|
457 QCOMPARE(url.toString(), QString::fromLatin1("file:///usr/local/src/kde2/////kdelibs/kio")); |
|
458 } |
|
459 |
|
460 { |
|
461 QUrl url("http://www.foo.bar"); |
|
462 QVERIFY(url.isValid()); |
|
463 |
|
464 QUrl url2("mailto:bastian@kde.org"); |
|
465 QVERIFY(url2.isValid()); |
|
466 QCOMPARE(url.resolved(url2).toString(), QString::fromLatin1("mailto:bastian@kde.org")); |
|
467 } |
|
468 |
|
469 { |
|
470 QUrl url("mailto:bastian@kde.org?subject=hello"); |
|
471 QCOMPARE(url.toString(), QString::fromLatin1("mailto:bastian@kde.org?subject=hello")); |
|
472 } |
|
473 |
|
474 { |
|
475 QUrl url("file:/usr/local/src/kde2/kdelibs/kio/"); |
|
476 QVERIFY(url.isValid()); |
|
477 |
|
478 QUrl url2("../../////kdebase/konqueror"); |
|
479 QCOMPARE(url.resolved(url2).toString(), |
|
480 QString::fromLatin1("file:///usr/local/src/kde2/////kdebase/konqueror")); |
|
481 } |
|
482 |
|
483 { |
|
484 QString u1 = "file:/home/dfaure/my#myref"; |
|
485 QUrl url = u1; |
|
486 QVERIFY(url.isValid()); |
|
487 QCOMPARE(url.toString(), QString::fromLatin1("file:///home/dfaure/my#myref")); |
|
488 QCOMPARE(url.fragment(), QString::fromLatin1("myref")); |
|
489 } |
|
490 |
|
491 { |
|
492 QString u1 = "file:/home/dfaure/my#myref"; |
|
493 QUrl url = u1; |
|
494 QVERIFY(url.isValid()); |
|
495 |
|
496 QCOMPARE(url.toString(), QString::fromLatin1("file:///home/dfaure/my#myref")); |
|
497 QCOMPARE(url.fragment(), QString::fromLatin1("myref")); |
|
498 } |
|
499 |
|
500 { |
|
501 QUrl url("gg:www.kde.org"); |
|
502 QVERIFY(url.isValid()); |
|
503 QCOMPARE(url.scheme(), QString::fromLatin1("gg")); |
|
504 QVERIFY(url.host().isEmpty()); |
|
505 QCOMPARE(url.path(), QString::fromLatin1("www.kde.org")); |
|
506 } |
|
507 |
|
508 { |
|
509 QUrl url("KDE"); |
|
510 QVERIFY(url.isValid()); |
|
511 QCOMPARE(url.path(), QString::fromLatin1("KDE")); |
|
512 QVERIFY(url.scheme().isEmpty()); |
|
513 } |
|
514 |
|
515 { |
|
516 QUrl url("$HOME/.kde/share/config"); |
|
517 QVERIFY(url.isValid()); |
|
518 QCOMPARE(url.path(), QString::fromLatin1("$HOME/.kde/share/config")); |
|
519 QVERIFY(url.scheme().isEmpty()); |
|
520 } |
|
521 |
|
522 { |
|
523 QUrl url("file:/opt/kde2/qt2/doc/html/showimg-main-cpp.html#QObject::connect"); |
|
524 QVERIFY(url.isValid()); |
|
525 QCOMPARE(url.fragment(), QString::fromLatin1("QObject::connect")); |
|
526 } |
|
527 |
|
528 { |
|
529 QUrl url("file:/opt/kde2/qt2/doc/html/showimg-main-cpp.html#QObject:connect"); |
|
530 QVERIFY(url.isValid()); |
|
531 QCOMPARE(url.fragment(), QString::fromLatin1("QObject:connect")); |
|
532 } |
|
533 |
|
534 { |
|
535 // suburls |
|
536 QUrl url("file:/home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/#myref"); |
|
537 QVERIFY(url.isValid()); |
|
538 |
|
539 // or simply 'myref?' |
|
540 QCOMPARE(url.fragment(), QString::fromLatin1("gzip:/#tar:/#myref")); |
|
541 } |
|
542 |
|
543 { |
|
544 QUrl url("error:/?error=14&errText=Unknown%20host%20asdfu.adgi.sdfgoi#http://asdfu.adgi.sdfgoi"); |
|
545 QVERIFY(url.isValid()); |
|
546 QCOMPARE(url.fragment(), QString::fromLatin1("http://asdfu.adgi.sdfgoi")); |
|
547 } |
|
548 |
|
549 { |
|
550 // suburls |
|
551 QUrl url("file:/home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/"); |
|
552 QVERIFY(url.isValid()); |
|
553 } |
|
554 |
|
555 { |
|
556 QUrl url("file:/home/dfaure/cdrdao-1.1.5/dao/#CdrDriver.cc#"); |
|
557 QVERIFY(url.isValid()); |
|
558 } |
|
559 |
|
560 { |
|
561 QUrl url("file:/home/dfaure/my%20tar%20file.tgz#gzip:/#tar:/README"); |
|
562 QVERIFY(url.isValid()); |
|
563 QCOMPARE(url.toString(), QString::fromLatin1("file:///home/dfaure/my tar file.tgz#gzip:/#tar:/README")); |
|
564 } |
|
565 |
|
566 { |
|
567 QUrl notPretty; |
|
568 notPretty.setEncodedUrl("http://ferret.lmh.ox.ac.uk/%7Ekdecvs/"); |
|
569 QVERIFY(notPretty.isValid()); |
|
570 QCOMPARE(notPretty.toString(), QString::fromLatin1("http://ferret.lmh.ox.ac.uk/~kdecvs/")); |
|
571 |
|
572 QUrl notPretty2; |
|
573 notPretty2.setEncodedUrl("file:/home/test/directory%20with%20spaces"); |
|
574 QVERIFY(notPretty2.isValid()); |
|
575 QCOMPARE(notPretty2.toString(), QString::fromLatin1("file:///home/test/directory with spaces")); |
|
576 |
|
577 QUrl notPretty3("fish://foo/%23README%23"); |
|
578 QVERIFY(notPretty3.isValid()); |
|
579 QCOMPARE(notPretty3.toString(), QString::fromLatin1("fish://foo/%23README%23")); |
|
580 |
|
581 QUrl url15581; |
|
582 url15581.setUrl("http://alain.knaff.linux.lu/bug-reports/kde/spaces in url.html"); |
|
583 QCOMPARE(url15581.toString(), QString::fromLatin1("http://alain.knaff.linux.lu/bug-reports/kde/spaces in url.html")); |
|
584 QCOMPARE(url15581.toEncoded().constData(), QByteArray("http://alain.knaff.linux.lu/bug-reports/kde/spaces%20in%20url.html").constData()); |
|
585 |
|
586 QUrl url15582("http://alain.knaff.linux.lu/bug-reports/kde/percentage%in%url.html"); |
|
587 QCOMPARE(url15582.toString(), QString::fromLatin1("http://alain.knaff.linux.lu/bug-reports/kde/percentage%in%url.html")); |
|
588 QCOMPARE(url15582.toEncoded(), QByteArray("http://alain.knaff.linux.lu/bug-reports/kde/percentage%25in%25url.html")); |
|
589 } |
|
590 |
|
591 { |
|
592 QUrl carsten; |
|
593 carsten.setPath("/home/gis/src/kde/kdelibs/kfile/.#kfiledetailview.cpp.1.18"); |
|
594 QCOMPARE(carsten.path(), QString::fromLatin1("/home/gis/src/kde/kdelibs/kfile/.#kfiledetailview.cpp.1.18")); |
|
595 |
|
596 QUrl charles; |
|
597 charles.setPath("/home/charles/foo%20moo"); |
|
598 QCOMPARE(charles.path(), QString::fromLatin1("/home/charles/foo%20moo")); |
|
599 |
|
600 QUrl charles2; |
|
601 charles2.setEncodedUrl("file:/home/charles/foo%20moo"); |
|
602 QCOMPARE(charles2.path(), QString::fromLatin1("/home/charles/foo moo")); |
|
603 } |
|
604 |
|
605 { |
|
606 QUrl udir; |
|
607 QCOMPARE(udir.toEncoded(), QByteArray()); |
|
608 QVERIFY(!udir.isValid()); |
|
609 |
|
610 udir = QUrl::fromLocalFile("/home/dfaure/file.txt"); |
|
611 QCOMPARE(udir.path(), QString::fromLatin1("/home/dfaure/file.txt")); |
|
612 QCOMPARE(udir.toEncoded(), QByteArray("file:///home/dfaure/file.txt")); |
|
613 } |
|
614 |
|
615 { |
|
616 QUrl url; |
|
617 url.setUrl("hello.com#?"); |
|
618 QVERIFY(url.isValid()); |
|
619 url.setUrl("hello.com"); |
|
620 QVERIFY(!url.toString().contains(QLatin1Char('#'))); |
|
621 QVERIFY(!url.toString().contains(QLatin1Char('?'))); |
|
622 } |
|
623 |
|
624 { |
|
625 QUrl url; |
|
626 url.setUrl("http://1.2.3.4.example.com"); |
|
627 QVERIFY(url.isValid()); |
|
628 QCOMPARE(url.scheme(), QString("http")); |
|
629 QCOMPARE(url.host(), QString("1.2.3.4.example.com")); |
|
630 } |
|
631 |
|
632 { |
|
633 QUrl url; |
|
634 url.setUrl("http://1.2.3.4"); |
|
635 QVERIFY(url.isValid()); |
|
636 QCOMPARE(url.scheme(), QString("http")); |
|
637 QCOMPARE(url.host(), QString("1.2.3.4")); |
|
638 } |
|
639 { |
|
640 QUrl url; |
|
641 url.setUrl("http://1.2.3.4/"); |
|
642 QVERIFY(url.isValid()); |
|
643 QCOMPARE(url.scheme(), QString("http")); |
|
644 QCOMPARE(url.host(), QString("1.2.3.4")); |
|
645 QCOMPARE(url.path(), QString("/")); |
|
646 } |
|
647 { |
|
648 QUrl url; |
|
649 url.setUrl("http://1.2.3.4?foo"); |
|
650 QVERIFY(url.isValid()); |
|
651 QCOMPARE(url.scheme(), QString("http")); |
|
652 QCOMPARE(url.host(), QString("1.2.3.4")); |
|
653 QCOMPARE(url.encodedQuery(), QByteArray("foo")); |
|
654 } |
|
655 { |
|
656 QUrl url; |
|
657 url.setUrl("http://1.2.3.4#bar"); |
|
658 QVERIFY(url.isValid()); |
|
659 QCOMPARE(url.scheme(), QString("http")); |
|
660 QCOMPARE(url.host(), QString("1.2.3.4")); |
|
661 QCOMPARE(url.fragment(), QString("bar")); |
|
662 } |
|
663 |
|
664 { |
|
665 QUrl url; |
|
666 url.setEncodedUrl("data:text/javascript,d5%20%3D%20'five\\u0027s'%3B"); |
|
667 QVERIFY(url.isValid()); |
|
668 QCOMPARE(url.scheme(), QString("data")); |
|
669 QCOMPARE(url.host(), QString()); |
|
670 QCOMPARE(url.path(), QString("text/javascript,d5 = 'five\\u0027s';")); |
|
671 QCOMPARE(url.encodedPath().constData(), "text/javascript,d5%20%3D%20'five%5Cu0027s'%3B"); |
|
672 } |
|
673 |
|
674 /* |
|
675 The tests below are copied from kdelibs/kdecore/tests/kurltest.cpp (an old version of) |
|
676 |
|
677 Copyright (c) 1999-2005 Waldo Bastian <bastian@kde.org> |
|
678 Copyright (c) 2000-2005 David Faure <faure@kde.org> |
|
679 |
|
680 This library is free software; you can redistribute it and/or |
|
681 modify it under the terms of the GNU Library General Public |
|
682 License version 2 as published by the Free Software Foundation. |
|
683 |
|
684 This library is distributed in the hope that it will be useful, |
|
685 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
686 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
687 Library General Public License for more details. |
|
688 |
|
689 You should have received a copy of the GNU Library General Public License |
|
690 along with this library; see the file COPYING.LIB. If not, write to |
|
691 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
692 Boston, MA 02110-1301, USA. |
|
693 */ |
|
694 /* |
|
695 ### File / directory specifics |
|
696 |
|
697 KURL u2( QCString("/home/dfaure/") ); |
|
698 printf("\n* URL is %s\n",u2.url().ascii()); |
|
699 // not ignoring trailing slash |
|
700 check("KURL::directory(false,false)", u2.directory(false,false), "/home/dfaure/"); |
|
701 check("KURL::directory(true,false)", u2.directory(true,false), "/home/dfaure"); |
|
702 // ignoring trailing slash |
|
703 check("KURL::directory(false,true)", u2.directory(false,true), "/home/"); |
|
704 check("KURL::directory(true,true)", u2.directory(true,true), "/home"); |
|
705 u2.cd(".."); |
|
706 check("KURL::cd(\"..\")", u2.url(), "file:/home"); |
|
707 u2.cd("thomas"); |
|
708 check("KURL::cd(\"thomas\")", u2.url(), "file:/home/thomas"); |
|
709 u2.cd("/opt/kde/bin/"); |
|
710 check("KURL::cd(\"/opt/kde/bin/\")", u2.url(), "file:/opt/kde/bin/"); |
|
711 u2 = "ftp://ftp.kde.org/"; |
|
712 printf("\n* URL is %s\n",u2.url().ascii()); |
|
713 u2.cd("pub"); |
|
714 check("KURL::cd(\"pub\")", u2.url(), "ftp://ftp.kde.org/pub"); |
|
715 u2 = u2.upURL(); |
|
716 check("KURL::upURL()", u2.url(), "ftp://ftp.kde.org/"); |
|
717 u2 = u1; |
|
718 printf("\n* URL is %s\n",u2.url().ascii()); |
|
719 // setFileName |
|
720 u2.setFileName( "myfile.txt" ); |
|
721 check("KURL::setFileName()", u2.url(), "file:/home/dfaure/myfile.txt"); |
|
722 u2.setFileName( "myotherfile.txt" ); |
|
723 check("KURL::setFileName()", u2.url(), "file:/home/dfaure/myotherfile.txt"); |
|
724 // more tricky, renaming a directory (kpropsdlg.cc, line ~ 238) |
|
725 QString tmpurl = "file:/home/dfaure/myolddir/"; |
|
726 if ( tmpurl.at(tmpurl.length() - 1) == '/') |
|
727 // It's a directory, so strip the trailing slash first |
|
728 tmpurl.truncate( tmpurl.length() - 1); |
|
729 KURL newUrl = tmpurl; |
|
730 newUrl.setFileName( "mynewdir" ); |
|
731 check("KURL::setFileName() special", newUrl.url(), "file:/home/dfaure/mynewdir"); |
|
732 // addPath tests |
|
733 newUrl.addPath( "subdir" ); |
|
734 check("KURL::addPath(\"subdir\")", newUrl.url(), "file:/home/dfaure/mynewdir/subdir"); |
|
735 newUrl.addPath( "/foo/" ); |
|
736 check("KURL::addPath(\"/foo/\")", newUrl.url(), "file:/home/dfaure/mynewdir/subdir/foo/"); |
|
737 u2 = "http://www.kde.org"; // no path |
|
738 u2.addPath( "subdir" ); |
|
739 check("KURL::addPath(\"subdir\")", u2.url(), "http://www.kde.org/subdir"); |
|
740 u2.addPath( "" ); |
|
741 check("KURL::addPath(\"subdir\")", u2.url(), "http://www.kde.org/subdir"); // unchanged |
|
742 |
|
743 // even more tricky |
|
744 u2 = "print:/specials/Print%20To%20File%20(PDF%2FAcrobat)"; |
|
745 printf("\n* URL is %s\n",u2.url().ascii()); |
|
746 check("KURL::path()", u2.path(), "/specials/Print To File (PDF/Acrobat)"); |
|
747 check("KURL::fileName()", u2.fileName(), "Print To File (PDF/Acrobat)"); |
|
748 u2.setFileName( "" ); |
|
749 check("KURL::setFileName()", u2.url(), "print:/specials/"); |
|
750 |
|
751 u2 = "file:/specials/Print"; |
|
752 printf("\n* URL is %s\n",u2.url().ascii()); |
|
753 check("KURL::path()", u2.path(), "/specials/Print"); |
|
754 check("KURL::fileName()", u2.fileName(), "Print"); |
|
755 u2.setFileName( "" ); |
|
756 check("KURL::setFileName()", u2.url(), "file:/specials/"); |
|
757 |
|
758 const char * u3 = "ftp://host/dir1/dir2/myfile.txt"; |
|
759 printf("\n* URL is %s\n",u3); |
|
760 check("KURL::hasSubURL()", KURL(u3).hasSubURL() ? "yes" : "no", "no"); |
|
761 lst.clear(); |
|
762 lst = KURL::split( KURL(u3) ); |
|
763 check("KURL::split()", lst.count()==1 ? "1" : "error", "1"); |
|
764 check("KURL::split()", lst.first().url(), "ftp://host/dir1/dir2/myfile.txt"); |
|
765 // cdUp code |
|
766 KURL lastUrl = lst.last(); |
|
767 QString dir = lastUrl.directory( true, true ); |
|
768 check( "KURL::directory(true,true)", dir, "/dir1/dir2"); |
|
769 */ |
|
770 |
|
771 { |
|
772 // !!! FAILS |
|
773 // QString ucmp1 = "ftp://ftp.de.kde.org/dir"; |
|
774 // QString ucmp2 = "ftp://ftp.de.kde.org/dir/"; |
|
775 // QVERIFY(QUrl(ucmp1) == QUrl(ucmp2)); |
|
776 } |
|
777 |
|
778 |
|
779 /* |
|
780 /// Comparisons |
|
781 QString ucmp1 = "ftp://ftp.de.kde.org/dir"; |
|
782 QString ucmp2 = "ftp://ftp.de.kde.org/dir/"; |
|
783 check("urlcmp(only slash difference)", urlcmp(ucmp1,ucmp2)?"ko":"ok","ok"); |
|
784 check("urlcmp(only slash difference, ignore_trailing)", urlcmp(ucmp1,ucmp2,true,false)?"ok":"ko","ok"); |
|
785 QString ucmp3 = "ftp://ftp.de.kde.org/dir/#"; |
|
786 check("urlcmp(only hash difference)", urlcmp(ucmp2,ucmp3)?"ko":"ok","ok"); |
|
787 check("urlcmp(only hash difference, ignore_ref)", urlcmp(ucmp2,ucmp3,false,true)?"ok":"ko","ok"); |
|
788 check("urlcmp(slash and hash difference, ignore_trailing, ignore_ref)", urlcmp(ucmp2,ucmp3,true,true)?"ok":"ko","ok"); |
|
789 check("urlcmp(empty, empty)", urlcmp("","",false,true)?"ok":"ko","ok"); |
|
790 check("urlcmp(empty, empty)", urlcmp("","")?"ok":"ko","ok"); |
|
791 check("urlcmp(empty, not empty)", urlcmp("",ucmp1)?"ok":"ko","ko"); |
|
792 check("urlcmp(empty, not empty)", urlcmp("",ucmp1,false,true)?"ok":"ko","ko"); |
|
793 check("urlcmp(malformed, not empty)", urlcmp("file",ucmp1)?"ok":"ko","ko"); |
|
794 check("urlcmp(malformed, not empty)", urlcmp("file",ucmp1,false,true)?"ok":"ko","ko"); |
|
795 |
|
796 KURL ftpUrl ( "ftp://ftp.de.kde.org" ); |
|
797 printf("\n* URL is %s\n",ftpUrl.url().latin1()); |
|
798 check("KURL::path()", ftpUrl.path(), QString()); |
|
799 ftpUrl = "ftp://ftp.de.kde.org/"; |
|
800 check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp.de.kde.org/host/subdir/") ? "yes" : "no", "yes"); |
|
801 ftpUrl = "ftp://ftp/host/subdir/"; |
|
802 check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/host/subdir/") ? "yes" : "no", "yes"); |
|
803 check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/host/subdir") ? "yes" : "no", "yes"); |
|
804 check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/host/subdi") ? "yes" : "no", "no"); |
|
805 check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/host/subdir/blah/") ? "yes" : "no", "yes"); |
|
806 check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/blah/subdir") ? "yes" : "no", "no"); |
|
807 check("KURL::isParentOf()", ftpUrl.isParentOf( "file://ftp/host/subdir/") ? "yes" : "no", "no"); |
|
808 check("KURL::isParentOf()", ftpUrl.isParentOf( "ftp://ftp/host/subdir/subsub") ? "yes" : "no", "yes"); |
|
809 |
|
810 // WABA: The following tests are to test the handling of relative URLs as |
|
811 // found on web-pages. |
|
812 |
|
813 KURL waba1( "http://www.website.com/directory/?hello#ref" ); |
|
814 { |
|
815 KURL waba2( waba1, "relative.html"); |
|
816 check("http: Relative URL, single file", waba2.url(), "http://www.website.com/directory/relative.html"); |
|
817 } |
|
818 { |
|
819 KURL waba2( waba1, "../relative.html"); |
|
820 check("http: Relative URL, single file, directory up", waba2.url(), "http://www.website.com/relative.html"); |
|
821 } |
|
822 { |
|
823 KURL waba2( waba1, "down/relative.html"); |
|
824 check("http: Relative URL, single file, directory down", waba2.url(), "http://www.website.com/directory/down/relative.html"); |
|
825 } |
|
826 { |
|
827 KURL waba2( waba1, "/down/relative.html"); |
|
828 check("http: Relative URL, full path", waba2.url(), "http://www.website.com/down/relative.html"); |
|
829 } |
|
830 { |
|
831 KURL waba2( waba1, "//www.kde.org/relative.html"); |
|
832 check("http: Relative URL, with host", waba2.url(), "http://www.kde.org/relative.html"); |
|
833 } |
|
834 { |
|
835 KURL waba2( waba1, "relative.html?query=test&name=harry"); |
|
836 check("http: Relative URL, with query", waba2.url(), "http://www.website.com/directory/relative.html?query=test&name=harry"); |
|
837 waba2.removeQueryItem("query"); |
|
838 check("http: Removing query item", waba2.url(), "http://www.website.com/directory/relative.html?name=harry"); |
|
839 waba2.addQueryItem("age", "18"); |
|
840 check("http: Adding query item", waba2.url(), "http://www.website.com/directory/relative.html?name=harry&age=18"); |
|
841 waba2.addQueryItem("age", "21"); |
|
842 check("http: Adding query item", waba2.url(), "http://www.website.com/directory/relative.html?name=harry&age=18&age=21"); |
|
843 waba2.addQueryItem("fullname", "Harry Potter"); |
|
844 check("http: Adding query item", waba2.url(), "http://www.website.com/directory/relative.html?name=harry&age=18&age=21&fullname=Harry%20Potter"); |
|
845 } |
|
846 { |
|
847 KURL waba2( waba1, "?query=test&name=harry"); |
|
848 check("http: Relative URL, with query and no filename", waba2.url(), "http://www.website.com/directory/?query=test&name=harry"); |
|
849 } |
|
850 { |
|
851 KURL waba2( waba1, "relative.html#with_reference"); |
|
852 check("http: Relative URL, with reference", waba2.url(), "http://www.website.com/directory/relative.html#with_reference"); |
|
853 } |
|
854 { |
|
855 KURL waba2( waba1, "#"); |
|
856 check("http: Relative URL, with empty reference", waba2.url(), "http://www.website.com/directory/?hello#"); |
|
857 } |
|
858 { |
|
859 KURL waba2( waba1, ""); |
|
860 check("http: Empty relative URL", waba2.url(), "http://www.website.com/directory/?hello#ref"); |
|
861 } |
|
862 { |
|
863 KURL base( "http://faure@www.kde.org" ); // no path |
|
864 KURL waba2( base, "filename.html"); |
|
865 check("http: Relative URL, orig URL had no path", waba2.url(), "http://faure@www.kde.org/filename.html"); |
|
866 } |
|
867 { |
|
868 KURL base( "http://faure:pass@www.kde.org:81?query" ); |
|
869 KURL rel1( base, "http://www.kde.org/bleh/"); // same host |
|
870 check("http: Relative URL, orig URL had username", rel1.url(), "http://faure:pass@www.kde.org/bleh/"); |
|
871 KURL rel2( base, "http://www.yahoo.org"); // different host |
|
872 check("http: Relative URL, orig URL had username", rel2.url(), "http://www.yahoo.org"); |
|
873 } |
|
874 |
|
875 waba1 = "http://www.website.com/directory/filename?bla#blub"; |
|
876 { |
|
877 KURL waba2( waba1, "relative.html"); |
|
878 check("http: Relative URL, single file", waba2.url(), "http://www.website.com/directory/relative.html"); |
|
879 } |
|
880 { |
|
881 KURL waba2( waba1, "../relative.html"); |
|
882 check("http: Relative URL, single file, directory up", waba2.url(), "http://www.website.com/relative.html"); |
|
883 } |
|
884 { |
|
885 KURL waba2( waba1, "down/relative.html"); |
|
886 check("http: Relative URL, single file, directory down", waba2.url(), "http://www.website.com/directory/down/relative.html"); |
|
887 } |
|
888 { |
|
889 KURL waba2( waba1, "/down/relative.html"); |
|
890 check("http: Relative URL, full path", waba2.url(), "http://www.website.com/down/relative.html"); |
|
891 } |
|
892 { |
|
893 KURL waba2( waba1, "relative.html?query=test&name=harry"); |
|
894 check("http: Relative URL, with query", waba2.url(), "http://www.website.com/directory/relative.html?query=test&name=harry"); |
|
895 } |
|
896 { |
|
897 KURL waba2( waba1, "?query=test&name=harry"); |
|
898 check("http: Relative URL, with query and no filename", waba2.url(), "http://www.website.com/directory/filename?query=test&name=harry"); |
|
899 } |
|
900 { |
|
901 KURL waba2( waba1, "relative.html#with_reference"); |
|
902 check("http: Relative URL, with reference", waba2.url(), "http://www.website.com/directory/relative.html#with_reference"); |
|
903 } |
|
904 { |
|
905 KURL waba2( waba1, "http:/relative.html"); // "rfc 1606 loophole" |
|
906 check("http: Strange relative URL", waba2.url(), "http://www.website.com/relative.html"); |
|
907 } |
|
908 waba1.setUser("waldo"); |
|
909 check("http: Set user", waba1.url(), "http://waldo@www.website.com/directory/filename?bla#blub"); |
|
910 waba1.setUser("waldo/bastian"); |
|
911 check("http: Set user with slash in it", waba1.url(), "http://waldo%2Fbastian@www.website.com/directory/filename?bla#blub"); |
|
912 waba1.setRef( QString() ); |
|
913 waba1.setPass( "pass" ); |
|
914 waba1.setDirectory( "/foo" ); |
|
915 waba1.setProtocol( "https" ); |
|
916 waba1.setHost( "web.com" ); |
|
917 waba1.setPort( 881 ); |
|
918 check("http: setRef/setPass/setDirectory/setHost/setPort", waba1.url(), "https://waldo%2Fbastian:pass@web.com:881/foo/?bla"); |
|
919 waba1.setDirectory( "/foo/" ); |
|
920 check("http: setDirectory #2", waba1.url(), "https://waldo%2Fbastian:pass@web.com:881/foo/?bla"); |
|
921 |
|
922 // Empty queries should be preserved! |
|
923 waba1 = "http://www.kde.org/cgi/test.cgi?"; |
|
924 check("http: URL with empty query string", waba1.url(), |
|
925 "http://www.kde.org/cgi/test.cgi?"); |
|
926 |
|
927 // Empty references should be preserved |
|
928 waba1 = "http://www.kde.org/cgi/test.cgi#"; |
|
929 check("http: URL with empty reference string", waba1.url(), |
|
930 "http://www.kde.org/cgi/test.cgi#"); |
|
931 check("hasRef()", waba1.hasRef()?"true":"false","true"); |
|
932 check("hasHTMLRef()", waba1.hasHTMLRef()?"true":"false","true"); |
|
933 check("encodedHtmlRef()", waba1.encodedHtmlRef(),QString()); |
|
934 |
|
935 // URLs who forgot to encode spaces in the query. |
|
936 waba1 = "http://www.kde.org/cgi/test.cgi?hello=My Value"; |
|
937 check("http: URL with incorrect encoded query", waba1.url(), |
|
938 "http://www.kde.org/cgi/test.cgi?hello=My%20Value"); |
|
939 |
|
940 // URL with ':' in query (':' should NOT be encoded!) |
|
941 waba1.setQuery("hello:My Value"); |
|
942 check("http: URL with ':' in query", waba1.url(), |
|
943 "http://www.kde.org/cgi/test.cgi?hello:My%20Value"); |
|
944 check("upURL() removes query", waba1.upURL().url(), |
|
945 "http://www.kde.org/cgi/test.cgi"); |
|
946 |
|
947 // URLs who forgot to encode spaces in the query. |
|
948 waba1 = "http://www.kde.org/cgi/test.cgi?hello=My Value+20"; |
|
949 check("http: URL with incorrect encoded query", waba1.url(), |
|
950 "http://www.kde.org/cgi/test.cgi?hello=My%20Value+20"); |
|
951 |
|
952 // Urls without path (BR21387) |
|
953 waba1 = "http://meine.db24.de?link=home_c_login_login"; |
|
954 check("http: URL with empty path string", waba1.url(), |
|
955 "http://meine.db24.de?link=home_c_login_login"); |
|
956 check("http: URL with empty path string path", waba1.path(), |
|
957 ""); |
|
958 check("http: URL with empty path string query", waba1.query(), |
|
959 "?link=home_c_login_login"); |
|
960 |
|
961 waba1 = "http://a:389?b=c"; |
|
962 check( "http: URL with port, query, and empty path; url", waba1.url(), "http://a:389?b=c" ); |
|
963 check( "http: URL with port, query, and empty path; host", waba1.host(), "a" ); |
|
964 check( "http: URL with port, query, and empty path; port", QString::number( waba1.port() ), "389" ); |
|
965 check( "http: URL with port, query, and empty path; path", waba1.path(), "" ); |
|
966 check( "http: URL with port, query, and empty path; query", waba1.query(), "?b=c" ); |
|
967 |
|
968 // Urls without path (BR21387) |
|
969 waba1 = "http://meine.db24.de#link=home_c_login_login"; |
|
970 check("http: URL with empty path string", waba1.url(), |
|
971 "http://meine.db24.de#link=home_c_login_login"); |
|
972 check("http: URL with empty path string path", waba1.path(), |
|
973 ""); |
|
974 |
|
975 waba1 = "http://a:389#b=c"; |
|
976 check( "http: URL with port, ref, and empty path; url", waba1.url(), "http://a:389#b=c" ); |
|
977 check( "http: URL with port, ref, and empty path; host", waba1.host(), "a" ); |
|
978 check( "http: URL with port, ref, and empty path; port", QString::number( waba1.port() ), "389" ); |
|
979 check( "http: URL with port, ref, and empty path; path", waba1.path(), "" ); |
|
980 check( "http: URL with port, ref, and empty path; ref", waba1.ref(), "b=c" ); |
|
981 check( "http: URL with port, ref, and empty path; query", waba1.query(), "" ); |
|
982 |
|
983 // IPV6 |
|
984 waba1 = "http://[::FFFF:129.144.52.38]:81/index.html"; |
|
985 check("http: IPV6 host", waba1.host(), |
|
986 "::ffff:129.144.52.38"); |
|
987 check("http: IPV6 port", QString("%1").arg(waba1.port()), |
|
988 "81"); |
|
989 |
|
990 // IPV6 |
|
991 waba1 = "http://waba:pass@[::FFFF:129.144.52.38]:81/index.html"; |
|
992 check("http: IPV6 host", waba1.host(), |
|
993 "::ffff:129.144.52.38"); |
|
994 check("http: IPV6 host", waba1.user(), |
|
995 "waba"); |
|
996 check("http: IPV6 host", waba1.pass(), |
|
997 "pass"); |
|
998 check("http: IPV6 port", QString("%1").arg(waba1.port()), |
|
999 "81"); |
|
1000 |
|
1001 // IPV6 |
|
1002 waba1 = "http://www.kde.org/cgi/test.cgi"; |
|
1003 waba1.setHost("::ffff:129.144.52.38"); |
|
1004 check("http: IPV6 host", waba1.url(), |
|
1005 "http://[::ffff:129.144.52.38]/cgi/test.cgi"); |
|
1006 waba1 = "http://[::ffff:129.144.52.38]/cgi/test.cgi"; |
|
1007 assert( waba1.isValid() ); |
|
1008 |
|
1009 // IPV6 without path |
|
1010 waba1 = "http://[::ffff:129.144.52.38]?query"; |
|
1011 assert( waba1.isValid() ); |
|
1012 check("http: IPV6 without path", waba1.url(), |
|
1013 "http://[::ffff:129.144.52.38]?query"); |
|
1014 check("http: IPV6 without path; query", waba1.query(), |
|
1015 "?query"); |
|
1016 waba1 = "http://[::ffff:129.144.52.38]#ref"; |
|
1017 assert( waba1.isValid() ); |
|
1018 check("http: IPV6 without path", waba1.url(), |
|
1019 "http://[::ffff:129.144.52.38]#ref"); |
|
1020 check("http: IPV6 without path; ref", waba1.ref(), |
|
1021 "ref"); |
|
1022 // IPV6 without path but with a port |
|
1023 waba1 = "http://[::ffff:129.144.52.38]:81?query"; |
|
1024 assert( waba1.isValid() ); |
|
1025 check("http: IPV6 without path", waba1.url(), |
|
1026 "http://[::ffff:129.144.52.38]:81?query"); |
|
1027 check("http: IPV6 without path; port", QString::number( waba1.port() ), "81" ); |
|
1028 check("http: IPV6 without path; query", waba1.query(), "?query"); |
|
1029 waba1 = "http://[::ffff:129.144.52.38]:81#ref"; |
|
1030 assert( waba1.isValid() ); |
|
1031 check("http: IPV6 without path", waba1.url(), |
|
1032 "http://[::ffff:129.144.52.38]:81#ref"); |
|
1033 check("http: IPV6 without path; port", QString::number( waba1.port() ), "81" ); |
|
1034 check("http: IPV6 without path; ref", waba1.ref(), "ref"); |
|
1035 |
|
1036 // Streaming operators |
|
1037 KURL origURL( "http://www.website.com/directory/?#ref" ); |
|
1038 waba1 = "http://[::ffff:129.144.52.38]:81?query"; |
|
1039 QByteArray buffer; |
|
1040 { |
|
1041 QDataStream stream( buffer, QIODevice::WriteOnly ); |
|
1042 stream << origURL |
|
1043 << KURL( "file:" ) // an invalid one |
|
1044 << waba1; // the IPv6 one |
|
1045 } |
|
1046 { |
|
1047 QDataStream stream( buffer, QIODevice::ReadOnly ); |
|
1048 KURL restoredURL; |
|
1049 stream >> restoredURL; |
|
1050 check( "Streaming valid URL", origURL.url(), restoredURL.url() ); |
|
1051 stream >> restoredURL; |
|
1052 check( "Streaming invalid URL", restoredURL.isValid()?"valid":"malformed", "malformed" ); |
|
1053 check( "Streaming invalid URL", restoredURL.url(), "file:" ); |
|
1054 stream >> restoredURL; |
|
1055 check( "Streaming ipv6 URL with query", restoredURL.url(), waba1.url() ); |
|
1056 } |
|
1057 |
|
1058 // Broken stuff |
|
1059 waba1 = "file:a"; |
|
1060 check("Broken stuff #1 path", waba1.path(), "a"); |
|
1061 check("Broken stuff #1 fileName(false)", waba1.fileName(false), "a"); |
|
1062 check("Broken stuff #1 fileName(true)", waba1.fileName(true), "a"); |
|
1063 check("Broken stuff #1 directory(false, false)", waba1.directory(false, false), ""); |
|
1064 check("Broken stuff #1 directory(true, false)", waba1.directory(true, false), ""); |
|
1065 check("Broken stuff #1 directory(false, true)", waba1.directory(true, true), ""); |
|
1066 |
|
1067 waba1 = "file:a/"; |
|
1068 check("Broken stuff #2 path", waba1.path(), "a/"); |
|
1069 check("Broken stuff #2 fileName(false)", waba1.fileName(false), ""); |
|
1070 check("Broken stuff #2 fileName(true)", waba1.fileName(true), "a"); |
|
1071 check("Broken stuff #2 directory(false, false)", waba1.directory(false, false), "a/"); |
|
1072 check("Broken stuff #2 directory(true, false)", waba1.directory(true, false), "a"); |
|
1073 check("Broken stuff #2 directory(false, true)", waba1.directory(true, true), ""); |
|
1074 |
|
1075 waba1 = "file:"; |
|
1076 check("Broken stuff #3 empty", waba1.isEmpty()?"EMPTY":"NOT", "NOT"); |
|
1077 check("Broken stuff #3 valid", waba1.isValid()?"VALID":"MALFORMED", "MALFORMED"); |
|
1078 check("Broken stuff #3 path", waba1.path(), ""); |
|
1079 check("Broken stuff #3 fileName(false)", waba1.fileName(false), ""); |
|
1080 check("Broken stuff #3 fileName(true)", waba1.fileName(true), ""); |
|
1081 check("Broken stuff #3 directory(false, false)", waba1.directory(false, false), ""); |
|
1082 check("Broken stuff #3 directory(true, false)", waba1.directory(true, false), ""); |
|
1083 check("Broken stuff #3 directory(false, true)", waba1.directory(true, true), ""); |
|
1084 KURL broken; |
|
1085 broken.setPath( QString() ); |
|
1086 check("Broken stuff #4 empty", broken.isEmpty()?"EMPTY":"NOT", "NOT"); |
|
1087 // It's valid: because isValid refers to parsing, not to what happens afterwards. |
|
1088 check("Broken stuff #4 valid", broken.isValid()?"VALID":"MALFORMED", "VALID"); |
|
1089 check("Broken stuff #4 path", broken.path(), ""); |
|
1090 broken = "file://"; // just because coolo wondered |
|
1091 check("Broken stuff #5 empty", broken.isEmpty()?"EMPTY":"NOT", "NOT"); |
|
1092 check("Broken stuff #5 valid", broken.isValid()?"VALID":"MALFORMED", "MALFORMED"); |
|
1093 check("Broken stuff #5 path", broken.path(), ""); |
|
1094 broken = "file"; |
|
1095 check("Broken stuff #6 valid", broken.isValid()?"VALID":"MALFORMED", "MALFORMED"); |
|
1096 |
|
1097 #if 0 // BROKEN? |
|
1098 // UNC like names |
|
1099 KURL unc1("FILE://localhost/home/root"); |
|
1100 check("UNC, with localhost", unc1.path(), "/home/root"); |
|
1101 check("UNC, with localhost", unc1.url(), "file:/home/root"); |
|
1102 #endif |
|
1103 KURL unc2("file:///home/root"); |
|
1104 check("UNC, with empty host", unc2.path(), "/home/root"); |
|
1105 check("UNC, with empty host", unc2.url(), "file:/home/root"); |
|
1106 |
|
1107 { |
|
1108 KURL unc3("FILE://remotehost/home/root"); |
|
1109 #if 0 // BROKEN? |
|
1110 check("UNC, with remote host", unc3.path(), "//remotehost/home/root"); |
|
1111 #endif |
|
1112 check("UNC, with remote host", unc3.url(), "file://remotehost/home/root"); |
|
1113 KURL url2("file://atlas/dfaure"); |
|
1114 check("KURL::host()", url2.host(), "atlas"); |
|
1115 check("KURL::path()", url2.path(), "/dfaure"); |
|
1116 //check("KURL::path()", url3.path(), "//atlas/dfaure"); // says Waba |
|
1117 //KURL url3("file:////atlas/dfaure"); |
|
1118 //check("KURL::path()", url3.path(), "//atlas/dfaure"); // says Waba |
|
1119 } |
|
1120 |
|
1121 KURL umail1 ( "mailto:faure@kde.org" ); |
|
1122 check("mailto: URL, general form", umail1.protocol(), "mailto"); |
|
1123 check("mailto: URL, general form", umail1.path(), "faure@kde.org"); |
|
1124 check("mailto: URL, is relative", KURL::isRelativeURL("mailto:faure@kde.org") ? "true" : "false", "false"); |
|
1125 KURL umail2 ( "mailto:Faure David <faure@kde.org>" ); |
|
1126 check("mailto: URL, general form", umail2.protocol(), "mailto"); |
|
1127 check("mailto: URL, general form", umail2.path(), "Faure David <faure@kde.org>"); |
|
1128 check("isRelativeURL(\"mailto:faure@kde.org\")", KURL::isRelativeURL("mailto:faure@kde.org") ? "yes" : "no", "no"); |
|
1129 KURL umail3 ( "mailto:" ); |
|
1130 check("mailto: invalid URL", umail3.isValid()?"valid":"malformed", "malformed"); |
|
1131 |
|
1132 check("man: URL, is relative", KURL::isRelativeURL("man:mmap") ? "true" : "false", "false"); |
|
1133 check("javascript: URL, is relative", KURL::isRelativeURL("javascript:doSomething()") ? "true" : "false", "false"); |
|
1134 // more isRelative |
|
1135 check("file: URL, is relative", KURL::isRelativeURL("file:/blah") ? "true" : "false", "false"); |
|
1136 check("/path, is relative", KURL::isRelativeURL("/path") ? "true" : "false", "true"); // arguable |
|
1137 check("something, is relative", KURL::isRelativeURL("something") ? "true" : "false", "true"); |
|
1138 KURL about("about:konqueror"); |
|
1139 check("about:",about.path(),"konqueror"); |
|
1140 |
|
1141 KURL ulong("https://swww.gad.de:443/servlet/CookieAccepted?MAIL=s@gad.de&VER=25901"); |
|
1142 check("host",ulong.host(),"swww.gad.de"); |
|
1143 check("path",ulong.path(),"/servlet/CookieAccepted"); |
|
1144 |
|
1145 QTextCodec::setCodecForLocale( KGlobal::charsets()->codecForName( "iso-8859-1" ) ); |
|
1146 // UTF8 tests |
|
1147 KURL uloc("/home/dfaure/konqtests/Matériel"); |
|
1148 check("locale8bit",uloc.url().latin1(),"file:/home/dfaure/konqtests/Mat%E9riel"); // escaping the letter would be correct too |
|
1149 check("pretty",uloc.prettyURL(),"file:/home/dfaure/konqtests/Matériel"); // escaping the letter would be correct too |
|
1150 // 106 is MIB for UTF-8 |
|
1151 check("UTF8",uloc.url(0, 106),"file:/home/dfaure/konqtests/Mat%C3%A9riel"); |
|
1152 uloc = KURL("file:/home/dfaure/konqtests/Mat%C3%A9riel", 106); |
|
1153 check("UTF8 path", uloc.path(), "/home/dfaure/konqtests/Matériel"); |
|
1154 |
|
1155 // fromPathOrURL tests |
|
1156 uloc = KURL::fromPathOrURL( "/home/dfaure/konqtests/Mat%E9riel" ); |
|
1157 check("fromPathOrURL path", uloc.path(), "/home/dfaure/konqtests/Mat%E9riel"); |
|
1158 uloc = KURL::fromPathOrURL( "http://www.kde.org" ); |
|
1159 check("fromPathOrURL url", uloc.url(), "http://www.kde.org"); |
|
1160 uloc = KURL::fromPathOrURL( "www.kde.org" ); |
|
1161 check("fromPathOrURL url", uloc.isValid()?"valid":"malformed", "malformed"); |
|
1162 uloc = KURL::fromPathOrURL( "index.html" ); |
|
1163 check("fromPathOrURL url", uloc.isValid()?"valid":"malformed", "malformed"); |
|
1164 uloc = KURL::fromPathOrURL( "" ); |
|
1165 check("fromPathOrURL url", uloc.isValid()?"valid":"malformed", "malformed"); |
|
1166 |
|
1167 QTextCodec::setCodecForLocale( KGlobal::charsets()->codecForName( "koi8-r" ) ); |
|
1168 baseURL = "file:/home/coolo"; |
|
1169 KURL russian = baseURL.directory(false, true) + QString::fromLocal8Bit( "ÆÇÎ7" ); |
|
1170 check( "russian", russian.url(), "file:/home/%C6%C7%CE7" ); |
|
1171 |
|
1172 KURL tobi1("http://some.host.net/path/to/file#fragmentPrecedes?theQuery"); |
|
1173 check("wrong order of query and hypertext reference #1", tobi1.ref(), "fragmentPrecedes"); |
|
1174 check("wrong order of query and hypertext reference #2", tobi1.query(), "?theQuery"); |
|
1175 |
|
1176 tobi1 = "http://host.net/path/?#http://brokenäadsfküpoij31ü029muß2890zupycÜ*!*'O´+ß0i"; |
|
1177 check("zero-length query",tobi1.query(),"?"); |
|
1178 |
|
1179 tobi1 = "http://host.net/path/#no-query"; |
|
1180 check("no query", tobi1.query(),""); |
|
1181 |
|
1182 tobi1 = "http://host.net/path?myfirstquery#andsomeReference"; |
|
1183 tobi1.setEncodedPathAndQuery("another/path/?another&query"); |
|
1184 check("setEncodedPathAndQuery test#1", tobi1.query(), "?another&query"); |
|
1185 check("setEncodedPathAndQuery test#2", tobi1.path(), "another/path/"); |
|
1186 tobi1.setEncodedPathAndQuery("another/path?another&query"); |
|
1187 check("setEncodedPathAndQuery test#1", tobi1.query(), "?another&query"); |
|
1188 check("setEncodedPathAndQuery test#2", tobi1.path(), "another/path"); |
|
1189 |
|
1190 KURL theKow = "http://www.google.de/search?q=frerich&hlx=xx&hl=de&empty=&lr=lang+de&test=%2B%20%3A%25"; |
|
1191 check("queryItem (first item)", theKow.queryItem("q"), "frerich"); |
|
1192 check("queryItem (middle item)", theKow.queryItem("hl"), "de"); |
|
1193 check("queryItem (last item)", theKow.queryItem("lr"), "lang de"); |
|
1194 check("queryItem (invalid item)", theKow.queryItem("InterstellarCounselor"), QString()); |
|
1195 check("queryItem (empty item)", theKow.queryItem("empty"), ""); |
|
1196 check("queryItem (item with encoded chars)", theKow.queryItem("test"), "+ :%"); |
|
1197 |
|
1198 // checks for queryItems(), which returns a QMap<QString,QString>: |
|
1199 KURL queryUrl( "mailto:Marc%20Mutz%20%3cmutz@kde.org%3E?" |
|
1200 "Subject=subscribe+me&" |
|
1201 "body=subscribe+mutz%40kde.org&" |
|
1202 "Cc=majordomo%40lists.kde.org" ); |
|
1203 check("queryItems (c.s. keys)", |
|
1204 QStringList(queryUrl.queryItems().keys()).join(", "), |
|
1205 "Cc, Subject, body" ); |
|
1206 check("queryItems (c.i.s. keys)", |
|
1207 QStringList(queryUrl.queryItems(KURL::CaseInsensitiveKeys).keys()).join(", "), |
|
1208 "body, cc, subject" ); |
|
1209 check("queryItems (values; c.s. keys)", |
|
1210 QStringList(queryUrl.queryItems().values()).join(", "), |
|
1211 "majordomo@lists.kde.org, subscribe me, subscribe mutz@kde.org" ); |
|
1212 check("queryItems (values; c.i.s. keys)", |
|
1213 QStringList(queryUrl.queryItems(KURL::CaseInsensitiveKeys).values()).join(", "), |
|
1214 "subscribe mutz@kde.org, majordomo@lists.kde.org, subscribe me" ); |
|
1215 |
|
1216 KURL umlaut1("http://www.clever-tanken.de/liste.asp?ort=N%FCrnberg&typ=Diesel"); |
|
1217 check("umlaut1.url()", umlaut1.url(), "http://www.clever-tanken.de/liste.asp?ort=N%FCrnberg&typ=Diesel"); |
|
1218 |
|
1219 KURL umlaut2("http://www.clever-tanken.de/liste.asp?ort=N%FCrnberg&typ=Diesel", 106); |
|
1220 check("umlaut2.url()", umlaut2.url(), "http://www.clever-tanken.de/liste.asp?ort=N%FCrnberg&typ=Diesel"); |
|
1221 |
|
1222 // Needed for #49616 |
|
1223 check( "encode_string('C++')", KURL::encode_string( "C++" ), "C%2B%2B" ); |
|
1224 check( "decode_string('C%2B%2B')", KURL::decode_string( "C%2B%2B" ), "C++" ); |
|
1225 check( "decode_string('C%00A')", KURL::decode_string( "C%00%A" ), "C" ); // we stop at %00 |
|
1226 |
|
1227 check( "encode_string('%')", KURL::encode_string( "%" ), "%25" ); |
|
1228 check( "encode_string(':')", KURL::encode_string( ":" ), "%3A" ); |
|
1229 |
|
1230 KURL amantia( "http://%E1.foo" ); |
|
1231 check("amantia.isValid()", amantia.isValid() ? "true" : "false", "true"); |
|
1232 #ifdef HAVE_IDNA_H |
|
1233 check("amantia.url()", amantia.url(), "http://xn--80a.foo"); // Non-ascii is allowed in IDN domain names. |
|
1234 #else |
|
1235 check("amantia.url()", amantia.url(), "http://?.foo"); // why not |
|
1236 #endif |
|
1237 |
|
1238 KURL smb("smb://domain;username:password@server/share"); |
|
1239 check("smb.isValid()", smb.isValid() ? "true" : "false", "true"); |
|
1240 check("smb.user()", smb.user(), "domain;username"); |
|
1241 smb = "smb:/"; |
|
1242 check("smb:/", smb.isValid()?"VALID":"MALFORMED", "VALID"); |
|
1243 smb = "smb://"; // kurl.cpp rev 1.106 |
|
1244 check("smb://", smb.isValid()?"VALID":"MALFORMED", "MALFORMED"); |
|
1245 smb = "smb://host"; |
|
1246 check("smb://host", smb.isValid()?"VALID":"MALFORMED", "VALID"); |
|
1247 smb = "smb:///"; |
|
1248 check("smb:///", smb.isValid()?"VALID":"MALFORMED", "VALID"); |
|
1249 |
|
1250 KURL weird; |
|
1251 weird = "http://strange<hostname>/"; |
|
1252 check("weird.isValid()", weird.isValid() ? "true" : "false", "false"); |
|
1253 |
|
1254 weird = "http://strange<username>@strange<hostname>/"; |
|
1255 check("weird.isValid()", weird.isValid() ? "true" : "false", "false"); |
|
1256 |
|
1257 weird = "http://strange<username>@ok_hostname/"; |
|
1258 check("weird.isValid()", weird.isValid() ? "true" : "false", "true"); |
|
1259 check("weird.host()", weird.host(), "ok_hostname"); |
|
1260 |
|
1261 weird = "http://strange;hostname/"; |
|
1262 check("weird.isValid()", weird.isValid() ? "true" : "false", "false"); |
|
1263 |
|
1264 weird = "http://strange;username@strange;hostname/"; |
|
1265 check("weird.isValid()", weird.isValid() ? "true" : "false", "false"); |
|
1266 |
|
1267 weird = "http://strange;username@ok_hostname/"; |
|
1268 check("weird.isValid()", weird.isValid() ? "true" : "false", "true"); |
|
1269 check("weird.host()", weird.host(), "ok_hostname"); |
|
1270 |
|
1271 weird = "http://strange;username:password@strange;hostname/"; |
|
1272 check("weird.isValid()", weird.isValid() ? "true" : "false", "false"); |
|
1273 |
|
1274 weird = "http://strange;username:password@ok_hostname/"; |
|
1275 check("weird.isValid()", weird.isValid() ? "true" : "false", "true"); |
|
1276 check("weird.host()", weird.host(), "ok_hostname"); |
|
1277 |
|
1278 weird = "http://[strange;hostname]/"; |
|
1279 check("weird.isValid()", weird.isValid() ? "true" : "false", "false"); |
|
1280 |
|
1281 weird = "http://[::fff:1:23]/"; |
|
1282 check("weird.isValid()", weird.isValid() ? "true" : "false", "true"); |
|
1283 check("weird.host()", weird.host(), "::fff:1:23"); |
|
1284 |
|
1285 KURL com1("http://server.com/dir/", "."); |
|
1286 check("com1.url()", com1.url(), "http://server.com/dir/"); |
|
1287 |
|
1288 KURL com2("http://server.com/dir/blubb/", "blah/"); |
|
1289 check("com2.url()", com2.url(), "http://server.com/dir/blubb/blah/"); |
|
1290 |
|
1291 KURL utf8_1("audiocd:/By%20Name/15%20Geantra%C3%AE.wav", 106); |
|
1292 check("utf8_1.fileName()", utf8_1.fileName(), QString::fromLatin1("15 Geantraî.wav")); |
|
1293 |
|
1294 KURL utf8_2("audiocd:/By%20Name/15%2fGeantra%C3%AE.wav", 106); |
|
1295 check("utf8_2.fileName()", utf8_2.fileName(), QString::fromLatin1("15/Geantraî.wav")); |
|
1296 |
|
1297 KURL url_newline_1("http://www.foo.bar/foo/bar\ngnork"); |
|
1298 check("url_newline_1.url()", url_newline_1.url(), QString::fromLatin1("http://www.foo.bar/foo/bar%0Agnork")); |
|
1299 |
|
1300 KURL url_newline_2("http://www.foo.bar/foo?bar\ngnork"); |
|
1301 check("url_newline_2.url()", url_newline_2.url(), QString::fromLatin1("http://www.foo.bar/foo?bar%0Agnork")); |
|
1302 |
|
1303 KURL local_file_1("file://localhost/my/file"); |
|
1304 check("local_file_1.isLocalFile()", local_file_1.isLocalFile() ? "true" : "false", "true"); |
|
1305 |
|
1306 KURL local_file_2("file://www.kde.org/my/file"); |
|
1307 check("local_file_2.isLocalFile()", local_file_2.isLocalFile() ? "true" : "false", "false"); |
|
1308 |
|
1309 KURL local_file_3; |
|
1310 local_file_3.setHost(getenv("HOSTNAME")); |
|
1311 local_file_3.setPath("/my/file"); |
|
1312 printf("\nURL=%s\n", local_file_3.url().latin1()); |
|
1313 check("local_file_3.isLocalFile()", local_file_3.isLocalFile() ? "true" : "false", "true"); |
|
1314 |
|
1315 KURL local_file_4("file:///my/file"); |
|
1316 check("local_file_4.isLocalFile()", local_file_4.isLocalFile() ? "true" : "false", "true"); |
|
1317 |
|
1318 KURL local_file_5; |
|
1319 local_file_5.setPath("/foo?bar"); |
|
1320 check("local_file_5.url()", local_file_5.url(), "file:/foo%3Fbar"); |
|
1321 |
|
1322 QString basePath = "/home/bastian"; |
|
1323 |
|
1324 check("relativePath(\"/home/bastian\", \"/home/bastian\")", KURL::relativePath(basePath, "/home/bastian"), "./"); |
|
1325 bool b; |
|
1326 check("relativePath(\"/home/bastian\", \"/home/bastian/src/plugins\")", KURL::relativePath(basePath, "/home/bastian/src/plugins", &b), "./src/plugins"); |
|
1327 check("Is a subdirectory?", b ? "true" : "false", "true"); |
|
1328 check("relativePath(\"/home/bastian\", \"./src/plugins\")", KURL::relativePath(basePath, "./src/plugins"), "./src/plugins"); |
|
1329 check("relativePath(\"/home/bastian\", \"/home/waba/src/plugins\")", KURL::relativePath(basePath, "/home/waba/src/plugins", &b), "../waba/src/plugins"); |
|
1330 check("Is a subdirectory?", b ? "true" : "false", "false"); |
|
1331 check("relativePath(\"/home/bastian\", \"/\")", KURL::relativePath(basePath, "/"), "../../"); |
|
1332 |
|
1333 check("relativePath(\"/\", \"/\")", KURL::relativePath("/", "/"), "./"); |
|
1334 check("relativePath(\"/\", \"/home/bastian\")", KURL::relativePath("/", "/home/bastian"), "./home/bastian"); |
|
1335 check("relativePath(\"\", \"/home/bastian\")", KURL::relativePath("", "/home/bastian"), "/home/bastian"); |
|
1336 |
|
1337 baseURL = "http://www.kde.org/index.html"; |
|
1338 check("relativeURL(\"http://www.kde.org/index.html\", \"http://www.kde.org/index.html#help\")", KURL::relativeURL(baseURL, "http://www.kde.org/index.html#help"), "#help"); |
|
1339 check("relativeURL(\"http://www.kde.org/index.html\", \"http://www.kde.org/index.html?help=true\")", KURL::relativeURL(baseURL, "http://www.kde.org/index.html?help=true"), "index.html?help=true"); |
|
1340 check("relativeURL(\"http://www.kde.org/index.html\", \"http://www.kde.org/contact.html\")", KURL::relativeURL(baseURL, "http://www.kde.org/contact.html"), "contact.html"); |
|
1341 check("relativeURL(\"http://www.kde.org/index.html\", \"ftp://ftp.kde.org/pub/kde\")", KURL::relativeURL(baseURL, "ftp://ftp.kde.org/pub/kde"), "ftp://ftp.kde.org/pub/kde"); |
|
1342 check("relativeURL(\"http://www.kde.org/index.html\", \"http://www.kde.org/index.html\")", KURL::relativeURL(baseURL, "http://www.kde.org/index.html"), "./"); |
|
1343 |
|
1344 baseURL = "http://www.kde.org/info/index.html"; |
|
1345 check("relativeURL(\"http://www.kde.org/info/index.html\", \"http://www.kde.org/bugs/contact.html\")", KURL::relativeURL(baseURL, "http://www.kde.org/bugs/contact.html"), "../bugs/contact.html"); |
|
1346 |
|
1347 baseURL = "ptal://mlc:usb:PC_970"; |
|
1348 check("isValid()?", baseURL.isValid() ? "true" : "false", "false"); |
|
1349 check("url()", baseURL.url(), "ptal://mlc:usb:PC_970"); |
|
1350 |
|
1351 baseURL = "http://mlc:80/"; |
|
1352 check("isValid()?", baseURL.isValid() ? "true" : "false", "true"); |
|
1353 check("port()?", QString::number(baseURL.port()), "80"); |
|
1354 check("path()?", baseURL.path(), "/"); |
|
1355 |
|
1356 baseURL = "ptal://mlc:usb@PC_970"; // User=mlc, password=usb, host=PC_970 |
|
1357 check("isValid()?", baseURL.isValid() ? "true" : "false", "true"); |
|
1358 check("host()?", baseURL.host(), "pc_970"); |
|
1359 check("user()?", baseURL.user(), "mlc"); |
|
1360 check("pass()?", baseURL.pass(), "usb"); |
|
1361 |
|
1362 weird = "ftp://user%40host.com@ftp.host.com/var/www/"; |
|
1363 check("user()?", weird.user(), "user@host.com" ); |
|
1364 check("host()?", weird.host(), "ftp.host.com" ); |
|
1365 KURL up = weird.upURL(); |
|
1366 check("KURL::upURL()", up.url(), "ftp://user%40host.com@ftp.host.com/var/"); |
|
1367 up = up.upURL(); |
|
1368 check("KURL::upURL()", up.url(), "ftp://user%40host.com@ftp.host.com/"); |
|
1369 up = up.upURL(); |
|
1370 check("KURL::upURL()", up.url(), "ftp://user%40host.com@ftp.host.com/"); // unchanged |
|
1371 |
|
1372 KURL ldap = "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)"; |
|
1373 check("host()?", ldap.host(), "host.com"); |
|
1374 check("port()?", QString("%1").arg(ldap.port()), "6666"); |
|
1375 check("path()?", ldap.path(), "/o=University of Michigan,c=US"); |
|
1376 check("query()?", ldap.query(), "??sub?(cn=Babs%20Jensen)"); |
|
1377 check("url()?", ldap.url(), "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)"); |
|
1378 ldap.setQuery("??sub?(cn=Karl%20Marx)"); |
|
1379 check("query()?", ldap.query(), "??sub?(cn=Karl%20Marx)"); |
|
1380 check("url()?", ldap.url(), "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Karl%20Marx)"); |
|
1381 |
|
1382 KURL leo = "data:text/html,http://www.invalid/"; |
|
1383 check("data URL: isValid", leo.isValid()?"valid":"malformed", "valid" ); |
|
1384 check("data URL: protocol", leo.protocol(), "data" ); |
|
1385 check("data URL: url", leo.url(), "data:text/html,http://www.invalid/" ); |
|
1386 check("data URL: path", leo.path(), "text/html,http://www.invalid/" ); |
|
1387 |
|
1388 // URI Mode tests |
|
1389 url1 = "http://www.foobar.com/"; |
|
1390 check("KURL(\"http://www.foobar.com/\").uriMode()", QString::number(url1.uriMode()), QString::number(KURL::URL)); |
|
1391 url1 = "mailto:user@host.com"; |
|
1392 check("KURL(\"mailto:user@host.com\").uriMode()", QString::number(url1.uriMode()), QString::number(KURL::Mailto)); |
|
1393 check("KURL(\"mailto:user@host.com\").url()", url1.url(), "mailto:user@host.com"); |
|
1394 check("KURL(\"mailto:user@host.com\").url(0, 106)", url1.url(0, 106), "mailto:user@host.com"); |
|
1395 url1 = "data:text/plain,foobar?gazonk=flarp"; |
|
1396 check("KURL(\"data:text/plain,foobar?gazonk=flarp\").uriMode()", QString::number(url1.uriMode()), QString::number(KURL::RawURI)); |
|
1397 check("KURL(\"data:text/plain,foobar?gazonk=flarp\").path()", url1.path(), "text/plain,foobar?gazonk=flarp"); |
|
1398 url1 = "mailto:User@Host.COM?subject=Hello"; |
|
1399 check("KURL(\"mailto:User@Host.COM?subject=Hello\").path()", url1.path(), "User@host.com"); |
|
1400 |
|
1401 printf("\nTest OK !\n"); |
|
1402 */ |
|
1403 |
|
1404 |
|
1405 } |
|
1406 |
|
1407 void tst_QUrl::i18n_data() |
|
1408 { |
|
1409 QTest::addColumn<QString>("input"); |
|
1410 QTest::addColumn<QByteArray>("punyOutput"); |
|
1411 |
|
1412 QTest::newRow("øl") << QString::fromLatin1("http://ole:passord@www.øl.no/index.html?ole=æsemann&ilder gud=hei#top") |
|
1413 << QByteArray("http://ole:passord@www.xn--l-4ga.no/index.html?ole=%C3%A6semann&ilder%20gud=hei#top"); |
|
1414 QTest::newRow("räksmörgås") << QString::fromLatin1("http://www.räksmörgås.no/") |
|
1415 << QByteArray("http://www.xn--rksmrgs-5wao1o.no/"); |
|
1416 QTest::newRow("bühler") << QString::fromLatin1("http://www.bühler.no/") |
|
1417 << QByteArray("http://www.xn--bhler-kva.no/"); |
|
1418 QTest::newRow("non-latin1") |
|
1419 << QString::fromUtf8("http://www.\316\261\316\270\316\256\316\275\316\261.info") |
|
1420 << QByteArray("http://www.xn--jxafb0a0a.info"); |
|
1421 } |
|
1422 |
|
1423 void tst_QUrl::i18n() |
|
1424 { |
|
1425 QFETCH(QString, input); |
|
1426 QFETCH(QByteArray, punyOutput); |
|
1427 |
|
1428 QUrl url(input); |
|
1429 QVERIFY(url.isValid()); |
|
1430 |
|
1431 QCOMPARE(url.toEncoded().constData(), punyOutput.constData()); |
|
1432 QCOMPARE(QUrl::fromEncoded(punyOutput), url); |
|
1433 QCOMPARE(QUrl::fromEncoded(punyOutput).toString(), input); |
|
1434 } |
|
1435 |
|
1436 |
|
1437 void tst_QUrl::resolving_data() |
|
1438 { |
|
1439 QTest::addColumn<QString>("baseUrl"); |
|
1440 QTest::addColumn<QString>("relativeUrl"); |
|
1441 QTest::addColumn<QString>("relsolvedUrl"); |
|
1442 |
|
1443 // 5.4.1 Normal Examples (http://www.ietf.org/rfc/rfc3986.txt) |
|
1444 QTest::newRow("g:h") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g:h") << QString::fromLatin1("g:h"); |
|
1445 QTest::newRow("g") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g") << QString::fromLatin1("http://a/b/c/g"); |
|
1446 QTest::newRow("./g") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("./g") << QString::fromLatin1("http://a/b/c/g"); |
|
1447 QTest::newRow("g/") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g/") << QString::fromLatin1("http://a/b/c/g/"); |
|
1448 QTest::newRow("/g") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("/g") << QString::fromLatin1("http://a/g"); |
|
1449 QTest::newRow("//g") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("//g") << QString::fromLatin1("http://g"); |
|
1450 QTest::newRow("?y") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("?y") << QString::fromLatin1("http://a/b/c/d;p?y"); |
|
1451 QTest::newRow("g?y") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g?y") << QString::fromLatin1("http://a/b/c/g?y"); |
|
1452 QTest::newRow("#s") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("#s") << QString::fromLatin1("http://a/b/c/d;p?q#s"); |
|
1453 QTest::newRow("g#s") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g#s") << QString::fromLatin1("http://a/b/c/g#s"); |
|
1454 QTest::newRow("g?y#s") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g?y#s") << QString::fromLatin1("http://a/b/c/g?y#s"); |
|
1455 QTest::newRow(";x") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1(";x") << QString::fromLatin1("http://a/b/c/;x"); |
|
1456 QTest::newRow("g;x") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g;x") << QString::fromLatin1("http://a/b/c/g;x"); |
|
1457 QTest::newRow("g;x?y#s") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g;x?y#s") << QString::fromLatin1("http://a/b/c/g;x?y#s"); |
|
1458 QTest::newRow("[empty]") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("") << QString::fromLatin1("http://a/b/c/d;p?q"); |
|
1459 QTest::newRow(".") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1(".") << QString::fromLatin1("http://a/b/c/"); |
|
1460 QTest::newRow("./") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("./") << QString::fromLatin1("http://a/b/c/"); |
|
1461 QTest::newRow("..") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("..") << QString::fromLatin1("http://a/b/"); |
|
1462 QTest::newRow("../") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("../") << QString::fromLatin1("http://a/b/"); |
|
1463 QTest::newRow("../g") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("../g") << QString::fromLatin1("http://a/b/g"); |
|
1464 QTest::newRow("../..") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("../..") << QString::fromLatin1("http://a/"); |
|
1465 QTest::newRow("../../") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("../../") << QString::fromLatin1("http://a/"); |
|
1466 QTest::newRow("../../g") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("../../g") << QString::fromLatin1("http://a/g"); |
|
1467 |
|
1468 // 5.4.2 Abnormal Examples (http://www.ietf.org/rfc/rfc3986.txt) |
|
1469 |
|
1470 // Parsers must be careful in handling cases where there are more |
|
1471 // relative path ".." segments than there are hierarchical levels in the |
|
1472 // base URI's path. Note that the ".." syntax cannot be used to change |
|
1473 // the authority component of a URI. |
|
1474 QTest::newRow("../../../g") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("../../../g") << QString::fromLatin1("http://a/g"); |
|
1475 QTest::newRow("../../../../g") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("../../../../g") << QString::fromLatin1("http://a/g"); |
|
1476 |
|
1477 // Similarly, parsers must remove the dot-segments "." and ".." when |
|
1478 // they are complete components of a path, but not when they are only |
|
1479 // part of a segment. |
|
1480 QTest::newRow("/./g") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("/./g") << QString::fromLatin1("http://a/g"); |
|
1481 QTest::newRow("/../g") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("/../g") << QString::fromLatin1("http://a/g"); |
|
1482 QTest::newRow("g.") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g.") << QString::fromLatin1("http://a/b/c/g."); |
|
1483 QTest::newRow(".g") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1(".g") << QString::fromLatin1("http://a/b/c/.g"); |
|
1484 QTest::newRow("g..") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g..") << QString::fromLatin1("http://a/b/c/g.."); |
|
1485 QTest::newRow("..g") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("..g") << QString::fromLatin1("http://a/b/c/..g"); |
|
1486 |
|
1487 // Less likely are cases where the relative URI reference uses |
|
1488 // unnecessary or nonsensical forms of the "." and ".." complete path |
|
1489 // segments. |
|
1490 QTest::newRow("./../g") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("./../g") << QString::fromLatin1("http://a/b/g"); |
|
1491 QTest::newRow("./g/.") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("./g/.") << QString::fromLatin1("http://a/b/c/g/"); |
|
1492 QTest::newRow("g/./h") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g/./h") << QString::fromLatin1("http://a/b/c/g/h"); |
|
1493 QTest::newRow("g/../h") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g/../h") << QString::fromLatin1("http://a/b/c/h"); |
|
1494 QTest::newRow("g;x=1/./y") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g;x=1/./y") << QString::fromLatin1("http://a/b/c/g;x=1/y"); |
|
1495 QTest::newRow("g;x=1/../y") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g;x=1/../y") << QString::fromLatin1("http://a/b/c/y"); |
|
1496 |
|
1497 // Some applications fail to separate the reference's query and/or |
|
1498 // fragment components from a relative path before merging it with the |
|
1499 // base path and removing dot-segments. This error is rarely noticed, |
|
1500 // since typical usage of a fragment never includes the hierarchy ("/") |
|
1501 // character, and the query component is not normally used within |
|
1502 // relative references. |
|
1503 QTest::newRow("g?y/./x") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g?y/./x") << QString::fromLatin1("http://a/b/c/g?y/./x"); |
|
1504 QTest::newRow("g?y/../x") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g?y/../x") << QString::fromLatin1("http://a/b/c/g?y/../x"); |
|
1505 QTest::newRow("g#s/./x") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g#s/./x") << QString::fromLatin1("http://a/b/c/g#s/./x"); |
|
1506 QTest::newRow("g#s/../x") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("g#s/../x") << QString::fromLatin1("http://a/b/c/g#s/../x"); |
|
1507 |
|
1508 // Some parsers allow the scheme name to be present in a relative URI |
|
1509 // reference if it is the same as the base URI scheme. This is |
|
1510 // considered to be a loophole in prior specifications of partial URI |
|
1511 // [RFC1630]. Its use should be avoided, but is allowed for backward |
|
1512 // compatibility. |
|
1513 // For strict parsers : |
|
1514 // QTest::newRow("http:g [for strict parsers]") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("http:g") << QString::fromLatin1("http:g"); |
|
1515 // For backward compatibility : |
|
1516 QTest::newRow("http:g [for backward compatibility]") << QString::fromLatin1("http://a/b/c/d;p?q") << QString::fromLatin1("http:g") << QString::fromLatin1("http://a/b/c/g"); |
|
1517 |
|
1518 // Resolve relative with relative |
|
1519 QTest::newRow("../a (1)") << QString::fromLatin1("b") << QString::fromLatin1("../a") << QString::fromLatin1("a"); |
|
1520 QTest::newRow("../a (2)") << QString::fromLatin1("b/a") << QString::fromLatin1("../a") << QString::fromLatin1("a"); |
|
1521 QTest::newRow("../a (3)") << QString::fromLatin1("b/c/a") << QString::fromLatin1("../a") << QString::fromLatin1("b/a"); |
|
1522 QTest::newRow("../a (4)") << QString::fromLatin1("b") << QString::fromLatin1("/a") << QString::fromLatin1("/a"); |
|
1523 |
|
1524 QTest::newRow("../a (5)") << QString::fromLatin1("/b") << QString::fromLatin1("../a") << QString::fromLatin1("/a"); |
|
1525 QTest::newRow("../a (6)") << QString::fromLatin1("/b/a") << QString::fromLatin1("../a") << QString::fromLatin1("/a"); |
|
1526 QTest::newRow("../a (7)") << QString::fromLatin1("/b/c/a") << QString::fromLatin1("../a") << QString::fromLatin1("/b/a"); |
|
1527 QTest::newRow("../a (8)") << QString::fromLatin1("/b") << QString::fromLatin1("/a") << QString::fromLatin1("/a"); |
|
1528 } |
|
1529 |
|
1530 void tst_QUrl::resolving() |
|
1531 { |
|
1532 QFETCH(QString, baseUrl); |
|
1533 QFETCH(QString, relativeUrl); |
|
1534 QFETCH(QString, relsolvedUrl); |
|
1535 |
|
1536 QUrl url(baseUrl); |
|
1537 QCOMPARE(url.resolved(relativeUrl).toString(), relsolvedUrl); |
|
1538 } |
|
1539 |
|
1540 |
|
1541 void tst_QUrl::toString_data() |
|
1542 { |
|
1543 QTest::addColumn<QString>("urlString"); |
|
1544 QTest::addColumn<uint>("options"); |
|
1545 QTest::addColumn<QString>("string"); |
|
1546 |
|
1547 QTest::newRow("data0") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1548 << uint(QUrl::RemoveScheme) |
|
1549 << QString::fromLatin1("//ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top"); |
|
1550 |
|
1551 QTest::newRow("data2") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1552 << uint(QUrl::RemovePassword) |
|
1553 << QString::fromLatin1("http://ole@www.troll.no:9090/index.html?ole=semann&gud=hei#top"); |
|
1554 |
|
1555 QTest::newRow("data3") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1556 << uint(QUrl::RemoveUserInfo) |
|
1557 << QString::fromLatin1("http://www.troll.no:9090/index.html?ole=semann&gud=hei#top"); |
|
1558 |
|
1559 QTest::newRow("data4") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1560 << uint(QUrl::RemovePort) |
|
1561 << QString::fromLatin1("http://ole:password@www.troll.no/index.html?ole=semann&gud=hei#top"); |
|
1562 |
|
1563 QTest::newRow("data5") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1564 << uint(QUrl::RemoveAuthority) |
|
1565 << QString::fromLatin1("http:/index.html?ole=semann&gud=hei#top"); |
|
1566 |
|
1567 QTest::newRow("data6") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1568 << uint(QUrl::RemovePath) |
|
1569 << QString::fromLatin1("http://ole:password@www.troll.no:9090?ole=semann&gud=hei#top"); |
|
1570 |
|
1571 QTest::newRow("data7") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1572 << uint(QUrl::RemoveQuery) |
|
1573 << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html#top"); |
|
1574 |
|
1575 QTest::newRow("data8") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1576 << uint(QUrl::RemoveFragment) |
|
1577 << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei"); |
|
1578 |
|
1579 QTest::newRow("data9") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1580 << uint(QUrl::RemoveScheme | QUrl::RemovePassword) |
|
1581 << QString::fromLatin1("//ole@www.troll.no:9090/index.html?ole=semann&gud=hei#top"); |
|
1582 |
|
1583 QTest::newRow("data10") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1584 << uint(QUrl::RemoveScheme | QUrl::RemoveUserInfo) |
|
1585 << QString::fromLatin1("//www.troll.no:9090/index.html?ole=semann&gud=hei#top"); |
|
1586 |
|
1587 QTest::newRow("data11") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1588 << uint(QUrl::RemoveScheme | QUrl::RemovePort) |
|
1589 << QString::fromLatin1("//ole:password@www.troll.no/index.html?ole=semann&gud=hei#top"); |
|
1590 |
|
1591 QTest::newRow("data12") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1592 << uint(QUrl::RemoveScheme | QUrl::RemoveAuthority) |
|
1593 << QString::fromLatin1("/index.html?ole=semann&gud=hei#top"); |
|
1594 |
|
1595 QTest::newRow("data13") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1596 << uint(QUrl::RemoveScheme | QUrl::RemovePath) |
|
1597 << QString::fromLatin1("//ole:password@www.troll.no:9090?ole=semann&gud=hei#top"); |
|
1598 |
|
1599 QTest::newRow("data14") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1600 << uint(QUrl::RemoveScheme | QUrl::RemoveAuthority | QUrl::RemoveFragment) |
|
1601 << QString::fromLatin1("/index.html?ole=semann&gud=hei"); |
|
1602 |
|
1603 QTest::newRow("data15") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1604 << uint(QUrl::RemoveAuthority | QUrl::RemoveQuery) |
|
1605 << QString::fromLatin1("http:/index.html#top"); |
|
1606 |
|
1607 QTest::newRow("data16") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1608 << uint(QUrl::RemovePassword | QUrl::RemovePort |
|
1609 | QUrl::RemovePath | QUrl::RemoveQuery |
|
1610 | QUrl::RemoveFragment) |
|
1611 << QString::fromLatin1("http://ole@www.troll.no"); |
|
1612 |
|
1613 QTest::newRow("data17") << QString::fromLatin1("http://ole:password@www.troll.no:9090/index.html?ole=semann&gud=hei#top") |
|
1614 << uint(QUrl::RemoveScheme | QUrl::RemovePassword |
|
1615 | QUrl::RemovePort | QUrl::RemovePath |
|
1616 | QUrl::RemoveQuery | QUrl::RemoveFragment) |
|
1617 << QString::fromLatin1("//ole@www.troll.no"); |
|
1618 |
|
1619 QTest::newRow("data18") << QString::fromLatin1("http://andreas:hemmelig@www.vg.no/?my=query&your=query#yougotfragged") |
|
1620 << uint(QUrl::None) |
|
1621 << QString::fromLatin1("http://andreas:hemmelig@www.vg.no/?my=query&your=query#yougotfragged"); |
|
1622 |
|
1623 /* |
|
1624 QTest::newRow("data19") << QString::fromLatin1("http://andreas:hemmelig@www.vg.no/a/../?my=query&your=query#yougotfragged") |
|
1625 << uint(QUrl::None) |
|
1626 << QString::fromLatin1("http://andreas:hemmelig@www.vg.no/?my=query&your=query#yougotfragged"); |
|
1627 */ |
|
1628 |
|
1629 QTest::newRow("nopath_task31320") << QString::fromLatin1("host://protocol") |
|
1630 << uint(QUrl::None) |
|
1631 << QString::fromLatin1("host://protocol"); |
|
1632 } |
|
1633 |
|
1634 void tst_QUrl::toString() |
|
1635 { |
|
1636 QFETCH(QString, urlString); |
|
1637 QFETCH(uint, options); |
|
1638 QFETCH(QString, string); |
|
1639 |
|
1640 QUrl url(urlString); |
|
1641 QCOMPARE(url.toString(QUrl::FormattingOptions(options)), string); |
|
1642 } |
|
1643 |
|
1644 //### more tests ... what do we expect ... |
|
1645 void tst_QUrl::isParentOf_data() |
|
1646 { |
|
1647 QTest::addColumn<QString>("parent"); |
|
1648 QTest::addColumn<QString>("child"); |
|
1649 QTest::addColumn<bool>("trueFalse"); |
|
1650 |
|
1651 QTest::newRow("data0") << QString::fromLatin1("http://a.b.c/d") |
|
1652 << QString::fromLatin1("http://a.b.c/d/e?f") << true; |
|
1653 QTest::newRow("data1") << QString::fromLatin1("http://a.b.c/d") |
|
1654 << QString::fromLatin1("http://a.b.c/d") << false; |
|
1655 QTest::newRow("data2") << QString::fromLatin1("http://a.b.c/d") |
|
1656 << QString::fromLatin1("http://a.b.c/de") << false; |
|
1657 QTest::newRow("data3") << QString::fromLatin1("http://a.b.c/d/") |
|
1658 << QString::fromLatin1("http://a.b.c/de") << false; |
|
1659 QTest::newRow("data4") << QString::fromLatin1("http://a.b.c/d/") |
|
1660 << QString::fromLatin1("http://a.b.c/d/e") << true; |
|
1661 |
|
1662 |
|
1663 } |
|
1664 |
|
1665 void tst_QUrl::toString_constructed_data() |
|
1666 { |
|
1667 QTest::addColumn<QString>("scheme"); |
|
1668 QTest::addColumn<QString>("userName"); |
|
1669 QTest::addColumn<QString>("password"); |
|
1670 QTest::addColumn<QString>("host"); |
|
1671 QTest::addColumn<int>("port"); |
|
1672 QTest::addColumn<QString>("path"); |
|
1673 QTest::addColumn<QByteArray>("query"); |
|
1674 QTest::addColumn<QString>("fragment"); |
|
1675 QTest::addColumn<QString>("asString"); |
|
1676 QTest::addColumn<QByteArray>("asEncoded"); |
|
1677 |
|
1678 QString n(""); |
|
1679 |
|
1680 QTest::newRow("data1") << n << n << n << QString::fromLatin1("qt.nokia.com") << -1 << QString::fromLatin1("index.html") |
|
1681 << QByteArray() << n << QString::fromLatin1("//qt.nokia.com/index.html") |
|
1682 << QByteArray("//qt.nokia.com/index.html"); |
|
1683 QTest::newRow("data2") << QString::fromLatin1("file") << n << n << n << -1 << QString::fromLatin1("/root") << QByteArray() |
|
1684 << n << QString::fromLatin1("file:///root") << QByteArray("file:///root"); |
|
1685 } |
|
1686 |
|
1687 void tst_QUrl::toString_constructed() |
|
1688 { |
|
1689 QFETCH(QString, scheme); |
|
1690 QFETCH(QString, userName); |
|
1691 QFETCH(QString, password); |
|
1692 QFETCH(QString, host); |
|
1693 QFETCH(int, port); |
|
1694 QFETCH(QString, path); |
|
1695 QFETCH(QByteArray, query); |
|
1696 QFETCH(QString, fragment); |
|
1697 QFETCH(QString, asString); |
|
1698 QFETCH(QByteArray, asEncoded); |
|
1699 |
|
1700 QUrl url; |
|
1701 if (!scheme.isEmpty()) |
|
1702 url.setScheme(scheme); |
|
1703 if (!userName.isEmpty()) |
|
1704 url.setUserName(userName); |
|
1705 if (!password.isEmpty()) |
|
1706 url.setPassword(password); |
|
1707 if (!host.isEmpty()) |
|
1708 url.setHost(host); |
|
1709 if (port != -1) |
|
1710 url.setPort(port); |
|
1711 if (!path.isEmpty()) |
|
1712 url.setPath(path); |
|
1713 if (!query.isEmpty()) |
|
1714 url.setEncodedQuery(query); |
|
1715 if (!fragment.isEmpty()) |
|
1716 url.setFragment(fragment); |
|
1717 |
|
1718 QVERIFY(url.isValid()); |
|
1719 QCOMPARE(url.toString(), asString); |
|
1720 QCOMPARE(url.toEncoded(), asEncoded); |
|
1721 } |
|
1722 |
|
1723 |
|
1724 void tst_QUrl::isParentOf() |
|
1725 { |
|
1726 QFETCH(QString, parent); |
|
1727 QFETCH(QString, child); |
|
1728 QFETCH(bool, trueFalse); |
|
1729 |
|
1730 QUrl url(parent); |
|
1731 QCOMPARE(url.isParentOf(QUrl(child)), trueFalse); |
|
1732 } |
|
1733 |
|
1734 void tst_QUrl::toLocalFile_data() |
|
1735 { |
|
1736 QTest::addColumn<QString>("theUrl"); |
|
1737 QTest::addColumn<QString>("theFile"); |
|
1738 |
|
1739 QTest::newRow("data0") << QString::fromLatin1("file:/a.txt") << QString::fromLatin1("/a.txt"); |
|
1740 QTest::newRow("data4") << QString::fromLatin1("file:///a.txt") << QString::fromLatin1("/a.txt"); |
|
1741 QTest::newRow("data5") << QString::fromLatin1("file:///c:/a.txt") << QString::fromLatin1("c:/a.txt"); |
|
1742 QTest::newRow("data6") << QString::fromLatin1("file://somehost/somedir/somefile") << QString::fromLatin1("//somehost/somedir/somefile"); |
|
1743 QTest::newRow("data7") << QString::fromLatin1("file://somehost/") << QString::fromLatin1("//somehost/"); |
|
1744 QTest::newRow("data8") << QString::fromLatin1("file://somehost") << QString::fromLatin1("//somehost"); |
|
1745 QTest::newRow("data9") << QString::fromLatin1("file:////somehost/somedir/somefile") << QString::fromLatin1("//somehost/somedir/somefile"); |
|
1746 |
|
1747 } |
|
1748 |
|
1749 void tst_QUrl::toLocalFile() |
|
1750 { |
|
1751 QFETCH(QString, theUrl); |
|
1752 QFETCH(QString, theFile); |
|
1753 |
|
1754 QUrl url(theUrl); |
|
1755 QCOMPARE(url.toLocalFile(), theFile); |
|
1756 } |
|
1757 |
|
1758 void tst_QUrl::fromLocalFile_data() |
|
1759 { |
|
1760 QTest::addColumn<QString>("theFile"); |
|
1761 QTest::addColumn<QString>("theUrl"); |
|
1762 QTest::addColumn<QString>("thePath"); |
|
1763 |
|
1764 QTest::newRow("data0") << QString::fromLatin1("/a.txt") << QString::fromLatin1("file:///a.txt") << QString::fromLatin1("/a.txt"); |
|
1765 QTest::newRow("data1") << QString::fromLatin1("a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("a.txt"); |
|
1766 QTest::newRow("data2") << QString::fromLatin1("/a/b.txt") << QString::fromLatin1("file:///a/b.txt") << QString::fromLatin1("/a/b.txt"); |
|
1767 QTest::newRow("data3") << QString::fromLatin1("c:/a.txt") << QString::fromLatin1("file:///c:/a.txt") << QString::fromLatin1("/c:/a.txt"); |
|
1768 QTest::newRow("data4") << QString::fromLatin1("//somehost/somedir/somefile") << QString::fromLatin1("file://somehost/somedir/somefile") |
|
1769 << QString::fromLatin1("/somedir/somefile"); |
|
1770 QTest::newRow("data5") << QString::fromLatin1("//somehost") << QString::fromLatin1("file://somehost") |
|
1771 << QString::fromLatin1(""); |
|
1772 QTest::newRow("data6") << QString::fromLatin1("//somehost/") << QString::fromLatin1("file://somehost/") |
|
1773 << QString::fromLatin1("/"); |
|
1774 } |
|
1775 |
|
1776 void tst_QUrl::fromLocalFile() |
|
1777 { |
|
1778 QFETCH(QString, theFile); |
|
1779 QFETCH(QString, theUrl); |
|
1780 QFETCH(QString, thePath); |
|
1781 |
|
1782 QUrl url = QUrl::fromLocalFile(theFile); |
|
1783 |
|
1784 QCOMPARE(url.toString(), theUrl); |
|
1785 QCOMPARE(url.path(), thePath); |
|
1786 } |
|
1787 |
|
1788 void tst_QUrl::compat_legacy() |
|
1789 { |
|
1790 { |
|
1791 QUrl u( "file:bar" ); |
|
1792 QCOMPARE( u.toString(QUrl::RemoveScheme), QString("bar") ); |
|
1793 } |
|
1794 |
|
1795 /* others |
|
1796 */ |
|
1797 { |
|
1798 QUrl u( "http://qt.nokia.com/images/ban/pgs_front.jpg" ); |
|
1799 QCOMPARE( u.path(), QString("/images/ban/pgs_front.jpg") ); |
|
1800 } |
|
1801 { |
|
1802 QUrl tmp( "http://qt.nokia.com/images/ban/" ); |
|
1803 QUrl u = tmp.resolved(QString("pgs_front.jpg")); |
|
1804 QCOMPARE( u.path(), QString("/images/ban/pgs_front.jpg") ); |
|
1805 } |
|
1806 { |
|
1807 QUrl tmp; |
|
1808 QUrl u = tmp.resolved(QString("http://qt.nokia.com/images/ban/pgs_front.jpg")); |
|
1809 QCOMPARE( u.path(), QString("/images/ban/pgs_front.jpg") ); |
|
1810 } |
|
1811 { |
|
1812 QUrl tmp; |
|
1813 QUrl u = tmp.resolved(QString("http://qt.nokia.com/images/ban/pgs_front.jpg")); |
|
1814 QFileInfo fi(u.path()); |
|
1815 u.setPath(fi.path()); |
|
1816 QCOMPARE( u.path(), QString("/images/ban") ); |
|
1817 } |
|
1818 } |
|
1819 |
|
1820 void tst_QUrl::compat_constructor_01_data() |
|
1821 { |
|
1822 QTest::addColumn<QString>("urlStr"); |
|
1823 QTest::addColumn<QString>("res"); |
|
1824 |
|
1825 //next we fill it with data |
|
1826 QTest::newRow( "data0" ) << QString("Makefile") << QString("Makefile"); // nolonger add file by defualt |
|
1827 QTest::newRow( "data1" ) << QString("Makefile") << QString("Makefile"); |
|
1828 QTest::newRow( "data2" ) << QString("ftp://ftp.qt.nokia.com/qt/INSTALL") << QString("ftp://ftp.qt.nokia.com/qt/INSTALL"); |
|
1829 QTest::newRow( "data3" ) << QString("ftp://ftp.qt.nokia.com/qt/INSTALL") << QString("ftp://ftp.qt.nokia.com/qt/INSTALL"); |
|
1830 } |
|
1831 |
|
1832 void tst_QUrl::compat_constructor_01() |
|
1833 { |
|
1834 /* The following should work as expected: |
|
1835 * |
|
1836 * QUrlOperator op; |
|
1837 * op.copy( QString( "Makefile" ), |
|
1838 * QString("ftp://rms:grmpf12@nibbler/home/rms/tmp"), |
|
1839 * false ); |
|
1840 * |
|
1841 * as well as the following: |
|
1842 * |
|
1843 * QUrlOperator op; |
|
1844 * op.copy(QString("ftp://ftp.qt.nokia.com/qt/INSTALL"), "."); |
|
1845 */ |
|
1846 QFETCH( QString, urlStr ); |
|
1847 |
|
1848 { |
|
1849 QUrl empty; |
|
1850 QUrl u = empty.resolved(urlStr); |
|
1851 |
|
1852 QTEST( u.toString(), "res" ); |
|
1853 } |
|
1854 { |
|
1855 QUrl empty; |
|
1856 QUrl u = empty.resolved(urlStr); |
|
1857 |
|
1858 QTEST( u.toString(), "res" ); |
|
1859 } |
|
1860 } |
|
1861 |
|
1862 void tst_QUrl::compat_constructor_02_data() |
|
1863 { |
|
1864 QTest::addColumn<QString>("urlStr"); |
|
1865 QTest::addColumn<QString>("fileName"); |
|
1866 QTest::addColumn<QString>("res"); |
|
1867 |
|
1868 //next we fill it with data |
|
1869 QTest::newRow( "data0" ) << QString("ftp://ftp.qt.nokia.com/qt") << QString("INSTALL") << QString("ftp://ftp.qt.nokia.com/INSTALL"); |
|
1870 QTest::newRow( "data1" ) << QString("ftp://ftp.qt.nokia.com/qt/") << QString("INSTALL") << QString("ftp://ftp.qt.nokia.com/qt/INSTALL"); |
|
1871 } |
|
1872 |
|
1873 void tst_QUrl::compat_constructor_02() |
|
1874 { |
|
1875 /* The following should work as expected: |
|
1876 * |
|
1877 * QUrlOperator op( "ftp://ftp.qt.nokia.com/qt" ); |
|
1878 * op.copy(QString("INSTALL"), "."); |
|
1879 */ |
|
1880 QFETCH( QString, urlStr ); |
|
1881 QFETCH( QString, fileName ); |
|
1882 |
|
1883 QUrl tmp( urlStr ); |
|
1884 QUrl u = tmp.resolved(fileName); |
|
1885 |
|
1886 QTEST( u.toString(), "res" ); |
|
1887 } |
|
1888 |
|
1889 void tst_QUrl::compat_constructor_03_data() |
|
1890 { |
|
1891 QTest::addColumn<QString>("urlStr"); |
|
1892 QTest::addColumn<QString>("res"); |
|
1893 |
|
1894 //next we fill it with data |
|
1895 QTest::newRow( "protocol00" ) << QString( "http://qt.nokia.com/index.html" ) << QString( "http://qt.nokia.com/index.html" ); |
|
1896 QTest::newRow( "protocol01" ) << QString( "http://qt.nokia.com" ) << QString( "http://qt.nokia.com" ); |
|
1897 QTest::newRow( "protocol02" ) << QString( "http://qt.nokia.com/" ) << QString( "http://qt.nokia.com/" ); |
|
1898 QTest::newRow( "protocol03" ) << QString( "http://qt.nokia.com/foo" ) << QString( "http://qt.nokia.com/foo" ); |
|
1899 QTest::newRow( "protocol04" ) << QString( "http://qt.nokia.com/foo/" ) << QString( "http://qt.nokia.com/foo/" ); |
|
1900 QTest::newRow( "protocol05" ) << QString( "ftp://ftp.qt.nokia.com/foo/index.txt" ) << QString( "ftp://ftp.qt.nokia.com/foo/index.txt" ); |
|
1901 |
|
1902 QTest::newRow( "local00" ) << QString( "/foo" ) << QString( "/foo" ); |
|
1903 QTest::newRow( "local01" ) << QString( "/foo/" ) << QString( "/foo/" ); |
|
1904 QTest::newRow( "local02" ) << QString( "/foo/bar" ) << QString( "/foo/bar" ); |
|
1905 QTest::newRow( "local03" ) << QString( "/foo/bar/" ) << QString( "/foo/bar/" ); |
|
1906 QTest::newRow( "local04" ) << QString( "foo" ) << QString( "foo" ); |
|
1907 QTest::newRow( "local05" ) << QString( "foo/" ) << QString( "foo/" ); |
|
1908 QTest::newRow( "local06" ) << QString( "foo/bar" ) << QString( "foo/bar" ); |
|
1909 QTest::newRow( "local07" ) << QString( "foo/bar/" ) << QString( "foo/bar/" ); |
|
1910 QTest::newRow( "local09" ) << QString( "" ) << QString( "" ); |
|
1911 |
|
1912 QTest::newRow( "file00" ) << QString( "file:/foo" ) << QString( "file:///foo" ); |
|
1913 QTest::newRow( "file01" ) << QString( "file:/foo/" ) << QString( "file:///foo/" ); |
|
1914 QTest::newRow( "file02" ) << QString( "file:/foo/bar" ) << QString( "file:///foo/bar" ); |
|
1915 QTest::newRow( "file03" ) << QString( "file:/foo/bar/" ) << QString( "file:///foo/bar/" ); |
|
1916 QTest::newRow( "relProtocol00" ) << QString( "foo:bar" ) << QString( "foo:bar" ); |
|
1917 QTest::newRow( "relProtocol01" ) << QString( "foo:/bar" ) << QString( "foo:/bar" ); |
|
1918 |
|
1919 QTest::newRow( "windowsDrive00" ) << QString( "c:/" ) << QString( "c:/" ); |
|
1920 QTest::newRow( "windowsDrive01" ) << QString( "c:" ) << QString( "c:" ); |
|
1921 QTest::newRow( "windowsDrive02" ) << QString( "c:/WinNT/" ) << QString( "c:/WinNT/" ); |
|
1922 QTest::newRow( "windowsDrive03" ) << QString( "c:/autoexec.bat" ) << QString( "c:/autoexec.bat" ); |
|
1923 QTest::newRow( "windowsDrive04" ) << QString( "c:WinNT/" ) << QString( "c:WinNT/" ); |
|
1924 QTest::newRow( "windowsDrive05" ) << QString( "c:autoexec.bat" ) << QString( "c:autoexec.bat" ); |
|
1925 |
|
1926 QTest::newRow("task31280") << QString("protocol://host") << QString("protocol://host"); |
|
1927 } |
|
1928 |
|
1929 void tst_QUrl::compat_constructor_03() |
|
1930 { |
|
1931 QFETCH( QString, urlStr ); |
|
1932 |
|
1933 QUrl u( urlStr ); |
|
1934 QTEST( u.toString(), "res" ); |
|
1935 } |
|
1936 |
|
1937 void tst_QUrl::compat_isValid_01_data() |
|
1938 { |
|
1939 QTest::addColumn<QString>("urlStr"); |
|
1940 QTest::addColumn<bool>("res"); |
|
1941 |
|
1942 QTest::newRow( "ok_01" ) << QString("ftp://ftp.qt.nokia.com/qt/INSTALL") << (bool)true; |
|
1943 QTest::newRow( "ok_02" ) << QString( "file:/foo") << (bool)true; |
|
1944 QTest::newRow( "ok_03" ) << QString( "file:foo") << (bool)true; |
|
1945 |
|
1946 QTest::newRow( "err_01" ) << QString("#ftp://ftp.qt.nokia.com/qt/INSTALL") << (bool)true; |
|
1947 QTest::newRow( "err_02" ) << QString( "file:/::foo") << (bool)true; |
|
1948 } |
|
1949 |
|
1950 void tst_QUrl::compat_isValid_01() |
|
1951 { |
|
1952 QFETCH( QString, urlStr ); |
|
1953 QFETCH( bool, res ); |
|
1954 |
|
1955 QUrl url( urlStr ); |
|
1956 QVERIFY( url.isValid() == res ); |
|
1957 } |
|
1958 |
|
1959 void tst_QUrl::compat_isValid_02_data() |
|
1960 { |
|
1961 QTest::addColumn<QString>("protocol"); |
|
1962 QTest::addColumn<QString>("user"); |
|
1963 QTest::addColumn<QString>("password"); |
|
1964 QTest::addColumn<QString>("host"); |
|
1965 QTest::addColumn<int>("port"); |
|
1966 QTest::addColumn<QString>("path"); |
|
1967 QTest::addColumn<bool>("res"); |
|
1968 |
|
1969 QString n = ""; |
|
1970 |
|
1971 QTest::newRow( "ok_01" ) << n << n << n << n << -1 << QString("path") << (bool)true; |
|
1972 QTest::newRow( "ok_02" ) << QString("ftp") << n << n << QString("ftp.qt.nokia.com") << -1 << n << (bool)true; |
|
1973 QTest::newRow( "ok_03" ) << QString("ftp") << QString("foo") << n << QString("ftp.qt.nokia.com") << -1 << n << (bool)true; |
|
1974 QTest::newRow( "ok_04" ) << QString("ftp") << QString("foo") << QString("bar") << QString("ftp.qt.nokia.com") << -1 << n << (bool)true; |
|
1975 QTest::newRow( "ok_05" ) << QString("ftp") << n << n << QString("ftp.qt.nokia.com") << -1 << QString("path")<< (bool)true; |
|
1976 QTest::newRow( "ok_06" ) << QString("ftp") << QString("foo") << n << QString("ftp.qt.nokia.com") << -1 << QString("path") << (bool)true; |
|
1977 QTest::newRow( "ok_07" ) << QString("ftp") << QString("foo") << QString("bar") << QString("ftp.qt.nokia.com") << -1 << QString("path")<< (bool)true; |
|
1978 |
|
1979 QTest::newRow( "err_01" ) << n << n << n << n << -1 << n << (bool)false; |
|
1980 QTest::newRow( "err_02" ) << QString("ftp") << n << n << n << -1 << n << (bool)true; |
|
1981 QTest::newRow( "err_03" ) << n << QString("foo") << n << n << -1 << n << (bool)true; |
|
1982 QTest::newRow( "err_04" ) << n << n << QString("bar") << n << -1 << n << (bool)true; |
|
1983 QTest::newRow( "err_05" ) << n << n << n << QString("ftp.qt.nokia.com") << -1 << n << (bool)true; |
|
1984 QTest::newRow( "err_06" ) << n << n << n << n << 80 << n << (bool)true; |
|
1985 QTest::newRow( "err_07" ) << QString("ftp") << QString("foo") << n << n << -1 << n << (bool)true; |
|
1986 QTest::newRow( "err_08" ) << QString("ftp") << n << QString("bar") << n << -1 << n << (bool)true; |
|
1987 QTest::newRow( "err_09" ) << QString("ftp") << QString("foo") << QString("bar") << n << -1 << n << (bool)true; |
|
1988 } |
|
1989 |
|
1990 void tst_QUrl::compat_isValid_02() |
|
1991 { |
|
1992 QFETCH( QString, protocol ); |
|
1993 QFETCH( QString, user ); |
|
1994 QFETCH( QString, password ); |
|
1995 QFETCH( QString, host ); |
|
1996 QFETCH( int, port ); |
|
1997 QFETCH( QString, path ); |
|
1998 QFETCH( bool, res ); |
|
1999 |
|
2000 QUrl url; |
|
2001 if ( !protocol.isEmpty() ) |
|
2002 url.setScheme( protocol ); |
|
2003 if ( !user.isEmpty() ) |
|
2004 url.setUserName( user ); |
|
2005 if ( !password.isEmpty() ) |
|
2006 url.setPassword( password ); |
|
2007 if ( !host.isEmpty() ) |
|
2008 url.setHost( host ); |
|
2009 if ( port != -1 ) |
|
2010 url.setPort( port ); |
|
2011 if ( !path.isEmpty() ) |
|
2012 url.setPath( path ); |
|
2013 |
|
2014 QVERIFY( url.isValid() == res ); |
|
2015 } |
|
2016 |
|
2017 void tst_QUrl::compat_path_data() |
|
2018 { |
|
2019 QTest::addColumn<QString>("url"); |
|
2020 QTest::addColumn<QString>("res"); |
|
2021 |
|
2022 QTest::newRow( "protocol00" ) << "http://qt.nokia.com/images/ban/pgs_front.jpg" << "/images/ban/pgs_front.jpg"; |
|
2023 |
|
2024 #if defined( Q_OS_WIN32 ) |
|
2025 QTest::newRow( "winShare00" ) << "//Anarki/homes" << "/homes"; |
|
2026 #endif |
|
2027 } |
|
2028 |
|
2029 void tst_QUrl::compat_path() |
|
2030 { |
|
2031 QFETCH( QString, url ); |
|
2032 |
|
2033 QUrl u( url ); |
|
2034 QTEST( u.path(), "res" ); |
|
2035 } |
|
2036 |
|
2037 void tst_QUrl::compat_fileName_data() |
|
2038 { |
|
2039 QTest::addColumn<QString>("url"); |
|
2040 QTest::addColumn<QString>("fileName"); |
|
2041 |
|
2042 #ifdef Q_OS_WIN32 |
|
2043 QTest::newRow( "Windows - DrivePathFileName - \\" ) << QString("c:\\windows\\tmp\\filename.txt")<< QString("filename.txt"); |
|
2044 QTest::newRow( "Windows - DrivePathFileName - /" ) << QString("c:/windows/tmp/filename.txt") << QString("filename.txt"); |
|
2045 QTest::newRow( "Windows - DrivePathWithSlash - \\" ) << QString("c:\\windows\\tmp\\") << QString(); |
|
2046 QTest::newRow( "Windows - DrivePathWithSlash - /" ) << QString("c:/windows/tmp/") << QString(); |
|
2047 QTest::newRow( "Windows - DrivePathWithoutSlash - \\" ) << QString("c:/windows/tmp") << QString("tmp"); |
|
2048 QTest::newRow( "Windows - DrivePathWithoutSlash - /" ) << QString("c:/windows/tmp") << QString("tmp"); |
|
2049 #endif |
|
2050 QTest::newRow( "Path00" ) << QString("/") << QString(); |
|
2051 QTest::newRow( "Path01" ) << QString("/home/dev/test/") << QString(); |
|
2052 QTest::newRow( "PathFileName00" ) << QString("/home/dev/test") << QString("test"); |
|
2053 } |
|
2054 |
|
2055 void tst_QUrl::compat_fileName() |
|
2056 { |
|
2057 QFETCH( QString, url ); |
|
2058 QFETCH( QString, fileName ); |
|
2059 QUrl fileUrl = QUrl::fromLocalFile(url); |
|
2060 QFileInfo fi(fileUrl.toLocalFile()); |
|
2061 QCOMPARE( fi.fileName(), fileName ); |
|
2062 } |
|
2063 |
|
2064 void tst_QUrl::compat_decode_data() |
|
2065 { |
|
2066 QTest::addColumn<QByteArray>("encodedString"); |
|
2067 QTest::addColumn<QString>("decodedString"); |
|
2068 |
|
2069 QTest::newRow("NormalString") << QByteArray("filename") << QString("filename"); |
|
2070 QTest::newRow("NormalStringEncoded") << QByteArray("file%20name") << QString("file name"); |
|
2071 QTest::newRow("JustEncoded") << QByteArray("%20") << QString(" "); |
|
2072 QTest::newRow("HTTPUrl") << QByteArray("http://qt.nokia.com") << QString("http://qt.nokia.com"); |
|
2073 QTest::newRow("HTTPUrlEncoded") << QByteArray("http://qt%20nokia%20com") << QString("http://qt nokia com"); |
|
2074 QTest::newRow("EmptyString") << QByteArray("") << QString(""); |
|
2075 QTest::newRow("Task27166") << QByteArray("Fran%C3%A7aise") << QString("Française"); |
|
2076 } |
|
2077 |
|
2078 void tst_QUrl::compat_decode() |
|
2079 { |
|
2080 QFETCH(QByteArray, encodedString); |
|
2081 QFETCH(QString, decodedString); |
|
2082 |
|
2083 QCOMPARE(QUrl::fromPercentEncoding(encodedString), decodedString); |
|
2084 } |
|
2085 |
|
2086 void tst_QUrl::compat_encode_data() |
|
2087 { |
|
2088 QTest::addColumn<QString>("decodedString"); |
|
2089 QTest::addColumn<QByteArray>("encodedString"); |
|
2090 |
|
2091 QTest::newRow("NormalString") << QString("filename") << QByteArray("filename"); |
|
2092 QTest::newRow("NormalStringEncoded") << QString("file name") << QByteArray("file%20name"); |
|
2093 QTest::newRow("JustEncoded") << QString(" ") << QByteArray("%20"); |
|
2094 QTest::newRow("HTTPUrl") << QString("http://qt.nokia.com") << QByteArray("http%3A//qt.nokia.com"); |
|
2095 QTest::newRow("HTTPUrlEncoded") << QString("http://qt nokia com") << QByteArray("http%3A//qt%20nokia%20com"); |
|
2096 QTest::newRow("EmptyString") << QString("") << QByteArray(""); |
|
2097 QTest::newRow("Task27166") << QString::fromLatin1("Française") << QByteArray("Fran%C3%A7aise"); |
|
2098 } |
|
2099 |
|
2100 void tst_QUrl::compat_encode() |
|
2101 { |
|
2102 QFETCH(QString, decodedString); |
|
2103 QFETCH(QByteArray, encodedString); |
|
2104 |
|
2105 QCOMPARE(QUrl::toPercentEncoding(decodedString, "/.").constData(), encodedString.constData()); |
|
2106 } |
|
2107 |
|
2108 |
|
2109 void tst_QUrl::relative() |
|
2110 { |
|
2111 QUrl url("../ole"); |
|
2112 QCOMPARE(url.path(), QString::fromLatin1("../ole")); |
|
2113 |
|
2114 QUrl url2("./"); |
|
2115 QCOMPARE(url2.path(), QString::fromLatin1("./")); |
|
2116 |
|
2117 QUrl url3(".."); |
|
2118 QCOMPARE(url3.path(), QString::fromLatin1("..")); |
|
2119 |
|
2120 QUrl url4("../.."); |
|
2121 QCOMPARE(url4.path(), QString::fromLatin1("../..")); |
|
2122 } |
|
2123 |
|
2124 void tst_QUrl::percentEncoding_data() |
|
2125 { |
|
2126 QTest::addColumn<QString>("original"); |
|
2127 QTest::addColumn<QByteArray>("encoded"); |
|
2128 |
|
2129 QTest::newRow("test_01") << QString::fromLatin1("sdfsdf") << QByteArray("sdfsdf"); |
|
2130 QTest::newRow("test_02") << QString::fromLatin1("æss") << QByteArray("%C3%A6ss"); |
|
2131 // not unreserved or reserved |
|
2132 QTest::newRow("test_03") << QString::fromLatin1("{}") << QByteArray("%7B%7D"); |
|
2133 } |
|
2134 |
|
2135 void tst_QUrl::percentEncoding() |
|
2136 { |
|
2137 QFETCH(QString, original); |
|
2138 QFETCH(QByteArray, encoded); |
|
2139 |
|
2140 QCOMPARE(QUrl(original).toEncoded().constData(), encoded.constData()); |
|
2141 QVERIFY(QUrl::fromEncoded(QUrl(original).toEncoded()) == QUrl(original)); |
|
2142 QCOMPARE(QUrl::fromEncoded(QUrl(original).toEncoded()).toString(), original); |
|
2143 QVERIFY(QUrl::fromEncoded(encoded) == QUrl(original)); |
|
2144 } |
|
2145 |
|
2146 void tst_QUrl::toPercentEncoding_data() |
|
2147 { |
|
2148 QTest::addColumn<QString>("original"); |
|
2149 QTest::addColumn<QByteArray>("encoded"); |
|
2150 QTest::addColumn<QByteArray>("excludeInEncoding"); |
|
2151 QTest::addColumn<QByteArray>("includeInEncoding"); |
|
2152 |
|
2153 QTest::newRow("test_01") << QString::fromLatin1("abcdevghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678-._~") |
|
2154 << QByteArray("abcdevghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678-._~") |
|
2155 << QByteArray("") |
|
2156 << QByteArray(""); |
|
2157 QTest::newRow("test_02") << QString::fromLatin1("{\t\n\r^\"abc}") |
|
2158 << QByteArray("%7B%09%0A%0D%5E%22abc%7D") |
|
2159 << QByteArray("") |
|
2160 << QByteArray(""); |
|
2161 QTest::newRow("test_03") << QString::fromLatin1("://?#[]@!$&'()*+,;=") |
|
2162 << QByteArray("%3A%2F%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D") |
|
2163 << QByteArray("") |
|
2164 << QByteArray(""); |
|
2165 QTest::newRow("test_04") << QString::fromLatin1("://?#[]@!$&'()*+,;=") |
|
2166 << QByteArray("%3A%2F%2F%3F%23%5B%5D%40!$&'()*+,;=") |
|
2167 << QByteArray("!$&'()*+,;=") |
|
2168 << QByteArray(""); |
|
2169 QTest::newRow("test_05") << QString::fromLatin1("abcd") |
|
2170 << QByteArray("a%62%63d") |
|
2171 << QByteArray("") |
|
2172 << QByteArray("bc"); |
|
2173 } |
|
2174 |
|
2175 void tst_QUrl::toPercentEncoding() |
|
2176 { |
|
2177 QFETCH(QString, original); |
|
2178 QFETCH(QByteArray, encoded); |
|
2179 QFETCH(QByteArray, excludeInEncoding); |
|
2180 QFETCH(QByteArray, includeInEncoding); |
|
2181 |
|
2182 QByteArray encodedUrl = QUrl::toPercentEncoding(original, excludeInEncoding, includeInEncoding); |
|
2183 QCOMPARE(encodedUrl.constData(), encoded.constData()); |
|
2184 QCOMPARE(original, QUrl::fromPercentEncoding(encodedUrl)); |
|
2185 } |
|
2186 |
|
2187 void tst_QUrl::symmetry() |
|
2188 { |
|
2189 QUrl url(QString::fromLatin1("http://www.räksmörgås.se/pub?a=b&a=dø&a=f#vræl")); |
|
2190 QCOMPARE(url.scheme(), QString::fromLatin1("http")); |
|
2191 QCOMPARE(url.host(), QString::fromLatin1("www.räksmörgås.se")); |
|
2192 QCOMPARE(url.path(), QString::fromLatin1("/pub")); |
|
2193 // this will be encoded ... |
|
2194 QCOMPARE(url.encodedQuery().constData(), QString::fromLatin1("a=b&a=d%C3%B8&a=f").toLatin1().constData()); |
|
2195 // unencoded |
|
2196 QCOMPARE(url.allQueryItemValues("a").join("").toLatin1().constData(), "bdøf"); |
|
2197 QCOMPARE(url.fragment(), QString::fromLatin1("vræl")); |
|
2198 |
|
2199 QUrl onlyHost("//qt.nokia.com"); |
|
2200 QCOMPARE(onlyHost.toString(), QString::fromLatin1("//qt.nokia.com")); |
|
2201 |
|
2202 { |
|
2203 QString urlString = QString::fromLatin1("http://desktop:33326/upnp/{32f525a6-6f31-426e-91ca-01c2e6c2c57e}"); |
|
2204 QUrl urlPreviewList(urlString); |
|
2205 QCOMPARE(urlPreviewList.toString(), urlString); |
|
2206 QByteArray b = urlPreviewList.toEncoded(); |
|
2207 QCOMPARE(b.constData(), "http://desktop:33326/upnp/%7B32f525a6-6f31-426e-91ca-01c2e6c2c57e%7D"); |
|
2208 QCOMPARE(QUrl::fromEncoded(b).toString(), urlString); |
|
2209 |
|
2210 }{ |
|
2211 QString urlString = QString::fromLatin1("http://desktop:53423/deviceDescription?uuid={7977c17b-00bf-4af9-894e-fed28573c3a9}"); |
|
2212 QUrl urlPreviewList(urlString); |
|
2213 QCOMPARE(urlPreviewList.toString(), urlString); |
|
2214 QByteArray b = urlPreviewList.toEncoded(); |
|
2215 QCOMPARE(b.constData(), "http://desktop:53423/deviceDescription?uuid=%7B7977c17b-00bf-4af9-894e-fed28573c3a9%7D"); |
|
2216 QCOMPARE(QUrl::fromEncoded(b).toString(), urlString); |
|
2217 } |
|
2218 } |
|
2219 |
|
2220 |
|
2221 void tst_QUrl::ipv6_data() |
|
2222 { |
|
2223 QTest::addColumn<QString>("ipv6Auth"); |
|
2224 QTest::addColumn<bool>("isValid"); |
|
2225 |
|
2226 QTest::newRow("case 1") << QString::fromLatin1("//[56:56:56:56:56:56:56:56]") << true; |
|
2227 QTest::newRow("case 2") << QString::fromLatin1("//[::56:56:56:56:56:56:56]") << true; |
|
2228 QTest::newRow("case 3") << QString::fromLatin1("//[56::56:56:56:56:56:56]") << true; |
|
2229 QTest::newRow("case 4") << QString::fromLatin1("//[56:56::56:56:56:56:56]") << true; |
|
2230 QTest::newRow("case 5") << QString::fromLatin1("//[56:56:56::56:56:56:56]") << true; |
|
2231 QTest::newRow("case 6") << QString::fromLatin1("//[56:56:56:56::56:56:56]") << true; |
|
2232 QTest::newRow("case 7") << QString::fromLatin1("//[56:56:56:56:56::56:56]") << true; |
|
2233 QTest::newRow("case 8") << QString::fromLatin1("//[56:56:56:56:56:56::56]") << true; |
|
2234 QTest::newRow("case 9") << QString::fromLatin1("//[56:56:56:56:56:56:56::]") << true; |
|
2235 QTest::newRow("case 4 with one less") << QString::fromLatin1("//[56::56:56:56:56:56]") << true; |
|
2236 QTest::newRow("case 4 with less and ip4") << QString::fromLatin1("//[56::56:56:56:127.0.0.1]") << true; |
|
2237 QTest::newRow("case 7 with one and ip4") << QString::fromLatin1("//[56::255.0.0.0]") << true; |
|
2238 QTest::newRow("case 2 with ip4") << QString::fromLatin1("//[::56:56:56:56:56:0.0.0.255]") << true; |
|
2239 QTest::newRow("case 2 with half ip4") << QString::fromLatin1("//[::56:56:56:56:56:56:0.255]") << false; |
|
2240 QTest::newRow("case 4 with less and ip4 and port and useinfo") << QString::fromLatin1("//user:pass@[56::56:56:56:127.0.0.1]:99") << true; |
|
2241 QTest::newRow("case :,") << QString::fromLatin1("//[:,]") << false; |
|
2242 QTest::newRow("case ::bla") << QString::fromLatin1("//[::bla]") << false; |
|
2243 } |
|
2244 |
|
2245 void tst_QUrl::ipv6() |
|
2246 { |
|
2247 QFETCH(QString, ipv6Auth); |
|
2248 QFETCH(bool, isValid); |
|
2249 |
|
2250 QUrl url(ipv6Auth); |
|
2251 |
|
2252 QCOMPARE(url.isValid(), isValid); |
|
2253 if (url.isValid()) { |
|
2254 QCOMPARE(url.toString(), ipv6Auth); |
|
2255 } |
|
2256 }; |
|
2257 |
|
2258 void tst_QUrl::ipv6_2_data() |
|
2259 { |
|
2260 QTest::addColumn<QString>("input"); |
|
2261 QTest::addColumn<QString>("output"); |
|
2262 |
|
2263 QTest::newRow("[::ffff:129.144.52.38]") |
|
2264 << QString("http://[::ffff:129.144.52.38]/cgi/test.cgi") |
|
2265 << QString("http://[::ffff:129.144.52.38]/cgi/test.cgi"); |
|
2266 QTest::newRow("[::FFFF:129.144.52.38]") |
|
2267 << QString("http://[::FFFF:129.144.52.38]/cgi/test.cgi") |
|
2268 << QString("http://[::ffff:129.144.52.38]/cgi/test.cgi"); |
|
2269 } |
|
2270 |
|
2271 void tst_QUrl::ipv6_2() |
|
2272 { |
|
2273 QFETCH(QString, input); |
|
2274 QFETCH(QString, output); |
|
2275 |
|
2276 QUrl url(input); |
|
2277 QCOMPARE(url.toString(), output); |
|
2278 } |
|
2279 |
|
2280 void tst_QUrl::moreIpv6() |
|
2281 { |
|
2282 QUrl waba1("http://www.kde.org/cgi/test.cgi"); |
|
2283 waba1.setHost("::ffff:129.144.52.38"); |
|
2284 QCOMPARE(QString::fromLatin1(waba1.toEncoded()), QString::fromLatin1("http://[::ffff:129.144.52.38]/cgi/test.cgi")); |
|
2285 } |
|
2286 |
|
2287 void tst_QUrl::punycode_data() |
|
2288 { |
|
2289 QTest::addColumn<QString>("original"); |
|
2290 QTest::addColumn<QByteArray>("encoded"); |
|
2291 |
|
2292 QTest::newRow("øl") << QString::fromLatin1("øl") << QByteArray("xn--l-4ga"); |
|
2293 QTest::newRow("Bühler") << QString::fromLatin1("Bühler") << QByteArray("xn--Bhler-kva"); |
|
2294 QTest::newRow("räksmörgås") << QString::fromLatin1("räksmörgås") << QByteArray("xn--rksmrgs-5wao1o"); |
|
2295 } |
|
2296 |
|
2297 void tst_QUrl::punycode() |
|
2298 { |
|
2299 QFETCH(QString, original); |
|
2300 QFETCH(QByteArray, encoded); |
|
2301 |
|
2302 QCOMPARE(QUrl::fromPunycode(encoded), original); |
|
2303 QCOMPARE(QUrl::fromPunycode(QUrl::toPunycode(original)), original); |
|
2304 QCOMPARE(QUrl::toPunycode(original).constData(), encoded.constData()); |
|
2305 } |
|
2306 |
|
2307 void tst_QUrl::isRelative_data() |
|
2308 { |
|
2309 QTest::addColumn<QString>("url"); |
|
2310 QTest::addColumn<bool>("trueFalse"); |
|
2311 |
|
2312 QTest::newRow("not") << QString::fromLatin1("http://qt.nokia.com") << false; |
|
2313 QTest::newRow("55288") << QString::fromLatin1("node64.html#fig:form:ana") << true; |
|
2314 |
|
2315 // kde |
|
2316 QTest::newRow("mailto: URL, is relative") << "mailto:faure@kde.org" << false; |
|
2317 QTest::newRow("man: URL, is relative") << "man:mmap" << false; |
|
2318 QTest::newRow("javascript: URL, is relative") << "javascript:doSomething()" << false; |
|
2319 QTest::newRow("file: URL, is relative") << "file:/blah" << false; |
|
2320 QTest::newRow("/path, is relative") << "/path" << true; |
|
2321 QTest::newRow("something, is relative") << "something" << true; |
|
2322 // end kde |
|
2323 } |
|
2324 |
|
2325 void tst_QUrl::isRelative() |
|
2326 { |
|
2327 QFETCH(QString, url); |
|
2328 QFETCH(bool, trueFalse); |
|
2329 |
|
2330 QCOMPARE(QUrl(url).isRelative(), trueFalse); |
|
2331 } |
|
2332 |
|
2333 void tst_QUrl::queryItems() |
|
2334 { |
|
2335 QUrl url; |
|
2336 QVERIFY(!url.hasQuery()); |
|
2337 |
|
2338 QList<QPair<QString, QString> > newItems; |
|
2339 newItems += qMakePair(QString("2"), QString("b")); |
|
2340 newItems += qMakePair(QString("1"), QString("a")); |
|
2341 newItems += qMakePair(QString("3"), QString("c")); |
|
2342 newItems += qMakePair(QString("4"), QString("a b")); |
|
2343 newItems += qMakePair(QString("5"), QString("&")); |
|
2344 newItems += qMakePair(QString("foo bar"), QString("hello world")); |
|
2345 newItems += qMakePair(QString("foo+bar"), QString("hello+world")); |
|
2346 newItems += qMakePair(QString("tex"), QString("a + b = c")); |
|
2347 url.setQueryItems(newItems); |
|
2348 QVERIFY(url.hasQuery()); |
|
2349 |
|
2350 QList<QPair<QString, QString> > setItems = url.queryItems(); |
|
2351 QVERIFY(newItems == setItems); |
|
2352 |
|
2353 url.addQueryItem("1", "z"); |
|
2354 |
|
2355 QVERIFY(url.hasQueryItem("1")); |
|
2356 QCOMPARE(url.queryItemValue("1").toLatin1().constData(), "a"); |
|
2357 |
|
2358 url.addQueryItem("1", "zz"); |
|
2359 |
|
2360 QStringList expected; |
|
2361 expected += "a"; |
|
2362 expected += "z"; |
|
2363 expected += "zz"; |
|
2364 QCOMPARE(expected, url.allQueryItemValues("1")); |
|
2365 |
|
2366 url.removeQueryItem("1"); |
|
2367 QCOMPARE(url.allQueryItemValues("1").size(), 2); |
|
2368 QCOMPARE(url.queryItemValue("1").toLatin1().constData(), "z"); |
|
2369 |
|
2370 url.removeAllQueryItems("1"); |
|
2371 QVERIFY(!url.hasQueryItem("1")); |
|
2372 |
|
2373 QCOMPARE(url.queryItemValue("4").toLatin1().constData(), "a b"); |
|
2374 QCOMPARE(url.queryItemValue("5").toLatin1().constData(), "&"); |
|
2375 QCOMPARE(url.queryItemValue("tex").toLatin1().constData(), "a + b = c"); |
|
2376 QCOMPARE(url.queryItemValue("foo bar").toLatin1().constData(), "hello world"); |
|
2377 url.setUrl("http://www.google.com/search?q=a+b"); |
|
2378 QCOMPARE(url.queryItemValue("q"), QString("a+b")); |
|
2379 url.setUrl("http://www.google.com/search?q=a=b"); // invalid, but should be tolerated |
|
2380 QCOMPARE(url.queryItemValue("q"), QString("a=b")); |
|
2381 } |
|
2382 |
|
2383 void tst_QUrl::hasQuery_data() |
|
2384 { |
|
2385 QTest::addColumn<QString>("url"); |
|
2386 QTest::addColumn<bool>("trueFalse"); |
|
2387 |
|
2388 QTest::newRow("no query items") << "http://www.foo.bar" << false; |
|
2389 |
|
2390 QTest::newRow("empty query") << "http://www.foo.bar?" << true; |
|
2391 QTest::newRow("empty query 2") << "http://www.foo.bar/?" << true; |
|
2392 |
|
2393 QTest::newRow("query") << "http://www.foo.bar?query" << true; |
|
2394 QTest::newRow("query=") << "http://www.foo.bar?query=" << true; |
|
2395 QTest::newRow("query=value") << "http://www.foo.bar?query=value" << true; |
|
2396 |
|
2397 QTest::newRow("%3f") << "http://www.foo.bar/file%3f" << false; |
|
2398 QTest::newRow("%3f-query") << "http://www.foo.bar/file%3fquery" << false; |
|
2399 QTest::newRow("%3f-query=value") << "http://www.foo.bar/file%3fquery=value" << false; |
|
2400 } |
|
2401 |
|
2402 void tst_QUrl::hasQuery() |
|
2403 { |
|
2404 QFETCH(QString, url); |
|
2405 QFETCH(bool, trueFalse); |
|
2406 |
|
2407 QUrl qurl(url); |
|
2408 QCOMPARE(qurl.hasQuery(), trueFalse); |
|
2409 QCOMPARE(qurl.encodedQuery().isNull(), !trueFalse); |
|
2410 } |
|
2411 |
|
2412 void tst_QUrl::hasQueryItem_data() |
|
2413 { |
|
2414 QTest::addColumn<QString>("url"); |
|
2415 QTest::addColumn<QString>("item"); |
|
2416 QTest::addColumn<bool>("trueFalse"); |
|
2417 |
|
2418 QTest::newRow("no query items") << "http://www.foo.bar" << "baz" << false; |
|
2419 QTest::newRow("query item: hello") << "http://www.foo.bar?hello=world" << "hello" << true; |
|
2420 QTest::newRow("no query item: world") << "http://www.foo.bar?hello=world" << "world" << false; |
|
2421 QTest::newRow("query item: qt") << "http://www.foo.bar?hello=world&qt=rocks" << "qt" << true; |
|
2422 } |
|
2423 |
|
2424 void tst_QUrl::hasQueryItem() |
|
2425 { |
|
2426 QFETCH(QString, url); |
|
2427 QFETCH(QString, item); |
|
2428 QFETCH(bool, trueFalse); |
|
2429 |
|
2430 QCOMPARE(QUrl(url).hasQueryItem(item), trueFalse); |
|
2431 } |
|
2432 |
|
2433 void tst_QUrl::nameprep() |
|
2434 { |
|
2435 QUrl url(QString::fromUtf8("http://www.fu""\xc3""\x9f""ball.de/")); |
|
2436 QCOMPARE(url.toString(), QString::fromLatin1("http://www.fussball.de/")); |
|
2437 } |
|
2438 |
|
2439 void tst_QUrl::isValid() |
|
2440 { |
|
2441 { |
|
2442 QUrl url(QString("A=B")); |
|
2443 QVERIFY(url.isValid()); |
|
2444 QCOMPARE(url.path(), QString("A=B")); |
|
2445 } |
|
2446 { |
|
2447 QUrl url = QUrl::fromEncoded("http://strange<username>@ok-hostname/", QUrl::StrictMode); |
|
2448 QVERIFY(!url.isValid()); |
|
2449 // < and > are not allowed in userinfo in strict mode |
|
2450 } |
|
2451 { |
|
2452 QUrl url = QUrl::fromEncoded("http://strange<username>@ok-hostname/"); |
|
2453 QVERIFY(url.isValid()); |
|
2454 // < and > are allowed in tolerant mode |
|
2455 } |
|
2456 { |
|
2457 QUrl url = QUrl::fromEncoded("http://strange;hostname/here"); |
|
2458 QVERIFY(!url.isValid()); |
|
2459 QCOMPARE(url.path(), QString("/here")); |
|
2460 } |
|
2461 } |
|
2462 |
|
2463 void tst_QUrl::schemeValidator_data() |
|
2464 { |
|
2465 QTest::addColumn<QByteArray>("encodedUrl"); |
|
2466 QTest::addColumn<bool>("result"); |
|
2467 QTest::addColumn<QString>("toString"); |
|
2468 |
|
2469 QTest::newRow("empty") << QByteArray() << false << QString(); |
|
2470 |
|
2471 // ftp |
|
2472 QTest::newRow("ftp:") << QByteArray("ftp:") << true << QString("ftp:"); |
|
2473 QTest::newRow("ftp://ftp.qt.nokia.com") |
|
2474 << QByteArray("ftp://ftp.qt.nokia.com") |
|
2475 << true << QString("ftp://ftp.qt.nokia.com"); |
|
2476 QTest::newRow("ftp://ftp.qt.nokia.com/") |
|
2477 << QByteArray("ftp://ftp.qt.nokia.com/") |
|
2478 << true << QString("ftp://ftp.qt.nokia.com/"); |
|
2479 QTest::newRow("ftp:/index.html") |
|
2480 << QByteArray("ftp:/index.html") |
|
2481 << false << QString(); |
|
2482 |
|
2483 // mailto |
|
2484 QTest::newRow("mailto:") << QByteArray("mailto:") << true << QString("mailto:"); |
|
2485 QTest::newRow("mailto://smtp.trolltech.com/ole@bull.name") |
|
2486 << QByteArray("mailto://smtp.trolltech.com/ole@bull.name") << false << QString(); |
|
2487 QTest::newRow("mailto:") << QByteArray("mailto:") << true << QString("mailto:"); |
|
2488 QTest::newRow("mailto:ole@bull.name") |
|
2489 << QByteArray("mailto:ole@bull.name") << true << QString("mailto:ole@bull.name"); |
|
2490 |
|
2491 // file |
|
2492 QTest::newRow("file:") << QByteArray("file:/etc/passwd") << true << QString("file:///etc/passwd"); |
|
2493 } |
|
2494 |
|
2495 void tst_QUrl::schemeValidator() |
|
2496 { |
|
2497 QFETCH(QByteArray, encodedUrl); |
|
2498 QFETCH(bool, result); |
|
2499 QFETCH(QString, toString); |
|
2500 |
|
2501 QUrl url = QUrl::fromEncoded(encodedUrl); |
|
2502 QCOMPARE(url.isValid(), result); |
|
2503 } |
|
2504 |
|
2505 void tst_QUrl::invalidSchemeValidator() |
|
2506 { |
|
2507 // enable that test when QUrl is fixed |
|
2508 return; |
|
2509 |
|
2510 // test that if scheme does not start with an ALPHA, QUrl::isValid() returns false |
|
2511 { |
|
2512 QUrl url("1http://qt.nokia.com", QUrl::StrictMode); |
|
2513 qDebug() << url; |
|
2514 QCOMPARE(url.isValid(), false); |
|
2515 } |
|
2516 { |
|
2517 QUrl url("http://qt.nokia.com"); |
|
2518 url.setScheme("111http://qt.nokia.com"); |
|
2519 QCOMPARE(url.isValid(), false); |
|
2520 } |
|
2521 { |
|
2522 QUrl url = QUrl::fromEncoded("1http://qt.nokia.com", QUrl::StrictMode); |
|
2523 QCOMPARE(url.isValid(), false); |
|
2524 } |
|
2525 |
|
2526 // non-ALPHA character at other positions in the scheme are ok |
|
2527 { |
|
2528 QUrl url("ht111tp://qt.nokia.com", QUrl::StrictMode); |
|
2529 QVERIFY(url.isValid()); |
|
2530 } |
|
2531 { |
|
2532 QUrl url("http://qt.nokia.com"); |
|
2533 url.setScheme("ht123tp://qt.nokia.com"); |
|
2534 QVERIFY(url.isValid()); |
|
2535 } |
|
2536 { |
|
2537 QUrl url = QUrl::fromEncoded("ht321tp://qt.nokia.com", QUrl::StrictMode); |
|
2538 QVERIFY(url.isValid()); |
|
2539 } |
|
2540 } |
|
2541 |
|
2542 void tst_QUrl::tolerantParser() |
|
2543 { |
|
2544 { |
|
2545 QUrl url("http://www.example.com/path%20with spaces.html"); |
|
2546 QVERIFY(url.isValid()); |
|
2547 QCOMPARE(url.path(), QString("/path with spaces.html")); |
|
2548 QCOMPARE(url.toEncoded(), QByteArray("http://www.example.com/path%20with%20spaces.html")); |
|
2549 url.setUrl("http://www.example.com/path%20with spaces.html", QUrl::StrictMode); |
|
2550 QVERIFY(url.isValid()); |
|
2551 QCOMPARE(url.toEncoded(), QByteArray("http://www.example.com/path%2520with%20spaces.html")); |
|
2552 } |
|
2553 { |
|
2554 QUrl url = QUrl::fromEncoded("http://www.example.com/path%20with spaces.html"); |
|
2555 QVERIFY(url.isValid()); |
|
2556 QCOMPARE(url.path(), QString("/path with spaces.html")); |
|
2557 url.setEncodedUrl("http://www.example.com/path%20with spaces.html", QUrl::StrictMode); |
|
2558 QVERIFY(!url.isValid()); |
|
2559 } |
|
2560 |
|
2561 { |
|
2562 QUrl url15581("http://alain.knaff.linux.lu/bug-reports/kde/percentage%in%url.htm>"); |
|
2563 QVERIFY(url15581.isValid()); |
|
2564 QCOMPARE(url15581.toEncoded().constData(), "http://alain.knaff.linux.lu/bug-reports/kde/percentage%25in%25url.htm%3E"); |
|
2565 } |
|
2566 |
|
2567 { |
|
2568 QUrl webkit22616 = |
|
2569 QUrl::fromEncoded("http://example.com/testya.php?browser-info=s:1400x1050x24:f:9.0%20r152:t:%u0442%u0435%u0441%u0442"); |
|
2570 QVERIFY(webkit22616.isValid()); |
|
2571 QCOMPARE(webkit22616.toEncoded().constData(), |
|
2572 "http://example.com/testya.php?browser-info=s:1400x1050x24:f:9.0%20r152:t:%25u0442%25u0435%25u0441%25u0442"); |
|
2573 } |
|
2574 |
|
2575 { |
|
2576 QUrl url; |
|
2577 url.setUrl("http://foo.bar/[image][1].jpg"); |
|
2578 QVERIFY(url.isValid()); |
|
2579 QCOMPARE(url.toEncoded(), QByteArray("http://foo.bar/%5Bimage%5D%5B1%5D.jpg")); |
|
2580 |
|
2581 url.setUrl("[].jpg"); |
|
2582 QCOMPARE(url.toEncoded(), QByteArray("%5B%5D.jpg")); |
|
2583 |
|
2584 url.setUrl("/some/[path]/[]"); |
|
2585 QCOMPARE(url.toEncoded(), QByteArray("/some/%5Bpath%5D/%5B%5D")); |
|
2586 |
|
2587 url.setUrl("//[::56:56:56:56:56:56:56]"); |
|
2588 QCOMPARE(url.toEncoded(), QByteArray("//[::56:56:56:56:56:56:56]")); |
|
2589 |
|
2590 url.setUrl("//[::56:56:56:56:56:56:56]#[]"); |
|
2591 QCOMPARE(url.toEncoded(), QByteArray("//[::56:56:56:56:56:56:56]#%5B%5D")); |
|
2592 |
|
2593 url.setUrl("//[::56:56:56:56:56:56:56]?[]"); |
|
2594 QCOMPARE(url.toEncoded(), QByteArray("//[::56:56:56:56:56:56:56]?%5B%5D")); |
|
2595 |
|
2596 url.setUrl("%hello.com/f%"); |
|
2597 QCOMPARE(url.toEncoded(), QByteArray("%25hello.com/f%25")); |
|
2598 |
|
2599 url.setEncodedUrl("http://www.host.com/foo.php?P0=[2006-3-8]"); |
|
2600 QVERIFY(url.isValid()); |
|
2601 |
|
2602 url.setEncodedUrl("http://foo.bar/[image][1].jpg"); |
|
2603 QVERIFY(url.isValid()); |
|
2604 QCOMPARE(url.toEncoded(), QByteArray("http://foo.bar/%5Bimage%5D%5B1%5D.jpg")); |
|
2605 |
|
2606 url.setEncodedUrl("[].jpg"); |
|
2607 QCOMPARE(url.toEncoded(), QByteArray("%5B%5D.jpg")); |
|
2608 |
|
2609 url.setEncodedUrl("/some/[path]/[]"); |
|
2610 QCOMPARE(url.toEncoded(), QByteArray("/some/%5Bpath%5D/%5B%5D")); |
|
2611 |
|
2612 url.setEncodedUrl("//[::56:56:56:56:56:56:56]"); |
|
2613 QCOMPARE(url.toEncoded(), QByteArray("//[::56:56:56:56:56:56:56]")); |
|
2614 |
|
2615 url.setEncodedUrl("//[::56:56:56:56:56:56:56]#[]"); |
|
2616 QCOMPARE(url.toEncoded(), QByteArray("//[::56:56:56:56:56:56:56]#%5B%5D")); |
|
2617 |
|
2618 url.setEncodedUrl("//[::56:56:56:56:56:56:56]?[]"); |
|
2619 QCOMPARE(url.toEncoded(), QByteArray("//[::56:56:56:56:56:56:56]?%5B%5D")); |
|
2620 |
|
2621 url.setEncodedUrl("data:text/css,div%20{%20border-right:%20solid;%20}"); |
|
2622 QCOMPARE(url.toEncoded(), QByteArray("data:text/css,div%20%7B%20border-right:%20solid;%20%7D")); |
|
2623 } |
|
2624 |
|
2625 { |
|
2626 // task 243557 |
|
2627 QByteArray tsdgeos("http://google.com/c?c=Translation+%C2%BB+trunk|"); |
|
2628 QUrl tsdgeosQUrl; |
|
2629 tsdgeosQUrl.setEncodedUrl(tsdgeos, QUrl::TolerantMode); |
|
2630 QVERIFY(tsdgeosQUrl.isValid()); // failed in Qt-4.4, works in Qt-4.5 |
|
2631 QByteArray tsdgeosExpected("http://google.com/c?c=Translation+%C2%BB+trunk%7C"); |
|
2632 //QCOMPARE(tsdgeosQUrl.toEncoded(), tsdgeosExpected); // unusable output from qtestlib... |
|
2633 QCOMPARE(QString(tsdgeosQUrl.toEncoded()), QString(tsdgeosExpected)); |
|
2634 } |
|
2635 |
|
2636 { |
|
2637 QUrl url; |
|
2638 url.setUrl("http://strange<username>@hostname/", QUrl::TolerantMode); |
|
2639 QVERIFY(url.isValid()); |
|
2640 QCOMPARE(QString(url.toEncoded()), QString("http://strange%3Cusername%3E@hostname/")); |
|
2641 } |
|
2642 } |
|
2643 |
|
2644 void tst_QUrl::correctEncodedMistakes_data() |
|
2645 { |
|
2646 QTest::addColumn<QByteArray>("encodedUrl"); |
|
2647 QTest::addColumn<bool>("result"); |
|
2648 QTest::addColumn<QString>("toString"); |
|
2649 QTest::addColumn<QByteArray>("toEncoded"); |
|
2650 |
|
2651 QTest::newRow("%") << QByteArray("%") << true << QString("%") << QByteArray("%25"); |
|
2652 QTest::newRow("3%") << QByteArray("3%") << true << QString("3%") << QByteArray("3%25"); |
|
2653 QTest::newRow("13%") << QByteArray("13%") << true << QString("13%") << QByteArray("13%25"); |
|
2654 QTest::newRow("13%!") << QByteArray("13%!") << true << QString("13%!") << QByteArray("13%25!"); |
|
2655 QTest::newRow("13%!!") << QByteArray("13%!!") << true << QString("13%!!") << QByteArray("13%25!!"); |
|
2656 QTest::newRow("13%a") << QByteArray("13%a") << true << QString("13%a") << QByteArray("13%25a"); |
|
2657 QTest::newRow("13%az") << QByteArray("13%az") << true << QString("13%az") << QByteArray("13%25az"); |
|
2658 QTest::newRow("13%25") << QByteArray("13%25") << true << QString("13%") << QByteArray("13%25"); |
|
2659 } |
|
2660 |
|
2661 void tst_QUrl::correctEncodedMistakes() |
|
2662 { |
|
2663 QFETCH(QByteArray, encodedUrl); |
|
2664 QFETCH(bool, result); |
|
2665 QFETCH(QString, toString); |
|
2666 QFETCH(QByteArray, toEncoded); |
|
2667 |
|
2668 QUrl url = QUrl::fromEncoded(encodedUrl); |
|
2669 QCOMPARE(url.isValid(), result); |
|
2670 if (url.isValid()) { |
|
2671 QCOMPARE(url.toString(), toString); |
|
2672 QCOMPARE(url.toEncoded(), toEncoded); |
|
2673 } |
|
2674 } |
|
2675 |
|
2676 void tst_QUrl::correctDecodedMistakes_data() |
|
2677 { |
|
2678 QTest::addColumn<QString>("decodedUrl"); |
|
2679 QTest::addColumn<bool>("result"); |
|
2680 QTest::addColumn<QString>("toString"); |
|
2681 QTest::addColumn<QByteArray>("toEncoded"); |
|
2682 |
|
2683 QTest::newRow("%") << QString("%") << true << QString("%") << QByteArray("%25"); |
|
2684 QTest::newRow("3%") << QString("3%") << true << QString("3%") << QByteArray("3%25"); |
|
2685 QTest::newRow("13%") << QString("13%") << true << QString("13%") << QByteArray("13%25"); |
|
2686 QTest::newRow("13%!") << QString("13%!") << true << QString("13%!") << QByteArray("13%25!"); |
|
2687 QTest::newRow("13%!!") << QString("13%!!") << true << QString("13%!!") << QByteArray("13%25!!"); |
|
2688 QTest::newRow("13%a") << QString("13%a") << true << QString("13%a") << QByteArray("13%25a"); |
|
2689 QTest::newRow("13%az") << QString("13%az") << true << QString("13%az") << QByteArray("13%25az"); |
|
2690 QTest::newRow("13%25") << QString("13%25") << true << QString("13%25") << QByteArray("13%2525"); |
|
2691 } |
|
2692 |
|
2693 void tst_QUrl::correctDecodedMistakes() |
|
2694 { |
|
2695 QFETCH(QString, decodedUrl); |
|
2696 QFETCH(bool, result); |
|
2697 QFETCH(QString, toString); |
|
2698 QFETCH(QByteArray, toEncoded); |
|
2699 |
|
2700 QUrl url(decodedUrl); |
|
2701 QCOMPARE(url.isValid(), result); |
|
2702 if (url.isValid()) { |
|
2703 QCOMPARE(url.toString(), toString); |
|
2704 QCOMPARE(url.toEncoded(), toEncoded); |
|
2705 } |
|
2706 } |
|
2707 |
|
2708 void tst_QUrl::idna_testsuite_data() |
|
2709 { |
|
2710 QTest::addColumn<int>("numchars"); |
|
2711 QTest::addColumn<ushortarray>("unicode"); |
|
2712 QTest::addColumn<QByteArray>("punycode"); |
|
2713 QTest::addColumn<int>("allowunassigned"); |
|
2714 QTest::addColumn<int>("usestd3asciirules"); |
|
2715 QTest::addColumn<int>("toasciirc"); |
|
2716 QTest::addColumn<int>("tounicoderc"); |
|
2717 |
|
2718 unsigned short d1[] = { 0x0644, 0x064A, 0x0647, 0x0645, 0x0627, 0x0628, 0x062A, 0x0643, |
|
2719 0x0644, 0x0645, 0x0648, 0x0634, 0x0639, 0x0631, 0x0628, 0x064A, |
|
2720 0x061F }; |
|
2721 QTest::newRow("Arabic (Egyptian)") << 17 << ushortarray(d1) |
|
2722 << QByteArray(IDNA_ACE_PREFIX "egbpdaj6bu4bxfgehfvwxn") |
|
2723 << 0 << 0 << IDNA_SUCCESS << IDNA_SUCCESS; |
|
2724 |
|
2725 unsigned short d2[] = { 0x4ED6, 0x4EEC, 0x4E3A, 0x4EC0, 0x4E48, 0x4E0D, 0x8BF4, 0x4E2D, |
|
2726 0x6587 }; |
|
2727 QTest::newRow("Chinese (simplified)") << 9 << ushortarray(d2) |
|
2728 << QByteArray(IDNA_ACE_PREFIX "ihqwcrb4cv8a8dqg056pqjye") |
|
2729 << 0 << 0 << IDNA_SUCCESS << IDNA_SUCCESS; |
|
2730 |
|
2731 unsigned short d3[] = { 0x4ED6, 0x5011, 0x7232, 0x4EC0, 0x9EBD, 0x4E0D, 0x8AAA, 0x4E2D, |
|
2732 0x6587 }; |
|
2733 QTest::newRow("Chinese (traditional)") << 9 << ushortarray(d3) |
|
2734 << QByteArray(IDNA_ACE_PREFIX "ihqwctvzc91f659drss3x8bo0yb") |
|
2735 << 0 << 0 << IDNA_SUCCESS << IDNA_SUCCESS; |
|
2736 |
|
2737 unsigned short d4[] = { 0x0050, 0x0072, 0x006F, 0x010D, 0x0070, 0x0072, 0x006F, 0x0073, |
|
2738 0x0074, 0x011B, 0x006E, 0x0065, 0x006D, 0x006C, 0x0075, 0x0076, |
|
2739 0x00ED, 0x010D, 0x0065, 0x0073, 0x006B, 0x0079 }; |
|
2740 QTest::newRow("Czech") << 22 << ushortarray(d4) |
|
2741 << QByteArray(IDNA_ACE_PREFIX "Proprostnemluvesky-uyb24dma41a") |
|
2742 << 0 << 0 << IDNA_SUCCESS << IDNA_SUCCESS; |
|
2743 |
|
2744 unsigned short d5[] = { 0x05DC, 0x05DE, 0x05D4, 0x05D4, 0x05DD, 0x05E4, 0x05E9, 0x05D5, |
|
2745 0x05D8, 0x05DC, 0x05D0, 0x05DE, 0x05D3, 0x05D1, 0x05E8, 0x05D9, |
|
2746 0x05DD, 0x05E2, 0x05D1, 0x05E8, 0x05D9, 0x05EA }; |
|
2747 QTest::newRow("Hebrew") << 22 << ushortarray(d5) |
|
2748 << QByteArray(IDNA_ACE_PREFIX "4dbcagdahymbxekheh6e0a7fei0b") |
|
2749 << 0 << 0 << IDNA_SUCCESS << IDNA_SUCCESS; |
|
2750 |
|
2751 unsigned short d6[] = { 0x092F, 0x0939, 0x0932, 0x094B, 0x0917, 0x0939, 0x093F, 0x0928, |
|
2752 0x094D, 0x0926, 0x0940, 0x0915, 0x094D, 0x092F, 0x094B, 0x0902, |
|
2753 0x0928, 0x0939, 0x0940, 0x0902, 0x092C, 0x094B, 0x0932, 0x0938, |
|
2754 0x0915, 0x0924, 0x0947, 0x0939, 0x0948, 0x0902 }; |
|
2755 QTest::newRow("Hindi (Devanagari)") << 30 << ushortarray(d6) |
|
2756 << QByteArray(IDNA_ACE_PREFIX "i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd") |
|
2757 << 0 << 0 << IDNA_SUCCESS; |
|
2758 |
|
2759 unsigned short d7[] = { 0x306A, 0x305C, 0x307F, 0x3093, 0x306A, 0x65E5, 0x672C, 0x8A9E, |
|
2760 0x3092, 0x8A71, 0x3057, 0x3066, 0x304F, 0x308C, 0x306A, 0x3044, |
|
2761 0x306E, 0x304B }; |
|
2762 QTest::newRow("Japanese (kanji and hiragana)") << 18 << ushortarray(d7) |
|
2763 << QByteArray(IDNA_ACE_PREFIX "n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa") |
|
2764 << 0 << 0 << IDNA_SUCCESS; |
|
2765 |
|
2766 unsigned short d8[] = { 0x043F, 0x043E, 0x0447, 0x0435, 0x043C, 0x0443, 0x0436, 0x0435, |
|
2767 0x043E, 0x043D, 0x0438, 0x043D, 0x0435, 0x0433, 0x043E, 0x0432, |
|
2768 0x043E, 0x0440, 0x044F, 0x0442, 0x043F, 0x043E, 0x0440, 0x0443, |
|
2769 0x0441, 0x0441, 0x043A, 0x0438 }; |
|
2770 QTest::newRow("Russian (Cyrillic)") << 28 << ushortarray(d8) |
|
2771 << QByteArray(IDNA_ACE_PREFIX "b1abfaaepdrnnbgefbadotcwatmq2g4l") |
|
2772 << 0 << 0 << IDNA_SUCCESS << IDNA_SUCCESS; |
|
2773 |
|
2774 unsigned short d9[] = { 0x0050, 0x006F, 0x0072, 0x0071, 0x0075, 0x00E9, 0x006E, 0x006F, |
|
2775 0x0070, 0x0075, 0x0065, 0x0064, 0x0065, 0x006E, 0x0073, 0x0069, |
|
2776 0x006D, 0x0070, 0x006C, 0x0065, 0x006D, 0x0065, 0x006E, 0x0074, |
|
2777 0x0065, 0x0068, 0x0061, 0x0062, 0x006C, 0x0061, 0x0072, 0x0065, |
|
2778 0x006E, 0x0045, 0x0073, 0x0070, 0x0061, 0x00F1, 0x006F, 0x006C }; |
|
2779 QTest::newRow("Spanish") << 40 << ushortarray(d9) |
|
2780 << QByteArray(IDNA_ACE_PREFIX "PorqunopuedensimplementehablarenEspaol-fmd56a") |
|
2781 << 0 << 0 << IDNA_SUCCESS; |
|
2782 |
|
2783 unsigned short d10[] = { 0x0054, 0x1EA1, 0x0069, 0x0073, 0x0061, 0x006F, 0x0068, 0x1ECD, |
|
2784 0x006B, 0x0068, 0x00F4, 0x006E, 0x0067, 0x0074, 0x0068, 0x1EC3, |
|
2785 0x0063, 0x0068, 0x1EC9, 0x006E, 0x00F3, 0x0069, 0x0074, 0x0069, |
|
2786 0x1EBF, 0x006E, 0x0067, 0x0056, 0x0069, 0x1EC7, 0x0074 }; |
|
2787 QTest::newRow("Vietnamese") << 31 << ushortarray(d10) |
|
2788 << QByteArray(IDNA_ACE_PREFIX "TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g") |
|
2789 << 0 << 0 << IDNA_SUCCESS; |
|
2790 |
|
2791 unsigned short d11[] = { 0x0033, 0x5E74, 0x0042, 0x7D44, 0x91D1, 0x516B, 0x5148, 0x751F }; |
|
2792 QTest::newRow("Japanese") << 8 << ushortarray(d11) |
|
2793 << QByteArray(IDNA_ACE_PREFIX "3B-ww4c5e180e575a65lsy2b") |
|
2794 << 0 << 0 << IDNA_SUCCESS << IDNA_SUCCESS; |
|
2795 |
|
2796 unsigned short d12[] = { 0x5B89, 0x5BA4, 0x5948, 0x7F8E, 0x6075, 0x002D, 0x0077, 0x0069, |
|
2797 0x0074, 0x0068, 0x002D, 0x0053, 0x0055, 0x0050, 0x0045, 0x0052, |
|
2798 0x002D, 0x004D, 0x004F, 0x004E, 0x004B, 0x0045, 0x0059, 0x0053 }; |
|
2799 QTest::newRow("Japanese2") << 24 << ushortarray(d12) |
|
2800 << QByteArray(IDNA_ACE_PREFIX "-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n") |
|
2801 << 0 << 0 << IDNA_SUCCESS; |
|
2802 |
|
2803 unsigned short d13[] = { 0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x002D, 0x0041, 0x006E, |
|
2804 0x006F, 0x0074, 0x0068, 0x0065, 0x0072, 0x002D, 0x0057, 0x0061, |
|
2805 0x0079, 0x002D, 0x305D, 0x308C, 0x305E, 0x308C, 0x306E, 0x5834, |
|
2806 0x6240 }; |
|
2807 QTest::newRow("Japanese3") << 25 << ushortarray(d13) |
|
2808 << QByteArray(IDNA_ACE_PREFIX "Hello-Another-Way--fc4qua05auwb3674vfr0b") |
|
2809 << 0 << 0 << IDNA_SUCCESS; |
|
2810 |
|
2811 unsigned short d14[] = { 0x3072, 0x3068, 0x3064, 0x5C4B, 0x6839, 0x306E, 0x4E0B, 0x0032 }; |
|
2812 QTest::newRow("Japanese4") << 8 << ushortarray(d14) |
|
2813 << QByteArray(IDNA_ACE_PREFIX "2-u9tlzr9756bt3uc0v") |
|
2814 << 0 << 0 << IDNA_SUCCESS << IDNA_SUCCESS; |
|
2815 |
|
2816 unsigned short d15[] = { 0x004D, 0x0061, 0x006A, 0x0069, 0x3067, 0x004B, 0x006F, 0x0069, |
|
2817 0x3059, 0x308B, 0x0035, 0x79D2, 0x524D }; |
|
2818 QTest::newRow("Japanese5") << 13 << ushortarray(d15) |
|
2819 << QByteArray(IDNA_ACE_PREFIX "MajiKoi5-783gue6qz075azm5e") |
|
2820 << 0 << 0 << IDNA_SUCCESS << IDNA_SUCCESS; |
|
2821 |
|
2822 unsigned short d16[] = { 0x30D1, 0x30D5, 0x30A3, 0x30FC, 0x0064, 0x0065, 0x30EB, 0x30F3, 0x30D0 }; |
|
2823 QTest::newRow("Japanese6") << 9 << ushortarray(d16) |
|
2824 << QByteArray(IDNA_ACE_PREFIX "de-jg4avhby1noc0d") |
|
2825 << 0 << 0 << IDNA_SUCCESS << IDNA_SUCCESS; |
|
2826 |
|
2827 unsigned short d17[] = { 0x305D, 0x306E, 0x30B9, 0x30D4, 0x30FC, 0x30C9, 0x3067 }; |
|
2828 QTest::newRow("Japanese7") << 7 << ushortarray(d17) |
|
2829 << QByteArray(IDNA_ACE_PREFIX "d9juau41awczczp") |
|
2830 << 0 << 0 << IDNA_SUCCESS << IDNA_SUCCESS; |
|
2831 |
|
2832 unsigned short d18[] = { 0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba, 0x03ac }; |
|
2833 QTest::newRow("Greek") << 8 << ushortarray(d18) |
|
2834 << QByteArray(IDNA_ACE_PREFIX "hxargifdar") |
|
2835 << 0 << 0 << IDNA_SUCCESS << IDNA_SUCCESS; |
|
2836 |
|
2837 unsigned short d19[] = { 0x0062, 0x006f, 0x006e, 0x0121, 0x0075, 0x0073, 0x0061, 0x0127, |
|
2838 0x0127, 0x0061 }; |
|
2839 QTest::newRow("Maltese (Malti)") << 10 << ushortarray(d19) |
|
2840 << QByteArray(IDNA_ACE_PREFIX "bonusaa-5bb1da") |
|
2841 << 0 << 0 << IDNA_SUCCESS << IDNA_SUCCESS; |
|
2842 |
|
2843 unsigned short d20[] = {0x043f, 0x043e, 0x0447, 0x0435, 0x043c, 0x0443, 0x0436, 0x0435, |
|
2844 0x043e, 0x043d, 0x0438, 0x043d, 0x0435, 0x0433, 0x043e, 0x0432, |
|
2845 0x043e, 0x0440, 0x044f, 0x0442, 0x043f, 0x043e, 0x0440, 0x0443, |
|
2846 0x0441, 0x0441, 0x043a, 0x0438 }; |
|
2847 QTest::newRow("Russian (Cyrillic)") << 28 << ushortarray(d20) |
|
2848 << QByteArray(IDNA_ACE_PREFIX "b1abfaaepdrnnbgefbadotcwatmq2g4l") |
|
2849 << 0 << 0 << IDNA_SUCCESS << IDNA_SUCCESS; |
|
2850 } |
|
2851 |
|
2852 void tst_QUrl::idna_testsuite() |
|
2853 { |
|
2854 QFETCH(int, numchars); |
|
2855 QFETCH(ushortarray, unicode); |
|
2856 QFETCH(QByteArray, punycode); |
|
2857 |
|
2858 QString s = QString::fromUtf16(unicode.points, numchars); |
|
2859 QCOMPARE(punycode, QUrl::toPunycode(s)); |
|
2860 } |
|
2861 |
|
2862 void tst_QUrl::nameprep_testsuite_data() |
|
2863 { |
|
2864 QTest::addColumn<QString>("in"); |
|
2865 QTest::addColumn<QString>("out"); |
|
2866 QTest::addColumn<QString>("profile"); |
|
2867 QTest::addColumn<int>("flags"); |
|
2868 QTest::addColumn<int>("rc"); |
|
2869 |
|
2870 QTest::newRow("Map to nothing") |
|
2871 << QString::fromUtf8("foo\xC2\xAD\xCD\x8F\xE1\xA0\x86\xE1\xA0\x8B" |
|
2872 "bar""\xE2\x80\x8B\xE2\x81\xA0""baz\xEF\xB8\x80\xEF\xB8\x88" |
|
2873 "\xEF\xB8\x8F\xEF\xBB\xBF") |
|
2874 << QString::fromUtf8("foobarbaz") |
|
2875 << QString() << 0 << 0; |
|
2876 |
|
2877 QTest::newRow("Case folding ASCII U+0043 U+0041 U+0046 U+0045") |
|
2878 << QString::fromUtf8("CAFE") |
|
2879 << QString::fromUtf8("cafe") |
|
2880 << QString() << 0 << 0; |
|
2881 |
|
2882 QTest::newRow("Case folding 8bit U+00DF (german sharp s)") |
|
2883 // << QString::fromUtf8("\xC3\xDF") ### typo in the original testsuite |
|
2884 << QString::fromUtf8("\xC3\x9F") |
|
2885 << QString("ss") |
|
2886 << QString() << 0 << 0; |
|
2887 |
|
2888 QTest::newRow("Case folding U+0130 (turkish capital I with dot)") |
|
2889 << QString::fromUtf8("\xC4\xB0") |
|
2890 << QString::fromUtf8("i\xcc\x87") |
|
2891 << QString() << 0 << 0; |
|
2892 |
|
2893 QTest::newRow("Case folding multibyte U+0143 U+037A") |
|
2894 << QString::fromUtf8("\xC5\x83\xCD\xBA") |
|
2895 << QString::fromUtf8("\xC5\x84 \xCE\xB9") |
|
2896 << QString() << 0 << 0; |
|
2897 |
|
2898 QTest::newRow("Case folding U+2121 U+33C6 U+1D7BB") |
|
2899 << QString::fromUtf8("\xE2\x84\xA1\xE3\x8F\x86\xF0\x9D\x9E\xBB") |
|
2900 << QString::fromUtf8("telc\xE2\x88\x95""kg\xCF\x83") |
|
2901 << QString() << 0 << 0; |
|
2902 |
|
2903 QTest::newRow("Normalization of U+006a U+030c U+00A0 U+00AA") |
|
2904 << QString::fromUtf8("\x6A\xCC\x8C\xC2\xA0\xC2\xAA") |
|
2905 << QString::fromUtf8("\xC7\xB0 a") |
|
2906 << QString() << 0 << 0; |
|
2907 |
|
2908 QTest::newRow("Case folding U+1FB7 and normalization") |
|
2909 << QString::fromUtf8("\xE1\xBE\xB7") |
|
2910 << QString::fromUtf8("\xE1\xBE\xB6\xCE\xB9") |
|
2911 << QString() << 0 << 0; |
|
2912 |
|
2913 QTest::newRow("Self-reverting case folding U+01F0 and normalization") |
|
2914 << QString::fromUtf8("\xC7\xF0") |
|
2915 << QString::fromUtf8("\xC7\xB0") |
|
2916 << QString() << 0 << 0; |
|
2917 |
|
2918 QTest::newRow("Self-reverting case folding U+0390 and normalization") |
|
2919 << QString::fromUtf8("\xCE\x90") |
|
2920 << QString::fromUtf8("\xCE\x90") |
|
2921 << QString() << 0 << 0; |
|
2922 |
|
2923 QTest::newRow("Self-reverting case folding U+03B0 and normalization") |
|
2924 << QString::fromUtf8("\xCE\xB0") |
|
2925 << QString::fromUtf8("\xCE\xB0") |
|
2926 << QString() << 0 << 0; |
|
2927 |
|
2928 QTest::newRow("Self-reverting case folding U+1E96 and normalization") |
|
2929 << QString::fromUtf8("\xE1\xBA\x96") |
|
2930 << QString::fromUtf8("\xE1\xBA\x96") |
|
2931 << QString() << 0 << 0; |
|
2932 |
|
2933 QTest::newRow("Self-reverting case folding U+1F56 and normalization") |
|
2934 << QString::fromUtf8("\xE1\xBD\x96") |
|
2935 << QString::fromUtf8("\xE1\xBD\x96") |
|
2936 << QString() << 0 << 0; |
|
2937 |
|
2938 QTest::newRow("ASCII space character U+0020") |
|
2939 << QString::fromUtf8("\x20") |
|
2940 << QString::fromUtf8("\x20") |
|
2941 << QString() << 0 << 0; |
|
2942 |
|
2943 QTest::newRow("Non-ASCII 8bit space character U+00A0") |
|
2944 << QString::fromUtf8("\xC2\xA0") |
|
2945 << QString::fromUtf8("\x20") |
|
2946 << QString() << 0 << 0; |
|
2947 |
|
2948 QTest::newRow("Non-ASCII multibyte space character U+1680") |
|
2949 << QString::fromUtf8("\xE1\x9A\x80") |
|
2950 << QString() |
|
2951 << QString("Nameprep") << 0 << STRINGPREP_CONTAINS_PROHIBITED; |
|
2952 |
|
2953 QTest::newRow("Non-ASCII multibyte space character U+2000") |
|
2954 << QString::fromUtf8("\xE2\x80\x80") |
|
2955 << QString::fromUtf8("\x20") |
|
2956 << QString() << 0 << 0; |
|
2957 |
|
2958 QTest::newRow("Zero Width Space U+200b") |
|
2959 << QString::fromUtf8("\xE2\x80\x8b") |
|
2960 << QString() |
|
2961 << QString() << 0 << 0; |
|
2962 |
|
2963 QTest::newRow("Non-ASCII multibyte space character U+3000") |
|
2964 << QString::fromUtf8("\xE3\x80\x80") |
|
2965 << QString::fromUtf8("\x20") |
|
2966 << QString() << 0 << 0; |
|
2967 |
|
2968 QTest::newRow("ASCII control characters U+0010 U+007F") |
|
2969 << QString::fromUtf8("\x10\x7F") |
|
2970 << QString::fromUtf8("\x10\x7F") |
|
2971 << QString() << 0 << 0; |
|
2972 |
|
2973 QTest::newRow("Non-ASCII 8bit control character U+0085") |
|
2974 << QString::fromUtf8("\xC2\x85") |
|
2975 << QString() |
|
2976 << QString("Nameprep") << 0 << STRINGPREP_CONTAINS_PROHIBITED; |
|
2977 |
|
2978 QTest::newRow("Non-ASCII multibyte control character U+180E") |
|
2979 << QString::fromUtf8("\xE1\xA0\x8E") |
|
2980 << QString() |
|
2981 << QString("Nameprep") << 0 << STRINGPREP_CONTAINS_PROHIBITED; |
|
2982 |
|
2983 QTest::newRow("Zero Width No-Break Space U+FEFF") |
|
2984 << QString::fromUtf8("\xEF\xBB\xBF") |
|
2985 << QString() |
|
2986 << QString() << 0 << 0; |
|
2987 |
|
2988 QTest::newRow("Non-ASCII control character U+1D175") |
|
2989 << QString::fromUtf8("\xF0\x9D\x85\xB5") |
|
2990 << QString() |
|
2991 << QString("Nameprep") << 0 << STRINGPREP_CONTAINS_PROHIBITED; |
|
2992 |
|
2993 QTest::newRow("Plane 0 private use character U+F123") |
|
2994 << QString::fromUtf8("\xEF\x84\xA3") |
|
2995 << QString() |
|
2996 << QString("Nameprep") << 0 << STRINGPREP_CONTAINS_PROHIBITED; |
|
2997 |
|
2998 QTest::newRow("Plane 15 private use character U+F1234") |
|
2999 << QString::fromUtf8("\xF3\xB1\x88\xB4") |
|
3000 << QString() |
|
3001 << QString("Nameprep") << 0 << STRINGPREP_CONTAINS_PROHIBITED; |
|
3002 |
|
3003 QTest::newRow("Plane 16 private use character U+10F234") |
|
3004 << QString::fromUtf8("\xF4\x8F\x88\xB4") |
|
3005 << QString() |
|
3006 << QString("Nameprep") << 0 << STRINGPREP_CONTAINS_PROHIBITED; |
|
3007 |
|
3008 QTest::newRow("Non-character code point U+8FFFE") |
|
3009 << QString::fromUtf8("\xF2\x8F\xBF\xBE") |
|
3010 << QString() |
|
3011 << QString("Nameprep") << 0 << STRINGPREP_CONTAINS_PROHIBITED; |
|
3012 |
|
3013 QTest::newRow("Non-character code point U+10FFFF") |
|
3014 << QString::fromUtf8("\xF4\x8F\xBF\xBF") |
|
3015 << QString() |
|
3016 << QString("Nameprep") << 0 << STRINGPREP_CONTAINS_PROHIBITED; |
|
3017 |
|
3018 QTest::newRow("Surrogate code U+DF42") |
|
3019 << QString::fromUtf8("\xED\xBD\x82") |
|
3020 << QString() |
|
3021 << QString("Nameprep") << 0 << STRINGPREP_CONTAINS_PROHIBITED; |
|
3022 |
|
3023 QTest::newRow("Non-plain text character U+FFFD") |
|
3024 << QString::fromUtf8("\xEF\xBF\xBD") |
|
3025 << QString() |
|
3026 << QString("Nameprep") << 0 << STRINGPREP_CONTAINS_PROHIBITED; |
|
3027 |
|
3028 QTest::newRow("Ideographic description character U+2FF5") |
|
3029 << QString::fromUtf8("\xE2\xBF\xB5") |
|
3030 << QString() |
|
3031 << QString("Nameprep") << 0 << STRINGPREP_CONTAINS_PROHIBITED; |
|
3032 |
|
3033 QTest::newRow("Display property character U+0341") |
|
3034 << QString::fromUtf8("\xCD\x81") |
|
3035 << QString::fromUtf8("\xCC\x81") |
|
3036 << QString() << 0 << 0; |
|
3037 |
|
3038 QTest::newRow("Left-to-right mark U+200E") |
|
3039 << QString::fromUtf8("\xE2\x80\x8E") |
|
3040 << QString::fromUtf8("\xCC\x81") |
|
3041 << QString("Nameprep") << 0 << STRINGPREP_CONTAINS_PROHIBITED; |
|
3042 |
|
3043 QTest::newRow("Deprecated U+202A") |
|
3044 << QString::fromUtf8("\xE2\x80\xAA") |
|
3045 << QString::fromUtf8("\xCC\x81") |
|
3046 << QString("Nameprep") << 0 << STRINGPREP_CONTAINS_PROHIBITED; |
|
3047 |
|
3048 QTest::newRow("Language tagging character U+E0001") |
|
3049 << QString::fromUtf8("\xF3\xA0\x80\x81") |
|
3050 << QString::fromUtf8("\xCC\x81") |
|
3051 << QString("Nameprep") << 0 << STRINGPREP_CONTAINS_PROHIBITED; |
|
3052 |
|
3053 QTest::newRow("Language tagging character U+E0042") |
|
3054 << QString::fromUtf8("\xF3\xA0\x81\x82") |
|
3055 << QString() |
|
3056 << QString("Nameprep") << 0 << STRINGPREP_CONTAINS_PROHIBITED; |
|
3057 |
|
3058 QTest::newRow("Bidi: RandALCat character U+05BE and LCat characters") |
|
3059 << QString::fromUtf8("foo\xD6\xBE""bar") |
|
3060 << QString() |
|
3061 << QString("Nameprep") << 0 << STRINGPREP_BIDI_BOTH_L_AND_RAL; |
|
3062 |
|
3063 QTest::newRow("Bidi: RandALCat character U+FD50 and LCat characters") |
|
3064 << QString::fromUtf8("foo\xEF\xB5\x90""bar") |
|
3065 << QString() |
|
3066 << QString("Nameprep") << 0 << STRINGPREP_BIDI_BOTH_L_AND_RAL; |
|
3067 |
|
3068 QTest::newRow("Bidi: RandALCat character U+FB38 and LCat characters") |
|
3069 << QString::fromUtf8("foo\xEF\xB9\xB6""bar") |
|
3070 << QString::fromUtf8("foo \xd9\x8e""bar") |
|
3071 << QString() << 0 << 0; |
|
3072 |
|
3073 QTest::newRow("Bidi: RandALCat without trailing RandALCat U+0627 U+0031") |
|
3074 << QString::fromUtf8("\xD8\xA7\x31") |
|
3075 << QString() |
|
3076 << QString("Nameprep") << 0 << STRINGPREP_BIDI_LEADTRAIL_NOT_RAL; |
|
3077 |
|
3078 QTest::newRow("Bidi: RandALCat character U+0627 U+0031 U+0628") |
|
3079 << QString::fromUtf8("\xD8\xA7\x31\xD8\xA8") |
|
3080 << QString::fromUtf8("\xD8\xA7\x31\xD8\xA8") |
|
3081 << QString() << 0 << 0; |
|
3082 |
|
3083 QTest::newRow("Unassigned code point U+E0002") |
|
3084 << QString::fromUtf8("\xF3\xA0\x80\x82") |
|
3085 << QString() |
|
3086 << QString("Nameprep") << STRINGPREP_NO_UNASSIGNED << STRINGPREP_CONTAINS_UNASSIGNED; |
|
3087 |
|
3088 QTest::newRow("Larger test (shrinking)") |
|
3089 << QString::fromUtf8("X\xC2\xAD\xC3\xDF\xC4\xB0\xE2\x84\xA1\x6a\xcc\x8c\xc2\xa0\xc2" |
|
3090 "\xaa\xce\xb0\xe2\x80\x80") |
|
3091 << QString::fromUtf8("xssi\xcc\x87""tel\xc7\xb0 a\xce\xb0 ") |
|
3092 << QString("Nameprep") << 0 << 0; |
|
3093 |
|
3094 QTest::newRow("Larger test (expanding)") |
|
3095 << QString::fromUtf8("X\xC3\xDF\xe3\x8c\x96\xC4\xB0\xE2\x84\xA1\xE2\x92\x9F\xE3\x8c\x80") |
|
3096 << QString::fromUtf8("xss\xe3\x82\xad\xe3\x83\xad\xe3\x83\xa1\xe3\x83\xbc\xe3\x83\x88" |
|
3097 "\xe3\x83\xab""i\xcc\x87""tel\x28""d\x29\xe3\x82\xa2\xe3\x83\x91" |
|
3098 "\xe3\x83\xbc\xe3\x83\x88") |
|
3099 << QString() << 0 << 0; |
|
3100 } |
|
3101 |
|
3102 #ifdef QT_BUILD_INTERNAL |
|
3103 QT_BEGIN_NAMESPACE |
|
3104 extern void qt_nameprep(QString *source, int from); |
|
3105 extern bool qt_check_std3rules(const QChar *, int); |
|
3106 QT_END_NAMESPACE |
|
3107 #endif |
|
3108 |
|
3109 void tst_QUrl::nameprep_testsuite() |
|
3110 { |
|
3111 #ifdef QT_BUILD_INTERNAL |
|
3112 QFETCH(QString, in); |
|
3113 QFETCH(QString, out); |
|
3114 QFETCH(QString, profile); |
|
3115 |
|
3116 QEXPECT_FAIL("Case folding U+2121 U+33C6 U+1D7BB", |
|
3117 ">0xffff unicode points are not supported", Continue); |
|
3118 QEXPECT_FAIL("Self-reverting case folding U+01F0 and normalization", |
|
3119 "Investigate further", Continue); |
|
3120 QEXPECT_FAIL("Left-to-right mark U+200E", |
|
3121 "Investigate further", Continue); |
|
3122 QEXPECT_FAIL("Deprecated U+202A", |
|
3123 "Investigate further", Continue); |
|
3124 QEXPECT_FAIL("Language tagging character U+E0001", |
|
3125 "Investigate further", Continue); |
|
3126 QEXPECT_FAIL("Larger test (shrinking)", |
|
3127 "Investigate further", Continue); |
|
3128 QEXPECT_FAIL("Larger test (expanding)", |
|
3129 "Investigate further", Continue); |
|
3130 qt_nameprep(&in, 0); |
|
3131 QCOMPARE(in, out); |
|
3132 #endif |
|
3133 } |
|
3134 |
|
3135 void tst_QUrl::ace_testsuite_data() |
|
3136 { |
|
3137 QTest::addColumn<QString>("in"); |
|
3138 QTest::addColumn<QString>("toace"); |
|
3139 QTest::addColumn<QString>("fromace"); |
|
3140 QTest::addColumn<QString>("unicode"); |
|
3141 |
|
3142 QTest::newRow("ascii-lower") << "fluke" << "fluke" << "fluke" << "fluke"; |
|
3143 QTest::newRow("ascii-mixed") << "FLuke" << "fluke" << "fluke" << "fluke"; |
|
3144 QTest::newRow("ascii-upper") << "FLUKE" << "fluke" << "fluke" << "fluke"; |
|
3145 |
|
3146 QTest::newRow("asciifolded") << QString::fromLatin1("stra\337e") << "strasse" << "." << "strasse"; |
|
3147 QTest::newRow("asciifolded-dotcom") << QString::fromLatin1("stra\337e.example.com") << "strasse.example.com" << "." << "strasse.example.com"; |
|
3148 QTest::newRow("greek-mu") << QString::fromLatin1("\265V") |
|
3149 <<"xn--v-lmb" |
|
3150 << "." |
|
3151 << QString::fromUtf8("\316\274v"); |
|
3152 |
|
3153 QTest::newRow("non-ascii-lower") << QString::fromLatin1("alqualond\353") |
|
3154 << "xn--alqualond-34a" |
|
3155 << "." |
|
3156 << QString::fromLatin1("alqualond\353"); |
|
3157 QTest::newRow("non-ascii-mixed") << QString::fromLatin1("Alqualond\353") |
|
3158 << "xn--alqualond-34a" |
|
3159 << "." |
|
3160 << QString::fromLatin1("alqualond\353"); |
|
3161 QTest::newRow("non-ascii-upper") << QString::fromLatin1("ALQUALOND\313") |
|
3162 << "xn--alqualond-34a" |
|
3163 << "." |
|
3164 << QString::fromLatin1("alqualond\353"); |
|
3165 |
|
3166 QTest::newRow("idn-lower") << "xn--alqualond-34a" << "xn--alqualond-34a" |
|
3167 << QString::fromLatin1("alqualond\353") |
|
3168 << QString::fromLatin1("alqualond\353"); |
|
3169 QTest::newRow("idn-mixed") << "Xn--alqualond-34a" << "xn--alqualond-34a" |
|
3170 << QString::fromLatin1("alqualond\353") |
|
3171 << QString::fromLatin1("alqualond\353"); |
|
3172 QTest::newRow("idn-mixed2") << "XN--alqualond-34a" << "xn--alqualond-34a" |
|
3173 << QString::fromLatin1("alqualond\353") |
|
3174 << QString::fromLatin1("alqualond\353"); |
|
3175 QTest::newRow("idn-mixed3") << "xn--ALQUALOND-34a" << "xn--alqualond-34a" |
|
3176 << QString::fromLatin1("alqualond\353") |
|
3177 << QString::fromLatin1("alqualond\353"); |
|
3178 QTest::newRow("idn-mixed4") << "xn--alqualond-34A" << "xn--alqualond-34a" |
|
3179 << QString::fromLatin1("alqualond\353") |
|
3180 << QString::fromLatin1("alqualond\353"); |
|
3181 QTest::newRow("idn-upper") << "XN--ALQUALOND-34A" << "xn--alqualond-34a" |
|
3182 << QString::fromLatin1("alqualond\353") |
|
3183 << QString::fromLatin1("alqualond\353"); |
|
3184 |
|
3185 QTest::newRow("separator-3002") << QString::fromUtf8("example\343\200\202com") |
|
3186 << "example.com" << "." << "example.com"; |
|
3187 } |
|
3188 |
|
3189 void tst_QUrl::ace_testsuite() |
|
3190 { |
|
3191 static const char canonsuffix[] = ".troll.no"; |
|
3192 QFETCH(QString, in); |
|
3193 QFETCH(QString, toace); |
|
3194 QFETCH(QString, fromace); |
|
3195 QFETCH(QString, unicode); |
|
3196 |
|
3197 const char *suffix = canonsuffix; |
|
3198 if (toace.contains('.')) |
|
3199 suffix = 0; |
|
3200 |
|
3201 QString domain = in + suffix; |
|
3202 QCOMPARE(QString::fromLatin1(QUrl::toAce(domain)), toace + suffix); |
|
3203 if (fromace != ".") |
|
3204 QCOMPARE(QUrl::fromAce(domain.toLatin1()), fromace + suffix); |
|
3205 QCOMPARE(QUrl::fromAce(QUrl::toAce(domain)), unicode + suffix); |
|
3206 |
|
3207 domain = in + (suffix ? ".troll.No" : ""); |
|
3208 QCOMPARE(QString::fromLatin1(QUrl::toAce(domain)), toace + suffix); |
|
3209 if (fromace != ".") |
|
3210 QCOMPARE(QUrl::fromAce(domain.toLatin1()), fromace + suffix); |
|
3211 QCOMPARE(QUrl::fromAce(QUrl::toAce(domain)), unicode + suffix); |
|
3212 |
|
3213 domain = in + (suffix ? ".troll.NO" : ""); |
|
3214 QCOMPARE(QString::fromLatin1(QUrl::toAce(domain)), toace + suffix); |
|
3215 if (fromace != ".") |
|
3216 QCOMPARE(QUrl::fromAce(domain.toLatin1()), fromace + suffix); |
|
3217 QCOMPARE(QUrl::fromAce(QUrl::toAce(domain)), unicode + suffix); |
|
3218 } |
|
3219 |
|
3220 void tst_QUrl::std3violations_data() |
|
3221 { |
|
3222 QTest::addColumn<QString>("source"); |
|
3223 QTest::addColumn<bool>("validUrl"); |
|
3224 |
|
3225 QTest::newRow("too-long") << "this-domain-is-far-too-long-for-its-own-good-and-should-have-been-limited-to-63-chars" << false; |
|
3226 QTest::newRow("dash-begin") << "-x-foo" << false; |
|
3227 QTest::newRow("dash-end") << "x-foo-" << false; |
|
3228 QTest::newRow("dash-begin-end") << "-foo-" << false; |
|
3229 |
|
3230 QTest::newRow("control") << "\033foo" << false; |
|
3231 QTest::newRow("bang") << "foo!" << false; |
|
3232 QTest::newRow("plus") << "foo+bar" << false; |
|
3233 QTest::newRow("dot") << "foo.bar"; |
|
3234 QTest::newRow("slash") << "foo/bar" << true; |
|
3235 QTest::newRow("colon") << "foo:80" << true; |
|
3236 QTest::newRow("question") << "foo?bar" << true; |
|
3237 QTest::newRow("at") << "foo@bar" << true; |
|
3238 QTest::newRow("backslash") << "foo\\bar" << false; |
|
3239 QTest::newRow("underline") << "foo_bar" << false; |
|
3240 |
|
3241 // these characters are transformed by NFKC to non-LDH characters |
|
3242 QTest::newRow("dot-like") << QString::fromUtf8("foo\342\200\244bar") << false; // U+2024 ONE DOT LEADER |
|
3243 QTest::newRow("slash-like") << QString::fromUtf8("foo\357\274\217bar") << false; // U+FF0F FULLWIDTH SOLIDUS |
|
3244 |
|
3245 // The following should be invalid but isn't |
|
3246 // the DIVISON SLASH doesn't case-fold to a slash |
|
3247 // is this a problem with RFC 3490? |
|
3248 //QTest::newRow("slash-like2") << QString::fromUtf8("foo\342\210\225bar") << false; // U+2215 DIVISION SLASH |
|
3249 } |
|
3250 |
|
3251 void tst_QUrl::std3violations() |
|
3252 { |
|
3253 QFETCH(QString, source); |
|
3254 |
|
3255 #ifdef QT_BUILD_INTERNAL |
|
3256 { |
|
3257 QString prepped = source; |
|
3258 qt_nameprep(&prepped, 0); |
|
3259 QVERIFY(!qt_check_std3rules(prepped.constData(), prepped.length())); |
|
3260 } |
|
3261 #endif |
|
3262 |
|
3263 if (source.contains('.')) |
|
3264 return; // this test ends here |
|
3265 |
|
3266 QUrl url; |
|
3267 url.setHost(source); |
|
3268 QVERIFY(url.host().isEmpty()); |
|
3269 |
|
3270 QFETCH(bool, validUrl); |
|
3271 if (validUrl) |
|
3272 return; // test ends here for these cases |
|
3273 |
|
3274 url = QUrl("http://" + source + "/some/path"); |
|
3275 QVERIFY(!url.isValid()); |
|
3276 } |
|
3277 |
|
3278 void tst_QUrl::tldRestrictions_data() |
|
3279 { |
|
3280 QTest::addColumn<QString>("tld"); |
|
3281 QTest::addColumn<bool>("encode"); |
|
3282 |
|
3283 // current whitelist |
|
3284 QTest::newRow("ac") << QString("ac") << true; |
|
3285 QTest::newRow("at") << QString("at") << true; |
|
3286 QTest::newRow("br") << QString("br") << true; |
|
3287 QTest::newRow("cat") << QString("cat") << true; |
|
3288 QTest::newRow("ch") << QString("ch") << true; |
|
3289 QTest::newRow("cl") << QString("cl") << true; |
|
3290 QTest::newRow("cn") << QString("cn") << true; |
|
3291 QTest::newRow("de") << QString("de") << true; |
|
3292 QTest::newRow("dk") << QString("dk") << true; |
|
3293 QTest::newRow("fi") << QString("fi") << true; |
|
3294 QTest::newRow("hu") << QString("hu") << true; |
|
3295 QTest::newRow("info") << QString("info") << true; |
|
3296 QTest::newRow("io") << QString("io") << true; |
|
3297 QTest::newRow("jp") << QString("jp") << true; |
|
3298 QTest::newRow("kr") << QString("kr") << true; |
|
3299 QTest::newRow("li") << QString("li") << true; |
|
3300 QTest::newRow("lt") << QString("lt") << true; |
|
3301 QTest::newRow("museum") << QString("museum") << true; |
|
3302 QTest::newRow("no") << QString("no") << true; |
|
3303 QTest::newRow("se") << QString("se") << true; |
|
3304 QTest::newRow("sh") << QString("sh") << true; |
|
3305 QTest::newRow("th") << QString("th") << true; |
|
3306 QTest::newRow("tm") << QString("tm") << true; |
|
3307 QTest::newRow("tw") << QString("tw") << true; |
|
3308 QTest::newRow("vn") << QString("vn") << true; |
|
3309 |
|
3310 // known blacklists: |
|
3311 QTest::newRow("com") << QString("com") << false; |
|
3312 QTest::newRow("foo") << QString("foo") << false; |
|
3313 } |
|
3314 |
|
3315 void tst_QUrl::tldRestrictions() |
|
3316 { |
|
3317 QFETCH(QString, tld); |
|
3318 |
|
3319 // www.brød.tld |
|
3320 QByteArray ascii = "www.xn--brd-1na." + tld.toLatin1(); |
|
3321 QString unicode = QLatin1String("www.br\370d.") + tld; |
|
3322 QString encoded = QUrl::fromAce(ascii); |
|
3323 QTEST(!encoded.contains(".xn--"), "encode"); |
|
3324 QTEST(encoded == unicode, "encode"); |
|
3325 |
|
3326 QUrl url = QUrl::fromEncoded("http://www.xn--brd-1na." + tld.toLatin1()); |
|
3327 QTEST(!url.host().contains(".xn--"), "encode"); |
|
3328 QTEST(url.host() == unicode, "encode"); |
|
3329 |
|
3330 url.setUrl(QLatin1String("http://www.xn--brd-1na.") + tld); |
|
3331 QTEST(!url.host().contains(".xn--"), "encode"); |
|
3332 QTEST(url.host() == unicode, "encode"); |
|
3333 |
|
3334 url.setUrl(QLatin1String("http://www.br\370d.") + tld); |
|
3335 QTEST(!url.host().contains(".xn--"), "encode"); |
|
3336 QTEST(url.host() == unicode, "encode"); |
|
3337 |
|
3338 url = QUrl::fromEncoded("http://www.br%C3%B8d." + tld.toLatin1()); |
|
3339 QTEST(!url.host().contains(".xn--"), "encode"); |
|
3340 QTEST(url.host() == unicode, "encode"); |
|
3341 } |
|
3342 |
|
3343 void tst_QUrl::emptyQueryOrFragment() |
|
3344 { |
|
3345 QUrl qurl = QUrl::fromEncoded("http://www.kde.org/cgi/test.cgi?", QUrl::TolerantMode); |
|
3346 QCOMPARE(qurl.toEncoded().constData(), "http://www.kde.org/cgi/test.cgi?"); // Empty refs should be preserved |
|
3347 QCOMPARE(qurl.toString(), QString("http://www.kde.org/cgi/test.cgi?")); |
|
3348 qurl = QUrl::fromEncoded("http://www.kde.org/cgi/test.cgi#", QUrl::TolerantMode); |
|
3349 QCOMPARE(qurl.toEncoded().constData(), "http://www.kde.org/cgi/test.cgi#"); |
|
3350 QCOMPARE(qurl.toString(), QString("http://www.kde.org/cgi/test.cgi#")); |
|
3351 |
|
3352 { |
|
3353 // start with an empty one |
|
3354 QUrl url("http://www.foo.bar/baz"); |
|
3355 QVERIFY(!url.hasFragment()); |
|
3356 QVERIFY(url.fragment().isNull()); |
|
3357 |
|
3358 // add fragment |
|
3359 url.setFragment(QLatin1String("abc")); |
|
3360 QVERIFY(url.hasFragment()); |
|
3361 QCOMPARE(url.fragment(), QString(QLatin1String("abc"))); |
|
3362 QCOMPARE(url.toString(), QString(QLatin1String("http://www.foo.bar/baz#abc"))); |
|
3363 |
|
3364 // remove fragment |
|
3365 url.setFragment(QString()); |
|
3366 QVERIFY(!url.hasFragment()); |
|
3367 QVERIFY(url.fragment().isNull()); |
|
3368 QCOMPARE(url.toString(), QString(QLatin1String("http://www.foo.bar/baz"))); |
|
3369 |
|
3370 // add empty fragment |
|
3371 url.setFragment(QLatin1String("")); |
|
3372 QVERIFY(url.hasFragment()); |
|
3373 QVERIFY(url.fragment().isEmpty()); |
|
3374 QVERIFY(!url.fragment().isNull()); |
|
3375 QCOMPARE(url.toString(), QString(QLatin1String("http://www.foo.bar/baz#"))); |
|
3376 } |
|
3377 |
|
3378 { |
|
3379 // start with an empty one |
|
3380 QUrl url("http://www.foo.bar/baz"); |
|
3381 QVERIFY(!url.hasQuery()); |
|
3382 QVERIFY(url.encodedQuery().isNull()); |
|
3383 |
|
3384 // add encodedQuery |
|
3385 url.setEncodedQuery("abc=def"); |
|
3386 QVERIFY(url.hasQuery()); |
|
3387 QCOMPARE(QString(url.encodedQuery()), QString(QLatin1String("abc=def"))); |
|
3388 QCOMPARE(url.toString(), QString(QLatin1String("http://www.foo.bar/baz?abc=def"))); |
|
3389 |
|
3390 // remove encodedQuery |
|
3391 url.setEncodedQuery(0); |
|
3392 QVERIFY(!url.hasQuery()); |
|
3393 QVERIFY(url.encodedQuery().isNull()); |
|
3394 QCOMPARE(url.toString(), QString(QLatin1String("http://www.foo.bar/baz"))); |
|
3395 |
|
3396 // add empty encodedQuery |
|
3397 url.setEncodedQuery(""); |
|
3398 QVERIFY(url.hasQuery()); |
|
3399 QVERIFY(url.encodedQuery().isEmpty()); |
|
3400 QVERIFY(!url.encodedQuery().isNull()); |
|
3401 QCOMPARE(url.toString(), QString(QLatin1String("http://www.foo.bar/baz?"))); |
|
3402 } |
|
3403 } |
|
3404 |
|
3405 void tst_QUrl::hasFragment_data() |
|
3406 { |
|
3407 QTest::addColumn<QString>("url"); |
|
3408 QTest::addColumn<bool>("trueFalse"); |
|
3409 |
|
3410 QTest::newRow("no fragment") << "http://www.foo.bar" << false; |
|
3411 |
|
3412 QTest::newRow("empty fragment") << "http://www.foo.bar#" << true; |
|
3413 QTest::newRow("empty fragment 2") << "http://www.foo.bar/#" << true; |
|
3414 |
|
3415 QTest::newRow("fragment") << "http://www.foo.bar#baz" << true; |
|
3416 QTest::newRow("fragment2") << "http://www.foo.bar/#baz" << true; |
|
3417 |
|
3418 QTest::newRow("%23") << "http://www.foo.bar/%23" << false; |
|
3419 QTest::newRow("%23-and-something") << "http://www.foo.bar/%23baz" << false; |
|
3420 } |
|
3421 |
|
3422 void tst_QUrl::hasFragment() |
|
3423 { |
|
3424 QFETCH(QString, url); |
|
3425 QFETCH(bool, trueFalse); |
|
3426 |
|
3427 QUrl qurl(url); |
|
3428 QCOMPARE(qurl.hasFragment(), trueFalse); |
|
3429 QCOMPARE(qurl.fragment().isNull(), !trueFalse); |
|
3430 } |
|
3431 |
|
3432 void tst_QUrl::setEncodedFragment_data() |
|
3433 { |
|
3434 QTest::addColumn<QByteArray>("base"); |
|
3435 QTest::addColumn<QByteArray>("fragment"); |
|
3436 QTest::addColumn<QByteArray>("expected"); |
|
3437 |
|
3438 typedef QByteArray BA; |
|
3439 QTest::newRow("empty") << BA("http://www.kde.org") << BA("") << BA("http://www.kde.org#"); |
|
3440 QTest::newRow("basic test") << BA("http://www.kde.org") << BA("abc") << BA("http://www.kde.org#abc"); |
|
3441 QTest::newRow("initial url has fragment") << BA("http://www.kde.org#old") << BA("new") << BA("http://www.kde.org#new"); |
|
3442 QTest::newRow("encoded fragment") << BA("http://www.kde.org") << BA("a%20c") << BA("http://www.kde.org#a%20c"); |
|
3443 QTest::newRow("with #") << BA("http://www.kde.org") << BA("a#b") << BA("http://www.kde.org#a#b"); |
|
3444 } |
|
3445 |
|
3446 void tst_QUrl::setEncodedFragment() |
|
3447 { |
|
3448 QFETCH(QByteArray, base); |
|
3449 QFETCH(QByteArray, fragment); |
|
3450 QFETCH(QByteArray, expected); |
|
3451 QUrl u; |
|
3452 u.setEncodedUrl(base, QUrl::TolerantMode); |
|
3453 QVERIFY(u.isValid()); |
|
3454 u.setEncodedFragment(fragment); |
|
3455 QVERIFY(u.isValid()); |
|
3456 QVERIFY(u.hasFragment()); |
|
3457 QCOMPARE(QString::fromLatin1(u.toEncoded()), QString::fromLatin1(expected)); |
|
3458 } |
|
3459 |
|
3460 void tst_QUrl::fromEncoded() |
|
3461 { |
|
3462 QUrl qurl2 = QUrl::fromEncoded("print:/specials/Print%20To%20File%20(PDF%252FAcrobat)", QUrl::TolerantMode); |
|
3463 QCOMPARE(qurl2.path(), QString::fromLatin1("/specials/Print To File (PDF%2FAcrobat)")); |
|
3464 QCOMPARE(QFileInfo(qurl2.path()).fileName(), QString::fromLatin1("Print To File (PDF%2FAcrobat)")); |
|
3465 QCOMPARE(qurl2.toEncoded().constData(), "print:/specials/Print%20To%20File%20(PDF%252FAcrobat)"); |
|
3466 |
|
3467 QUrl qurl = QUrl::fromEncoded("http://\303\244.de"); |
|
3468 QVERIFY(qurl.isValid()); |
|
3469 QCOMPARE(qurl.toEncoded().constData(), "http://xn--4ca.de"); |
|
3470 |
|
3471 QUrl qurltest(QUrl::fromPercentEncoding("http://\303\244.de")); |
|
3472 QVERIFY(qurltest.isValid()); |
|
3473 |
|
3474 QUrl qurl_newline_1 = QUrl::fromEncoded("http://www.foo.bar/foo/bar\ngnork", QUrl::TolerantMode); |
|
3475 QVERIFY(qurl_newline_1.isValid()); |
|
3476 QCOMPARE(qurl_newline_1.toEncoded().constData(), "http://www.foo.bar/foo/bar%0Agnork"); |
|
3477 } |
|
3478 |
|
3479 void tst_QUrl::stripTrailingSlash() |
|
3480 { |
|
3481 QUrl u1( "ftp://ftp.de.kde.org/dir" ); |
|
3482 QUrl u2( "ftp://ftp.de.kde.org/dir/" ); |
|
3483 QUrl::FormattingOptions options = QUrl::None; |
|
3484 options |= QUrl::StripTrailingSlash; |
|
3485 QString str1 = u1.toString(options); |
|
3486 QString str2 = u2.toString(options); |
|
3487 QCOMPARE( str1, u1.toString() ); |
|
3488 QCOMPARE( str2, u1.toString() ); |
|
3489 bool same = str1 == str2; |
|
3490 QVERIFY( same ); |
|
3491 } |
|
3492 |
|
3493 void tst_QUrl::hosts_data() |
|
3494 { |
|
3495 QTest::addColumn<QString>("url"); |
|
3496 QTest::addColumn<QString>("host"); |
|
3497 |
|
3498 QTest::newRow("empty") << QString("") << QString(""); |
|
3499 QTest::newRow("empty1") << QString("file:///file") << QString(""); |
|
3500 QTest::newRow("empty2") << QString("file:/file") << QString(""); |
|
3501 QTest::newRow("empty3") << QString("http:///file") << QString(""); |
|
3502 QTest::newRow("empty4") << QString("http:/file") << QString(""); |
|
3503 |
|
3504 // numeric hostnames |
|
3505 QTest::newRow("http://123/") << QString("http://123/") << QString("123"); |
|
3506 QTest::newRow("http://456/") << QString("http://456/") << QString("456"); |
|
3507 QTest::newRow("http://1000/") << QString("http://1000/") << QString("1000"); |
|
3508 |
|
3509 // IP literals |
|
3510 QTest::newRow("normal-ip-literal") << QString("http://1.2.3.4") << QString("1.2.3.4"); |
|
3511 QTest::newRow("normal-ip-literal-with-port") << QString("http://1.2.3.4:80") |
|
3512 << QString("1.2.3.4"); |
|
3513 QTest::newRow("ipv6-literal") << QString("http://[::1]") << QString("::1"); |
|
3514 QTest::newRow("ipv6-literal-with-port") << QString("http://[::1]:80") << QString("::1"); |
|
3515 QTest::newRow("long-ipv6-literal") << QString("http://[2001:200:0:8002:203:47ff:fea5:3085]") |
|
3516 << QString("2001:200:0:8002:203:47ff:fea5:3085"); |
|
3517 QTest::newRow("long-ipv6-literal-with-port") << QString("http://[2001:200:0:8002:203:47ff:fea5:3085]:80") |
|
3518 << QString("2001:200:0:8002:203:47ff:fea5:3085"); |
|
3519 QTest::newRow("ipv6-literal-v4compat") << QString("http://[::255.254.253.252]") |
|
3520 << QString("::255.254.253.252"); |
|
3521 QTest::newRow("ipv6-literal-v4compat-2") << QString("http://[1000::ffff:127.128.129.1]") |
|
3522 << QString("1000::ffff:127.128.129.1"); |
|
3523 QTest::newRow("long-ipv6-literal-v4compat") << QString("http://[fec0:8000::8002:1000:ffff:200.100.50.250]") |
|
3524 << QString("fec0:8000::8002:1000:ffff:200.100.50.250"); |
|
3525 QTest::newRow("longer-ipv6-literal-v4compat") << QString("http://[fec0:8000:4000:8002:1000:ffff:200.100.50.250]") |
|
3526 << QString("fec0:8000:4000:8002:1000:ffff:200.100.50.250"); |
|
3527 |
|
3528 #if 0 |
|
3529 // this is actually invalid |
|
3530 QTest::newRow("mac-literal") << QString("obex://[00:30:1b:b7:21:fb]") |
|
3531 << QString("00:30:1b:b7:21:fb"); |
|
3532 #endif |
|
3533 |
|
3534 // normal hostnames |
|
3535 QTest::newRow("normal") << QString("http://intern") << QString("intern"); |
|
3536 QTest::newRow("normal2") << QString("http://qt.nokia.com") << QString("qt.nokia.com"); |
|
3537 |
|
3538 // IDN hostnames |
|
3539 QTest::newRow("idn") << QString(QLatin1String("http://\345r.no")) << QString(QLatin1String("\345r.no")); |
|
3540 QTest::newRow("idn-ace") << QString("http://xn--r-1fa.no") << QString(QLatin1String("\345r.no")); |
|
3541 } |
|
3542 |
|
3543 void tst_QUrl::hosts() |
|
3544 { |
|
3545 QFETCH(QString, url); |
|
3546 |
|
3547 QTEST(QUrl(url).host(), "host"); |
|
3548 } |
|
3549 |
|
3550 void tst_QUrl::setPort() |
|
3551 { |
|
3552 { |
|
3553 QUrl url; |
|
3554 QVERIFY(url.toString().isEmpty()); |
|
3555 url.setPort(80); |
|
3556 QCOMPARE(url.port(), 80); |
|
3557 QCOMPARE(url.toString(), QString::fromLatin1("//:80")); |
|
3558 url.setPort(-1); |
|
3559 QCOMPARE(url.port(), -1); |
|
3560 QVERIFY(url.toString().isEmpty()); |
|
3561 url.setPort(80); |
|
3562 QTest::ignoreMessage(QtWarningMsg, "QUrl::setPort: Out of range"); |
|
3563 url.setPort(65536); |
|
3564 QCOMPARE(url.port(), -1); |
|
3565 } |
|
3566 } |
|
3567 |
|
3568 void tst_QUrl::toEncoded_data() |
|
3569 { |
|
3570 QTest::addColumn<QByteArray>("url"); |
|
3571 QTest::addColumn<QUrl::FormattingOptions>("options"); |
|
3572 QTest::addColumn<QByteArray>("encoded"); |
|
3573 QTest::newRow("file:///dir/") << QByteArray("file:///dir/") |
|
3574 << QUrl::FormattingOptions(QUrl::StripTrailingSlash) |
|
3575 << QByteArray("file:///dir"); |
|
3576 } |
|
3577 |
|
3578 void tst_QUrl::toEncoded() |
|
3579 { |
|
3580 QFETCH(QByteArray, url); |
|
3581 QFETCH(QUrl::FormattingOptions, options); |
|
3582 QFETCH(QByteArray, encoded); |
|
3583 |
|
3584 QCOMPARE(QUrl::fromEncoded(url).toEncoded(options), encoded); |
|
3585 } |
|
3586 |
|
3587 void tst_QUrl::setAuthority_data() |
|
3588 { |
|
3589 QTest::addColumn<QString>("authority"); |
|
3590 QTest::addColumn<QString>("url"); |
|
3591 QTest::newRow("Plain auth") << QString("62.70.27.22:21") << QString("//62.70.27.22:21"); |
|
3592 QTest::newRow("Yet another plain auth") << QString("192.168.1.1:21") << QString("//192.168.1.1:21"); |
|
3593 QTest::newRow("Auth without port") << QString("192.168.1.1") << QString("//192.168.1.1"); |
|
3594 QTest::newRow("Auth w/full hostname without port") << QString("shusaku.troll.no") << QString("//shusaku.troll.no"); |
|
3595 QTest::newRow("Auth w/hostname without port") << QString("shusaku") << QString("//shusaku"); |
|
3596 QTest::newRow("Auth w/full hostname that ends with number, without port") << QString("shusaku.troll.no.2") << QString("//shusaku.troll.no.2"); |
|
3597 QTest::newRow("Auth w/hostname that ends with number, without port") << QString("shusaku2") << QString("//shusaku2"); |
|
3598 QTest::newRow("Empty auth") << QString() << QString(); |
|
3599 } |
|
3600 |
|
3601 void tst_QUrl::setAuthority() |
|
3602 { |
|
3603 QUrl u; |
|
3604 QFETCH(QString, authority); |
|
3605 QFETCH(QString, url); |
|
3606 u.setAuthority(authority); |
|
3607 QCOMPARE(u.toString(), url); |
|
3608 } |
|
3609 |
|
3610 void tst_QUrl::errorString() |
|
3611 { |
|
3612 QUrl u = QUrl::fromEncoded("http://strange<username>@bad_hostname/", QUrl::StrictMode); |
|
3613 QVERIFY(!u.isValid()); |
|
3614 QString errorString = "Invalid URL \"http://strange<username>@bad_hostname/\": " |
|
3615 "error at position 14: expected end of URL, but found '<'"; |
|
3616 QCOMPARE(u.errorString(), errorString); |
|
3617 |
|
3618 QUrl v; |
|
3619 errorString = "Invalid URL \"\": "; |
|
3620 QCOMPARE(v.errorString(), errorString); |
|
3621 } |
|
3622 |
|
3623 void tst_QUrl::clear() |
|
3624 { |
|
3625 QUrl url("a"); |
|
3626 QUrl url2("a"); |
|
3627 QCOMPARE(url, url2); |
|
3628 url.clear(); |
|
3629 QVERIFY(url != url2); |
|
3630 } |
|
3631 |
|
3632 void tst_QUrl::binaryData_data() |
|
3633 { |
|
3634 QTest::addColumn<QString>("url"); |
|
3635 QTest::newRow("username") << "http://%01%0D%0A%7F@foo/"; |
|
3636 QTest::newRow("username-at") << "http://abc%40_def@foo/"; |
|
3637 QTest::newRow("username-nul") << "http://abc%00_def@foo/"; |
|
3638 QTest::newRow("username-colon") << "http://abc%3A_def@foo/"; |
|
3639 QTest::newRow("username-nonutf8") << "http://abc%E1_def@foo/"; |
|
3640 |
|
3641 QTest::newRow("password") << "http://user:%01%0D%0A%7F@foo/"; |
|
3642 QTest::newRow("password-at") << "http://user:abc%40_def@foo/"; |
|
3643 QTest::newRow("password-nul") << "http://user:abc%00_def@foo/"; |
|
3644 QTest::newRow("password-nonutf8") << "http://user:abc%E1_def@foo/"; |
|
3645 |
|
3646 QTest::newRow("file") << "http://foo/%01%0D%0A%7F"; |
|
3647 QTest::newRow("file-nul") << "http://foo/abc%00_def"; |
|
3648 QTest::newRow("file-hash") << "http://foo/abc%23_def"; |
|
3649 QTest::newRow("file-question") << "http://foo/abc%3F_def"; |
|
3650 QTest::newRow("file-nonutf8") << "http://foo/abc%E1_def"; |
|
3651 QTest::newRow("file-slash") << "http://foo/abc%2f_def"; |
|
3652 |
|
3653 QTest::newRow("ref") << "http://foo/file#a%01%0D%0A%7F"; |
|
3654 QTest::newRow("ref-nul") << "http://foo/file#abc%00_def"; |
|
3655 QTest::newRow("ref-question") << "http://foo/file#abc?_def"; |
|
3656 QTest::newRow("ref-nonutf8") << "http://foo/file#abc%E1_def"; |
|
3657 |
|
3658 QTest::newRow("query-value") << "http://foo/query?foo=%01%0D%0A%7F"; |
|
3659 QTest::newRow("query-value-nul") << "http://foo/query?foo=abc%00_def"; |
|
3660 QTest::newRow("query-value-nonutf8") << "http://foo/query?foo=abc%E1_def"; |
|
3661 |
|
3662 QTest::newRow("query-name") << "http://foo/query/a%01%0D%0A%7Fz=foo"; |
|
3663 QTest::newRow("query-name-nul") << "http://foo/query/abc%00_def=foo"; |
|
3664 QTest::newRow("query-name-nonutf8") << "http://foo/query/abc%E1_def=foo"; |
|
3665 } |
|
3666 |
|
3667 void tst_QUrl::binaryData() |
|
3668 { |
|
3669 QFETCH(QString, url); |
|
3670 QUrl u = QUrl::fromEncoded(url.toUtf8()); |
|
3671 |
|
3672 QVERIFY(u.isValid()); |
|
3673 QVERIFY(!u.isEmpty()); |
|
3674 |
|
3675 QString url2 = QString::fromUtf8(u.toEncoded()); |
|
3676 //QCOMPARE(url2.length(), url.length()); |
|
3677 QCOMPARE(url2, url); |
|
3678 } |
|
3679 |
|
3680 void tst_QUrl::fromUserInput_data() |
|
3681 { |
|
3682 QTest::addColumn<QString>("string"); |
|
3683 QTest::addColumn<QUrl>("url"); |
|
3684 |
|
3685 // Null |
|
3686 QTest::newRow("null") << QString() << QUrl(); |
|
3687 |
|
3688 // File |
|
3689 QDirIterator it(QDir::homePath()); |
|
3690 QString fileString; |
|
3691 int c = 0; |
|
3692 while (it.hasNext()) { |
|
3693 it.next(); |
|
3694 QTest::newRow(QString("file-%1").arg(c++).toLatin1()) << it.filePath() << QUrl::fromLocalFile(it.filePath()); |
|
3695 } |
|
3696 |
|
3697 // basic latin1 |
|
3698 QTest::newRow("unicode-0") << QString::fromUtf8("\xC3\xA5.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xC3\xA5.com/").toUtf8(), QUrl::TolerantMode); |
|
3699 // unicode |
|
3700 QTest::newRow("unicode-1") << QString::fromUtf8("\xCE\xBB.com/") << QUrl::fromEncoded(QString::fromUtf8("http://\xCE\xBB.com/").toUtf8(), QUrl::TolerantMode); |
|
3701 |
|
3702 // no scheme |
|
3703 QTest::newRow("add scheme-0") << "webkit.org" << QUrl("http://webkit.org"); |
|
3704 QTest::newRow("add scheme-1") << "www.webkit.org" << QUrl("http://www.webkit.org"); |
|
3705 QTest::newRow("add scheme-2") << "ftp.webkit.org" << QUrl("ftp://ftp.webkit.org"); |
|
3706 QTest::newRow("add scheme-3") << "webkit" << QUrl("webkit"); |
|
3707 |
|
3708 // QUrl's tolerant parser should already handle this |
|
3709 QTest::newRow("not-encoded-0") << "http://webkit.org/test page.html" << QUrl("http://webkit.org/test%20page.html"); |
|
3710 |
|
3711 // Make sure the :80, i.e. port doesn't screw anything up |
|
3712 QUrl portUrl("http://webkit.org"); |
|
3713 portUrl.setPort(80); |
|
3714 QTest::newRow("port-0") << "webkit.org:80" << portUrl; |
|
3715 QTest::newRow("port-1") << "http://webkit.org:80" << portUrl; |
|
3716 |
|
3717 // mailto doesn't have a ://, but is valid |
|
3718 QUrl mailto("somebody@somewhere.net"); |
|
3719 mailto.setScheme("mailto"); |
|
3720 QTest::newRow("mailto") << "mailto:somebody@somewhere.net" << mailto; |
|
3721 |
|
3722 // misc |
|
3723 QTest::newRow("localhost-0") << "localhost" << QUrl("http://localhost"); |
|
3724 QTest::newRow("localhost-1") << "localhost:80" << QUrl("http://localhost:80"); |
|
3725 QTest::newRow("spaces-0") << " http://webkit.org/test page.html " << QUrl("http://webkit.org/test%20page.html"); |
|
3726 QTest::newRow("trash-0") << "webkit.org/test?someData=42%&someOtherData=abcde#anchor" << QUrl::fromEncoded("http://webkit.org/test?someData=42%25&someOtherData=abcde#anchor"); |
|
3727 |
|
3728 // FYI: The scheme in the resulting url user |
|
3729 QUrl authUrl("user:pass@domain.com"); |
|
3730 QTest::newRow("misc-1") << "user:pass@domain.com" << authUrl; |
|
3731 } |
|
3732 |
|
3733 // public static QUrl guessUrlFromString(QString const& string) |
|
3734 void tst_QUrl::fromUserInput() |
|
3735 { |
|
3736 QFETCH(QString, string); |
|
3737 QFETCH(QUrl, url); |
|
3738 |
|
3739 QUrl guessedUrl = QUrl::fromUserInput(string); |
|
3740 QCOMPARE(guessedUrl, url); |
|
3741 } |
|
3742 |
|
3743 void tst_QUrl::task_199967() |
|
3744 { |
|
3745 { |
|
3746 QUrl url; |
|
3747 url.setEncodedUrl("LABEL=USB_STICK", QUrl::TolerantMode); |
|
3748 QVERIFY( url.isValid() ); |
|
3749 QCOMPARE( url.path(), QString("LABEL=USB_STICK") ); |
|
3750 QVERIFY( !url.isEmpty() ); |
|
3751 } |
|
3752 { |
|
3753 QUrl url; |
|
3754 url.setEncodedUrl("LABEL=USB_STICK", QUrl::TolerantMode); |
|
3755 QVERIFY( url.isValid() ); |
|
3756 QVERIFY( !url.isEmpty() ); |
|
3757 QCOMPARE( url.path(), QString("LABEL=USB_STICK") ); |
|
3758 } |
|
3759 } |
|
3760 |
|
3761 void tst_QUrl::task_240612() |
|
3762 { |
|
3763 QUrl url; |
|
3764 url.setEncodedPath("test.txt"); |
|
3765 url.setHost("example.com"); |
|
3766 |
|
3767 QCOMPARE(url.toEncoded().constData(), "//example.com/test.txt"); |
|
3768 |
|
3769 url.path(); |
|
3770 QCOMPARE(url.toEncoded().constData(), "//example.com/test.txt"); |
|
3771 } |
|
3772 |
|
3773 #ifdef QT3_SUPPORT |
|
3774 void tst_QUrl::dirPath() |
|
3775 { |
|
3776 QCOMPARE(QUrl("http://www.vg.no/test/file.txt").dirPath(), QString("/test")); |
|
3777 } |
|
3778 #endif |
|
3779 |
|
3780 void tst_QUrl::resolvedWithAbsoluteSchemes() const |
|
3781 { |
|
3782 QFETCH(QUrl, base); |
|
3783 QFETCH(QUrl, relative); |
|
3784 QFETCH(QUrl, expected); |
|
3785 |
|
3786 /* Check our input. */ |
|
3787 QVERIFY(relative.isValid()); |
|
3788 QVERIFY(base.isValid()); |
|
3789 QVERIFY(expected.isValid()); |
|
3790 |
|
3791 const QUrl result(base.resolved(relative)); |
|
3792 |
|
3793 QVERIFY(result.isValid()); |
|
3794 QCOMPARE(result, expected); |
|
3795 } |
|
3796 |
|
3797 void tst_QUrl::resolvedWithAbsoluteSchemes_data() const |
|
3798 { |
|
3799 QTest::addColumn<QUrl>("base"); |
|
3800 QTest::addColumn<QUrl>("relative"); |
|
3801 QTest::addColumn<QUrl>("expected"); |
|
3802 |
|
3803 QTest::newRow("Absolute file:/// against absolute FTP.") |
|
3804 << QUrl::fromEncoded("file:///foo/") |
|
3805 << QUrl::fromEncoded("ftp://example.com/") |
|
3806 << QUrl::fromEncoded("ftp://example.com/"); |
|
3807 |
|
3808 QTest::newRow("Absolute file:/// against absolute HTTP.") |
|
3809 << QUrl::fromEncoded("file:///foo/") |
|
3810 << QUrl::fromEncoded("http://example.com/") |
|
3811 << QUrl::fromEncoded("http://example.com/"); |
|
3812 |
|
3813 |
|
3814 QTest::newRow("Absolute file:/// against data scheme.") |
|
3815 << QUrl::fromEncoded("file:///foo/") |
|
3816 << QUrl::fromEncoded("data:application/xml,%3Ce%2F%3E") |
|
3817 << QUrl::fromEncoded("data:application/xml,%3Ce%2F%3E"); |
|
3818 |
|
3819 QTest::newRow("Resolve with base url and port.") |
|
3820 << QUrl::fromEncoded("http://www.foo.com:8080/") |
|
3821 << QUrl::fromEncoded("newfile.html") |
|
3822 << QUrl::fromEncoded("http://www.foo.com:8080/newfile.html"); |
|
3823 } |
|
3824 |
|
3825 QTEST_MAIN(tst_QUrl) |
|
3826 #include "tst_qurl.moc" |