]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/leaf/test/error_id_test.cpp
1 // Copyright (c) 2018-2020 Emil Dotchevski and Reverge Studios, Inc.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/leaf/error.hpp>
7 #include "lightweight_test.hpp"
13 namespace leaf
= boost::leaf
;
15 constexpr int ids_per_thread
= 10000;
17 std::vector
<int> generate_ids()
20 ids
.reserve(ids_per_thread
);
21 for(int i
=0; i
!=ids_per_thread
-1; ++i
)
23 int id
= leaf::leaf_detail::new_id();
24 BOOST_TEST_NE(id
&1, 0);
25 int last
= leaf::leaf_detail::current_id();
26 BOOST_TEST_EQ(last
, leaf::leaf_detail::current_id());
27 BOOST_TEST_NE(last
&1, 0);
28 BOOST_TEST_EQ(last
, id
);
40 BOOST_TEST_EQ(e1
.value(), 0);
42 BOOST_TEST_EQ(e2
.value(), 0);
44 BOOST_TEST(!(e1
!=e2
));
50 leaf::error_id e2
= leaf::new_error();
52 BOOST_TEST_EQ(e1
.value(), 0);
54 BOOST_TEST_EQ(e2
.value(), 1);
55 BOOST_TEST(!(e1
==e2
));
61 leaf::error_id e1
= leaf::new_error();
62 leaf::error_id e2
= leaf::new_error();
64 BOOST_TEST_EQ(e1
.value(), 5);
66 BOOST_TEST_EQ(e2
.value(), 9);
67 BOOST_TEST(!(e1
==e2
));
73 leaf::error_id e1
= leaf::new_error();
74 leaf::error_id e2
= e1
;
76 BOOST_TEST_EQ(e1
.value(), 13);
78 BOOST_TEST_EQ(e2
.value(), 13);
80 BOOST_TEST(!(e1
!=e2
));
85 leaf::error_id e1
= leaf::new_error();
86 leaf::error_id e2
; e2
= e1
;
88 BOOST_TEST_EQ(e1
.value(), 17);
90 BOOST_TEST_EQ(e2
.value(), 17);
92 BOOST_TEST(!(e1
!=e2
));
96 #ifdef BOOST_LEAF_NO_THREADS
97 std::vector
<int> all_ids
= generate_ids();
99 constexpr int thread_count
= 100;
100 using thread_ids
= std::future
<std::vector
<int>>;
101 std::vector
<thread_ids
> fut
;
102 fut
.reserve(thread_count
);
104 std::back_inserter(fut
),
108 return std::async(std::launch::async
, &generate_ids
);
110 std::vector
<int> all_ids
;
114 all_ids
.insert(all_ids
.end(), fv
.begin(), fv
.end());
117 std::sort(all_ids
.begin(), all_ids
.end());
118 auto u
= std::unique(all_ids
.begin(), all_ids
.end());
119 BOOST_TEST(u
==all_ids
.end());
121 return boost::report_errors();