[SVN r59673]
This commit is contained in:
Beman Dawes
2010-02-13 17:08:39 +00:00
parent d493021c7d
commit 2f6659f39e
6 changed files with 97 additions and 82 deletions

View File

@ -62,11 +62,8 @@ namespace boost
try try
{ {
m_what = this->std::runtime_error::what(); m_what = this->std::runtime_error::what();
if ( m_error_code ) if ( !m_what.empty() ) m_what += ": ";
{ m_what += m_error_code.message();
if ( !m_what.empty() ) m_what += ": ";
m_what += m_error_code.message();
}
} }
catch (...) { return std::runtime_error::what(); } catch (...) { return std::runtime_error::what(); }
} }

View File

@ -7,7 +7,10 @@
// See library home page at http://www.boost.org/libs/system // See library home page at http://www.boost.org/libs/system
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// test without deprecated features
#define BOOST_SYSTEM_NO_DEPRECATED
#include <boost/config/warning_disable.hpp> #include <boost/config/warning_disable.hpp>
@ -59,31 +62,31 @@ int main( int, char ** )
std::cout << "General tests...\n"; std::cout << "General tests...\n";
// unit tests: // unit tests:
BOOST_TEST( posix_category == posix_category ); BOOST_TEST( generic_category == generic_category );
BOOST_TEST( system_category == system_category ); BOOST_TEST( system_category == system_category );
BOOST_TEST( posix_category != system_category ); BOOST_TEST( generic_category != system_category );
BOOST_TEST( system_category != posix_category ); BOOST_TEST( system_category != generic_category );
if ( std::less<const error_category*>()( &posix_category, &system_category ) ) if ( std::less<const error_category*>()( &generic_category, &system_category ) )
{ {
BOOST_TEST( posix_category < system_category ); BOOST_TEST( generic_category < system_category );
BOOST_TEST( !(system_category < posix_category) ); BOOST_TEST( !(system_category < generic_category) );
} }
else else
{ {
BOOST_TEST( system_category < posix_category ); BOOST_TEST( system_category < generic_category );
BOOST_TEST( !(posix_category < system_category) ); BOOST_TEST( !(generic_category < system_category) );
} }
error_code ec; error_code ec;
error_condition dec; error_condition econd;
BOOST_TEST( !ec ); BOOST_TEST( !ec );
BOOST_TEST( ec.value() == 0 ); BOOST_TEST( ec.value() == 0 );
dec = ec.default_error_condition(); econd = ec.default_error_condition();
BOOST_TEST( dec.value() == 0 ); BOOST_TEST( econd.value() == 0 );
BOOST_TEST( dec.category() == posix_category ); BOOST_TEST( econd.category() == generic_category );
BOOST_TEST( ec == posix::success ); BOOST_TEST( ec == errc::success );
BOOST_TEST( ec.category() == system_category ); BOOST_TEST( ec.category() == system_category );
BOOST_TEST( std::strcmp( ec.category().name(), "system") == 0 ); BOOST_TEST( std::strcmp( ec.category().name(), "system") == 0 );
BOOST_TEST( !(ec < error_code( 0, system_category )) ); BOOST_TEST( !(ec < error_code( 0, system_category )) );
@ -94,10 +97,10 @@ int main( int, char ** )
error_code ec_0_system( 0, system_category ); error_code ec_0_system( 0, system_category );
BOOST_TEST( !ec_0_system ); BOOST_TEST( !ec_0_system );
BOOST_TEST( ec_0_system.value() == 0 ); BOOST_TEST( ec_0_system.value() == 0 );
dec = ec_0_system.default_error_condition(); econd = ec_0_system.default_error_condition();
BOOST_TEST( dec.value() == 0 ); BOOST_TEST( econd.value() == 0 );
BOOST_TEST( dec.category() == posix_category ); BOOST_TEST( econd.category() == generic_category );
BOOST_TEST( ec_0_system == posix::success ); BOOST_TEST( ec_0_system == errc::success );
BOOST_TEST( ec_0_system.category() == system_category ); BOOST_TEST( ec_0_system.category() == system_category );
BOOST_TEST( std::strcmp( ec_0_system.category().name(), "system") == 0 ); BOOST_TEST( std::strcmp( ec_0_system.category().name(), "system") == 0 );
check_ostream( ec_0_system, "system:0" ); check_ostream( ec_0_system, "system:0" );
@ -115,38 +118,40 @@ int main( int, char ** )
ec = error_code( BOOST_ACCESS_ERROR_MACRO, system_category ); ec = error_code( BOOST_ACCESS_ERROR_MACRO, system_category );
BOOST_TEST( ec ); BOOST_TEST( ec );
BOOST_TEST( ec.value() == BOOST_ACCESS_ERROR_MACRO ); BOOST_TEST( ec.value() == BOOST_ACCESS_ERROR_MACRO );
dec = ec.default_error_condition(); econd = ec.default_error_condition();
BOOST_TEST( dec.value() == static_cast<int>(posix::permission_denied) ); BOOST_TEST( econd.value() == static_cast<int>(errc::permission_denied) );
BOOST_TEST( dec.category() == posix_category ); BOOST_TEST( econd.category() == generic_category );
BOOST_TEST( dec == error_condition( posix::permission_denied, posix_category ) ); BOOST_TEST( econd == error_condition( errc::permission_denied, generic_category ) );
BOOST_TEST( dec == posix::permission_denied ); BOOST_TEST( econd == errc::permission_denied );
BOOST_TEST( posix::permission_denied == dec ); BOOST_TEST( errc::permission_denied == econd );
BOOST_TEST( ec == posix::permission_denied ); BOOST_TEST( ec == errc::permission_denied );
BOOST_TEST( ec.category() == system_category ); BOOST_TEST( ec.category() == system_category );
BOOST_TEST( std::strcmp( ec.category().name(), "system") == 0 ); BOOST_TEST( std::strcmp( ec.category().name(), "system") == 0 );
// test the explicit make_error_code conversion for posix // test the explicit make_error_code conversion for errc
ec = make_error_code( posix::bad_message ); ec = make_error_code( errc::bad_message );
BOOST_TEST( ec ); BOOST_TEST( ec );
BOOST_TEST( ec == posix::bad_message ); BOOST_TEST( ec == errc::bad_message );
BOOST_TEST( posix::bad_message == ec ); BOOST_TEST( errc::bad_message == ec );
BOOST_TEST( ec != posix::permission_denied ); BOOST_TEST( ec != errc::permission_denied );
BOOST_TEST( posix::permission_denied != ec ); BOOST_TEST( errc::permission_denied != ec );
BOOST_TEST( ec.category() == posix_category ); BOOST_TEST( ec.category() == generic_category );
// test the deprecated predefined error_category synonyms //// test the deprecated predefined error_category synonyms
BOOST_TEST( &system_category == &native_ecat ); //BOOST_TEST( &system_category == &native_ecat );
BOOST_TEST( &posix_category == &errno_ecat ); //BOOST_TEST( &generic_category == &errno_ecat );
BOOST_TEST( system_category == native_ecat ); //BOOST_TEST( system_category == native_ecat );
BOOST_TEST( posix_category == errno_ecat ); //BOOST_TEST( generic_category == errno_ecat );
// test error_code and error_condition message(); // test error_code and error_condition message();
// see Boost.Filesystem operations_test for code specific message() tests // see Boost.Filesystem operations_test for code specific message() tests
ec = error_code( -1, system_category ); ec = error_code( -1, system_category );
std::cout << "error_code message for -1 is \"" << ec.message() << "\"\n"; std::cout << "error_code message for -1 is \"" << ec.message() << "\"\n";
std::cout << "error_code message for 0 is \"" << ec_0_system.message() << "\"\n";
#if defined(BOOST_WINDOWS_API) #if defined(BOOST_WINDOWS_API)
// Borland appends newline, so just check text // Borland appends newline, so just check text
BOOST_TEST( ec.message().substr(0,13) == "Unknown error" ); BOOST_TEST( ec.message().substr(0,13) == "Unknown error" );
BOOST_TEST( ec_0_system.message().substr(0,36) == "The operation completed successfully" );
#elif defined(linux) || defined(__linux) || defined(__linux__) #elif defined(linux) || defined(__linux) || defined(__linux__)
// Linux appends value to message as unsigned, so it varies with # of bits // Linux appends value to message as unsigned, so it varies with # of bits
BOOST_TEST( ec.message().substr(0,13) == "Unknown error" ); BOOST_TEST( ec.message().substr(0,13) == "Unknown error" );
@ -162,63 +167,66 @@ int main( int, char ** )
BOOST_TEST( ec.message() != "" ); BOOST_TEST( ec.message() != "" );
BOOST_TEST( ec.message().substr( 0, 13) != "Unknown error" ); BOOST_TEST( ec.message().substr( 0, 13) != "Unknown error" );
dec = error_condition( -1, posix_category ); econd = error_condition( -1, generic_category );
std::cout << "error_condition message for -1 is \"" << dec.message() << "\"\n"; error_condition econd_ok;
std::cout << "error_condition message for -1 is \"" << econd.message() << "\"\n";
std::cout << "error_condition message for 0 is \"" << econd_ok.message() << "\"\n";
#if defined(BOOST_WINDOWS_API) #if defined(BOOST_WINDOWS_API)
// Borland appends newline, so just check text // Borland appends newline, so just check text
BOOST_TEST( dec.message().substr(0,13) == "Unknown error" ); BOOST_TEST( econd.message().substr(0,13) == "Unknown error" );
BOOST_TEST( econd_ok.message().substr(0,8) == "No error" );
#elif defined(linux) || defined(__linux) || defined(__linux__) #elif defined(linux) || defined(__linux) || defined(__linux__)
// Linux appends value to message as unsigned, so it varies with # of bits // Linux appends value to message as unsigned, so it varies with # of bits
BOOST_TEST( dec.message().substr(0,13) == "Unknown error" ); BOOST_TEST( econd.message().substr(0,13) == "Unknown error" );
#elif defined(__hpux) #elif defined(__hpux)
BOOST_TEST( dec.message() == "" ); BOOST_TEST( econd.message() == "" );
#elif defined(__osf__) #elif defined(__osf__)
BOOST_TEST( dec.message() == "Error -1 occurred." ); BOOST_TEST( econd.message() == "Error -1 occurred." );
#elif defined(__vms) #elif defined(__vms)
BOOST_TEST( dec.message() == "error -1" ); BOOST_TEST( econd.message() == "error -1" );
#endif #endif
dec = error_condition( BOOST_ACCESS_ERROR_MACRO, posix_category ); econd = error_condition( BOOST_ACCESS_ERROR_MACRO, generic_category );
BOOST_TEST( dec.message() != "" ); BOOST_TEST( econd.message() != "" );
BOOST_TEST( dec.message().substr( 0, 13) != "Unknown error" ); BOOST_TEST( econd.message().substr( 0, 13) != "Unknown error" );
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
std::cout << "Windows tests...\n"; std::cout << "Windows tests...\n";
// these tests probe the Windows posix decoder // these tests probe the Windows errc decoder
// test the first entry in the decoder table: // test the first entry in the decoder table:
ec = error_code( ERROR_ACCESS_DENIED, system_category ); ec = error_code( ERROR_ACCESS_DENIED, system_category );
BOOST_TEST( ec.value() == ERROR_ACCESS_DENIED ); BOOST_TEST( ec.value() == ERROR_ACCESS_DENIED );
BOOST_TEST( ec == posix::permission_denied ); BOOST_TEST( ec == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().value() == posix::permission_denied ); BOOST_TEST( ec.default_error_condition().value() == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().category() == posix_category ); BOOST_TEST( ec.default_error_condition().category() == generic_category );
// test the second entry in the decoder table: // test the second entry in the decoder table:
ec = error_code( ERROR_ALREADY_EXISTS, system_category ); ec = error_code( ERROR_ALREADY_EXISTS, system_category );
BOOST_TEST( ec.value() == ERROR_ALREADY_EXISTS ); BOOST_TEST( ec.value() == ERROR_ALREADY_EXISTS );
BOOST_TEST( ec == posix::file_exists ); BOOST_TEST( ec == errc::file_exists );
BOOST_TEST( ec.default_error_condition().value() == posix::file_exists ); BOOST_TEST( ec.default_error_condition().value() == errc::file_exists );
BOOST_TEST( ec.default_error_condition().category() == posix_category ); BOOST_TEST( ec.default_error_condition().category() == generic_category );
// test the third entry in the decoder table: // test the third entry in the decoder table:
ec = error_code( ERROR_BAD_UNIT, system_category ); ec = error_code( ERROR_BAD_UNIT, system_category );
BOOST_TEST( ec.value() == ERROR_BAD_UNIT ); BOOST_TEST( ec.value() == ERROR_BAD_UNIT );
BOOST_TEST( ec == posix::no_such_device ); BOOST_TEST( ec == errc::no_such_device );
BOOST_TEST( ec.default_error_condition().value() == posix::no_such_device ); BOOST_TEST( ec.default_error_condition().value() == errc::no_such_device );
BOOST_TEST( ec.default_error_condition().category() == posix_category ); BOOST_TEST( ec.default_error_condition().category() == generic_category );
// test the last non-Winsock entry in the decoder table: // test the last non-Winsock entry in the decoder table:
ec = error_code( ERROR_WRITE_PROTECT, system_category ); ec = error_code( ERROR_WRITE_PROTECT, system_category );
BOOST_TEST( ec.value() == ERROR_WRITE_PROTECT ); BOOST_TEST( ec.value() == ERROR_WRITE_PROTECT );
BOOST_TEST( ec == posix::permission_denied ); BOOST_TEST( ec == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().value() == posix::permission_denied ); BOOST_TEST( ec.default_error_condition().value() == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().category() == posix_category ); BOOST_TEST( ec.default_error_condition().category() == generic_category );
// test the last Winsock entry in the decoder table: // test the last Winsock entry in the decoder table:
ec = error_code( WSAEWOULDBLOCK, system_category ); ec = error_code( WSAEWOULDBLOCK, system_category );
BOOST_TEST( ec.value() == WSAEWOULDBLOCK ); BOOST_TEST( ec.value() == WSAEWOULDBLOCK );
BOOST_TEST( ec == posix::operation_would_block ); BOOST_TEST( ec == errc::operation_would_block );
BOOST_TEST( ec.default_error_condition().value() == posix::operation_would_block ); BOOST_TEST( ec.default_error_condition().value() == errc::operation_would_block );
BOOST_TEST( ec.default_error_condition().category() == posix_category ); BOOST_TEST( ec.default_error_condition().category() == generic_category );
// test not-in-table condition: // test not-in-table condition:
ec = error_code( 1234567890, system_category ); ec = error_code( 1234567890, system_category );
@ -230,12 +238,12 @@ int main( int, char ** )
std::cout << "POSIX tests...\n"; std::cout << "POSIX tests...\n";
ec = error_code( EACCES, system_category ); ec = error_code( EACCES, system_category );
BOOST_TEST( ec == error_code( posix::permission_denied, system_category ) ); BOOST_TEST( ec == error_code( errc::permission_denied, system_category ) );
BOOST_TEST( error_code( posix::permission_denied, system_category ) == ec ); BOOST_TEST( error_code( errc::permission_denied, system_category ) == ec );
BOOST_TEST( ec == posix::permission_denied ); BOOST_TEST( ec == errc::permission_denied );
BOOST_TEST( posix::permission_denied == ec ); BOOST_TEST( errc::permission_denied == ec );
BOOST_TEST( ec.default_error_condition().value() == posix::permission_denied ); BOOST_TEST( ec.default_error_condition().value() == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().category() == posix_category ); BOOST_TEST( ec.default_error_condition().category() == generic_category );
# ifdef __CYGWIN__ # ifdef __CYGWIN__

