forked from varoudis/depthmapX
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathteststepdepthparser.cpp
More file actions
159 lines (138 loc) · 5.38 KB
/
teststepdepthparser.cpp
File metadata and controls
159 lines (138 loc) · 5.38 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
// Copyright (C) 2017 Petros Koutsolampros
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <catch.hpp>
#include "depthmapXcli/stepdepthparser.h"
#include "argumentholder.h"
#include "selfcleaningfile.h"
TEST_CASE("StepDepthParserFail", "Error cases")
{
SECTION("Missing argument to -sdp")
{
StepDepthParser parser;
ArgumentHolder ah{"prog", "-sdp"};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("-sdp requires an argument"));
}
SECTION("Missing argument to -sdf")
{
StepDepthParser parser;
ArgumentHolder ah{"prog", "-sdf"};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("-sdf requires an argument"));
}
SECTION("Missing argument to -sdt")
{
StepDepthParser parser;
ArgumentHolder ah{"prog", "-sdt"};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("-sdt requires an argument"));
}
SECTION("rubbish input to -sdp")
{
StepDepthParser parser;
ArgumentHolder ah{"prog", "-sdp", "foo"};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("Invalid step depth point provided (foo). Should only contain digits dots and commas"));
}
SECTION("rubbish input to -sdt")
{
StepDepthParser parser;
ArgumentHolder ah{"prog", "-sdt", "foo"};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("Invalid step type: foo"));
}
SECTION("Non-existing file provided")
{
StepDepthParser parser;
ArgumentHolder ah{"prog", "-sdf", "foo.csv"};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("Failed to load file foo.csv, error"));
}
SECTION("Neiter points nor point file provided")
{
StepDepthParser parser;
ArgumentHolder ah{"prog"};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("Either -sdp or -sdf must be given"));
}
SECTION("Points and pointfile provided")
{
StepDepthParser parser;
SelfCleaningFile scf("testpoints.csv");
{
std::ofstream f("testpoints.csv");
f << "x\ty\n1\t2\n" << std::flush;
}
ArgumentHolder ah{"prog", "-sdp", "0.1,5.2", "-sdf", "testpoints.csv"};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("-sdf cannot be used together with -sdp"));
}
SECTION("Pointfile and points provided")
{
StepDepthParser parser;
SelfCleaningFile scf("testpoints.csv");
{
std::ofstream f("testpoints.csv");
f << "x\ty\n1\t2\n" << std::flush;
}
ArgumentHolder ah{"prog", "-sdf", "testpoints.csv", "-sdp", "0.1,5.2"};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("-sdp cannot be used together with -sdf"));
}
SECTION("Malformed pointfile")
{
StepDepthParser parser;
SelfCleaningFile scf("testpoints.csv");
{
std::ofstream f("testpoints.csv");
f << "x\ty\n1\n" << std::flush;
}
ArgumentHolder ah{"prog", "-sdf", "testpoints.csv"};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("Error parsing line: 1"));
}
SECTION("Malformed point arg")
{
StepDepthParser parser;
SelfCleaningFile scf("testpoints.csv");
{
std::ofstream f("testpoints.csv");
f << "x\ty\n1\n" << std::flush;
}
ArgumentHolder ah{"prog", "-sdp", "0.1"};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("Error parsing line: 0.1"));
}
}
TEST_CASE("StepDepthParserSuccess", "Read successfully")
{
StepDepthParser parser;
double x1 = 1.0;
double y1 = 2.0;
double x2 = 1.1;
double y2 = 1.2;
SECTION("Read from commandline")
{
std::stringstream p1;
p1 << x1 << "," << y1 << std::flush;
std::stringstream p2;
p2 << x2 << "," << y2 << std::flush;
ArgumentHolder ah{"prog", "-sdp", p1.str(), "-sdp", p2.str(), "-sdt", "visual"};
parser.parse(ah.argc(), ah.argv());
}
SECTION("Read from file")
{
SelfCleaningFile scf("testpoints.csv");
{
std::ofstream f(scf.Filename().c_str());
f << "x\ty\n" << x1 << "\t" << y1 << "\n"
<< x2 << "\t" << y2 << "\n" << std::flush;
}
ArgumentHolder ah{"prog", "-sdf", scf.Filename(), "-sdt", "visual"};
parser.parse(ah.argc(), ah.argv() );
}
auto points = parser.getStepDepthPoints();
REQUIRE(points.size() == 2);
REQUIRE(points[0].x == Approx(x1));
REQUIRE(points[0].y == Approx(y1));
REQUIRE(points[1].x == Approx(x2));
REQUIRE(points[1].y == Approx(y2));
}