Test error code handling

fix #478
This commit is contained in:
Vinnie Falco
2017-06-13 07:23:58 -07:00
parent ee191d865c
commit 7d92048c5c
5 changed files with 39 additions and 21 deletions

View File

@@ -83,6 +83,26 @@ make_error_code(error ev)
detail::get_error_category()}; 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<class Arg0, class... ArgN>
fail_error_code(Arg0&& arg0, ArgN&&... argn)
: error_code(arg0, std::forward<ArgN>(argn)...)
{
}
};
/** A countdown to simulated failure. /** A countdown to simulated failure.
On the Nth operation, the class will fail with the specified On the Nth operation, the class will fail with the specified

View File

@@ -59,7 +59,7 @@ public:
decltype(fs)&, multi_buffer> srs(fs); decltype(fs)&, multi_buffer> srs(fs);
srs.buffer().commit(buffer_copy( srs.buffer().commit(buffer_copy(
srs.buffer().prepare(5), buffer("Hello", 5))); 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); boost::asio::read(srs, buffer(&s[0], s.size()), ec);
if(! ec) if(! ec)
{ {
@@ -78,7 +78,7 @@ public:
srs.capacity(3); srs.capacity(3);
srs.buffer().commit(buffer_copy( srs.buffer().commit(buffer_copy(
srs.buffer().prepare(5), buffer("Hello", 5))); 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); boost::asio::read(srs, buffer(&s[0], s.size()), ec);
if(! ec) if(! ec)
{ {
@@ -96,7 +96,7 @@ public:
decltype(fs)&, multi_buffer> srs(fs); decltype(fs)&, multi_buffer> srs(fs);
srs.buffer().commit(buffer_copy( srs.buffer().commit(buffer_copy(
srs.buffer().prepare(5), buffer("Hello", 5))); srs.buffer().prepare(5), buffer("Hello", 5)));
error_code ec; error_code ec = test::error::fail_error;
boost::asio::async_read( boost::asio::async_read(
srs, buffer(&s[0], s.size()), do_yield[ec]); srs, buffer(&s[0], s.size()), do_yield[ec]);
if(! ec) if(! ec)
@@ -116,7 +116,7 @@ public:
srs.capacity(3); srs.capacity(3);
srs.buffer().commit(buffer_copy( srs.buffer().commit(buffer_copy(
srs.buffer().prepare(5), buffer("Hello", 5))); srs.buffer().prepare(5), buffer("Hello", 5)));
error_code ec; error_code ec = test::error::fail_error;
boost::asio::async_read( boost::asio::async_read(
srs, buffer(&s[0], s.size()), do_yield[ec]); srs, buffer(&s[0], s.size()), do_yield[ec]);
if(! ec) if(! ec)

View File

@@ -50,7 +50,7 @@ public:
test::fail_stream< test::fail_stream<
test::string_istream> fs{fc, ios_, ""}; test::string_istream> fs{fc, ios_, ""};
test_parser<isRequest> p(fc); test_parser<isRequest> p(fc);
error_code ec; error_code ec = test::error::fail_error;
read(fs, b, p, ec); read(fs, b, p, ec);
if(! ec) if(! ec)
break; break;
@@ -66,7 +66,7 @@ public:
test::fail_stream<test::string_istream> fs{ test::fail_stream<test::string_istream> fs{
fc, ios_, std::string{s + pre, len - pre}}; fc, ios_, std::string{s + pre, len - pre}};
test_parser<isRequest> p(fc); test_parser<isRequest> p(fc);
error_code ec; error_code ec = test::error::fail_error;
read(fs, b, p, ec); read(fs, b, p, ec);
if(! ec) if(! ec)
break; break;
@@ -81,7 +81,7 @@ public:
test::fail_stream< test::fail_stream<
test::string_istream> fs{fc, ios_, ""}; test::string_istream> fs{fc, ios_, ""};
test_parser<isRequest> p(fc); test_parser<isRequest> p(fc);
error_code ec; error_code ec = test::error::fail_error;
async_read(fs, b, p, do_yield[ec]); async_read(fs, b, p, do_yield[ec]);
if(! ec) if(! ec)
break; break;
@@ -97,7 +97,7 @@ public:
test::fail_stream<test::string_istream> fs{ test::fail_stream<test::string_istream> fs{
fc, ios_, std::string{s + pre, len - pre}}; fc, ios_, std::string{s + pre, len - pre}};
test_parser<isRequest> p(fc); test_parser<isRequest> p(fc);
error_code ec; error_code ec = test::error::fail_error;
async_read(fs, b, p, do_yield[ec]); async_read(fs, b, p, do_yield[ec]);
if(! ec) if(! ec)
break; break;
@@ -158,7 +158,7 @@ public:
"10\r\n" "10\r\n"
"****************\r\n" "****************\r\n"
"0\r\n\r\n"; "0\r\n\r\n";
error_code ec; error_code ec = test::error::fail_error;
static_buffer_n<10> b; static_buffer_n<10> b;
request<string_body> req; request<string_body> req;
read(p.server, b, req, ec); read(p.server, b, req, ec);
@@ -266,7 +266,7 @@ public:
"\r\n" "\r\n"
); );
request<dynamic_body> m; request<dynamic_body> m;
error_code ec; error_code ec = test::error::fail_error;
multi_buffer b; multi_buffer b;
read(fs, b, m, ec); read(fs, b, m, ec);
if(! ec) if(! ec)
@@ -284,7 +284,7 @@ public:
"\r\n" "\r\n"
); );
request<dynamic_body> m; request<dynamic_body> m;
error_code ec; error_code ec = test::error::fail_error;
multi_buffer b; multi_buffer b;
async_read(fs, b, m, do_yield[ec]); async_read(fs, b, m, do_yield[ec]);
if(! ec) if(! ec)
@@ -393,7 +393,7 @@ public:
for(std::size_t n = 1; n < s.size() - 1; ++n) for(std::size_t n = 1; n < s.size() - 1; ++n)
{ {
Parser p; Parser p;
error_code ec; error_code ec = test::error::fail_error;
flat_buffer b; flat_buffer b;
test::pipe c{ios_}; test::pipe c{ios_};
ostream(c.server.buffer) << s; ostream(c.server.buffer) << s;
@@ -442,7 +442,6 @@ public:
void void
run() override run() override
{ {
#if 0
testThrow(); testThrow();
testBufferOverflow(); testBufferOverflow();
@@ -455,7 +454,6 @@ public:
testIoService(); testIoService();
testRegression430(); testRegression430();
#endif
testReadGrind(); testReadGrind();
} }
}; };

View File

@@ -395,7 +395,7 @@ public:
m.insert(field::user_agent, "test"); m.insert(field::user_agent, "test");
m.insert("Transfer-Encoding", "chunked"); m.insert("Transfer-Encoding", "chunked");
m.body = "*****"; m.body = "*****";
error_code ec; error_code ec = test::error::fail_error;
write(fs, m, ec); write(fs, m, ec);
if(ec == error::end_of_stream) if(ec == error::end_of_stream)
{ {
@@ -428,7 +428,7 @@ public:
m.insert(field::user_agent, "test"); m.insert(field::user_agent, "test");
m.insert("Transfer-Encoding", "chunked"); m.insert("Transfer-Encoding", "chunked");
m.body = "*****"; m.body = "*****";
error_code ec; error_code ec = test::error::fail_error;
async_write(fs, m, do_yield[ec]); async_write(fs, m, do_yield[ec]);
if(ec == error::end_of_stream) if(ec == error::end_of_stream)
{ {
@@ -461,7 +461,7 @@ public:
m.insert(field::user_agent, "test"); m.insert(field::user_agent, "test");
m.insert("Content-Length", "5"); m.insert("Content-Length", "5");
m.body = "*****"; m.body = "*****";
error_code ec; error_code ec = test::error::fail_error;
write(fs, m, ec); write(fs, m, ec);
if(! ec) if(! ec)
{ {
@@ -489,7 +489,7 @@ public:
m.insert(field::user_agent, "test"); m.insert(field::user_agent, "test");
m.insert("Content-Length", "5"); m.insert("Content-Length", "5");
m.body = "*****"; m.body = "*****";
error_code ec; error_code ec = test::error::fail_error;
async_write(fs, m, do_yield[ec]); async_write(fs, m, do_yield[ec]);
if(! ec) if(! ec)
{ {

View File

@@ -965,7 +965,7 @@ public:
void void
testHandshake() testHandshake()
{ {
error_code ec; error_code ec = test::error::fail_error;
::websocket::async_echo_server server{nullptr, 1}; ::websocket::async_echo_server server{nullptr, 1};
auto const any = endpoint_type{ auto const any = endpoint_type{
address_type::from_string("127.0.0.1"), 0}; address_type::from_string("127.0.0.1"), 0};
@@ -1177,7 +1177,7 @@ public:
std::vector<char> v; std::vector<char> v;
for(char n = 0; n < 20; ++n) for(char n = 0; n < 20; ++n)
{ {
error_code ec; error_code ec = test::error::fail_error;
socket_type sock(ios_); socket_type sock(ios_);
sock.connect(ep, ec); sock.connect(ep, ec);
if(! BEAST_EXPECTS(! ec, ec.message())) if(! BEAST_EXPECTS(! ec, ec.message()))
@@ -1202,7 +1202,7 @@ public:
std::vector<char> v; std::vector<char> v;
for(char n = 0; n < 20; ++n) for(char n = 0; n < 20; ++n)
{ {
error_code ec; error_code ec = test::error::fail_error;
socket_type sock(ios_); socket_type sock(ios_);
sock.connect(ep, ec); sock.connect(ep, ec);
if(! BEAST_EXPECTS(! ec, ec.message())) if(! BEAST_EXPECTS(! ec, ec.message()))