]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Moved file handling code from test to superclass
authorLinux Karlsson <karlsson@ntp.org>
Fri, 30 Jul 2010 08:41:21 +0000 (10:41 +0200)
committerLinux Karlsson <karlsson@ntp.org>
Fri, 30 Jul 2010 08:41:21 +0000 (10:41 +0200)
bk: 4c529031-lASH__w0kmTKYkMTiRgbw

tests/sntp/fileHandlingTest.h
tests/sntp/kodFile.cpp

index 4668cb6876e1be6153d0b1a0be09046b6477cb37..0a25ac02c803d5212997391bcfe142f6de121184 100644 (file)
@@ -1,5 +1,12 @@
 #include "sntptest.h"
 
+#include <fstream>
+#include <string>
+
+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++;
+               }
+       }
 };
index c59f3152c9d25f969800d0b5c861c2c19145368d..aed65ee4e89010cd14032e6f8d4bc9a68128de46 100644 (file)
@@ -6,11 +6,6 @@ extern "C" {
 #include "ntp_stdlib.h" // For estrdup()
 };
 
-#include <fstream>
-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) {