mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Changed layout to match boost
This commit is contained in:
parent
7a8ba352c6
commit
c950c24f52
122 changed files with 15469 additions and 15550 deletions
24
doc/example/calculator.hpp
Normal file
24
doc/example/calculator.hpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef CALCULATOR
|
||||
#define CALCULATOR
|
||||
|
||||
class view;
|
||||
|
||||
//[ calculator
|
||||
class calculator
|
||||
{
|
||||
public:
|
||||
calculator( view& v );
|
||||
|
||||
void add( int a, int b ); // the result will be sent to the view 'v'
|
||||
};
|
||||
//]
|
||||
|
||||
#endif // CALCULATOR
|
||||
178
doc/example/customization.cpp
Normal file
178
doc/example/customization.cpp
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ mock_use_conversions
|
||||
#define MOCK_USE_CONVERSIONS
|
||||
#include <turtle/mock.hpp>
|
||||
//]
|
||||
#include "calculator.hpp"
|
||||
#include "mock_view.hpp"
|
||||
|
||||
//[ mock_stream_user_type
|
||||
namespace user_namespace
|
||||
{
|
||||
struct user_type
|
||||
{};
|
||||
|
||||
inline mock::stream& operator<<( mock::stream& s, const user_type& )
|
||||
{
|
||||
return s << "user_type";
|
||||
}
|
||||
}
|
||||
//]
|
||||
|
||||
namespace custom_constraint_free_function_test
|
||||
{
|
||||
//[ custom_constraint_free_function
|
||||
bool custom_constraint( int actual )
|
||||
{
|
||||
return actual == 42;
|
||||
}
|
||||
//]
|
||||
|
||||
//[ custom_constraint_free_function_test
|
||||
BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two )
|
||||
{
|
||||
mock_view v;
|
||||
calculator c( v );
|
||||
MOCK_EXPECT( v.display ).with( &custom_constraint );
|
||||
c.add( 41, 1 );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace custom_constraint_functor_test
|
||||
{
|
||||
//[ custom_constraint_functor
|
||||
struct custom_constraint
|
||||
{
|
||||
friend bool operator==( int actual, const custom_constraint& )
|
||||
{
|
||||
return actual == 42;
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& s, const custom_constraint& )
|
||||
{
|
||||
return s << "_ == 42";
|
||||
}
|
||||
};
|
||||
//]
|
||||
|
||||
//[ custom_constraint_functor_test
|
||||
BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two )
|
||||
{
|
||||
mock_view v;
|
||||
calculator c( v );
|
||||
MOCK_EXPECT( v.display ).with( custom_constraint() );
|
||||
c.add( 41, 1 );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
//[ near_constraint
|
||||
template< typename Expected >
|
||||
struct near_constraint
|
||||
{
|
||||
near_constraint( Expected expected, Expected threshold )
|
||||
: expected_( expected )
|
||||
, threshold_( threshold )
|
||||
{}
|
||||
|
||||
template< typename Actual >
|
||||
bool operator()( Actual actual ) const
|
||||
{
|
||||
return std::abs( actual - boost::unwrap_ref( expected_ ) )
|
||||
< boost::unwrap_ref( threshold_ );
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& s, const near_constraint& c )
|
||||
{
|
||||
return s << "near( " << mock::format( c.expected_ )
|
||||
<< ", " << mock::format( c.threshold_ ) << " )";
|
||||
}
|
||||
|
||||
Expected expected_, threshold_;
|
||||
};
|
||||
|
||||
template< typename Expected >
|
||||
mock::constraint< near_constraint< Expected > > near( Expected expected, Expected threshold )
|
||||
{
|
||||
return near_constraint< Expected >( expected, threshold );
|
||||
}
|
||||
//]
|
||||
|
||||
namespace near_constraint_test
|
||||
{
|
||||
//[ near_constraint_test
|
||||
BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two_plus_or_minus_one )
|
||||
{
|
||||
mock_view v;
|
||||
calculator c( v );
|
||||
MOCK_EXPECT( v.display ).with( near( 42, 1 ) );
|
||||
c.add( 41, 1 );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace near_constraint_cref_test
|
||||
{
|
||||
//[ near_constraint_cref_test
|
||||
BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two_plus_or_minus_one )
|
||||
{
|
||||
mock_view v;
|
||||
calculator c( v );
|
||||
int expected, threshold;
|
||||
MOCK_EXPECT( v.display ).with( near( boost::cref( expected ), boost::cref( threshold ) ) );
|
||||
expected = 42;
|
||||
threshold = 1;
|
||||
c.add( 41, 1 );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
#undef MOCK_MAX_ARGS
|
||||
//[ max_args
|
||||
#define MOCK_MAX_ARGS 20
|
||||
#include <turtle/mock.hpp>
|
||||
//]
|
||||
|
||||
//[ custom_policy
|
||||
template< typename Result >
|
||||
struct custom_policy
|
||||
{
|
||||
static Result abort()
|
||||
{
|
||||
// ...
|
||||
}
|
||||
template< typename Context >
|
||||
static void fail( const char* message, const Context& context, const char* file = "unknown location", int line = 0 )
|
||||
{
|
||||
// ...
|
||||
}
|
||||
template< typename Context >
|
||||
static void call( const Context& context, const char* file, int line )
|
||||
{
|
||||
// ...
|
||||
}
|
||||
static void pass( const char* file, int line )
|
||||
{
|
||||
// ...
|
||||
}
|
||||
};
|
||||
//]
|
||||
|
||||
#undef MOCK_ERROR_POLICY
|
||||
//[ define_custom_policy
|
||||
#define MOCK_ERROR_POLICY custom_policy
|
||||
#include <turtle/mock.hpp>
|
||||
//]
|
||||
|
||||
//[ thread_safe
|
||||
#define MOCK_THREAD_SAFE
|
||||
#include <turtle/mock.hpp>
|
||||
//]
|
||||
96
doc/example/getting_started.cpp
Normal file
96
doc/example/getting_started.cpp
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ prerequisite
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
//]
|
||||
#include "calculator.hpp"
|
||||
#include "mock_view.hpp"
|
||||
|
||||
namespace phases
|
||||
{
|
||||
//[ phases
|
||||
BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||
{
|
||||
mock_view v; // create mock objects
|
||||
calculator c( v ); // create object under test
|
||||
MOCK_EXPECT( v.display ).once().with( 0 ); // configure mock objects
|
||||
c.add( 0, 0 ); // exercise object under test
|
||||
} // verify mock objects
|
||||
//]
|
||||
}
|
||||
|
||||
namespace verify_reset
|
||||
{
|
||||
//[ verify_reset
|
||||
BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||
{
|
||||
mock_view v;
|
||||
calculator c( v );
|
||||
MOCK_EXPECT( v.display ).once().with( 0 );
|
||||
c.add( 0, 0 );
|
||||
MOCK_VERIFY( v.display ); // verify all expectations are fulfilled for the 'display' method
|
||||
mock::verify( v ); // verify all expectations are fulfilled for all methods of 'v'
|
||||
mock::verify(); // verify all expectations are fulfilled for all existing mock objects
|
||||
MOCK_RESET( v.display ); // reset all expectations for the 'display' method
|
||||
mock::reset( v ); // reset all expectations for all methods of 'v'
|
||||
mock::reset(); // reset all expectations for all existing mock objects
|
||||
} // automatically verify all expectations are fulfilled for all mock objects going out of scope
|
||||
//]
|
||||
}
|
||||
|
||||
namespace expectations
|
||||
{
|
||||
//[ expectations
|
||||
BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||
{
|
||||
mock_view v;
|
||||
calculator c( v );
|
||||
MOCK_EXPECT( v.display ).once().with( 0 ); // this call must occur once (and only once)
|
||||
MOCK_EXPECT( v.display ).with( 1 ); // this call can occur any number of times (including never)
|
||||
c.add( 0, 0 );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace sequence
|
||||
{
|
||||
//[ sequence
|
||||
BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||
{
|
||||
mock_view v;
|
||||
calculator c( v );
|
||||
mock::sequence s;
|
||||
MOCK_EXPECT( v.display ).once().with( 0 ).in( s ); // add this expectation to the sequence
|
||||
MOCK_EXPECT( v.display ).with( 1 ).in( s ); // add this expectation to the sequence after the previous call
|
||||
c.add( 0, 0 );
|
||||
c.add( 1, 0 );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace several_sequences
|
||||
{
|
||||
//[ several_sequences
|
||||
BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||
{
|
||||
mock_view v;
|
||||
calculator c( v );
|
||||
mock::sequence s1, s2;
|
||||
MOCK_EXPECT( v.display ).once().with( 0 ).in( s1 );
|
||||
MOCK_EXPECT( v.display ).once().with( 1 ).in( s2 );
|
||||
MOCK_EXPECT( v.display ).with( 2 ).in( s1, s2 ); // add this expectation to both sequences after the previous calls
|
||||
c.add( 0, 0 );
|
||||
c.add( 1, 0 );
|
||||
c.add( 1, 1 );
|
||||
c.add( 2, 0 );
|
||||
}
|
||||
//]
|
||||
}
|
||||
48
doc/example/limitations_comma_in_macro.cpp
Normal file
48
doc/example/limitations_comma_in_macro.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
//[ limitations_comma_in_macro_problem
|
||||
template< typename T1, typename T2 >
|
||||
struct my_base_class
|
||||
{};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_comma_in_macro_solution_1
|
||||
{
|
||||
//[ limitations_comma_in_macro_solution_1
|
||||
typedef my_base_class< int, int > my_base_type;
|
||||
|
||||
MOCK_BASE_CLASS( my_mock, my_base_type )
|
||||
{};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_comma_in_macro_solution_2
|
||||
{
|
||||
//[ limitations_comma_in_macro_solution_2
|
||||
template< typename T1, typename T2 >
|
||||
MOCK_BASE_CLASS( my_mock, my_base_class< T1 BOOST_PP_COMMA() T2 > )
|
||||
{};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_comma_in_macro_solution_3
|
||||
{
|
||||
//[ limitations_comma_in_macro_solution_3
|
||||
template< typename T1, typename T2 >
|
||||
struct my_mock : my_base_class< T1, T2 >, mock::object
|
||||
{};
|
||||
//]
|
||||
}
|
||||
50
doc/example/limitations_const_parameter_warning.cpp
Normal file
50
doc/example/limitations_const_parameter_warning.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
//[ limitations_const_parameter_warning_problem
|
||||
class base
|
||||
{
|
||||
public:
|
||||
virtual void method( const int ) = 0;
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_const_parameter_warning_explanation
|
||||
{
|
||||
//[ limitations_const_parameter_warning_explanation
|
||||
class derived : public base
|
||||
{
|
||||
public:
|
||||
virtual void method( const int );
|
||||
};
|
||||
|
||||
void derived::method( int )
|
||||
{}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_const_parameter_warning_solution
|
||||
{
|
||||
//[ limitations_const_parameter_warning_solution
|
||||
MOCK_BASE_CLASS( mock_base, base )
|
||||
{
|
||||
void method( const int i )
|
||||
{
|
||||
method_stub( i );
|
||||
}
|
||||
MOCK_METHOD( method_stub, 1, void( int ), method )
|
||||
};
|
||||
//]
|
||||
}
|
||||
43
doc/example/limitations_literal_zero.cpp
Normal file
43
doc/example/limitations_literal_zero.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
//[ limitations_literal_zero_problem
|
||||
class base
|
||||
{
|
||||
public:
|
||||
virtual void method( int* i ) = 0;
|
||||
};
|
||||
|
||||
MOCK_BASE_CLASS( mock_base, base )
|
||||
{
|
||||
MOCK_METHOD( method, 1 )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( literal_zero )
|
||||
{
|
||||
mock_base m;
|
||||
//[ limitations_literal_zero_solution_1
|
||||
MOCK_EXPECT( m.method ).with( mock::equal< int* >( 0 ) ); // this compiles
|
||||
//]
|
||||
//[ limitations_literal_zero_solution_2
|
||||
MOCK_EXPECT( m.method ).with( mock::negate );
|
||||
//]
|
||||
#ifdef MOCK_NULLPTR
|
||||
//[ limitations_literal_zero_solution_3
|
||||
MOCK_EXPECT( m.method ).with( nullptr );
|
||||
//]
|
||||
#endif
|
||||
}
|
||||
27
doc/example/limitations_non_virtual_method.cpp
Normal file
27
doc/example/limitations_non_virtual_method.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
//[ limitations_non_virtual_method_problem
|
||||
class base
|
||||
{
|
||||
public:
|
||||
void method() // the method is not virtual
|
||||
{}
|
||||
};
|
||||
//]
|
||||
|
||||
//[ limitations_non_virtual_method_problem_2
|
||||
MOCK_BASE_CLASS( mock_base, base )
|
||||
{
|
||||
MOCK_METHOD( method, 0 )
|
||||
};
|
||||
//]
|
||||
29
doc/example/limitations_private_method.cpp
Normal file
29
doc/example/limitations_private_method.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
//[ limitations_private_method_problem
|
||||
class base
|
||||
{
|
||||
private:
|
||||
virtual void method() = 0;
|
||||
};
|
||||
//]
|
||||
|
||||
//[ limitations_private_method_solution
|
||||
MOCK_BASE_CLASS( mock_base, base )
|
||||
{
|
||||
MOCK_METHOD( method, 0, void() )
|
||||
};
|
||||
//]
|
||||
}
|
||||
83
doc/example/limitations_template_method.cpp
Normal file
83
doc/example/limitations_template_method.cpp
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace limitations_template_method_problem
|
||||
{
|
||||
//[ limitations_template_method_problem
|
||||
class concept
|
||||
{
|
||||
public:
|
||||
template< typename T >
|
||||
void method( T t )
|
||||
{}
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
void function_under_test( T t ) // T is supposed to model the previous concept
|
||||
{
|
||||
t.method( 42 );
|
||||
t.method( "string" );
|
||||
}
|
||||
//]
|
||||
|
||||
//[ limitations_template_method_solution
|
||||
MOCK_CLASS( mock_concept )
|
||||
{
|
||||
MOCK_METHOD( method, 1, void( int ), method_int )
|
||||
MOCK_METHOD( method, 1, void( const char* ), method_string )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace limitations_template_method_problem_2
|
||||
{
|
||||
//[ limitations_template_method_problem_2
|
||||
class concept
|
||||
{
|
||||
public:
|
||||
template< typename T >
|
||||
T create()
|
||||
{
|
||||
return T();
|
||||
}
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
void function_under_test( T t ) // T is supposed to model the previous concept
|
||||
{
|
||||
t.create< int >();
|
||||
t.create< std::string >();
|
||||
}
|
||||
//]
|
||||
|
||||
//[ limitations_template_method_solution_2
|
||||
MOCK_CLASS( mock_concept )
|
||||
{
|
||||
template< typename T >
|
||||
T create();
|
||||
|
||||
template<>
|
||||
int create< int >()
|
||||
{
|
||||
return create_int();
|
||||
}
|
||||
template<>
|
||||
std::string create< std::string >()
|
||||
{
|
||||
return create_string();
|
||||
}
|
||||
|
||||
MOCK_METHOD( create_int, 0, int(), create_int )
|
||||
MOCK_METHOD( create_string, 0, std::string(), create_string )
|
||||
};
|
||||
//]
|
||||
}
|
||||
35
doc/example/limitations_throw_specifier.cpp
Normal file
35
doc/example/limitations_throw_specifier.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
//[ limitations_throw_specifier_problem
|
||||
struct base_class
|
||||
{
|
||||
virtual ~base_class()
|
||||
{}
|
||||
|
||||
virtual void method() throw ();
|
||||
};
|
||||
//]
|
||||
|
||||
//[ limitations_throw_specifier_solution
|
||||
MOCK_BASE_CLASS( mock_class, base_class )
|
||||
{
|
||||
void method() throw ()
|
||||
{
|
||||
method_proxy();
|
||||
}
|
||||
MOCK_METHOD( method_proxy, 0, void(), method )
|
||||
};
|
||||
//]
|
||||
}
|
||||
22
doc/example/mock_view.hpp
Normal file
22
doc/example/mock_view.hpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef MOCK_VIEW
|
||||
#define MOCK_VIEW
|
||||
|
||||
#include <turtle/mock.hpp>
|
||||
#include "view.hpp"
|
||||
|
||||
//[ mock_view
|
||||
MOCK_BASE_CLASS( mock_view, view ) // declare a 'mock_view' class implementing 'view'
|
||||
{
|
||||
MOCK_METHOD( display, 1 ) // implement the 'display' method from 'view' (taking 1 argument)
|
||||
};
|
||||
//]
|
||||
|
||||
#endif // MOCK_VIEW
|
||||
76
doc/example/motivation.cpp
Normal file
76
doc/example/motivation.cpp
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/mock/mock.hpp>
|
||||
#include "calculator.hpp"
|
||||
#include "mock_view.hpp"
|
||||
|
||||
namespace simple
|
||||
{
|
||||
//[ simple_calculator
|
||||
class calculator
|
||||
{
|
||||
public:
|
||||
int add( int a, int b );
|
||||
};
|
||||
//]
|
||||
|
||||
//[ simple_zero_plus_zero_is_zero
|
||||
BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||
{
|
||||
calculator c;
|
||||
BOOST_CHECK_EQUAL( 0, c.add( 0, 0 ) );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace without_mock_object
|
||||
{
|
||||
//[ my_view
|
||||
class my_view : public view
|
||||
{
|
||||
public:
|
||||
my_view()
|
||||
: called( false )
|
||||
{}
|
||||
virtual void display( int result )
|
||||
{
|
||||
called = true;
|
||||
value = result;
|
||||
}
|
||||
bool called;
|
||||
int value;
|
||||
};
|
||||
//]
|
||||
|
||||
//[ zero_plus_zero_is_zero_without_mock_object
|
||||
BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||
{
|
||||
my_view v;
|
||||
calculator c( v );
|
||||
c.add( 0, 0 );
|
||||
BOOST_REQUIRE( v.called );
|
||||
BOOST_CHECK_EQUAL( 0, v.value );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace with_mock_object
|
||||
{
|
||||
//[ zero_plus_zero_is_zero_with_mock_object
|
||||
BOOST_AUTO_TEST_CASE( zero_plus_zero_is_zero )
|
||||
{
|
||||
mock_view v;
|
||||
calculator c( v );
|
||||
MOCK_EXPECT( v.display ).once().with( 0 ); // expect the 'display' method to be called once (and only once) with a parameter value equal to 0
|
||||
c.add( 0, 0 );
|
||||
}
|
||||
//]
|
||||
}
|
||||
61
doc/example/patterns_async_call.cpp
Normal file
61
doc/example/patterns_async_call.cpp
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ async_call_problem
|
||||
namespace
|
||||
{
|
||||
class base_class
|
||||
{
|
||||
public:
|
||||
virtual void method() = 0;
|
||||
};
|
||||
|
||||
class my_class
|
||||
{
|
||||
public:
|
||||
explicit my_class( base_class& );
|
||||
|
||||
void flush(); // repetitively calling this method will in turn call base_class::method at some point
|
||||
};
|
||||
}
|
||||
//]
|
||||
|
||||
//[ async_call_solution
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename F >
|
||||
void wait( bool& condition, F flush, int timeout = 100, int sleep = 100 )
|
||||
{
|
||||
while( !condition && timeout > 0 )
|
||||
{
|
||||
--timeout;
|
||||
boost::this_thread::sleep( boost::posix_time::milliseconds( sleep ) );
|
||||
flush();
|
||||
}
|
||||
}
|
||||
MOCK_BASE_CLASS( mock_base_class, base_class )
|
||||
{
|
||||
MOCK_METHOD( method, 0 )
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( method_is_called )
|
||||
{
|
||||
mock_base_class mock;
|
||||
my_class c( mock );
|
||||
bool done = false;
|
||||
MOCK_EXPECT( mock.method ).once().calls( boost::lambda::var( done ) = true ); // when method is called it will set done to true
|
||||
wait( done, boost::bind( &my_class::flush, &c ) ); // just wait on done, flushing from time to time
|
||||
}
|
||||
//]
|
||||
44
doc/example/patterns_invoke_functor.cpp
Normal file
44
doc/example/patterns_invoke_functor.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ invoke_functor_problem
|
||||
#include <boost/function.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
class base_class
|
||||
{
|
||||
public:
|
||||
virtual void method( boost::function< void( int ) > functor ) = 0;
|
||||
};
|
||||
|
||||
void function( base_class& ); // the function will call 'method' with a functor to be applied
|
||||
}
|
||||
//]
|
||||
|
||||
//[ invoke_functor_solution
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/bind/apply.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
MOCK_BASE_CLASS( mock_class, base_class )
|
||||
{
|
||||
MOCK_METHOD( method, 1 )
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( how_to_invoke_a_functor_passed_as_parameter_of_a_mock_method )
|
||||
{
|
||||
mock_class mock;
|
||||
MOCK_EXPECT( mock.method ).calls( boost::bind( boost::apply< void >(), _1, 42 ) ); // whenever 'method' is called, invoke the functor with 42
|
||||
function( mock );
|
||||
}
|
||||
//]
|
||||
54
doc/example/patterns_quick_constraint.cpp
Normal file
54
doc/example/patterns_quick_constraint.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ quick_constraint_problem
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
class my_class
|
||||
{
|
||||
public:
|
||||
explicit my_class( int data )
|
||||
: data_( data )
|
||||
{}
|
||||
int data_;
|
||||
};
|
||||
std::ostream& operator<<( std::ostream& os, const my_class& c ) // my_class is serializable to an std::ostream
|
||||
{
|
||||
return os << "my_class( " << c.data_ << " )";
|
||||
}
|
||||
|
||||
MOCK_CLASS( my_mock )
|
||||
{
|
||||
MOCK_METHOD( method, 1, void( const my_class& ) ) // how to simply write a custom constraint ?
|
||||
};
|
||||
}
|
||||
//]
|
||||
|
||||
//[ quick_constraint_solution
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
namespace mock // it could also be in the namespace of 'my_class'
|
||||
{
|
||||
bool operator==( const my_class& actual, const std::string& expected ) // the first part of the trick is to compare to a string
|
||||
{
|
||||
return boost::lexical_cast< std::string >( actual ) == expected;
|
||||
}
|
||||
} // mock
|
||||
|
||||
BOOST_AUTO_TEST_CASE( method_is_called )
|
||||
{
|
||||
my_mock mock;
|
||||
MOCK_EXPECT( mock.method ).once().with( "my_class( 42 )" ); // the second part of the trick is to express the constraint as a string
|
||||
mock.method( my_class( 42 ) );
|
||||
}
|
||||
//]
|
||||
50
doc/example/patterns_retrieve_cref.cpp
Normal file
50
doc/example/patterns_retrieve_cref.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//[ retrieve_cref_problem
|
||||
namespace
|
||||
{
|
||||
class base_class
|
||||
{
|
||||
public:
|
||||
virtual void method( int value ) = 0;
|
||||
};
|
||||
|
||||
class my_class
|
||||
{
|
||||
public:
|
||||
explicit my_class( base_class& );
|
||||
|
||||
void process(); // the processing will call 'method' two times with the same value, but we don't know what value beforehand
|
||||
};
|
||||
}
|
||||
//]
|
||||
|
||||
//[ retrieve_cref_solution
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
MOCK_BASE_CLASS( mock_base_class, base_class )
|
||||
{
|
||||
MOCK_METHOD( method, 1 )
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( method_is_called_two_times_with_the_same_value )
|
||||
{
|
||||
mock_base_class mock;
|
||||
my_class c( mock );
|
||||
int value;
|
||||
MOCK_EXPECT( mock.method ).once().with( mock::retrieve( value ) ); // on first call retrieve the value, this expectation takes precedence because it can never fail
|
||||
MOCK_EXPECT( mock.method ).once().with( boost::cref( value ) ); // on second call compare the previously retrieved value with the newly received one
|
||||
c.process();
|
||||
}
|
||||
//]
|
||||
20
doc/example/rationale.cpp
Normal file
20
doc/example/rationale.cpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <turtle/mock.hpp>
|
||||
#include "calculator.hpp"
|
||||
#include "mock_view.hpp"
|
||||
|
||||
//[ overflow_throws
|
||||
BOOST_AUTO_TEST_CASE( overflow_throws )
|
||||
{
|
||||
mock_view v;
|
||||
calculator c( v );
|
||||
BOOST_CHECK_THROW( c.add( (std::numeric_limits< int >::max)(), 1 ), std::exception );
|
||||
}
|
||||
//]
|
||||
984
doc/example/reference.cpp
Normal file
984
doc/example/reference.cpp
Normal file
|
|
@ -0,0 +1,984 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2014
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define BOOST_AUTO_TEST_MAIN
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
namespace class_example_1
|
||||
{
|
||||
//[ class_example_1
|
||||
MOCK_CLASS( mock_class )
|
||||
{};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_mock_class )
|
||||
{
|
||||
mock_class c;
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace class_example_2
|
||||
{
|
||||
//[ class_example_2
|
||||
template< typename T >
|
||||
MOCK_CLASS( mock_class )
|
||||
{};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_template_mock_class )
|
||||
{
|
||||
mock_class< int > c;
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace class_example_3
|
||||
{
|
||||
//[ class_example_3
|
||||
struct base_class
|
||||
{};
|
||||
|
||||
MOCK_BASE_CLASS( mock_class, base_class )
|
||||
{};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_derived_mock_class )
|
||||
{
|
||||
mock_class c;
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace class_example_4
|
||||
{
|
||||
//[ class_example_4
|
||||
template< typename T >
|
||||
struct base_class
|
||||
{};
|
||||
|
||||
template< typename T >
|
||||
MOCK_BASE_CLASS( mock_class, base_class< T > )
|
||||
{};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_template_derived_mock_class )
|
||||
{
|
||||
mock_class< int > c;
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace class_example_5
|
||||
{
|
||||
//[ class_example_5
|
||||
struct name : mock::object // equivalent to using MOCK_CLASS
|
||||
{};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace class_example_6
|
||||
{
|
||||
//[ class_example_6
|
||||
template< typename T >
|
||||
struct name : mock::object // equivalent to using MOCK_CLASS
|
||||
{};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace class_example_7
|
||||
{
|
||||
//[ class_example_7
|
||||
class base
|
||||
{};
|
||||
|
||||
struct name : base, mock::object // equivalent to using MOCK_BASE_CLASS
|
||||
{
|
||||
typedef base base_type; // this is required for the shortest form of MOCK_METHOD to work when not using MOCK_BASE_CLASS
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace class_example_8
|
||||
{
|
||||
//[ class_example_8
|
||||
template< typename T >
|
||||
struct base
|
||||
{};
|
||||
|
||||
template< typename T >
|
||||
struct mock : base< T >, mock::object
|
||||
{
|
||||
typedef typename base< T > base_type;
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace member_function_example_1
|
||||
{
|
||||
//[ member_function_example_1
|
||||
struct base_class
|
||||
{
|
||||
virtual ~base_class()
|
||||
{}
|
||||
virtual void method( int ) = 0;
|
||||
};
|
||||
|
||||
MOCK_BASE_CLASS( mock_class, base_class )
|
||||
{
|
||||
MOCK_METHOD( method, 1 ) // only possible when referring unambiguously to a base class method
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace member_function_example_2
|
||||
{
|
||||
//[ member_function_example_2
|
||||
struct base_class
|
||||
{
|
||||
virtual ~base_class()
|
||||
{}
|
||||
virtual void method( int, const std::string& ) = 0;
|
||||
virtual void method( float ) = 0;
|
||||
};
|
||||
|
||||
MOCK_BASE_CLASS( mock_class, base_class )
|
||||
{
|
||||
MOCK_METHOD( method, 2, void( int, const std::string& ), identifier_1 ) // both the signature and identifier must be specified because of ambiguity due to overloading
|
||||
MOCK_METHOD( method, 1, void( float ), identifier_2 ) // the identifier must differ from the previous one in order to fully disambiguate methods
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace member_function_example_3
|
||||
{
|
||||
//[ member_function_example_3
|
||||
struct base_class
|
||||
{
|
||||
virtual ~base_class()
|
||||
{}
|
||||
virtual void method( float ) = 0;
|
||||
virtual void method( float ) const = 0;
|
||||
};
|
||||
|
||||
MOCK_BASE_CLASS( mock_class, base_class )
|
||||
{
|
||||
MOCK_METHOD( method, 1, void( float ) ) // this generates both const and non-const versions
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace member_function_example_4
|
||||
{
|
||||
//[ member_function_example_4
|
||||
struct base_class
|
||||
{
|
||||
virtual ~base_class()
|
||||
{}
|
||||
virtual void method( float ) = 0;
|
||||
virtual void method( float ) const = 0;
|
||||
};
|
||||
|
||||
MOCK_BASE_CLASS( mock_class, base_class )
|
||||
{
|
||||
MOCK_CONST_METHOD( method, 1, void( float ), identifier_1 ) // this generates only the const version
|
||||
MOCK_NON_CONST_METHOD( method, 1, void( float ), identifier_2 ) // this generates only the non-const version, with a different identifier
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace member_function_example_5
|
||||
{
|
||||
//[ member_function_example_5
|
||||
struct base_class
|
||||
{
|
||||
virtual ~base_class()
|
||||
{}
|
||||
virtual void method( float ) = 0;
|
||||
};
|
||||
|
||||
struct mock_class : base_class
|
||||
{
|
||||
typedef base_class base_type; // this is required for MOCK_METHOD to work when not using MOCK_BASE_CLASS
|
||||
|
||||
MOCK_METHOD( method, 1 )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace member_function_example_6
|
||||
{
|
||||
//[ member_function_example_6
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_NON_CONST_METHOD( operator=, 1, mock_class&( const mock_class& ), assignment ) // operators require a custom identifier
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace member_function_example_7
|
||||
{
|
||||
//[ member_function_example_7
|
||||
template< typename T >
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD_TPL( method, 1, void( const T& ) ) // the _TPL variants must be used if the signature includes a template parameter of the class
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace member_function_example_8
|
||||
{
|
||||
//[ member_function_example_8
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( method, 0, (std::map< int, int >()) ) // the signature must be surrounded with round parenthesis if the return type contains a comma
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
namespace member_function_example_9
|
||||
{
|
||||
//[ member_function_example_9
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( __stdcall method, 0, void(), method ) // all parameters must be provided when specifying a different calling convention
|
||||
};
|
||||
//]
|
||||
}
|
||||
#elif defined( BOOST_GCC )
|
||||
namespace member_function_example_10
|
||||
{
|
||||
//[ member_function_example_10
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( __attribute((stdcall)) method, 0, void(), method ) // all parameters must be provided when specifying a different calling convention
|
||||
};
|
||||
//]
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace static_member_function_example_1
|
||||
{
|
||||
//[ static_member_function_example_1
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_STATIC_METHOD( method, 1, float( int ) )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace static_member_function_example_2
|
||||
{
|
||||
//[ static_member_function_example_2
|
||||
template< typename T >
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_STATIC_METHOD_TPL( method, 1, void( T ) )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
namespace static_member_function_example_3
|
||||
{
|
||||
//[ static_member_function_example_3
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_STATIC_METHOD( __stdcall method, 0, void(), method ) // all parameters must be provided when specifying a different calling convention
|
||||
};
|
||||
//]
|
||||
}
|
||||
#elif defined( BOOST_GCC )
|
||||
namespace static_member_function_example_4
|
||||
{
|
||||
//[ static_member_function_example_4
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_STATIC_METHOD( __attribute((stdcall)) method, 0, void(), method ) // all parameters must be provided when specifying a different calling convention
|
||||
};
|
||||
//]
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace constructor_example_1
|
||||
{
|
||||
//[ constructor_example_1
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_CONSTRUCTOR( mock_class, 2, ( int, const std::string& ), identifier )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace constructor_example_2
|
||||
{
|
||||
//[ constructor_example_2
|
||||
template< typename T >
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_CONSTRUCTOR( mock_class, 2, ( int, const std::string& ), identifier )
|
||||
MOCK_CONSTRUCTOR_TPL( mock_class, 2, ( T, const std::string& ), identifier )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
namespace constructor_example_3
|
||||
{
|
||||
//[ constructor_example_3
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_CONSTRUCTOR( __stdcall mock_class, 0, (), constructor )
|
||||
};
|
||||
//]
|
||||
}
|
||||
#elif defined( BOOST_GCC )
|
||||
namespace constructor_example_4
|
||||
{
|
||||
//[ constructor_example_4
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_CONSTRUCTOR( __attribute((stdcall)) mock_class, 0, (), constructor )
|
||||
};
|
||||
//]
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace destructor_example_1
|
||||
{
|
||||
//[ destructor_example_1
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_DESTRUCTOR( ~mock_class, destructor )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
namespace destructor_example_2
|
||||
{
|
||||
//[ destructor_example_2
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_DESTRUCTOR( __stdcall ~mock_class, destructor )
|
||||
};
|
||||
//]
|
||||
}
|
||||
#elif defined( BOOST_GCC )
|
||||
namespace destructor_example_3
|
||||
{
|
||||
//[ destructor_example_3
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_DESTRUCTOR( __attribute((stdcall)) ~mock_class, destructor )
|
||||
};
|
||||
//]
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace conversion_operator_example_1
|
||||
{
|
||||
//[ conversion_operator_example_1
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_CONVERSION_OPERATOR( operator, int, conversion_to_int )
|
||||
MOCK_CONST_CONVERSION_OPERATOR( operator, const std::string&, conversion_to_string )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
namespace conversion_operator_example_2
|
||||
{
|
||||
//[ conversion_operator_example_2
|
||||
template< typename T >
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_CONVERSION_OPERATOR_TPL( operator, T, conversion_to_T ) // the _TPL variants must be used if the signature includes a template parameter of the class
|
||||
MOCK_CONST_CONVERSION_OPERATOR( operator, const std::string&, const_conversion_to_string )
|
||||
MOCK_NON_CONST_CONVERSION_OPERATOR( operator, const std::string&, non_const_conversion_to_string )
|
||||
};
|
||||
//]
|
||||
}
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
namespace conversion_operator_example_3
|
||||
{
|
||||
//[ conversion_operator_example_3
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_CONVERSION_OPERATOR( __stdcall operator, int, conversion_to_int )
|
||||
};
|
||||
//]
|
||||
}
|
||||
#elif defined( BOOST_GCC )
|
||||
namespace conversion_operator_example_4
|
||||
{
|
||||
//[ conversion_operator_example_4
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_CONVERSION_OPERATOR( __attribute((stdcall)) operator, int, conversion_to_int )
|
||||
};
|
||||
//]
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace function_example_1
|
||||
{
|
||||
//[ function_example_1
|
||||
MOCK_FUNCTION( f, 1, float( int ) )
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_mock_function )
|
||||
{
|
||||
f( 3 );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
namespace function_example_2
|
||||
{
|
||||
//[ function_example_2
|
||||
MOCK_FUNCTION( __stdcall f, 0, void(), f ) // all parameters must be provided when specifying a different calling convention
|
||||
//]
|
||||
}
|
||||
#elif defined( BOOST_GCC )
|
||||
namespace function_example_3
|
||||
{
|
||||
//[ function_example_3
|
||||
MOCK_FUNCTION( __attribute((stdcall)) f, 0, void(), f ) // all parameters must be provided when specifying a different calling convention
|
||||
//]
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace functor_example_1
|
||||
{
|
||||
//[ functor_example_1
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_mock_functor )
|
||||
{
|
||||
MOCK_FUNCTOR( f, void( int ) );
|
||||
f( 3 );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace functor_example_2
|
||||
{
|
||||
//[ functor_example_2
|
||||
template< typename T >
|
||||
struct mock_class
|
||||
{
|
||||
MOCK_FUNCTOR_TPL( f, void( T ) );
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_instantiating_a_mock_functor )
|
||||
{
|
||||
mock_class< int > c;
|
||||
c.f( 3 );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace expectation_example_1
|
||||
{
|
||||
//[ expectation_example_1
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( method, 1, int( int ), method )
|
||||
MOCK_METHOD( method, 2, void( const std::string&, float ), method2 )
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_configuring_mock_objects )
|
||||
{
|
||||
mock_class c;
|
||||
mock::sequence s;
|
||||
MOCK_EXPECT( c.method ).once().with( 0 ).in( s ).returns( 42 );
|
||||
MOCK_EXPECT( c.method2 ).never().with( "ok", mock::any );
|
||||
MOCK_EXPECT( c.method2 ).at_least( 2 ).in( s ).throws( std::runtime_error( "error !" ) );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace invocation_example_1
|
||||
{
|
||||
//[ invocation_example_1
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( method, 2, void( int, const std::string& ) )
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_setting_up_invocations_on_a_mock_method )
|
||||
{
|
||||
mock_class c;
|
||||
MOCK_EXPECT( c.method ).once(); // can only be called once
|
||||
MOCK_EXPECT( c.method ); // can be called an unlimited number of times
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace invocation_example_2
|
||||
{
|
||||
//[ invocation_example_2
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_setting_up_an_invocation_on_a_mock_functor )
|
||||
{
|
||||
MOCK_FUNCTOR( f, void( int, const std::string& ) );
|
||||
MOCK_EXPECT( f ).once();
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace invocation_example_3
|
||||
{
|
||||
//[ invocation_example_3
|
||||
MOCK_FUNCTION( f, 1, void( int ) )
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_setting_up_an_invocation_on_a_mock_function )
|
||||
{
|
||||
MOCK_EXPECT( f ).once();
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace invocation_example_4
|
||||
{
|
||||
//[ invocation_example_4
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_STATIC_METHOD( method, 1, void( int ) )
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_setting_up_an_invocation_on_a_mock_static_method )
|
||||
{
|
||||
mock_class c;
|
||||
MOCK_EXPECT( c.method ).once();
|
||||
MOCK_EXPECT( mock_class::method ).once(); // does the same
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace constraints_example_1
|
||||
{
|
||||
//[ constraints_example_1
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( method, 2, void( int, const std::string& ) )
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_adding_builtin_constraints )
|
||||
{
|
||||
mock_class c;
|
||||
MOCK_EXPECT( c.method ).with( mock::equal( 3 ), mock::equal( "some string" ) );
|
||||
MOCK_EXPECT( c.method ).with( 3, "some string" ); // equivalent to the previous one using short-cuts
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace constraints_example_2
|
||||
{
|
||||
//[ constraints_example_2
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( method, 1, void( int ) )
|
||||
};
|
||||
|
||||
bool custom_constraint( int actual )
|
||||
{
|
||||
return actual == 42;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_adding_a_custom_constraint_with_a_free_function )
|
||||
{
|
||||
mock_class c;
|
||||
MOCK_EXPECT( c.method ).with( &custom_constraint );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace constraints_example_3
|
||||
{
|
||||
//[ constraints_example_3
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( method, 1, void( int ) )
|
||||
};
|
||||
|
||||
bool custom_constraint( int expected, int actual )
|
||||
{
|
||||
return expected == actual;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_adding_a_custom_constraint_with_a_standard_library_functor )
|
||||
{
|
||||
mock_class c;
|
||||
MOCK_EXPECT( c.method ).with( std::bind1st( std::ptr_fun( &custom_constraint ), 42 ) ); // std::ptr_fun creates an std::unary_function
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace constraints_example_4
|
||||
{
|
||||
//[ constraints_example_4
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( method, 1, void( int ) )
|
||||
};
|
||||
|
||||
bool custom_constraint( int expected, int actual )
|
||||
{
|
||||
return expected == actual;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_adding_a_custom_constraint_with_boost_bind )
|
||||
{
|
||||
mock_class c;
|
||||
MOCK_EXPECT( c.method ).with( boost::bind( &custom_constraint, 42, _1 ) );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
#ifndef BOOST_MSVC // this produces an ICE with all versions of MSVC
|
||||
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
|
||||
namespace constraints_example_5
|
||||
{
|
||||
//[ constraints_example_5
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( method, 1, void( int ) )
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_adding_a_custom_constraint_with_boost_lambda )
|
||||
{
|
||||
mock_class c;
|
||||
MOCK_EXPECT( c.method ).with( boost::lambda::_1 == 42 );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
#endif // BOOST_MSVC
|
||||
|
||||
#include <boost/phoenix/phoenix.hpp>
|
||||
|
||||
namespace constraints_example_6
|
||||
{
|
||||
//[ constraints_example_6
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( method, 1, void( int ) )
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_adding_a_custom_constraint_with_boost_phoenix )
|
||||
{
|
||||
mock_class c;
|
||||
MOCK_EXPECT( c.method ).with( boost::phoenix::arg_names::arg1 == 42 );
|
||||
MOCK_EXPECT( c.method ).with( boost::phoenix::arg_names::_1 == 42 );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
#ifdef MOCK_LAMBDAS
|
||||
|
||||
namespace constraints_example_7
|
||||
{
|
||||
//[ constraints_example_7
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( method, 1, void( int ) )
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_adding_a_constraint_with_cxx11_lambda )
|
||||
{
|
||||
mock_class c;
|
||||
MOCK_EXPECT( c.method ).with( []( int actual ) { return 42 == actual; } );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
namespace constraints_example_8
|
||||
{
|
||||
//[ constraints_example_8
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( method, 2, void( int, const std::string& ) )
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_combining_constraints )
|
||||
{
|
||||
mock_class c;
|
||||
MOCK_EXPECT( c.method ).with( mock::less( 4 ) && mock::greater( 2 ), ! mock::equal( "" ) );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace sequence_example_1
|
||||
{
|
||||
//[ sequence_example_1
|
||||
MOCK_CLASS( mock_class_1 )
|
||||
{
|
||||
MOCK_METHOD( method_1, 0, void() )
|
||||
};
|
||||
|
||||
MOCK_CLASS( mock_class_2 )
|
||||
{
|
||||
MOCK_METHOD( method_2, 0, void() )
|
||||
};
|
||||
|
||||
MOCK_CLASS( mock_class_3 )
|
||||
{
|
||||
MOCK_METHOD( method_3, 0, void() )
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_enforcing_several_expectation_orders )
|
||||
{
|
||||
mock_class_1 c_1;
|
||||
mock_class_2 c_2;
|
||||
mock_class_3 c_3;
|
||||
mock::sequence s_1, s_2;
|
||||
MOCK_EXPECT( c_1.method_1 ).in( s_1 );
|
||||
MOCK_EXPECT( c_2.method_2 ).in( s_2 ); // c_1.method_1 and c_2.method_2 are in different sequences and can be called in any order
|
||||
MOCK_EXPECT( c_3.method_3 ).in( s_1, s_2 ); // c_3.method_3 must be called after both c_1.method_1 and c_2.method_2
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace action_example_1
|
||||
{
|
||||
//[ action_example_1
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( method, 1, int( int ) )
|
||||
};
|
||||
|
||||
int function( int i )
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_configuring_actions )
|
||||
{
|
||||
mock_class c;
|
||||
MOCK_EXPECT( c.method ).returns( 42 );
|
||||
MOCK_EXPECT( c.method ).moves( 42 ); // returns by moving the value
|
||||
MOCK_EXPECT( c.method ).throws( std::runtime_error( "error !" ) );
|
||||
MOCK_EXPECT( c.method ).calls( &function ); // forwards 'method' parameter to 'function'
|
||||
MOCK_EXPECT( c.method ).calls( boost::bind( &function, 42 ) ); // drops 'method' parameter and binds 42 as parameter to 'function'
|
||||
MOCK_EXPECT( c.method ).calls( []( int i ) { return i; } ); // uses a C++11 lambda
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace verification_example_1
|
||||
{
|
||||
//[ verification_example_1
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( method, 0, void() )
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_verifying_a_mock_method )
|
||||
{
|
||||
mock_class c;
|
||||
MOCK_VERIFY( c.method ); // logs an error and returns false if not all expectations are met
|
||||
mock::verify( c ); // verifies all expectations set for all methods of 'c'
|
||||
mock::verify(); // verifies all existing mock objects, functions and functors
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace verification_example_2
|
||||
{
|
||||
//[ verification_example_2
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_verifying_a_mock_functor )
|
||||
{
|
||||
MOCK_FUNCTOR( f, void( int ) );
|
||||
MOCK_VERIFY( f ); // logs an error and returns false if not all expectations are met
|
||||
mock::verify( f ); // behaves the same as MOCK_VERIFY
|
||||
mock::verify(); // verifies all existing mock objects, functions and functors
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace verification_example_3
|
||||
{
|
||||
//[ verification_example_3
|
||||
MOCK_FUNCTION( f, 1, void( int ) )
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_verifying_a_mock_function )
|
||||
{
|
||||
MOCK_VERIFY( f ); // logs an error and returns false if not all expectations are met
|
||||
mock::verify(); // verifies all existing mock objects, functions and functors
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace verification_example_4
|
||||
{
|
||||
//[ verification_example_4
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_STATIC_METHOD( method, 0, void() )
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_verifying_a_static_mock_method )
|
||||
{
|
||||
mock_class c;
|
||||
MOCK_VERIFY( c.method ); // logs an error and returns false if not all expectations are met
|
||||
MOCK_VERIFY( mock_class::method ); // does the same
|
||||
mock::verify(); // verifies all existing mock objects, functions and functors
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace reset_example_1
|
||||
{
|
||||
//[ reset_example_1
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_METHOD( method, 0, void() )
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_resetting_a_mock_method )
|
||||
{
|
||||
mock_class c;
|
||||
MOCK_RESET( c.method ); // resets all expectations set for 'c.method'
|
||||
mock::reset( c ); // resets all expectations set on 'c'
|
||||
mock::reset(); // resets all existing mock objects, functions and functors
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace reset_example_2
|
||||
{
|
||||
//[ reset_example_2
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_resetting_a_mock_functor )
|
||||
{
|
||||
MOCK_FUNCTOR( f, void( int ) );
|
||||
MOCK_RESET( f ); // resets all expectations set for 'f'
|
||||
mock::reset( f ); // behaves the same as MOCK_RESET
|
||||
mock::reset(); // resets all existing mock objects, functions and functors
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace reset_example_3
|
||||
{
|
||||
//[ reset_example_3
|
||||
MOCK_FUNCTION( f, 1, void( int ) )
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_resetting_a_mock_function )
|
||||
{
|
||||
MOCK_RESET( f ); // resets all expectations set for 'f'
|
||||
mock::reset(); // resets all existing mock objects, functions and functors
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace reset_example_4
|
||||
{
|
||||
//[ reset_example_4
|
||||
MOCK_CLASS( mock_class )
|
||||
{
|
||||
MOCK_STATIC_METHOD( method, 0, void() )
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( demonstrates_resetting_a_static_mock_method )
|
||||
{
|
||||
mock_class c;
|
||||
MOCK_RESET( c.method ); // resets all expectations set for 'c::method'
|
||||
MOCK_RESET( mock_class::method ); // resets all expectations set for 'c::method'
|
||||
mock::reset(); // resets all existing mock objects, functions and functors
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace helpers_example_1
|
||||
{
|
||||
//[ helpers_example_1
|
||||
MOCK_CONSTRAINT( any, true ) // this is how mock::any could be defined
|
||||
MOCK_CONSTRAINT( forty_two, actual == 42 ) // this defines a 'forty_two' constraint
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mock_constraint_0_arity )
|
||||
{
|
||||
MOCK_FUNCTOR( f, void( int ) );
|
||||
MOCK_EXPECT( f ).with( forty_two );
|
||||
MOCK_EXPECT( f ).with( any );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace helpers_example_2
|
||||
{
|
||||
//[ helpers_example_2
|
||||
MOCK_CONSTRAINT( equal, expected, actual == expected ) // this is how mock::equal could be defined
|
||||
MOCK_CONSTRAINT( near, expected, std::abs( actual - expected ) < 0.01 ) // this defines a 'near' constraint which can be used as 'near( 42 )'
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mock_constraint_1_arity )
|
||||
{
|
||||
MOCK_FUNCTOR( f, void( int ) );
|
||||
MOCK_EXPECT( f ).with( near( 42 ) );
|
||||
MOCK_EXPECT( f ).with( equal( 42 ) );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace helpers_example_3
|
||||
{
|
||||
//[ helpers_example_3
|
||||
MOCK_CONSTRAINT( near, expected, tolerance, std::abs( actual - expected ) < tolerance ) // this is how mock::near could be defined
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mock_constraint_2_arity )
|
||||
{
|
||||
MOCK_FUNCTOR( f, void( int ) );
|
||||
MOCK_EXPECT( f ).with( near( 42, 0.001 ) );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace helpers_example_4
|
||||
{
|
||||
//[ helpers_example_4
|
||||
MOCK_CONSTRAINT_EXT( any, 0,, true ) // this is (almost) how mock::any is defined
|
||||
MOCK_CONSTRAINT_EXT( forty_two, 0,, actual == 42 ) // this defines a 'forty_two' constraint
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mock_constraint_0_arity )
|
||||
{
|
||||
MOCK_FUNCTOR( f, void( int ) );
|
||||
MOCK_EXPECT( f ).with( forty_two );
|
||||
MOCK_EXPECT( f ).with( any );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace helpers_example_5
|
||||
{
|
||||
//[ helpers_example_5
|
||||
MOCK_CONSTRAINT_EXT( equal, 1, ( expected ), actual == expected ) // this is how mock::equal is defined
|
||||
MOCK_CONSTRAINT_EXT( near, 1, ( expected ), std::abs( actual - expected ) < 0.01 ) // this defines a 'near' constraint which can be used as 'near( 42 )'
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mock_constraint_1_arity )
|
||||
{
|
||||
MOCK_FUNCTOR( f, void( int ) );
|
||||
MOCK_EXPECT( f ).with( near( 42 ) );
|
||||
MOCK_EXPECT( f ).with( equal( 42 ) );
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
||||
namespace helpers_example_6
|
||||
{
|
||||
//[ helpers_example_6
|
||||
MOCK_CONSTRAINT_EXT( near, 2, ( expected, tolerance ), std::abs( actual - expected ) < tolerance ) // this is how mock::near is defined
|
||||
|
||||
BOOST_AUTO_TEST_CASE( mock_constraint_2_arity )
|
||||
{
|
||||
MOCK_FUNCTOR( f, void( int ) );
|
||||
MOCK_EXPECT( f ).with( near( 42, 0.001 ) );
|
||||
}
|
||||
//]
|
||||
}
|
||||
20
doc/example/view.hpp
Normal file
20
doc/example/view.hpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// http://turtle.sourceforge.net
|
||||
//
|
||||
// Copyright Mathieu Champlon 2012
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef VIEW
|
||||
#define VIEW
|
||||
|
||||
//[ view
|
||||
class view
|
||||
{
|
||||
public:
|
||||
virtual void display( int result ) = 0;
|
||||
};
|
||||
//]
|
||||
|
||||
#endif // VIEW
|
||||
Loading…
Add table
Add a link
Reference in a new issue