forked from valhalla/valhalla
/
test_ignore_restrictions.cc
180 lines (155 loc) · 7.07 KB
/
test_ignore_restrictions.cc
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
176
177
178
179
180
#include "gurka.h"
#include "test.h"
#include <gtest/gtest.h>
using namespace valhalla;
std::string get_access_mode(const std::string& costing_mode) {
if (costing_mode == "auto") {
return "motorcar";
} else if (costing_mode == "truck") {
return "hgv";
} else if (costing_mode == "motorcycle") {
return "motorcycle";
} else if (costing_mode == "taxi") {
return "taxi";
} else if (costing_mode == "bus") {
return "bus";
} else if (costing_mode == "motor_scooter") {
return "moped";
} else if (costing_mode == "bicycle") {
return "bicycle";
}
throw std::runtime_error("unexpected costing mode " + costing_mode + ".");
}
class CommonRestrictionTest : public ::testing::TestWithParam<std::string> {
protected:
static gurka::nodelayout layout;
static void SetUpTestSuite() {
constexpr double gridsize = 500;
const std::string map = R"(
A----------B-----C----D
|
E
|
|
F
)";
layout = gurka::detail::map_to_coordinates(map, gridsize);
}
};
gurka::nodelayout CommonRestrictionTest::layout = {};
TEST_P(CommonRestrictionTest, IgnoreCommonRestrictions) {
const std::string& costing = GetParam();
const gurka::ways ways = {
{"AB", {{"highway", "secondary"}}},
{"BC", {{"highway", "secondary"}}},
{"CD", {{"highway", "secondary"}}},
{"AE", {{"highway", "secondary"}}},
{"EF",
{{"highway", "secondary"}, {get_access_mode(costing) + ":conditional", "no @ (09:00-18:00)"}}},
};
const gurka::relations relations = {{{
{gurka::way_member, "AB", "from"},
{gurka::way_member, "BC", "to"},
{gurka::node_member, "B", "via"},
},
{{"type", "restriction"}, {"restriction", "no_straight_on"}}}};
gurka::map map =
gurka::buildtiles(layout, ways, {}, relations, "test/data/ignore_non_vehicular_restrictions",
{{"mjolnir.timezone", {VALHALLA_BUILD_DIR "test/data/tz.sqlite"}}});
// first, route through turn restriction, should fail...
try {
valhalla::Api route = gurka::do_action(valhalla::Options::route, map, {"A", "D"}, costing, {});
FAIL() << "Expected valhalla_exception_t.";
} catch (const valhalla_exception_t& err) { EXPECT_EQ(err.code, 442); } catch (...) {
FAIL() << "Expected valhalla_exception_t.";
}
// ...but succeed with ignore_non_vehicular_restrictions
valhalla::Api route =
gurka::do_action(valhalla::Options::route, map, {"A", "D"}, costing,
{{"/costing_options/" + costing + "/ignore_non_vehicular_restrictions", "1"}});
gurka::assert::raw::expect_path(route, {"AB", "BC", "CD"});
// second, route through time based access restrictions, should fail...
try {
valhalla::Api route =
gurka::do_action(valhalla::Options::route, map, {"A", "F"}, costing,
{{"/date_time/type", "1"}, {"/date_time/value", "2020-10-10T13:00"}});
FAIL() << "Expected route to fail.";
} catch (const valhalla_exception_t& err) { EXPECT_EQ(err.code, 442); } catch (...) {
FAIL() << "Expected different error code.";
}
//...but succeed with ignore_non_vehicular_restrictions
valhalla::Api route_succeed =
gurka::do_action(valhalla::Options::route, map, {"A", "F"}, costing,
{{"/costing_options/" + costing + "/ignore_non_vehicular_restrictions", "1"},
{"/date_time/type", "1"},
{"/date_time/value", "2020-10-10T13:00"}});
gurka::assert::raw::expect_path(route_succeed, {"AE", "EF"});
}
// check that dimensional restrictions are not affected
TEST_P(CommonRestrictionTest, IgnoreCommonRestrictionsFail) {
const std::string& costing = GetParam();
if (costing == "motorcycle" || costing == "bicycle" || costing == "motor_scooter")
return; // no height restrictions for these
const gurka::ways ways = {
{"AB", {{"highway", "secondary"}}}, {"BC", {{"highway", "secondary"}, {"maxheight", "2.5"}}},
{"CD", {{"highway", "secondary"}}}, {"AE", {{"highway", "secondary"}}},
{"EF", {{"highway", "secondary"}}},
};
gurka::map map =
gurka::buildtiles(layout, ways, {}, {}, "test/data/ignore_non_vehicular_restrictions",
{{"mjolnir.timezone", {VALHALLA_BUILD_DIR "test/data/tz.sqlite"}}});
// should fail, too low
try {
valhalla::Api route = gurka::do_action(valhalla::Options::route, map, {"A", "D"}, costing,
{{"/costing_options/" + costing + "/height", "3"}});
FAIL() << "Expected valhalla_exception_t.";
} catch (const valhalla_exception_t& err) { EXPECT_EQ(err.code, 442); } catch (...) {
FAIL() << "Expected valhalla_exception_t.";
}
// still too low
try {
valhalla::Api route =
gurka::do_action(valhalla::Options::route, map, {"A", "D"}, costing,
{{"/costing_options/" + costing + "/ignore_non_vehicular_restrictions", "1"},
{"/costing_options/" + costing + "/height", "3"}});
FAIL() << "Expected valhalla_exception_t.";
} catch (const valhalla_exception_t& err) { EXPECT_EQ(err.code, 442); } catch (...) {
FAIL() << "Expected valhalla_exception_t.";
}
}
INSTANTIATE_TEST_SUITE_P(
CommonRestrictionsTest,
CommonRestrictionTest,
::testing::Values("auto", "truck", "motorcycle", "taxi", "bus", "bicycle", "motor_scooter"));
// make sure truck weight restrictions are not affected by the request parameter
TEST(CommonRestrictionsFail, Truck) {
constexpr double gridsize = 500;
const std::string ascii_map = R"(
A----------B-----C----D
)";
const auto layout = gurka::detail::map_to_coordinates(ascii_map, gridsize);
const gurka::ways ways = {{"AB", {{"highway", "residential"}}},
{"BC", {{"highway", "residential"}, {"maxheight", "2.5"}}},
{"CD", {{"highway", "residential"}}}};
gurka::map map =
gurka::buildtiles(layout, ways, {}, {}, "test/data/ignore_non_vehicular_restrictions_truck",
{{"mjolnir.timezone", {VALHALLA_BUILD_DIR "test/data/tz.sqlite"}}});
// too long
try {
valhalla::Api route = gurka::do_action(valhalla::Options::route, map, {"A", "D"}, "truck",
{{"/costing_options/truck/height", "3"}});
FAIL() << "Expected valhalla_exception_t.";
} catch (const valhalla_exception_t& err) { EXPECT_EQ(err.code, 442); } catch (...) {
FAIL() << "Expected to fail with a different error code.";
}
// ...still too long
try {
valhalla::Api route =
gurka::do_action(valhalla::Options::route, map, {"A", "D"}, "truck",
{{"/costing_options/truck/ignore_non_vehicular_restrictions", "1"},
{"/costing_options/truck/height", "3"}});
FAIL() << "Expected no route to be found.";
} catch (const valhalla_exception_t& err) { EXPECT_EQ(err.code, 442); } catch (...) {
FAIL() << "Expected to fail with a different error code.";
}
}