Reputation: 155
std::vector<uint8_t> vector1(10);
std::vector<uint8_t> vector2(10);
std::fill(vector1.begin(), vector1.end(), 2);
std::fill(vector2.begin(), vector2.end(), 2);
EXPECT_EQ(vector1, vector2);
Does the EXPECT_EQ() above check that the contents in vector1 and vector2 are equal? If not, how do I check that that the contents in vector1 and vector2 are equal using a googletest EXPECT_* function?
The documentation for googletest explains how to test the contents of C strings and c++ string objects, but not how to check the contents of a c++ vector.
Upvotes: 1
Views: 4650
Reputation: 671
The googletest does explain how to compare containers (such as a vector) in the matchers section.
The matcher ContainerEq(container)
would probably do what you're after.
So something similar to EXPECT_THAT(firstVector, testing::ContainerEq(secondVector));
might do the trick.
Upvotes: 0
Reputation: 22269
EXPECT_EQ
uses operator ==
to compare objects, and operator ==
for std::vector
(quote from cppreference):
Checks if the contents of
lhs
andrhs
are equal, that is, they have the same number of elements and each element inlhs
compares equal with the element inrhs
at the same position.
So the answer is yes, it will compare the contents of the vectors.
Upvotes: 8