forked from boostorg/beast
Test self copy, self move for dynamic buffers:
* Swap * Copy assignment to self * Move assignment to self
This commit is contained in:
@@ -15,6 +15,7 @@ Version 200
|
|||||||
* Tidy up flat_buffer tests
|
* Tidy up flat_buffer tests
|
||||||
* Fix ostream prepare calculation for low limits
|
* Fix ostream prepare calculation for low limits
|
||||||
* Tidy up flat_static_buffer tests
|
* Tidy up flat_static_buffer tests
|
||||||
|
* Add more tests for dynamic buffers
|
||||||
|
|
||||||
API Changes:
|
API Changes:
|
||||||
|
|
||||||
|
@@ -246,7 +246,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
static
|
static
|
||||||
std::size_t
|
std::size_t
|
||||||
dist(char const* first, char const* last)
|
dist(char const* first, char const* last) noexcept
|
||||||
{
|
{
|
||||||
return static_cast<std::size_t>(last - first);
|
return static_cast<std::size_t>(last - first);
|
||||||
}
|
}
|
||||||
|
@@ -113,7 +113,7 @@ class buffers_adaptor<MutableBufferSequence>::
|
|||||||
readable_bytes<isMutable>::
|
readable_bytes<isMutable>::
|
||||||
const_iterator
|
const_iterator
|
||||||
{
|
{
|
||||||
iter_type it_;
|
iter_type it_{};
|
||||||
buffers_adaptor const* b_ = nullptr;
|
buffers_adaptor const* b_ = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -259,7 +259,7 @@ template<class MutableBufferSequence>
|
|||||||
class buffers_adaptor<MutableBufferSequence>::
|
class buffers_adaptor<MutableBufferSequence>::
|
||||||
mutable_buffers_type::const_iterator
|
mutable_buffers_type::const_iterator
|
||||||
{
|
{
|
||||||
iter_type it_;
|
iter_type it_{};
|
||||||
buffers_adaptor const* b_ = nullptr;
|
buffers_adaptor const* b_ = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -442,6 +442,8 @@ buffers_adaptor<MutableBufferSequence>::
|
|||||||
operator=(buffers_adaptor const& other) ->
|
operator=(buffers_adaptor const& other) ->
|
||||||
buffers_adaptor&
|
buffers_adaptor&
|
||||||
{
|
{
|
||||||
|
if(this == &other)
|
||||||
|
return *this;
|
||||||
auto const nbegin = std::distance<iter_type>(
|
auto const nbegin = std::distance<iter_type>(
|
||||||
net::buffer_sequence_begin(other.bs_),
|
net::buffer_sequence_begin(other.bs_),
|
||||||
other.begin_);
|
other.begin_);
|
||||||
|
@@ -30,7 +30,8 @@ template<class Allocator>
|
|||||||
basic_flat_buffer<Allocator>::
|
basic_flat_buffer<Allocator>::
|
||||||
~basic_flat_buffer()
|
~basic_flat_buffer()
|
||||||
{
|
{
|
||||||
if(begin_)
|
if(! begin_)
|
||||||
|
return;
|
||||||
alloc_traits::deallocate(
|
alloc_traits::deallocate(
|
||||||
this->get(), begin_, capacity());
|
this->get(), begin_, capacity());
|
||||||
}
|
}
|
||||||
@@ -124,9 +125,9 @@ basic_flat_buffer(
|
|||||||
max_ = other.max_;
|
max_ = other.max_;
|
||||||
copy_from(other);
|
copy_from(other);
|
||||||
other.clear();
|
other.clear();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
begin_ = other.begin_;
|
begin_ = other.begin_;
|
||||||
in_ = other.in_;
|
in_ = other.in_;
|
||||||
out_ = other.out_;
|
out_ = other.out_;
|
||||||
@@ -142,7 +143,6 @@ basic_flat_buffer(
|
|||||||
other.last_ = nullptr;
|
other.last_ = nullptr;
|
||||||
other.end_ = nullptr;
|
other.end_ = nullptr;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
template<class Allocator>
|
template<class Allocator>
|
||||||
basic_flat_buffer<Allocator>::
|
basic_flat_buffer<Allocator>::
|
||||||
@@ -217,7 +217,8 @@ basic_flat_buffer<Allocator>::
|
|||||||
operator=(basic_flat_buffer&& other) noexcept ->
|
operator=(basic_flat_buffer&& other) noexcept ->
|
||||||
basic_flat_buffer&
|
basic_flat_buffer&
|
||||||
{
|
{
|
||||||
if(this != &other)
|
if(this == &other)
|
||||||
|
return *this;
|
||||||
move_assign(other, pocma{});
|
move_assign(other, pocma{});
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -228,7 +229,8 @@ basic_flat_buffer<Allocator>::
|
|||||||
operator=(basic_flat_buffer const& other) ->
|
operator=(basic_flat_buffer const& other) ->
|
||||||
basic_flat_buffer&
|
basic_flat_buffer&
|
||||||
{
|
{
|
||||||
if(this != &other)
|
if(this == &other)
|
||||||
|
return *this;
|
||||||
copy_assign(other, pocca{});
|
copy_assign(other, pocca{});
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@@ -102,6 +102,8 @@ operator=(flat_static_buffer const& other) ->
|
|||||||
flat_static_buffer<N>&
|
flat_static_buffer<N>&
|
||||||
{
|
{
|
||||||
using net::buffer_copy;
|
using net::buffer_copy;
|
||||||
|
if(this == &other)
|
||||||
|
return *this;
|
||||||
this->consume(this->size());
|
this->consume(this->size());
|
||||||
this->commit(buffer_copy(
|
this->commit(buffer_copy(
|
||||||
this->prepare(other.size()), other.data()));
|
this->prepare(other.size()), other.data()));
|
||||||
|
@@ -145,6 +145,8 @@ static_buffer<N>::
|
|||||||
operator=(static_buffer const& other) noexcept ->
|
operator=(static_buffer const& other) noexcept ->
|
||||||
static_buffer<N>&
|
static_buffer<N>&
|
||||||
{
|
{
|
||||||
|
if(this == &other)
|
||||||
|
return *this;
|
||||||
this->consume(this->size());
|
this->consume(this->size());
|
||||||
this->commit(net::buffer_copy(
|
this->commit(net::buffer_copy(
|
||||||
this->prepare(other.size()), other.data()));
|
this->prepare(other.size()), other.data()));
|
||||||
|
@@ -479,7 +479,7 @@ test_dynamic_buffer(
|
|||||||
SUITE_EXPECT(test, b0.size() == 0);
|
SUITE_EXPECT(test, b0.size() == 0);
|
||||||
SUITE_EXPECT(test, buffer_size(b0.data()) == 0);
|
SUITE_EXPECT(test, buffer_size(b0.data()) == 0);
|
||||||
|
|
||||||
// special members
|
// members
|
||||||
{
|
{
|
||||||
string_view src = "Hello, world!";
|
string_view src = "Hello, world!";
|
||||||
|
|
||||||
@@ -503,8 +503,8 @@ test_dynamic_buffer(
|
|||||||
DynamicBuffer b3(std::move(b2));
|
DynamicBuffer b3(std::move(b2));
|
||||||
SUITE_EXPECT(test, b3.size() == b1.size());
|
SUITE_EXPECT(test, b3.size() == b1.size());
|
||||||
SUITE_EXPECT(test,
|
SUITE_EXPECT(test,
|
||||||
buffers_to_string(b1.data()) ==
|
buffers_to_string(b3.data()) ==
|
||||||
buffers_to_string(b3.data()));
|
buffers_to_string(b1.data()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy assignment
|
// copy assignment
|
||||||
@@ -515,6 +515,13 @@ test_dynamic_buffer(
|
|||||||
SUITE_EXPECT(test,
|
SUITE_EXPECT(test,
|
||||||
buffers_to_string(b1.data()) ==
|
buffers_to_string(b1.data()) ==
|
||||||
buffers_to_string(b2.data()));
|
buffers_to_string(b2.data()));
|
||||||
|
|
||||||
|
// self assignment
|
||||||
|
b2 = b2;
|
||||||
|
SUITE_EXPECT(test, b2.size() == b1.size());
|
||||||
|
SUITE_EXPECT(test,
|
||||||
|
buffers_to_string(b2.data()) ==
|
||||||
|
buffers_to_string(b1.data()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// move assignment
|
// move assignment
|
||||||
@@ -524,8 +531,30 @@ test_dynamic_buffer(
|
|||||||
b3 = std::move(b2);
|
b3 = std::move(b2);
|
||||||
SUITE_EXPECT(test, b3.size() == b1.size());
|
SUITE_EXPECT(test, b3.size() == b1.size());
|
||||||
SUITE_EXPECT(test,
|
SUITE_EXPECT(test,
|
||||||
buffers_to_string(b1.data()) ==
|
buffers_to_string(b3.data()) ==
|
||||||
buffers_to_string(b3.data()));
|
buffers_to_string(b1.data()));
|
||||||
|
|
||||||
|
// self move
|
||||||
|
b3 = std::move(b3);
|
||||||
|
SUITE_EXPECT(test, b3.size() == b1.size());
|
||||||
|
SUITE_EXPECT(test,
|
||||||
|
buffers_to_string(b3.data()) ==
|
||||||
|
buffers_to_string(b1.data()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// swap
|
||||||
|
{
|
||||||
|
DynamicBuffer b2(b1);
|
||||||
|
DynamicBuffer b3(b0);
|
||||||
|
SUITE_EXPECT(test, b2.size() == b1.size());
|
||||||
|
SUITE_EXPECT(test, b3.size() == b0.size());
|
||||||
|
using std::swap;
|
||||||
|
swap(b2, b3);
|
||||||
|
SUITE_EXPECT(test, b2.size() == b0.size());
|
||||||
|
SUITE_EXPECT(test, b3.size() == b1.size());
|
||||||
|
SUITE_EXPECT(test,
|
||||||
|
buffers_to_string(b3.data()) ==
|
||||||
|
buffers_to_string(b1.data()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -571,6 +600,7 @@ test_dynamic_buffer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setup source buffer
|
||||||
char buf[13];
|
char buf[13];
|
||||||
unsigned char k0 = 0;
|
unsigned char k0 = 0;
|
||||||
string_view src(buf, sizeof(buf));
|
string_view src(buf, sizeof(buf));
|
||||||
|
Reference in New Issue
Block a user