Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cpp11 branch] memory access violation with multiple mock repositories #94

Open
torbjoernk opened this issue Jul 10, 2018 · 2 comments
Open

Comments

@torbjoernk
Copy link

When using more than one mock repository, the destructor of the second mock repository fails with a memory access violation at hippomocks.h:942 when calling TestFinished() on the reporter of the second repository as MockRepoInstanceHolder<0>::instance = nullptr; and MockRepoInstanceHolder<0>::reporter = nullptr; has been called in the destructor of the first mock repository.

Sample code:

#include <boost/test/unit_test.hpp>
#include <hippomocks.h>

struct Foo
{
  virtual ~Foo() noexcept = 0;
  virtual int foo() = 0;
};

struct Bar
{
  virtual ~Bar() noexcept = 0;
  virtual int bar() = 0;
};

struct Fixture
{
  Fixture()
  {
    mocks_foo.autoExpect = false;
    mocks_bar.autoExpect = false;

    foo.reset(mocks_foo.Mock<Foo>());
    bar.reset(mocks_bar.Mock<Bar>());

    mocks_foo.ExpectCallDestructor(foo.get());
    mocks_bar.ExpectCallDestructor(bar.get());
  }

  HippoMocks::MockRepository mocks_foo;
  HippoMocks::MockRepository mocks_bar;
  std::shared_ptr<Foo> foo;
  std::shared_ptr<Bar> bar;
};

BOOST_FIXTURE_TEST_SUITE(HippoMocksTest, Fixture)

BOOST_AUTO_TEST_CASE(hippomocks_two_repos)
{
}

BOOST_AUTO_TEST_SUITE_END()
@tnovotny
Copy link
Collaborator

tnovotny commented Jul 10, 2018

Hmm, it looks like there is a singleton being used now, so using two repos no longer works. The example is a skinned down example where, due to complex setup, it was necessary to introduce a second repository to change the order of destructor calls, or rather the point in time when the expectations on a mock are evaluated. Is there any way to achieve such an effect using other means?

@torbjoernk
Copy link
Author

We were able to workaround our need for two separate mock repositories. Thus, this issue isn't relevant for us any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants