// endian_operations_test.cpp ----------------------------------------------// // Copyright Beman Dawes 2008 // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // See library home page at http://www.boost.org/libs/endian //----------------------------------------------------------------------------// // This test probes operator overloading, including interaction between // operand types. // See endian_test for tests of endianess correctness, size, and value. //----------------------------------------------------------------------------// #define BOOST_ENDIAN_LOG #include #include #include namespace bi = boost::integer; #ifdef _MSC_VER # pragma warning( disable : 4244 ) // conversion ..., possible loss of data # pragma warning( disable : 4018 ) // signed/unsigned mismatch #endif template struct default_construct { static void test() { T1 o1; o1 = 1; // quiet warnings } }; template struct construct { static void test() { T2 o2(1); T1 o1(o2); ++o1; // quiet gcc unused variable warning } }; template struct initialize { static void test() { T1 o2(2); T1 o1 = o2; ++o1; // quiet gcc unused variable warning } }; template struct assign { static void test() { T2 o2; o2 = 1; T1 o1; o1 = o2; } }; template struct relational { static void test() { T1 o1(1); T2 o2(2); if ( o1 == o2 ) return; if ( o1 != o2 ) return; if ( o1 < o2 ) return; if ( o1 <= o2 ) return; if ( o1 > o2 ) return; if ( o1 >= o2 ) return; } }; template struct op_plus { static void test() { T1 o1(1); T2 o2(2); T1 o3; o3 = +o1; o3 = o1 + o2; o1 += o2; } }; template struct op_star { static void test() { T1 o1(1); T2 o2(2); T1 o3; o3 = o1 * o2; o1 *= o2; } }; template class Test, class T1> void op_test_aux() { #ifdef BOOST_SHORT_ENDIAN_TEST Test::test(); Test::test(); Test::test(); Test::test(); #else Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); Test::test(); #endif } template class Test> void op_test() { #ifdef BOOST_SHORT_ENDIAN_TEST op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); #else op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); op_test_aux(); #endif } int main() { bi::endian_log = false; // make sure some simple things work bi::big32_t o1(1); bi::big32_t o2(2L); bi::big32_t o3(3LL); bi::big64_t o4(1); // use cases; if BOOST_ENDIAN_LOG is defined, will output to clog info on // what overloads and conversions are actually being performed. bi::endian_log = true; std::clog << "set up test values\n"; bi::big32_t big(12345); bi::ulittle16_t ulittle(10); bi::big64_t result; std::clog << "\nresult = +big\n"; result = +big; std::clog << "\nresult = -big\n"; result = -big; std::clog << "\n++big\n"; ++big; std::clog << "\nresult = big++\n"; result = big++; std::clog << "\n--big\n"; --big; std::clog << "\nbig--\n"; big--; std::clog << "\nresult = big * big\n"; result = big * big; std::clog << "\nresult = big * big\n"; result = big * big; std::clog << "\nresult = big * ulittle\n"; result = big * ulittle; std::clog << "\nbig *= ulittle\n"; big *= ulittle; std::clog << "\nresult = ulittle * big\n"; result = ulittle * big; std::clog << "\nresult = big * 5\n"; result = big * 5; std::clog << "\nbig *= 5\n"; big *= 5; std::clog << "\nresult = 5 * big\n"; result = 5 * big; std::clog << "\nresult = ulittle * 5\n"; result = ulittle * 5; std::clog << "\nresult = 5 * ulittle\n"; result = 5 * ulittle; std::clog << "\nresult = 5 * 10\n"; result = 5 * 10; std::clog << "\n"; bi::endian_log = false; // perform the indicated test on ~60*60 operand types op_test(); op_test(); // includes copy construction op_test(); op_test(); op_test(); op_test(); op_test(); return 0; }