Use BOOST_ASSERT

This commit is contained in:
Vinnie Falco
2016-09-25 12:17:32 -04:00
parent 58d3ea6548
commit dff2751c07
20 changed files with 73 additions and 72 deletions

View File

@ -4,6 +4,7 @@
* Fix error handling in http server examples
* Fix CMake scripts for MinGW
* Better WebSocket decorator
* Use BOOST_ASSERT
--------------------------------------------------------------------------------

View File

@ -9,7 +9,7 @@
#define BEAST_UNIT_TEST_RUNNER_H_INCLUDED
#include <beast/unit_test/suite_info.hpp>
#include <cassert>
#include <boost/assert.hpp>
#include <mutex>
#include <ostream>
#include <string>
@ -185,7 +185,7 @@ runner::run(suite_info const& s)
on_suite_begin(s);
s.run(*this);
// Forgot to call pass or fail.
assert(cond_);
BOOST_ASSERT(cond_);
on_case_end();
on_suite_end();
return failed_;
@ -239,9 +239,9 @@ runner::testcase(std::string const& name)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
// Name may not be empty
assert(default_ || ! name.empty());
BOOST_ASSERT(default_ || ! name.empty());
// Forgot to call pass or fail
assert(default_ || cond_);
BOOST_ASSERT(default_ || cond_);
if(! default_)
on_case_end();
default_ = false;

View File

