Can Google Mock a method with a smart pointer return type?

前端 未结 5 1318
死守一世寂寞
死守一世寂寞 2020-11-28 23:32

I have a factory that returns a smart pointer. Regardless of what smart pointer I use, I can\'t get Google Mock to mock the factory method.

The mock object is the im

5条回答
  •  醉话见心
    2020-11-28 23:53

    I know this post was from a long time ago, so you've probably discovered the answer by now.

    gmock previously did not support mock functions that returned any movable type, including smart pointers. However, in April 2017, gmock introduced a new Action modifier ByMove.

    EXPECT_CALL(*foo_, Bar(_, )).WillOnce(Return(ByMove(some_move_only_object)));

    where some_move_only_object can be e.g. a std::unique_ptr.

    So yes, now gmock can mock a function that takes a smart pointer.

提交回复
热议问题