mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Added detection for a pointer in mock::assign to dereference it before performing the assignment
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@158 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
a4b061184c
commit
df46dec9e0
3 changed files with 28 additions and 15 deletions
|
|
@ -57,8 +57,7 @@ namespace detail
|
|||
template< typename T >
|
||||
detail::placeholder< detail::same< T > > same( T& t )
|
||||
{
|
||||
return constraint( detail::same< T >( boost::ref( t ) ),
|
||||
"same", &t );
|
||||
return constraint( detail::same< T >( t ), "same", &t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
|
|
@ -100,8 +99,7 @@ namespace detail
|
|||
template< typename T >
|
||||
detail::placeholder< detail::retrieve< T > > retrieve( T& t )
|
||||
{
|
||||
return constraint( detail::retrieve< T >( boost::ref( t ) ),
|
||||
"retrieve", t );
|
||||
return constraint( detail::retrieve< T >( t ), "retrieve", t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
#ifndef MOCK_FUNCTIONAL_HPP_INCLUDED
|
||||
#define MOCK_FUNCTIONAL_HPP_INCLUDED
|
||||
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
|
|
@ -68,16 +67,16 @@ namespace detail
|
|||
class same
|
||||
{
|
||||
public:
|
||||
explicit same( const boost::reference_wrapper< Expected >& expected )
|
||||
: expected_( expected )
|
||||
explicit same( const Expected& expected )
|
||||
: expected_( &expected )
|
||||
{}
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual ) const
|
||||
{
|
||||
return &actual == expected_.get_pointer();
|
||||
return &actual == expected_;
|
||||
}
|
||||
private:
|
||||
boost::reference_wrapper< Expected > expected_;
|
||||
const Expected* expected_;
|
||||
};
|
||||
|
||||
template< typename Expected >
|
||||
|
|
@ -119,12 +118,23 @@ namespace detail
|
|||
explicit assign( const Expected& expected )
|
||||
: expected_( expected )
|
||||
{}
|
||||
|
||||
template< typename Actual >
|
||||
bool operator()( Actual& actual ) const
|
||||
bool operator()( Actual& actual,
|
||||
BOOST_DEDUCED_TYPENAME boost::disable_if<
|
||||
boost::is_convertible< Expected*, Actual >, Actual >::type* = 0 ) const
|
||||
{
|
||||
actual = expected_;
|
||||
return true;
|
||||
}
|
||||
template< typename Actual >
|
||||
bool operator()( Actual* actual,
|
||||
BOOST_DEDUCED_TYPENAME boost::enable_if<
|
||||
boost::is_convertible< Expected, Actual >, Actual >::type* = 0 ) const
|
||||
{
|
||||
*actual = expected_;
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
Expected expected_;
|
||||
};
|
||||
|
|
@ -133,15 +143,15 @@ namespace detail
|
|||
class retrieve
|
||||
{
|
||||
public:
|
||||
explicit retrieve( const boost::reference_wrapper< Expected >& expected )
|
||||
: expected_( expected )
|
||||
explicit retrieve( Expected& expected )
|
||||
: expected_( &expected )
|
||||
{}
|
||||
template< typename Actual >
|
||||
bool operator()( const Actual& actual,
|
||||
BOOST_DEDUCED_TYPENAME boost::disable_if<
|
||||
boost::is_convertible< const Actual*, Expected >, Actual >::type* = 0 ) const
|
||||
{
|
||||
expected_.get() = actual;
|
||||
*expected_ = actual;
|
||||
return true;
|
||||
}
|
||||
template< typename Actual >
|
||||
|
|
@ -149,11 +159,11 @@ namespace detail
|
|||
BOOST_DEDUCED_TYPENAME boost::enable_if<
|
||||
boost::is_convertible< Actual*, Expected >, Actual >::type* = 0 ) const
|
||||
{
|
||||
expected_.get() = &actual;
|
||||
*expected_ = &actual;
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
boost::reference_wrapper< Expected > expected_;
|
||||
Expected* expected_;
|
||||
};
|
||||
|
||||
template< typename Expected >
|
||||
|
|
|
|||
|
|
@ -59,6 +59,11 @@ BOOST_AUTO_TEST_CASE( assign )
|
|||
BOOST_CHECK( mock::assign( 3 ).f_( i ) );
|
||||
BOOST_CHECK_EQUAL( 3, i );
|
||||
}
|
||||
{
|
||||
int i = 0;
|
||||
BOOST_CHECK( mock::assign( 3 ).f_( &i ) );
|
||||
BOOST_CHECK_EQUAL( 3, i );
|
||||
}
|
||||
{
|
||||
const int* i = 0;
|
||||
const int j = 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue