Add const char* constructors to system_error, rationalize test coverage

[SVN r46678]
This commit is contained in:
Beman Dawes
2008-06-25 14:16:59 +00:00
parent 2953464e99
commit a97517585c
3 changed files with 70 additions and 19 deletions

View File

@ -689,7 +689,10 @@ application program interfaces.</p>
{ {
public: public:
system_error( error_code ec ); system_error( error_code ec );
system_error( error_code ec, const char * what_arg );
system_error( error_code ec, const std::string &amp; what_arg ); system_error( error_code ec, const std::string &amp; what_arg );
system_error( error_code::value_type ev, const error_category &amp; ecat,
const char * what_arg );
system_error( error_code::value_type ev, const error_category &amp; ecat, system_error( error_code::value_type ev, const error_category &amp; ecat,
const std::string &amp; what_arg ); const std::string &amp; what_arg );
system_error( error_code::value_type ev, const error_category &amp; ecat); system_error( error_code::value_type ev, const error_category &amp; ecat);
@ -706,12 +709,25 @@ application program interfaces.</p>
<p><i>Postcondition:</i> <code>code() == ec <br> <p><i>Postcondition:</i> <code>code() == ec <br>
&nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), &quot;&quot; ) == 0</code></p> &nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), &quot;&quot; ) == 0</code></p>
</blockquote> </blockquote>
<pre>system_error( error_code ec, const char * what_arg );</pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p>
<p><i>Postcondition:</i> <code>code() == ec <br>
&nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), what_arg ) == 0</code></p>
</blockquote>
<pre>system_error( error_code ec, const std::string &amp; what_arg );</pre> <pre>system_error( error_code ec, const std::string &amp; what_arg );</pre>
<blockquote> <blockquote>
<p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p> <p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p>
<p><i>Postcondition:</i> <code>code() == ec <br> <p><i>Postcondition:</i> <code>code() == ec <br>
&nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), what_arg.c_str() ) == 0</code></p> &nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), what_arg.c_str() ) == 0</code></p>
</blockquote> </blockquote>
<pre>system_error( error_code::value_type ev, const error_category &amp; ecat,
const char * what_arg );</pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p>
<p><i>Postcondition:</i> <code>code() == error_code( ev, ecat )<br>
&nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), what_arg ) == 0</code></p>
</blockquote>
<pre>system_error( error_code::value_type ev, const error_category &amp; ecat, <pre>system_error( error_code::value_type ev, const error_category &amp; ecat,
const std::string &amp; what_arg );</pre> const std::string &amp; what_arg );</pre>
<blockquote> <blockquote>
@ -743,7 +759,7 @@ Distributed under the Boost Software License, Version 1.0. See
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p> <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
<p>Revised <p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%B %d, %Y" startspan -->June 24, 2008<!--webbot bot="Timestamp" endspan i-checksum="14232" --> </font> <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%B %d, %Y" startspan -->June 25, 2008<!--webbot bot="Timestamp" endspan i-checksum="14296" --> </font>
</p> </p>
</body> </body>

View File

@ -24,13 +24,23 @@ namespace boost
public: public:
system_error( error_code ec ) system_error( error_code ec )
: std::runtime_error(""), m_error_code(ec) {} : std::runtime_error(""), m_error_code(ec) {}
system_error( error_code ec, const std::string & what_arg ) system_error( error_code ec, const std::string & what_arg )
: std::runtime_error(what_arg), m_error_code(ec) {} : std::runtime_error(what_arg), m_error_code(ec) {}
system_error( error_code ec, const char* what_arg )
: std::runtime_error(what_arg), m_error_code(ec) {}
system_error( int ev, const error_category & ecat )
: std::runtime_error(""), m_error_code(ev,ecat) {}
system_error( int ev, const error_category & ecat, system_error( int ev, const error_category & ecat,
const std::string & what_arg ) const std::string & what_arg )
: std::runtime_error(what_arg), m_error_code(ev,ecat) {} : std::runtime_error(what_arg), m_error_code(ev,ecat) {}
system_error( int ev, const error_category & ecat )
: std::runtime_error(""), m_error_code(ev,ecat) {} system_error( int ev, const error_category & ecat,
const char * what_arg )
: std::runtime_error(what_arg), m_error_code(ev,ecat) {}
virtual ~system_error() throw() {} virtual ~system_error() throw() {}

