From f872785e26559148da0263fb4c1c8c8887f6f5e5 Mon Sep 17 00:00:00 2001 From: Mathieu Champlon Date: Mon, 11 Dec 2017 22:04:11 +0100 Subject: [PATCH] Added support for movable objects in mock::retrieve --- doc/changelog.qbk | 1 + include/turtle/constraints.hpp | 7 +++++++ test/test_constraints.cpp | 10 ++++++++++ 3 files changed, 18 insertions(+) diff --git a/doc/changelog.qbk b/doc/changelog.qbk index 64aba81..2a87dab 100644 --- a/doc/changelog.qbk +++ b/doc/changelog.qbk @@ -13,6 +13,7 @@ Not yet released * Fixed mocking of a function returning a reference for gcc 4.1 * Added MOCK_NO_AUTO_PTR to deactivate std::auto_ptr support * Added [@https://github.com/philsquared/Catch Catch] integration +* Added support for movable objects in mock::retrieve [endsect] diff --git a/include/turtle/constraints.hpp b/include/turtle/constraints.hpp index 77a142f..823d34f 100644 --- a/include/turtle/constraints.hpp +++ b/include/turtle/constraints.hpp @@ -14,6 +14,7 @@ #include "detail/addressof.hpp" #include #include +#include #include #include #include @@ -157,6 +158,12 @@ namespace detail *expected_ = detail::addressof( actual ); return true; } + template< typename Actual > + bool operator()( BOOST_RV_REF( Actual ) actual ) const + { + *expected_ = boost::move( actual ); + return true; + } friend std::ostream& operator<<( std::ostream& s, const retrieve& r ) { return s << "retrieve( " << mock::format( *r.expected_ ) << " )"; diff --git a/test/test_constraints.cpp b/test/test_constraints.cpp index 60e3128..86a4632 100644 --- a/test/test_constraints.cpp +++ b/test/test_constraints.cpp @@ -219,6 +219,16 @@ BOOST_AUTO_TEST_CASE( retrieve_constraint ) BOOST_CHECK_EQUAL( i, &j ); } #endif +#ifdef MOCK_SMART_PTR + { + std::unique_ptr< int > i; + std::unique_ptr< int > j( new int( 3 ) ); + BOOST_CHECK( mock::retrieve( i ).c_( j ) ); + BOOST_REQUIRE( i ); + BOOST_CHECK_EQUAL( 3, *i ); + BOOST_CHECK( !j ); + } +#endif } namespace