sl@0: // (C) Copyright Gennadiy Rozental 2001-2005. sl@0: // Distributed under the Boost Software License, Version 1.0. sl@0: // (See accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: sl@0: // See http://www.boost.org/libs/test for the library home page. sl@0: // sl@0: // File : $RCSfile: parameterized_test.hpp,v $ sl@0: // sl@0: // Version : $Revision: 1.7.2.1 $ sl@0: // sl@0: // Description : generators and helper macros for parameterized tests sl@0: // *************************************************************************** sl@0: sl@0: #ifndef BOOST_TEST_PARAMETERIZED_TEST_HPP_021102GER sl@0: #define BOOST_TEST_PARAMETERIZED_TEST_HPP_021102GER sl@0: sl@0: // Boost.Test sl@0: #include sl@0: #include sl@0: sl@0: // Boost sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_PARAM_TEST_CASE( function, begin, end ) \ sl@0: boost::unit_test::make_test_case( function, \ sl@0: BOOST_TEST_STRINGIZE( function ), \ sl@0: (begin), (end) ) \ sl@0: /**/ sl@0: sl@0: #define BOOST_PARAM_CLASS_TEST_CASE( function, tc_instance, begin, end ) \ sl@0: boost::unit_test::make_test_case( function, \ sl@0: BOOST_TEST_STRINGIZE( function ), \ sl@0: (tc_instance), \ sl@0: (begin), (end) ) \ sl@0: /**/ sl@0: sl@0: namespace boost { sl@0: sl@0: namespace unit_test { sl@0: sl@0: // ************************************************************************** // sl@0: // ************** test_func_with_bound_param ************** // sl@0: // ************************************************************************** // sl@0: sl@0: namespace ut_detail { sl@0: sl@0: template sl@0: struct test_func_with_bound_param { sl@0: template sl@0: test_func_with_bound_param( callback1 test_func, T const& param ) sl@0: : m_test_func( test_func ) sl@0: , m_param( param ) sl@0: {} sl@0: sl@0: void operator()() { m_test_func( m_param ); } sl@0: sl@0: private: sl@0: callback1 m_test_func; sl@0: ParamType m_param; sl@0: }; sl@0: sl@0: // ************************************************************************** // sl@0: // ************** param_test_case_generator ************** // sl@0: // ************************************************************************** // sl@0: sl@0: template sl@0: class param_test_case_generator : public test_unit_generator { sl@0: public: sl@0: param_test_case_generator( callback1 const& test_func, sl@0: const_string tc_name, sl@0: ParamIter par_begin, sl@0: ParamIter par_end ) sl@0: : m_test_func( test_func ) sl@0: , m_tc_name( ut_detail::normalize_test_case_name( tc_name ) ) sl@0: , m_par_begin( par_begin ) sl@0: , m_par_end( par_end ) sl@0: {} sl@0: sl@0: test_unit* next() const sl@0: { sl@0: if( m_par_begin == m_par_end ) sl@0: return (test_unit*)0; sl@0: sl@0: test_func_with_bound_param bound_test_func( m_test_func, *m_par_begin ); sl@0: ::boost::unit_test::test_unit* res = new test_case( m_tc_name, bound_test_func ); sl@0: sl@0: ++m_par_begin; sl@0: sl@0: return res; sl@0: } sl@0: sl@0: private: sl@0: // Data members sl@0: callback1 m_test_func; sl@0: std::string m_tc_name; sl@0: mutable ParamIter m_par_begin; sl@0: ParamIter m_par_end; sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template sl@0: struct user_param_tc_method_invoker { sl@0: typedef void (UserTestCase::*test_method)( ParamType ); sl@0: sl@0: // Constructor sl@0: user_param_tc_method_invoker( shared_ptr inst, test_method test_method ) sl@0: : m_inst( inst ), m_test_method( test_method ) {} sl@0: sl@0: void operator()( ParamType p ) { ((*m_inst).*m_test_method)( p ); } sl@0: sl@0: // Data members sl@0: shared_ptr m_inst; sl@0: test_method m_test_method; sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: } // namespace ut_detail sl@0: sl@0: template sl@0: inline ut_detail::param_test_case_generator sl@0: make_test_case( callback1 const& test_func, sl@0: const_string tc_name, sl@0: ParamIter par_begin, sl@0: ParamIter par_end ) sl@0: { sl@0: return ut_detail::param_test_case_generator( test_func, tc_name, par_begin, par_end ); sl@0: } sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template sl@0: inline ut_detail::param_test_case_generator< sl@0: BOOST_DEDUCED_TYPENAME remove_const::type>::type,ParamIter> sl@0: make_test_case( void (*test_func)( ParamType ), sl@0: const_string tc_name, sl@0: ParamIter par_begin, sl@0: ParamIter par_end ) sl@0: { sl@0: typedef BOOST_DEDUCED_TYPENAME remove_const::type>::type param_value_type; sl@0: return ut_detail::param_test_case_generator( test_func, tc_name, par_begin, par_end ); sl@0: } sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template sl@0: inline ut_detail::param_test_case_generator< sl@0: BOOST_DEDUCED_TYPENAME remove_const::type>::type,ParamIter> sl@0: make_test_case( void (UserTestCase::*test_method )( ParamType ), sl@0: const_string tc_name, sl@0: boost::shared_ptr const& user_test_case, sl@0: ParamIter par_begin, sl@0: ParamIter par_end ) sl@0: { sl@0: typedef BOOST_DEDUCED_TYPENAME remove_const::type>::type param_value_type; sl@0: return ut_detail::param_test_case_generator( sl@0: ut_detail::user_param_tc_method_invoker( user_test_case, test_method ), sl@0: tc_name, sl@0: par_begin, sl@0: par_end ); sl@0: } sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: } // unit_test sl@0: sl@0: } // namespace boost sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #include sl@0: sl@0: // *************************************************************************** sl@0: // Revision History : sl@0: // sl@0: // $Log: parameterized_test.hpp,v $ sl@0: // Revision 1.7.2.1 2006/10/19 09:23:04 johnmaddock sl@0: // Fix for VC6. sl@0: // sl@0: // Revision 1.7 2006/01/28 08:57:02 rogeeff sl@0: // VC6.0 workaround removed sl@0: // sl@0: // Revision 1.6 2006/01/28 07:10:20 rogeeff sl@0: // tm->test_method sl@0: // sl@0: // Revision 1.5 2005/12/14 05:16:49 rogeeff sl@0: // dll support introduced sl@0: // sl@0: // Revision 1.4 2005/05/02 06:00:10 rogeeff sl@0: // restore a parameterized user case method based testing sl@0: // sl@0: // Revision 1.3 2005/03/21 15:32:31 rogeeff sl@0: // check reworked sl@0: // sl@0: // Revision 1.2 2005/02/21 10:25:04 rogeeff sl@0: // remove const during ParamType deduction sl@0: // sl@0: // Revision 1.1 2005/02/20 08:27:06 rogeeff sl@0: // This a major update for Boost.Test framework. See release docs for complete list of fixes/updates sl@0: // sl@0: // *************************************************************************** sl@0: sl@0: #endif // BOOST_TEST_PARAMETERIZED_TEST_HPP_021102GER sl@0: