Chris@16
|
1 // (C) Copyright Gennadiy Rozental 2005-2008.
|
Chris@16
|
2 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
3 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
4 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5
|
Chris@16
|
6 // See http://www.boost.org/libs/test for the library home page.
|
Chris@16
|
7 //
|
Chris@16
|
8 // File : $RCSfile$
|
Chris@16
|
9 //
|
Chris@101
|
10 // Version : $Revision$
|
Chris@16
|
11 //
|
Chris@16
|
12 // Description : Facilities to perform exception safety_tests
|
Chris@16
|
13 // ***************************************************************************
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_TEST_MOCK_OBJECT_HPP_112205GER
|
Chris@16
|
16 #define BOOST_TEST_MOCK_OBJECT_HPP_112205GER
|
Chris@16
|
17
|
Chris@16
|
18 // Boost.Test
|
Chris@16
|
19 #include <boost/test/detail/config.hpp>
|
Chris@16
|
20 #include <boost/test/interaction_based.hpp>
|
Chris@16
|
21
|
Chris@16
|
22 // Boost
|
Chris@16
|
23 #include <boost/preprocessor/punctuation/comma.hpp>
|
Chris@16
|
24
|
Chris@16
|
25 #include <boost/test/detail/suppress_warnings.hpp>
|
Chris@16
|
26
|
Chris@16
|
27 //____________________________________________________________________________//
|
Chris@16
|
28
|
Chris@16
|
29 namespace boost {
|
Chris@16
|
30
|
Chris@16
|
31 namespace itest {
|
Chris@16
|
32
|
Chris@16
|
33 // ************************************************************************** //
|
Chris@16
|
34 // ************** mock_object_base ************** //
|
Chris@16
|
35 // ************************************************************************** //
|
Chris@16
|
36
|
Chris@16
|
37 class mock_object_base {
|
Chris@16
|
38 public:
|
Chris@16
|
39 mock_object_base() {}
|
Chris@16
|
40
|
Chris@16
|
41 template<typename T1>
|
Chris@16
|
42 mock_object_base( T1 const& ) {}
|
Chris@16
|
43
|
Chris@16
|
44 template<typename T1, typename T2>
|
Chris@16
|
45 mock_object_base( T1 const&, T2 const& ) {}
|
Chris@16
|
46
|
Chris@16
|
47 template<typename T1, typename T2, typename T3>
|
Chris@16
|
48 mock_object_base( T1 const&, T2 const&, T3 const& ) {}
|
Chris@16
|
49
|
Chris@16
|
50 template<typename T1, typename T2, typename T3, typename T4>
|
Chris@16
|
51 mock_object_base( T1 const&, T2 const&, T3 const&, T4 const& ) {}
|
Chris@16
|
52
|
Chris@16
|
53 template<typename T1, typename T2, typename T3, typename T4, typename T5>
|
Chris@16
|
54 mock_object_base( T1 const&, T2 const&, T3 const&, T4 const&, T5 const& ) {}
|
Chris@16
|
55 };
|
Chris@16
|
56
|
Chris@16
|
57 // ************************************************************************** //
|
Chris@16
|
58 // ************** mock_object implementation helpers ************** //
|
Chris@16
|
59 // ************************************************************************** //
|
Chris@16
|
60
|
Chris@16
|
61 #define MO_OP_IMPL( op, descr, ret ) \
|
Chris@16
|
62 BOOST_ITEST_SCOPE( mock_object::operator op ); \
|
Chris@16
|
63 BOOST_ITEST_EPOINT( descr ); \
|
Chris@16
|
64 return ret \
|
Chris@16
|
65 /**/
|
Chris@16
|
66
|
Chris@16
|
67 #define MO_UNARY_OP( op, descr ) \
|
Chris@16
|
68 self_type const& operator op() const \
|
Chris@16
|
69 { \
|
Chris@16
|
70 MO_OP_IMPL( op, descr, prototype() ); \
|
Chris@16
|
71 } \
|
Chris@16
|
72 /**/
|
Chris@16
|
73
|
Chris@16
|
74 #define MO_UNARY_BOOL_OP( op, descr ) \
|
Chris@16
|
75 bool operator op() const \
|
Chris@16
|
76 { \
|
Chris@16
|
77 MO_OP_IMPL( op, descr, (!!BOOST_ITEST_DPOINT()) ); \
|
Chris@16
|
78 } \
|
Chris@16
|
79 /**/
|
Chris@16
|
80
|
Chris@16
|
81 #define MO_BINARY_OP( op, descr ) \
|
Chris@16
|
82 template<int i1, typename Base1,int i2, typename Base2> \
|
Chris@16
|
83 inline mock_object<i1,Base1> const& \
|
Chris@16
|
84 operator op( mock_object<i1,Base1> const& mo, \
|
Chris@16
|
85 mock_object<i2,Base2> const& ) \
|
Chris@16
|
86 { \
|
Chris@16
|
87 MO_OP_IMPL( op, descr, mo ); \
|
Chris@16
|
88 } \
|
Chris@16
|
89 \
|
Chris@16
|
90 template<int i, typename Base, typename T> \
|
Chris@16
|
91 inline mock_object<i,Base> const& \
|
Chris@16
|
92 operator op( mock_object<i,Base> const& mo, T const& ) \
|
Chris@16
|
93 { \
|
Chris@16
|
94 MO_OP_IMPL( op, descr, mo ); \
|
Chris@16
|
95 } \
|
Chris@16
|
96 \
|
Chris@16
|
97 template<int i, typename Base, typename T> \
|
Chris@16
|
98 inline mock_object<i,Base> const& \
|
Chris@16
|
99 operator op( T const&, mock_object<i,Base> const& mo ) \
|
Chris@16
|
100 { \
|
Chris@16
|
101 MO_OP_IMPL( op, descr, mo ); \
|
Chris@16
|
102 } \
|
Chris@16
|
103 /**/
|
Chris@16
|
104
|
Chris@16
|
105 #define MO_BINARY_BOOL_OP( op, descr ) \
|
Chris@16
|
106 template<int i1, typename Base1,int i2, typename Base2> \
|
Chris@16
|
107 inline bool \
|
Chris@16
|
108 operator op( mock_object<i1,Base1> const&, \
|
Chris@16
|
109 mock_object<i2,Base2> const& ) \
|
Chris@16
|
110 { \
|
Chris@16
|
111 MO_OP_IMPL( op, descr, BOOST_ITEST_DPOINT() ); \
|
Chris@16
|
112 } \
|
Chris@16
|
113 \
|
Chris@16
|
114 template<int i, typename Base, typename T> \
|
Chris@16
|
115 inline bool \
|
Chris@16
|
116 operator op( mock_object<i,Base> const&, T const& ) \
|
Chris@16
|
117 { \
|
Chris@16
|
118 MO_OP_IMPL( op, descr, BOOST_ITEST_DPOINT() ); \
|
Chris@16
|
119 } \
|
Chris@16
|
120 \
|
Chris@16
|
121 template<int i, typename Base, typename T> \
|
Chris@16
|
122 inline bool \
|
Chris@16
|
123 operator op( T const&, mock_object<i,Base> const& ) \
|
Chris@16
|
124 { \
|
Chris@16
|
125 MO_OP_IMPL( op, descr, BOOST_ITEST_DPOINT() ); \
|
Chris@16
|
126 } \
|
Chris@16
|
127 /**/
|
Chris@16
|
128
|
Chris@16
|
129 // ************************************************************************** //
|
Chris@16
|
130 // ************** mock_object ************** //
|
Chris@16
|
131 // ************************************************************************** //
|
Chris@16
|
132
|
Chris@16
|
133 template<int i = 0, typename Base=mock_object_base>
|
Chris@16
|
134 class mock_object;
|
Chris@16
|
135
|
Chris@16
|
136 template<int i, typename Base>
|
Chris@16
|
137 class mock_object : public Base {
|
Chris@16
|
138 // Private typeefs
|
Chris@16
|
139 typedef mock_object<i,Base> self_type;
|
Chris@16
|
140 struct dummy { void nonnull() {}; };
|
Chris@16
|
141 typedef void (dummy::*safe_bool)();
|
Chris@16
|
142
|
Chris@16
|
143 // prototype constructor
|
Chris@16
|
144 mock_object( dummy* ) {}
|
Chris@16
|
145
|
Chris@16
|
146 public:
|
Chris@16
|
147 static mock_object& prototype()
|
Chris@16
|
148 {
|
Chris@16
|
149 static mock_object p( reinterpret_cast<dummy*>(0) );
|
Chris@16
|
150 return p;
|
Chris@16
|
151 }
|
Chris@16
|
152
|
Chris@16
|
153 // Constructors
|
Chris@16
|
154 mock_object()
|
Chris@16
|
155 {
|
Chris@16
|
156 BOOST_ITEST_SCOPE( mock_object::mock_object );
|
Chris@16
|
157 BOOST_ITEST_EPOINT( "Mock object default constructor" );
|
Chris@16
|
158 }
|
Chris@16
|
159
|
Chris@16
|
160 template<typename T1>
|
Chris@16
|
161 mock_object( T1 const& arg1 )
|
Chris@16
|
162 : mock_object_base( arg1 )
|
Chris@16
|
163 {
|
Chris@16
|
164 BOOST_ITEST_SCOPE( mock_object::mock_object );
|
Chris@16
|
165 BOOST_ITEST_EPOINT( "Mock object constructor" );
|
Chris@16
|
166 }
|
Chris@16
|
167
|
Chris@16
|
168 template<typename T1, typename T2>
|
Chris@16
|
169 mock_object( T1 const& arg1, T2 const& arg2 )
|
Chris@16
|
170 : mock_object_base( arg1, arg2 )
|
Chris@16
|
171 {
|
Chris@16
|
172 BOOST_ITEST_SCOPE( mock_object::mock_object );
|
Chris@16
|
173 BOOST_ITEST_EPOINT( "Mock object constructor" );
|
Chris@16
|
174 }
|
Chris@16
|
175
|
Chris@16
|
176 template<typename T1, typename T2, typename T3>
|
Chris@16
|
177 mock_object( T1 const& arg1, T2 const& arg2, T3 const& arg3 )
|
Chris@16
|
178 : mock_object_base( arg1, arg2, arg3 )
|
Chris@16
|
179 {
|
Chris@16
|
180 BOOST_ITEST_SCOPE( mock_object::mock_object );
|
Chris@16
|
181 BOOST_ITEST_EPOINT( "Mock object constructor" );
|
Chris@16
|
182 }
|
Chris@16
|
183
|
Chris@16
|
184 template<typename T1, typename T2, typename T3, typename T4>
|
Chris@16
|
185 mock_object( T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4 )
|
Chris@16
|
186 : mock_object_base( arg1, arg2, arg3, arg4 )
|
Chris@16
|
187 {
|
Chris@16
|
188 BOOST_ITEST_SCOPE( mock_object::mock_object );
|
Chris@16
|
189 BOOST_ITEST_EPOINT( "Mock object constructor" );
|
Chris@16
|
190 }
|
Chris@16
|
191
|
Chris@16
|
192 template<typename T1, typename T2, typename T3, typename T4, typename T5>
|
Chris@16
|
193 mock_object( T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4, T5 const& arg5 )
|
Chris@16
|
194 : mock_object_base( arg1, arg2, arg3, arg4, arg5 )
|
Chris@16
|
195 {
|
Chris@16
|
196 BOOST_ITEST_SCOPE( mock_object::mock_object );
|
Chris@16
|
197 BOOST_ITEST_EPOINT( "Mock object constructor" );
|
Chris@16
|
198 }
|
Chris@16
|
199
|
Chris@16
|
200 mock_object( mock_object const& )
|
Chris@16
|
201 {
|
Chris@16
|
202 BOOST_ITEST_SCOPE( mock_object::mock_object );
|
Chris@16
|
203 BOOST_ITEST_EPOINT( "Mock object copy constructor" );
|
Chris@16
|
204 }
|
Chris@16
|
205
|
Chris@16
|
206 // assignment
|
Chris@16
|
207 self_type const& operator =( mock_object const& ) const
|
Chris@16
|
208 {
|
Chris@16
|
209 MO_OP_IMPL( =, "Copy assignment", prototype() );
|
Chris@16
|
210 }
|
Chris@16
|
211
|
Chris@16
|
212 template <typename T>
|
Chris@16
|
213 self_type const& operator =( T const& ) const
|
Chris@16
|
214 {
|
Chris@16
|
215 MO_OP_IMPL( =, "Copy assignment", prototype() );
|
Chris@16
|
216 }
|
Chris@16
|
217
|
Chris@16
|
218 // Unary operators
|
Chris@16
|
219 MO_UNARY_BOOL_OP( !, "Logical NOT operator" )
|
Chris@16
|
220 MO_UNARY_OP( &, "Address-of operator" )
|
Chris@16
|
221 MO_UNARY_OP( ~, "One's complement operator" )
|
Chris@16
|
222 MO_UNARY_OP( *, "Pointer dereference" )
|
Chris@16
|
223 MO_UNARY_OP( +, "Unary plus" )
|
Chris@16
|
224
|
Chris@16
|
225 // Increment and Decrement
|
Chris@16
|
226 MO_UNARY_OP( ++, "Prefix increment" )
|
Chris@16
|
227 MO_UNARY_OP( --, "Prefix decrement" )
|
Chris@16
|
228 self_type const& operator ++(int) const
|
Chris@16
|
229 {
|
Chris@16
|
230 MO_OP_IMPL( ++, "Postfix increment", prototype() );
|
Chris@16
|
231 }
|
Chris@16
|
232 self_type const& operator --(int) const
|
Chris@16
|
233 {
|
Chris@16
|
234 MO_OP_IMPL( --, "Postfix decrement", prototype() );
|
Chris@16
|
235 }
|
Chris@16
|
236
|
Chris@16
|
237 // Bool context convertion
|
Chris@16
|
238 operator safe_bool() const
|
Chris@16
|
239 {
|
Chris@16
|
240 MO_OP_IMPL( safe_bool, "Bool context conversion",
|
Chris@16
|
241 (BOOST_ITEST_DPOINT() ? 0 : &dummy::nonnull) );
|
Chris@16
|
242 }
|
Chris@16
|
243
|
Chris@16
|
244 // Function-call operators
|
Chris@16
|
245 self_type const& operator ()() const
|
Chris@16
|
246 {
|
Chris@16
|
247 MO_OP_IMPL( (), "0-arity function-call", prototype() );
|
Chris@16
|
248 }
|
Chris@16
|
249 template<typename T1>
|
Chris@16
|
250 self_type const& operator ()( T1 const& arg1 ) const
|
Chris@16
|
251 {
|
Chris@16
|
252 MO_OP_IMPL( (), "1-arity function-call", prototype() );
|
Chris@16
|
253 }
|
Chris@16
|
254 template<typename T1, typename T2>
|
Chris@16
|
255 self_type const& operator ()( T1 const&, T2 const& ) const
|
Chris@16
|
256 {
|
Chris@16
|
257 MO_OP_IMPL( (), "2-arity function-call", prototype() );
|
Chris@16
|
258 }
|
Chris@16
|
259 template<typename T1, typename T2, typename T3>
|
Chris@16
|
260 self_type const& operator ()( T1 const&, T2 const&, T3 const& ) const
|
Chris@16
|
261 {
|
Chris@16
|
262 MO_OP_IMPL( (), "3-arity function-call", prototype() );
|
Chris@16
|
263 }
|
Chris@16
|
264 template<typename T1, typename T2, typename T3, typename T4>
|
Chris@16
|
265 self_type const& operator ()( T1 const&, T2 const&, T3 const&, T4 const& ) const
|
Chris@16
|
266 {
|
Chris@16
|
267 MO_OP_IMPL( (), "4-arity function-call", prototype() );
|
Chris@16
|
268 }
|
Chris@16
|
269 template<typename T1, typename T2, typename T3, typename T4, typename T5>
|
Chris@16
|
270 self_type const& operator ()( T1 const&, T2 const&, T3 const&, T4 const&, T5 const& ) const
|
Chris@16
|
271 {
|
Chris@16
|
272 MO_OP_IMPL( (), "5-arity function-call", prototype() );
|
Chris@16
|
273 }
|
Chris@16
|
274
|
Chris@16
|
275 // Substripting
|
Chris@16
|
276 template<typename T>
|
Chris@16
|
277 self_type const& operator []( T const& ) const
|
Chris@16
|
278 {
|
Chris@16
|
279 MO_OP_IMPL( [], "Substripting", prototype() );
|
Chris@16
|
280 }
|
Chris@16
|
281
|
Chris@16
|
282 // Class member access
|
Chris@16
|
283 self_type const* operator->() const
|
Chris@16
|
284 {
|
Chris@16
|
285 MO_OP_IMPL( ->, "Class member access", this );
|
Chris@16
|
286 }
|
Chris@16
|
287 };
|
Chris@16
|
288
|
Chris@16
|
289 // !! MO_BINARY_OP( BOOST_PP_COMMA(), "Comma operator" )
|
Chris@16
|
290
|
Chris@16
|
291 MO_BINARY_BOOL_OP( !=, "Inequality" )
|
Chris@16
|
292 MO_BINARY_OP( %, "Modulus" )
|
Chris@16
|
293 MO_BINARY_OP( %=, "Modulus/assignment" )
|
Chris@16
|
294 MO_BINARY_OP( &, "Bitwise AND" )
|
Chris@16
|
295 MO_BINARY_BOOL_OP( &&, "Logical AND" )
|
Chris@16
|
296 MO_BINARY_OP( &=, "Bitwise AND/assignment" )
|
Chris@16
|
297 MO_BINARY_OP( *, "Multiplication" )
|
Chris@16
|
298 MO_BINARY_OP( *=, "Multiplication/assignment" )
|
Chris@16
|
299 MO_BINARY_OP( +, "Addition" )
|
Chris@16
|
300 MO_BINARY_OP( +=, "Addition/assignment" )
|
Chris@16
|
301 //MO_BINARY_OP( -, "Subtraction" )
|
Chris@16
|
302 MO_BINARY_OP( -=, "Subtraction/assignment" )
|
Chris@16
|
303 MO_BINARY_OP( ->*, "Pointer-to-member selection" )
|
Chris@16
|
304 MO_BINARY_OP( /, "Division" )
|
Chris@16
|
305 MO_BINARY_OP( /=, "Division/assignment" )
|
Chris@16
|
306 MO_BINARY_BOOL_OP( <, "Less than" )
|
Chris@16
|
307 MO_BINARY_OP( <<=, "Left shift/assignment" )
|
Chris@16
|
308 MO_BINARY_BOOL_OP( <=, "Less than or equal to" )
|
Chris@16
|
309 MO_BINARY_BOOL_OP( ==, "Equality" )
|
Chris@16
|
310 MO_BINARY_BOOL_OP( >, "Greater than" )
|
Chris@16
|
311 MO_BINARY_BOOL_OP( >=, "Greater than or equal to" )
|
Chris@16
|
312 MO_BINARY_OP( >>=, "Right shift/assignment" )
|
Chris@16
|
313 MO_BINARY_OP( ^, "Exclusive OR" )
|
Chris@16
|
314 MO_BINARY_OP( ^=, "Exclusive OR/assignment" )
|
Chris@16
|
315 MO_BINARY_OP( |, "Bitwise inclusive OR" )
|
Chris@16
|
316 MO_BINARY_OP( |=, "Bitwise inclusive OR/assignment" )
|
Chris@16
|
317 MO_BINARY_BOOL_OP( ||, "Logical OR" )
|
Chris@16
|
318
|
Chris@16
|
319 MO_BINARY_OP( <<, "Left shift" )
|
Chris@16
|
320 MO_BINARY_OP( >>, "Right shift" )
|
Chris@16
|
321
|
Chris@16
|
322 } // namespace itest
|
Chris@16
|
323
|
Chris@16
|
324 } // namespace boost
|
Chris@16
|
325
|
Chris@16
|
326 #include <boost/test/detail/enable_warnings.hpp>
|
Chris@16
|
327
|
Chris@16
|
328 #endif // BOOST_TEST_MOCK_OBJECT_HPP_112205GER
|