Skip to content

Commit 8c6a08a

Browse files
committed
Starting to break down the HTTP client tests to reduce test build times.
1 parent 48e511e commit 8c6a08a

9 files changed

+226
-16
lines changed

libs/network/test/CMakeLists.txt

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ find_package( Threads )
1414
set(Boost_USE_STATIC_LIBS ON)
1515
set(Boost_USE_MULTITHREADED ON)
1616

17+
add_subdirectory(http)
18+
1719
if (Boost_FOUND)
1820
set(
1921
TESTS
@@ -41,22 +43,8 @@ if (Boost_FOUND)
4143
target_link_libraries(cpp-netlib-${test} ${OPENSSL_LIBRARIES})
4244
endif()
4345
set_target_properties(cpp-netlib-${test}
44-
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../../../build/tests)
45-
add_test(cpp-netlib-${test} ../../../build/tests/cpp-netlib-${test})
46-
endforeach (test)
47-
48-
set(SERVER_TESTS
49-
hello_world
50-
http_async_server
51-
)
52-
foreach (test ${SERVER_TESTS})
53-
set_source_files_properties(${test}.cpp
54-
PROPERTIES COMPILE_FLAGS "-Wall")
55-
add_executable(cpp-netlib-${test} ${test}.cpp)
56-
target_link_libraries(cpp-netlib-${test} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
57-
set_target_properties(cpp-netlib-${test}
58-
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../../../build/tests)
59-
add_test(cpp-netlib-${test} python httplib_acceptance.py ../../../build/tests/cpp-netlib-${test} ../../../build/tests/cpp-netlib-${test}.passed)
46+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
47+
add_test(cpp-netlib-${test} ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-${test})
6048
endforeach (test)
6149

6250
endif()

libs/network/test/http/CMakeLists.txt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
# Copyright 2010 Dean Michael Berris.
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+
include_directories(${CPP-NETLIB_SOURCE_DIR})
8+
find_package( Boost 1.43.0 COMPONENTS unit_test_framework system regex thread filesystem )
9+
find_package( OpenSSL )
10+
11+
if (OPENSSL_FOUND)
12+
include_directories( ${OPENSSL_INCLUDE_DIR} )
13+
add_definitions(-DBOOST_NETWORK_ENABLE_HTTPS)
14+
endif()
15+
16+
find_package( Threads )
17+
set(Boost_USE_STATIC_LIBS ON)
18+
set(Boost_USE_MULTITHREADED ON)
19+
20+
if (Boost_FOUND)
21+
set ( TESTS
22+
client_constructor_test
23+
client_get_test
24+
client_get_different_port_test
25+
client_get_timeout_test
26+
)
27+
foreach ( test ${TESTS} )
28+
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
29+
set_source_files_properties(${test}.cpp
30+
PROPERTIES COMPILE_FLAGS "-Wall")
31+
endif()
32+
add_executable(cpp-netlib-http-${test} ${test}.cpp)
33+
target_link_libraries(cpp-netlib-http-${test} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
34+
if (OPENSSL_FOUND)
35+
target_link_libraries(cpp-netlib-http-${test} ${OPENSSL_LIBRARIES})
36+
endif()
37+
set_target_properties(cpp-netlib-http-${test}
38+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
39+
add_test(cpp-netlib-http-${test}
40+
%{CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-${test})
41+
endforeach (test)
42+
43+
set ( SERVER_TESTS
44+
server_hello_world
45+
server_async
46+
)
47+
foreach ( test ${SERVER_TESTS} )
48+
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
49+
set_source_files_properties(${test}.cpp
50+
PROPERTIES COMPILE_FLAGS "-Wall")
51+
endif()
52+
add_executable(cpp-netlib-http-${test} ${test}.cpp)
53+
target_link_libraries(cpp-netlib-http-${test} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
54+
set_target_properties(cpp-netlib-http-${test}
55+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY
56+
${CPP-NETLIB_BINARY_DIR}/tests)
57+
add_test(cpp-netlib-${test}
58+
python
59+
${CPP-NETLIB_SOURCE_DIR}/libs/network/httplib_acceptance.py
60+
${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-${test}
61+
${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-http-${test}.passed)
62+
endforeach (test)
63+
64+
endif()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
// Copyright 2010 Dean Michael Berris.
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.0 Client Constructor Test
8+
#include <boost/network/include/http/client.hpp>
9+
#include <boost/test/unit_test.hpp>
10+
#include "tag_types.hpp"
11+
12+
namespace http = boost::network::http;
13+
14+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_1_0_constructor_test, T, tag_types) {
15+
typedef http::basic_client<T, 1, 0> client;
16+
client instance;
17+
boost::asio::io_service io_service;
18+
client instance2(io_service);
19+
}
20+
21+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_1_1_constructor_test, T, tag_types) {
22+
typedef http::basic_client<T, 1, 1> client;
23+
client instance;
24+
boost::asio::io_service io_service;
25+
client instance2(io_service);
26+
}
27+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
// Copyright 2010 Dean Michael Berris.
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 Client Get Different Port Test
8+
#include <boost/network/include/http/client.hpp>
9+
#include <boost/test/unit_test.hpp>
10+
#include "tag_types.hpp"
11+
12+
namespace net = boost::network;
13+
namespace http = boost::network::http;
14+
15+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_different_port_1_0, T, tag_types) {
16+
typedef http::basic_client<T, 1, 0> client;
17+
typename client::request request("http://www.boost.org:80/");
18+
client client_;
19+
typename client::response response_ = client_.get(request);
20+
typename net::headers_range<typename http::basic_response<T> >::type range = headers(response_)["Content-Type"];
21+
BOOST_CHECK ( boost::begin(range) != boost::end(range) );
22+
BOOST_CHECK ( body(response_).size() != 0 );
23+
}
24+
25+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_different_port_1_1, T, tag_types) {
26+
typedef http::basic_client<T, 1, 1> client;
27+
typename client::request request("http://www.boost.org:80/");
28+
typename client::response response_;
29+
client client_;
30+
BOOST_CHECK_NO_THROW ( response_ = client_.get(request) );
31+
typename net::headers_range<typename client::response >::type range = headers(response_)["Content-Type"];
32+
BOOST_CHECK ( boost::begin(range) != boost::end(range) );
33+
BOOST_CHECK ( body(response_).size() != 0 );
34+
}
35+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2010 Dean Michael Berris.
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+
#define BOOST_TEST_MODULE HTTP 1.0 Get Test
7+
#include <boost/network/include/http/client.hpp>
8+
#include <boost/test/unit_test.hpp>
9+
#include "tag_types.hpp"
10+
11+
namespace net = boost::network;
12+
namespace http = boost::network::http;
13+
14+
15+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_client_get_test, T, tag_types) {
16+
typedef http::basic_client<T, 1, 0> client;
17+
typename client::request request("http://www.boost.org");
18+
client client_;
19+
typename client::response response;
20+
BOOST_CHECK_NO_THROW ( response = client_.get(request) );
21+
typename net::headers_range<typename client::response>::type range = headers(response)["Content-Type"];
22+
BOOST_CHECK ( !boost::empty(range) );
23+
BOOST_CHECK ( body(response).size() != 0 );
24+
BOOST_CHECK_EQUAL ( response.version().substr(0,7), std::string("HTTP/1.") );
25+
BOOST_CHECK_EQUAL ( response.status(), 200u );
26+
BOOST_CHECK_EQUAL ( response.status_message(), std::string("OK") );
27+
}
28+
29+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test, T, tag_types) {
30+
typedef http::basic_client<T, 1, 1> client;
31+
typename client::request request("http://www.boost.org/");
32+
typename client::response response_;
33+
client client_;
34+
BOOST_CHECK_NO_THROW ( response_ = client_.get(request) );
35+
typename net::headers_range<typename client::response>::type range = headers(response_)["Content-Type"];
36+
BOOST_CHECK ( boost::begin(range) != boost::end(range) );
37+
BOOST_CHECK ( body(response_).size() != 0 );
38+
BOOST_CHECK_EQUAL ( response_.version().substr(0,7), std::string("HTTP/1.") );
39+
BOOST_CHECK_EQUAL ( response_.status(), 200u );
40+
BOOST_CHECK_EQUAL ( response_.status_message(), std::string("OK") );
41+
}
42+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
// Copyright 2010 Dean Michael Berris.
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 Client Get Timeout Test
8+
#include <boost/network/include/http/client.hpp>
9+
#include <boost/test/unit_test.hpp>
10+
#include "tag_types.hpp"
11+
12+
namespace http = boost::network::http;
13+
14+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_timeout_1_0, T, tag_types) {
15+
typedef http::basic_client<T, 1, 0> client;
16+
typename client::request request("http://localhost:12121/");
17+
client client_;
18+
typename client::response response_;
19+
boost::uint16_t port_ = port(request);
20+
BOOST_CHECK_EQUAL ( 12121, port_ );
21+
BOOST_CHECK_THROW ( response_ = client_.get(request); body(response_); , std::exception );
22+
}
23+
24+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_timeout_1_1, T, tag_types) {
25+
typedef http::basic_client<T, 1, 1> client_type;
26+
typename client_type::request request("http://localhost:12121/");
27+
typename client_type::response response_;
28+
boost::uint16_t port_ = port(request);
29+
BOOST_CHECK_EQUAL ( 12121, port_ );
30+
client_type client_;
31+
BOOST_CHECK_THROW ( response_ = client_.get(request); body(response_); , std::exception );
32+
}

libs/network/test/http/tag_types.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef TAG_TYPES_4NNM8B5T
2+
#define TAG_TYPES_4NNM8B5T
3+
4+
// Copyright 2010 Dean Michael Berris.
5+
// Distributed under the Boost Software License, Version 1.0.
6+
// (See accompanying file LICENSE_1_0.txt or copy at
7+
// http://www.boost.org/LICENSE_1_0.txt)
8+
9+
#include <boost/mpl/list.hpp>
10+
#include <boost/network/protocol/http/tags.hpp>
11+
12+
namespace http = boost::network::http;
13+
14+
typedef boost::mpl::list<
15+
http::tags::http_default_8bit_tcp_resolve
16+
, http::tags::http_default_8bit_udp_resolve
17+
, http::tags::http_async_8bit_udp_resolve
18+
, http::tags::http_async_8bit_tcp_resolve
19+
> tag_types;
20+
21+
22+
#endif /* TAG_TYPES_4NNM8B5T */

0 commit comments

Comments
 (0)