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/core/static_buffer.hpp>
13 #include "test_buffer.hpp"
15 #include <boost/beast/core/buffer_traits.hpp>
16 #include <boost/beast/core/ostream.hpp>
17 #include <boost/beast/core/read_size.hpp>
18 #include <boost/beast/core/string.hpp>
19 #include <boost/beast/_experimental/unit_test/suite.hpp>
20 #include <boost/asio/buffers_iterator.hpp>
28 class static_buffer_test
: public beast::unit_test::suite
32 is_mutable_dynamic_buffer
<
33 static_buffer
<13>>::value
);
36 is_mutable_dynamic_buffer
<
37 static_buffer_base
>::value
);
42 test_dynamic_buffer(static_buffer
<13>{});
48 string_view
const s
= "Hello, world!";
53 static_buffer_base b
{buf
, sizeof(buf
)};
55 BEAST_EXPECT(buffers_to_string(b
.data()) == s
);
57 BEAST_EXPECT(b
.size() == 0);
58 BEAST_EXPECT(buffer_bytes(b
.data()) == 0);
64 BEAST_EXPECT(b1
.size() == 0);
65 BEAST_EXPECT(b1
.max_size() == 64);
66 BEAST_EXPECT(b1
.capacity() == 64);
68 BEAST_EXPECT(buffers_to_string(b1
.data()) == s
);
70 static_buffer
<64> b2
{b1
};
71 BEAST_EXPECT(buffers_to_string(b2
.data()) == s
);
73 BEAST_EXPECT(buffers_to_string(b2
.data()) == s
.substr(7));
78 BEAST_EXPECT(buffers_to_string(b2
.data()) == s
);
80 BEAST_EXPECT(buffers_to_string(b2
.data()) == s
.substr(7));
87 ostream(b
) << "12345";
89 ostream(b
) << "67890123";
90 BEAST_EXPECT(buffers_to_string(b
.data()) == "4567890123");
94 fail("", __FILE__
, __LINE__
);
96 catch(std::length_error
const&)
105 BEAST_EXPECT(read_size(b
, 512) == 10);
108 BEAST_EXPECT(read_size(b
, 512) == 6);
110 BEAST_EXPECT(read_size(b
, 512) == 8);
113 BEAST_EXPECT(read_size(b
, 512) == 0);
119 [&](static_buffer_base
& base
)
121 BEAST_EXPECT(base
.max_size() == b
.capacity());
125 [&](static_buffer_base
const& base
)
127 BEAST_EXPECT(base
.max_size() == b
.capacity());
132 // This exercises the wrap-around cases
133 // for the circular buffer representation
137 auto const mb
= b
.prepare(5);
138 BEAST_EXPECT(buffers_length(mb
) == 1);
141 BEAST_EXPECT(buffers_length(b
.data()) == 1);
142 BEAST_EXPECT(buffers_length(b
.cdata()) == 1);
145 auto const mb
= b
.prepare(3);
146 BEAST_EXPECT(buffers_length(mb
) == 2);
147 auto it1
= mb
.begin();
148 auto it2
= std::next(it1
);
150 net::const_buffer(*it1
).data() >
151 net::const_buffer(*it2
).data());
155 auto const mb
= b
.data();
156 auto it1
= mb
.begin();
157 auto it2
= std::next(it1
);
159 net::const_buffer(*it1
).data() >
160 net::const_buffer(*it2
).data());
163 auto const cb
= b
.cdata();
164 auto it1
= cb
.begin();
165 auto it2
= std::next(it1
);
167 net::const_buffer(*it1
).data() >
168 net::const_buffer(*it2
).data());
181 BEAST_DEFINE_TESTSUITE(beast
,core
,static_buffer
);