1// Copyright 2021, 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_category.hpp>
7#include <boost/core/lightweight_test.hpp>
8#include <boost/config.hpp>
9#include <cerrno>
10#include <system_error>
11
12class my_category_impl: public std::error_category
13{
14public:
15
16 char const* name() const noexcept
17 {
18 return "mycat";
19 }
20
21 std::string message( int /*ev*/ ) const
22 {
23 return "Unknown error";
24 }
25};
26
27std::error_category const& my_category()
28{
29 static my_category_impl mycat;
30 return mycat;
31}
32
33int main()
34{
35 {
36 std::error_code e1( 5, boost::system::system_category() );
37 boost::system::error_code e2( e1 );
38 std::error_code e3( e2 );
39
40 BOOST_TEST_EQ( e1, e3 );
41 BOOST_TEST_EQ( e1.value(), e3.value() );
42 BOOST_TEST_EQ( &e1.category(), &e3.category() );
43 }
44
45 {
46 std::error_code e1( 5, boost::system::generic_category() );
47 boost::system::error_code e2( e1 );
48 std::error_code e3( e2 );
49
50 BOOST_TEST_EQ( e1, e3 );
51 BOOST_TEST_EQ( e1.value(), e3.value() );
52 BOOST_TEST_EQ( &e1.category(), &e3.category() );
53 }
54
55 {
56 std::error_code e1( 5, my_category() );
57 boost::system::error_code e2( e1 );
58 std::error_code e3( e2 );
59
60 BOOST_TEST_EQ( e1, e3 );
61 BOOST_TEST_EQ( e1.value(), e3.value() );
62 BOOST_TEST_EQ( &e1.category(), &e3.category() );
63 }
64
65 return boost::report_errors();
66}
67

source code of boost/libs/system/test/std_interop_test13.cpp