google mock with boost::test causes memory leak
Asked Answered
O

0

0

I am trying to create unit tests using boost::test and google mock. Adding a call to InitGoogleMock causes boost to signal some memory leaks. I searched for some sort of "DeInitGoogleMock" but didn't find any.

Why does this memory leak come up? How can it be fixed?

main.cpp:

#include <gmock/gmock.h>

#define BOOST_TEST_MODULE my_testt
#include <boost/test/unit_test.hpp>

struct InitGMock {
  InitGMock() {
    ::testing::GTEST_FLAG(throw_on_failure) = true;
    //::testing::InitGoogleMock(&boost::unit_test::framework::master_test_suite().argc,
    //  boost::unit_test::framework::master_test_suite().argv);
  }

  ~InitGMock() { }
};

BOOST_GLOBAL_FIXTURE(InitGMock);

BOOST_AUTO_TEST_CASE( test_case )
{
  BOOST_CHECK( true );
}

Output:

Running 1 test case...
*** No errors detected

Output after uncommenting the InitGoogleMock lines:

Running 1 test case...
*** No errors detected
Detected memory leaks!
Dumping objects ->
{669} normal block at 0x00B4E700, 48 bytes long.
 Data: <                > 00 E7 B4 00 00 E7 B4 00 00 E7 B4 00 CD CD CD CD
{668} normal block at 0x00B473B0, 28 bytes long.
 Data: <                > 00 00 00 00 CD CD CD CD CD CD CD CD CD CD CD CD
{667} normal block at 0x00B471B8, 24 bytes long.
 Data: <                > FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00
Object dump complete.
Outfall answered 11/8, 2016 at 8:20 Comment(4)
Is there a justified reason to use boost::test instead of googletest? If you are already planning to use googlemock, using anything other than googletest is a poor choice. You will constantly run into issues which will require workarounds (github.com/google/googletest/blob/master/googlemock/docs/…). Save yourself time and nerves and decide either to use boost::test with some other mocking framework or googletest/googlemock combo.Yakutsk
Unfortunately I am constrained to use boost::test for this project :(. Google mock was the one that got the most recommendations (#6760060 and https://mcmap.net/q/918993/-mocking-with-boost-test )... Would you suggest using any other? (I also had a look on hippo mocks and mockitopp)Outfall
As you can see in selected answer (your first link), even the person that recommends googlemock says he ended up using googletest. As far as the recommendation goes, I did not try out all other mock frameworks but I remember I liked how FakeIt was easy to use. Plus, it was header only.Yakutsk
Thank you! I just came across Turtle (turtle.sourceforge.net ) and it seems to be the right choice to go along with boost::test...Outfall

© 2022 - 2024 — McMap. All rights reserved.