Search code examples
c++googletestgooglemockmatcher

EXPECT_CALL check if parameter contains given subset


I'm using gtest & gmock and want to set expectations on a function that is called with a set. I want to make sure this set contains several elements.

Something like this:

EXPECT_CALL(*mView, SetHighlightedCells(Contains(AllOf(c5, c6))));

I know I can specify the full set,

EXPECT_CALL(*mView, SetHighlightedCells(UnorderedElementsAre(c5, c6, ...and all the rest..)));

or

EXPECT_CALL(*mView, SetHighlightedCells(UnorderedElementsAreArray(vector_containing_c5_c6_and_ALL_other_elements)));

But I'm not interested in all other elements passed, I only need to make sure this set contains c5 and c6.


Solution

  • Just looking at the docs AllOf() takes a bunch of matchers, of which one of is:

    Contains(e)
    argument contains an element that matches e, which can be either a value or a matcher.

    So I would guess:

    EXPECT_CALL(*mView, SetHighlightedCells(AllOf(Contains(c5), Contains(c6))));