mirror of
https://github.com/boostorg/endian.git
synced 2025-07-30 20:47:26 +02:00
add test to expose undefined behaviors endian_buffer when used with signed integers
This commit is contained in:
@ -18,6 +18,7 @@
|
|||||||
#include <boost/cstdint.hpp>
|
#include <boost/cstdint.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
using namespace boost::endian;
|
using namespace boost::endian;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
@ -198,6 +199,23 @@ namespace
|
|||||||
std::cout << "test construction and assignment" << std::endl;
|
std::cout << "test construction and assignment" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Int>
|
||||||
|
void test_boundary_values()
|
||||||
|
{
|
||||||
|
endian_buffer<order::big, Int, sizeof(Int) * CHAR_BIT, align::no> bmax(
|
||||||
|
std::numeric_limits<Int>::max());
|
||||||
|
endian_buffer<order::big, Int, sizeof(Int) * CHAR_BIT, align::no> bmin(
|
||||||
|
std::numeric_limits<Int>::min());
|
||||||
|
endian_buffer<order::little, Int, sizeof(Int) * CHAR_BIT, align::no> lmax(
|
||||||
|
std::numeric_limits<Int>::max());
|
||||||
|
endian_buffer<order::little, Int, sizeof(Int) * CHAR_BIT, align::no> lmin(
|
||||||
|
std::numeric_limits<Int>::min());
|
||||||
|
|
||||||
|
BOOST_TEST(bmax.value() == std::numeric_limits<Int>::max());
|
||||||
|
BOOST_TEST(bmin.value() == std::numeric_limits<Int>::min());
|
||||||
|
BOOST_TEST(lmax.value() == std::numeric_limits<Int>::max());
|
||||||
|
BOOST_TEST(lmin.value() == std::numeric_limits<Int>::min());
|
||||||
|
}
|
||||||
} // unnamed namespace
|
} // unnamed namespace
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------//
|
//--------------------------------------------------------------------------------------//
|
||||||
@ -230,6 +248,13 @@ int cpp_main(int, char *[])
|
|||||||
test_inserter_and_extractor();
|
test_inserter_and_extractor();
|
||||||
test_construction_and_assignment();
|
test_construction_and_assignment();
|
||||||
|
|
||||||
|
test_boundary_values<signed int>();
|
||||||
|
test_boundary_values<unsigned int>();
|
||||||
|
test_boundary_values<signed short>();
|
||||||
|
test_boundary_values<unsigned short>();
|
||||||
|
test_boundary_values<signed char>();
|
||||||
|
test_boundary_values<unsigned char>();
|
||||||
|
|
||||||
cout << " done" << endl;
|
cout << " done" << endl;
|
||||||
|
|
||||||
return ::boost::report_errors();
|
return ::boost::report_errors();
|
||||||
|
Reference in New Issue
Block a user