diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b07a343..56bdd598 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Require Visual Studio 2015 Update 3 or later * Use fwrite return value in file_body +* Add decorator unit test -------------------------------------------------------------------------------- diff --git a/test/websocket/stream.cpp b/test/websocket/stream.cpp index d02dd2f4..08895a81 100644 --- a/test/websocket/stream.cpp +++ b/test/websocket/stream.cpp @@ -109,26 +109,38 @@ public: return false; } - struct identity + struct test_decorator { - template - void - operator()(http::message&) + int& what; + + test_decorator(test_decorator const&) = default; + + test_decorator(int& what_) + : what(what_) { + what = 0; } - template + template void - operator()(http::message&) + operator()(http::header&) const { + what |= 1; + } + + template + void + operator()(http::header&) const + { + what |= 2; } }; - void testOptions() + void + testOptions() { stream ws(ios_); ws.set_option(auto_fragment{true}); - ws.set_option(decorate(identity{})); ws.set_option(keep_alive{false}); ws.set_option(write_buffer_size{2048}); 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 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, yield_context do_yield) { @@ -1257,6 +1287,7 @@ public: server.open(any, ec); BEAST_EXPECTS(! ec, ec.message()); auto const ep = server.local_endpoint(); + testDecorator(ep); //testInvokable1(ep); testInvokable2(ep); testInvokable3(ep);