我一直在試圖在Google C++ Testing Framework/gtest中找到斷言,這相當於在Boost Test Library中找到的BOOST_CHECK_EQUAL_COLLECTIONS斷言。BOOST_CHECK_EQUAL_COLLECTIONS在Google測試中
但是;沒有成功。所以我的問題是雙重的:
EDIT(略作修改答案):
#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();
}
我想你需要看看姊妹項目:Google Mock。 – 2013-03-16 11:22:04