Question

I want to check a vector of strings against a long sequence of matchers. For short sequences I can do:

std::vector<std::string> results = SomeCall();
ExpectThat (results, ElementsAre(IsDelay(7), "read", IsDelay(5), "write"));

(where IsDelay is my own custom matcher).

But ElementsAre only works up to 10 elements. If I want to check longer sequences, I could use ElementsAreArray, but what do I declare the expected array as? So for example, if I try to do:

XXX expected[] = {IsDelay(7), "read", IsDelay(5), "write")};
ExpectThat (results, ElementsAreArray (expected));

what should XXX be?

I am using gcc 4.8.1 in C++11 mode, with gmock 1.5.0.

Was it helpful?

Solution

The type should be ::testing::Matcher<std::string>, so:

::testing::Matcher<std::string> expected[] = {IsDelay(7), "read",
                                              IsDelay(5), "write"};

See the Matching Containers section in the docs, specifically the example:

// Or, an array of element matchers.
Matcher<int> expected_vector2 = { 1, Gt(2), _, 3, ... };
EXPECT_CALL(mock, Foo(ElementsAreArray(expected_vector2)));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top