Tidy up core sources:

The core headers are moved to their own directory (but remain in
the same namespace).
This commit is contained in:
Vinnie Falco
2016-05-07 14:57:15 -04:00
parent 2893f8c82a
commit e0956c36c1
120 changed files with 299 additions and 233 deletions

36
test/core/CMakeLists.txt Normal file
View File

@@ -0,0 +1,36 @@
# Part of Beast
GroupSources(extras/beast beast)
GroupSources(include/beast beast)
GroupSources(test/core "/")
add_executable (core-tests
${BEAST_INCLUDES}
../../extras/beast/unit_test/main.cpp
async_completion.cpp
basic_streambuf.cpp
bind_handler.cpp
buffer_cat.cpp
buffer_concepts.cpp
buffers_adapter.cpp
consuming_buffers.cpp
error.cpp
handler_alloc.cpp
handler_concepts.cpp
placeholders.cpp
prepare_buffers.cpp
static_streambuf.cpp
static_string.cpp
stream_concepts.cpp
streambuf.cpp
streambuf_readstream.cpp
to_string.cpp
write_streambuf.cpp
detail/base64.cpp
detail/empty_base_optimization.cpp
detail/sha1.cpp
)
if (NOT WIN32)
target_link_libraries(core-tests ${Boost_LIBRARIES})
endif()

View File

@@ -0,0 +1,9 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/async_completion.hpp>

View File

