Skip to content

Commit 63f07da

Browse files
committed
[uri] Added a swap function and less than operator.
1 parent 00715df commit 63f07da

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

boost/network/uri/uri.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#ifndef __BOOST_NETWORK_URI_INC__
88
# define __BOOST_NETWORK_URI_INC__
99

10+
# pragma once
11+
1012
# include <boost/network/uri/config.hpp>
1113
# include <boost/network/uri/detail/uri_parts.hpp>
1214
# include <boost/network/uri/schemes.hpp>
@@ -295,6 +297,11 @@ bool is_valid(const uri &uri_) {
295297
return valid(uri_);
296298
}
297299

300+
inline
301+
void swap(uri &lhs, uri &rhs) {
302+
lhs.swap(rhs);
303+
}
304+
298305
inline
299306
bool operator == (const uri &lhs, const uri &rhs) {
300307
return boost::equal(lhs, rhs);
@@ -304,6 +311,11 @@ inline
304311
bool operator != (const uri &lhs, const uri &rhs) {
305312
return !(lhs == rhs);
306313
}
314+
315+
inline
316+
bool operator < (const uri &lhs, const uri &rhs) {
317+
return lhs.string() < rhs.string();
318+
}
307319
} // namespace uri
308320
} // namespace network
309321
} // namespace boost

libs/network/test/uri/uri_test.cpp

+33-1
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,42 @@ BOOST_AUTO_TEST_CASE(assignment_test) {
310310
BOOST_CHECK_EQUAL(instance, copy);
311311
}
312312

313+
BOOST_AUTO_TEST_CASE(swap_test) {
314+
uri::uri instance("http://www.example.com/");
315+
uri::uri copy("http://www.example.org/");
316+
uri::swap(instance, copy);
317+
BOOST_CHECK_EQUAL(instance.string(), "http://www.example.org/");
318+
BOOST_CHECK_EQUAL(copy.string(), "http://www.example.com/");
319+
}
320+
321+
BOOST_AUTO_TEST_CASE(equality_test) {
322+
uri::uri uri_1("http://www.example.com/");
323+
uri::uri uri_2("http://www.example.com/");
324+
BOOST_CHECK(uri_1 == uri_2);
325+
}
326+
327+
BOOST_AUTO_TEST_CASE(inequality_test) {
328+
uri::uri uri_1("http://www.example.com/");
329+
uri::uri uri_2("http://www.example.com/");
330+
BOOST_CHECK(!(uri_1 != uri_2));
331+
}
332+
333+
BOOST_AUTO_TEST_CASE(less_than_test) {
334+
// uri_1 is lexicographically less than uri_2
335+
uri::uri uri_1("http://www.example.com/");
336+
uri::uri uri_2("http://www.example.org/");
337+
BOOST_CHECK(uri_1 < uri_2);
338+
}
339+
313340
BOOST_AUTO_TEST_CASE(username_test) {
314-
uri::uri instance("ftp://john.doe:password@ftp.example.com/");
341+
uri::uri instance("ftp://[email protected]/");
315342
BOOST_REQUIRE(uri::valid(instance));
316343
BOOST_CHECK_EQUAL(uri::username(instance), "john.doe");
344+
}
345+
346+
BOOST_AUTO_TEST_CASE(pasword_test) {
347+
uri::uri instance("ftp://john.doe:[email protected]/");
348+
BOOST_REQUIRE(uri::valid(instance));
317349
BOOST_CHECK_EQUAL(uri::password(instance), "password");
318350
}
319351

0 commit comments

Comments
 (0)