| 17 | } |
| 18 | |
| 19 | void compare(char const* refName, char const* testName) |
| 20 | { |
| 21 | std::ifstream ref; |
| 22 | ref.open(refName); |
| 23 | if (!ref.is_open()) { |
| 24 | std::cout << "Could not open \"" << refName << "\"." << std::endl; |
| 25 | exit(1); |
| 26 | } |
| 27 | std::ifstream test; |
| 28 | test.open(testName); |
| 29 | if (!test.is_open()) { |
| 30 | std::cout << "Could not open \"" << testName << "\"." << std::endl; |
| 31 | exit(1); |
| 32 | } |
| 33 | |
| 34 | while (!ref.eof() && !test.eof()) { |
| 35 | std::string refLine; |
| 36 | std::string testLine; |
| 37 | std::getline(ref, refLine); |
| 38 | std::getline(test, testLine); |
| 39 | // Some very old Borland runtimes (C++ Builder 5 WITHOUT Update 1) add a |
| 40 | // trailing null to the string that we need to strip before testing for a |
| 41 | // trailing space. |
| 42 | rtrim(refLine, 0); |
| 43 | rtrim(testLine, 0); |
| 44 | // The reference files never have trailing spaces: |
| 45 | rtrim(testLine, ' '); |
| 46 | // Strip trailing CR. LF is not returned by getline, but CR is returned |
| 47 | // on some platforms. |
| 48 | rtrim(refLine, '\r'); |
| 49 | rtrim(testLine, '\r'); |
| 50 | if (refLine != testLine) { |
| 51 | std::cout << "Ref and test are not the same:\n Ref: \"" << refLine |
| 52 | << "\"\n Test: \"" << testLine << "\"\n"; |
| 53 | exit(1); |
| 54 | } |
| 55 | } |
| 56 | if (!ref.eof() || !test.eof()) { |
| 57 | std::cout << "Ref and test have differing numbers of lines."; |
| 58 | exit(1); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | int main() |
| 63 | { |