Add decorator unit test

fix #302
This commit is contained in:
Vinnie Falco
2017-04-12 18:49:18 -07:00
parent a595c3ba85
commit f8b0c22501
2 changed files with 40 additions and 8 deletions

View File

@@ -2,6 +2,7 @@
* Require Visual Studio 2015 Update 3 or later * Require Visual Studio 2015 Update 3 or later
* Use fwrite return value in file_body * Use fwrite return value in file_body
* Add decorator unit test
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@@ -109,26 +109,38 @@ public:
return false; return false;
} }
struct identity struct test_decorator
{ {
template<class Body, class Fields> int& what;
void
operator()(http::message<true, Body, Fields>&) test_decorator(test_decorator const&) = default;
test_decorator(int& what_)
: what(what_)
{ {
what = 0;
} }
template<class Body, class Fields> template<class Fields>
void void
operator()(http::message<false, Body, Fields>&) operator()(http::header<true, Fields>&) const
{ {
what |= 1;
}
template<class Fields>
void
operator()(http::header<false, Fields>&) const
{
what |= 2;
} }
}; };
void testOptions() void
testOptions()
{ {
stream<socket_type> ws(ios_); stream<socket_type> ws(ios_);
ws.set_option(auto_fragment{true}); ws.set_option(auto_fragment{true});
ws.set_option(decorate(identity{}));
ws.set_option(keep_alive{false}); ws.set_option(keep_alive{false});
ws.set_option(write_buffer_size{2048}); ws.set_option(write_buffer_size{2048});
ws.set_option(message_type{opcode::text}); ws.set_option(message_type{opcode::text});
@@ -411,6 +423,24 @@ public:
); );
} }
void
testDecorator(endpoint_type const& ep)
{
error_code ec;
socket_type sock{ios_};
sock.connect(ep, ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
return;
stream<socket_type&> ws{sock};
int what;
ws.set_option(decorate(test_decorator{what}));
BEAST_EXPECT(what == 0);
ws.handshake("localhost", "/", ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
return;
BEAST_EXPECT(what == 1);
}
void testMask(endpoint_type const& ep, void testMask(endpoint_type const& ep,
yield_context do_yield) yield_context do_yield)
{ {
@@ -1257,6 +1287,7 @@ public:
server.open(any, ec); server.open(any, ec);
BEAST_EXPECTS(! ec, ec.message()); BEAST_EXPECTS(! ec, ec.message());
auto const ep = server.local_endpoint(); auto const ep = server.local_endpoint();
testDecorator(ep);
//testInvokable1(ep); //testInvokable1(ep);
testInvokable2(ep); testInvokable2(ep);
testInvokable3(ep); testInvokable3(ep);