35 #ifndef FILECOMPARISON_HPP_ 36 #define FILECOMPARISON_HPP_ 38 #include "AbstractFileComparison.hpp" 40 #include <boost/foreach.hpp> 75 FileComparison(std::string fileName1, std::string fileName2,
bool calledCollectively=
true,
bool suppressOutput =
false)
77 mIgnoreCommentLines(true),
78 mIgnoreBlankLines(false)
94 mIgnoreCommentLines(true),
95 mIgnoreBlankLines(false)
107 mCommentLineStarts.push_back(
"#");
108 mCommentLineStarts.push_back(
"!");
109 mCommentLineStarts.push_back(
"Created by Chaste");
110 mCommentLineStarts.push_back(
"<!-- Created by Chaste");
122 mIgnoreCommentLines = ignore;
125 mCommentLineStarts.clear();
137 mIgnoreBlankLines = ignore;
148 mIgnoreCommentLines =
true;
149 mCommentLineStarts.push_back(lineStart);
160 mIgnorableContent.push_back(rIgnorableText);
169 bool CompareFiles(
unsigned ignoreFirstFewLines=0,
bool doTsAssert=
true)
179 unsigned failures = 0;
180 unsigned max_display_failures = 10;
184 bool files_empty =
false;
192 if (mIgnoreBlankLines)
195 while (buffer1.empty() &&
mpFile1->good())
199 while (buffer2.empty() &&
mpFile2->good())
205 if (mIgnoreCommentLines)
207 bool skip_this_line =
false;
208 for (
unsigned i=0; i<mCommentLineStarts.size(); i++)
211 size_t found1 = buffer1.find(mCommentLineStarts[i]);
212 size_t found2 = buffer2.find(mCommentLineStarts[i]);
213 if (found1 == 0 && found2 == 0)
215 skip_this_line =
true;
226 if (!mIgnorableContent.empty())
228 bool skip_this_line =
false;
229 BOOST_FOREACH(
const std::string& rText, mIgnorableContent)
231 size_t found1 = buffer1.find(rText);
232 size_t found2 = buffer2.find(rText);
233 if (found1 != std::string::npos && found2 != std::string::npos)
235 skip_this_line =
true;
245 if (!(buffer1==buffer2) && !files_empty)
250 std::stringstream message;
253 TS_TRACE(message.str());
266 TS_ASSERT_EQUALS(failures, 0u);
277 return (failures==0);
void IgnoreBlankLines(bool ignore=true)
void SkipHeaderLines(unsigned numLinesToSkip)
FileComparison(std::string fileName1, std::string fileName2, bool calledCollectively=true, bool suppressOutput=false)
FileComparison(const FileFinder &rFileName1, const FileFinder &rFileName2, bool calledCollectively=true, bool suppressOutput=false)
std::vector< std::string > mIgnorableContent
void SetIgnoreCommentLines(bool ignore=true)
void SetIgnoreLinesBeginningWith(std::string lineStart)
bool CompareFiles(unsigned ignoreFirstFewLines=0, bool doTsAssert=true)
std::vector< std::string > mCommentLineStarts
void IgnoreLinesContaining(const std::string &rIgnorableText)