mirror of
https://github.com/boostorg/exception.git
synced 2025-07-15 21:42:06 +02:00
Implemented support for custom to_string overloads for converting boost::error_info objects to string by the boost::diagnostic_information function.
[SVN r50507]
This commit is contained in:
@ -9,10 +9,21 @@
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
#if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x610))
|
||||
struct test_tag {};
|
||||
struct test_tag1 {};
|
||||
struct test_tag2 {};
|
||||
#endif
|
||||
|
||||
typedef boost::error_info<struct test_tag,int> tag_int;
|
||||
typedef boost::error_info<struct test_tag1,int> tagged_int1;
|
||||
typedef boost::error_info<struct test_tag2,int> tagged_int2;
|
||||
|
||||
std::string
|
||||
to_string( tagged_int2 const & x )
|
||||
{
|
||||
if( x.value()==42 )
|
||||
return "fourty-two";
|
||||
else
|
||||
return "bad value";
|
||||
}
|
||||
|
||||
struct
|
||||
error1:
|
||||
@ -38,19 +49,30 @@ main()
|
||||
using namespace boost;
|
||||
try
|
||||
{
|
||||
error1 x; x << tag_int(42);
|
||||
error1 x; x << tagged_int1(42) << tagged_int2(42);
|
||||
BOOST_TEST(x.what()==std::string("error1"));
|
||||
throw x;
|
||||
}
|
||||
catch(
|
||||
boost::exception & x )
|
||||
{
|
||||
std::string di=boost::diagnostic_information(x);
|
||||
std::string di1=boost::diagnostic_information(x);
|
||||
x << tagged_int1(2) << tagged_int2(2);
|
||||
std::string di2 = diagnostic_information(x);
|
||||
#ifndef BOOST_NO_RTTI
|
||||
BOOST_TEST(di.find("type:")!=std::string::npos);
|
||||
BOOST_TEST(di.find("error1")!=std::string::npos);
|
||||
BOOST_TEST(di1.find("type:")!=std::string::npos);
|
||||
BOOST_TEST(di1.find("error1")!=std::string::npos);
|
||||
#endif
|
||||
BOOST_TEST(di.find("test_tag")!=std::string::npos);
|
||||
BOOST_TEST(di1.find("test_tag1")!=std::string::npos);
|
||||
BOOST_TEST(di1.find("test_tag2")!=std::string::npos);
|
||||
BOOST_TEST(di1.find("fourty-two")!=std::string::npos);
|
||||
#ifndef BOOST_NO_RTTI
|
||||
BOOST_TEST(di2.find("type:")!=std::string::npos);
|
||||
BOOST_TEST(di2.find("error1")!=std::string::npos);
|
||||
#endif
|
||||
BOOST_TEST(di2.find("test_tag1")!=std::string::npos);
|
||||
BOOST_TEST(di2.find("test_tag2")!=std::string::npos);
|
||||
BOOST_TEST(di2.find("bad value")!=std::string::npos);
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
@ -60,18 +82,22 @@ main()
|
||||
try
|
||||
{
|
||||
error2 x;
|
||||
x << tag_int(1);
|
||||
x << tagged_int1(42) << tagged_int2(42);
|
||||
throw x;
|
||||
}
|
||||
catch(
|
||||
boost::exception & x )
|
||||
{
|
||||
std::string w1 = diagnostic_information(x);
|
||||
x << tag_int(2);
|
||||
std::string w2 = diagnostic_information(x);
|
||||
BOOST_TEST( w1!=w2 );
|
||||
BOOST_TEST(w1.find("test_tag")!=std::string::npos);
|
||||
BOOST_TEST(w2.find("test_tag")!=std::string::npos);
|
||||
std::string di1 = diagnostic_information(x);
|
||||
x << tagged_int1(2) << tagged_int2(2);
|
||||
std::string di2 = diagnostic_information(x);
|
||||
BOOST_TEST( di1!=di2 );
|
||||
BOOST_TEST(di1.find("test_tag1")!=std::string::npos);
|
||||
BOOST_TEST(di1.find("test_tag2")!=std::string::npos);
|
||||
BOOST_TEST(di1.find("fourty-two")!=std::string::npos);
|
||||
BOOST_TEST(di2.find("test_tag1")!=std::string::npos);
|
||||
BOOST_TEST(di2.find("test_tag2")!=std::string::npos);
|
||||
BOOST_TEST(di2.find("bad value")!=std::string::npos);
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
|
Reference in New Issue
Block a user