Changed layout to match boost

This commit is contained in:
Mathieu Champlon 2015-03-04 06:23:30 +01:00
parent 7a8ba352c6
commit c950c24f52
122 changed files with 15469 additions and 15550 deletions

50
test/Jamfile.jam Normal file
View file

@ -0,0 +1,50 @@
# Boost.Mock
#
# 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)
import testing ;
project
: requirements
<define>BOOST_AUTO_TEST_MAIN
<define>BOOST_ALL_NO_LIB
<include>../include
;
path-constant parent : .. ;
alias mock_inspect :
[ run /boost/tools/inspect//inspect/<variant>release
: $(parent) -text -brief : : : inspect
]
;
rule run-test ( name )
{
run $(name) undefined.cpp /boost//unit_test_framework : : : : $(name)_ ;
run $(name) undefined.cpp /boost//unit_test_framework : : : <define>MOCK_MAX_ARGS=21 : $(name)_max_args ;
run $(name) undefined.cpp /boost//unit_test_framework : : : <define>MOCK_USE_CONVERSIONS : $(name)_use_conversions ;
run $(name) undefined.cpp /boost//unit_test_framework : : : <define>MOCK_NO_DECLTYPE : $(name)_no_decltype ;
run $(name) undefined.cpp /boost//unit_test_framework : : : <define>MOCK_NO_VARIADIC_MACROS : $(name)_no_variadic_macros ;
run $(name) undefined.cpp /boost//unit_test_framework /boost//thread : : : <define>MOCK_THREAD_SAFE <define>BOOST_THREAD_USES_MOVE : $(name)_thread_safe ;
}
rule run-tests
{
for name in [ glob test_*.cpp detail/test_*.cpp ] { run-test $(name) ; }
}
alias mock_tests : [ run-tests ] ;
rule run-failures
{
for name in [ glob fail_*.cpp ] { compile-fail $(name) ; }
}
alias mock_failures : [ run-failures ] ;
# How to time bench_*.cpp compilation ?

View file

