Repository navigation
Expand file tree
/
Copy pathPassagierInputTests.cpp
More file actions
175 lines (140 loc) · 6.5 KB
/
Copy pathPassagierInputTests.cpp
File metadata and controls
175 lines (140 loc) · 6.5 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <iostream>
#include <fstream>
#include <sys/stat.h>
#include <gtest/gtest.h>
#include "MetroNet.h"
#include "MetroNetUtils.h"
#include "MetroNetImporter.h"
class PassagierInputTests: public ::testing::Test {
protected:
friend class MetroNet;
virtual void SetUp() {
delete metronet;
metronet = new MetroNet();
}
MetroNet* metronet = new MetroNet();
};
TEST_F(PassagierInputTests, correctInput) {
ASSERT_TRUE(DirectoryExists("_testInput"));
ASSERT_TRUE(DirectoryExists("_testInput/PassagierInputTests"));
ASSERT_TRUE(DirectoryExists("_testOutput"));
std::ofstream ofile;
SuccessEnum importResult;
int fileCounter = 1;
std::string fileName = "_testInput/PassagierInputTests/correctInput" + std::to_string(fileCounter) + ".xml";
while (FileExists(fileName)) {
SetUp();
importResult = MetroNetImporter::importMetroNet("_testInput/PassagierInputTests/MetroNetInput.xml", ofile, *metronet);
EXPECT_TRUE(importResult == Success);
ofile.open("_testOutput/passagierInputTestsError.txt");
importResult = MetroNetImporter::importPassengers(fileName.c_str(), ofile, *metronet);
ofile.close();
EXPECT_TRUE(importResult == Success);
EXPECT_TRUE(FileIsEmpty("_testOutput/passagierInputTestsError.txt"));
fileCounter++;
fileName = "_testInput/PassagierInputTests/correctInput" + std::to_string(fileCounter) + ".xml";
}
EXPECT_TRUE(fileCounter == 3);
}
TEST_F(PassagierInputTests, wrongInputSyntaxError) {
ASSERT_TRUE(DirectoryExists("_testInput"));
ASSERT_TRUE(DirectoryExists("_testInput/PassagierInputTests"));
ASSERT_TRUE(DirectoryExists("_testOutput"));
ASSERT_TRUE(DirectoryExists("_testOutput/PassagierInputTestsExpected"));
std::ofstream ofile;
SuccessEnum importResult;
int fileCounter = 1;
std::string fileName = "_testInput/PassagierInputTests/syntaxErrorInput" + std::to_string(fileCounter) + ".xml";
while (FileExists(fileName)) {
SetUp();
importResult = MetroNetImporter::importMetroNet("_testInput/PassagierInputTests/MetroNetInput.xml", ofile, *metronet);
EXPECT_TRUE(importResult == Success);
ofile.open("_testOutput/passagierInputTestsError.txt");
importResult = MetroNetImporter::importPassengers(fileName.c_str(), ofile, *metronet);
ofile.close();
EXPECT_TRUE(importResult == ImportAborted);
std::string expectedFileName = "_testOutput/PassagierInputTestsExpected/syntaxError" + std::to_string(fileCounter) + ".txt";
EXPECT_TRUE(FileCompare("_testOutput/passagierInputTestsError.txt", expectedFileName));
fileCounter++;
fileName = "_testInput/PassagierInputTests/syntaxErrorInput" + std::to_string(fileCounter) + ".xml";
}
EXPECT_TRUE(fileCounter == 6);
}
TEST_F(PassagierInputTests, wrongInputNoCrash) {
ASSERT_TRUE(DirectoryExists("_testInput"));
ASSERT_TRUE(DirectoryExists("_testInput/PassagierInputTests"));
ASSERT_TRUE(DirectoryExists("_testOutput"));
ASSERT_TRUE(DirectoryExists("_testOutput/PassagierInputTestsExpected"));
std::ofstream ofile;
SuccessEnum importResult;
int fileCounter = 1;
std::string fileName = "_testInput/PassagierInputTests/wrongInput" + std::to_string(fileCounter) + ".xml";
while (FileExists(fileName)) {
SetUp();
importResult = MetroNetImporter::importMetroNet("_testInput/PassagierInputTests/MetroNetInput.xml", ofile, *metronet);
EXPECT_TRUE(importResult == Success);
ofile.open("_testOutput/passagierInputTestsError.txt");
importResult = MetroNetImporter::importPassengers(fileName.c_str(), ofile, *metronet);
ofile.close();
EXPECT_TRUE(importResult == PartialImport);
std::string expectedFileName = "_testOutput/PassagierInputTestsExpected/wrongInput" + std::to_string(fileCounter) + ".txt";
EXPECT_TRUE(FileCompare("_testOutput/passagierInputTestsError.txt", expectedFileName));
fileCounter++;
fileName = "_testInput/PassagierInputTests/wrongInput" + std::to_string(fileCounter) + ".xml";
}
EXPECT_TRUE(fileCounter == 13);
}
TEST_F(PassagierInputTests, wrongInputCrash) {
ASSERT_TRUE(DirectoryExists("_testInput"));
ASSERT_TRUE(DirectoryExists("_testInput/PassagierInputTests"));
ASSERT_TRUE(DirectoryExists("_testOutput"));
ASSERT_TRUE(DirectoryExists("_testOutput/PassagierInputTestsExpected"));
std::string errors[4] =
{
"Passagier::moveToBeginStation made MetroNet inconsistent",
"Passagier::moveToBeginStation made MetroNet inconsistent",
"beginStation is not a station of MetroNet",
"This MetroNet allready contains a passenger with this name"
};
std::ofstream ofile;
SuccessEnum importResult;
int fileCounter = 1;
std::string fileName = "_testInput/PassagierInputTests/crashInput" + std::to_string(fileCounter) + ".xml";
while (FileExists(fileName)) {
SetUp();
importResult = MetroNetImporter::importMetroNet("_testInput/PassagierInputTests/MetroNetInput.xml", ofile, *metronet);
EXPECT_TRUE(importResult == Success);
ofile.open("_testOutput/passagierInputTestsError.txt");
EXPECT_DEATH(MetroNetImporter::importPassengers(fileName.c_str(), ofile, *metronet), errors[fileCounter-1]);
ofile.close();
std::string expectedFileName = "_testOutput/PassagierInputTestsExpected/crash" + std::to_string(fileCounter) + ".txt";
EXPECT_TRUE(FileCompare("_testOutput/passagierInputTestsError.txt", expectedFileName));
fileCounter++;
fileName = "_testInput/PassagierInputTests/crashInput" + std::to_string(fileCounter) + ".xml";
}
EXPECT_TRUE(fileCounter == 5);
}
TEST_F(PassagierInputTests, multipleWrongInputs) {
ASSERT_TRUE(DirectoryExists("_testInput"));
ASSERT_TRUE(DirectoryExists("_testInput/PassagierInputTests"));
ASSERT_TRUE(DirectoryExists("_testOutput"));
ASSERT_TRUE(DirectoryExists("_testOutput/PassagierInputTestsExpected"));
std::ofstream ofile;
SuccessEnum importResult;
int fileCounter = 1;
std::string fileName = "_testInput/PassagierInputTests/multipleWrongInputs" + std::to_string(fileCounter) + ".xml";
while (FileExists(fileName)) {
SetUp();
importResult = MetroNetImporter::importMetroNet("_testInput/PassagierInputTests/MetroNetInput.xml", ofile, *metronet);
EXPECT_TRUE(importResult == Success);
ofile.open("_testOutput/passagierInputTestsError.txt");
importResult = MetroNetImporter::importPassengers(fileName.c_str(), ofile, *metronet);
ofile.close();
EXPECT_TRUE(importResult == PartialImport);
std::string expectedFileName = "_testOutput/PassagierInputTestsExpected/multipleWrongInputs" + std::to_string(fileCounter) + ".txt";
EXPECT_TRUE(FileCompare("_testOutput/passagierInputTestsError.txt", expectedFileName));
fileCounter++;
fileName = "_testInput/PassagierInputTests/multipleWrongInputs" + std::to_string(fileCounter) + ".xml";
}
EXPECT_TRUE(fileCounter == 3);
}