| 1 | // |
|---|---|
| 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) |
| 3 | // |
| 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) |
| 6 | // |
| 7 | // Official repository: https://github.com/boostorg/beast |
| 8 | // |
| 9 | |
| 10 | // Test that header file is self-contained. |
| 11 | #include <boost/beast/websocket/detail/prng.hpp> |
| 12 | |
| 13 | #include <boost/beast/_experimental/unit_test/suite.hpp> |
| 14 | |
| 15 | namespace boost { |
| 16 | namespace beast { |
| 17 | namespace websocket { |
| 18 | namespace detail { |
| 19 | |
| 20 | #ifdef BOOST_BEAST_TEST_STATIC_PRNG_SEED |
| 21 | auto prng_init = []() |
| 22 | { |
| 23 | // Workaround for https://bugs.launchpad.net/ubuntu/+source/valgrind/+bug/1501545 |
| 24 | std::seed_seq seq{{0xDEAD, 0xBEEF}}; |
| 25 | detail::prng_seed(&seq); |
| 26 | return 0; |
| 27 | }(); |
| 28 | #endif // BOOST_BEAST_TEST_STATIC_PRNG_SEED |
| 29 | |
| 30 | class prng_test |
| 31 | : public beast::unit_test::suite |
| 32 | { |
| 33 | public: |
| 34 | #if 0 |
| 35 | char const* name() const noexcept //override |
| 36 | { |
| 37 | return "boost.beast.websocket.detail.prng"; |
| 38 | } |
| 39 | #endif |
| 40 | |
| 41 | template <class F> |
| 42 | void |
| 43 | testPrng(F const& f) |
| 44 | { |
| 45 | auto const mn = (std::numeric_limits<std::uint32_t>::min)(); |
| 46 | auto const mx = (std::numeric_limits<std::uint32_t>::max)(); |
| 47 | |
| 48 | { |
| 49 | auto v = f()(); |
| 50 | BEAST_EXPECT( |
| 51 | v >= mn && |
| 52 | v <= mx); |
| 53 | } |
| 54 | { |
| 55 | auto v = f()(); |
| 56 | BEAST_EXPECT( |
| 57 | v >= mn && |
| 58 | v <= mx); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | run() override |
| 64 | { |
| 65 | testPrng(f: []{ return make_prng(secure: true); }); |
| 66 | testPrng(f: []{ return make_prng(secure: false); }); |
| 67 | } |
| 68 | }; |
| 69 | |
| 70 | //static prng_test t; |
| 71 | BEAST_DEFINE_TESTSUITE(beast,websocket,prng); |
| 72 | |
| 73 | } // detail |
| 74 | } // websocket |
| 75 | } // beast |
| 76 | } // boost |
| 77 |
