1 | // Copyright 2022 Peter Dimov. |
2 | // Distributed under the Boost Software License, Version 1.0. |
3 | // http://www.boost.org/LICENSE_1_0.txt |
4 | |
5 | #include <boost/system/error_code.hpp> |
6 | #include <boost/system/error_condition.hpp> |
7 | #include <boost/system/generic_category.hpp> |
8 | #include <boost/core/lightweight_test.hpp> |
9 | |
10 | namespace sys = boost::system; |
11 | |
12 | enum my_errc |
13 | { |
14 | enomem_c = ENOMEM |
15 | }; |
16 | |
17 | enum my_errn |
18 | { |
19 | enomem_n = ENOMEM |
20 | }; |
21 | |
22 | namespace boost { |
23 | namespace system { |
24 | |
25 | template<> struct is_error_code_enum<my_errc> |
26 | { |
27 | static const bool value = true; |
28 | }; |
29 | |
30 | template<> struct is_error_condition_enum<my_errn> |
31 | { |
32 | static const bool value = true; |
33 | }; |
34 | |
35 | } // namespace system |
36 | } // namespace boost |
37 | |
38 | sys::error_code make_error_code( my_errc e ) |
39 | { |
40 | return sys::error_code( e, sys::generic_category() ); |
41 | } |
42 | |
43 | sys::error_condition make_error_condition( my_errn e ) |
44 | { |
45 | return sys::error_condition( e, sys::generic_category() ); |
46 | } |
47 | |
48 | int main() |
49 | { |
50 | sys::error_code ec = make_error_code( e: sys::errc::not_enough_memory ); |
51 | sys::error_condition en( sys::errc::not_enough_memory ); |
52 | |
53 | BOOST_TEST_EQ( ec, en ); |
54 | BOOST_TEST_EQ( en, ec ); |
55 | |
56 | BOOST_TEST_EQ( ec, enomem_c ); |
57 | BOOST_TEST_EQ( enomem_c, ec ); |
58 | |
59 | BOOST_TEST_EQ( ec, enomem_n ); |
60 | BOOST_TEST_EQ( enomem_n, ec ); |
61 | |
62 | BOOST_TEST_EQ( en, enomem_c ); |
63 | BOOST_TEST_EQ( enomem_c, en ); |
64 | |
65 | BOOST_TEST_EQ( en, enomem_n ); |
66 | BOOST_TEST_EQ( enomem_n, en ); |
67 | |
68 | return boost::report_errors(); |
69 | } |
70 | |