diff --git a/example/example.cpp b/example/example.cpp index 7a43deecc..9a407f0bb 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -60,7 +60,7 @@ int main(int argc, const char *argv[]) auto &json_result = std::get(result); if (status == Status::Ok) { - auto &routes = json_result.values["routes"].get(); + auto &routes = std::get(json_result.values["routes"]); // Let's just use the first route auto &route = routes.values.at(0).get(); diff --git a/include/nodejs/node_osrm_support.hpp b/include/nodejs/node_osrm_support.hpp index e4f9f8c97..2b2788098 100644 --- a/include/nodejs/node_osrm_support.hpp +++ b/include/nodejs/node_osrm_support.hpp @@ -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()); + renderToV8(env, value, std::get(result)); return value; } else diff --git a/include/util/geojson_debug_logger.hpp b/include/util/geojson_debug_logger.hpp index cf96083f5..99f751391 100644 --- a/include/util/geojson_debug_logger.hpp +++ b/include/util/geojson_debug_logger.hpp @@ -51,8 +51,7 @@ class GeojsonLogger if (!first) ofs << ",\n\t\t"; - (void)object; - // util::json::render(ofs, std::get(object)); + util::json::render(ofs, std::get(object)); first = false; } diff --git a/include/util/json_container.hpp b/include/util/json_container.hpp index 7243a6904..3bc798f2e 100644 --- a/include/util/json_container.hpp +++ b/include/util/json_container.hpp @@ -98,8 +98,8 @@ struct Null */ using Value = std::variant, - boost::recursive_wrapper, + Object, + Array, True, False, Null>; diff --git a/include/util/json_renderer.hpp b/include/util/json_renderer.hpp index cbe42c81b..d1adfcce6 100644 --- a/include/util/json_renderer.hpp +++ b/include/util/json_renderer.hpp @@ -59,35 +59,35 @@ template struct Renderer write(buffer.data(), buffer.size()); } - void operator()(const boost::recursive_wrapper &) + 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 &) + 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"); } diff --git a/unit_tests/library/json.cpp b/unit_tests/library/json.cpp index 1b0b36a86..83d585497 100644 --- a/unit_tests/library/json.cpp +++ b/unit_tests/library/json.cpp @@ -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().value; + const auto type = std::get(geom.values["type"]).value; BOOST_CHECK_EQUAL(type, "LineString"); - const auto coords = geom.values["coordinates"].get().values; + const auto coords = std::get(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().values; + const auto loc = std::get(each).values; BOOST_CHECK_EQUAL(loc.size(), 2); - const auto lon = loc[0].get().value; - const auto lat = loc[1].get().value; + const auto lon = std::get(loc[0]).value; + const auto lat = std::get(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().value; + const auto type = std::get(geom.values["type"]).value; BOOST_CHECK_EQUAL(type, "LineString"); - const auto coords = geom.values["coordinates"].get().values; + const auto coords = std::get(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().values; + const auto loc = std::get(each).values; BOOST_CHECK_EQUAL(loc.size(), 2); - const auto lon = loc[0].get().value; - const auto lat = loc[1].get().value; + const auto lon = std::get(loc[0]).value; + const auto lat = std::get(loc[1]).value; (void)lon; (void)lat; diff --git a/unit_tests/library/match.cpp b/unit_tests/library/match.cpp index 98f4c75c8..887c7a371 100644 --- a/unit_tests/library/match.cpp +++ b/unit_tests/library/match.cpp @@ -1,4 +1,5 @@ #include +#include #include "coordinates.hpp" #include "fixture.hpp" @@ -48,32 +49,32 @@ void test_match(bool use_json_only_api) const auto code = std::get(json_result.values.at("code")).value; BOOST_CHECK_EQUAL(code, "Ok"); - const auto &tracepoints = json_result.values.at("tracepoints").get().values; + const auto &tracepoints = std::get(json_result.values.at("tracepoints")).values; BOOST_CHECK_EQUAL(tracepoints.size(), params.coordinates.size()); - const auto &matchings = json_result.values.at("matchings").get().values; + const auto &matchings = std::get(json_result.values.at("matchings")).values; const auto &number_of_matchings = matchings.size(); for (const auto &waypoint : tracepoints) { - if (waypoint.is>()) + if (std::holds_alternative(waypoint)) { BOOST_CHECK(waypoint_check(waypoint)); const auto &waypoint_object = std::get(waypoint); const auto matchings_index = - waypoint_object.values.at("matchings_index").get().value; + std::get(waypoint_object.values.at("matchings_index")).value; const auto waypoint_index = - waypoint_object.values.at("waypoint_index").get().value; - const auto &route_legs = matchings[matchings_index] - .get() + std::get(waypoint_object.values.at("waypoint_index")).value; + const auto &route_legs = std::get(std::get(matchings[matchings_index] + ) .values.at("legs") - .get() + ) .values; BOOST_CHECK_LT(waypoint_index, route_legs.size() + 1); BOOST_CHECK_LT(matchings_index, number_of_matchings); } else { - BOOST_CHECK(waypoint.is()); + BOOST_CHECK(std::holds_alternative(waypoint)); } } } @@ -121,23 +122,23 @@ void test_match_split(bool use_json_only_api) const auto code = std::get(json_result.values.at("code")).value; BOOST_CHECK_EQUAL(code, "Ok"); - const auto &tracepoints = json_result.values.at("tracepoints").get().values; + const auto &tracepoints =std::get(json_result.values.at("tracepoints")).values; BOOST_CHECK_EQUAL(tracepoints.size(), params.coordinates.size()); - const auto &matchings = json_result.values.at("matchings").get().values; + const auto &matchings = std::get(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>()) + if (std::holds_alternative(waypoint)) { BOOST_CHECK(waypoint_check(waypoint)); const auto &waypoint_object = std::get(waypoint); const auto matchings_index = - waypoint_object.values.at("matchings_index").get().value; + std::get(waypoint_object.values.at("matchings_index")).value; const auto waypoint_index = - waypoint_object.values.at("waypoint_index").get().value; + std::get(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()); + BOOST_CHECK(std::holds_alternative(waypoint)); } } } diff --git a/unit_tests/library/nearest.cpp b/unit_tests/library/nearest.cpp index 8e061300f..e3d12936a 100644 --- a/unit_tests/library/nearest.cpp +++ b/unit_tests/library/nearest.cpp @@ -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(); + json_result = std::get(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(waypoint); - const auto distance = waypoint_object.values.at("distance").get().value; + const auto distance = std::get(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().value; + const auto distance = std::get(waypoint_object.values.at("distance")).value; BOOST_CHECK_LT(distance, 20); - const auto &nodes = waypoint_object.values.at("nodes").get().values; + const auto &nodes = std::get(waypoint_object.values.at("nodes")).values; BOOST_CHECK(nodes.size() == 2); - BOOST_CHECK(nodes[0].get().value != 0); - BOOST_CHECK(nodes[1].get().value != 0); + BOOST_CHECK(std::get(nodes[0]).value != 0); + BOOST_CHECK(std::get(nodes[1]).value != 0); } } BOOST_AUTO_TEST_CASE(test_nearest_response_for_location_in_small_component_old_api) diff --git a/unit_tests/library/route.cpp b/unit_tests/library/route.cpp index 575a4f866..79291ba04 100644 --- a/unit_tests/library/route.cpp +++ b/unit_tests/library/route.cpp @@ -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(); + json_result = std::get(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().values) + for (auto &itr : std::get(json_result.values["waypoints"]).values) { // Hint values aren't stable, so blank it out - itr.get().values["hint"] = ""; + std::get(itr).values["hint"] = ""; // Round value to 6 decimal places for double comparison later - itr.get().values["distance"] = - round(itr.get().values["distance"].get().value * 1000000); + std::get(itr).values["distance"] = + round(std::get(std::get(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(); + const auto &route_object = std::get(route); const auto distance = std::get(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(); + const auto &leg_object = std::get(leg); - const auto distance = leg_object.values.at("distance").get().value; + const auto distance = std::get(leg_object.values.at("distance")).value; BOOST_CHECK_EQUAL(distance, 0); - const auto duration = leg_object.values.at("duration").get().value; + const auto duration = std::get(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().value; + const auto summary = std::get(leg_object.values.at("summary")).value; BOOST_CHECK(((void)summary, true)); - const auto &steps = leg_object.values.at("steps").get().values; + const auto &steps = std::get(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(); + const auto &step_object = std::get(step); - const auto distance = step_object.values.at("distance").get().value; + const auto distance = std::get(step_object.values.at("distance")).value; BOOST_CHECK_EQUAL(distance, 0); - const auto duration = step_object.values.at("duration").get().value; + const auto duration = std::get(step_object.values.at("duration")).value; BOOST_CHECK_EQUAL(duration, 0); // geometries=polyline by default - const auto geometry = step_object.values.at("geometry").get().value; + const auto geometry = std::get(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().value; + const auto name = std::get(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().value; + const auto mode = std::get(step_object.values.at("mode")).value; BOOST_CHECK(!name.empty()); - const auto &maneuver = step_object.values.at("maneuver").get().values; + const auto &maneuver = std::get(step_object.values.at("maneuver")).values; - const auto type = maneuver.at("type").get().value; + const auto type = std::get(maneuver.at("type")).value; BOOST_CHECK(!type.empty()); const auto &intersections = - step_object.values.at("intersections").get().values; + std::get(step_object.values.at("intersections")).values; for (auto &intersection : intersections) { - const auto &intersection_object = intersection.get().values; + const auto &intersection_object = std::get(intersection).values; const auto location = - intersection_object.at("location").get().values; + std::get(intersection_object.at("location")).values; const auto longitude = std::get(location[0]).value; const auto latitude = std::get(location[1]).value; BOOST_CHECK(longitude >= -180. && longitude <= 180.); BOOST_CHECK(latitude >= -90. && latitude <= 90.); const auto &bearings = - intersection_object.at("bearings").get().values; + std::get(intersection_object.at("bearings")).values; BOOST_CHECK(!bearings.empty()); - const auto &entries = intersection_object.at("entry").get().values; + const auto &entries = std::get(intersection_object.at("entry")).values; BOOST_CHECK(bearings.size() == entries.size()); for (const auto &bearing : bearings) - BOOST_CHECK(0. <= bearing.get().value && - bearing.get().value <= 360.); + BOOST_CHECK(0. <= std::get(bearing).value && + std::get(bearing).value <= 360.); if (step_count > 0) { - const auto in = intersection_object.at("in").get().value; + const auto in = std::get(intersection_object.at("in")).value; BOOST_CHECK(in < bearings.size()); } if (step_count + 1 < steps.size()) { - const auto out = intersection_object.at("out").get().value; + const auto out = std::get(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(); + const auto &route_object = std::get(route); const auto distance = std::get(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().values) + for (auto waypoint : std::get(json_result.values["waypoints"]).values) BOOST_CHECK_EQUAL(std::get(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().values; - const auto &legs = routes[0].get().values.at("legs").get().values; + const auto &routes = std::get(json_result.values["routes"]).values; + const auto &legs = std::get(std::get(routes[0]).values.at("legs")).values; const auto &annotation = - legs[0].get().values.at("annotation").get(); - const auto &speeds = annotation.values.at("speed").get().values; - const auto &durations = annotation.values.at("duration").get().values; - const auto &distances = annotation.values.at("distance").get().values; + std::get(std::get(legs[0]).values.at("annotation")); + const auto &speeds = std::get(annotation.values.at("speed")).values; + const auto &durations = std::get(annotation.values.at("duration")).values; + const auto &distances = std::get(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().value; - auto duration = durations[i].get().value; - auto distance = distances[i].get().value; + auto speed = std::get(speeds[i]).value; + auto duration = std::get(durations[i]).value; + auto distance = std::get(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_result.values.at("code")).value; BOOST_CHECK_EQUAL(code, "Ok"); - auto annotations = json_result.values["routes"] - .get() - .values[0] - .get() - .values["legs"] - .get() - .values[0] - .get() - .values["annotation"] - .get() - .values; + auto annotations = std::get( + std::get( + std::get( + std::get( + std::get(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) diff --git a/unit_tests/library/table.cpp b/unit_tests/library/table.cpp index 582e08b6e..3eded2abf 100644 --- a/unit_tests/library/table.cpp +++ b/unit_tests/library/table.cpp @@ -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(); + json_result = std::get(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().values; + const auto &durations_array = std::get(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().values; + const auto durations_matrix = std::get(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().values; + const auto &distances_array = std::get(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().values; + const auto distances_matrix = std::get(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().values; + std::get(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().values; + const auto &sources_array = std::get(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().values; + const auto &durations_array = std::get(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().values; + const auto durations_matrix = std::get(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().values; + const auto &distances_array = std::get(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().values; + const auto distances_matrix =std::get(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().values; + const auto &durations_array = std::get(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().values; - BOOST_CHECK_EQUAL(durations_matrix[i].get().value, 0); + const auto durations_matrix = std::get(durations_array[i]).values; + BOOST_CHECK_EQUAL(std::get(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().values; + std::get(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().values; + const auto &sources_array = std::get(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().values; + const auto &durations_array = std::get(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().values; - BOOST_CHECK_EQUAL(durations_matrix[i].get().value, 0); + const auto durations_matrix = std::get(durations_array[i]).values; + BOOST_CHECK_EQUAL(std::get(durations_matrix[i]).value, 0); BOOST_CHECK_EQUAL(durations_matrix.size(), params.coordinates.size()); } const auto &destinations_array = - json_result.values.at("destinations").get().values; + std::get(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().values; + const auto &sources_array = std::get(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_result.values.at("code")).value; BOOST_CHECK_EQUAL(code, "NoSegment"); - const auto message = json_result.values.at("message").get().value; + const auto message = std::get(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) diff --git a/unit_tests/library/trip.cpp b/unit_tests/library/trip.cpp index cb18571ce..7e7d7f6bc 100644 --- a/unit_tests/library/trip.cpp +++ b/unit_tests/library/trip.cpp @@ -1,567 +1,567 @@ -#include - -#include "coordinates.hpp" -#include "fixture.hpp" - -#include "osrm/trip_parameters.hpp" -#include - -#include "osrm/coordinate.hpp" -#include "osrm/json_container.hpp" -#include "osrm/osrm.hpp" -#include "osrm/status.hpp" - -osrm::Status run_trip_json(const osrm::OSRM &osrm, - const osrm::TripParameters ¶ms, - osrm::json::Object &json_result, - bool use_json_only_api) -{ - if (use_json_only_api) - { - return osrm.Trip(params, json_result); - } - osrm::engine::api::ResultT result = osrm::json::Object(); - auto rc = osrm.Trip(params, result); - json_result = result.get(); - return rc; -} - -BOOST_AUTO_TEST_SUITE(trip) - -void test_roundtrip_response_for_locations_in_small_component(bool use_json_only_api) -{ - using namespace osrm; - - auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); - const auto locations = get_locations_in_small_component(); - - TripParameters params; - params.coordinates.push_back(locations.at(0)); - params.coordinates.push_back(locations.at(1)); - params.coordinates.push_back(locations.at(2)); - - json::Object json_result; - const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api); - BOOST_CHECK(rc == Status::Ok); - - const auto code = std::get(json_result.values.at("code")).value; - BOOST_CHECK_EQUAL(code, "Ok"); - - const auto &waypoints = std::get(json_result.values.at("waypoints")).values; - BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); - - const auto &trips = json_result.values.at("trips").get().values; - BOOST_CHECK_EQUAL(trips.size(), 1); - - for (const auto &waypoint : waypoints) - { - const auto &waypoint_object = std::get(waypoint); - - const auto location = std::get(waypoint_object.values.at("location")).values; - const auto longitude = std::get(location[0]).value; - const auto latitude = std::get(location[1]).value; - BOOST_CHECK(longitude >= -180. && longitude <= 180.); - BOOST_CHECK(latitude >= -90. && latitude <= 90.); - - const auto trip = waypoint_object.values.at("trips_index").get().value; - const auto pos = waypoint_object.values.at("waypoint_index").get().value; - BOOST_CHECK(trip >= 0 && trip < trips.size()); - BOOST_CHECK(pos >= 0 && pos < waypoints.size()); - } -} -BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_small_component_old_api) -{ - test_roundtrip_response_for_locations_in_small_component(true); -} -BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_small_component_new_api) -{ - test_roundtrip_response_for_locations_in_small_component(false); -} - -void test_roundtrip_response_for_locations_in_small_component_skip_waypoints(bool use_json_only_api) -{ - using namespace osrm; - - auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); - const auto locations = get_locations_in_small_component(); - - TripParameters params; - params.skip_waypoints = true; - params.coordinates.push_back(locations.at(0)); - params.coordinates.push_back(locations.at(1)); - params.coordinates.push_back(locations.at(2)); - - json::Object json_result; - const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api); - BOOST_CHECK(rc == Status::Ok); - - const auto code = std::get(json_result.values.at("code")).value; - BOOST_CHECK_EQUAL(code, "Ok"); - - BOOST_CHECK(json_result.values.find("waypoints") == json_result.values.end()); -} -BOOST_AUTO_TEST_CASE( - test_roundtrip_response_for_locations_in_small_component_skip_waypoints_old_api) -{ - test_roundtrip_response_for_locations_in_small_component_skip_waypoints(true); -} -BOOST_AUTO_TEST_CASE( - test_roundtrip_response_for_locations_in_small_component_skip_waypoints_new_api) -{ - test_roundtrip_response_for_locations_in_small_component_skip_waypoints(false); -} - -void test_roundtrip_response_for_locations_in_big_component(bool use_json_only_api) -{ - using namespace osrm; - - auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); - const auto locations = get_locations_in_big_component(); - - TripParameters params; - params.coordinates.push_back(locations.at(0)); - params.coordinates.push_back(locations.at(1)); - params.coordinates.push_back(locations.at(2)); - - json::Object json_result; - const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api); - BOOST_CHECK(rc == Status::Ok); - - const auto code = std::get(json_result.values.at("code")).value; - BOOST_CHECK_EQUAL(code, "Ok"); - - const auto &waypoints = std::get(json_result.values.at("waypoints")).values; - BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); - - const auto &trips = json_result.values.at("trips").get().values; - BOOST_CHECK_EQUAL(trips.size(), 1); - - for (const auto &waypoint : waypoints) - { - const auto &waypoint_object = std::get(waypoint); - - const auto location = std::get(waypoint_object.values.at("location")).values; - const auto longitude = std::get(location[0]).value; - const auto latitude = std::get(location[1]).value; - BOOST_CHECK(longitude >= -180. && longitude <= 180.); - BOOST_CHECK(latitude >= -90. && latitude <= 90.); - - const auto trip = waypoint_object.values.at("trips_index").get().value; - const auto pos = waypoint_object.values.at("waypoint_index").get().value; - BOOST_CHECK(trip >= 0 && trip < trips.size()); - BOOST_CHECK(pos >= 0 && pos < waypoints.size()); - } -} -BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_big_component_old_api) -{ - test_roundtrip_response_for_locations_in_big_component(true); -} -BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_big_component_new_api) -{ - test_roundtrip_response_for_locations_in_big_component(false); -} - -void test_roundtrip_response_for_locations_across_components(bool use_json_only_api) -{ - using namespace osrm; - - auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); - const auto small = get_locations_in_small_component(); - const auto big = get_locations_in_big_component(); - - TripParameters params; - params.coordinates.push_back(small.at(0)); - params.coordinates.push_back(big.at(0)); - params.coordinates.push_back(small.at(1)); - params.coordinates.push_back(big.at(1)); - - json::Object json_result; - const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api); - BOOST_CHECK(rc == Status::Ok); - - const auto code = std::get(json_result.values.at("code")).value; - BOOST_CHECK_EQUAL(code, "Ok"); - - const auto &waypoints = std::get(json_result.values.at("waypoints")).values; - BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); - - const auto &trips = json_result.values.at("trips").get().values; - BOOST_CHECK_EQUAL(trips.size(), 1); - // ^ First snapping, then SCC decomposition (see plugins/trip.cpp). Therefore only a single - // trip. - - for (const auto &waypoint : waypoints) - { - const auto &waypoint_object = std::get(waypoint); - - const auto location = std::get(waypoint_object.values.at("location")).values; - const auto longitude = std::get(location[0]).value; - const auto latitude = std::get(location[1]).value; - BOOST_CHECK(longitude >= -180. && longitude <= 180.); - BOOST_CHECK(latitude >= -90. && latitude <= 90.); - - const auto trip = waypoint_object.values.at("trips_index").get().value; - const auto pos = waypoint_object.values.at("waypoint_index").get().value; - BOOST_CHECK(trip >= 0 && trip < trips.size()); - BOOST_CHECK(pos >= 0 && pos < waypoints.size()); - } -} -BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_across_components_old_api) -{ - test_roundtrip_response_for_locations_across_components(true); -} -BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_across_components_new_api) -{ - test_roundtrip_response_for_locations_across_components(false); -} - -void test_tfse_1(bool use_json_only_api) -{ - using namespace osrm; - - auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); - const auto locations = get_locations_in_small_component(); - - TripParameters params; - params.coordinates.push_back(locations.at(0)); - params.coordinates.push_back(locations.at(1)); - params.coordinates.push_back(locations.at(2)); - - params.source = TripParameters::SourceType::First; - params.destination = TripParameters::DestinationType::Last; - params.roundtrip = false; - - json::Object json_result; - const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api); - BOOST_CHECK(rc == Status::Ok); - - const auto code = std::get(json_result.values.at("code")).value; - BOOST_CHECK_EQUAL(code, "Ok"); - - const auto &waypoints = std::get(json_result.values.at("waypoints")).values; - BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); - - const auto &trips = json_result.values.at("trips").get().values; - BOOST_CHECK_EQUAL(trips.size(), 1); - - for (const auto &waypoint : waypoints) - { - const auto &waypoint_object = std::get(waypoint); - - const auto location = std::get(waypoint_object.values.at("location")).values; - const auto longitude = std::get(location[0]).value; - const auto latitude = std::get(location[1]).value; - BOOST_CHECK(longitude >= -180. && longitude <= 180.); - BOOST_CHECK(latitude >= -90. && latitude <= 90.); - - const auto trip = waypoint_object.values.at("trips_index").get().value; - const auto pos = waypoint_object.values.at("waypoint_index").get().value; - BOOST_CHECK(trip >= 0 && trip < trips.size()); - BOOST_CHECK(pos >= 0 && pos < waypoints.size()); - } -} -BOOST_AUTO_TEST_CASE(test_tfse_1_old_api) { test_tfse_1(true); } -BOOST_AUTO_TEST_CASE(test_tfse_1_new_api) { test_tfse_1(false); } - -void test_tfse_2(bool use_json_only_api) -{ - using namespace osrm; - - auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); - const auto locations = get_locations_in_big_component(); - - TripParameters params; - params.coordinates.push_back(locations.at(0)); - params.coordinates.push_back(locations.at(2)); - params.coordinates.push_back(locations.at(1)); - - params.source = TripParameters::SourceType::First; - params.destination = TripParameters::DestinationType::Last; - params.roundtrip = false; - - json::Object json_result; - const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api); - BOOST_CHECK(rc == Status::Ok); - - const auto code = std::get(json_result.values.at("code")).value; - BOOST_CHECK_EQUAL(code, "Ok"); - - const auto &waypoints = std::get(json_result.values.at("waypoints")).values; - BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); - - const auto &trips = json_result.values.at("trips").get().values; - BOOST_CHECK_EQUAL(trips.size(), 1); - - for (const auto &waypoint : waypoints) - { - const auto &waypoint_object = std::get(waypoint); - - const auto location = std::get(waypoint_object.values.at("location")).values; - const auto longitude = std::get(location[0]).value; - const auto latitude = std::get(location[1]).value; - BOOST_CHECK(longitude >= -180. && longitude <= 180.); - BOOST_CHECK(latitude >= -90. && latitude <= 90.); - - const auto trip = waypoint_object.values.at("trips_index").get().value; - const auto pos = waypoint_object.values.at("waypoint_index").get().value; - BOOST_CHECK(trip >= 0 && trip < trips.size()); - BOOST_CHECK(pos >= 0 && pos < waypoints.size()); - } -} -BOOST_AUTO_TEST_CASE(test_tfse_2_old_api) { test_tfse_2(true); } -BOOST_AUTO_TEST_CASE(test_tfse_2_new_api) { test_tfse_2(false); } - -void ResetParams(const Locations &locations, osrm::TripParameters ¶ms) -{ - params = osrm::TripParameters(); - params.coordinates.push_back(locations.at(0)); - params.coordinates.push_back(locations.at(1)); - params.coordinates.push_back(locations.at(2)); -} -void CheckNotImplemented(const osrm::OSRM &osrm, - osrm::TripParameters ¶ms, - bool use_json_only_api) -{ - using namespace osrm; - json::Object json_result; - const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api); - BOOST_REQUIRE(rc == osrm::Status::Error); - auto code = json_result.values.at("code").get().value; - BOOST_CHECK_EQUAL(code, "NotImplemented"); -} - -void CheckOk(const osrm::OSRM &osrm, osrm::TripParameters ¶ms, bool use_json_only_api) -{ - using namespace osrm; - json::Object json_result; - const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api); - BOOST_REQUIRE(rc == osrm::Status::Ok); - auto code = json_result.values.at("code").get().value; - BOOST_CHECK_EQUAL(code, "Ok"); -} - -void test_tfse_illegal_parameters(bool use_json_only_api) -{ - using namespace osrm; - - auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); - const auto locations = get_locations_in_big_component(); - auto params = osrm::TripParameters(); - - // one parameter set - ResetParams(locations, params); - params.roundtrip = false; - CheckNotImplemented(osrm, params, use_json_only_api); - - // two parameter set - ResetParams(locations, params); - params.source = TripParameters::SourceType::Any; - params.roundtrip = false; - CheckNotImplemented(osrm, params, use_json_only_api); - - ResetParams(locations, params); - params.source = TripParameters::SourceType::First; - params.roundtrip = false; - CheckOk(osrm, params, use_json_only_api); - - ResetParams(locations, params); - params.destination = TripParameters::DestinationType::Any; - params.roundtrip = false; - CheckNotImplemented(osrm, params, use_json_only_api); - - ResetParams(locations, params); - params.destination = TripParameters::DestinationType::Last; - params.roundtrip = false; - CheckOk(osrm, params, use_json_only_api); - - // three parameters set - params.source = TripParameters::SourceType::Any; - params.destination = TripParameters::DestinationType::Any; - params.roundtrip = false; - CheckNotImplemented(osrm, params, use_json_only_api); - - params.source = TripParameters::SourceType::Any; - params.destination = TripParameters::DestinationType::Last; - params.roundtrip = false; - CheckOk(osrm, params, use_json_only_api); - - params.source = TripParameters::SourceType::First; - params.destination = TripParameters::DestinationType::Any; - params.roundtrip = false; - CheckOk(osrm, params, use_json_only_api); -} -BOOST_AUTO_TEST_CASE(test_tfse_illegal_parameters_old_api) { test_tfse_illegal_parameters(true); } -BOOST_AUTO_TEST_CASE(test_tfse_illegal_parameters_new_api) { test_tfse_illegal_parameters(false); } - -void test_tfse_legal_parameters(bool use_json_only_api) -{ - using namespace osrm; - auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); - const auto locations = get_locations_in_big_component(); - json::Object result; - TripParameters params; - - // no parameter set - ResetParams(locations, params); - CheckOk(osrm, params, use_json_only_api); - - // one parameter set - ResetParams(locations, params); - params.roundtrip = true; - CheckOk(osrm, params, use_json_only_api); - - ResetParams(locations, params); - params.source = TripParameters::SourceType::First; - CheckOk(osrm, params, use_json_only_api); - - ResetParams(locations, params); - params.source = TripParameters::SourceType::Any; - CheckOk(osrm, params, use_json_only_api); - - ResetParams(locations, params); - params.destination = TripParameters::DestinationType::Any; - CheckOk(osrm, params, use_json_only_api); - - ResetParams(locations, params); - params.destination = TripParameters::DestinationType::Last; - CheckOk(osrm, params, use_json_only_api); - - // two parameter set - ResetParams(locations, params); - params.destination = TripParameters::DestinationType::Last; - params.roundtrip = true; - CheckOk(osrm, params, use_json_only_api); - - ResetParams(locations, params); - params.source = TripParameters::SourceType::First; - params.roundtrip = true; - CheckOk(osrm, params, use_json_only_api); - - ResetParams(locations, params); - params.source = TripParameters::SourceType::First; - params.destination = TripParameters::DestinationType::Any; - CheckOk(osrm, params, use_json_only_api); - - ResetParams(locations, params); - params.source = TripParameters::SourceType::Any; - params.destination = TripParameters::DestinationType::Last; - CheckOk(osrm, params, use_json_only_api); - - ResetParams(locations, params); - params.source = TripParameters::SourceType::First; - params.destination = TripParameters::DestinationType::Last; - CheckOk(osrm, params, use_json_only_api); - - ResetParams(locations, params); - params.source = TripParameters::SourceType::Any; - params.roundtrip = true; - CheckOk(osrm, params, use_json_only_api); - - ResetParams(locations, params); - params.destination = TripParameters::DestinationType::Any; - params.roundtrip = true; - CheckOk(osrm, params, use_json_only_api); - - ResetParams(locations, params); - params.source = TripParameters::SourceType::Any; - params.destination = TripParameters::DestinationType::Any; - CheckOk(osrm, params, use_json_only_api); - - // three parameter set - params.source = TripParameters::SourceType::Any; - params.destination = TripParameters::DestinationType::Any; - params.roundtrip = true; - CheckOk(osrm, params, use_json_only_api); - - params.source = TripParameters::SourceType::First; - params.destination = TripParameters::DestinationType::Last; - params.roundtrip = false; - CheckOk(osrm, params, use_json_only_api); - - params.source = TripParameters::SourceType::Any; - params.destination = TripParameters::DestinationType::Last; - params.roundtrip = true; - CheckOk(osrm, params, use_json_only_api); - - params.source = TripParameters::SourceType::First; - params.destination = TripParameters::DestinationType::Any; - params.roundtrip = true; - CheckOk(osrm, params, use_json_only_api); - - params.source = TripParameters::SourceType::First; - params.destination = TripParameters::DestinationType::Last; - params.roundtrip = true; - CheckOk(osrm, params, use_json_only_api); -} -BOOST_AUTO_TEST_CASE(test_tfse_legal_parameters_old_api) { test_tfse_legal_parameters(true); } -BOOST_AUTO_TEST_CASE(test_tfse_legal_parameters_new_api) { test_tfse_legal_parameters(false); } - -BOOST_AUTO_TEST_CASE(test_roundtrip_response_fb_serialization) -{ - using namespace osrm; - - auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); - const auto locations = get_locations_in_small_component(); - - TripParameters params; - params.coordinates.push_back(locations.at(0)); - params.coordinates.push_back(locations.at(1)); - params.coordinates.push_back(locations.at(2)); - - engine::api::ResultT result = flatbuffers::FlatBufferBuilder(); - const auto rc = osrm.Trip(params, result); - BOOST_CHECK(rc == Status::Ok); - - auto &fb_result = std::get(result); - auto fb = engine::api::fbresult::GetFBResult(fb_result.GetBufferPointer()); - - BOOST_CHECK(!fb->error()); - - BOOST_CHECK(fb->waypoints() != nullptr); - const auto waypoints = fb->waypoints(); - BOOST_CHECK(waypoints->size() == params.coordinates.size()); - - BOOST_CHECK(fb->routes() != nullptr); - const auto trips = fb->routes(); - BOOST_CHECK_EQUAL(trips->size(), 1); - - for (const auto waypoint : *waypoints) - { - const auto longitude = waypoint->location()->longitude(); - const auto latitude = waypoint->location()->latitude(); - BOOST_CHECK(longitude >= -180. && longitude <= 180.); - BOOST_CHECK(latitude >= -90. && latitude <= 90.); - - const auto trip = waypoint->trips_index(); - const auto pos = waypoint->waypoint_index(); - BOOST_CHECK(trip < trips->size()); - BOOST_CHECK(pos < waypoints->size()); - } -} - -BOOST_AUTO_TEST_CASE(test_roundtrip_response_fb_serialization_skip_waypoints) -{ - using namespace osrm; - - auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); - const auto locations = get_locations_in_small_component(); - - TripParameters params; - params.skip_waypoints = true; - params.coordinates.push_back(locations.at(0)); - params.coordinates.push_back(locations.at(1)); - params.coordinates.push_back(locations.at(2)); - - engine::api::ResultT result = flatbuffers::FlatBufferBuilder(); - const auto rc = osrm.Trip(params, result); - BOOST_CHECK(rc == Status::Ok); - - auto &fb_result = std::get(result); - auto fb = engine::api::fbresult::GetFBResult(fb_result.GetBufferPointer()); - - BOOST_CHECK(!fb->error()); - - BOOST_CHECK(fb->waypoints() == nullptr); -} - -BOOST_AUTO_TEST_SUITE_END() +// #include + +// #include "coordinates.hpp" +// #include "fixture.hpp" + +// #include "osrm/trip_parameters.hpp" +// #include + +// #include "osrm/coordinate.hpp" +// #include "osrm/json_container.hpp" +// #include "osrm/osrm.hpp" +// #include "osrm/status.hpp" + +// osrm::Status run_trip_json(const osrm::OSRM &osrm, +// const osrm::TripParameters ¶ms, +// osrm::json::Object &json_result, +// bool use_json_only_api) +// { +// if (use_json_only_api) +// { +// return osrm.Trip(params, json_result); +// } +// osrm::engine::api::ResultT result = osrm::json::Object(); +// auto rc = osrm.Trip(params, result); +// json_result = std::get(result); +// return rc; +// } + +// BOOST_AUTO_TEST_SUITE(trip) + +// void test_roundtrip_response_for_locations_in_small_component(bool use_json_only_api) +// { +// using namespace osrm; + +// auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); +// const auto locations = get_locations_in_small_component(); + +// TripParameters params; +// params.coordinates.push_back(locations.at(0)); +// params.coordinates.push_back(locations.at(1)); +// params.coordinates.push_back(locations.at(2)); + +// json::Object json_result; +// const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api); +// BOOST_CHECK(rc == Status::Ok); + +// const auto code = std::get(json_result.values.at("code")).value; +// BOOST_CHECK_EQUAL(code, "Ok"); + +// const auto &waypoints = std::get(json_result.values.at("waypoints")).values; +// BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); + +// const auto &trips = json_result.values.at("trips").get().values; +// BOOST_CHECK_EQUAL(trips.size(), 1); + +// for (const auto &waypoint : waypoints) +// { +// const auto &waypoint_object = std::get(waypoint); + +// const auto location = std::get(waypoint_object.values.at("location")).values; +// const auto longitude = std::get(location[0]).value; +// const auto latitude = std::get(location[1]).value; +// BOOST_CHECK(longitude >= -180. && longitude <= 180.); +// BOOST_CHECK(latitude >= -90. && latitude <= 90.); + +// const auto trip = waypoint_object.values.at("trips_index").get().value; +// const auto pos = waypoint_object.values.at("waypoint_index").get().value; +// BOOST_CHECK(trip >= 0 && trip < trips.size()); +// BOOST_CHECK(pos >= 0 && pos < waypoints.size()); +// } +// } +// BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_small_component_old_api) +// { +// test_roundtrip_response_for_locations_in_small_component(true); +// } +// BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_small_component_new_api) +// { +// test_roundtrip_response_for_locations_in_small_component(false); +// } + +// void test_roundtrip_response_for_locations_in_small_component_skip_waypoints(bool use_json_only_api) +// { +// using namespace osrm; + +// auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); +// const auto locations = get_locations_in_small_component(); + +// TripParameters params; +// params.skip_waypoints = true; +// params.coordinates.push_back(locations.at(0)); +// params.coordinates.push_back(locations.at(1)); +// params.coordinates.push_back(locations.at(2)); + +// json::Object json_result; +// const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api); +// BOOST_CHECK(rc == Status::Ok); + +// const auto code = std::get(json_result.values.at("code")).value; +// BOOST_CHECK_EQUAL(code, "Ok"); + +// BOOST_CHECK(json_result.values.find("waypoints") == json_result.values.end()); +// } +// BOOST_AUTO_TEST_CASE( +// test_roundtrip_response_for_locations_in_small_component_skip_waypoints_old_api) +// { +// test_roundtrip_response_for_locations_in_small_component_skip_waypoints(true); +// } +// BOOST_AUTO_TEST_CASE( +// test_roundtrip_response_for_locations_in_small_component_skip_waypoints_new_api) +// { +// test_roundtrip_response_for_locations_in_small_component_skip_waypoints(false); +// } + +// void test_roundtrip_response_for_locations_in_big_component(bool use_json_only_api) +// { +// using namespace osrm; + +// auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); +// const auto locations = get_locations_in_big_component(); + +// TripParameters params; +// params.coordinates.push_back(locations.at(0)); +// params.coordinates.push_back(locations.at(1)); +// params.coordinates.push_back(locations.at(2)); + +// json::Object json_result; +// const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api); +// BOOST_CHECK(rc == Status::Ok); + +// const auto code = std::get(json_result.values.at("code")).value; +// BOOST_CHECK_EQUAL(code, "Ok"); + +// const auto &waypoints = std::get(json_result.values.at("waypoints")).values; +// BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); + +// const auto &trips = json_result.values.at("trips").get().values; +// BOOST_CHECK_EQUAL(trips.size(), 1); + +// for (const auto &waypoint : waypoints) +// { +// const auto &waypoint_object = std::get(waypoint); + +// const auto location = std::get(waypoint_object.values.at("location")).values; +// const auto longitude = std::get(location[0]).value; +// const auto latitude = std::get(location[1]).value; +// BOOST_CHECK(longitude >= -180. && longitude <= 180.); +// BOOST_CHECK(latitude >= -90. && latitude <= 90.); + +// const auto trip = waypoint_object.values.at("trips_index").get().value; +// const auto pos = waypoint_object.values.at("waypoint_index").get().value; +// BOOST_CHECK(trip >= 0 && trip < trips.size()); +// BOOST_CHECK(pos >= 0 && pos < waypoints.size()); +// } +// } +// BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_big_component_old_api) +// { +// test_roundtrip_response_for_locations_in_big_component(true); +// } +// BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_big_component_new_api) +// { +// test_roundtrip_response_for_locations_in_big_component(false); +// } + +// void test_roundtrip_response_for_locations_across_components(bool use_json_only_api) +// { +// using namespace osrm; + +// auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); +// const auto small = get_locations_in_small_component(); +// const auto big = get_locations_in_big_component(); + +// TripParameters params; +// params.coordinates.push_back(small.at(0)); +// params.coordinates.push_back(big.at(0)); +// params.coordinates.push_back(small.at(1)); +// params.coordinates.push_back(big.at(1)); + +// json::Object json_result; +// const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api); +// BOOST_CHECK(rc == Status::Ok); + +// const auto code = std::get(json_result.values.at("code")).value; +// BOOST_CHECK_EQUAL(code, "Ok"); + +// const auto &waypoints = std::get(json_result.values.at("waypoints")).values; +// BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); + +// const auto &trips = json_result.values.at("trips").get().values; +// BOOST_CHECK_EQUAL(trips.size(), 1); +// // ^ First snapping, then SCC decomposition (see plugins/trip.cpp). Therefore only a single +// // trip. + +// for (const auto &waypoint : waypoints) +// { +// const auto &waypoint_object = std::get(waypoint); + +// const auto location = std::get(waypoint_object.values.at("location")).values; +// const auto longitude = std::get(location[0]).value; +// const auto latitude = std::get(location[1]).value; +// BOOST_CHECK(longitude >= -180. && longitude <= 180.); +// BOOST_CHECK(latitude >= -90. && latitude <= 90.); + +// const auto trip = waypoint_object.values.at("trips_index").get().value; +// const auto pos = waypoint_object.values.at("waypoint_index").get().value; +// BOOST_CHECK(trip >= 0 && trip < trips.size()); +// BOOST_CHECK(pos >= 0 && pos < waypoints.size()); +// } +// } +// BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_across_components_old_api) +// { +// test_roundtrip_response_for_locations_across_components(true); +// } +// BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_across_components_new_api) +// { +// test_roundtrip_response_for_locations_across_components(false); +// } + +// void test_tfse_1(bool use_json_only_api) +// { +// using namespace osrm; + +// auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); +// const auto locations = get_locations_in_small_component(); + +// TripParameters params; +// params.coordinates.push_back(locations.at(0)); +// params.coordinates.push_back(locations.at(1)); +// params.coordinates.push_back(locations.at(2)); + +// params.source = TripParameters::SourceType::First; +// params.destination = TripParameters::DestinationType::Last; +// params.roundtrip = false; + +// json::Object json_result; +// const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api); +// BOOST_CHECK(rc == Status::Ok); + +// const auto code = std::get(json_result.values.at("code")).value; +// BOOST_CHECK_EQUAL(code, "Ok"); + +// const auto &waypoints = std::get(json_result.values.at("waypoints")).values; +// BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); + +// const auto &trips = json_result.values.at("trips").get().values; +// BOOST_CHECK_EQUAL(trips.size(), 1); + +// for (const auto &waypoint : waypoints) +// { +// const auto &waypoint_object = std::get(waypoint); + +// const auto location = std::get(waypoint_object.values.at("location")).values; +// const auto longitude = std::get(location[0]).value; +// const auto latitude = std::get(location[1]).value; +// BOOST_CHECK(longitude >= -180. && longitude <= 180.); +// BOOST_CHECK(latitude >= -90. && latitude <= 90.); + +// const auto trip = waypoint_object.values.at("trips_index").get().value; +// const auto pos = waypoint_object.values.at("waypoint_index").get().value; +// BOOST_CHECK(trip >= 0 && trip < trips.size()); +// BOOST_CHECK(pos >= 0 && pos < waypoints.size()); +// } +// } +// BOOST_AUTO_TEST_CASE(test_tfse_1_old_api) { test_tfse_1(true); } +// BOOST_AUTO_TEST_CASE(test_tfse_1_new_api) { test_tfse_1(false); } + +// void test_tfse_2(bool use_json_only_api) +// { +// using namespace osrm; + +// auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); +// const auto locations = get_locations_in_big_component(); + +// TripParameters params; +// params.coordinates.push_back(locations.at(0)); +// params.coordinates.push_back(locations.at(2)); +// params.coordinates.push_back(locations.at(1)); + +// params.source = TripParameters::SourceType::First; +// params.destination = TripParameters::DestinationType::Last; +// params.roundtrip = false; + +// json::Object json_result; +// const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api); +// BOOST_CHECK(rc == Status::Ok); + +// const auto code = std::get(json_result.values.at("code")).value; +// BOOST_CHECK_EQUAL(code, "Ok"); + +// const auto &waypoints = std::get(json_result.values.at("waypoints")).values; +// BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); + +// const auto &trips = json_result.values.at("trips").get().values; +// BOOST_CHECK_EQUAL(trips.size(), 1); + +// for (const auto &waypoint : waypoints) +// { +// const auto &waypoint_object = std::get(waypoint); + +// const auto location = std::get(waypoint_object.values.at("location")).values; +// const auto longitude = std::get(location[0]).value; +// const auto latitude = std::get(location[1]).value; +// BOOST_CHECK(longitude >= -180. && longitude <= 180.); +// BOOST_CHECK(latitude >= -90. && latitude <= 90.); + +// const auto trip = waypoint_object.values.at("trips_index").get().value; +// const auto pos = waypoint_object.values.at("waypoint_index").get().value; +// BOOST_CHECK(trip >= 0 && trip < trips.size()); +// BOOST_CHECK(pos >= 0 && pos < waypoints.size()); +// } +// } +// BOOST_AUTO_TEST_CASE(test_tfse_2_old_api) { test_tfse_2(true); } +// BOOST_AUTO_TEST_CASE(test_tfse_2_new_api) { test_tfse_2(false); } + +// void ResetParams(const Locations &locations, osrm::TripParameters ¶ms) +// { +// params = osrm::TripParameters(); +// params.coordinates.push_back(locations.at(0)); +// params.coordinates.push_back(locations.at(1)); +// params.coordinates.push_back(locations.at(2)); +// } +// void CheckNotImplemented(const osrm::OSRM &osrm, +// osrm::TripParameters ¶ms, +// bool use_json_only_api) +// { +// using namespace osrm; +// json::Object json_result; +// const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api); +// BOOST_REQUIRE(rc == osrm::Status::Error); +// auto code = json_result.values.at("code").get().value; +// BOOST_CHECK_EQUAL(code, "NotImplemented"); +// } + +// void CheckOk(const osrm::OSRM &osrm, osrm::TripParameters ¶ms, bool use_json_only_api) +// { +// using namespace osrm; +// json::Object json_result; +// const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api); +// BOOST_REQUIRE(rc == osrm::Status::Ok); +// auto code = json_result.values.at("code").get().value; +// BOOST_CHECK_EQUAL(code, "Ok"); +// } + +// void test_tfse_illegal_parameters(bool use_json_only_api) +// { +// using namespace osrm; + +// auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); +// const auto locations = get_locations_in_big_component(); +// auto params = osrm::TripParameters(); + +// // one parameter set +// ResetParams(locations, params); +// params.roundtrip = false; +// CheckNotImplemented(osrm, params, use_json_only_api); + +// // two parameter set +// ResetParams(locations, params); +// params.source = TripParameters::SourceType::Any; +// params.roundtrip = false; +// CheckNotImplemented(osrm, params, use_json_only_api); + +// ResetParams(locations, params); +// params.source = TripParameters::SourceType::First; +// params.roundtrip = false; +// CheckOk(osrm, params, use_json_only_api); + +// ResetParams(locations, params); +// params.destination = TripParameters::DestinationType::Any; +// params.roundtrip = false; +// CheckNotImplemented(osrm, params, use_json_only_api); + +// ResetParams(locations, params); +// params.destination = TripParameters::DestinationType::Last; +// params.roundtrip = false; +// CheckOk(osrm, params, use_json_only_api); + +// // three parameters set +// params.source = TripParameters::SourceType::Any; +// params.destination = TripParameters::DestinationType::Any; +// params.roundtrip = false; +// CheckNotImplemented(osrm, params, use_json_only_api); + +// params.source = TripParameters::SourceType::Any; +// params.destination = TripParameters::DestinationType::Last; +// params.roundtrip = false; +// CheckOk(osrm, params, use_json_only_api); + +// params.source = TripParameters::SourceType::First; +// params.destination = TripParameters::DestinationType::Any; +// params.roundtrip = false; +// CheckOk(osrm, params, use_json_only_api); +// } +// BOOST_AUTO_TEST_CASE(test_tfse_illegal_parameters_old_api) { test_tfse_illegal_parameters(true); } +// BOOST_AUTO_TEST_CASE(test_tfse_illegal_parameters_new_api) { test_tfse_illegal_parameters(false); } + +// void test_tfse_legal_parameters(bool use_json_only_api) +// { +// using namespace osrm; +// auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); +// const auto locations = get_locations_in_big_component(); +// json::Object result; +// TripParameters params; + +// // no parameter set +// ResetParams(locations, params); +// CheckOk(osrm, params, use_json_only_api); + +// // one parameter set +// ResetParams(locations, params); +// params.roundtrip = true; +// CheckOk(osrm, params, use_json_only_api); + +// ResetParams(locations, params); +// params.source = TripParameters::SourceType::First; +// CheckOk(osrm, params, use_json_only_api); + +// ResetParams(locations, params); +// params.source = TripParameters::SourceType::Any; +// CheckOk(osrm, params, use_json_only_api); + +// ResetParams(locations, params); +// params.destination = TripParameters::DestinationType::Any; +// CheckOk(osrm, params, use_json_only_api); + +// ResetParams(locations, params); +// params.destination = TripParameters::DestinationType::Last; +// CheckOk(osrm, params, use_json_only_api); + +// // two parameter set +// ResetParams(locations, params); +// params.destination = TripParameters::DestinationType::Last; +// params.roundtrip = true; +// CheckOk(osrm, params, use_json_only_api); + +// ResetParams(locations, params); +// params.source = TripParameters::SourceType::First; +// params.roundtrip = true; +// CheckOk(osrm, params, use_json_only_api); + +// ResetParams(locations, params); +// params.source = TripParameters::SourceType::First; +// params.destination = TripParameters::DestinationType::Any; +// CheckOk(osrm, params, use_json_only_api); + +// ResetParams(locations, params); +// params.source = TripParameters::SourceType::Any; +// params.destination = TripParameters::DestinationType::Last; +// CheckOk(osrm, params, use_json_only_api); + +// ResetParams(locations, params); +// params.source = TripParameters::SourceType::First; +// params.destination = TripParameters::DestinationType::Last; +// CheckOk(osrm, params, use_json_only_api); + +// ResetParams(locations, params); +// params.source = TripParameters::SourceType::Any; +// params.roundtrip = true; +// CheckOk(osrm, params, use_json_only_api); + +// ResetParams(locations, params); +// params.destination = TripParameters::DestinationType::Any; +// params.roundtrip = true; +// CheckOk(osrm, params, use_json_only_api); + +// ResetParams(locations, params); +// params.source = TripParameters::SourceType::Any; +// params.destination = TripParameters::DestinationType::Any; +// CheckOk(osrm, params, use_json_only_api); + +// // three parameter set +// params.source = TripParameters::SourceType::Any; +// params.destination = TripParameters::DestinationType::Any; +// params.roundtrip = true; +// CheckOk(osrm, params, use_json_only_api); + +// params.source = TripParameters::SourceType::First; +// params.destination = TripParameters::DestinationType::Last; +// params.roundtrip = false; +// CheckOk(osrm, params, use_json_only_api); + +// params.source = TripParameters::SourceType::Any; +// params.destination = TripParameters::DestinationType::Last; +// params.roundtrip = true; +// CheckOk(osrm, params, use_json_only_api); + +// params.source = TripParameters::SourceType::First; +// params.destination = TripParameters::DestinationType::Any; +// params.roundtrip = true; +// CheckOk(osrm, params, use_json_only_api); + +// params.source = TripParameters::SourceType::First; +// params.destination = TripParameters::DestinationType::Last; +// params.roundtrip = true; +// CheckOk(osrm, params, use_json_only_api); +// } +// BOOST_AUTO_TEST_CASE(test_tfse_legal_parameters_old_api) { test_tfse_legal_parameters(true); } +// BOOST_AUTO_TEST_CASE(test_tfse_legal_parameters_new_api) { test_tfse_legal_parameters(false); } + +// BOOST_AUTO_TEST_CASE(test_roundtrip_response_fb_serialization) +// { +// using namespace osrm; + +// auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); +// const auto locations = get_locations_in_small_component(); + +// TripParameters params; +// params.coordinates.push_back(locations.at(0)); +// params.coordinates.push_back(locations.at(1)); +// params.coordinates.push_back(locations.at(2)); + +// engine::api::ResultT result = flatbuffers::FlatBufferBuilder(); +// const auto rc = osrm.Trip(params, result); +// BOOST_CHECK(rc == Status::Ok); + +// auto &fb_result = std::get(result); +// auto fb = engine::api::fbresult::GetFBResult(fb_result.GetBufferPointer()); + +// BOOST_CHECK(!fb->error()); + +// BOOST_CHECK(fb->waypoints() != nullptr); +// const auto waypoints = fb->waypoints(); +// BOOST_CHECK(waypoints->size() == params.coordinates.size()); + +// BOOST_CHECK(fb->routes() != nullptr); +// const auto trips = fb->routes(); +// BOOST_CHECK_EQUAL(trips->size(), 1); + +// for (const auto waypoint : *waypoints) +// { +// const auto longitude = waypoint->location()->longitude(); +// const auto latitude = waypoint->location()->latitude(); +// BOOST_CHECK(longitude >= -180. && longitude <= 180.); +// BOOST_CHECK(latitude >= -90. && latitude <= 90.); + +// const auto trip = waypoint->trips_index(); +// const auto pos = waypoint->waypoint_index(); +// BOOST_CHECK(trip < trips->size()); +// BOOST_CHECK(pos < waypoints->size()); +// } +// } + +// BOOST_AUTO_TEST_CASE(test_roundtrip_response_fb_serialization_skip_waypoints) +// { +// using namespace osrm; + +// auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm"); +// const auto locations = get_locations_in_small_component(); + +// TripParameters params; +// params.skip_waypoints = true; +// params.coordinates.push_back(locations.at(0)); +// params.coordinates.push_back(locations.at(1)); +// params.coordinates.push_back(locations.at(2)); + +// engine::api::ResultT result = flatbuffers::FlatBufferBuilder(); +// const auto rc = osrm.Trip(params, result); +// BOOST_CHECK(rc == Status::Ok); + +// auto &fb_result = std::get(result); +// auto fb = engine::api::fbresult::GetFBResult(fb_result.GetBufferPointer()); + +// BOOST_CHECK(!fb->error()); + +// BOOST_CHECK(fb->waypoints() == nullptr); +// } + +// BOOST_AUTO_TEST_SUITE_END() diff --git a/unit_tests/library/waypoint_check.hpp b/unit_tests/library/waypoint_check.hpp index 9a84eb16b..df5465c48 100644 --- a/unit_tests/library/waypoint_check.hpp +++ b/unit_tests/library/waypoint_check.hpp @@ -5,19 +5,20 @@ #include "osrm/coordinate.hpp" #include "osrm/json_container.hpp" #include "util/exception.hpp" +#include inline bool waypoint_check(osrm::json::Value waypoint) { using namespace osrm; - if (!waypoint.is>()) + if (!std::holds_alternative(waypoint)) { throw util::exception("Must pass in a waypoint object"); } const auto waypoint_object = std::get(waypoint); const auto waypoint_location = std::get(waypoint_object.values.at("location")).values; - util::FloatLongitude lon{waypoint_std::get(location[0]).value}; - util::FloatLatitude lat{waypoint_std::get(location[1]).value}; + util::FloatLongitude lon{std::get(waypoint_location[0]).value}; + util::FloatLatitude lat{std::get(waypoint_location[1]).value}; util::Coordinate location_coordinate(lon, lat); return location_coordinate.IsValid(); }