@@ -0,0 +1,415 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/basic_streambuf.hpp>
#include <beast/core/streambuf.hpp>
#include <beast/core/to_string.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/asio/buffer.hpp>
#include <algorithm>
#include <atomic>
#include <memory>
#include <string>
namespace beast {
struct test_allocator_info
{
std::size_t ncopy = 0;
std::size_t nmove = 0;
std::size_t nselect = 0;
};
template<class T,
bool Assign, bool Move, bool Swap, bool Select>
class test_allocator;
template<class T,
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>
{
static
test_allocator<T, Assign, Move, Swap, true>
select_on_container_copy_construction(
test_allocator<T, Assign, Move, Swap, true> const& a)
{
return test_allocator<T, Assign, Move, Swap, true>{};
}
};
template<class T,
bool Assign, bool Move, bool Swap, bool Select>
class test_allocator : public test_allocator_base<
T, Assign, Move, Swap, Select>
{
std::size_t id_;
std::shared_ptr<test_allocator_info> info_;
template<class, 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>;
template<class U>
struct rebind
{
using other = test_allocator<
U, Assign, Move, Swap, Select>;
};
test_allocator()
: id_([]
{
static std::atomic<
std::size_t> sid(0);
return ++sid;
}())
, info_(std::make_shared<test_allocator_info>())
{
}
test_allocator(test_allocator const& u) noexcept
: id_(u.id_)
, info_(u.info_)
{
++info_->ncopy;
}
template<class U>
test_allocator(test_allocator<
U, Assign, Move, Swap, Select> const& u) noexcept
: id_(u.id_)
, info_(u.info_)
{
++info_->ncopy;
}
test_allocator(test_allocator&& t)
: id_(t.id_)
, info_(t.info_)
{
++info_->nmove;
}
value_type*
allocate(std::size_t n)
{
return static_cast<value_type*>(
::operator new (n*sizeof(value_type)));
}
void
deallocate(value_type* p, std::size_t) noexcept
{
::operator delete(p);
}
std::size_t
id() const
{
return id_;
}
test_allocator_info const*
operator->() const
{
return info_.get();
}
};
class basic_streambuf_test : public beast::unit_test::suite
{
public:
template<class Alloc1, class Alloc2>
static
bool
eq(basic_streambuf<Alloc1> const& sb1,
basic_streambuf<Alloc2> const& sb2)
{
return to_string(sb1.data()) == to_string(sb2.data());
}
void testSpecialMembers()
{
using boost::asio::buffer;
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
std::string const s = "Hello, world";
expect(s.size() == 12);
for(std::size_t i = 1; i < 12; ++i) {
for(std::size_t x = 1; x < 4; ++x) {
for(std::size_t y = 1; y < 4; ++y) {
std::size_t z = s.size() - (x + y);
{
streambuf sb(i);
sb.commit(buffer_copy(sb.prepare(x), buffer(s.data(), x)));
sb.commit(buffer_copy(sb.prepare(y), buffer(s.data()+x, y)));
sb.commit(buffer_copy(sb.prepare(z), buffer(s.data()+x+y, z)));
expect(to_string(sb.data()) == s);
{
streambuf sb2(sb);
expect(eq(sb, sb2));
}
{
streambuf sb2;
sb2 = sb;
expect(eq(sb, sb2));
}
{
streambuf sb2(std::move(sb));
expect(to_string(sb2.data()) == s);
expect(buffer_size(sb.data()) == 0);
sb = std::move(sb2);
expect(to_string(sb.data()) == s);
expect(buffer_size(sb2.data()) == 0);
}
sb = sb;
sb = std::move(sb);
}
}}}
}
void testAllocator()
{
{
using alloc_type =
test_allocator<char, false, false, false, false>;
using sb_type = basic_streambuf<alloc_type>;
sb_type sb;
expect(sb.get_allocator().id() == 1);
}
{
using alloc_type =
test_allocator<char, false, false, false, false>;
using sb_type = basic_streambuf<alloc_type>;
sb_type sb;
expect(sb.get_allocator().id() == 2);
sb_type sb2(sb);
expect(sb2.get_allocator().id() == 2);
sb_type sb3(sb, alloc_type{});
//expect(sb3.get_allocator().id() == 3);
}
}
void
testPrepare()
{
using boost::asio::buffer_size;
{
streambuf sb(2);
expect(buffer_size(sb.prepare(5)) == 5);
expect(buffer_size(sb.prepare(8)) == 8);
expect(buffer_size(sb.prepare(7)) == 7);
}
{
streambuf sb(2);
sb.prepare(2);
{
auto const bs = sb.prepare(5);
expect(std::distance(
bs.begin(), bs.end()) == 2);
}
{
auto const bs = sb.prepare(8);
expect(std::distance(
bs.begin(), bs.end()) == 3);
}
{
auto const bs = sb.prepare(4);
expect(std::distance(
bs.begin(), bs.end()) == 2);
}
}
}
void testCommit()
{
using boost::asio::buffer_size;
streambuf sb(2);
sb.prepare(2);
sb.prepare(5);
sb.commit(1);
expect(buffer_size(sb.data()) == 1);
}
void testStreambuf()
{
using boost::asio::buffer;
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
std::string const s = "Hello, world";
expect(s.size() == 12);
for(std::size_t i = 1; i < 12; ++i) {
for(std::size_t x = 1; x < 4; ++x) {
for(std::size_t y = 1; y < 4; ++y) {
for(std::size_t t = 1; t < 4; ++ t) {
for(std::size_t u = 1; u < 4; ++ u) {
std::size_t z = s.size() - (x + y);
std::size_t v = s.size() - (t + u);
{
streambuf sb(i);
{
auto d = sb.prepare(z);
expect(buffer_size(d) == z);
}
{
auto d = sb.prepare(0);
expect(buffer_size(d) == 0);
}
{
auto d = sb.prepare(y);
expect(buffer_size(d) == y);
}
{
auto d = sb.prepare(x);
expect(buffer_size(d) == x);
sb.commit(buffer_copy(d, buffer(s.data(), x)));
}
expect(sb.size() == x);
expect(buffer_size(sb.data()) == sb.size());
{
auto d = sb.prepare(x);
expect(buffer_size(d) == x);
}
{
auto d = sb.prepare(0);
expect(buffer_size(d) == 0);
}
{
auto d = sb.prepare(z);
expect(buffer_size(d) == z);
}
{
auto d = sb.prepare(y);
expect(buffer_size(d) == y);
sb.commit(buffer_copy(d, buffer(s.data()+x, y)));
}
sb.commit(1);
expect(sb.size() == x + y);
expect(buffer_size(sb.data()) == sb.size());
{
auto d = sb.prepare(x);
expect(buffer_size(d) == x);
}
{
auto d = sb.prepare(y);
expect(buffer_size(d) == y);
}
{
auto d = sb.prepare(0);
expect(buffer_size(d) == 0);
}
{
auto d = sb.prepare(z);
expect(buffer_size(d) == z);
sb.commit(buffer_copy(d, buffer(s.data()+x+y, z)));
}
sb.commit(2);
expect(sb.size() == x + y + z);
expect(buffer_size(sb.data()) == sb.size());
expect(to_string(sb.data()) == s);
sb.consume(t);
{
auto d = sb.prepare(0);
expect(buffer_size(d) == 0);
}
expect(to_string(sb.data()) == s.substr(t, std::string::npos));
sb.consume(u);
expect(to_string(sb.data()) == s.substr(t + u, std::string::npos));
sb.consume(v);
expect(to_string(sb.data()) == "");
sb.consume(1);
{
auto d = sb.prepare(0);
expect(buffer_size(d) == 0);
}
}
}}}}}
}
void testIterators()
{
using boost::asio::buffer_size;
streambuf sb(1);
sb.prepare(1);
sb.commit(1);
sb.prepare(2);
sb.commit(2);
expect(buffer_size(sb.data()) == 3);
sb.prepare(1);
expect(buffer_size(sb.prepare(3)) == 3);
expect(read_size_helper(sb, 3) == 3);
sb.commit(2);
try
{
streambuf sb0(0);
fail();
}
catch(std::exception const&)
{
pass();
}
std::size_t n;
n = 0;
for(auto it = sb.data().begin();
it != sb.data().end(); it++)
++n;
expect(n == 4);
n = 0;
for(auto it = sb.data().begin();
it != sb.data().end(); ++it)
++n;
expect(n == 4);
n = 0;
for(auto it = sb.data().end();
it != sb.data().begin(); it--)
++n;
expect(n == 4);
n = 0;
for(auto it = sb.data().end();
it != sb.data().begin(); --it)
++n;
expect(n == 4);
}
void testOutputStream()
{
streambuf sb;
sb << "x";
expect(to_string(sb.data()) == "x");
}
void run() override
{
testSpecialMembers();
testAllocator();
testPrepare();
testCommit();
testStreambuf();
testIterators();
testOutputStream();
}
};
BEAST_DEFINE_TESTSUITE(basic_streambuf,core,beast);
} // beast

View File

@@ -0,0 +1,35 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/bind_handler.hpp>
#include <beast/unit_test/suite.hpp>
#include <functional>
namespace beast {
class bind_handler_test : public unit_test::suite
{
public:
static void foo (int)
{
}
void run()
{
auto f (bind_handler (
std::bind (&foo, std::placeholders::_1),
42));
f();
pass();
}
};
BEAST_DEFINE_TESTSUITE(bind_handler,core,beast);
} // beast

134
test/core/buffer_cat.cpp Normal file
View File

