mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Use std::reference_wrapper instead of boost
This commit is contained in:
parent
353849e9ad
commit
35e43d58a6
16 changed files with 116 additions and 90 deletions
|
|
@ -86,8 +86,8 @@ struct near_constraint
|
||||||
template< typename Actual >
|
template< typename Actual >
|
||||||
bool operator()( Actual actual ) const
|
bool operator()( Actual actual ) const
|
||||||
{
|
{
|
||||||
return std::abs( actual - boost::unwrap_ref( expected_ ) )
|
return std::abs( actual - unwrap_ref( expected_ ) )
|
||||||
< boost::unwrap_ref( threshold_ );
|
< unwrap_ref( threshold_ );
|
||||||
}
|
}
|
||||||
|
|
||||||
friend std::ostream& operator<<( std::ostream& s, const near_constraint& c )
|
friend std::ostream& operator<<( std::ostream& s, const near_constraint& c )
|
||||||
|
|
@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two_plus_or_minus_one )
|
||||||
mock_view v;
|
mock_view v;
|
||||||
calculator c( v );
|
calculator c( v );
|
||||||
int expected, threshold;
|
int expected, threshold;
|
||||||
MOCK_EXPECT( v.display ).with( near( boost::cref( expected ), boost::cref( threshold ) ) );
|
MOCK_EXPECT( v.display ).with( near( std::cref( expected ), std::cref( threshold ) ) );
|
||||||
expected = 42;
|
expected = 42;
|
||||||
threshold = 1;
|
threshold = 1;
|
||||||
c.add( 41, 1 );
|
c.add( 41, 1 );
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE( method_is_called_two_times_with_the_same_value )
|
||||||
my_class c( mock );
|
my_class c( mock );
|
||||||
int value;
|
int value;
|
||||||
MOCK_EXPECT( mock.method ).once().with( mock::retrieve( value ) ); // on first call retrieve the value, this expectation takes precedence because it can never fail
|
MOCK_EXPECT( mock.method ).once().with( mock::retrieve( value ) ); // on first call retrieve the value, this expectation takes precedence because it can never fail
|
||||||
MOCK_EXPECT( mock.method ).once().with( boost::cref( value ) ); // on second call compare the previously retrieved value with the newly received one
|
MOCK_EXPECT( mock.method ).once().with( std::cref( value ) ); // on second call compare the previously retrieved value with the newly received one
|
||||||
c.process();
|
c.process();
|
||||||
}
|
}
|
||||||
//]
|
//]
|
||||||
|
|
|
||||||
|
|
@ -740,7 +740,7 @@ BOOST_AUTO_TEST_CASE( demonstrates_configuring_actions_with_references )
|
||||||
{
|
{
|
||||||
mock_class c;
|
mock_class c;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
MOCK_EXPECT( c.method ).returns( boost::ref( i ) ); // wrap i to store a reference
|
MOCK_EXPECT( c.method ).returns( std::ref( i ) ); // wrap i to store a reference
|
||||||
c.method() = 42; // really change i and not just the stored copy
|
c.method() = 42; // really change i and not just the stored copy
|
||||||
BOOST_CHECK_EQUAL( 42, i ); // indeed
|
BOOST_CHECK_EQUAL( 42, i ); // indeed
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
#include <boost/ref.hpp>
|
#include "detail/unwrap_reference.hpp"
|
||||||
#include <boost/preprocessor/stringize.hpp>
|
#include <boost/preprocessor/stringize.hpp>
|
||||||
#include <boost/preprocessor/control/if.hpp>
|
#include <boost/preprocessor/control/if.hpp>
|
||||||
#include <boost/preprocessor/variadic/to_array.hpp>
|
#include <boost/preprocessor/variadic/to_array.hpp>
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||||
#include <boost/preprocessor/repetition/enum.hpp>
|
#include <boost/preprocessor/repetition/enum.hpp>
|
||||||
#include <boost/preprocessor/array.hpp>
|
#include <boost/preprocessor/array.hpp>
|
||||||
|
#include <functional>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace mock
|
namespace mock
|
||||||
|
|
@ -148,7 +149,7 @@ namespace detail
|
||||||
expected##n( std::forward< T##n >(e##n) )
|
expected##n( std::forward< T##n >(e##n) )
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_UNWRAP_REF(z, n, d) \
|
#define MOCK_CONSTRAINT_UNWRAP_REF(z, n, d) \
|
||||||
boost::unwrap_ref( expected##n )
|
mock::detail::unwrap_ref( expected##n )
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_FORMAT(z, n, d) \
|
#define MOCK_CONSTRAINT_FORMAT(z, n, d) \
|
||||||
BOOST_PP_IF(n, << ", " <<,) mock::format( c.expected##n )
|
BOOST_PP_IF(n, << ", " <<,) mock::format( c.expected##n )
|
||||||
|
|
@ -160,7 +161,7 @@ namespace detail
|
||||||
std::decay_t< const T##n >
|
std::decay_t< const T##n >
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_CREF_PARAM(z, n, Args) \
|
#define MOCK_CONSTRAINT_CREF_PARAM(z, n, Args) \
|
||||||
const typename boost::unwrap_reference< Expected_##n >::type& \
|
const mock::detail::unwrap_reference_t< Expected_##n >& \
|
||||||
BOOST_PP_ARRAY_ELEM(n, Args)
|
BOOST_PP_ARRAY_ELEM(n, Args)
|
||||||
|
|
||||||
#define MOCK_CONSTRAINT_ARG(z, n, Args) \
|
#define MOCK_CONSTRAINT_ARG(z, n, Args) \
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "constraint.hpp"
|
#include "constraint.hpp"
|
||||||
#include "detail/move_helper.hpp"
|
#include "detail/move_helper.hpp"
|
||||||
#include <boost/ref.hpp>
|
#include "detail/unwrap_reference.hpp"
|
||||||
#include <boost/version.hpp>
|
#include <boost/version.hpp>
|
||||||
#include <boost/type_traits/make_void.hpp>
|
#include <boost/type_traits/make_void.hpp>
|
||||||
#if BOOST_VERSION >= 107000
|
#if BOOST_VERSION >= 107000
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
#else
|
#else
|
||||||
#include <boost/test/floating_point_comparison.hpp>
|
#include <boost/test/floating_point_comparison.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
|
@ -131,24 +132,22 @@ namespace detail
|
||||||
std::enable_if_t<
|
std::enable_if_t<
|
||||||
has_equal_to<
|
has_equal_to<
|
||||||
Actual,
|
Actual,
|
||||||
typename
|
unwrap_reference_t< Expected >
|
||||||
boost::unwrap_reference< Expected >::type
|
|
||||||
>::value
|
>::value
|
||||||
>* = 0 ) const
|
>* = 0 ) const
|
||||||
{
|
{
|
||||||
return actual == boost::unwrap_ref( expected_ );
|
return actual == unwrap_ref( expected_ );
|
||||||
}
|
}
|
||||||
template< typename Actual >
|
template< typename Actual >
|
||||||
bool operator()( const Actual& actual,
|
bool operator()( const Actual& actual,
|
||||||
std::enable_if_t<
|
std::enable_if_t<
|
||||||
!has_equal_to<
|
!has_equal_to<
|
||||||
Actual,
|
Actual,
|
||||||
typename
|
unwrap_reference_t< Expected >
|
||||||
boost::unwrap_reference< Expected >::type
|
|
||||||
>::value
|
>::value
|
||||||
>* = 0 ) const
|
>* = 0 ) const
|
||||||
{
|
{
|
||||||
return actual && *actual == boost::unwrap_ref( expected_ );
|
return actual && *actual == unwrap_ref( expected_ );
|
||||||
}
|
}
|
||||||
friend std::ostream& operator<<( std::ostream& s, const equal& e )
|
friend std::ostream& operator<<( std::ostream& s, const equal& e )
|
||||||
{
|
{
|
||||||
|
|
@ -161,7 +160,7 @@ namespace detail
|
||||||
struct same
|
struct same
|
||||||
{
|
{
|
||||||
explicit same( const Expected& expected )
|
explicit same( const Expected& expected )
|
||||||
: expected_( std::addressof( boost::unwrap_ref( expected ) ) )
|
: expected_( std::addressof( unwrap_ref( expected ) ) )
|
||||||
{}
|
{}
|
||||||
template< typename Actual >
|
template< typename Actual >
|
||||||
bool operator()( const Actual& actual ) const
|
bool operator()( const Actual& actual ) const
|
||||||
|
|
@ -172,23 +171,21 @@ namespace detail
|
||||||
{
|
{
|
||||||
return os << "same( " << mock::format( *s.expected_ ) << " )";
|
return os << "same( " << mock::format( *s.expected_ ) << " )";
|
||||||
}
|
}
|
||||||
const typename
|
const unwrap_reference_t< Expected >* expected_;
|
||||||
boost::unwrap_reference< Expected >::type* expected_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename Expected >
|
template< typename Expected >
|
||||||
struct retrieve
|
struct retrieve
|
||||||
{
|
{
|
||||||
explicit retrieve( Expected& expected )
|
explicit retrieve( Expected& expected )
|
||||||
: expected_( std::addressof( boost::unwrap_ref( expected ) ) )
|
: expected_( std::addressof( unwrap_ref( expected ) ) )
|
||||||
{}
|
{}
|
||||||
template< typename Actual >
|
template< typename Actual >
|
||||||
bool operator()( const Actual& actual,
|
bool operator()( const Actual& actual,
|
||||||
std::enable_if_t<
|
std::enable_if_t<
|
||||||
!std::is_convertible<
|
!std::is_convertible<
|
||||||
const Actual*,
|
const Actual*,
|
||||||
typename
|
unwrap_reference_t< Expected >
|
||||||
boost::unwrap_reference< Expected >::type
|
|
||||||
>::value
|
>::value
|
||||||
>* = 0 ) const
|
>* = 0 ) const
|
||||||
{
|
{
|
||||||
|
|
@ -200,8 +197,7 @@ namespace detail
|
||||||
std::enable_if_t<
|
std::enable_if_t<
|
||||||
!std::is_convertible<
|
!std::is_convertible<
|
||||||
const Actual*,
|
const Actual*,
|
||||||
typename
|
unwrap_reference_t< Expected >
|
||||||
boost::unwrap_reference< Expected >::type
|
|
||||||
>::value
|
>::value
|
||||||
>* = 0 ) const
|
>* = 0 ) const
|
||||||
{
|
{
|
||||||
|
|
@ -212,8 +208,7 @@ namespace detail
|
||||||
bool operator()( Actual& actual,
|
bool operator()( Actual& actual,
|
||||||
std::enable_if_t<
|
std::enable_if_t<
|
||||||
std::is_convertible< Actual*,
|
std::is_convertible< Actual*,
|
||||||
typename
|
unwrap_reference_t< Expected >
|
||||||
boost::unwrap_reference< Expected >::type
|
|
||||||
>::value
|
>::value
|
||||||
>* = 0 ) const
|
>* = 0 ) const
|
||||||
{
|
{
|
||||||
|
|
@ -224,8 +219,7 @@ namespace detail
|
||||||
{
|
{
|
||||||
return s << "retrieve( " << mock::format( *r.expected_ ) << " )";
|
return s << "retrieve( " << mock::format( *r.expected_ ) << " )";
|
||||||
}
|
}
|
||||||
typename
|
unwrap_reference_t< Expected >* expected_;
|
||||||
boost::unwrap_reference< Expected >::type* expected_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename Expected >
|
template< typename Expected >
|
||||||
|
|
@ -237,22 +231,21 @@ namespace detail
|
||||||
template< typename Actual >
|
template< typename Actual >
|
||||||
bool operator()( Actual& actual ) const
|
bool operator()( Actual& actual ) const
|
||||||
{
|
{
|
||||||
actual = boost::unwrap_ref( expected_ );
|
actual = unwrap_ref( expected_ );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
template< typename Actual >
|
template< typename Actual >
|
||||||
bool operator()( Actual* actual,
|
bool operator()( Actual* actual,
|
||||||
std::enable_if_t<
|
std::enable_if_t<
|
||||||
std::is_convertible<
|
std::is_convertible<
|
||||||
typename
|
unwrap_reference_t< Expected >,
|
||||||
boost::unwrap_reference< Expected >::type,
|
|
||||||
Actual
|
Actual
|
||||||
>::value
|
>::value
|
||||||
>* = 0 ) const
|
>* = 0 ) const
|
||||||
{
|
{
|
||||||
if( ! actual )
|
if( ! actual )
|
||||||
return false;
|
return false;
|
||||||
*actual = boost::unwrap_ref( expected_ );
|
*actual = unwrap_ref( expected_ );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
friend std::ostream& operator<<( std::ostream& s, const assign& a )
|
friend std::ostream& operator<<( std::ostream& s, const assign& a )
|
||||||
|
|
@ -270,7 +263,7 @@ namespace detail
|
||||||
{}
|
{}
|
||||||
bool operator()( const std::string& actual ) const
|
bool operator()( const std::string& actual ) const
|
||||||
{
|
{
|
||||||
return actual.find( boost::unwrap_ref( expected_ ) )
|
return actual.find( unwrap_ref( expected_ ) )
|
||||||
!= std::string::npos;
|
!= std::string::npos;
|
||||||
}
|
}
|
||||||
friend std::ostream& operator<<( std::ostream& s, const contain& n )
|
friend std::ostream& operator<<( std::ostream& s, const contain& n )
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/ref.hpp>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
@ -60,9 +59,9 @@ namespace detail
|
||||||
a_ = a;
|
a_ = a;
|
||||||
}
|
}
|
||||||
template< typename Y >
|
template< typename Y >
|
||||||
void set( const boost::reference_wrapper< Y >& r )
|
void set( const std::reference_wrapper< Y >& r )
|
||||||
{
|
{
|
||||||
a_ = boost::bind( &do_ref< Y >, r.get_pointer() );
|
a_ = boost::bind( &do_ref< Y >, &r.get() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -88,10 +87,10 @@ namespace detail
|
||||||
template< typename Value >
|
template< typename Value >
|
||||||
void returns( const Value& v )
|
void returns( const Value& v )
|
||||||
{
|
{
|
||||||
this->set( boost::ref( store( v ) ) );
|
this->set( std::ref( store( v ) ) );
|
||||||
}
|
}
|
||||||
template< typename Y >
|
template< typename Y >
|
||||||
void returns( const boost::reference_wrapper< Y >& r )
|
void returns( const std::reference_wrapper< Y >& r )
|
||||||
{
|
{
|
||||||
this->set( r );
|
this->set( r );
|
||||||
}
|
}
|
||||||
|
|
@ -102,7 +101,7 @@ namespace detail
|
||||||
this->set(
|
this->set(
|
||||||
boost::bind(
|
boost::bind(
|
||||||
&move< std::remove_reference_t< Value > >,
|
&move< std::remove_reference_t< Value > >,
|
||||||
boost::ref( store( std::move( v ) ) ) ) );
|
std::ref( store( std::move( v ) ) ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -183,23 +182,23 @@ namespace detail
|
||||||
: v_( rhs.v_.release() )
|
: v_( rhs.v_.release() )
|
||||||
{
|
{
|
||||||
if( v_.get() )
|
if( v_.get() )
|
||||||
returns( boost::ref( v_ ) );
|
returns( std::ref( v_ ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename Y >
|
template< typename Y >
|
||||||
void returns( Y* r )
|
void returns( Y* r )
|
||||||
{
|
{
|
||||||
v_.reset( r );
|
v_.reset( r );
|
||||||
this->set( boost::ref( v_ ) );
|
this->set( std::ref( v_ ) );
|
||||||
}
|
}
|
||||||
template< typename Y >
|
template< typename Y >
|
||||||
void returns( std::auto_ptr< Y > r )
|
void returns( std::auto_ptr< Y > r )
|
||||||
{
|
{
|
||||||
v_ = r;
|
v_ = r;
|
||||||
this->set( boost::ref( v_ ) );
|
this->set( std::ref( v_ ) );
|
||||||
}
|
}
|
||||||
template< typename Y >
|
template< typename Y >
|
||||||
void returns( const boost::reference_wrapper< Y >& r )
|
void returns( const std::reference_wrapper< Y >& r )
|
||||||
{
|
{
|
||||||
this->set( r );
|
this->set( r );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ namespace detail
|
||||||
e_->returns( r );
|
e_->returns( r );
|
||||||
}
|
}
|
||||||
template< typename Y >
|
template< typename Y >
|
||||||
void returns( const boost::reference_wrapper< Y >& r )
|
void returns( const std::reference_wrapper< Y >& r )
|
||||||
{
|
{
|
||||||
e_->returns( r );
|
e_->returns( r );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
45
include/turtle/detail/unwrap_reference.hpp
Normal file
45
include/turtle/detail/unwrap_reference.hpp
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
// http://turtle.sourceforge.net
|
||||||
|
//
|
||||||
|
// Copyright Alexander Grund 2020
|
||||||
|
//
|
||||||
|
// 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_UNWRAP_REFERENCE_HPP_INCLUDED
|
||||||
|
#define MOCK_UNWRAP_REFERENCE_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace mock
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template<class T>
|
||||||
|
struct unwrap_reference
|
||||||
|
{
|
||||||
|
using type = T;
|
||||||
|
};
|
||||||
|
template<class T>
|
||||||
|
struct unwrap_reference<std::reference_wrapper<T>>
|
||||||
|
{
|
||||||
|
using type = T;
|
||||||
|
};
|
||||||
|
template<class T>
|
||||||
|
struct unwrap_reference<const std::reference_wrapper<T>>
|
||||||
|
{
|
||||||
|
using type = T;
|
||||||
|
};
|
||||||
|
template<class T>
|
||||||
|
using unwrap_reference_t = typename unwrap_reference<T>::type;
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
BOOST_FORCEINLINE unwrap_reference_t<T>& unwrap_ref( T& t ) noexcept
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // MOCK_UNWRAP_REFERENCE_HPP_INCLUDED
|
||||||
|
|
@ -123,6 +123,11 @@ namespace detail
|
||||||
return s << mock::format( t.get() );
|
return s << mock::format( t.get() );
|
||||||
}
|
}
|
||||||
template< typename T >
|
template< typename T >
|
||||||
|
stream& operator<<( stream& s, const std::reference_wrapper< T >& t )
|
||||||
|
{
|
||||||
|
return s << mock::format( t.get() );
|
||||||
|
}
|
||||||
|
template< typename T >
|
||||||
stream& operator<<( stream& s, const boost::shared_ptr< T >& t )
|
stream& operator<<( stream& s, const boost::shared_ptr< T >& t )
|
||||||
{
|
{
|
||||||
return s << mock::format( t.get() );
|
return s << mock::format( t.get() );
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@
|
||||||
#include "constraints.hpp"
|
#include "constraints.hpp"
|
||||||
#include "detail/is_functor.hpp"
|
#include "detail/is_functor.hpp"
|
||||||
#include "detail/move_helper.hpp"
|
#include "detail/move_helper.hpp"
|
||||||
#include <boost/ref.hpp>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <functional>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace mock
|
namespace mock
|
||||||
|
|
@ -30,7 +30,7 @@ namespace mock
|
||||||
bool operator()( std::add_lvalue_reference_t< const Actual > actual )
|
bool operator()( std::add_lvalue_reference_t< const Actual > actual )
|
||||||
{
|
{
|
||||||
return mock::equal(
|
return mock::equal(
|
||||||
boost::unwrap_ref( expected_ ) ).c_( actual );
|
mock::detail::unwrap_ref( expected_ ) ).c_( actual );
|
||||||
}
|
}
|
||||||
friend std::ostream& operator<<(
|
friend std::ostream& operator<<(
|
||||||
std::ostream& s, const matcher& m )
|
std::ostream& s, const matcher& m )
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ BOOST_FIXTURE_TEST_CASE( a_function_can_be_passed_as_functor, mock_error_fixture
|
||||||
BOOST_FIXTURE_TEST_CASE( a_function_can_be_passed_as_functor_using_boost_bind_and_boost_ref, mock_error_fixture )
|
BOOST_FIXTURE_TEST_CASE( a_function_can_be_passed_as_functor_using_boost_bind_and_boost_ref, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
std::function< void() > functor = boost::bind( boost::ref( f ) );
|
std::function< void() > functor = boost::bind( std::ref( f ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// invocations
|
// invocations
|
||||||
|
|
@ -410,7 +410,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_value, mock_e
|
||||||
{
|
{
|
||||||
mock::detail::function< int() > f;
|
mock::detail::function< int() > f;
|
||||||
int i = 42;
|
int i = 42;
|
||||||
f.expect().returns( boost::ref( i ) );
|
f.expect().returns( std::ref( i ) );
|
||||||
i = 43;
|
i = 43;
|
||||||
BOOST_CHECK_EQUAL( 43, f() );
|
BOOST_CHECK_EQUAL( 43, f() );
|
||||||
CHECK_CALLS( 1 );
|
CHECK_CALLS( 1 );
|
||||||
|
|
@ -439,7 +439,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_value, mock_e
|
||||||
{
|
{
|
||||||
mock::detail::function< int&() > f;
|
mock::detail::function< int&() > f;
|
||||||
int i = 42;
|
int i = 42;
|
||||||
f.expect().returns( boost::ref( i ) );
|
f.expect().returns( std::ref( i ) );
|
||||||
i = 43;
|
i = 43;
|
||||||
BOOST_CHECK_EQUAL( 43, f() );
|
BOOST_CHECK_EQUAL( 43, f() );
|
||||||
BOOST_CHECK_EQUAL( 12, f() = 12 );
|
BOOST_CHECK_EQUAL( 12, f() = 12 );
|
||||||
|
|
@ -514,7 +514,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_auto_ptr_valu
|
||||||
{
|
{
|
||||||
mock::detail::function< std::auto_ptr< int >() > f;
|
mock::detail::function< std::auto_ptr< int >() > f;
|
||||||
std::auto_ptr< int > ptr( new int( 3 ) );
|
std::auto_ptr< int > ptr( new int( 3 ) );
|
||||||
f.expect().returns( boost::ref( ptr ) );
|
f.expect().returns( std::ref( ptr ) );
|
||||||
BOOST_CHECK_EQUAL( 3, *ptr );
|
BOOST_CHECK_EQUAL( 3, *ptr );
|
||||||
BOOST_CHECK_EQUAL( 3, *f() );
|
BOOST_CHECK_EQUAL( 3, *f() );
|
||||||
BOOST_CHECK( ! ptr.get() );
|
BOOST_CHECK( ! ptr.get() );
|
||||||
|
|
@ -638,7 +638,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_by_reference, mock_er
|
||||||
{
|
{
|
||||||
mock::detail::function< base&() > f;
|
mock::detail::function< base&() > f;
|
||||||
derived b;
|
derived b;
|
||||||
f.expect().returns( boost::ref( b ) );
|
f.expect().returns( std::ref( b ) );
|
||||||
BOOST_CHECK_NO_THROW( f() );
|
BOOST_CHECK_NO_THROW( f() );
|
||||||
CHECK_CALLS( 1 );
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
@ -651,7 +651,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_by_reference, mock_er
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
mock::detail::function< undefined&() > f;
|
mock::detail::function< undefined&() > f;
|
||||||
f.expect().returns( boost::ref( get_undefined() ) );
|
f.expect().returns( std::ref( get_undefined() ) );
|
||||||
f.reset();
|
f.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -917,7 +917,7 @@ BOOST_FIXTURE_TEST_CASE( function_is_thread_safe, mock_error_fixture )
|
||||||
mock::detail::function< int() > f;
|
mock::detail::function< int() > f;
|
||||||
boost::thread_group group;
|
boost::thread_group group;
|
||||||
for( int i = 0; i < 100; ++i )
|
for( int i = 0; i < 100; ++i )
|
||||||
group.create_thread( boost::bind( &iterate, boost::ref( f ) ) );
|
group.create_thread( boost::bind( &iterate, std::ref( f ) ) );
|
||||||
group.join_all();
|
group.join_all();
|
||||||
CHECK_CALLS( 100 );
|
CHECK_CALLS( 100 );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE( equal_constraint )
|
||||||
BOOST_CHECK( ! mock::equal( std::string( "string" ) ).c_( "not string" ) );
|
BOOST_CHECK( ! mock::equal( std::string( "string" ) ).c_( "not string" ) );
|
||||||
{
|
{
|
||||||
std::string s;
|
std::string s;
|
||||||
BOOST_AUTO( c, mock::equal( boost::cref( s ) ) );
|
BOOST_AUTO( c, mock::equal( std::cref( s ) ) );
|
||||||
s = "string";
|
s = "string";
|
||||||
BOOST_CHECK( c.c_( "string" ) );
|
BOOST_CHECK( c.c_( "string" ) );
|
||||||
}
|
}
|
||||||
|
|
@ -94,11 +94,7 @@ BOOST_AUTO_TEST_CASE( same_constraint )
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
BOOST_CHECK_EQUAL( i, j );
|
BOOST_CHECK_EQUAL( i, j );
|
||||||
mock::constraint<
|
auto c = mock::same( i );
|
||||||
mock::detail::same<
|
|
||||||
const boost::reference_wrapper< const int >
|
|
||||||
>
|
|
||||||
> c = mock::same( boost::cref( i ) );
|
|
||||||
BOOST_CHECK( ! c.c_( j ) );
|
BOOST_CHECK( ! c.c_( j ) );
|
||||||
BOOST_CHECK( c.c_( i ) );
|
BOOST_CHECK( c.c_( i ) );
|
||||||
}
|
}
|
||||||
|
|
@ -137,9 +133,9 @@ BOOST_AUTO_TEST_CASE( assign_constraint )
|
||||||
int j = 1;
|
int j = 1;
|
||||||
mock::constraint<
|
mock::constraint<
|
||||||
mock::detail::assign<
|
mock::detail::assign<
|
||||||
boost::reference_wrapper< const int >
|
std::reference_wrapper< const int >
|
||||||
>
|
>
|
||||||
> c = mock::assign( boost::cref( j ) );
|
> c = mock::assign( std::cref( j ) );
|
||||||
BOOST_CHECK( c.c_( i ) );
|
BOOST_CHECK( c.c_( i ) );
|
||||||
BOOST_CHECK_EQUAL( 1, i );
|
BOOST_CHECK_EQUAL( 1, i );
|
||||||
j = 3;
|
j = 3;
|
||||||
|
|
@ -149,11 +145,7 @@ BOOST_AUTO_TEST_CASE( assign_constraint )
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 1;
|
int j = 1;
|
||||||
mock::constraint<
|
auto c = mock::assign( std::cref( j ) );
|
||||||
mock::detail::assign<
|
|
||||||
boost::reference_wrapper< const int >
|
|
||||||
>
|
|
||||||
> c = mock::assign( boost::cref( j ) );
|
|
||||||
BOOST_CHECK( c.c_( &i ) );
|
BOOST_CHECK( c.c_( &i ) );
|
||||||
BOOST_CHECK_EQUAL( 1, i );
|
BOOST_CHECK_EQUAL( 1, i );
|
||||||
j = 3;
|
j = 3;
|
||||||
|
|
@ -164,11 +156,7 @@ BOOST_AUTO_TEST_CASE( assign_constraint )
|
||||||
const int* i = 0;
|
const int* i = 0;
|
||||||
int k = 1;
|
int k = 1;
|
||||||
int* j = &k;
|
int* j = &k;
|
||||||
mock::constraint<
|
auto c = mock::assign( std::cref( j ) );
|
||||||
mock::detail::assign<
|
|
||||||
boost::reference_wrapper< int* const >
|
|
||||||
>
|
|
||||||
> c = mock::assign( boost::cref( j ) );
|
|
||||||
BOOST_CHECK( c.c_( i ) );
|
BOOST_CHECK( c.c_( i ) );
|
||||||
BOOST_CHECK_EQUAL( j, i );
|
BOOST_CHECK_EQUAL( j, i );
|
||||||
j = 0;
|
j = 0;
|
||||||
|
|
@ -230,13 +218,13 @@ BOOST_AUTO_TEST_CASE( retrieve_constraint )
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
const int j = 1;
|
const int j = 1;
|
||||||
BOOST_CHECK( mock::retrieve( boost::ref( i ) ).c_( j ) );
|
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
|
||||||
BOOST_CHECK_EQUAL( i, j );
|
BOOST_CHECK_EQUAL( i, j );
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const int* i = 0;
|
const int* i = 0;
|
||||||
const int j = 1;
|
const int j = 1;
|
||||||
BOOST_CHECK( mock::retrieve( boost::ref( i ) ).c_( j ) );
|
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
|
||||||
BOOST_CHECK_EQUAL( i, &j );
|
BOOST_CHECK_EQUAL( i, &j );
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|
@ -332,11 +320,7 @@ BOOST_AUTO_TEST_CASE( contain_constraint_with_const_char_ptr )
|
||||||
BOOST_CHECK( ! mock::contain( "not found" ).c_( std::string( "this is a string" ) ) );
|
BOOST_CHECK( ! mock::contain( "not found" ).c_( std::string( "this is a string" ) ) );
|
||||||
{
|
{
|
||||||
const char* s = 0;
|
const char* s = 0;
|
||||||
mock::constraint<
|
auto c = mock::contain( std::cref( s ) );
|
||||||
mock::detail::contain<
|
|
||||||
boost::reference_wrapper< const char* const >
|
|
||||||
>
|
|
||||||
> c = mock::contain( boost::cref( s ) );
|
|
||||||
s = "string";
|
s = "string";
|
||||||
BOOST_CHECK( c.c_( "this is a string" ) );
|
BOOST_CHECK( c.c_( "this is a string" ) );
|
||||||
BOOST_CHECK( c.c_( std::string( "this is a string" ) ) );
|
BOOST_CHECK( c.c_( std::string( "this is a string" ) ) );
|
||||||
|
|
@ -356,9 +340,9 @@ BOOST_AUTO_TEST_CASE( contain_constraint_with_strings )
|
||||||
std::string s;
|
std::string s;
|
||||||
mock::constraint<
|
mock::constraint<
|
||||||
mock::detail::contain<
|
mock::detail::contain<
|
||||||
boost::reference_wrapper< const std::string >
|
std::reference_wrapper< const std::string >
|
||||||
>
|
>
|
||||||
> c = mock::contain( boost::cref( s ) );
|
> c = mock::contain( std::cref( s ) );
|
||||||
s = "string";
|
s = "string";
|
||||||
BOOST_CHECK( c.c_( "this is a string" ) );
|
BOOST_CHECK( c.c_( "this is a string" ) );
|
||||||
BOOST_CHECK( c.c_( std::string( "this is a string" ) ) );
|
BOOST_CHECK( c.c_( std::string( "this is a string" ) ) );
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
#include <boost/ref.hpp>
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
|
@ -294,7 +293,7 @@ namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( basic_mock_object_collaboration_usage, fixture )
|
BOOST_FIXTURE_TEST_CASE( basic_mock_object_collaboration_usage, fixture )
|
||||||
{
|
{
|
||||||
MOCK_EXPECT( manager.get_observer ).returns( boost::ref( observer ) );
|
MOCK_EXPECT( manager.get_observer ).returns( std::ref( observer ) );
|
||||||
my_subject subject( manager );
|
my_subject subject( manager );
|
||||||
MOCK_EXPECT( observer.notify ).once().with( 1 );
|
MOCK_EXPECT( observer.notify ).once().with( 1 );
|
||||||
subject.increment();
|
subject.increment();
|
||||||
|
|
@ -395,7 +394,7 @@ BOOST_FIXTURE_TEST_CASE( boost_optional_on_base_class_reference_as_return_type_i
|
||||||
{
|
{
|
||||||
boost_optional b;
|
boost_optional b;
|
||||||
my_mock_observer o;
|
my_mock_observer o;
|
||||||
MOCK_EXPECT( b.tag ).once().returns( boost::ref( o ) );
|
MOCK_EXPECT( b.tag ).once().returns( std::ref( o ) );
|
||||||
b.method();
|
b.method();
|
||||||
CHECK_CALLS( 1 );
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
@ -460,7 +459,7 @@ BOOST_FIXTURE_TEST_CASE( boost_reference_wrapper_is_supported_in_value_constrain
|
||||||
{
|
{
|
||||||
MOCK_FUNCTOR( f, void( const std::string& ) );
|
MOCK_FUNCTOR( f, void( const std::string& ) );
|
||||||
std::string s;
|
std::string s;
|
||||||
MOCK_EXPECT( f ).once().with( boost::cref( s ) );
|
MOCK_EXPECT( f ).once().with( std::cref( s ) );
|
||||||
s = "string";
|
s = "string";
|
||||||
f( "string" );
|
f( "string" );
|
||||||
CHECK_CALLS( 1 );
|
CHECK_CALLS( 1 );
|
||||||
|
|
@ -666,7 +665,7 @@ BOOST_FIXTURE_TEST_CASE( mock_class_is_thread_safe, mock_error_fixture )
|
||||||
my_mock m;
|
my_mock m;
|
||||||
boost::thread_group group;
|
boost::thread_group group;
|
||||||
for( int i = 0; i < 100; ++i )
|
for( int i = 0; i < 100; ++i )
|
||||||
group.create_thread( boost::bind( &iterate, boost::ref( m ) ) );
|
group.create_thread( boost::bind( &iterate, std::ref( m ) ) );
|
||||||
group.join_all();
|
group.join_all();
|
||||||
CHECK_CALLS( 100 );
|
CHECK_CALLS( 100 );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -517,11 +517,11 @@ BOOST_AUTO_TEST_CASE( boost_assign_map_list_of_are_serialized )
|
||||||
BOOST_CHECK_EQUAL( "((12,\"12\"),(42,\"42\"))", to_string( boost::assign::map_list_of( 12, "12" )( 42, "42" ) ) );
|
BOOST_CHECK_EQUAL( "((12,\"12\"),(42,\"42\"))", to_string( boost::assign::map_list_of( 12, "12" )( 42, "42" ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( boost_reference_wrappers_are_serialized )
|
BOOST_AUTO_TEST_CASE( std_reference_wrappers_are_serialized )
|
||||||
{
|
{
|
||||||
const int i = 3;
|
const int i = 3;
|
||||||
BOOST_CHECK_EQUAL( "3", to_string( boost::cref( i ) ) );
|
BOOST_CHECK_EQUAL( "3", to_string( std::cref( i ) ) );
|
||||||
BOOST_CHECK_EQUAL( "\"string\"", to_string( boost::cref( "string" ) ) );
|
BOOST_CHECK_EQUAL( "\"string\"", to_string( std::cref( "string" ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ BOOST_AUTO_TEST_CASE( int_and_int_can_be_compared )
|
||||||
BOOST_AUTO_TEST_CASE( ref_to_int_and_int_can_be_compared )
|
BOOST_AUTO_TEST_CASE( ref_to_int_and_int_can_be_compared )
|
||||||
{
|
{
|
||||||
const int i = 3;
|
const int i = 3;
|
||||||
BOOST_CHECK( match( 3, boost::cref( i ) ) );
|
BOOST_CHECK( match( 3, std::cref( i ) ) );
|
||||||
BOOST_CHECK( ! match( 4, boost::cref( i ) ) );
|
BOOST_CHECK( ! match( 4, std::cref( i ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ namespace
|
||||||
BOOST_FIXTURE_TEST_CASE( mock_addition_operator, mock_error_fixture )
|
BOOST_FIXTURE_TEST_CASE( mock_addition_operator, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock_class_with_operator m;
|
mock_class_with_operator m;
|
||||||
MOCK_EXPECT( m.addition ).once().returns( boost::ref( m ) );
|
MOCK_EXPECT( m.addition ).once().returns( std::ref( m ) );
|
||||||
m += 1;
|
m += 1;
|
||||||
CHECK_CALLS( 1 );
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue