预计在GMock打电话,工厂返回unique_ptr
Expect call in GMock with Factory returning unique_ptr
我有工厂通过返回unique_ptr来创建一些窗口:
std::unique_ptr<WindowsInterface> NCursesWindowsFactory::createMainWindow()
{
return std::make_unique<NCursesMainWindowDecorator>(std::make_unique<NCursesWindow>());
}
在模拟工厂类中,此方法:
MOCK_METHOD0(createMainWindow, std::unique_ptr<WindowsInterface>());
如何编写EXPECT_CALL,在不复制的情况下将某些对象作为unique_ptr返回,就像我在拳头方法中所做的那样?
我在工厂模拟上的EXPECT_CALL是这样返回的:
.WillOnce(Return(std::make_unique<NCursesMainWindowDecorator>(std::make_unique<NCursesWindow>())))
我想移动这个unique_ptr但 gmock 试图复制它:
./lib/googletest/googlemock/include/gmock/gmock-actions.h:579:59: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = miniReader::windowsManager::WindowsInterface; _Dp = std::default_delete<miniReader::windowsManager::WindowsInterface>]’
也许有点晚了,但这里有一个选项:
只需添加"ByMove"附加操作即可移动参数:
.WillOnce(Return(ByMove(std::make_unique<NCursesMainWindowDecorator>(std::make_unique<NCursesWindow>()))))
相关文章:
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- 什么时候在C++中返回常量引用是个好主意
- 你能重载对象变量名本身返回的内容吗
- 为什么 Serial.println(<char[]>);返回随机字符?
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 如何获取std::result_of函数的返回类型
- QueryWorkingSet总是返回false
- (C++)分析树以计算返回错误值的简单算术表达式
- 访问者访问变体并返回不同类型时出错
- 如何返回一个类的两个对象相加的结果
- 为什么 std::unique 不调用 std::sort?
- OpenInventor从9.8升级到10.4.2后,GLSL纹理返回零
- lower_bound()返回最后一个元素
- "throw expression code" 1e7 >返回 d 是什么?投掷标准::overflow_error( "too big" ) : d;意味 着?
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 如何取消对nullptr的屏蔽,返回正确的对象
- 奇怪的结构&GCC&clang(void*返回类型)
- 从 std::unique 返回的迭代器的用法
- SQLite INSERT 命令返回错误"column number is not unique"
- 返回c++中的unique()函数