]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/endian/test/endian_ld_st_roundtrip_test.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / endian / test / endian_ld_st_roundtrip_test.cpp
1 // Copyright 2019 Peter Dimov
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5
6 #include <boost/endian/conversion.hpp>
7 #include <boost/core/lightweight_test.hpp>
8 #include <boost/config.hpp>
9 #include <boost/cstdint.hpp>
10 #include <cstddef>
11
12 template<class T> void test( T const& x )
13 {
14 {
15 unsigned char buffer[ sizeof(T) ];
16
17 boost::endian::endian_store<T, sizeof(T), boost::endian::order::little>( buffer, x );
18 T x2 = boost::endian::endian_load<T, sizeof(T), boost::endian::order::little>( buffer );
19
20 BOOST_TEST_EQ( x, x2 );
21 }
22
23 {
24 unsigned char buffer[ sizeof(T) ];
25
26 boost::endian::endian_store<T, sizeof(T), boost::endian::order::big>( buffer, x );
27 T x2 = boost::endian::endian_load<T, sizeof(T), boost::endian::order::big>( buffer );
28
29 BOOST_TEST_EQ( x, x2 );
30 }
31 }
32
33 enum E
34 {
35 e = 0xF1F2F3
36 };
37
38 int main()
39 {
40 test( 1.2e+34f );
41 test( -1.234e+56 );
42 test( e );
43
44 return boost::report_errors();
45 }