mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Adress review comments
This commit is contained in:
parent
279bb2c767
commit
c7873cde4b
13 changed files with 36 additions and 48 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<base*>(&b)->method(1);
|
||||
// Example user code taking a base* (or smart pointer variant)
|
||||
auto callMethod = [](base* bPtr){ bPtr->method(1); };
|
||||
callMethod(&b);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,5 +29,5 @@ BOOST_AUTO_TEST_CASE(method_not_called_through_base)
|
|||
{
|
||||
mock_base b;
|
||||
MOCK_EXPECT(b.method).never();
|
||||
static_cast<base*>(&b)->method(); // Doesn't call the mocked method
|
||||
static_cast<base*>(&b)->method(); // Doesn't call the mocked method as asserted above
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
//]
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
//]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue