]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/system/test/error_category_test.cpp
2 // Copyright 2018 Peter Dimov.
4 // Distributed under the Boost Software License, Version 1.0.
6 // See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt
9 // See library home page at http://www.boost.org/libs/system
11 // Avoid spurious VC++ warnings
12 # define _CRT_SECURE_NO_WARNINGS
14 #include <boost/system/error_code.hpp>
15 #include <boost/core/lightweight_test.hpp>
20 namespace sys
= boost::system
;
22 class user_category
: public sys::error_category
26 virtual const char * name() const BOOST_NOEXCEPT
31 virtual std::string
message( int ev
) const
34 std::sprintf( buffer
, "user message %d", ev
);
39 using sys::error_category::message
;
42 static user_category s_cat_1
;
43 static user_category s_cat_2
;
47 // default_error_condition
49 BOOST_TEST( s_cat_1
.default_error_condition( 1 ) == sys::error_condition( 1, s_cat_1
) );
50 BOOST_TEST( s_cat_2
.default_error_condition( 2 ) == sys::error_condition( 2, s_cat_2
) );
54 BOOST_TEST( s_cat_1
.equivalent( 1, sys::error_condition( 1, s_cat_1
) ) );
55 BOOST_TEST( !s_cat_1
.equivalent( 1, sys::error_condition( 2, s_cat_1
) ) );
56 BOOST_TEST( !s_cat_1
.equivalent( 1, sys::error_condition( 2, s_cat_2
) ) );
58 // the other equivalent
60 BOOST_TEST( s_cat_1
.equivalent( sys::error_code( 1, s_cat_1
), 1 ) );
61 BOOST_TEST( !s_cat_1
.equivalent( sys::error_code( 1, s_cat_1
), 2 ) );
62 BOOST_TEST( !s_cat_1
.equivalent( sys::error_code( 1, s_cat_2
), 1 ) );
68 BOOST_TEST_CSTR_EQ( s_cat_1
.message( 1, buffer
, sizeof( buffer
) ), s_cat_1
.message( 1 ).c_str() );
73 BOOST_TEST_CSTR_EQ( s_cat_1
.message( 1, buffer
, sizeof( buffer
) ), "use" );
78 BOOST_TEST_NOT( s_cat_1
== s_cat_2
);
79 BOOST_TEST( s_cat_1
!= s_cat_2
);
81 return boost::report_errors();