]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/safe_numerics/test/test_checked_xor.cpp
1 // Copyright (c) 2012 Robert Ramey
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
9 #include <boost/core/demangle.hpp>
10 #include <boost/safe_numerics/checked_result_operations.hpp>
11 #include <boost/safe_numerics/checked_integer.hpp>
13 // note: T should be of tyme checked_result<R> for some integer type R
15 bool test_checked_xor(
20 using namespace boost::safe_numerics
;
21 const T result
= v1
^ v2
;
23 << v1
<< " ^ " << v2
<< " -> " << result
26 switch(expected_result
){
28 if(result
.exception()){
30 << "erroneously detected error in exclusive or "
37 if(safe_numerics_error::negative_overflow_error
== result
.m_e
)
40 if(safe_numerics_error::positive_overflow_error
== result
.m_e
)
43 if(safe_numerics_error::range_error
== result
.m_e
)
47 << "failed to detect error in exclusive or "
48 << std::hex
<< result
<< "(" << std::dec
<< result
<< ")"
49 << " != "<< v1
<< " ^ " << v2
55 #include "test_checked_xor.hpp"
57 template<typename T
, typename First
, typename Second
>
58 struct test_signed_pair
{
59 bool operator()() const {
60 std::size_t i
= First();
61 std::size_t j
= Second();
62 std::cout
<< std::dec
<< i
<< ',' << j
<< ','
63 << "testing " << boost::core::demangle(typeid(T
).name()) << ' ';
64 return test_checked_xor(
67 signed_xor_results
[i
][j
]
72 template<typename T
, typename First
, typename Second
>
73 struct test_unsigned_pair
{
74 bool operator()() const {
75 std::size_t i
= First();
76 std::size_t j
= Second();
77 std::cout
<< std::dec
<< i
<< ',' << j
<< ','
78 << "testing " << boost::core::demangle(typeid(T
).name()) << ' ';
79 return test_checked_xor(
80 unsigned_values
<T
>[i
],
81 unsigned_values
<T
>[j
],
82 unsigned_xor_results
[i
][j
]
87 #include "check_symmetry.hpp"
89 #include <boost/mp11/algorithm.hpp>
92 using namespace boost::mp11
;
93 // sanity check on test matrix - should be symetrical
94 check_symmetry(signed_xor_results
);
95 check_symmetry(unsigned_xor_results
);
99 std::cout
<< "*** testing signed values\n";
105 signed_value_indices
,
112 std::cout
<< "*** testing unsigned values\n";
118 unsigned_value_indices
, unsigned_value_indices
124 std::cout
<< (rval
? "success!" : "failure") << std::endl
;