diff --git a/extras/beast/test/fail_counter.hpp b/extras/beast/test/fail_counter.hpp index e263a31a..4ad34959 100644 --- a/extras/beast/test/fail_counter.hpp +++ b/extras/beast/test/fail_counter.hpp @@ -83,6 +83,26 @@ make_error_code(error ev) detail::get_error_category()}; } +/** An error code with an error set on default construction + + Default constructed versions of this object will have + an error code set right away. This helps tests find code + which forgets to clear the error code on success. +*/ +struct fail_error_code : error_code +{ + fail_error_code() + : error_code(make_error_code(error::fail_error)) + { + } + + template + fail_error_code(Arg0&& arg0, ArgN&&... argn) + : error_code(arg0, std::forward(argn)...) + { + } +}; + /** A countdown to simulated failure. On the Nth operation, the class will fail with the specified diff --git a/test/core/buffered_read_stream.cpp b/test/core/buffered_read_stream.cpp index e4338814..81536e1e 100644 --- a/test/core/buffered_read_stream.cpp +++ b/test/core/buffered_read_stream.cpp @@ -59,7 +59,7 @@ public: decltype(fs)&, multi_buffer> srs(fs); srs.buffer().commit(buffer_copy( srs.buffer().prepare(5), buffer("Hello", 5))); - error_code ec; + error_code ec = test::error::fail_error; boost::asio::read(srs, buffer(&s[0], s.size()), ec); if(! ec) { @@ -78,7 +78,7 @@ public: srs.capacity(3); srs.buffer().commit(buffer_copy( srs.buffer().prepare(5), buffer("Hello", 5))); - error_code ec; + error_code ec = test::error::fail_error; boost::asio::read(srs, buffer(&s[0], s.size()), ec); if(! ec) { @@ -96,7 +96,7 @@ public: decltype(fs)&, multi_buffer> srs(fs); srs.buffer().commit(buffer_copy( srs.buffer().prepare(5), buffer("Hello", 5))); - error_code ec; + error_code ec = test::error::fail_error; boost::asio::async_read( srs, buffer(&s[0], s.size()), do_yield[ec]); if(! ec) @@ -116,7 +116,7 @@ public: srs.capacity(3); srs.buffer().commit(buffer_copy( srs.buffer().prepare(5), buffer("Hello", 5))); - error_code ec; + error_code ec = test::error::fail_error; boost::asio::async_read( srs, buffer(&s[0], s.size()), do_yield[ec]); if(! ec) diff --git a/test/http/read.cpp b/test/http/read.cpp index 937b522c..3e28ea50 100644 --- a/test/http/read.cpp +++ b/test/http/read.cpp @@ -50,7 +50,7 @@ public: test::fail_stream< test::string_istream> fs{fc, ios_, ""}; test_parser p(fc); - error_code ec; + error_code ec = test::error::fail_error; read(fs, b, p, ec); if(! ec) break; @@ -66,7 +66,7 @@ public: test::fail_stream fs{ fc, ios_, std::string{s + pre, len - pre}}; test_parser p(fc); - error_code ec; + error_code ec = test::error::fail_error; read(fs, b, p, ec); if(! ec) break; @@ -81,7 +81,7 @@ public: test::fail_stream< test::string_istream> fs{fc, ios_, ""}; test_parser p(fc); - error_code ec; + error_code ec = test::error::fail_error; async_read(fs, b, p, do_yield[ec]); if(! ec) break; @@ -97,7 +97,7 @@ public: test::fail_stream fs{ fc, ios_, std::string{s + pre, len - pre}}; test_parser p(fc); - error_code ec; + error_code ec = test::error::fail_error; async_read(fs, b, p, do_yield[ec]); if(! ec) break; @@ -158,7 +158,7 @@ public: "10\r\n" "****************\r\n" "0\r\n\r\n"; - error_code ec; + error_code ec = test::error::fail_error; static_buffer_n<10> b; request req; read(p.server, b, req, ec); @@ -266,7 +266,7 @@ public: "\r\n" ); request m; - error_code ec; + error_code ec = test::error::fail_error; multi_buffer b; read(fs, b, m, ec); if(! ec) @@ -284,7 +284,7 @@ public: "\r\n" ); request m; - error_code ec; + error_code ec = test::error::fail_error; multi_buffer b; async_read(fs, b, m, do_yield[ec]); if(! ec) @@ -393,7 +393,7 @@ public: for(std::size_t n = 1; n < s.size() - 1; ++n) { Parser p; - error_code ec; + error_code ec = test::error::fail_error; flat_buffer b; test::pipe c{ios_}; ostream(c.server.buffer) << s; @@ -442,7 +442,6 @@ public: void run() override { -#if 0 testThrow(); testBufferOverflow(); @@ -455,7 +454,6 @@ public: testIoService(); testRegression430(); -#endif testReadGrind(); } }; diff --git a/test/http/write.cpp b/test/http/write.cpp index 3d8d6db9..d3d9895c 100644 --- a/test/http/write.cpp +++ b/test/http/write.cpp @@ -395,7 +395,7 @@ public: m.insert(field::user_agent, "test"); m.insert("Transfer-Encoding", "chunked"); m.body = "*****"; - error_code ec; + error_code ec = test::error::fail_error; write(fs, m, ec); if(ec == error::end_of_stream) { @@ -428,7 +428,7 @@ public: m.insert(field::user_agent, "test"); m.insert("Transfer-Encoding", "chunked"); m.body = "*****"; - error_code ec; + error_code ec = test::error::fail_error; async_write(fs, m, do_yield[ec]); if(ec == error::end_of_stream) { @@ -461,7 +461,7 @@ public: m.insert(field::user_agent, "test"); m.insert("Content-Length", "5"); m.body = "*****"; - error_code ec; + error_code ec = test::error::fail_error; write(fs, m, ec); if(! ec) { @@ -489,7 +489,7 @@ public: m.insert(field::user_agent, "test"); m.insert("Content-Length", "5"); m.body = "*****"; - error_code ec; + error_code ec = test::error::fail_error; async_write(fs, m, do_yield[ec]); if(! ec) { diff --git a/test/websocket/stream.cpp b/test/websocket/stream.cpp index 45747d7c..91f06a7a 100644 --- a/test/websocket/stream.cpp +++ b/test/websocket/stream.cpp @@ -965,7 +965,7 @@ public: void testHandshake() { - error_code ec; + error_code ec = test::error::fail_error; ::websocket::async_echo_server server{nullptr, 1}; auto const any = endpoint_type{ address_type::from_string("127.0.0.1"), 0}; @@ -1177,7 +1177,7 @@ public: std::vector v; for(char n = 0; n < 20; ++n) { - error_code ec; + error_code ec = test::error::fail_error; socket_type sock(ios_); sock.connect(ep, ec); if(! BEAST_EXPECTS(! ec, ec.message())) @@ -1202,7 +1202,7 @@ public: std::vector v; for(char n = 0; n < 20; ++n) { - error_code ec; + error_code ec = test::error::fail_error; socket_type sock(ios_); sock.connect(ep, ec); if(! BEAST_EXPECTS(! ec, ec.message()))