2008-03-04 01:41:17 +00:00
|
|
|
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
|
|
|
|
|
|
|
|
//Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
2008-08-28 23:49:55 +00:00
|
|
|
#include <boost/exception/get_error_info.hpp>
|
2008-03-04 01:41:17 +00:00
|
|
|
#include <boost/exception/info_tuple.hpp>
|
|
|
|
#include <boost/detail/lightweight_test.hpp>
|
|
|
|
|
|
|
|
struct throws_on_copy;
|
|
|
|
struct non_printable { };
|
|
|
|
|
|
|
|
typedef boost::error_info<struct tag_test_1,int> test_1;
|
|
|
|
typedef boost::error_info<struct tag_test_2,unsigned int> test_2;
|
|
|
|
typedef boost::error_info<struct tag_test_3,float> test_3;
|
|
|
|
typedef boost::error_info<struct tag_test_4,throws_on_copy> test_4;
|
|
|
|
typedef boost::error_info<struct tag_test_5,std::string> test_5;
|
|
|
|
typedef boost::error_info<struct tag_test_6,non_printable> test_6;
|
|
|
|
|
|
|
|
struct
|
|
|
|
test_exception:
|
2008-06-25 23:27:56 +00:00
|
|
|
boost::exception
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
|
|
|
};
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
struct
|
|
|
|
throws_on_copy
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
|
|
|
throws_on_copy()
|
|
|
|
{
|
|
|
|
}
|
2008-03-04 01:41:17 +00:00
|
|
|
|
2008-04-08 21:29:37 +00:00
|
|
|
throws_on_copy( throws_on_copy const & )
|
|
|
|
{
|
|
|
|
throw test_exception();
|
|
|
|
}
|
|
|
|
};
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
basic_test()
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
2008-08-28 23:49:55 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
test_exception x;
|
|
|
|
x << test_1(1) << test_2(2u) << test_3(3.14159f);
|
|
|
|
throw x;
|
|
|
|
}
|
|
|
|
catch(
|
|
|
|
test_exception & x )
|
|
|
|
{
|
|
|
|
BOOST_TEST(*boost::get_error_info<test_1>(x)==1);
|
|
|
|
BOOST_TEST(*boost::get_error_info<test_2>(x)==2u);
|
|
|
|
BOOST_TEST(*boost::get_error_info<test_3>(x)==3.14159f);
|
|
|
|
BOOST_TEST(!boost::get_error_info<test_4>(x));
|
|
|
|
}
|
2008-04-08 21:29:37 +00:00
|
|
|
}
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
exception_safety_test()
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
|
|
|
test_exception x;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
x << test_4(throws_on_copy());
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
|
|
|
catch(
|
|
|
|
test_exception & )
|
|
|
|
{
|
2008-08-28 23:49:55 +00:00
|
|
|
BOOST_TEST(!boost::get_error_info<test_4>(x));
|
2008-04-08 21:29:37 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
throw_empty()
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
|
|
|
throw test_exception();
|
|
|
|
}
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
throw_test_1( char const * value )
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
|
|
|
throw test_exception() << test_5(std::string(value));
|
|
|
|
}
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
throw_test_2()
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
|
|
|
throw test_exception() << test_6(non_printable());
|
|
|
|
}
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
throw_catch_add_file_name( char const * name )
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw_empty();
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
|
|
|
catch(
|
|
|
|
boost::exception & x )
|
|
|
|
{
|
|
|
|
x << test_5(std::string(name));
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
test_empty()
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw_empty();
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
|
|
|
catch(
|
|
|
|
boost::exception & x )
|
|
|
|
{
|
2008-08-28 23:49:55 +00:00
|
|
|
#ifndef BOOST_NO_RTTI
|
2008-04-08 21:29:37 +00:00
|
|
|
BOOST_TEST( dynamic_cast<test_exception *>(&x) );
|
2008-08-28 23:49:55 +00:00
|
|
|
#endif
|
2008-04-08 21:29:37 +00:00
|
|
|
BOOST_TEST( !boost::get_error_info<test_1>(x) );
|
|
|
|
}
|
2008-06-25 23:27:56 +00:00
|
|
|
catch(
|
|
|
|
... )
|
|
|
|
{
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
2008-04-08 21:29:37 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw_empty();
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
|
|
|
catch(
|
|
|
|
test_exception & x )
|
|
|
|
{
|
2008-08-28 23:49:55 +00:00
|
|
|
BOOST_TEST( boost::exception_detail::get_boost_exception(&x) );
|
2008-04-08 21:29:37 +00:00
|
|
|
}
|
2008-06-25 23:27:56 +00:00
|
|
|
catch(
|
|
|
|
... )
|
|
|
|
{
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
2008-04-08 21:29:37 +00:00
|
|
|
}
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
test_basic_throw_catch()
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw_test_1("test");
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
}
|
|
|
|
catch(
|
|
|
|
boost::exception & x )
|
|
|
|
{
|
|
|
|
BOOST_TEST(*boost::get_error_info<test_5>(x)==std::string("test"));
|
|
|
|
}
|
2008-06-25 23:27:56 +00:00
|
|
|
catch(
|
|
|
|
... )
|
|
|
|
{
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
|
|
|
|
2008-04-08 21:29:37 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
throw_test_2();
|
|
|
|
BOOST_ASSERT(false);
|
|
|
|
}
|
|
|
|
catch(
|
|
|
|
boost::exception & x )
|
|
|
|
{
|
|
|
|
BOOST_TEST(boost::get_error_info<test_6>(x));
|
|
|
|
}
|
2008-06-25 23:27:56 +00:00
|
|
|
catch(
|
|
|
|
... )
|
|
|
|
{
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
2008-04-08 21:29:37 +00:00
|
|
|
}
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
test_catch_add_info()
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw_catch_add_file_name("test");
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
|
|
|
catch(
|
|
|
|
boost::exception & x )
|
|
|
|
{
|
|
|
|
BOOST_TEST(*boost::get_error_info<test_5>(x)==std::string("test"));
|
|
|
|
}
|
2008-06-25 23:27:56 +00:00
|
|
|
catch(
|
|
|
|
... )
|
|
|
|
{
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
2008-04-08 21:29:37 +00:00
|
|
|
}
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
test_add_tuple()
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
|
|
|
typedef boost::tuple<test_1,test_2> test_12;
|
|
|
|
typedef boost::tuple<test_1,test_2,test_3> test_123;
|
|
|
|
typedef boost::tuple<test_1,test_2,test_3,test_5> test_1235;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw test_exception() << test_12(42,42u);
|
|
|
|
}
|
|
|
|
catch(
|
|
|
|
test_exception & x )
|
|
|
|
{
|
|
|
|
BOOST_TEST( *boost::get_error_info<test_1>(x)==42 );
|
|
|
|
BOOST_TEST( *boost::get_error_info<test_2>(x)==42u );
|
|
|
|
}
|
2008-06-25 23:27:56 +00:00
|
|
|
catch(
|
|
|
|
... )
|
|
|
|
{
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
2008-04-08 21:29:37 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
throw test_exception() << test_123(42,42u,42.0f);
|
|
|
|
}
|
|
|
|
catch(
|
|
|
|
test_exception & x )
|
|
|
|
{
|
|
|
|
BOOST_TEST( *boost::get_error_info<test_1>(x)==42 );
|
|
|
|
BOOST_TEST( *boost::get_error_info<test_2>(x)==42u );
|
|
|
|
BOOST_TEST( *boost::get_error_info<test_3>(x)==42.0f );
|
|
|
|
}
|
2008-06-25 23:27:56 +00:00
|
|
|
catch(
|
|
|
|
... )
|
|
|
|
{
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
2008-04-08 21:29:37 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
throw test_exception() << test_1235(42,42u,42.0f,std::string("42"));
|
|
|
|
}
|
|
|
|
catch(
|
|
|
|
test_exception & x )
|
|
|
|
{
|
|
|
|
BOOST_TEST( *boost::get_error_info<test_1>(x)==42 );
|
|
|
|
BOOST_TEST( *boost::get_error_info<test_2>(x)==42u );
|
|
|
|
BOOST_TEST( *boost::get_error_info<test_3>(x)==42.0f );
|
|
|
|
BOOST_TEST( *boost::get_error_info<test_5>(x)=="42" );
|
|
|
|
}
|
2008-06-25 23:27:56 +00:00
|
|
|
catch(
|
|
|
|
... )
|
|
|
|
{
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
2008-04-08 21:29:37 +00:00
|
|
|
}
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main()
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
|
|
|
basic_test();
|
|
|
|
exception_safety_test();
|
|
|
|
test_empty();
|
|
|
|
test_basic_throw_catch();
|
|
|
|
test_catch_add_info();
|
|
|
|
test_add_tuple();
|
|
|
|
return boost::report_errors();
|
|
|
|
}
|