Skip to content

Commit 5b11b29

Browse files
committed
Cleaned up the URI tests a little further.
1 parent 316c8cf commit 5b11b29

File tree

11 files changed

+125
-96
lines changed

11 files changed

+125
-96
lines changed

boost/network/uri/directives/authority.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ struct authority_directive {
1111
: authority(authority)
1212
{}
1313

14-
void operator () (uri &uri_) const {
15-
uri_.append(authority);
14+
template <
15+
class Uri
16+
>
17+
void operator () (Uri &uri) const {
18+
uri.append(authority);
1619
}
1720

1821
std::string authority;

boost/network/uri/directives/fragment.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ struct fragment_directive {
1616
: fragment(fragment)
1717
{}
1818

19-
void operator () (uri &uri_) const {
20-
std::string encoded_fragment;
21-
static const char separator[] = {'#'};
22-
uri_.append(boost::begin(separator), boost::end(separator));
23-
encode(fragment, std::back_inserter(encoded_fragment));
24-
uri_.append(encoded_fragment);
19+
template <
20+
class Uri
21+
>
22+
void operator () (Uri &uri) const {
23+
uri.append("#");
24+
uri.append(fragment);
2525
}
2626

2727
std::string fragment;

boost/network/uri/directives/host.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ struct host_directive {
1515
: host(host)
1616
{}
1717

18-
void operator () (uri &uri_) const {
19-
uri_.append(host);
18+
template <
19+
class Uri
20+
>
21+
void operator () (Uri &uri) const {
22+
uri.append(host);
2023
}
2124

2225
std::string host;

boost/network/uri/directives/path.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ struct path_directive {
1515
: path(path)
1616
{}
1717

18-
void operator () (uri &uri_) const {
19-
uri_.append(path);
18+
template <
19+
class Uri
20+
>
21+
void operator () (Uri &uri) const {
22+
uri.append(path);
2023
}
2124

2225
std::string path;

boost/network/uri/directives/port.hpp

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,19 @@ struct port_directive {
1717
: port(port)
1818
{}
1919

20-
void operator () (uri &uri_) const {
21-
static const char separator[] = {':'};
22-
uri_.append(boost::begin(separator), boost::end(separator));
23-
uri_.append(port);
24-
}
25-
26-
std::string port;
27-
28-
};
29-
30-
31-
struct port_directive_us {
32-
33-
explicit port_directive_us(boost::uint16_t port)
34-
: port(port)
20+
explicit port_directive(boost::uint16_t port)
21+
: port(boost::lexical_cast<std::string>(port))
3522
{}
3623

37-
void operator () (uri &uri_) const {
38-
static const char separator[] = {':'};
39-
uri_.append(boost::begin(separator), boost::end(separator));
40-
std::string port_ = boost::lexical_cast<std::string>(port);
41-
uri_.append(port_);
24+
template <
25+
class Uri
26+
>
27+
void operator () (Uri &uri) const {
28+
uri.append(":");
29+
uri.append(port);
4230
}
4331

44-
boost::uint16_t port;
32+
std::string port;
4533

4634
};
4735

@@ -51,8 +39,8 @@ port_directive port(const std::string &port) {
5139
}
5240

5341
inline
54-
port_directive_us port(boost::uint16_t port) {
55-
return port_directive_us(port);
42+
port_directive port(boost::uint16_t port) {
43+
return port_directive(port);
5644
}
5745
} // namespace uri
5846
} // namespace network

boost/network/uri/directives/query.hpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ struct query_directive {
1616
: query(query)
1717
{}
1818

19-
void operator () (uri &uri_) const {
20-
std::string encoded_query;
21-
static const char separator[] = {'?'};
22-
uri_.append(boost::begin(separator), boost::end(separator));
23-
uri_.append(query);
19+
template <
20+
class Uri
21+
>
22+
void operator () (Uri &uri) const {
23+
uri.append("?");
24+
uri.append(query);
2425
}
2526

2627
std::string query;
@@ -38,24 +39,22 @@ struct query_key_query_directive {
3839
: key(key), query(query)
3940
{}
4041

41-
void operator () (uri &uri_) const {
42+
template <
43+
class Uri
44+
>
45+
void operator () (Uri &uri) const {
4246
std::string encoded_key, encoded_query;
43-
static const char qmark[] = {'?'};
44-
static const char equal[] = {'='};
45-
static const char scolon[] = {';'};
46-
if (!uri_.query_range())
47+
if (!uri.query_range())
4748
{
48-
uri_.append(boost::begin(qmark), boost::end(qmark));
49+
uri.append("?");
4950
}
5051
else
5152
{
52-
uri_.append(boost::begin(scolon), boost::end(scolon));
53+
uri.append(";");
5354
}
54-
encode(key, std::back_inserter(encoded_key));
55-
uri_.append(encoded_key);
56-
uri_.append(boost::begin(equal), boost::end(equal));
57-
encode(query, std::back_inserter(encoded_query));
58-
uri_.append(encoded_query);
55+
uri.append(key);
56+
uri.append("=");
57+
uri.append(query);
5958
}
6059

6160
std::string key;

boost/network/uri/directives/scheme.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ struct scheme_directive {
1515
: scheme(scheme)
1616
{}
1717

18-
void operator () (uri &uri_) const {
19-
static const char separator[] = {':', '/', '/'};
20-
uri_.append(scheme);
21-
uri_.append(boost::begin(separator), boost::end(separator));
18+
template <
19+
class Uri
20+
>
21+
void operator () (Uri &uri) const {
22+
uri.append(scheme);
23+
uri.append("://");
2224
}
2325

2426
std::string scheme;

boost/network/uri/directives/user_info.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ struct user_info_directive {
1515
: user_info(user_info)
1616
{}
1717

18-
void operator () (uri &uri_) const {
19-
static const char separator[] = {'@'};
20-
uri_.append(user_info);
21-
uri_.append(boost::begin(separator), boost::end(separator));
18+
template <
19+
class Uri
20+
>
21+
void operator () (Uri &uri) const {
22+
uri.append(user_info);
23+
uri.append("@");
2224
}
2325

2426
std::string user_info;

boost/network/uri/uri.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,21 @@ bool is_valid(const uri &uri_) {
281281
return valid(uri_);
282282
}
283283

284+
inline
285+
bool is_hierarchical(const uri &uri_) {
286+
//uri::const_range_type scheme = uri_.scheme_range();
287+
//uri::const_range_type user_info = uri_.user_info_range();
288+
//return is_valid(uri_) &&
289+
// boost::equal(std::make_pair(boost::end(scheme),
290+
// boost::begin(user_info)),
291+
// boost::as_literal("://"));
292+
return false;
293+
}
294+
295+
bool is_opaque(const uri &uri_) {
296+
return false;
297+
}
298+
284299
inline
285300
bool operator == (const uri &lhs, const uri &rhs) {
286301
return std::equal(lhs.begin(), lhs.end(), rhs.begin());

libs/network/test/uri/url_builder_test.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@ BOOST_AUTO_TEST_CASE(encoded_path_test)
7070
instance << uri::scheme("http")
7171
<< uri::host("www.example.com")
7272
<< uri::port(8000)
73-
<< uri::encoded_path("/Path%20With%20%28Some%29%20Encoded%20Characters%21")
74-
//<< uri::path(uri::encoded("/Path%20With%20%28Some%29%20Encoded%20Characters%21")
73+
<< uri::encoded_path("/Path With (Some) Encoded Characters!")
74+
;
7575
;
76-
std::cout << instance << std::endl;
7776
BOOST_REQUIRE(uri::valid(instance));
7877
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
7978
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
@@ -141,24 +140,17 @@ BOOST_AUTO_TEST_CASE(from_root_test)
141140
// BOOST_CHECK_EQUAL(uri::path(instance), "/");
142141
//}
143142

144-
//BOOST_AUTO_TEST_CASE(encoded_null_char_test)
145-
//{
146-
// typedef uri::uri uri_type;
147-
// typedef uri_type::string_type string_type;
148-
//
149-
// const std::string scheme("http");
150-
// const std::string host("www.example.com");
151-
// const std::string path("/");
152-
//
153-
// uri_type instance;
154-
// // there is a potential bug in the way we process ranges if the
155-
// // strings are null terminated.
156-
// instance << uri::scheme("http")
157-
// << uri::host("www.example.com")
158-
// << uri::encoded_path("/")
159-
// ;
160-
// BOOST_REQUIRE(uri::valid(instance));
161-
// BOOST_CHECK_EQUAL(uri::scheme(instance), scheme);
162-
// BOOST_CHECK_EQUAL(uri::host(instance), host);
163-
// BOOST_CHECK_EQUAL(uri::path(instance), path);
164-
//}
143+
BOOST_AUTO_TEST_CASE(encoded_null_char_test)
144+
{
145+
// there is a potential bug in the way we process ranges if the
146+
// strings are null terminated.
147+
uri::uri instance;
148+
instance << uri::scheme("http")
149+
<< uri::host("www.example.com")
150+
<< uri::encoded_path("/")
151+
;
152+
BOOST_REQUIRE(uri::valid(instance));
153+
BOOST_CHECK_EQUAL(uri::scheme(instance), "http");
154+
BOOST_CHECK_EQUAL(uri::host(instance), "www.example.com");
155+
BOOST_CHECK_EQUAL(uri::path(instance), "/");
156+
}

0 commit comments

Comments
 (0)