1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#define BOOST_TEST_MODULE URL
#include <boost/test/unit_test.hpp>
#include "odil/webservices/URL.h"
BOOST_AUTO_TEST_CASE(Equal)
{
auto const url = odil::webservices::URL::parse(
"foo://example.com:8042/over/there?name=ferret#nose");
BOOST_REQUIRE(url == url);
BOOST_REQUIRE(!(url != url));
}
BOOST_AUTO_TEST_CASE(Different)
{
auto const url1 = odil::webservices::URL::parse(
"foo://example.com:8042/over/there?name=ferret#nose");
auto const url2 = odil::webservices::URL::parse(
"foo://example.com:8042/over/there?name=goose#wing");
BOOST_REQUIRE(!(url1 == url2));
BOOST_REQUIRE(url1 != url2);
}
BOOST_AUTO_TEST_CASE(Parse)
{
auto const url = odil::webservices::URL::parse(
"foo://example.com:8042/over/there?name=ferret#nose");
BOOST_REQUIRE_EQUAL(url.scheme, "foo");
BOOST_REQUIRE_EQUAL(url.authority, "example.com:8042");
BOOST_REQUIRE_EQUAL(url.path, "/over/there");
BOOST_REQUIRE_EQUAL(url.query, "name=ferret");
BOOST_REQUIRE_EQUAL(url.fragment, "nose");
}
BOOST_AUTO_TEST_CASE(ParseIncomplete)
{
auto const url = odil::webservices::URL::parse(
"foo://example.com:8042?name=ferret#nose");
BOOST_REQUIRE_EQUAL(url.scheme, "foo");
BOOST_REQUIRE_EQUAL(url.authority, "example.com:8042");
BOOST_REQUIRE_EQUAL(url.path, "");
BOOST_REQUIRE_EQUAL(url.query, "name=ferret");
BOOST_REQUIRE_EQUAL(url.fragment, "nose");
}
BOOST_AUTO_TEST_CASE(Recompose)
{
odil::webservices::URL const url{
"foo", "example.com:8042", "/over/there", "name=ferret", "nose"};
std::string const string(url);
BOOST_REQUIRE_EQUAL(
string, "foo://example.com:8042/over/there?name=ferret#nose");
}
BOOST_AUTO_TEST_CASE(ParseQueryDefaultSeparator)
{
odil::webservices::URL const url{"", "", "", "name=ferret&color=purple", ""};
auto const items = url.parse_query();
decltype(items) expected{ {"name", "ferret"}, {"color", "purple"}};
BOOST_REQUIRE(items == expected);
}
BOOST_AUTO_TEST_CASE(ParseQueryOtherSeparator)
{
odil::webservices::URL const url{"", "", "", "name=ferret;color=purple", ""};
auto const items = url.parse_query(";");
decltype(items) expected{ {"name", "ferret"}, {"color", "purple"}};
BOOST_REQUIRE(items == expected);
}
|