Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65178 - sandbox/endian_ext/libs/integer/test
From: vicente.botet_at_[hidden]
Date: 2010-09-01 15:43:01


Author: viboes
Date: 2010-09-01 15:43:00 EDT (Wed, 01 Sep 2010)
New Revision: 65178
URL: http://svn.boost.org/trac/boost/changeset/65178

Log:
Added endian flip
Added:
   sandbox/endian_ext/libs/integer/test/endian_flip_test.cpp (contents, props changed)
Text files modified:
   sandbox/endian_ext/libs/integer/test/Jamfile.v2 | 1 +
   1 files changed, 1 insertions(+), 0 deletions(-)

Modified: sandbox/endian_ext/libs/integer/test/Jamfile.v2
==============================================================================
--- sandbox/endian_ext/libs/integer/test/Jamfile.v2 (original)
+++ sandbox/endian_ext/libs/integer/test/Jamfile.v2 2010-09-01 15:43:00 EDT (Wed, 01 Sep 2010)
@@ -25,6 +25,7 @@
             : : : <toolset>gcc:<cxxflags>-Wno-sign-compare ]
          [ run endian_in_union_test.cpp ]
          [ run scoped_enum_emulation_test.cpp ]
+ [ run endian_flip_test.cpp ]
          [ run endian_view_test.cpp ]
          [ run endian_type_test.cpp ]
          [ run endian_convert_test.cpp ]

Added: sandbox/endian_ext/libs/integer/test/endian_flip_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/test/endian_flip_test.cpp 2010-09-01 15:43:00 EDT (Wed, 01 Sep 2010)
@@ -0,0 +1,73 @@
+// endian_flip_test.cpp --------------------------------------------------------------//
+
+// Copyright Beman Dawes 2010
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+//--------------------------------------------------------------------------------------//
+
+#include <boost/integer/endian_flip.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+namespace bi = boost::integer;
+
+int main()
+{
+ boost::int64_t i64 = 0x0102030405060708;
+ bi::endian_flip(i64);
+ BOOST_TEST_EQ(i64, 0x0807060504030201);
+ bi::endian_flip(i64);
+ BOOST_TEST_EQ(i64, 0x0102030405060708);
+
+ i64 = 0xfefdfcfbfaf9f8f7;
+ bi::endian_flip(i64);
+ BOOST_TEST_EQ(i64, 0xf7f8f9fafbfcfdfe);
+ bi::endian_flip(i64);
+ BOOST_TEST_EQ(i64, 0xfefdfcfbfaf9f8f7);
+
+ boost::int32_t i32 = 0x01020304;
+ bi::endian_flip(i32);
+ BOOST_TEST_EQ(i32, 0x04030201);
+ bi::endian_flip(i32);
+ BOOST_TEST_EQ(i32, 0x01020304);
+
+ i32 = 0xfefdfcfb;
+ bi::endian_flip(i32);
+ BOOST_TEST_EQ(i32, 0xfbfcfdfe);
+ bi::endian_flip(i32);
+ BOOST_TEST_EQ(i32, 0xfefdfcfb);
+
+ boost::int16_t i16 = 0x0102;
+ bi::endian_flip(i16);
+ BOOST_TEST_EQ(i16, 0x0201);
+ bi::endian_flip(i16);
+ BOOST_TEST_EQ(i16, 0x0102);
+
+ i16 = (boost::int16_t)0xfefd;
+ bi::endian_flip(i16);
+ BOOST_TEST_EQ(i16, (boost::int16_t)0xfdfe);
+ bi::endian_flip(i16);
+ BOOST_TEST_EQ(i16, (boost::int16_t)0xfefd);
+
+ boost::uint64_t ui64 = 0x0102030405060708;
+ bi::endian_flip(ui64);
+ BOOST_TEST_EQ(ui64, 0x0807060504030201);
+ bi::endian_flip(ui64);
+ BOOST_TEST_EQ(ui64, 0x0102030405060708);
+
+ boost::uint32_t ui32 = 0x01020304;
+ bi::endian_flip(ui32);
+ BOOST_TEST_EQ(ui32, 0x04030201);
+ bi::endian_flip(ui32);
+ BOOST_TEST_EQ(ui32, 0x01020304);
+
+ boost::uint16_t ui16 = 0x0102;
+ bi::endian_flip(ui16);
+ BOOST_TEST_EQ(ui16, 0x0201);
+ bi::endian_flip(ui16);
+ BOOST_TEST_EQ(ui16, 0x0102);
+
+
+ return ::boost::report_errors();
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk