| 1 | // |
| 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) |
| 3 | // |
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | // |
| 7 | // Official repository: https://github.com/boostorg/beast |
| 8 | // |
| 9 | |
| 10 | // Test that header file is self-contained. |
| 11 | //#include <boost/beast/core/buffer.hpp> |
| 12 | |
| 13 | #include <boost/beast/core/detail/buffer.hpp> |
| 14 | #include <boost/beast/core/flat_buffer.hpp> |
| 15 | #include <boost/beast/_experimental/unit_test/suite.hpp> |
| 16 | #include <string> |
| 17 | |
| 18 | #include <boost/asio/error.hpp> |
| 19 | |
| 20 | namespace boost { |
| 21 | namespace beast { |
| 22 | namespace detail { |
| 23 | |
| 24 | // VFALCO No idea why boost::system::errc::message_size fails |
| 25 | // to compile, so we use net::error::eof instead. |
| 26 | // |
| 27 | class buffer_test : public beast::unit_test::suite |
| 28 | { |
| 29 | public: |
| 30 | template<class DynamicBuffer> |
| 31 | void |
| 32 | testPrepare() |
| 33 | { |
| 34 | #ifndef BOOST_NO_EXCEPTIONS |
| 35 | error_code ec; |
| 36 | DynamicBuffer b(32); |
| 37 | dynamic_buffer_prepare(b, 20, ec, |
| 38 | net::error::eof); |
| 39 | BEAST_EXPECTS(! ec, ec.message()); |
| 40 | b.commit(20); |
| 41 | auto const result = |
| 42 | dynamic_buffer_prepare(b, 20, ec, |
| 43 | net::error::eof); |
| 44 | BEAST_EXPECT(result == boost::none); |
| 45 | BEAST_EXPECTS( |
| 46 | ec == net::error::eof, ec.message()); |
| 47 | #else |
| 48 | fail("exceptions disabled" , __FILE__, __LINE__); |
| 49 | #endif |
| 50 | } |
| 51 | |
| 52 | template<class DynamicBuffer> |
| 53 | void |
| 54 | testPrepareNoexcept() |
| 55 | { |
| 56 | error_code ec; |
| 57 | DynamicBuffer b(32); |
| 58 | dynamic_buffer_prepare_noexcept(b, 20, ec, |
| 59 | net::error::eof); |
| 60 | BEAST_EXPECTS(! ec, ec.message()); |
| 61 | b.commit(20); |
| 62 | auto const result = |
| 63 | detail::dynamic_buffer_prepare_noexcept(b, 20, ec, |
| 64 | net::error::eof); |
| 65 | BEAST_EXPECT(result == boost::none); |
| 66 | BEAST_EXPECTS( |
| 67 | ec == net::error::eof, ec.message()); |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | run() override |
| 72 | { |
| 73 | testPrepare<flat_buffer>(); |
| 74 | testPrepareNoexcept<flat_buffer>(); |
| 75 | pass(); |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | BEAST_DEFINE_TESTSUITE(beast,core,buffer); |
| 80 | |
| 81 | } // detail |
| 82 | } // beast |
| 83 | } // boost |
| 84 | |