Skip to content

Commit

Permalink
Merge pull request #144 from ericlemes/master
Browse files Browse the repository at this point in the history
Fix access violation that happens when Mock with destructor has more methods.
  • Loading branch information
eranpeer committed Jul 25, 2018
2 parents 33022fe + 5fb5a87 commit 5dd30de
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/mockutils/DynamicProxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ namespace fakeit {
std::vector<std::shared_ptr<Destructible>> &methodMocks,
std::vector<unsigned int> &offsets) :
_methodMocks(methodMocks), _offsets(offsets) {
for (std::vector<unsigned int>::iterator it = _offsets.begin(); it != _offsets.end(); ++it)
{
*it = INT_MAX;
}
}

Destructible *getInvocatoinHandlerPtrById(unsigned int id) override {
Expand Down
19 changes: 18 additions & 1 deletion tests/dtor_mocking_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ struct DtorMocking : tpunit::TestFixture
TEST(DtorMocking::mock_virtual_dtor_by_assignment),
TEST(DtorMocking::call_dtor_without_delete),
TEST(DtorMocking::spy_dtor),
TEST(DtorMocking::production_takes_ownwership_with_uniqe_ptr)//
TEST(DtorMocking::production_takes_ownwership_with_uniqe_ptr),
TEST(DtorMocking::production_takes_ownership_interface_with_more_methods)
)
{
}
Expand Down Expand Up @@ -94,4 +95,20 @@ struct DtorMocking : tpunit::TestFixture
ASSERT_THROW(Verify(Dtor(mock)).Once(), fakeit::VerificationException);
}

class SomeInterface2 {
public:
virtual void DoSomething() = 0;
virtual ~SomeInterface2() = default;
};

void production_takes_ownership_interface_with_more_methods() {
Mock<SomeInterface2> m;

Fake(Method(m, DoSomething));
Fake(Dtor(m));

std::unique_ptr<SomeInterface2> ptr = std::unique_ptr<SomeInterface2>(&m.get());
ptr = nullptr;
}

} __DtorMocking;

0 comments on commit 5dd30de

Please sign in to comment.