forked from valhalla/valhalla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactor.cc
86 lines (68 loc) · 3.08 KB
/
actor.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
#include <functional>
#include <string>
#include "tyr/actor.h"
#include "test.h"
#if !defined(VALHALLA_SOURCE_DIR)
#define VALHALLA_SOURCE_DIR
#endif
using namespace valhalla;
namespace {
// fake up config against pine grove traffic extract
const auto conf = test::make_config(VALHALLA_SOURCE_DIR "test/traffic_matcher_tiles");
TEST(Actor, Basic) {
tyr::actor_t actor(conf);
actor.route(R"({"locations":[{"lat":40.546115,"lon":-76.385076,"type":"break"},
{"lat":40.544232,"lon":-76.385752,"type":"break"}],"costing":"auto"})");
actor.cleanup();
auto route_json = actor.route(R"({"locations":[{"lat":40.546115,"lon":-76.385076,"type":"break"},
{"lat":40.544232,"lon":-76.385752,"type":"break"}],"costing":"auto"})");
actor.cleanup();
auto route = test::json_to_pt(route_json);
ASSERT_NE(route_json.find("Tulpehocken"), std::string::npos);
actor.trace_attributes(R"({"shape":[{"lat":40.546115,"lon":-76.385076},
{"lat":40.544232,"lon":-76.385752}],"costing":"auto","shape_match":"map_snap"})");
actor.cleanup();
auto attributes_json = actor.trace_attributes(R"({"shape":[{"lat":40.546115,"lon":-76.385076},
{"lat":40.544232,"lon":-76.385752}],"costing":"auto","shape_match":"map_snap"})");
actor.cleanup();
auto attributes = test::json_to_pt(attributes_json);
ASSERT_NE(attributes_json.find("Tulpehocken"), std::string::npos);
actor.transit_available(R"({"locations":[{"lat":35.647452, "lon":-79.597477, "radius":20},
{"lat":34.766908, "lon":-80.325936,"radius":10}]})");
actor.cleanup();
auto transit_json =
actor.transit_available(R"({"locations":[{"lat":35.647452, "lon":-79.597477, "radius":20},
{"lat":34.766908, "lon":-80.325936,"radius":10}]})");
actor.cleanup();
auto transit = test::json_to_pt(transit_json);
ASSERT_NE(transit_json.find(std::to_string(false)), std::string::npos);
auto status_json = actor.status("");
ASSERT_NE(status_json.find("tileset_last_modified"), std::string::npos);
actor.cleanup();
status_json = actor.status(R"({"verbose":true})");
actor.cleanup();
auto status = test::json_to_pt(status_json);
ASSERT_NE(status_json.find("Polygon"), std::string::npos);
// TODO: test the rest of them
}
struct test_exception_t {};
TEST(Actor, Route) {
tyr::actor_t actor(conf);
std::string request = R"({"locations":[{"lat":40.546115,"lon":-76.385076,"type":"break"},
{"lat":40.544232,"lon":-76.385752,"type":"break"}],"costing":"auto"})";
std::function<void()> interrupt = [] { throw test_exception_t{}; };
EXPECT_THROW(actor.route(request, &interrupt), test_exception_t);
}
TEST(Actor, TraceAttributes) {
tyr::actor_t actor(conf);
std::string request = R"({"shape":[{"lat":40.546115,"lon":-76.385076},
{"lat":40.544232,"lon":-76.385752}],"costing":"auto","shape_match":"map_snap"})";
std::function<void()> interrupt = [] { throw test_exception_t{}; };
EXPECT_THROW(actor.trace_attributes(request, &interrupt), test_exception_t);
}
// TODO: test the rest of them
} // namespace
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}