Files
boost_beast/test/beast/websocket/_detail_prng.cpp
T

77 lines
1.7 KiB
C++
Raw Normal View History

2019-01-19 07:23:47 -08:00
//
2019-02-21 07:00:31 -08:00
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
2019-01-19 07:23:47 -08:00
//
// 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)
//
// Official repository: https://github.com/boostorg/beast
//
// Test that header file is self-contained.
#include <boost/beast/websocket/detail/prng.hpp>
#include <boost/beast/_experimental/unit_test/suite.hpp>
namespace boost {
namespace beast {
namespace websocket {
namespace detail {
2019-05-19 19:30:05 +02:00
#ifdef BOOST_BEAST_TEST_STATIC_PRNG_SEED
auto prng_init = []()
{
// Workaround for https://bugs.launchpad.net/ubuntu/+source/valgrind/+bug/1501545
std::seed_seq seq{{0xDEAD, 0xBEEF}};
detail::prng_seed(&seq);
return 0;
}();
#endif // BOOST_BEAST_TEST_STATIC_PRNG_SEED
2019-01-19 07:23:47 -08:00
class prng_test
: public beast::unit_test::suite
{
public:
#if 0
char const* name() const noexcept //override
{
return "boost.beast.websocket.detail.prng";
}
#endif
template <class F>
void
testPrng(F const& f)
{
2019-06-16 23:03:26 +02:00
auto const min = std::numeric_limits<std::uint32_t>::min();
auto const max = std::numeric_limits<std::uint32_t>::max();
2019-01-19 07:23:47 -08:00
{
auto v = f()();
BEAST_EXPECT(
2019-06-16 23:03:26 +02:00
v >= min &&
v <= max);
2019-01-19 07:23:47 -08:00
}
{
auto v = f()();
BEAST_EXPECT(
2019-06-16 23:03:26 +02:00
v >= min &&
v <= max);
2019-01-19 07:23:47 -08:00
}
}
void
run() override
{
testPrng([]{ return make_prng(true); });
testPrng([]{ return make_prng(false); });
}
};
//static prng_test t;
BEAST_DEFINE_TESTSUITE(beast,websocket,prng);
} // detail
} // websocket
} // beast
} // boost