chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes

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();
}

asked by kennyC (1.1k points)
reshown by Tom_Typemock

1 Answer

0 votes

This is an MSTest issue, more information can be found here: https://developercommunity.visualstudio.com/t/testhostexe-crashes-with-access-violation-exceptio/1152388. Changing the project tests to GTest fixed the problem.

answered by Tom_Typemock (680 points)
...