Skip to content

Commit a411abd

Browse files
committed
Updated some of the URI tests. Added begin/end accessors to make the URI a valid forward range.
1 parent 2c2cf86 commit a411abd

File tree

7 files changed

+161
-106
lines changed

7 files changed

+161
-106
lines changed

boost/network/uri/uri.hpp

+19
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# include <boost/network/tags.hpp>
1313
# include <boost/network/constants.hpp>
1414
# include <boost/network/uri/detail/uri_parts.hpp>
15+
# ifdef BOOST_NETWORK_NO_LIB
16+
# include <boost/network/uri/detail/parse_uri.hpp>
17+
# endif // #ifdef BOOST_NETWORK_NO_LIB
1518
# include <boost/algorithm/string.hpp>
1619
# include <boost/range/iterator_range.hpp>
1720
# include <boost/operators.hpp>
@@ -85,6 +88,22 @@ class basic_uri
8588
boost::swap(is_valid_, other.is_valid_);
8689
}
8790

91+
iterator_type begin() {
92+
return uri_.begin();
93+
}
94+
95+
const_iterator_type begin() const {
96+
return uri_.begin();
97+
}
98+
99+
iterator_type end() {
100+
return uri_.end();
101+
}
102+
103+
const_iterator_type end() const {
104+
return uri_.end();
105+
}
106+
88107
const_range_type scheme_range() const {
89108
using boost::fusion::at_c;
90109
return const_range_type(at_c<0>(at_c<0>(uri_parts_)),

libs/network/test/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ find_package( Threads )
1010
set(Boost_USE_STATIC_LIBS ON)
1111
set(Boost_USE_MULTITHREADED ON)
1212

13+
add_subdirectory(uri)
1314
add_subdirectory(http)
1415

1516
if (Boost_FOUND)
1617
set(
1718
TESTS
1819
message_test
1920
message_transform_test
20-
url_test
2121
utils_thread_pool
2222
)
2323
foreach (test ${TESTS})

libs/network/test/http/url_test.cpp

-89
This file was deleted.

libs/network/test/mailto_url_test.cpp

-13
This file was deleted.

libs/network/test/uri/CMakeLists.txt

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright (c) Dean Michael Berris 2010.
2+
# Distributed under the Boost Software License, Version 1.0.
3+
# (See accompanying file LICENSE_1_0.txt or copy at
4+
# http://www.boost.org/LICENSE_1_0.txt)
5+
6+
include_directories(${CPP-NETLIB_SOURCE_DIR})
7+
find_package( Boost 1.41.0 COMPONENTS unit_test_framework system regex date_time filesystem )
8+
find_package( OpenSSL )
9+
find_package( Threads )
10+
set(Boost_USE_STATIC_LIBS ON)
11+
set(Boost_USE_MULTITHREADED ON)
12+
13+
14+
if (Boost_FOUND)
15+
set(
16+
TESTS
17+
url_test
18+
url_http_test
19+
)
20+
foreach (test ${TESTS})
21+
set_source_files_properties(${test}.cpp
22+
PROPERTIES COMPILE_FLAGS "-Wall")
23+
add_executable(cpp-netlib-${test} ${test}.cpp)
24+
add_dependencies(cpp-netlib-${test} cppnetlib-uri-parsers)
25+
target_link_libraries(cpp-netlib-${test} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri-parsers)
26+
if (OPENSSL_FOUND)
27+
target_link_libraries(cpp-netlib-${test} ${OPENSSL_LIBRARIES})
28+
endif()
29+
set_target_properties(cpp-netlib-${test}
30+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
31+
add_test(cpp-netlib-${test} ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-${test})
32+
endforeach (test)
33+
34+
endif()
+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright (c) Glyn Matthews 2011.
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See accompanying file LICENSE_1_0.txt or copy at
4+
// http://www.boost.org/LICENSE_1_0.txt)
5+
6+
7+
8+
#define BOOST_TEST_MODULE HTTP URL Test
9+
#include <boost/config/warning_disable.hpp>
10+
#include <boost/test/unit_test.hpp>
11+
#include <boost/network/uri/http/uri.hpp>
12+
#include <boost/mpl/list.hpp>
13+
#include <boost/range/algorithm/equal.hpp>
14+
15+
using namespace boost::network;
16+
17+
typedef boost::mpl::list<
18+
tags::default_string
19+
, tags::default_wstring
20+
> tag_types;
21+
22+
23+
BOOST_AUTO_TEST_CASE_TEMPLATE(not_http, T, tag_types)
24+
{
25+
typedef uri::http::basic_uri<T> uri_type;
26+
typedef typename uri_type::string_type string_type;
27+
const std::string url("mailto:[email protected]");
28+
uri_type instance(string_type(boost::begin(url), boost::end(url)));
29+
std::copy(instance.begin(), instance.end(),
30+
std::ostream_iterator<char>(std::cout));
31+
std::cout << std::endl;
32+
//BOOST_CHECK(!uri::is_valid(instance));
33+
}
34+
35+
// BOOST_AUTO_TEST_CASE(http_url_test) {
36+
// typedef uri::basic_uri<http::tags::http_default_8bit_tcp_resolve> uri_type;
37+
// typedef uri_type::string_type string_type;
38+
//
39+
// const std::string url(https://github.com/"http://www.boost.org/");
40+
// const std::string scheme("http");
41+
// const std::string host("www.boost.org");
42+
// const std::string path("/");
43+
//
44+
// uri_type instance(string_type(boost::begin(url), boost::end(url)));
45+
// boost::optional<string_type> host_ = uri::host(instance);
46+
// boost::optional<boost::uint16_t> port_ = uri::port(instance);
47+
//
48+
// BOOST_REQUIRE(uri::is_valid(instance));
49+
// BOOST_CHECK_EQUAL(instance.raw(), url);
50+
// BOOST_CHECK( !port_ );
51+
// string_type scheme_ = uri::scheme(instance);
52+
// BOOST_CHECK_EQUAL(scheme_, scheme);
53+
// BOOST_CHECK(boost::equal(uri::scheme(instance), scheme));
54+
// BOOST_CHECK(boost::equal(uri::host(instance), host));
55+
// BOOST_CHECK(boost::equal(uri::path(instance), path));
56+
// }
57+
//
58+
// BOOST_AUTO_TEST_CASE(full_http_url_test) {
59+
// typedef uri::basic_uri<http::tags::http_default_8bit_tcp_resolve> uri_type;
60+
// typedef uri_type::string_type string_type;
61+
//
62+
// const std::string url(https://github.com/"http://user:%3Ca%20href=%22/service/https://github.com/cdn-cgi/l/email-protection%22%20class=%22__cf_email__%22%20data-cfemail=%228fffeefcfcf8e0fdebcff8f8f8a1ede0e0fcfba1e0fde8%22%3E[email protected]%3C/a%3E:8000/path?query#fragment");
63+
// const std::string scheme("http");
64+
// const std::string user_info("user:password");
65+
// const std::string host("www.boost.org");
66+
// const boost::uint16_t port = 8000;
67+
// const std::string path("/path");
68+
// const std::string query("query");
69+
// const std::string fragment("fragment");
70+
//
71+
// uri_type instance(string_type(boost::begin(url), boost::end(url)));
72+
// BOOST_REQUIRE(uri::is_valid(instance));
73+
// BOOST_CHECK(boost::equal(uri::scheme(instance), scheme));
74+
// BOOST_CHECK(boost::equal(uri::user_info(instance), user_info));
75+
// BOOST_CHECK(boost::equal(uri::host(instance), host));
76+
// BOOST_CHECK_EQUAL(uri::port(instance), port);
77+
// BOOST_CHECK(boost::equal(uri::path(instance), path));
78+
// BOOST_CHECK(boost::equal(uri::query(instance), query));
79+
// BOOST_CHECK(boost::equal(uri::fragment(instance), fragment));
80+
// }
81+
//
82+
// BOOST_AUTO_TEST_CASE(https_url_test) {
83+
// typedef uri::basic_uri<http::tags::http_default_8bit_tcp_resolve> uri_type;
84+
// typedef uri_type::string_type string_type;
85+
//
86+
// const std::string url(https://github.com/"https://www.boost.org/");
87+
// const std::string scheme("https");
88+
// const std::string host("www.boost.org");
89+
// const boost::uint16_t port = 443;
90+
// const std::string path("/");
91+
//
92+
// uri_type instance(string_type(boost::begin(url), boost::end(url)));
93+
// BOOST_REQUIRE(uri::is_valid(instance));
94+
// BOOST_CHECK(boost::equal(uri::scheme(instance), scheme));
95+
// BOOST_CHECK(boost::equal(uri::host(instance), host));
96+
// BOOST_CHECK_EQUAL(uri::port(instance), port);
97+
// BOOST_CHECK(boost::equal(uri::path(instance), path));
98+
// }
99+
//
100+
//BOOST_AUTO_TEST_CASE(invalid_http_url_test) {
101+
// typedef uri::basic_uri<http::tags::http_default_8bit_tcp_resolve> uri_type;
102+
// typedef uri_type::string_type string_type;
103+
// const std::string url(https://github.com/"ftp://www.boost.org/");
104+
// uri_type instance(string_type(boost::begin(url), boost::end(url)));
105+
// BOOST_CHECK(!uri::is_valid(instance));
106+
//}

libs/network/test/url_test.cpp renamed to libs/network/test/uri/url_test.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
2-
// Copyright 2009 Dean Michael Berris, Jeroen Habraken.
3-
// Copyright 2010 Glyn Matthews.
1+
// Copyright 2009, 2010, 2011 Dean Michael Berris, Jeroen Habraken, Glyn Matthews.
42
// Distributed under the Boost Software License, Version 1.0.
53
// (See accompanying file LICENSE_1_0.txt of copy at
64
// http://www.boost.org/LICENSE_1_0.txt)

0 commit comments

Comments
 (0)