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