]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/uuid/test/test_random_generator.cpp
add subtree-ish sources for 12.0.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
18 template <typename RandomUuidGenerator>
19 void check_random_generator(RandomUuidGenerator& uuid_gen)
20 {
21 boost::uuids::uuid u1 = uuid_gen();
22 boost::uuids::uuid u2 = uuid_gen();
23
24 BOOST_TEST_NE(u1, u2);
25
26 // check variant
27 BOOST_TEST_EQ(u1.variant(), boost::uuids::uuid::variant_rfc_4122);
28
29 // version
30 BOOST_TEST_EQ(u1.version(), boost::uuids::uuid::version_random_number_based);
31 }
32
33 int main(int, char*[])
34 {
35 using namespace boost::uuids;
36
37 // default random number generator
38 random_generator uuid_gen1;
39 check_random_generator(uuid_gen1);
40
41 // specific random number generator
42 basic_random_generator<boost::rand48> uuid_gen2;
43 check_random_generator(uuid_gen2);
44
45 // pass by reference
46 boost::ecuyer1988 ecuyer1988_gen;
47 basic_random_generator<boost::ecuyer1988> uuid_gen3(ecuyer1988_gen);
48 check_random_generator(uuid_gen3);
49
50 // pass by pointer
51 boost::lagged_fibonacci607 lagged_fibonacci607_gen;
52 basic_random_generator<boost::lagged_fibonacci607> uuid_gen4(&lagged_fibonacci607_gen);
53 check_random_generator(uuid_gen4);
54
55 // random device
56 //basic_random_generator<boost::random_device> uuid_gen5;
57 //check_random_generator(uuid_gen5);
58
59 // there was a bug in basic_random_generator where it did not
60 // produce very random numbers. This checks for that bug.
61 uuid u = random_generator()();
62 if ( (u.data[4] == u.data[12]) &&
63 (u.data[5] == u.data[9] && u.data[5] == u.data[13]) &&
64 (u.data[7] == u.data[11] && u.data[7] == u.data[15]) &&
65 (u.data[10] == u.data[14]) )
66 {
67 BOOST_ERROR("basic_random_generator is not producing random uuids");
68 }
69
70 return boost::report_errors();
71 }