]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/uuid/test/test_random_generator.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / uuid / test / test_random_generator.cpp
1 // (C) Copyright Andy Tompkins 2010. Permission to copy, use, modify, sell and
2 // distribute this software is granted provided this copyright notice appears
3 // in all copies. This software is provided "as is" without express or implied
4 // warranty, and with no claim as to its suitability for any purpose.
5
6 // Distributed under the Boost Software License, Version 1.0. (See
7 // accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 // libs/uuid/test/test_random_generator.cpp -------------------------------//
11
12 #include <boost/uuid/uuid.hpp>
13 #include <boost/uuid/random_generator.hpp>
14 #include <boost/uuid/uuid_io.hpp>
15 #include <boost/detail/lightweight_test.hpp>
16 #include <boost/random.hpp>
17 #include <boost/random/random_device.hpp>
18
19 template <typename RandomUuidGenerator>
20 void check_random_generator(RandomUuidGenerator& uuid_gen)
21 {
22 boost::uuids::uuid u1 = uuid_gen();
23 boost::uuids::uuid u2 = uuid_gen();
24
25 BOOST_TEST_NE(u1, u2);
26
27 // check variant
28 BOOST_TEST_EQ(u1.variant(), boost::uuids::uuid::variant_rfc_4122);
29
30 // version
31 BOOST_TEST_EQ(u1.version(), boost::uuids::uuid::version_random_number_based);
32 }
33
34 int main(int, char*[])
35 {
36 using namespace boost::uuids;
37
38 // default random number generator
39 random_generator uuid_gen1;
40 check_random_generator(uuid_gen1);
41
42 // specific random number generator
43 basic_random_generator<boost::rand48> uuid_gen2;
44 check_random_generator(uuid_gen2);
45
46 // pass by reference
47 boost::ecuyer1988 ecuyer1988_gen;
48 basic_random_generator<boost::ecuyer1988> uuid_gen3(ecuyer1988_gen);
49 check_random_generator(uuid_gen3);
50
51 // pass by pointer
52 boost::lagged_fibonacci607 lagged_fibonacci607_gen;
53 basic_random_generator<boost::lagged_fibonacci607> uuid_gen4(&lagged_fibonacci607_gen);
54 check_random_generator(uuid_gen4);
55
56 // random device
57 basic_random_generator<boost::random::random_device> uuid_gen5;
58 check_random_generator(uuid_gen5);
59
60 // there was a bug in basic_random_generator where it did not
61 // produce very random numbers. This checks for that bug.
62 uuid u = random_generator()();
63 if ( (u.data[4] == u.data[12]) &&
64 (u.data[5] == u.data[9] && u.data[5] == u.data[13]) &&
65 (u.data[7] == u.data[11] && u.data[7] == u.data[15]) &&
66 (u.data[10] == u.data[14]) )
67 {
68 BOOST_ERROR("basic_random_generator is not producing random uuids");
69 }
70
71 return boost::report_errors();
72 }