File indexing completed on 2025-01-18 09:52:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_TEST_TOOLS_DETAIL_BITWISE_MANIP_HPP_012705GER
0013 #define BOOST_TEST_TOOLS_DETAIL_BITWISE_MANIP_HPP_012705GER
0014
0015
0016 #include <boost/test/tools/detail/fwd.hpp>
0017 #include <boost/test/tools/detail/indirections.hpp>
0018
0019 #include <boost/test/tools/assertion_result.hpp>
0020 #include <boost/test/tools/assertion.hpp>
0021
0022
0023 #include <climits> // for CHAR_BIT
0024
0025 #include <boost/test/detail/suppress_warnings.hpp>
0026
0027
0028
0029 namespace boost {
0030 namespace test_tools {
0031
0032
0033
0034
0035
0036
0037
0038 struct bitwise {};
0039
0040
0041
0042 inline unit_test::lazy_ostream &
0043 operator<<( unit_test::lazy_ostream &o, bitwise ) { return o; }
0044
0045
0046 inline std::ostream&
0047 operator<<( std::ostream& o, bitwise ) { return o; }
0048
0049
0050
0051
0052 namespace tt_detail {
0053
0054
0055
0056
0057
0058
0059 template<typename Lhs, typename Rhs, typename E>
0060 inline assertion_result
0061 bitwise_compare(Lhs const& lhs, Rhs const& rhs, E const& expr )
0062 {
0063 assertion_result pr( true );
0064
0065 std::size_t left_bit_size = sizeof(Lhs)*CHAR_BIT;
0066 std::size_t right_bit_size = sizeof(Rhs)*CHAR_BIT;
0067
0068 static Lhs const leftOne( 1 );
0069 static Rhs const rightOne( 1 );
0070
0071 std::size_t total_bits = left_bit_size < right_bit_size ? left_bit_size : right_bit_size;
0072
0073 for( std::size_t counter = 0; counter < total_bits; ++counter ) {
0074 if( (lhs & ( leftOne << counter )) != (rhs & (rightOne << counter)) ) {
0075 if( pr ) {
0076 pr.message() << " [";
0077 expr.report( pr.message().stream() );
0078 pr.message() << "]. Bitwise comparison failed";
0079 pr = false;
0080 }
0081 pr.message() << "\nMismatch at position " << counter;
0082 }
0083 }
0084
0085 if( left_bit_size != right_bit_size ) {
0086 if( pr ) {
0087 pr.message() << " [";
0088 expr.report( pr.message().stream() );
0089 pr.message() << "]. Bitwise comparison failed";
0090 pr = false;
0091 }
0092 pr.message() << "\nOperands bit sizes mismatch: " << left_bit_size << " != " << right_bit_size;
0093 }
0094
0095 return pr;
0096 }
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106 template<typename T1, typename T2, typename T3, typename T4>
0107 inline assertion_result
0108 operator<<(assertion_evaluate_t<assertion::binary_expr<T1,T2,assertion::op::EQ<T3,T4> > > const& ae, bitwise )
0109 {
0110 return bitwise_compare( ae.m_e.lhs().value(), ae.m_e.rhs(), ae.m_e );
0111 }
0112
0113
0114
0115 inline assertion_type
0116 operator<<( assertion_type const& , bitwise )
0117 {
0118 return assertion_type(CHECK_BUILT_ASSERTION);
0119 }
0120
0121
0122
0123 }
0124 }
0125 }
0126
0127 #include <boost/test/detail/enable_warnings.hpp>
0128
0129 #endif