From bef2c5ef6ab3e86c25b5908e7ab586cf08fe268a Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 2 Jun 2024 22:26:01 +0300 Subject: [PATCH] Update error_code_test2.cpp --- test/error_code_test2.cpp | 95 ++++++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 15 deletions(-) diff --git a/test/error_code_test2.cpp b/test/error_code_test2.cpp index aca7a055..9bed6a59 100644 --- a/test/error_code_test2.cpp +++ b/test/error_code_test2.cpp @@ -11,29 +11,53 @@ namespace sys = boost::system; int main() { - char buffer[ 1024 ]; + char buffer[ 4096 ], buffer2[ 4096 ]; - sys::error_code ec; + { + sys::error_code ec; + + BOOST_TEST_EQ( ec.value(), 0 ); + BOOST_TEST( ec.category() == sys::system_category() ); + + BOOST_TEST_EQ( ec.message(), ec.category().message( ec.value() ) ); + BOOST_TEST_CSTR_EQ( ec.message( buffer, sizeof( buffer ) ), ec.category().message( ec.value(), buffer2, sizeof( buffer2 ) ) ); + BOOST_TEST_CSTR_EQ( ec.message( buffer, sizeof( buffer ) ), ec.message().c_str() ); - BOOST_TEST_EQ( ec.value(), 0 ); - BOOST_TEST( ec.category() == sys::system_category() ); - BOOST_TEST_EQ( ec.message(), ec.category().message( ec.value() ) ); - BOOST_TEST_CSTR_EQ( ec.message( buffer, sizeof( buffer ) ), ec.category().message( ec.value(), buffer, sizeof( buffer ) ) ); - BOOST_TEST( !ec.failed() ); - BOOST_TEST( !ec ); + { + char const* msg = ec.message( nullptr, 0 ); - BOOST_TEST_EQ( ec.to_string(), std::string( "system:0" ) ); + if( msg != nullptr ) + { + BOOST_TEST_CSTR_EQ( msg, ec.message().c_str() ); + } + } - // when len is 0 buffer can be nullptr - ec.message( nullptr, 0 ); + BOOST_TEST( !ec.failed() ); + BOOST_TEST( !ec ); + + BOOST_TEST_EQ( ec.to_string(), std::string( "system:0" ) ); + } { + sys::error_code ec; sys::error_code ec2( ec ); BOOST_TEST_EQ( ec2.value(), 0 ); BOOST_TEST( ec2.category() == sys::system_category() ); + BOOST_TEST_EQ( ec2.message(), ec2.category().message( ec2.value() ) ); - BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer, sizeof( buffer ) ) ); + BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer2, sizeof( buffer2 ) ) ); + BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.message().c_str() ); + + { + char const* msg = ec2.message( nullptr, 0 ); + + if( msg != nullptr ) + { + BOOST_TEST_CSTR_EQ( msg, ec2.message().c_str() ); + } + } + BOOST_TEST( !ec2.failed() ); BOOST_TEST( !ec2 ); @@ -44,12 +68,25 @@ int main() } { + sys::error_code ec; sys::error_code ec2( ec.value(), ec.category() ); BOOST_TEST_EQ( ec2.value(), 0 ); BOOST_TEST( ec2.category() == sys::system_category() ); + BOOST_TEST_EQ( ec2.message(), ec2.category().message( ec2.value() ) ); - BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer, sizeof( buffer ) ) ); + BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer2, sizeof( buffer2 ) ) ); + BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.message().c_str() ); + + { + char const* msg = ec2.message( nullptr, 0 ); + + if( msg != nullptr ) + { + BOOST_TEST_CSTR_EQ( msg, ec2.message().c_str() ); + } + } + BOOST_TEST( !ec2.failed() ); BOOST_TEST( !ec2 ); @@ -64,12 +101,26 @@ int main() BOOST_TEST_EQ( ec2.value(), 5 ); BOOST_TEST( ec2.category() == sys::generic_category() ); + BOOST_TEST_EQ( ec2.message(), ec2.category().message( ec2.value() ) ); - BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer, sizeof( buffer ) ) ); + BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer2, sizeof( buffer2 ) ) ); + BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.message().c_str() ); + + { + char const* msg = ec2.message( nullptr, 0 ); + + if( msg != nullptr ) + { + BOOST_TEST_CSTR_EQ( msg, ec2.message().c_str() ); + } + } + BOOST_TEST( ec2.failed() ); BOOST_TEST( ec2 ); BOOST_TEST_NOT( !ec2 ); + sys::error_code ec; + BOOST_TEST_NE( ec, ec2 ); BOOST_TEST_NOT( ec == ec2 ); @@ -81,12 +132,26 @@ int main() BOOST_TEST_EQ( ec2.value(), 5 ); BOOST_TEST( ec2.category() == sys::system_category() ); + BOOST_TEST_EQ( ec2.message(), ec2.category().message( ec2.value() ) ); - BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer, sizeof( buffer ) ) ); + BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer2, sizeof( buffer2 ) ) ); + BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.message().c_str() ); + + { + char const* msg = ec2.message( nullptr, 0 ); + + if( msg != nullptr ) + { + BOOST_TEST_CSTR_EQ( msg, ec2.message().c_str() ); + } + } + BOOST_TEST( ec2.failed() ); BOOST_TEST( ec2 ); BOOST_TEST_NOT( !ec2 ); + sys::error_code ec; + BOOST_TEST_NE( ec, ec2 ); BOOST_TEST_NOT( ec == ec2 );