More complete error_info testing

This commit is contained in:
Emil Dotchevski
2015-03-25 14:28:54 -07:00
parent 5a040eedf5
commit c57eefbf42
6 changed files with 81 additions and 125 deletions

View File

@ -34,8 +34,10 @@ run exception_test.cpp ;
run enable_error_info_test.cpp helper1.cpp ;
run throw_exception_test.cpp helper2.cpp ;
run errno_test.cpp ;
run error_info_test.cpp ;
run error_info_lv_test.cpp ;
run error_info_lv_const_test.cpp ;
run error_info_rv_test.cpp ;
run error_info_rv_const_test.cpp ;
run diagnostic_information_test.cpp ;
run refcount_ptr_test.cpp ;
run current_exception_cast_test.cpp ;

View File

@ -0,0 +1,13 @@
//Copyright (c) 2006-2015 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)
#include "boost/exception/info.hpp"
template <class E,class I>
E const &
add_info( E const & e, I const & i )
{
return e << i;
}
#include "error_info_test.hpp"

View File

@ -0,0 +1,13 @@
//Copyright (c) 2006-2015 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)
#include "boost/exception/info.hpp"
template <class E,class I>
E const &
add_info( E const & e, I i )
{
return e << i;
}
#include "error_info_test.hpp"

View File

@ -0,0 +1,28 @@
//Copyright (c) 2006-2015 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)
#include "boost/exception/info.hpp"
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
int
main()
{
return 0;
}
#else
template <class I>
I const
rv_const( I i )
{
return i;
}
template <class E,class I>
E const &
add_info( E const & e, I i )
{
return e << rv_const(i);
}
#include "error_info_test.hpp"
#endif

View File

@ -1,122 +1,22 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//Copyright (c) 2006-2015 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)
#include <boost/exception/get_error_info.hpp>
#include <boost/exception/info.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/detail/workaround.hpp>
#include <string.h>
#include "boost/exception/info.hpp"
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
int
main()
{
BOOST_FAIL("Platform does not support rvalue references.");
return 1;
{
return 0;
}
#else
struct move_only;
typedef boost::error_info<struct tag_test1,move_only> test1;
struct
test_exception:
boost::exception
{
};
struct
move_only
{
explicit move_only(int x) : x_(x) { }
move_only( move_only && other ) : x_(other.x_) { }
int x_;
private:
move_only( move_only const & );
};
void
throw_test1()
{
throw test_exception() << test1(move_only(7));
}
void
throw_test_throw_file_rv()
template <class E,class I>
E const &
add_info( E const & e, I i )
{
throw test_exception() << std::move(boost::throw_file("throw_file"));
return e << std::move(i);
}
void
throw_test_throw_function_rv()
{
throw test_exception() << std::move(boost::throw_function("throw_function"));
}
void
throw_test_throw_line_rv()
{
throw test_exception() << std::move(boost::throw_line(42));
}
int
main()
{
try
{
throw_test1();
BOOST_ASSERT(false);
}
catch(
boost::exception & x )
{
BOOST_TEST(boost::get_error_info<test1>(x));
BOOST_TEST(boost::get_error_info<test1>(x)->x_ == 7);
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
throw_test_throw_function_rv();
BOOST_ASSERT(false);
}
catch(
boost::exception & x )
{
BOOST_TEST(boost::get_error_info<boost::throw_function>(x) && !strcmp(*boost::get_error_info<boost::throw_function>(x),"throw_function"));
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
throw_test_throw_file_rv();
BOOST_ASSERT(false);
}
catch(
boost::exception & x )
{
BOOST_TEST(boost::get_error_info<boost::throw_file>(x) && !strcmp(*boost::get_error_info<boost::throw_file>(x),"throw_file"));
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
throw_test_throw_line_rv();
BOOST_ASSERT(false);
}
catch(
boost::exception & x )
{
BOOST_TEST(boost::get_error_info<boost::throw_line>(x) && *boost::get_error_info<boost::throw_line>(x)==42);
}
catch(
... )
{
BOOST_TEST(false);
}
return boost::report_errors();
}
#include "error_info_test.hpp"
#endif

View File

@ -1,4 +1,4 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//Copyright (c) 2006-2015 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)
@ -69,7 +69,7 @@ basic_test()
try
{
test_exception x;
x << test_1(1) << test_2(2u) << test_3(3.14159f);
add_info(add_info(add_info(x,test_1(1)),test_2(2u)),test_3(3.14159f));
throw x;
}
catch(
@ -86,7 +86,7 @@ basic_test()
try
{
test_exception x;
x << test_1(1) << test_2(2u) << test_3(3.14159f);
add_info(add_info(add_info(x,test_1(1)),test_2(2u)),test_3(3.14159f));
throw x;
}
catch(
@ -105,7 +105,7 @@ exception_safety_test()
test_exception x;
try
{
x << test_4(throws_on_copy());
add_info(x,test_4(throws_on_copy()));
BOOST_TEST(false);
}
catch(
@ -124,13 +124,13 @@ throw_empty()
void
throw_test_1( char const * value )
{
throw test_exception() << test_5(std::string(value));
throw add_info(test_exception(),test_5(std::string(value)));
}
void
throw_test_2()
{
throw test_exception() << test_6(non_printable());
throw add_info(test_exception(),test_6(non_printable()));
}
void
@ -144,7 +144,7 @@ throw_catch_add_file_name( char const * name )
catch(
boost::exception & x )
{
x << test_5(std::string(name));
add_info(x,test_5(std::string(name)));
throw;
}
}
@ -256,10 +256,10 @@ test_add_tuple()
typedef boost::tuple<test_1,test_2,test_3,test_5> tuple_test_1235;
try
{
throw test_exception() << tuple_test_();
throw add_info(test_exception(),tuple_test_());
}
catch(
test_exception & x )
test_exception & )
{
}
catch(
@ -269,7 +269,7 @@ test_add_tuple()
}
try
{
throw test_exception() << tuple_test_1(42);
throw add_info(test_exception(),tuple_test_1(42));
}
catch(
test_exception & x )
@ -283,7 +283,7 @@ test_add_tuple()
}
try
{
throw test_exception() << tuple_test_12(42,42u);
throw add_info(test_exception(),tuple_test_12(42,42u));
}
catch(
test_exception & x )
@ -298,7 +298,7 @@ test_add_tuple()
}
try
{
throw test_exception() << tuple_test_123(42,42u,42.0f);
throw add_info(test_exception(),tuple_test_123(42,42u,42.0f));
}
catch(
test_exception & x )
@ -314,7 +314,7 @@ test_add_tuple()
}
try
{
throw test_exception() << tuple_test_1235(42,42u,42.0f,std::string("42"));
throw add_info(test_exception(),tuple_test_1235(42,42u,42.0f,std::string("42")));
}
catch(
test_exception & x )
@ -337,7 +337,7 @@ test_lifetime1()
int count=0;
try
{
throw test_exception() << test_7(user_data(count));
throw add_info(test_exception(),test_7(user_data(count)));
}
catch(
boost::exception & x )
@ -359,7 +359,7 @@ test_lifetime2()
int count=0;
{
boost::exception_ptr ep;
test_exception e; e<<test_7(user_data(count));
test_exception e; add_info(e,test_7(user_data(count)));
ep=boost::copy_exception(e);
BOOST_TEST(count>0);
}