How to verify just a few elements in an array?

227 views
Skip to first unread message

Mike Long

unread,
Feb 25, 2011, 8:11:35 AM2/25/11
to Google C++ Mocking Framework
Hi,

I have a question about matching arrays with googlemock.  Say I have an array but I only want to check the first two elements, how would I do that?

I have asked the question on StackOverflow with an example of what I'm trying to do, but I thought maybe someone here might be able to help:
http://stackoverflow.com/questions/5117519/googlemock-how-to-verify-elements-in-an-array-in-a-pointer-to-an-object

Thanks,
Mike

Piotr Gorak

unread,
Feb 25, 2011, 10:06:43 AM2/25/11
to Google C++ Mocking Framework
How about this: let's assume that I want to check only first two
elements of the array that passed as the 2nd argument of the mock
object function. I could add a small custom matcher:

MATCHER_P2(CheckFirstTwo, first, second)
{
return arg[0] == first && arg[1] == second;
}

And then:

EXPECT_CALL(myobj, MyMethod(_, CheckFirstTwo(1, 2), _)

or (since it will also work for other types)

EXPECT_CALL(myobj, MyMethod(_, CheckFirstTwo('a', 'b'), _)

Piotr
Reply all
Reply to author
Forward
0 new messages