Split out and rename test stream classes

This commit is contained in:
Vinnie Falco committed 2017-07-20 08:12:15 -07:00
1 parent 5bbbb1fb30
commit 1f52f4a791
9 files changed
+180 -111

No files matched your search

+5 -5
View File
@@ -10,7 +10,7 @@
#include <beast/core/streambuf.hpp>
#include <beast/test/fail_stream.hpp>
#include <beast/test/string_stream.hpp>
#include <beast/test/string_istream.hpp>
#include <beast/test/yield_to.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/asio.hpp>
@@ -54,7 +54,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_stream<
test::string_stream> fs(n, ios_, ", world!");
test::string_istream> fs(n, ios_, ", world!");
dynabuf_readstream<
decltype(fs)&, streambuf> srs(fs);
srs.buffer().commit(buffer_copy(
@@ -72,7 +72,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_stream<
test::string_stream> fs(n, ios_, ", world!");
test::string_istream> fs(n, ios_, ", world!");
dynabuf_readstream<
decltype(fs)&, streambuf> srs(fs);
srs.capacity(3);
@@ -91,7 +91,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_stream<
test::string_stream> fs(n, ios_, ", world!");
test::string_istream> fs(n, ios_, ", world!");
dynabuf_readstream<
decltype(fs)&, streambuf> srs(fs);
srs.buffer().commit(buffer_copy(
@@ -110,7 +110,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_stream<
test::string_stream> fs(n, ios_, ", world!");
test::string_istream> fs(n, ios_, ", world!");
dynabuf_readstream<
decltype(fs)&, streambuf> srs(fs);
srs.capacity(3);
+2 -2
View File
@@ -13,7 +13,7 @@
#include <beast/http/header_parser_v1.hpp>
#include <beast/http/parse.hpp>
#include <beast/http/string_body.hpp>
#include <beast/test/string_stream.hpp>
#include <beast/test/string_istream.hpp>
#include <beast/test/yield_to.hpp>
#include <beast/unit_test/suite.hpp>
@@ -55,7 +55,7 @@ public:
void testWithBody()
{
test::string_stream ss{ios_,
test::string_istream ss{ios_,
"GET / HTTP/1.1\r\n"
"User-Agent: test\r\n"
"Content-Length: 1\r\n"
+14 -14
View File
@@ -13,7 +13,7 @@
#include <beast/http/fields.hpp>
#include <beast/http/streambuf_body.hpp>
#include <beast/test/fail_stream.hpp>
#include <beast/test/string_stream.hpp>
#include <beast/test/string_istream.hpp>
#include <beast/test/yield_to.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/asio/spawn.hpp>
@@ -95,7 +95,7 @@ public:
sb.prepare(len), buffer(s, len)));
test::fail_counter fc(n);
test::fail_stream<
test::string_stream> fs{fc, ios_, ""};
test::string_istream> fs{fc, ios_, ""};
fail_parser<isRequest> p(fc);
error_code ec;
parse(fs, sb, p, ec);
@@ -110,7 +110,7 @@ public:
sb.commit(buffer_copy(
sb.prepare(pre), buffer(s, pre)));
test::fail_counter fc(n);
test::fail_stream<test::string_stream> fs{
test::fail_stream<test::string_istream> fs{
fc, ios_, std::string{s + pre, len - pre}};
fail_parser<isRequest> p(fc);
error_code ec;
@@ -126,7 +126,7 @@ public:
sb.prepare(len), buffer(s, len)));
test::fail_counter fc(n);
test::fail_stream<
test::string_stream> fs{fc, ios_, ""};
test::string_istream> fs{fc, ios_, ""};
fail_parser<isRequest> p(fc);
error_code ec;
async_parse(fs, sb, p, do_yield[ec]);
@@ -141,7 +141,7 @@ public:
sb.commit(buffer_copy(
sb.prepare(pre), buffer(s, pre)));
test::fail_counter fc(n);
test::fail_stream<test::string_stream> fs{
test::fail_stream<test::string_istream> fs{
fc, ios_, std::string{s + pre, len - pre}};
fail_parser<isRequest> p(fc);
error_code ec;
@@ -156,7 +156,7 @@ public:
sb.commit(buffer_copy(
sb.prepare(len), buffer(s, len)));
test::fail_counter fc{n};
test::string_stream ss{ios_, s};
test::string_istream ss{ios_, s};
parser_v1<isRequest, fail_body, fields> p{fc};
error_code ec;
parse(ss, sb, p, ec);
@@ -171,7 +171,7 @@ public:
try
{
streambuf sb;
test::string_stream ss(ios_, "GET / X");
test::string_istream ss(ios_, "GET / X");
parser_v1<true, streambuf_body, fields> p;
parse(ss, sb, p);
fail();
@@ -251,7 +251,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_stream<test::string_stream> fs{n, ios_,
test::fail_stream<test::string_istream> fs{n, ios_,
"GET / HTTP/1.1\r\n"
"Host: localhost\r\n"
"User-Agent: test\r\n"
@@ -273,7 +273,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_stream<test::string_stream> fs(n, ios_,
test::fail_stream<test::string_istream> fs(n, ios_,
"GET / HTTP/1.1\r\n"
"Host: localhost\r\n"
"User-Agent: test\r\n"
@@ -297,7 +297,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_stream<test::string_stream> fs(n, ios_,
test::fail_stream<test::string_istream> fs(n, ios_,
"GET / HTTP/1.1\r\n"
"Host: localhost\r\n"
"User-Agent: test\r\n"
@@ -319,7 +319,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_stream<test::string_stream> fs(n, ios_,
test::fail_stream<test::string_istream> fs(n, ios_,
"GET / HTTP/1.1\r\n"
"Host: localhost\r\n"
"User-Agent: test\r\n"
@@ -337,7 +337,7 @@ public:
for(n = 0; n < limit; ++n)
{
test::fail_stream<test::string_stream> fs(n, ios_,
test::fail_stream<test::string_istream> fs(n, ios_,
"GET / HTTP/1.1\r\n"
"Host: localhost\r\n"
"User-Agent: test\r\n"
@@ -358,7 +358,7 @@ public:
{
{
streambuf sb;
test::string_stream ss(ios_, "");
test::string_istream ss(ios_, "");
parser_v1<true, streambuf_body, fields> p;
error_code ec;
parse(ss, sb, p, ec);
@@ -366,7 +366,7 @@ public:
}
{
streambuf sb;
test::string_stream ss(ios_, "");
test::string_istream ss(ios_, "");
parser_v1<true, streambuf_body, fields> p;
error_code ec;
async_parse(ss, sb, p, do_yield[ec]);
+2 -2
View File
@@ -13,7 +13,7 @@
#include <beast/http/parser_v1.hpp>
#include <beast/http/read.hpp>
#include <beast/http/write.hpp>
#include <beast/test/string_stream.hpp>
#include <beast/test/string_istream.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/lexical_cast.hpp>
@@ -33,7 +33,7 @@ public:
"Content-Length: 3\r\n"
"\r\n"
"xyz";
test::string_stream ss(ios_, s);
test::string_istream ss(ios_, s);
parser_v1<false, streambuf_body, fields> p;
streambuf sb;
parse(ss, sb, p);
+14 -75
View File
@@ -17,6 +17,7 @@
#include <beast/core/streambuf.hpp>
#include <beast/core/to_string.hpp>
#include <beast/test/fail_stream.hpp>
#include <beast/test/string_ostream.hpp>
#include <beast/test/yield_to.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/asio/error.hpp>
@@ -31,68 +32,6 @@ class write_test
, public test::enable_yield_to
{
public:
class string_write_stream
{
boost::asio::io_service& ios_;
public:
std::string str;
explicit
string_write_stream(boost::asio::io_service& ios)
: ios_(ios)
{
}
boost::asio::io_service&
get_io_service()
{
return ios_;
}
template<class ConstBufferSequence>
std::size_t
write_some(ConstBufferSequence const& buffers)
{
error_code ec;
auto const n = write_some(buffers, ec);
if(ec)
throw system_error{ec};
return n;
}
template<class ConstBufferSequence>
std::size_t
write_some(
ConstBufferSequence const& buffers, error_code&)
{
auto const n = buffer_size(buffers);
using boost::asio::buffer_size;
using boost::asio::buffer_cast;
str.reserve(str.size() + n);
for(auto const& buffer : buffers)
str.append(buffer_cast<char const*>(buffer),
buffer_size(buffer));
return n;
}
template<class ConstBufferSequence, class WriteHandler>
typename async_completion<
WriteHandler, void(error_code)>::result_type
async_write_some(ConstBufferSequence const& buffers,
WriteHandler&& handler)
{
error_code ec;
auto const bytes_transferred = write_some(buffers, ec);
async_completion<
WriteHandler, void(error_code, std::size_t)
> completion(handler);
get_io_service().post(
bind_handler(completion.handler, ec, bytes_transferred));
return completion.result.get();
}
};
struct unsized_body
{
using value_type = std::string;
@@ -225,7 +164,7 @@ public:
std::string
str(message<isRequest, Body, Fields> const& m)
{
string_write_stream ss(ios_);
test::string_ostream ss(ios_);
write(ss, m);
return ss.str;
}
@@ -240,7 +179,7 @@ public:
m.url = "/";
m.fields.insert("User-Agent", "test");
error_code ec;
string_write_stream ss{ios_};
test::string_ostream ss{ios_};
async_write(ss, m, do_yield[ec]);
if(BEAST_EXPECTS(! ec, ec.message()))
BEAST_EXPECT(ss.str ==
@@ -256,7 +195,7 @@ public:
m.fields.insert("Server", "test");
m.fields.insert("Content-Length", "5");
error_code ec;
string_write_stream ss{ios_};
test::string_ostream ss{ios_};
async_write(ss, m, do_yield[ec]);
if(BEAST_EXPECTS(! ec, ec.message()))
BEAST_EXPECT(ss.str ==
@@ -279,7 +218,7 @@ public:
m.fields.insert("Content-Length", "5");
m.body = "*****";
error_code ec;
string_write_stream ss{ios_};
test::string_ostream ss{ios_};
async_write(ss, m, do_yield[ec]);
if(BEAST_EXPECTS(! ec, ec.message()))
BEAST_EXPECT(ss.str ==
@@ -298,7 +237,7 @@ public:
m.fields.insert("Transfer-Encoding", "chunked");
m.body = "*****";
error_code ec;
string_write_stream ss(ios_);
test::string_ostream ss(ios_);
async_write(ss, m, do_yield[ec]);
if(BEAST_EXPECTS(! ec, ec.message()))
BEAST_EXPECT(ss.str ==
@@ -322,7 +261,7 @@ public:
{
test::fail_counter fc(n);
test::fail_stream<
string_write_stream> fs(fc, ios_);
test::string_ostream> fs(fc, ios_);
message<true, fail_body, fields> m(
std::piecewise_construct,
std::forward_as_tuple(fc, ios_));
@@ -355,7 +294,7 @@ public:
{
test::fail_counter fc(n);
test::fail_stream<
string_write_stream> fs(fc, ios_);
test::string_ostream> fs(fc, ios_);
message<true, fail_body, fields> m(
std::piecewise_construct,
std::forward_as_tuple(fc, ios_));
@@ -390,7 +329,7 @@ public:
{
test::fail_counter fc(n);
test::fail_stream<
string_write_stream> fs(fc, ios_);
test::string_ostream> fs(fc, ios_);
message<true, fail_body, fields> m(
std::piecewise_construct,
std::forward_as_tuple(fc, ios_));
@@ -425,7 +364,7 @@ public:
{
test::fail_counter fc(n);
test::fail_stream<
string_write_stream> fs(fc, ios_);
test::string_ostream> fs(fc, ios_);
message<true, fail_body, fields> m(
std::piecewise_construct,
std::forward_as_tuple(fc, ios_));
@@ -455,7 +394,7 @@ public:
{
test::fail_counter fc(n);
test::fail_stream<
string_write_stream> fs(fc, ios_);
test::string_ostream> fs(fc, ios_);
message<true, fail_body, fields> m(
std::piecewise_construct,
std::forward_as_tuple(fc, ios_));
@@ -547,7 +486,7 @@ public:
m.fields.insert("User-Agent", "test");
m.body = "*";
prepare(m);
string_write_stream ss(ios_);
test::string_ostream ss(ios_);
error_code ec;
write(ss, m, ec);
BEAST_EXPECT(ec == boost::asio::error::eof);
@@ -584,7 +523,7 @@ public:
m.fields.insert("User-Agent", "test");
m.body = "*";
prepare(m, connection::close);
string_write_stream ss(ios_);
test::string_ostream ss(ios_);
error_code ec;
write(ss, m, ec);
BEAST_EXPECT(ec == boost::asio::error::eof);
@@ -621,7 +560,7 @@ public:
m.fields.insert("User-Agent", "test");
m.body = "*";
prepare(m);
string_write_stream ss(ios_);
test::string_ostream ss(ios_);
error_code ec;
write(ss, m, ec);
BEAST_EXPECT(ss.str ==
+6 -6
View File
@@ -14,7 +14,7 @@
#include <beast/core/streambuf.hpp>
#include <beast/core/to_string.hpp>
#include <beast/test/fail_stream.hpp>
#include <beast/test/string_stream.hpp>
#include <beast/test/string_istream.hpp>
#include <beast/test/yield_to.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/asio.hpp>
@@ -172,7 +172,7 @@ public:
req.fields.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
req.fields.insert("Sec-WebSocket-Version", "13");
stream<test::fail_stream<
test::string_stream>> ws(n, ios_, "");
test::string_istream>> ws(n, ios_, "");
try
{
ws.accept(req);
@@ -186,7 +186,7 @@ public:
}
{
// valid
stream<test::string_stream> ws(ios_,
stream<test::string_istream> ws(ios_,
"GET / HTTP/1.1\r\n"
"Host: localhost:80\r\n"
"Upgrade: WebSocket\r\n"
@@ -207,7 +207,7 @@ public:
}
{
// invalid
stream<test::string_stream> ws(ios_,
stream<test::string_istream> ws(ios_,
"GET / HTTP/1.0\r\n"
"\r\n"
);
@@ -230,7 +230,7 @@ public:
{
for(std::size_t i = 0; i < s.size(); ++i)
{
stream<test::string_stream> ws(ios_,
stream<test::string_istream> ws(ios_,
s.substr(i, s.size() - i));
ws.set_option(keep_alive{true});
try
@@ -339,7 +339,7 @@ public:
auto const check =
[&](std::string const& s)
{
stream<test::string_stream> ws(ios_, s);
stream<test::string_istream> ws(ios_, s);
try
{
ws.handshake("localhost:80", "/");