Add error_code_test3.cpp

This commit is contained in:
Peter Dimov
2022-08-24 20:54:20 +03:00
parent 8c740705e6
commit 2bba3fd5e2
3 changed files with 67 additions and 0 deletions

View File

@ -126,6 +126,8 @@ boost_test(TYPE run SOURCES ec_location_test4.cpp)
boost_test(TYPE compile SOURCES constexpr_test2.cpp)
boost_test(TYPE run SOURCES error_code_test3.cpp)
# result
set(BOOST_TEST_COMPILE_FEATURES cxx_std_11)

View File

@ -154,6 +154,8 @@ run ec_location_test4.cpp ;
compile constexpr_test2.cpp ;
run error_code_test3.cpp ;
# result
import ../../config/checks/config : requires ;

63
test/error_code_test3.cpp Normal file
View File

@ -0,0 +1,63 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/system/error_condition.hpp>
#include <boost/system/generic_category.hpp>
#include <boost/core/lightweight_test.hpp>
namespace sys = boost::system;
enum my_errc
{
enomem_c = ENOMEM
};
enum my_errn
{
enomem_n = ENOMEM
};
namespace boost {
namespace system {
template<> struct is_error_code_enum<my_errc>
{
static const bool value = true;
};
template<> struct is_error_condition_enum<my_errn>
{
static const bool value = true;
};
} // namespace system
} // namespace boost
sys::error_code make_error_code( my_errc e )
{
return sys::error_code( e, sys::generic_category() );
}
sys::error_condition make_error_condition( my_errn e )
{
return sys::error_condition( e, sys::generic_category() );
}
int main()
{
sys::error_code ec = make_error_code( sys::errc::not_enough_memory );
sys::error_condition en( sys::errc::not_enough_memory );
BOOST_TEST_EQ( ec, en );
BOOST_TEST_EQ( en, ec );
BOOST_TEST_EQ( ec, enomem_n );
BOOST_TEST_EQ( enomem_n, ec );
// BOOST_TEST_EQ( en, enomem_c );
// BOOST_TEST_EQ( enomem_c, en );
return boost::report_errors();
}