Reputation: 16412
I have the following interface:
struct IBackgroundModel {
virtual Image process(const Image& inputImage) = 0;
virtual ~IBackgroundModel() = default;
};
and a test with a mock:
TEST_F(EnvFixture, INCOMPLETE) {
struct BackgroundModelMock : IBackgroundModel {
MOCK_METHOD1(process, Image(const Image& override));
};
std::unique_ptr<IBackgroundModel> model = std::make_unique<BackgroundModelMock>();
Image input;
Image output;
EXPECT_CALL(model, process(input)).Will(Return(output));
BackgroundModelFactory factory;
factory.set(model.get());
const auto result = factory.process(input);
}
But I can't compile nor figure out what the error means:
error C2039: 'gmock_process': is not a member of 'std::unique_ptr<P,std::default_delete<P>>'
with
[
P=kv::backgroundmodel::IBackgroundModel
]
C:\Source\Kiwi\Kiwi.CoreBasedAnalysis\Libraries\Core\Kiwi.Vision.Core.Native\include\Ptr.hpp(17): message : see declaration of 'std::unique_ptr<P,std::default_delete<P>>'
with
[
P=kv::backgroundmodel::IBackgroundModel
]
Upvotes: 1
Views: 685
Reputation: 10315
Firstly EXPECT_CALL
takes reference, not a (smart) pointer. Secondly, it has to be reference to the concrete mock, not to the mocked class/interface. And thirdly, in latest gtest there is no Will
funciton. There is WillOnce
and WillRepeadately
. So the fix is like this:
std::unique_ptr<BackgroundModelMock> model = std::make_unique<BackgroundModelMock>();
Image input;
Image output;
EXPECT_CALL(*model, process(input)).WillOnce(testing::Return(output));
Upvotes: 3