diff --git a/include/boost/endian.hpp b/include/boost/endian.hpp new file mode 100644 index 0000000..c1afa7a --- /dev/null +++ b/include/boost/endian.hpp @@ -0,0 +1,13 @@ +#ifndef BOOST_ENDIAN_HPP_INCLUDED +#define BOOST_ENDIAN_HPP_INCLUDED + +// Copyright 2019 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include + +#endif // #ifndef BOOST_ENDIAN_HPP_INCLUDED diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 74265f1..88963c8 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -77,3 +77,5 @@ endian-run store_convenience_test.cpp ; endian-run float_typedef_test.cpp ; endian-run data_test.cpp ; + +endian-run endian_hpp_test.cpp ; diff --git a/test/endian_hpp_test.cpp b/test/endian_hpp_test.cpp new file mode 100644 index 0000000..8ae0431 --- /dev/null +++ b/test/endian_hpp_test.cpp @@ -0,0 +1,59 @@ +// Copyright 2019 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include + +int main() +{ + using namespace boost::endian; + + // conversion + + { + BOOST_TEST_EQ( endian_reverse( 0x01020304 ), 0x04030201 ); + } + + // buffers + + { + little_uint32_buf_t v( 0x01020304 ); + + BOOST_TEST_EQ( v.data()[ 0 ], 0x04 ); + BOOST_TEST_EQ( v.data()[ 1 ], 0x03 ); + BOOST_TEST_EQ( v.data()[ 2 ], 0x02 ); + BOOST_TEST_EQ( v.data()[ 3 ], 0x01 ); + } + + { + big_uint32_buf_t v( 0x01020304 ); + + BOOST_TEST_EQ( v.data()[ 0 ], 0x01 ); + BOOST_TEST_EQ( v.data()[ 1 ], 0x02 ); + BOOST_TEST_EQ( v.data()[ 2 ], 0x03 ); + BOOST_TEST_EQ( v.data()[ 3 ], 0x04 ); + } + + // arithmetic + + { + little_uint32_t v( 0x01020304 ); + + BOOST_TEST_EQ( v.data()[ 0 ], 0x04 ); + BOOST_TEST_EQ( v.data()[ 1 ], 0x03 ); + BOOST_TEST_EQ( v.data()[ 2 ], 0x02 ); + BOOST_TEST_EQ( v.data()[ 3 ], 0x01 ); + } + + { + big_uint32_t v( 0x01020304 ); + + BOOST_TEST_EQ( v.data()[ 0 ], 0x01 ); + BOOST_TEST_EQ( v.data()[ 1 ], 0x02 ); + BOOST_TEST_EQ( v.data()[ 2 ], 0x03 ); + BOOST_TEST_EQ( v.data()[ 3 ], 0x04 ); + } + + return boost::report_errors(); +}