forked from boostorg/beast
Add span_body
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
// Test that header file is self-contained.
|
||||
#include <beast/core/span.hpp>
|
||||
|
||||
#include <beast/core/string.hpp>
|
||||
#include <beast/unit_test/suite.hpp>
|
||||
|
||||
namespace beast {
|
||||
@@ -15,6 +16,10 @@ namespace beast {
|
||||
class span_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
BOOST_STATIC_ASSERT(
|
||||
detail::is_contiguous_container<
|
||||
string_view, char const>::value);
|
||||
|
||||
struct base {};
|
||||
struct derived : base {};
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ add_executable (http-tests
|
||||
read.cpp
|
||||
rfc7230.cpp
|
||||
serializer.cpp
|
||||
span_body.cpp
|
||||
status.cpp
|
||||
string_body.cpp
|
||||
string_view_body.cpp
|
||||
|
||||
@@ -21,6 +21,7 @@ unit-test http-tests :
|
||||
read.cpp
|
||||
rfc7230.cpp
|
||||
serializer.cpp
|
||||
span_body.cpp
|
||||
status.cpp
|
||||
string_body.cpp
|
||||
string_view_body.cpp
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include <beast/http/span_body.hpp>
|
||||
|
||||
#include <beast/http/message.hpp>
|
||||
#include <beast/unit_test/suite.hpp>
|
||||
|
||||
namespace beast {
|
||||
namespace http {
|
||||
|
||||
struct span_body_test
|
||||
: public beast::unit_test::suite
|
||||
{
|
||||
void
|
||||
testSpanBody()
|
||||
{
|
||||
{
|
||||
using B = span_body<char const>;
|
||||
request<B> req;
|
||||
|
||||
BEAST_EXPECT(req.body.size() == 0);
|
||||
BEAST_EXPECT(B::size(req.body) == 0);
|
||||
|
||||
req.body = B::value_type("xyz", 3);
|
||||
BEAST_EXPECT(req.body.size() == 3);
|
||||
BEAST_EXPECT(B::size(req.body) == 3);
|
||||
|
||||
B::reader r{req};
|
||||
error_code ec;
|
||||
r.init(ec);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
auto const buf = r.get(ec);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
if(! BEAST_EXPECT(buf != boost::none))
|
||||
return;
|
||||
BEAST_EXPECT(boost::asio::buffer_size(buf->first) == 3);
|
||||
BEAST_EXPECT(! buf->second);
|
||||
}
|
||||
{
|
||||
char buf[5];
|
||||
using B = span_body<char>;
|
||||
request<B> req;
|
||||
req.body = span<char>{buf, sizeof(buf)};
|
||||
B::writer w{req};
|
||||
error_code ec;
|
||||
w.init(boost::none, ec);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
w.put(boost::asio::const_buffers_1{
|
||||
"123", 3}, ec);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
BEAST_EXPECT(buf[0] == '1');
|
||||
BEAST_EXPECT(buf[1] == '2');
|
||||
BEAST_EXPECT(buf[2] == '3');
|
||||
w.put(boost::asio::const_buffers_1{
|
||||
"456", 3}, ec);
|
||||
BEAST_EXPECTS(ec == error::buffer_overflow, ec.message());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testSpanBody();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(span_body,http,beast);
|
||||
|
||||
} // http
|
||||
} // beast
|
||||
Reference in New Issue
Block a user