Irbis
Irbis

Reputation: 13569

gmock - testing mock method arguments

I have following mock method:

MOCK_METHOD1(send, void(const std::vector<int>& data));

How to check if that method was called with a particular argument, for example std::vector<int> vec{1,2,3} ?

Upvotes: 1

Views: 2083

Answers (2)

Antonio P&#233;rez
Antonio P&#233;rez

Reputation: 7002

According to gmock docs on container matchers, for the proposed use case, you could simply do:

EXPECT_CALL(mockObj, send(std::vector<int>{1,2,3}).Times(1);

Upvotes: 2

Marko Popovic
Marko Popovic

Reputation: 4153

Assuming that you mock object is named mockObj, this is how to you would match the argument with the desired vector:

std::vector<int> dataToMatch{ 1, 2, 3 };
EXPECT_CALL(mockObj, send(ElementsAreArray(dataToMatch.cbegin(), dataToMatch.cend())))
    .WillOnce(Return());

Upvotes: 1

Related Questions