Skip to content

Commit 2c2cf86

Browse files
committed
Updated test for port as an unsigned short.
1 parent a47e864 commit 2c2cf86

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

boost/network/uri/uri.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,18 +263,21 @@ struct port_wrapper {
263263

264264
}
265265

266-
operator boost::optional<unsigned short> () const {
266+
boost::optional<unsigned short> to_optional() const {
267267
typename basic_uri<Tag>::string_type port = uri.port();
268268
return (port.empty())?
269269
boost::optional<unsigned short>() :
270270
boost::optional<unsigned short>(boost::lexical_cast<unsigned short>(port));
271271
}
272272

273+
operator boost::optional<unsigned short> () const {
274+
return to_optional();
275+
}
276+
273277
operator unsigned short () const {
274-
const boost::optional<unsigned short> &port =
275-
static_cast<boost::optional<unsigned short> >(*this);
276278
typedef typename string<Tag>::type string_type;
277279
typedef constants<Tag> consts;
280+
const boost::optional<unsigned short> &port = to_optional();
278281
if (port) return *port;
279282
return boost::iequals(uri.scheme_range(), string_type(consts::https())) ? 443 : 80;
280283
}

libs/network/test/url_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(full_uri_test, T, tag_types) {
5656
BOOST_CHECK(boost::equal(uri::scheme(instance), scheme));
5757
BOOST_CHECK(boost::equal(uri::user_info(instance), user_info));
5858
BOOST_CHECK(boost::equal(uri::host(instance), host));
59-
// BOOST_CHECK_EQUAL(uri::port(instance), port);
59+
BOOST_CHECK_EQUAL(static_cast<unsigned short>(uri::port_us(instance)), 8000);
6060
BOOST_CHECK(boost::equal(uri::port(instance), port));
6161
BOOST_CHECK(boost::equal(uri::path(instance), path));
6262
BOOST_CHECK(boost::equal(uri::query(instance), query));
@@ -214,7 +214,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(assignment_test, T, tag_types) {
214214
uri_type instance(string_type(boost::begin(url), boost::end(url)));
215215
uri_type copy;
216216
copy = instance;
217-
// BOOST_CHECK(instance.raw() == copy.raw());
218217
BOOST_CHECK(instance.to_string() == copy.to_string());
219218
BOOST_CHECK(instance == copy);
220219
}

0 commit comments

Comments
 (0)