Skip to content

Commit

Permalink
Update error_condition_test3.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Jun 2, 2024
1 parent bef2c5e commit c63bca6
Showing 1 changed file with 80 additions and 15 deletions.
95 changes: 80 additions & 15 deletions test/error_condition_test3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -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 );

Expand All @@ -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 );

Expand All @@ -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 );

Expand Down

0 comments on commit c63bca6

Please sign in to comment.