From 674adbd59250781831ee2c9b79ef525260d277da Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 6 Nov 2017 13:18:47 +0100 Subject: [PATCH] add test to expose undefined behaviors endian_buffer when used with signed integers --- test/buffer_test.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/buffer_test.cpp b/test/buffer_test.cpp index 803936a..ffe79ac 100644 --- a/test/buffer_test.cpp +++ b/test/buffer_test.cpp @@ -18,6 +18,7 @@ #include #include #include +#include using namespace boost::endian; using std::cout; @@ -198,6 +199,23 @@ namespace std::cout << "test construction and assignment" << std::endl; } + template + void test_boundary_values() + { + endian_buffer bmax( + std::numeric_limits::max()); + endian_buffer bmin( + std::numeric_limits::min()); + endian_buffer lmax( + std::numeric_limits::max()); + endian_buffer lmin( + std::numeric_limits::min()); + + BOOST_TEST(bmax.value() == std::numeric_limits::max()); + BOOST_TEST(bmin.value() == std::numeric_limits::min()); + BOOST_TEST(lmax.value() == std::numeric_limits::max()); + BOOST_TEST(lmin.value() == std::numeric_limits::min()); + } } // unnamed namespace //--------------------------------------------------------------------------------------// @@ -230,6 +248,13 @@ int cpp_main(int, char *[]) test_inserter_and_extractor(); test_construction_and_assignment(); + test_boundary_values(); + test_boundary_values(); + test_boundary_values(); + test_boundary_values(); + test_boundary_values(); + test_boundary_values(); + cout << " done" << endl; return ::boost::report_errors();