diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4c50b99..d5a1812 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 3217ae0..3a02003 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -154,6 +154,8 @@ run ec_location_test4.cpp ; compile constexpr_test2.cpp ; +run error_code_test3.cpp ; + # result import ../../config/checks/config : requires ; diff --git a/test/error_code_test3.cpp b/test/error_code_test3.cpp new file mode 100644 index 0000000..1c987b6 --- /dev/null +++ b/test/error_code_test3.cpp @@ -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 +#include +#include +#include + +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 +{ + static const bool value = true; +}; + +template<> struct is_error_condition_enum +{ + 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(); +}