mirror of
https://github.com/boostorg/endian.git
synced 2025-08-01 05:24:39 +02:00
conversion_test coverage improvement + other work-in-progress
git-svn-id: http://svn.boost.org/svn/boost/sandbox/endian@72118 b8fc166d-592f-0410-95f2-cb63ce0dd405
This commit is contained in:
@@ -137,7 +137,7 @@ namespace endian
|
||||
const char* s (reinterpret_cast<const char*>(&source));
|
||||
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
||||
*t = *s;
|
||||
*++t = *++s;
|
||||
*--t = *++s;
|
||||
}
|
||||
|
||||
inline void flip(int32_t source, int32_t& target)
|
||||
@@ -145,9 +145,9 @@ namespace endian
|
||||
const char* s (reinterpret_cast<const char*>(&source));
|
||||
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
||||
*t = *s;
|
||||
*++t = *++s;
|
||||
*++t = *++s;
|
||||
*++t = *++s;
|
||||
*--t = *++s;
|
||||
*--t = *++s;
|
||||
*--t = *++s;
|
||||
}
|
||||
|
||||
inline void flip(int64_t source, int64_t& target)
|
||||
@@ -155,13 +155,13 @@ namespace endian
|
||||
const char* s (reinterpret_cast<const char*>(&source));
|
||||
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
||||
*t = *s;
|
||||
*++t = *++s;
|
||||
*++t = *++s;
|
||||
*++t = *++s;
|
||||
*++t = *++s;
|
||||
*++t = *++s;
|
||||
*++t = *++s;
|
||||
*++t = *++s;
|
||||
*--t = *++s;
|
||||
*--t = *++s;
|
||||
*--t = *++s;
|
||||
*--t = *++s;
|
||||
*--t = *++s;
|
||||
*--t = *++s;
|
||||
*--t = *++s;
|
||||
}
|
||||
|
||||
inline void flip(uint16_t source, uint16_t& target)
|
||||
@@ -169,7 +169,7 @@ namespace endian
|
||||
const char* s (reinterpret_cast<const char*>(&source));
|
||||
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
||||
*t = *s;
|
||||
*++t = *++s;
|
||||
*--t = *++s;
|
||||
}
|
||||
|
||||
inline void flip(uint32_t source, uint32_t& target)
|
||||
@@ -177,9 +177,9 @@ namespace endian
|
||||
const char* s (reinterpret_cast<const char*>(&source));
|
||||
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
||||
*t = *s;
|
||||
*++t = *++s;
|
||||
*++t = *++s;
|
||||
*++t = *++s;
|
||||
*--t = *++s;
|
||||
*--t = *++s;
|
||||
*--t = *++s;
|
||||
}
|
||||
|
||||
inline void flip(uint64_t source, uint64_t& target)
|
||||
@@ -187,15 +187,78 @@ namespace endian
|
||||
const char* s (reinterpret_cast<const char*>(&source));
|
||||
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
||||
*t = *s;
|
||||
*++t = *++s;
|
||||
*++t = *++s;
|
||||
*++t = *++s;
|
||||
*++t = *++s;
|
||||
*++t = *++s;
|
||||
*++t = *++s;
|
||||
*++t = *++s;
|
||||
*--t = *++s;
|
||||
*--t = *++s;
|
||||
*--t = *++s;
|
||||
*--t = *++s;
|
||||
*--t = *++s;
|
||||
*--t = *++s;
|
||||
*--t = *++s;
|
||||
}
|
||||
|
||||
template <class T> inline void to_big(T& x)
|
||||
{
|
||||
# ifdef BOOST_LITTLE_ENDIAN
|
||||
flip(x);
|
||||
# endif
|
||||
}
|
||||
|
||||
template <class T> inline void to_little(T& x)
|
||||
{
|
||||
# ifdef BOOST_BIG_ENDIAN
|
||||
flip(x);
|
||||
# endif
|
||||
}
|
||||
|
||||
template <class T> inline void from_big(T& x)
|
||||
{
|
||||
# ifdef BOOST_LITTLE_ENDIAN
|
||||
flip(x);
|
||||
# endif
|
||||
}
|
||||
|
||||
template <class T> inline void from_little(T& x)
|
||||
{
|
||||
# ifdef BOOST_BIG_ENDIAN
|
||||
flip(x);
|
||||
# endif
|
||||
}
|
||||
|
||||
template <class T> inline void to_big(T native, T& big)
|
||||
{
|
||||
# ifdef BOOST_LITTLE_ENDIAN
|
||||
flip(native, big);
|
||||
# else
|
||||
big = native;
|
||||
# endif
|
||||
}
|
||||
|
||||
template <class T> inline void to_little(T native, T& little)
|
||||
{
|
||||
# ifdef BOOST_BIG_ENDIAN
|
||||
flip(native, little);
|
||||
# else
|
||||
little = native;
|
||||
# endif
|
||||
}
|
||||
|
||||
template <class T> inline void from_big(T big, T& native)
|
||||
{
|
||||
# ifdef BOOST_LITTLE_ENDIAN
|
||||
flip(big, native);
|
||||
# else
|
||||
native = big;
|
||||
# endif
|
||||
}
|
||||
|
||||
template <class T> inline void from_little(T little, T& native)
|
||||
{
|
||||
# ifdef BOOST_BIG_ENDIAN
|
||||
flip(little, native);
|
||||
# else
|
||||
native = little;
|
||||
# endif
|
||||
}
|
||||
} // namespace endian
|
||||
} // namespace boost
|
||||
|
||||
|
@@ -5,18 +5,18 @@
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# See http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
# See library home page at http://www.boost.org/libs/integer/doc/endian.html
|
||||
# See library home page at http://www.boost.org/libs/endian
|
||||
|
||||
import testing ;
|
||||
|
||||
test-suite "endian"
|
||||
:
|
||||
[ run binary_stream_test.cpp ]
|
||||
[ run endian_binary_stream_test.cpp ]
|
||||
# [ run binary_stream_test.cpp ]
|
||||
# [ run endian_binary_stream_test.cpp ]
|
||||
[ run endian_test.cpp ]
|
||||
[ run endian_operations_test.cpp
|
||||
: : : <toolset>gcc:<cxxflags>-Wno-sign-compare ]
|
||||
[ run endian_in_union_test.cpp ]
|
||||
[ run scoped_enum_emulation_test.cpp ]
|
||||
[ run endian_flip_test.cpp ]
|
||||
[ run conversion_test.cpp ]
|
||||
;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// endian_flip_test.cpp --------------------------------------------------------------//
|
||||
// conversion_test.cpp ---------------------------------------------------------------//
|
||||
|
||||
// Copyright Beman Dawes 2010
|
||||
|
||||
@@ -7,67 +7,360 @@
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
#include <boost/integer/endian_flip.hpp>
|
||||
#include <boost/endian/conversion.hpp>
|
||||
#include <boost/detail/lightweight_main.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace bi = boost::integer;
|
||||
namespace be = boost::endian;
|
||||
|
||||
int main()
|
||||
namespace
|
||||
{
|
||||
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, static_cast<boost::int64_t>(0xf7f8f9fafbfcfdfe));
|
||||
bi::endian_flip(i64);
|
||||
BOOST_TEST_EQ(i64, static_cast<boost::int64_t>(0xfefdfcfbfaf9f8f7));
|
||||
void test_in_place_flip()
|
||||
{
|
||||
std::cout << "test_in_place_flip...\n";
|
||||
|
||||
boost::int32_t i32 = 0x01020304;
|
||||
bi::endian_flip(i32);
|
||||
BOOST_TEST_EQ(i32, 0x04030201);
|
||||
bi::endian_flip(i32);
|
||||
BOOST_TEST_EQ(i32, 0x01020304);
|
||||
boost::int64_t i64 = 0x0102030405060708;
|
||||
be::flip(i64);
|
||||
BOOST_TEST_EQ(i64, 0x0807060504030201);
|
||||
be::flip(i64);
|
||||
BOOST_TEST_EQ(i64, 0x0102030405060708);
|
||||
|
||||
i32 = 0xfefdfcfb;
|
||||
bi::endian_flip(i32);
|
||||
BOOST_TEST_EQ(i32, static_cast<boost::int32_t>(0xfbfcfdfe));
|
||||
bi::endian_flip(i32);
|
||||
BOOST_TEST_EQ(i32, static_cast<boost::int32_t>(0xfefdfcfb));
|
||||
i64 = 0xfefdfcfbfaf9f8f7;
|
||||
be::flip(i64);
|
||||
BOOST_TEST_EQ(i64, static_cast<boost::int64_t>(0xf7f8f9fafbfcfdfe));
|
||||
be::flip(i64);
|
||||
BOOST_TEST_EQ(i64, static_cast<boost::int64_t>(0xfefdfcfbfaf9f8f7));
|
||||
|
||||
boost::int16_t i16 = 0x0102;
|
||||
bi::endian_flip(i16);
|
||||
BOOST_TEST_EQ(i16, 0x0201);
|
||||
bi::endian_flip(i16);
|
||||
BOOST_TEST_EQ(i16, 0x0102);
|
||||
boost::int32_t i32 = 0x01020304;
|
||||
be::flip(i32);
|
||||
BOOST_TEST_EQ(i32, 0x04030201);
|
||||
be::flip(i32);
|
||||
BOOST_TEST_EQ(i32, 0x01020304);
|
||||
|
||||
i16 = static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd));
|
||||
bi::endian_flip(i16);
|
||||
BOOST_TEST_EQ(i16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfdfe)));
|
||||
bi::endian_flip(i16);
|
||||
BOOST_TEST_EQ(i16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd)));
|
||||
i32 = 0xfefdfcfb;
|
||||
be::flip(i32);
|
||||
BOOST_TEST_EQ(i32, static_cast<boost::int32_t>(0xfbfcfdfe));
|
||||
be::flip(i32);
|
||||
BOOST_TEST_EQ(i32, static_cast<boost::int32_t>(0xfefdfcfb));
|
||||
|
||||
boost::uint64_t ui64 = 0x0102030405060708;
|
||||
bi::endian_flip(ui64);
|
||||
BOOST_TEST_EQ(ui64, static_cast<boost::uint64_t>(0x0807060504030201));
|
||||
bi::endian_flip(ui64);
|
||||
BOOST_TEST_EQ(ui64, static_cast<boost::uint64_t>(0x0102030405060708));
|
||||
boost::int16_t i16 = 0x0102;
|
||||
be::flip(i16);
|
||||
BOOST_TEST_EQ(i16, 0x0201);
|
||||
be::flip(i16);
|
||||
BOOST_TEST_EQ(i16, 0x0102);
|
||||
|
||||
boost::uint32_t ui32 = 0x01020304;
|
||||
bi::endian_flip(ui32);
|
||||
BOOST_TEST_EQ(ui32, static_cast<boost::uint32_t>(0x04030201));
|
||||
bi::endian_flip(ui32);
|
||||
BOOST_TEST_EQ(ui32, static_cast<boost::uint32_t>(0x01020304));
|
||||
i16 = static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd));
|
||||
be::flip(i16);
|
||||
BOOST_TEST_EQ(i16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfdfe)));
|
||||
be::flip(i16);
|
||||
BOOST_TEST_EQ(i16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd)));
|
||||
|
||||
boost::uint16_t ui16 = 0x0102;
|
||||
bi::endian_flip(ui16);
|
||||
BOOST_TEST_EQ(ui16, 0x0201);
|
||||
bi::endian_flip(ui16);
|
||||
BOOST_TEST_EQ(ui16, 0x0102);
|
||||
boost::uint64_t ui64 = 0x0102030405060708;
|
||||
be::flip(ui64);
|
||||
BOOST_TEST_EQ(ui64, static_cast<boost::uint64_t>(0x0807060504030201));
|
||||
be::flip(ui64);
|
||||
BOOST_TEST_EQ(ui64, static_cast<boost::uint64_t>(0x0102030405060708));
|
||||
|
||||
boost::uint32_t ui32 = 0x01020304;
|
||||
be::flip(ui32);
|
||||
BOOST_TEST_EQ(ui32, static_cast<boost::uint32_t>(0x04030201));
|
||||
be::flip(ui32);
|
||||
BOOST_TEST_EQ(ui32, static_cast<boost::uint32_t>(0x01020304));
|
||||
|
||||
boost::uint16_t ui16 = 0x0102;
|
||||
be::flip(ui16);
|
||||
BOOST_TEST_EQ(ui16, 0x0201);
|
||||
be::flip(ui16);
|
||||
BOOST_TEST_EQ(ui16, 0x0102);
|
||||
|
||||
std::cout << " test_in_place_flip complete\n";
|
||||
}
|
||||
|
||||
void test_copying_flip()
|
||||
{
|
||||
std::cout << "test_copying_flip...\n";
|
||||
|
||||
boost::int64_t i64 = 0x0102030405060708, j64, k64;
|
||||
be::flip(i64, j64);
|
||||
BOOST_TEST_EQ(j64, 0x0807060504030201);
|
||||
BOOST_TEST_EQ(i64, 0x0102030405060708);
|
||||
be::flip(j64, k64);
|
||||
BOOST_TEST_EQ(k64, 0x0102030405060708);
|
||||
|
||||
i64 = 0xfefdfcfbfaf9f8f7;
|
||||
be::flip(i64, j64);
|
||||
BOOST_TEST_EQ(j64, static_cast<boost::int64_t>(0xf7f8f9fafbfcfdfe));
|
||||
be::flip(j64, k64);
|
||||
BOOST_TEST_EQ(k64, static_cast<boost::int64_t>(0xfefdfcfbfaf9f8f7));
|
||||
|
||||
boost::int32_t i32 = 0x01020304, j32, k32;
|
||||
be::flip(i32, j32);
|
||||
BOOST_TEST_EQ(j32, 0x04030201);
|
||||
be::flip(j32, k32);
|
||||
BOOST_TEST_EQ(k32, 0x01020304);
|
||||
|
||||
i32 = 0xfefdfcfb;
|
||||
be::flip(i32, j32);
|
||||
BOOST_TEST_EQ(j32, static_cast<boost::int32_t>(0xfbfcfdfe));
|
||||
be::flip(j32, k32);
|
||||
BOOST_TEST_EQ(k32, static_cast<boost::int32_t>(0xfefdfcfb));
|
||||
|
||||
boost::int16_t i16 = 0x0102, j16, k16;
|
||||
be::flip(i16, j16);
|
||||
BOOST_TEST_EQ(j16, 0x0201);
|
||||
be::flip(j16, k16);
|
||||
BOOST_TEST_EQ(k16, 0x0102);
|
||||
|
||||
i16 = static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd)), j16, k16;
|
||||
be::flip(i16, j16);
|
||||
BOOST_TEST_EQ(j16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfdfe)));
|
||||
be::flip(j16, k16);
|
||||
BOOST_TEST_EQ(k16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd)));
|
||||
|
||||
boost::uint64_t ui64 = 0x0102030405060708, uj64, uk64;
|
||||
be::flip(ui64, uj64);
|
||||
BOOST_TEST_EQ(uj64, static_cast<boost::uint64_t>(0x0807060504030201));
|
||||
be::flip(uj64, uk64);
|
||||
BOOST_TEST_EQ(uk64, static_cast<boost::uint64_t>(0x0102030405060708));
|
||||
|
||||
boost::uint32_t ui32 = 0x01020304, uj32, uk32;
|
||||
be::flip(ui32, uj32);
|
||||
BOOST_TEST_EQ(uj32, static_cast<boost::uint32_t>(0x04030201));
|
||||
be::flip(uj32, uk32);
|
||||
BOOST_TEST_EQ(uk32, static_cast<boost::uint32_t>(0x01020304));
|
||||
|
||||
boost::uint16_t ui16 = 0x0102, uj16, uk16;
|
||||
be::flip(ui16, uj16);
|
||||
BOOST_TEST_EQ(uj16, 0x0201);
|
||||
be::flip(uj16, uk16);
|
||||
BOOST_TEST_EQ(uk16, 0x0102);
|
||||
|
||||
std::cout << " test_copying_flip complete\n";
|
||||
}
|
||||
|
||||
const boost::int64_t ni64 = 0x0102030405060708;
|
||||
# ifdef BOOST_BIG_ENDIAN
|
||||
const boost::int64_t bi64 = 0x0102030405060708;
|
||||
const boost::int64_t li64 = 0x0807060504030201;
|
||||
# else
|
||||
const boost::int64_t bi64 = 0x0807060504030201;
|
||||
const boost::int64_t li64 = 0x0102030405060708;
|
||||
# endif
|
||||
|
||||
const boost::int32_t ni32 = 0x01020304;
|
||||
# ifdef BOOST_BIG_ENDIAN
|
||||
const boost::int32_t bi32 = 0x01020304;
|
||||
const boost::int32_t li32 = 0x04030201;
|
||||
# else
|
||||
const boost::int32_t bi32 = 0x04030201;
|
||||
const boost::int32_t li32 = 0x01020304;
|
||||
# endif
|
||||
|
||||
const boost::int16_t ni16 = 0x0102;
|
||||
# ifdef BOOST_BIG_ENDIAN
|
||||
const boost::int16_t bi16 = 0x0102;
|
||||
const boost::int16_t li16 = 0x0201;
|
||||
# else
|
||||
const boost::int16_t bi16 = 0x0201;
|
||||
const boost::int16_t li16 = 0x0102;
|
||||
# endif
|
||||
|
||||
const boost::uint64_t nui64 = 0x0102030405060708;
|
||||
# ifdef BOOST_BIG_ENDIAN
|
||||
const boost::uint64_t bui64 = 0x0102030405060708;
|
||||
const boost::uint64_t lui64 = 0x0807060504030201;
|
||||
# else
|
||||
const boost::uint64_t bui64 = 0x0807060504030201;
|
||||
const boost::uint64_t lui64 = 0x0102030405060708;
|
||||
# endif
|
||||
|
||||
const boost::uint32_t nui32 = 0x01020304;
|
||||
# ifdef BOOST_BIG_ENDIAN
|
||||
const boost::uint32_t bui32 = 0x01020304;
|
||||
const boost::uint32_t lui32 = 0x04030201;
|
||||
# else
|
||||
const boost::uint32_t bui32 = 0x04030201;
|
||||
const boost::uint32_t lui32 = 0x01020304;
|
||||
# endif
|
||||
|
||||
const boost::uint16_t nui16 = 0x0102;
|
||||
# ifdef BOOST_BIG_ENDIAN
|
||||
const boost::uint16_t bui16 = 0x0102;
|
||||
const boost::uint16_t lui16 = 0x0201;
|
||||
# else
|
||||
const boost::uint16_t bui16 = 0x0201;
|
||||
const boost::uint16_t lui16 = 0x0102;
|
||||
# endif
|
||||
|
||||
void test_in_place_conditional_flip()
|
||||
{
|
||||
std::cout << "test_in_place_conditional_flip...\n";
|
||||
|
||||
boost::int64_t i64;
|
||||
|
||||
i64 = ni64;
|
||||
be::to_big(i64);
|
||||
BOOST_TEST_EQ(i64, bi64);
|
||||
|
||||
i64 = ni64;
|
||||
be::to_little(i64);
|
||||
BOOST_TEST_EQ(i64, li64);
|
||||
|
||||
i64 = bi64;
|
||||
be::from_big(i64);
|
||||
BOOST_TEST_EQ(i64, ni64);
|
||||
|
||||
i64 = li64;
|
||||
be::from_little(i64);
|
||||
BOOST_TEST_EQ(i64, ni64);
|
||||
|
||||
boost::uint64_t ui64;
|
||||
|
||||
ui64 = nui64;
|
||||
be::to_big(ui64);
|
||||
BOOST_TEST_EQ(ui64, bui64);
|
||||
|
||||
ui64 = nui64;
|
||||
be::to_little(ui64);
|
||||
BOOST_TEST_EQ(ui64, lui64);
|
||||
|
||||
ui64 = bui64;
|
||||
be::from_big(ui64);
|
||||
BOOST_TEST_EQ(ui64, nui64);
|
||||
|
||||
ui64 = lui64;
|
||||
be::from_little(ui64);
|
||||
BOOST_TEST_EQ(ui64, nui64);
|
||||
|
||||
boost::int32_t i32;
|
||||
|
||||
i32 = ni32;
|
||||
be::to_big(i32);
|
||||
BOOST_TEST_EQ(i32, bi32);
|
||||
|
||||
i32 = ni32;
|
||||
be::to_little(i32);
|
||||
BOOST_TEST_EQ(i32, li32);
|
||||
|
||||
i32 = bi32;
|
||||
be::from_big(i32);
|
||||
BOOST_TEST_EQ(i32, ni32);
|
||||
|
||||
i32 = li32;
|
||||
be::from_little(i32);
|
||||
BOOST_TEST_EQ(i32, ni32);
|
||||
|
||||
boost::uint32_t ui32;
|
||||
|
||||
ui32 = nui32;
|
||||
be::to_big(ui32);
|
||||
BOOST_TEST_EQ(ui32, bui32);
|
||||
|
||||
ui32 = nui32;
|
||||
be::to_little(ui32);
|
||||
BOOST_TEST_EQ(ui32, lui32);
|
||||
|
||||
ui32 = bui32;
|
||||
be::from_big(ui32);
|
||||
BOOST_TEST_EQ(ui32, nui32);
|
||||
|
||||
ui32 = lui32;
|
||||
be::from_little(ui32);
|
||||
BOOST_TEST_EQ(ui32, nui32);
|
||||
|
||||
boost::int16_t i16;
|
||||
|
||||
i16 = ni16;
|
||||
be::to_big(i16);
|
||||
BOOST_TEST_EQ(i16, bi16);
|
||||
|
||||
i16 = ni16;
|
||||
be::to_little(i16);
|
||||
BOOST_TEST_EQ(i16, li16);
|
||||
|
||||
i16 = bi16;
|
||||
be::from_big(i16);
|
||||
BOOST_TEST_EQ(i16, ni16);
|
||||
|
||||
i16 = li16;
|
||||
be::from_little(i16);
|
||||
BOOST_TEST_EQ(i16, ni16);
|
||||
|
||||
boost::uint16_t ui16;
|
||||
|
||||
ui16 = nui16;
|
||||
be::to_big(ui16);
|
||||
BOOST_TEST_EQ(ui16, bui16);
|
||||
|
||||
ui16 = nui16;
|
||||
be::to_little(ui16);
|
||||
BOOST_TEST_EQ(ui16, lui16);
|
||||
|
||||
ui16 = bui16;
|
||||
be::from_big(ui16);
|
||||
BOOST_TEST_EQ(ui16, nui16);
|
||||
|
||||
ui16 = lui16;
|
||||
be::from_little(ui16);
|
||||
BOOST_TEST_EQ(ui16, nui16);
|
||||
|
||||
|
||||
|
||||
i32 = 0x01020304;
|
||||
be::flip(i32);
|
||||
BOOST_TEST_EQ(i32, 0x04030201);
|
||||
be::flip(i32);
|
||||
BOOST_TEST_EQ(i32, 0x01020304);
|
||||
|
||||
i32 = 0xfefdfcfb;
|
||||
be::flip(i32);
|
||||
BOOST_TEST_EQ(i32, static_cast<boost::int32_t>(0xfbfcfdfe));
|
||||
be::flip(i32);
|
||||
BOOST_TEST_EQ(i32, static_cast<boost::int32_t>(0xfefdfcfb));
|
||||
|
||||
i16 = 0x0102;
|
||||
be::flip(i16);
|
||||
BOOST_TEST_EQ(i16, 0x0201);
|
||||
be::flip(i16);
|
||||
BOOST_TEST_EQ(i16, 0x0102);
|
||||
|
||||
i16 = static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd));
|
||||
be::flip(i16);
|
||||
BOOST_TEST_EQ(i16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfdfe)));
|
||||
be::flip(i16);
|
||||
BOOST_TEST_EQ(i16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd)));
|
||||
|
||||
ui64 = 0x0102030405060708;
|
||||
be::flip(ui64);
|
||||
BOOST_TEST_EQ(ui64, static_cast<boost::uint64_t>(0x0807060504030201));
|
||||
be::flip(ui64);
|
||||
BOOST_TEST_EQ(ui64, static_cast<boost::uint64_t>(0x0102030405060708));
|
||||
|
||||
ui32 = 0x01020304;
|
||||
be::flip(ui32);
|
||||
BOOST_TEST_EQ(ui32, static_cast<boost::uint32_t>(0x04030201));
|
||||
be::flip(ui32);
|
||||
BOOST_TEST_EQ(ui32, static_cast<boost::uint32_t>(0x01020304));
|
||||
|
||||
ui16 = 0x0102;
|
||||
be::flip(ui16);
|
||||
BOOST_TEST_EQ(ui16, 0x0201);
|
||||
be::flip(ui16);
|
||||
BOOST_TEST_EQ(ui16, 0x0102);
|
||||
|
||||
std::cout << " test_in_place_conditional_flip complete\n";
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
int cpp_main(int, char * [])
|
||||
{
|
||||
std::cerr << std::hex;
|
||||
test_in_place_flip();
|
||||
test_copying_flip();
|
||||
test_in_place_conditional_flip();
|
||||
|
||||
return ::boost::report_errors();
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\endian_flip_test.cpp" />
|
||||
<ClCompile Include="..\..\conversion_test.cpp" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{9FA33B0B-2B00-49E8-A892-E049D86076A9}</ProjectGuid>
|
||||
|
@@ -19,6 +19,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "endian_binary_stream_test",
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "binary_stream_example", "binary_stream_example\binary_stream_example.vcxproj", "{06736C67-6305-4A9F-8D10-850FD0CE907D}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "conversion_test", "conversion_test\conversion_test.vcxproj", "{9FA33B0B-2B00-49E8-A892-E049D86076A9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
@@ -61,6 +63,10 @@ Global
|
||||
{06736C67-6305-4A9F-8D10-850FD0CE907D}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{06736C67-6305-4A9F-8D10-850FD0CE907D}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{06736C67-6305-4A9F-8D10-850FD0CE907D}.Release|Win32.Build.0 = Release|Win32
|
||||
{9FA33B0B-2B00-49E8-A892-E049D86076A9}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{9FA33B0B-2B00-49E8-A892-E049D86076A9}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{9FA33B0B-2B00-49E8-A892-E049D86076A9}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{9FA33B0B-2B00-49E8-A892-E049D86076A9}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@@ -1,7 +1,8 @@
|
||||
@echo off
|
||||
echo Special version of boost_test for sandbox version of endian library.
|
||||
xcopy /D %BOOST_TRUNK%\boost-build.jam ..\..\..
|
||||
xcopy /D %BOOST_TRUNK%\Jamroot ..\..\..
|
||||
xcopy /D %BOOST_TRUNK%\boost-build.jam ..\..\..\..
|
||||
xcopy /D %BOOST_TRUNK%\boostcpp.jam ..\..\..\..
|
||||
xcopy /D %BOOST_TRUNK%\Jamroot ..\..\..\..
|
||||
set BOOST_BUILD_PATH=%BOOST_TRUNK%\tools\build\v2
|
||||
|
||||
if not $%1==$--help goto nohelp
|
||||
|
Reference in New Issue
Block a user