]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/test/beast/_experimental/icy_stream.cpp
2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
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)
7 // Official repository: https://github.com/boostorg/beast
10 // Test that header file is self-contained.
11 #include <boost/beast/_experimental/http/icy_stream.hpp>
13 #include <boost/beast/core/buffers_adaptor.hpp>
14 #include <boost/beast/core/buffers_to_string.hpp>
15 #include <boost/beast/core/read_size.hpp>
16 #include <boost/beast/_experimental/test/stream.hpp>
17 #include <boost/beast/_experimental/unit_test/suite.hpp>
27 : public unit_test::suite
31 doMatrix(string_view in
, string_view out
)
33 using net::mutable_buffer
;
35 auto len
= out
.size() + 8;
36 std::unique_ptr
<char[]> p(new char[len
]);
37 for(std::size_t i
= 1; i
< len
; ++i
)
39 std::array
<mutable_buffer
, 2> mbs
{{
40 mutable_buffer(p
.get(), i
),
41 mutable_buffer(p
.get() + i
, len
- i
)}};
42 for(std::size_t j
= 1; j
< in
.size(); ++j
)
44 for(std::size_t k
= 1; k
< len
; ++k
)
48 buffers_adaptor
<decltype(mbs
)> ba(mbs
);
49 std::memset(p
.get(), 0, len
);
51 icy_stream
<test::stream
> is
{ioc
};
52 is
.next_layer().read_size(j
);
53 is
.next_layer().append(in
);
54 connect(is
.next_layer()).close();
59 ba
.commit(is
.read_some(
60 ba
.prepare(read_size(ba
, k
)), ec
));
65 ec
== net::error::eof
, ec
.message()))
67 auto const s
= buffers_to_string(ba
.data());
68 BEAST_EXPECTS(s
== out
, s
);
72 buffers_adaptor
<decltype(mbs
)> ba(mbs
);
73 std::memset(p
.get(), 0, len
);
75 icy_stream
<test::stream
> is
{ioc
};
76 is
.next_layer().read_size(j
);
77 is
.next_layer().append(in
);
78 connect(is
.next_layer()).close();
84 ba
.prepare(read_size(ba
, k
)),
85 [&ec
, &ba
](error_code ec_
, std::size_t n
)
96 ec
== net::error::eof
, ec
.message()))
98 auto const s
= buffers_to_string(ba
.data());
99 if(! BEAST_EXPECTS(s
== out
, s
))
112 doMatrix("HTTP/1.1 200 OK\r\n", "HTTP/1.1 200 OK\r\n");
113 doMatrix("ICY 200 OK\r\n", "HTTP/1.1 200 OK\r\n");
123 BEAST_DEFINE_TESTSUITE(beast
,http
,icy_stream
);