Files
boost_beast/test/beast/core/detail_buffer.cpp
T

84 lines
2.1 KiB
C++
Raw Normal View History

2018-10-09 19:39:42 -07:00
//
// Copyright (c) 2016-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)
//
// Official repository: https://github.com/boostorg/beast
//
// Test that header file is self-contained.
//#include <boost/beast/core/buffer.hpp>
#include <boost/beast/core/detail/buffer.hpp>
#include <boost/beast/core/flat_buffer.hpp>
2018-11-11 14:07:55 -08:00
#include <boost/beast/_experimental/unit_test/suite.hpp>
2018-10-09 19:39:42 -07:00
#include <string>
#include <boost/asio/error.hpp>
namespace boost {
namespace beast {
2018-12-14 07:27:46 -08:00
namespace detail {
2018-10-09 19:39:42 -07:00
// VFALCO No idea why boost::system::errc::message_size fails
2018-11-30 14:58:38 -08:00
// to compile, so we use net::error::eof instead.
2018-10-09 19:39:42 -07:00
//
2018-12-14 07:27:46 -08:00
class detail_buffer_test : public beast::unit_test::suite
2018-10-09 19:39:42 -07:00
{
public:
template<class DynamicBuffer>
void
testPrepare()
{
#ifndef BOOST_NO_EXCEPTIONS
error_code ec;
DynamicBuffer b(32);
2018-12-14 07:27:46 -08:00
dynamic_buffer_prepare(b, 20, ec,
2018-11-30 14:58:38 -08:00
net::error::eof);
2018-10-09 19:39:42 -07:00
BEAST_EXPECTS(! ec, ec.message());
b.commit(20);
auto const result =
2018-12-14 07:27:46 -08:00
dynamic_buffer_prepare(b, 20, ec,
2018-11-30 14:58:38 -08:00
net::error::eof);
2018-10-09 19:39:42 -07:00
BEAST_EXPECT(result == boost::none);
BEAST_EXPECTS(
2018-11-30 14:58:38 -08:00
ec == net::error::eof, ec.message());
2018-10-09 19:39:42 -07:00
#else
fail("exceptions disabled", __FILE__, __LINE__);
#endif
}
template<class DynamicBuffer>
void
testPrepareNoexcept()
{
error_code ec;
DynamicBuffer b(32);
2018-12-14 07:27:46 -08:00
dynamic_buffer_prepare_noexcept(b, 20, ec,
2018-11-30 14:58:38 -08:00
net::error::eof);
2018-10-09 19:39:42 -07:00
BEAST_EXPECTS(! ec, ec.message());
b.commit(20);
auto const result =
detail::dynamic_buffer_prepare_noexcept(b, 20, ec,
2018-11-30 14:58:38 -08:00
net::error::eof);
2018-10-09 19:39:42 -07:00
BEAST_EXPECT(result == boost::none);
BEAST_EXPECTS(
2018-11-30 14:58:38 -08:00
ec == net::error::eof, ec.message());
2018-10-09 19:39:42 -07:00
}
void
run() override
{
testPrepare<flat_buffer>();
testPrepareNoexcept<flat_buffer>();
pass();
}
};
2018-12-14 07:27:46 -08:00
BEAST_DEFINE_TESTSUITE(beast,core,detail_buffer);
2018-10-09 19:39:42 -07:00
2018-12-14 07:27:46 -08:00
} // detail
2018-10-09 19:39:42 -07:00
} // beast
} // boost