mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-17 23:23:47 +02:00
SF# 3181882
This commit is contained in:
parent
dcad41262d
commit
d21cc6edc9
@ -16,14 +16,14 @@
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
@ -69,7 +69,7 @@ URI::URI(const char* uri):
|
||||
parse(std::string(uri));
|
||||
}
|
||||
|
||||
|
||||
|
||||
URI::URI(const std::string& scheme, const std::string& pathEtc):
|
||||
_scheme(scheme),
|
||||
_port(0)
|
||||
@ -81,7 +81,7 @@ URI::URI(const std::string& scheme, const std::string& pathEtc):
|
||||
parsePathEtc(beg, end);
|
||||
}
|
||||
|
||||
|
||||
|
||||
URI::URI(const std::string& scheme, const std::string& authority, const std::string& pathEtc):
|
||||
_scheme(scheme)
|
||||
{
|
||||
@ -131,7 +131,7 @@ URI::URI(const URI& uri):
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
URI::URI(const URI& baseURI, const std::string& relativeURI):
|
||||
_scheme(baseURI._scheme),
|
||||
_userInfo(baseURI._userInfo),
|
||||
@ -165,7 +165,7 @@ URI& URI::operator = (const URI& uri)
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
URI& URI::operator = (const std::string& uri)
|
||||
{
|
||||
clear();
|
||||
@ -252,14 +252,14 @@ void URI::setScheme(const std::string& scheme)
|
||||
_port = getWellKnownPort();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URI::setUserInfo(const std::string& userInfo)
|
||||
{
|
||||
_userInfo.clear();
|
||||
decode(userInfo, _userInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URI::setHost(const std::string& host)
|
||||
{
|
||||
_host = host;
|
||||
@ -280,7 +280,7 @@ void URI::setPort(unsigned short port)
|
||||
_port = port;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string URI::getAuthority() const
|
||||
{
|
||||
std::string auth;
|
||||
@ -298,7 +298,7 @@ std::string URI::getAuthority() const
|
||||
return auth;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URI::setAuthority(const std::string& authority)
|
||||
{
|
||||
_userInfo.clear();
|
||||
@ -309,14 +309,14 @@ void URI::setAuthority(const std::string& authority)
|
||||
parseAuthority(beg, end);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URI::setPath(const std::string& path)
|
||||
{
|
||||
_path.clear();
|
||||
decode(path, _path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URI::setRawQuery(const std::string& query)
|
||||
{
|
||||
_query = query;
|
||||
@ -355,7 +355,7 @@ void URI::setPathEtc(const std::string& pathEtc)
|
||||
parsePathEtc(beg, end);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string URI::getPathEtc() const
|
||||
{
|
||||
std::string pathEtc;
|
||||
@ -363,7 +363,7 @@ std::string URI::getPathEtc() const
|
||||
if (!_query.empty())
|
||||
{
|
||||
pathEtc += '?';
|
||||
encode(_query, RESERVED_QUERY, pathEtc);
|
||||
pathEtc.append(_query);
|
||||
}
|
||||
if (!_fragment.empty())
|
||||
{
|
||||
@ -386,7 +386,7 @@ std::string URI::getPathAndQuery() const
|
||||
return pathAndQuery;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URI::resolve(const std::string& relativeURI)
|
||||
{
|
||||
URI parsedURI(relativeURI);
|
||||
@ -439,7 +439,7 @@ void URI::resolve(const URI& relativeURI)
|
||||
}
|
||||
}
|
||||
}
|
||||
_fragment = relativeURI._fragment;
|
||||
_fragment = relativeURI._fragment;
|
||||
}
|
||||
|
||||
|
||||
@ -454,7 +454,7 @@ bool URI::empty() const
|
||||
return _scheme.empty() && _host.empty() && _path.empty() && _query.empty() && _fragment.empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool URI::operator == (const URI& uri) const
|
||||
{
|
||||
return equals(uri);
|
||||
@ -492,7 +492,7 @@ bool URI::equals(const URI& uri) const
|
||||
&& _fragment == uri._fragment;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URI::normalize()
|
||||
{
|
||||
removeDotSegments(!isRelative());
|
||||
@ -502,7 +502,7 @@ void URI::normalize()
|
||||
void URI::removeDotSegments(bool removeLeading)
|
||||
{
|
||||
if (_path.empty()) return;
|
||||
|
||||
|
||||
bool leadingSlash = *(_path.begin()) == '/';
|
||||
bool trailingSlash = *(_path.rbegin()) == '/';
|
||||
std::vector<std::string> segments;
|
||||
@ -567,10 +567,10 @@ void URI::encode(const std::string& str, const std::string& reserved, std::strin
|
||||
for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)
|
||||
{
|
||||
char c = *it;
|
||||
if (c >= 'a' && c <= 'z' ||
|
||||
c >= 'A' && c <= 'Z' ||
|
||||
if (c >= 'a' && c <= 'z' ||
|
||||
c >= 'A' && c <= 'Z' ||
|
||||
c >= '0' && c <= '9' ||
|
||||
c == '-' || c == '_' ||
|
||||
c == '-' || c == '_' ||
|
||||
c == '.' || c == '~')
|
||||
{
|
||||
encodedStr += c;
|
||||
@ -584,7 +584,7 @@ void URI::encode(const std::string& str, const std::string& reserved, std::strin
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void URI::decode(const std::string& str, std::string& decodedStr)
|
||||
{
|
||||
std::string::const_iterator it = str.begin();
|
||||
@ -672,7 +672,7 @@ void URI::parse(const std::string& uri)
|
||||
}
|
||||
parsePathEtc(it, end);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
it = uri.begin();
|
||||
parsePathEtc(it, end);
|
||||
@ -761,7 +761,7 @@ void URI::parsePathEtc(std::string::const_iterator& it, const std::string::const
|
||||
{
|
||||
++it;
|
||||
parseFragment(it, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -833,7 +833,7 @@ void URI::buildPath(const std::vector<std::string>& segments, bool leadingSlash,
|
||||
else _path += '/';
|
||||
_path.append(*it);
|
||||
}
|
||||
if (trailingSlash)
|
||||
if (trailingSlash)
|
||||
_path += '/';
|
||||
}
|
||||
|
||||
|
@ -12,14 +12,14 @@
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
@ -60,58 +60,58 @@ void URITest::testConstruction()
|
||||
assert (uri.getPath().empty());
|
||||
assert (uri.getQuery().empty());
|
||||
assert (uri.getFragment().empty());
|
||||
|
||||
|
||||
uri.setScheme("ftp");
|
||||
assert (uri.getScheme() == "ftp");
|
||||
assert (uri.getPort() == 21);
|
||||
|
||||
|
||||
uri.setScheme("HTTP");
|
||||
assert (uri.getScheme() == "http");
|
||||
|
||||
|
||||
uri.setAuthority("www.appinf.com");
|
||||
assert (uri.getAuthority() == "www.appinf.com");
|
||||
assert (uri.getPort() == 80);
|
||||
|
||||
|
||||
uri.setAuthority("user@services.appinf.com:8000");
|
||||
assert (uri.getUserInfo() == "user");
|
||||
assert (uri.getHost() == "services.appinf.com");
|
||||
assert (uri.getPort() == 8000);
|
||||
|
||||
|
||||
uri.setPath("/index.html");
|
||||
assert (uri.getPath() == "/index.html");
|
||||
|
||||
|
||||
uri.setPath("/file%20with%20spaces.html");
|
||||
assert (uri.getPath() == "/file with spaces.html");
|
||||
|
||||
|
||||
uri.setPathEtc("/query.cgi?query=foo");
|
||||
assert (uri.getPath() == "/query.cgi");
|
||||
assert (uri.getQuery() == "query=foo");
|
||||
assert (uri.getFragment().empty());
|
||||
assert (uri.getPathEtc() == "/query.cgi?query=foo");
|
||||
assert (uri.getPathAndQuery() == "/query.cgi?query=foo");
|
||||
|
||||
|
||||
uri.setPathEtc("/query.cgi?query=bar#frag");
|
||||
assert (uri.getPath() == "/query.cgi");
|
||||
assert (uri.getQuery() == "query=bar");
|
||||
assert (uri.getFragment() == "frag");
|
||||
assert (uri.getPathEtc() == "/query.cgi?query=bar#frag");
|
||||
assert (uri.getPathAndQuery() == "/query.cgi?query=bar");
|
||||
|
||||
|
||||
uri.setQuery("query=test");
|
||||
assert (uri.getQuery() == "query=test");
|
||||
|
||||
|
||||
uri.setFragment("result");
|
||||
assert (uri.getFragment() == "result");
|
||||
|
||||
|
||||
URI uri2("file", "/home/guenter/foo.bar");
|
||||
assert (uri2.getScheme() == "file");
|
||||
assert (uri2.getPath() == "/home/guenter/foo.bar");
|
||||
|
||||
|
||||
URI uri3("http", "www.appinf.com", "/index.html");
|
||||
assert (uri3.getScheme() == "http");
|
||||
assert (uri3.getAuthority() == "www.appinf.com");
|
||||
assert (uri3.getPath() == "/index.html");
|
||||
|
||||
|
||||
URI uri4("http", "www.appinf.com:8000", "/index.html");
|
||||
assert (uri4.getScheme() == "http");
|
||||
assert (uri4.getAuthority() == "www.appinf.com:8000");
|
||||
@ -140,7 +140,7 @@ void URITest::testConstruction()
|
||||
assert (uri7.getPort() == 80);
|
||||
assert (uri7.getAuthority() == "user@www.appinf.com");
|
||||
assert (uri7.getPath() == "/index.html");
|
||||
|
||||
|
||||
URI uri8("http", "www.appinf.com", "/index.html", "query=test");
|
||||
assert (uri8.getScheme() == "http");
|
||||
assert (uri8.getAuthority() == "www.appinf.com");
|
||||
@ -172,7 +172,7 @@ void URITest::testConstruction()
|
||||
assert (uri10.getPort() == 389);
|
||||
assert (uri10.getAuthority() == "[2001:db8::7]");
|
||||
assert (uri10.getPathEtc() == "/c=GB?objectClass?one");
|
||||
|
||||
|
||||
URI uri11("http", "www.appinf.com", "/index.html?query=test#fragment");
|
||||
assert (uri11.getScheme() == "http");
|
||||
assert (uri11.getAuthority() == "www.appinf.com");
|
||||
@ -201,7 +201,7 @@ void URITest::testParse()
|
||||
assert (uri.getQuery().empty());
|
||||
assert (uri.getFragment().empty());
|
||||
assert (!uri.isRelative());
|
||||
|
||||
|
||||
uri = "ftp://anonymous@ftp.appinf.com/pub/";
|
||||
assert (uri.getScheme() == "ftp");
|
||||
assert (uri.getUserInfo() == "anonymous");
|
||||
@ -222,7 +222,7 @@ void URITest::testParse()
|
||||
assert (uri.getQuery().empty());
|
||||
assert (uri.getFragment() == "top");
|
||||
assert (!uri.isRelative());
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/search.cgi?keyword=test&scope=all";
|
||||
assert (uri.getScheme() == "http");
|
||||
assert (uri.getHost() == "www.appinf.com");
|
||||
@ -240,7 +240,7 @@ void URITest::testParse()
|
||||
assert (uri.getQuery() == "keyword=test&scope=all");
|
||||
assert (uri.getFragment() == "result");
|
||||
assert (!uri.isRelative());
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/search.cgi?keyword=test%20encoded&scope=all#result";
|
||||
assert (uri.getScheme() == "http");
|
||||
assert (uri.getHost() == "www.appinf.com");
|
||||
@ -249,7 +249,7 @@ void URITest::testParse()
|
||||
assert (uri.getQuery() == "keyword=test encoded&scope=all");
|
||||
assert (uri.getFragment() == "result");
|
||||
assert (!uri.isRelative());
|
||||
|
||||
|
||||
uri = "ldap://[2001:db8::7]/c=GB?objectClass?one";
|
||||
assert (uri.getScheme() == "ldap");
|
||||
assert (uri.getUserInfo().empty());
|
||||
@ -259,7 +259,7 @@ void URITest::testParse()
|
||||
assert (uri.getPath() == "/c=GB");
|
||||
assert (uri.getQuery() == "objectClass?one");
|
||||
assert (uri.getFragment().empty());
|
||||
|
||||
|
||||
uri = "mailto:John.Doe@example.com";
|
||||
assert (uri.getScheme() == "mailto");
|
||||
assert (uri.getUserInfo().empty());
|
||||
@ -269,7 +269,7 @@ void URITest::testParse()
|
||||
assert (uri.getPath() == "John.Doe@example.com");
|
||||
assert (uri.getQuery().empty());
|
||||
assert (uri.getFragment().empty());
|
||||
|
||||
|
||||
uri = "tel:+1-816-555-1212";
|
||||
assert (uri.getScheme() == "tel");
|
||||
assert (uri.getUserInfo().empty());
|
||||
@ -279,7 +279,7 @@ void URITest::testParse()
|
||||
assert (uri.getPath() == "+1-816-555-1212");
|
||||
assert (uri.getQuery().empty());
|
||||
assert (uri.getFragment().empty());
|
||||
|
||||
|
||||
uri = "telnet://192.0.2.16:80";
|
||||
assert (uri.getScheme() == "telnet");
|
||||
assert (uri.getUserInfo().empty());
|
||||
@ -289,7 +289,7 @@ void URITest::testParse()
|
||||
assert (uri.getPath().empty());
|
||||
assert (uri.getQuery().empty());
|
||||
assert (uri.getFragment().empty());
|
||||
|
||||
|
||||
uri = "urn:oasis:names:specification:docbook:dtd:xml:4.1.2";
|
||||
assert (uri.getScheme() == "urn");
|
||||
assert (uri.getUserInfo().empty());
|
||||
@ -299,7 +299,7 @@ void URITest::testParse()
|
||||
assert (uri.getPath() == "oasis:names:specification:docbook:dtd:xml:4.1.2");
|
||||
assert (uri.getQuery().empty());
|
||||
assert (uri.getFragment().empty());
|
||||
|
||||
|
||||
uri = "";
|
||||
assert (uri.getScheme().empty());
|
||||
assert (uri.getAuthority().empty());
|
||||
@ -310,9 +310,9 @@ void URITest::testParse()
|
||||
assert (uri.getQuery().empty());
|
||||
assert (uri.getFragment().empty());
|
||||
assert (uri.empty());
|
||||
|
||||
|
||||
// relative references
|
||||
|
||||
|
||||
uri = "/foo/bar";
|
||||
assert (uri.getScheme().empty());
|
||||
assert (uri.getAuthority().empty());
|
||||
@ -367,8 +367,8 @@ void URITest::testParse()
|
||||
assert (uri.getQuery().empty());
|
||||
assert (uri.getFragment() == "frag");
|
||||
assert (uri.isRelative());
|
||||
|
||||
uri = "?query=test";
|
||||
|
||||
uri = "?query=test";
|
||||
assert (uri.getScheme().empty());
|
||||
assert (uri.getAuthority().empty());
|
||||
assert (uri.getUserInfo().empty());
|
||||
@ -379,7 +379,7 @@ void URITest::testParse()
|
||||
assert (uri.getFragment().empty());
|
||||
assert (uri.isRelative());
|
||||
|
||||
uri = "?query=test#frag";
|
||||
uri = "?query=test#frag";
|
||||
assert (uri.getScheme().empty());
|
||||
assert (uri.getAuthority().empty());
|
||||
assert (uri.getUserInfo().empty());
|
||||
@ -389,8 +389,8 @@ void URITest::testParse()
|
||||
assert (uri.getQuery() == "query=test");
|
||||
assert (uri.getFragment() == "frag");
|
||||
assert (uri.isRelative());
|
||||
|
||||
uri = "#frag";
|
||||
|
||||
uri = "#frag";
|
||||
assert (uri.getScheme().empty());
|
||||
assert (uri.getAuthority().empty());
|
||||
assert (uri.getUserInfo().empty());
|
||||
@ -401,7 +401,7 @@ void URITest::testParse()
|
||||
assert (uri.getFragment() == "frag");
|
||||
assert (uri.isRelative());
|
||||
|
||||
uri = "#";
|
||||
uri = "#";
|
||||
assert (uri.getScheme().empty());
|
||||
assert (uri.getAuthority().empty());
|
||||
assert (uri.getUserInfo().empty());
|
||||
@ -411,7 +411,7 @@ void URITest::testParse()
|
||||
assert (uri.getQuery().empty());
|
||||
assert (uri.getFragment().empty());
|
||||
assert (uri.isRelative());
|
||||
|
||||
|
||||
uri = "file:///a/b/c";
|
||||
assert (uri.getScheme() == "file");
|
||||
assert (uri.getAuthority().empty());
|
||||
@ -433,7 +433,7 @@ void URITest::testParse()
|
||||
assert (uri.getQuery().empty());
|
||||
assert (uri.getFragment().empty());
|
||||
assert (!uri.isRelative());
|
||||
|
||||
|
||||
uri = "file:///c:/Windows/system32/";
|
||||
assert (uri.getScheme() == "file");
|
||||
assert (uri.getAuthority().empty());
|
||||
@ -455,7 +455,7 @@ void URITest::testParse()
|
||||
assert (uri.getQuery().empty());
|
||||
assert (uri.getFragment().empty());
|
||||
assert (uri.isRelative());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -466,42 +466,42 @@ void URITest::testToString()
|
||||
|
||||
uri = "http://www.appinf.com/";
|
||||
assert (uri.toString() == "http://www.appinf.com/");
|
||||
|
||||
|
||||
uri = "ftp://anonymous@ftp.appinf.com/pub/";
|
||||
assert (uri.toString() == "ftp://anonymous@ftp.appinf.com/pub/");
|
||||
|
||||
uri = "https://www.appinf.com/index.html#top";
|
||||
assert (uri.toString() == "https://www.appinf.com/index.html#top");
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/search.cgi?keyword=test&scope=all";
|
||||
assert (uri.toString() == "http://www.appinf.com/search.cgi?keyword=test&scope=all");
|
||||
|
||||
uri = "http://www.appinf.com/search.cgi?keyword=test&scope=all#result";
|
||||
assert (uri.toString() == "http://www.appinf.com/search.cgi?keyword=test&scope=all#result");
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/search.cgi?keyword=test%20encoded&scope=all#result";
|
||||
assert (uri.toString() == "http://www.appinf.com/search.cgi?keyword=test%20encoded&scope=all#result");
|
||||
|
||||
|
||||
uri = "ldap://[2001:db8::7]/c=GB?objectClass?one";
|
||||
assert (uri.toString() == "ldap://[2001:db8::7]/c=GB?objectClass?one");
|
||||
|
||||
|
||||
uri = "mailto:John.Doe@example.com";
|
||||
assert (uri.toString() == "mailto:John.Doe@example.com");
|
||||
|
||||
|
||||
uri = "tel:+1-816-555-1212";
|
||||
assert (uri.toString() == "tel:+1-816-555-1212");
|
||||
|
||||
|
||||
uri = "telnet://192.0.2.16:80";
|
||||
assert (uri.toString() == "telnet://192.0.2.16:80");
|
||||
|
||||
|
||||
uri = "urn:oasis:names:specification:docbook:dtd:xml:4.1.2";
|
||||
assert (uri.toString() == "urn:oasis:names:specification:docbook:dtd:xml:4.1.2");
|
||||
|
||||
|
||||
uri = "";
|
||||
assert (uri.toString() == "");
|
||||
|
||||
// relative references
|
||||
|
||||
|
||||
uri = "/foo/bar";
|
||||
assert (uri.toString() == "/foo/bar");
|
||||
|
||||
@ -519,25 +519,25 @@ void URITest::testToString()
|
||||
|
||||
uri = "index.html#frag";
|
||||
assert (uri.toString() == "index.html#frag");
|
||||
|
||||
uri = "?query=test";
|
||||
|
||||
uri = "?query=test";
|
||||
assert (uri.toString() == "?query=test");
|
||||
|
||||
uri = "?query=test#frag";
|
||||
uri = "?query=test#frag";
|
||||
assert (uri.toString() == "?query=test#frag");
|
||||
|
||||
uri = "#frag";
|
||||
|
||||
uri = "#frag";
|
||||
assert (uri.toString() == "#frag");
|
||||
|
||||
uri = "#";
|
||||
uri = "#";
|
||||
assert (uri.toString() == "");
|
||||
|
||||
|
||||
uri = "file:///a/b/c";
|
||||
assert (uri.toString() == "file:///a/b/c");
|
||||
|
||||
|
||||
uri = "file://localhost/a/b/c";
|
||||
assert (uri.toString() == "file://localhost/a/b/c");
|
||||
|
||||
|
||||
uri = "file:///c:/Windows/system32/";
|
||||
assert (uri.toString() == "file:///c:/Windows/system32/");
|
||||
|
||||
@ -553,19 +553,19 @@ void URITest::testCompare()
|
||||
assert (uri1 == uri2);
|
||||
assert (uri1 == "http://www.appinf.com:");
|
||||
assert (uri1 != "http://www.google.com");
|
||||
|
||||
|
||||
uri1 = "/foo/bar";
|
||||
assert (uri1 == "/foo/bar");
|
||||
assert (uri1 != "/foo/baz");
|
||||
|
||||
|
||||
uri1 = "?query";
|
||||
assert (uri1 == "?query");
|
||||
assert (uri1 != "?query2");
|
||||
|
||||
|
||||
uri1 = "#frag";
|
||||
assert (uri1 == "#frag");
|
||||
assert (uri1 != "#frag2");
|
||||
|
||||
|
||||
uri1 = "/index.html#frag";
|
||||
assert (uri1 == "/index.html#frag");
|
||||
assert (uri1 != "/index.html");
|
||||
@ -577,15 +577,15 @@ void URITest::testNormalize()
|
||||
URI uri("http://www.appinf.com");
|
||||
uri.normalize();
|
||||
assert (uri.toString() == "http://www.appinf.com");
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/";
|
||||
uri.normalize();
|
||||
assert (uri.toString() == "http://www.appinf.com/");
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/foo/bar/./index.html";
|
||||
uri.normalize();
|
||||
assert (uri.toString() == "http://www.appinf.com/foo/bar/index.html");
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/foo/bar/../index.html";
|
||||
uri.normalize();
|
||||
assert (uri.toString() == "http://www.appinf.com/foo/index.html");
|
||||
@ -625,7 +625,7 @@ void URITest::testNormalize()
|
||||
uri = "http://www.appinf.com/../foo/../";
|
||||
uri.normalize();
|
||||
assert (uri.toString() == "http://www.appinf.com/");
|
||||
|
||||
|
||||
uri = "file:///c:/Windows/system32/";
|
||||
uri.normalize();
|
||||
assert (uri.toString() == "file:///c:/Windows/system32/");
|
||||
@ -640,13 +640,13 @@ void URITest::testNormalize()
|
||||
void URITest::testResolve()
|
||||
{
|
||||
URI uri("http://www.appinf.com");
|
||||
|
||||
|
||||
uri.resolve("/index.html");
|
||||
assert (uri.toString() == "http://www.appinf.com/index.html");
|
||||
|
||||
|
||||
uri.resolve("#frag");
|
||||
assert (uri.toString() == "http://www.appinf.com/index.html#frag");
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/html";
|
||||
uri.resolve("../images/foo.gif");
|
||||
assert (uri.toString() == "http://www.appinf.com/images/foo.gif");
|
||||
@ -674,7 +674,7 @@ void URITest::testResolve()
|
||||
uri = "/a/b/c/d/e";
|
||||
uri.resolve("./../../f/./g");
|
||||
assert (uri.toString() == "/a/b/f/g");
|
||||
|
||||
|
||||
uri = "/a/b/../c/";
|
||||
uri.resolve("../d");
|
||||
assert (uri.toString() == "/a/d");
|
||||
@ -714,7 +714,7 @@ void URITest::testResolve()
|
||||
uri = "http://www.appinf.com/html/";
|
||||
uri.resolve("http://www.google.com/");
|
||||
assert (uri.toString() == "http://www.google.com/");
|
||||
|
||||
|
||||
uri = "http://www.appinf.com/";
|
||||
URI uri2(uri, "index.html");
|
||||
assert (uri2.toString() == "http://www.appinf.com/index.html");
|
||||
@ -729,13 +729,41 @@ void URITest::testSwap()
|
||||
{
|
||||
URI uri1("http://www.appinf.com/search.cgi?keyword=test%20encoded&scope=all#result");
|
||||
URI uri2("mailto:John.Doe@example.com");
|
||||
|
||||
|
||||
uri1.swap(uri2);
|
||||
assert (uri1.toString() == "mailto:John.Doe@example.com");
|
||||
assert (uri2.toString() == "http://www.appinf.com/search.cgi?keyword=test%20encoded&scope=all#result");
|
||||
}
|
||||
|
||||
|
||||
void URITest::testOther()
|
||||
{
|
||||
// The search string is "hello%world"; google happens to ignore the '%'
|
||||
// character, so it finds lots of hits for "hello world" programs. This is
|
||||
// a convenient reproduction case, and a URL that actually works.
|
||||
Poco::URI uri("http://google.com/search?q=hello%25world#frag%20ment");
|
||||
|
||||
assert(uri.getHost() == "google.com");
|
||||
assert(uri.getPath() == "/search");
|
||||
assert(uri.getQuery() == "q=hello%world");
|
||||
assert(uri.getRawQuery() == "q=hello%25world");
|
||||
assert(uri.getFragment() == "frag ment");
|
||||
assert(uri.toString() == "http://google.com/search?q=hello%25world#frag%20ment");
|
||||
assert(uri.getPathEtc() == "/search?q=hello%25world#frag%20ment");
|
||||
|
||||
uri.setQuery("q=goodbye cruel world");
|
||||
assert(uri.getQuery() == "q=goodbye cruel world");
|
||||
assert(uri.getRawQuery() == "q=goodbye%20cruel%20world");
|
||||
assert(uri.toString() == "http://google.com/search?q=goodbye%20cruel%20world#frag%20ment");
|
||||
assert(uri.getPathEtc() == "/search?q=goodbye%20cruel%20world#frag%20ment");
|
||||
|
||||
uri.setRawQuery("q=pony%7eride");
|
||||
assert(uri.getQuery() == "q=pony~ride");
|
||||
assert(uri.getRawQuery() == "q=pony%7eride");
|
||||
assert(uri.toString() == "http://google.com/search?q=pony%7eride#frag%20ment");
|
||||
assert(uri.getPathEtc() == "/search?q=pony%7eride#frag%20ment");
|
||||
}
|
||||
|
||||
void URITest::setUp()
|
||||
{
|
||||
}
|
||||
@ -757,6 +785,7 @@ CppUnit::Test* URITest::suite()
|
||||
CppUnit_addTest(pSuite, URITest, testNormalize);
|
||||
CppUnit_addTest(pSuite, URITest, testResolve);
|
||||
CppUnit_addTest(pSuite, URITest, testSwap);
|
||||
CppUnit_addTest(pSuite, URITest, testOther);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@ -14,14 +14,14 @@
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
@ -53,6 +53,7 @@ public:
|
||||
void testNormalize();
|
||||
void testResolve();
|
||||
void testSwap();
|
||||
void testOther();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
Loading…
x
Reference in New Issue
Block a user