@@ -0,0 +1,134 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/buffer_cat.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/streambuf.hpp>
#include <iterator>
#include <list>
#include <vector>
namespace beast {
class buffer_cat_test : public unit_test::suite
{
public:
template< class Iterator >
static
std::reverse_iterator<Iterator>
make_reverse_iterator( Iterator i )
{
return std::reverse_iterator<Iterator>(i);
}
void testBufferCat()
{
using boost::asio::buffer_size;
using boost::asio::const_buffer;
char buf[10];
std::list<const_buffer> b1;
std::vector<const_buffer> b2{
const_buffer{buf+0, 1},
const_buffer{buf+1, 2}};
std::list<const_buffer> b3;
std::array<const_buffer, 3> b4{{
const_buffer{buf+3, 1},
const_buffer{buf+4, 2},
const_buffer{buf+6, 3}}};
std::list<const_buffer> b5{
const_buffer{buf+9, 1}};
std::list<const_buffer> b6;
auto bs = buffer_cat(
b1, b2, b3, b4, b5, b6);
expect(buffer_size(bs) == 10);
std::vector<const_buffer> v;
for(auto iter = make_reverse_iterator(bs.end());
iter != make_reverse_iterator(bs.begin()); ++iter)
v.emplace_back(*iter);
expect(buffer_size(bs) == 10);
decltype(bs) bs2(bs);
auto bs3(std::move(bs));
bs = bs2;
bs3 = std::move(bs2);
{
boost::asio::streambuf sb1, sb2;
expect(buffer_size(buffer_cat(
sb1.prepare(5), sb2.prepare(7))) == 12);
sb1.commit(5);
sb2.commit(7);
expect(buffer_size(buffer_cat(
sb1.data(), sb2.data())) == 12);
}
}
void testIterators()
{
using boost::asio::buffer_size;
using boost::asio::const_buffer;
char buf[9];
std::vector<const_buffer> b1{
const_buffer{buf+0, 1},
const_buffer{buf+1, 2}};
std::array<const_buffer, 3> b2{{
const_buffer{buf+3, 1},
const_buffer{buf+4, 2},
const_buffer{buf+6, 3}}};
auto bs = buffer_cat(b1, b2);
try
{
std::size_t n = 0;
for(auto it = bs.begin(); n < 100; ++it)
++n;
fail();
}
catch(std::exception const&)
{
pass();
}
try
{
std::size_t n = 0;
for(auto it = bs.end(); n < 100; --it)
++n;
fail();
}
catch(std::exception const&)
{
pass();
}
try
{
expect((buffer_size(*bs.end()) == 0, false));
}
catch(std::exception const&)
{
pass();
}
auto bs2 = bs;
expect(bs.begin() != bs2.begin());
expect(bs.end() != bs2.end());
decltype(bs)::const_iterator it;
decltype(bs2)::const_iterator it2;
expect(it == it2);
}
void run() override
{
testBufferCat();
testIterators();
}
};
BEAST_DEFINE_TESTSUITE(buffer_cat,core,beast);
} // beast

View File

@@ -0,0 +1,25 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/buffer_concepts.hpp>
namespace beast {
namespace {
struct T
{
};
}
static_assert(is_ConstBufferSequence<detail::ConstBufferSequence>::value, "");
static_assert(! is_ConstBufferSequence<T>::value, "");
static_assert(is_MutableBufferSequence<detail::MutableBufferSequence>::value, "");
static_assert(! is_MutableBufferSequence<T>::value, "");
} // beast

View File

