forked from boostorg/beast
More flat_streambuf tests
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
* Use static_string for WebSocket handshakes
|
* Use static_string for WebSocket handshakes
|
||||||
* Simplify get_lowest_layer test
|
* Simplify get_lowest_layer test
|
||||||
* Add test_allocator to extras/test
|
* Add test_allocator to extras/test
|
||||||
|
* More flat_streambuf tests
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@@ -23,45 +23,50 @@ struct test_allocator_info
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<class T,
|
template<class T,
|
||||||
bool Assign, bool Move, bool Swap, bool Select>
|
bool Equal, bool Assign, bool Move, bool Swap, bool Select>
|
||||||
class test_allocator;
|
class test_allocator;
|
||||||
|
|
||||||
template<class T,
|
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
|
struct test_allocator_base
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T,
|
template<class T,
|
||||||
bool Assign, bool Move, bool Swap>
|
bool Equal, bool Assign, bool Move, bool Swap>
|
||||||
struct test_allocator_base<T, Assign, Move, Swap, true>
|
struct test_allocator_base<
|
||||||
|
T, Equal, Assign, Move, Swap, true>
|
||||||
{
|
{
|
||||||
static
|
static
|
||||||
test_allocator<T, Assign, Move, Swap, true>
|
test_allocator<T, Equal, Assign, Move, Swap, true>
|
||||||
select_on_container_copy_construction(
|
select_on_container_copy_construction(test_allocator<
|
||||||
test_allocator<T, Assign, Move, Swap, true> const& a)
|
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,
|
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<
|
class test_allocator : public test_allocator_base<
|
||||||
T, Assign, Move, Swap, Select>
|
T, Equal, Assign, Move, Swap, Select>
|
||||||
{
|
{
|
||||||
std::size_t id_;
|
std::size_t id_;
|
||||||
std::shared_ptr<test_allocator_info> info_;
|
std::shared_ptr<test_allocator_info> info_;
|
||||||
|
|
||||||
template<class, bool, bool, bool, bool>
|
template<class, bool, bool, bool, bool, bool>
|
||||||
friend class test_allocator;
|
friend class test_allocator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
|
|
||||||
using propagate_on_container_copy_assignment =
|
using propagate_on_container_copy_assignment =
|
||||||
std::integral_constant<bool, Assign>;
|
std::integral_constant<bool, Assign>;
|
||||||
|
|
||||||
using propagate_on_container_move_assignment =
|
using propagate_on_container_move_assignment =
|
||||||
std::integral_constant<bool, Move>;
|
std::integral_constant<bool, Move>;
|
||||||
|
|
||||||
using propagate_on_container_swap =
|
using propagate_on_container_swap =
|
||||||
std::integral_constant<bool, Swap>;
|
std::integral_constant<bool, Swap>;
|
||||||
|
|
||||||
@@ -69,7 +74,7 @@ public:
|
|||||||
struct rebind
|
struct rebind
|
||||||
{
|
{
|
||||||
using other = test_allocator<
|
using other = test_allocator<
|
||||||
U, Assign, Move, Swap, Select>;
|
U, Equal, Assign, Move, Swap, Select>;
|
||||||
};
|
};
|
||||||
|
|
||||||
test_allocator()
|
test_allocator()
|
||||||
@@ -91,8 +96,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class U>
|
template<class U>
|
||||||
test_allocator(test_allocator<
|
test_allocator(test_allocator<U,
|
||||||
U, Assign, Move, Swap, Select> const& u) noexcept
|
Equal, Assign, Move, Swap, Select> const& u) noexcept
|
||||||
: id_(u.id_)
|
: id_(u.id_)
|
||||||
, info_(u.info_)
|
, info_(u.info_)
|
||||||
{
|
{
|
||||||
@@ -119,6 +124,18 @@ public:
|
|||||||
::operator delete(p);
|
::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
|
std::size_t
|
||||||
id() const
|
id() const
|
||||||
{
|
{
|
||||||
|
@@ -10,7 +10,9 @@
|
|||||||
|
|
||||||
#include "buffer_test.hpp"
|
#include "buffer_test.hpp"
|
||||||
#include <beast/core/to_string.hpp>
|
#include <beast/core/to_string.hpp>
|
||||||
|
#include <beast/test/test_allocator.hpp>
|
||||||
#include <beast/unit_test/suite.hpp>
|
#include <beast/unit_test/suite.hpp>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace beast {
|
namespace beast {
|
||||||
|
|
||||||
@@ -29,6 +31,121 @@ public:
|
|||||||
return to_string(sb1.data()) == to_string(sb2.data());
|
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
|
void
|
||||||
testSpecialMembers()
|
testSpecialMembers()
|
||||||
{
|
{
|
||||||
@@ -159,6 +276,9 @@ public:
|
|||||||
void
|
void
|
||||||
run() override
|
run() override
|
||||||
{
|
{
|
||||||
|
testCtors();
|
||||||
|
testOperations();
|
||||||
|
|
||||||
testSpecialMembers();
|
testSpecialMembers();
|
||||||
testStream();
|
testStream();
|
||||||
testPrepare();
|
testPrepare();
|
||||||
|
@@ -109,14 +109,14 @@ public:
|
|||||||
// VFALCO This needs work
|
// VFALCO This needs work
|
||||||
{
|
{
|
||||||
using alloc_type =
|
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>;
|
using sb_type = basic_streambuf<alloc_type>;
|
||||||
sb_type sb;
|
sb_type sb;
|
||||||
BEAST_EXPECT(sb.get_allocator().id() == 1);
|
BEAST_EXPECT(sb.get_allocator().id() == 1);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
using alloc_type =
|
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>;
|
using sb_type = basic_streambuf<alloc_type>;
|
||||||
sb_type sb;
|
sb_type sb;
|
||||||
BEAST_EXPECT(sb.get_allocator().id() == 2);
|
BEAST_EXPECT(sb.get_allocator().id() == 2);
|
||||||
|
Reference in New Issue
Block a user