From e41ba84da8deac8f4d821f72c82e2ebe67d9b7da Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 30 Jun 2020 22:06:37 +0300 Subject: [PATCH] Add protect_cpp20_test.cpp --- test/Jamfile.v2 | 1 + test/protect_cpp20_test.cpp | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 test/protect_cpp20_test.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index e2c1b2c..828dfdb 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -76,3 +76,4 @@ run global_placeholders.cpp ; run mem_fn_noexcept_test.cpp ; run bind_cpp20_test.cpp ; run protect_test2.cpp ; +run protect_cpp20_test.cpp ; diff --git a/test/protect_cpp20_test.cpp b/test/protect_cpp20_test.cpp new file mode 100644 index 0000000..b20ce00 --- /dev/null +++ b/test/protect_cpp20_test.cpp @@ -0,0 +1,42 @@ +// Copyright 2020 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include + +// + +int main() +{ + BOOST_TEST_EQ( boost::protect( std::plus() )( 1, 2 ), 3 ); + BOOST_TEST_EQ( boost::protect( std::minus() )( 1, 2 ), -1 ); + BOOST_TEST_EQ( boost::protect( std::multiplies() )( 1, 2 ), 2 ); + BOOST_TEST_EQ( boost::protect( std::divides() )( 1, 2 ), 0 ); + BOOST_TEST_EQ( boost::protect( std::modulus() )( 1, 2 ), 1 ); + BOOST_TEST_EQ( boost::protect( std::negate() )( 1 ), -1 ); + + BOOST_TEST_EQ( boost::protect( std::equal_to() )( 1, 2 ), false ); + BOOST_TEST_EQ( boost::protect( std::not_equal_to() )( 1, 2 ), true ); + BOOST_TEST_EQ( boost::protect( std::greater() )( 1, 2 ), false ); + BOOST_TEST_EQ( boost::protect( std::less() )( 1, 2 ), true ); + BOOST_TEST_EQ( boost::protect( std::greater_equal() )( 1, 2 ), false ); + BOOST_TEST_EQ( boost::protect( std::less_equal() )( 1, 2 ), true ); + + BOOST_TEST_EQ( boost::protect( std::logical_and() )( 1, 2 ), true ); + BOOST_TEST_EQ( boost::protect( std::logical_or() )( 1, 2 ), true ); + BOOST_TEST_EQ( boost::protect( std::logical_not() )( 1 ), false ); + +#if !BOOST_WORKAROUND(BOOST_MSVC, < 1600) + + BOOST_TEST_EQ( boost::protect( std::bit_and() )( 1, 2 ), 0 ); + BOOST_TEST_EQ( boost::protect( std::bit_or() )( 1, 2 ), 3 ); + BOOST_TEST_EQ( boost::protect( std::bit_xor() )( 1, 2 ), 3 ); + +#endif + + return boost::report_errors(); +}