2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_TEST_FUZZ_HPP
11 #define BOOST_BEAST_TEST_FUZZ_HPP
13 #include <boost/beast/core/static_string.hpp>
14 #include <boost/beast/core/string.hpp>
32 template<class Unsigned>
34 operator()(Unsigned n)
36 return static_cast<Unsigned>(
37 std::uniform_int_distribution<
38 Unsigned>{0, n-1}(rng_));
42 template<std::size_t N, class Rand, class F>
46 static_string<N> const& input,
52 static_string<N> mod{input};
53 for(auto i = repeat; i; --i)
58 if(mod.size() >= mod.max_size())
60 mod.insert(r(mod.size() + 1), 1,
61 static_cast<char>(r(256)));
67 mod.erase(r(mod.size()), 1);
74 auto off = r(mod.size() - 1);
75 auto const temp = mod[off];
76 mod[off] = mod[off + 1];
85 std::geometric_distribution<
86 std::size_t>{}(r.rng()),
87 mod.max_size() - mod.size());
90 auto off = r(mod.size());
91 mod.insert(off, n, mod[off + 1]);
95 f(string_view{mod.data(), mod.size()});
97 fuzz(mod, repeat, depth - 1, r, f);