diff --git a/build/vc80/turtle.vcproj b/build/vc80/turtle.vcproj index 461616d..8f6b0de 100644 --- a/build/vc80/turtle.vcproj +++ b/build/vc80/turtle.vcproj @@ -152,6 +152,10 @@ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > + + @@ -212,10 +216,6 @@ RelativePath="..\..\src\libraries\turtle\placeholder.hpp" > - - diff --git a/src/libraries/turtle/result.hpp b/src/libraries/turtle/action.hpp similarity index 89% rename from src/libraries/turtle/result.hpp rename to src/libraries/turtle/action.hpp index 264c526..013e94f 100644 --- a/src/libraries/turtle/result.hpp +++ b/src/libraries/turtle/action.hpp @@ -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 @@ -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 diff --git a/src/libraries/turtle/is_functor.hpp b/src/libraries/turtle/is_functor.hpp index e00791f..5f12b4d 100644 --- a/src/libraries/turtle/is_functor.hpp +++ b/src/libraries/turtle/is_functor.hpp @@ -11,61 +11,39 @@ #include #include +#include #include 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; }; } diff --git a/src/libraries/turtle/matcher.hpp b/src/libraries/turtle/matcher.hpp index e990dcc..09097de 100644 --- a/src/libraries/turtle/matcher.hpp +++ b/src/libraries/turtle/matcher.hpp @@ -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: \ diff --git a/src/libraries/turtle/mock.hpp b/src/libraries/turtle/mock.hpp index 443d932..5f700a6 100644 --- a/src/libraries/turtle/mock.hpp +++ b/src/libraries/turtle/mock.hpp @@ -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 } } diff --git a/src/tests/turtle_test/is_functor_test.cpp b/src/tests/turtle_test/is_functor_test.cpp index dd511fe..be3c4ba 100644 --- a/src/tests/turtle_test/is_functor_test.cpp +++ b/src/tests/turtle_test/is_functor_test.cpp @@ -13,6 +13,7 @@ # pragma warning( push, 0 ) #endif #include +#include #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() >() ); diff --git a/src/tests/turtle_test/mock_test.cpp b/src/tests/turtle_test/mock_test.cpp index 0ddb52c..c4b8a3e 100644 --- a/src/tests/turtle_test/mock_test.cpp +++ b/src/tests/turtle_test/mock_test.cpp @@ -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 ) {