• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 Peter Dimov
2 // Distributed under the Boost Software License, Version 1.0.
3 // https://www.boost.org/LICENSE_1_0.txt
4 
5 #include <boost/endian/conversion.hpp>
6 #include <boost/core/lightweight_test.hpp>
7 #include <boost/config.hpp>
8 #include <cstddef>
9 
test_reverse(T x)10 template<class T> void test_reverse( T x )
11 {
12     using boost::endian::endian_reverse;
13 
14     T x2( x );
15 
16     x2 = endian_reverse( endian_reverse( x2 ) );
17     BOOST_TEST( x == x2 );
18 
19     x2 = boost::endian::native_to_little( boost::endian::little_to_native( x2 ) );
20     BOOST_TEST( x == x2 );
21 
22     x2 = boost::endian::native_to_big( boost::endian::big_to_native( x2 ) );
23     BOOST_TEST( x == x2 );
24 }
25 
test_reverse_inplace(T x)26 template<class T> void test_reverse_inplace( T x )
27 {
28     using boost::endian::endian_reverse_inplace;
29 
30     T x2( x );
31 
32     endian_reverse_inplace( x2 );
33     endian_reverse_inplace( x2 );
34     BOOST_TEST( x == x2 );
35 
36     boost::endian::native_to_little_inplace( x2 );
37     boost::endian::little_to_native_inplace( x2 );
38     BOOST_TEST( x == x2 );
39 
40     boost::endian::native_to_big_inplace( x2 );
41     boost::endian::big_to_native_inplace( x2 );
42     BOOST_TEST( x == x2 );
43 }
44 
45 enum E1 { e1 };
46 
47 #if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
48 
49 enum E2: long { e2 };
50 enum class E3 { e3 };
51 enum class E4: long { e4 };
52 
53 #endif
54 
main()55 int main()
56 {
57     test_reverse( 1 );
58 
59 #if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
60 
61     test_reverse( E3::e3 );
62     test_reverse( E4::e4 );
63 
64 #endif
65 
66     test_reverse_inplace( 1 );
67     test_reverse_inplace( true );
68 
69     test_reverse_inplace( 1.0f );
70     test_reverse_inplace( 1.0 );
71 
72     test_reverse_inplace( e1 );
73 
74 #if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
75 
76     test_reverse_inplace( e2 );
77     test_reverse_inplace( E3::e3 );
78     test_reverse_inplace( E4::e4 );
79 
80 #endif
81 
82     return boost::report_errors();
83 }
84