I have an array of mocked objects and I need to provide the same expectation for many of them. I can only succeed in this by manually writing the expectation for each object of the array.
the function under test
struct IWheel {
virtual bool is_flat() = 0;
};
bool all_tyres_ok( IWheel* wheels[4] )
{
return all_of(wheels, wheels+4, [](IWheel*w) {
return w->is_flat();
});
}
setting the expectations of the mocks
struct MockWheel : public IWheel {
MAKE_MOCK0(is_flat, bool(), override);
};
TEST_CASE("test_wheels")
{
MockWheel w[4];
{
ALLOW_CALL(w[0], is_flat()).RETURN(true);
ALLOW_CALL(w[1], is_flat()).RETURN(true);
ALLOW_CALL(w[2], is_flat()).RETURN(false);
ALLOW_CALL(w[3], is_flat()).RETURN(true);
REQUIRE(all_tyres_ok(w) == false);
}
}
Is there a way of setting the same expectation to many objects? and maybe override the expectation for some?
for
loop does not work.