2016-03-16 06:58:39 -04:00
|
|
|
#include <boost/test/test_case_template.hpp>
|
2016-04-06 10:47:16 -04:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2016-03-16 06:58:39 -04:00
|
|
|
|
2016-03-23 07:57:47 -04:00
|
|
|
#include "coordinates.hpp"
|
2016-04-06 10:47:16 -04:00
|
|
|
#include "equal_json.hpp"
|
|
|
|
#include "fixture.hpp"
|
2016-03-16 07:42:26 -04:00
|
|
|
|
|
|
|
#include "osrm/coordinate.hpp"
|
|
|
|
#include "osrm/engine_config.hpp"
|
2017-06-05 18:58:50 -04:00
|
|
|
#include "osrm/exception.hpp"
|
2016-03-16 07:42:26 -04:00
|
|
|
#include "osrm/json_container.hpp"
|
|
|
|
#include "osrm/osrm.hpp"
|
2016-04-06 10:47:16 -04:00
|
|
|
#include "osrm/route_parameters.hpp"
|
|
|
|
#include "osrm/status.hpp"
|
2016-03-16 07:42:26 -04:00
|
|
|
|
2016-03-16 06:58:39 -04:00
|
|
|
BOOST_AUTO_TEST_SUITE(route)
|
|
|
|
|
2016-03-24 16:02:55 -04:00
|
|
|
BOOST_AUTO_TEST_CASE(test_route_same_coordinates_fixture)
|
|
|
|
{
|
2017-03-21 06:27:15 -04:00
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
2016-03-24 16:02:55 -04:00
|
|
|
|
|
|
|
using namespace osrm;
|
|
|
|
|
|
|
|
RouteParameters params;
|
2016-04-05 03:56:38 -04:00
|
|
|
params.steps = true;
|
2016-03-24 16:02:55 -04:00
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
|
|
|
|
json::Object result;
|
|
|
|
const auto rc = osrm.Route(params, result);
|
|
|
|
BOOST_CHECK(rc == Status::Ok);
|
|
|
|
|
2017-03-21 06:27:15 -04:00
|
|
|
// unset snapping dependent hint
|
|
|
|
for (auto &itr : result.values["waypoints"].get<json::Array>().values)
|
|
|
|
itr.get<json::Object>().values["hint"] = "";
|
|
|
|
|
|
|
|
const auto location = json::Array{{{7.437070}, {43.749248}}};
|
2016-04-06 10:47:16 -04:00
|
|
|
|
2016-03-24 16:02:55 -04:00
|
|
|
json::Object reference{
|
2016-04-04 08:45:13 -04:00
|
|
|
{{"code", "Ok"},
|
2016-03-24 16:02:55 -04:00
|
|
|
{"waypoints",
|
2017-03-21 06:27:15 -04:00
|
|
|
json::Array{
|
|
|
|
{json::Object{
|
|
|
|
{{"name", "Boulevard du Larvotto"}, {"location", location}, {"hint", ""}}},
|
|
|
|
json::Object{
|
|
|
|
{{"name", "Boulevard du Larvotto"}, {"location", location}, {"hint", ""}}}}}},
|
2016-04-06 10:47:16 -04:00
|
|
|
{"routes",
|
|
|
|
json::Array{{json::Object{
|
|
|
|
{{"distance", 0.},
|
|
|
|
{"duration", 0.},
|
2017-01-26 11:28:27 -05:00
|
|
|
{"weight", 0.},
|
2017-02-09 04:54:39 -05:00
|
|
|
{"weight_name", "routability"},
|
2017-03-21 06:27:15 -04:00
|
|
|
{"geometry", "yw_jGupkl@??"},
|
2016-04-06 10:47:16 -04:00
|
|
|
{"legs",
|
|
|
|
json::Array{{json::Object{
|
|
|
|
{{"distance", 0.},
|
|
|
|
{"duration", 0.},
|
2017-01-26 11:28:27 -05:00
|
|
|
{"weight", 0.},
|
2017-03-21 06:27:15 -04:00
|
|
|
{"summary", "Boulevard du Larvotto"},
|
2016-05-12 05:16:52 -04:00
|
|
|
{"steps",
|
|
|
|
json::Array{{{json::Object{{{"duration", 0.},
|
|
|
|
{"distance", 0.},
|
2016-05-12 12:50:10 -04:00
|
|
|
{"weight", 0.},
|
2017-03-21 06:27:15 -04:00
|
|
|
{"geometry", "yw_jGupkl@??"},
|
|
|
|
{"name", "Boulevard du Larvotto"},
|
2016-05-12 05:16:52 -04:00
|
|
|
{"mode", "driving"},
|
2017-10-31 23:51:11 -04:00
|
|
|
{"driving_side", "right"},
|
2016-05-27 15:05:04 -04:00
|
|
|
{"maneuver",
|
|
|
|
json::Object{{
|
|
|
|
{"location", location},
|
|
|
|
{"bearing_before", 0},
|
2018-01-09 04:27:19 -05:00
|
|
|
{"bearing_after", 238},
|
2016-05-27 15:05:04 -04:00
|
|
|
{"type", "depart"},
|
|
|
|
}}},
|
2016-05-12 05:16:52 -04:00
|
|
|
{"intersections",
|
|
|
|
json::Array{{json::Object{
|
|
|
|
{{"location", location},
|
2018-01-09 04:27:19 -05:00
|
|
|
{"bearings", json::Array{{238}}},
|
2016-05-18 18:19:35 -04:00
|
|
|
{"entry", json::Array{{json::True()}}},
|
2016-05-12 05:16:52 -04:00
|
|
|
{"out", 0}}}}}}}}},
|
|
|
|
|
|
|
|
json::Object{{{"duration", 0.},
|
|
|
|
{"distance", 0.},
|
2016-05-12 12:50:10 -04:00
|
|
|
{"weight", 0.},
|
2017-03-21 06:27:15 -04:00
|
|
|
{"geometry", "yw_jGupkl@"},
|
|
|
|
{"name", "Boulevard du Larvotto"},
|
2016-05-12 05:16:52 -04:00
|
|
|
{"mode", "driving"},
|
2017-10-31 23:51:11 -04:00
|
|
|
{"driving_side", "right"},
|
2016-05-27 15:05:04 -04:00
|
|
|
{"maneuver",
|
|
|
|
json::Object{{{"location", location},
|
2018-01-09 04:27:19 -05:00
|
|
|
{"bearing_before", 238},
|
2016-05-27 15:05:04 -04:00
|
|
|
{"bearing_after", 0},
|
|
|
|
{"type", "arrive"}}}},
|
2016-05-12 05:16:52 -04:00
|
|
|
{"intersections",
|
|
|
|
json::Array{{json::Object{
|
|
|
|
{{"location", location},
|
2018-01-09 04:27:19 -05:00
|
|
|
{"bearings", json::Array{{58}}},
|
2016-05-18 18:19:35 -04:00
|
|
|
{"entry", json::Array{{json::True()}}},
|
|
|
|
{"in", 0}}}}}}
|
2016-05-12 05:16:52 -04:00
|
|
|
|
|
|
|
}}}}}}}}}}}}}}}}};
|
2016-03-24 16:02:55 -04:00
|
|
|
|
|
|
|
CHECK_EQUAL_JSON(reference, result);
|
|
|
|
}
|
|
|
|
|
2016-03-18 08:48:17 -04:00
|
|
|
BOOST_AUTO_TEST_CASE(test_route_same_coordinates)
|
2016-03-16 07:42:26 -04:00
|
|
|
{
|
2017-03-21 06:27:15 -04:00
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
2016-03-16 07:42:26 -04:00
|
|
|
|
|
|
|
using namespace osrm;
|
|
|
|
|
|
|
|
RouteParameters params;
|
2016-04-05 03:56:38 -04:00
|
|
|
params.steps = true;
|
2016-03-23 07:57:47 -04:00
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
2016-03-16 07:42:26 -04:00
|
|
|
|
|
|
|
json::Object result;
|
|
|
|
const auto rc = osrm.Route(params, result);
|
2016-03-18 08:48:17 -04:00
|
|
|
BOOST_CHECK(rc == Status::Ok);
|
|
|
|
|
|
|
|
const auto code = result.values.at("code").get<json::String>().value;
|
2016-04-04 08:45:13 -04:00
|
|
|
BOOST_CHECK_EQUAL(code, "Ok");
|
2016-03-18 08:48:17 -04:00
|
|
|
|
|
|
|
const auto &waypoints = result.values.at("waypoints").get<json::Array>().values;
|
2016-03-23 10:55:25 -04:00
|
|
|
BOOST_CHECK(waypoints.size() == params.coordinates.size());
|
2016-03-18 08:48:17 -04:00
|
|
|
|
|
|
|
for (const auto &waypoint : waypoints)
|
|
|
|
{
|
|
|
|
const auto &waypoint_object = waypoint.get<json::Object>();
|
|
|
|
|
|
|
|
// nothing can be said about name, empty or contains name of the street
|
|
|
|
const auto name = waypoint_object.values.at("name").get<json::String>().value;
|
|
|
|
BOOST_CHECK(((void)name, true));
|
|
|
|
|
|
|
|
const auto location = waypoint_object.values.at("location").get<json::Array>().values;
|
|
|
|
const auto longitude = location[0].get<json::Number>().value;
|
|
|
|
const auto latitude = location[1].get<json::Number>().value;
|
2016-03-23 07:57:47 -04:00
|
|
|
BOOST_CHECK(longitude >= -180. && longitude <= 180.);
|
2016-03-18 08:48:17 -04:00
|
|
|
BOOST_CHECK(latitude >= -90. && latitude <= 90.);
|
|
|
|
|
|
|
|
const auto hint = waypoint_object.values.at("hint").get<json::String>().value;
|
|
|
|
BOOST_CHECK(!hint.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto &routes = result.values.at("routes").get<json::Array>().values;
|
2016-04-05 04:38:21 -04:00
|
|
|
BOOST_REQUIRE_GT(routes.size(), 0);
|
2016-03-18 08:48:17 -04:00
|
|
|
|
|
|
|
for (const auto &route : routes)
|
|
|
|
{
|
|
|
|
const auto &route_object = route.get<json::Object>();
|
|
|
|
|
|
|
|
const auto distance = route_object.values.at("distance").get<json::Number>().value;
|
2016-03-23 09:15:17 -04:00
|
|
|
BOOST_CHECK_EQUAL(distance, 0);
|
2016-03-18 08:48:17 -04:00
|
|
|
|
|
|
|
const auto duration = route_object.values.at("duration").get<json::Number>().value;
|
2016-03-23 09:15:17 -04:00
|
|
|
BOOST_CHECK_EQUAL(duration, 0);
|
2016-03-18 08:48:17 -04:00
|
|
|
|
|
|
|
// geometries=polyline by default
|
|
|
|
const auto geometry = route_object.values.at("geometry").get<json::String>().value;
|
|
|
|
BOOST_CHECK(!geometry.empty());
|
|
|
|
|
|
|
|
const auto &legs = route_object.values.at("legs").get<json::Array>().values;
|
|
|
|
BOOST_CHECK(!legs.empty());
|
|
|
|
|
|
|
|
for (const auto &leg : legs)
|
|
|
|
{
|
|
|
|
const auto &leg_object = leg.get<json::Object>();
|
|
|
|
|
|
|
|
const auto distance = leg_object.values.at("distance").get<json::Number>().value;
|
2016-03-23 09:15:17 -04:00
|
|
|
BOOST_CHECK_EQUAL(distance, 0);
|
2016-03-18 08:48:17 -04:00
|
|
|
|
|
|
|
const auto duration = leg_object.values.at("duration").get<json::Number>().value;
|
2016-03-23 09:15:17 -04:00
|
|
|
BOOST_CHECK_EQUAL(duration, 0);
|
2016-03-18 08:48:17 -04:00
|
|
|
|
2016-04-19 15:10:54 -04:00
|
|
|
// nothing can be said about summary, empty or contains human readable summary
|
|
|
|
const auto summary = leg_object.values.at("summary").get<json::String>().value;
|
|
|
|
BOOST_CHECK(((void)summary, true));
|
|
|
|
|
2016-03-18 08:48:17 -04:00
|
|
|
const auto &steps = leg_object.values.at("steps").get<json::Array>().values;
|
|
|
|
BOOST_CHECK(!steps.empty());
|
|
|
|
|
2016-05-12 05:16:52 -04:00
|
|
|
std::size_t step_count = 0;
|
|
|
|
|
2016-03-18 08:48:17 -04:00
|
|
|
for (const auto &step : steps)
|
|
|
|
{
|
|
|
|
const auto &step_object = step.get<json::Object>();
|
|
|
|
|
|
|
|
const auto distance = step_object.values.at("distance").get<json::Number>().value;
|
2016-03-23 09:15:17 -04:00
|
|
|
BOOST_CHECK_EQUAL(distance, 0);
|
2016-03-18 08:48:17 -04:00
|
|
|
|
|
|
|
const auto duration = step_object.values.at("duration").get<json::Number>().value;
|
2016-03-23 09:15:17 -04:00
|
|
|
BOOST_CHECK_EQUAL(duration, 0);
|
2016-03-18 08:48:17 -04:00
|
|
|
|
|
|
|
// geometries=polyline by default
|
|
|
|
const auto geometry = step_object.values.at("geometry").get<json::String>().value;
|
|
|
|
BOOST_CHECK(!geometry.empty());
|
|
|
|
|
|
|
|
// nothing can be said about name, empty or contains way name
|
|
|
|
const auto name = step_object.values.at("name").get<json::String>().value;
|
|
|
|
BOOST_CHECK(((void)name, true));
|
|
|
|
|
|
|
|
// nothing can be said about mode, contains mode of transportation
|
|
|
|
const auto mode = step_object.values.at("mode").get<json::String>().value;
|
|
|
|
BOOST_CHECK(!name.empty());
|
|
|
|
|
|
|
|
const auto &maneuver = step_object.values.at("maneuver").get<json::Object>().values;
|
|
|
|
|
|
|
|
const auto type = maneuver.at("type").get<json::String>().value;
|
|
|
|
BOOST_CHECK(!type.empty());
|
|
|
|
|
2016-05-12 05:16:52 -04:00
|
|
|
const auto &intersections =
|
|
|
|
step_object.values.at("intersections").get<json::Array>().values;
|
|
|
|
|
|
|
|
for (auto &intersection : intersections)
|
|
|
|
{
|
|
|
|
const auto &intersection_object = intersection.get<json::Object>().values;
|
2016-05-27 15:05:04 -04:00
|
|
|
const auto location =
|
|
|
|
intersection_object.at("location").get<json::Array>().values;
|
2016-05-12 05:16:52 -04:00
|
|
|
const auto longitude = location[0].get<json::Number>().value;
|
|
|
|
const auto latitude = location[1].get<json::Number>().value;
|
|
|
|
BOOST_CHECK(longitude >= -180. && longitude <= 180.);
|
|
|
|
BOOST_CHECK(latitude >= -90. && latitude <= 90.);
|
|
|
|
|
2016-05-27 15:05:04 -04:00
|
|
|
const auto &bearings =
|
|
|
|
intersection_object.at("bearings").get<json::Array>().values;
|
2016-05-12 05:16:52 -04:00
|
|
|
BOOST_CHECK(!bearings.empty());
|
|
|
|
const auto &entries = intersection_object.at("entry").get<json::Array>().values;
|
|
|
|
BOOST_CHECK(bearings.size() == entries.size());
|
|
|
|
|
2016-05-27 15:05:04 -04:00
|
|
|
for (const auto bearing : bearings)
|
|
|
|
BOOST_CHECK(0. <= bearing.get<json::Number>().value &&
|
|
|
|
bearing.get<json::Number>().value <= 360.);
|
2016-05-12 05:16:52 -04:00
|
|
|
|
2016-05-27 15:05:04 -04:00
|
|
|
if (step_count > 0)
|
2016-05-12 05:16:52 -04:00
|
|
|
{
|
|
|
|
const auto in = intersection_object.at("in").get<json::Number>().value;
|
|
|
|
BOOST_CHECK(in < bearings.size());
|
|
|
|
}
|
2016-05-27 15:05:04 -04:00
|
|
|
if (step_count + 1 < steps.size())
|
2016-05-12 05:16:52 -04:00
|
|
|
{
|
|
|
|
const auto out = intersection_object.at("out").get<json::Number>().value;
|
|
|
|
BOOST_CHECK(out < bearings.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-18 08:48:17 -04:00
|
|
|
// modifier is optional
|
|
|
|
// TODO(daniel-j-h):
|
2016-03-16 07:42:26 -04:00
|
|
|
|
2016-03-18 08:48:17 -04:00
|
|
|
// exit is optional
|
|
|
|
// TODO(daniel-j-h):
|
2016-05-12 05:16:52 -04:00
|
|
|
++step_count;
|
2016-03-18 08:48:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-16 07:42:26 -04:00
|
|
|
}
|
2016-03-16 06:58:39 -04:00
|
|
|
|
2016-03-23 10:55:25 -04:00
|
|
|
BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_small_component)
|
|
|
|
{
|
2017-03-21 06:27:15 -04:00
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
2016-03-23 10:55:25 -04:00
|
|
|
|
|
|
|
using namespace osrm;
|
|
|
|
|
|
|
|
const auto locations = get_locations_in_small_component();
|
|
|
|
|
|
|
|
RouteParameters params;
|
|
|
|
params.coordinates.push_back(locations.at(0));
|
|
|
|
params.coordinates.push_back(locations.at(1));
|
|
|
|
params.coordinates.push_back(locations.at(2));
|
|
|
|
|
|
|
|
json::Object result;
|
|
|
|
const auto rc = osrm.Route(params, result);
|
|
|
|
BOOST_CHECK(rc == Status::Ok);
|
|
|
|
|
|
|
|
const auto code = result.values.at("code").get<json::String>().value;
|
2016-04-04 08:45:13 -04:00
|
|
|
BOOST_CHECK_EQUAL(code, "Ok");
|
2016-03-23 10:55:25 -04:00
|
|
|
|
|
|
|
const auto &waypoints = result.values.at("waypoints").get<json::Array>().values;
|
|
|
|
BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size());
|
|
|
|
|
|
|
|
for (const auto &waypoint : waypoints)
|
|
|
|
{
|
|
|
|
const auto &waypoint_object = waypoint.get<json::Object>();
|
|
|
|
|
|
|
|
const auto location = waypoint_object.values.at("location").get<json::Array>().values;
|
|
|
|
const auto longitude = location[0].get<json::Number>().value;
|
|
|
|
const auto latitude = location[1].get<json::Number>().value;
|
|
|
|
BOOST_CHECK(longitude >= -180. && longitude <= 180.);
|
|
|
|
BOOST_CHECK(latitude >= -90. && latitude <= 90.);
|
2016-04-11 06:31:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_big_component)
|
|
|
|
{
|
2017-03-21 06:27:15 -04:00
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
2016-04-11 06:31:06 -04:00
|
|
|
|
|
|
|
using namespace osrm;
|
|
|
|
|
|
|
|
const auto locations = get_locations_in_big_component();
|
|
|
|
|
|
|
|
RouteParameters params;
|
|
|
|
params.coordinates.push_back(locations.at(0));
|
|
|
|
params.coordinates.push_back(locations.at(1));
|
|
|
|
params.coordinates.push_back(locations.at(2));
|
|
|
|
|
|
|
|
json::Object result;
|
|
|
|
const auto rc = osrm.Route(params, result);
|
|
|
|
BOOST_CHECK(rc == Status::Ok);
|
|
|
|
|
|
|
|
const auto code = result.values.at("code").get<json::String>().value;
|
|
|
|
BOOST_CHECK_EQUAL(code, "Ok");
|
|
|
|
|
|
|
|
const auto &waypoints = result.values.at("waypoints").get<json::Array>().values;
|
|
|
|
BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size());
|
|
|
|
|
|
|
|
for (const auto &waypoint : waypoints)
|
|
|
|
{
|
|
|
|
const auto &waypoint_object = waypoint.get<json::Object>();
|
|
|
|
|
|
|
|
const auto location = waypoint_object.values.at("location").get<json::Array>().values;
|
|
|
|
const auto longitude = location[0].get<json::Number>().value;
|
|
|
|
const auto latitude = location[1].get<json::Number>().value;
|
|
|
|
BOOST_CHECK(longitude >= -180. && longitude <= 180.);
|
|
|
|
BOOST_CHECK(latitude >= -90. && latitude <= 90.);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_route_response_for_locations_across_components)
|
|
|
|
{
|
2017-03-21 06:27:15 -04:00
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
2016-04-11 06:31:06 -04:00
|
|
|
|
|
|
|
using namespace osrm;
|
|
|
|
|
|
|
|
const auto big_component = get_locations_in_big_component();
|
|
|
|
const auto small_component = get_locations_in_small_component();
|
|
|
|
|
|
|
|
RouteParameters params;
|
|
|
|
params.coordinates.push_back(small_component.at(0));
|
|
|
|
params.coordinates.push_back(big_component.at(0));
|
|
|
|
params.coordinates.push_back(small_component.at(1));
|
|
|
|
params.coordinates.push_back(big_component.at(1));
|
|
|
|
|
|
|
|
json::Object result;
|
|
|
|
const auto rc = osrm.Route(params, result);
|
|
|
|
BOOST_CHECK(rc == Status::Ok);
|
|
|
|
|
|
|
|
const auto code = result.values.at("code").get<json::String>().value;
|
|
|
|
BOOST_CHECK_EQUAL(code, "Ok");
|
|
|
|
|
|
|
|
const auto &waypoints = result.values.at("waypoints").get<json::Array>().values;
|
|
|
|
BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size());
|
|
|
|
|
|
|
|
for (const auto &waypoint : waypoints)
|
|
|
|
{
|
|
|
|
const auto &waypoint_object = waypoint.get<json::Object>();
|
2016-03-23 10:55:25 -04:00
|
|
|
|
2016-04-11 06:31:06 -04:00
|
|
|
const auto location = waypoint_object.values.at("location").get<json::Array>().values;
|
|
|
|
const auto longitude = location[0].get<json::Number>().value;
|
|
|
|
const auto latitude = location[1].get<json::Number>().value;
|
|
|
|
BOOST_CHECK(longitude >= -180. && longitude <= 180.);
|
|
|
|
BOOST_CHECK(latitude >= -90. && latitude <= 90.);
|
2016-03-23 10:55:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-15 09:28:54 -05:00
|
|
|
BOOST_AUTO_TEST_CASE(test_route_user_disables_generating_hints)
|
|
|
|
{
|
2017-03-21 06:27:15 -04:00
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
2016-12-15 09:28:54 -05:00
|
|
|
|
|
|
|
using namespace osrm;
|
|
|
|
|
|
|
|
RouteParameters params;
|
|
|
|
params.steps = true;
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
params.generate_hints = false;
|
|
|
|
|
|
|
|
json::Object result;
|
|
|
|
const auto rc = osrm.Route(params, result);
|
|
|
|
BOOST_CHECK(rc == Status::Ok);
|
|
|
|
|
|
|
|
for (auto waypoint : result.values["waypoints"].get<json::Array>().values)
|
|
|
|
BOOST_CHECK_EQUAL(waypoint.get<json::Object>().values.count("hint"), 0);
|
|
|
|
}
|
|
|
|
|
2017-02-10 10:52:36 -05:00
|
|
|
BOOST_AUTO_TEST_CASE(speed_annotation_matches_duration_and_distance)
|
|
|
|
{
|
2017-03-21 06:27:15 -04:00
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
2017-02-10 10:52:36 -05:00
|
|
|
|
|
|
|
using namespace osrm;
|
|
|
|
|
2017-02-13 06:53:05 -05:00
|
|
|
RouteParameters params;
|
2017-02-10 10:52:36 -05:00
|
|
|
params.annotations_type = RouteParameters::AnnotationsType::Duration |
|
|
|
|
RouteParameters::AnnotationsType::Distance |
|
|
|
|
RouteParameters::AnnotationsType::Speed;
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
|
|
|
|
json::Object result;
|
|
|
|
const auto rc = osrm.Route(params, result);
|
|
|
|
BOOST_CHECK(rc == Status::Ok);
|
|
|
|
|
|
|
|
const auto &routes = result.values["routes"].get<json::Array>().values;
|
|
|
|
const auto &legs = routes[0].get<json::Object>().values.at("legs").get<json::Array>().values;
|
|
|
|
const auto &annotation =
|
|
|
|
legs[0].get<json::Object>().values.at("annotation").get<json::Object>();
|
|
|
|
const auto &speeds = annotation.values.at("speed").get<json::Array>().values;
|
|
|
|
const auto &durations = annotation.values.at("duration").get<json::Array>().values;
|
|
|
|
const auto &distances = annotation.values.at("distance").get<json::Array>().values;
|
|
|
|
int length = speeds.size();
|
2018-03-13 14:31:29 -04:00
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(length, 1);
|
2017-02-10 10:52:36 -05:00
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
auto speed = speeds[i].get<json::Number>().value;
|
|
|
|
auto duration = durations[i].get<json::Number>().value;
|
|
|
|
auto distance = distances[i].get<json::Number>().value;
|
2018-03-13 14:31:29 -04:00
|
|
|
auto calc = std::round(distance / duration * 10.) / 10.;
|
|
|
|
BOOST_CHECK_EQUAL(speed, std::isnan(calc) ? 0 : calc);
|
|
|
|
|
|
|
|
// Because we route from/to the same location, all annotations should be 0;
|
|
|
|
BOOST_CHECK_EQUAL(speed, 0);
|
|
|
|
BOOST_CHECK_EQUAL(distance, 0);
|
|
|
|
BOOST_CHECK_EQUAL(duration, 0);
|
2017-02-10 10:52:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 06:53:05 -05:00
|
|
|
BOOST_AUTO_TEST_CASE(test_manual_setting_of_annotations_property)
|
|
|
|
{
|
2017-03-21 06:27:15 -04:00
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
2017-02-13 06:53:05 -05:00
|
|
|
|
|
|
|
using namespace osrm;
|
|
|
|
|
|
|
|
RouteParameters params{};
|
|
|
|
params.annotations = true;
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
|
|
|
|
json::Object result;
|
|
|
|
const auto rc = osrm.Route(params, result);
|
|
|
|
BOOST_CHECK(rc == Status::Ok);
|
|
|
|
|
|
|
|
const auto code = result.values.at("code").get<json::String>().value;
|
|
|
|
BOOST_CHECK_EQUAL(code, "Ok");
|
|
|
|
|
|
|
|
auto annotations = result.values["routes"]
|
|
|
|
.get<json::Array>()
|
|
|
|
.values[0]
|
|
|
|
.get<json::Object>()
|
|
|
|
.values["legs"]
|
|
|
|
.get<json::Array>()
|
|
|
|
.values[0]
|
|
|
|
.get<json::Object>()
|
|
|
|
.values["annotation"]
|
|
|
|
.get<json::Object>()
|
|
|
|
.values;
|
2018-04-03 18:13:25 -04:00
|
|
|
BOOST_CHECK_EQUAL(annotations.size(), 6);
|
2017-02-13 06:53:05 -05:00
|
|
|
}
|
|
|
|
|
2016-03-16 06:58:39 -04:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|