Mantid
|
Typedefs | |
using | streamCharIter = std::istreambuf_iterator< char > |
FileComparisonHelper provides several helper functions to compare files or file-streams within unit tests. More... | |
Functions | |
bool | areFilesEqual (const std::string &referenceFileFullPath, const std::string &outFileFullPath) |
Checks if two files are equal in content and length at the specified path. More... | |
bool | areFileStreamsEqual (std::ifstream &referenceFileStream, std::ifstream &fileToCheck) |
Checks if two file streams are equal in content and length. More... | |
bool | areIteratorsEqual (streamCharIter refStream, streamCharIter testStream, streamCharIter refStreamEnd=streamCharIter(), streamCharIter testStreamEnd=streamCharIter()) |
Compares the length and content of std::streams iterators and returns if they are equal. More... | |
bool | isEqualToReferenceFile (const std::string &referenceFileName, const std::string &outFileFullPath) |
Attempts to find a reference file with the given name using Mantid then compares content and length of files (ignoring EOL differences). More... | |
using FileComparisonHelper::streamCharIter = typedef std::istreambuf_iterator<char> |
FileComparisonHelper provides several helper functions to compare files or file-streams within unit tests.
It accounts for EOL differences between Unix and Windows and will emit an error in the Mantid logging system as to how the files differed
Definition at line 27 of file FileComparisonHelper.h.
bool FileComparisonHelper::areFilesEqual | ( | const std::string & | referenceFileFullPath, |
const std::string & | outFileFullPath | ||
) |
Checks if two files are equal in content and length at the specified path.
Checks the two files at the specified paths are equal in both length and content.
Accounts for EOL differences if they exist
This does not take into account line endings i.e. CRLF and LF between Windows and Unix. If the files cannot be opened it will throw. a runtime error.
referenceFileFullPath,: | The full path to the reference file |
outFileFullPath,: | The full path to the output file to check |
Definition at line 138 of file FileComparisonHelper.cpp.
References areFileStreamsEqual().
Referenced by isEqualToReferenceFile().
bool FileComparisonHelper::areFileStreamsEqual | ( | std::ifstream & | referenceFileStream, |
std::ifstream & | fileToCheck | ||
) |
Checks if two file streams are equal in content and length.
Compares two file streams for equality and returns true if these are equal, false if they differ in any way.
Accounts for EOL differences.
This does not account for line endings i.e. CRLF and LF on Windows and Unix files would return false
referenceFileStream | :: The ifstream to the reference file |
fileToCheck | :: The ifstream to the file to check |
Definition at line 164 of file FileComparisonHelper.cpp.
References areIteratorsEqual().
Referenced by areFilesEqual().
bool FileComparisonHelper::areIteratorsEqual | ( | streamCharIter | refStream, |
streamCharIter | testStream, | ||
streamCharIter | refStreamEnd, | ||
streamCharIter | testStreamEnd | ||
) |
Compares the length and content of std::streams iterators and returns if they are equal.
Takes a pair of iterators and checks that all the values those iterators point to are identical.
If they differ in size or value it will return false. If they are identical it will return true.
refStream,: | The starting position of the reference stream to check |
testStream,: | The starting position of the test stream to check |
refStreamEnd,: | The final position of the reference stream to check |
testStreamEnd,: | The final position of the second stream to check |
Definition at line 85 of file FileComparisonHelper.cpp.
References Mantid::Kernel::Logger::error().
Referenced by areFileStreamsEqual().
bool FileComparisonHelper::isEqualToReferenceFile | ( | const std::string & | referenceFileName, |
const std::string & | outFileFullPath | ||
) |
Attempts to find a reference file with the given name using Mantid then compares content and length of files (ignoring EOL differences).
Attempts to find a reference file with the given name using the FileFinder.
If it cannot be found it will throw a std::invalid_argument. If the file is found it will compare the two specified files are equal in length and content whilst ignoring EOL differences
referenceFileName | :: The filename of the reference file |
outFileFullPath | :: The path to the file written by the test to compare |
: | If the reference file could not be found throws std::invalid_argument |
Definition at line 189 of file FileComparisonHelper.cpp.
References areFilesEqual(), and Mantid::Kernel::SingletonHolder< T >::Instance().