Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/test/parameterized_test.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 // (C) Copyright Gennadiy Rozental 2001-2008. | |
2 // Distributed under the Boost Software License, Version 1.0. | |
3 // (See accompanying file LICENSE_1_0.txt or copy at | |
4 // http://www.boost.org/LICENSE_1_0.txt) | |
5 | |
6 // See http://www.boost.org/libs/test for the library home page. | |
7 // | |
8 // File : $RCSfile$ | |
9 // | |
10 // Version : $Revision: 54633 $ | |
11 // | |
12 // Description : generators and helper macros for parameterized tests | |
13 // *************************************************************************** | |
14 | |
15 #ifndef BOOST_TEST_PARAMETERIZED_TEST_HPP_021102GER | |
16 #define BOOST_TEST_PARAMETERIZED_TEST_HPP_021102GER | |
17 | |
18 // Boost.Test | |
19 #include <boost/test/unit_test_suite.hpp> | |
20 #include <boost/test/utils/callback.hpp> | |
21 | |
22 // Boost | |
23 #include <boost/type_traits/remove_reference.hpp> | |
24 #include <boost/type_traits/remove_const.hpp> | |
25 | |
26 #include <boost/test/detail/suppress_warnings.hpp> | |
27 | |
28 //____________________________________________________________________________// | |
29 | |
30 #define BOOST_PARAM_TEST_CASE( function, begin, end ) \ | |
31 boost::unit_test::make_test_case( function, \ | |
32 BOOST_TEST_STRINGIZE( function ), \ | |
33 (begin), (end) ) \ | |
34 /**/ | |
35 | |
36 #define BOOST_PARAM_CLASS_TEST_CASE( function, tc_instance, begin, end ) \ | |
37 boost::unit_test::make_test_case( function, \ | |
38 BOOST_TEST_STRINGIZE( function ), \ | |
39 (tc_instance), \ | |
40 (begin), (end) ) \ | |
41 /**/ | |
42 | |
43 namespace boost { | |
44 | |
45 namespace unit_test { | |
46 | |
47 // ************************************************************************** // | |
48 // ************** test_func_with_bound_param ************** // | |
49 // ************************************************************************** // | |
50 | |
51 namespace ut_detail { | |
52 | |
53 template<typename ParamType> | |
54 struct test_func_with_bound_param { | |
55 template<typename T> | |
56 test_func_with_bound_param( callback1<ParamType> test_func, T const& param ) | |
57 : m_test_func( test_func ) | |
58 , m_param( param ) | |
59 {} | |
60 | |
61 void operator()() { m_test_func( m_param ); } | |
62 | |
63 private: | |
64 callback1<ParamType> m_test_func; | |
65 ParamType m_param; | |
66 }; | |
67 | |
68 // ************************************************************************** // | |
69 // ************** param_test_case_generator ************** // | |
70 // ************************************************************************** // | |
71 | |
72 template<typename ParamType, typename ParamIter> | |
73 class param_test_case_generator : public test_unit_generator { | |
74 public: | |
75 param_test_case_generator( callback1<ParamType> const& test_func, | |
76 const_string tc_name, | |
77 ParamIter par_begin, | |
78 ParamIter par_end ) | |
79 : m_test_func( test_func ) | |
80 , m_tc_name( ut_detail::normalize_test_case_name( tc_name ) ) | |
81 , m_par_begin( par_begin ) | |
82 , m_par_end( par_end ) | |
83 {} | |
84 | |
85 virtual test_unit* next() const | |
86 { | |
87 if( m_par_begin == m_par_end ) | |
88 return (test_unit*)0; | |
89 | |
90 test_func_with_bound_param<ParamType> bound_test_func( m_test_func, *m_par_begin ); | |
91 test_unit* res = new test_case( m_tc_name, bound_test_func ); | |
92 | |
93 ++m_par_begin; | |
94 | |
95 return res; | |
96 } | |
97 | |
98 private: | |
99 // Data members | |
100 callback1<ParamType> m_test_func; | |
101 std::string m_tc_name; | |
102 mutable ParamIter m_par_begin; | |
103 ParamIter m_par_end; | |
104 }; | |
105 | |
106 //____________________________________________________________________________// | |
107 | |
108 template<typename UserTestCase,typename ParamType> | |
109 struct user_param_tc_method_invoker { | |
110 typedef void (UserTestCase::*test_method)( ParamType ); | |
111 | |
112 // Constructor | |
113 user_param_tc_method_invoker( shared_ptr<UserTestCase> inst, test_method test_method ) | |
114 : m_inst( inst ), m_test_method( test_method ) {} | |
115 | |
116 void operator()( ParamType p ) { ((*m_inst).*m_test_method)( p ); } | |
117 | |
118 // Data members | |
119 shared_ptr<UserTestCase> m_inst; | |
120 test_method m_test_method; | |
121 }; | |
122 | |
123 //____________________________________________________________________________// | |
124 | |
125 } // namespace ut_detail | |
126 | |
127 template<typename ParamType, typename ParamIter> | |
128 inline ut_detail::param_test_case_generator<ParamType,ParamIter> | |
129 make_test_case( callback1<ParamType> const& test_func, | |
130 const_string tc_name, | |
131 ParamIter par_begin, | |
132 ParamIter par_end ) | |
133 { | |
134 return ut_detail::param_test_case_generator<ParamType,ParamIter>( test_func, tc_name, par_begin, par_end ); | |
135 } | |
136 | |
137 //____________________________________________________________________________// | |
138 | |
139 template<typename ParamType, typename ParamIter> | |
140 inline ut_detail::param_test_case_generator< | |
141 BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type,ParamIter> | |
142 make_test_case( void (*test_func)( ParamType ), | |
143 const_string tc_name, | |
144 ParamIter par_begin, | |
145 ParamIter par_end ) | |
146 { | |
147 typedef BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type param_value_type; | |
148 return ut_detail::param_test_case_generator<param_value_type,ParamIter>( test_func, tc_name, par_begin, par_end ); | |
149 } | |
150 | |
151 //____________________________________________________________________________// | |
152 | |
153 template<typename UserTestCase,typename ParamType, typename ParamIter> | |
154 inline ut_detail::param_test_case_generator< | |
155 BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type,ParamIter> | |
156 make_test_case( void (UserTestCase::*test_method )( ParamType ), | |
157 const_string tc_name, | |
158 boost::shared_ptr<UserTestCase> const& user_test_case, | |
159 ParamIter par_begin, | |
160 ParamIter par_end ) | |
161 { | |
162 typedef BOOST_DEDUCED_TYPENAME remove_const<BOOST_DEDUCED_TYPENAME remove_reference<ParamType>::type>::type param_value_type; | |
163 return ut_detail::param_test_case_generator<param_value_type,ParamIter>( | |
164 ut_detail::user_param_tc_method_invoker<UserTestCase,ParamType>( user_test_case, test_method ), | |
165 tc_name, | |
166 par_begin, | |
167 par_end ); | |
168 } | |
169 | |
170 //____________________________________________________________________________// | |
171 | |
172 } // unit_test | |
173 | |
174 } // namespace boost | |
175 | |
176 //____________________________________________________________________________// | |
177 | |
178 #include <boost/test/detail/enable_warnings.hpp> | |
179 | |
180 #endif // BOOST_TEST_PARAMETERIZED_TEST_HPP_021102GER | |
181 |