I have been trying to find an assertion in the Google C++ Testing Framework / gtest which is equivalent to the BOOST_CHECK_EQUAL_COLLECTIONS assertion found in the Boost Test Library.
However; without success. So my question is two-fold:
- Does gtest have an equivalent assertion?
- If not: how would one go about asserting container-content in gtest?
EDIT (slightly modified answer):
#include <iostream>
template<typename LeftIter, typename RightIter>
::testing::AssertionResult CheckEqualCollections(LeftIter left_begin,
LeftIter left_end,
RightIter right_begin)
{
std::stringstream message;
std::size_t index(0);
bool equal(true);
for(;left_begin != left_end; left_begin++, right_begin++) {
if (*left_begin != *right_begin) {
equal = false;
message << "\n Mismatch in position " << index << ": " << *left_begin << " != " << *right_begin;
}
++index;
}
if (message.str().size()) {
message << "\n";
}
return equal ? ::testing::AssertionSuccess() :
::testing::AssertionFailure() << message.str();
}