This commit is contained in:
Siarhei Fedartsou 2024-05-25 16:54:51 +02:00
parent 4f46705026
commit ad990aafe7
12 changed files with 704 additions and 704 deletions

View File

@ -60,7 +60,7 @@ int main(int argc, const char *argv[])
auto &json_result = std::get<json::Object>(result);
if (status == Status::Ok)
{
auto &routes = json_result.values["routes"].get<json::Array>();
auto &routes = std::get<json::Array>(json_result.values["routes"]);
// Let's just use the first route
auto &route = routes.values.at(0).get<json::Object>();

View File

@ -65,7 +65,7 @@ template <> Napi::Value inline render(const Napi::Env &env, const ObjectOrString
{
// Convert osrm::json object tree into matching v8 object tree
Napi::Value value;
renderToV8(env, value, result.get<osrm::json::Object>());
renderToV8(env, value, std::get<osrm::json::Object>(result));
return value;
}
else

View File

@ -51,8 +51,7 @@ class GeojsonLogger
if (!first)
ofs << ",\n\t\t";
(void)object;
// util::json::render(ofs, std::get<util::json::Object>(object));
util::json::render(ofs, std::get<util::json::Object>(object));
first = false;
}

View File

@ -98,8 +98,8 @@ struct Null
*/
using Value = std::variant<String,
Number,
boost::recursive_wrapper<Object>,
boost::recursive_wrapper<Array>,
Object,
Array,
True,
False,
Null>;

View File

@ -59,35 +59,35 @@ template <typename Out> struct Renderer
write(buffer.data(), buffer.size());
}
void operator()(const boost::recursive_wrapper<Object> &)
void operator()(const Object &object)
{
// write('{');
// for (auto it = object.values.begin(), end = object.values.end(); it != end;)
// {
// write('\"');
// write(it->first);
// write<>("\":");
// std::visit(Renderer(out), it->second);
// if (++it != end)
// {
// write(',');
// }
// }
// write('}');
write('{');
for (auto it = object.values.begin(), end = object.values.end(); it != end;)
{
write('\"');
write(it->first);
write<>("\":");
std::visit(Renderer(out), it->second);
if (++it != end)
{
write(',');
}
}
write('}');
}
void operator()(const boost::recursive_wrapper<Array> &)
void operator()(const Array &array)
{
// write('[');
// for (auto it = array.values.cbegin(), end = array.values.cend(); it != end;)
// {
// std::visit(Renderer(out), *it);
// if (++it != end)
// {
// write(',');
// }
// }
// write(']');
write('[');
for (auto it = array.values.cbegin(), end = array.values.cend(); it != end;)
{
std::visit(Renderer(out), *it);
if (++it != end)
{
write(',');
}
}
write(']');
}
void operator()(const True &) { write<>("true"); }

View File

