UriTest.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2006-2007 by Peter Dimov.
00004 
00005 This file is part of Calitko (http://www.calitko.org).
00006 
00007 Calitko is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2 of the License, or
00010 (at your option) any later version.
00011 
00012 Calitko is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Calitko; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 */
00022 
00023 #include "Qt.h"
00024 #include "../Uri.h"
00025 #include "Imports.cpp"
00026 
00027 using namespace Utils::Testing;
00028 
00029 
00030 namespace Utils {
00031 namespace Testing {
00032 
00033 class UriTest : public CppUnit::TestFixture
00034 {
00035     CPPUNIT_TEST_SUITE (UriTest);
00036     CPPUNIT_TEST (testNoEncodingScheme);
00037     CPPUNIT_TEST (testNoEncodingSchemeWithEmptyAuthority);
00038     CPPUNIT_TEST (testNoEncodingSchemeWithAuthority);
00039     CPPUNIT_TEST (testNoEncodingSchemeWithEmptyAuthorityWithPath);
00040     CPPUNIT_TEST (testNoEncodingSchemeWithEmptyAuthorityWithEmptyPathWithEmptyQuery);
00041     CPPUNIT_TEST (testNoEncodingSchemeWithEmptyAuthorityWithEmptyPathWithEmptyFragment);
00042     CPPUNIT_TEST (testNoEncodingSchemeWithEmptyAuthorityWithEmptyPathWithEmptyQueryWithEmptyFragment);
00043     CPPUNIT_TEST (testNoEncodingSchemeWithAuthorityWithPath);
00044     CPPUNIT_TEST (testNoEncodingSchemeWithAuthorityWithQuery);
00045     CPPUNIT_TEST (testNoEncodingSchemeWithAuthorityWithFragment);
00046     CPPUNIT_TEST (testNoEncodingSchemeWithAuthorityWithPathWithQueryWithFragment);
00047     CPPUNIT_TEST (testNoEncodingAuthorityWithPathWithQueryWithFragment);
00048     CPPUNIT_TEST (testNoEncodingPathWithQueryWithFragment);
00049     CPPUNIT_TEST (testNoEncodingQueryWithFragment);
00050     CPPUNIT_TEST (testNoEncodingQuery);
00051     CPPUNIT_TEST (testNoEncodingFragment);
00052     CPPUNIT_TEST (testEncodingIncorrectlyUncodedUriIsNull);
00053     CPPUNIT_TEST (testEncodingCorrectlyEncodedUri);
00054     CPPUNIT_TEST (testParseUriWithoutQueryThenAppendQueryTwice);
00055     CPPUNIT_TEST (testParseUriWithQueryThenAppendQueryTwice);
00056     CPPUNIT_TEST (testParseUriWithoutQueryThenAppendQueryItemAFewTimes);
00057     CPPUNIT_TEST (testParseUriWithQueryThenAppendQueryItemAFewTimes);
00058     CPPUNIT_TEST (testParseUnencodedProduceEncoded);
00059     CPPUNIT_TEST (testCompareTwoEqualNonEmptyUris);
00060     CPPUNIT_TEST (testCompareTwoEqualEmptyUris);
00061     CPPUNIT_TEST (testCompareTwoDifferentNonEmptyUris);
00062     CPPUNIT_TEST (testCompareEmptyAndNonEmptyUris);
00063     CPPUNIT_TEST (testCompareUrisWithEmptyAndNullQuery);
00064     CPPUNIT_TEST (testKeysAndValuesInQueryItemsGetCorrectlyEncoded);
00065     CPPUNIT_TEST (testParseEncodedUriQueryIsNotPrematurelyDecoded);
00066     CPPUNIT_TEST (testParseQueryItemsFromQueryTwoItems);
00067     CPPUNIT_TEST (testParseQueryItemsFromEmptyQuery);
00068     CPPUNIT_TEST (testEncodingAllCharsInQuery);
00069     CPPUNIT_TEST (testQueryItemValueNoneValueAssociated);
00070     CPPUNIT_TEST (testQueryItemValueOneValueAssociated);
00071     CPPUNIT_TEST (testQueryItemValueTwoValuesAssociated);
00072     CPPUNIT_TEST (testParsingUriWithPortButWithoutHostFails);
00073     CPPUNIT_TEST (testParsingUriWithUserinfoButWithoutHostFails);
00074     CPPUNIT_TEST (testParsingUriWithUserinfoAndPortButWithoutHostFails);
00075     CPPUNIT_TEST (testGettingSubsetsOfEncodedRepresentation);
00076     CPPUNIT_TEST_SUITE_END();
00077 
00078     static const QByteArray validUriUnencoded1;
00079     static const QByteArray validUriUnencoded2;
00080 
00081 public:
00082 
00083     void scenarioParseAndWrite (bool encoded,
00084                                 const QByteArray &bytes,
00085                                 const QByteArray &scheme,
00086                                 const QByteArray &authority,
00087                                 const QByteArray &path,
00088                                 const QByteArray &query,
00089                                 const QByteArray &fragment)
00090     {
00091         Uri uri;
00092         if (encoded)
00093             uri = Uri::fromEncoded (bytes);
00094         else
00095             uri = Uri::fromUnencoded (bytes);
00096         /*
00097         qDebug() << encoded << bytes;
00098         qDebug() << uri.scheme() << uri.authority() << uri.path()
00099                  << uri.query() << uri.fragment();
00100         qDebug() << uri.encoded();
00101         qDebug() << uri.unencoded();
00102         */
00103         CPPUNIT_ASSERT (uri.scheme() == scheme);
00104         CPPUNIT_ASSERT (uri.authority() == authority);
00105         CPPUNIT_ASSERT (uri.path() == path);
00106         CPPUNIT_ASSERT (uri.query() == query);
00107         CPPUNIT_ASSERT (uri.fragment() == fragment);
00108 
00109         if (encoded)
00110             CPPUNIT_ASSERT (uri.encoded() == bytes);
00111         else
00112             CPPUNIT_ASSERT (uri.unencoded() == bytes);
00113     }
00114 
00115     void testNoEncodingScheme()
00116     {
00117         scenarioParseAndWrite (false, "my-scheme:",
00118                                "my-scheme", "", "", "", "");
00119     }
00120 
00121     void testNoEncodingSchemeWithEmptyAuthority()
00122     {
00123         scenarioParseAndWrite (false, "my-scheme://",
00124                                "my-scheme", "", "", "", "");
00125     }
00126 
00127     void testNoEncodingSchemeWithAuthority()
00128     {
00129         scenarioParseAndWrite (false, "my-scheme://test",
00130                                "my-scheme", "test", "", "", "");
00131     }
00132 
00133     void testNoEncodingSchemeWithEmptyAuthorityWithEmptyPathWithEmptyQuery()
00134     {
00135         scenarioParseAndWrite (false, "schema://?",
00136                                "schema", "", "", "", "");
00137     }
00138 
00139     void testNoEncodingSchemeWithEmptyAuthorityWithEmptyPathWithEmptyFragment()
00140     {
00141         scenarioParseAndWrite (false, "schema://#",
00142                                "schema", "", "", "", "");
00143     }
00144 
00145     void testNoEncodingSchemeWithEmptyAuthorityWithEmptyPathWithEmptyQueryWithEmptyFragment()
00146     {
00147         scenarioParseAndWrite (false, "schema://?#",
00148                                "schema", "", "", "", "");
00149     }
00150 
00151     void testNoEncodingSchemeWithEmptyAuthorityWithPath()
00152     {
00153         scenarioParseAndWrite (false, "file:///",
00154                                "file", "", "/", "", "");
00155     }
00156 
00157     void testNoEncodingSchemeWithAuthorityWithPath()
00158     {
00159         scenarioParseAndWrite (false, "http://www.calitko.org/source-talk",
00160                                "http", "www.calitko.org",
00161                                "/source-talk", "", "");
00162     }
00163 
00164     void testNoEncodingSchemeWithAuthorityWithQuery()
00165     {
00166         scenarioParseAndWrite (false, "http://www.calitko.org?p=1",
00167                                "http", "www.calitko.org", "", "p=1", "");
00168     }
00169 
00170     void testNoEncodingSchemeWithAuthorityWithFragment()
00171     {
00172         scenarioParseAndWrite (false, "http://www.calitko.org#Welcome",
00173                                "http", "www.calitko.org", "", "", "Welcome");
00174     }
00175 
00176     void testNoEncodingSchemeWithAuthorityWithPathWithQueryWithFragment()
00177     {
00178         scenarioParseAndWrite (false, "http://www.calitko.org/?p=1#Welcome",
00179                                "http", "www.calitko.org",
00180                                "/", "p=1", "Welcome");
00181     }
00182 
00183     void testNoEncodingAuthorityWithPathWithQueryWithFragment()
00184     {
00185         scenarioParseAndWrite (false, "//www.calitko.org/?p=1#Welcome",
00186                                "", "www.calitko.org", "/", "p=1", "Welcome");
00187     }
00188 
00189     void testNoEncodingPathWithQueryWithFragment()
00190     {
00191         scenarioParseAndWrite (false, "/?p=1#Welcome",
00192                                "", "", "/", "p=1", "Welcome");
00193     }
00194 
00195     void testNoEncodingQueryWithFragment()
00196     {
00197         scenarioParseAndWrite (false, "?p=1#Welcome",
00198                                "", "", "", "p=1", "Welcome");
00199     }
00200 
00201     void testNoEncodingQuery()
00202     {
00203         scenarioParseAndWrite (false, "?p=1",
00204                                "", "", "", "p=1", "");
00205     }
00206 
00207     void testNoEncodingFragment()
00208     {
00209         scenarioParseAndWrite (false, "#Welcome",
00210                                "", "", "", "", "Welcome");
00211     }
00212 
00213     void testEncodingIncorrectlyUncodedUriIsNull()
00214     {
00215         // "%bv" is invalid percent encoding:
00216         Uri uri = Uri::fromEncoded ("http://www.calitko.org?%bva");
00217         CPPUNIT_ASSERT (uri == Uri());
00218     }
00219 
00220     void testEncodingCorrectlyEncodedUri()
00221     {
00222         scenarioParseAndWrite (true, "http://calitko.org?name%26=%3Dval",
00223                                "http", "calitko.org", "", "name&==val", "");
00224     }
00225 
00226     void scenarioParseUriAndAppendQuery (const QByteArray &bytes,
00227                                          const QByteArray &initialQuery,
00228                                          const QList <QByteArray> &extraQueries)
00229     {
00230         Uri uri;
00231         if (initialQuery.isEmpty())
00232             uri = Uri::fromUnencoded (bytes);
00233         else
00234             uri = Uri::fromUnencoded (bytes + '?' + initialQuery);
00235 
00236         QByteArray fullQuery = initialQuery;
00237         foreach (QByteArray query, extraQueries) {
00238             uri.appendQuery (query);
00239             fullQuery += query;
00240             CPPUNIT_ASSERT (uri.query() == fullQuery);
00241             CPPUNIT_ASSERT (uri.unencoded() == bytes + '?' + fullQuery);
00242         }
00243     }
00244 
00245     void testParseUriWithoutQueryThenAppendQueryTwice()
00246     {
00247         scenarioParseUriAndAppendQuery ("http://tracker.com/announce.php",
00248                                         "",
00249                                         QList <QByteArray> ()
00250                                         += QByteArray ("name1=val1&name2=val2")
00251                                         += QByteArray ("&name3"));
00252     }
00253 
00254     void testParseUriWithQueryThenAppendQueryTwice()
00255     {
00256         scenarioParseUriAndAppendQuery ("http://tracker.com/announce.php",
00257                                         "someparam=somevalue",
00258                                         QList <QByteArray> ()
00259                                         += QByteArray ("name1=val1&name2=val2")
00260                                         += QByteArray ("&name3"));
00261     }
00262 
00263     void scenarioParseUriAndAppendQueryItem (const QByteArray &bytes,
00264                                              const QByteArray &initialQuery,
00265                                              const Uri::QueryItemList &items)
00266     {
00267         Uri uri;
00268         if (initialQuery.isEmpty())
00269             uri = Uri::fromUnencoded (bytes);
00270         else
00271             uri = Uri::fromUnencoded (bytes + '?' + initialQuery);
00272 
00273         Uri uri2 (uri), uri3 (uri);
00274         QByteArray fullQuery = initialQuery;
00275         foreach (Uri::QueryItem item, items) {
00276             uri.appendQueryItem (item.first, item.second);
00277             uri2.appendQueryItem (item);
00278             if (!fullQuery.isEmpty())
00279                 fullQuery += '&';
00280             fullQuery += item.first;
00281             if (!item.second.isEmpty())
00282                 fullQuery += '=' + item.second;
00283         }
00284         uri3.appendQueryItems (items);
00285         CPPUNIT_ASSERT (uri.query() == fullQuery);
00286         CPPUNIT_ASSERT (uri.unencoded() == bytes + '?' + fullQuery);
00287         CPPUNIT_ASSERT (uri2.query() == fullQuery);
00288         CPPUNIT_ASSERT (uri2.unencoded() == bytes + '?' + fullQuery);
00289         CPPUNIT_ASSERT (uri3.query() == fullQuery);
00290         CPPUNIT_ASSERT (uri3.unencoded() == bytes + '?' + fullQuery);
00291     }
00292 
00293     void testParseUriWithoutQueryThenAppendQueryItemAFewTimes()
00294     {
00295         Uri::QueryItemList items;
00296         items += Uri::QueryItem (QByteArray ("key1"), QByteArray ("value1"));
00297         items += Uri::QueryItem (QByteArray ("key2"), QByteArray ("value2"));
00298         items += Uri::QueryItem (QByteArray ("key3"), QByteArray (""));
00299         items += Uri::QueryItem (QByteArray (""), QByteArray ("value2"));
00300         scenarioParseUriAndAppendQueryItem ("http://tracker.com/announce.php",
00301                                             "", items);
00302     }
00303 
00304     void testParseUriWithQueryThenAppendQueryItemAFewTimes()
00305     {
00306         Uri::QueryItemList items;
00307         items += Uri::QueryItem (QByteArray ("key1"), QByteArray ("value1"));
00308         items += Uri::QueryItem (QByteArray ("key2"), QByteArray ("value2"));
00309         items += Uri::QueryItem (QByteArray ("key3"), QByteArray (""));
00310         items += Uri::QueryItem (QByteArray (""), QByteArray ("value2"));
00311         scenarioParseUriAndAppendQueryItem ("http://tracker.com/announce.php",
00312                                             "someparam=somevalue", items);
00313     }
00314 
00315     void testParseUnencodedProduceEncoded()
00316     {
00317         QByteArray unencoded ("file:///This is a test.txt~");
00318         QByteArray encoded ("file:///This%20is%20a%20test.txt~");
00319         Uri uri = Uri::fromUnencoded (unencoded);
00320         CPPUNIT_ASSERT (unencoded == uri.unencoded());
00321         CPPUNIT_ASSERT (encoded == uri.encoded());
00322         uri = Uri::fromEncoded (encoded);
00323         CPPUNIT_ASSERT (unencoded == uri.unencoded());
00324         CPPUNIT_ASSERT (encoded == uri.encoded());
00325     }
00326 
00327     void testCompareTwoEqualNonEmptyUris()
00328     {
00329         Uri uri1 = Uri::fromUnencoded (validUriUnencoded1);
00330         Uri uri2 = Uri::fromUnencoded (validUriUnencoded1);
00331 
00332         CPPUNIT_ASSERT (uri1 == uri2);
00333         CPPUNIT_ASSERT (!(uri1 != uri2));
00334     }
00335 
00336     void testCompareTwoEqualEmptyUris()
00337     {
00338         Uri uri1, uri2;
00339 
00340         CPPUNIT_ASSERT (uri1 == uri2);
00341         CPPUNIT_ASSERT (!(uri1 != uri2));
00342     }
00343     void testCompareTwoDifferentNonEmptyUris()
00344     {
00345         Uri uri1 = Uri::fromUnencoded (validUriUnencoded1);
00346         Uri uri2 = Uri::fromUnencoded (validUriUnencoded2);
00347 
00348         CPPUNIT_ASSERT (uri1 != uri2);
00349         CPPUNIT_ASSERT (!(uri1 == uri2));
00350     }
00351 
00352     void testCompareEmptyAndNonEmptyUris()
00353     {
00354         Uri uri1 = Uri::fromUnencoded (validUriUnencoded1);
00355         Uri uri2;
00356 
00357         CPPUNIT_ASSERT (uri1 != uri2);
00358         CPPUNIT_ASSERT (!(uri1 == uri2));
00359     }
00360 
00361     void testCompareUrisWithEmptyAndNullQuery()
00362     {
00363         Uri uri1 = Uri::fromUnencoded ("http://localhost?");
00364         Uri uri2 = Uri::fromUnencoded ("http://localhost");
00365 
00366         CPPUNIT_ASSERT (uri1 != uri2);
00367         CPPUNIT_ASSERT (!(uri1 == uri2));
00368     }
00369 
00371     void testKeysAndValuesInQueryItemsGetCorrectlyEncoded()
00372     {
00373         Uri uri;
00374         Uri::QueryItemList queryItems;
00375         queryItems += Uri::QueryItem ("o&k", "n=o");
00376         uri.appendQueryItems (queryItems);
00377 
00378         CPPUNIT_ASSERT (uri.query() == "o&k=n=o");
00379         CPPUNIT_ASSERT (uri.queryItems() == queryItems);
00380         CPPUNIT_ASSERT (uri.encoded() == "?o%26k=n%3Do");
00381         CPPUNIT_ASSERT (uri.unencoded() == "?o&k=n=o");
00382     }
00383 
00384     void testParseEncodedUriQueryIsNotPrematurelyDecoded()
00385     {
00386         Uri uri = Uri::fromEncoded ("http://www.calitko.org?name=va%26lue&key");
00387         Uri::QueryItemList queryItems;
00388         queryItems += Uri::QueryItem ("name", "va&lue");
00389         queryItems += Uri::QueryItem ("key", "");
00390 
00391         CPPUNIT_ASSERT (uri.queryItems() == queryItems);
00392     }
00393 
00394     void testParseQueryItemsFromQueryTwoItems()
00395     {
00396         Uri uri = Uri::fromEncoded ("http://www.calitko.org?name=value&key");
00397         Uri::QueryItemList queryItems;
00398         queryItems += Uri::QueryItem ("name", "value");
00399         queryItems += Uri::QueryItem ("key", "");
00400 
00401         CPPUNIT_ASSERT (uri.queryItems() == queryItems);
00402     }
00403 
00404     void testParseQueryItemsFromEmptyQuery()
00405     {
00406         Uri uri = Uri::fromEncoded ("http://www.calitko.org?");
00407         CPPUNIT_ASSERT (uri.queryItems() == Uri::QueryItemList());
00408     }
00409 
00410     void testEncodingAllCharsInQuery()
00411     {
00412         const QByteArray allBytes =
00413             "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
00414             "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"
00415             "\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30"
00416             "\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40"
00417             "\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50"
00418             "\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60"
00419             "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70"
00420             "\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80"
00421             "\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90"
00422             "\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0"
00423             "\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0"
00424             "\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0"
00425             "\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0"
00426             "\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0"
00427             "\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0"
00428             "\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff";
00429 
00430         const QByteArray allBytesEncoded =
00431             "%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15"
00432             "%16%17%18%19%1A%1B%1C%1D%1E%1F%20!%22%23$%25%26'()*+,-./01234"
00433             "56789:;%3C%3D%3E?@ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E"
00434             "_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~%7F%80%81%82%83%84%85"
00435             "%86%87%88%89%8A%8B%8C%8D%8E%8F%90%91%92%93%94%95%96%97%98%99%9A"
00436             "%9B%9C%9D%9E%9F%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF"
00437             "%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF%C0%C1%C2%C3%C4"
00438             "%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9"
00439             "%DA%DB%DC%DD%DE%DF%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE"
00440             "%EF%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF";
00441 
00442         Uri uri;
00443         uri.appendQueryItem ("bytes", allBytes);
00444 
00445         CPPUNIT_ASSERT (uri.encoded() == "?bytes=" + allBytesEncoded);
00446     }
00447 
00449     void testQueryItemValueNoneValueAssociated()
00450     {
00451         Uri uri = Uri::fromUnencoded ("http://www.calitko.org?");
00452         CPPUNIT_ASSERT (uri.queryItemValue ("key") == QByteArray());
00453     }
00454 
00456     void testQueryItemValueOneValueAssociated()
00457     {
00458         Uri uri = Uri::fromUnencoded ("http://www.calitko.org?key=value");
00459         CPPUNIT_ASSERT (uri.queryItemValue ("key") == QByteArray ("value"));
00460     }
00461 
00463     void testQueryItemValueTwoValuesAssociated()
00464     {
00465         Uri uri = Uri::fromUnencoded ("http://www.calitko.org?key=value1&key=value2");
00466         CPPUNIT_ASSERT (uri.queryItemValue ("key") == QByteArray ("value1"));
00467     }
00468 
00470     void testParsingUriWithPortButWithoutHostFails()
00471     {
00472         Uri uri = Uri::fromUnencoded ("scheme://:80");
00473         CPPUNIT_ASSERT (uri == Uri());
00474     }
00475 
00477     void testParsingUriWithUserinfoButWithoutHostFails()
00478     {
00479         Uri uri = Uri::fromUnencoded ("scheme://userinfo@/");
00480         CPPUNIT_ASSERT (uri == Uri());
00481     }
00482 
00484     void testParsingUriWithUserinfoAndPortButWithoutHostFails()
00485     {
00486         Uri uri = Uri::fromUnencoded ("scheme://userinfo@:80");
00487         CPPUNIT_ASSERT (uri == Uri());
00488     }
00489 
00498     void testGettingSubsetsOfEncodedRepresentation()
00499     {
00500         Uri uri = Uri::fromUnencoded (validUriUnencoded1);
00501 
00502         CPPUNIT_ASSERT (uri.unencoded() == uri.unencoded (Uri::AllFields));
00503         CPPUNIT_ASSERT (uri.unencoded (Uri::Scheme) == uri.scheme() + ":");
00504         CPPUNIT_ASSERT (uri.unencoded (Uri::UserInfo)
00505                                         == "//" + uri.userInfo() + "@");
00506         CPPUNIT_ASSERT (uri.unencoded (Uri::Host) == "//" + uri.host());
00507         CPPUNIT_ASSERT (uri.unencoded (Uri::Port) == "//:" + uri.port());
00508         CPPUNIT_ASSERT (uri.unencoded (Uri::Authority)
00509                                         == "//" + uri.authority());
00510         CPPUNIT_ASSERT (uri.unencoded (Uri::Path) == uri.path());
00511         CPPUNIT_ASSERT (uri.unencoded (Uri::Query) == "?" + uri.query());
00512         CPPUNIT_ASSERT (uri.unencoded (Uri::Fragment) == "#" + uri.fragment());
00513         CPPUNIT_ASSERT (uri.unencoded (Uri::Fragment) == "#" + uri.fragment());
00514     }
00515 };
00516 
00517 const QByteArray UriTest::validUriUnencoded1 (
00518     "http://user@domain.com:81/some/path?param=value#fragment");
00519 const QByteArray UriTest::validUriUnencoded2 (
00520     "ftp://username@server.net/data/");
00521 
00522 CPPUNIT_TEST_SUITE_REGISTRATION (UriTest);
00523 
00524 } // namespace Testing
00525 } // namespace Utils