IsolatorPP: 4.2.4.0
VS 2019: 16.11.29 professional
If you invoke WHEN_CALLED/PRIVATE_WHEN_CALLED inside functions invoked by WHEN_CALLED/PRIVATE_WHEN_CALLED, the call will just crash. Please refer to the following snippet:
// CodeUnderTest Foo.h
class FooParent {
public:
FooParent(int x, std::string y): x(x), y(y) {}
FooParent() {}
bool foo1(std::string const &x) { throw; }
private:
int x = 0;
std::string y;
};
struct FooUser {
FooUser() {}
void touch(FooParent&) {}
void doFoo() {
FooParant foo{};
touch(foo);
foo.foo1("");
}
};
// In the test file:
struct Stub {
ISOLATOR_TESTABLE void fakeTouch(FooParent &v) {
// THIS WILL CRASH:
WHEN_CALLED(v.foo1(ANY_REF(std::string))).Return(false);
// Or THIS WILL CRASH:
// PRIVATE_WHEN_CALLED(&v, foo1).Return(false);
}
};
TEST_METHOD(TestStubInStub) {
Stub stub{};
FooUser f;
WHEN_CALLED(f.touch(ANY_REF(FooParent)))
.DoMemberFunctionInstead(&a, fakeTouch);
f.doFoo();
}