@ -20,19 +20,19 @@ BOOST_AUTO_TEST_CASE(test_json_linestring)
auto geom = engine::api::json::makeGeoJSONGeometry(begin(locations), end(locations));
const auto type = geom.values["type"].get<util::json::String>().value;
const auto type = std::get<util::json::String>(geom.values["type"]).value;
BOOST_CHECK_EQUAL(type, "LineString");
const auto coords = geom.values["coordinates"].get<util::json::Array>().values;
const auto coords = std::get<util::json::Array>(geom.values["coordinates"]).values;
BOOST_CHECK_EQUAL(coords.size(), 3); // array of three location arrays
for (const auto &each : coords)
{
const auto loc = each.get<util::json::Array>().values;
const auto loc = std::get<util::json::Array>(each).values;
BOOST_CHECK_EQUAL(loc.size(), 2);
const auto lon = loc[0].get<util::json::Number>().value;
const auto lat = loc[1].get<util::json::Number>().value;
const auto lon = std::get<util::json::Number>(loc[0]).value;
const auto lat = std::get<util::json::Number>(loc[1]).value;
(void)lon;
(void)lat;
@ -46,19 +46,19 @@ BOOST_AUTO_TEST_CASE(test_json_single_point)
auto geom = engine::api::json::makeGeoJSONGeometry(begin(locations), end(locations));
const auto type = geom.values["type"].get<util::json::String>().value;
const auto type = std::get<util::json::String>(geom.values["type"]).value;
BOOST_CHECK_EQUAL(type, "LineString");
const auto coords = geom.values["coordinates"].get<util::json::Array>().values;
const auto coords = std::get<util::json::Array>(geom.values["coordinates"]).values;
BOOST_CHECK_EQUAL(coords.size(), 2); // array of two location arrays
for (const auto &each : coords)
{
const auto loc = each.get<util::json::Array>().values;
const auto loc = std::get<util::json::Array>(each).values;
BOOST_CHECK_EQUAL(loc.size(), 2);
const auto lon = loc[0].get<util::json::Number>().value;
const auto lat = loc[1].get<util::json::Number>().value;
const auto lon = std::get<util::json::Number>(loc[0]).value;
const auto lat = std::get<util::json::Number>(loc[1]).value;
(void)lon;
(void)lat;

View File

@ -1,4 +1,5 @@
#include <boost/test/unit_test.hpp>
#include <variant>
#include "coordinates.hpp"
#include "fixture.hpp"
@ -48,32 +49,32 @@ void test_match(bool use_json_only_api)
const auto code = std::get<json::String>(json_result.values.at("code")).value;
BOOST_CHECK_EQUAL(code, "Ok");
const auto &tracepoints = json_result.values.at("tracepoints").get<json::Array>().values;
const auto &tracepoints = std::get<json::Array>(json_result.values.at("tracepoints")).values;
BOOST_CHECK_EQUAL(tracepoints.size(), params.coordinates.size());
const auto &matchings = json_result.values.at("matchings").get<json::Array>().values;
const auto &matchings = std::get<json::Array>(json_result.values.at("matchings")).values;
const auto &number_of_matchings = matchings.size();
for (const auto &waypoint : tracepoints)
{
if (waypoint.is<mapbox::util::recursive_wrapper<util::json::Object>>())
if (std::holds_alternative<util::json::Object>(waypoint))
{
BOOST_CHECK(waypoint_check(waypoint));
const auto &waypoint_object = std::get<json::Object>(waypoint);
const auto matchings_index =
waypoint_object.values.at("matchings_index").get<json::Number>().value;
std::get<json::Number>(waypoint_object.values.at("matchings_index")).value;
const auto waypoint_index =
waypoint_object.values.at("waypoint_index").get<json::Number>().value;
const auto &route_legs = matchings[matchings_index]
.get<json::Object>()
std::get<json::Number>(waypoint_object.values.at("waypoint_index")).value;
const auto &route_legs = std::get<json::Array>(std::get<json::Object>(matchings[matchings_index]
)
.values.at("legs")
.get<json::Array>()
)
.values;
BOOST_CHECK_LT(waypoint_index, route_legs.size() + 1);
BOOST_CHECK_LT(matchings_index, number_of_matchings);
}
else
{
BOOST_CHECK(waypoint.is<json::Null>());
BOOST_CHECK(std::holds_alternative<json::Null>(waypoint));
}
}
}
@ -121,23 +122,23 @@ void test_match_split(bool use_json_only_api)
const auto code = std::get<json::String>(json_result.values.at("code")).value;
BOOST_CHECK_EQUAL(code, "Ok");
const auto &tracepoints = json_result.values.at("tracepoints").get<json::Array>().values;
const auto &tracepoints =std::get<json::Array>(json_result.values.at("tracepoints")).values;
BOOST_CHECK_EQUAL(tracepoints.size(), params.coordinates.size());
const auto &matchings = json_result.values.at("matchings").get<json::Array>().values;
const auto &matchings = std::get<json::Array>(json_result.values.at("matchings")).values;
const auto &number_of_matchings = matchings.size();
BOOST_CHECK_EQUAL(number_of_matchings, 2);
std::size_t current_matchings_index = 0, expected_waypoint_index = 0;
for (const auto &waypoint : tracepoints)
{
if (waypoint.is<mapbox::util::recursive_wrapper<util::json::Object>>())
if (std::holds_alternative<util::json::Object>(waypoint))
{
BOOST_CHECK(waypoint_check(waypoint));
const auto &waypoint_object = std::get<json::Object>(waypoint);
const auto matchings_index =
waypoint_object.values.at("matchings_index").get<json::Number>().value;
std::get<json::Number>(waypoint_object.values.at("matchings_index")).value;
const auto waypoint_index =
waypoint_object.values.at("waypoint_index").get<json::Number>().value;
std::get<json::Number>(waypoint_object.values.at("waypoint_index")).value;
BOOST_CHECK_LT(matchings_index, number_of_matchings);
@ -150,7 +151,7 @@ void test_match_split(bool use_json_only_api)
}
else
{
BOOST_CHECK(waypoint.is<json::Null>());
BOOST_CHECK(std::holds_alternative<json::Null>(waypoint));
}
}
}

