blob: 502a248b9bd084f502c6057905d0b0c1ca1a257a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
|