即使使用虚拟析构函数,也无法在EXPECT_CALL上泄漏Google模拟信号

时间:2019-06-26 08:45:24

标签: c++ memory googletest gmock

此测试中我遇到内存泄漏,低于该水平似乎是由于删除此行以来EXPECT_CALL触发的-

EXPECT_CALL(*AMock_, method(_,_);

使泄漏消失。

这是测试:

TEST_F(Test, testing)
{
    auto AMock_ = std::make_unique<AMock>();

    EXPECT_CALL(*AMock_, method(_,_).Times(AtLeast(1));
    AMock_->init(NUMROW, NUMCOL);

    EXPECT_TRUE(Mock::VerifyAndClearExpectations(AMock_.get()));
}

这里是模拟:

#include <gmock/gmock.h>
#include "BaseB.h"

class AMock: public BaseB
{
public:
MOCK_METHOD2(method, void(int row, int col));
};

和BaseB类:

class BaseB: public BaseA
{
public:
    BaseB();
    virtual ~BaseB();
    virtual void init(int row, int col);
};

void BaseB::init(int row, int col)
{
   int x = row / 2;
   int y = col / 5;
   method(x, y);
   //codes codes codes..
}

哪个来自BaseA:

class BaseA
{
public:
    BaseA();
    virtual ~BaseA();

    virtual void method(int param1, int param2);
};

该模拟的基类(BaseB和BaseA)都已经具有虚拟析构函数,因此我不确定这是什么错误。救命!

0 个答案:

没有答案