// Copyright (c) 2022 Klemens D. Morgenstern // // 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) #include #include #include #include #include #include #include #include #include #include #include #include #include #include "test_buffer.hpp" namespace boost { namespace beast { template struct buffer_ref; template struct buffer_ref>; template struct buffer_ref; template struct buffer_ref>; class buffer_ref_test : public beast::unit_test::suite { template void testBuffer() { net::io_context ioc; net::readable_pipe rp{ioc}; net::writable_pipe wp{ioc}; net::connect_pipe(rp, wp); const char msg[] = "Hello, world!\n"; net::async_write(wp, net::buffer(msg), asio::detached); Buffer buf; net::async_read_until(rp, ref(buf), '\n', asio::detached); ioc.run(); // writable, not commited yet! std::string cmp; cmp.resize(sizeof(msg) -1); const auto n = net::buffer_copy(net::buffer(cmp), buf.data()); BEAST_EXPECT(n >= std::strlen(msg)); cmp.resize(13); BEAST_EXPECT(cmp == "Hello, world!"); buf = Buffer(); test_dynamic_buffer_ref(ref(buf)); } void run() override { testBuffer(); testBuffer>(); testBuffer(); testBuffer>(); { std::string buf; test_dynamic_buffer_ref(asio::dynamic_buffer(buf)); } { std::vector buf; test_dynamic_buffer_ref(asio::dynamic_buffer(buf)); } } }; BEAST_DEFINE_TESTSUITE(beast,core, buffer_ref); } }