diff --git a/src/ripple/beast/test/fail_counter.h b/src/ripple/beast/test/fail_counter.h index 8c577cbea..8a11602e2 100644 --- a/src/ripple/beast/test/fail_counter.h +++ b/src/ripple/beast/test/fail_counter.h @@ -8,16 +8,13 @@ #ifndef BEAST_TEST_FAIL_COUNTER_HPP #define BEAST_TEST_FAIL_COUNTER_HPP -#include #include +#include namespace beast { namespace test { -enum class error -{ - fail_error = 1 -}; +enum class error { fail_error = 1 }; namespace detail { @@ -33,11 +30,11 @@ public: std::string message(int ev) const override { - switch(static_cast(ev)) + switch (static_cast(ev)) { - default: - case error::fail_error: - return "test error"; + default: + case error::fail_error: + return "test error"; } } @@ -48,39 +45,34 @@ public: } bool - equivalent(int ev, - boost::system::error_condition const& condition - ) const noexcept override + equivalent(int ev, boost::system::error_condition const& condition) + const noexcept override { - return condition.value() == ev && - &condition.category() == this; + return condition.value() == ev && &condition.category() == this; } bool equivalent(error_code const& error, int ev) const noexcept override { - return error.value() == ev && - &error.category() == this; + return error.value() == ev && &error.category() == this; } }; -inline -boost::system::error_category const& +inline boost::system::error_category const& get_error_category() { static fail_error_category const cat{}; return cat; } -} // detail +} // namespace detail -inline -error_code +inline error_code make_error_code(error ev) { return error_code{ static_cast::type>(ev), - detail::get_error_category()}; + detail::get_error_category()}; } /** An error code with an error set on default construction @@ -91,12 +83,11 @@ make_error_code(error ev) */ struct fail_error_code : error_code { - fail_error_code() - : error_code(make_error_code(error::fail_error)) + fail_error_code() : error_code(make_error_code(error::fail_error)) { } - template + template fail_error_code(Arg0&& arg0, ArgN&&... argn) : error_code(arg0, std::forward(argn)...) { @@ -120,11 +111,10 @@ public: @param The 0-based index of the operation to fail on or after. */ - explicit - fail_counter(std::size_t n, - error_code ev = make_error_code(error::fail_error)) - : n_(n) - , ec_(ev) + explicit fail_counter( + std::size_t n, + error_code ev = make_error_code(error::fail_error)) + : n_(n), ec_(ev) { } @@ -132,9 +122,9 @@ public: void fail() { - if(n_ > 0) + if (n_ > 0) --n_; - if(! n_) + if (!n_) BOOST_THROW_EXCEPTION(system_error{ec_}); } @@ -142,9 +132,9 @@ public: bool fail(error_code& ec) { - if(n_ > 0) + if (n_ > 0) --n_; - if(! n_) + if (!n_) { ec = ec_; return true; @@ -154,17 +144,17 @@ public: } }; -} // test -} // beast +} // namespace test +} // namespace beast namespace boost { namespace system { -template<> +template <> struct is_error_code_enum { static bool const value = true; }; -} // system -} // boost +} // namespace system +} // namespace boost #endif diff --git a/src/ripple/beast/test/fail_stream.h b/src/ripple/beast/test/fail_stream.h index c4b38538b..a1465f006 100644 --- a/src/ripple/beast/test/fail_stream.h +++ b/src/ripple/beast/test/fail_stream.h @@ -8,13 +8,13 @@ #ifndef BEAST_TEST_FAIL_STREAM_HPP #define BEAST_TEST_FAIL_STREAM_HPP +#include #include #include -#include #include -#include +#include #include -#include +#include namespace beast { namespace test { @@ -24,7 +24,7 @@ namespace test { On the Nth operation, the stream will fail with the specified error code, or the default error code of invalid_argument. */ -template +template class fail_stream { boost::optional fc_; @@ -32,31 +32,26 @@ class fail_stream NextLayer next_layer_; public: - using next_layer_type = - typename std::remove_reference::type; + using next_layer_type = typename std::remove_reference::type; - using lowest_layer_type = - typename get_lowest_layer::type; + using lowest_layer_type = typename get_lowest_layer::type; fail_stream(fail_stream&&) = delete; fail_stream(fail_stream const&) = delete; - fail_stream& operator=(fail_stream&&) = delete; - fail_stream& operator=(fail_stream const&) = delete; + fail_stream& + operator=(fail_stream&&) = delete; + fail_stream& + operator=(fail_stream const&) = delete; - template - explicit - fail_stream(std::size_t n, Args&&... args) - : fc_(n) - , pfc_(&*fc_) - , next_layer_(std::forward(args)...) + template + explicit fail_stream(std::size_t n, Args&&... args) + : fc_(n), pfc_(&*fc_), next_layer_(std::forward(args)...) { } - template - explicit - fail_stream(fail_counter& fc, Args&&... args) - : pfc_(&fc) - , next_layer_(std::forward(args)...) + template + explicit fail_stream(fail_counter& fc, Args&&... args) + : pfc_(&fc), next_layer_(std::forward(args)...) { } @@ -84,7 +79,7 @@ public: return next_layer_.get_io_service(); } - template + template std::size_t read_some(MutableBufferSequence const& buffers) { @@ -92,35 +87,33 @@ public: return next_layer_.read_some(buffers); } - template + template std::size_t read_some(MutableBufferSequence const& buffers, error_code& ec) { - if(pfc_->fail(ec)) + if (pfc_->fail(ec)) return 0; return next_layer_.read_some(buffers, ec); } - template - async_return_type< - ReadHandler, void(error_code, std::size_t)> - async_read_some(MutableBufferSequence const& buffers, - ReadHandler&& handler) + template + async_return_type + async_read_some(MutableBufferSequence const& buffers, ReadHandler&& handler) { error_code ec; - if(pfc_->fail(ec)) + if (pfc_->fail(ec)) { - async_completion init{handler}; + async_completion init{ + handler}; next_layer_.get_io_service().post( bind_handler(init.completion_handler, ec, 0)); return init.result.get(); } - return next_layer_.async_read_some(buffers, - std::forward(handler)); + return next_layer_.async_read_some( + buffers, std::forward(handler)); } - template + template std::size_t write_some(ConstBufferSequence const& buffers) { @@ -128,57 +121,54 @@ public: return next_layer_.write_some(buffers); } - template + template std::size_t write_some(ConstBufferSequence const& buffers, error_code& ec) { - if(pfc_->fail(ec)) + if (pfc_->fail(ec)) return 0; return next_layer_.write_some(buffers, ec); } - template - async_return_type< - WriteHandler, void(error_code, std::size_t)> - async_write_some(ConstBufferSequence const& buffers, - WriteHandler&& handler) + template + async_return_type + async_write_some(ConstBufferSequence const& buffers, WriteHandler&& handler) { error_code ec; - if(pfc_->fail(ec)) + if (pfc_->fail(ec)) { - async_completion init{handler}; + async_completion init{ + handler}; next_layer_.get_io_service().post( bind_handler(init.completion_handler, ec, 0)); return init.result.get(); } - return next_layer_.async_write_some(buffers, - std::forward(handler)); + return next_layer_.async_write_some( + buffers, std::forward(handler)); } - friend - void - teardown(websocket::teardown_tag, + friend void + teardown( + websocket::teardown_tag, fail_stream& stream, - boost::system::error_code& ec) + boost::system::error_code& ec) { - if(stream.pfc_->fail(ec)) + if (stream.pfc_->fail(ec)) return; beast::websocket_helpers::call_teardown(stream.next_layer(), ec); } - template - friend - void - async_teardown(websocket::teardown_tag, + template + friend void + async_teardown( + websocket::teardown_tag, fail_stream& stream, - TeardownHandler&& handler) + TeardownHandler&& handler) { error_code ec; - if(stream.pfc_->fail(ec)) + if (stream.pfc_->fail(ec)) { - stream.get_io_service().post( - bind_handler(std::move(handler), ec)); + stream.get_io_service().post(bind_handler(std::move(handler), ec)); return; } beast::websocket_helpers::call_async_teardown( @@ -186,7 +176,7 @@ public: } }; -} // test -} // beast +} // namespace test +} // namespace beast #endif diff --git a/src/ripple/beast/test/pipe_stream.h b/src/ripple/beast/test/pipe_stream.h index dfaef479b..1aaaadfa4 100644 --- a/src/ripple/beast/test/pipe_stream.h +++ b/src/ripple/beast/test/pipe_stream.h @@ -8,17 +8,17 @@ #ifndef BEAST_TEST_PIPE_STREAM_HPP #define BEAST_TEST_PIPE_STREAM_HPP +#include +#include +#include +#include #include #include #include #include #include -#include #include -#include -#include -#include -#include +#include #include #include #include @@ -46,7 +46,8 @@ private: struct read_op { virtual ~read_op() = default; - virtual void operator()() = 0; + virtual void + operator()() = 0; }; struct state @@ -69,24 +70,18 @@ public: { friend class pipe; - template + template class read_op_impl; state& in_; state& out_; boost::asio::io_service& ios_; fail_counter* fc_ = nullptr; - std::size_t read_max_ = - (std::numeric_limits::max)(); - std::size_t write_max_ = - (std::numeric_limits::max)(); + std::size_t read_max_ = (std::numeric_limits::max)(); + std::size_t write_max_ = (std::numeric_limits::max)(); - stream(state& in, state& out, - boost::asio::io_service& ios) - : in_(in) - , out_(out) - , ios_(ios) - , buffer(in_.b) + stream(state& in, state& out, boost::asio::io_service& ios) + : in_(in), out_(out), ios_(ios), buffer(in_.b) { } @@ -148,8 +143,7 @@ public: void clear() { - in_.b.consume((std::numeric_limits< - std::size_t>::max)()); + in_.b.consume((std::numeric_limits::max)()); } /** Close the stream. @@ -157,57 +151,56 @@ public: The other end of the pipe will see `boost::asio::error::eof` on read. */ - template + template void close(); - template + template std::size_t read_some(MutableBufferSequence const& buffers); - template + template std::size_t - read_some(MutableBufferSequence const& buffers, - error_code& ec); + read_some(MutableBufferSequence const& buffers, error_code& ec); - template - async_return_type< - ReadHandler, void(error_code, std::size_t)> - async_read_some(MutableBufferSequence const& buffers, + template + async_return_type + async_read_some( + MutableBufferSequence const& buffers, ReadHandler&& handler); - template + template std::size_t write_some(ConstBufferSequence const& buffers); - template + template std::size_t - write_some( - ConstBufferSequence const& buffers, error_code&); + write_some(ConstBufferSequence const& buffers, error_code&); - template - async_return_type< - WriteHandler, void(error_code, std::size_t)> - async_write_some(ConstBufferSequence const& buffers, + template + async_return_type + async_write_some( + ConstBufferSequence const& buffers, WriteHandler&& handler); - friend - void - teardown(websocket::teardown_tag, - stream&, boost::system::error_code& ec) + friend void + teardown( + websocket::teardown_tag, + stream&, + boost::system::error_code& ec) { ec.assign(0, ec.category()); } - template - friend - void - async_teardown(websocket::teardown_tag, - stream& s, TeardownHandler&& handler) + template + friend void + async_teardown( + websocket::teardown_tag, + stream& s, + TeardownHandler&& handler) { s.get_io_service().post( - bind_handler(std::move(handler), - error_code{})); + bind_handler(std::move(handler), error_code{})); } }; @@ -215,10 +208,8 @@ public: The client and server endpoints will use the same `io_service`. */ - explicit - pipe(boost::asio::io_service& ios) - : client(s_[0], s_[1], ios) - , server(s_[1], s_[0], ios) + explicit pipe(boost::asio::io_service& ios) + : client(s_[0], s_[1], ios), server(s_[1], s_[0], ios) { } @@ -226,11 +217,8 @@ public: The client and server endpoints will different `io_service` objects. */ - explicit - pipe(boost::asio::io_service& ios1, - boost::asio::io_service& ios2) - : client(s_[0], s_[1], ios1) - , server(s_[1], s_[0], ios2) + explicit pipe(boost::asio::io_service& ios1, boost::asio::io_service& ios2) + : client(s_[0], s_[1], ios1), server(s_[1], s_[0], ios2) { } @@ -243,28 +231,21 @@ public: //------------------------------------------------------------------------------ -template -class pipe::stream::read_op_impl : - public pipe::read_op +template +class pipe::stream::read_op_impl : public pipe::read_op { stream& s_; Buffers b_; Handler h_; public: - read_op_impl(stream& s, - Buffers const& b, Handler&& h) - : s_(s) - , b_(b) - , h_(std::move(h)) + read_op_impl(stream& s, Buffers const& b, Handler&& h) + : s_(s), b_(b), h_(std::move(h)) { } - read_op_impl(stream& s, - Buffers const& b, Handler const& h) - : s_(s) - , b_(b) - , h_(h) + read_op_impl(stream& s, Buffers const& b, Handler const& h) + : s_(s), b_(b), h_(h) { } @@ -274,103 +255,89 @@ public: //------------------------------------------------------------------------------ -template +template void -pipe::stream:: -read_op_impl::operator()() +pipe::stream::read_op_impl::operator()() { using boost::asio::buffer_copy; using boost::asio::buffer_size; - s_.ios_.post( - [&]() + s_.ios_.post([&]() { + BOOST_ASSERT(s_.in_.op); + std::unique_lock lock{s_.in_.m}; + if (s_.in_.b.size() > 0) { - BOOST_ASSERT(s_.in_.op); - std::unique_lock lock{s_.in_.m}; - if(s_.in_.b.size() > 0) - { - auto const bytes_transferred = buffer_copy( - b_, s_.in_.b.data(), s_.read_max_); - s_.in_.b.consume(bytes_transferred); - auto& s = s_; - Handler h{std::move(h_)}; - lock.unlock(); - s.in_.op.reset(nullptr); - ++s.nread; - s.ios_.post(bind_handler(std::move(h), - error_code{}, bytes_transferred)); - } - else - { - BOOST_ASSERT(s_.in_.eof); - auto& s = s_; - Handler h{std::move(h_)}; - lock.unlock(); - s.in_.op.reset(nullptr); - ++s.nread; - s.ios_.post(bind_handler(std::move(h), - boost::asio::error::eof, 0)); - } - }); + auto const bytes_transferred = + buffer_copy(b_, s_.in_.b.data(), s_.read_max_); + s_.in_.b.consume(bytes_transferred); + auto& s = s_; + Handler h{std::move(h_)}; + lock.unlock(); + s.in_.op.reset(nullptr); + ++s.nread; + s.ios_.post( + bind_handler(std::move(h), error_code{}, bytes_transferred)); + } + else + { + BOOST_ASSERT(s_.in_.eof); + auto& s = s_; + Handler h{std::move(h_)}; + lock.unlock(); + s.in_.op.reset(nullptr); + ++s.nread; + s.ios_.post(bind_handler(std::move(h), boost::asio::error::eof, 0)); + } + }); } //------------------------------------------------------------------------------ -template +template void -pipe::stream:: -close() +pipe::stream::close() { std::lock_guard lock{out_.m}; out_.eof = true; - if(out_.op) + if (out_.op) out_.op.get()->operator()(); else out_.cv.notify_all(); } - -template +template std::size_t -pipe::stream:: -read_some(MutableBufferSequence const& buffers) +pipe::stream::read_some(MutableBufferSequence const& buffers) { - static_assert(is_mutable_buffer_sequence< - MutableBufferSequence>::value, + static_assert( + is_mutable_buffer_sequence::value, "MutableBufferSequence requirements not met"); error_code ec; auto const n = read_some(buffers, ec); - if(ec) + if (ec) BOOST_THROW_EXCEPTION(system_error{ec}); return n; } -template +template std::size_t -pipe::stream:: -read_some(MutableBufferSequence const& buffers, - error_code& ec) +pipe::stream::read_some(MutableBufferSequence const& buffers, error_code& ec) { - static_assert(is_mutable_buffer_sequence< - MutableBufferSequence>::value, + static_assert( + is_mutable_buffer_sequence::value, "MutableBufferSequence requirements not met"); using boost::asio::buffer_copy; using boost::asio::buffer_size; - BOOST_ASSERT(! in_.op); + BOOST_ASSERT(!in_.op); BOOST_ASSERT(buffer_size(buffers) > 0); - if(fc_ && fc_->fail(ec)) + if (fc_ && fc_->fail(ec)) return 0; std::unique_lock lock{in_.m}; - in_.cv.wait(lock, - [&]() - { - return in_.b.size() > 0 || in_.eof; - }); + in_.cv.wait(lock, [&]() { return in_.b.size() > 0 || in_.eof; }); std::size_t bytes_transferred; - if(in_.b.size() > 0) - { + if (in_.b.size() > 0) + { ec.assign(0, ec.category()); - bytes_transferred = buffer_copy( - buffers, in_.b.data(), read_max_); + bytes_transferred = buffer_copy(buffers, in_.b.data(), read_max_); in_.b.consume(bytes_transferred); } else @@ -383,99 +350,90 @@ read_some(MutableBufferSequence const& buffers, return bytes_transferred; } -template -async_return_type< - ReadHandler, void(error_code, std::size_t)> -pipe::stream:: -async_read_some(MutableBufferSequence const& buffers, +template +async_return_type +pipe::stream::async_read_some( + MutableBufferSequence const& buffers, ReadHandler&& handler) { - static_assert(is_mutable_buffer_sequence< - MutableBufferSequence>::value, + static_assert( + is_mutable_buffer_sequence::value, "MutableBufferSequence requirements not met"); using boost::asio::buffer_copy; using boost::asio::buffer_size; - BOOST_ASSERT(! in_.op); + BOOST_ASSERT(!in_.op); BOOST_ASSERT(buffer_size(buffers) > 0); - async_completion init{handler}; - if(fc_) + async_completion init{handler}; + if (fc_) { error_code ec; - if(fc_->fail(ec)) - return ios_.post(bind_handler( - init.completion_handler, ec, 0)); + if (fc_->fail(ec)) + return ios_.post(bind_handler(init.completion_handler, ec, 0)); } { std::unique_lock lock{in_.m}; - if(in_.eof) + if (in_.eof) { lock.unlock(); ++nread; - ios_.post(bind_handler(init.completion_handler, - boost::asio::error::eof, 0)); + ios_.post(bind_handler( + init.completion_handler, boost::asio::error::eof, 0)); } - else if(buffer_size(buffers) == 0 || - buffer_size(in_.b.data()) > 0) + else if (buffer_size(buffers) == 0 || buffer_size(in_.b.data()) > 0) { - auto const bytes_transferred = buffer_copy( - buffers, in_.b.data(), read_max_); + auto const bytes_transferred = + buffer_copy(buffers, in_.b.data(), read_max_); in_.b.consume(bytes_transferred); lock.unlock(); ++nread; - ios_.post(bind_handler(init.completion_handler, - error_code{}, bytes_transferred)); + ios_.post(bind_handler( + init.completion_handler, error_code{}, bytes_transferred)); } else { - in_.op.reset(new read_op_impl, - MutableBufferSequence>{*this, buffers, - init.completion_handler}); + in_.op.reset( + new read_op_impl< + handler_type, + MutableBufferSequence>{ + *this, buffers, init.completion_handler}); } } return init.result.get(); } -template +template std::size_t -pipe::stream:: -write_some(ConstBufferSequence const& buffers) +pipe::stream::write_some(ConstBufferSequence const& buffers) { - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, + static_assert( + is_const_buffer_sequence::value, "ConstBufferSequence requirements not met"); - BOOST_ASSERT(! out_.eof); + BOOST_ASSERT(!out_.eof); error_code ec; - auto const bytes_transferred = - write_some(buffers, ec); - if(ec) + auto const bytes_transferred = write_some(buffers, ec); + if (ec) BOOST_THROW_EXCEPTION(system_error{ec}); return bytes_transferred; } -template +template std::size_t -pipe::stream:: -write_some( - ConstBufferSequence const& buffers, error_code& ec) +pipe::stream::write_some(ConstBufferSequence const& buffers, error_code& ec) { - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, + static_assert( + is_const_buffer_sequence::value, "ConstBufferSequence requirements not met"); using boost::asio::buffer_copy; using boost::asio::buffer_size; - BOOST_ASSERT(! out_.eof); - if(fc_ && fc_->fail(ec)) + BOOST_ASSERT(!out_.eof); + if (fc_ && fc_->fail(ec)) return 0; - auto const n = (std::min)( - buffer_size(buffers), write_max_); + auto const n = (std::min)(buffer_size(buffers), write_max_); std::unique_lock lock{out_.m}; - auto const bytes_transferred = - buffer_copy(out_.b.prepare(n), buffers); + auto const bytes_transferred = buffer_copy(out_.b.prepare(n), buffers); out_.b.commit(bytes_transferred); lock.unlock(); - if(out_.op) + if (out_.op) out_.op.get()->operator()(); else out_.cv.notify_all(); @@ -484,46 +442,41 @@ write_some( return bytes_transferred; } -template -async_return_type< - WriteHandler, void(error_code, std::size_t)> -pipe::stream:: -async_write_some(ConstBufferSequence const& buffers, +template +async_return_type +pipe::stream::async_write_some( + ConstBufferSequence const& buffers, WriteHandler&& handler) { - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, + static_assert( + is_const_buffer_sequence::value, "ConstBufferSequence requirements not met"); using boost::asio::buffer_copy; using boost::asio::buffer_size; - BOOST_ASSERT(! out_.eof); - async_completion init{handler}; - if(fc_) + BOOST_ASSERT(!out_.eof); + async_completion init{handler}; + if (fc_) { error_code ec; - if(fc_->fail(ec)) - return ios_.post(bind_handler( - init.completion_handler, ec, 0)); + if (fc_->fail(ec)) + return ios_.post(bind_handler(init.completion_handler, ec, 0)); } - auto const n = - (std::min)(buffer_size(buffers), write_max_); + auto const n = (std::min)(buffer_size(buffers), write_max_); std::unique_lock lock{out_.m}; - auto const bytes_transferred = - buffer_copy(out_.b.prepare(n), buffers); + auto const bytes_transferred = buffer_copy(out_.b.prepare(n), buffers); out_.b.commit(bytes_transferred); lock.unlock(); - if(out_.op) + if (out_.op) out_.op.get()->operator()(); else out_.cv.notify_all(); ++nwrite; - ios_.post(bind_handler(init.completion_handler, - error_code{}, bytes_transferred)); + ios_.post( + bind_handler(init.completion_handler, error_code{}, bytes_transferred)); return init.result.get(); } -} // test -} // beast +} // namespace test +} // namespace beast #endif diff --git a/src/ripple/beast/test/sig_wait.h b/src/ripple/beast/test/sig_wait.h index cadd21660..92720561f 100644 --- a/src/ripple/beast/test/sig_wait.h +++ b/src/ripple/beast/test/sig_wait.h @@ -14,21 +14,16 @@ namespace beast { namespace test { /// Block until SIGINT or SIGTERM is received. -inline -void +inline void sig_wait() { boost::asio::io_service ios; - boost::asio::signal_set signals( - ios, SIGINT, SIGTERM); - signals.async_wait( - [&](boost::system::error_code const&, int) - { - }); + boost::asio::signal_set signals(ios, SIGINT, SIGTERM); + signals.async_wait([&](boost::system::error_code const&, int) {}); ios.run(); } -} // test -} // beast +} // namespace test +} // namespace beast #endif diff --git a/src/ripple/beast/test/string_iostream.h b/src/ripple/beast/test/string_iostream.h index eeeb7e21a..56f741be0 100644 --- a/src/ripple/beast/test/string_iostream.h +++ b/src/ripple/beast/test/string_iostream.h @@ -8,20 +8,21 @@ #ifndef BEAST_TEST_STRING_IOSTREAM_HPP #define BEAST_TEST_STRING_IOSTREAM_HPP +#include +#include +#include #include #include #include #include #include -#include -#include -#include #include namespace beast { namespace test { -/** A SyncStream and AsyncStream that reads from a string and writes to another string. +/** A SyncStream and AsyncStream that reads from a string and writes to another + string. This class behaves like a socket, except that written data is appended to a string exposed as a public data member, and when @@ -37,9 +38,10 @@ class string_iostream public: std::string str; - string_iostream(boost::asio::io_service& ios, - std::string s, std::size_t read_max = - (std::numeric_limits::max)()) + string_iostream( + boost::asio::io_service& ios, + std::string s, + std::size_t read_max = (std::numeric_limits::max)()) : s_(std::move(s)) , cb_(boost::asio::buffer(s_)) , ios_(ios) @@ -53,25 +55,24 @@ public: return ios_; } - template + template std::size_t read_some(MutableBufferSequence const& buffers) { error_code ec; auto const n = read_some(buffers, ec); - if(ec) + if (ec) BOOST_THROW_EXCEPTION(system_error{ec}); return n; } - template + template std::size_t - read_some(MutableBufferSequence const& buffers, - error_code& ec) + read_some(MutableBufferSequence const& buffers, error_code& ec) { - auto const n = boost::asio::buffer_copy( - buffers, buffer_prefix(read_max_, cb_)); - if(n > 0) + auto const n = + boost::asio::buffer_copy(buffers, buffer_prefix(read_max_, cb_)); + if (n > 0) { ec.assign(0, ec.category()); cb_ = cb_ + n; @@ -83,91 +84,83 @@ public: return n; } - template - async_return_type< - ReadHandler, void(error_code, std::size_t)> - async_read_some(MutableBufferSequence const& buffers, - ReadHandler&& handler) + template + async_return_type + async_read_some(MutableBufferSequence const& buffers, ReadHandler&& handler) { - auto const n = boost::asio::buffer_copy( - buffers, boost::asio::buffer(s_)); + auto const n = + boost::asio::buffer_copy(buffers, boost::asio::buffer(s_)); error_code ec; - if(n > 0) + if (n > 0) s_.erase(0, n); else ec = boost::asio::error::eof; - async_completion init{handler}; - ios_.post(bind_handler( - init.completion_handler, ec, n)); + async_completion init{ + handler}; + ios_.post(bind_handler(init.completion_handler, ec, n)); return init.result.get(); } - template + template std::size_t write_some(ConstBufferSequence const& buffers) { error_code ec; auto const n = write_some(buffers, ec); - if(ec) + if (ec) BOOST_THROW_EXCEPTION(system_error{ec}); return n; } - template + template std::size_t - write_some( - ConstBufferSequence const& buffers, error_code& ec) + write_some(ConstBufferSequence const& buffers, error_code& ec) { ec.assign(0, ec.category()); - using boost::asio::buffer_size; using boost::asio::buffer_cast; + using boost::asio::buffer_size; auto const n = buffer_size(buffers); str.reserve(str.size() + n); - for(boost::asio::const_buffer buffer : buffers) - str.append(buffer_cast(buffer), - buffer_size(buffer)); + for (boost::asio::const_buffer buffer : buffers) + str.append(buffer_cast(buffer), buffer_size(buffer)); return n; } - template - async_return_type< - WriteHandler, void(error_code, std::size_t)> - async_write_some(ConstBufferSequence const& buffers, - WriteHandler&& handler) + template + async_return_type + async_write_some(ConstBufferSequence const& buffers, WriteHandler&& handler) { error_code ec; auto const bytes_transferred = write_some(buffers, ec); - async_completion init{handler}; + async_completion init{ + handler}; get_io_service().post( bind_handler(init.completion_handler, ec, bytes_transferred)); return init.result.get(); } - friend - void - teardown(websocket::teardown_tag, + friend void + teardown( + websocket::teardown_tag, string_iostream&, - boost::system::error_code& ec) + boost::system::error_code& ec) { ec.assign(0, ec.category()); } - template - friend - void - async_teardown(websocket::teardown_tag, + template + friend void + async_teardown( + websocket::teardown_tag, string_iostream& stream, - TeardownHandler&& handler) + TeardownHandler&& handler) { stream.get_io_service().post( - bind_handler(std::move(handler), - error_code{})); + bind_handler(std::move(handler), error_code{})); } }; -} // test -} // beast +} // namespace test +} // namespace beast #endif diff --git a/src/ripple/beast/test/string_istream.h b/src/ripple/beast/test/string_istream.h index c9692b872..81f354699 100644 --- a/src/ripple/beast/test/string_istream.h +++ b/src/ripple/beast/test/string_istream.h @@ -8,13 +8,13 @@ #ifndef BEAST_TEST_STRING_ISTREAM_HPP #define BEAST_TEST_STRING_ISTREAM_HPP +#include +#include +#include #include #include #include #include -#include -#include -#include #include namespace beast { @@ -34,9 +34,10 @@ class string_istream std::size_t read_max_; public: - string_istream(boost::asio::io_service& ios, - std::string s, std::size_t read_max = - (std::numeric_limits::max)()) + string_istream( + boost::asio::io_service& ios, + std::string s, + std::size_t read_max = (std::numeric_limits::max)()) : s_(std::move(s)) , cb_(boost::asio::buffer(s_)) , ios_(ios) @@ -50,25 +51,23 @@ public: return ios_; } - template + template std::size_t read_some(MutableBufferSequence const& buffers) { error_code ec; auto const n = read_some(buffers, ec); - if(ec) + if (ec) BOOST_THROW_EXCEPTION(system_error{ec}); return n; } - template + template std::size_t - read_some(MutableBufferSequence const& buffers, - error_code& ec) + read_some(MutableBufferSequence const& buffers, error_code& ec) { - auto const n = boost::asio::buffer_copy( - buffers, cb_, read_max_); - if(n > 0) + auto const n = boost::asio::buffer_copy(buffers, cb_, read_max_); + if (n > 0) { ec.assign(0, ec.category()); cb_ = cb_ + n; @@ -80,82 +79,77 @@ public: return n; } - template - async_return_type< - ReadHandler, void(error_code, std::size_t)> - async_read_some(MutableBufferSequence const& buffers, - ReadHandler&& handler) + template + async_return_type + async_read_some(MutableBufferSequence const& buffers, ReadHandler&& handler) { - auto const n = boost::asio::buffer_copy( - buffers, boost::asio::buffer(s_)); + auto const n = + boost::asio::buffer_copy(buffers, boost::asio::buffer(s_)); error_code ec; - if(n > 0) + if (n > 0) s_.erase(0, n); else ec = boost::asio::error::eof; - async_completion init{handler}; - ios_.post(bind_handler( - init.completion_handler, ec, n)); + async_completion init{ + handler}; + ios_.post(bind_handler(init.completion_handler, ec, n)); return init.result.get(); } - template + template std::size_t write_some(ConstBufferSequence const& buffers) { error_code ec; auto const n = write_some(buffers, ec); - if(ec) + if (ec) BOOST_THROW_EXCEPTION(system_error{ec}); return n; } - template + template std::size_t - write_some(ConstBufferSequence const& buffers, - error_code& ec) + write_some(ConstBufferSequence const& buffers, error_code& ec) { ec.assign(0, ec.category()); return boost::asio::buffer_size(buffers); } - template - async_return_type< - WriteHandler, void(error_code, std::size_t)> - async_write_some(ConstBuffeSequence const& buffers, - WriteHandler&& handler) + template + async_return_type + async_write_some(ConstBuffeSequence const& buffers, WriteHandler&& handler) { - async_completion init{handler}; - ios_.post(bind_handler(init.completion_handler, - error_code{}, boost::asio::buffer_size(buffers))); + async_completion init{ + handler}; + ios_.post(bind_handler( + init.completion_handler, + error_code{}, + boost::asio::buffer_size(buffers))); return init.result.get(); } - friend - void - teardown(websocket::teardown_tag, + friend void + teardown( + websocket::teardown_tag, string_istream&, - boost::system::error_code& ec) + boost::system::error_code& ec) { ec.assign(0, ec.category()); } - template - friend - void - async_teardown(websocket::teardown_tag, + template + friend void + async_teardown( + websocket::teardown_tag, string_istream& stream, - TeardownHandler&& handler) + TeardownHandler&& handler) { stream.get_io_service().post( - bind_handler(std::move(handler), - error_code{})); + bind_handler(std::move(handler), error_code{})); } }; -} // test -} // beast +} // namespace test +} // namespace beast #endif diff --git a/src/ripple/beast/test/string_ostream.h b/src/ripple/beast/test/string_ostream.h index dd57d8a99..4cca9e7fc 100644 --- a/src/ripple/beast/test/string_ostream.h +++ b/src/ripple/beast/test/string_ostream.h @@ -8,14 +8,14 @@ #ifndef BEAST_TEST_STRING_OSTREAM_HPP #define BEAST_TEST_STRING_OSTREAM_HPP +#include +#include +#include #include #include #include #include #include -#include -#include -#include #include namespace beast { @@ -29,12 +29,10 @@ class string_ostream public: std::string str; - explicit - string_ostream(boost::asio::io_service& ios, - std::size_t write_max = - (std::numeric_limits::max)()) - : ios_(ios) - , write_max_(write_max) + explicit string_ostream( + boost::asio::io_service& ios, + std::size_t write_max = (std::numeric_limits::max)()) + : ios_(ios), write_max_(write_max) { } @@ -44,106 +42,96 @@ public: return ios_; } - template + template std::size_t read_some(MutableBufferSequence const& buffers) { error_code ec; auto const n = read_some(buffers, ec); - if(ec) + if (ec) BOOST_THROW_EXCEPTION(system_error{ec}); return n; } - template + template std::size_t - read_some(MutableBufferSequence const&, - error_code& ec) + read_some(MutableBufferSequence const&, error_code& ec) { ec = boost::asio::error::eof; return 0; } - template - async_return_type< - ReadHandler, void(error_code, std::size_t)> - async_read_some(MutableBufferSequence const&, - ReadHandler&& handler) + template + async_return_type + async_read_some(MutableBufferSequence const&, ReadHandler&& handler) { - async_completion init{handler}; - ios_.post(bind_handler(init.completion_handler, - boost::asio::error::eof, 0)); + async_completion init{ + handler}; + ios_.post( + bind_handler(init.completion_handler, boost::asio::error::eof, 0)); return init.result.get(); } - template + template std::size_t write_some(ConstBufferSequence const& buffers) { error_code ec; auto const n = write_some(buffers, ec); - if(ec) + if (ec) BOOST_THROW_EXCEPTION(system_error{ec}); return n; } - template + template std::size_t - write_some( - ConstBufferSequence const& buffers, error_code& ec) + write_some(ConstBufferSequence const& buffers, error_code& ec) { ec.assign(0, ec.category()); - using boost::asio::buffer_size; using boost::asio::buffer_cast; - auto const n = - (std::min)(buffer_size(buffers), write_max_); + using boost::asio::buffer_size; + auto const n = (std::min)(buffer_size(buffers), write_max_); str.reserve(str.size() + n); - for(boost::asio::const_buffer buffer : - buffer_prefix(n, buffers)) - str.append(buffer_cast(buffer), - buffer_size(buffer)); + for (boost::asio::const_buffer buffer : buffer_prefix(n, buffers)) + str.append(buffer_cast(buffer), buffer_size(buffer)); return n; } - template - async_return_type< - WriteHandler, void(error_code, std::size_t)> - async_write_some(ConstBufferSequence const& buffers, - WriteHandler&& handler) + template + async_return_type + async_write_some(ConstBufferSequence const& buffers, WriteHandler&& handler) { error_code ec; auto const bytes_transferred = write_some(buffers, ec); - async_completion init{handler}; + async_completion init{ + handler}; get_io_service().post( bind_handler(init.completion_handler, ec, bytes_transferred)); return init.result.get(); } - friend - void - teardown(websocket::teardown_tag, + friend void + teardown( + websocket::teardown_tag, string_ostream&, - boost::system::error_code& ec) + boost::system::error_code& ec) { ec.assign(0, ec.category()); } - template - friend - void - async_teardown(websocket::teardown_tag, + template + friend void + async_teardown( + websocket::teardown_tag, string_ostream& stream, - TeardownHandler&& handler) + TeardownHandler&& handler) { stream.get_io_service().post( - bind_handler(std::move(handler), - error_code{})); + bind_handler(std::move(handler), error_code{})); } }; -} // test -} // beast +} // namespace test +} // namespace beast #endif diff --git a/src/ripple/beast/test/test_allocator.h b/src/ripple/beast/test/test_allocator.h index bc468de2a..598e22c27 100644 --- a/src/ripple/beast/test/test_allocator.h +++ b/src/ripple/beast/test/test_allocator.h @@ -25,42 +25,40 @@ struct test_allocator_info std::size_t nselect = 0; test_allocator_info() - : id([] - { - static std::atomic sid(0); - return ++sid; - }()) + : id([] { + static std::atomic sid(0); + return ++sid; + }()) { } }; -template +template class test_allocator; -template +template struct test_allocator_base { }; -template +template struct test_allocator_base { - static - test_allocator - select_on_container_copy_construction(test_allocator< - T, Equal, Assign, Move, Swap, true> const& a) + static test_allocator + select_on_container_copy_construction( + test_allocator const& a) { return test_allocator{}; } }; -template -class test_allocator : public test_allocator_base< - T, Equal, Assign, Move, Swap, Select> +template +class test_allocator + : public test_allocator_base { std::shared_ptr info_; - template + template friend class test_allocator; public: @@ -72,36 +70,32 @@ public: using propagate_on_container_move_assignment = std::integral_constant; - using propagate_on_container_swap = - std::integral_constant; + using propagate_on_container_swap = std::integral_constant; - template + template struct rebind { using other = test_allocator; }; - test_allocator() - : info_(std::make_shared()) + test_allocator() : info_(std::make_shared()) { } - test_allocator(test_allocator const& u) noexcept + test_allocator(test_allocator const& u) noexcept : info_(u.info_) + { + ++info_->ncopy; + } + + template + test_allocator( + test_allocator const& u) noexcept : info_(u.info_) { ++info_->ncopy; } - template - test_allocator(test_allocator const& u) noexcept - : info_(u.info_) - { - ++info_->ncopy; - } - - test_allocator(test_allocator&& t) - : info_(t.info_) + test_allocator(test_allocator&& t) : info_(t.info_) { ++info_->nmove; } @@ -125,8 +119,7 @@ public: value_type* allocate(std::size_t n) { - return static_cast( - ::operator new (n*sizeof(value_type))); + return static_cast(::operator new(n * sizeof(value_type))); } void @@ -144,7 +137,7 @@ public: bool operator!=(test_allocator const& other) const { - return ! this->operator==(other); + return !this->operator==(other); } std::size_t @@ -160,7 +153,7 @@ public: } }; -} // test -} // beast +} // namespace test +} // namespace beast #endif diff --git a/src/ripple/beast/test/yield_to.h b/src/ripple/beast/test/yield_to.h index 03de3e4cb..9d0f50eeb 100644 --- a/src/ripple/beast/test/yield_to.h +++ b/src/ripple/beast/test/yield_to.h @@ -40,23 +40,19 @@ private: public: /// The type of yield context passed to functions. - using yield_context = - boost::asio::yield_context; + using yield_context = boost::asio::yield_context; - explicit - enable_yield_to(std::size_t concurrency = 1) - : work_(ios_) + explicit enable_yield_to(std::size_t concurrency = 1) : work_(ios_) { threads_.reserve(concurrency); - while(concurrency--) - threads_.emplace_back( - [&]{ ios_.run(); }); + while (concurrency--) + threads_.emplace_back([&] { ios_.run(); }); } ~enable_yield_to() { work_ = boost::none; - for(auto& t : threads_) + for (auto& t : threads_) t.join(); } @@ -79,11 +75,11 @@ public: @param fn... One or more functions to invoke. */ #if BEAST_DOXYGEN - template + template void - yield_to(FN&&... fn) + yield_to(FN&&... fn); #else - template + template void yield_to(F0&& f0, FN&&... fn); #endif @@ -94,41 +90,38 @@ private: { } - template + template void spawn(F0&& f, FN&&... fn); }; -template +template void -enable_yield_to:: -yield_to(F0&& f0, FN&&... fn) +enable_yield_to::yield_to(F0&& f0, FN&&... fn) { running_ = 1 + sizeof...(FN); spawn(f0, fn...); std::unique_lock lock{m_}; - cv_.wait(lock, [&]{ return running_ == 0; }); + cv_.wait(lock, [&] { return running_ == 0; }); } -template -inline -void -enable_yield_to:: -spawn(F0&& f, FN&&... fn) +template +inline void +enable_yield_to::spawn(F0&& f, FN&&... fn) { - boost::asio::spawn(ios_, - [&](yield_context yield) - { + boost::asio::spawn( + ios_, + [&](yield_context yield) { f(yield); std::lock_guard lock{m_}; - if(--running_ == 0) + if (--running_ == 0) cv_.notify_all(); - } - , boost::coroutines::attributes(2 * 1024 * 1024)); + }, + boost::coroutines::attributes(2 * 1024 * 1024)); spawn(fn...); } -} // test -} // beast +} // namespace test +} // namespace beast #endif diff --git a/src/ripple/beast/unit_test/amount.h b/src/ripple/beast/unit_test/amount.h index a045d4d75..6f2182f59 100644 --- a/src/ripple/beast/unit_test/amount.h +++ b/src/ripple/beast/unit_test/amount.h @@ -24,32 +24,29 @@ private: public: amount(amount const&) = default; - amount& operator=(amount const&) = delete; + amount& + operator=(amount const&) = delete; - template + template amount(std::size_t n, std::string const& what); - friend - std::ostream& + friend std::ostream& operator<<(std::ostream& s, amount const& t); }; -template -amount::amount(std::size_t n, std::string const& what) - : n_(n) - , what_(what) +template +amount::amount(std::size_t n, std::string const& what) : n_(n), what_(what) { } -inline -std::ostream& +inline std::ostream& operator<<(std::ostream& s, amount const& t) { - s << t.n_ << " " << t.what_ <<((t.n_ != 1) ? "s" : ""); + s << t.n_ << " " << t.what_ << ((t.n_ != 1) ? "s" : ""); return s; } -} // unit_test -} // beast +} // namespace unit_test +} // namespace beast #endif diff --git a/src/ripple/beast/unit_test/detail/const_container.h b/src/ripple/beast/unit_test/detail/const_container.h index ed613537d..b1f089fee 100644 --- a/src/ripple/beast/unit_test/detail/const_container.h +++ b/src/ripple/beast/unit_test/detail/const_container.h @@ -16,7 +16,7 @@ namespace detail { The interface allows for limited read only operations. Derived classes provide additional behavior. */ -template +template class const_container { private: @@ -25,12 +25,14 @@ private: cont_type m_cont; protected: - cont_type& cont() + cont_type& + cont() { return m_cont; } - cont_type const& cont() const + cont_type const& + cont() const { return m_cont; } @@ -84,8 +86,8 @@ public: /** @} */ }; -} // detail -} // unit_test -} // beast +} // namespace detail +} // namespace unit_test +} // namespace beast #endif diff --git a/src/ripple/beast/unit_test/dstream.h b/src/ripple/beast/unit_test/dstream.h index fe02a26ed..ff2036a12 100644 --- a/src/ripple/beast/unit_test/dstream.h +++ b/src/ripple/beast/unit_test/dstream.h @@ -27,37 +27,37 @@ namespace unit_test { namespace detail { -template -class dstream_buf - : public std::basic_stringbuf +template +class dstream_buf : public std::basic_stringbuf { using ostream = std::basic_ostream; bool dbg_; ostream& os_; - template - void write(T const*) = delete; + template + void + write(T const*) = delete; - void write(char const* s) + void + write(char const* s) { - if(dbg_) - /*boost::detail::winapi*/::OutputDebugStringA(s); + if (dbg_) + /*boost::detail::winapi*/ ::OutputDebugStringA(s); os_ << s; } - void write(wchar_t const* s) + void + write(wchar_t const* s) { - if(dbg_) - /*boost::detail::winapi*/::OutputDebugStringW(s); + if (dbg_) + /*boost::detail::winapi*/ ::OutputDebugStringW(s); os_ << s; } public: - explicit - dstream_buf(ostream& os) - : os_(os) - , dbg_(/*boost::detail::winapi*/::IsDebuggerPresent() != 0) + explicit dstream_buf(ostream& os) + : os_(os), dbg_(/*boost::detail::winapi*/ ::IsDebuggerPresent() != 0) { } @@ -75,7 +75,7 @@ public: } }; -} // detail +} // namespace detail /** std::ostream with Visual Studio IDE redirection. @@ -84,28 +84,23 @@ public: is attached when the stream is created, output will be additionally copied to the Visual Studio Output window. */ -template< +template < class CharT, class Traits = std::char_traits, - class Allocator = std::allocator -> -class basic_dstream - : public std::basic_ostream + class Allocator = std::allocator> +class basic_dstream : public std::basic_ostream { - detail::dstream_buf< - CharT, Traits, Allocator> buf_; + detail::dstream_buf buf_; public: /** Construct a stream. @param os The output stream to wrap. */ - explicit - basic_dstream(std::ostream& os) - : std::basic_ostream(&buf_) - , buf_(os) + explicit basic_dstream(std::ostream& os) + : std::basic_ostream(&buf_), buf_(os) { - if(os.flags() & std::ios::unitbuf) + if (os.flags() & std::ios::unitbuf) std::unitbuf(*this); } }; @@ -120,7 +115,7 @@ using dwstream = std::wostream&; #endif -} // unit_test -} // beast +} // namespace unit_test +} // namespace beast #endif diff --git a/src/ripple/beast/unit_test/global_suites.h b/src/ripple/beast/unit_test/global_suites.h index b641ed7cb..d1ee4d177 100644 --- a/src/ripple/beast/unit_test/global_suites.h +++ b/src/ripple/beast/unit_test/global_suites.h @@ -16,36 +16,37 @@ namespace unit_test { namespace detail { /// Holds test suites registered during static initialization. -inline -suite_list& +inline suite_list& global_suites() { static suite_list s; return s; } -template +template struct insert_suite { - insert_suite(char const* name, char const* module, - char const* library, bool manual, int priority) + insert_suite( + char const* name, + char const* module, + char const* library, + bool manual, + int priority) { - global_suites().insert( - name, module, library, manual, priority); + global_suites().insert(name, module, library, manual, priority); } }; -} // detail +} // namespace detail /// Holds test suites registered during static initialization. -inline -suite_list const& +inline suite_list const& global_suites() { return detail::global_suites(); } -} // unit_test -} // beast +} // namespace unit_test +} // namespace beast #endif diff --git a/src/ripple/beast/unit_test/match.h b/src/ripple/beast/unit_test/match.h index 689b18956..e5b341b33 100644 --- a/src/ripple/beast/unit_test/match.h +++ b/src/ripple/beast/unit_test/match.h @@ -18,8 +18,7 @@ namespace unit_test { class selector { public: - enum mode_t - { + enum mode_t { // Run all tests except manual ones all, @@ -45,83 +44,81 @@ private: std::string library_; public: - template - explicit - selector(mode_t mode, std::string const& pattern = ""); + template + explicit selector(mode_t mode, std::string const& pattern = ""); - template + template bool operator()(suite_info const& s); }; //------------------------------------------------------------------------------ -template +template selector::selector(mode_t mode, std::string const& pattern) - : mode_(mode) - , pat_(pattern) + : mode_(mode), pat_(pattern) { - if(mode_ == automatch && pattern.empty()) + if (mode_ == automatch && pattern.empty()) mode_ = all; } -template +template bool selector::operator()(suite_info const& s) { - switch(mode_) + switch (mode_) { - case automatch: - // suite or full name - if(s.name() == pat_ || s.full_name() == pat_) - { - mode_ = none; - return true; - } + case automatch: + // suite or full name + if (s.name() == pat_ || s.full_name() == pat_) + { + mode_ = none; + return true; + } - // check module - if(pat_ == s.module()) - { - mode_ = module; - library_ = s.library(); - return ! s.manual(); - } + // check module + if (pat_ == s.module()) + { + mode_ = module; + library_ = s.library(); + return !s.manual(); + } - // check library - if(pat_ == s.library()) - { - mode_ = library; - return ! s.manual(); - } + // check library + if (pat_ == s.library()) + { + mode_ = library; + return !s.manual(); + } - // check start of name - if (s.name().starts_with(pat_) || s.full_name().starts_with(pat_)) - { - // Don't change the mode so that the partial pattern can match - // more than once - return !s.manual(); - } + // check start of name + if (s.name().starts_with(pat_) || s.full_name().starts_with(pat_)) + { + // Don't change the mode so that the partial pattern can match + // more than once + return !s.manual(); + } - return false; + return false; - case suite: - return pat_ == s.name(); + case suite: + return pat_ == s.name(); - case module: - return pat_ == s.module() && ! s.manual(); + case module: + return pat_ == s.module() && !s.manual(); - case library: - return pat_ == s.library() && ! s.manual(); + case library: + return pat_ == s.library() && !s.manual(); - case none: - return false; + case none: + return false; - case all: - default: - break; + case all: + default: + break; }; - return ! s.manual(); + return !s.manual(); } //------------------------------------------------------------------------------ @@ -143,38 +140,34 @@ selector::operator()(suite_info const& s) not marked manual are selected from then on. */ -inline -selector +inline selector match_auto(std::string const& name) { return selector(selector::automatch, name); } /** Return a predicate that matches all suites not marked manual. */ -inline -selector +inline selector match_all() { return selector(selector::all); } /** Returns a predicate that matches a specific suite. */ -inline -selector +inline selector match_suite(std::string const& name) { return selector(selector::suite, name); } /** Returns a predicate that matches all suites in a library. */ -inline -selector +inline selector match_library(std::string const& name) { return selector(selector::library, name); } -} // unit_test -} // beast +} // namespace unit_test +} // namespace beast #endif diff --git a/src/ripple/beast/unit_test/recorder.h b/src/ripple/beast/unit_test/recorder.h index c7c543889..5aa1f7124 100644 --- a/src/ripple/beast/unit_test/recorder.h +++ b/src/ripple/beast/unit_test/recorder.h @@ -33,58 +33,51 @@ public: } private: - virtual - void + virtual void on_suite_begin(suite_info const& info) override { m_suite = suite_results(info.full_name()); } - virtual - void + virtual void on_suite_end() override { m_results.insert(std::move(m_suite)); } - virtual - void + virtual void on_case_begin(std::string const& name) override { m_case = case_results(name); } - virtual - void + virtual void on_case_end() override { - if(m_case.tests.size() > 0) + if (m_case.tests.size() > 0) m_suite.insert(std::move(m_case)); } - virtual - void + virtual void on_pass() override { m_case.tests.pass(); } - virtual - void + virtual void on_fail(std::string const& reason) override { m_case.tests.fail(reason); } - virtual - void + virtual void on_log(std::string const& s) override { m_case.log.insert(s); } }; -} // unit_test -} // beast +} // namespace unit_test +} // namespace beast #endif diff --git a/src/ripple/beast/unit_test/reporter.h b/src/ripple/beast/unit_test/reporter.h index 844c321a0..a61ff0460 100644 --- a/src/ripple/beast/unit_test/reporter.h +++ b/src/ripple/beast/unit_test/reporter.h @@ -29,7 +29,7 @@ namespace detail { /** A simple test runner that writes everything to a stream in real time. The totals are output when the object is destroyed. */ -template +template class reporter : public runner { private: @@ -41,9 +41,7 @@ private: std::size_t total = 0; std::size_t failed = 0; - explicit - case_results(std::string name_ = "") - : name(std::move(name_)) + explicit case_results(std::string name_ = "") : name(std::move(name_)) { } }; @@ -56,9 +54,7 @@ private: std::size_t failed = 0; typename clock_type::time_point start = clock_type::now(); - explicit - suite_results(std::string name_ = "") - : name(std::move(name_)) + explicit suite_results(std::string name_ = "") : name(std::move(name_)) { } @@ -68,13 +64,9 @@ private: struct results { - using run_time = std::pair; + using run_time = std::pair; - enum - { - max_top = 10 - }; + enum { max_top = 10 }; std::size_t suites = 0; std::size_t cases = 0; @@ -94,85 +86,75 @@ private: public: reporter(reporter const&) = delete; - reporter& operator=(reporter const&) = delete; + reporter& + operator=(reporter const&) = delete; ~reporter(); - explicit - reporter(std::ostream& os = std::cout); + explicit reporter(std::ostream& os = std::cout); private: - static - std::string + static std::string fmtdur(typename clock_type::duration const& d); - virtual - void + virtual void on_suite_begin(suite_info const& info) override; - virtual - void + virtual void on_suite_end() override; - virtual - void + virtual void on_case_begin(std::string const& name) override; - virtual - void + virtual void on_case_end() override; - virtual - void + virtual void on_pass() override; - virtual - void + virtual void on_fail(std::string const& reason) override; - virtual - void + virtual void on_log(std::string const& s) override; }; //------------------------------------------------------------------------------ -template +template void -reporter<_>:: -suite_results::add(case_results const& r) +reporter<_>::suite_results::add(case_results const& r) { ++cases; total += r.total; failed += r.failed; } -template +template void -reporter<_>:: -results::add(suite_results const& r) +reporter<_>::results::add(suite_results const& r) { ++suites; total += r.total; cases += r.cases; failed += r.failed; auto const elapsed = clock_type::now() - r.start; - if(elapsed >= std::chrono::seconds{1}) + if (elapsed >= std::chrono::seconds{1}) { - auto const iter = std::lower_bound(top.begin(), - top.end(), elapsed, - [](run_time const& t1, - typename clock_type::duration const& t2) - { + auto const iter = std::lower_bound( + top.begin(), + top.end(), + elapsed, + [](run_time const& t1, typename clock_type::duration const& t2) { return t1.second > t2; }); - if(iter != top.end()) + if (iter != top.end()) { - if(top.size() == max_top) + if (top.size() == max_top) top.resize(top.size() - 1); top.emplace(iter, r.name, elapsed); } - else if(top.size() < max_top) + else if (top.size() < max_top) { top.emplace_back(r.name, elapsed); } @@ -181,115 +163,100 @@ results::add(suite_results const& r) //------------------------------------------------------------------------------ -template -reporter<_>:: -reporter(std::ostream& os) - : os_(os) +template +reporter<_>::reporter(std::ostream& os) : os_(os) { } -template +template reporter<_>::~reporter() { - if(results_.top.size() > 0) + if (results_.top.size() > 0) { os_ << "Longest suite times:\n"; - for(auto const& i : results_.top) - os_ << std::setw(8) << - fmtdur(i.second) << " " << i.first << '\n'; + for (auto const& i : results_.top) + os_ << std::setw(8) << fmtdur(i.second) << " " << i.first << '\n'; } auto const elapsed = clock_type::now() - results_.start; - os_ << - fmtdur(elapsed) << ", " << - amount{results_.suites, "suite"} << ", " << - amount{results_.cases, "case"} << ", " << - amount{results_.total, "test"} << " total, " << - amount{results_.failed, "failure"} << - std::endl; + os_ << fmtdur(elapsed) << ", " << amount{results_.suites, "suite"} << ", " + << amount{results_.cases, "case"} << ", " + << amount{results_.total, "test"} << " total, " + << amount{results_.failed, "failure"} << std::endl; } -template +template std::string reporter<_>::fmtdur(typename clock_type::duration const& d) { using namespace std::chrono; auto const ms = duration_cast(d); - if(ms < seconds{1}) - return boost::lexical_cast( - ms.count()) + "ms"; + if (ms < seconds{1}) + return boost::lexical_cast(ms.count()) + "ms"; std::stringstream ss; - ss << std::fixed << std::setprecision(1) << - (ms.count()/1000.) << "s"; + ss << std::fixed << std::setprecision(1) << (ms.count() / 1000.) << "s"; return ss.str(); } -template +template void -reporter<_>:: -on_suite_begin(suite_info const& info) +reporter<_>::on_suite_begin(suite_info const& info) { suite_results_ = suite_results{info.full_name()}; } -template +template void reporter<_>::on_suite_end() { results_.add(suite_results_); } -template +template void -reporter<_>:: -on_case_begin(std::string const& name) +reporter<_>::on_case_begin(std::string const& name) { case_results_ = case_results(name); - os_ << suite_results_.name << - (case_results_.name.empty() ? "" : - (" " + case_results_.name)) << std::endl; + os_ << suite_results_.name + << (case_results_.name.empty() ? "" : (" " + case_results_.name)) + << std::endl; } -template +template void -reporter<_>:: -on_case_end() +reporter<_>::on_case_end() { suite_results_.add(case_results_); } -template +template void -reporter<_>:: -on_pass() +reporter<_>::on_pass() { ++case_results_.total; } -template +template void -reporter<_>:: -on_fail(std::string const& reason) +reporter<_>::on_fail(std::string const& reason) { ++case_results_.failed; ++case_results_.total; - os_ << - "#" << case_results_.total << " failed" << - (reason.empty() ? "" : ": ") << reason << std::endl; + os_ << "#" << case_results_.total << " failed" + << (reason.empty() ? "" : ": ") << reason << std::endl; } -template +template void -reporter<_>:: -on_log(std::string const& s) +reporter<_>::on_log(std::string const& s) { os_ << s; } -} // detail +} // namespace detail using reporter = detail::reporter<>; -} // unit_test -} // beast +} // namespace unit_test +} // namespace beast #endif diff --git a/src/ripple/beast/unit_test/results.h b/src/ripple/beast/unit_test/results.h index 58d6e9c8a..c9478a7f4 100644 --- a/src/ripple/beast/unit_test/results.h +++ b/src/ripple/beast/unit_test/results.h @@ -23,14 +23,12 @@ public: /** Holds the result of evaluating one test condition. */ struct test { - explicit test(bool pass_) - : pass(pass_) + explicit test(bool pass_) : pass(pass_) { } test(bool pass_, std::string const& reason_) - : pass(pass_) - , reason(reason_) + : pass(pass_), reason(reason_) { } @@ -39,15 +37,13 @@ public: }; private: - class tests_t - : public detail::const_container > + class tests_t : public detail::const_container> { private: std::size_t failed_; public: - tests_t() - : failed_(0) + tests_t() : failed_(0) { } @@ -81,8 +77,7 @@ private: } }; - class log_t - : public detail::const_container > + class log_t : public detail::const_container> { public: /** Insert a string into the log. */ @@ -96,8 +91,7 @@ private: std::string name_; public: - explicit case_results(std::string const& name = "") - : name_(name) + explicit case_results(std::string const& name = "") : name_(name) { } @@ -118,8 +112,7 @@ public: //-------------------------------------------------------------------------- /** Holds the set of testcase results in a suite. */ -class suite_results - : public detail::const_container > +class suite_results : public detail::const_container> { private: std::string name_; @@ -127,8 +120,7 @@ private: std::size_t failed_ = 0; public: - explicit suite_results(std::string const& name = "") - : name_(name) + explicit suite_results(std::string const& name = "") : name_(name) { } @@ -177,8 +169,7 @@ public: // VFALCO TODO Make this a template class using scoped allocators /** Holds the results of running a set of testsuites. */ -class results - : public detail::const_container > +class results : public detail::const_container> { private: std::size_t m_cases; @@ -186,10 +177,7 @@ private: std::size_t failed_; public: - results() - : m_cases(0) - , total_(0) - , failed_(0) + results() : m_cases(0), total_(0), failed_(0) { } @@ -236,7 +224,7 @@ public: /** @} */ }; -} // unit_test -} // beast +} // namespace unit_test +} // namespace beast #endif diff --git a/src/ripple/beast/unit_test/runner.h b/src/ripple/beast/unit_test/runner.h index 17fa0b9d7..f8d8f99be 100644 --- a/src/ripple/beast/unit_test/runner.h +++ b/src/ripple/beast/unit_test/runner.h @@ -34,7 +34,8 @@ public: runner() = default; virtual ~runner() = default; runner(runner const&) = delete; - runner& operator=(runner const&) = delete; + runner& + operator=(runner const&) = delete; /** Set the argument string. @@ -59,7 +60,7 @@ public: /** Run the specified suite. @return `true` if any conditions failed. */ - template + template bool run(suite_info const& s); @@ -69,7 +70,7 @@ public: must be convertible to `suite_info`. @return `true` if any conditions failed. */ - template + template bool run(FwdIter first, FwdIter last); @@ -80,14 +81,14 @@ public: @endcode @return `true` if any conditions failed. */ - template + template bool run_if(FwdIter first, FwdIter last, Pred pred = Pred{}); /** Run all suites in a container. @return `true` if any conditions failed. */ - template + template bool run_each(SequenceContainer const& c); @@ -98,56 +99,49 @@ public: @endcode @return `true` if any conditions failed. */ - template + template bool run_each_if(SequenceContainer const& c, Pred pred = Pred{}); protected: /// Called when a new suite starts. - virtual - void + virtual void on_suite_begin(suite_info const&) { } /// Called when a suite ends. - virtual - void + virtual void on_suite_end() { } /// Called when a new case starts. - virtual - void + virtual void on_case_begin(std::string const&) { } /// Called when a new case ends. - virtual - void + virtual void on_case_end() { } /// Called for each passing condition. - virtual - void + virtual void on_pass() { } /// Called for each failing condition. - virtual - void + virtual void on_fail(std::string const&) { } /// Called when a test logs output. - virtual - void + virtual void on_log(std::string const&) { } @@ -156,26 +150,26 @@ private: friend class suite; // Start a new testcase. - template + template void testcase(std::string const& name); - template + template void pass(); - template + template void fail(std::string const& reason); - template + template void log(std::string const& s); }; //------------------------------------------------------------------------------ -template +template bool runner::run(suite_info const& s) { @@ -191,98 +185,98 @@ runner::run(suite_info const& s) return failed_; } -template +template bool runner::run(FwdIter first, FwdIter last) { bool failed(false); - for(;first != last; ++first) + for (; first != last; ++first) failed = run(*first) || failed; return failed; } -template +template bool runner::run_if(FwdIter first, FwdIter last, Pred pred) { bool failed(false); - for(;first != last; ++first) - if(pred(*first)) + for (; first != last; ++first) + if (pred(*first)) failed = run(*first) || failed; return failed; } -template +template bool runner::run_each(SequenceContainer const& c) { bool failed(false); - for(auto const& s : c) + for (auto const& s : c) failed = run(s) || failed; return failed; } -template +template bool runner::run_each_if(SequenceContainer const& c, Pred pred) { bool failed(false); - for(auto const& s : c) - if(pred(s)) + for (auto const& s : c) + if (pred(s)) failed = run(s) || failed; return failed; } -template +template void runner::testcase(std::string const& name) { std::lock_guard lock(mutex_); // Name may not be empty - BOOST_ASSERT(default_ || ! name.empty()); + BOOST_ASSERT(default_ || !name.empty()); // Forgot to call pass or fail BOOST_ASSERT(default_ || cond_); - if(! default_) + if (!default_) on_case_end(); default_ = false; cond_ = false; on_case_begin(name); } -template +template void runner::pass() { std::lock_guard lock(mutex_); - if(default_) + if (default_) testcase(""); on_pass(); cond_ = true; } -template +template void runner::fail(std::string const& reason) { std::lock_guard lock(mutex_); - if(default_) + if (default_) testcase(""); on_fail(reason); failed_ = true; cond_ = true; } -template +template void runner::log(std::string const& s) { std::lock_guard lock(mutex_); - if(default_) + if (default_) testcase(""); on_log(s); } -} // unit_test -} // beast +} // namespace unit_test +} // namespace beast #endif diff --git a/src/ripple/beast/unit_test/suite.h b/src/ripple/beast/unit_test/suite.h index befc9a281..6a6c03ccb 100644 --- a/src/ripple/beast/unit_test/suite.h +++ b/src/ripple/beast/unit_test/suite.h @@ -21,14 +21,12 @@ namespace unit_test { namespace detail { -template -static -std::string -make_reason(String const& reason, - char const* file, int line) +template +static std::string +make_reason(String const& reason, char const* file, int line) { std::string s(reason); - if(! s.empty()) + if (!s.empty()) s.append(": "); namespace fs = boost::filesystem; s.append(fs::path{file}.filename().string()); @@ -38,15 +36,11 @@ make_reason(String const& reason, return s; } -} // detail +} // namespace detail class thread; -enum abort_t -{ - no_abort_on_fail, - abort_on_fail -}; +enum abort_t { no_abort_on_fail, abort_on_fail }; /** A testsuite class. @@ -73,16 +67,13 @@ private: } }; - template - class log_buf - : public std::basic_stringbuf + template + class log_buf : public std::basic_stringbuf { suite& suite_; public: - explicit - log_buf(suite& self) - : suite_(self) + explicit log_buf(suite& self) : suite_(self) { } @@ -95,27 +86,24 @@ private: sync() override { auto const& s = this->str(); - if(s.size() > 0) + if (s.size() > 0) suite_.runner_->log(s); this->str(""); return 0; } }; - template< + template < class CharT, class Traits = std::char_traits, - class Allocator = std::allocator - > + class Allocator = std::allocator> class log_os : public std::basic_ostream { log_buf buf_; public: - explicit - log_os(suite& self) - : std::basic_ostream(&buf_) - , buf_(self) + explicit log_os(suite& self) + : std::basic_ostream(&buf_), buf_(self) { } }; @@ -128,9 +116,7 @@ private: std::stringstream ss_; public: - explicit - testcase_t(suite& self) - : suite_(self) + explicit testcase_t(suite& self) : suite_(self) { } @@ -145,13 +131,12 @@ private: @param abort Determines if suite continues running after a failure. */ void - operator()(std::string const& name, - abort_t abort = no_abort_on_fail); + operator()(std::string const& name, abort_t abort = no_abort_on_fail); scoped_testcase operator()(abort_t abort); - template + template scoped_testcase operator<<(T const& t); }; @@ -170,22 +155,20 @@ public: /** Returns the "current" running suite. If no suite is running, nullptr is returned. */ - static - suite* + static suite* this_suite() { return *p_this_suite(); } - suite() - : log(*this) - , testcase(*this) + suite() : log(*this), testcase(*this) { } virtual ~suite() = default; suite(suite const&) = delete; - suite& operator=(suite const&) = delete; + suite& + operator=(suite const&) = delete; /** Invokes the test using the specified runner. @@ -194,12 +177,12 @@ public: forwarded constructor arguments to the base. Normally this is called by the framework for you. */ - template + template void operator()(runner& r); /** Record a successful test condition. */ - template + template void pass(); @@ -212,11 +195,11 @@ public: @param line The source code line number where the test failed. */ /** @{ */ - template + template void fail(String const& reason, char const* file, int line); - template + template void fail(std::string const& reason = ""); /** @} */ @@ -239,57 +222,59 @@ public: @return `true` if the test condition indicates success. */ /** @{ */ - template + template bool expect(Condition const& shouldBeTrue) { return expect(shouldBeTrue, ""); } - template + template bool expect(Condition const& shouldBeTrue, String const& reason); - template + template bool - expect(Condition const& shouldBeTrue, - char const* file, int line) + expect(Condition const& shouldBeTrue, char const* file, int line) { return expect(shouldBeTrue, "", file, line); } - template + template bool - expect(Condition const& shouldBeTrue, - String const& reason, char const* file, int line); + expect( + Condition const& shouldBeTrue, + String const& reason, + char const* file, + int line); /** @} */ // // DEPRECATED // // Expect an exception from f() - template + template bool except(F&& f, String const& reason); - template + template bool except(F&& f) { return except(f, ""); } - template + template bool except(F&& f, String const& reason); - template + template bool except(F&& f) { return except(f, ""); } - template + template bool unexcept(F&& f, String const& reason); - template + template bool unexcept(F&& f) { @@ -305,12 +290,11 @@ public: // DEPRECATED // @return `true` if the test condition indicates success(a false value) - template + template bool - unexpected(Condition shouldBeFalse, - String const& reason); + unexpected(Condition shouldBeFalse, String const& reason); - template + template bool unexpected(Condition shouldBeFalse) { @@ -320,8 +304,7 @@ public: private: friend class thread; - static - suite** + static suite** p_this_suite() { static suite* pts = nullptr; @@ -329,14 +312,13 @@ private: } /** Runs the suite. */ - virtual - void + virtual void run() = 0; void propagate_abort(); - template + template void run(runner& r); }; @@ -351,35 +333,32 @@ private: std::stringstream& ss_; public: - scoped_testcase& operator=(scoped_testcase const&) = delete; + scoped_testcase& + operator=(scoped_testcase const&) = delete; ~scoped_testcase() { auto const& name = ss_.str(); - if(! name.empty()) + if (!name.empty()) suite_.runner_->testcase(name); } - scoped_testcase(suite& self, std::stringstream& ss) - : suite_(self) - , ss_(ss) + scoped_testcase(suite& self, std::stringstream& ss) : suite_(self), ss_(ss) { ss_.clear(); ss_.str({}); } - template - scoped_testcase(suite& self, - std::stringstream& ss, T const& t) - : suite_(self) - , ss_(ss) + template + scoped_testcase(suite& self, std::stringstream& ss, T const& t) + : suite_(self), ss_(ss) { ss_.clear(); ss_.str({}); ss_ << t; } - template + template scoped_testcase& operator<<(T const& t) { @@ -390,37 +369,32 @@ public: //------------------------------------------------------------------------------ -inline -void -suite::testcase_t::operator()( - std::string const& name, abort_t abort) +inline void +suite::testcase_t::operator()(std::string const& name, abort_t abort) { suite_.abort_ = abort == abort_on_fail; suite_.runner_->testcase(name); } -inline -suite::scoped_testcase +inline suite::scoped_testcase suite::testcase_t::operator()(abort_t abort) { suite_.abort_ = abort == abort_on_fail; - return { suite_, ss_ }; + return {suite_, ss_}; } -template -inline -suite::scoped_testcase +template +inline suite::scoped_testcase suite::testcase_t::operator<<(T const& t) { - return { suite_, ss_, t }; + return {suite_, ss_, t}; } //------------------------------------------------------------------------------ -template +template void -suite:: -operator()(runner& r) +suite::operator()(runner& r) { *p_this_suite() = this; try @@ -428,20 +402,18 @@ operator()(runner& r) run(r); *p_this_suite() = nullptr; } - catch(...) + catch (...) { *p_this_suite() = nullptr; throw; } } -template +template bool -suite:: -expect( - Condition const& shouldBeTrue, String const& reason) +suite::expect(Condition const& shouldBeTrue, String const& reason) { - if(shouldBeTrue) + if (shouldBeTrue) { pass(); return true; @@ -450,13 +422,15 @@ expect( return false; } -template +template bool -suite:: -expect(Condition const& shouldBeTrue, - String const& reason, char const* file, int line) +suite::expect( + Condition const& shouldBeTrue, + String const& reason, + char const* file, + int line) { - if(shouldBeTrue) + if (shouldBeTrue) { pass(); return true; @@ -467,10 +441,9 @@ expect(Condition const& shouldBeTrue, // DEPRECATED -template +template bool -suite:: -except(F&& f, String const& reason) +suite::except(F&& f, String const& reason) { try { @@ -478,17 +451,16 @@ except(F&& f, String const& reason) fail(reason); return false; } - catch(...) + catch (...) { pass(); } return true; } -template +template bool -suite:: -except(F&& f, String const& reason) +suite::except(F&& f, String const& reason) { try { @@ -496,17 +468,16 @@ except(F&& f, String const& reason) fail(reason); return false; } - catch(E const&) + catch (E const&) { pass(); } return true; } -template +template bool -suite:: -unexcept(F&& f, String const& reason) +suite::unexcept(F&& f, String const& reason) { try { @@ -514,73 +485,64 @@ unexcept(F&& f, String const& reason) pass(); return true; } - catch(...) + catch (...) { fail(reason); } return false; } -template +template bool -suite:: -unexpected( - Condition shouldBeFalse, String const& reason) +suite::unexpected(Condition shouldBeFalse, String const& reason) { - bool const b = - static_cast(shouldBeFalse); - if(! b) + bool const b = static_cast(shouldBeFalse); + if (!b) pass(); else fail(reason); - return ! b; + return !b; } -template +template void -suite:: -pass() +suite::pass() { propagate_abort(); runner_->pass(); } // ::fail -template +template void -suite:: -fail(std::string const& reason) +suite::fail(std::string const& reason) { propagate_abort(); runner_->fail(reason); - if(abort_) + if (abort_) { aborted_ = true; BOOST_THROW_EXCEPTION(abort_exception()); } } -template +template void -suite:: -fail(String const& reason, char const* file, int line) +suite::fail(String const& reason, char const* file, int line) { fail(detail::make_reason(reason, file, line)); } -inline -void -suite:: -propagate_abort() +inline void +suite::propagate_abort() { - if(abort_ && aborted_) + if (abort_ && aborted_) BOOST_THROW_EXCEPTION(abort_exception()); } -template +template void -suite:: -run(runner& r) +suite::run(runner& r) { runner_ = &r; @@ -588,16 +550,15 @@ run(runner& r) { run(); } - catch(abort_exception const&) + catch (abort_exception const&) { // ends the suite } - catch(std::exception const& e) + catch (std::exception const& e) { - runner_->fail("unhandled exception: " + - std::string(e.what())); + runner_->fail("unhandled exception: " + std::string(e.what())); } - catch(...) + catch (...) { runner_->fail("unhandled exception"); } @@ -616,20 +577,21 @@ run(runner& r) If the condition is false, the file and line number are reported. */ -#define BEAST_EXPECTS(cond, reason) ((cond) ? (pass(), true) : \ - (fail((reason), __FILE__, __LINE__), false)) +#define BEAST_EXPECTS(cond, reason) \ + ((cond) ? (pass(), true) : (fail((reason), __FILE__, __LINE__), false)) #endif -} // unit_test -} // beast +} // namespace unit_test +} // namespace beast //------------------------------------------------------------------------------ // detail: // This inserts the suite with the given manual flag -#define BEAST_DEFINE_TESTSUITE_INSERT(Class,Module,Library,manual,priority) \ - static beast::unit_test::detail::insert_suite \ - Library ## Module ## Class ## _test_instance( \ +#define BEAST_DEFINE_TESTSUITE_INSERT( \ + Class, Module, Library, manual, priority) \ + static beast::unit_test::detail::insert_suite \ + Library##Module##Class##_test_instance( \ #Class, #Module, #Library, manual, priority) //------------------------------------------------------------------------------ @@ -678,21 +640,21 @@ run(runner& r) */ #if BEAST_NO_UNIT_TEST_INLINE -#define BEAST_DEFINE_TESTSUITE(Class,Module,Library) -#define BEAST_DEFINE_TESTSUITE_MANUAL(Class,Module,Library) -#define BEAST_DEFINE_TESTSUITE_PRIO(Class,Module,Library,Priority) -#define BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(Class,Module,Library,Priority) +#define BEAST_DEFINE_TESTSUITE(Class, Module, Library) +#define BEAST_DEFINE_TESTSUITE_MANUAL(Class, Module, Library) +#define BEAST_DEFINE_TESTSUITE_PRIO(Class, Module, Library, Priority) +#define BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(Class, Module, Library, Priority) #else #include -#define BEAST_DEFINE_TESTSUITE(Class,Module,Library) \ - BEAST_DEFINE_TESTSUITE_INSERT(Class,Module,Library,false,0) -#define BEAST_DEFINE_TESTSUITE_MANUAL(Class,Module,Library) \ - BEAST_DEFINE_TESTSUITE_INSERT(Class,Module,Library,true,0) -#define BEAST_DEFINE_TESTSUITE_PRIO(Class,Module,Library,Priority) \ - BEAST_DEFINE_TESTSUITE_INSERT(Class,Module,Library,false,Priority) -#define BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(Class,Module,Library,Priority) \ - BEAST_DEFINE_TESTSUITE_INSERT(Class,Module,Library,true,Priority) +#define BEAST_DEFINE_TESTSUITE(Class, Module, Library) \ + BEAST_DEFINE_TESTSUITE_INSERT(Class, Module, Library, false, 0) +#define BEAST_DEFINE_TESTSUITE_MANUAL(Class, Module, Library) \ + BEAST_DEFINE_TESTSUITE_INSERT(Class, Module, Library, true, 0) +#define BEAST_DEFINE_TESTSUITE_PRIO(Class, Module, Library, Priority) \ + BEAST_DEFINE_TESTSUITE_INSERT(Class, Module, Library, false, Priority) +#define BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(Class, Module, Library, Priority) \ + BEAST_DEFINE_TESTSUITE_INSERT(Class, Module, Library, true, Priority) #endif #endif diff --git a/src/ripple/beast/unit_test/suite_info.h b/src/ripple/beast/unit_test/suite_info.h index 0131fb902..a7e63d606 100644 --- a/src/ripple/beast/unit_test/suite_info.h +++ b/src/ripple/beast/unit_test/suite_info.h @@ -32,12 +32,12 @@ class suite_info public: suite_info( - std::string name, - std::string module, - std::string library, - bool manual, - int priority, - run_type run) + std::string name, + std::string module, + std::string library, + bool manual, + int priority, + run_type run) : name_(std::move(name)) , module_(std::move(module)) , library_(std::move(library)) @@ -86,21 +86,22 @@ public: run_(r); } - friend - bool + friend bool operator<(suite_info const& lhs, suite_info const& rhs) { // we want higher priority suites sorted first, thus the negation // of priority value here - return std::forward_as_tuple(-lhs.priority_, lhs.library_, lhs.module_, lhs.name_) < - std::forward_as_tuple(-rhs.priority_, rhs.library_, rhs.module_, rhs.name_); + return std::forward_as_tuple( + -lhs.priority_, lhs.library_, lhs.module_, lhs.name_) < + std::forward_as_tuple( + -rhs.priority_, rhs.library_, rhs.module_, rhs.name_); } }; //------------------------------------------------------------------------------ /// Convenience for producing suite_info for a given test type. -template +template suite_info make_suite_info( std::string name, @@ -115,14 +116,10 @@ make_suite_info( std::move(library), manual, priority, - [](runner& r) - { - Suite{}(r); - } - ); + [](runner& r) { Suite{}(r); }); } -} // unit_test -} // beast +} // namespace unit_test +} // namespace beast #endif diff --git a/src/ripple/beast/unit_test/suite_list.h b/src/ripple/beast/unit_test/suite_list.h index 1a7e241e9..5f0541db8 100644 --- a/src/ripple/beast/unit_test/suite_list.h +++ b/src/ripple/beast/unit_test/suite_list.h @@ -8,19 +8,18 @@ #ifndef BEAST_UNIT_TEST_SUITE_LIST_HPP #define BEAST_UNIT_TEST_SUITE_LIST_HPP -#include #include +#include #include -#include #include +#include #include namespace beast { namespace unit_test { /// A container of test suites. -class suite_list - : public detail::const_container > +class suite_list : public detail::const_container> { private: #ifndef NDEBUG @@ -33,7 +32,7 @@ public: The suite must not already exist. */ - template + template void insert( char const* name, @@ -45,7 +44,7 @@ public: //------------------------------------------------------------------------------ -template +template void suite_list::insert( char const* name, @@ -59,20 +58,19 @@ suite_list::insert( std::string s; s = std::string(library) + "." + module + "." + name; auto const result(names_.insert(s)); - BOOST_ASSERT(result.second); // Duplicate name + BOOST_ASSERT(result.second); // Duplicate name } { - auto const result(classes_.insert( - std::type_index(typeid(Suite)))); - BOOST_ASSERT(result.second); // Duplicate type + auto const result(classes_.insert(std::type_index(typeid(Suite)))); + BOOST_ASSERT(result.second); // Duplicate type } #endif - cont().emplace(make_suite_info( - name, module, library, manual, priority)); + cont().emplace( + make_suite_info(name, module, library, manual, priority)); } -} // unit_test -} // beast +} // namespace unit_test +} // namespace beast #endif diff --git a/src/ripple/beast/unit_test/thread.h b/src/ripple/beast/unit_test/thread.h index 9f02ba5ee..3fd22a30c 100644 --- a/src/ripple/beast/unit_test/thread.h +++ b/src/ripple/beast/unit_test/thread.h @@ -29,31 +29,27 @@ public: thread() = default; thread(thread const&) = delete; - thread& operator=(thread const&) = delete; + thread& + operator=(thread const&) = delete; - thread(thread&& other) - : s_(other.s_) - , t_(std::move(other.t_)) + thread(thread&& other) : s_(other.s_), t_(std::move(other.t_)) { } - thread& operator=(thread&& other) + thread& + operator=(thread&& other) { s_ = other.s_; t_ = std::move(other.t_); return *this; } - template - explicit - thread(suite& s, F&& f, Args&&... args) - : s_(&s) + template + explicit thread(suite& s, F&& f, Args&&... args) : s_(&s) { std::function b = - std::bind(std::forward(f), - std::forward(args)...); - t_ = std::thread(&thread::run, this, - std::move(b)); + std::bind(std::forward(f), std::forward(args)...); + t_ = std::thread(&thread::run, this, std::move(b)); } bool @@ -68,8 +64,7 @@ public: return t_.get_id(); } - static - unsigned + static unsigned hardware_concurrency() noexcept { return std::thread::hardware_concurrency(); @@ -97,28 +92,27 @@ public: private: void - run(std::function f) + run(std::function f) { try { f(); } - catch(suite::abort_exception const&) + catch (suite::abort_exception const&) { } - catch(std::exception const& e) + catch (std::exception const& e) { - s_->fail("unhandled exception: " + - std::string(e.what())); + s_->fail("unhandled exception: " + std::string(e.what())); } - catch(...) + catch (...) { s_->fail("unhandled exception"); } } }; -} // unit_test -} // beast +} // namespace unit_test +} // namespace beast #endif