Skip to content

Commit

Permalink
Update error_code_test2.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Jun 2, 2024
1 parent 4d4f906 commit bef2c5e
Showing 1 changed file with 80 additions and 15 deletions.
95 changes: 80 additions & 15 deletions test/error_code_test2.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_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 );

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

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

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

Expand Down

0 comments on commit bef2c5e

Please sign in to comment.