1 // boost integer_mask.hpp test program -------------------------------------// 2 3 // (C) Copyright Daryle Walker 2001. 4 // Distributed under the Boost Software License, Version 1.0. (See 5 // accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt) 7 8 // See http://www.boost.org for most recent version including documentation. 9 10 // Revision History 11 // 23 Sep 2001 Initial version (Daryle Walker) 12 13 #include <boost/detail/lightweight_test.hpp> 14 15 #include <boost/cstdlib.hpp> // for boost::exit_success 16 #include <boost/integer/integer_mask.hpp> // for boost::high_bit_mask_t, etc. 17 18 #include <iostream> // for std::cout (std::endl indirectly) 19 20 #ifdef BOOST_MSVC 21 #pragma warning(disable:4127) // conditional expression is constant 22 #endif 23 24 #if defined(BOOST_HAS_LONG_LONG) 25 #define MASK_TYPE ::boost::ulong_long_type 26 #elif defined(BOOST_HAS_MS_INT64) 27 #define MASK_TYPE unsigned __int64 28 #else 29 #define MASK_TYPE unsigned long 30 #endif 31 32 #define ONE (static_cast<MASK_TYPE>(1)) 33 34 #define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \ 35 (v) >::high_bit == (ONE << (v)) ); 36 #define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \ 37 (v) >::high_bit_fast == (ONE << (v)) ); 38 #define PRIVATE_HIGH_BIT_TEST(v) do { PRIVATE_HIGH_BIT_SLOW_TEST(v); \ 39 PRIVATE_HIGH_BIT_FAST_TEST(v); } while (false) 40 41 #define PRIVATE_LOW_BITS_SLOW_TEST(v) \ 42 do{ \ 43 MASK_TYPE mask = 0;\ 44 if(v > 0)\ 45 { mask = ((ONE << (v-1)) - 1); mask <<= 1; mask |= 1; }\ 46 BOOST_TEST( ::boost::low_bits_mask_t< (v) >::sig_bits == mask); \ 47 }while(false); 48 #define PRIVATE_LOW_BITS_FAST_TEST(v) \ 49 do{ \ 50 MASK_TYPE mask = 0;\ 51 if(v > 0)\ 52 { mask = ((ONE << (v-1)) - 1); mask <<= 1; mask |= 1; }\ 53 BOOST_TEST( ::boost::low_bits_mask_t< (v) >::sig_bits_fast == mask);\ 54 }while(false); 55 #define PRIVATE_LOW_BITS_TEST(v) do { PRIVATE_LOW_BITS_SLOW_TEST(v); \ 56 PRIVATE_LOW_BITS_FAST_TEST(v); } while (false) 57 58 main(int,char * [])59int main( int, char*[] ) 60 { 61 using std::cout; 62 using std::endl; 63 64 cout << "Doing high_bit_mask_t tests." << endl; 65 66 #if defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64) 67 PRIVATE_HIGH_BIT_TEST( 63 ); 68 PRIVATE_HIGH_BIT_TEST( 62 ); 69 PRIVATE_HIGH_BIT_TEST( 61 ); 70 PRIVATE_HIGH_BIT_TEST( 60 ); 71 PRIVATE_HIGH_BIT_TEST( 59 ); 72 PRIVATE_HIGH_BIT_TEST( 58 ); 73 PRIVATE_HIGH_BIT_TEST( 57 ); 74 PRIVATE_HIGH_BIT_TEST( 56 ); 75 PRIVATE_HIGH_BIT_TEST( 55 ); 76 PRIVATE_HIGH_BIT_TEST( 54 ); 77 PRIVATE_HIGH_BIT_TEST( 53 ); 78 PRIVATE_HIGH_BIT_TEST( 52 ); 79 PRIVATE_HIGH_BIT_TEST( 51 ); 80 PRIVATE_HIGH_BIT_TEST( 50 ); 81 PRIVATE_HIGH_BIT_TEST( 49 ); 82 PRIVATE_HIGH_BIT_TEST( 48 ); 83 PRIVATE_HIGH_BIT_TEST( 47 ); 84 PRIVATE_HIGH_BIT_TEST( 46 ); 85 PRIVATE_HIGH_BIT_TEST( 45 ); 86 PRIVATE_HIGH_BIT_TEST( 44 ); 87 PRIVATE_HIGH_BIT_TEST( 43 ); 88 PRIVATE_HIGH_BIT_TEST( 42 ); 89 PRIVATE_HIGH_BIT_TEST( 41 ); 90 PRIVATE_HIGH_BIT_TEST( 40 ); 91 PRIVATE_HIGH_BIT_TEST( 39 ); 92 PRIVATE_HIGH_BIT_TEST( 38 ); 93 PRIVATE_HIGH_BIT_TEST( 37 ); 94 PRIVATE_HIGH_BIT_TEST( 36 ); 95 PRIVATE_HIGH_BIT_TEST( 35 ); 96 PRIVATE_HIGH_BIT_TEST( 34 ); 97 PRIVATE_HIGH_BIT_TEST( 33 ); 98 PRIVATE_HIGH_BIT_TEST( 32 ); 99 #endif 100 PRIVATE_HIGH_BIT_TEST( 31 ); 101 PRIVATE_HIGH_BIT_TEST( 30 ); 102 PRIVATE_HIGH_BIT_TEST( 29 ); 103 PRIVATE_HIGH_BIT_TEST( 28 ); 104 PRIVATE_HIGH_BIT_TEST( 27 ); 105 PRIVATE_HIGH_BIT_TEST( 26 ); 106 PRIVATE_HIGH_BIT_TEST( 25 ); 107 PRIVATE_HIGH_BIT_TEST( 24 ); 108 PRIVATE_HIGH_BIT_TEST( 23 ); 109 PRIVATE_HIGH_BIT_TEST( 22 ); 110 PRIVATE_HIGH_BIT_TEST( 21 ); 111 PRIVATE_HIGH_BIT_TEST( 20 ); 112 PRIVATE_HIGH_BIT_TEST( 19 ); 113 PRIVATE_HIGH_BIT_TEST( 18 ); 114 PRIVATE_HIGH_BIT_TEST( 17 ); 115 PRIVATE_HIGH_BIT_TEST( 16 ); 116 PRIVATE_HIGH_BIT_TEST( 15 ); 117 PRIVATE_HIGH_BIT_TEST( 14 ); 118 PRIVATE_HIGH_BIT_TEST( 13 ); 119 PRIVATE_HIGH_BIT_TEST( 12 ); 120 PRIVATE_HIGH_BIT_TEST( 11 ); 121 PRIVATE_HIGH_BIT_TEST( 10 ); 122 PRIVATE_HIGH_BIT_TEST( 9 ); 123 PRIVATE_HIGH_BIT_TEST( 8 ); 124 PRIVATE_HIGH_BIT_TEST( 7 ); 125 PRIVATE_HIGH_BIT_TEST( 6 ); 126 PRIVATE_HIGH_BIT_TEST( 5 ); 127 PRIVATE_HIGH_BIT_TEST( 4 ); 128 PRIVATE_HIGH_BIT_TEST( 3 ); 129 PRIVATE_HIGH_BIT_TEST( 2 ); 130 PRIVATE_HIGH_BIT_TEST( 1 ); 131 PRIVATE_HIGH_BIT_TEST( 0 ); 132 133 cout << "Doing low_bits_mask_t tests." << endl; 134 135 #if defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64) 136 PRIVATE_LOW_BITS_TEST( 64 ); 137 PRIVATE_LOW_BITS_TEST( 63 ); 138 PRIVATE_LOW_BITS_TEST( 62 ); 139 PRIVATE_LOW_BITS_TEST( 61 ); 140 PRIVATE_LOW_BITS_TEST( 60 ); 141 PRIVATE_LOW_BITS_TEST( 59 ); 142 PRIVATE_LOW_BITS_TEST( 58 ); 143 PRIVATE_LOW_BITS_TEST( 57 ); 144 PRIVATE_LOW_BITS_TEST( 56 ); 145 PRIVATE_LOW_BITS_TEST( 55 ); 146 PRIVATE_LOW_BITS_TEST( 54 ); 147 PRIVATE_LOW_BITS_TEST( 53 ); 148 PRIVATE_LOW_BITS_TEST( 52 ); 149 PRIVATE_LOW_BITS_TEST( 51 ); 150 PRIVATE_LOW_BITS_TEST( 50 ); 151 PRIVATE_LOW_BITS_TEST( 49 ); 152 PRIVATE_LOW_BITS_TEST( 48 ); 153 PRIVATE_LOW_BITS_TEST( 47 ); 154 PRIVATE_LOW_BITS_TEST( 46 ); 155 PRIVATE_LOW_BITS_TEST( 45 ); 156 PRIVATE_LOW_BITS_TEST( 44 ); 157 PRIVATE_LOW_BITS_TEST( 43 ); 158 PRIVATE_LOW_BITS_TEST( 42 ); 159 PRIVATE_LOW_BITS_TEST( 41 ); 160 PRIVATE_LOW_BITS_TEST( 40 ); 161 PRIVATE_LOW_BITS_TEST( 39 ); 162 PRIVATE_LOW_BITS_TEST( 38 ); 163 PRIVATE_LOW_BITS_TEST( 37 ); 164 PRIVATE_LOW_BITS_TEST( 36 ); 165 PRIVATE_LOW_BITS_TEST( 35 ); 166 PRIVATE_LOW_BITS_TEST( 34 ); 167 PRIVATE_LOW_BITS_TEST( 33 ); 168 #endif 169 PRIVATE_LOW_BITS_TEST( 32 ); 170 PRIVATE_LOW_BITS_TEST( 31 ); 171 PRIVATE_LOW_BITS_TEST( 30 ); 172 PRIVATE_LOW_BITS_TEST( 29 ); 173 PRIVATE_LOW_BITS_TEST( 28 ); 174 PRIVATE_LOW_BITS_TEST( 27 ); 175 PRIVATE_LOW_BITS_TEST( 26 ); 176 PRIVATE_LOW_BITS_TEST( 25 ); 177 PRIVATE_LOW_BITS_TEST( 24 ); 178 PRIVATE_LOW_BITS_TEST( 23 ); 179 PRIVATE_LOW_BITS_TEST( 22 ); 180 PRIVATE_LOW_BITS_TEST( 21 ); 181 PRIVATE_LOW_BITS_TEST( 20 ); 182 PRIVATE_LOW_BITS_TEST( 19 ); 183 PRIVATE_LOW_BITS_TEST( 18 ); 184 PRIVATE_LOW_BITS_TEST( 17 ); 185 PRIVATE_LOW_BITS_TEST( 16 ); 186 PRIVATE_LOW_BITS_TEST( 15 ); 187 PRIVATE_LOW_BITS_TEST( 14 ); 188 PRIVATE_LOW_BITS_TEST( 13 ); 189 PRIVATE_LOW_BITS_TEST( 12 ); 190 PRIVATE_LOW_BITS_TEST( 11 ); 191 PRIVATE_LOW_BITS_TEST( 10 ); 192 PRIVATE_LOW_BITS_TEST( 9 ); 193 PRIVATE_LOW_BITS_TEST( 8 ); 194 PRIVATE_LOW_BITS_TEST( 7 ); 195 PRIVATE_LOW_BITS_TEST( 6 ); 196 PRIVATE_LOW_BITS_TEST( 5 ); 197 PRIVATE_LOW_BITS_TEST( 4 ); 198 PRIVATE_LOW_BITS_TEST( 3 ); 199 PRIVATE_LOW_BITS_TEST( 2 ); 200 PRIVATE_LOW_BITS_TEST( 1 ); 201 202 return boost::report_errors(); 203 } 204