@ -1,14 +1,14 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
int main()
{
return 0;
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
int main()
{
return 0;
}

View file

@ -1,10 +1,10 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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 MOCK_MAX_ARGS 10
#include <turtle/mock.hpp>
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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 MOCK_MAX_ARGS 10
#include <turtle/mock.hpp>

View file

@ -1,10 +1,10 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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 MOCK_MAX_ARGS 20
#include <turtle/mock.hpp>
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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 MOCK_MAX_ARGS 20
#include <turtle/mock.hpp>

View file

@ -1,10 +1,10 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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 MOCK_MAX_ARGS 30
#include <turtle/mock.hpp>
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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 MOCK_MAX_ARGS 30
#include <turtle/mock.hpp>

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,76 +1,76 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// 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/detail/invocation.hpp>
#include <boost/test/auto_unit_test.hpp>
BOOST_AUTO_TEST_CASE( unlimited )
{
mock::detail::unlimited invocation;
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
}
BOOST_AUTO_TEST_CASE( once )
{
mock::detail::once invocation;
BOOST_CHECK( ! invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( invocation.exhausted() );
BOOST_CHECK( ! invocation.invoke() );
}
BOOST_AUTO_TEST_CASE( never )
{
mock::detail::never invocation;
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( invocation.exhausted() );
BOOST_CHECK( ! invocation.invoke() );
}
BOOST_AUTO_TEST_CASE( at_most )
{
mock::detail::at_most invocation( 1 );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( invocation.exhausted() );
BOOST_CHECK( ! invocation.invoke() );
}
BOOST_AUTO_TEST_CASE( at_least )
{
mock::detail::at_least invocation( 1 );
BOOST_CHECK( ! invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
}
BOOST_AUTO_TEST_CASE( between )
{
mock::detail::between invocation( 1, 2 );
BOOST_CHECK( ! invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( invocation.exhausted() );
BOOST_CHECK( ! invocation.invoke() );
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// 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/detail/invocation.hpp>
#include <boost/test/auto_unit_test.hpp>
BOOST_AUTO_TEST_CASE( unlimited )
{
mock::detail::unlimited invocation;
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
}
BOOST_AUTO_TEST_CASE( once )
{
mock::detail::once invocation;
BOOST_CHECK( ! invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( invocation.exhausted() );
BOOST_CHECK( ! invocation.invoke() );
}
BOOST_AUTO_TEST_CASE( never )
{
mock::detail::never invocation;
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( invocation.exhausted() );
BOOST_CHECK( ! invocation.invoke() );
}
BOOST_AUTO_TEST_CASE( at_most )
{
mock::detail::at_most invocation( 1 );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( invocation.exhausted() );
BOOST_CHECK( ! invocation.invoke() );
}
BOOST_AUTO_TEST_CASE( at_least )
{
mock::detail::at_least invocation( 1 );
BOOST_CHECK( ! invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
}
BOOST_AUTO_TEST_CASE( between )
{
mock::detail::between invocation( 1, 2 );
BOOST_CHECK( ! invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( invocation.exhausted() );
BOOST_CHECK( ! invocation.invoke() );
}

View file

@ -1,155 +1,155 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2009
//
// 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/detail/is_functor.hpp>
#include <boost/test/auto_unit_test.hpp>
#ifdef BOOST_MSVC
#pragma warning( push, 0 )
#endif
#include <boost/lambda/lambda.hpp>
#include <boost/phoenix/phoenix.hpp>
#ifdef BOOST_MSVC
#pragma warning( pop )
#endif
#include <boost/function.hpp>
#include <boost/bind.hpp>
namespace
{
struct declared_but_not_defined;
BOOST_MPL_ASSERT_NOT((
mock::detail::is_functor< declared_but_not_defined, int > ));
template< typename T >
void is_functor( T )
{
BOOST_MPL_ASSERT(( mock::detail::is_functor< T, int > ));
}
template< typename T >
void is_not_functor( T )
{
BOOST_MPL_ASSERT_NOT(( mock::detail::is_functor< T, int > ));
}
void f0() {}
bool f1( int ) { return false; }
bool f2( std::string, int ) { return false; }
}
BOOST_AUTO_TEST_CASE( data_is_not_functor )
{
is_not_functor( 42 );
}
BOOST_AUTO_TEST_CASE( function_is_functor )
{
is_functor( f0 );
is_functor( f1 );
is_functor( f2 );
}
BOOST_AUTO_TEST_CASE( function_pointer_is_functor )
{
is_functor( &f0 );
is_functor( &f1 );
is_functor( &f2 );
}
BOOST_AUTO_TEST_CASE( std_ptr_fun_is_functor )
{
is_functor( std::ptr_fun( &f1 ) );
is_functor( std::ptr_fun( &f2 ) );
}
BOOST_AUTO_TEST_CASE( std_bind_first_is_functor )
{
is_functor( std::bind1st( std::ptr_fun( &f2 ), "" ) );
}
namespace
{
struct unary_functor0 : public std::unary_function< void, void >
{};
struct unary_functor1 : public std::unary_function< int, void >
{};
}
BOOST_AUTO_TEST_CASE( std_unary_functor_is_functor )
{
is_functor( unary_functor0() );
is_functor( unary_functor1() );
}
BOOST_AUTO_TEST_CASE( boost_bind_is_functor )
{
is_functor( boost::bind( &f0 ) );
is_functor( boost::bind( &f1, _1 ) );
is_functor( boost::bind( &f2, "", _1 ) );
}
BOOST_AUTO_TEST_CASE( boost_lambda_is_functor )
{
is_functor( boost::lambda::_1 < 42 );
}
BOOST_AUTO_TEST_CASE( boost_phoenix_is_functor )
{
is_functor( boost::phoenix::arg_names::arg1 < 42 );
is_functor( boost::phoenix::arg_names::_1 < 42 );
}
BOOST_AUTO_TEST_CASE( boost_function_is_functor )
{
is_functor( boost::function< void() >() );
}
namespace
{
struct result_type_functor
{
typedef void result_type;
};
}
BOOST_AUTO_TEST_CASE( class_with_result_type_is_functor )
{
is_functor( result_type_functor() );
}
namespace
{
struct sig_functor
{
template< typename Args >
struct sig
{
typedef void type;
};
};
}
BOOST_AUTO_TEST_CASE( class_with_sig_is_functor )
{
is_functor( sig_functor() );
}
#ifdef MOCK_LAMBDAS
BOOST_AUTO_TEST_CASE( cxx11_lambda_is_functor )
{
is_not_functor( []() {} );
#ifdef MOCK_DECLTYPE
is_functor( []( int ) {} );
#else
is_not_functor( []( int ) {} );
#endif
is_not_functor( []( const std::string&, int ) {} );
is_not_functor( []( int, const std::string& ) {} );
}
#endif
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2009
//
// 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/detail/is_functor.hpp>
#include <boost/test/auto_unit_test.hpp>
#ifdef BOOST_MSVC
#pragma warning( push, 0 )
#endif
#include <boost/lambda/lambda.hpp>
#include <boost/phoenix/phoenix.hpp>
#ifdef BOOST_MSVC
#pragma warning( pop )
#endif
#include <boost/function.hpp>
#include <boost/bind.hpp>
namespace
{
struct declared_but_not_defined;
BOOST_MPL_ASSERT_NOT((
mock::detail::is_functor< declared_but_not_defined, int > ));
template< typename T >
void is_functor( T )
{
BOOST_MPL_ASSERT(( mock::detail::is_functor< T, int > ));
}
template< typename T >
void is_not_functor( T )
{
BOOST_MPL_ASSERT_NOT(( mock::detail::is_functor< T, int > ));
}
void f0() {}
bool f1( int ) { return false; }
bool f2( std::string, int ) { return false; }
}
BOOST_AUTO_TEST_CASE( data_is_not_functor )
{
is_not_functor( 42 );
}
BOOST_AUTO_TEST_CASE( function_is_functor )
{
is_functor( f0 );
is_functor( f1 );
is_functor( f2 );
}
BOOST_AUTO_TEST_CASE( function_pointer_is_functor )
{
is_functor( &f0 );
is_functor( &f1 );
is_functor( &f2 );
}
BOOST_AUTO_TEST_CASE( std_ptr_fun_is_functor )
{
is_functor( std::ptr_fun( &f1 ) );
is_functor( std::ptr_fun( &f2 ) );
}
BOOST_AUTO_TEST_CASE( std_bind_first_is_functor )
{
is_functor( std::bind1st( std::ptr_fun( &f2 ), "" ) );
}
namespace
{
struct unary_functor0 : public std::unary_function< void, void >
{};
struct unary_functor1 : public std::unary_function< int, void >
{};
}
BOOST_AUTO_TEST_CASE( std_unary_functor_is_functor )
{
is_functor( unary_functor0() );
is_functor( unary_functor1() );
}
BOOST_AUTO_TEST_CASE( boost_bind_is_functor )
{
is_functor( boost::bind( &f0 ) );
is_functor( boost::bind( &f1, _1 ) );
is_functor( boost::bind( &f2, "", _1 ) );
}
BOOST_AUTO_TEST_CASE( boost_lambda_is_functor )
{
is_functor( boost::lambda::_1 < 42 );
}
BOOST_AUTO_TEST_CASE( boost_phoenix_is_functor )
{
is_functor( boost::phoenix::arg_names::arg1 < 42 );
is_functor( boost::phoenix::arg_names::_1 < 42 );
}
BOOST_AUTO_TEST_CASE( boost_function_is_functor )
{
is_functor( boost::function< void() >() );
}
namespace
{
struct result_type_functor
{
typedef void result_type;
};
}
BOOST_AUTO_TEST_CASE( class_with_result_type_is_functor )
{
is_functor( result_type_functor() );
}
namespace
{
struct sig_functor
{
template< typename Args >
struct sig
{
typedef void type;
};
};
}
BOOST_AUTO_TEST_CASE( class_with_sig_is_functor )
{
is_functor( sig_functor() );
}
#ifdef MOCK_LAMBDAS
BOOST_AUTO_TEST_CASE( cxx11_lambda_is_functor )
{
is_not_functor( []() {} );
#ifdef MOCK_DECLTYPE
is_functor( []( int ) {} );
#else
is_not_functor( []( int ) {} );
#endif
is_not_functor( []( const std::string&, int ) {} );
is_not_functor( []( int, const std::string& ) {} );
}
#endif

View file

@ -1,29 +1,29 @@
// 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)
#include <turtle/detail/signature.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <boost/mpl/assert.hpp>
namespace
{
struct base
{
void method_1();
float method_2( int ) const;
};
typedef base base_type;
}
BOOST_AUTO_TEST_CASE( mock_signature_generates_signature )
{
BOOST_MPL_ASSERT((
boost::is_same< void(), MOCK_SIGNATURE( method_1 ) > ));
BOOST_MPL_ASSERT((
boost::is_same< float( int ), MOCK_SIGNATURE( method_2 ) > ));
}
// 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)
#include <turtle/detail/signature.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <boost/mpl/assert.hpp>
namespace
{
struct base
{
void method_1();
float method_2( int ) const;
};
typedef base base_type;
}
BOOST_AUTO_TEST_CASE( mock_signature_generates_signature )
{
BOOST_MPL_ASSERT((
boost::is_same< void(), MOCK_SIGNATURE( method_1 ) > ));
BOOST_MPL_ASSERT((
boost::is_same< float( int ), MOCK_SIGNATURE( method_2 ) > ));
}

View file

@ -1,225 +1,225 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// 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/detail/type_name.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <boost/lexical_cast.hpp>
namespace
{
template< typename T >
std::string to_string( const T& )
{
return boost::lexical_cast< std::string >( MOCK_TYPE_NAME(T) );
}
}
BOOST_AUTO_TEST_CASE( name_of_base_type_is_extracted )
{
BOOST_CHECK_EQUAL( "char", to_string( 'a' ) );
BOOST_CHECK_EQUAL( "bool", to_string( true ) );
BOOST_CHECK_EQUAL( "int", to_string< int >( 0 ) );
BOOST_CHECK_EQUAL( "short", to_string< short >( 0 ) );
BOOST_CHECK_EQUAL( "long", to_string< long >( 0 ) );
BOOST_CHECK_EQUAL( "unsigned int", to_string< unsigned int >( 0 ) );
BOOST_CHECK_EQUAL( "unsigned short", to_string< unsigned short >( 0 ) );
BOOST_CHECK_EQUAL( "unsigned long", to_string< unsigned long >( 0 ) );
}
struct my_type_in_default_namespace
{
struct inner {};
};
BOOST_AUTO_TEST_CASE( name_of_type_in_default_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_type_in_default_namespace", to_string( my_type_in_default_namespace() ) );
}
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_type_in_default_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "inner", to_string( my_type_in_default_namespace::inner() ) );
}
template< typename T >
struct my_template_type_in_default_namespace
{
struct inner {};
};
BOOST_AUTO_TEST_CASE( name_of_template_type_in_default_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_template_type_in_default_namespace<int>", to_string( my_template_type_in_default_namespace<int>() ) );
}
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_default_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type_in_default_namespace<int>::inner() ) );
}
namespace
{
struct my_type_in_anonymous_namespace {};
}
BOOST_AUTO_TEST_CASE( name_of_type_in_anonymous_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_type_in_anonymous_namespace", to_string( my_type_in_anonymous_namespace() ) );
}
namespace nm
{
struct my_type_from_named_namespace {};
}
BOOST_AUTO_TEST_CASE( name_of_type_from_named_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_type_from_named_namespace", to_string( nm::my_type_from_named_namespace() ) );
}
namespace nm
{
namespace inner
{
struct my_type_in_named_inner_namespace {};
}
}
BOOST_AUTO_TEST_CASE( name_of_type_in_named_inner_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_type_in_named_inner_namespace", to_string( nm::inner::my_type_in_named_inner_namespace() ) );
}
namespace
{
namespace inner
{
struct my_type_in_unnamed_inner_namespace {};
}
}
BOOST_AUTO_TEST_CASE( name_of_type_in_unnamed_inner_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_type_in_unnamed_inner_namespace", to_string( inner::my_type_in_unnamed_inner_namespace() ) );
}
BOOST_AUTO_TEST_CASE( name_of_local_type_is_extracted )
{
struct my_local_type {};
BOOST_CHECK_EQUAL( "my_local_type", boost::lexical_cast< std::string >( MOCK_TYPE_NAME(my_local_type) ) );
}
namespace
{
template< typename T >
struct my_template_type
{
struct inner {};
};
}
BOOST_AUTO_TEST_CASE( name_of_template_type_in_anonymous_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_template_type<int>", to_string( my_template_type< int >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception>", to_string( my_template_type< std::exception >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const&>", to_string( my_template_type< int const& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const&>", to_string( my_template_type< std::exception const& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const*>", to_string( my_template_type< int const* >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const*>", to_string( my_template_type< std::exception const* >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const*&>", to_string( my_template_type< int const*& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const*&>", to_string( my_template_type< std::exception const*& >() ) );
}
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_anonymous_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int const& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception const& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int const* >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception const* >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int const*& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception const*& >::inner() ) );
}
namespace nm
{
template< typename T >
struct my_template_type
{
struct inner {};
};
}
BOOST_AUTO_TEST_CASE( name_of_template_type_in_named_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_template_type<int>", to_string( nm::my_template_type< int >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception>", to_string( nm::my_template_type< std::exception >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const&>", to_string( nm::my_template_type< int const& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const&>", to_string( nm::my_template_type< std::exception const& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const*>", to_string( nm::my_template_type< int const* >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const*>", to_string( nm::my_template_type< std::exception const* >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const*&>", to_string( nm::my_template_type< int const*& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const*&>", to_string( nm::my_template_type< std::exception const*& >() ) );
}
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_named_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int const& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception const& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int const* >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception const* >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int const*& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception const*& >::inner() ) );
}
namespace nm2
{
template< typename T >
struct my_template_type
{
template< typename U >
struct inner {};
};
}
BOOST_AUTO_TEST_CASE( name_of_template_inner_type_from_template_type_in_named_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int const& >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception const& >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int const* >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception const* >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int const*& >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception const*& >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int const&>", to_string( nm2::my_template_type< int >::inner< int const& >() ) );
BOOST_CHECK_EQUAL( "inner<int const&>", to_string( nm2::my_template_type< std::exception >::inner< int const& >() ) );
BOOST_CHECK_EQUAL( "inner<int const*>", to_string( nm2::my_template_type< int >::inner< int const* >() ) );
BOOST_CHECK_EQUAL( "inner<int const*>", to_string( nm2::my_template_type< std::exception >::inner< int const* >() ) );
BOOST_CHECK_EQUAL( "inner<int const*&>", to_string( nm2::my_template_type< int >::inner< int const*& >() ) );
BOOST_CHECK_EQUAL( "inner<int const*&>", to_string( nm2::my_template_type< std::exception >::inner< int const*& >() ) );
}
namespace
{
template< typename T1, typename T2, typename T3 >
struct my_tpl
{};
}
BOOST_AUTO_TEST_CASE( name_of_nested_template_with_multiple_arguments_is_extracted )
{
BOOST_CHECK_EQUAL( "vector<int, allocator<int>>", to_string( std::vector< int >() ) );
BOOST_CHECK_EQUAL( "vector<vector<int, allocator<int>>, allocator<vector<int, allocator<int>>>>", to_string( std::vector< std::vector< int > >() ) );
BOOST_CHECK_EQUAL( "my_tpl<my_tpl<int, int, int>, my_tpl<int, int, int>, my_tpl<int, int, int>>", to_string( my_tpl< my_tpl< int, int, int >, my_tpl< int, int, int >, my_tpl< int, int, int > >() ) );
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// 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/detail/type_name.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <boost/lexical_cast.hpp>
namespace
{
template< typename T >
std::string to_string( const T& )
{
return boost::lexical_cast< std::string >( MOCK_TYPE_NAME(T) );
}
}
BOOST_AUTO_TEST_CASE( name_of_base_type_is_extracted )
{
BOOST_CHECK_EQUAL( "char", to_string( 'a' ) );
BOOST_CHECK_EQUAL( "bool", to_string( true ) );
BOOST_CHECK_EQUAL( "int", to_string< int >( 0 ) );
BOOST_CHECK_EQUAL( "short", to_string< short >( 0 ) );
BOOST_CHECK_EQUAL( "long", to_string< long >( 0 ) );
BOOST_CHECK_EQUAL( "unsigned int", to_string< unsigned int >( 0 ) );
BOOST_CHECK_EQUAL( "unsigned short", to_string< unsigned short >( 0 ) );
BOOST_CHECK_EQUAL( "unsigned long", to_string< unsigned long >( 0 ) );
}
struct my_type_in_default_namespace
{
struct inner {};
};
BOOST_AUTO_TEST_CASE( name_of_type_in_default_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_type_in_default_namespace", to_string( my_type_in_default_namespace() ) );
}
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_type_in_default_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "inner", to_string( my_type_in_default_namespace::inner() ) );
}
template< typename T >
struct my_template_type_in_default_namespace
{
struct inner {};
};
BOOST_AUTO_TEST_CASE( name_of_template_type_in_default_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_template_type_in_default_namespace<int>", to_string( my_template_type_in_default_namespace<int>() ) );
}
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_default_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type_in_default_namespace<int>::inner() ) );
}
namespace
{
struct my_type_in_anonymous_namespace {};
}
BOOST_AUTO_TEST_CASE( name_of_type_in_anonymous_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_type_in_anonymous_namespace", to_string( my_type_in_anonymous_namespace() ) );
}
namespace nm
{
struct my_type_from_named_namespace {};
}
BOOST_AUTO_TEST_CASE( name_of_type_from_named_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_type_from_named_namespace", to_string( nm::my_type_from_named_namespace() ) );
}
namespace nm
{
namespace inner
{
struct my_type_in_named_inner_namespace {};
}
}
BOOST_AUTO_TEST_CASE( name_of_type_in_named_inner_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_type_in_named_inner_namespace", to_string( nm::inner::my_type_in_named_inner_namespace() ) );
}
namespace
{
namespace inner
{
struct my_type_in_unnamed_inner_namespace {};
}
}
BOOST_AUTO_TEST_CASE( name_of_type_in_unnamed_inner_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_type_in_unnamed_inner_namespace", to_string( inner::my_type_in_unnamed_inner_namespace() ) );
}
BOOST_AUTO_TEST_CASE( name_of_local_type_is_extracted )
{
struct my_local_type {};
BOOST_CHECK_EQUAL( "my_local_type", boost::lexical_cast< std::string >( MOCK_TYPE_NAME(my_local_type) ) );
}
namespace
{
template< typename T >
struct my_template_type
{
struct inner {};
};
}
BOOST_AUTO_TEST_CASE( name_of_template_type_in_anonymous_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_template_type<int>", to_string( my_template_type< int >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception>", to_string( my_template_type< std::exception >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const&>", to_string( my_template_type< int const& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const&>", to_string( my_template_type< std::exception const& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const*>", to_string( my_template_type< int const* >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const*>", to_string( my_template_type< std::exception const* >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const*&>", to_string( my_template_type< int const*& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const*&>", to_string( my_template_type< std::exception const*& >() ) );
}
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_anonymous_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int const& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception const& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int const* >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception const* >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int const*& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception const*& >::inner() ) );
}
namespace nm
{
template< typename T >
struct my_template_type
{
struct inner {};
};
}
BOOST_AUTO_TEST_CASE( name_of_template_type_in_named_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_template_type<int>", to_string( nm::my_template_type< int >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception>", to_string( nm::my_template_type< std::exception >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const&>", to_string( nm::my_template_type< int const& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const&>", to_string( nm::my_template_type< std::exception const& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const*>", to_string( nm::my_template_type< int const* >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const*>", to_string( nm::my_template_type< std::exception const* >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const*&>", to_string( nm::my_template_type< int const*& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const*&>", to_string( nm::my_template_type< std::exception const*& >() ) );
}
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_named_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int const& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception const& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int const* >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception const* >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int const*& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception const*& >::inner() ) );
}
namespace nm2
{
template< typename T >
struct my_template_type
{
template< typename U >
struct inner {};
};
}
BOOST_AUTO_TEST_CASE( name_of_template_inner_type_from_template_type_in_named_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int const& >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception const& >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int const* >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception const* >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int const*& >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception const*& >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int const&>", to_string( nm2::my_template_type< int >::inner< int const& >() ) );
BOOST_CHECK_EQUAL( "inner<int const&>", to_string( nm2::my_template_type< std::exception >::inner< int const& >() ) );
BOOST_CHECK_EQUAL( "inner<int const*>", to_string( nm2::my_template_type< int >::inner< int const* >() ) );
BOOST_CHECK_EQUAL( "inner<int const*>", to_string( nm2::my_template_type< std::exception >::inner< int const* >() ) );
BOOST_CHECK_EQUAL( "inner<int const*&>", to_string( nm2::my_template_type< int >::inner< int const*& >() ) );
BOOST_CHECK_EQUAL( "inner<int const*&>", to_string( nm2::my_template_type< std::exception >::inner< int const*& >() ) );
}
namespace
{
template< typename T1, typename T2, typename T3 >
struct my_tpl
{};
}
BOOST_AUTO_TEST_CASE( name_of_nested_template_with_multiple_arguments_is_extracted )
{
BOOST_CHECK_EQUAL( "vector<int, allocator<int>>", to_string( std::vector< int >() ) );
BOOST_CHECK_EQUAL( "vector<vector<int, allocator<int>>, allocator<vector<int, allocator<int>>>>", to_string( std::vector< std::vector< int > >() ) );
BOOST_CHECK_EQUAL( "my_tpl<my_tpl<int, int, int>, my_tpl<int, int, int>, my_tpl<int, int, int>>", to_string( my_tpl< my_tpl< int, int, int >, my_tpl< int, int, int >, my_tpl< int, int, int > >() ) );
}

