diff --git a/doc/example/customization.cpp b/doc/example/customization.cpp
index 98aa0e1..e33c3ef 100644
--- a/doc/example/customization.cpp
+++ b/doc/example/customization.cpp
@@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE( forty_one_plus_one_is_forty_two_plus_or_minus_one_near_cre
{
mock_view v;
calculator c( v );
- int expected, threshold;
+ int expected = 0, threshold = 0;
MOCK_EXPECT( v.display ).with( near( std::cref( expected ), std::cref( threshold ) ) );
expected = 42;
threshold = 1;
diff --git a/doc/example/limitations_const_parameter_warning.cpp b/doc/example/limitations_const_parameter_warning.cpp
index 4cddbd5..88a163c 100644
--- a/doc/example/limitations_const_parameter_warning.cpp
+++ b/doc/example/limitations_const_parameter_warning.cpp
@@ -52,5 +52,7 @@ BOOST_AUTO_TEST_CASE(check_method_stub_is_called)
{
mock_base b;
MOCK_EXPECT(b.method).once().with(1);
- static_cast(&b)->method(1);
+ // Example user code taking a base* (or smart pointer variant)
+ auto callMethod = [](base* bPtr){ bPtr->method(1); };
+ callMethod(&b);
}
diff --git a/doc/example/limitations_non_virtual_method.cpp b/doc/example/limitations_non_virtual_method.cpp
index 96258f4..27e1899 100644
--- a/doc/example/limitations_non_virtual_method.cpp
+++ b/doc/example/limitations_non_virtual_method.cpp
@@ -29,5 +29,5 @@ BOOST_AUTO_TEST_CASE(method_not_called_through_base)
{
mock_base b;
MOCK_EXPECT(b.method).never();
- static_cast(&b)->method(); // Doesn't call the mocked method
+ static_cast(&b)->method(); // Doesn't call the mocked method as asserted above
}
diff --git a/doc/example/limitations_template_method.cpp b/doc/example/limitations_template_method.cpp
index 72874c5..f03bd8b 100644
--- a/doc/example/limitations_template_method.cpp
+++ b/doc/example/limitations_template_method.cpp
@@ -90,8 +90,8 @@ std::string mock_concept::create< std::string >()
BOOST_AUTO_TEST_CASE(dispatch_methods_are_called)
{
mock_concept b;
- MOCK_EXPECT(b.create_int).once().returns(int{});
- MOCK_EXPECT(b.create_string).once().returns(std::string{});
+ MOCK_EXPECT(b.create_int).once().returns(0);
+ MOCK_EXPECT(b.create_string).once().returns("");
function_under_test(b);
}
}
diff --git a/doc/example/patterns_async_call.cpp b/doc/example/patterns_async_call.cpp
index 9a9f9e7..0e8b779 100644
--- a/doc/example/patterns_async_call.cpp
+++ b/doc/example/patterns_async_call.cpp
@@ -31,8 +31,8 @@ namespace mock_test
my_class::my_class( base_class& b): b(b){}
void my_class::flush()
{
- static int secret_value = 7;
- if(--secret_value == 0)
+ static int counter = 7;
+ if(--counter == 0)
b.method();
}
}
@@ -59,15 +59,16 @@ namespace mock_test
{
MOCK_METHOD( method, 0 )
};
-}
BOOST_AUTO_TEST_CASE( method_is_called )
{
- using namespace mock_test;
mock_base_class m;
my_class c( m );
bool done = false;
MOCK_EXPECT( m.method ).once().calls( [&done](){ done = true; } );
check( done, [&c](){ c.flush(); } ); // just wait on done, flushing from time to time
}
+
+}
+
//]
diff --git a/doc/example/patterns_invoke_functor.cpp b/doc/example/patterns_invoke_functor.cpp
index cabdb67..01f7809 100644
--- a/doc/example/patterns_invoke_functor.cpp
+++ b/doc/example/patterns_invoke_functor.cpp
@@ -21,14 +21,14 @@
namespace
{
int receivedValue = 0;
- void setx(int newValue)
+ void setValue(int newValue)
{
receivedValue = newValue;
}
}
void function( base_class& c)
{
- c.method(setx);
+ c.method(setValue);
}
//[ invoke_functor_solution
@@ -48,6 +48,6 @@ BOOST_AUTO_TEST_CASE( how_to_invoke_a_functor_passed_as_parameter_of_a_mock_meth
mock_class mock;
MOCK_EXPECT( mock.method ).calls( [](const auto &functor){ functor(42); } ); // whenever 'method' is called, invoke the functor with 42
function( mock );
- BOOST_CHECK(receivedValue == 42);
+ BOOST_CHECK(receivedValue == 42); // functor was called and received the value 42
}
//]
diff --git a/doc/example/patterns_retrieve_cref.cpp b/doc/example/patterns_retrieve_cref.cpp
index 439585f..be28298 100644
--- a/doc/example/patterns_retrieve_cref.cpp
+++ b/doc/example/patterns_retrieve_cref.cpp
@@ -17,7 +17,6 @@ namespace
class my_class
{
- base_class& b;
public:
explicit my_class( base_class& );
@@ -28,12 +27,13 @@ namespace
namespace
{
- my_class::my_class( base_class& b): b(b){}
+ static base_class* global_b = nullptr;
+ my_class::my_class( base_class& b){ global_b = &b; }
void my_class::process()
{
int secret_value = 42;
- b.method(secret_value);
- b.method(secret_value);
+ global_b->method(secret_value);
+ global_b->method(secret_value);
}
}
diff --git a/doc/example/reference.cpp b/doc/example/reference.cpp
index 19033e4..ae6ca2e 100644
--- a/doc/example/reference.cpp
+++ b/doc/example/reference.cpp
@@ -438,7 +438,7 @@ BOOST_AUTO_TEST_CASE( demonstrates_configuring_mock_objects )
MOCK_EXPECT( c.method ).once().with( 0 ).in( s ).returns( 42 );
MOCK_EXPECT( c.method2 ).never().with( "ok", mock::any );
MOCK_EXPECT( c.method2 ).at_least( 2 ).in( s ).throws( std::runtime_error( "error !" ) );
- BOOST_CHECK(c.method(0) == 42);
+ BOOST_TEST(c.method(0) == 42);
BOOST_CHECK_THROW(c.method("not ok", 1.f), std::runtime_error);
BOOST_CHECK_THROW(c.method("not ok", 2.f), std::runtime_error);
}
@@ -505,7 +505,7 @@ BOOST_AUTO_TEST_CASE( demonstrates_setting_up_an_invocation_on_a_mock_static_met
{
mock_class c;
MOCK_EXPECT( c.method1 ).once();
- MOCK_EXPECT( mock_class::method2 ).once(); // does the same
+ MOCK_EXPECT( mock_class::method2 ).once(); // does the same (but for the other method)
c.method1(42);
c.method2(42);
}
@@ -525,7 +525,7 @@ BOOST_AUTO_TEST_CASE( demonstrates_adding_builtin_constraints )
{
mock_class c;
MOCK_EXPECT( c.method1 ).with( mock::equal( 3 ), mock::equal( "some string" ) );
- MOCK_EXPECT( c.method2 ).with( 3, "some string" ); // equivalent to the previous one using short-cuts
+ MOCK_EXPECT( c.method2 ).with( 3, "some string" ); // similar to the previous one using short-cuts
c.method1(3, "some string");
c.method2(3, "some string");
}
@@ -756,12 +756,12 @@ BOOST_AUTO_TEST_CASE( demonstrates_configuring_actions )
MOCK_EXPECT( c.method ).once().calls( &function ); // forwards 'method' parameter to 'function'
MOCK_EXPECT( c.method ).once().calls( std::bind( &function, 42 ) ); // drops 'method' parameter and binds 42 as parameter to 'function'
MOCK_EXPECT( c.method ).once().calls( []( int i ) { return i; } ); // uses a C++11 lambda
- BOOST_CHECK(c.method(0) == 42);
- BOOST_CHECK(c.method(1) == 42);
+ BOOST_TEST(c.method(0) == 42);
+ BOOST_TEST(c.method(1) == 42);
BOOST_CHECK_THROW(c.method(0), std::runtime_error);
- BOOST_CHECK(c.method(2) == 2);
- BOOST_CHECK(c.method(3) == 42);
- BOOST_CHECK(c.method(4) == 4);
+ BOOST_TEST(c.method(2) == 2);
+ BOOST_TEST(c.method(3) == 42);
+ BOOST_TEST(c.method(4) == 4);
}
//]
}
diff --git a/include/turtle/detail/function_impl_template.hpp b/include/turtle/detail/function_impl_template.hpp
index c40d66d..ecf6667 100644
--- a/include/turtle/detail/function_impl_template.hpp
+++ b/include/turtle/detail/function_impl_template.hpp
@@ -24,7 +24,7 @@
<< ')' \
<< lazy_expectations( this )
-#define MOCK_MOVE(z, n, d) \
+#define MOCK_FORWARD(z, n, d) \
std::forward< T##n >( t##n )
namespace mock
@@ -229,7 +229,7 @@ namespace detail
for( const auto& expectation: expectations_ )
{
if( expectation.is_valid(
- BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_MOVE, _) ) )
+ BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_FORWARD, _) ) )
{
if( ! expectation.invoke() )
{
@@ -247,7 +247,7 @@ namespace detail
error_type::call( MOCK_FUNCTION_CONTEXT, expectation.file(), expectation.line() );
if( expectation.functor() )
return expectation.functor()(
- BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_MOVE, _) );
+ BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_FORWARD, _) );
return expectation.trigger();
}
}
@@ -314,4 +314,4 @@ namespace detail
#undef MOCK_FUNCTION_FORMAT
#undef MOCK_FUNCTION_CONTEXT
-#undef MOCK_MOVE
+#undef MOCK_FORWARD
diff --git a/include/turtle/detail/function_template.hpp b/include/turtle/detail/function_template.hpp
index 179148e..e4de743 100644
--- a/include/turtle/detail/function_template.hpp
+++ b/include/turtle/detail/function_template.hpp
@@ -8,7 +8,7 @@
#include "function_impl_template.hpp"
-#define MOCK_MOVE(z, n, d) \
+#define MOCK_FORWARD(z, n, d) \
std::forward< T##n >( t##n )
namespace mock
@@ -65,7 +65,7 @@ namespace detail
R operator()(
BOOST_PP_ENUM_BINARY_PARAMS(MOCK_NUM_ARGS, T, t) ) const
{
- return (*impl_)( BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_MOVE, _) );
+ return (*impl_)( BOOST_PP_ENUM(MOCK_NUM_ARGS, MOCK_FORWARD, _) );
}
friend std::ostream& operator<<( std::ostream& s, const function& f )
@@ -94,4 +94,4 @@ namespace detail
}
} // mock
-#undef MOCK_MOVE
+#undef MOCK_FORWARD
diff --git a/include/turtle/mock.hpp b/include/turtle/mock.hpp
index 423ab74..17b5092 100644
--- a/include/turtle/mock.hpp
+++ b/include/turtle/mock.hpp
@@ -47,8 +47,7 @@
#define MOCK_FUNCTOR(f, ...) \
mock::detail::functor< MOCK_FUNCTION_TYPE(__VA_ARGS__) > f, f##_mock
/// MOCK_FUNCTOR_TPL( name, signature )
-/// Deprecated. Same as MOCK_FUNCTOR
-#define MOCK_FUNCTOR_TPL(f, ...) MOCK_FUNCTOR(f, __VA_ARGS__)
+#define MOCK_FUNCTOR_TPL(f, ...) static_assert(false, "MOCK_FUNCTOR_TPL has been replaced by MOCK_FUNCTOR")
#define MOCK_HELPER(t) \
t##_mock( mock::detail::root, BOOST_PP_STRINGIZE(t) )
diff --git a/test/detail/test_type_name.cpp b/test/detail/test_type_name.cpp
index 0a0fc97..0f577ef 100644
--- a/test/detail/test_type_name.cpp
+++ b/test/detail/test_type_name.cpp
@@ -16,7 +16,7 @@ namespace
std::string to_string( const T& t)
{
std::ostringstream s;
- s << mock::detail::make_type_name(t); // Typename can be streamed
+ s << mock::detail::make_type_name(t);
return s.str();
}
}
diff --git a/test/test_constraint.cpp b/test/test_constraint.cpp
index ca35e7b..58793f3 100644
--- a/test/test_constraint.cpp
+++ b/test/test_constraint.cpp
@@ -22,17 +22,3 @@ BOOST_AUTO_TEST_CASE( mock_constraint_is_supported_by_compilers_with_variadic_ma
BOOST_CHECK( constraint_1( 0 ).c_( 0 ) );
BOOST_CHECK( constraint_2( 0, 0 ).c_( 0 ) );
}
-
-namespace
-{
- MOCK_CONSTRAINT_EXT( constraint_0_ext, 0,, actual == 0 )
- MOCK_CONSTRAINT_EXT( constraint_1_ext, 1, ( expected ), actual == expected )
- MOCK_CONSTRAINT_EXT( constraint_2_ext, 2, ( expected_0, expected_1 ), actual == expected_0 || actual == expected_1 )
-}
-
-BOOST_AUTO_TEST_CASE( mock_constraint_ext_is_supported_by_all_compilers )
-{
- BOOST_CHECK( constraint_0_ext.c_( 0 ) );
- BOOST_CHECK( constraint_1_ext( 0 ).c_( 0 ) );
- BOOST_CHECK( constraint_2_ext( 0, 0 ).c_( 0 ) );
-}