Skip to content

Commit 4c9fbda

Browse files
committed
Added a unit tests for the HTTP client request.
1 parent 2f61e45 commit 4c9fbda

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

boost/network/protocol/http/impl/request.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace http {
5050
*/
5151
template <class Tag>
5252
struct basic_request : public basic_message<Tag> {
53-
mutable boost::network::uri::uri uri_;
53+
boost::network::uri::uri uri_;
5454
std::uint16_t source_port_;
5555
typedef basic_message<Tag> base_type;
5656

@@ -65,10 +65,6 @@ struct basic_request : public basic_message<Tag> {
6565
explicit basic_request(boost::network::uri::uri const& uri_)
6666
: uri_(uri_), source_port_(0) {}
6767

68-
void uri(string_type const& new_uri) { uri_ = new_uri; }
69-
70-
void uri(boost::network::uri::uri const& new_uri) { uri_ = new_uri; }
71-
7268
basic_request() : base_type(), source_port_(0) {}
7369

7470
basic_request(basic_request const& other)

libs/network/test/http/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ if (OPENSSL_FOUND)
1212
endif()
1313

1414
if (Boost_FOUND)
15+
add_subdirectory(client)
16+
1517
set(TESTS response_incremental_parser_test request_incremental_parser_test
1618
request_linearize_test)
1719
foreach ( test ${TESTS} )
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2016 Glyn Matthews.
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+
set(
8+
TESTS
9+
request_test
10+
)
11+
12+
foreach(test ${TESTS})
13+
set(test_name cpp-netlib-http-client-${test})
14+
15+
add_executable(${test_name} ${test}.cpp)
16+
add_dependencies(${test_name} cppnetlib-uri gtest_main)
17+
target_link_libraries(${test_name}
18+
${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri gtest_main)
19+
set_target_properties(${test_name}
20+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
21+
add_test(${test_name}
22+
${CPP-NETLIB_BINARY_DIR}/tests/${test_name})
23+
24+
if (OPENSSL_FOUND)
25+
target_link_libraries(${test_name} ${OPENSSL_LIBRARIES})
26+
endif()
27+
28+
endforeach(test)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2016 Glyn Matthews.
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+
#include <gtest/gtest.h>
8+
// #include <boost/network/protocol/http/client/request.hpp>
9+
#include <boost/network/protocol/http/client.hpp>
10+
11+
12+
using client_request = boost::network::http::client::request;
13+
14+
15+
TEST(http_client_request, construct_from_uri) {
16+
ASSERT_NO_THROW(client_request("http://cpp-netlib.org/"));
17+
}
18+
19+
TEST(http_client_request, construct_from_invalid_uri) {
20+
ASSERT_THROW(client_request("I am not a valid URI"), std::exception);
21+
}

0 commit comments

Comments
 (0)