Mantid
Loading...
Searching...
No Matches
Typedefs | Functions
FileComparisonHelper Namespace Reference

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...
 

Typedef Documentation

◆ streamCharIter

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

Author
David Fairbrother
Date
2017 Typedef buffered stream iterator (char) to a shorter name

Definition at line 27 of file FileComparisonHelper.h.

Function Documentation

◆ areFilesEqual()

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.

Parameters
referenceFileFullPath,:The full path to the reference file
outFileFullPath,:The full path to the output file to check
Returns
True if files are equal in content and length, else false.

Definition at line 138 of file FileComparisonHelper.cpp.

References areFileStreamsEqual().

Referenced by isEqualToReferenceFile().

◆ areFileStreamsEqual()

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

Parameters
referenceFileStream:: The ifstream to the reference file
fileToCheck:: The ifstream to the file to check
Returns
True if files are identical else false

Definition at line 164 of file FileComparisonHelper.cpp.

References areIteratorsEqual().

Referenced by areFilesEqual().

◆ areIteratorsEqual()

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.

Parameters
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
Returns
True if iterators are identical in value and length else false

Definition at line 85 of file FileComparisonHelper.cpp.

References Mantid::Kernel::Logger::error().

Referenced by areFileStreamsEqual().

◆ isEqualToReferenceFile()

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

Parameters
referenceFileName:: The filename of the reference file
outFileFullPath:: The path to the file written by the test to compare
Exceptions
:If the reference file could not be found throws std::invalid_argument
Returns
:: True if files are equal length and content (ignoring EOL) else false.

Definition at line 189 of file FileComparisonHelper.cpp.

References areFilesEqual(), and Mantid::Kernel::SingletonHolder< T >::Instance().