diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-12-02 09:01:21 +0000 |
---|---|---|
committer | <> | 2014-12-04 16:11:25 +0000 |
commit | bdab5265fcbf3f472545073a23f8999749a9f2b9 (patch) | |
tree | c6018dd03dea906f8f1fb5f105f05b71a7dc250a /sntp/tests/fileHandlingTest.h | |
download | ntp-dev-4.2.7p482.tar.gz |
Imported from /home/lorry/working-area/delta_ntp/ntp-dev-4.2.7p482.tar.gz.ntp-dev-4.2.7p482
Diffstat (limited to 'sntp/tests/fileHandlingTest.h')
-rw-r--r-- | sntp/tests/fileHandlingTest.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/sntp/tests/fileHandlingTest.h b/sntp/tests/fileHandlingTest.h new file mode 100644 index 0000000..502a248 --- /dev/null +++ b/sntp/tests/fileHandlingTest.h @@ -0,0 +1,64 @@ +#ifndef FILE_HANDLING_TEST_H +#define FILE_HANDLING_TEST_H + +#include "sntptest.h" + +#include <fstream> +#include <string> + +using std::ifstream; +using std::string; +using std::ios; + +class fileHandlingTest : public sntptest { +protected: + enum DirectoryType { + INPUT_DIR = 0, + OUTPUT_DIR = 1 + }; + + std::string CreatePath(const char* filename, DirectoryType argument) { + std::string path; + + if (m_params.size() >= argument + 1) { + path = m_params[argument]; + } + + if (path[path.size()-1] != DIR_SEP && !path.empty()) { + path.append(1, DIR_SEP); + } + path.append(filename); + + return path; + } + + int GetFileSize(ifstream& file) { + int initial = file.tellg(); + + file.seekg(0, ios::end); + int length = file.tellg(); + file.seekg(initial); + + return length; + } + + void CompareFileContent(ifstream& expected, ifstream& actual) { + int currentLine = 1; + while (actual.good() && expected.good()) { + string actualLine, expectedLine; + getline(actual, actualLine); + getline(expected, expectedLine); + + EXPECT_EQ(expectedLine, actualLine) << "Comparision failed on line " << currentLine; + currentLine++; + } + } + + void ClearFile(const std::string& filename) { + std::ofstream clear(filename.c_str(), ios::trunc); + ASSERT_TRUE(clear.good()); + clear.close(); + } +}; + +#endif // FILE_HANDLING_TEST_H |