Skip to content

Commit 4874357

Browse files
committed
Migrate message, request, and response tests
1 parent 113e9fb commit 4874357

11 files changed

+168
-219
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
4343
INCLUDE(CheckCXXCompilerFlag)
4444
CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD11)
4545
if (HAVE_STD11)
46-
set(CMAKE_CXX_FLAGS -std=c++11)
46+
set(CMAKE_CXX_FLAGS -std=c++11 -Wall)
4747
else()
4848
message(FATAL_ERROR "No advanced standard C++ support (-std=c++11 not defined).")
4949
endif()
5050
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
5151
INCLUDE(CheckCXXCompilerFlag)
5252
CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD11)
5353
if (HAVE_STD11)
54-
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++")
54+
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall")
5555
set(CMAKE_CXX_LINK_FLAGS "-std=c++11 -stdlib=libc++")
5656
else()
5757
message(FATAL_ERROR "No C++11 support for Clang version. Please upgrade Clang to a version supporting C++11.")

http/test/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ endif()
2424
# if not then it will be empty
2525
set( CPP-NETLIB_LOGGING_LIB cppnetlib-logging )
2626

27-
if (Boost_FOUND)
27+
if (CPP-NETLIB_BUILD_TESTS)
2828
# These are the internal (simple) tests.
29-
set ( MESSAGE_TESTS
29+
set (MESSAGE_TESTS
3030
request_base_test
3131
request_test
32-
request_linearize_test
3332
response_test
33+
response_incremental_parser_test
3434
)
3535
foreach ( test ${MESSAGE_TESTS} )
3636
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)

http/test/request_base_test.cpp

+10-14
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44
// (See accompanying file LICENSE_1_0.txt or copy at
55
// http://www.boost.org/LICENSE_1_0.txt)
66

7-
#ifdef BUILD_SHARED_LIBS
8-
# define BOOST_TEST_DYN_LINK
9-
#endif
10-
#define BOOST_TEST_MODULE HTTP Request Storage Base Test
7+
#include <gtest/gtest.h>
118
#include <network/protocol/http/request/request_base.hpp>
12-
#include <boost/test/unit_test.hpp>
139

1410
namespace http = network::http;
1511

@@ -39,37 +35,37 @@ struct request_test : http::request_storage_base {
3935
}
4036
};
4137

