diff --git a/CHANGELOG.md b/CHANGELOG.md index e623521e..a6bad614 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Fix error handling in http server examples * Fix CMake scripts for MinGW * Better WebSocket decorator +* Use BOOST_ASSERT -------------------------------------------------------------------------------- diff --git a/extras/beast/unit_test/runner.hpp b/extras/beast/unit_test/runner.hpp index 3530c46b..c0091c45 100644 --- a/extras/beast/unit_test/runner.hpp +++ b/extras/beast/unit_test/runner.hpp @@ -9,7 +9,7 @@ #define BEAST_UNIT_TEST_RUNNER_H_INCLUDED #include -#include +#include #include #include #include @@ -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 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; diff --git a/extras/beast/unit_test/suite_list.hpp b/extras/beast/unit_test/suite_list.hpp index 77020e92..44bb4f90 100644 --- a/extras/beast/unit_test/suite_list.hpp +++ b/extras/beast/unit_test/suite_list.hpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include #include @@ -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( diff --git a/include/beast/core/impl/basic_streambuf.ipp b/include/beast/core/impl/basic_streambuf.ipp index 50bb43e0..76f15c57 100644 --- a/include/beast/core/impl/basic_streambuf.ipp +++ b/include/beast/core/impl/basic_streambuf.ipp @@ -9,8 +9,8 @@ #define BEAST_IMPL_BASIC_STREAMBUF_IPP #include +#include #include -#include #include #include #include @@ -816,36 +816,36 @@ basic_streambuf::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 } diff --git a/include/beast/http/basic_parser_v1.hpp b/include/beast/http/basic_parser_v1.hpp index 555d3f6e..86b9c2d5 100644 --- a/include/beast/http/basic_parser_v1.hpp +++ b/include/beast/http/basic_parser_v1.hpp @@ -13,8 +13,8 @@ #include #include #include +#include #include -#include #include #include #include diff --git a/include/beast/http/detail/chunk_encode.hpp b/include/beast/http/detail/chunk_encode.hpp index 62accf16..3c03dca1 100644 --- a/include/beast/http/detail/chunk_encode.hpp +++ b/include/beast/http/detail/chunk_encode.hpp @@ -10,10 +10,10 @@ #include #include +#include #include #include #include -#include #include #include #include diff --git a/include/beast/http/impl/basic_parser_v1.ipp b/include/beast/http/impl/basic_parser_v1.ipp index 918c52cf..60fd866d 100644 --- a/include/beast/http/impl/basic_parser_v1.ipp +++ b/include/beast/http/impl/basic_parser_v1.ipp @@ -38,7 +38,7 @@ #include #include -#include +#include 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(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? diff --git a/include/beast/http/impl/read.ipp b/include/beast/http/impl/read.ipp index b2acc0d9..4dab0461 100644 --- a/include/beast/http/impl/read.ipp +++ b/include/beast/http/impl/read.ipp @@ -13,7 +13,7 @@ #include #include #include -#include +#include 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(); } diff --git a/include/beast/websocket/detail/frame.hpp b/include/beast/websocket/detail/frame.hpp index 672d11c1..9af1c009 100644 --- a/include/beast/websocket/detail/frame.hpp +++ b/include/beast/websocket/detail/frame.hpp @@ -15,8 +15,8 @@ #include #include #include +#include #include -#include #include 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{}; diff --git a/include/beast/websocket/detail/invokable.hpp b/include/beast/websocket/detail/invokable.hpp index df5b46de..596b44e4 100644 --- a/include/beast/websocket/detail/invokable.hpp +++ b/include/beast/websocket/detail/invokable.hpp @@ -8,8 +8,8 @@ #ifndef BEAST_WEBSOCKET_DETAIL_INVOKABLE_HPP #define BEAST_WEBSOCKET_DETAIL_INVOKABLE_HPP +#include #include -#include #include #include #include @@ -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), "buffer too small"); - assert(! base_); + BOOST_ASSERT(! base_); ::new(buf_) holder(std::forward(f)); base_ = reinterpret_cast(&buf_[0]); } diff --git a/include/beast/websocket/detail/stream_base.hpp b/include/beast/websocket/detail/stream_base.hpp index 5d66747f..0c81b006 100644 --- a/include/beast/websocket/detail/stream_base.hpp +++ b/include/beast/websocket/detail/stream_base.hpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/beast/websocket/impl/accept_op.ipp b/include/beast/websocket/impl/accept_op.ipp index 38443eb4..4fb41d3c 100644 --- a/include/beast/websocket/impl/accept_op.ipp +++ b/include/beast/websocket/impl/accept_op.ipp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include diff --git a/include/beast/websocket/impl/close_op.ipp b/include/beast/websocket/impl/close_op.ipp index 4884a2a1..bed4e81c 100644 --- a/include/beast/websocket/impl/close_op.ipp +++ b/include/beast/websocket/impl/close_op.ipp @@ -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)); diff --git a/include/beast/websocket/impl/handshake_op.ipp b/include/beast/websocket/impl/handshake_op.ipp index 8443fd9a..4e408b72 100644 --- a/include/beast/websocket/impl/handshake_op.ipp +++ b/include/beast/websocket/impl/handshake_op.ipp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include namespace beast { diff --git a/include/beast/websocket/impl/ping_op.ipp b/include/beast/websocket/impl/ping_op.ipp index 8fc9936d..4034754a 100644 --- a/include/beast/websocket/impl/ping_op.ipp +++ b/include/beast/websocket/impl/ping_op.ipp @@ -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)); diff --git a/include/beast/websocket/impl/read_frame_op.ipp b/include/beast/websocket/impl/read_frame_op.ipp index 0ba00176..fea01a6c 100644 --- a/include/beast/websocket/impl/read_frame_op.ipp +++ b/include/beast/websocket/impl/read_frame_op.ipp @@ -12,8 +12,8 @@ #include #include #include +#include #include -#include #include 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)); diff --git a/include/beast/websocket/impl/stream.ipp b/include/beast/websocket/impl/stream.ipp index 4c69a032..9c9493c9 100644 --- a/include/beast/websocket/impl/stream.ipp +++ b/include/beast/websocket/impl/stream.ipp @@ -29,9 +29,9 @@ #include #include #include +#include #include #include -#include #include #include @@ -411,7 +411,7 @@ close(close_reason const& cr, error_code& ec) { static_assert(is_SyncStream::value, "SyncStream requirements not met"); - assert(! wr_close_); + BOOST_ASSERT(! wr_close_); wr_close_ = true; detail::frame_streambuf fb; write_close(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) diff --git a/include/beast/websocket/impl/write_frame_op.ipp b/include/beast/websocket/impl/write_frame_op.ipp index 2bc9e74f..2bbf250d 100644 --- a/include/beast/websocket/impl/write_frame_op.ipp +++ b/include/beast/websocket/impl/write_frame_op.ipp @@ -14,8 +14,8 @@ #include #include #include +#include #include -#include #include 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; diff --git a/include/beast/websocket/impl/write_op.ipp b/include/beast/websocket/impl/write_op.ipp index 3aa48361..225d523e 100644 --- a/include/beast/websocket/impl/write_op.ipp +++ b/include/beast/websocket/impl/write_op.ipp @@ -12,8 +12,8 @@ #include #include #include +#include #include -#include #include namespace beast { diff --git a/test/http/basic_parser_v1.cpp b/test/http/basic_parser_v1.cpp index 304be84f..3b0144e1 100644 --- a/test/http/basic_parser_v1.cpp +++ b/test/http/basic_parser_v1.cpp @@ -14,8 +14,8 @@ #include #include #include +#include #include -#include #include #include #include