From 5b041193f2d95120a8b5aa76a6b875316bfb3428 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Tue, 8 Nov 2016 13:15:07 -0500 Subject: [PATCH] Increase code coverage --- CHANGELOG.md | 1 + include/beast/core/impl/prepare_buffers.ipp | 50 +++++++++++++++++-- include/beast/http/impl/parse_error.ipp | 3 +- include/beast/http/parse_error.hpp | 4 +- test/core/buffer_cat.cpp | 12 +++++ test/core/prepare_buffers.cpp | 55 +++++++++++++++++++++ test/http/parse_error.cpp | 5 +- 7 files changed, 119 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8a26f0e..426ea60d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ 1.0.0-b19 * Boost library min/max guidance +* Improvements to code coverage HTTP diff --git a/include/beast/core/impl/prepare_buffers.ipp b/include/beast/core/impl/prepare_buffers.ipp index 1bf469bc..a25c0952 100644 --- a/include/beast/core/impl/prepare_buffers.ipp +++ b/include/beast/core/impl/prepare_buffers.ipp @@ -59,10 +59,10 @@ public: std::bidirectional_iterator_tag; const_iterator() = default; - const_iterator(const_iterator&& other) = default; - const_iterator(const_iterator const& other) = default; - const_iterator& operator=(const_iterator&& other) = default; - const_iterator& operator=(const_iterator const& other) = default; + const_iterator(const_iterator&& other); + const_iterator(const_iterator const& other); + const_iterator& operator=(const_iterator&& other); + const_iterator& operator=(const_iterator const& other); bool operator==(const_iterator const& other) const @@ -126,6 +126,44 @@ private: } }; +template +prepared_buffers::const_iterator:: +const_iterator(const_iterator&& other) + : b_(other.b_) + , it_(std::move(other.it_)) +{ +} + +template +prepared_buffers::const_iterator:: +const_iterator(const_iterator const& other) + : b_(other.b_) + , it_(other.it_) +{ +} + +template +auto +prepared_buffers::const_iterator:: +operator=(const_iterator&& other) -> + const_iterator& +{ + b_ = other.b_; + it_ = std::move(other.it_); + return *this; +} + +template +auto +prepared_buffers::const_iterator:: +operator=(const_iterator const& other) -> + const_iterator& +{ + b_ = other.b_; + it_ = other.it_; + return *this; +} + template prepared_buffers:: prepared_buffers(prepared_buffers&& other) @@ -187,6 +225,7 @@ prepared_buffers(std::size_t n, BufferSequence const& bs) } template +inline auto prepared_buffers::begin() const -> const_iterator @@ -195,6 +234,7 @@ prepared_buffers::begin() const -> } template +inline auto prepared_buffers::end() const -> const_iterator @@ -207,7 +247,7 @@ inline prepared_buffers prepare_buffers(std::size_t n, BufferSequence const& buffers) { - return prepared_buffers(n, buffers); + return prepared_buffers{n, buffers}; } } // beast diff --git a/include/beast/http/impl/parse_error.ipp b/include/beast/http/impl/parse_error.ipp index 155eb6eb..25b5374e 100644 --- a/include/beast/http/impl/parse_error.ipp +++ b/include/beast/http/impl/parse_error.ipp @@ -52,9 +52,8 @@ public: case parse_error::invalid_ext_val: return "invalid ext val"; case parse_error::headers_too_big: return "headers size limit exceeded"; case parse_error::body_too_big: return "body size limit exceeded"; - case parse_error::short_read: return "unexpected end of data"; default: - return "parse error"; + case parse_error::short_read: return "unexpected end of data"; } } diff --git a/include/beast/http/parse_error.hpp b/include/beast/http/parse_error.hpp index 72025f7d..56f8dc2b 100644 --- a/include/beast/http/parse_error.hpp +++ b/include/beast/http/parse_error.hpp @@ -36,9 +36,7 @@ enum class parse_error headers_too_big, body_too_big, - short_read, - - general + short_read }; } // http diff --git a/test/core/buffer_cat.cpp b/test/core/buffer_cat.cpp index 803d2efc..7833f2b9 100644 --- a/test/core/buffer_cat.cpp +++ b/test/core/buffer_cat.cpp @@ -110,6 +110,18 @@ public: pass(); } + // decrement iterator + { + auto const rbegin = + make_reverse_iterator(bs.end()); + auto const rend = + make_reverse_iterator(bs.begin()); + std::size_t n = 0; + for(auto it = rbegin; it != rend; ++it) + n += buffer_size(*it); + BEAST_EXPECT(n == 9); + } + try { std::size_t n = 0; diff --git a/test/core/prepare_buffers.cpp b/test/core/prepare_buffers.cpp index eb40d4c4..44debdfa 100644 --- a/test/core/prepare_buffers.cpp +++ b/test/core/prepare_buffers.cpp @@ -18,6 +18,57 @@ namespace beast { class prepare_buffers_test : public beast::unit_test::suite { public: + template + static + std::size_t + bsize1(ConstBufferSequence const& bs) + { + using boost::asio::buffer_size; + std::size_t n = 0; + for(auto it = bs.begin(); it != bs.end(); ++it) + n += buffer_size(*it); + return n; + } + + template + static + std::size_t + bsize2(ConstBufferSequence const& bs) + { + using boost::asio::buffer_size; + std::size_t n = 0; + for(auto it = bs.begin(); it != bs.end(); it++) + n += buffer_size(*it); + return n; + } + + template + static + std::size_t + bsize3(ConstBufferSequence const& bs) + { + using boost::asio::buffer_size; + std::size_t n = 0; + for(auto it = bs.end(); it != bs.begin();) + n += buffer_size(*--it); + return n; + } + + template + static + std::size_t + bsize4(ConstBufferSequence const& bs) + { + using boost::asio::buffer_size; + std::size_t n = 0; + for(auto it = bs.end(); it != bs.begin();) + { + it--; + n += buffer_size(*it); + } + return n; + } + template static std::string @@ -97,6 +148,10 @@ public: const_buffer{&b[1], 1}, const_buffer{&b[2], 1}}}; auto pb = prepare_buffers(2, bs); + BEAST_EXPECT(bsize1(pb) == 2); + BEAST_EXPECT(bsize2(pb) == 2); + BEAST_EXPECT(bsize3(pb) == 2); + BEAST_EXPECT(bsize4(pb) == 2); std::size_t n = 0; for(auto it = pb.end(); it != pb.begin(); --it) { diff --git a/test/http/parse_error.cpp b/test/http/parse_error.cpp index 1bbb3025..ac8c95ca 100644 --- a/test/http/parse_error.cpp +++ b/test/http/parse_error.cpp @@ -46,8 +46,11 @@ public: check("http", parse_error::bad_content_length); check("http", parse_error::illegal_content_length); check("http", parse_error::invalid_chunk_size); + check("http", parse_error::invalid_ext_name); + check("http", parse_error::invalid_ext_val); + check("http", parse_error::headers_too_big); + check("http", parse_error::body_too_big); check("http", parse_error::short_read); - check("http", parse_error::general); } };