View File

@ -14,6 +14,7 @@
#include <boost/test/minimal.hpp> #include <boost/test/minimal.hpp>
#include <boost/system/system_error.hpp> #include <boost/system/system_error.hpp>
#include <iostream> #include <iostream>
#include <string>
#ifdef BOOST_WINDOWS_API #ifdef BOOST_WINDOWS_API
#include <windows.h> #include <windows.h>
@ -22,6 +23,7 @@
using boost::system::system_error; using boost::system::system_error;
using boost::system::error_code; using boost::system::error_code;
using boost::system::system_category; using boost::system::system_category;
using std::string;
#define TEST(x,v,w) test(#x,x,v,w) #define TEST(x,v,w) test(#x,x,v,w)
@ -51,29 +53,52 @@ namespace
# endif # endif
} }
const boost::uint_least32_t uvalue = 1u; const boost::uint_least32_t uvalue = 2u;
} }
int test_main( int, char *[] ) int test_main( int, char *[] )
{ {
// all combinations of constructors: // all constructors, in the same order as they appear in the header:
system_error se_0_m( error_code(0, system_category), "se_0_m" ); system_error c1_0( error_code(0, system_category) );
system_error se_1_m( 1, system_category, "se_1_m" ); system_error c1_1( error_code(1, system_category) );
system_error se_0_nm( error_code(0, system_category), "" ); system_error c1_2u( error_code(uvalue, system_category) );
system_error se_1_nm( 1, system_category, "" );
system_error se_0_nmx( error_code(0, system_category), "" );
system_error se_1_nmx( 1, system_category, "" );
system_error se_1u_m( uvalue, system_category, "se_1u_m" );
TEST( se_0_m, 0, "se_0_m" ); system_error c2_0( error_code(0, system_category), string("c2_0") );
TEST( se_1_m, 1, "se_1_m: Incorrect function" ); system_error c2_1( error_code(1, system_category), string("c2_1") );
TEST( se_0_nm, 0, "" );
TEST( se_1_nm, 1, "Incorrect function" );
TEST( se_0_nmx, 0, "" );
TEST( se_1_nmx, 1, "Incorrect function" );
TEST( se_1u_m, 1, "se_1u_m: Incorrect function" );
system_error c3_0( error_code(0, system_category), "c3_0" );
system_error c3_1( error_code(1, system_category), "c3_1" );
system_error c4_0( 0, system_category );
system_error c4_1( 1, system_category );
system_error c4_2u( uvalue, system_category );
system_error c5_0( 0, system_category, string("c5_0") );
system_error c5_1( 1, system_category, string("c5_1") );
system_error c6_0( 0, system_category, "c6_0" );
system_error c6_1( 1, system_category, "c6_1" );
TEST( c1_0, 0, "" );
TEST( c1_1, 1, "Incorrect function" );
TEST( c1_2u, 2, "The system cannot find the file specified" );
TEST( c2_0, 0, "c2_0" );
TEST( c2_1, 1, "c2_1: Incorrect function" );
TEST( c3_0, 0, "c3_0" );
TEST( c3_1, 1, "c3_1: Incorrect function" );
TEST( c4_0, 0, "" );
TEST( c4_1, 1, "Incorrect function" );
TEST( c4_2u, 2, "The system cannot find the file specified" );
TEST( c5_0, 0, "c5_0" );
TEST( c5_1, 1, "c5_1: Incorrect function" );
TEST( c6_0, 0, "c6_0" );
TEST( c6_1, 1, "c6_1: Incorrect function" );
return 0; return 0;
} }