42-
BOOST_AUTO_TEST_CASE(request_storage_flow) {
38+
TEST(request_test, request_storage_flow) {
4339
// Use a few byte chunks just to make it manageable.
4440
request_test simple(64);
4541
static char data[] =
4642
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vitae ante sed nunc dapibus convallis in at neque. Vestibulum sed congue nunc. Sed tempus lorem non dui ultrices porttitor porta ligula venenatis. Sed a orci gravida tellus condimentum laoreet. Vivamus pulvinar, tortor eu adipiscing tempus, dolor urna tincidunt enim, id pretium eros ante quis dui. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In hac habitasse platea dictumst. Maecenas mattis metus.";
4743
simple.append(data, sizeof(data));
4844
std::string output;
4945
size_t bytes_read = simple.read(output, 0, sizeof(data));
50-
BOOST_CHECK_EQUAL(bytes_read, sizeof(data));
46+
ASSERT_EQ(bytes_read, sizeof(data));
5147
std::string flattened;
5248
simple.flatten(flattened);
53-
BOOST_CHECK_EQUAL(flattened, std::string(output, sizeof(data)));
54-
BOOST_CHECK_EQUAL(std::string(data, sizeof(data)), std::string(output, sizeof(data)));
49+
ASSERT_EQ(flattened, std::string(output, sizeof(data)));
50+
ASSERT_EQ(std::string(data, sizeof(data)), std::string(output, sizeof(data)));
5551
simple.clear();
5652
}
5753

58-
BOOST_AUTO_TEST_CASE(request_storage_copy) {
54+
TEST(request_test, request_storage_copy) {
5955
// Use a few byt chunks just to make it manageable.
6056
request_test original(64);
6157
static char quick_brown[] = "The quick brown fox jumps over the lazy dog.";
6258
original.append(quick_brown, sizeof(quick_brown));
6359
std::string output;
6460
request_test copy(original);
6561
size_t bytes_read = copy.read(output, 0, sizeof(quick_brown));
66-
BOOST_CHECK_EQUAL(bytes_read, sizeof(quick_brown));
62+
ASSERT_EQ(bytes_read, sizeof(quick_brown));
6763
std::string flattened;
6864
copy.flatten(flattened);
69-
BOOST_CHECK_EQUAL(flattened, std::string(output, sizeof(quick_brown)));
70-
BOOST_CHECK_EQUAL(std::string(quick_brown, sizeof(quick_brown)), std::string(output, sizeof(quick_brown)));
65+
ASSERT_EQ(flattened, std::string(output, sizeof(quick_brown)));
66+
ASSERT_EQ(std::string(quick_brown, sizeof(quick_brown)), std::string(output, sizeof(quick_brown)));
7167
copy.clear();
7268
flattened.clear();
7369
original.flatten(flattened);
74-
BOOST_CHECK_EQUAL(flattened, std::string(quick_brown, sizeof(quick_brown)));
70+
ASSERT_EQ(flattened, std::string(quick_brown, sizeof(quick_brown)));
7571
}

http/test/request_incremental_parser_test.cpp

+19-21
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
// (See accompanying file LICENSE_1_0.txt or copy at
55
// http://www.boost.org/LICENSE_1_0.txt)
66

7-
#define BOOST_TEST_MODULE HTTP Incremental Request Parser Test
8-
#include <boost/config/warning_disable.hpp>
9-
#include <boost/test/unit_test.hpp>
7+
#include <gtest/gtest.h>
108
#include <network/protocol/http/server/request_parser.hpp>
119
#include <network/tags.hpp>
1210
#include <boost/range.hpp>
@@ -30,11 +28,11 @@ namespace logic = boost::logic;
3028
namespace fusion = boost::fusion;
3129
using namespace boost::network::http;
3230

33-
BOOST_AUTO_TEST_CASE(incremental_parser_constructor) {
31+
TEST(request_test, incremental_parser_constructor) {
3432
request_parser<tags::default_string> p; // default constructible
3533
}
3634

37-
BOOST_AUTO_TEST_CASE(incremental_parser_parse_http_method) {
35+
TEST(request_test, incremental_parser_parse_http_method) {
3836
request_parser<tags::default_string> p;
3937
logic::tribool parsed_ok = false;
4038
typedef request_parser<tags::default_string> request_parser_type;
@@ -45,8 +43,8 @@ BOOST_AUTO_TEST_CASE(incremental_parser_parse_http_method) {
4543
fusion::tie(parsed_ok, result_range) = p.parse_until(
4644
request_parser_type::method_done
4745
, valid_http_method);
48-
BOOST_CHECK_EQUAL(parsed_ok, true);
49-
BOOST_CHECK(!boost::empty(result_range));
46+
ASSERT_EQ(parsed_ok, true);
47+
ASSERT_TRUE(!boost::empty(result_range));
5048
std::string parsed(boost::begin(result_range), boost::end(result_range));
5149
std::cout << "PARSED: " << parsed << " [state:" << p.state() << "] " << std::endl;
5250

@@ -55,12 +53,12 @@ BOOST_AUTO_TEST_CASE(incremental_parser_parse_http_method) {
5553
fusion::tie(parsed_ok, result_range) = p.parse_until(
5654
request_parser_type::method_done
5755
, invalid_http_method);
58-
BOOST_CHECK_EQUAL(parsed_ok, false);
56+
ASSERT_EQ(parsed_ok, false);
5957
parsed.assign(boost::begin(result_range), boost::end(result_range));
6058
std::cout << "PARSED: " << parsed << " [state:" << p.state() << "] " << std::endl;
6159
}
6260

63-
BOOST_AUTO_TEST_CASE(incremental_parser_parse_http_uri) {
61+
TEST(request_test, incremental_parser_parse_http_uri) {
6462
request_parser<tags::default_string> p;
6563
logic::tribool parsed_ok = false;
6664
typedef request_parser<tags::default_string> request_parser_type;
@@ -70,21 +68,21 @@ BOOST_AUTO_TEST_CASE(incremental_parser_parse_http_uri) {
7068
std::string valid_http_request = "GET / HTTP/1.1\r\n";
7169
fusion::tie(parsed_ok, result_range) = p.parse_until(
7270
request_parser_type::uri_done, valid_http_request);
73-
BOOST_CHECK_EQUAL(parsed_ok, true);
74-
BOOST_CHECK(!boost::empty(result_range));
71+
ASSERT_EQ(parsed_ok, true);
72+
ASSERT_TRUE(!boost::empty(result_range));
7573
std::string parsed(boost::begin(result_range), boost::end(result_range));
7674
std::cout << "PARSED: " << parsed << " [state:" << p.state() << "] " << std::endl;
7775

7876
std::string invalid_http_request = "GET /\t HTTP/1.1\r\n";
7977
p.reset();
8078
fusion::tie(parsed_ok, result_range) = p.parse_until(
8179
request_parser_type::uri_done, invalid_http_request);
82-
BOOST_CHECK_EQUAL(parsed_ok, false);
80+
ASSERT_EQ(parsed_ok, false);
8381
parsed.assign(boost::begin(result_range), boost::end(result_range));
8482
std::cout << "PARSED: " << parsed << " [state:" << p.state() << "] " << std::endl;
8583
}
8684

87-
BOOST_AUTO_TEST_CASE(incremental_parser_parse_http_version) {
85+
TEST(request_test, incremental_parser_parse_http_version) {
8886
request_parser<tags::default_string> p;
8987
logic::tribool parsed_ok = false;
9088
typedef request_parser<tags::default_string> request_parser_type;
@@ -94,21 +92,21 @@ BOOST_AUTO_TEST_CASE(incremental_parser_parse_http_version) {
9492
std::string valid_http_request = "GET / HTTP/1.1\r\n";
9593
fusion::tie(parsed_ok, result_range) = p.parse_until(
9694
request_parser_type::version_done, valid_http_request);
97-
BOOST_CHECK_EQUAL(parsed_ok, true);
98-
BOOST_CHECK(!boost::empty(result_range));
95+
ASSERT_EQ(parsed_ok, true);
96+
ASSERT_TRUE(!boost::empty(result_range));
9997
std::string parsed(boost::begin(result_range), boost::end(result_range));
10098
std::cout << "PARSED: " << parsed << " [state:" << p.state() << "] " << std::endl;
10199

102100
std::string invalid_http_request = "GET / HTTP 1.1\r\n";
103101
p.reset();
104102
fusion::tie(parsed_ok, result_range) = p.parse_until(
105103
request_parser_type::version_done, invalid_http_request);
106-
BOOST_CHECK_EQUAL(parsed_ok, false);
104+
ASSERT_EQ(parsed_ok, false);
107105
parsed.assign(boost::begin(result_range), boost::end(result_range));
108106
std::cout << "PARSED: " << parsed << " [state:" << p.state() << "] " << std::endl;
109107
}
110108

111-
BOOST_AUTO_TEST_CASE(incremental_parser_parse_http_headers) {
109+
TEST(request_test, incremental_parser_parse_http_headers) {
112110
request_parser<tags::default_string> p;
113111
logic::tribool parsed_ok = false;
114112
typedef request_parser<tags::default_string> request_parser_type;
@@ -118,17 +116,17 @@ BOOST_AUTO_TEST_CASE(incremental_parser_parse_http_headers) {
118116
std::string valid_http_request = "GET / HTTP/1.1\r\nHost: cpp-netlib.org\r\n\r\n";
119117
fusion::tie(parsed_ok, result_range) = p.parse_until(
120118
request_parser_type::headers_done, valid_http_request);
121-
BOOST_CHECK_EQUAL(parsed_ok, true);
122-
BOOST_CHECK(!boost::empty(result_range));
119+
ASSERT_EQ(parsed_ok, true);
120+
ASSERT_TRUE(!boost::empty(result_range));
123121
std::string parsed(boost::begin(result_range), boost::end(result_range));
124122
std::cout << "PARSED: " << parsed << " [state:" << p.state() << "] " << std::endl;
125123

126124
valid_http_request = "GET / HTTP/1.1\r\nHost: cpp-netlib.org\r\nConnection: close\r\n\r\n";
127125
p.reset();
128126
fusion::tie(parsed_ok, result_range) = p.parse_until(
129127
request_parser_type::headers_done, valid_http_request);
130-
BOOST_CHECK_EQUAL(parsed_ok, true);
131-
BOOST_CHECK(!boost::empty(result_range));
128+
ASSERT_EQ(parsed_ok, true);
129+
ASSERT_TRUE(!boost::empty(result_range));
132130
parsed.assign(boost::begin(result_range), boost::end(result_range));
133131
std::cout << "PARSED: " << parsed << " [state:" << p.state() << "] " << std::endl;
134132
}

http/test/request_linearize_test.cpp

-25
This file was deleted.

http/test/request_test.cpp

+45-41
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,28 @@
44
// (See accompanying file LICENSE_1_0.txt or copy at
55
// http://www.boost.org/LICENSE_1_0.txt)
66

7-
#ifdef BUILD_SHARED_LIBS
8-
# define BOOST_TEST_DYN_LINK
9-
#endif
10-
#define BOOST_TEST_MODULE HTTP Request Test
7+
#include <gtest/gtest.h>
118
#include <network/protocol/http/request.hpp>
129
#include <network/protocol/http/message/wrappers.hpp>
1310
#include <network/message/wrappers.hpp>
14-
#include <boost/test/unit_test.hpp>
11+
#include <network/protocol/http/algorithms/linearize.hpp>
1512
#include <network/uri/uri_io.hpp>
1613

1714
namespace http = network::http;
1815
namespace net = network;
1916

20-
BOOST_AUTO_TEST_CASE(request_construction) {
17+
TEST(message_test, request_construction) {
2118
http::request request;
2219
http::request other(request);
2320
}
2421

25-
BOOST_AUTO_TEST_CASE(request_value_semantics) {
22+
TEST(message_test, request_value_semantics) {
2623
// First let's default construct a request.
2724
http::request original;
2825
// Next let's copy the request.
2926
http::request copy(original);
3027
// Next let's compare the requests.
31-
BOOST_CHECK(original == copy);
28+
ASSERT_TRUE(original == copy);
3229
// Next let's assign the original to another request.
3330
http::request assigned;
3431
assigned = original;
@@ -39,50 +36,50 @@ BOOST_AUTO_TEST_CASE(request_value_semantics) {
3936
assigned.set_destination("http://www.google.com/");
4037
assigned.append_header("Connection", "close");
4138
assigned.set_body("Hello, world!");
42-
BOOST_CHECK(original != assigned);
39+
ASSERT_TRUE(original != assigned);
4340
// Next we swap the assigned and copy.
4441
std::swap(assigned, copy);
45-
BOOST_CHECK(copy != assigned);
46-
BOOST_CHECK(copy != original);
47-
BOOST_CHECK(original == assigned);
42+
ASSERT_TRUE(copy != assigned);
43+
ASSERT_TRUE(copy != original);
44+
ASSERT_TRUE(original == assigned);
4845
}
4946

50-
//BOOST_AUTO_TEST_CASE(request_uri_test) {
51-
// http::request request;
52-
// request.set_uri("http://www.google.com/");
53-
// http::request other(request);
54-
// std::string original, copied;
55-
// request.get_uri(original);
56-
// other.get_uri(copied);
57-
// BOOST_CHECK_EQUAL(std::string("http://www.google.com/"), original);
58-
// BOOST_CHECK_EQUAL(original, copied);
59-
//
60-
// // Now we test the bare uri instance with accessing using the request
61-
// // convenience wrapper.
62-
// network::uri uri_;
63-
// request.get_uri(uri_);
64-
// std::string host_ = http::host(request);
65-
// BOOST_CHECK(network::valid(uri_));
66-
// BOOST_CHECK_EQUAL(std::string("www.google.com"), host_);
67-
// BOOST_CHECK_EQUAL(uri_.host(), host_);
68-
// BOOST_CHECK_EQUAL(std::string("www.google.com"), uri_.host());
69-
//}
47+
TEST(message_test, request_uri) {
48+
http::request request;
49+
request.set_uri("http://www.google.com/");
50+
http::request other(request);
51+
std::string original, copied;
52+
request.get_uri(original);
53+
other.get_uri(copied);
54+
ASSERT_EQ(std::string("http://www.google.com/"), original);
55+
ASSERT_EQ(original, copied);
56+
57+
// Now we test the bare uri instance with accessing using the request
58+
// convenience wrapper.
59+
network::uri uri_;
60+
request.get_uri(uri_);
61+
std::string host_ = http::host(request);
62+
ASSERT_EQ(std::string("www.google.com"), host_);
63+
std::string gotten_host(*uri_.host());
64+
ASSERT_EQ(gotten_host, host_);
65+
ASSERT_EQ(std::string("www.google.com"), gotten_host);
66+
}
7067

71-
BOOST_AUTO_TEST_CASE(request_url_constructor_test) {
68+
TEST(message_test, request_url_constructor) {
7269
http::request request("http://www.google.com/");
7370
http::request other;
7471
other.set_uri("http://www.google.com/");
7572
network::uri original, other_uri;
7673
request.get_uri(original);
7774
other.get_uri(other_uri);
78-
BOOST_CHECK_EQUAL(original, other_uri);
75+
ASSERT_EQ(original, other_uri);
7976

8077
// Now test the directives..
8178
network::uri directive_original = http::uri(request);
82-
BOOST_CHECK_EQUAL(original, directive_original);
79+
ASSERT_EQ(original, directive_original);
8380
}
8481

85-
BOOST_AUTO_TEST_CASE(request_basics_test) {
82+
TEST(message_test, request_basics) {
8683
http::request request;
8784
request.set_uri("http://www.google.com/");
8885
request.set_source("127.0.0.1");
@@ -99,9 +96,16 @@ BOOST_AUTO_TEST_CASE(request_basics_test) {
9996
request.get_destination(destination_);
10097
request.get_body(body_);
10198

102-
BOOST_CHECK_EQUAL(uri_.string(), std::string("http://www.google.com/"));
103-
BOOST_CHECK_EQUAL(source_, std::string("127.0.0.1"));
104-
BOOST_CHECK_EQUAL(destination_, std::string("destination!"));
105-
BOOST_CHECK_EQUAL(body_, std::string("The quick brown fox jumps over the lazy dog!"));
106-
BOOST_CHECK(!boost::empty(headers_));
99+
ASSERT_EQ(uri_.string(), std::string("http://www.google.com/"));
100+
ASSERT_EQ(source_, std::string("127.0.0.1"));
101+
ASSERT_EQ(destination_, std::string("destination!"));
102+
ASSERT_EQ(body_, std::string("The quick brown fox jumps over the lazy dog!"));
103+
ASSERT_TRUE(!boost::empty(headers_));
104+
}
105+
106+
TEST(message_test, linearize_request) {
107+
http::request request("http://www.boost.org");
108+
// TODO: Actually specify the expected output.
109+
linearize(request, "GET", 1, 0, std::ostream_iterator<char>(std::cout));
110+
linearize(request, "GET", 2, 1, std::ostream_iterator<char>(std::cout));
107111
}

0 commit comments

Comments
 (0)