2017-02-05 18:02:14 -05:00
|
|
|
//
|
2017-07-24 09:42:36 -07:00
|
|
|
// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2017-02-05 18:02:14 -05:00
|
|
|
//
|
|
|
|
// 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)
|
|
|
|
//
|
2017-07-20 13:40:34 -07:00
|
|
|
// Official repository: https://github.com/boostorg/beast
|
|
|
|
//
|
2017-02-05 18:02:14 -05:00
|
|
|
|
|
|
|
// Test that header file is self-contained.
|
2017-07-20 13:40:34 -07:00
|
|
|
#include <boost/beast/core/flat_buffer.hpp>
|
2017-02-05 18:02:14 -05:00
|
|
|
|
|
|
|
#include "buffer_test.hpp"
|
2017-06-09 22:36:57 -07:00
|
|
|
|
2017-07-20 13:40:34 -07:00
|
|
|
#include <boost/beast/core/ostream.hpp>
|
|
|
|
#include <boost/beast/core/read_size.hpp>
|
|
|
|
#include <boost/beast/core/string.hpp>
|
|
|
|
#include <boost/beast/test/test_allocator.hpp>
|
2018-11-11 14:07:55 -08:00
|
|
|
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
2018-11-29 12:57:29 -08:00
|
|
|
#include <boost/asio/buffers_iterator.hpp>
|
2017-04-30 14:36:16 -07:00
|
|
|
#include <algorithm>
|
2018-11-29 12:57:29 -08:00
|
|
|
#include <cctype>
|
2017-02-05 18:02:14 -05:00
|
|
|
|
2017-07-20 13:40:34 -07:00
|
|
|
namespace boost {
|
2017-02-05 18:02:14 -05:00
|
|
|
namespace beast {
|
|
|
|
|
2017-05-04 16:00:20 -07:00
|
|
|
class flat_buffer_test : public beast::unit_test::suite
|
2017-02-05 18:02:14 -05:00
|
|
|
{
|
|
|
|
public:
|
2018-11-29 12:57:29 -08:00
|
|
|
BOOST_STATIC_ASSERT(
|
|
|
|
boost::asio::is_dynamic_buffer<
|
|
|
|
flat_buffer>::value);
|
|
|
|
BOOST_STATIC_ASSERT(
|
|
|
|
boost::asio::is_const_buffer_sequence<
|
|
|
|
flat_buffer::const_buffers_type>::value);
|
|
|
|
BOOST_STATIC_ASSERT(
|
|
|
|
boost::asio::is_mutable_buffer_sequence<
|
|
|
|
flat_buffer::mutable_data_type>::value);
|
|
|
|
BOOST_STATIC_ASSERT(
|
|
|
|
boost::asio::is_mutable_buffer_sequence<
|
|
|
|
flat_buffer::mutable_buffers_type>::value);
|
|
|
|
BOOST_STATIC_ASSERT(std::is_convertible<
|
|
|
|
flat_buffer::mutable_data_type,
|
|
|
|
flat_buffer::const_buffers_type>::value);
|
|
|
|
|
|
|
|
template<class DynamicBuffer>
|
|
|
|
void
|
|
|
|
testMutableData()
|
|
|
|
{
|
|
|
|
DynamicBuffer b;
|
|
|
|
DynamicBuffer const& cb = b;
|
|
|
|
ostream(b) << "Hello";
|
|
|
|
BOOST_STATIC_ASSERT(
|
|
|
|
boost::asio::is_const_buffer_sequence<
|
|
|
|
decltype(cb.data())>::value &&
|
|
|
|
! boost::asio::is_mutable_buffer_sequence<
|
|
|
|
decltype(cb.data())>::value);
|
|
|
|
BOOST_STATIC_ASSERT(
|
|
|
|
boost::asio::is_const_buffer_sequence<
|
|
|
|
decltype(cb.cdata())>::value &&
|
|
|
|
! boost::asio::is_mutable_buffer_sequence<
|
|
|
|
decltype(cb.cdata())>::value);
|
|
|
|
BOOST_STATIC_ASSERT(
|
|
|
|
boost::asio::is_mutable_buffer_sequence<
|
|
|
|
decltype(b.data())>::value);
|
|
|
|
std::for_each(
|
|
|
|
boost::asio::buffers_iterator<decltype(b.data())>::begin(b.data()),
|
|
|
|
boost::asio::buffers_iterator<decltype(b.data())>::end(b.data()),
|
|
|
|
[](char& c)
|
|
|
|
{
|
|
|
|
c = static_cast<char>(std::toupper(c));
|
|
|
|
});
|
|
|
|
BEAST_EXPECT(buffers_to_string(b.data()) == "HELLO");
|
|
|
|
BEAST_EXPECT(buffers_to_string(b.cdata()) == "HELLO");
|
|
|
|
}
|
|
|
|
|
2017-06-09 22:36:57 -07:00
|
|
|
void
|
|
|
|
testBuffer()
|
2017-05-04 05:01:50 -07:00
|
|
|
{
|
2017-06-09 22:36:57 -07:00
|
|
|
using namespace test;
|
2017-05-04 05:01:50 -07:00
|
|
|
|
2017-06-09 22:36:57 -07:00
|
|
|
using a_t = test::test_allocator<char,
|
|
|
|
true, true, true, true, true>;
|
2017-02-05 18:02:14 -05:00
|
|
|
|
2017-06-09 22:36:57 -07:00
|
|
|
// Equal == false
|
|
|
|
using a_neq_t = test::test_allocator<char,
|
|
|
|
false, true, true, true, true>;
|
|
|
|
|
|
|
|
// construction
|
2017-04-30 14:36:16 -07:00
|
|
|
{
|
2017-06-09 22:36:57 -07:00
|
|
|
{
|
|
|
|
flat_buffer b;
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b.capacity() == 0);
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
flat_buffer b{500};
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b.capacity() == 0);
|
|
|
|
BEAST_EXPECT(b.max_size() == 500);
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
a_neq_t a1;
|
|
|
|
basic_flat_buffer<a_neq_t> b{a1};
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b.get_allocator() == a1);
|
2017-06-09 22:36:57 -07:00
|
|
|
a_neq_t a2;
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b.get_allocator() != a2);
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
a_neq_t a;
|
|
|
|
basic_flat_buffer<a_neq_t> b{500, a};
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b.capacity() == 0);
|
|
|
|
BEAST_EXPECT(b.max_size() == 500);
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
2017-04-30 14:36:16 -07:00
|
|
|
}
|
2017-06-09 22:36:57 -07:00
|
|
|
|
|
|
|
// move construction
|
2017-04-30 14:36:16 -07:00
|
|
|
{
|
2017-06-09 22:36:57 -07:00
|
|
|
{
|
|
|
|
basic_flat_buffer<a_t> b1{30};
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.get_allocator()->nmove == 0);
|
2017-06-09 22:36:57 -07:00
|
|
|
ostream(b1) << "Hello";
|
|
|
|
basic_flat_buffer<a_t> b2{std::move(b1)};
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b2.get_allocator()->nmove == 1);
|
|
|
|
BEAST_EXPECT(b1.size() == 0);
|
|
|
|
BEAST_EXPECT(b1.capacity() == 0);
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.max_size() == b2.max_size());
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
basic_flat_buffer<a_t> b1{30};
|
|
|
|
ostream(b1) << "Hello";
|
|
|
|
a_t a;
|
|
|
|
basic_flat_buffer<a_t> b2{std::move(b1), a};
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.size() == 0);
|
|
|
|
BEAST_EXPECT(b1.capacity() == 0);
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.max_size() == b2.max_size());
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
basic_flat_buffer<a_neq_t> b1{30};
|
|
|
|
ostream(b1) << "Hello";
|
|
|
|
a_neq_t a;
|
|
|
|
basic_flat_buffer<a_neq_t> b2{std::move(b1), a};
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.size() == 0);
|
|
|
|
BEAST_EXPECT(b1.capacity() == 0);
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.max_size() == b2.max_size());
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
2017-04-30 14:36:16 -07:00
|
|
|
}
|
2017-06-09 22:36:57 -07:00
|
|
|
|
|
|
|
// copy construction
|
2017-04-30 14:36:16 -07:00
|
|
|
{
|
2017-06-09 22:36:57 -07:00
|
|
|
basic_flat_buffer<a_t> b1;
|
|
|
|
ostream(b1) << "Hello";
|
|
|
|
basic_flat_buffer<a_t> b2(b1);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.get_allocator() == b2.get_allocator());
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-04-30 14:36:16 -07:00
|
|
|
}
|
|
|
|
{
|
2017-06-09 22:36:57 -07:00
|
|
|
basic_flat_buffer<a_neq_t> b1;
|
|
|
|
ostream(b1) << "Hello";
|
|
|
|
a_neq_t a;
|
|
|
|
basic_flat_buffer<a_neq_t> b2(b1, a);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.get_allocator() != b2.get_allocator());
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-04-30 14:36:16 -07:00
|
|
|
}
|
|
|
|
{
|
2017-06-09 22:36:57 -07:00
|
|
|
basic_flat_buffer<a_t> b1;
|
|
|
|
ostream(b1) << "Hello";
|
|
|
|
basic_flat_buffer<a_neq_t> b2(b1);
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-04-30 14:36:16 -07:00
|
|
|
}
|
|
|
|
{
|
2017-06-09 22:36:57 -07:00
|
|
|
basic_flat_buffer<a_neq_t> b1;
|
|
|
|
ostream(b1) << "Hello";
|
|
|
|
a_t a;
|
|
|
|
basic_flat_buffer<a_t> b2(b1, a);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b2.get_allocator() == a);
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-04-30 14:36:16 -07:00
|
|
|
}
|
2017-06-09 22:36:57 -07:00
|
|
|
|
|
|
|
// move assignment
|
2017-04-30 14:36:16 -07:00
|
|
|
{
|
2017-06-09 22:36:57 -07:00
|
|
|
{
|
|
|
|
flat_buffer b1;
|
|
|
|
ostream(b1) << "Hello";
|
|
|
|
flat_buffer b2;
|
|
|
|
b2 = std::move(b1);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.size() == 0);
|
|
|
|
BEAST_EXPECT(b1.capacity() == 0);
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
using na_t = test::test_allocator<char,
|
|
|
|
true, true, false, true, true>;
|
|
|
|
basic_flat_buffer<na_t> b1;
|
|
|
|
ostream(b1) << "Hello";
|
|
|
|
basic_flat_buffer<na_t> b2;
|
|
|
|
b2 = std::move(b1);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.get_allocator() == b2.get_allocator());
|
|
|
|
BEAST_EXPECT(b1.size() == 0);
|
|
|
|
BEAST_EXPECT(b1.capacity() == 0);
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
using na_t = test::test_allocator<char,
|
|
|
|
false, true, false, true, true>;
|
|
|
|
basic_flat_buffer<na_t> b1;
|
|
|
|
ostream(b1) << "Hello";
|
|
|
|
basic_flat_buffer<na_t> b2;
|
|
|
|
b2 = std::move(b1);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.get_allocator() != b2.get_allocator());
|
|
|
|
BEAST_EXPECT(b1.size() == 0);
|
|
|
|
BEAST_EXPECT(b1.capacity() == 0);
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
// propagate_on_container_move_assignment : true
|
|
|
|
using pocma_t = test::test_allocator<char,
|
|
|
|
true, true, true, true, true>;
|
|
|
|
basic_flat_buffer<pocma_t> b1;
|
|
|
|
ostream(b1) << "Hello";
|
|
|
|
basic_flat_buffer<pocma_t> b2;
|
|
|
|
b2 = std::move(b1);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.size() == 0);
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
// propagate_on_container_move_assignment : false
|
|
|
|
using pocma_t = test::test_allocator<char,
|
|
|
|
true, true, false, true, true>;
|
|
|
|
basic_flat_buffer<pocma_t> b1;
|
|
|
|
ostream(b1) << "Hello";
|
|
|
|
basic_flat_buffer<pocma_t> b2;
|
|
|
|
b2 = std::move(b1);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.size() == 0);
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
2017-04-30 14:36:16 -07:00
|
|
|
}
|
|
|
|
|
2017-06-09 22:36:57 -07:00
|
|
|
// copy assignment
|
|
|
|
{
|
|
|
|
{
|
|
|
|
flat_buffer b1;
|
|
|
|
ostream(b1) << "Hello";
|
|
|
|
flat_buffer b2;
|
|
|
|
b2 = b1;
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b1.data()) == "Hello");
|
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-06-09 22:36:57 -07:00
|
|
|
basic_flat_buffer<a_t> b3;
|
|
|
|
b3 = b2;
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b3.data()) == "Hello");
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
// propagate_on_container_copy_assignment : true
|
|
|
|
using pocca_t = test::test_allocator<char,
|
|
|
|
true, true, true, true, true>;
|
|
|
|
basic_flat_buffer<pocca_t> b1;
|
|
|
|
ostream(b1) << "Hello";
|
|
|
|
basic_flat_buffer<pocca_t> b2;
|
|
|
|
b2 = b1;
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
// propagate_on_container_copy_assignment : false
|
|
|
|
using pocca_t = test::test_allocator<char,
|
|
|
|
true, false, true, true, true>;
|
|
|
|
basic_flat_buffer<pocca_t> b1;
|
|
|
|
ostream(b1) << "Hello";
|
|
|
|
basic_flat_buffer<pocca_t> b2;
|
|
|
|
b2 = b1;
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
|
|
|
}
|
2017-04-30 14:36:16 -07:00
|
|
|
|
2017-06-09 22:36:57 -07:00
|
|
|
// operations
|
2017-04-30 14:36:16 -07:00
|
|
|
{
|
2017-06-09 22:36:57 -07:00
|
|
|
string_view const s = "Hello, world!";
|
|
|
|
flat_buffer b1{64};
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.size() == 0);
|
|
|
|
BEAST_EXPECT(b1.max_size() == 64);
|
|
|
|
BEAST_EXPECT(b1.capacity() == 0);
|
2017-06-09 22:36:57 -07:00
|
|
|
ostream(b1) << s;
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b1.data()) == s);
|
2017-06-09 22:36:57 -07:00
|
|
|
{
|
|
|
|
flat_buffer b2{b1};
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == s);
|
2017-06-09 22:36:57 -07:00
|
|
|
b2.consume(7);
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == s.substr(7));
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
flat_buffer b2{64};
|
|
|
|
b2 = b1;
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == s);
|
2017-06-09 22:36:57 -07:00
|
|
|
b2.consume(7);
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == s.substr(7));
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
2017-04-30 14:36:16 -07:00
|
|
|
}
|
2017-06-09 22:36:57 -07:00
|
|
|
|
|
|
|
// cause memmove
|
2017-04-30 14:36:16 -07:00
|
|
|
{
|
2017-06-10 10:12:29 -07:00
|
|
|
flat_buffer b{20};
|
|
|
|
ostream(b) << "12345";
|
|
|
|
b.consume(3);
|
|
|
|
ostream(b) << "67890123";
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b.data()) == "4567890123");
|
2017-04-30 14:36:16 -07:00
|
|
|
}
|
|
|
|
|
2017-06-12 01:51:52 -07:00
|
|
|
// read_size
|
2017-02-05 18:02:14 -05:00
|
|
|
{
|
2017-05-04 16:00:20 -07:00
|
|
|
flat_buffer b{10};
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(read_size(b, 512) == 10);
|
2017-06-09 22:36:57 -07:00
|
|
|
b.prepare(4);
|
|
|
|
b.commit(4);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(read_size(b, 512) == 6);
|
2017-06-09 22:36:57 -07:00
|
|
|
b.consume(2);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(read_size(b, 512) == 8);
|
2017-06-09 22:36:57 -07:00
|
|
|
b.prepare(8);
|
|
|
|
b.commit(8);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(read_size(b, 512) == 0);
|
2017-02-05 18:02:14 -05:00
|
|
|
}
|
|
|
|
|
2017-06-09 22:36:57 -07:00
|
|
|
// swap
|
|
|
|
{
|
2017-02-05 18:02:14 -05:00
|
|
|
{
|
2017-06-09 22:36:57 -07:00
|
|
|
basic_flat_buffer<a_neq_t> b1;
|
|
|
|
ostream(b1) << "Hello";
|
|
|
|
basic_flat_buffer<a_neq_t> b2;
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.get_allocator() != b2.get_allocator());
|
2017-06-09 22:36:57 -07:00
|
|
|
swap(b1, b2);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.get_allocator() != b2.get_allocator());
|
|
|
|
BEAST_EXPECT(b1.size() == 0);
|
|
|
|
BEAST_EXPECT(b1.capacity() == 0);
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-02-05 18:02:14 -05:00
|
|
|
}
|
|
|
|
{
|
2017-06-09 22:36:57 -07:00
|
|
|
using na_t = test::test_allocator<char,
|
|
|
|
true, true, true, false, true>;
|
|
|
|
na_t a1;
|
|
|
|
basic_flat_buffer<na_t> b1{a1};
|
|
|
|
na_t a2;
|
|
|
|
ostream(b1) << "Hello";
|
|
|
|
basic_flat_buffer<na_t> b2{a2};
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.get_allocator() == a1);
|
|
|
|
BEAST_EXPECT(b2.get_allocator() == a2);
|
2017-06-09 22:36:57 -07:00
|
|
|
swap(b1, b2);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b1.get_allocator() == b2.get_allocator());
|
|
|
|
BEAST_EXPECT(b1.size() == 0);
|
|
|
|
BEAST_EXPECT(b1.capacity() == 0);
|
2018-04-24 10:55:39 -07:00
|
|
|
BEAST_EXPECT(buffers_to_string(b2.data()) == "Hello");
|
2017-02-05 18:02:14 -05:00
|
|
|
}
|
2017-06-09 22:36:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// prepare
|
|
|
|
{
|
|
|
|
flat_buffer b{100};
|
|
|
|
b.prepare(10);
|
|
|
|
b.commit(10);
|
|
|
|
b.prepare(5);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b.capacity() >= 5);
|
2017-06-09 22:36:57 -07:00
|
|
|
try
|
2017-02-05 18:02:14 -05:00
|
|
|
{
|
2017-06-09 22:36:57 -07:00
|
|
|
b.prepare(1000);
|
|
|
|
fail("", __FILE__, __LINE__);
|
2017-02-05 18:02:14 -05:00
|
|
|
}
|
2017-06-09 22:36:57 -07:00
|
|
|
catch(std::length_error const&)
|
2017-02-05 18:02:14 -05:00
|
|
|
{
|
2017-06-09 22:36:57 -07:00
|
|
|
pass();
|
2017-02-05 18:02:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-09 22:36:57 -07:00
|
|
|
// shrink to fit
|
2017-02-05 18:02:14 -05:00
|
|
|
{
|
2017-06-09 22:36:57 -07:00
|
|
|
flat_buffer b;
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b.capacity() == 0);
|
2017-06-09 22:36:57 -07:00
|
|
|
b.prepare(50);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b.capacity() == 50);
|
2017-06-09 22:36:57 -07:00
|
|
|
b.commit(50);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b.capacity() == 50);
|
2017-06-09 22:36:57 -07:00
|
|
|
b.prepare(75);
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b.capacity() >= 125);
|
2017-06-09 22:36:57 -07:00
|
|
|
b.shrink_to_fit();
|
2017-07-25 12:35:54 -07:00
|
|
|
BEAST_EXPECT(b.capacity() == b.size());
|
2017-02-05 18:02:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
run() override
|
|
|
|
{
|
2017-06-09 22:36:57 -07:00
|
|
|
testBuffer();
|
2018-11-29 12:57:29 -08:00
|
|
|
testMutableData<flat_buffer>();
|
2017-02-05 18:02:14 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-08-01 17:01:57 -07:00
|
|
|
BEAST_DEFINE_TESTSUITE(beast,core,flat_buffer);
|
2017-02-05 18:02:14 -05:00
|
|
|
|
|
|
|
} // beast
|
2017-07-20 13:40:34 -07:00
|
|
|
} // boost
|