@@ -0,0 +1,190 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/buffers_adapter.hpp>
#include <beast/core/streambuf.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/streambuf.hpp>
#include <iterator>
namespace beast {
class buffers_adapter_test : public unit_test::suite
{
public:
template<class ConstBufferSequence>
static
std::string
to_string(ConstBufferSequence const& bs)
{
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
std::string s;
s.reserve(buffer_size(bs));
for(auto const& b : bs)
s.append(buffer_cast<char const*>(b),
buffer_size(b));
return s;
}
void testBuffersAdapter()
{
using boost::asio::buffer;
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
using boost::asio::const_buffer;
using boost::asio::mutable_buffer;
char buf[12];
std::string const s = "Hello, world";
expect(s.size() == sizeof(buf));
for(std::size_t i = 1; i < 4; ++i) {
for(std::size_t j = 1; j < 4; ++j) {
for(std::size_t x = 1; x < 4; ++x) {
for(std::size_t y = 1; y < 4; ++y) {
for(std::size_t t = 1; t < 4; ++ t) {
for(std::size_t u = 1; u < 4; ++ u) {
std::size_t k = sizeof(buf) - (i + j);
std::size_t z = sizeof(buf) - (x + y);
std::size_t v = sizeof(buf) - (t + u);
{
std::memset(buf, 0, sizeof(buf));
std::array<mutable_buffer, 3> bs{{
mutable_buffer{&buf[0], i},
mutable_buffer{&buf[i], j},
mutable_buffer{&buf[i+j], k}}};
buffers_adapter<decltype(bs)> ba(std::move(bs));
expect(ba.max_size() == sizeof(buf));
{
auto d = ba.prepare(z);
expect(buffer_size(d) == z);
}
{
auto d = ba.prepare(0);
expect(buffer_size(d) == 0);
}
{
auto d = ba.prepare(y);
expect(buffer_size(d) == y);
}
{
auto d = ba.prepare(x);
expect(buffer_size(d) == x);
ba.commit(buffer_copy(d, buffer(s.data(), x)));
}
expect(ba.size() == x);
expect(ba.max_size() == sizeof(buf) - x);
expect(buffer_size(ba.data()) == ba.size());
{
auto d = ba.prepare(x);
expect(buffer_size(d) == x);
}
{
auto d = ba.prepare(0);
expect(buffer_size(d) == 0);
}
{
auto d = ba.prepare(z);
expect(buffer_size(d) == z);
}
{
auto d = ba.prepare(y);
expect(buffer_size(d) == y);
ba.commit(buffer_copy(d, buffer(s.data()+x, y)));
}
ba.commit(1);
expect(ba.size() == x + y);
expect(ba.max_size() == sizeof(buf) - (x + y));
expect(buffer_size(ba.data()) == ba.size());
{
auto d = ba.prepare(x);
expect(buffer_size(d) == x);
}
{
auto d = ba.prepare(y);
expect(buffer_size(d) == y);
}
{
auto d = ba.prepare(0);
expect(buffer_size(d) == 0);
}
{
auto d = ba.prepare(z); expect(buffer_size(d) == z);
ba.commit(buffer_copy(d, buffer(s.data()+x+y, z)));
}
ba.commit(2);
expect(ba.size() == x + y + z);
expect(ba.max_size() == 0);
expect(buffer_size(ba.data()) == ba.size());
expect(to_string(ba.data()) == s);
ba.consume(t);
{
auto d = ba.prepare(0);
expect(buffer_size(d) == 0);
}
expect(to_string(ba.data()) == s.substr(t, std::string::npos));
ba.consume(u);
expect(to_string(ba.data()) == s.substr(t + u, std::string::npos));
ba.consume(v);
expect(to_string(ba.data()) == "");
ba.consume(1);
{
auto d = ba.prepare(0);
expect(buffer_size(d) == 0);
}
try
{
ba.prepare(1);
fail();
}
catch(...)
{
pass();
}
}
}}}}}}
}
void testCommit()
{
using boost::asio::buffer_size;
{
using sb_type = boost::asio::streambuf;
sb_type sb;
buffers_adapter<
sb_type::mutable_buffers_type> ba(sb.prepare(3));
expect(buffer_size(ba.prepare(3)) == 3);
ba.commit(2);
expect(buffer_size(ba.data()) == 2);
}
{
using sb_type = beast::streambuf;
sb_type sb(2);
sb.prepare(3);
buffers_adapter<
sb_type::mutable_buffers_type> ba(sb.prepare(8));
expect(buffer_size(ba.prepare(8)) == 8);
ba.commit(2);
expect(buffer_size(ba.data()) == 2);
ba.consume(1);
ba.commit(6);
ba.consume(2);
expect(buffer_size(ba.data()) == 5);
ba.consume(5);
}
}
void run() override
{
testBuffersAdapter();
testCommit();
}
};
BEAST_DEFINE_TESTSUITE(buffers_adapter,core,beast);
} // beast

View File

@@ -0,0 +1,105 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/consuming_buffers.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/asio/buffer.hpp>
#include <string>
namespace beast {
class consuming_buffers_test : public beast::unit_test::suite
{
public:
template<class ConstBufferSequence>
static
std::string
to_string(ConstBufferSequence const& bs)
{
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
std::string s;
s.reserve(buffer_size(bs));
for(auto const& b : bs)
s.append(buffer_cast<char const*>(b),
buffer_size(b));
return s;
}
void testBuffers()
{
using boost::asio::buffer;
using boost::asio::const_buffer;
char buf[12];
std::string const s = "Hello, world";
expect(s.size() == sizeof(buf));
buffer_copy(buffer(buf), buffer(s));
expect(to_string(buffer(buf)) == s);
for(std::size_t i = 1; i < 4; ++i) {
for(std::size_t j = 1; j < 4; ++j) {
for(std::size_t x = 1; x < 4; ++x) {
for(std::size_t y = 1; y < 4; ++y) {
std::size_t k = sizeof(buf) - (i + j);
std::size_t z = sizeof(buf) - (x + y);
{
std::array<const_buffer, 3> bs{{
const_buffer{&buf[0], i},
const_buffer{&buf[i], j},
const_buffer{&buf[i+j], k}}};
consuming_buffers<decltype(bs)> cb(bs);
expect(to_string(cb) == s);
cb.consume(0);
expect(to_string(cb) == s);
cb.consume(x);
expect(to_string(cb) == s.substr(x));
cb.consume(y);
expect(to_string(cb) == s.substr(x+y));
cb.consume(z);
expect(to_string(cb) == "");
cb.consume(1);
expect(to_string(cb) == "");
}
}}}}
}
void testNullBuffers()
{
using boost::asio::buffer_copy;
using boost::asio::buffer_size;
using boost::asio::null_buffers;
consuming_buffers<null_buffers> cb(
null_buffers{});
expect(buffer_size(cb) == 0);
consuming_buffers<null_buffers> cb2(
null_buffers{});
expect(buffer_copy(cb2, cb) == 0);
}
void testIterator()
{
using boost::asio::const_buffer;
std::array<const_buffer, 3> ba;
consuming_buffers<decltype(ba)> cb(ba);
std::size_t n = 0;
for(auto it = cb.end(); it != cb.begin(); --it)
++n;
expect(n == 3);
}
void run() override
{
testBuffers();
testNullBuffers();
testIterator();
}
};
BEAST_DEFINE_TESTSUITE(consuming_buffers,core,beast);
} // beast

View File

