1
// (C) Copyright Gennadiy Rozental 2005-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)
6
// See http://www.boost.org/libs/test for the library home page.
10
// Version : $Revision: 54633 $
12
// Description : Facilities to perform exception safety_tests
13
// ***************************************************************************
15
#ifndef BOOST_TEST_MOCK_OBJECT_HPP_112205GER
16
#define BOOST_TEST_MOCK_OBJECT_HPP_112205GER
19
#include <boost/test/detail/config.hpp>
20
#include <boost/test/interaction_based.hpp>
23
#include <boost/preprocessor/punctuation/comma.hpp>
25
#include <boost/test/detail/suppress_warnings.hpp>
27
//____________________________________________________________________________//
33
// ************************************************************************** //
34
// ************** mock_object_base ************** //
35
// ************************************************************************** //
37
class mock_object_base {
42
mock_object_base( T1 const& ) {}
44
template<typename T1, typename T2>
45
mock_object_base( T1 const&, T2 const& ) {}
47
template<typename T1, typename T2, typename T3>
48
mock_object_base( T1 const&, T2 const&, T3 const& ) {}
50
template<typename T1, typename T2, typename T3, typename T4>
51
mock_object_base( T1 const&, T2 const&, T3 const&, T4 const& ) {}
53
template<typename T1, typename T2, typename T3, typename T4, typename T5>
54
mock_object_base( T1 const&, T2 const&, T3 const&, T4 const&, T5 const& ) {}
57
// ************************************************************************** //
58
// ************** mock_object implementation helpers ************** //
59
// ************************************************************************** //
61
#define MO_OP_IMPL( op, descr, ret ) \
62
BOOST_ITEST_SCOPE( mock_object::operator op ); \
63
BOOST_ITEST_EPOINT( descr ); \
67
#define MO_UNARY_OP( op, descr ) \
68
self_type const& operator op() const \
70
MO_OP_IMPL( op, descr, prototype() ); \
74
#define MO_UNARY_BOOL_OP( op, descr ) \
75
bool operator op() const \
77
MO_OP_IMPL( op, descr, (!!BOOST_ITEST_DPOINT()) ); \
81
#define MO_BINARY_OP( op, descr ) \
82
template<int i1, typename Base1,int i2, typename Base2> \
83
inline mock_object<i1,Base1> const& \
84
operator op( mock_object<i1,Base1> const& mo, \
85
mock_object<i2,Base2> const& ) \
87
MO_OP_IMPL( op, descr, mo ); \
90
template<int i, typename Base, typename T> \
91
inline mock_object<i,Base> const& \
92
operator op( mock_object<i,Base> const& mo, T const& ) \
94
MO_OP_IMPL( op, descr, mo ); \
97
template<int i, typename Base, typename T> \
98
inline mock_object<i,Base> const& \
99
operator op( T const&, mock_object<i,Base> const& mo ) \
101
MO_OP_IMPL( op, descr, mo ); \
105
#define MO_BINARY_BOOL_OP( op, descr ) \
106
template<int i1, typename Base1,int i2, typename Base2> \
108
operator op( mock_object<i1,Base1> const&, \
109
mock_object<i2,Base2> const& ) \
111
MO_OP_IMPL( op, descr, BOOST_ITEST_DPOINT() ); \
114
template<int i, typename Base, typename T> \
116
operator op( mock_object<i,Base> const&, T const& ) \
118
MO_OP_IMPL( op, descr, BOOST_ITEST_DPOINT() ); \
121
template<int i, typename Base, typename T> \
123
operator op( T const&, mock_object<i,Base> const& ) \
125
MO_OP_IMPL( op, descr, BOOST_ITEST_DPOINT() ); \
129
// ************************************************************************** //
130
// ************** mock_object ************** //
131
// ************************************************************************** //
133
template<int i = 0, typename Base=mock_object_base>
136
template<int i, typename Base>
137
class mock_object : public Base {
139
typedef mock_object<i,Base> self_type;
140
struct dummy { void nonnull() {}; };
141
typedef void (dummy::*safe_bool)();
143
// prototype constructor
144
mock_object( dummy* ) {}
147
static mock_object& prototype()
149
static mock_object p( reinterpret_cast<dummy*>(0) );
156
BOOST_ITEST_SCOPE( mock_object::mock_object );
157
BOOST_ITEST_EPOINT( "Mock object default constructor" );
160
template<typename T1>
161
mock_object( T1 const& arg1 )
162
: mock_object_base( arg1 )
164
BOOST_ITEST_SCOPE( mock_object::mock_object );
165
BOOST_ITEST_EPOINT( "Mock object constructor" );
168
template<typename T1, typename T2>
169
mock_object( T1 const& arg1, T2 const& arg2 )
170
: mock_object_base( arg1, arg2 )
172
BOOST_ITEST_SCOPE( mock_object::mock_object );
173
BOOST_ITEST_EPOINT( "Mock object constructor" );
176
template<typename T1, typename T2, typename T3>
177
mock_object( T1 const& arg1, T2 const& arg2, T3 const& arg3 )
178
: mock_object_base( arg1, arg2, arg3 )
180
BOOST_ITEST_SCOPE( mock_object::mock_object );
181
BOOST_ITEST_EPOINT( "Mock object constructor" );
184
template<typename T1, typename T2, typename T3, typename T4>
185
mock_object( T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4 )
186
: mock_object_base( arg1, arg2, arg3, arg4 )
188
BOOST_ITEST_SCOPE( mock_object::mock_object );
189
BOOST_ITEST_EPOINT( "Mock object constructor" );
192
template<typename T1, typename T2, typename T3, typename T4, typename T5>
193
mock_object( T1 const& arg1, T2 const& arg2, T3 const& arg3, T4 const& arg4, T5 const& arg5 )
194
: mock_object_base( arg1, arg2, arg3, arg4, arg5 )
196
BOOST_ITEST_SCOPE( mock_object::mock_object );
197
BOOST_ITEST_EPOINT( "Mock object constructor" );
200
mock_object( mock_object const& )
202
BOOST_ITEST_SCOPE( mock_object::mock_object );
203
BOOST_ITEST_EPOINT( "Mock object copy constructor" );
207
self_type const& operator =( mock_object const& ) const
209
MO_OP_IMPL( =, "Copy assignment", prototype() );
212
template <typename T>
213
self_type const& operator =( T const& ) const
215
MO_OP_IMPL( =, "Copy assignment", prototype() );
219
MO_UNARY_BOOL_OP( !, "Logical NOT operator" )
220
MO_UNARY_OP( &, "Address-of operator" )
221
MO_UNARY_OP( ~, "One's complement operator" )
222
MO_UNARY_OP( *, "Pointer dereference" )
223
MO_UNARY_OP( +, "Unary plus" )
225
// Increment and Decrement
226
MO_UNARY_OP( ++, "Prefix increment" )
227
MO_UNARY_OP( --, "Prefix decrement" )
228
self_type const& operator ++(int) const
230
MO_OP_IMPL( ++, "Postfix increment", prototype() );
232
self_type const& operator --(int) const
234
MO_OP_IMPL( --, "Postfix decrement", prototype() );
237
// Bool context convertion
238
operator safe_bool() const
240
MO_OP_IMPL( safe_bool, "Bool context conversion",
241
(BOOST_ITEST_DPOINT() ? 0 : &dummy::nonnull) );
244
// Function-call operators
245
self_type const& operator ()() const
247
MO_OP_IMPL( (), "0-arity function-call", prototype() );
249
template<typename T1>
250
self_type const& operator ()( T1 const& arg1 ) const
252
MO_OP_IMPL( (), "1-arity function-call", prototype() );
254
template<typename T1, typename T2>
255
self_type const& operator ()( T1 const&, T2 const& ) const
257
MO_OP_IMPL( (), "2-arity function-call", prototype() );
259
template<typename T1, typename T2, typename T3>
260
self_type const& operator ()( T1 const&, T2 const&, T3 const& ) const
262
MO_OP_IMPL( (), "3-arity function-call", prototype() );
264
template<typename T1, typename T2, typename T3, typename T4>
265
self_type const& operator ()( T1 const&, T2 const&, T3 const&, T4 const& ) const
267
MO_OP_IMPL( (), "4-arity function-call", prototype() );
269
template<typename T1, typename T2, typename T3, typename T4, typename T5>
270
self_type const& operator ()( T1 const&, T2 const&, T3 const&, T4 const&, T5 const& ) const
272
MO_OP_IMPL( (), "5-arity function-call", prototype() );
277
self_type const& operator []( T const& ) const
279
MO_OP_IMPL( [], "Substripting", prototype() );
282
// Class member access
283
self_type const* operator->() const
285
MO_OP_IMPL( ->, "Class member access", this );
289
// !! MO_BINARY_OP( BOOST_PP_COMMA(), "Comma operator" )
291
MO_BINARY_BOOL_OP( !=, "Inequality" )
292
MO_BINARY_OP( %, "Modulus" )
293
MO_BINARY_OP( %=, "Modulus/assignment" )
294
MO_BINARY_OP( &, "Bitwise AND" )
295
MO_BINARY_BOOL_OP( &&, "Logical AND" )
296
MO_BINARY_OP( &=, "Bitwise AND/assignment" )
297
MO_BINARY_OP( *, "Multiplication" )
298
MO_BINARY_OP( *=, "Multiplication/assignment" )
299
MO_BINARY_OP( +, "Addition" )
300
MO_BINARY_OP( +=, "Addition/assignment" )
301
//MO_BINARY_OP( -, "Subtraction" )
302
MO_BINARY_OP( -=, "Subtraction/assignment" )
303
MO_BINARY_OP( ->*, "Pointer-to-member selection" )
304
MO_BINARY_OP( /, "Division" )
305
MO_BINARY_OP( /=, "Division/assignment" )
306
MO_BINARY_BOOL_OP( <, "Less than" )
307
MO_BINARY_OP( <<=, "Left shift/assignment" )
308
MO_BINARY_BOOL_OP( <=, "Less than or equal to" )
309
MO_BINARY_BOOL_OP( ==, "Equality" )
310
MO_BINARY_BOOL_OP( >, "Greater than" )
311
MO_BINARY_BOOL_OP( >=, "Greater than or equal to" )
312
MO_BINARY_OP( >>=, "Right shift/assignment" )
313
MO_BINARY_OP( ^, "Exclusive OR" )
314
MO_BINARY_OP( ^=, "Exclusive OR/assignment" )
315
MO_BINARY_OP( |, "Bitwise inclusive OR" )
316
MO_BINARY_OP( |=, "Bitwise inclusive OR/assignment" )
317
MO_BINARY_BOOL_OP( ||, "Logical OR" )
319
MO_BINARY_OP( <<, "Left shift" )
320
MO_BINARY_OP( >>, "Right shift" )
326
#include <boost/test/detail/enable_warnings.hpp>
328
#endif // BOOST_TEST_MOCK_OBJECT_HPP_112205GER