mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Fixes, fail testing:
Core: * Test buffer_cat iterator move members HTTP: * Fixed yield / resume in writer * Fixed message serialization with chunked encoding * Test yield / resume in writer * Test all conditional branches during message serialization * Test chunked encoding * Increase coverage on parse_error * Add parse_error::general WebSocket: * Add error::general * Increase coverage in error
This commit is contained in:
@@ -9,15 +9,22 @@
|
||||
#include <beast/core/streambuf_readstream.hpp>
|
||||
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/test/fail_stream.hpp>
|
||||
#include <beast/test/string_stream.hpp>
|
||||
#include <beast/test/yield_to.hpp>
|
||||
#include <beast/unit_test/suite.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
namespace beast {
|
||||
|
||||
class streambuf_readstream_test : public beast::unit_test::suite
|
||||
class streambuf_readstream_test
|
||||
: public unit_test::suite
|
||||
, public test::enable_yield_to
|
||||
{
|
||||
using self = streambuf_readstream_test;
|
||||
|
||||
public:
|
||||
void testSpecial()
|
||||
void testSpecialMembers()
|
||||
{
|
||||
using socket_type = boost::asio::ip::tcp::socket;
|
||||
boost::asio::io_service ios;
|
||||
@@ -33,12 +40,100 @@ public:
|
||||
streambuf_readstream<socket_type&, streambuf> srs(sock);
|
||||
streambuf_readstream<socket_type&, streambuf> srs2(std::move(srs));
|
||||
}
|
||||
pass();
|
||||
}
|
||||
|
||||
void testRead(yield_context do_yield)
|
||||
{
|
||||
using boost::asio::buffer;
|
||||
using boost::asio::buffer_copy;
|
||||
static std::size_t constexpr limit = 100;
|
||||
std::size_t n;
|
||||
std::string s;
|
||||
s.resize(13);
|
||||
|
||||
for(n = 0; n < limit; ++n)
|
||||
{
|
||||
test::fail_stream<
|
||||
test::string_stream> fs(n, ios_, ", world!");
|
||||
streambuf_readstream<
|
||||
decltype(fs)&, streambuf> srs(fs);
|
||||
srs.buffer().commit(buffer_copy(
|
||||
srs.buffer().prepare(5), buffer("Hello", 5)));
|
||||
boost::system::error_code ec;
|
||||
boost::asio::read(srs, buffer(&s[0], s.size()), ec);
|
||||
if(! ec)
|
||||
{
|
||||
expect(s == "Hello, world!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
expect(n < limit);
|
||||
|
||||
for(n = 0; n < limit; ++n)
|
||||
{
|
||||
test::fail_stream<
|
||||
test::string_stream> fs(n, ios_, ", world!");
|
||||
streambuf_readstream<
|
||||
decltype(fs)&, streambuf> srs(fs);
|
||||
srs.capacity(3);
|
||||
srs.buffer().commit(buffer_copy(
|
||||
srs.buffer().prepare(5), buffer("Hello", 5)));
|
||||
boost::system::error_code ec;
|
||||
boost::asio::read(srs, buffer(&s[0], s.size()), ec);
|
||||
if(! ec)
|
||||
{
|
||||
expect(s == "Hello, world!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
expect(n < limit);
|
||||
|
||||
for(n = 0; n < limit; ++n)
|
||||
{
|
||||
test::fail_stream<
|
||||
test::string_stream> fs(n, ios_, ", world!");
|
||||
streambuf_readstream<
|
||||
decltype(fs)&, streambuf> srs(fs);
|
||||
srs.buffer().commit(buffer_copy(
|
||||
srs.buffer().prepare(5), buffer("Hello", 5)));
|
||||
boost::system::error_code ec;
|
||||
boost::asio::async_read(
|
||||
srs, buffer(&s[0], s.size()), do_yield[ec]);
|
||||
if(! ec)
|
||||
{
|
||||
expect(s == "Hello, world!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
expect(n < limit);
|
||||
|
||||
for(n = 0; n < limit; ++n)
|
||||
{
|
||||
test::fail_stream<
|
||||
test::string_stream> fs(n, ios_, ", world!");
|
||||
streambuf_readstream<
|
||||
decltype(fs)&, streambuf> srs(fs);
|
||||
srs.capacity(3);
|
||||
srs.buffer().commit(buffer_copy(
|
||||
srs.buffer().prepare(5), buffer("Hello", 5)));
|
||||
boost::system::error_code ec;
|
||||
boost::asio::async_read(
|
||||
srs, buffer(&s[0], s.size()), do_yield[ec]);
|
||||
if(! ec)
|
||||
{
|
||||
expect(s == "Hello, world!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
expect(n < limit);
|
||||
}
|
||||
|
||||
void run() override
|
||||
{
|
||||
testSpecial();
|
||||
testSpecialMembers();
|
||||
|
||||
yield_to(std::bind(&self::testRead,
|
||||
this, std::placeholders::_1));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user