View file

@ -1,24 +1,24 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
struct my_base
{
virtual ~my_base() {}
virtual void my_method() = 0;
virtual void my_method( int ) = 0;
};
MOCK_BASE_CLASS( my_class, my_base )
{
MOCK_METHOD( my_method, 0 )
};
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
struct my_base
{
virtual ~my_base() {}
virtual void my_method() = 0;
virtual void my_method( int ) = 0;
};
MOCK_BASE_CLASS( my_class, my_base )
{
MOCK_METHOD( my_method, 0 )
};
}

View file

@ -1,24 +1,24 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
};
bool constraint( int, int );
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).with( &constraint );
}
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
};
bool constraint( int, int );
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).with( &constraint );
}
}

View file

@ -1,22 +1,22 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).with( "42" );
}
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).with( "42" );
}
}

View file

@ -1,22 +1,22 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).with( mock::equal( "42" ) );
}
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).with( mock::equal( "42" ) );
}
}

View file

@ -1,22 +1,22 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 0, int(), my_method )
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).returns( std::string() );
}
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 0, int(), my_method )
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).returns( std::string() );
}
}

View file

@ -1,22 +1,22 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 0, std::string(), my_method )
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).returns( 42 );
}
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 0, std::string(), my_method )
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).returns( 42 );
}
}

View file

@ -1,22 +1,22 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 0, void(), my_method )
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).returns( "42" );
}
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 0, void(), my_method )
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).returns( "42" );
}
}

View file

@ -1,22 +1,22 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
struct my_base
{
virtual ~my_base() {}
};
MOCK_BASE_CLASS( my_class, my_base )
{
MOCK_METHOD( my_method, 0 )
};
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
struct my_base
{
virtual ~my_base() {}
};
MOCK_BASE_CLASS( my_class, my_base )
{
MOCK_METHOD( my_method, 0 )
};
}

View file

@ -1,25 +1,25 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
BOOST_STATIC_ASSERT( MOCK_MAX_ARGS == 9 );
namespace
{
struct my_base
{
virtual ~my_base() {}
virtual void my_method( int, int, int, int, int, int, int, int, int, int ) = 0;
};
MOCK_BASE_CLASS( my_class, my_base )
{
MOCK_METHOD( my_method, 10 )
};
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
BOOST_STATIC_ASSERT( MOCK_MAX_ARGS == 9 );
namespace
{
struct my_base
{
virtual ~my_base() {}
virtual void my_method( int, int, int, int, int, int, int, int, int, int ) = 0;
};
MOCK_BASE_CLASS( my_class, my_base )
{
MOCK_METHOD( my_method, 10 )
};
}

View file

@ -1,18 +1,18 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
template< typename T >
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 1, void( T ), my_method )
};
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
template< typename T >
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 1, void( T ), my_method )
};
}

View file

@ -1,23 +1,23 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
struct my_base
{
virtual ~my_base() {}
virtual void my_method( int ) = 0;
};
MOCK_BASE_CLASS( my_class, my_base )
{
MOCK_METHOD( my_method, 2 )
};
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
struct my_base
{
virtual ~my_base() {}
virtual void my_method( int ) = 0;
};
MOCK_BASE_CLASS( my_class, my_base )
{
MOCK_METHOD( my_method, 2 )
};
}

View file

@ -1,22 +1,22 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).with( 42, 42 );
}
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// 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>
namespace
{
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).with( 42, 42 );
}
}

View file

@ -1,112 +1,112 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// 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_TEST_MOCK_ERROR_HPP_INCLUDED
#define MOCK_TEST_MOCK_ERROR_HPP_INCLUDED
#define MOCK_ERROR_POLICY mock_error
#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/utils/trivial_singleton.hpp>
#include <stdexcept>
struct mock_error_data_t : boost::unit_test::singleton< mock_error_data_t >
{
void reset()
{
call_count = 0;
error_count = 0;
last_message.clear();
last_context.clear();
}
bool verify()
{
return error_count == 0;
}
void call()
{
last_context.clear();
last_message.clear();
++call_count;
}
void fail( const std::string& message,
const std::string& context,
const char* file, int line )
{
last_context = context;
last_message = message;
last_file = file;
last_line = line;
++error_count;
}
int error_count;
int call_count;
std::string last_message;
std::string last_context;
std::string last_file;
int last_line;
private:
BOOST_TEST_SINGLETON_CONS( mock_error_data_t );
};
BOOST_TEST_SINGLETON_INST( mock_error_data )
template< typename Result >
struct mock_error
{
static Result abort()
{
throw std::runtime_error( "aborted" );
}
static void pass( const char* /*file*/, int /*line*/ )
{}
template< typename Context >
static void call( const Context& /*context*/,
const char* /*file*/, int /*line*/ )
{
mock_error_data.call();
}
template< typename Context >
static void fail( const std::string& message, const Context& context,
const char* file = "", int line = 0 )
{
mock_error_data.fail( message,
boost::lexical_cast< std::string >( context ), file, line );
}
};
struct mock_error_fixture
{
mock_error_fixture()
{
mock_error_data.reset();
}
~mock_error_fixture()
{
BOOST_CHECK( mock_error_data.verify() );
BOOST_CHECK_EQUAL( 0, mock_error_data.call_count );
}
};
#define CHECK_CALLS( calls ) \
BOOST_CHECK_EQUAL( calls, mock_error_data.call_count ); \
mock_error_data.call_count = 0;
#define CHECK_ERROR( expr, error, calls, context ) \
BOOST_CHECK( mock_error_data.verify() ); \
try { expr; } catch( ... ) {} \
BOOST_CHECK_EQUAL( 1, mock_error_data.error_count ); \
BOOST_CHECK_EQUAL( error, mock_error_data.last_message ); \
BOOST_CHECK_EQUAL( context, mock_error_data.last_context ); \
CHECK_CALLS( calls ); \
mock_error_data.reset();
#endif // MOCK_TEST_MOCK_ERROR_HPP_INCLUDED
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// 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_TEST_MOCK_ERROR_HPP_INCLUDED
#define MOCK_TEST_MOCK_ERROR_HPP_INCLUDED
#define MOCK_ERROR_POLICY mock_error
#include <boost/lexical_cast.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/utils/trivial_singleton.hpp>
#include <stdexcept>
struct mock_error_data_t : boost::unit_test::singleton< mock_error_data_t >
{
void reset()
{
call_count = 0;
error_count = 0;
last_message.clear();
last_context.clear();
}
bool verify()
{
return error_count == 0;
}
void call()
{
last_context.clear();
last_message.clear();
++call_count;
}
void fail( const std::string& message,
const std::string& context,
const char* file, int line )
{
last_context = context;
last_message = message;
last_file = file;
last_line = line;
++error_count;
}
int error_count;
int call_count;
std::string last_message;
std::string last_context;
std::string last_file;
int last_line;
private:
BOOST_TEST_SINGLETON_CONS( mock_error_data_t );
};
BOOST_TEST_SINGLETON_INST( mock_error_data )
template< typename Result >
struct mock_error
{
static Result abort()
{
throw std::runtime_error( "aborted" );
}
static void pass( const char* /*file*/, int /*line*/ )
{}
template< typename Context >
static void call( const Context& /*context*/,
const char* /*file*/, int /*line*/ )
{
mock_error_data.call();
}
template< typename Context >
static void fail( const std::string& message, const Context& context,
const char* file = "", int line = 0 )
{
mock_error_data.fail( message,
boost::lexical_cast< std::string >( context ), file, line );
}
};
struct mock_error_fixture
{
mock_error_fixture()
{
mock_error_data.reset();
}
~mock_error_fixture()
{
BOOST_CHECK( mock_error_data.verify() );
BOOST_CHECK_EQUAL( 0, mock_error_data.call_count );
}
};
#define CHECK_CALLS( calls ) \
BOOST_CHECK_EQUAL( calls, mock_error_data.call_count ); \
mock_error_data.call_count = 0;
#define CHECK_ERROR( expr, error, calls, context ) \
BOOST_CHECK( mock_error_data.verify() ); \
try { expr; } catch( ... ) {} \
BOOST_CHECK_EQUAL( 1, mock_error_data.error_count ); \
BOOST_CHECK_EQUAL( error, mock_error_data.last_message ); \
BOOST_CHECK_EQUAL( context, mock_error_data.last_context ); \
CHECK_CALLS( calls ); \
mock_error_data.reset();
#endif // MOCK_TEST_MOCK_ERROR_HPP_INCLUDED

View file

@ -1,28 +1,42 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2013
//
// 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/constraint.hpp>
#include <boost/test/auto_unit_test.hpp>
#ifdef MOCK_VARIADIC_MACROS
namespace
{
MOCK_CONSTRAINT( constraint_0, actual == 0 )
MOCK_CONSTRAINT( constraint_1, expected, actual == expected )
MOCK_CONSTRAINT( constraint_2, expected_0, expected_1, actual == expected_0 || actual == expected_1 )
}
BOOST_AUTO_TEST_CASE( mock_constraint_is_supported_by_compilers_with_variadic_macros )
{
BOOST_CHECK( constraint_0.c_( 0 ) );
BOOST_CHECK( constraint_1( 0 ).c_( 0 ) );
BOOST_CHECK( constraint_2( 0, 0 ).c_( 0 ) );
}
#endif // MOCK_VARIADIC_MACROS
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2013
//
// 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/constraint.hpp>
#include <boost/test/auto_unit_test.hpp>
#ifdef MOCK_VARIADIC_MACROS
namespace
{
MOCK_CONSTRAINT( constraint_0, actual == 0 )
MOCK_CONSTRAINT( constraint_1, expected, actual == expected )
MOCK_CONSTRAINT( constraint_2, expected_0, expected_1, actual == expected_0 || actual == expected_1 )
}
BOOST_AUTO_TEST_CASE( mock_constraint_is_supported_by_compilers_with_variadic_macros )
{
BOOST_CHECK( constraint_0.c_( 0 ) );
BOOST_CHECK( constraint_1( 0 ).c_( 0 ) );
BOOST_CHECK( constraint_2( 0, 0 ).c_( 0 ) );
}
#endif // MOCK_VARIADIC_MACROS
namespace
{
MOCK_CONSTRAINT_EXT( constraint_0_ext, 0,, actual == 0 )
MOCK_CONSTRAINT_EXT( constraint_1_ext, 1, ( expected ), actual == expected )
MOCK_CONSTRAINT_EXT( constraint_2_ext, 2, ( expected_0, expected_1 ), actual == expected_0 || actual == expected_1 )
}
BOOST_AUTO_TEST_CASE( mock_constraint_ext_is_supported_by_all_compilers )
{
BOOST_CHECK( constraint_0_ext.c_( 0 ) );
BOOST_CHECK( constraint_1_ext( 0 ).c_( 0 ) );
BOOST_CHECK( constraint_2_ext( 0, 0 ).c_( 0 ) );
}

View file

