Skip to content

Commit dc151fc

Browse files
author
Dean Michael Berris
committed
Adding tests for HTTP 1.1 beginnings.
1 parent ec5996d commit dc151fc

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

libs/network/test/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@ set(Boost_USE_MULTITHREADED ON)
66
if (Boost_FOUND)
77
add_executable(cpp-netlib-hello_world hello_world.cpp)
88
add_executable(cpp-netlib-http_1_0_test http_1_0_test.cpp)
9+
add_executable(cpp-netlib-http_1_1_test http_1_1_test.cpp)
910
add_executable(cpp-netlib-localhost_tests localhost_tests.cpp)
1011
add_executable(cpp-netlib-message_test message_test.cpp)
1112
add_executable(cpp-netlib-message_transform_test message_transform_test.cpp)
1213
add_executable(cpp-netlib-url_test url_test.cpp)
1314
target_link_libraries(cpp-netlib-hello_world ${Boost_SYSTEM_LIBRARY} ${Boost_REGEX_LIBRARY} ${Boost_DATE_TIME_LIBRARY} ${Boost_THREAD_LIBRARY} pthread)
1415
target_link_libraries(cpp-netlib-http_1_0_test ${Boost_LIBRARIES} pthread)
16+
target_link_libraries(cpp-netlib-http_1_1_test ${Boost_LIBRARIES} pthread)
1517
target_link_libraries(cpp-netlib-message_test ${Boost_LIBRARIES} pthread)
1618
target_link_libraries(cpp-netlib-message_transform_test ${Boost_LIBRARIES} pthread)
1719
target_link_libraries(cpp-netlib-localhost_tests ${Boost_LIBRARIES} pthread)
1820
target_link_libraries(cpp-netlib-url_test ${Boost_LIBRARIES} pthread)
19-
set_target_properties(cpp-netlib-hello_world cpp-netlib-http_1_0_test cpp-netlib-message_test cpp-netlib-message_transform_test cpp-netlib-localhost_tests cpp-netlib-url_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../../../build/tests)
21+
set_target_properties(cpp-netlib-hello_world cpp-netlib-http_1_0_test cpp-netlib-http_1_1_test cpp-netlib-message_test cpp-netlib-message_transform_test cpp-netlib-localhost_tests cpp-netlib-url_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../../../build/tests)
2022
add_test(cpp-netlib-hello_world python httplib_acceptance.py ../../../build/tests/cpp-netlib-hello_world ../../../build/tests/cpp-netlib-hello_world.passed)
2123
add_test(cpp-netlib-http_1_0_test ../../../build/tests/cpp-netlib-http_1_0_test)
24+
add_test(cpp-netlib-http_1_1_test ../../../build/tests/cpp-netlib-http_1_1_test)
2225
add_test(cpp-netlib-localhost_tests ../../../build/tests/cpp-netlib-localhost_tests)
2326
add_test(cpp-netlib-message_test ../../../build/tests/cpp-netlib-message_test)
2427
add_test(cpp-netlib-url_test ../../../build/tests/cpp-netlib-url_test)

libs/network/test/http_1_1_test.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
// Copyright Dean Michael Berris 2009.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#define BOOST_TEST_MODULE http 1.1 test
8+
#include <boost/test/unit_test.hpp>
9+
#include <boost/network.hpp>
10+
#include <iostream>
11+
#include <boost/mpl/list.hpp>
12+
13+
using namespace boost::network;
14+
15+
typedef boost::mpl::list<tags::http_default_8bit_tcp_resolve, tags::http_default_8bit_udp_resolve> tag_types;
16+
17+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test, T, tag_types) {
18+
http::basic_request<T> request("http://www.boost.org/");
19+
http::basic_client<T, 1, 1> client_;
20+
http::basic_response<T> response_;
21+
response_ = client_.get(request);
22+
typename headers_range<typename http::basic_response<T> >::type range = headers(response_)["Content-Type"];
23+
BOOST_CHECK ( begin(range) != end(range) );
24+
BOOST_CHECK ( body(response_).size() != 0 );
25+
}
26+
27+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_different_port, T, tag_types) {
28+
http::basic_request<T> request("http://www.boost.org:80/");
29+
http::basic_client<T, 1, 1> client_;
30+
http::basic_response<T> response_;
31+
response_ = client_.get(request);
32+
typename headers_range<typename http::basic_response<T> >::type range = headers(response_)["Content-Type"];
33+
BOOST_CHECK ( begin(range) != end(range) );
34+
BOOST_CHECK ( body(response_).size() != 0 );
35+
}
36+
37+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_timeout, T, tag_types) {
38+
http::basic_request<T> request("http://localhost:12121/");
39+
http::basic_client<T, 1, 1> client_;
40+
http::basic_response<T> response_;
41+
BOOST_CHECK_THROW ( response_ = client_.get(request), boost::system::system_error );
42+
}
43+
44+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_details, T, tag_types) {
45+
http::basic_request<T> request("http://www.boost.org/");
46+
http::basic_client<T, 1, 1> client_;
47+
http::basic_response<T> response_;
48+
BOOST_CHECK_NO_THROW ( response_ = client_.get(request) );
49+
BOOST_CHECK_EQUAL ( response_.version().substr(0,7), std::string("HTTP/1.") );
50+
BOOST_CHECK_EQUAL ( response_.status(), 200u );
51+
BOOST_CHECK_EQUAL ( response_.status_message(), std::string("OK") );
52+
}
53+
54+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_cached_resolve, T, tag_types) {
55+
http::basic_request<T> request("http://www.boost.org");
56+
http::basic_request<T> other_request("http://www.boost.org/users/license.html");
57+
http::basic_client<T, 1, 1> client_(http::basic_client<T, 1, 1>::cache_resolved);
58+
http::basic_response<T> response_;
59+
BOOST_CHECK_NO_THROW ( response_ = client_.get(request) );
60+
BOOST_CHECK_NO_THROW ( response_ = client_.get(other_request) );
61+
}
62+
63+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_redirection_test, T, tag_types) {
64+
http::basic_request<T> request("http://boost.org");
65+
http::basic_client<T, 1, 1> client_(http::basic_client<T, 1, 1>::follow_redirect);
66+
http::basic_response<T> response_;
67+
BOOST_CHECK_NO_THROW ( response_ = client_.get(request) );
68+
BOOST_CHECK_EQUAL ( response_.status(), 200u );
69+
}
70+
71+

0 commit comments

Comments
 (0)