📄 test_tools.hpp
字号:
// (C) Copyright Gennadiy Rozental 2001-2004.// (C) Copyright Ullrich Koethe 2001.// 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)// See http://www.boost.org/libs/test for the library home page.//// File : $RCSfile: test_tools.hpp,v $//// Version : $Revision: 1.1.1.2 $//// Description : contains definition for all test tools in test toolbox// ***************************************************************************#ifndef BOOST_TEST_TOOLS_HPP_071894GER#define BOOST_TEST_TOOLS_HPP_071894GER// Boost.Test#include <boost/test/detail/unit_test_config.hpp>#include <boost/test/unit_test_log.hpp>#include <boost/test/detail/class_properties.hpp>#include <boost/test/detail/wrap_stringstream.hpp>// BOOST#include <boost/cstdlib.hpp> // for boost::exit_success;#include <boost/config.hpp> // compilers workarounds#include <boost/shared_ptr.hpp>#include <stdexcept> // for std::exception#include <cstddef> // for std::size_t#include <memory> // for std::auto_ptr#include <string> // for std::string#include <boost/test/detail/suppress_warnings.hpp>// ************************************************************************** //// ************** TOOL BOX ************** //// ************************************************************************** //#define BOOST_CHECKPOINT(message_) \ boost::test_tools::tt_detail::checkpoint_impl( \ boost::wrap_stringstream().ref() << message_, BOOST_TEST_STRING_LITERAL(__FILE__), (std::size_t)__LINE__) \/**/#define BOOST_WARN(predicate) \ boost::test_tools::tt_detail::warn_and_continue_impl((predicate), \ boost::wrap_stringstream().ref() << #predicate, BOOST_TEST_STRING_LITERAL(__FILE__), (std::size_t)__LINE__) \/**/#define BOOST_CHECK(predicate) \ boost::test_tools::tt_detail::test_and_continue_impl((predicate), \ boost::wrap_stringstream().ref() << #predicate, BOOST_TEST_STRING_LITERAL(__FILE__), (std::size_t)__LINE__) \/**/#define BOOST_CHECK_EQUAL(left_, right_) \ boost::test_tools::tt_detail::equal_and_continue_impl((left_), (right_), \ boost::wrap_stringstream().ref() << #left_ " == " #right_, BOOST_TEST_STRING_LITERAL(__FILE__), (std::size_t)__LINE__)/**/#define BOOST_CHECK_CLOSE(left_, right_, tolerance) \ boost::test_tools::tt_detail::compare_and_continue_impl((left_), (right_), (tolerance), \ BOOST_TEST_STRING_LITERAL( #left_ ), \ BOOST_TEST_STRING_LITERAL( #right_ ), \ BOOST_TEST_STRING_LITERAL(__FILE__), (std::size_t)__LINE__) \/**/#define BOOST_BITWISE_EQUAL(left_, right_) \ boost::test_tools::tt_detail::bitwise_equal_and_continue_impl((left_), (right_), \ boost::wrap_stringstream().ref() << #left_ " =.= " #right_, BOOST_TEST_STRING_LITERAL(__FILE__), (std::size_t)__LINE__)/**/#define BOOST_REQUIRE(predicate) \ boost::test_tools::tt_detail::test_and_throw_impl((predicate), \ boost::wrap_stringstream().ref() << #predicate, BOOST_TEST_STRING_LITERAL(__FILE__), (std::size_t)__LINE__)/**/#define BOOST_MESSAGE(message_) \ boost::test_tools::tt_detail::message_impl( \ boost::wrap_stringstream().ref() << message_, BOOST_TEST_STRING_LITERAL(__FILE__), (std::size_t)__LINE__)/**/#define BOOST_WARN_MESSAGE(predicate, message_) \ boost::test_tools::tt_detail::warn_and_continue_impl((predicate), \ boost::wrap_stringstream().ref() << message_, BOOST_TEST_STRING_LITERAL(__FILE__), (std::size_t)__LINE__,false)/**/#define BOOST_CHECK_MESSAGE(predicate, message_) \ boost::test_tools::tt_detail::test_and_continue_impl((predicate), \ boost::wrap_stringstream().ref() << message_, BOOST_TEST_STRING_LITERAL(__FILE__), (std::size_t)__LINE__,false)/**/#define BOOST_REQUIRE_MESSAGE(predicate, message_) \ boost::test_tools::tt_detail::test_and_throw_impl((predicate), \ boost::wrap_stringstream().ref() << message_, BOOST_TEST_STRING_LITERAL(__FILE__), (std::size_t)__LINE__,false)/**/#define BOOST_CHECK_PREDICATE( predicate, arg_list_size, arg_list ) \ boost::test_tools::tt_detail::test_and_continue_impl(predicate, BOOST_PLACE_PREDICATE_ARGS ## arg_list_size arg_list, \ boost::wrap_stringstream().ref() << #predicate << "("\ << BOOST_PRINT_PREDICATE_ARGS ## arg_list_size arg_list << ")", BOOST_TEST_STRING_LITERAL(__FILE__), (std::size_t)__LINE__)/**/#define BOOST_REQUIRE_PREDICATE( predicate, arg_list_size, arg_list ) \ boost::test_tools::tt_detail::test_and_throw_impl(predicate, BOOST_PLACE_PREDICATE_ARGS ## arg_list_size arg_list, \ boost::wrap_stringstream().ref() << #predicate << "("\ << BOOST_PRINT_PREDICATE_ARGS ## arg_list_size arg_list << ")", BOOST_TEST_STRING_LITERAL(__FILE__), (std::size_t)__LINE__)/**/#define BOOST_ERROR(message_) BOOST_CHECK_MESSAGE( false, message_ )#define BOOST_FAIL(message_) BOOST_REQUIRE_MESSAGE( false, message_ )#define BOOST_CHECK_THROW( statement, exception ) \ try { statement; BOOST_ERROR( "exception "#exception" is expected" ); } \ catch( exception const& ) { \ BOOST_CHECK_MESSAGE( true, "exception "#exception" is caught" ); \ } \/**/#define BOOST_CHECK_EXCEPTION( statement, exception, predicate ) \ try { statement; BOOST_ERROR( "exception "#exception" is expected" ); } \ catch( exception const& ex ) { \ BOOST_CHECK_MESSAGE( predicate( ex ), "incorrect exception "#exception" is caught" ); \ } \/**/#define BOOST_IGNORE_CHECK( e ) true#define BOOST_CHECK_NO_THROW( statement ) \ try { statement; BOOST_CHECK_MESSAGE( true, "no exceptions was thrown by "#statement ); } \ catch( ... ) { \ BOOST_ERROR( "exception was thrown by "#statement ); \ }/**/#define BOOST_CHECK_EQUAL_COLLECTIONS( left_begin_, left_end_, right_begin_ ) \ boost::test_tools::tt_detail::equal_and_continue_impl( (left_begin_), (left_end_), (right_begin_),\ boost::wrap_stringstream().ref() << \ "{" #left_begin_ ", " #left_end_ "}" " == {" #right_begin_ ", ...}", BOOST_TEST_STRING_LITERAL(__FILE__), (std::size_t)__LINE__)/**/#define BOOST_IS_DEFINED(symb) boost::test_tools::tt_detail::is_defined_impl( #symb, BOOST_STRINGIZE(= symb) )// ***************************** //// helper macros#define BOOST_PLACE_PREDICATE_ARGS1( first_ ) first_#define BOOST_PLACE_PREDICATE_ARGS2( first_, second_ ) first_, second_#define BOOST_PRINT_PREDICATE_ARGS1( first_ ) #first_#define BOOST_PRINT_PREDICATE_ARGS2( first_, second_ ) #first_ << ", " << #second_// ***************************** //// depricated interface#define BOOST_TEST(predicate) BOOST_CHECK(predicate)#define BOOST_CRITICAL_TEST(predicate) BOOST_REQUIRE(predicate)#define BOOST_CRITICAL_ERROR(message_) BOOST_FAIL(message_)namespace boost {namespace test_tools {typedef boost::unit_test::const_string const_string;// ************************************************************************** //// ************** extended_predicate_value ************** //// ************************************************************************** //class extended_predicate_value {public: // Constructor extended_predicate_value( bool predicate_value_ ) : p_predicate_value( predicate_value_ ), p_message( new wrap_stringstream ) {} extended_predicate_value( extended_predicate_value const& rhs ) : p_predicate_value( rhs.p_predicate_value ), p_message( rhs.p_message ) {} bool operator!() const { return !p_predicate_value; } void operator=( bool predicate_value_ ) { p_predicate_value.value = predicate_value_; } BOOST_READONLY_PROPERTY( bool, (extended_predicate_value) ) p_predicate_value; boost::shared_ptr<wrap_stringstream> p_message;};namespace tt_detail {// ************************************************************************** //// ************** test_tool_failed ************** //// ************************************************************************** //// exception used to implement critical checksstruct test_tool_failed : public std::exception {};// ************************************************************************** //// ************** log print helper ************** //// ************************************************************************** //template<typename T>struct print_log_value { void operator()( std::ostream& ostr, T const& t ) { ostr << t; // by default print the value }};//____________________________________________________________________________//template<>struct print_log_value<char> { void operator()( std::ostream& ostr, char t );};//____________________________________________________________________________//template<>struct print_log_value<unsigned char> { void operator()( std::ostream& ostr, unsigned char t );};//____________________________________________________________________________//#define BOOST_TEST_DONT_PRINT_LOG_VALUE( the_type ) \namespace boost { namespace test_tools { namespace tt_detail { \template<> \struct print_log_value<the_type > { \ void operator()( std::ostream& ostr, the_type const& t ) {} \}; \}}} \/**///____________________________________________________________________________//template<typename T>struct print_helper { explicit print_helper( T const& t ) : m_t( t ) {} T const& m_t;};//____________________________________________________________________________//template<typename T>inline std::ostream& operator<<( std::ostream& ostr, print_helper<T> const& ph ){ print_log_value<T>()( ostr, ph.m_t ); return ostr;}//____________________________________________________________________________//// ************************************************************************** //// ************** TOOL BOX Implementation ************** //// ************************************************************************** //voidcheckpoint_impl( wrap_stringstream& message_, const_string file_name_, std::size_t line_num_ );//____________________________________________________________________________//voidmessage_impl( wrap_stringstream& message_, const_string file_name_, std::size_t line_num_ );//____________________________________________________________________________//// ************************************* //voidwarn_and_continue_impl( bool predicate_, wrap_stringstream& message_, const_string file_name_, std::size_t line_num_, bool add_fail_pass_ = true );//____________________________________________________________________________//voidwarn_and_continue_impl( extended_predicate_value const& v_, wrap_stringstream& message_, const_string file_name_, std::size_t line_num_, bool add_fail_pass_ = true );//____________________________________________________________________________//// ************************************* //bool // return true if error detectedtest_and_continue_impl( bool predicate_, wrap_stringstream& message_, const_string file_name_, std::size_t line_num_, bool add_fail_pass_ = true, unit_test::log_level log_level_ = unit_test::log_all_errors );voidtest_and_throw_impl ( bool predicate_, wrap_stringstream& message_, const_string file_name_, std::size_t line_num_, bool add_fail_pass_ = true, unit_test::log_level log_level_ = unit_test::log_fatal_errors );//____________________________________________________________________________//booltest_and_continue_impl( extended_predicate_value const& v_, wrap_stringstream& message_, const_string file_name_, std::size_t line_num_, bool add_fail_pass_ = true, unit_test::log_level log_level_ = unit_test::log_all_errors );//____________________________________________________________________________//// Borland bug workaround
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -