mirror of
https://github.com/boostorg/beast.git
synced 2025-08-03 14:54:32 +02:00
More flat_streambuf tests
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
* Use static_string for WebSocket handshakes
|
||||
* Simplify get_lowest_layer test
|
||||
* Add test_allocator to extras/test
|
||||
* More flat_streambuf tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
@@ -23,45 +23,50 @@ struct test_allocator_info
|
||||
};
|
||||
|
||||
template<class T,
|
||||
bool Assign, bool Move, bool Swap, bool Select>
|
||||
bool Equal, bool Assign, bool Move, bool Swap, bool Select>
|
||||
class test_allocator;
|
||||
|
||||
template<class T,
|
||||
bool Assign, bool Move, bool Swap, bool Select>
|
||||
bool Equal, bool Assign, bool Move, bool Swap, bool Select>
|
||||
struct test_allocator_base
|
||||
{
|
||||
};
|
||||
|
||||
template<class T,
|
||||
bool Assign, bool Move, bool Swap>
|
||||
struct test_allocator_base<T, Assign, Move, Swap, true>
|
||||
bool Equal, bool Assign, bool Move, bool Swap>
|
||||
struct test_allocator_base<
|
||||
T, Equal, Assign, Move, Swap, true>
|
||||
{
|
||||
static
|
||||
test_allocator<T, Assign, Move, Swap, true>
|
||||
select_on_container_copy_construction(
|
||||
test_allocator<T, Assign, Move, Swap, true> const& a)
|
||||
test_allocator<T, Equal, Assign, Move, Swap, true>
|
||||
select_on_container_copy_construction(test_allocator<
|
||||
T, Equal, Assign, Move, Swap, true> const& a)
|
||||
{
|
||||
return test_allocator<T, Assign, Move, Swap, true>{};
|
||||
return test_allocator<T,
|
||||
Equal, Assign, Move, Swap, true>{};
|
||||
}
|
||||
};
|
||||
|
||||
template<class T,
|
||||
bool Assign, bool Move, bool Swap, bool Select>
|
||||
bool Equal, bool Assign, bool Move, bool Swap, bool Select>
|
||||
class test_allocator : public test_allocator_base<
|
||||
T, Assign, Move, Swap, Select>
|
||||
T, Equal, Assign, Move, Swap, Select>
|
||||
{
|
||||
std::size_t id_;
|
||||
std::shared_ptr<test_allocator_info> info_;
|
||||
|
||||
template<class, bool, bool, bool, bool>
|
||||
template<class, bool, bool, bool, bool, bool>
|
||||
friend class test_allocator;
|
||||
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
using propagate_on_container_copy_assignment =
|
||||
std::integral_constant<bool, Assign>;
|
||||
|
||||
using propagate_on_container_move_assignment =
|
||||
std::integral_constant<bool, Move>;
|
||||
|
||||
using propagate_on_container_swap =
|
||||
std::integral_constant<bool, Swap>;
|
||||
|
||||
@@ -69,7 +74,7 @@ public:
|
||||
struct rebind
|
||||
{
|
||||
using other = test_allocator<
|
||||
U, Assign, Move, Swap, Select>;
|
||||
U, Equal, Assign, Move, Swap, Select>;
|
||||
};
|
||||
|
||||
test_allocator()
|
||||
@@ -91,8 +96,8 @@ public:
|
||||
}
|
||||
|
||||
template<class U>
|
||||
test_allocator(test_allocator<
|
||||
U, Assign, Move, Swap, Select> const& u) noexcept
|
||||
test_allocator(test_allocator<U,
|
||||
Equal, Assign, Move, Swap, Select> const& u) noexcept
|
||||
: id_(u.id_)
|
||||
, info_(u.info_)
|
||||
{
|
||||
@@ -119,6 +124,18 @@ public:
|
||||
::operator delete(p);
|
||||
}
|
||||
|
||||
bool
|
||||
operator==(test_allocator const& other) const
|
||||
{
|
||||
return id_ == other.id_ || Equal;
|
||||
}
|
||||
|
||||
bool
|
||||
operator!=(test_allocator const& other) const
|
||||
{
|
||||
return ! this->operator==(other);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
id() const
|
||||
{
|
||||
|
@@ -10,7 +10,9 @@
|
||||
|
||||
#include "buffer_test.hpp"
|
||||
#include <beast/core/to_string.hpp>
|
||||
#include <beast/test/test_allocator.hpp>
|
||||
#include <beast/unit_test/suite.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
namespace beast {
|
||||
|
||||
@@ -29,6 +31,121 @@ public:
|
||||
return to_string(sb1.data()) == to_string(sb2.data());
|
||||
}
|
||||
|
||||
template<
|
||||
bool Equal, bool Assign, bool Move, bool Swap, bool Select>
|
||||
void
|
||||
testCtor()
|
||||
{
|
||||
using allocator = test::test_allocator<char,
|
||||
Equal, Assign, Move, Swap, Select>;
|
||||
{
|
||||
using boost::asio::buffer_size;
|
||||
basic_flat_streambuf<allocator> b1{10};
|
||||
BEAST_EXPECT(b1.size() == 0);
|
||||
BEAST_EXPECT(b1.capacity() == 0);
|
||||
BEAST_EXPECT(b1.max_size() == 10);
|
||||
b1.prepare(1);
|
||||
b1.commit(1);
|
||||
basic_flat_streambuf<allocator> b2{std::move(b1)};
|
||||
BEAST_EXPECT(b1.capacity() == 0);
|
||||
BEAST_EXPECT(b1.max_size() == 10);
|
||||
BEAST_EXPECT(b2.size() == 1);
|
||||
BEAST_EXPECT(b2.max_size() == 10);
|
||||
BEAST_EXPECT(buffer_size(b1.data()) == 0);
|
||||
BEAST_EXPECT(buffer_size(b1.prepare(1)) == 1);
|
||||
}
|
||||
{
|
||||
basic_flat_streambuf<allocator> b1{10};
|
||||
basic_flat_streambuf<allocator> b2{std::move(b1), allocator{}};
|
||||
}
|
||||
{
|
||||
basic_flat_streambuf<allocator> b1{10};
|
||||
basic_flat_streambuf<allocator> b2{b1};
|
||||
}
|
||||
{
|
||||
basic_flat_streambuf<allocator> b1{10};
|
||||
basic_flat_streambuf<allocator> b2{b1, allocator{}};
|
||||
}
|
||||
{
|
||||
flat_streambuf b1{10};
|
||||
b1.prepare(1);
|
||||
b1.commit(1);
|
||||
basic_flat_streambuf<allocator> b2{b1};
|
||||
BEAST_EXPECT(b2.size() == 1);
|
||||
}
|
||||
{
|
||||
basic_flat_streambuf<allocator> b1{10};
|
||||
}
|
||||
{
|
||||
basic_flat_streambuf<allocator> b1{allocator{}, 10};
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testCtors()
|
||||
{
|
||||
testCtor<false, false, false, false, false>();
|
||||
testCtor<false, false, false, false, true>();
|
||||
testCtor<false, false, false, true, false>();
|
||||
testCtor<false, false, false, true, true>();
|
||||
testCtor<false, false, true, false, false>();
|
||||
testCtor<false, false, true, false, true>();
|
||||
testCtor<false, false, true, true, false>();
|
||||
testCtor<false, false, true, true, true>();
|
||||
testCtor<false, true, false, false, false>();
|
||||
testCtor<false, true, false, false, true>();
|
||||
testCtor<false, true, false, true, false>();
|
||||
testCtor<false, true, false, true, true>();
|
||||
testCtor<false, true, true, false, false>();
|
||||
testCtor<false, true, true, false, true>();
|
||||
testCtor<false, true, true, true, false>();
|
||||
testCtor<false, true, true, true, true>();
|
||||
testCtor< true, false, false, false, false>();
|
||||
testCtor< true, false, false, false, true>();
|
||||
testCtor< true, false, false, true, false>();
|
||||
testCtor< true, false, false, true, true>();
|
||||
testCtor< true, false, true, false, false>();
|
||||
testCtor< true, false, true, false, true>();
|
||||
testCtor< true, false, true, true, false>();
|
||||
testCtor< true, false, true, true, true>();
|
||||
testCtor< true, true, false, false, false>();
|
||||
testCtor< true, true, false, false, true>();
|
||||
testCtor< true, true, false, true, false>();
|
||||
testCtor< true, true, false, true, true>();
|
||||
testCtor< true, true, true, false, false>();
|
||||
testCtor< true, true, true, false, true>();
|
||||
testCtor< true, true, true, true, false>();
|
||||
testCtor< true, true, true, true, true>();
|
||||
}
|
||||
|
||||
void
|
||||
testOperations()
|
||||
{
|
||||
//
|
||||
// reserve
|
||||
//
|
||||
|
||||
{
|
||||
flat_streambuf b{10};
|
||||
b.prepare(1);
|
||||
b.commit(1);
|
||||
b.reserve(2);
|
||||
BEAST_EXPECT(b.size() == 1);
|
||||
}
|
||||
{
|
||||
flat_streambuf b{10};
|
||||
try
|
||||
{
|
||||
b.reserve(11);
|
||||
fail("", __FILE__, __LINE__);
|
||||
}
|
||||
catch(std::length_error const&)
|
||||
{
|
||||
pass();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testSpecialMembers()
|
||||
{
|
||||
@@ -159,6 +276,9 @@ public:
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testCtors();
|
||||
testOperations();
|
||||
|
||||
testSpecialMembers();
|
||||
testStream();
|
||||
testPrepare();
|
||||
|
@@ -109,14 +109,14 @@ public:
|
||||
// VFALCO This needs work
|
||||
{
|
||||
using alloc_type =
|
||||
test_allocator<char, false, false, false, false>;
|
||||
test_allocator<char, false, false, false, false, false>;
|
||||
using sb_type = basic_streambuf<alloc_type>;
|
||||
sb_type sb;
|
||||
BEAST_EXPECT(sb.get_allocator().id() == 1);
|
||||
}
|
||||
{
|
||||
using alloc_type =
|
||||
test_allocator<char, false, false, false, false>;
|
||||
test_allocator<char, false, false, false, false, false>;
|
||||
using sb_type = basic_streambuf<alloc_type>;
|
||||
sb_type sb;
|
||||
BEAST_EXPECT(sb.get_allocator().id() == 2);
|
||||
|
Reference in New Issue
Block a user