google mock with boost::test causes memory leak

跟風遠走 提交于 2019-12-12 04:44:34

问题


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.

来源:https://stackoverflow.com/questions/38890959/google-mock-with-boosttest-causes-memory-leak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!