mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Added support for Boost.Phoenix
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@113 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
05654f9f5f
commit
0bcfffcc03
7 changed files with 55 additions and 71 deletions
|
|
@ -6,8 +6,8 @@
|
|||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef MOCK_RESULT_HPP_INCLUDED
|
||||
#define MOCK_RESULT_HPP_INCLUDED
|
||||
#ifndef MOCK_ACTION_HPP_INCLUDED
|
||||
#define MOCK_ACTION_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include <boost/bind.hpp>
|
||||
|
|
@ -19,7 +19,7 @@ namespace mock
|
|||
namespace detail
|
||||
{
|
||||
template< typename T, typename Signature >
|
||||
class result
|
||||
class action
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
boost::function< Signature > functor_type;
|
||||
|
|
@ -75,7 +75,7 @@ namespace detail
|
|||
};
|
||||
|
||||
template< typename T, typename Signature >
|
||||
class result< T*, Signature >
|
||||
class action< T*, Signature >
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
boost::function< Signature > functor_type;
|
||||
|
|
@ -125,13 +125,13 @@ namespace detail
|
|||
};
|
||||
|
||||
template< typename Signature >
|
||||
class result< void, Signature >
|
||||
class action< void, Signature >
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
boost::function< Signature > functor_type;
|
||||
|
||||
public:
|
||||
result()
|
||||
action()
|
||||
: f_( boost::bind( ¬hing ) )
|
||||
{}
|
||||
|
||||
|
|
@ -167,18 +167,18 @@ namespace detail
|
|||
};
|
||||
|
||||
template< typename T, typename Signature >
|
||||
class result< std::auto_ptr< T >, Signature >
|
||||
class action< std::auto_ptr< T >, Signature >
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
boost::function< Signature > functor_type;
|
||||
|
||||
public:
|
||||
result()
|
||||
action()
|
||||
: t_()
|
||||
, f_()
|
||||
{}
|
||||
result( const result& rhs )
|
||||
: t_( const_cast< result& >( rhs ).t_.release() )
|
||||
action( const action& rhs )
|
||||
: t_( const_cast< action& >( rhs ).t_.release() )
|
||||
, f_( t_.get() ? boost::bind( &return_value, boost::ref( t_ ) ) : rhs.f_ )
|
||||
{}
|
||||
|
||||
|
|
@ -245,4 +245,4 @@ namespace detail
|
|||
}
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_RESULT_HPP_INCLUDED
|
||||
#endif // #ifndef MOCK_ACTION_HPP_INCLUDED
|
||||
|
|
@ -11,61 +11,39 @@
|
|||
|
||||
#include <boost/function_types/is_callable_builtin.hpp>
|
||||
#include <boost/type_traits/integral_constant.hpp>
|
||||
#include <boost/type_traits/detail/yes_no_type.hpp>
|
||||
#include <boost/mpl/or.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
typedef char true_type;
|
||||
struct false_type
|
||||
{
|
||||
true_type padding[2];
|
||||
typedef boost::type_traits::yes_type yes_type;
|
||||
typedef boost::type_traits::no_type no_type;
|
||||
|
||||
#define MOCK_IS_FUNCTION_HELPER(name, check) \
|
||||
template< typename T > yes_type& name##_helper( T*, BOOST_DEDUCED_TYPENAME T::check* = 0 ); \
|
||||
template< typename T > no_type& name##_helper( T, ... ); \
|
||||
template< typename T > struct name \
|
||||
{ \
|
||||
static T* t; \
|
||||
enum { value = sizeof( name##_helper( t ) ) == sizeof( yes_type ) }; \
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
true_type& has_result_type_tester( T*, BOOST_DEDUCED_TYPENAME T::result_type* = 0 );
|
||||
template< typename T >
|
||||
false_type& has_result_type_tester( T, ... );
|
||||
MOCK_IS_FUNCTION_HELPER( has_result_type, result_type )
|
||||
MOCK_IS_FUNCTION_HELPER( has_sig, sig< void > )
|
||||
MOCK_IS_FUNCTION_HELPER( has_result, result< void > )
|
||||
|
||||
template< typename T >
|
||||
struct has_result_type_impl
|
||||
{
|
||||
static T* t;
|
||||
enum { value = sizeof( has_result_type_tester( t ) ) == sizeof( true_type ) };
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
struct has_result_type : boost::integral_constant< bool, has_result_type_impl< T >::value >
|
||||
{
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
true_type& has_sig_tester( T*, BOOST_DEDUCED_TYPENAME T::template sig< void >* = 0 );
|
||||
template< typename T >
|
||||
false_type& has_sig_tester( T, ... );
|
||||
|
||||
template< typename T >
|
||||
struct has_sig_impl
|
||||
{
|
||||
static T* t;
|
||||
enum { value = sizeof( has_sig_tester( t ) ) == sizeof( true_type ) };
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
struct has_sig : boost::integral_constant< bool, has_sig_impl< T >::value >
|
||||
{
|
||||
};
|
||||
#undef MOCK_IS_FUNCTION_HELPER
|
||||
|
||||
template< typename T >
|
||||
struct is_functor
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::mpl::or_<
|
||||
BOOST_DEDUCED_TYPENAME boost::mpl::or_<
|
||||
BOOST_DEDUCED_TYPENAME boost::function_types::is_callable_builtin< T >::type,
|
||||
BOOST_DEDUCED_TYPENAME has_result_type< T >::type
|
||||
>::type,
|
||||
BOOST_DEDUCED_TYPENAME has_sig< T >::type
|
||||
BOOST_DEDUCED_TYPENAME boost::function_types::is_callable_builtin< T >::type,
|
||||
BOOST_DEDUCED_TYPENAME boost::integral_constant< bool, has_result_type< T >::value >::type,
|
||||
BOOST_DEDUCED_TYPENAME boost::integral_constant< bool, has_result< T >::value >::type,
|
||||
BOOST_DEDUCED_TYPENAME boost::integral_constant< bool, has_sig< T >::value >::type
|
||||
>::type type;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
#include "config.hpp"
|
||||
#include "invocation.hpp"
|
||||
#include "result.hpp"
|
||||
#include "action.hpp"
|
||||
#include "sequence.hpp"
|
||||
#include "check.hpp"
|
||||
#include "constraint.hpp"
|
||||
|
|
@ -149,7 +149,7 @@ namespace detail
|
|||
|
||||
template< typename Result, typename Signature >
|
||||
class matcher< Result, Signature, 0 >
|
||||
: public matcher_base, public result< Result, Signature >
|
||||
: public matcher_base, public action< Result, Signature >
|
||||
{
|
||||
public:
|
||||
bool is_valid() const
|
||||
|
|
@ -182,7 +182,7 @@ namespace detail
|
|||
#define MOCK_MATCHER(z, n, d) \
|
||||
template< typename Result, typename Signature > \
|
||||
class matcher< Result, Signature, n > \
|
||||
: public matcher_base, public result< Result, Signature > \
|
||||
: public matcher_base, public action< Result, Signature > \
|
||||
{ \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_MATCHER_TYPEDEF, BOOST_PP_EMPTY) \
|
||||
public: \
|
||||
|
|
|
|||
|
|
@ -147,16 +147,16 @@ namespace detail
|
|||
typedef T base_type;
|
||||
};
|
||||
|
||||
struct no_type
|
||||
struct invalid_type
|
||||
{
|
||||
private:
|
||||
no_type();
|
||||
invalid_type();
|
||||
};
|
||||
|
||||
template< typename S, int n, bool B >
|
||||
struct arg_imp
|
||||
{
|
||||
typedef no_type type;
|
||||
typedef invalid_type type;
|
||||
};
|
||||
template< typename S, int n >
|
||||
struct arg_imp< S, n, true >
|
||||
|
|
@ -195,7 +195,7 @@ namespace detail
|
|||
BOOST_DEDUCED_TYPENAME E::parameter_types, \
|
||||
n \
|
||||
>::type t##n
|
||||
#define MOCK_CALL_NO_TYPE(z, n, d) no_type
|
||||
#define MOCK_CALL_INVALID_TYPE(z, n, d) invalid_type
|
||||
#define MOCK_CALL(z, n, d) \
|
||||
template< typename E > \
|
||||
BOOST_DEDUCED_TYPENAME boost::enable_if< \
|
||||
|
|
@ -211,13 +211,13 @@ namespace detail
|
|||
BOOST_DEDUCED_TYPENAME has_arity< E, n >::type, \
|
||||
BOOST_DEDUCED_TYPENAME E::result_type \
|
||||
>::type \
|
||||
call( E BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, MOCK_CALL_NO_TYPE, BOOST_PP_EMPTY) ) \
|
||||
call( E BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, MOCK_CALL_INVALID_TYPE, BOOST_PP_EMPTY) ) \
|
||||
{ \
|
||||
throw std::logic_error( "should never be called" ); \
|
||||
}
|
||||
BOOST_PP_REPEAT_FROM_TO(0, MOCK_MAX_ARGS, MOCK_CALL, BOOST_PP_EMPTY)
|
||||
#undef MOCK_CALL
|
||||
#undef MOCK_CALL_NO_TYPE
|
||||
#undef MOCK_CALL_INVALID_TYPE
|
||||
#undef MOCK_CALL_PARAM
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
# pragma warning( push, 0 )
|
||||
#endif
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/spirit/home/phoenix.hpp>
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning( pop )
|
||||
#endif
|
||||
|
|
@ -23,7 +24,7 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
BOOST_STATIC_ASSERT( sizeof( mock::detail::true_type ) != sizeof( mock::detail::false_type ) );
|
||||
BOOST_STATIC_ASSERT( sizeof( mock::detail::yes_type ) != sizeof( mock::detail::no_type ) );
|
||||
|
||||
template< typename T >
|
||||
void check( T )
|
||||
|
|
@ -88,6 +89,11 @@ BOOST_AUTO_TEST_CASE( boost_lambda_is_functor )
|
|||
check( boost::lambda::_1 < 42 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( boost_phoenix_is_functor )
|
||||
{
|
||||
check( boost::phoenix::arg_names::arg1 < 42 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( boost_function_is_functor )
|
||||
{
|
||||
check( boost::function< void() >() );
|
||||
|
|
|
|||
|
|
@ -221,11 +221,11 @@ BOOST_AUTO_TEST_CASE( mocking_a_destructor )
|
|||
BOOST_MPL_ASSERT(( boost::is_same< float, mock::detail::arg< void( float ), 1, 1 >::type > ));
|
||||
BOOST_MPL_ASSERT(( boost::is_same< float, mock::detail::arg< void( float, int ), 1, 2 >::type > ));
|
||||
BOOST_MPL_ASSERT(( boost::is_same< int, mock::detail::arg< void( float, int ), 2, 2 >::type > ));
|
||||
BOOST_MPL_ASSERT(( boost::is_same< mock::detail::no_type, mock::detail::arg< void( float ), 1, 2 >::type > ));
|
||||
BOOST_MPL_ASSERT(( boost::is_same< mock::detail::no_type, mock::detail::arg< void( float ), 2, 2 >::type > ));
|
||||
BOOST_MPL_ASSERT(( boost::is_same< mock::detail::no_type, mock::detail::arg< void( float, int ), 1, 1 >::type > ));
|
||||
BOOST_MPL_ASSERT(( boost::is_same< mock::detail::no_type, mock::detail::arg< void( float, int ), 1, 3 >::type > ));
|
||||
BOOST_MPL_ASSERT(( boost::is_same< mock::detail::no_type, mock::detail::arg< void( float, int ), 2, 3 >::type > ));
|
||||
BOOST_MPL_ASSERT(( boost::is_same< mock::detail::invalid_type, mock::detail::arg< void( float ), 1, 2 >::type > ));
|
||||
BOOST_MPL_ASSERT(( boost::is_same< mock::detail::invalid_type, mock::detail::arg< void( float ), 2, 2 >::type > ));
|
||||
BOOST_MPL_ASSERT(( boost::is_same< mock::detail::invalid_type, mock::detail::arg< void( float, int ), 1, 1 >::type > ));
|
||||
BOOST_MPL_ASSERT(( boost::is_same< mock::detail::invalid_type, mock::detail::arg< void( float, int ), 1, 3 >::type > ));
|
||||
BOOST_MPL_ASSERT(( boost::is_same< mock::detail::invalid_type, mock::detail::arg< void( float, int ), 2, 3 >::type > ));
|
||||
|
||||
BOOST_AUTO_TEST_CASE( call_selects_proper_form )
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue