sl@0
|
1 |
// (C) Copyright Gennadiy Rozental 2001-2005.
|
sl@0
|
2 |
// Distributed under the Boost Software License, Version 1.0.
|
sl@0
|
3 |
// (See accompanying file LICENSE_1_0.txt or copy at
|
sl@0
|
4 |
// http://www.boost.org/LICENSE_1_0.txt)
|
sl@0
|
5 |
|
sl@0
|
6 |
// See http://www.boost.org/libs/test for the library home page.
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// File : $RCSfile: parameterized_test.hpp,v $
|
sl@0
|
9 |
//
|
sl@0
|
10 |
// Version : $Revision: 1.7.2.1 $
|
sl@0
|
11 |
//
|
sl@0
|
12 |
// Description : generators and helper macros for parameterized tests
|
sl@0
|
13 |
// ***************************************************************************
|
sl@0
|
14 |
|
sl@0
|
15 |
#ifndef BOOST_TEST_PARAMETERIZED_TEST_HPP_021102GER
|
sl@0
|
16 |
#define BOOST_TEST_PARAMETERIZED_TEST_HPP_021102GER
|
sl@0
|
17 |
|
sl@0
|
18 |
// Boost.Test
|
sl@0
|
19 |
#include <boost/test/unit_test_suite.hpp>
|
sl@0
|
20 |
#include <boost/test/utils/callback.hpp>
|
sl@0
|
21 |
|
sl@0
|
22 |
// Boost
|
sl@0
|
23 |
#include <boost/type_traits/remove_reference.hpp>
|
sl@0
|
24 |
#include <boost/type_traits/remove_const.hpp>
|
sl@0
|
25 |
|
sl@0
|
26 |
#include <boost/test/detail/suppress_warnings.hpp>
|
sl@0
|
27 |
|
sl@0
|
28 |
//____________________________________________________________________________//
|
sl@0
|
29 |
|
sl@0
|
30 |
#define BOOST_PARAM_TEST_CASE( function, begin, end ) \
|
sl@0
|
31 |
boost::unit_test::make_test_case( function, \
|
sl@0
|
32 |
BOOST_TEST_STRINGIZE( function ), \
|
sl@0
|
33 |
(begin), (end) ) \
|
sl@0
|
34 |
/**/
|
sl@0
|
35 |
|
sl@0
|
36 |
#define BOOST_PARAM_CLASS_TEST_CASE( function, tc_instance, begin, end ) \
|
sl@0
|
37 |
boost::unit_test::make_test_case( function, \
|
sl@0
|
38 |
BOOST_TEST_STRINGIZE( function ), \
|
sl@0
|
39 |
(tc_instance), \
|
sl@0
|
40 |
(begin), (end) ) \
|
sl@0
|
41 |
/**/
|
sl@0
|
42 |
|
sl@0
|
43 |
namespace boost {
|
sl@0
|
44 |
|
sl@0
|
45 |
namespace unit_test {
|
sl@0
|
46 |
|
sl@0
|
47 |
// ************************************************************************** //
|
sl@0
|
48 |
// ************** test_func_with_bound_param ************** //
|
sl@0
|
49 |
// ************************************************************************** //
|
sl@0
|
50 |
|
sl@0
|
51 |
namespace ut_detail {
|
sl@0
|
52 |
|
sl@0
|
53 |
template<typename ParamType>
|
sl@0
|
54 |
struct test_func_with_bound_param {
|
sl@0
|
55 |
template<typename T>
|
sl@0
|
56 |
test_func_with_bound_param( callback1<ParamType> test_func, T const& param )
|
sl@0
|
57 |
: m_test_func( test_func )
|
sl@0
|
58 |
, m_param( param )
|
sl@0
|
59 |
{}
|
sl@0
|
60 |
|
sl@0
|
61 |
void operator()() { m_test_func( m_param ); }
|
sl@0
|
62 |
|
sl@0
|
63 |
private:
|
sl@0
|
64 |
callback1<ParamType> m_test_func;
|
sl@0
|
65 |
ParamType m_param;
|
sl@0
|
66 |
};
|
sl@0
|
67 |
|
sl@0
|
68 |
// ************************************************************************** //
|
sl@0
|
69 |
// ************** param_test_case_generator ************** //
|
sl@0
|
70 |
// ************************************************************************** //
|
sl@0
|
71 |
|
sl@0
|
72 |
template<typename ParamType, typename ParamIter>
|
sl@0
|
73 |
class param_test_case_generator : public test_unit_generator {
|
sl@0
|
74 |
public:
|
sl@0
|
75 |
param_test_case_generator( callback1<ParamType> const& test_func,
|
sl@0
|
76 |
const_string tc_name,
|
sl@0
|
77 |
ParamIter par_begin,
|
sl@0
|
78 |
ParamIter par_end )
|
sl@0
|
79 |
: m_test_func( test_func )
|
sl@0
|
80 |
, m_tc_name( ut_detail::normalize_test_case_name( tc_name ) )
|
sl@0
|
81 |
, m_par_begin( par_begin )
|
sl@0
|
82 |
, m_par_end( par_end )
|
sl@0
|
83 |
{}
|
sl@0
|
84 |
|
sl@0
|
85 |
test_unit* next() const
|
sl@0
|
86 |
{
|
sl@0
|
87 |
if( m_par_begin == m_par_end )
|
sl@0
|
88 |
return (test_unit*)0;
|
sl@0
|
89 |
|
sl@0
|
90 |
test_func_with_bound_param<ParamType> bound_test_func( m_test_func, *m_par_begin );
|
sl@0
|
91 |
::boost::unit_test::test_unit* res = new test_case( m_tc_name, bound_test_func );
|
sl@0
|
92 |
|
sl@0
|
93 |
++m_par_begin;
|
sl@0
|
94 |
|
sl@0
|
95 |
return res;
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
private:
|
sl@0
|
99 |
// Data members
|
sl@0
|
100 |
callback1<ParamType> m_test_func;
|
sl@0
|
101 |
std::string m_tc_name;
|
sl@0
|
102 |
mutable ParamIter m_par_begin;
|
sl@0
|
103 |
ParamIter m_par_end;
|
sl@0
|
104 |
};
|
sl@0
|
105 |
|
sl@0
|
106 |
//____________________________________________________________________________//
|
sl@0
|
107 |
|
sl@0
|
108 |
template<typename UserTestCase,typename ParamType>
|
sl@0
|
109 |
struct user_param_tc_method_invoker {
|
sl@0
|
110 |
typedef void (UserTestCase::*test_method)( ParamType );
|
sl@0
|
111 |
|
sl@0
|
112 |
// Constructor
|
sl@0
|
113 |
user_param_tc_method_invoker( shared_ptr<UserTestCase> inst, test_method test_method )
|
sl@0
|
114 |
: m_inst( inst ), m_test_method( test_method ) {}
|
sl@0
|
115 |
|
sl@0
|
116 |
void operator()( ParamType p ) { ((*m_inst).*m_test_method)( p ); }
|
sl@0
|
117 |
|
sl@0
|
118 |
// Data members
|
sl@0
|
119 |
shared_ptr<UserTestCase> m_inst;
|
sl@0
|
120 |
test_method m_test_method;
|
sl@0
|
121 |
};
|
sl@0
|
122 |
|
sl@0
|
123 |
//____________________________________________________________________________//
|
sl@0
|
124 |
|
sl@0
|
125 |
} // namespace ut_detail
|
sl@0
|
126 |
|
sl@0
|
127 |
template<typename ParamType, typename ParamIter>
|
sl@0
|
128 |
inline ut_detail::param_test_case_generator<ParamType,ParamIter>
|
sl@0
|
129 |
make_test_case( callback1<ParamType> const& test_func,
|
sl@0
|
130 |
const_string tc_name,
|
sl@0
|
131 |
ParamIter par_begin,
|
sl@0
|
132 |
ParamIter par_end )
|
sl@0
|
133 |
{
|
sl@0
|
134 |
return ut_detail::param_test_case_generator<ParamType,ParamIter>( test_func, tc_name, par_begin, par_end );
|
sl@0
|
135 |
}
|
sl@0
|
136 |
|
sl@0
|
137 |
//____________________________________________________________________________//
|
sl@0
|
138 |
|
sl@0
|
139 |
template<typename ParamType, typename ParamIter>
|
sl@0
|
140 |
inline ut_detail::param_test_case_generator<
|
sl@0
|
141 |
BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type,ParamIter>
|
sl@0
|
142 |
make_test_case( void (*test_func)( ParamType ),
|
sl@0
|
143 |
const_string tc_name,
|
sl@0
|
144 |
ParamIter par_begin,
|
sl@0
|
145 |
ParamIter par_end )
|
sl@0
|
146 |
{
|
sl@0
|
147 |
typedef BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type param_value_type;
|
sl@0
|
148 |
return ut_detail::param_test_case_generator<param_value_type,ParamIter>( test_func, tc_name, par_begin, par_end );
|
sl@0
|
149 |
}
|
sl@0
|
150 |
|
sl@0
|
151 |
//____________________________________________________________________________//
|
sl@0
|
152 |
|
sl@0
|
153 |
template<typename UserTestCase,typename ParamType, typename ParamIter>
|
sl@0
|
154 |
inline ut_detail::param_test_case_generator<
|
sl@0
|
155 |
BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type,ParamIter>
|
sl@0
|
156 |
make_test_case( void (UserTestCase::*test_method )( ParamType ),
|
sl@0
|
157 |
const_string tc_name,
|
sl@0
|
158 |
boost::shared_ptr<UserTestCase> const& user_test_case,
|
sl@0
|
159 |
ParamIter par_begin,
|
sl@0
|
160 |
ParamIter par_end )
|
sl@0
|
161 |
{
|
sl@0
|
162 |
typedef BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type param_value_type;
|
sl@0
|
163 |
return ut_detail::param_test_case_generator<param_value_type,ParamIter>(
|
sl@0
|
164 |
ut_detail::user_param_tc_method_invoker<UserTestCase,ParamType>( user_test_case, test_method ),
|
sl@0
|
165 |
tc_name,
|
sl@0
|
166 |
par_begin,
|
sl@0
|
167 |
par_end );
|
sl@0
|
168 |
}
|
sl@0
|
169 |
|
sl@0
|
170 |
//____________________________________________________________________________//
|
sl@0
|
171 |
|
sl@0
|
172 |
} // unit_test
|
sl@0
|
173 |
|
sl@0
|
174 |
} // namespace boost
|
sl@0
|
175 |
|
sl@0
|
176 |
//____________________________________________________________________________//
|
sl@0
|
177 |
|
sl@0
|
178 |
#include <boost/test/detail/enable_warnings.hpp>
|
sl@0
|
179 |
|
sl@0
|
180 |
// ***************************************************************************
|
sl@0
|
181 |
// Revision History :
|
sl@0
|
182 |
//
|
sl@0
|
183 |
// $Log: parameterized_test.hpp,v $
|
sl@0
|
184 |
// Revision 1.7.2.1 2006/10/19 09:23:04 johnmaddock
|
sl@0
|
185 |
// Fix for VC6.
|
sl@0
|
186 |
//
|
sl@0
|
187 |
// Revision 1.7 2006/01/28 08:57:02 rogeeff
|
sl@0
|
188 |
// VC6.0 workaround removed
|
sl@0
|
189 |
//
|
sl@0
|
190 |
// Revision 1.6 2006/01/28 07:10:20 rogeeff
|
sl@0
|
191 |
// tm->test_method
|
sl@0
|
192 |
//
|
sl@0
|
193 |
// Revision 1.5 2005/12/14 05:16:49 rogeeff
|
sl@0
|
194 |
// dll support introduced
|
sl@0
|
195 |
//
|
sl@0
|
196 |
// Revision 1.4 2005/05/02 06:00:10 rogeeff
|
sl@0
|
197 |
// restore a parameterized user case method based testing
|
sl@0
|
198 |
//
|
sl@0
|
199 |
// Revision 1.3 2005/03/21 15:32:31 rogeeff
|
sl@0
|
200 |
// check reworked
|
sl@0
|
201 |
//
|
sl@0
|
202 |
// Revision 1.2 2005/02/21 10:25:04 rogeeff
|
sl@0
|
203 |
// remove const during ParamType deduction
|
sl@0
|
204 |
//
|
sl@0
|
205 |
// Revision 1.1 2005/02/20 08:27:06 rogeeff
|
sl@0
|
206 |
// This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
|
sl@0
|
207 |
//
|
sl@0
|
208 |
// ***************************************************************************
|
sl@0
|
209 |
|
sl@0
|
210 |
#endif // BOOST_TEST_PARAMETERIZED_TEST_HPP_021102GER
|
sl@0
|
211 |
|