Refactoring

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@171 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2010-07-29 05:40:46 +00:00
parent f3173c7770
commit 0377bccad2
2 changed files with 26 additions and 34 deletions

View file

@ -11,6 +11,9 @@
#include "config.hpp"
#include <boost/spirit/home/phoenix/bind/bind_function.hpp>
#include <boost/spirit/home/phoenix/statement/throw.hpp>
#include <boost/spirit/home/phoenix/operator/self.hpp>
#include <boost/spirit/home/phoenix/core/nothing.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <boost/ref.hpp>
@ -40,7 +43,7 @@ namespace detail
template< typename Y >
void returns( const boost::reference_wrapper< Y >& r )
{
f_ = boost::phoenix::val( r );
f_ = *boost::phoenix::val( r.get_pointer() );
}
void calls( const functor_type& f )
@ -53,7 +56,7 @@ namespace detail
template< typename Exception >
void throws( Exception e )
{
f_ = boost::phoenix::bind( &throw_exception< Exception >, e );
f_ = boost::phoenix::throw_( e );
}
const functor_type& functor() const
@ -62,13 +65,6 @@ namespace detail
}
private:
template< typename Exception >
static Result throw_exception( const Exception& e )
{
throw e;
}
boost::shared_ptr< result_type > r_;
functor_type f_;
};
@ -100,7 +96,7 @@ namespace detail
template< typename Exception >
void throws( Exception e )
{
f_ = boost::phoenix::bind( &throw_exception< Exception >, e );
f_ = boost::phoenix::throw_( e );
}
const functor_type& functor() const
@ -109,12 +105,6 @@ namespace detail
}
private:
template< typename Exception >
static Result* throw_exception( const Exception& e )
{
throw e;
}
functor_type f_;
};
@ -126,7 +116,7 @@ namespace detail
public:
action()
: f_( boost::phoenix::bind( &nothing ) )
: f_( boost::phoenix::nothing )
{}
void calls( const functor_type& f )
@ -139,7 +129,7 @@ namespace detail
template< typename Exception >
void throws( Exception e )
{
f_ = boost::phoenix::bind( &throw_exception< Exception >, e );
f_ = boost::phoenix::throw_( e );
}
const functor_type& functor() const
@ -148,15 +138,6 @@ namespace detail
}
private:
static void nothing()
{}
template< typename Exception >
static void throw_exception( const Exception& e )
{
throw e;
}
functor_type f_;
};
@ -192,7 +173,7 @@ namespace detail
template< typename Exception >
void throws( Exception e )
{
f_ = boost::phoenix::bind( &throw_exception< Exception >, e );
f_ = boost::phoenix::throw_( e );
r_.reset();
}
@ -221,12 +202,6 @@ namespace detail
f_ = boost::phoenix::val( boost::ref( r_ ) );
}
template< typename Exception >
static std::auto_ptr< Result > throw_exception( const Exception& e )
{
throw e;
}
mutable std::auto_ptr< Result > r_;
functor_type f_;
};

View file

@ -16,6 +16,7 @@
#include <turtle/mock.hpp>
#include <boost/noncopyable.hpp>
#include <boost/optional.hpp>
#include <boost/ref.hpp>
namespace
@ -293,3 +294,19 @@ BOOST_AUTO_TEST_CASE( failed_sequence_in_mocked_destructor_does_not_throw )
m.my_method();
}
}
namespace
{
MOCK_CLASS( boost_optional )
{
MOCK_METHOD_EXT( method, 0, boost::optional< my_observer& >(), method )
};
}
BOOST_AUTO_TEST_CASE( boost_optional_on_base_class_reference_as_return_type )
{
boost_optional b;
my_mock_observer o;
MOCK_EXPECT( b, method ).once().returns( boost::ref( o ) );
b.method();
}