@ -1,369 +1,369 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// 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/constraints.hpp>
#include <boost/test/auto_unit_test.hpp>
BOOST_AUTO_TEST_CASE( all_comparison_constraints_can_be_instanciated )
{
mock::equal( 0 );
mock::less( 0 );
mock::greater( 0 );
mock::less_equal( 0 );
mock::greater_equal( 0 );
}
BOOST_AUTO_TEST_CASE( constraints_can_be_negated_using_the_not_operator )
{
! mock::any;
! mock::affirm;
! mock::negate;
! mock::evaluate;
! mock::equal( 0 );
! mock::less( 0 );
! mock::greater( 0 );
! mock::less_equal( 0 );
! mock::greater_equal( 0 );
}
BOOST_AUTO_TEST_CASE( constraints_can_be_combined_using_the_or_operator )
{
mock::less( 0 ) || mock::greater( 0 );
}
BOOST_AUTO_TEST_CASE( constraints_can_be_combined_using_the_and_operator )
{
mock::less( 0 ) && mock::greater( 0 );
}
BOOST_AUTO_TEST_CASE( equal_constraint )
{
BOOST_CHECK( mock::equal( std::string( "string" ) ).c_( "string" ) );
BOOST_CHECK( ! mock::equal( std::string( "string" ) ).c_( "not string" ) );
{
std::string s;
mock::constraint<
mock::detail::equal<
boost::reference_wrapper< const std::string >
>
> c = mock::equal( boost::cref( s ) );
s = "string";
BOOST_CHECK( c.c_( "string" ) );
}
}
BOOST_AUTO_TEST_CASE( same_constraint )
{
{
int i = 0;
int j = 0;
BOOST_CHECK_EQUAL( i, j );
BOOST_CHECK( ! mock::same( i ).c_( j ) );
BOOST_CHECK( mock::same( i ).c_( i ) );
}
{
int i = 0;
int j = 0;
BOOST_CHECK_EQUAL( i, j );
mock::constraint<
mock::detail::same<
const boost::reference_wrapper< const int >
>
> c = mock::same( boost::cref( i ) );
BOOST_CHECK( ! c.c_( j ) );
BOOST_CHECK( c.c_( i ) );
}
#ifdef MOCK_NULLPTR
{
std::nullptr_t p;
BOOST_CHECK( mock::same( p ).c_( p ) );
}
#endif
}
BOOST_AUTO_TEST_CASE( assign_constraint )
{
{
int i = 0;
BOOST_CHECK( mock::assign( 3 ).c_( i ) );
BOOST_CHECK_EQUAL( 3, i );
}
{
int i = 0;
BOOST_CHECK( mock::assign( 3 ).c_( &i ) );
BOOST_CHECK_EQUAL( 3, i );
}
{
const int* i = 0;
const int j = 1;
BOOST_CHECK( mock::assign( &j ).c_( i ) );
BOOST_CHECK_EQUAL( &j, i );
}
{
int i = 0;
int j = 1;
mock::constraint<
mock::detail::assign<
boost::reference_wrapper< const int >
>
> c = mock::assign( boost::cref( j ) );
BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL( 1, i );
j = 3;
BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL( 3, i );
}
{
int i = 0;
int j = 1;
mock::constraint<
mock::detail::assign<
boost::reference_wrapper< const int >
>
> c = mock::assign( boost::cref( j ) );
BOOST_CHECK( c.c_( &i ) );
BOOST_CHECK_EQUAL( 1, i );
j = 3;
BOOST_CHECK( c.c_( &i ) );
BOOST_CHECK_EQUAL( 3, i );
}
{
const int* i = 0;
int k = 1;
int* j = &k;
mock::constraint<
mock::detail::assign<
boost::reference_wrapper< int* const >
>
> c = mock::assign( boost::cref( j ) );
BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL( j, i );
j = 0;
BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL( j, i );
}
}
BOOST_AUTO_TEST_CASE( retrieve_constraint )
{
{
int i = 0;
const int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, j );
}
{
int* i = 0;
int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( &j ) );
BOOST_CHECK_EQUAL( i, &j );
}
{
const int* i = 0;
const int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
}
{
const int* i = 0;
int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
}
{
int* i = 0;
int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
}
{
const int* i = 0;
const int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
}
{
int** i = 0;
int* j = 0;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
}
{
const int** i = 0;
const int* j = 0;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
}
{
int i = 0;
const int j = 1;
BOOST_CHECK( mock::retrieve( boost::ref( i ) ).c_( j ) );
BOOST_CHECK_EQUAL( i, j );
}
{
const int* i = 0;
const int j = 1;
BOOST_CHECK( mock::retrieve( boost::ref( i ) ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
}
#ifdef MOCK_NULLPTR
{
std::nullptr_t* i = 0;
std::nullptr_t j;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
}
#endif
}
namespace
{
struct A
{
};
struct B
{
B& operator=( const A& )
{
return *this;
}
};
}
BOOST_AUTO_TEST_CASE( retrieve_constraint_uses_assignment_operator )
{
B b;
const A a = A();
mock::retrieve( b ).c_( a );
}
BOOST_AUTO_TEST_CASE( affirm_constraint )
{
int* i = 0;
int j;
BOOST_CHECK( ! mock::affirm.c_( i ) );
BOOST_CHECK( mock::affirm.c_( &j ) );
}
BOOST_AUTO_TEST_CASE( negate_constraint )
{
int* i = 0;
int j;
BOOST_CHECK( mock::negate.c_( i ) );
BOOST_CHECK( ! mock::negate.c_( &j ) );
}
namespace
{
bool return_true()
{
return true;
}
bool return_false()
{
return false;
}
}
BOOST_AUTO_TEST_CASE( call_constraint )
{
BOOST_CHECK( mock::call( &return_true ).c_() );
BOOST_CHECK( ! mock::call( &return_false ).c_() );
}
BOOST_AUTO_TEST_CASE( evaluate_constraint )
{
BOOST_CHECK( mock::evaluate.c_( &return_true ) );
BOOST_CHECK( ! mock::evaluate.c_( &return_false ) );
}
BOOST_AUTO_TEST_CASE( contain_constraint_with_const_char_ptr )
{
BOOST_CHECK( mock::contain( "string" ).c_( "this is a string" ) );
BOOST_CHECK( mock::contain( "string" ).c_( std::string( "this is a string" ) ) );
BOOST_CHECK( ! mock::contain( "not found" ).c_( "this is a string" ) );
BOOST_CHECK( ! mock::contain( "not found" ).c_( std::string( "this is a string" ) ) );
{
const char* s = 0;
mock::constraint<
mock::detail::contain<
boost::reference_wrapper< const char* const >
>
> c = mock::contain( boost::cref( s ) );
s = "string";
BOOST_CHECK( c.c_( "this is a string" ) );
BOOST_CHECK( c.c_( std::string( "this is a string" ) ) );
s = "not found";
BOOST_CHECK( ! c.c_( "this is a string" ) );
BOOST_CHECK( ! c.c_( std::string( "this is a string" ) ) );
}
}
BOOST_AUTO_TEST_CASE( contain_constraint_with_strings )
{
BOOST_CHECK( mock::contain( std::string( "string" ) ).c_( "this is a string" ) );
BOOST_CHECK( mock::contain( std::string( "string" ) ).c_( std::string( "this is a string" ) ) );
BOOST_CHECK( ! mock::contain( std::string( "not found" ) ).c_( "this is a string" ) );
BOOST_CHECK( ! mock::contain( std::string( "not found" ) ).c_( std::string( "this is a string" ) ) );
{
std::string s;
mock::constraint<
mock::detail::contain<
boost::reference_wrapper< const std::string >
>
> c = mock::contain( boost::cref( s ) );
s = "string";
BOOST_CHECK( c.c_( "this is a string" ) );
BOOST_CHECK( c.c_( std::string( "this is a string" ) ) );
s = "not found";
BOOST_CHECK( ! c.c_( "this is a string" ) );
BOOST_CHECK( ! c.c_( std::string( "this is a string" ) ) );
}
}
namespace
{
struct type_with_overloaded_address_operator
{
void operator&() {}
void operator&() const {}
};
}
BOOST_AUTO_TEST_CASE( type_with_overloaded_address_operator_can_be_used_in_constraints )
{
type_with_overloaded_address_operator t;
mock::same( t ).c_( t );
mock::retrieve( t ).c_( t );
type_with_overloaded_address_operator* pt;
mock::retrieve( pt ).c_( t );
}
BOOST_AUTO_TEST_CASE( close_constraint )
{
BOOST_CHECK( mock::close( 12.0, 0.0001 ).c_( 12 ) );
BOOST_CHECK( ! mock::close( 12.0, 0.0001 ).c_( 13 ) );
}
BOOST_AUTO_TEST_CASE( close_fraction_constraint )
{
BOOST_CHECK( mock::close_fraction( 12.0, 0.0001 ).c_( 12 ) );
BOOST_CHECK( ! mock::close_fraction( 12.0, 0.0001 ).c_( 13 ) );
}
BOOST_AUTO_TEST_CASE( small_constraint )
{
BOOST_CHECK( mock::small( 0.0001 ).c_( 0. ) );
BOOST_CHECK( ! mock::small( 0.0001 ).c_( 12. ) );
}
BOOST_AUTO_TEST_CASE( near_constraint )
{
BOOST_CHECK( mock::near( 12.0, 0.0001 ).c_( 12 ) );
BOOST_CHECK( ! mock::near( 12.0, 0.0001 ).c_( 13 ) );
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// 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/constraints.hpp>
#include <boost/test/auto_unit_test.hpp>
BOOST_AUTO_TEST_CASE( all_comparison_constraints_can_be_instanciated )
{
mock::equal( 0 );
mock::less( 0 );
mock::greater( 0 );
mock::less_equal( 0 );
mock::greater_equal( 0 );
}
BOOST_AUTO_TEST_CASE( constraints_can_be_negated_using_the_not_operator )
{
! mock::any;
! mock::affirm;
! mock::negate;
! mock::evaluate;
! mock::equal( 0 );
! mock::less( 0 );
! mock::greater( 0 );
! mock::less_equal( 0 );
! mock::greater_equal( 0 );
}
BOOST_AUTO_TEST_CASE( constraints_can_be_combined_using_the_or_operator )
{
mock::less( 0 ) || mock::greater( 0 );
}
BOOST_AUTO_TEST_CASE( constraints_can_be_combined_using_the_and_operator )
{
mock::less( 0 ) && mock::greater( 0 );
}
BOOST_AUTO_TEST_CASE( equal_constraint )
{
BOOST_CHECK( mock::equal( std::string( "string" ) ).c_( "string" ) );
BOOST_CHECK( ! mock::equal( std::string( "string" ) ).c_( "not string" ) );
{
std::string s;
mock::constraint<
mock::detail::equal<
boost::reference_wrapper< const std::string >
>
> c = mock::equal( boost::cref( s ) );
s = "string";
BOOST_CHECK( c.c_( "string" ) );
}
}
BOOST_AUTO_TEST_CASE( same_constraint )
{
{
int i = 0;
int j = 0;
BOOST_CHECK_EQUAL( i, j );
BOOST_CHECK( ! mock::same( i ).c_( j ) );
BOOST_CHECK( mock::same( i ).c_( i ) );
}
{
int i = 0;
int j = 0;
BOOST_CHECK_EQUAL( i, j );
mock::constraint<
mock::detail::same<
const boost::reference_wrapper< const int >
>
> c = mock::same( boost::cref( i ) );
BOOST_CHECK( ! c.c_( j ) );
BOOST_CHECK( c.c_( i ) );
}
#ifdef MOCK_NULLPTR
{
std::nullptr_t p;
BOOST_CHECK( mock::same( p ).c_( p ) );
}
#endif
}
BOOST_AUTO_TEST_CASE( assign_constraint )
{
{
int i = 0;
BOOST_CHECK( mock::assign( 3 ).c_( i ) );
BOOST_CHECK_EQUAL( 3, i );
}
{
int i = 0;
BOOST_CHECK( mock::assign( 3 ).c_( &i ) );
BOOST_CHECK_EQUAL( 3, i );
}
{
const int* i = 0;
const int j = 1;
BOOST_CHECK( mock::assign( &j ).c_( i ) );
BOOST_CHECK_EQUAL( &j, i );
}
{
int i = 0;
int j = 1;
mock::constraint<
mock::detail::assign<
boost::reference_wrapper< const int >
>
> c = mock::assign( boost::cref( j ) );
BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL( 1, i );
j = 3;
BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL( 3, i );
}
{
int i = 0;
int j = 1;
mock::constraint<
mock::detail::assign<
boost::reference_wrapper< const int >
>
> c = mock::assign( boost::cref( j ) );
BOOST_CHECK( c.c_( &i ) );
BOOST_CHECK_EQUAL( 1, i );
j = 3;
BOOST_CHECK( c.c_( &i ) );
BOOST_CHECK_EQUAL( 3, i );
}
{
const int* i = 0;
int k = 1;
int* j = &k;
mock::constraint<
mock::detail::assign<
boost::reference_wrapper< int* const >
>
> c = mock::assign( boost::cref( j ) );
BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL( j, i );
j = 0;
BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL( j, i );
}
}
BOOST_AUTO_TEST_CASE( retrieve_constraint )
{
{
int i = 0;
const int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, j );
}
{
int* i = 0;
int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( &j ) );
BOOST_CHECK_EQUAL( i, &j );
}
{
const int* i = 0;
const int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
}
{
const int* i = 0;
int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
}
{
int* i = 0;
int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
}
{
const int* i = 0;
const int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
}
{
int** i = 0;
int* j = 0;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
}
{
const int** i = 0;
const int* j = 0;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
}
{
int i = 0;
const int j = 1;
BOOST_CHECK( mock::retrieve( boost::ref( i ) ).c_( j ) );
BOOST_CHECK_EQUAL( i, j );
}
{
const int* i = 0;
const int j = 1;
BOOST_CHECK( mock::retrieve( boost::ref( i ) ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
}
#ifdef MOCK_NULLPTR
{
std::nullptr_t* i = 0;
std::nullptr_t j;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
}
#endif
}
namespace
{
struct A
{
};
struct B
{
B& operator=( const A& )
{
return *this;
}
};
}
BOOST_AUTO_TEST_CASE( retrieve_constraint_uses_assignment_operator )
{
B b;
const A a = A();
mock::retrieve( b ).c_( a );
}
BOOST_AUTO_TEST_CASE( affirm_constraint )
{
int* i = 0;
int j;
BOOST_CHECK( ! mock::affirm.c_( i ) );
BOOST_CHECK( mock::affirm.c_( &j ) );
}
BOOST_AUTO_TEST_CASE( negate_constraint )
{
int* i = 0;
int j;
BOOST_CHECK( mock::negate.c_( i ) );
BOOST_CHECK( ! mock::negate.c_( &j ) );
}
namespace
{
bool return_true()
{
return true;
}
bool return_false()
{
return false;
}
}
BOOST_AUTO_TEST_CASE( call_constraint )
{
BOOST_CHECK( mock::call( &return_true ).c_() );
BOOST_CHECK( ! mock::call( &return_false ).c_() );
}
BOOST_AUTO_TEST_CASE( evaluate_constraint )
{
BOOST_CHECK( mock::evaluate.c_( &return_true ) );
BOOST_CHECK( ! mock::evaluate.c_( &return_false ) );
}
BOOST_AUTO_TEST_CASE( contain_constraint_with_const_char_ptr )
{
BOOST_CHECK( mock::contain( "string" ).c_( "this is a string" ) );
BOOST_CHECK( mock::contain( "string" ).c_( std::string( "this is a string" ) ) );
BOOST_CHECK( ! mock::contain( "not found" ).c_( "this is a string" ) );
BOOST_CHECK( ! mock::contain( "not found" ).c_( std::string( "this is a string" ) ) );
{
const char* s = 0;
mock::constraint<
mock::detail::contain<
boost::reference_wrapper< const char* const >
>
> c = mock::contain( boost::cref( s ) );
s = "string";
BOOST_CHECK( c.c_( "this is a string" ) );
BOOST_CHECK( c.c_( std::string( "this is a string" ) ) );
s = "not found";
BOOST_CHECK( ! c.c_( "this is a string" ) );
BOOST_CHECK( ! c.c_( std::string( "this is a string" ) ) );
}
}
BOOST_AUTO_TEST_CASE( contain_constraint_with_strings )
{
BOOST_CHECK( mock::contain( std::string( "string" ) ).c_( "this is a string" ) );
BOOST_CHECK( mock::contain( std::string( "string" ) ).c_( std::string( "this is a string" ) ) );
BOOST_CHECK( ! mock::contain( std::string( "not found" ) ).c_( "this is a string" ) );
BOOST_CHECK( ! mock::contain( std::string( "not found" ) ).c_( std::string( "this is a string" ) ) );
{
std::string s;
mock::constraint<
mock::detail::contain<
boost::reference_wrapper< const std::string >
>
> c = mock::contain( boost::cref( s ) );
s = "string";
BOOST_CHECK( c.c_( "this is a string" ) );
BOOST_CHECK( c.c_( std::string( "this is a string" ) ) );
s = "not found";
BOOST_CHECK( ! c.c_( "this is a string" ) );
BOOST_CHECK( ! c.c_( std::string( "this is a string" ) ) );
}
}
namespace
{
struct type_with_overloaded_address_operator
{
void operator&() {}
void operator&() const {}
};
}
BOOST_AUTO_TEST_CASE( type_with_overloaded_address_operator_can_be_used_in_constraints )
{
type_with_overloaded_address_operator t;
mock::same( t ).c_( t );
mock::retrieve( t ).c_( t );
type_with_overloaded_address_operator* pt;
mock::retrieve( pt ).c_( t );
}
BOOST_AUTO_TEST_CASE( close_constraint )
{
BOOST_CHECK( mock::close( 12.0, 0.0001 ).c_( 12 ) );
BOOST_CHECK( ! mock::close( 12.0, 0.0001 ).c_( 13 ) );
}
BOOST_AUTO_TEST_CASE( close_fraction_constraint )
{
BOOST_CHECK( mock::close_fraction( 12.0, 0.0001 ).c_( 12 ) );
BOOST_CHECK( ! mock::close_fraction( 12.0, 0.0001 ).c_( 13 ) );
}
BOOST_AUTO_TEST_CASE( small_constraint )
{
BOOST_CHECK( mock::small( 0.0001 ).c_( 0. ) );
BOOST_CHECK( ! mock::small( 0.0001 ).c_( 12. ) );
}
BOOST_AUTO_TEST_CASE( near_constraint )
{
BOOST_CHECK( mock::near( 12.0, 0.0001 ).c_( 12 ) );
BOOST_CHECK( ! mock::near( 12.0, 0.0001 ).c_( 13 ) );
}

View file

@ -1,25 +1,25 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// 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 MOCK_USE_BOOST_TEST
#include <turtle/exception.hpp>
#include <boost/test/auto_unit_test.hpp>
BOOST_AUTO_TEST_CASE( a_mock_exception_is_not_an_std_exception_to_not_mess_with_user_exceptions )
{
try
{
throw mock::exception();
}
catch( std::exception& )
{
BOOST_FAIL( "mock::exception must not be an std::exception" );
}
catch( mock::exception& )
{}
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// 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 MOCK_USE_BOOST_TEST
#include <turtle/exception.hpp>
#include <boost/test/auto_unit_test.hpp>
BOOST_AUTO_TEST_CASE( a_mock_exception_is_not_an_std_exception_to_not_mess_with_user_exceptions )
{
try
{
throw mock::exception();
}
catch( std::exception& )
{
BOOST_FAIL( "mock::exception must not be an std::exception" );
}
catch( mock::exception& )
{}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,78 +1,78 @@
// 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)
#include <turtle/detail/function.hpp>
#include <boost/test/auto_unit_test.hpp>
namespace
{
template< typename Expected, typename Actual >
bool match( Expected expected, Actual actual )
{
return mock::matcher< Actual, Expected >( expected )( actual );
}
}
BOOST_AUTO_TEST_CASE( int_and_int_can_be_compared )
{
BOOST_CHECK( match( 3, 3 ) );
BOOST_CHECK( ! match( 3, 4 ) );
BOOST_CHECK( ! match( 4, 3 ) );
}
BOOST_AUTO_TEST_CASE( ref_to_int_and_int_can_be_compared )
{
const int i = 3;
BOOST_CHECK( match( 3, boost::cref( i ) ) );
BOOST_CHECK( ! match( 4, boost::cref( i ) ) );
}
namespace
{
struct fixture
{
fixture()
: text( "same text" )
, actual( text.c_str() )
{
const char* static_string = "same text";
BOOST_REQUIRE( actual != static_string );
BOOST_REQUIRE( actual == std::string( static_string ) );
}
std::string text;
const char* actual;
};
}
BOOST_FIXTURE_TEST_CASE( const_char_pointer_and_const_char_pointer_can_be_compared, fixture )
{
const char* expected = "same text";
BOOST_CHECK( match( expected, actual ) );
const char* unexpected = "different text";
BOOST_CHECK( ! match( actual, unexpected ) );
}
BOOST_FIXTURE_TEST_CASE( const_char_pointer_and_string_literal_can_be_compared, fixture )
{
BOOST_CHECK( match( "same text", actual ) );
BOOST_CHECK( ! match( "different text", actual ) );
}
BOOST_FIXTURE_TEST_CASE( const_char_pointer_and_const_char_array_can_be_compared, fixture )
{
const char expected[10] = "same text";
BOOST_CHECK( match( expected, actual ) );
const char unexpected[15] = "different text";
BOOST_CHECK( ! match( unexpected, actual ) );
}
BOOST_FIXTURE_TEST_CASE( const_char_pointer_and_std_string_can_be_compared, fixture )
{
BOOST_CHECK( match( std::string( "same text" ), actual ) );
BOOST_CHECK( ! match( std::string( "different text" ), actual ) );
}
// 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)
#include <turtle/detail/function.hpp>
#include <boost/test/auto_unit_test.hpp>
namespace
{
template< typename Expected, typename Actual >
bool match( Expected expected, Actual actual )
{
return mock::matcher< Actual, Expected >( expected )( actual );
}
}
BOOST_AUTO_TEST_CASE( int_and_int_can_be_compared )
{
BOOST_CHECK( match( 3, 3 ) );
BOOST_CHECK( ! match( 3, 4 ) );
BOOST_CHECK( ! match( 4, 3 ) );
}
BOOST_AUTO_TEST_CASE( ref_to_int_and_int_can_be_compared )
{
const int i = 3;
BOOST_CHECK( match( 3, boost::cref( i ) ) );
BOOST_CHECK( ! match( 4, boost::cref( i ) ) );
}
namespace
{
struct fixture
{
fixture()
: text( "same text" )
, actual( text.c_str() )
{
const char* static_string = "same text";
BOOST_REQUIRE( actual != static_string );
BOOST_REQUIRE( actual == std::string( static_string ) );
}
std::string text;
const char* actual;
};
}
BOOST_FIXTURE_TEST_CASE( const_char_pointer_and_const_char_pointer_can_be_compared, fixture )
{
const char* expected = "same text";
BOOST_CHECK( match( expected, actual ) );
const char* unexpected = "different text";
BOOST_CHECK( ! match( actual, unexpected ) );
}
BOOST_FIXTURE_TEST_CASE( const_char_pointer_and_string_literal_can_be_compared, fixture )
{
BOOST_CHECK( match( "same text", actual ) );
BOOST_CHECK( ! match( "different text", actual ) );
}
BOOST_FIXTURE_TEST_CASE( const_char_pointer_and_const_char_array_can_be_compared, fixture )
{
const char expected[10] = "same text";
BOOST_CHECK( match( expected, actual ) );
const char unexpected[15] = "different text";
BOOST_CHECK( ! match( unexpected, actual ) );
}
BOOST_FIXTURE_TEST_CASE( const_char_pointer_and_std_string_can_be_compared, fixture )
{
BOOST_CHECK( match( std::string( "same text" ), actual ) );
BOOST_CHECK( ! match( std::string( "different text" ), actual ) );
}

View file

@ -1,39 +1,39 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// 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 "mock_error.hpp"
#include <turtle/mock.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <boost/preprocessor/repetition/enum.hpp>
#define IDENTITY(z, n, d) d
namespace
{
struct my_custom_mock
{
MOCK_METHOD_EXT( method, MOCK_MAX_ARGS, void( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int) ), tag )
MOCK_METHOD_EXT( method2, MOCK_MAX_ARGS, int( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int) ), tag_2 )
};
}
BOOST_FIXTURE_TEST_CASE( call_mock_method_with_max_number_of_args, mock_error_fixture )
{
my_custom_mock m;
MOCK_EXPECT( m.tag ).once().with( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) );
m.method( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) );
CHECK_CALLS( 1 );
}
BOOST_FIXTURE_TEST_CASE( call_mock_method_with_max_number_of_args_and_a_return_value, mock_error_fixture )
{
my_custom_mock m;
MOCK_EXPECT( m.tag_2 ).once().with( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) ).returns( 42 );
BOOST_CHECK_EQUAL( 42, m.method2( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) ) );
CHECK_CALLS( 1 );
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// 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 "mock_error.hpp"
#include <turtle/mock.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <boost/preprocessor/repetition/enum.hpp>
#define IDENTITY(z, n, d) d
namespace
{
struct my_custom_mock
{
MOCK_METHOD_EXT( method, MOCK_MAX_ARGS, void( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int) ), tag )
MOCK_METHOD_EXT( method2, MOCK_MAX_ARGS, int( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int) ), tag_2 )
};
}
BOOST_FIXTURE_TEST_CASE( call_mock_method_with_max_number_of_args, mock_error_fixture )
{
my_custom_mock m;
MOCK_EXPECT( m.tag ).once().with( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) );
m.method( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) );
CHECK_CALLS( 1 );
}
BOOST_FIXTURE_TEST_CASE( call_mock_method_with_max_number_of_args_and_a_return_value, mock_error_fixture )
{
my_custom_mock m;
MOCK_EXPECT( m.tag_2 ).once().with( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) ).returns( 42 );
BOOST_CHECK_EQUAL( 42, m.method2( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) ) );
CHECK_CALLS( 1 );
}

View file

@ -1,434 +1,434 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2009
//
// 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 "mock_error.hpp"
#include <turtle/mock.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/bind.hpp>
namespace
{
template< typename T >
void my_function( T& t )
{
t.my_method( "some parameter" );
}
MOCK_CLASS( mock_class )
{
MOCK_METHOD_EXT( my_method, 1, void( const std::string& ), my_tag )
};
}
BOOST_FIXTURE_TEST_CASE( mock_object_for_static_polymorphism, mock_error_fixture )
{
const mock_class m;
MOCK_EXPECT( m.my_tag ).once().with( "some parameter" );
my_function( m );
CHECK_CALLS( 1 );
}
namespace
{
MOCK_CLASS( mock_class_with_operator )
{
MOCK_CONST_METHOD_EXT( operator+=, 1, mock_class_with_operator&( int ), addition )
};
}
BOOST_FIXTURE_TEST_CASE( mock_addition_operator, mock_error_fixture )
{
mock_class_with_operator m;
MOCK_EXPECT( m.addition ).once().returns( boost::ref( m ) );
m += 1;
CHECK_CALLS( 1 );
}
namespace
{
MOCK_CLASS( mock_class_with_conversion_operator )
{
MOCK_CONVERSION_OPERATOR( operator, int, conversion )
};
}
BOOST_FIXTURE_TEST_CASE( mock_conversion_operator, mock_error_fixture )
{
mock_class_with_conversion_operator m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
CHECK_CALLS( 1 );
}
namespace
{
template< typename T >
MOCK_CLASS( mock_template_class_with_conversion_operator )
{
MOCK_CONVERSION_OPERATOR_TPL( operator, T, conversion )
};
}
BOOST_FIXTURE_TEST_CASE( mock_template_conversion_operator, mock_error_fixture )
{
mock_template_class_with_conversion_operator< int > m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
CHECK_CALLS( 1 );
}
namespace
{
MOCK_CLASS( mock_class_with_const_conversion_operator )
{
MOCK_CONST_CONVERSION_OPERATOR( operator, int, conversion )
};
}
BOOST_FIXTURE_TEST_CASE( mock_const_conversion_operator, mock_error_fixture )
{
mock_class_with_const_conversion_operator m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
int i = m;
BOOST_CHECK_EQUAL( 42, i );
CHECK_CALLS( 1 );
}
namespace
{
MOCK_CLASS( mock_class_with_non_const_conversion_operator )
{
MOCK_CONST_CONVERSION_OPERATOR( operator, int, conversion )
};
}
BOOST_FIXTURE_TEST_CASE( mock_non_const_conversion_operator, mock_error_fixture )
{
mock_class_with_non_const_conversion_operator m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
int i = m;
BOOST_CHECK_EQUAL( 42, i );
CHECK_CALLS( 1 );
}
namespace
{
template< typename T >
MOCK_CLASS( mock_template_class_with_const_conversion_operator )
{
MOCK_CONST_CONVERSION_OPERATOR_TPL( operator, T, conversion )
};
}
BOOST_FIXTURE_TEST_CASE( mock_template_const_conversion_operator, mock_error_fixture )
{
mock_template_class_with_const_conversion_operator< int > m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
CHECK_CALLS( 1 );
}
namespace
{
template< typename T >
MOCK_CLASS( mock_template_class_with_non_const_conversion_operator )
{
MOCK_NON_CONST_CONVERSION_OPERATOR_TPL( operator, T, conversion )
};
}
BOOST_FIXTURE_TEST_CASE( mock_template_non_const_conversion_operator, mock_error_fixture )
{
mock_template_class_with_non_const_conversion_operator< int > m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
CHECK_CALLS( 1 );
}
namespace
{
MOCK_CLASS( my_mock )
{
MOCK_CONST_METHOD_EXT( my_method, 1, void( int ), my_method )
MOCK_CONST_METHOD_EXT( my_method_2, 1, void( int ), my_method_2 )
};
}
BOOST_FIXTURE_TEST_CASE( MOCK_CONST_METHOD_EXT_macro_defines_a_bindable_method, mock_error_fixture )
{
my_mock m;
boost::bind( &my_mock::my_method, &m, 42 );
}
BOOST_FIXTURE_TEST_CASE( MOCK_VERIFY_macro, mock_error_fixture )
{
my_mock m;
MOCK_VERIFY( m.my_method );
}
BOOST_FIXTURE_TEST_CASE( MOCK_RESET_macro, mock_error_fixture )
{
my_mock m;
MOCK_RESET( m.my_method );
}
BOOST_FIXTURE_TEST_CASE( MOCK_EXPECT_macro, mock_error_fixture )
{
my_mock m;
MOCK_EXPECT( m.my_method ).once().with( 42 );
m.my_method( 42 );
CHECK_CALLS( 1 );
}
namespace
{
template< typename T >
std::string to_string( const T& t )
{
std::stringstream s;
s << t;
return s.str();
}
}
BOOST_FIXTURE_TEST_CASE( mock_object_is_named, mock_error_fixture )
{
my_mock m;
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m.my_method ) ) );
BOOST_CHECK_EQUAL( "?.my_mock::my_method_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_method_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_mock::my_method", to_string( MOCK_HELPER( m.my_method ) ) );
BOOST_CHECK_EQUAL( "m.my_mock::my_method_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_method_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m.my_method ) ) );
BOOST_CHECK_EQUAL( "m.my_mock::my_method", to_string( MOCK_HELPER( m.my_method ) ) );
}
BOOST_FIXTURE_TEST_CASE( mock_object_auto_pointer_is_named, mock_error_fixture )
{
std::auto_ptr< my_mock > m( new my_mock );
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
}
BOOST_FIXTURE_TEST_CASE( mock_object_const_auto_pointer_is_named, mock_error_fixture )
{
const std::auto_ptr< my_mock > m( new my_mock );
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
}
BOOST_FIXTURE_TEST_CASE( mock_object_shared_pointer_is_named, mock_error_fixture )
{
boost::shared_ptr< my_mock > m( new my_mock );
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
}
BOOST_FIXTURE_TEST_CASE( mock_object_const_shared_pointer_is_named, mock_error_fixture )
{
const boost::shared_ptr< my_mock > m( new my_mock );
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
}
namespace
{
struct my_custom_mock
{
MOCK_METHOD_EXT( my_method, 0, void(), my_tag )
MOCK_METHOD_EXT( my_method_2, 0, void(), my_tag_2 )
};
}
BOOST_FIXTURE_TEST_CASE( custom_mock_object_without_macros_and_without_inheriting_from_object_is_named, mock_error_fixture )
{
my_custom_mock m;
BOOST_CHECK_EQUAL( "?.my_custom_mock::my_tag", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "?.my_custom_mock::my_tag_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock::my_tag", to_string( MOCK_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock::my_tag_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock::my_tag", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock::my_tag", to_string( MOCK_HELPER( m.my_tag ) ) );
}
namespace
{
struct my_custom_mock_object : mock::object
{
MOCK_METHOD_EXT( my_method, 0, void(), my_tag )
MOCK_METHOD_EXT( my_method_2, 0, void(), my_tag_2 )
};
}
BOOST_FIXTURE_TEST_CASE( custom_mock_object_without_macros_is_named, mock_error_fixture )
{
my_custom_mock_object m;
BOOST_CHECK_EQUAL( "?.my_custom_mock_object::my_tag", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "?.my_custom_mock_object::my_tag_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock_object::my_tag", to_string( MOCK_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock_object::my_tag_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock_object::my_tag", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock_object::my_tag", to_string( MOCK_HELPER( m.my_tag ) ) );
}
BOOST_FIXTURE_TEST_CASE( mock_functor, mock_error_fixture )
{
MOCK_FUNCTOR( f1, void() );
MOCK_FUNCTOR( f2, int( const std::string& ) );
}
namespace
{
template< typename T >
struct tpl_functor_class
{
MOCK_FUNCTOR_TPL( f, void( T ) );
};
}
BOOST_FIXTURE_TEST_CASE( mock_functor_reset, mock_error_fixture )
{
MOCK_FUNCTOR( f, void() );
MOCK_RESET( f );
mock::reset( f );
}
BOOST_FIXTURE_TEST_CASE( mock_functor_verify, mock_error_fixture )
{
MOCK_FUNCTOR( f, void() );
MOCK_VERIFY( f );
mock::verify( f );
}
BOOST_FIXTURE_TEST_CASE( mock_functor_is_named, mock_error_fixture )
{
MOCK_FUNCTOR( f, void() );
BOOST_CHECK_EQUAL( "f", to_string( MOCK_HELPER( f ) ) );
}
namespace
{
MOCK_FUNCTION( mock_function, 1, float( int ), mock_function )
}
BOOST_FIXTURE_TEST_CASE( mock_function_is_named, mock_error_fixture )
{
BOOST_CHECK_EQUAL( "mock_function", to_string( MOCK_HELPER( mock_function ) ) );
}
namespace
{
MOCK_CLASS( static_function_class )
{
MOCK_STATIC_METHOD( f, 1, float( int ), f )
};
}
BOOST_FIXTURE_TEST_CASE( mock_static_function_is_named, mock_error_fixture )
{
BOOST_CHECK_EQUAL( "static_function_class::f", to_string( MOCK_HELPER( static_function_class::f ) ) );
}
namespace
{
MOCK_CLASS( round_parenthesized_signature )
{
MOCK_METHOD_EXT( m0, 0, (std::map< int, int >()), m0 )
MOCK_STATIC_METHOD( m1, 0, (std::map< int, int >()), m1 )
MOCK_FUNCTOR( f0, (std::map< int, int >()) );
};
MOCK_FUNCTION( fun0, 0, (std::map< int, int >()), fun0 )
}
#ifdef MOCK_VARIADIC_MACROS
namespace
{
struct base
{
virtual ~base()
{}
virtual void m1() = 0;
};
MOCK_BASE_CLASS( variadic, base )
{
MOCK_METHOD( m1, 0 )
MOCK_METHOD( m2, 0, void() )
MOCK_METHOD( m3, 0, void(), m3 )
MOCK_CONST_METHOD( m4, 0, void() )
MOCK_CONST_METHOD( m5, 0, void(), m5 )
MOCK_NON_CONST_METHOD( m6, 0, void() )
MOCK_NON_CONST_METHOD( m7, 0, void(), m7 )
MOCK_STATIC_METHOD( m8, 0, void() )
MOCK_STATIC_METHOD( m9, 0, void(), m9 )
};
template< typename T >
MOCK_CLASS( variadic_tpl )
{
MOCK_METHOD_TPL( m2, 0, T() )
MOCK_METHOD_TPL( m3, 0, T(), m3 )
MOCK_CONST_METHOD_TPL( m4, 0, T() )
MOCK_CONST_METHOD_TPL( m5, 0, T(), m5 )
MOCK_NON_CONST_METHOD_TPL( m6, 0, T() )
MOCK_NON_CONST_METHOD_TPL( m7, 0, T(), m7 )
MOCK_STATIC_METHOD_TPL( m8, 0, T() )
MOCK_STATIC_METHOD_TPL( m9, 0, T(), m9 )
};
MOCK_BASE_CLASS( comma_base, std::map< int, int > )
{};
MOCK_FUNCTION( fun1, 0, void() )
MOCK_FUNCTION( fun2, 0, void(), fun2 )
MOCK_FUNCTION( fun3, 0, (std::map< int, int >()) )
MOCK_FUNCTOR( f_variadic, std::map< int, int >() );
}
#endif // MOCK_VARIADIC_MACROS
#ifdef BOOST_MSVC
# define MOCK_STDCALL __stdcall
#elif defined( BOOST_GCC )
# define MOCK_STDCALL __attribute((stdcall))
#else
# define MOCK_STDCALL
#endif // BOOST_GCC
namespace stdcall
{
struct base
{
virtual void MOCK_STDCALL m1() = 0;
};
MOCK_BASE_CLASS( derived, base )
{
MOCK_CONSTRUCTOR( MOCK_STDCALL derived, 0, (), derived )
MOCK_DESTRUCTOR( MOCK_STDCALL ~derived, derived )
MOCK_CONVERSION_OPERATOR( MOCK_STDCALL operator, int, to_int )
MOCK_METHOD_EXT( MOCK_STDCALL m1, 0, void(), m1 )
MOCK_METHOD_EXT( MOCK_STDCALL m2, 0, void(), m2 )
#ifdef MOCK_VARIADIC_MACROS
MOCK_METHOD( MOCK_STDCALL m3, 0, void(), m3 )
#endif
MOCK_STATIC_METHOD( MOCK_STDCALL m4, 0, void(), m4 )
};
MOCK_FUNCTION( MOCK_STDCALL f, 0, void(), f )
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2009
//
// 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 "mock_error.hpp"
#include <turtle/mock.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/bind.hpp>
namespace
{
template< typename T >
void my_function( T& t )
{
t.my_method( "some parameter" );
}
MOCK_CLASS( mock_class )
{
MOCK_METHOD_EXT( my_method, 1, void( const std::string& ), my_tag )
};
}
BOOST_FIXTURE_TEST_CASE( mock_object_for_static_polymorphism, mock_error_fixture )
{
const mock_class m;
MOCK_EXPECT( m.my_tag ).once().with( "some parameter" );
my_function( m );
CHECK_CALLS( 1 );
}
namespace
{
MOCK_CLASS( mock_class_with_operator )
{
MOCK_CONST_METHOD_EXT( operator+=, 1, mock_class_with_operator&( int ), addition )
};
}
BOOST_FIXTURE_TEST_CASE( mock_addition_operator, mock_error_fixture )
{
mock_class_with_operator m;
MOCK_EXPECT( m.addition ).once().returns( boost::ref( m ) );
m += 1;
CHECK_CALLS( 1 );
}
namespace
{
MOCK_CLASS( mock_class_with_conversion_operator )
{
MOCK_CONVERSION_OPERATOR( operator, int, conversion )
};
}
BOOST_FIXTURE_TEST_CASE( mock_conversion_operator, mock_error_fixture )
{
mock_class_with_conversion_operator m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
CHECK_CALLS( 1 );
}
namespace
{
template< typename T >
MOCK_CLASS( mock_template_class_with_conversion_operator )
{
MOCK_CONVERSION_OPERATOR_TPL( operator, T, conversion )
};
}
BOOST_FIXTURE_TEST_CASE( mock_template_conversion_operator, mock_error_fixture )
{
mock_template_class_with_conversion_operator< int > m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
CHECK_CALLS( 1 );
}
namespace
{
MOCK_CLASS( mock_class_with_const_conversion_operator )
{
MOCK_CONST_CONVERSION_OPERATOR( operator, int, conversion )
};
}
BOOST_FIXTURE_TEST_CASE( mock_const_conversion_operator, mock_error_fixture )
{
mock_class_with_const_conversion_operator m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
int i = m;
BOOST_CHECK_EQUAL( 42, i );
CHECK_CALLS( 1 );
}
namespace
{
MOCK_CLASS( mock_class_with_non_const_conversion_operator )
{
MOCK_CONST_CONVERSION_OPERATOR( operator, int, conversion )
};
}
BOOST_FIXTURE_TEST_CASE( mock_non_const_conversion_operator, mock_error_fixture )
{
mock_class_with_non_const_conversion_operator m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
int i = m;
BOOST_CHECK_EQUAL( 42, i );
CHECK_CALLS( 1 );
}
namespace
{
template< typename T >
MOCK_CLASS( mock_template_class_with_const_conversion_operator )
{
MOCK_CONST_CONVERSION_OPERATOR_TPL( operator, T, conversion )
};
}
BOOST_FIXTURE_TEST_CASE( mock_template_const_conversion_operator, mock_error_fixture )
{
mock_template_class_with_const_conversion_operator< int > m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
CHECK_CALLS( 1 );
}
namespace
{
template< typename T >
MOCK_CLASS( mock_template_class_with_non_const_conversion_operator )
{
MOCK_NON_CONST_CONVERSION_OPERATOR_TPL( operator, T, conversion )
};
}
BOOST_FIXTURE_TEST_CASE( mock_template_non_const_conversion_operator, mock_error_fixture )
{
mock_template_class_with_non_const_conversion_operator< int > m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
CHECK_CALLS( 1 );
}
namespace
{
MOCK_CLASS( my_mock )
{
MOCK_CONST_METHOD_EXT( my_method, 1, void( int ), my_method )
MOCK_CONST_METHOD_EXT( my_method_2, 1, void( int ), my_method_2 )
};
}
BOOST_FIXTURE_TEST_CASE( MOCK_CONST_METHOD_EXT_macro_defines_a_bindable_method, mock_error_fixture )
{
my_mock m;
boost::bind( &my_mock::my_method, &m, 42 );
}
BOOST_FIXTURE_TEST_CASE( MOCK_VERIFY_macro, mock_error_fixture )
{
my_mock m;
MOCK_VERIFY( m.my_method );
}
BOOST_FIXTURE_TEST_CASE( MOCK_RESET_macro, mock_error_fixture )
{
my_mock m;
MOCK_RESET( m.my_method );
}
BOOST_FIXTURE_TEST_CASE( MOCK_EXPECT_macro, mock_error_fixture )
{
my_mock m;
MOCK_EXPECT( m.my_method ).once().with( 42 );
m.my_method( 42 );
CHECK_CALLS( 1 );
}
namespace
{
template< typename T >
std::string to_string( const T& t )
{
std::stringstream s;
s << t;
return s.str();
}
}
BOOST_FIXTURE_TEST_CASE( mock_object_is_named, mock_error_fixture )
{
my_mock m;
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m.my_method ) ) );
BOOST_CHECK_EQUAL( "?.my_mock::my_method_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_method_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_mock::my_method", to_string( MOCK_HELPER( m.my_method ) ) );
BOOST_CHECK_EQUAL( "m.my_mock::my_method_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_method_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m.my_method ) ) );
BOOST_CHECK_EQUAL( "m.my_mock::my_method", to_string( MOCK_HELPER( m.my_method ) ) );
}
BOOST_FIXTURE_TEST_CASE( mock_object_auto_pointer_is_named, mock_error_fixture )
{
std::auto_ptr< my_mock > m( new my_mock );
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
}
BOOST_FIXTURE_TEST_CASE( mock_object_const_auto_pointer_is_named, mock_error_fixture )
{
const std::auto_ptr< my_mock > m( new my_mock );
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
}
BOOST_FIXTURE_TEST_CASE( mock_object_shared_pointer_is_named, mock_error_fixture )
{
boost::shared_ptr< my_mock > m( new my_mock );
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
}
BOOST_FIXTURE_TEST_CASE( mock_object_const_shared_pointer_is_named, mock_error_fixture )
{
const boost::shared_ptr< my_mock > m( new my_mock );
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
}
namespace
{
struct my_custom_mock
{
MOCK_METHOD_EXT( my_method, 0, void(), my_tag )
MOCK_METHOD_EXT( my_method_2, 0, void(), my_tag_2 )
};
}
BOOST_FIXTURE_TEST_CASE( custom_mock_object_without_macros_and_without_inheriting_from_object_is_named, mock_error_fixture )
{
my_custom_mock m;
BOOST_CHECK_EQUAL( "?.my_custom_mock::my_tag", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "?.my_custom_mock::my_tag_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock::my_tag", to_string( MOCK_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock::my_tag_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock::my_tag", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock::my_tag", to_string( MOCK_HELPER( m.my_tag ) ) );
}
namespace
{
struct my_custom_mock_object : mock::object
{
MOCK_METHOD_EXT( my_method, 0, void(), my_tag )
MOCK_METHOD_EXT( my_method_2, 0, void(), my_tag_2 )
};
}
BOOST_FIXTURE_TEST_CASE( custom_mock_object_without_macros_is_named, mock_error_fixture )
{
my_custom_mock_object m;
BOOST_CHECK_EQUAL( "?.my_custom_mock_object::my_tag", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "?.my_custom_mock_object::my_tag_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock_object::my_tag", to_string( MOCK_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock_object::my_tag_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock_object::my_tag", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock_object::my_tag", to_string( MOCK_HELPER( m.my_tag ) ) );
}
BOOST_FIXTURE_TEST_CASE( mock_functor, mock_error_fixture )
{
MOCK_FUNCTOR( f1, void() );
MOCK_FUNCTOR( f2, int( const std::string& ) );
}
namespace
{
template< typename T >
struct tpl_functor_class
{
MOCK_FUNCTOR_TPL( f, void( T ) );
};
}
BOOST_FIXTURE_TEST_CASE( mock_functor_reset, mock_error_fixture )
{
MOCK_FUNCTOR( f, void() );
MOCK_RESET( f );
mock::reset( f );
}
BOOST_FIXTURE_TEST_CASE( mock_functor_verify, mock_error_fixture )
{
MOCK_FUNCTOR( f, void() );
MOCK_VERIFY( f );
mock::verify( f );
}
BOOST_FIXTURE_TEST_CASE( mock_functor_is_named, mock_error_fixture )
{
MOCK_FUNCTOR( f, void() );
BOOST_CHECK_EQUAL( "f", to_string( MOCK_HELPER( f ) ) );
}
namespace
{
MOCK_FUNCTION( mock_function, 1, float( int ), mock_function )
}
BOOST_FIXTURE_TEST_CASE( mock_function_is_named, mock_error_fixture )
{
BOOST_CHECK_EQUAL( "mock_function", to_string( MOCK_HELPER( mock_function ) ) );
}
namespace
{
MOCK_CLASS( static_function_class )
{
MOCK_STATIC_METHOD( f, 1, float( int ), f )
};
}
BOOST_FIXTURE_TEST_CASE( mock_static_function_is_named, mock_error_fixture )
{
BOOST_CHECK_EQUAL( "static_function_class::f", to_string( MOCK_HELPER( static_function_class::f ) ) );
}
namespace
{
MOCK_CLASS( round_parenthesized_signature )
{
MOCK_METHOD_EXT( m0, 0, (std::map< int, int >()), m0 )
MOCK_STATIC_METHOD( m1, 0, (std::map< int, int >()), m1 )
MOCK_FUNCTOR( f0, (std::map< int, int >()) );
};
MOCK_FUNCTION( fun0, 0, (std::map< int, int >()), fun0 )
}
#ifdef MOCK_VARIADIC_MACROS
namespace
{
struct base
{
virtual ~base()
{}
virtual void m1() = 0;
};
MOCK_BASE_CLASS( variadic, base )
{
MOCK_METHOD( m1, 0 )
MOCK_METHOD( m2, 0, void() )
MOCK_METHOD( m3, 0, void(), m3 )
MOCK_CONST_METHOD( m4, 0, void() )
MOCK_CONST_METHOD( m5, 0, void(), m5 )
MOCK_NON_CONST_METHOD( m6, 0, void() )
MOCK_NON_CONST_METHOD( m7, 0, void(), m7 )
MOCK_STATIC_METHOD( m8, 0, void() )
MOCK_STATIC_METHOD( m9, 0, void(), m9 )
};
template< typename T >
MOCK_CLASS( variadic_tpl )
{
MOCK_METHOD_TPL( m2, 0, T() )
MOCK_METHOD_TPL( m3, 0, T(), m3 )
MOCK_CONST_METHOD_TPL( m4, 0, T() )
MOCK_CONST_METHOD_TPL( m5, 0, T(), m5 )
MOCK_NON_CONST_METHOD_TPL( m6, 0, T() )
MOCK_NON_CONST_METHOD_TPL( m7, 0, T(), m7 )
MOCK_STATIC_METHOD_TPL( m8, 0, T() )
MOCK_STATIC_METHOD_TPL( m9, 0, T(), m9 )
};
MOCK_BASE_CLASS( comma_base, std::map< int, int > )
{};
MOCK_FUNCTION( fun1, 0, void() )
MOCK_FUNCTION( fun2, 0, void(), fun2 )
MOCK_FUNCTION( fun3, 0, (std::map< int, int >()) )
MOCK_FUNCTOR( f_variadic, std::map< int, int >() );
}
#endif // MOCK_VARIADIC_MACROS
#ifdef BOOST_MSVC
# define MOCK_STDCALL __stdcall
#elif defined( BOOST_GCC )
# define MOCK_STDCALL __attribute((stdcall))
#else
# define MOCK_STDCALL
#endif // BOOST_GCC
namespace stdcall
{
struct base
{
virtual void MOCK_STDCALL m1() = 0;
};
MOCK_BASE_CLASS( derived, base )
{
MOCK_CONSTRUCTOR( MOCK_STDCALL derived, 0, (), derived )
MOCK_DESTRUCTOR( MOCK_STDCALL ~derived, derived )
MOCK_CONVERSION_OPERATOR( MOCK_STDCALL operator, int, to_int )
MOCK_METHOD_EXT( MOCK_STDCALL m1, 0, void(), m1 )
MOCK_METHOD_EXT( MOCK_STDCALL m2, 0, void(), m2 )
#ifdef MOCK_VARIADIC_MACROS
MOCK_METHOD( MOCK_STDCALL m3, 0, void(), m3 )
#endif
MOCK_STATIC_METHOD( MOCK_STDCALL m4, 0, void(), m4 )
};
MOCK_FUNCTION( MOCK_STDCALL f, 0, void(), f )
}

View file

@ -1,107 +1,107 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// 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 "mock_error.hpp"
#include <turtle/reset.hpp>
#include <turtle/verify.hpp>
#include <turtle/detail/function.hpp>
#include <boost/test/auto_unit_test.hpp>
namespace
{
struct object : mock::object
{};
object static_o;
}
BOOST_FIXTURE_TEST_CASE( verifying_an_empty_object_succeeds, mock_error_fixture )
{
object o;
BOOST_CHECK( mock::verify( o ) );
}
namespace
{
struct fixture : mock_error_fixture
{
fixture()
{
mock::detail::configure( o, e, "instance", MOCK_TYPE_NAME(o), "name" );
}
object o;
mock::detail::function< void() > e;
};
}
BOOST_FIXTURE_TEST_CASE( verifying_an_object_containing_a_failing_expectation_fails, fixture )
{
e.expect().once();
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
mock::reset( o );
BOOST_CHECK( mock::verify( o ) );
}
BOOST_FIXTURE_TEST_CASE( verifying_all_objects_with_one_of_them_containing_a_failing_expectation_fails, fixture )
{
e.expect().once();
CHECK_ERROR(
BOOST_CHECK( ! mock::verify() ),
"verification failed", 0, "instanceobject::name\n. once()" );
mock::reset();
BOOST_CHECK( mock::verify() );
}
BOOST_FIXTURE_TEST_CASE( resetting_an_object_containing_a_failing_expectation_and_verifying_it_succeeds, fixture )
{
e.expect().once();
mock::reset( o );
BOOST_CHECK( mock::verify( o ) );
}
BOOST_FIXTURE_TEST_CASE( an_object_is_assignable_by_sharing_its_state, mock_error_fixture )
{
object o1;
mock::detail::function< void() > e;
{
object o2;
mock::detail::configure( o2, e, "instance", MOCK_TYPE_NAME(o2), "name" );
e.expect().once();
o1 = o2;
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o1 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o2 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
}
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o1 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
}
BOOST_FIXTURE_TEST_CASE( an_object_is_copiable_by_sharing_its_state, mock_error_fixture )
{
std::auto_ptr< object > o2( new object );
const object o1( *o2 );
mock::detail::function< void() > e;
mock::detail::configure( *o2, e, "instance", MOCK_TYPE_NAME(*o2), "name" );
e.expect().once();
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( *o2 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o1 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
o2.reset();
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o1 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// 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 "mock_error.hpp"
#include <turtle/reset.hpp>
#include <turtle/verify.hpp>
#include <turtle/detail/function.hpp>
#include <boost/test/auto_unit_test.hpp>
namespace
{
struct object : mock::object
{};
object static_o;
}
BOOST_FIXTURE_TEST_CASE( verifying_an_empty_object_succeeds, mock_error_fixture )
{
object o;
BOOST_CHECK( mock::verify( o ) );
}
namespace
{
struct fixture : mock_error_fixture
{
fixture()
{
mock::detail::configure( o, e, "instance", MOCK_TYPE_NAME(o), "name" );
}
object o;
mock::detail::function< void() > e;
};
}
BOOST_FIXTURE_TEST_CASE( verifying_an_object_containing_a_failing_expectation_fails, fixture )
{
e.expect().once();
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
mock::reset( o );
BOOST_CHECK( mock::verify( o ) );
}
BOOST_FIXTURE_TEST_CASE( verifying_all_objects_with_one_of_them_containing_a_failing_expectation_fails, fixture )
{
e.expect().once();
CHECK_ERROR(
BOOST_CHECK( ! mock::verify() ),
"verification failed", 0, "instanceobject::name\n. once()" );
mock::reset();
BOOST_CHECK( mock::verify() );
}
BOOST_FIXTURE_TEST_CASE( resetting_an_object_containing_a_failing_expectation_and_verifying_it_succeeds, fixture )
{
e.expect().once();
mock::reset( o );
BOOST_CHECK( mock::verify( o ) );
}
BOOST_FIXTURE_TEST_CASE( an_object_is_assignable_by_sharing_its_state, mock_error_fixture )
{
object o1;
mock::detail::function< void() > e;
{
object o2;
mock::detail::configure( o2, e, "instance", MOCK_TYPE_NAME(o2), "name" );
e.expect().once();
o1 = o2;
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o1 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o2 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
}
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o1 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
}
BOOST_FIXTURE_TEST_CASE( an_object_is_copiable_by_sharing_its_state, mock_error_fixture )
{
std::auto_ptr< object > o2( new object );
const object o1( *o2 );
mock::detail::function< void() > e;
mock::detail::configure( *o2, e, "instance", MOCK_TYPE_NAME(*o2), "name" );
e.expect().once();
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( *o2 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o1 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
o2.reset();
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o1 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
}

View file

@ -1,114 +1,114 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// 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 "mock_error.hpp"
#include <turtle/sequence.hpp>
#include <turtle/detail/function.hpp>
#include <boost/test/auto_unit_test.hpp>
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_calling_out_of_order_throws, mock_error_fixture )
{
mock::sequence s;
mock::detail::function< void( int ) > e;
e.expect().once().with( 1 ).in( s );
e.expect().once().with( 2 ).in( s );
BOOST_CHECK_NO_THROW( e( 2 ) );
CHECK_ERROR( e( 1 ), "sequence failed", 1, "?( 1 )\n. once().with( 1 )\nv once().with( 2 )" );
}
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_calling_out_of_order_multiple_invocations_throws, mock_error_fixture )
{
mock::sequence s;
mock::detail::function< void( int ) > e;
e.expect().with( 1 ).in( s );
e.expect().once().with( 2 ).in( s );
BOOST_CHECK_NO_THROW( e( 1 ) );
BOOST_CHECK_NO_THROW( e( 2 ) );
CHECK_ERROR( e( 1 ), "sequence failed", 2, "?( 1 )\n. unlimited().with( 1 )\nv once().with( 2 )" );
}
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_calling_in_order_is_valid, mock_error_fixture )
{
mock::sequence s;
mock::detail::function< void( int ) > e;
e.expect().once().with( 1 ).in( s );
e.expect().once().with( 2 ).in( s );
BOOST_CHECK_NO_THROW( e( 1 ) );
BOOST_CHECK_NO_THROW( e( 2 ) );
BOOST_CHECK( e.verify() );
CHECK_CALLS( 2 );
}
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_multiply_calling_in_order_is_valid, mock_error_fixture )
{
mock::sequence s;
mock::detail::function< void( int ) > e;
e.expect().exactly( 2 ).with( 1 ).in( s );
e.expect().exactly( 2 ).with( 2 ).in( s );
BOOST_CHECK_NO_THROW( e( 1 ) );
BOOST_CHECK_NO_THROW( e( 1 ) );
BOOST_CHECK_NO_THROW( e( 2 ) );
BOOST_CHECK_NO_THROW( e( 2 ) );
BOOST_CHECK( e.verify() );
CHECK_CALLS( 4 );
}
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_enforces_call_order_verification_between_two_different_expectations, mock_error_fixture )
{
mock::sequence s;
mock::detail::function< void() > e1, e2;
e1.expect().once().in( s );
e2.expect().once().in( s );
BOOST_CHECK_NO_THROW( e2() );
CHECK_ERROR( e1(), "sequence failed", 1, "?()\n. once()" );
}
BOOST_FIXTURE_TEST_CASE( destroying_a_sequence_does_not_remove_order_call_enforcement, mock_error_fixture )
{
mock::detail::function< void() > e1, e2;
{
mock::sequence s;
e1.expect().once().in( s );
e2.expect().once().in( s );
}
BOOST_CHECK_NO_THROW( e2() );
CHECK_ERROR( e1(), "sequence failed", 1, "?()\n. once()" );
}
BOOST_FIXTURE_TEST_CASE( resetting_an_expectation_removes_it_from_order_call_enforcement, mock_error_fixture )
{
mock::sequence s;
mock::detail::function< void() > e1, e2;
e1.expect().once().in( s );
e2.expect().once().in( s );
e1.reset();
BOOST_CHECK_NO_THROW( e2() );
BOOST_CHECK( e1.verify() );
BOOST_CHECK( e2.verify() );
CHECK_CALLS( 1 );
}
BOOST_FIXTURE_TEST_CASE( an_expectation_can_be_used_in_several_sequences, mock_error_fixture )
{
mock::sequence s1, s2;
mock::detail::function< void() > e;
e.expect().once().in( s1, s2 );
BOOST_CHECK_NO_THROW( e() );
BOOST_CHECK( e.verify() );
CHECK_CALLS( 1 );
}
BOOST_FIXTURE_TEST_CASE( a_result_specification_is_set_after_a_sequence, mock_error_fixture )
{
mock::sequence s;
mock::detail::function< int() > e;
e.expect().once().in( s ).returns( 3 );
BOOST_CHECK_EQUAL( 3, e() );
BOOST_CHECK( e.verify() );
CHECK_CALLS( 1 );
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2008
//
// 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 "mock_error.hpp"
#include <turtle/sequence.hpp>
#include <turtle/detail/function.hpp>
#include <boost/test/auto_unit_test.hpp>
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_calling_out_of_order_throws, mock_error_fixture )
{
mock::sequence s;
mock::detail::function< void( int ) > e;
e.expect().once().with( 1 ).in( s );
e.expect().once().with( 2 ).in( s );
BOOST_CHECK_NO_THROW( e( 2 ) );
CHECK_ERROR( e( 1 ), "sequence failed", 1, "?( 1 )\n. once().with( 1 )\nv once().with( 2 )" );
}
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_calling_out_of_order_multiple_invocations_throws, mock_error_fixture )
{
mock::sequence s;
mock::detail::function< void( int ) > e;
e.expect().with( 1 ).in( s );
e.expect().once().with( 2 ).in( s );
BOOST_CHECK_NO_THROW( e( 1 ) );
BOOST_CHECK_NO_THROW( e( 2 ) );
CHECK_ERROR( e( 1 ), "sequence failed", 2, "?( 1 )\n. unlimited().with( 1 )\nv once().with( 2 )" );
}
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_calling_in_order_is_valid, mock_error_fixture )
{
mock::sequence s;
mock::detail::function< void( int ) > e;
e.expect().once().with( 1 ).in( s );
e.expect().once().with( 2 ).in( s );
BOOST_CHECK_NO_THROW( e( 1 ) );
BOOST_CHECK_NO_THROW( e( 2 ) );
BOOST_CHECK( e.verify() );
CHECK_CALLS( 2 );
}
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_multiply_calling_in_order_is_valid, mock_error_fixture )
{
mock::sequence s;
mock::detail::function< void( int ) > e;
e.expect().exactly( 2 ).with( 1 ).in( s );
e.expect().exactly( 2 ).with( 2 ).in( s );
BOOST_CHECK_NO_THROW( e( 1 ) );
BOOST_CHECK_NO_THROW( e( 1 ) );
BOOST_CHECK_NO_THROW( e( 2 ) );
BOOST_CHECK_NO_THROW( e( 2 ) );
BOOST_CHECK( e.verify() );
CHECK_CALLS( 4 );
}
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_enforces_call_order_verification_between_two_different_expectations, mock_error_fixture )
{
mock::sequence s;
mock::detail::function< void() > e1, e2;
e1.expect().once().in( s );
e2.expect().once().in( s );
BOOST_CHECK_NO_THROW( e2() );
CHECK_ERROR( e1(), "sequence failed", 1, "?()\n. once()" );
}
BOOST_FIXTURE_TEST_CASE( destroying_a_sequence_does_not_remove_order_call_enforcement, mock_error_fixture )
{
mock::detail::function< void() > e1, e2;
{
mock::sequence s;
e1.expect().once().in( s );
e2.expect().once().in( s );
}
BOOST_CHECK_NO_THROW( e2() );
CHECK_ERROR( e1(), "sequence failed", 1, "?()\n. once()" );
}
BOOST_FIXTURE_TEST_CASE( resetting_an_expectation_removes_it_from_order_call_enforcement, mock_error_fixture )
{
mock::sequence s;
mock::detail::function< void() > e1, e2;
e1.expect().once().in( s );
e2.expect().once().in( s );
e1.reset();
BOOST_CHECK_NO_THROW( e2() );
BOOST_CHECK( e1.verify() );
BOOST_CHECK( e2.verify() );
CHECK_CALLS( 1 );
}
BOOST_FIXTURE_TEST_CASE( an_expectation_can_be_used_in_several_sequences, mock_error_fixture )
{
mock::sequence s1, s2;
mock::detail::function< void() > e;
e.expect().once().in( s1, s2 );
BOOST_CHECK_NO_THROW( e() );
BOOST_CHECK( e.verify() );
CHECK_CALLS( 1 );
}
BOOST_FIXTURE_TEST_CASE( a_result_specification_is_set_after_a_sequence, mock_error_fixture )
{
mock::sequence s;
mock::detail::function< int() > e;
e.expect().once().in( s ).returns( 3 );
BOOST_CHECK_EQUAL( 3, e() );
BOOST_CHECK( e.verify() );
CHECK_CALLS( 1 );
}

View file

@ -1,18 +1,18 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2013
//
// 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 "undefined.hpp"
struct undefined
{};
undefined& get_undefined()
{
static undefined u;
return u;
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2013
//
// 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 "undefined.hpp"
struct undefined
{};
undefined& get_undefined()
{
static undefined u;
return u;
}

View file

@ -1,16 +1,16 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2013
//
// 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_TEST_UNDEFINED_HPP_INCLUDED
#define MOCK_TEST_UNDEFINED_HPP_INCLUDED
struct undefined;
undefined& get_undefined();
#endif // MOCK_TEST_UNDEFINED_HPP_INCLUDED
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2013
//
// 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_TEST_UNDEFINED_HPP_INCLUDED
#define MOCK_TEST_UNDEFINED_HPP_INCLUDED
struct undefined;
undefined& get_undefined();
#endif // MOCK_TEST_UNDEFINED_HPP_INCLUDED