View File

@ -22,7 +22,7 @@ osrm::Status run_nearest_json(const osrm::OSRM &osrm,
}
osrm::engine::api::ResultT result = osrm::json::Object();
auto rc = osrm.Nearest(params, result);
json_result = result.get<osrm::json::Object>();
json_result = std::get<osrm::json::Object>(result);
return rc;
}
@ -50,7 +50,7 @@ void test_nearest_response(bool use_json_only_api)
for (const auto &waypoint : waypoints)
{
const auto &waypoint_object = std::get<json::Object>(waypoint);
const auto distance = waypoint_object.values.at("distance").get<json::Number>().value;
const auto distance = std::get<json::Number>(waypoint_object.values.at("distance")).value;
BOOST_CHECK(distance >= 0);
}
}
@ -163,13 +163,13 @@ void test_nearest_response_for_location_in_small_component(bool use_json_only_ap
// Everything within ~20m (actually more) is still in small component.
// Nearest service should snap to road network without considering components.
const auto distance = waypoint_object.values.at("distance").get<json::Number>().value;
const auto distance = std::get<json::Number>(waypoint_object.values.at("distance")).value;
BOOST_CHECK_LT(distance, 20);
const auto &nodes = waypoint_object.values.at("nodes").get<json::Array>().values;
const auto &nodes = std::get<json::Array>(waypoint_object.values.at("nodes")).values;
BOOST_CHECK(nodes.size() == 2);
BOOST_CHECK(nodes[0].get<util::json::Number>().value != 0);
BOOST_CHECK(nodes[1].get<util::json::Number>().value != 0);
BOOST_CHECK(std::get<util::json::Number>(nodes[0]).value != 0);
BOOST_CHECK(std::get<util::json::Number>(nodes[1]).value != 0);
}
}
BOOST_AUTO_TEST_CASE(test_nearest_response_for_location_in_small_component_old_api)

View File

@ -26,7 +26,7 @@ osrm::Status run_route_json(const osrm::OSRM &osrm,
}
osrm::engine::api::ResultT result = osrm::json::Object();
auto rc = osrm.Route(params, result);
json_result = result.get<osrm::json::Object>();
json_result = std::get<osrm::json::Object>(result);
return rc;
}
@ -48,14 +48,14 @@ void test_route_same_coordinates_fixture(bool use_json_only_api)
BOOST_CHECK(rc == Status::Ok);
// unset snapping dependent hint
for (auto &itr : json_result.values["waypoints"].get<json::Array>().values)
for (auto &itr : std::get<json::Array>(json_result.values["waypoints"]).values)
{
// Hint values aren't stable, so blank it out
itr.get<json::Object>().values["hint"] = "";
std::get<json::Object>(itr).values["hint"] = "";
// Round value to 6 decimal places for double comparison later
itr.get<json::Object>().values["distance"] =
round(itr.get<json::Object>().values["distance"].get<json::Number>().value * 1000000);
std::get<json::Object>(itr).values["distance"] =
round(std::get<json::Number>(std::get<json::Object>(itr).values["distance"]).value * 1000000);
}
const auto location = json::Array{{{7.437070}, {43.749248}}};
@ -183,7 +183,7 @@ void test_route_same_coordinates(bool use_json_only_api)
for (const auto &route : routes)
{
const auto &route_object = route.get<json::Object>();
const auto &route_object = std::get<json::Object>(route);
const auto distance = std::get<json::Number>(route_object.values.at("distance")).value;
BOOST_CHECK_EQUAL(distance, 0);
@ -200,81 +200,81 @@ void test_route_same_coordinates(bool use_json_only_api)
for (const auto &leg : legs)
{
const auto &leg_object = leg.get<json::Object>();
const auto &leg_object = std::get<json::Object>(leg);
const auto distance = leg_object.values.at("distance").get<json::Number>().value;
const auto distance = std::get<json::Number>(leg_object.values.at("distance")).value;
BOOST_CHECK_EQUAL(distance, 0);
const auto duration = leg_object.values.at("duration").get<json::Number>().value;
const auto duration = std::get<json::Number>(leg_object.values.at("duration")).value;
BOOST_CHECK_EQUAL(duration, 0);
// nothing can be said about summary, empty or contains human readable summary
const auto summary = leg_object.values.at("summary").get<json::String>().value;
const auto summary = std::get<json::String>(leg_object.values.at("summary")).value;
BOOST_CHECK(((void)summary, true));
const auto &steps = leg_object.values.at("steps").get<json::Array>().values;
const auto &steps = std::get<json::Array>(leg_object.values.at("steps")).values;
BOOST_CHECK(!steps.empty());
std::size_t step_count = 0;
for (const auto &step : steps)
{
const auto &step_object = step.get<json::Object>();
const auto &step_object = std::get<json::Object>(step);
const auto distance = step_object.values.at("distance").get<json::Number>().value;
const auto distance = std::get<json::Number>(step_object.values.at("distance")).value;
BOOST_CHECK_EQUAL(distance, 0);
const auto duration = step_object.values.at("duration").get<json::Number>().value;
const auto duration = std::get<json::Number>(step_object.values.at("duration")).value;
BOOST_CHECK_EQUAL(duration, 0);
// geometries=polyline by default
const auto geometry = step_object.values.at("geometry").get<json::String>().value;
const auto geometry = std::get<json::String>(step_object.values.at("geometry")).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;
const auto name = std::get<json::String>(step_object.values.at("name")).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;
const auto mode = std::get<json::String>(step_object.values.at("mode")).value;
BOOST_CHECK(!name.empty());
const auto &maneuver = step_object.values.at("maneuver").get<json::Object>().values;
const auto &maneuver = std::get<json::Object>(step_object.values.at("maneuver")).values;
const auto type = maneuver.at("type").get<json::String>().value;
const auto type = std::get<json::String>(maneuver.at("type")).value;
BOOST_CHECK(!type.empty());
const auto &intersections =
step_object.values.at("intersections").get<json::Array>().values;
std::get<json::Array>(step_object.values.at("intersections")).values;
for (auto &intersection : intersections)
{
const auto &intersection_object = intersection.get<json::Object>().values;
const auto &intersection_object = std::get<json::Object>(intersection).values;
const auto location =
intersection_object.at("location").get<json::Array>().values;
std::get<json::Array>(intersection_object.at("location")).values;
const auto longitude = std::get<json::Number>(location[0]).value;
const auto latitude = std::get<json::Number>(location[1]).value;
BOOST_CHECK(longitude >= -180. && longitude <= 180.);
BOOST_CHECK(latitude >= -90. && latitude <= 90.);
const auto &bearings =
intersection_object.at("bearings").get<json::Array>().values;
std::get<json::Array>(intersection_object.at("bearings")).values;
BOOST_CHECK(!bearings.empty());
const auto &entries = intersection_object.at("entry").get<json::Array>().values;
const auto &entries = std::get<json::Array>(intersection_object.at("entry")).values;
BOOST_CHECK(bearings.size() == entries.size());
for (const auto &bearing : bearings)
BOOST_CHECK(0. <= bearing.get<json::Number>().value &&
bearing.get<json::Number>().value <= 360.);
BOOST_CHECK(0. <= std::get<json::Number>(bearing).value &&
std::get<json::Number>(bearing).value <= 360.);
if (step_count > 0)
{
const auto in = intersection_object.at("in").get<json::Number>().value;
const auto in = std::get<json::Number>(intersection_object.at("in")).value;
BOOST_CHECK(in < bearings.size());
}
if (step_count + 1 < steps.size())
{
const auto out = intersection_object.at("out").get<json::Number>().value;
const auto out = std::get<json::Number>(intersection_object.at("out")).value;
BOOST_CHECK(out < bearings.size());
}
}
@ -319,7 +319,7 @@ void test_route_same_coordinates_no_waypoints(bool use_json_only_api)
for (const auto &route : routes)
{
const auto &route_object = route.get<json::Object>();
const auto &route_object = std::get<json::Object>(route);
const auto distance = std::get<json::Number>(route_object.values.at("distance")).value;
BOOST_CHECK_EQUAL(distance, 0);
@ -493,7 +493,7 @@ void test_route_user_disables_generating_hints(bool use_json_only_api)
const auto rc = run_route_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
for (auto waypoint : json_result.values["waypoints"].get<json::Array>().values)
for (auto waypoint : std::get<json::Array>(json_result.values["waypoints"]).values)
BOOST_CHECK_EQUAL(std::get<json::Object>(waypoint).values.count("hint"), 0);
}
BOOST_AUTO_TEST_CASE(test_route_user_disables_generating_hints_old_api)
@ -522,21 +522,21 @@ void speed_annotation_matches_duration_and_distance(bool use_json_only_api)
const auto rc = run_route_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
const auto &routes = json_result.values["routes"].get<json::Array>().values;
const auto &legs = routes[0].get<json::Object>().values.at("legs").get<json::Array>().values;
const auto &routes = std::get<json::Array>(json_result.values["routes"]).values;
const auto &legs = std::get<json::Array>(std::get<json::Object>(routes[0]).values.at("legs")).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;
std::get<json::Object>(std::get<json::Object>(legs[0]).values.at("annotation"));
const auto &speeds = std::get<json::Array>(annotation.values.at("speed")).values;
const auto &durations = std::get<json::Array>(annotation.values.at("duration")).values;
const auto &distances = std::get<json::Array>(annotation.values.at("distance")).values;
int length = speeds.size();
BOOST_CHECK_EQUAL(length, 1);
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;
auto speed = std::get<json::Number>(speeds[i]).value;
auto duration = std::get<json::Number>(durations[i]).value;
auto distance = std::get<json::Number>(distances[i]).value;
auto calc = std::round(distance / duration * 10.) / 10.;
BOOST_CHECK_EQUAL(speed, std::isnan(calc) ? 0 : calc);
@ -573,17 +573,16 @@ void test_manual_setting_of_annotations_property(bool use_json_only_api)
const auto code = std::get<json::String>(json_result.values.at("code")).value;
BOOST_CHECK_EQUAL(code, "Ok");
auto annotations = json_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;
auto annotations = std::get<json::Object>(
std::get<json::Object>(
std::get<json::Array>(
std::get<json::Object>(
std::get<json::Array>(json_result.values["routes"])
.values[0])
.values["legs"])
.values[0])
.values["annotation"])
.values;
BOOST_CHECK_EQUAL(annotations.size(), 7);
}
BOOST_AUTO_TEST_CASE(test_manual_setting_of_annotations_property_old_api)

View File

@ -22,7 +22,7 @@ osrm::Status run_table_json(const osrm::OSRM &osrm,
}
osrm::engine::api::ResultT result = osrm::json::Object();
auto rc = osrm.Table(params, result);
json_result = result.get<osrm::json::Object>();
json_result = std::get<osrm::json::Object>(result);
return rc;
}
@ -51,36 +51,36 @@ void test_table_three_coords_one_source_one_dest_matrix(bool use_json_only_api)
// check that returned durations error is expected size and proportions
// this test expects a 1x1 matrix
const auto &durations_array = json_result.values.at("durations").get<json::Array>().values;
const auto &durations_array = std::get<json::Array>(json_result.values.at("durations")).values;
BOOST_CHECK_EQUAL(durations_array.size(), params.sources.size());
for (unsigned int i = 0; i < durations_array.size(); i++)
{
const auto durations_matrix = durations_array[i].get<json::Array>().values;
const auto durations_matrix = std::get<json::Array>(durations_array[i]).values;
BOOST_CHECK_EQUAL(durations_matrix.size(),
params.sources.size() * params.destinations.size());
}
// check that returned distances error is expected size and proportions
// this test expects a 1x1 matrix
const auto &distances_array = json_result.values.at("distances").get<json::Array>().values;
const auto &distances_array = std::get<json::Array>(json_result.values.at("distances")).values;
BOOST_CHECK_EQUAL(distances_array.size(), params.sources.size());
for (unsigned int i = 0; i < distances_array.size(); i++)
{
const auto distances_matrix = distances_array[i].get<json::Array>().values;
const auto distances_matrix = std::get<json::Array>(distances_array[i]).values;
BOOST_CHECK_EQUAL(distances_matrix.size(),
params.sources.size() * params.destinations.size());
}
// check destinations array of waypoint objects
const auto &destinations_array =
json_result.values.at("destinations").get<json::Array>().values;
std::get<json::Array>(json_result.values.at("destinations")).values;
BOOST_CHECK_EQUAL(destinations_array.size(), params.destinations.size());
for (const auto &destination : destinations_array)
{
BOOST_CHECK(waypoint_check(destination));
}
// check sources array of waypoint objects
const auto &sources_array = json_result.values.at("sources").get<json::Array>().values;
const auto &sources_array = std::get<json::Array>(json_result.values.at("sources")).values;
BOOST_CHECK_EQUAL(sources_array.size(), params.sources.size());
for (const auto &source : sources_array)
{
@ -120,22 +120,22 @@ void test_table_three_coords_one_source_one_dest_matrix_no_waypoints(bool use_js
// check that returned durations error is expected size and proportions
// this test expects a 1x1 matrix
const auto &durations_array = json_result.values.at("durations").get<json::Array>().values;
const auto &durations_array = std::get<json::Array>(json_result.values.at("durations")).values;
BOOST_CHECK_EQUAL(durations_array.size(), params.sources.size());
for (unsigned int i = 0; i < durations_array.size(); i++)
{
const auto durations_matrix = durations_array[i].get<json::Array>().values;
const auto durations_matrix = std::get<json::Array>(durations_array[i]).values;
BOOST_CHECK_EQUAL(durations_matrix.size(),
params.sources.size() * params.destinations.size());
}
// check that returned distances error is expected size and proportions
// this test expects a 1x1 matrix
const auto &distances_array = json_result.values.at("distances").get<json::Array>().values;
const auto &distances_array = std::get<json::Array>(json_result.values.at("distances")).values;
BOOST_CHECK_EQUAL(distances_array.size(), params.sources.size());
for (unsigned int i = 0; i < distances_array.size(); i++)
{
const auto distances_matrix = distances_array[i].get<json::Array>().values;
const auto distances_matrix =std::get<json::Array>(distances_array[i]).values;
BOOST_CHECK_EQUAL(distances_matrix.size(),
params.sources.size() * params.destinations.size());
}
@ -175,25 +175,25 @@ void test_table_three_coords_one_source_matrix(bool use_json_only_api)
// check that returned durations error is expected size and proportions
// this test expects a 1x3 matrix
const auto &durations_array = json_result.values.at("durations").get<json::Array>().values;
const auto &durations_array = std::get<json::Array>(json_result.values.at("durations")).values;
BOOST_CHECK_EQUAL(durations_array.size(), params.sources.size());
for (unsigned int i = 0; i < durations_array.size(); i++)
{
const auto durations_matrix = durations_array[i].get<json::Array>().values;
BOOST_CHECK_EQUAL(durations_matrix[i].get<json::Number>().value, 0);
const auto durations_matrix = std::get<json::Array>(durations_array[i]).values;
BOOST_CHECK_EQUAL(std::get<json::Number>(durations_matrix[i]).value, 0);
BOOST_CHECK_EQUAL(durations_matrix.size(),
params.sources.size() * params.coordinates.size());
}
// check destinations array of waypoint objects
const auto &destinations_array =
json_result.values.at("destinations").get<json::Array>().values;
std::get<json::Array>(json_result.values.at("destinations")).values;
BOOST_CHECK_EQUAL(destinations_array.size(), params.coordinates.size());
for (const auto &destination : destinations_array)
{
BOOST_CHECK(waypoint_check(destination));
}
// check sources array of waypoint objects
const auto &sources_array = json_result.values.at("sources").get<json::Array>().values;
const auto &sources_array = std::get<json::Array>(json_result.values.at("sources")).values;
BOOST_CHECK_EQUAL(sources_array.size(), params.sources.size());
for (const auto &source : sources_array)
{
@ -230,21 +230,21 @@ void test_table_three_coordinates_matrix(bool use_json_only_api)
// check that returned durations error is expected size and proportions
// this test expects a 3x3 matrix
const auto &durations_array = json_result.values.at("durations").get<json::Array>().values;
const auto &durations_array = std::get<json::Array>(json_result.values.at("durations")).values;
BOOST_CHECK_EQUAL(durations_array.size(), params.coordinates.size());
for (unsigned int i = 0; i < durations_array.size(); i++)
{
const auto durations_matrix = durations_array[i].get<json::Array>().values;
BOOST_CHECK_EQUAL(durations_matrix[i].get<json::Number>().value, 0);
const auto durations_matrix = std::get<json::Array>(durations_array[i]).values;
BOOST_CHECK_EQUAL(std::get<json::Number>(durations_matrix[i]).value, 0);
BOOST_CHECK_EQUAL(durations_matrix.size(), params.coordinates.size());
}
const auto &destinations_array =
json_result.values.at("destinations").get<json::Array>().values;
std::get<json::Array>(json_result.values.at("destinations")).values;
for (const auto &destination : destinations_array)
{
BOOST_CHECK(waypoint_check(destination));
}
const auto &sources_array = json_result.values.at("sources").get<json::Array>().values;
const auto &sources_array = std::get<json::Array>(json_result.values.at("sources")).values;
BOOST_CHECK_EQUAL(sources_array.size(), params.coordinates.size());
for (const auto &source : sources_array)
{
@ -280,7 +280,7 @@ void test_table_no_segment_for_some_coordinates(bool use_json_only_api)
BOOST_CHECK(rc == Status::Error);
const auto code = std::get<json::String>(json_result.values.at("code")).value;
BOOST_CHECK_EQUAL(code, "NoSegment");
const auto message = json_result.values.at("message").get<json::String>().value;
const auto message = std::get<json::String>(json_result.values.at("message")).value;
BOOST_CHECK_EQUAL(message, "Could not find a matching segment for coordinate 0");
}
BOOST_AUTO_TEST_CASE(test_table_no_segment_for_some_coordinates_old_api)

File diff suppressed because it is too large Load Diff

View File

@ -5,19 +5,20 @@
#include "osrm/coordinate.hpp"
#include "osrm/json_container.hpp"
#include "util/exception.hpp"
#include <variant>
inline bool waypoint_check(osrm::json::Value waypoint)
{
using namespace osrm;
if (!waypoint.is<mapbox::util::recursive_wrapper<util::json::Object>>())
if (!std::holds_alternative<util::json::Object>(waypoint))
{
throw util::exception("Must pass in a waypoint object");
}
const auto waypoint_object = std::get<json::Object>(waypoint);
const auto waypoint_location = std::get<json::Array>(waypoint_object.values.at("location")).values;
util::FloatLongitude lon{waypoint_std::get<json::Number>(location[0]).value};
util::FloatLatitude lat{waypoint_std::get<json::Number>(location[1]).value};
util::FloatLongitude lon{std::get<json::Number>(waypoint_location[0]).value};
util::FloatLatitude lat{std::get<json::Number>(waypoint_location[1]).value};
util::Coordinate location_coordinate(lon, lat);
return location_coordinate.IsValid();
}