View File

@ -9,6 +9,9 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// test without deprecated features
#define BOOST_SYSTEM_NO_DEPRECATED
#include <boost/config/warning_disable.hpp> #include <boost/config/warning_disable.hpp>
#include <boost/test/minimal.hpp> #include <boost/test/minimal.hpp>
@ -80,24 +83,24 @@ int test_main( int, char *[] )
system_error c6_0( 0, system_category, "c6_0" ); system_error c6_0( 0, system_category, "c6_0" );
system_error c6_1( 1, system_category, "c6_1" ); system_error c6_1( 1, system_category, "c6_1" );
TEST( c1_0, 0, "" ); TEST( c1_0, 0, "The operation completed successfully" );
TEST( c1_1, 1, "Incorrect function" ); TEST( c1_1, 1, "Incorrect function" );
TEST( c1_2u, 2, "The system cannot find the file specified" ); TEST( c1_2u, 2, "The system cannot find the file specified" );
TEST( c2_0, 0, "c2_0" ); TEST( c2_0, 0, "c2_0: The operation completed successfully" );
TEST( c2_1, 1, "c2_1: Incorrect function" ); TEST( c2_1, 1, "c2_1: Incorrect function" );
TEST( c3_0, 0, "c3_0" ); TEST( c3_0, 0, "c3_0: The operation completed successfully" );
TEST( c3_1, 1, "c3_1: Incorrect function" ); TEST( c3_1, 1, "c3_1: Incorrect function" );
TEST( c4_0, 0, "" ); TEST( c4_0, 0, "The operation completed successfully" );
TEST( c4_1, 1, "Incorrect function" ); TEST( c4_1, 1, "Incorrect function" );
TEST( c4_2u, 2, "The system cannot find the file specified" ); TEST( c4_2u, 2, "The system cannot find the file specified" );
TEST( c5_0, 0, "c5_0" ); TEST( c5_0, 0, "c5_0: The operation completed successfully" );
TEST( c5_1, 1, "c5_1: Incorrect function" ); TEST( c5_1, 1, "c5_1: Incorrect function" );
TEST( c6_0, 0, "c6_0" ); TEST( c6_0, 0, "c6_0: The operation completed successfully" );
TEST( c6_1, 1, "c6_1: Incorrect function" ); TEST( c6_1, 1, "c6_1: Incorrect function" );
return 0; return 0;

