|
1 | 1 |
|
2 |
| -// Copyright Dean Michael Berris 2007. |
| 2 | +// Copyright Dean Michael Berris 2007. |
| 3 | +// Copyright 2015 Google, Inc. |
3 | 4 | // 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) |
| 5 | +// (See accompanying file LICENSE_1_0.txt or copy at |
| 6 | +// http://www.boost.org/LICENSE_1_0.txt) |
6 | 7 |
|
7 |
| -#define BOOST_TEST_MODULE message test |
8 |
| -#include <boost/config/warning_disable.hpp> |
9 |
| -#include <boost/test/unit_test.hpp> |
10 |
| -#include <boost/network.hpp> |
| 8 | +// Migrated from using Boost.Test to using googletest instead. |
| 9 | +#include <gtest/gtest.h> |
11 | 10 | #include <algorithm>
|
12 |
| -#include <boost/mpl/list.hpp> |
| 11 | +#include <boost/network/include/message.hpp> |
| 12 | +#include <boost/network/message/directives.hpp> |
13 | 13 |
|
14 |
| -using namespace boost::network; |
| 14 | +namespace { |
15 | 15 |
|
16 |
| -typedef boost::mpl::list<http::tags::http_default_8bit_tcp_resolve, |
17 |
| - http::tags::http_default_8bit_udp_resolve, |
18 |
| - http::tags::http_keepalive_8bit_tcp_resolve, |
19 |
| - http::tags::http_keepalive_8bit_udp_resolve, |
20 |
| - tags::default_string, tags::default_wstring> tag_types; |
| 16 | +namespace http = boost::network::http; |
| 17 | +namespace network = boost::network; |
21 | 18 |
|
22 |
| -struct string_header_name { |
23 |
| - static std::string string; |
| 19 | +template <class T> |
| 20 | +class MessageTest : public ::testing::Test { |
24 | 21 | };
|
25 | 22 |
|
26 |
| -std::string string_header_name::string = "Header"; |
27 |
| - |
28 |
| -struct wstring_header_name { |
29 |
| - static std::wstring string; |
30 |
| -}; |
31 |
| - |
32 |
| -std::wstring wstring_header_name::string = L"Header"; |
33 |
| - |
34 |
| -struct string_header_value { |
35 |
| - static std::string string; |
36 |
| -}; |
37 |
| - |
38 |
| -std::string string_header_value::string = "Value"; |
39 |
| - |
40 |
| -struct wstring_header_value { |
41 |
| - static std::wstring string; |
42 |
| -}; |
43 |
| - |
44 |
| -std::wstring wstring_header_value::string = L"Value"; |
45 |
| - |
46 |
| -template <class Tag> |
47 |
| -struct header_name : string_header_name {}; |
48 |
| - |
49 |
| -template <> |
50 |
| -struct header_name<tags::default_wstring> : wstring_header_name {}; |
51 |
| - |
52 |
| -template <class Tag> |
53 |
| -struct header_value : string_header_value {}; |
54 |
| - |
55 |
| -template <> |
56 |
| -struct header_value<tags::default_wstring> : wstring_header_value {}; |
57 |
| - |
58 |
| -struct string_body_data { |
59 |
| - static std::string string; |
60 |
| -}; |
61 |
| - |
62 |
| -std::string string_body_data::string = |
63 |
| - "The quick brown fox jumps over the lazy dog."; |
64 |
| - |
65 |
| -struct wstring_body_data { |
66 |
| - static std::wstring string; |
67 |
| -}; |
68 |
| - |
69 |
| -std::wstring wstring_body_data::string = |
70 |
| - L"The quick brown fox jumps over the lazy dog."; |
71 |
| - |
72 |
| -template <class Tag> |
73 |
| -struct body_data : string_body_data {}; |
74 |
| - |
75 |
| -template <> |
76 |
| -struct body_data<tags::default_wstring> : wstring_body_data {}; |
77 |
| - |
78 |
| -struct string_source_data { |
79 |
| - static std::string string; |
80 |
| -}; |
81 |
| - |
82 |
| -std::string string_source_data::string = "Source"; |
83 |
| - |
84 |
| -struct wstring_source_data { |
85 |
| - static std::wstring string; |
86 |
| -}; |
87 |
| - |
88 |
| -std::wstring wstring_source_data::string = L"Source"; |
89 |
| - |
90 |
| -template <class Tag> |
91 |
| -struct source_data : string_source_data {}; |
92 |
| - |
93 |
| -template <> |
94 |
| -struct source_data<tags::default_wstring> : wstring_body_data {}; |
95 |
| - |
96 |
| -struct string_destination_data { |
97 |
| - static std::string string; |
98 |
| -}; |
99 |
| - |
100 |
| -std::string string_destination_data::string = "Destination"; |
101 |
| - |
102 |
| -struct wstring_destination_data { |
103 |
| - static std::wstring string; |
104 |
| -}; |
105 |
| - |
106 |
| -std::wstring wstring_destination_data::string = L"Destination"; |
107 |
| - |
108 |
| -template <class Tag> |
109 |
| -struct destination_data : string_destination_data {}; |
110 |
| - |
111 |
| -template <> |
112 |
| -struct destination_data<tags::default_wstring> : wstring_destination_data {}; |
| 23 | +using TagTypes = ::testing::Types<http::tags::http_default_8bit_tcp_resolve, |
| 24 | + http::tags::http_default_8bit_udp_resolve, |
| 25 | + http::tags::http_keepalive_8bit_tcp_resolve, |
| 26 | + http::tags::http_keepalive_8bit_udp_resolve, |
| 27 | + network::tags::default_string>; |
| 28 | +TYPED_TEST_CASE(MessageTest, TagTypes); |
| 29 | + |
| 30 | +TYPED_TEST(MessageTest, Constructors){ |
| 31 | + network::basic_message<TypeParam> message; // default construction |
| 32 | + auto copy = message; // copy construction |
| 33 | + ASSERT_TRUE(copy == message); |
| 34 | +} |
113 | 35 |
|
114 |
| -/** |
115 |
| - * Defines a set of template functions that can be used to test |
116 |
| - * generic code. |
117 |
| - */ |
| 36 | +TYPED_TEST(MessageTest, Equality) { |
| 37 | + // Create an original message. |
| 38 | + network::basic_message<TypeParam> message; |
| 39 | + message << network::source("source") << network::destination("destination") |
| 40 | + << network::header("key", "value") << network::body("body"); |
118 | 41 |
|
119 |
| -BOOST_AUTO_TEST_CASE_TEMPLATE(copy_constructor_test, T, tag_types) { |
120 |
| - basic_message<T> instance; |
121 |
| - instance << header(header_name<T>::string, header_value<T>::string); |
122 |
| - basic_message<T> copy(instance); |
123 |
| - BOOST_CHECK_EQUAL(headers(copy).count(header_name<T>::string), |
124 |
| - static_cast<std::size_t>(1)); |
125 |
| - typename headers_range<basic_message<T> >::type range = |
126 |
| - headers(copy)[header_name<T>::string]; |
127 |
| - BOOST_CHECK(boost::begin(range) != boost::end(range)); |
128 |
| -} |
| 42 | + // Create the identical message. |
| 43 | + network::basic_message<TypeParam> other; |
| 44 | + other << network::source("source") << network::destination("destination") |
| 45 | + << network::header("key", "value") << network::body("body"); |
129 | 46 |
|
130 |
| -BOOST_AUTO_TEST_CASE_TEMPLATE(swap_test, T, tag_types) { |
131 |
| - basic_message<T> instance; |
132 |
| - instance << header(header_name<T>::string, header_value<T>::string); |
133 |
| - basic_message<T> other; |
134 |
| - swap(instance, other); |
135 |
| - BOOST_CHECK_EQUAL(headers(instance).count(header_name<T>::string), |
136 |
| - static_cast<std::size_t>(0)); |
137 |
| - BOOST_CHECK_EQUAL(headers(other).count(header_name<T>::string), |
138 |
| - static_cast<std::size_t>(1)); |
| 47 | + ASSERT_TRUE(message == other); |
139 | 48 | }
|
140 | 49 |
|
141 |
| -BOOST_AUTO_TEST_CASE_TEMPLATE(headers_directive_test, T, tag_types) { |
142 |
| - basic_message<T> instance; |
143 |
| - instance << header(header_name<T>::string, header_value<T>::string); |
144 |
| - BOOST_CHECK_EQUAL(headers(instance).count(header_name<T>::string), |
145 |
| - static_cast<std::size_t>(1)); |
146 |
| - typename headers_range<basic_message<T> >::type range = |
147 |
| - headers(instance)[header_name<T>::string]; |
148 |
| - BOOST_CHECK(boost::begin(range) != boost::end(range)); |
149 |
| -} |
| 50 | +TYPED_TEST(MessageTest, Inequality) { |
| 51 | + // Create an original message. |
| 52 | + network::basic_message<TypeParam> message; |
| 53 | + message << network::source("source") << network::destination("destination") |
| 54 | + << network::header("key", "value") << network::body("body"); |
150 | 55 |
|
151 |
| -BOOST_AUTO_TEST_CASE_TEMPLATE(body_directive_test, T, tag_types) { |
152 |
| - basic_message<T> instance; |
153 |
| - instance << ::boost::network::body(body_data<T>::string); |
154 |
| - typename string<T>::type body_string = body(instance); |
155 |
| - BOOST_CHECK(body_string == body_data<T>::string); |
156 |
| -} |
| 56 | + // Create a different message. |
| 57 | + network::basic_message<TypeParam> other; |
| 58 | + other << network::source("source") << network::destination("destination") |
| 59 | + << network::header("key", "value") << network::body("different body!"); |
157 | 60 |
|
158 |
| -BOOST_AUTO_TEST_CASE_TEMPLATE(source_directive_test, T, tag_types) { |
159 |
| - basic_message<T> instance; |
160 |
| - instance << ::boost::network::source(source_data<T>::string); |
161 |
| - typename string<T>::type source_string = source(instance); |
162 |
| - BOOST_CHECK(source_string == source_data<T>::string); |
| 61 | + ASSERT_FALSE(message == other); |
163 | 62 | }
|
164 | 63 |
|
165 |
| -BOOST_AUTO_TEST_CASE_TEMPLATE(destination_directive_test, T, tag_types) { |
166 |
| - basic_message<T> instance; |
167 |
| - instance << destination(destination_data<T>::string); |
168 |
| - BOOST_CHECK(destination(instance) == destination_data<T>::string); |
169 |
| -} |
| 64 | +} // namespace |
170 | 65 |
|
171 |
| -BOOST_AUTO_TEST_CASE_TEMPLATE(remove_header_directive_test, T, tag_types) { |
172 |
| - basic_message<T> instance; |
173 |
| - instance << header(header_name<T>::string, header_value<T>::string) |
174 |
| - << remove_header(header_name<T>::string); |
175 |
| - typename headers_range<basic_message<T> >::type range = headers(instance); |
176 |
| - BOOST_CHECK(boost::begin(range) == boost::end(range)); |
177 |
| -} |
0 commit comments