diff options
Diffstat (limited to 'test/test-url.cc')
| -rw-r--r-- | test/test-url.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/test-url.cc b/test/test-url.cc index 79e6564..41c41e8 100644 --- a/test/test-url.cc +++ b/test/test-url.cc @@ -170,6 +170,39 @@ bool relative(std::string const& url, std::string const& base, return true; } +bool good_authority(std::string const& str, + std::string const& host, + uint16_t port) { + std::string h; + uint16_t p; + if (!Url::parse_authority(str, &h, &p)) { + std::cerr << "good_authority:" << str << ": Invalid authority" << std::endl; + return false; + } + if (host != h) { + std::cerr << "good_authority:" << str << ":host: Expected " << host + << " got " << h << std::endl; + return false; + } + if (port != p) { + std::cerr << "good_authority:" << str << ":port: Expected " << port + << " got " << p << std::endl; + return false; + } + return true; +} + +bool bad_authority(std::string const& str) { + std::string h; + uint16_t p; + if (Url::parse_authority(str, &h, &p)) { + std::cerr << "bad_authority:" << str << ": Expected invalid autority got " + << h << ':' << p << std::endl; + return false; + } + return true; +} + } // namespace int main() { @@ -208,5 +241,13 @@ int main() { RUN(relative("foo#c", "http://host/#b", "http://host/foo#c")); RUN(relative("foo#c", "http://host/?b", "http://host/foo#c")); RUN(relative("foo", "http://host/?b", "http://host/foo")); + RUN(good_authority("www.example.org", "www.example.org", 0)); + RUN(good_authority("www.example.org:80", "www.example.org", 80)); + RUN(good_authority("localhost:5678", "localhost", 5678)); + RUN(good_authority("[::1]:5678", "::1", 5678)); + RUN(good_authority("::1:5678", "::1", 5678)); + RUN(bad_authority("foo@localhost")); + RUN(bad_authority("")); + RUN(bad_authority(":500")); AFTER; } |
