From c697b488023fb42165cb2c8a638d65243997a1e9 Mon Sep 17 00:00:00 2001 From: mat007 Date: Tue, 21 May 2013 09:21:52 +0000 Subject: [PATCH] Fixed regression git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@665 860be788-9bd5-4423-9f1e-828f051e677b --- build/vc100/turtle_test.vcxproj | 2 ++ build/vc100/turtle_test.vcxproj.filters | 6 +++++ test/detail/test_function.cpp | 20 +++++++++++++++++ test/test_integration.cpp | 9 ++++---- test/undefined.cpp | 18 +++++++++++++++ test/undefined.hpp | 16 ++++++++++++++ turtle/detail/action.hpp | 29 +++++++++---------------- 7 files changed, 76 insertions(+), 24 deletions(-) create mode 100644 test/undefined.cpp create mode 100644 test/undefined.hpp diff --git a/build/vc100/turtle_test.vcxproj b/build/vc100/turtle_test.vcxproj index bb5b6d6..72ab186 100644 --- a/build/vc100/turtle_test.vcxproj +++ b/build/vc100/turtle_test.vcxproj @@ -20,6 +20,7 @@ + @@ -36,6 +37,7 @@ + {74810A2A-33D8-47D6-9A50-71261F1683F5} diff --git a/build/vc100/turtle_test.vcxproj.filters b/build/vc100/turtle_test.vcxproj.filters index 5a0a82d..9d769d5 100644 --- a/build/vc100/turtle_test.vcxproj.filters +++ b/build/vc100/turtle_test.vcxproj.filters @@ -13,6 +13,9 @@ Source Files + + Source Files + @@ -57,5 +60,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/test/detail/test_function.cpp b/test/detail/test_function.cpp index c08cdf5..bd30f5a 100644 --- a/test/detail/test_function.cpp +++ b/test/detail/test_function.cpp @@ -8,6 +8,7 @@ #define BOOST_AUTO_TEST_MAIN #include "../mock_error.hpp" +#include "../undefined.hpp" #include #include #include @@ -533,6 +534,20 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_auto_ptr_valu BOOST_CHECK_NO_THROW( f() ); CHECK_CALLS( 1 ); } +} + +BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_shared_ptr_value, error_fixture ) +{ + { + mock::detail::function< boost::shared_ptr< A >() > f; + f.expect().returns( new B ); + BOOST_CHECK_NO_THROW( f() ); + CHECK_CALLS( 1 ); + } +} + +BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_by_reference, error_fixture ) +{ { mock::detail::function< A&() > f; B b; @@ -547,6 +562,11 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_auto_ptr_valu BOOST_CHECK_NO_THROW( f() ); CHECK_CALLS( 1 ); } + { + mock::detail::function< undefined&() > f; + f.expect().returns( boost::ref( get_undefined() ) ); + f.reset(); + } } namespace diff --git a/test/test_integration.cpp b/test/test_integration.cpp index db47626..de9b85c 100644 --- a/test/test_integration.cpp +++ b/test/test_integration.cpp @@ -7,6 +7,7 @@ // http://www.boost.org/LICENSE_1_0.txt) #include "mock_error.hpp" +#include "undefined.hpp" #include #include #include @@ -128,17 +129,15 @@ BOOST_AUTO_TEST_CASE( mock_object_method_const_disambiguation ) namespace { - struct my_declared_but_undefined_type; - - MOCK_CLASS( my_declared_but_undefined_mock ) + MOCK_CLASS( my_undefined_mock ) { - MOCK_METHOD_EXT( m, 1, void( my_declared_but_undefined_type& ), t ) + MOCK_METHOD_EXT( m, 1, void( undefined& ), t ) }; } BOOST_AUTO_TEST_CASE( mock_object_method_with_declared_but_not_defined_parameter_is_valid ) { - my_declared_but_undefined_mock mock; + my_undefined_mock mock; MOCK_EXPECT( mock.t ); } diff --git a/test/undefined.cpp b/test/undefined.cpp new file mode 100644 index 0000000..9855cbb --- /dev/null +++ b/test/undefined.cpp @@ -0,0 +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; +} diff --git a/test/undefined.hpp b/test/undefined.hpp new file mode 100644 index 0000000..f2418c0 --- /dev/null +++ b/test/undefined.hpp @@ -0,0 +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 diff --git a/turtle/detail/action.hpp b/turtle/detail/action.hpp index ddfde74..f3447d4 100644 --- a/turtle/detail/action.hpp +++ b/turtle/detail/action.hpp @@ -12,9 +12,7 @@ #include "../config.hpp" #include "lambda.hpp" #include -#include #include -#include #include #include #include @@ -37,26 +35,19 @@ namespace detail public: template< typename Value > - void returns( Value v, - BOOST_DEDUCED_TYPENAME boost::enable_if< - boost::is_convertible< Value, result_type > >::type* = 0 ) + void returns( Value v ) + { + r_ = boost::make_shared< Value >( v ); + f_ = lambda_type::make_val( boost::ref( *r_ ) ); + } + template< typename Value > + void returns( Value* v ) { r_ = boost::make_shared< result_type >( v ); f_ = lambda_type::make_val( boost::ref( *r_ ) ); } - template< typename Value > - void returns( Value v, - BOOST_DEDUCED_TYPENAME boost::disable_if< - boost::is_convertible< Value, result_type > >::type* = 0 ) - { - // if an error is generated by the line below it means a value - // passed to 'returns' was of the wrong type as it cannot be - // used to copy construct a Result - r_ = boost::make_shared< Value >( v ); - f_ = lambda_type::make_val( boost::ref( *r_ ) ); - } template< typename Y > - void returns( boost::reference_wrapper< Y > r ) + void returns( const boost::reference_wrapper< Y >& r ) { f_ = lambda_type::make_val( r ); } @@ -98,7 +89,7 @@ namespace detail f_ = lambda_type::make_val( r ); } template< typename Y > - void returns( boost::reference_wrapper< Y > r ) + void returns( const boost::reference_wrapper< Y >& r ) { f_ = lambda_type::make_val( r ); } @@ -211,7 +202,7 @@ namespace detail f_ = lambda_type::make_val( boost::ref( r_ ) ); } template< typename Y > - void set( boost::reference_wrapper< Y > r ) + void set( const boost::reference_wrapper< Y >& r ) { f_ = lambda_type::make_val( r ); r_.reset();