1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/test/parameterized_test.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,211 @@
1.4 +// (C) Copyright Gennadiy Rozental 2001-2005.
1.5 +// Distributed under the Boost Software License, Version 1.0.
1.6 +// (See accompanying file LICENSE_1_0.txt or copy at
1.7 +// http://www.boost.org/LICENSE_1_0.txt)
1.8 +
1.9 +// See http://www.boost.org/libs/test for the library home page.
1.10 +//
1.11 +// File : $RCSfile: parameterized_test.hpp,v $
1.12 +//
1.13 +// Version : $Revision: 1.7.2.1 $
1.14 +//
1.15 +// Description : generators and helper macros for parameterized tests
1.16 +// ***************************************************************************
1.17 +
1.18 +#ifndef BOOST_TEST_PARAMETERIZED_TEST_HPP_021102GER
1.19 +#define BOOST_TEST_PARAMETERIZED_TEST_HPP_021102GER
1.20 +
1.21 +// Boost.Test
1.22 +#include <boost/test/unit_test_suite.hpp>
1.23 +#include <boost/test/utils/callback.hpp>
1.24 +
1.25 +// Boost
1.26 +#include <boost/type_traits/remove_reference.hpp>
1.27 +#include <boost/type_traits/remove_const.hpp>
1.28 +
1.29 +#include <boost/test/detail/suppress_warnings.hpp>
1.30 +
1.31 +//____________________________________________________________________________//
1.32 +
1.33 +#define BOOST_PARAM_TEST_CASE( function, begin, end ) \
1.34 +boost::unit_test::make_test_case( function, \
1.35 + BOOST_TEST_STRINGIZE( function ), \
1.36 + (begin), (end) ) \
1.37 +/**/
1.38 +
1.39 +#define BOOST_PARAM_CLASS_TEST_CASE( function, tc_instance, begin, end ) \
1.40 +boost::unit_test::make_test_case( function, \
1.41 + BOOST_TEST_STRINGIZE( function ), \
1.42 + (tc_instance), \
1.43 + (begin), (end) ) \
1.44 +/**/
1.45 +
1.46 +namespace boost {
1.47 +
1.48 +namespace unit_test {
1.49 +
1.50 +// ************************************************************************** //
1.51 +// ************** test_func_with_bound_param ************** //
1.52 +// ************************************************************************** //
1.53 +
1.54 +namespace ut_detail {
1.55 +
1.56 +template<typename ParamType>
1.57 +struct test_func_with_bound_param {
1.58 + template<typename T>
1.59 + test_func_with_bound_param( callback1<ParamType> test_func, T const& param )
1.60 + : m_test_func( test_func )
1.61 + , m_param( param )
1.62 + {}
1.63 +
1.64 + void operator()() { m_test_func( m_param ); }
1.65 +
1.66 +private:
1.67 + callback1<ParamType> m_test_func;
1.68 + ParamType m_param;
1.69 +};
1.70 +
1.71 +// ************************************************************************** //
1.72 +// ************** param_test_case_generator ************** //
1.73 +// ************************************************************************** //
1.74 +
1.75 +template<typename ParamType, typename ParamIter>
1.76 +class param_test_case_generator : public test_unit_generator {
1.77 +public:
1.78 + param_test_case_generator( callback1<ParamType> const& test_func,
1.79 + const_string tc_name,
1.80 + ParamIter par_begin,
1.81 + ParamIter par_end )
1.82 + : m_test_func( test_func )
1.83 + , m_tc_name( ut_detail::normalize_test_case_name( tc_name ) )
1.84 + , m_par_begin( par_begin )
1.85 + , m_par_end( par_end )
1.86 + {}
1.87 +
1.88 + test_unit* next() const
1.89 + {
1.90 + if( m_par_begin == m_par_end )
1.91 + return (test_unit*)0;
1.92 +
1.93 + test_func_with_bound_param<ParamType> bound_test_func( m_test_func, *m_par_begin );
1.94 + ::boost::unit_test::test_unit* res = new test_case( m_tc_name, bound_test_func );
1.95 +
1.96 + ++m_par_begin;
1.97 +
1.98 + return res;
1.99 + }
1.100 +
1.101 +private:
1.102 + // Data members
1.103 + callback1<ParamType> m_test_func;
1.104 + std::string m_tc_name;
1.105 + mutable ParamIter m_par_begin;
1.106 + ParamIter m_par_end;
1.107 +};
1.108 +
1.109 +//____________________________________________________________________________//
1.110 +
1.111 +template<typename UserTestCase,typename ParamType>
1.112 +struct user_param_tc_method_invoker {
1.113 + typedef void (UserTestCase::*test_method)( ParamType );
1.114 +
1.115 + // Constructor
1.116 + user_param_tc_method_invoker( shared_ptr<UserTestCase> inst, test_method test_method )
1.117 + : m_inst( inst ), m_test_method( test_method ) {}
1.118 +
1.119 + void operator()( ParamType p ) { ((*m_inst).*m_test_method)( p ); }
1.120 +
1.121 + // Data members
1.122 + shared_ptr<UserTestCase> m_inst;
1.123 + test_method m_test_method;
1.124 +};
1.125 +
1.126 +//____________________________________________________________________________//
1.127 +
1.128 +} // namespace ut_detail
1.129 +
1.130 +template<typename ParamType, typename ParamIter>
1.131 +inline ut_detail::param_test_case_generator<ParamType,ParamIter>
1.132 +make_test_case( callback1<ParamType> const& test_func,
1.133 + const_string tc_name,
1.134 + ParamIter par_begin,
1.135 + ParamIter par_end )
1.136 +{
1.137 + return ut_detail::param_test_case_generator<ParamType,ParamIter>( test_func, tc_name, par_begin, par_end );
1.138 +}
1.139 +
1.140 +//____________________________________________________________________________//
1.141 +
1.142 +template<typename ParamType, typename ParamIter>
1.143 +inline ut_detail::param_test_case_generator<
1.144 + BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type,ParamIter>
1.145 +make_test_case( void (*test_func)( ParamType ),
1.146 + const_string tc_name,
1.147 + ParamIter par_begin,
1.148 + ParamIter par_end )
1.149 +{
1.150 + typedef BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type param_value_type;
1.151 + return ut_detail::param_test_case_generator<param_value_type,ParamIter>( test_func, tc_name, par_begin, par_end );
1.152 +}
1.153 +
1.154 +//____________________________________________________________________________//
1.155 +
1.156 +template<typename UserTestCase,typename ParamType, typename ParamIter>
1.157 +inline ut_detail::param_test_case_generator<
1.158 + BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type,ParamIter>
1.159 +make_test_case( void (UserTestCase::*test_method )( ParamType ),
1.160 + const_string tc_name,
1.161 + boost::shared_ptr<UserTestCase> const& user_test_case,
1.162 + ParamIter par_begin,
1.163 + ParamIter par_end )
1.164 +{
1.165 + typedef BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type param_value_type;
1.166 + return ut_detail::param_test_case_generator<param_value_type,ParamIter>(
1.167 + ut_detail::user_param_tc_method_invoker<UserTestCase,ParamType>( user_test_case, test_method ),
1.168 + tc_name,
1.169 + par_begin,
1.170 + par_end );
1.171 +}
1.172 +
1.173 +//____________________________________________________________________________//
1.174 +
1.175 +} // unit_test
1.176 +
1.177 +} // namespace boost
1.178 +
1.179 +//____________________________________________________________________________//
1.180 +
1.181 +#include <boost/test/detail/enable_warnings.hpp>
1.182 +
1.183 +// ***************************************************************************
1.184 +// Revision History :
1.185 +//
1.186 +// $Log: parameterized_test.hpp,v $
1.187 +// Revision 1.7.2.1 2006/10/19 09:23:04 johnmaddock
1.188 +// Fix for VC6.
1.189 +//
1.190 +// Revision 1.7 2006/01/28 08:57:02 rogeeff
1.191 +// VC6.0 workaround removed
1.192 +//
1.193 +// Revision 1.6 2006/01/28 07:10:20 rogeeff
1.194 +// tm->test_method
1.195 +//
1.196 +// Revision 1.5 2005/12/14 05:16:49 rogeeff
1.197 +// dll support introduced
1.198 +//
1.199 +// Revision 1.4 2005/05/02 06:00:10 rogeeff
1.200 +// restore a parameterized user case method based testing
1.201 +//
1.202 +// Revision 1.3 2005/03/21 15:32:31 rogeeff
1.203 +// check reworked
1.204 +//
1.205 +// Revision 1.2 2005/02/21 10:25:04 rogeeff
1.206 +// remove const during ParamType deduction
1.207 +//
1.208 +// Revision 1.1 2005/02/20 08:27:06 rogeeff
1.209 +// This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
1.210 +//
1.211 +// ***************************************************************************
1.212 +
1.213 +#endif // BOOST_TEST_PARAMETERIZED_TEST_HPP_021102GER
1.214 +