From 206cb532bb0c9657103af69be0db12de24a0f3d2 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sat, 25 May 2024 19:07:58 +0200 Subject: [PATCH] wip --- include/engine/api/base_result.hpp | 3 +- include/engine/api/route_api.hpp | 7 +- include/extractor/internal_extractor_edge.hpp | 2 +- include/extractor/maneuver_override.hpp | 2 +- include/extractor/turn_path.hpp | 78 +- include/nodejs/node_osrm_support.hpp | 7 +- include/server/service/base_service.hpp | 2 +- include/util/json_container.hpp | 10 +- include/util/json_deep_compare.hpp | 22 +- src/benchmarks/match.cpp | 2 +- src/nodejs/node_osrm.cpp | 2 +- unit_tests/library/match.cpp | 13 +- unit_tests/library/route.cpp | 43 +- unit_tests/library/table.cpp | 2 +- unit_tests/library/trip.cpp | 1134 ++++++++--------- unit_tests/library/waypoint_check.hpp | 3 +- 16 files changed, 665 insertions(+), 667 deletions(-) diff --git a/include/engine/api/base_result.hpp b/include/engine/api/base_result.hpp index 801066a9dc0..76d083d6fa1 100644 --- a/include/engine/api/base_result.hpp +++ b/include/engine/api/base_result.hpp @@ -10,8 +10,7 @@ namespace osrm::engine::api { -using ResultT = - std::variant; +using ResultT = std::variant; } // namespace osrm::engine::api #endif diff --git a/include/engine/api/route_api.hpp b/include/engine/api/route_api.hpp index 7f5c74da278..476c0a501c0 100644 --- a/include/engine/api/route_api.hpp +++ b/include/engine/api/route_api.hpp @@ -159,7 +159,7 @@ class RouteAPI : public BaseAPI template std::variant, - flatbuffers::Offset>> + flatbuffers::Offset>> MakeGeometry(flatbuffers::FlatBufferBuilder &builder, ForwardIter begin, ForwardIter end) const { if (parameters.geometries == RouteParameters::GeometriesType::Polyline) @@ -409,7 +409,7 @@ class RouteAPI : public BaseAPI // Fill geometry auto overview = MakeOverview(leg_geometries); std::variant, - flatbuffers::Offset>> + flatbuffers::Offset>> geometry; if (overview) { @@ -426,8 +426,7 @@ class RouteAPI : public BaseAPI routeObject.add_legs(legs_vector); if (overview) { - std::visit(GeometryVisitor(routeObject), - geometry); + std::visit(GeometryVisitor(routeObject), geometry); } return routeObject.Finish(); diff --git a/include/extractor/internal_extractor_edge.hpp b/include/extractor/internal_extractor_edge.hpp index 32242252ade..453e15d0d0a 100644 --- a/include/extractor/internal_extractor_edge.hpp +++ b/include/extractor/internal_extractor_edge.hpp @@ -7,7 +7,7 @@ #include "util/typedefs.hpp" #include -#include +#include #include namespace osrm::extractor diff --git a/include/extractor/maneuver_override.hpp b/include/extractor/maneuver_override.hpp index 49668f2c18e..78eb31021b3 100644 --- a/include/extractor/maneuver_override.hpp +++ b/include/extractor/maneuver_override.hpp @@ -11,7 +11,7 @@ #include "util/std_hash.hpp" #include "util/vector_view.hpp" -#include +#include #include diff --git a/include/extractor/turn_path.hpp b/include/extractor/turn_path.hpp index 004036d593a..5747f620cfe 100644 --- a/include/extractor/turn_path.hpp +++ b/include/extractor/turn_path.hpp @@ -4,7 +4,7 @@ #include "util/typedefs.hpp" #include -#include +#include #include namespace osrm::extractor @@ -61,50 +61,50 @@ struct InputViaWayPath struct InputTurnPath { - mapbox::util::variant node_or_way; + std::variant node_or_way; TurnPathType Type() const { - BOOST_ASSERT(node_or_way.which() < TurnPathType::NUM_TURN_PATH_TYPES); - return static_cast(node_or_way.which()); + BOOST_ASSERT(node_or_way.index() < TurnPathType::NUM_TURN_PATH_TYPES); + return static_cast(node_or_way.index()); } OSMWayID From() const { - return node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH - ? mapbox::util::get(node_or_way).from - : mapbox::util::get(node_or_way).from; + return node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH + ? std::get(node_or_way).from + : std::get(node_or_way).from; } OSMWayID To() const { - return node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH - ? mapbox::util::get(node_or_way).to - : mapbox::util::get(node_or_way).to; + return node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH + ? std::get(node_or_way).to + : std::get(node_or_way).to; } InputViaWayPath &AsViaWayPath() { - BOOST_ASSERT(node_or_way.which() == TurnPathType::VIA_WAY_TURN_PATH); - return mapbox::util::get(node_or_way); + BOOST_ASSERT(node_or_way.index() == TurnPathType::VIA_WAY_TURN_PATH); + return std::get(node_or_way); } const InputViaWayPath &AsViaWayPath() const { - BOOST_ASSERT(node_or_way.which() == TurnPathType::VIA_WAY_TURN_PATH); - return mapbox::util::get(node_or_way); + BOOST_ASSERT(node_or_way.index() == TurnPathType::VIA_WAY_TURN_PATH); + return std::get(node_or_way); } InputViaNodePath &AsViaNodePath() { - BOOST_ASSERT(node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH); - return mapbox::util::get(node_or_way); + BOOST_ASSERT(node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH); + return std::get(node_or_way); } const InputViaNodePath &AsViaNodePath() const { - BOOST_ASSERT(node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH); - return mapbox::util::get(node_or_way); + BOOST_ASSERT(node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH); + return std::get(node_or_way); } }; @@ -175,63 +175,63 @@ struct ViaWayPath // between node/way paths struct TurnPath { - mapbox::util::variant node_or_way; + std::variant node_or_way; NodeID To() const { - return node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH - ? mapbox::util::get(node_or_way).to - : mapbox::util::get(node_or_way).to; + return node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH + ? std::get(node_or_way).to + : std::get(node_or_way).to; } NodeID From() const { - return node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH - ? mapbox::util::get(node_or_way).from - : mapbox::util::get(node_or_way).from; + return node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH + ? std::get(node_or_way).from + : std::get(node_or_way).from; } NodeID FirstVia() const { - if (node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH) + if (node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH) { - return mapbox::util::get(node_or_way).via; + return std::get(node_or_way).via; } else { - BOOST_ASSERT(!mapbox::util::get(node_or_way).via.empty()); - return mapbox::util::get(node_or_way).via[0]; + BOOST_ASSERT(!std::get(node_or_way).via.empty()); + return std::get(node_or_way).via[0]; } } ViaWayPath &AsViaWayPath() { - BOOST_ASSERT(node_or_way.which() == TurnPathType::VIA_WAY_TURN_PATH); - return mapbox::util::get(node_or_way); + BOOST_ASSERT(node_or_way.index() == TurnPathType::VIA_WAY_TURN_PATH); + return std::get(node_or_way); } const ViaWayPath &AsViaWayPath() const { - BOOST_ASSERT(node_or_way.which() == TurnPathType::VIA_WAY_TURN_PATH); - return mapbox::util::get(node_or_way); + BOOST_ASSERT(node_or_way.index() == TurnPathType::VIA_WAY_TURN_PATH); + return std::get(node_or_way); } ViaNodePath &AsViaNodePath() { - BOOST_ASSERT(node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH); - return mapbox::util::get(node_or_way); + BOOST_ASSERT(node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH); + return std::get(node_or_way); } const ViaNodePath &AsViaNodePath() const { - BOOST_ASSERT(node_or_way.which() == TurnPathType::VIA_NODE_TURN_PATH); - return mapbox::util::get(node_or_way); + BOOST_ASSERT(node_or_way.index() == TurnPathType::VIA_NODE_TURN_PATH); + return std::get(node_or_way); } TurnPathType Type() const { - BOOST_ASSERT(node_or_way.which() < TurnPathType::NUM_TURN_PATH_TYPES); - return static_cast(node_or_way.which()); + BOOST_ASSERT(node_or_way.index() < TurnPathType::NUM_TURN_PATH_TYPES); + return static_cast(node_or_way.index()); } bool operator==(const TurnPath &other) const diff --git a/include/nodejs/node_osrm_support.hpp b/include/nodejs/node_osrm_support.hpp index 4376e642a57..a8fb7412cc5 100644 --- a/include/nodejs/node_osrm_support.hpp +++ b/include/nodejs/node_osrm_support.hpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -51,7 +52,7 @@ struct PluginParameters bool renderToBuffer = false; }; -using ObjectOrString = typename mapbox::util::variant; +using ObjectOrString = typename std::variant; template inline Napi::Value render(const Napi::Env &env, const ResultT &result); @@ -62,7 +63,7 @@ template <> Napi::Value inline render(const Napi::Env &env, const std::string &r template <> Napi::Value inline render(const Napi::Env &env, const ObjectOrString &result) { - if (result.is()) + if (std::holds_alternative(result)) { // Convert osrm::json object tree into matching v8 object tree Napi::Value value; @@ -96,7 +97,7 @@ inline void ParseResult(const osrm::Status &result_status, osrm::json::Object &r if (result_status == osrm::Status::Error) { - throw std::logic_error(code_iter->second.get().value.c_str()); + throw std::logic_error(std::get(code_iter->second).value.c_str()); } result.values.erase(code_iter); diff --git a/include/server/service/base_service.hpp b/include/server/service/base_service.hpp index 4a5db6db12e..5e52a2e0933 100644 --- a/include/server/service/base_service.hpp +++ b/include/server/service/base_service.hpp @@ -5,7 +5,7 @@ #include "osrm/osrm.hpp" #include "util/coordinate.hpp" -#include +#include #include #include diff --git a/include/util/json_container.hpp b/include/util/json_container.hpp index 3bc798f2e65..d6a0291ac77 100644 --- a/include/util/json_container.hpp +++ b/include/util/json_container.hpp @@ -31,11 +31,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef JSON_CONTAINER_HPP #define JSON_CONTAINER_HPP -#include #include #include #include #include +#include #include namespace osrm::util::json @@ -96,13 +96,7 @@ struct Null * * Dispatch on its type by either by using apply_visitor or its get function. */ -using Value = std::variant; +using Value = std::variant; /** * Typed Object. diff --git a/include/util/json_deep_compare.hpp b/include/util/json_deep_compare.hpp index f82336ab356..24b226ca7f8 100644 --- a/include/util/json_deep_compare.hpp +++ b/include/util/json_deep_compare.hpp @@ -81,10 +81,10 @@ struct Comparator const auto &rhs_child = rhs.values.find(key)->second; const auto &lhs_child = lhs.values.find(key)->second; - auto is_same = std::visit( - Comparator(reason, lhs_path + "." + key, rhs_path + "." + key), - lhs_child, - rhs_child); + auto is_same = + std::visit(Comparator(reason, lhs_path + "." + key, rhs_path + "." + key), + lhs_child, + rhs_child); if (!is_same) { return false; @@ -104,12 +104,11 @@ struct Comparator for (auto i = 0UL; i < lhs.values.size(); ++i) { - auto is_same = - std::visit(Comparator(reason, - lhs_path + "[" + std::to_string(i) + "]", - rhs_path + "[" + std::to_string(i) + "]"), - lhs.values[i], - rhs.values[i]); + auto is_same = std::visit(Comparator(reason, + lhs_path + "[" + std::to_string(i) + "]", + rhs_path + "[" + std::to_string(i) + "]"), + lhs.values[i], + rhs.values[i]); if (!is_same) { return false; @@ -151,8 +150,7 @@ struct Comparator inline bool compare(const Value &reference, const Value &result, std::string &reason) { - return std::visit( - Comparator(reason, "reference", "result"), reference, result); + return std::visit(Comparator(reason, "reference", "result"), reference, result); } } // namespace osrm::util::json diff --git a/src/benchmarks/match.cpp b/src/benchmarks/match.cpp index 5292f1691c4..47a9b12b4d6 100644 --- a/src/benchmarks/match.cpp +++ b/src/benchmarks/match.cpp @@ -234,7 +234,7 @@ try const auto rc = osrm.Match(params, result); auto &json_result = std::get(result); if (rc != Status::Ok || - json_result.values.at("matchings").get().values.size() != 1) + std::get(json_result.values.at("matchings")).values.size() != 1) { throw std::runtime_error{"Couldn't match"}; } diff --git a/src/nodejs/node_osrm.cpp b/src/nodejs/node_osrm.cpp index 80aa06e89fa..65585abacbf 100644 --- a/src/nodejs/node_osrm.cpp +++ b/src/nodejs/node_osrm.cpp @@ -147,7 +147,7 @@ inline void async(const Napi::CallbackInfo &info, osrm::engine::api::ResultT r; r = osrm::util::json::Object(); const auto status = ((*osrm).*(service))(*params, r); - auto &json_result = r.get(); + auto &json_result = std::get(r); ParseResult(status, json_result); if (pluginParams.renderToBuffer) { diff --git a/unit_tests/library/match.cpp b/unit_tests/library/match.cpp index 887c7a37100..73dfb03ea89 100644 --- a/unit_tests/library/match.cpp +++ b/unit_tests/library/match.cpp @@ -64,11 +64,10 @@ void test_match(bool use_json_only_api) std::get(waypoint_object.values.at("matchings_index")).value; const auto waypoint_index = std::get(waypoint_object.values.at("waypoint_index")).value; - const auto &route_legs = std::get(std::get(matchings[matchings_index] - ) - .values.at("legs") - ) - .values; + const auto &route_legs = + std::get( + std::get(matchings[matchings_index]).values.at("legs")) + .values; BOOST_CHECK_LT(waypoint_index, route_legs.size() + 1); BOOST_CHECK_LT(matchings_index, number_of_matchings); } @@ -122,7 +121,7 @@ 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 =std::get(json_result.values.at("tracepoints")).values; + const auto &tracepoints = std::get(json_result.values.at("tracepoints")).values; BOOST_CHECK_EQUAL(tracepoints.size(), params.coordinates.size()); const auto &matchings = std::get(json_result.values.at("matchings")).values; @@ -136,7 +135,7 @@ void test_match_split(bool use_json_only_api) BOOST_CHECK(waypoint_check(waypoint)); const auto &waypoint_object = std::get(waypoint); const auto matchings_index = - std::get(waypoint_object.values.at("matchings_index")).value; + std::get(waypoint_object.values.at("matchings_index")).value; const auto waypoint_index = std::get(waypoint_object.values.at("waypoint_index")).value; diff --git a/unit_tests/library/route.cpp b/unit_tests/library/route.cpp index 79291ba044f..8df0ae9c22a 100644 --- a/unit_tests/library/route.cpp +++ b/unit_tests/library/route.cpp @@ -54,8 +54,8 @@ void test_route_same_coordinates_fixture(bool use_json_only_api) std::get(itr).values["hint"] = ""; // Round value to 6 decimal places for double comparison later - std::get(itr).values["distance"] = - round(std::get(std::get(itr).values["distance"]).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}}}; @@ -221,14 +221,17 @@ void test_route_same_coordinates(bool use_json_only_api) { const auto &step_object = std::get(step); - const auto distance = std::get(step_object.values.at("distance")).value; + const auto distance = + std::get(step_object.values.at("distance")).value; BOOST_CHECK_EQUAL(distance, 0); - const auto duration = std::get(step_object.values.at("duration")).value; + const auto duration = + std::get(step_object.values.at("duration")).value; BOOST_CHECK_EQUAL(duration, 0); // geometries=polyline by default - const auto geometry = std::get(step_object.values.at("geometry")).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 @@ -239,7 +242,8 @@ void test_route_same_coordinates(bool use_json_only_api) const auto mode = std::get(step_object.values.at("mode")).value; BOOST_CHECK(!name.empty()); - const auto &maneuver = std::get(step_object.values.at("maneuver")).values; + const auto &maneuver = + std::get(step_object.values.at("maneuver")).values; const auto type = std::get(maneuver.at("type")).value; BOOST_CHECK(!type.empty()); @@ -260,7 +264,8 @@ void test_route_same_coordinates(bool use_json_only_api) const auto &bearings = std::get(intersection_object.at("bearings")).values; BOOST_CHECK(!bearings.empty()); - const auto &entries = std::get(intersection_object.at("entry")).values; + const auto &entries = + std::get(intersection_object.at("entry")).values; BOOST_CHECK(bearings.size() == entries.size()); for (const auto &bearing : bearings) @@ -274,7 +279,8 @@ void test_route_same_coordinates(bool use_json_only_api) } if (step_count + 1 < steps.size()) { - const auto out = std::get(intersection_object.at("out")).value; + const auto out = + std::get(intersection_object.at("out")).value; BOOST_CHECK(out < bearings.size()); } } @@ -523,7 +529,8 @@ void speed_annotation_matches_duration_and_distance(bool use_json_only_api) BOOST_CHECK(rc == Status::Ok); 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 &legs = + std::get(std::get(routes[0]).values.at("legs")).values; const auto &annotation = std::get(std::get(legs[0]).values.at("annotation")); const auto &speeds = std::get(annotation.values.at("speed")).values; @@ -573,16 +580,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 = std::get( - std::get( - std::get( + auto annotations = + std::get( std::get( - std::get(json_result.values["routes"]) - .values[0]) - .values["legs"]) - .values[0]) -.values["annotation"]) -.values; + 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 3eded2abfcd..e1caafdae25 100644 --- a/unit_tests/library/table.cpp +++ b/unit_tests/library/table.cpp @@ -135,7 +135,7 @@ void test_table_three_coords_one_source_one_dest_matrix_no_waypoints(bool use_js BOOST_CHECK_EQUAL(distances_array.size(), params.sources.size()); for (unsigned int i = 0; i < distances_array.size(); i++) { - const auto distances_matrix =std::get(distances_array[i]).values; + const auto distances_matrix = std::get(distances_array[i]).values; BOOST_CHECK_EQUAL(distances_matrix.size(), params.sources.size() * params.destinations.size()); } diff --git a/unit_tests/library/trip.cpp b/unit_tests/library/trip.cpp index 7e7d7f6bc51..b286a1060df 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 = 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() +#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 = std::get(json_result.values.at("trips")).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 = std::get(waypoint_object.values.at("trips_index")).value; + const auto pos = std::get(waypoint_object.values.at("waypoint_index")).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 = std::get(json_result.values.at("trips")).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 = std::get(waypoint_object.values.at("trips_index")).value; + const auto pos = std::get(waypoint_object.values.at("waypoint_index")).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 = std::get(json_result.values.at("trips")).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 = std::get(waypoint_object.values.at("trips_index")).value; + const auto pos = std::get(waypoint_object.values.at("waypoint_index")).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 = std::get(json_result.values.at("trips")).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 = std::get(waypoint_object.values.at("trips_index")).value; + const auto pos = std::get(waypoint_object.values.at("waypoint_index")).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 = std::get(json_result.values.at("trips")).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 = std::get(waypoint_object.values.at("trips_index")).value; + const auto pos = std::get(waypoint_object.values.at("waypoint_index")).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 = std::get(json_result.values.at("code")).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 = std::get(json_result.values.at("code")).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 df5465c483b..bda7dfc8c97 100644 --- a/unit_tests/library/waypoint_check.hpp +++ b/unit_tests/library/waypoint_check.hpp @@ -16,7 +16,8 @@ inline bool waypoint_check(osrm::json::Value 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; + const auto waypoint_location = + std::get(waypoint_object.values.at("location")).values; util::FloatLongitude lon{std::get(waypoint_location[0]).value}; util::FloatLatitude lat{std::get(waypoint_location[1]).value}; util::Coordinate location_coordinate(lon, lat);