forked from boostorg/beast
Add buffer_size
This commit is contained in:
1 parent
64149f434a
commit
35dbd140d4
64 files changed
+427
-379
No files matched your search
@@ -31,6 +31,7 @@ add_executable (tests-beast-core
|
||||
async_op_base.cpp
|
||||
basic_timeout_stream.cpp
|
||||
bind_handler.cpp
|
||||
buffer_size.cpp
|
||||
buffer_traits.cpp
|
||||
buffered_read_stream.cpp
|
||||
buffers_adapter.cpp
|
||||
|
||||
@@ -19,6 +19,7 @@ local SOURCES =
|
||||
async_op_base.cpp
|
||||
basic_timeout_stream.cpp
|
||||
bind_handler.cpp
|
||||
buffer_size.cpp
|
||||
buffer_traits.cpp
|
||||
buffered_read_stream.cpp
|
||||
buffers_adapter.cpp
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// Copyright (c) 2018 Vinnie Falco (vinnie dot falco at gmail dot com)
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include <boost/beast/core/buffer_size.hpp>
|
||||
|
||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||
#include <boost/beast/core/detail/type_traits.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
|
||||
namespace {
|
||||
|
||||
struct sequence
|
||||
{
|
||||
struct value_type
|
||||
{
|
||||
operator net::const_buffer() const noexcept
|
||||
{
|
||||
return {"Hello, world!", 13};
|
||||
}
|
||||
};
|
||||
|
||||
using const_iterator = value_type const*;
|
||||
|
||||
const_iterator begin() const noexcept
|
||||
{
|
||||
return &v_;
|
||||
}
|
||||
|
||||
const_iterator end() const noexcept
|
||||
{
|
||||
return begin() + 1;
|
||||
}
|
||||
|
||||
private:
|
||||
value_type v_;
|
||||
};
|
||||
|
||||
struct not_sequence
|
||||
{
|
||||
};
|
||||
|
||||
} // (anon)
|
||||
|
||||
class buffer_size_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void
|
||||
testJavadocs()
|
||||
{
|
||||
pass();
|
||||
}
|
||||
|
||||
void
|
||||
testFunction()
|
||||
{
|
||||
BEAST_EXPECT(buffer_size(
|
||||
net::const_buffer("Hello, world!", 13)) == 13);
|
||||
|
||||
BEAST_EXPECT(buffer_size(
|
||||
net::mutable_buffer{}) == 0);
|
||||
|
||||
{
|
||||
sequence s;
|
||||
BEAST_EXPECT(buffer_size(s) == 13);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<net::const_buffer, 2> s({{
|
||||
net::const_buffer("Hello, world!", 13),
|
||||
net::const_buffer("Hello, world!", 13)}});
|
||||
BEAST_EXPECT(buffer_size(s) == 26);
|
||||
}
|
||||
|
||||
BOOST_STATIC_ASSERT(! detail::is_invocable<
|
||||
detail::buffer_size_impl,
|
||||
std::size_t(not_sequence const&)>::value);
|
||||
}
|
||||
|
||||
void run() override
|
||||
{
|
||||
testFunction();
|
||||
testJavadocs();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(beast,core,buffer_size);
|
||||
|
||||
} // beast
|
||||
} // boost
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <boost/beast/core/detail/config.hpp>
|
||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||
#include <boost/beast/core/buffer_size.hpp>
|
||||
#include <boost/beast/core/buffer_traits.hpp>
|
||||
#include <boost/beast/core/buffers_to_string.hpp>
|
||||
#include <boost/beast/core/string.hpp>
|
||||
@@ -116,7 +117,6 @@ void test_mutable_buffers(
|
||||
MutableBufferSequence const& b,
|
||||
net::mutable_buffer)
|
||||
{
|
||||
using net::buffer_size;
|
||||
string_view src = "Hello, world!";
|
||||
BOOST_ASSERT(buffer_size(b) <= src.size());
|
||||
if(src.size() > buffer_size(b))
|
||||
@@ -139,8 +139,6 @@ test_buffer_sequence(
|
||||
net::is_const_buffer_sequence<
|
||||
ConstBufferSequence>::value);
|
||||
|
||||
using net::buffer_size;
|
||||
|
||||
using iterator = decltype(
|
||||
net::buffer_sequence_begin(buffers));
|
||||
BEAST_EXPECT(sizeof(iterator) > 0);
|
||||
@@ -183,7 +181,6 @@ test_buffer_sequence(
|
||||
|
||||
// bidirectional
|
||||
{
|
||||
using net::buffer_size;
|
||||
auto const first =
|
||||
net::buffer_sequence_begin(buffers);
|
||||
auto const last =
|
||||
@@ -290,8 +287,6 @@ test_mutable_dynamic_buffer(
|
||||
MutableDynamicBuffer const& b0,
|
||||
std::true_type)
|
||||
{
|
||||
using net::buffer_size;
|
||||
|
||||
BOOST_STATIC_ASSERT(
|
||||
net::is_mutable_buffer_sequence<typename
|
||||
MutableDynamicBuffer::mutable_data_type>::value);
|
||||
@@ -372,8 +367,6 @@ void
|
||||
test_dynamic_buffer(
|
||||
DynamicBuffer const& b0)
|
||||
{
|
||||
using net::buffer_size;
|
||||
|
||||
BOOST_STATIC_ASSERT(
|
||||
net::is_dynamic_buffer<DynamicBuffer>::value);
|
||||
|
||||
|
||||
@@ -80,7 +80,6 @@ public:
|
||||
void
|
||||
on_read(error_code ec, std::size_t)
|
||||
{
|
||||
using net::buffer;
|
||||
if(! ec)
|
||||
{
|
||||
suite_.expect(s_ ==
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "buffer_test.hpp"
|
||||
|
||||
#include <boost/beast/core/buffer_size.hpp>
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
#include <boost/beast/core/ostream.hpp>
|
||||
#include <boost/beast/core/read_size.hpp>
|
||||
@@ -42,8 +43,6 @@ public:
|
||||
void
|
||||
testSpecial()
|
||||
{
|
||||
using net::buffer_size;
|
||||
|
||||
char s1[13];
|
||||
buffers_triple tb1(s1, sizeof(s1));
|
||||
BEAST_EXPECT(buffer_size(tb1) == sizeof(s1));
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "buffer_test.hpp"
|
||||
|
||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||
#include <boost/beast/core/buffer_size.hpp>
|
||||
#include <boost/beast/core/buffers_prefix.hpp>
|
||||
#include <boost/beast/core/buffers_suffix.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
@@ -155,8 +156,6 @@ public:
|
||||
void
|
||||
testEmpty()
|
||||
{
|
||||
using net::buffer_size;
|
||||
|
||||
struct empty_sequence
|
||||
{
|
||||
using value_type = net::const_buffer;
|
||||
@@ -275,19 +274,14 @@ public:
|
||||
void
|
||||
testGccWarning1()
|
||||
{
|
||||
using boost::beast::buffers_cat;
|
||||
using boost::beast::buffers_suffix;
|
||||
using net::buffer;
|
||||
using net::const_buffer;
|
||||
|
||||
char out[64];
|
||||
std::array<const_buffer, 2> buffers{
|
||||
{buffer("Hello, "), buffer("world!")}};
|
||||
std::array<net::const_buffer, 2> buffers{
|
||||
{net::buffer("Hello, "), net::buffer("world!")}};
|
||||
std::size_t i = 3;
|
||||
buffers_suffix<std::array<const_buffer, 2>> cb(buffers);
|
||||
buffers_suffix<std::array<net::const_buffer, 2>> cb(buffers);
|
||||
cb.consume(i);
|
||||
net::buffer_copy(
|
||||
buffer(out),
|
||||
net::buffer(out),
|
||||
buffers_cat(cb, cb));
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "buffer_test.hpp"
|
||||
|
||||
#include <boost/beast/core/buffer_size.hpp>
|
||||
#include <boost/beast/core/buffers_to_string.hpp>
|
||||
#include <boost/beast/core/type_traits.hpp>
|
||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||
@@ -89,7 +90,6 @@ public:
|
||||
void
|
||||
testPrefixes()
|
||||
{
|
||||
using net::buffer_size;
|
||||
std::string s = "Hello, world";
|
||||
BEAST_EXPECT(s.size() == 12);
|
||||
for(std::size_t x = 1; x < 4; ++x) {
|
||||
@@ -118,8 +118,6 @@ public:
|
||||
|
||||
void testEmpty()
|
||||
{
|
||||
using net::buffer_size;
|
||||
|
||||
auto pb0 = buffers_prefix(0, net::mutable_buffer{});
|
||||
BEAST_EXPECT(buffer_size(pb0) == 0);
|
||||
auto pb1 = buffers_prefix(1, net::mutable_buffer{});
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "buffer_test.hpp"
|
||||
|
||||
#include <boost/beast/core/buffer_size.hpp>
|
||||
#include <boost/beast/core/buffers_cat.hpp>
|
||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
@@ -80,7 +81,6 @@ public:
|
||||
|
||||
// empty sequence
|
||||
{
|
||||
using net::buffer_size;
|
||||
buffers_suffix<net::mutable_buffer> cb(
|
||||
net::mutable_buffer{});
|
||||
BEAST_EXPECT(buffer_size(cb) == 0);
|
||||
@@ -113,7 +113,6 @@ public:
|
||||
void
|
||||
testMatrix()
|
||||
{
|
||||
using net::buffer_size;
|
||||
char buf[12];
|
||||
std::string const s = "Hello, world";
|
||||
BEAST_EXPECT(s.size() == sizeof(buf));
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "buffer_test.hpp"
|
||||
|
||||
#include <boost/beast/core/buffer_size.hpp>
|
||||
#include <boost/beast/core/ostream.hpp>
|
||||
#include <boost/beast/core/read_size.hpp>
|
||||
#include <boost/beast/core/string.hpp>
|
||||
@@ -40,8 +41,6 @@ public:
|
||||
void
|
||||
testMembers()
|
||||
{
|
||||
using net::buffer_size;
|
||||
|
||||
string_view const s = "Hello, world!";
|
||||
|
||||
// flat_static_buffer_base
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include <boost/beast/core/make_printable.hpp>
|
||||
|
||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||
#include <boost/beast/core/buffer_size.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
@@ -25,7 +27,6 @@ public:
|
||||
void
|
||||
print (ConstBufferSequence const& buffers)
|
||||
{
|
||||
using net::buffer_size;
|
||||
std::cout <<
|
||||
"Buffer size: " << buffer_size(buffers) << " bytes\n"
|
||||
"Buffer data: '" << make_printable(buffers) << "'\n";
|
||||
@@ -40,8 +41,6 @@ public:
|
||||
void
|
||||
testMakePrintable()
|
||||
{
|
||||
using net::buffer;
|
||||
|
||||
char buf[13];
|
||||
buffers_triple b(buf, sizeof(buf));
|
||||
string_view src = "Hello, world!";
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "buffer_test.hpp"
|
||||
|
||||
#include <boost/beast/core/buffer_size.hpp>
|
||||
#include <boost/beast/core/ostream.hpp>
|
||||
#include <boost/beast/core/read_size.hpp>
|
||||
#include <boost/beast/core/string.hpp>
|
||||
@@ -577,8 +578,6 @@ public:
|
||||
void
|
||||
testMatrix1()
|
||||
{
|
||||
using net::buffer_size;
|
||||
|
||||
string_view s = "Hello, world";
|
||||
BEAST_EXPECT(s.size() == 12);
|
||||
for(std::size_t i = 1; i < 12; ++i) {
|
||||
@@ -621,8 +620,6 @@ public:
|
||||
testMatrix2()
|
||||
{
|
||||
using namespace test;
|
||||
using net::buffer;
|
||||
using net::buffer_size;
|
||||
std::string const s = "Hello, world";
|
||||
BEAST_EXPECT(s.size() == 12);
|
||||
for(std::size_t i = 1; i < 12; ++i) {
|
||||
@@ -649,7 +646,7 @@ public:
|
||||
{
|
||||
auto d = b.prepare(x);
|
||||
BEAST_EXPECT(buffer_size(d) == x);
|
||||
b.commit(buffer_copy(d, buffer(s.data(), x)));
|
||||
b.commit(buffer_copy(d, net::buffer(s.data(), x)));
|
||||
}
|
||||
BEAST_EXPECT(b.size() == x);
|
||||
BEAST_EXPECT(buffer_size(b.data()) == b.size());
|
||||
@@ -668,7 +665,7 @@ public:
|
||||
{
|
||||
auto d = b.prepare(y);
|
||||
BEAST_EXPECT(buffer_size(d) == y);
|
||||
b.commit(buffer_copy(d, buffer(s.data()+x, y)));
|
||||
b.commit(buffer_copy(d, net::buffer(s.data()+x, y)));
|
||||
}
|
||||
b.commit(1);
|
||||
BEAST_EXPECT(b.size() == x + y);
|
||||
@@ -688,7 +685,7 @@ public:
|
||||
{
|
||||
auto d = b.prepare(z);
|
||||
BEAST_EXPECT(buffer_size(d) == z);
|
||||
b.commit(buffer_copy(d, buffer(s.data()+x+y, z)));
|
||||
b.commit(buffer_copy(d, net::buffer(s.data()+x+y, z)));
|
||||
}
|
||||
b.commit(2);
|
||||
BEAST_EXPECT(b.size() == x + y + z);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "buffer_test.hpp"
|
||||
|
||||
#include <boost/beast/core/buffer_size.hpp>
|
||||
#include <boost/beast/core/ostream.hpp>
|
||||
#include <boost/beast/core/read_size.hpp>
|
||||
#include <boost/beast/core/string.hpp>
|
||||
@@ -44,8 +45,6 @@ public:
|
||||
void
|
||||
testMembers()
|
||||
{
|
||||
using net::buffer_size;
|
||||
|
||||
string_view const s = "Hello, world!";
|
||||
|
||||
// static_buffer_base
|
||||
|
||||
Reference in new issue
Block a user