mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Enhanced custom constraints support
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@178 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
4d75d42be5
commit
176611c735
10 changed files with 144 additions and 7 deletions
35
src/tests/turtle_test/has_operator_test.cpp
Normal file
35
src/tests/turtle_test/has_operator_test.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2009
|
||||
//
|
||||
// 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 <turtle/has_operator.hpp>
|
||||
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#define BOOST_LIB_NAME boost_unit_test_framework
|
||||
#include <boost/config/auto_link.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct functor_with_valid_operator
|
||||
{
|
||||
bool operator()( float ) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
BOOST_STATIC_ASSERT(( mock::detail::has_operator< functor_with_valid_operator, float >::type::value ));
|
||||
|
||||
struct functor_with_valid_template_operator
|
||||
{
|
||||
template< typename T >
|
||||
bool operator()( T ) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
BOOST_STATIC_ASSERT(( mock::detail::has_operator< functor_with_valid_template_operator, float >::type::value ));
|
||||
}
|
||||
|
|
@ -310,3 +310,52 @@ BOOST_AUTO_TEST_CASE( boost_optional_on_base_class_reference_as_return_type )
|
|||
MOCK_EXPECT( b, method ).once().returns( boost::ref( o ) );
|
||||
b.method();
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename Expected >
|
||||
struct near_constraint
|
||||
{
|
||||
near_constraint( Expected expected, Expected threshold )
|
||||
: expected_( expected )
|
||||
, threshold_( threshold )
|
||||
{}
|
||||
|
||||
template< typename Actual >
|
||||
bool operator()( Actual actual ) const
|
||||
{
|
||||
return std::abs( actual - expected_ ) < threshold_;
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& os, const near_constraint& c )
|
||||
{
|
||||
return os << "std::abs( _ - " << c.expected_ << " ) < " << c.threshold_;
|
||||
}
|
||||
|
||||
//template< typename Actual >
|
||||
//void explain( std::ostream& os, Actual actual ) const
|
||||
//{
|
||||
// os << std::abs( actual - expected_ ) << " >= " << threshold_;
|
||||
//}
|
||||
|
||||
Expected expected_;
|
||||
Expected threshold_;
|
||||
};
|
||||
template< typename Expected >
|
||||
near_constraint< Expected > near( Expected expected, Expected threshold )
|
||||
{
|
||||
return near_constraint< Expected >( expected, threshold );
|
||||
}
|
||||
|
||||
MOCK_CLASS( custom_constraint_mock )
|
||||
{
|
||||
MOCK_METHOD_EXT( method, 1, void( float ), method )
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( writing_custom_constraint )
|
||||
{
|
||||
custom_constraint_mock m;
|
||||
MOCK_EXPECT( m, method ).with( near( 3.f, 0.01f ) );
|
||||
m.method( 3.f );
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue