diff --git a/build/vc100/turtle.vcxproj b/build/vc100/turtle.vcxproj index adfe01d..c714e46 100644 --- a/build/vc100/turtle.vcxproj +++ b/build/vc100/turtle.vcxproj @@ -27,11 +27,11 @@ - + diff --git a/build/vc100/turtle.vcxproj.filters b/build/vc100/turtle.vcxproj.filters index 4bc1207..77db42a 100644 --- a/build/vc100/turtle.vcxproj.filters +++ b/build/vc100/turtle.vcxproj.filters @@ -70,9 +70,6 @@ Source Files\detail - - Source Files\detail - Source Files\detail @@ -97,5 +94,8 @@ Source Files\detail + + Source Files\detail + \ No newline at end of file diff --git a/build/vc100/turtle_test.vcxproj b/build/vc100/turtle_test.vcxproj index 943af8b..7963ae4 100644 --- a/build/vc100/turtle_test.vcxproj +++ b/build/vc100/turtle_test.vcxproj @@ -22,7 +22,7 @@ - + diff --git a/build/vc100/turtle_test.vcxproj.filters b/build/vc100/turtle_test.vcxproj.filters index 04dbbf0..c547135 100644 --- a/build/vc100/turtle_test.vcxproj.filters +++ b/build/vc100/turtle_test.vcxproj.filters @@ -51,10 +51,10 @@ Source Files\detail - + Source Files\detail - + Source Files\detail diff --git a/test/detail/test_args.cpp b/test/detail/test_args.cpp deleted file mode 100644 index e19232b..0000000 --- a/test/detail/test_args.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// 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 -#include -#include - -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::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 > )); diff --git a/test/detail/test_parameters.cpp b/test/detail/test_parameters.cpp new file mode 100644 index 0000000..005a9a0 --- /dev/null +++ b/test/detail/test_parameters.cpp @@ -0,0 +1,15 @@ +// 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 +#include +#include + +BOOST_MPL_ASSERT(( boost::is_same< float, mock::detail::parameters< void( float ), 1 >::at< 0 >::type > )); +BOOST_MPL_ASSERT(( boost::is_same< float, mock::detail::parameters< void( float, int ), 2 >::at< 0 >::type > )); +BOOST_MPL_ASSERT(( boost::is_same< int, mock::detail::parameters< void( float, int ), 2 >::at< 1 >::type > )); diff --git a/turtle/detail/args.hpp b/turtle/detail/args.hpp deleted file mode 100644 index 82e788c..0000000 --- a/turtle/detail/args.hpp +++ /dev/null @@ -1,69 +0,0 @@ -// http://turtle.sourceforge.net -// -// Copyright Mathieu Champlon 2010 -// -// 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_ARGS_HPP_INCLUDED -#define MOCK_ARGS_HPP_INCLUDED - -#include -#include -#include -#include - -namespace mock -{ -namespace detail -{ - struct invalid_type - { - private: - invalid_type(); - }; - - template< typename S, int n, bool B > - struct arg_imp - { - typedef invalid_type type; - }; - template< typename S, int n > - struct arg_imp< S, n, true > - { - typedef BOOST_DEDUCED_TYPENAME - boost::mpl::at_c< - BOOST_DEDUCED_TYPENAME - boost::function_types::parameter_types< S >, - n - 1 - >::type type; - }; - template< typename S, int n, int N > - struct arg : - arg_imp< S, n, boost::function_types::function_arity< S >::value == N > - { - BOOST_MPL_ASSERT_RELATION( n, >, 0 ); - BOOST_MPL_ASSERT_RELATION( n, <=, N ); - }; -} -} // mock - -#define MOCK_ARG(N, n, S, tpn) \ - BOOST_PP_COMMA_IF(n) tpn \ - mock::detail::arg< S, BOOST_PP_INC(n), N >::type p##n -#define MOCK_ARG_PROXY(z, n, d) \ - MOCK_ARG( \ - BOOST_PP_ARRAY_ELEM(0, d), \ - n, \ - BOOST_PP_ARRAY_ELEM(1, d), \ - BOOST_PP_ARRAY_ELEM(2, d) ) - -#define MOCK_ARGS(n, S, tpn) \ - BOOST_PP_REPEAT(n, MOCK_ARG_PROXY, (3, (n, S, tpn))) - -#define MOCK_DECL(M, n, S, c, tpn) \ - tpn boost::function_types::result_type< S >::type M( \ - MOCK_ARGS(n, S, tpn) ) c - -#endif // MOCK_ARGS_HPP_INCLUDED diff --git a/turtle/detail/parameters.hpp b/turtle/detail/parameters.hpp new file mode 100644 index 0000000..f43d0a6 --- /dev/null +++ b/turtle/detail/parameters.hpp @@ -0,0 +1,40 @@ +// http://turtle.sourceforge.net +// +// Copyright Mathieu Champlon 2010 +// +// 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_PARAMETERS_HPP_INCLUDED +#define MOCK_PARAMETERS_HPP_INCLUDED + +#include +#include +#include + +namespace mock +{ +namespace detail +{ + template< typename Signature, int Arity > + struct parameters + { + BOOST_MPL_ASSERT_RELATION( Arity, ==, + boost::function_types::function_arity< Signature >::value ); + + template< int n > + struct at + { + typedef BOOST_DEDUCED_TYPENAME + boost::mpl::at_c< + BOOST_DEDUCED_TYPENAME + boost::function_types::parameter_types< Signature >, + n + >::type type; + }; + }; +} +} // mock + +#endif // MOCK_PARAMETERS_HPP_INCLUDED diff --git a/turtle/mock.hpp b/turtle/mock.hpp index 1a51167..3d7f7e7 100644 --- a/turtle/mock.hpp +++ b/turtle/mock.hpp @@ -14,7 +14,7 @@ #include "object.hpp" #include "function.hpp" #include "detail/type_name.hpp" -#include "detail/args.hpp" +#include "detail/parameters.hpp" #include "detail/signature.hpp" #include #include @@ -66,6 +66,17 @@ namespace detail return t##_mock_; \ } +#define MOCK_PARAM(z, n, d) \ + BOOST_PP_COMMA_IF(n) d::at< n >::type p##n + +#define MOCK_PARAMS(n, S, tpn) \ + BOOST_PP_REPEAT(n, MOCK_PARAM, \ + tpn mock::detail::parameters< S BOOST_PP_COMMA() n >) + +#define MOCK_DECL(M, n, S, c, tpn) \ + tpn boost::function_types::result_type< S >::type M( \ + MOCK_PARAMS(n, S, tpn) ) c + #define MOCK_METHOD_AUX(M, n, S, t, c, tpn) \ MOCK_DECL(M, n, S, c, tpn) \ { \ @@ -119,7 +130,7 @@ namespace detail #define MOCK_CONSTRUCTOR_AUX(T, n, A, t, tpn) \ MOCK_FUNCTION_HELPER(void A, t, static) \ - T( MOCK_ARGS(n, void A, tpn) ) \ + T( MOCK_PARAMS(n, void A, tpn) ) \ { \ MOCK_HELPER(t)( BOOST_PP_ENUM_PARAMS(n, p) ); \ }