@@ -0,0 +1,44 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/detail/base64.hpp>
#include <beast/unit_test/suite.hpp>
namespace beast {
namespace detail {
class base64_test : public beast::unit_test::suite
{
public:
void
check (std::string const& in, std::string const& out)
{
auto const encoded = base64_encode (in);
expect (encoded == out);
expect (base64_decode (encoded) == in);
}
void
run()
{
check ("", "");
check ("f", "Zg==");
check ("fo", "Zm8=");
check ("foo", "Zm9v");
check ("foob", "Zm9vYg==");
check ("fooba", "Zm9vYmE=");
check ("foobar", "Zm9vYmFy");
}
};
BEAST_DEFINE_TESTSUITE(base64,core,beast);
} // detail
} // beast

View File

@@ -0,0 +1,94 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/detail/empty_base_optimization.hpp>
#include <beast/unit_test/suite.hpp>
namespace beast {
namespace detail {
class empty_base_optimization_test
: public beast::unit_test::suite
{
public:
template <class T>
class test1
: private empty_base_optimization<T>
{
using Base = empty_base_optimization<T>;
void* m_p;
public:
explicit test1 (T const& t)
: Base (t)
{}
T& member() {return Base::member();}
T const& member() const {return Base::member();}
};
template <class T>
class test2
{
void* m_p;
T m_t;
public:
explicit test2 (T const& t)
: m_t (t)
{}
T& member() {return m_t;}
T const& member() const {return m_t;}
};
struct Empty
{
operator bool() {return true;}
};
static
bool
test_one ()
{
test1<int> t1(1);
test2<int> t2(2);
static_assert(sizeof(t1) == sizeof(t2), "don't optimize for int");
if (t1.member() != 1)
return false;
if (t2.member() != 2)
return false;
return true;
}
static
bool
test_two ()
{
test1<Empty> t1((Empty()));
test2<Empty> t2((Empty()));
static_assert(sizeof(t1) < sizeof(t2), "do optimize for Empty");
if (t1.member() != true)
return false;
if (t2.member() != true)
return false;
return true;
}
void
run ()
{
expect (test_one());
expect (test_two());
pass ();
}
};
BEAST_DEFINE_TESTSUITE(empty_base_optimization,core,beast);
} // detail
} // beast

80
test/core/detail/sha1.cpp Normal file
View File

