21bool isEolDifference(streamCharIter &streamOne, streamCharIter &streamTwo) {
25 if (*streamOne ==
'\r' && *streamTwo ==
'\n') {
28 }
else if (*streamOne ==
'\n' && *streamTwo ==
'\r') {
40bool checkCharactersAreIdentical(streamCharIter streamOne, streamCharIter streamTwo) {
41 const char charOne = *streamOne;
42 const char charTwo = *streamTwo;
45 if (charOne == charTwo) {
50 return isEolDifference(streamOne, streamTwo);
53void logDifferenceError(
char refChar,
char testChar,
size_t numNewLines,
const std::string &seenChars) {
58 (outError +=
"At line number: ") += lineNumber;
59 (outError +=
". Character number: ") +=
std::to_string(seenChars.size() + 1);
60 (outError +=
" expected : '") += refChar;
61 (outError +=
"' found: '") += testChar;
62 ((outError +=
"\nReference output:\n") += seenChars) += refChar;
63 ((outError +=
"\nTest output:\n") += seenChars) += testChar;
88 size_t numNewLines = 0;
89 std::string seenChars;
91 while (refStream != refStreamEnd && testStream != testStreamEnd) {
93 if (!checkCharactersAreIdentical(refStream, testStream)) {
94 logDifferenceError(*refStream, *testStream, numNewLines, seenChars);
99 if (*refStream ==
'\n') {
103 seenChars += *refStream;
110 bool areStreamsEqual =
true;
114 if (refStream != refStreamEnd || testStream != testStreamEnd) {
116 g_log.
error(
"Length of both files were not identical");
117 areStreamsEqual =
false;
118 }
else if (numNewLines == 0 && seenChars.empty()) {
120 g_log.
error(
"No characters checked in FileComparisonHelper");
121 areStreamsEqual =
false;
124 return areStreamsEqual;
138bool areFilesEqual(
const std::string &referenceFileFullPath,
const std::string &outFileFullPath) {
139 std::ifstream refFileStream(referenceFileFullPath, std::ifstream::binary);
140 std::ifstream outFileStream(outFileFullPath, std::ifstream::binary);
142 if (refFileStream.fail()) {
143 throw std::runtime_error(
"Could not open reference file at specified path");
146 if (outFileStream.fail()) {
147 throw std::runtime_error(
"Could not open output file at specified path");
166 streamCharIter refIter(referenceFileStream), checkIter(fileToCheck);
192 if (referenceFilePath.empty()) {
193 throw std::invalid_argument(
"No reference file with the name: " + referenceFileName +
194 " could be found by FileComparisonHelper");
The Logger class is in charge of the publishing messages from the framework through various channels.
void error(const std::string &msg)
Logs at error level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
bool areFileStreamsEqual(std::ifstream &referenceFileStream, std::ifstream &fileToCheck)
Checks if two file streams are equal in content and length.
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 o...
std::istreambuf_iterator< char > streamCharIter
FileComparisonHelper provides several helper functions to compare files or file-streams within unit t...
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.
bool areFilesEqual(const std::string &referenceFileFullPath, const std::string &outFileFullPath)
Checks if two files are equal in content and length at the specified path.
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::string to_string(const wide_integer< Bits, Signed > &n)