Increase code coverage

This commit is contained in:
Vinnie Falco
2016-11-08 13:15:07 -05:00
parent 6d2195514d
commit 5b041193f2
7 changed files with 119 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
1.0.0-b19
* Boost library min/max guidance
* Improvements to code coverage
HTTP

View File

@@ -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<class BufferSequence>
prepared_buffers<BufferSequence>::const_iterator::
const_iterator(const_iterator&& other)
: b_(other.b_)
, it_(std::move(other.it_))
{
}
template<class BufferSequence>
prepared_buffers<BufferSequence>::const_iterator::
const_iterator(const_iterator const& other)
: b_(other.b_)
, it_(other.it_)
{
}
template<class BufferSequence>
auto
prepared_buffers<BufferSequence>::const_iterator::
operator=(const_iterator&& other) ->
const_iterator&
{
b_ = other.b_;
it_ = std::move(other.it_);
return *this;
}
template<class BufferSequence>
auto
prepared_buffers<BufferSequence>::const_iterator::
operator=(const_iterator const& other) ->
const_iterator&
{
b_ = other.b_;
it_ = other.it_;
return *this;
}
template<class BufferSequence>
prepared_buffers<BufferSequence>::
prepared_buffers(prepared_buffers&& other)
@@ -187,6 +225,7 @@ prepared_buffers(std::size_t n, BufferSequence const& bs)
}
template<class BufferSequence>
inline
auto
prepared_buffers<BufferSequence>::begin() const ->
const_iterator
@@ -195,6 +234,7 @@ prepared_buffers<BufferSequence>::begin() const ->
}
template<class BufferSequence>
inline
auto
prepared_buffers<BufferSequence>::end() const ->
const_iterator
@@ -207,7 +247,7 @@ inline
prepared_buffers<BufferSequence>
prepare_buffers(std::size_t n, BufferSequence const& buffers)
{
return prepared_buffers<BufferSequence>(n, buffers);
return prepared_buffers<BufferSequence>{n, buffers};
}
} // beast

View File

@@ -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";
}
}

View File

@@ -36,9 +36,7 @@ enum class parse_error
headers_too_big,
body_too_big,
short_read,
general
short_read
};
} // http

View File

@@ -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;

View File

@@ -18,6 +18,57 @@ namespace beast {
class prepare_buffers_test : public beast::unit_test::suite
{
public:
template<class ConstBufferSequence>
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<class ConstBufferSequence>
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<class ConstBufferSequence>
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<class ConstBufferSequence>
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<class ConstBufferSequence>
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)
{

View File

@@ -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);
}
};