@@ -0,0 +1,80 @@
//
// Copyright (c) 2013-2016 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)
//
#include <beast/core/detail/sha1.hpp>
#include <beast/unit_test/suite.hpp>
#include <array>
namespace beast {
namespace detail {
class sha1_test : public beast::unit_test::suite
{
public:
static
inline
std::uint8_t
unhex(char c)
{
if(c >= '0' && c <= '9')
return c - '0';
if(c >= 'a' && c <= 'f')
return c - 'a' + 10;
if(c >= 'A' && c <= 'F')
return c - 'A' + 10;
throw std::invalid_argument("not a hex digit");
}
static
std::string
unhex(std::string const& in)
{
std::string out;
out.reserve(in.size() / 2);
if(in.size() % 2)
throw std::domain_error("invalid hex string");
for(std::size_t i = 0; i < in.size(); i += 2)
out.push_back(
(unhex(in[i])<<4) + unhex(in[i+1]));
return out;
}
void
check(std::string const& message, std::string const& answer)
{
std::string digest;
digest = unhex(answer);
sha1_context ctx;
std::string result;
result.resize(sha1_context::digest_size);
init(ctx);
update(ctx, message.data(), message.size());
finish(ctx, &result[0]);
expect(result == digest);
}
void
run()
{
// http://www.di-mgt.com.au/sha_testvectors.html
//
check("abc",
"a9993e36" "4706816a" "ba3e2571" "7850c26c" "9cd0d89d");
check("",
"da39a3ee" "5e6b4b0d" "3255bfef" "95601890" "afd80709");
check("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"84983e44" "1c3bd26e" "baae4aa1" "f95129e5" "e54670f1");
check("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
"a49b2446" "a02c645b" "f419f995" "b6709125" "3a04a259");
}
};
BEAST_DEFINE_TESTSUITE(sha1,core,beast);
} // test
} // beast

9
test/core/error.cpp Normal file
View File

@@ -0,0 +1,9 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/error.hpp>

View File

@@ -0,0 +1,28 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/to_string.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/asio/buffer.hpp>
namespace beast {
class to_string_test : public beast::unit_test::suite
{
public:
void run()
{
expect(to_string(boost::asio::const_buffers_1("x", 1)) == "x");
}
};
BEAST_DEFINE_TESTSUITE(to_string,core,beast);
} // beast

View File

@@ -0,0 +1,23 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/handler_concepts.hpp>
namespace beast {
namespace {
struct T
{
void operator()(int);
};
}
static_assert(is_CompletionHandler<T, void(int)>::value, "");
static_assert(! is_CompletionHandler<T, void(void)>::value, "");
} // beast

View File

@@ -0,0 +1,9 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/placeholders.hpp>

View File

@@ -0,0 +1,115 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/prepare_buffers.hpp>
#include <beast/core/consuming_buffers.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/asio/buffer.hpp>
#include <string>
namespace beast {
class prepare_buffers_test : public beast::unit_test::suite
{
public:
template<class ConstBufferSequence>
static
std::string
to_string(ConstBufferSequence const& bs)
{
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
std::string s;
s.reserve(buffer_size(bs));
for(auto const& b : bs)
s.append(buffer_cast<char const*>(b),
buffer_size(b));
return s;
}
void testBuffers()
{
using boost::asio::buffer_size;
using boost::asio::const_buffer;
std::string const s = "Hello, world";
expect(s.size() == 12);
for(std::size_t x = 1; x < 4; ++x) {
for(std::size_t y = 1; y < 4; ++y) {
std::size_t z = s.size() - (x + y);
{
std::array<const_buffer, 3> bs{{
const_buffer{&s[0], x},
const_buffer{&s[x], y},
const_buffer{&s[x+y], z}}};
for(std::size_t i = 0; i <= s.size() + 1; ++i)
{
auto pb = prepare_buffers(i, bs);
expect(to_string(pb) == s.substr(0, i));
auto pb2 = pb;
expect(to_string(pb2) == to_string(pb));
pb = prepare_buffers(0, bs);
pb2 = pb;
expect(buffer_size(pb2) == 0);
pb2 = prepare_buffers(i, bs);
expect(to_string(pb2) == s.substr(0, i));
}
}
}}
}
void testNullBuffers()
{
using boost::asio::buffer_copy;
using boost::asio::buffer_size;
using boost::asio::null_buffers;
auto pb0 = prepare_buffers(0, null_buffers{});
expect(buffer_size(pb0) == 0);
auto pb1 = prepare_buffers(1, null_buffers{});
expect(buffer_size(pb1) == 0);
expect(buffer_copy(pb0, pb1) == 0);
using pb_type = decltype(pb0);
consuming_buffers<pb_type> cb(pb0);
expect(buffer_size(cb) == 0);
expect(buffer_copy(cb, pb1) == 0);
cb.consume(1);
expect(buffer_size(cb) == 0);
expect(buffer_copy(cb, pb1) == 0);
auto pbc = prepare_buffers(2, cb);
expect(buffer_size(pbc) == 0);
expect(buffer_copy(pbc, cb) == 0);
}
void testIterator()
{
using boost::asio::const_buffer;
char b[3];
std::array<const_buffer, 3> bs{{
const_buffer{&b[0], 1},
const_buffer{&b[1], 1},
const_buffer{&b[2], 1}}};
auto pb = prepare_buffers(2, bs);
std::size_t n = 0;
for(auto it = pb.end(); it != pb.begin(); --it)
++n;
expect(n == 2);
}
void run() override
{
testBuffers();
testNullBuffers();
testIterator();
}
};
BEAST_DEFINE_TESTSUITE(prepare_buffers,core,beast);
} // beast

View File

@@ -0,0 +1,206 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/static_streambuf.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/asio/buffer.hpp>
#include <string>
namespace beast {
class static_streambuf_test : public beast::unit_test::suite
{
public:
template<class ConstBufferSequence>
static
std::string
to_string(ConstBufferSequence const& bs)
{
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
std::string s;
s.reserve(buffer_size(bs));
for(auto const& b : bs)
s.append(buffer_cast<char const*>(b),
buffer_size(b));
return s;
}
void testStaticStreambuf()
{
using boost::asio::buffer;
using boost::asio::buffer_cast;
using boost::asio::buffer_size;
char buf[12];
std::string const s = "Hello, world";
expect(s.size() == sizeof(buf));
for(std::size_t i = 1; i < 4; ++i) {
for(std::size_t j = 1; j < 4; ++j) {
for(std::size_t x = 1; x < 4; ++x) {
for(std::size_t y = 1; y < 4; ++y) {
for(std::size_t t = 1; t < 4; ++ t) {
for(std::size_t u = 1; u < 4; ++ u) {
std::size_t z = sizeof(buf) - (x + y);
std::size_t v = sizeof(buf) - (t + u);
{
std::memset(buf, 0, sizeof(buf));
static_streambuf_n<sizeof(buf)> ba;
{
auto d = ba.prepare(z);
expect(buffer_size(d) == z);
}
{
auto d = ba.prepare(0);
expect(buffer_size(d) == 0);
}
{
auto d = ba.prepare(y);
expect(buffer_size(d) == y);
}
{
auto d = ba.prepare(x);
expect(buffer_size(d) == x);
ba.commit(buffer_copy(d, buffer(s.data(), x)));
}
expect(ba.size() == x);
expect(buffer_size(ba.data()) == ba.size());
{
auto d = ba.prepare(x);
expect(buffer_size(d) == x);
}
{
auto d = ba.prepare(0);
expect(buffer_size(d) == 0);
}
{
auto d = ba.prepare(z);
expect(buffer_size(d) == z);
}
{
auto d = ba.prepare(y);
expect(buffer_size(d) == y);
ba.commit(buffer_copy(d, buffer(s.data()+x, y)));
}
ba.commit(1);
expect(ba.size() == x + y);
expect(buffer_size(ba.data()) == ba.size());
{
auto d = ba.prepare(x);
expect(buffer_size(d) == x);
}
{
auto d = ba.prepare(y);
expect(buffer_size(d) == y);
}
{
auto d = ba.prepare(0);
expect(buffer_size(d) == 0);
}
{
auto d = ba.prepare(z);
expect(buffer_size(d) == z);
ba.commit(buffer_copy(d, buffer(s.data()+x+y, z)));
}
ba.commit(2);
expect(ba.size() == x + y + z);
expect(buffer_size(ba.data()) == ba.size());
expect(to_string(ba.data()) == s);
ba.consume(t);
{
auto d = ba.prepare(0);
expect(buffer_size(d) == 0);
}
expect(to_string(ba.data()) == s.substr(t, std::string::npos));
ba.consume(u);
expect(to_string(ba.data()) == s.substr(t + u, std::string::npos));
ba.consume(v);
expect(to_string(ba.data()) == "");
ba.consume(1);
{
auto d = ba.prepare(0);
expect(buffer_size(d) == 0);
}
try
{
ba.prepare(1);
fail();
}
catch(...)
{
pass();
}
}
}}}}}}
}
void testIterators()
{
static_streambuf_n<2> ba;
{
auto mb = ba.prepare(2);
std::size_t n;
n = 0;
for(auto it = mb.begin();
it != mb.end(); it++)
++n;
expect(n == 1);
mb = ba.prepare(2);
n = 0;
for(auto it = mb.begin();
it != mb.end(); ++it)
++n;
expect(n == 1);
mb = ba.prepare(2);
n = 0;
for(auto it = mb.end();
it != mb.begin(); it--)
++n;
expect(n == 1);
mb = ba.prepare(2);
n = 0;
for(auto it = mb.end();
it != mb.begin(); --it)
++n;
expect(n == 1);
}
ba.prepare(2);
ba.commit(1);
std::size_t n;
n = 0;
for(auto it = ba.data().begin();
it != ba.data().end(); it++)
++n;
expect(n == 1);
n = 0;
for(auto it = ba.data().begin();
it != ba.data().end(); ++it)
++n;
expect(n == 1);
n = 0;
for(auto it = ba.data().end();
it != ba.data().begin(); it--)
++n;
expect(n == 1);
n = 0;
for(auto it = ba.data().end();
it != ba.data().begin(); --it)
++n;
expect(n == 1);
}
void run() override
{
testStaticStreambuf();
testIterators();
}
};
BEAST_DEFINE_TESTSUITE(static_streambuf,core,beast);
} // beastp

263
test/core/static_string.cpp Normal file
View File

@@ -0,0 +1,263 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/static_string.hpp>
#include <beast/unit_test/suite.hpp>
namespace beast {
class static_string_test : public beast::unit_test::suite
{
public:
void testMembers()
{
using str1 = static_string<1>;
using str2 = static_string<2>;
{
str1 s1;
expect(s1 == "");
expect(s1.empty());
expect(s1.size() == 0);
expect(s1.max_size() == 1);
expect(s1.capacity() == 1);
expect(s1.begin() == s1.end());
expect(s1.cbegin() == s1.cend());
expect(s1.rbegin() == s1.rend());
expect(s1.crbegin() == s1.crend());
try
{
expect(s1.at(0) == 0);
fail();
}
catch(std::exception const&)
{
pass();
}
expect(s1.data()[0] == 0);
expect(*s1.c_str() == 0);
expect(std::distance(s1.begin(), s1.end()) == 0);
expect(std::distance(s1.cbegin(), s1.cend()) == 0);
expect(std::distance(s1.rbegin(), s1.rend()) == 0);
expect(std::distance(s1.crbegin(), s1.crend()) == 0);
expect(s1.compare(s1) == 0);
expect(s1.to_string() == std::string{});
}
{
str1 const s1;
expect(s1 == "");
expect(s1.empty());
expect(s1.size() == 0);
expect(s1.max_size() == 1);
expect(s1.capacity() == 1);
expect(s1.begin() == s1.end());
expect(s1.cbegin() == s1.cend());
expect(s1.rbegin() == s1.rend());
expect(s1.crbegin() == s1.crend());
try
{
expect(s1.at(0) == 0);
fail();
}
catch(std::exception const&)
{
pass();
}
expect(s1.data()[0] == 0);
expect(*s1.c_str() == 0);
expect(std::distance(s1.begin(), s1.end()) == 0);
expect(std::distance(s1.cbegin(), s1.cend()) == 0);
expect(std::distance(s1.rbegin(), s1.rend()) == 0);
expect(std::distance(s1.crbegin(), s1.crend()) == 0);
expect(s1.compare(s1) == 0);
expect(s1.to_string() == std::string{});
}
{
str1 s1;
str1 s2("x");
expect(s2 == "x");
expect(s2[0] == 'x');
expect(s2.at(0) == 'x');
expect(s2.front() == 'x');
expect(s2.back() == 'x');
str1 const s3(s2);
expect(s3 == "x");
expect(s3[0] == 'x');
expect(s3.at(0) == 'x');
expect(s3.front() == 'x');
expect(s3.back() == 'x');
s2 = "y";
expect(s2 == "y");
expect(s3 == "x");
s1 = s2;
expect(s1 == "y");
s1.clear();
expect(s1.empty());
expect(s1.size() == 0);
}
{
str2 s1("x");
str1 s2(s1);
expect(s2 == "x");
str1 s3;
s3 = s2;
expect(s3 == "x");
s1 = "xy";
expect(s1.size() == 2);
expect(s1[0] == 'x');
expect(s1[1] == 'y');
expect(s1.at(0) == 'x');
expect(s1.at(1) == 'y');
expect(s1.front() == 'x');
expect(s1.back() == 'y');
auto const s4 = s1;
expect(s4[0] == 'x');
expect(s4[1] == 'y');
expect(s4.at(0) == 'x');
expect(s4.at(1) == 'y');
expect(s4.front() == 'x');
expect(s4.back() == 'y');
try
{
s3 = s1;
fail();
}
catch(std::exception const&)
{
pass();
}
try
{
str1 s5(s1);
fail();
}
catch(std::exception const&)
{
pass();
}
}
{
str1 s1("x");
str2 s2;
s2 = s1;
try
{
s1.resize(2);
fail();
}
catch(std::length_error const&)
{
pass();
}
}
pass();
}
void testCompare()
{
using str1 = static_string<1>;
using str2 = static_string<2>;
{
str1 s1;
str2 s2;
s1 = "1";
s2 = "22";
expect(s1.compare(s2) < 0);
expect(s2.compare(s1) > 0);
expect(s1 < "10");
expect(s2 > "1");
expect("10" > s1);
expect("1" < s2);
expect(s1 < "20");
expect(s2 > "1");
expect(s2 > "2");
}
{
str2 s1("x");
str2 s2("x");
expect(s1 == s2);
expect(s1 <= s2);
expect(s1 >= s2);
expect(! (s1 < s2));
expect(! (s1 > s2));
expect(! (s1 != s2));
}
{
str1 s1("x");
str2 s2("x");
expect(s1 == s2);
expect(s1 <= s2);
expect(s1 >= s2);
expect(! (s1 < s2));
expect(! (s1 > s2));
expect(! (s1 != s2));
}
{
str2 s("x");
expect(s == "x");
expect(s <= "x");
expect(s >= "x");
expect(! (s < "x"));
expect(! (s > "x"));
expect(! (s != "x"));
expect("x" == s);
expect("x" <= s);
expect("x" >= s);
expect(! ("x" < s));
expect(! ("x" > s));
expect(! ("x" != s));
}
{
str2 s("x");
expect(s <= "y");
expect(s < "y");
expect(s != "y");
expect(! (s == "y"));
expect(! (s >= "y"));
expect(! (s > "x"));
expect("y" >= s);
expect("y" > s);
expect("y" != s);
expect(! ("y" == s));
expect(! ("y" <= s));
expect(! ("y" < s));
}
{
str1 s1("x");
str2 s2("y");
expect(s1 <= s2);
expect(s1 < s2);
expect(s1 != s2);
expect(! (s1 == s2));
expect(! (s1 >= s2));
expect(! (s1 > s2));
}
{
str1 s1("x");
str2 s2("xx");
expect(s1 < s2);
expect(s2 > s1);
}
{
str1 s1("x");
str2 s2("yy");
expect(s1 < s2);
expect(s2 > s1);
}
}
void run() override
{
testMembers();
testCompare();
}
};
BEAST_DEFINE_TESTSUITE(static_string,core,beast);
} // beast

View File

@@ -0,0 +1,30 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/stream_concepts.hpp>
#include <boost/asio/ip/tcp.hpp>
namespace beast {
using stream_type = boost::asio::ip::tcp::socket;
static_assert(has_get_io_service<stream_type>::value, "");
static_assert(is_AsyncReadStream<stream_type>::value, "");
static_assert(is_AsyncWriteStream<stream_type>::value, "");
static_assert(is_AsyncStream<stream_type>::value, "");
static_assert(is_SyncReadStream<stream_type>::value, "");
static_assert(is_SyncWriteStream<stream_type>::value, "");
static_assert(is_SyncStream<stream_type>::value, "");
static_assert(! has_get_io_service<int>::value, "");
static_assert(! is_AsyncReadStream<int>::value, "");
static_assert(! is_AsyncWriteStream<int>::value, "");
static_assert(! is_SyncReadStream<int>::value, "");
static_assert(! is_SyncWriteStream<int>::value, "");
} // beast

9
test/core/streambuf.cpp Normal file
View File

@@ -0,0 +1,9 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/streambuf.hpp>

View File

@@ -0,0 +1,48 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/streambuf_readstream.hpp>
#include <beast/core/streambuf.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/asio.hpp>
namespace beast {
class streambuf_readstream_test : public beast::unit_test::suite
{
public:
void testSpecial()
{
using socket_type = boost::asio::ip::tcp::socket;
boost::asio::io_service ios;
{
streambuf_readstream<socket_type, streambuf> srs(ios);
streambuf_readstream<socket_type, streambuf> srs2(std::move(srs));
srs = std::move(srs2);
expect(&srs.get_io_service() == &ios);
expect(&srs.get_io_service() == &srs2.get_io_service());
}
{
socket_type sock(ios);
streambuf_readstream<socket_type&, streambuf> srs(sock);
streambuf_readstream<socket_type&, streambuf> srs2(std::move(srs));
}
pass();
}
void run() override
{
testSpecial();
}
};
BEAST_DEFINE_TESTSUITE(streambuf_readstream,core,beast);
} // beast

10
test/core/to_string.cpp Normal file
View File

@@ -0,0 +1,10 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/to_string.hpp>

View File

@@ -0,0 +1,36 @@
//
// Copyright (c) 2013-2016 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)
//
// Test that header file is self-contained.
#include <beast/core/write_streambuf.hpp>
#include <beast/core/streambuf.hpp>
#include <beast/unit_test/suite.hpp>
namespace beast {
class write_streambuf_test : public beast::unit_test::suite
{
public:
void run() override
{
streambuf sb;
std::string s;
write(sb, boost::asio::const_buffer{"", 0});
write(sb, boost::asio::mutable_buffer{nullptr, 0});
write(sb, boost::asio::null_buffers{});
write(sb, boost::asio::const_buffers_1{"", 0});
write(sb, boost::asio::mutable_buffers_1{nullptr, 0});
write(sb, s);
write(sb, 23);
pass();
}
};
BEAST_DEFINE_TESTSUITE(write_streambuf,core,beast);
} // beast