View File

@ -9,6 +9,7 @@
AdditionalIncludeDirectories="../../../../.." AdditionalIncludeDirectories="../../../../.."
PreprocessorDefinitions="BOOST_ALL_NO_LIB" PreprocessorDefinitions="BOOST_ALL_NO_LIB"
ExceptionHandling="2" ExceptionHandling="2"
WarningLevel="4"
/> />
<Tool <Tool
Name="VCPostBuildEventTool" Name="VCPostBuildEventTool"

View File

@ -47,7 +47,7 @@
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="3" RuntimeLibrary="3"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="4"
DebugInformationFormat="4" DebugInformationFormat="4"
/> />
<Tool <Tool
@ -120,7 +120,7 @@
RuntimeLibrary="2" RuntimeLibrary="2"
EnableFunctionLevelLinking="true" EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="4"
DebugInformationFormat="3" DebugInformationFormat="3"
/> />
<Tool <Tool

View File

@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 10.00
# Visual C++ Express 2008 # Visual C++ Express 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "error_code_test", "error_code_test\error_code_test.vcproj", "{81960557-E9A9-4E81-AC96-9E11C33CB058}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "error_code_test", "error_code_test\error_code_test.vcproj", "{81960557-E9A9-4E81-AC96-9E11C33CB058}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "system_error_test", "system_error_test\system_error_test.vcproj", "{CBD12E59-99E5-4F35-9B66-0554D0FBDB76}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32 Debug|Win32 = Debug|Win32
@ -13,6 +15,10 @@ Global
{81960557-E9A9-4E81-AC96-9E11C33CB058}.Debug|Win32.Build.0 = Debug|Win32 {81960557-E9A9-4E81-AC96-9E11C33CB058}.Debug|Win32.Build.0 = Debug|Win32
{81960557-E9A9-4E81-AC96-9E11C33CB058}.Release|Win32.ActiveCfg = Release|Win32 {81960557-E9A9-4E81-AC96-9E11C33CB058}.Release|Win32.ActiveCfg = Release|Win32
{81960557-E9A9-4E81-AC96-9E11C33CB058}.Release|Win32.Build.0 = Release|Win32 {81960557-E9A9-4E81-AC96-9E11C33CB058}.Release|Win32.Build.0 = Release|Win32
{CBD12E59-99E5-4F35-9B66-0554D0FBDB76}.Debug|Win32.ActiveCfg = Debug|Win32
{CBD12E59-99E5-4F35-9B66-0554D0FBDB76}.Debug|Win32.Build.0 = Debug|Win32
{CBD12E59-99E5-4F35-9B66-0554D0FBDB76}.Release|Win32.ActiveCfg = Release|Win32
{CBD12E59-99E5-4F35-9B66-0554D0FBDB76}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE