Skip to content

Commit

Permalink
[uri] cleaned tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
glynos committed Apr 2, 2012
1 parent 63f07da commit eef48fa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 103 deletions.
66 changes: 13 additions & 53 deletions libs/network/test/uri/uri_builder_stream_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
#include <boost/test/unit_test.hpp>
#include <boost/network/uri/uri.hpp>
#include <boost/network/uri/directives.hpp>
#include <boost/network/uri/accessors.hpp>
#include <boost/network/uri/uri_io.hpp>
#include <boost/network/tags.hpp>
#include <boost/mpl/list.hpp>
#include <boost/range/algorithm/equal.hpp>
#include <boost/range/algorithm/copy.hpp>


using namespace boost::network;
Expand All @@ -24,9 +19,8 @@ BOOST_AUTO_TEST_CASE(builder_test)
uri::uri instance;
instance << uri::scheme("http") << uri::host("www.example.com") << uri::path("/");
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::path(instance), "/");
BOOST_CHECK_EQUAL("http://www.example.com/", instance.string());

}

BOOST_AUTO_TEST_CASE(full_uri_builder_test)
Expand All @@ -41,26 +35,15 @@ BOOST_AUTO_TEST_CASE(full_uri_builder_test)
<< uri::fragment("fragment")
;
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::user_info(instance), "user:password");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK(uri::port_us(instance));
BOOST_CHECK_EQUAL(uri::port_us(instance).get(), 80);
BOOST_CHECK_EQUAL(uri::port(instance), "80");
BOOST_CHECK_EQUAL(uri::path(instance), "/path");
BOOST_CHECK_EQUAL(uri::query(instance), "query");
BOOST_CHECK_EQUAL(uri::fragment(instance), "fragment");
BOOST_CHECK_EQUAL("http://user:password@www.example.com:80/path?query#fragment", instance.string());
}

BOOST_AUTO_TEST_CASE(port_test)
{
uri::uri instance;
instance << uri::scheme("http") << uri::host("www.example.com") << uri::port(8000) << uri::path("/");
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::port(instance), "8000");
BOOST_CHECK_EQUAL(uri::path(instance), "/");
BOOST_CHECK_EQUAL("http://www.example.com:8000/", instance.string());
}

BOOST_AUTO_TEST_CASE(encoded_path_test)
Expand All @@ -73,11 +56,7 @@ BOOST_AUTO_TEST_CASE(encoded_path_test)
;
;
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::port(instance), "8000");
BOOST_CHECK_EQUAL(uri::path(instance), "/Path%20With%20%28Some%29%20Encoded%20Characters%21");
BOOST_CHECK_EQUAL(uri::decoded_path(instance), "/Path With (Some) Encoded Characters!");
BOOST_CHECK_EQUAL("http://www.example.com:8000/Path%20With%20%28Some%29%20Encoded%20Characters%21", instance.string());
}

BOOST_AUTO_TEST_CASE(query_test)
Expand All @@ -87,10 +66,7 @@ BOOST_AUTO_TEST_CASE(query_test)
<< uri::query("key", "value")
;
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::path(instance), "/");
BOOST_CHECK_EQUAL(uri::query(instance), "key=value");
BOOST_CHECK_EQUAL("http://www.example.com/?key=value", instance.string());
}

BOOST_AUTO_TEST_CASE(query_2_test)
Expand All @@ -100,21 +76,15 @@ BOOST_AUTO_TEST_CASE(query_2_test)
<< uri::query("key1", "value1") << uri::query("key2", "value2")
;
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::path(instance), "/");
BOOST_CHECK_EQUAL(uri::query(instance), "key1=value1&key2=value2");
BOOST_CHECK_EQUAL("http://www.example.com/?key1=value1&key2=value2", instance.string());
}

BOOST_AUTO_TEST_CASE(fragment_test)
{
uri::uri instance;
instance << uri::scheme("http") << uri::host("www.example.com") << uri::path("/") << uri::fragment("fragment");
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::path(instance), "/");
BOOST_CHECK_EQUAL(uri::fragment(instance), "fragment");
BOOST_CHECK_EQUAL("http://www.example.com/#fragment", instance.string());
}

BOOST_AUTO_TEST_CASE(from_base_test)
Expand All @@ -123,30 +93,23 @@ BOOST_AUTO_TEST_CASE(from_base_test)
uri::uri instance;
instance << base_uri << uri::path("/") << uri::fragment("fragment");
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::path(instance), "/");
BOOST_CHECK_EQUAL(uri::fragment(instance), "fragment");
BOOST_CHECK_EQUAL("http://www.example.com/#fragment", instance.string());
}

BOOST_AUTO_TEST_CASE(scheme_http_test)
{
uri::uri instance;
instance << uri::schemes::http << uri::host("www.example.com") << uri::path("/");
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::path(instance), "/");
BOOST_CHECK_EQUAL("http://www.example.com/", instance.string());
}

BOOST_AUTO_TEST_CASE(scheme_https_test)
{
uri::uri instance;
instance << uri::schemes::https << uri::host("www.example.com") << uri::path("/");
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "https");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::path(instance), "/");
BOOST_CHECK_EQUAL("https://www.example.com/", instance.string());
}

BOOST_AUTO_TEST_CASE(encoded_null_char_test)
Expand All @@ -159,16 +122,13 @@ BOOST_AUTO_TEST_CASE(encoded_null_char_test)
<< uri::encoded_path("/")
;
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::path(instance), "/");
BOOST_CHECK_EQUAL("http://www.example.com/", instance.string());
}

