Add data_test

This commit is contained in:
Peter Dimov
2019-10-15 21:07:40 +03:00
parent 59097ada36
commit 51f095f019
2 changed files with 116 additions and 26 deletions

View File

@ -28,19 +28,23 @@ project
<toolset>clang:<warnings-as-errors>on
;
run buffer_test.cpp ;
run buffer_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : buffer_test_ni ;
local rule endian-run ( sources + )
{
local result ;
run endian_test.cpp ;
run endian_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : endian_test_ni ;
result += [ run $(sources) ] ;
result += [ run $(sources) : : : <define>BOOST_ENDIAN_NO_INTRINSICS : $(sources[1]:B)_ni ] ;
run endian_operations_test.cpp ;
run endian_operations_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : endian_operations_test_ni ;
return $(result) ;
}
endian-run buffer_test.cpp ;
endian-run endian_test.cpp ;
endian-run endian_operations_test.cpp ;
run endian_in_union_test.cpp ;
run conversion_test.cpp ;
run conversion_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : conversion_test_ni ;
endian-run conversion_test.cpp ;
run intrinsic_test.cpp ;
@ -54,31 +58,22 @@ local allow-warnings =
compile spirit_conflict_test.cpp
: $(allow-warnings) ;
run endian_reverse_test.cpp ;
run endian_reverse_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : endian_reverse_test_ni ;
endian-run endian_reverse_test.cpp ;
run endian_load_test.cpp ;
run endian_load_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : endian_load_test_ni ;
endian-run endian_load_test.cpp ;
endian-run endian_store_test.cpp ;
endian-run endian_ld_st_roundtrip_test.cpp ;
run endian_store_test.cpp ;
run endian_store_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : endian_store_test_ni ;
run endian_ld_st_roundtrip_test.cpp ;
run endian_ld_st_roundtrip_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : endian_ld_st_roundtrip_test_ni ;
run endian_arithmetic_test.cpp ;
run endian_arithmetic_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : endian_arithmetic_test_ni ;
endian-run endian_arithmetic_test.cpp ;
run deprecated_test.cpp ;
compile endian_reverse_cx_test.cpp ;
compile endian_reverse_cx_test.cpp : <define>BOOST_ENDIAN_NO_INTRINSICS : endian_reverse_cx_test_ni ;
run load_convenience_test.cpp ;
run load_convenience_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : load_convenience_test_ni ;
endian-run load_convenience_test.cpp ;
endian-run store_convenience_test.cpp ;
run store_convenience_test.cpp ;
run store_convenience_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : store_convenience_test_ni ;
endian-run float_typedef_test.cpp ;
run float_typedef_test.cpp ;
run float_typedef_test.cpp : : : <define>BOOST_ENDIAN_NO_INTRINSICS : float_typedef_test_ni ;
endian-run data_test.cpp ;

95
test/data_test.cpp Normal file
View File

@ -0,0 +1,95 @@
// Copyright 2019 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/endian/arithmetic.hpp>
#include <boost/endian/buffers.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#include <boost/cstdint.hpp>
#include <cstddef>
template<class U> void test()
{
{
U u( 0 );
unsigned char * p1 = u.data();
void * p2 = &u;
BOOST_TEST_EQ( p1, p2 );
}
{
U const u( 0 );
unsigned char const * p1 = u.data();
void const * p2 = &u;
BOOST_TEST_EQ( p1, p2 );
}
}
template<class T, std::size_t Bits> void test_unaligned()
{
using namespace boost::endian;
test< endian_buffer<order::big, T, Bits, align::no> >();
test< endian_buffer<order::little, T, Bits, align::no> >();
test< endian_buffer<order::native, T, Bits, align::no> >();
test< endian_arithmetic<order::big, T, Bits, align::no> >();
test< endian_arithmetic<order::little, T, Bits, align::no> >();
test< endian_arithmetic<order::native, T, Bits, align::no> >();
}
template<class T, std::size_t Bits> void test_aligned()
{
using namespace boost::endian;
test< endian_buffer<order::big, T, Bits, align::yes> >();
test< endian_buffer<order::little, T, Bits, align::yes> >();
test< endian_arithmetic<order::big, T, Bits, align::yes> >();
test< endian_arithmetic<order::little, T, Bits, align::yes> >();
}
int main()
{
test_unaligned<boost::int_least8_t, 8>();
test_unaligned<boost::int_least16_t, 16>();
test_unaligned<boost::int_least32_t, 24>();
test_unaligned<boost::int_least32_t, 32>();
test_unaligned<boost::int_least64_t, 40>();
test_unaligned<boost::int_least64_t, 48>();
test_unaligned<boost::int_least64_t, 56>();
test_unaligned<boost::int_least64_t, 64>();
test_unaligned<boost::uint_least8_t, 8>();
test_unaligned<boost::uint_least16_t, 16>();
test_unaligned<boost::uint_least32_t, 24>();
test_unaligned<boost::uint_least32_t, 32>();
test_unaligned<boost::uint_least64_t, 40>();
test_unaligned<boost::uint_least64_t, 48>();
test_unaligned<boost::uint_least64_t, 56>();
test_unaligned<boost::uint_least64_t, 64>();
test_unaligned<float, 32>();
test_unaligned<double, 64>();
test_aligned<boost::int8_t, 8>();
test_aligned<boost::int16_t, 16>();
test_aligned<boost::int32_t, 32>();
test_aligned<boost::int64_t, 64>();
test_aligned<boost::uint8_t, 8>();
test_aligned<boost::uint16_t, 16>();
test_aligned<boost::uint32_t, 32>();
test_aligned<boost::uint64_t, 64>();
test_aligned<float, 32>();
test_aligned<double, 64>();
return boost::report_errors();
}