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:
mat007 2010-02-04 07:40:26 +00:00
parent 05654f9f5f
commit 0bcfffcc03
7 changed files with 55 additions and 71 deletions

View file

@ -152,6 +152,10 @@
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
> >
<File
RelativePath="..\..\src\libraries\turtle\action.hpp"
>
</File>
<File <File
RelativePath="..\..\src\libraries\turtle\check.hpp" RelativePath="..\..\src\libraries\turtle\check.hpp"
> >
@ -212,10 +216,6 @@
RelativePath="..\..\src\libraries\turtle\placeholder.hpp" RelativePath="..\..\src\libraries\turtle\placeholder.hpp"
> >
</File> </File>
<File
RelativePath="..\..\src\libraries\turtle\result.hpp"
>
</File>
<File <File
RelativePath="..\..\src\libraries\turtle\root.hpp" RelativePath="..\..\src\libraries\turtle\root.hpp"
> >

View file

@ -6,8 +6,8 @@
// http://www.boost.org/LICENSE_1_0.txt) // http://www.boost.org/LICENSE_1_0.txt)
// //
#ifndef MOCK_RESULT_HPP_INCLUDED #ifndef MOCK_ACTION_HPP_INCLUDED
#define MOCK_RESULT_HPP_INCLUDED #define MOCK_ACTION_HPP_INCLUDED
#include "config.hpp" #include "config.hpp"
#include <boost/bind.hpp> #include <boost/bind.hpp>
@ -19,7 +19,7 @@ namespace mock
namespace detail namespace detail
{ {
template< typename T, typename Signature > template< typename T, typename Signature >
class result class action
{ {
typedef BOOST_DEDUCED_TYPENAME typedef BOOST_DEDUCED_TYPENAME
boost::function< Signature > functor_type; boost::function< Signature > functor_type;
@ -75,7 +75,7 @@ namespace detail
}; };
template< typename T, typename Signature > template< typename T, typename Signature >
class result< T*, Signature > class action< T*, Signature >
{ {
typedef BOOST_DEDUCED_TYPENAME typedef BOOST_DEDUCED_TYPENAME
boost::function< Signature > functor_type; boost::function< Signature > functor_type;
@ -125,13 +125,13 @@ namespace detail
}; };
template< typename Signature > template< typename Signature >
class result< void, Signature > class action< void, Signature >
{ {
typedef BOOST_DEDUCED_TYPENAME typedef BOOST_DEDUCED_TYPENAME
boost::function< Signature > functor_type; boost::function< Signature > functor_type;
public: public:
result() action()
: f_( boost::bind( &nothing ) ) : f_( boost::bind( &nothing ) )
{} {}
@ -167,18 +167,18 @@ namespace detail
}; };
template< typename T, typename Signature > template< typename T, typename Signature >
class result< std::auto_ptr< T >, Signature > class action< std::auto_ptr< T >, Signature >
{ {
typedef BOOST_DEDUCED_TYPENAME typedef BOOST_DEDUCED_TYPENAME
boost::function< Signature > functor_type; boost::function< Signature > functor_type;
public: public:
result() action()
: t_() : t_()
, f_() , f_()
{} {}
result( const result& rhs ) action( const action& rhs )
: t_( const_cast< result& >( rhs ).t_.release() ) : t_( const_cast< action& >( rhs ).t_.release() )
, f_( t_.get() ? boost::bind( &return_value, boost::ref( t_ ) ) : rhs.f_ ) , 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

View file

@ -11,61 +11,39 @@
#include <boost/function_types/is_callable_builtin.hpp> #include <boost/function_types/is_callable_builtin.hpp>
#include <boost/type_traits/integral_constant.hpp> #include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/detail/yes_no_type.hpp>
#include <boost/mpl/or.hpp> #include <boost/mpl/or.hpp>
namespace mock namespace mock
{ {
namespace detail namespace detail
{ {
typedef char true_type; typedef boost::type_traits::yes_type yes_type;
struct false_type typedef boost::type_traits::no_type no_type;
{
true_type padding[2]; #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 > MOCK_IS_FUNCTION_HELPER( has_result_type, result_type )
true_type& has_result_type_tester( T*, BOOST_DEDUCED_TYPENAME T::result_type* = 0 ); MOCK_IS_FUNCTION_HELPER( has_sig, sig< void > )
template< typename T > MOCK_IS_FUNCTION_HELPER( has_result, result< void > )
false_type& has_result_type_tester( T, ... );
template< typename T > #undef MOCK_IS_FUNCTION_HELPER
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 >
{
};
template< typename T > template< typename T >
struct is_functor struct is_functor
{ {
typedef BOOST_DEDUCED_TYPENAME boost::mpl::or_< 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 boost::function_types::is_callable_builtin< T >::type,
BOOST_DEDUCED_TYPENAME has_result_type< T >::type BOOST_DEDUCED_TYPENAME boost::integral_constant< bool, has_result_type< T >::value >::type,
>::type, BOOST_DEDUCED_TYPENAME boost::integral_constant< bool, has_result< T >::value >::type,
BOOST_DEDUCED_TYPENAME has_sig< T >::type BOOST_DEDUCED_TYPENAME boost::integral_constant< bool, has_sig< T >::value >::type
>::type type; >::type type;
}; };
} }

View file

@ -11,7 +11,7 @@
#include "config.hpp" #include "config.hpp"
#include "invocation.hpp" #include "invocation.hpp"
#include "result.hpp" #include "action.hpp"
#include "sequence.hpp" #include "sequence.hpp"
#include "check.hpp" #include "check.hpp"
#include "constraint.hpp" #include "constraint.hpp"
@ -149,7 +149,7 @@ namespace detail
template< typename Result, typename Signature > template< typename Result, typename Signature >
class matcher< Result, Signature, 0 > class matcher< Result, Signature, 0 >
: public matcher_base, public result< Result, Signature > : public matcher_base, public action< Result, Signature >
{ {
public: public:
bool is_valid() const bool is_valid() const
@ -182,7 +182,7 @@ namespace detail
#define MOCK_MATCHER(z, n, d) \ #define MOCK_MATCHER(z, n, d) \
template< typename Result, typename Signature > \ template< typename Result, typename Signature > \
class matcher< Result, Signature, n > \ 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) \ BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_MATCHER_TYPEDEF, BOOST_PP_EMPTY) \
public: \ public: \

View file

@ -147,16 +147,16 @@ namespace detail
typedef T base_type; typedef T base_type;
}; };
struct no_type struct invalid_type
{ {
private: private:
no_type(); invalid_type();
}; };
template< typename S, int n, bool B > template< typename S, int n, bool B >
struct arg_imp struct arg_imp
{ {
typedef no_type type; typedef invalid_type type;
}; };
template< typename S, int n > template< typename S, int n >
struct arg_imp< S, n, true > struct arg_imp< S, n, true >
@ -195,7 +195,7 @@ namespace detail
BOOST_DEDUCED_TYPENAME E::parameter_types, \ BOOST_DEDUCED_TYPENAME E::parameter_types, \
n \ n \
>::type t##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) \ #define MOCK_CALL(z, n, d) \
template< typename E > \ template< typename E > \
BOOST_DEDUCED_TYPENAME boost::enable_if< \ BOOST_DEDUCED_TYPENAME boost::enable_if< \
@ -211,13 +211,13 @@ namespace detail
BOOST_DEDUCED_TYPENAME has_arity< E, n >::type, \ BOOST_DEDUCED_TYPENAME has_arity< E, n >::type, \
BOOST_DEDUCED_TYPENAME E::result_type \ BOOST_DEDUCED_TYPENAME E::result_type \
>::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" ); \ throw std::logic_error( "should never be called" ); \
} }
BOOST_PP_REPEAT_FROM_TO(0, MOCK_MAX_ARGS, MOCK_CALL, BOOST_PP_EMPTY) BOOST_PP_REPEAT_FROM_TO(0, MOCK_MAX_ARGS, MOCK_CALL, BOOST_PP_EMPTY)
#undef MOCK_CALL #undef MOCK_CALL
#undef MOCK_CALL_NO_TYPE #undef MOCK_CALL_INVALID_TYPE
#undef MOCK_CALL_PARAM #undef MOCK_CALL_PARAM
} }
} }

View file

@ -13,6 +13,7 @@
# pragma warning( push, 0 ) # pragma warning( push, 0 )
#endif #endif
#include <boost/lambda/lambda.hpp> #include <boost/lambda/lambda.hpp>
#include <boost/spirit/home/phoenix.hpp>
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning( pop ) # pragma warning( pop )
#endif #endif
@ -23,7 +24,7 @@
namespace 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 > template< typename T >
void check( T ) void check( T )
@ -88,6 +89,11 @@ BOOST_AUTO_TEST_CASE( boost_lambda_is_functor )
check( boost::lambda::_1 < 42 ); 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 ) BOOST_AUTO_TEST_CASE( boost_function_is_functor )
{ {
check( boost::function< void() >() ); check( boost::function< void() >() );

View file

@ -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 ), 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< 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< 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::invalid_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::invalid_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::invalid_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::invalid_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, int ), 2, 3 >::type > ));
BOOST_AUTO_TEST_CASE( call_selects_proper_form ) BOOST_AUTO_TEST_CASE( call_selects_proper_form )
{ {