Menu

[r224]: / trunk / libs / network / test / message_test.cpp  Maximize  Restore  History

Download this file

169 lines (144 with data), 5.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright Dean Michael Berris 2007.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_TEST_MODULE message test
#include <boost/test/unit_test.hpp>
#include <boost/network.hpp>
#include <algorithm>
/**
* Defines a set of template functions that can be used to test
* generic code.
*/
namespace test_suite {
template <
class Message
>
void copy_constructor_test(Message instance,
const typename Message::string_type &h,
const typename Message::string_type &c) {
typedef typename Message::string_type string;
using namespace boost::network;
instance << header(h, c);
Message copy(instance);
BOOST_CHECK_EQUAL (headers(copy).count(h), static_cast<std::size_t>(1));
typename headers_range<Message>::type range = headers(copy)[h];
BOOST_CHECK (begin(range) != end(range));
}
template <
class Message
>
void swap_test(Message instance,
const typename Message::string_type &h,
const typename Message::string_type &c) {
instance << boost::network::header(h, c);
Message other;
swap(instance, other);
BOOST_CHECK_EQUAL (headers(instance).count(h), static_cast<std::size_t>(0));
BOOST_CHECK_EQUAL (headers(other).count(h), static_cast<std::size_t>(1));
}
template <
class Message
>
void headers_directive_test(Message instance,
const typename Message::string_type &h,
const typename Message::string_type &c) {
using namespace boost::network;
instance << header(h, c);
BOOST_CHECK_EQUAL( headers(instance).count(h), static_cast<std::size_t>(1) );
typename headers_range<Message>::type range = headers(instance)[h];
BOOST_CHECK( begin(range) != end(range) );
}
template <
class Message
>
void body_directive_test(Message instance,
const typename Message::string_type &b) {
using namespace boost::network;
instance << body(b) ;
// BOOST_CHECK_EQUAL( body(instance), b);
BOOST_CHECK( body(instance) == b);
}
template <
class Message
>
void source_directive_test(Message instance,
const typename Message::string_type &s) {
using namespace boost::network;
instance << source(s) ;
// BOOST_CHECK_EQUAL( source(instance), s);
BOOST_CHECK( source(instance) == s);
}
template <
class Message
>
void destination_directive_test(Message instance,
const typename Message::string_type &d) {
using namespace boost::network;
instance << destination(d);
// BOOST_CHECK_EQUAL( destination(instance), d);
BOOST_CHECK( destination(instance) == d);
}
template <
class Message
>
void remove_header_directive_test(Message instance,
const typename Message::string_type &h,
const typename Message::string_type &c) {
using namespace boost::network;
instance << header(h, c)
<< remove_header(h);
typename headers_range<Message>::type range = headers(instance);
BOOST_CHECK ( begin(range) == end(range) );
}
}
BOOST_AUTO_TEST_CASE(copy_constructor_test) {
test_suite::copy_constructor_test(boost::network::message(),
"SOME_HEADER",
"SOME_CONTENT");
test_suite::copy_constructor_test(boost::network::wmessage(),
L"SOME_HEADER",
L"SOME_CONTENT");
}
BOOST_AUTO_TEST_CASE(swap_test) {
test_suite::swap_test(boost::network::message(),
"SOME_HEADER",
"SOME_CONTENT");
test_suite::swap_test(boost::network::wmessage(),
L"SOME_HEADER",
L"SOME_CONTENT");
}
BOOST_AUTO_TEST_CASE(header_directives_test) {
test_suite::headers_directive_test(boost::network::message(),
"SOME_HEADER",
"SOME_CONTENT");
test_suite::headers_directive_test(boost::network::wmessage(),
L"SOME_HEADER",
L"SOME_CONTENT");
}
BOOST_AUTO_TEST_CASE(body_directive_test) {
test_suite::body_directive_test(boost::network::message(),
"The quick brown fox jumps over the lazy dog.");
test_suite::body_directive_test(boost::network::wmessage(),
L"The quick brown fox jumps over the lazy dog.");
}
BOOST_AUTO_TEST_CASE(source_directive_test) {
test_suite::source_directive_test(boost::network::message(),
"Somewhere Out There");
test_suite::source_directive_test(boost::network::wmessage(),
L"Somewhere Out There");
}
BOOST_AUTO_TEST_CASE(destination_directive_test) {
test_suite::destination_directive_test(boost::network::message(),
"Somewhere Out There");
test_suite::destination_directive_test(boost::network::wmessage(),
L"Somewhere Out There");
}
BOOST_AUTO_TEST_CASE(remove_header_directive_test) {
test_suite::remove_header_directive_test(boost::network::message(),
"Header",
"Value");
test_suite::remove_header_directive_test(boost::network::wmessage(),
L"Header",
L"Value");
}