Skip to content

Commit

Permalink
[uri] Added a swap function and less than operator.
Browse files Browse the repository at this point in the history
  • Loading branch information
glynos committed Apr 2, 2012
1 parent 00715df commit 63f07da
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
12 changes: 12 additions & 0 deletions boost/network/uri/uri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#ifndef __BOOST_NETWORK_URI_INC__
# define __BOOST_NETWORK_URI_INC__

# pragma once

# include <boost/network/uri/config.hpp>
# include <boost/network/uri/detail/uri_parts.hpp>
# include <boost/network/uri/schemes.hpp>
Expand Down Expand Up @@ -295,6 +297,11 @@ bool is_valid(const uri &uri_) {
return valid(uri_);
}

inline
void swap(uri &lhs, uri &rhs) {
lhs.swap(rhs);
}

inline
bool operator == (const uri &lhs, const uri &rhs) {
return boost::equal(lhs, rhs);
Expand All @@ -304,6 +311,11 @@ inline
bool operator != (const uri &lhs, const uri &rhs) {
return !(lhs == rhs);
}

inline
bool operator < (const uri &lhs, const uri &rhs) {
return lhs.string() < rhs.string();
}
} // namespace uri
} // namespace network
} // namespace boost
Expand Down
34 changes: 33 additions & 1 deletion libs/network/test/uri/uri_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,42 @@ BOOST_AUTO_TEST_CASE(assignment_test) {
BOOST_CHECK_EQUAL(instance, copy);
}

BOOST_AUTO_TEST_CASE(swap_test) {
uri::uri instance("http://www.example.com/");
uri::uri copy("http://www.example.org/");
uri::swap(instance, copy);
BOOST_CHECK_EQUAL(instance.string(), "http://www.example.org/");
BOOST_CHECK_EQUAL(copy.string(), "http://www.example.com/");
}

BOOST_AUTO_TEST_CASE(equality_test) {
uri::uri uri_1("http://www.example.com/");
uri::uri uri_2("http://www.example.com/");
BOOST_CHECK(uri_1 == uri_2);
}

BOOST_AUTO_TEST_CASE(inequality_test) {
uri::uri uri_1("http://www.example.com/");
uri::uri uri_2("http://www.example.com/");
BOOST_CHECK(!(uri_1 != uri_2));
}

BOOST_AUTO_TEST_CASE(less_than_test) {
// uri_1 is lexicographically less than uri_2
uri::uri uri_1("http://www.example.com/");
uri::uri uri_2("http://www.example.org/");
BOOST_CHECK(uri_1 < uri_2);
}

BOOST_AUTO_TEST_CASE(username_test) {
uri::uri instance("ftp://john.doe:password@ftp.example.com/");
uri::uri instance("ftp://john.doe@ftp.example.com/");
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::username(instance), "john.doe");
}

BOOST_AUTO_TEST_CASE(pasword_test) {
uri::uri instance("ftp://john.doe:password@ftp.example.com/");
BOOST_REQUIRE(uri::valid(instance));
BOOST_CHECK_EQUAL(uri::password(instance), "password");
}

Expand Down

0 comments on commit 63f07da

Please sign in to comment.