forked from boostorg/beast
1 parent
3543b4b913
commit
929174d4d8
15 files changed
+105
-46
No files matched your search
@@ -9,6 +9,8 @@
|
||||
#define BEAST_TEST_BUFFER_TEST_HPP
|
||||
|
||||
#include <beast/core/type_traits.hpp>
|
||||
#include <beast/core/detail/read_size_helper.hpp>
|
||||
#include <beast/core/detail/type_traits.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
@@ -83,6 +85,32 @@ size_rev_post(ConstBufferSequence const& buffers)
|
||||
return n;
|
||||
}
|
||||
|
||||
namespace has_read_size_helper
|
||||
{
|
||||
using beast::detail::read_size_helper;
|
||||
|
||||
template<class T, class = void>
|
||||
struct trait : std::false_type {};
|
||||
|
||||
template<class T>
|
||||
struct trait<T, decltype(
|
||||
std::declval<std::size_t&>() =
|
||||
read_size_helper(std::declval<T>(), 0),
|
||||
(void)0)> : std::true_type
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
// Make sure read_size_helper works
|
||||
template<class DynamicBuffer>
|
||||
inline
|
||||
void
|
||||
check_read_size_helper()
|
||||
{
|
||||
static_assert(has_read_size_helper::trait<DynamicBuffer>::value,
|
||||
"Missing read_size_helper for dynamic buffer");
|
||||
}
|
||||
|
||||
} // test
|
||||
} // beast
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
// Test that header file is self-contained.
|
||||
#include <beast/core/buffers_adapter.hpp>
|
||||
|
||||
#include "buffer_test.hpp"
|
||||
#include <beast/core/ostream.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/unit_test/suite.hpp>
|
||||
@@ -176,6 +177,9 @@ public:
|
||||
}
|
||||
void run() override
|
||||
{
|
||||
test::check_read_size_helper<buffers_adapter<
|
||||
boost::asio::mutable_buffers_1>>();
|
||||
|
||||
testBuffersAdapter();
|
||||
testCommit();
|
||||
}
|
||||
|
||||
@@ -286,6 +286,8 @@ public:
|
||||
void
|
||||
run() override
|
||||
{
|
||||
test::check_read_size_helper<flat_buffer>();
|
||||
|
||||
testCtors();
|
||||
testOperations();
|
||||
|
||||
|
||||
@@ -281,14 +281,15 @@ public:
|
||||
|
||||
void testCapacity()
|
||||
{
|
||||
using beast::detail::read_size_helper;
|
||||
using boost::asio::buffer_size;
|
||||
{
|
||||
multi_buffer b{10};
|
||||
BEAST_EXPECT(b.alloc_size() == 10);
|
||||
BEAST_EXPECT(read_size_helper(b, 1) == 1);
|
||||
BEAST_EXPECT(read_size_helper(b, 10) == 10);
|
||||
BEAST_EXPECT(read_size_helper(b, 20) == 20);
|
||||
BEAST_EXPECT(read_size_helper(b, 1000) == 512);
|
||||
BEAST_EXPECT(read_size_helper(b, 20) == 10);
|
||||
BEAST_EXPECT(read_size_helper(b, 1000) == 10);
|
||||
b.prepare(3);
|
||||
b.commit(3);
|
||||
BEAST_EXPECT(read_size_helper(b, 10) == 7);
|
||||
@@ -345,6 +346,8 @@ public:
|
||||
|
||||
void run() override
|
||||
{
|
||||
test::check_read_size_helper<multi_buffer>();
|
||||
|
||||
testSpecialMembers();
|
||||
testAllocator();
|
||||
testPrepare();
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
// Test that header file is self-contained.
|
||||
#include <beast/core/static_buffer.hpp>
|
||||
|
||||
#include "buffer_test.hpp"
|
||||
#include <beast/unit_test/suite.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <string>
|
||||
@@ -197,6 +198,8 @@ public:
|
||||
|
||||
void run() override
|
||||
{
|
||||
test::check_read_size_helper<static_buffer_n<32>>();
|
||||
|
||||
testStaticBuffer();
|
||||
testIterators();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user