forked from boostorg/beast
Refactor chunked parsing (API Change):
* parser now has a callback feature for intercepting chunk headers and chunk bodies * The names for basic_parser derived class callbacks have been refactored * basic_parser offers an additional callback for distinguishing chunk body data. Actions Required: * Adjust signatures for required members of user-defined subclasses of basic_parser * Use the new basic_parser chunk callbacks for accessing chunk extensions and chunk bodies.
This commit is contained in:
1 parent
cc73d883be
commit
4b71aa67e0
27 files changed
+1851
-269
No files matched your search
@@ -0,0 +1,101 @@
|
||||
//
|
||||
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef BEAST_TEST_FUZZ_HPP
|
||||
#define BEAST_TEST_FUZZ_HPP
|
||||
|
||||
#include <beast/core/static_string.hpp>
|
||||
#include <beast/core/string.hpp>
|
||||
#include <random>
|
||||
|
||||
namespace beast {
|
||||
namespace test {
|
||||
|
||||
class fuzz_rand
|
||||
{
|
||||
std::mt19937 rng_;
|
||||
|
||||
public:
|
||||
std::mt19937&
|
||||
rng()
|
||||
{
|
||||
return rng_;
|
||||
}
|
||||
|
||||
template<class Unsigned>
|
||||
Unsigned
|
||||
operator()(Unsigned n)
|
||||
{
|
||||
return static_cast<Unsigned>(
|
||||
std::uniform_int_distribution<
|
||||
Unsigned>{0, n-1}(rng_));
|
||||
}
|
||||
};
|
||||
|
||||
template<std::size_t N, class Rand, class F>
|
||||
static
|
||||
void
|
||||
fuzz(
|
||||
static_string<N> const& input,
|
||||
std::size_t repeat,
|
||||
std::size_t depth,
|
||||
Rand& r,
|
||||
F const& f)
|
||||
{
|
||||
static_string<N> mod{input};
|
||||
for(auto i = repeat; i; --i)
|
||||
{
|
||||
switch(r(4))
|
||||
{
|
||||
case 0: // insert
|
||||
if(mod.size() >= mod.max_size())
|
||||
continue;
|
||||
mod.insert(r(mod.size() + 1), 1,
|
||||
static_cast<char>(r(256)));
|
||||
break;
|
||||
|
||||
case 1: // erase
|
||||
if(mod.size() == 0)
|
||||
continue;
|
||||
mod.erase(r(mod.size()), 1);
|
||||
break;
|
||||
|
||||
case 2: // swap
|
||||
{
|
||||
if(mod.size() <= 1)
|
||||
continue;
|
||||
auto off = r(mod.size() - 1);
|
||||
auto const temp = mod[off];
|
||||
mod[off] = mod[off + 1];
|
||||
mod[off + 1] = temp;
|
||||
break;
|
||||
}
|
||||
case 3: // repeat
|
||||
{
|
||||
if(mod.empty())
|
||||
continue;
|
||||
auto n = (std::min)(
|
||||
std::geometric_distribution<
|
||||
std::size_t>{}(r.rng()),
|
||||
mod.max_size() - mod.size());
|
||||
if(n == 0)
|
||||
continue;
|
||||
auto off = r(mod.size());
|
||||
mod.insert(off, n, mod[off + 1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
f(string_view{mod.data(), mod.size()});
|
||||
if(depth > 0)
|
||||
fuzz(mod, repeat, depth - 1, r, f);
|
||||
}
|
||||
}
|
||||
|
||||
} // test
|
||||
} // beast
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user