|
9 | 9 | #include<boost/test/unit_test.hpp> |
10 | 10 | #include<boost/network.hpp> |
11 | 11 | #include<algorithm> |
| 12 | +#include<boost/mpl/list.hpp> |
12 | 13 |
|
| 14 | +usingnamespaceboost::network; |
13 | 15 |
|
14 | | -/** |
15 | | - * Defines a set of template functions that can be used to test |
16 | | - * generic code. |
17 | | -*/ |
18 | | -namespacetest_suite { |
19 | | -template< |
20 | | -classMessage |
21 | | - > |
22 | | -voidcopy_constructor_test(Message instance, |
23 | | -consttypename Message::string_type &h, |
24 | | -consttypename Message::string_type &c) { |
25 | | -typedeftypename Message::string_type string; |
26 | | - |
27 | | -usingnamespaceboost::network; |
28 | | - instance <<header(h, c); |
29 | | - Messagecopy(instance); |
30 | | -BOOST_CHECK_EQUAL (headers(copy).count(h),static_cast<std::size_t>(1)); |
31 | | -typename headers_range<Message>::type range =headers(copy)[h]; |
32 | | -BOOST_CHECK (begin(range) !=end(range)); |
33 | | -} |
| 16 | +typedef boost::mpl::list<tags::http_default_8bit_tcp_resolve, tags::http_default_8bit_udp_resolve, tags::http_keepalive_8bit_tcp_resolve, tags::http_keepalive_8bit_udp_resolve, tags::http_server, tags::default_string, tags::default_wstring> tag_types; |
34 | 17 |
|
35 | | -template< |
36 | | -classMessage |
37 | | - > |
38 | | -voidswap_test(Message instance, |
39 | | -consttypename Message::string_type &h, |
40 | | -consttypename Message::string_type &c) { |
41 | | - instance <<boost::network::header(h, c); |
42 | | - Message other; |
43 | | -swap(instance, other); |
44 | | -BOOST_CHECK_EQUAL (headers(instance).count(h),static_cast<std::size_t>(0)); |
45 | | -BOOST_CHECK_EQUAL (headers(other).count(h),static_cast<std::size_t>(1)); |
46 | | -} |
| 18 | +structstring_header_name { |
| 19 | +static std::string string; |
| 20 | +}; |
47 | 21 |
|
48 | | -template< |
49 | | -classMessage |
50 | | - > |
51 | | -voidheaders_directive_test(Message instance, |
52 | | -consttypename Message::string_type &h, |
53 | | -consttypename Message::string_type &c) { |
54 | | -usingnamespaceboost::network; |
55 | | - instance <<header(h, c); |
56 | | - |
57 | | -BOOST_CHECK_EQUAL(headers(instance).count(h),static_cast<std::size_t>(1) ); |
58 | | -typename headers_range<Message>::type range =headers(instance)[h]; |
59 | | -BOOST_CHECK(begin(range) !=end(range) ); |
60 | | -} |
| 22 | +std::string string_header_name::string ="Header"; |
61 | 23 |
|
62 | | -template< |
63 | | -classMessage |
64 | | - > |
65 | | -voidbody_directive_test(Message instance, |
66 | | -consttypename Message::string_type &b) { |
67 | | -usingnamespaceboost::network; |
68 | | - instance <<body(b) ; |
| 24 | +structwstring_header_name { |
| 25 | +static std::wstring string; |
| 26 | +}; |
69 | 27 |
|
70 | | -// BOOST_CHECK_EQUAL( body(instance), b); |
71 | | -BOOST_CHECK(body(instance) == b); |
72 | | -} |
| 28 | +std::wstring wstring_header_name::string =L"Header"; |
73 | 29 |
|
74 | | -template< |
75 | | -classMessage |
76 | | - > |
77 | | -voidsource_directive_test(Message instance, |
78 | | -consttypename Message::string_type &s) { |
79 | | -usingnamespaceboost::network; |
80 | | -instance <<source(s) ; |
81 | | - |
82 | | -// BOOST_CHECK_EQUAL( source(instance), s); |
83 | | -BOOST_CHECK(source(instance) == s); |
84 | | -} |
| 30 | +structstring_header_value { |
| 31 | +static std::string string; |
| 32 | +}; |
85 | 33 |
|
86 | | -template< |
87 | | -classMessage |
88 | | - > |
89 | | -voiddestination_directive_test(Message instance, |
90 | | -consttypename Message::string_type &d) { |
91 | | -usingnamespaceboost::network; |
92 | | - instance <<destination(d); |
93 | | - |
94 | | -// BOOST_CHECK_EQUAL( destination(instance), d); |
95 | | -BOOST_CHECK(destination(instance) == d); |
96 | | - |
97 | | -} |
| 34 | +std::string string_header_value::string ="Value"; |
98 | 35 |
|
99 | | -template< |
100 | | -classMessage |
101 | | - > |
102 | | -voidremove_header_directive_test(Message instance, |
103 | | -consttypename Message::string_type &h, |
104 | | -consttypename Message::string_type &c) { |
105 | | -usingnamespaceboost::network; |
106 | | - instance <<header(h, c) |
107 | | - <<remove_header(h); |
108 | | -typename headers_range<Message>::type range =headers(instance); |
109 | | -BOOST_CHECK (begin(range) ==end(range) ); |
110 | | -} |
111 | | -} |
| 36 | +structwstring_header_value { |
| 37 | +static std::wstring string; |
| 38 | +}; |
| 39 | + |
| 40 | +std::wstring wstring_header_value::string =L"Value"; |
| 41 | + |
| 42 | +template<classTag> |
| 43 | +structheader_name : string_header_name {}; |
| 44 | + |
| 45 | +template<> |
| 46 | +structheader_name<tags::default_wstring> : wstring_header_name {}; |
| 47 | + |
| 48 | +template<classTag> |
| 49 | +structheader_value : string_header_value {}; |
| 50 | + |
| 51 | +template<> |
| 52 | +structheader_value<tags::default_wstring> : wstring_header_value {}; |
| 53 | + |
| 54 | +structstring_body_data { |
| 55 | +static std::string string; |
| 56 | +}; |
| 57 | + |
| 58 | +std::string string_body_data::string ="The quick brown fox jumps over the lazy dog."; |
| 59 | + |
| 60 | +structwstring_body_data { |
| 61 | +static std::wstring string; |
| 62 | +}; |
| 63 | + |
| 64 | +std::wstring wstring_body_data::string =L"The quick brown fox jumps over the lazy dog."; |
| 65 | + |
| 66 | +template<classTag> |
| 67 | +structbody_data : string_body_data {}; |
112 | 68 |
|
113 | | -BOOST_AUTO_TEST_CASE(copy_constructor_test) { |
114 | | -test_suite::copy_constructor_test(boost::network::message(), |
115 | | -"SOME_HEADER", |
116 | | -"SOME_CONTENT"); |
117 | | -test_suite::copy_constructor_test(boost::network::wmessage(), |
118 | | -L"SOME_HEADER", |
119 | | -L"SOME_CONTENT"); |
| 69 | +template<> |
| 70 | +structbody_data<tags::default_wstring> : wstring_body_data {}; |
| 71 | + |
| 72 | +structstring_source_data { |
| 73 | +static std::string string; |
| 74 | +}; |
| 75 | + |
| 76 | +std::string string_source_data::string ="Source"; |
| 77 | + |
| 78 | +structwstring_source_data { |
| 79 | +static std::wstring string; |
| 80 | +}; |
| 81 | + |
| 82 | +std::wstring wstring_source_data::string =L"Source"; |
| 83 | + |
| 84 | +template<classTag> |
| 85 | +structsource_data : string_source_data {}; |
| 86 | + |
| 87 | +template<> |
| 88 | +structsource_data<tags::default_wstring> : wstring_body_data {}; |
| 89 | + |
| 90 | +structstring_destination_data { |
| 91 | +static std::string string; |
| 92 | +}; |
| 93 | + |
| 94 | +std::string string_destination_data::string ="Destination"; |
| 95 | + |
| 96 | +structwstring_destination_data { |
| 97 | +static std::wstring string; |
| 98 | +}; |
| 99 | + |
| 100 | +std::wstring wstring_destination_data::string =L"Destination"; |
| 101 | + |
| 102 | +template<classTag> |
| 103 | +structdestination_data : string_destination_data {}; |
| 104 | + |
| 105 | +template<> |
| 106 | +structdestination_data<tags::default_wstring> : wstring_destination_data {}; |
| 107 | + |
| 108 | + |
| 109 | +/** |
| 110 | + * Defines a set of template functions that can be used to test |
| 111 | + * generic code. |
| 112 | +*/ |
| 113 | + |
| 114 | +BOOST_AUTO_TEST_CASE_TEMPLATE(copy_constructor_test, T, tag_types) { |
| 115 | + basic_message<T> instance; |
| 116 | + instance <<header(header_name<T>::string, header_value<T>::string); |
| 117 | + basic_message<T>copy(instance); |
| 118 | +BOOST_CHECK_EQUAL(headers(copy).count(header_name<T>::string),static_cast<std::size_t>(1)); |
| 119 | +typename headers_range<basic_message<T> >::type range =headers(copy)[header_name<T>::string]; |
| 120 | +BOOST_CHECK (begin(range) !=end(range)); |
120 | 121 | } |
121 | 122 |
|
122 | | -BOOST_AUTO_TEST_CASE(swap_test) { |
123 | | -test_suite::swap_test(boost::network::message(), |
124 | | -"SOME_HEADER", |
125 | | -"SOME_CONTENT"); |
126 | | -test_suite::swap_test(boost::network::wmessage(), |
127 | | -L"SOME_HEADER", |
128 | | -L"SOME_CONTENT"); |
| 123 | +BOOST_AUTO_TEST_CASE_TEMPLATE(swap_test, T, tag_types) { |
| 124 | +basic_message<T> instance; |
| 125 | +instance <<header(header_name<T>::string, header_value<T>::string); |
| 126 | +basic_message<T> other; |
| 127 | +swap(instance, other); |
| 128 | +BOOST_CHECK_EQUAL (headers(instance).count(header_name<T>::string),static_cast<std::size_t>(0)); |
| 129 | +BOOST_CHECK_EQUAL (headers(other).count(header_name<T>::string),static_cast<std::size_t>(1)); |
129 | 130 | } |
130 | 131 |
|
131 | | -BOOST_AUTO_TEST_CASE(header_directives_test) { |
132 | | -test_suite::headers_directive_test(boost::network::message(), |
133 | | -"SOME_HEADER", |
134 | | -"SOME_CONTENT"); |
135 | | -test_suite::headers_directive_test(boost::network::wmessage(), |
136 | | -L"SOME_HEADER", |
137 | | -L"SOME_CONTENT"); |
| 132 | +BOOST_AUTO_TEST_CASE_TEMPLATE(headers_directive_test, T, tag_types) { |
| 133 | + basic_message<T> instance; |
| 134 | + instance <<header(header_name<T>::string, header_value<T>::string); |
| 135 | +BOOST_CHECK_EQUAL (headers(instance).count(header_name<T>::string),static_cast<std::size_t>(1) ); |
| 136 | +typename headers_range<basic_message<T> >::type range =headers(instance)[header_name<T>::string]; |
| 137 | +BOOST_CHECK (begin(range) !=end(range)); |
138 | 138 | } |
139 | 139 |
|
140 | | -BOOST_AUTO_TEST_CASE(body_directive_test) { |
141 | | -test_suite::body_directive_test(boost::network::message(), |
142 | | -"The quick brown fox jumps over the lazy dog."); |
143 | | -test_suite::body_directive_test(boost::network::wmessage(), |
144 | | -L"The quick brown fox jumps over the lazy dog."); |
| 140 | +BOOST_AUTO_TEST_CASE_TEMPLATE(body_directive_test, T, tag_types) { |
| 141 | + basic_message<T> instance; |
| 142 | + instance <<body(body_data<T>::string); |
| 143 | +BOOST_CHECK (body(instance) == body_data<T>::string ); |
145 | 144 | } |
146 | 145 |
|
147 | | -BOOST_AUTO_TEST_CASE(source_directive_test) { |
148 | | -test_suite::source_directive_test(boost::network::message(), |
149 | | -"Somewhere Out There"); |
150 | | -test_suite::source_directive_test(boost::network::wmessage(), |
151 | | -L"Somewhere Out There"); |
| 146 | +BOOST_AUTO_TEST_CASE_TEMPLATE(source_directive_test, T, tag_types) { |
| 147 | + basic_message<T> instance; |
| 148 | + instance <<source(source_data<T>::string); |
| 149 | +BOOST_CHECK (source(instance) == source_data<T>::string ); |
152 | 150 | } |
153 | 151 |
|
154 | | -BOOST_AUTO_TEST_CASE(destination_directive_test) { |
155 | | -test_suite::destination_directive_test(boost::network::message(), |
156 | | -"Somewhere Out There"); |
157 | | -test_suite::destination_directive_test(boost::network::wmessage(), |
158 | | -L"Somewhere Out There"); |
| 152 | +BOOST_AUTO_TEST_CASE_TEMPLATE(destination_directive_test, T, tag_types) { |
| 153 | + basic_message<T> instance; |
| 154 | + instance <<destination(destination_data<T>::string); |
| 155 | +BOOST_CHECK (destination(instance) == destination_data<T>::string ); |
159 | 156 | } |
160 | 157 |
|
161 | | -BOOST_AUTO_TEST_CASE(remove_header_directive_test) { |
162 | | -test_suite::remove_header_directive_test(boost::network::message(), |
163 | | -"Header", |
164 | | -"Value"); |
165 | | -test_suite::remove_header_directive_test(boost::network::wmessage(), |
166 | | -L"Header", |
167 | | -L"Value"); |
| 158 | +BOOST_AUTO_TEST_CASE_TEMPLATE(remove_header_directive_test, T, tag_types) { |
| 159 | + basic_message<T> instance; |
| 160 | + instance <<header(header_name<T>::string, header_value<T>::string) |
| 161 | + <<remove_header(header_name<T>::string); |
| 162 | +typename headers_range<basic_message<T> >::type range =headers(instance); |
| 163 | +BOOST_CHECK (begin(range) ==end(range) ); |
168 | 164 | } |
169 | 165 |
|
| 166 | + |