BOOST_AUTO_TEST_CASE(mailto_builder_test)
{
uri::uri instance;
instance << uri::scheme("mailto") << uri::path("cpp-netlib@example.com");
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "mailto");
BOOST_CHECK_EQUAL(uri::path(instance), "cpp-netlib@example.com");
BOOST_CHECK_EQUAL("mailto:cpp-netlib@example.com", instance.string());
}
60 changes: 10 additions & 50 deletions libs/network/test/uri/uri_builder_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
#include <boost/config/warning_disable.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/network/uri/uri.hpp>
#include <boost/network/uri/directives.hpp>
#include <boost/network/uri/accessors.hpp>
#include <boost/network/uri/uri_io.hpp>
#include <boost/network/tags.hpp>
#include <boost/mpl/list.hpp>
#include <boost/range/algorithm/equal.hpp>
#include <boost/range/algorithm/copy.hpp>


using namespace boost::network;
Expand All @@ -30,9 +24,6 @@ BOOST_AUTO_TEST_CASE(builder_test)
;
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL("http://www.example.com/", instance.string());
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::path(instance), "/");
}

BOOST_AUTO_TEST_CASE(full_uri_builder_test)
Expand All @@ -49,26 +40,15 @@ BOOST_AUTO_TEST_CASE(full_uri_builder_test)
.fragment("fragment")
;
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::user_info(instance), "user:password");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK(uri::port_us(instance));
BOOST_CHECK_EQUAL(uri::port_us(instance).get(), 80);
BOOST_CHECK_EQUAL(uri::port(instance), "80");
BOOST_CHECK_EQUAL(uri::path(instance), "/path");
BOOST_CHECK_EQUAL(uri::query(instance), "query");
BOOST_CHECK_EQUAL(uri::fragment(instance), "fragment");
BOOST_CHECK_EQUAL("http://user:password@www.example.com:80/path?query#fragment", instance.string());
}

BOOST_AUTO_TEST_CASE(port_test)
{
uri::uri instance;
uri::builder(instance).scheme("http").host("www.example.com").port(8000).path("/");
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::port(instance), "8000");
BOOST_CHECK_EQUAL(uri::path(instance), "/");
BOOST_CHECK_EQUAL("http://www.example.com:8000/", instance.string());
}

BOOST_AUTO_TEST_CASE(encoded_path_test)
Expand All @@ -82,11 +62,7 @@ BOOST_AUTO_TEST_CASE(encoded_path_test)
.encoded_path("/Path With (Some) Encoded Characters!")
;
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::port(instance), "8000");
BOOST_CHECK_EQUAL(uri::path(instance), "/Path%20With%20%28Some%29%20Encoded%20Characters%21");
BOOST_CHECK_EQUAL(uri::decoded_path(instance), "/Path With (Some) Encoded Characters!");
BOOST_CHECK_EQUAL("http://www.example.com:8000/Path%20With%20%28Some%29%20Encoded%20Characters%21", instance.string());
}

BOOST_AUTO_TEST_CASE(query_test)
Expand All @@ -100,10 +76,7 @@ BOOST_AUTO_TEST_CASE(query_test)
.query("key", "value")
;
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::path(instance), "/");
BOOST_CHECK_EQUAL(uri::query(instance), "key=value");
BOOST_CHECK_EQUAL("http://www.example.com/?key=value", instance.string());
}

BOOST_AUTO_TEST_CASE(query_2_test)
Expand All @@ -118,10 +91,7 @@ BOOST_AUTO_TEST_CASE(query_2_test)
.query("key2", "value2")
;
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::path(instance), "/");
BOOST_CHECK_EQUAL(uri::query(instance), "key1=value1&key2=value2");
BOOST_CHECK_EQUAL("http://www.example.com/?key1=value1&key2=value2", instance.string());
}

BOOST_AUTO_TEST_CASE(fragment_test)
Expand All @@ -135,26 +105,19 @@ BOOST_AUTO_TEST_CASE(fragment_test)
.fragment("fragment")
;
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::path(instance), "/");
BOOST_CHECK_EQUAL(uri::fragment(instance), "fragment");
BOOST_CHECK_EQUAL("http://www.example.com/#fragment", instance.string());
}

BOOST_AUTO_TEST_CASE(from_base_test)
{
uri::uri base_uri("http://www.example.com");
uri::uri instance(base_uri);
uri::uri instance("http://www.example.com");
uri::builder builder(instance);
builder
.path("/")
.fragment("fragment")
;
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::path(instance), "/");
BOOST_CHECK_EQUAL(uri::fragment(instance), "fragment");
BOOST_CHECK_EQUAL("http://www.example.com/#fragment", instance.string());
}

BOOST_AUTO_TEST_CASE(encoded_null_char_test)
Expand All @@ -169,9 +132,7 @@ BOOST_AUTO_TEST_CASE(encoded_null_char_test)
.encoded_path("/")
;
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
BOOST_CHECK_EQUAL(uri::path(instance), "/");
BOOST_CHECK_EQUAL("http://www.example.com/", instance.string());
}

BOOST_AUTO_TEST_CASE(mailto_builder_test)
Expand All @@ -183,6 +144,5 @@ BOOST_AUTO_TEST_CASE(mailto_builder_test)
.path("cpp-netlib@example.com")
;
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::scheme(instance), "mailto");
BOOST_CHECK_EQUAL(uri::path(instance), "cpp-netlib@example.com");
BOOST_CHECK_EQUAL("mailto:cpp-netlib@example.com", instance.string());
}

0 comments on commit eef48fa

Please sign in to comment.