From: Linux Karlsson Date: Fri, 30 Jul 2010 08:41:21 +0000 (+0200) Subject: Moved file handling code from test to superclass X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1b6de5fed2571d47fdc854ad02df78922350c3b;p=thirdparty%2Fntp.git Moved file handling code from test to superclass bk: 4c529031-lASH__w0kmTKYkMTiRgbw --- diff --git a/tests/sntp/fileHandlingTest.h b/tests/sntp/fileHandlingTest.h index 4668cb6876..0a25ac02c8 100644 --- a/tests/sntp/fileHandlingTest.h +++ b/tests/sntp/fileHandlingTest.h @@ -1,5 +1,12 @@ #include "sntptest.h" +#include +#include + +using std::ifstream; +using std::string; +using std::ios; + class fileHandlingTest : public sntptest { protected: enum DirectoryType { @@ -21,4 +28,26 @@ protected: 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++; + } + } }; diff --git a/tests/sntp/kodFile.cpp b/tests/sntp/kodFile.cpp index c59f3152c9..aed65ee4e8 100644 --- a/tests/sntp/kodFile.cpp +++ b/tests/sntp/kodFile.cpp @@ -6,11 +6,6 @@ extern "C" { #include "ntp_stdlib.h" // For estrdup() }; -#include -using std::ifstream; -using std::ios; -using std::string; - /* * We access some parts of the kod database directly, without * going through the public interface @@ -36,28 +31,6 @@ protected: kod_db_file = estrdup("/dev/null"); } - - int GetFileSize(ifstream& file) { - int initial = file.tellg(); - - file.seekg(0, std::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++; - } - } }; TEST_F(kodFileTest, ReadEmptyFile) {