@ -10,7 +10,7 @@
#include <beast/unit_test/suite_info.hpp>
#include <beast/unit_test/detail/const_container.hpp>
#include <cassert>
#include <boost/assert.hpp>
#include <typeindex>
#include <set>
#include <unordered_set>
@ -57,13 +57,13 @@ suite_list::insert(
std::string s;
s = std::string(library) + "." + module + "." + name;
auto const result(names_.insert(s));
assert(result.second); // Duplicate name
BOOST_ASSERT(result.second); // Duplicate name
}
{
auto const result(classes_.insert(
std::type_index(typeid(Suite))));
assert(result.second); // Duplicate type
BOOST_ASSERT(result.second); // Duplicate type
}
#endif
cont().emplace(make_suite_info<Suite>(

View File

@ -9,8 +9,8 @@
#define BEAST_IMPL_BASIC_STREAMBUF_IPP
#include <beast/core/detail/write_dynabuf.hpp>
#include <boost/assert.hpp>
#include <algorithm>
#include <cassert>
#include <exception>
#include <sstream>
#include <string>
@ -816,36 +816,36 @@ basic_streambuf<Allocator>::debug_check() const
{
#ifndef NDEBUG
using boost::asio::buffer_size;
assert(buffer_size(data()) == in_size_);
BOOST_ASSERT(buffer_size(data()) == in_size_);
if(list_.empty())
{
assert(in_pos_ == 0);
assert(in_size_ == 0);
assert(out_pos_ == 0);
assert(out_end_ == 0);
assert(out_ == list_.end());
BOOST_ASSERT(in_pos_ == 0);
BOOST_ASSERT(in_size_ == 0);
BOOST_ASSERT(out_pos_ == 0);
BOOST_ASSERT(out_end_ == 0);
BOOST_ASSERT(out_ == list_.end());
return;
}
auto const& front = list_.front();
assert(in_pos_ < front.size());
BOOST_ASSERT(in_pos_ < front.size());
if(out_ == list_.end())
{
assert(out_pos_ == 0);
assert(out_end_ == 0);
BOOST_ASSERT(out_pos_ == 0);
BOOST_ASSERT(out_end_ == 0);
}
else
{
auto const& out = *out_;
auto const& back = list_.back();
assert(out_end_ <= back.size());
assert(out_pos_ < out.size());
assert(&out != &front || out_pos_ >= in_pos_);
assert(&out != &front || out_pos_ - in_pos_ == in_size_);
assert(&out != &back || out_pos_ <= out_end_);
BOOST_ASSERT(out_end_ <= back.size());
BOOST_ASSERT(out_pos_ < out.size());
BOOST_ASSERT(&out != &front || out_pos_ >= in_pos_);
BOOST_ASSERT(&out != &front || out_pos_ - in_pos_ == in_size_);
BOOST_ASSERT(&out != &back || out_pos_ <= out_end_);
}
#endif
}

View File

@ -13,8 +13,8 @@
#include <beast/http/rfc7230.hpp>
#include <beast/http/detail/basic_parser_v1.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/assert.hpp>
#include <array>
#include <cassert>
#include <climits>
#include <cstdint>
#include <type_traits>

View File

@ -10,10 +10,10 @@
#include <beast/core/buffer_cat.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/assert.hpp>
#include <boost/logic/tribool.hpp>
#include <algorithm>
#include <array>
#include <cassert>
#include <cstddef>
#include <iterator>
#include <type_traits>

View File

@ -38,7 +38,7 @@
#include <beast/http/detail/rfc7230.hpp>
#include <beast/core/buffer_concepts.hpp>
#include <cassert>
#include <boost/assert.hpp>
namespace beast {
namespace http {
@ -170,7 +170,7 @@ write(boost::asio::const_buffer const& buffer, error_code& ec)
call_on_start(ec);
if(ec)
return errc();
assert(! cb_);
BOOST_ASSERT(! cb_);
cb(&self::call_on_method);
s_ = s_req_method;
break;
@ -194,7 +194,7 @@ write(boost::asio::const_buffer const& buffer, error_code& ec)
// VFALCO TODO Better checking for valid URL characters
if(! is_text(ch))
return err(parse_error::bad_uri);
assert(! cb_);
BOOST_ASSERT(! cb_);
cb(&self::call_on_uri);
s_ = s_req_url;
break;
@ -377,7 +377,7 @@ write(boost::asio::const_buffer const& buffer, error_code& ec)
}
if(! is_text(ch))
return err(parse_error::bad_reason);
assert(! cb_);
BOOST_ASSERT(! cb_);
cb(&self::call_on_reason);
s_ = s_res_reason;
break;
@ -429,7 +429,7 @@ write(boost::asio::const_buffer const& buffer, error_code& ec)
fs_ = h_general;
break;
}
assert(! cb_);
BOOST_ASSERT(! cb_);
cb(&self::call_on_field);
s_ = s_header_name;
break;
@ -549,7 +549,7 @@ write(boost::asio::const_buffer const& buffer, error_code& ec)
content_length_ = 0;
flags_ |= parse_flag::contentlength;
}
assert(! cb_);
BOOST_ASSERT(! cb_);
cb(&self::call_on_value);
s_ = s_header_value;
// fall through
@ -801,7 +801,7 @@ write(boost::asio::const_buffer const& buffer, error_code& ec)
return err(parse_error::bad_content_length);
if(fs_ == h_upgrade)
flags_ |= parse_flag::upgrade;
assert(! cb_);
BOOST_ASSERT(! cb_);
call_on_value(ec, boost::string_ref{"", 0});
if(ec)
return errc();
@ -880,7 +880,7 @@ write(boost::asio::const_buffer const& buffer, error_code& ec)
goto redo;
case s_header_value_unfold:
assert(! cb_);
BOOST_ASSERT(! cb_);
cb(&self::call_on_value);
s_ = s_header_value;
goto redo;
@ -921,7 +921,7 @@ write(boost::asio::const_buffer const& buffer, error_code& ec)
case s_headers_done:
{
assert(! cb_);
BOOST_ASSERT(! cb_);
call_on_headers(ec);
if(ec)
return errc();
@ -959,7 +959,7 @@ write(boost::asio::const_buffer const& buffer, error_code& ec)
}
case s_body_identity0:
assert(! cb_);
BOOST_ASSERT(! cb_);
cb(&self::call_on_body);
s_ = s_body_identity;
// fall through
@ -971,7 +971,7 @@ write(boost::asio::const_buffer const& buffer, error_code& ec)
n = end - p;
else
n = static_cast<std::size_t>(content_length_);
assert(content_length_ != 0 && content_length_ != no_content_length);
BOOST_ASSERT(content_length_ != 0 && content_length_ != no_content_length);
content_length_ -= n;
if(content_length_ == 0)
{
@ -984,7 +984,7 @@ write(boost::asio::const_buffer const& buffer, error_code& ec)
}
case s_body_identity_eof0:
assert(! cb_);
BOOST_ASSERT(! cb_);
cb(&self::call_on_body);
s_ = s_body_identity_eof;
// fall through
@ -1073,7 +1073,7 @@ write(boost::asio::const_buffer const& buffer, error_code& ec)
break;
case s_chunk_data0:
assert(! cb_);
BOOST_ASSERT(! cb_);
cb(&self::call_on_body);
s_ = s_chunk_data;
goto redo; // VFALCO fall through?

View File

@ -13,7 +13,7 @@
#include <beast/core/bind_handler.hpp>
#include <beast/core/handler_alloc.hpp>
#include <beast/core/stream_concepts.hpp>
#include <cassert>
#include <boost/assert.hpp>
namespace beast {
namespace http {
@ -161,7 +161,7 @@ operator()(error_code ec, std::size_t bytes_transferred, bool again)
// Caller will see eof on next read.
ec = {};
d.p.write_eof(ec);
assert(ec || d.p.complete());
BOOST_ASSERT(ec || d.p.complete());
// call handler
d.state = 99;
break;
@ -372,7 +372,7 @@ parse(SyncReadStream& stream, DynamicBuffer& dynabuf,
parser.write_eof(ec);
if(ec)
return;
assert(parser.complete());
BOOST_ASSERT(parser.complete());
break;
}
}
@ -434,7 +434,7 @@ read(SyncReadStream& stream, DynamicBuffer& dynabuf,
beast::http::parse(stream, dynabuf, p, ec);
if(ec)
return;
assert(p.complete());
BOOST_ASSERT(p.complete());
m = p.release();
}

View File

@ -15,8 +15,8 @@
#include <beast/core/static_streambuf.hpp>
#include <beast/core/static_string.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/assert.hpp>
#include <boost/endian/buffers.hpp>
#include <cassert>
#include <cstdint>
namespace beast {
@ -175,7 +175,7 @@ read_fh1(frame_header& fh, DynamicBuffer& db,
using boost::asio::buffer_copy;
using boost::asio::buffer_size;
std::uint8_t b[2];
assert(buffer_size(db.data()) >= sizeof(b));
BOOST_ASSERT(buffer_size(db.data()) >= sizeof(b));
db.consume(buffer_copy(buffer(b), db.data()));
std::size_t need;
fh.len = b[1] & 0x7f;
@ -250,7 +250,7 @@ read_fh2(frame_header& fh, DynamicBuffer& db,
case 126:
{
std::uint8_t b[2];
assert(buffer_size(db.data()) >= sizeof(b));
BOOST_ASSERT(buffer_size(db.data()) >= sizeof(b));
db.consume(buffer_copy(buffer(b), db.data()));
fh.len = big_uint16_to_native(&b[0]);
// length not canonical
@ -264,7 +264,7 @@ read_fh2(frame_header& fh, DynamicBuffer& db,
case 127:
{
std::uint8_t b[8];
assert(buffer_size(db.data()) >= sizeof(b));
BOOST_ASSERT(buffer_size(db.data()) >= sizeof(b));
db.consume(buffer_copy(buffer(b), db.data()));
fh.len = big_uint64_to_native(&b[0]);
// length not canonical
@ -279,7 +279,7 @@ read_fh2(frame_header& fh, DynamicBuffer& db,
if(fh.mask)
{
std::uint8_t b[4];
assert(buffer_size(db.data()) >= sizeof(b));
BOOST_ASSERT(buffer_size(db.data()) >= sizeof(b));
db.consume(buffer_copy(buffer(b), db.data()));
fh.key = little_uint32_to_native(&b[0]);
}
@ -301,7 +301,7 @@ read(ping_data& data, Buffers const& bs)
using boost::asio::buffer_copy;
using boost::asio::buffer_size;
using boost::asio::mutable_buffers_1;
assert(buffer_size(bs) <= data.max_size());
BOOST_ASSERT(buffer_size(bs) <= data.max_size());
data.resize(buffer_size(bs));
buffer_copy(mutable_buffers_1{
data.data(), data.size()}, bs);
@ -320,7 +320,7 @@ read(close_reason& cr,
using boost::asio::buffer_size;
using namespace boost::endian;
auto n = buffer_size(bs);
assert(n <= 125);
BOOST_ASSERT(n <= 125);
if(n == 0)
{
cr = close_reason{};

View File

@ -8,8 +8,8 @@
#ifndef BEAST_WEBSOCKET_DETAIL_INVOKABLE_HPP
#define BEAST_WEBSOCKET_DETAIL_INVOKABLE_HPP
#include <boost/assert.hpp>
#include <array>
#include <cassert>
#include <memory>
#include <new>
#include <utility>
@ -80,7 +80,7 @@ public:
// Engaged invokables must be invoked before
// destruction otherwise the io_service
// invariants are broken w.r.t completions.
assert(! base_);
BOOST_ASSERT(! base_);
}
#endif
@ -102,7 +102,7 @@ public:
// Engaged invokables must be invoked before
// assignment otherwise the io_service
// invariants are broken w.r.t completions.
assert(! base_);
BOOST_ASSERT(! base_);
if(other.base_)
{
@ -135,7 +135,7 @@ invokable::emplace(F&& f)
{
static_assert(sizeof(buf_type) >= sizeof(holder<F>),
"buffer too small");
assert(! base_);
BOOST_ASSERT(! base_);
::new(buf_) holder<F>(std::forward<F>(f));
base_ = reinterpret_cast<base*>(&buf_[0]);
}

View File

@ -19,7 +19,7 @@
#include <beast/http/message.hpp>
#include <beast/http/string_body.hpp>
#include <boost/asio/error.hpp>
#include <cassert>
#include <boost/assert.hpp>
#include <cstdint>
#include <functional>
#include <limits>

View File

@ -14,7 +14,7 @@
#include <beast/http/read.hpp>
#include <beast/core/handler_alloc.hpp>
#include <beast/core/prepare_buffers.hpp>
#include <cassert>
#include <boost/assert.hpp>
#include <memory>
#include <type_traits>

View File

@ -155,7 +155,7 @@ operator()(error_code ec, bool again)
// send close frame
d.state = 99;
d.ws.wr_close_ = true;
assert(! d.ws.wr_block_);
BOOST_ASSERT(! d.ws.wr_block_);
d.ws.wr_block_ = &d;
boost::asio::async_write(d.ws.stream_,
d.fb.data(), std::move(*this));

View File

@ -13,7 +13,7 @@
#include <beast/http/read.hpp>
#include <beast/http/write.hpp>
#include <beast/core/handler_alloc.hpp>
#include <cassert>
#include <boost/assert.hpp>
#include <memory>
namespace beast {

View File

@ -154,7 +154,7 @@ operator()(error_code ec, bool again)
case 1:
// send ping frame
d.state = 99;
assert(! d.ws.wr_block_);
BOOST_ASSERT(! d.ws.wr_block_);
d.ws.wr_block_ = &d;
boost::asio::async_write(d.ws.stream_,
d.fb.data(), std::move(*this));

View File

@ -12,8 +12,8 @@
#include <beast/core/handler_alloc.hpp>
#include <beast/core/prepare_buffers.hpp>
#include <beast/core/static_streambuf.hpp>
#include <boost/assert.hpp>
#include <boost/optional.hpp>
#include <cassert>
#include <memory>
namespace beast {
@ -330,7 +330,7 @@ operator()(error_code ec,std::size_t bytes_transferred, bool again)
{
// suspend
d.state = do_pong_resume;
assert(d.ws.wr_block_ != &d);
BOOST_ASSERT(d.ws.wr_block_ != &d);
d.ws.rd_op_.template emplace<
read_frame_op>(std::move(*this));
return;
@ -349,7 +349,7 @@ operator()(error_code ec,std::size_t bytes_transferred, bool again)
d.state = do_read_fh;
break;
}
assert(d.ws.rd_fh_.op == opcode::close);
BOOST_ASSERT(d.ws.rd_fh_.op == opcode::close);
{
detail::read(d.ws.cr_, d.fb.data(), code);
if(code != close_code::none)
@ -413,7 +413,7 @@ operator()(error_code ec,std::size_t bytes_transferred, bool again)
}
// send pong
d.state = do_pong + 1;
assert(! d.ws.wr_block_);
BOOST_ASSERT(! d.ws.wr_block_);
d.ws.wr_block_ = &d;
boost::asio::async_write(d.ws.stream_,
d.fb.data(), std::move(*this));
@ -455,7 +455,7 @@ operator()(error_code ec,std::size_t bytes_transferred, bool again)
case do_close:
d.state = do_close + 1;
d.ws.wr_close_ = true;
assert(! d.ws.wr_block_);
BOOST_ASSERT(! d.ws.wr_block_);
d.ws.wr_block_ = &d;
boost::asio::async_write(d.ws.stream_,
d.fb.data(), std::move(*this));
@ -498,7 +498,7 @@ operator()(error_code ec,std::size_t bytes_transferred, bool again)
// send close frame
d.state = do_fail + 4;
d.ws.wr_close_ = true;
assert(! d.ws.wr_block_);
BOOST_ASSERT(! d.ws.wr_block_);
d.ws.wr_block_ = &d;
boost::asio::async_write(d.ws.stream_,
d.fb.data(), std::move(*this));

View File

@ -29,9 +29,9 @@
#include <beast/core/prepare_buffers.hpp>
#include <beast/core/static_streambuf.hpp>
#include <beast/core/stream_concepts.hpp>
#include <boost/assert.hpp>
#include <boost/endian/buffers.hpp>
#include <algorithm>
#include <cassert>
#include <memory>
#include <utility>
@ -411,7 +411,7 @@ close(close_reason const& cr, error_code& ec)
{
static_assert(is_SyncStream<next_layer_type>::value,
"SyncStream requirements not met");
assert(! wr_close_);
BOOST_ASSERT(! wr_close_);
wr_close_ = true;
detail::frame_streambuf fb;
write_close<static_streambuf>(fb, cr);
@ -608,7 +608,7 @@ read_frame(frame_info& fi, DynamicBuffer& dynabuf, error_code& ec)
pong_cb_(payload);
continue;
}
assert(rd_fh_.op == opcode::close);
BOOST_ASSERT(rd_fh_.op == opcode::close);
{
detail::read(cr_, fb.data(), code);
if(code != close_code::none)

View File

@ -14,8 +14,8 @@
#include <beast/core/handler_alloc.hpp>
#include <beast/core/static_streambuf.hpp>
#include <beast/websocket/detail/frame.hpp>
#include <boost/assert.hpp>
#include <algorithm>
#include <cassert>
#include <memory>
namespace beast {
@ -199,7 +199,7 @@ operator()(error_code ec, bool again)
{
// send header and entire payload
d.state = 99;
assert(! d.ws.wr_block_);
BOOST_ASSERT(! d.ws.wr_block_);
d.ws.wr_block_ = &d;
boost::asio::async_write(d.ws.stream_,
buffer_cat(d.fh_buf.data(), d.cb),
@ -215,7 +215,7 @@ operator()(error_code ec, bool again)
detail::mask_inplace(mb, d.key);
// send header and payload
d.state = d.remain > 0 ? 2 : 99;
assert(! d.ws.wr_block_);
BOOST_ASSERT(! d.ws.wr_block_);
d.ws.wr_block_ = &d;
boost::asio::async_write(d.ws.stream_,
buffer_cat(d.fh_buf.data(),
@ -237,7 +237,7 @@ operator()(error_code ec, bool again)
// send payload
if(d.remain == 0)
d.state = 99;
assert(d.ws.wr_block_ == &d);
BOOST_ASSERT(d.ws.wr_block_ == &d);
boost::asio::async_write(
d.ws.stream_, mb, std::move(*this));
return;

View File

@ -12,8 +12,8 @@
#include <beast/core/prepare_buffers.hpp>
#include <beast/core/handler_alloc.hpp>
#include <beast/websocket/detail/frame.hpp>
#include <boost/assert.hpp>
#include <algorithm>
#include <cassert>
#include <memory>
namespace beast {

View File

@ -14,8 +14,8 @@
#include <beast/core/detail/ci_char_traits.hpp>
#include <beast/http/rfc7230.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/assert.hpp>
#include <boost/utility/string_ref.hpp>
#include <cassert>
#include <climits>
#include <map>
#include <new>