c++ - gmock:使用 unique_ptr 时 EXPECT_CALL 崩溃
问题描述
我在以下代码中遇到了崩溃:
class ITest
{
virtual void test(){};
};
void doNothing(){}
class TestMock: ITest
{
public:
MOCK_METHOD0(test, void());
};
class Server_Fixture: public ::testing::Test
{
public:
std::unique_ptr<TestMock> mock;
void SetUp() override
{
mock = std::unique_ptr<TestMock>();
}
void TearDown() override
{
}
TestMock& getMock(){ return *mock; }
};
TEST_F(Server_Fixture, execute)
{
EXPECT_CALL(getMock(), test()).WillRepeatedly(Invoke(doNothing)); // <<<< Segmentation fault (core dumped)
}
有人可以解释为什么它会崩溃吗?如果我在 TEST_F 函数中创建本地模拟对象(不使用 unique_ptr),则不会发生崩溃。
解决方案
推荐阅读
- java - Heroku 在 Spring Boot 中看不到 CSS 和静态 txt 文件
- android - Xamarin.Android - android:fontFamily 不起作用
- python - Python替换未知结构JSON文件中的值
- reporting-services - Report Builder 3.0 中的条件字段背景颜色
- android - 如何在 rxjava2 中正确调试 Completable,为什么没有人谈论链接它们?
- javascript - 管理点击多个文件的事件
- javascript - 将数据索引放入 Javascript 代码中
- solidity - 在 pet-shop-project 上运行“npm run dev”失败并给出错误
- vue.js - vuejs根据数据条件绑定一个类
- semantic-ui - Semantic-ui-react - 表格单元 Colspan