Skip to content

Commit 4169f81

Browse files
committed
Reducing code duplication by using the unified client_types MPL joint_view of all supported overloads of the HTTP client template.
1 parent 017d0f6 commit 4169f81

File tree

4 files changed

+11
-68
lines changed

4 files changed

+11
-68
lines changed

libs/network/test/http/client_constructor_test.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,11 @@
77
#define BOOST_TEST_MODULE HTTP 1.0 Client Constructor Test
88
#include <boost/network/include/http/client.hpp>
99
#include <boost/test/unit_test.hpp>
10-
#include "tag_types.hpp"
10+
#include "client_types.hpp"
1111

1212
namespace http = boost::network::http;
1313

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;
14+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_client_constructor_test, client, client_types) {
2315
client instance;
2416
boost::asio::io_service io_service;
2517
client instance2(io_service);

libs/network/test/http/client_get_different_port_test.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,16 @@
77
#define BOOST_TEST_MODULE HTTP Client Get Different Port Test
88
#include <boost/network/include/http/client.hpp>
99
#include <boost/test/unit_test.hpp>
10-
#include "tag_types.hpp"
10+
#include "client_types.hpp"
1111

1212
namespace net = boost::network;
1313
namespace http = boost::network::http;
1414

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;
15+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_different_port, client, client_types) {
1716
typename client::request request("http://www.boost.org:80/");
1817
client client_;
1918
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"];
19+
typename net::headers_range<typename client::response>::type range = headers(response_)["Content-Type"];
3220
BOOST_CHECK ( boost::begin(range) != boost::end(range) );
3321
BOOST_CHECK ( body(response_).size() != 0 );
3422
}

libs/network/test/http/client_get_test.cpp

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
#define BOOST_TEST_MODULE HTTP 1.0 Get Test
77
#include <boost/network/include/http/client.hpp>
88
#include <boost/test/unit_test.hpp>
9-
#include "tag_types.hpp"
9+
#include "client_types.hpp"
1010

1111
namespace net = boost::network;
1212
namespace http = boost::network::http;
1313

14-
BOOST_AUTO_TEST_CASE_TEMPLATE(http_client_get_test, T, tag_types) {
15-
typedef http::basic_client<T, 1, 0> client;
14+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_client_get_test, client, client_types) {
1615
typename client::request request("http://www.boost.org");
1716
client client_;
1817
typename client::response response;
@@ -25,38 +24,13 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(http_client_get_test, T, tag_types) {
2524
BOOST_CHECK_EQUAL ( response.status_message(), std::string("OK") );
2625
}
2726

28-
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test, T, tag_types) {
29-
typedef http::basic_client<T, 1, 1> client;
30-
typename client::request request("http://www.boost.org/");
31-
typename client::response response_;
32-
client client_;
33-
BOOST_CHECK_NO_THROW ( response_ = client_.get(request) );
34-
typename net::headers_range<typename client::response>::type range = headers(response_)["Content-Type"];
35-
BOOST_CHECK ( boost::begin(range) != boost::end(range) );
36-
BOOST_CHECK ( body(response_).size() != 0 );
37-
BOOST_CHECK_EQUAL ( response_.version().substr(0,7), std::string("HTTP/1.") );
38-
BOOST_CHECK_EQUAL ( response_.status(), 200u );
39-
BOOST_CHECK_EQUAL ( response_.status_message(), std::string("OK") );
40-
}
41-
4227
#ifdef BOOST_NETWORK_ENABLE_HTTPS
4328

44-
BOOST_AUTO_TEST_CASE_TEMPLATE(https_get_test_1_0, T, tag_types) {
45-
typedef http::basic_client<T, 1, 0> client;
46-
typename client::request request("https://www.google.com/");
47-
client client_;
48-
typename client::response response_ = client_.get(request);
49-
typename net::headers_range<typename http::basic_response<T> >::type range = headers(response_)["Content-Type"];
50-
BOOST_CHECK ( boost::begin(range) != boost::end(range) );
51-
BOOST_CHECK ( body(response_).size() != 0 );
52-
}
53-
54-
BOOST_AUTO_TEST_CASE_TEMPLATE(https_get_test_1_1, T, tag_types) {
55-
typedef http::basic_client<T, 1, 1> client;
29+
BOOST_AUTO_TEST_CASE_TEMPLATE(https_client_get_test, client, client_types) {
5630
typename client::request request("https://www.google.com/");
5731
client client_;
5832
typename client::response response_ = client_.get(request);
59-
typename net::headers_range<typename http::basic_response<T> >::type range = headers(response_)["Content-Type"];
33+
typename net::headers_range<typename client::response>::type range = headers(response_)["Content-Type"];
6034
BOOST_CHECK ( boost::begin(range) != boost::end(range) );
6135
BOOST_CHECK ( body(response_).size() != 0 );
6236
}

libs/network/test/http/client_get_timeout_test.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
#define BOOST_TEST_MODULE HTTP Client Get Timeout Test
88
#include <boost/network/include/http/client.hpp>
99
#include <boost/test/unit_test.hpp>
10-
#include "tag_types.hpp"
10+
#include "client_types.hpp"
1111

1212
namespace http = boost::network::http;
1313

14-
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_timeout_1_0, T, tag_types) {
15-
typedef http::basic_client<T, 1, 0> client;
14+
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_timeout_1_0, client, client_types) {
1615
typename client::request request("http://localhost:12121/");
1716
typename client::response response_;
1817
client client_;
@@ -22,13 +21,3 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_timeout_1_0, T, tag_types) {
2221
BOOST_CHECK_THROW ( response_ = client_.get(request); temp = body(response_); , std::exception );
2322
}
2423

25-
BOOST_AUTO_TEST_CASE_TEMPLATE(http_get_test_timeout_1_1, T, tag_types) {
26-
typedef http::basic_client<T, 1, 1> client_type;
27-
typename client_type::request request("http://localhost:12121/");
28-
typename client_type::response response_;
29-
boost::uint16_t port_ = port(request);
30-
typename client_type::response::string_type temp;
31-
BOOST_CHECK_EQUAL ( 12121, port_ );
32-
client_type client_;
33-
BOOST_CHECK_THROW ( response_ = client_.get(request); temp = body(response_); , std::exception );
34-
}

0 commit comments

Comments
 (0)