📄 test_tools.hpp
字号:
#if BOOST_WORKAROUND(__BORLANDC__, <= 0x570)inline booltest_and_continue_impl( void* ptr, 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 ){ return test_and_continue_impl( !!ptr, message_, file_name_, line_num_, add_fail_pass_, log_level_ );}#endif//____________________________________________________________________________//voidtest_and_throw_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_fatal_errors );//____________________________________________________________________________//template<typename ArgType, typename Predicate>inline booltest_and_continue_impl( Predicate const& pred_, ArgType const& arg_, wrap_stringstream& message_, const_string file_name_, std::size_t line_num_, unit_test::log_level log_level_ = unit_test::log_all_errors ){ extended_predicate_value predicate( pred_( arg_ ) ); if( !predicate ) { return test_and_continue_impl( predicate, wrap_stringstream().ref() << "test " << message_ << " failed for " << print_helper<ArgType>( arg_ ), file_name_, line_num_, false, log_level_ ); } return test_and_continue_impl( predicate, message_, file_name_, line_num_, true, log_level_ );}//____________________________________________________________________________//template<typename ArgType, typename Predicate>inline voidtest_and_throw_impl ( Predicate const& pred_, ArgType const& arg_, wrap_stringstream& message_, const_string file_name_, std::size_t line_num_, unit_test::log_level log_level_ = unit_test::log_fatal_errors ){ if( test_and_continue_impl( arg_, pred_, message_, file_name_, line_num_, log_level_ ) ) { throw test_tool_failed(); // error already reported by test_and_continue_impl }}//____________________________________________________________________________//template<typename First, typename Second, typename Predicate>inline booltest_and_continue_impl( Predicate const& pred_, First const& first_, Second const& second_, wrap_stringstream& message_, const_string file_name_, std::size_t line_num_, unit_test::log_level log_level_ = unit_test::log_all_errors ){ extended_predicate_value predicate( pred_( first_, second_ ) ); if( !predicate ) { return test_and_continue_impl( predicate, wrap_stringstream().ref() << "test " << message_ << " failed for (" << print_helper<First>( first_ ) << ", " << print_helper<Second>( second_ ) << ")", file_name_, line_num_, false, log_level_ ); } return test_and_continue_impl( predicate, message_, file_name_, line_num_, true, log_level_ );}//____________________________________________________________________________//template<typename First, typename Second, typename Predicate>inline voidtest_and_throw_impl( First const& first_, Second const& second_, Predicate const& pred_, wrap_stringstream& message_, const_string file_name_, std::size_t line_num_, unit_test::log_level log_level_ = unit_test::log_fatal_errors ){ if( test_and_continue_impl( first_, second_, pred_, message_, file_name_, line_num_, log_level_ ) ) { throw test_tool_failed(); // error already reported by test_and_continue_impl }}//____________________________________________________________________________//// ************************************* //boolequal_and_continue_impl( char const* left_, char const* right_, wrap_stringstream& message_, const_string file_name_, std::size_t line_num_, unit_test::log_level log_level_ = unit_test::log_all_errors );//____________________________________________________________________________//#if !defined( BOOST_NO_CWCHAR )boolequal_and_continue_impl( wchar_t const* left_, wchar_t const* right_, wrap_stringstream& message_, const_string file_name_, std::size_t line_num_, unit_test::log_level log_level_ = unit_test::log_all_errors );#endif // !defined( BOOST_NO_CWCHAR )//____________________________________________________________________________//template <class Left, class Right>inline boolequal_and_continue_impl( Left const& left_, Right const& right_, wrap_stringstream& message_, const_string file_name_, std::size_t line_num_, unit_test::log_level log_level_ = unit_test::log_all_errors, std::size_t pos = (std::size_t)-1 ){ extended_predicate_value predicate( left_ == right_ ); if( !predicate ) { wrap_stringstream error_message; error_message.ref() << "test " << message_ << " failed"; if( pos != (std::size_t)-1 ) error_message.ref() << " in a position " << pos; error_message.ref() << " [" << print_helper<Left>( left_ ) << " != " << print_helper<Right>( right_ ) << "]"; return test_and_continue_impl( predicate, error_message, file_name_, line_num_, false, log_level_ ); } return test_and_continue_impl( predicate, wrap_stringstream().ref() << message_, file_name_, line_num_, true, log_level_ ); //----------------------------------------------^ this is added to prevent message_ corruption when reused by collection comparison}//____________________________________________________________________________//template <class Left, class Right>inline voidequal_and_continue_impl( Left left_begin_, Left left_end_, Right right_begin_, wrap_stringstream& message_, const_string file_name_, std::size_t line_num_, unit_test::log_level log_level_ = unit_test::log_all_errors ){ std::size_t pos = 0; for( ; left_begin_ != left_end_; ++left_begin_, ++right_begin_, ++pos ) equal_and_continue_impl( *left_begin_, *right_begin_, message_, file_name_, line_num_, log_level_, pos );}//____________________________________________________________________________//// ************************************* //template<typename FPT, typename PersentType>inline boolcompare_and_continue_impl( FPT left_, FPT right_, PersentType tolerance_, const_string left_text_, const_string right_text_, const_string file_name_, std::size_t line_num_, unit_test::log_level log_level_ = unit_test::log_all_errors ){ extended_predicate_value predicate( check_is_close( left_, right_, tolerance_ ) ); if( !predicate ) { return test_and_continue_impl( predicate, wrap_stringstream().ref() << "difference between " << left_text_ << "{" << print_helper<FPT>( left_ ) << "}" << " and " << right_text_ << "{" << print_helper<FPT>( right_ ) << "}" << " exceeds " << print_helper<PersentType>( tolerance_ ) << "%", file_name_, line_num_, false, log_level_ ); } return test_and_continue_impl( predicate, wrap_stringstream().ref() << "difference between " << left_text_ << "{" << print_helper<FPT>( left_ ) << "}" << " and " << right_text_ << "{" << print_helper<FPT>( right_ ) << "}" << " does not exceeds " << print_helper<PersentType>( tolerance_ ) << "%", file_name_, line_num_, true, log_level_ );}//____________________________________________________________________________//template <class Left, class Right>inline voidbitwise_equal_and_continue_impl( Left const& left_, Right const& right_, wrap_stringstream& message_, const_string file_name_, std::size_t line_num_, unit_test::log_level log_level_ = unit_test::log_all_errors ){ std::size_t left_bit_size = sizeof(Left)*CHAR_BIT; std::size_t right_bit_size = sizeof(Right)*CHAR_BIT; static Left const L1( 1 ); static Right const R1( 1 ); if( left_bit_size != right_bit_size ) warn_and_continue_impl( false, wrap_stringstream().ref() << message_ << ": operands bit sizes does not coinside", file_name_, line_num_, false ); std::size_t total_bits = left_bit_size < right_bit_size ? left_bit_size : right_bit_size; for( std::size_t counter = 0; counter < total_bits; ++counter ) { bool predicate = ( left_ & ( L1 << counter ) ) == ( right_ & ( R1 << counter ) ); test_and_continue_impl( predicate, wrap_stringstream().ref() << message_.str() << " in the position " << counter, file_name_, line_num_, true, log_level_ ); }}//____________________________________________________________________________//// ************************************* //boolis_defined_impl( const_string symbol_name_, const_string symbol_value_ );//____________________________________________________________________________//} // namespace tt_detail// ************************************************************************** //// ************** output_test_stream ************** //// ************************************************************************** //// class to be used to simplify testing of ostream print functionsclass output_test_stream : public #ifdef BOOST_NO_STRINGSTREAM std::ostrstream#else std::ostringstream#endif // BOOST_NO_STRINGSTREAM{ typedef extended_predicate_value result_type;public: // Constructor explicit output_test_stream( const_string pattern_file_name = const_string(), bool match_or_save = true ); // Destructor ~output_test_stream(); // checking function result_type is_empty( bool flush_stream_ = true ); result_type check_length( std::size_t length_, bool flush_stream_ = true ); result_type is_equal( const_string arg_, bool flush_stream_ = true ); result_type match_pattern( bool flush_stream_ = true ); // helper function void flush(); std::size_t length();private: void sync(); struct Impl; boost::shared_ptr<Impl> m_pimpl;};} // namespace test_toolsnamespace test_toolbox = test_tools;} // namespace boost#include <boost/test/detail/enable_warnings.hpp>// ***************************************************************************// Revision History ://// $Log: test_tools.hpp,v $// Revision 1.1.1.2 2004/11/20 10:52:16 spion// Import of Boost v. 1.32.0//// Revision 1.45 2004/07/25 08:31:10 rogeeff// don't use wchar if BOOST_NO_CWCHAR is defined//// Revision 1.44 2004/07/19 12:15:45 rogeeff// guard rename// warning suppress reworked//// Revision 1.43 2004/06/07 07:33:49 rogeeff// detail namespace renamed//// Revision 1.42 2004/06/05 10:59:58 rogeeff// proper IBM VA port//// Revision 1.41 2004/06/03 10:38:31 tknapen// port to vacpp version 6//// Revision 1.40 2004/05/27 06:36:26 rogeeff// eliminate c_string_literal typedef//// Revision 1.39 2004/05/27 06:20:53 rogeeff// wide C string comparison support added//// Revision 1.38 2004/05/21 06:19:35 rogeeff// licence update//// Revision 1.37 2004/05/11 11:00:35 rogeeff// basic_cstring introduced and used everywhere// class properties reworked//// Revision 1.36 2004/01/05 11:56:25 johnmaddock// Borland specific workaround needs to be inline to prevent linker errors, and is unneeded for version 6 of the compiler.//// Revision 1.35 2003/12/01 00:41:56 rogeeff// prerelease cleaning//// ***************************************************************************#endif // BOOST_TEST_TOOLS_HPP_071894GER
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -