From bf06066796228447b6e1e3005c4daf4d252d7f62 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sun, 30 Jun 2024 19:24:54 +0200 Subject: [PATCH 1/9] Yet another attempt to get rid of boost::optional --- include/engine/api/base_parameters.hpp | 20 ++++---- include/engine/api/json_factory.hpp | 2 +- include/engine/api/nearest_api.hpp | 2 +- include/engine/api/route_api.hpp | 13 +++--- include/engine/api/route_parameters.hpp | 12 ++--- .../contiguous_internalmem_datafacade.hpp | 12 ++--- include/engine/datafacade/datafacade_base.hpp | 10 ++-- include/engine/engine_config.hpp | 2 +- include/engine/geospatial_query.hpp | 16 +++---- include/engine/internal_route_result.hpp | 2 +- include/engine/plugins/match.hpp | 2 +- include/engine/plugins/nearest.hpp | 2 +- include/engine/plugins/plugin_base.hpp | 16 +++---- include/engine/plugins/table.hpp | 2 +- include/engine/plugins/trip.hpp | 2 +- include/engine/plugins/viaroute.hpp | 2 +- include/engine/routing_algorithms.hpp | 12 ++--- .../routing_algorithms/map_matching.hpp | 2 +- .../routing_algorithms/routing_base.hpp | 4 +- .../routing_algorithms/shortest_path.hpp | 2 +- .../routing_algorithms/shortest_path_impl.hpp | 10 ++-- include/nodejs/node_osrm_support.hpp | 8 ++-- .../server/api/base_parameters_grammar.hpp | 24 +++++++--- include/server/api/parameters_parser.hpp | 6 +-- include/server/api/url_parser.hpp | 4 +- src/benchmarks/bench.cpp | 4 +- src/benchmarks/route.cpp | 4 +- src/engine/api/json_factory.cpp | 2 +- src/engine/engine_config.cpp | 16 +++---- src/engine/plugins/match.cpp | 2 +- src/engine/plugins/nearest.cpp | 2 +- src/engine/plugins/table.cpp | 2 +- src/engine/plugins/viaroute.cpp | 2 +- .../routing_algorithms/map_matching.cpp | 32 ++++++------- .../routing_algorithms/shortest_path.cpp | 4 +- src/server/api/parameters_parser.cpp | 30 ++++++------ src/server/api/url_parser.cpp | 6 +-- src/tools/routed.cpp | 2 +- .../engine/collapse_internal_route_result.cpp | 26 +++++------ unit_tests/engine/offline_facade.cpp | 10 ++-- unit_tests/library/table.cpp | 4 +- unit_tests/mocks/mock_datafacade.hpp | 10 ++-- unit_tests/server/parameters_parser.cpp | 46 +++++++++---------- unit_tests/util/static_rtree.cpp | 22 ++++----- 44 files changed, 210 insertions(+), 205 deletions(-) diff --git a/include/engine/api/base_parameters.hpp b/include/engine/api/base_parameters.hpp index d7422566f0a..905cb69eeff 100644 --- a/include/engine/api/base_parameters.hpp +++ b/include/engine/api/base_parameters.hpp @@ -74,12 +74,12 @@ struct BaseParameters }; std::vector coordinates; - std::vector> hints; - std::vector> radiuses; - std::vector> bearings; - std::vector> approaches; + std::vector> hints; + std::vector> radiuses; + std::vector> bearings; + std::vector> approaches; std::vector exclude; - boost::optional format = OutputFormatType::JSON; + std::optional format = OutputFormatType::JSON; // Adds hints to response which can be included in subsequent requests, see `hints` above. bool generate_hints = true; @@ -90,10 +90,10 @@ struct BaseParameters SnappingType snapping = SnappingType::Default; BaseParameters(std::vector coordinates_ = {}, - std::vector> hints_ = {}, - std::vector> radiuses_ = {}, - std::vector> bearings_ = {}, - std::vector> approaches_ = {}, + std::vector> hints_ = {}, + std::vector> radiuses_ = {}, + std::vector> bearings_ = {}, + std::vector> approaches_ = {}, bool generate_hints_ = true, std::vector exclude = {}, const SnappingType snapping_ = SnappingType::Default) @@ -112,7 +112,7 @@ struct BaseParameters (approaches.empty() || approaches.size() == coordinates.size()) && std::all_of(bearings.begin(), bearings.end(), - [](const boost::optional &bearing_and_range) + [](const std::optional &bearing_and_range) { if (bearing_and_range) { diff --git a/include/engine/api/json_factory.hpp b/include/engine/api/json_factory.hpp index 1175dcd7e2a..2b32b4446d0 100644 --- a/include/engine/api/json_factory.hpp +++ b/include/engine/api/json_factory.hpp @@ -90,7 +90,7 @@ util::json::Object makeRouteStep(guidance::RouteStep step, util::json::Value geo util::json::Object makeRoute(const guidance::Route &route, util::json::Array legs, - boost::optional geometry, + std::optional geometry, const char *weight_name); // Creates a Waypoint without Hint, see the Hint overload below diff --git a/include/engine/api/nearest_api.hpp b/include/engine/api/nearest_api.hpp index beae38cec33..0e2a9edbfdf 100644 --- a/include/engine/api/nearest_api.hpp +++ b/include/engine/api/nearest_api.hpp @@ -45,7 +45,7 @@ class NearestAPI final : public BaseAPI flatbuffers::FlatBufferBuilder &fb_result) const { auto data_timestamp = facade.GetTimestamp(); - boost::optional> data_version_string = boost::none; + std::optional> data_version_string = std::nullopt; if (!data_timestamp.empty()) { data_version_string = fb_result.CreateString(data_timestamp); diff --git a/include/engine/api/route_api.hpp b/include/engine/api/route_api.hpp index 211be7f8d19..fb1830ce361 100644 --- a/include/engine/api/route_api.hpp +++ b/include/engine/api/route_api.hpp @@ -184,10 +184,10 @@ class RouteAPI : public BaseAPI return builder.CreateVectorOfStructs(coordinates); } - boost::optional - MakeGeometry(boost::optional> &&annotations) const + std::optional + MakeGeometry(std::optional> &&annotations) const { - boost::optional json_geometry; + std::optional json_geometry; if (annotations) { auto begin = annotations->begin(); @@ -720,8 +720,7 @@ class RouteAPI : public BaseAPI std::vector &leg_geometries = legs_info.second; auto route = guidance::assembleRoute(legs); - boost::optional json_overview = - MakeGeometry(MakeOverview(leg_geometries)); + std::optional json_overview = MakeGeometry(MakeOverview(leg_geometries)); std::vector step_geometries; const auto total_step_count = @@ -997,10 +996,10 @@ class RouteAPI : public BaseAPI return result; } - boost::optional> + std::optional> MakeOverview(const std::vector &leg_geometries) const { - boost::optional> overview; + std::optional> overview; if (parameters.overview != RouteParameters::OverviewType::False) { const auto use_simplification = diff --git a/include/engine/api/route_parameters.hpp b/include/engine/api/route_parameters.hpp index 267058a46bc..a28f34b8c7c 100644 --- a/include/engine/api/route_parameters.hpp +++ b/include/engine/api/route_parameters.hpp @@ -82,7 +82,7 @@ struct RouteParameters : public BaseParameters const bool alternatives_, const GeometriesType geometries_, const OverviewType overview_, - const boost::optional continue_straight_, + const std::optional continue_straight_, Args &&...args_) // Once we perfectly-forward `args` (see #2990) this constructor can delegate to the one // below. @@ -100,7 +100,7 @@ struct RouteParameters : public BaseParameters const bool annotations_, const GeometriesType geometries_, const OverviewType overview_, - const boost::optional continue_straight_, + const std::optional continue_straight_, Args &&...args_) : BaseParameters{std::forward(args_)...}, steps{steps_}, alternatives{alternatives_}, number_of_alternatives{alternatives_ ? 1u : 0u}, annotations{annotations_}, @@ -118,7 +118,7 @@ struct RouteParameters : public BaseParameters const AnnotationsType annotations_, const GeometriesType geometries_, const OverviewType overview_, - const boost::optional continue_straight_, + const std::optional continue_straight_, Args &&...args_) : BaseParameters{std::forward(args_)...}, steps{steps_}, alternatives{alternatives_}, number_of_alternatives{alternatives_ ? 1u : 0u}, @@ -135,7 +135,7 @@ struct RouteParameters : public BaseParameters const bool annotations_, const GeometriesType geometries_, const OverviewType overview_, - const boost::optional continue_straight_, + const std::optional continue_straight_, std::vector waypoints_, const Args &&...args_) : BaseParameters{std::forward(args_)...}, steps{steps_}, alternatives{alternatives_}, @@ -153,7 +153,7 @@ struct RouteParameters : public BaseParameters const AnnotationsType annotations_, const GeometriesType geometries_, const OverviewType overview_, - const boost::optional continue_straight_, + const std::optional continue_straight_, std::vector waypoints_, Args &&...args_) : BaseParameters{std::forward(args_)...}, steps{steps_}, alternatives{alternatives_}, @@ -172,7 +172,7 @@ struct RouteParameters : public BaseParameters AnnotationsType annotations_type = AnnotationsType::None; GeometriesType geometries = GeometriesType::Polyline; OverviewType overview = OverviewType::Simplified; - boost::optional continue_straight; + std::optional continue_straight; std::vector waypoints; bool IsValid() const diff --git a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp index 7a495e86fe5..466c566942d 100644 --- a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp +++ b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp @@ -369,7 +369,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade std::vector NearestPhantomNodesInRange(const util::Coordinate input_coordinate, const double max_distance, - const boost::optional bearing, + const std::optional bearing, const Approach approach, const bool use_all_edges) const override final { @@ -382,20 +382,20 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade std::vector NearestPhantomNodes(const util::Coordinate input_coordinate, const size_t max_results, - const boost::optional max_distance, - const boost::optional bearing, + const std::optional max_distance, + const std::optional bearing, const Approach approach) const override final { BOOST_ASSERT(m_geospatial_query.get()); return m_geospatial_query->NearestPhantomNodes( - input_coordinate, approach, max_results, max_distance, bearing, boost::none); + input_coordinate, approach, max_results, max_distance, bearing, std::nullopt); } PhantomCandidateAlternatives NearestCandidatesWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, - const boost::optional max_distance, - const boost::optional bearing, + const std::optional max_distance, + const std::optional bearing, const Approach approach, const bool use_all_edges) const override final { diff --git a/include/engine/datafacade/datafacade_base.hpp b/include/engine/datafacade/datafacade_base.hpp index 2d110e7dad2..581aadd01cf 100644 --- a/include/engine/datafacade/datafacade_base.hpp +++ b/include/engine/datafacade/datafacade_base.hpp @@ -126,21 +126,21 @@ class BaseDataFacade virtual std::vector NearestPhantomNodesInRange(const util::Coordinate input_coordinate, const double max_distance, - const boost::optional bearing, + const std::optional bearing, const Approach approach, const bool use_all_edges) const = 0; virtual std::vector NearestPhantomNodes(const util::Coordinate input_coordinate, const size_t max_results, - const boost::optional max_distance, - const boost::optional bearing, + const std::optional max_distance, + const std::optional bearing, const Approach approach) const = 0; virtual PhantomCandidateAlternatives NearestCandidatesWithAlternativeFromBigComponent(const util::Coordinate input_coordinate, - const boost::optional max_distance, - const boost::optional bearing, + const std::optional max_distance, + const std::optional bearing, const Approach approach, const bool use_all_edges) const = 0; diff --git a/include/engine/engine_config.hpp b/include/engine/engine_config.hpp index 439ec8aa6c0..e46f2c5e2ba 100644 --- a/include/engine/engine_config.hpp +++ b/include/engine/engine_config.hpp @@ -79,7 +79,7 @@ struct EngineConfig final int max_locations_map_matching = -1; double max_radius_map_matching = -1.0; int max_results_nearest = -1; - boost::optional default_radius = -1.0; + double default_radius = -1.0; int max_alternatives = 3; // set an arbitrary upper bound; can be adjusted by user bool use_shared_memory = true; std::filesystem::path memory_file; diff --git a/include/engine/geospatial_query.hpp b/include/engine/geospatial_query.hpp index c4efbcbbbe0..46bcd01714a 100644 --- a/include/engine/geospatial_query.hpp +++ b/include/engine/geospatial_query.hpp @@ -53,8 +53,8 @@ template class GeospatialQuery NearestPhantomNodes(const util::Coordinate input_coordinate, const Approach approach, const double max_distance, - const boost::optional bearing_with_range, - const boost::optional use_all_edges) const + const std::optional bearing_with_range, + const std::optional use_all_edges) const { auto results = rtree.SearchInRange( input_coordinate, @@ -85,9 +85,9 @@ template class GeospatialQuery NearestPhantomNodes(const util::Coordinate input_coordinate, const Approach approach, const size_t max_results, - const boost::optional max_distance, - const boost::optional bearing_with_range, - const boost::optional use_all_edges) const + const std::optional max_distance, + const std::optional bearing_with_range, + const std::optional use_all_edges) const { auto results = rtree.Nearest( input_coordinate, @@ -121,9 +121,9 @@ template class GeospatialQuery PhantomCandidateAlternatives NearestCandidatesWithAlternativeFromBigComponent( const util::Coordinate input_coordinate, const Approach approach, - const boost::optional max_distance, - const boost::optional bearing_with_range, - const boost::optional use_all_edges) const + const std::optional max_distance, + const std::optional bearing_with_range, + const std::optional use_all_edges) const { bool has_nearest = false; bool has_big_component = false; diff --git a/include/engine/internal_route_result.hpp b/include/engine/internal_route_result.hpp index e2bc6f47553..2cec335b174 100644 --- a/include/engine/internal_route_result.hpp +++ b/include/engine/internal_route_result.hpp @@ -42,7 +42,7 @@ struct PathData // Source of the speed value on this road segment DatasourceID datasource_id; // If segment precedes a turn, ID of the turn itself - boost::optional turn_edge; + std::optional turn_edge; }; struct InternalRouteResult diff --git a/include/engine/plugins/match.hpp b/include/engine/plugins/match.hpp index d56be60fe0f..bfad1b7787d 100644 --- a/include/engine/plugins/match.hpp +++ b/include/engine/plugins/match.hpp @@ -22,7 +22,7 @@ class MatchPlugin : public BasePlugin MatchPlugin(const int max_locations_map_matching, const double max_radius_map_matching, - const boost::optional default_radius) + const std::optional default_radius) : BasePlugin(default_radius), max_locations_map_matching(max_locations_map_matching), max_radius_map_matching(max_radius_map_matching) { diff --git a/include/engine/plugins/nearest.hpp b/include/engine/plugins/nearest.hpp index 415639b2cc5..caa7463fd6a 100644 --- a/include/engine/plugins/nearest.hpp +++ b/include/engine/plugins/nearest.hpp @@ -13,7 +13,7 @@ namespace osrm::engine::plugins class NearestPlugin final : public BasePlugin { public: - explicit NearestPlugin(const int max_results, const boost::optional default_radius); + explicit NearestPlugin(const int max_results, const std::optional default_radius); Status HandleRequest(const RoutingAlgorithmsInterface &algorithms, const api::NearestParameters ¶ms, diff --git a/include/engine/plugins/plugin_base.hpp b/include/engine/plugins/plugin_base.hpp index 3a98022e98f..fbda1566413 100644 --- a/include/engine/plugins/plugin_base.hpp +++ b/include/engine/plugins/plugin_base.hpp @@ -29,7 +29,7 @@ class BasePlugin protected: BasePlugin() = default; - BasePlugin(const boost::optional default_radius_) : default_radius(default_radius_) {} + BasePlugin(const std::optional default_radius_) : default_radius(default_radius_) {} bool CheckAllCoordinates(const std::vector &coordinates) const { @@ -200,8 +200,8 @@ class BasePlugin phantom_nodes[i] = facade.NearestPhantomNodesInRange( parameters.coordinates[i], radiuses[i], - use_bearings ? parameters.bearings[i] : boost::none, - use_approaches && parameters.approaches[i] ? parameters.approaches[i].get() + use_bearings ? parameters.bearings[i] : std::nullopt, + use_approaches && parameters.approaches[i] ? parameters.approaches[i].value() : engine::Approach::UNRESTRICTED, use_all_edges); } @@ -242,8 +242,8 @@ class BasePlugin parameters.coordinates[i], number_of_results, use_radiuses ? parameters.radiuses[i] : default_radius, - use_bearings ? parameters.bearings[i] : boost::none, - use_approaches && parameters.approaches[i] ? parameters.approaches[i].get() + use_bearings ? parameters.bearings[i] : std::nullopt, + use_approaches && parameters.approaches[i] ? parameters.approaches[i].value() : engine::Approach::UNRESTRICTED); // we didn't find a fitting node, return error @@ -284,8 +284,8 @@ class BasePlugin alternatives[i] = facade.NearestCandidatesWithAlternativeFromBigComponent( parameters.coordinates[i], use_radiuses ? parameters.radiuses[i] : default_radius, - use_bearings ? parameters.bearings[i] : boost::none, - use_approaches && parameters.approaches[i] ? parameters.approaches[i].get() + use_bearings ? parameters.bearings[i] : std::nullopt, + use_approaches && parameters.approaches[i] ? parameters.approaches[i].value() : engine::Approach::UNRESTRICTED, use_all_edges); @@ -325,7 +325,7 @@ class BasePlugin std::to_string(missing_index); } - const boost::optional default_radius; + const std::optional default_radius; }; } // namespace osrm::engine::plugins diff --git a/include/engine/plugins/table.hpp b/include/engine/plugins/table.hpp index e4cf9a33ce2..9755cff3bdb 100644 --- a/include/engine/plugins/table.hpp +++ b/include/engine/plugins/table.hpp @@ -15,7 +15,7 @@ class TablePlugin final : public BasePlugin { public: explicit TablePlugin(const int max_locations_distance_table, - const boost::optional default_radius); + const std::optional default_radius); Status HandleRequest(const RoutingAlgorithmsInterface &algorithms, const api::TableParameters ¶ms, diff --git a/include/engine/plugins/trip.hpp b/include/engine/plugins/trip.hpp index 9cfdab09409..a08eaeed0d7 100644 --- a/include/engine/plugins/trip.hpp +++ b/include/engine/plugins/trip.hpp @@ -32,7 +32,7 @@ class TripPlugin final : public BasePlugin const bool roundtrip) const; public: - explicit TripPlugin(const int max_locations_trip_, boost::optional default_radius) + explicit TripPlugin(const int max_locations_trip_, std::optional default_radius) : BasePlugin(default_radius), max_locations_trip(max_locations_trip_) { } diff --git a/include/engine/plugins/viaroute.hpp b/include/engine/plugins/viaroute.hpp index e036ac90ecd..56040a58fe9 100644 --- a/include/engine/plugins/viaroute.hpp +++ b/include/engine/plugins/viaroute.hpp @@ -27,7 +27,7 @@ class ViaRoutePlugin final : public BasePlugin public: explicit ViaRoutePlugin(int max_locations_viaroute, int max_alternatives, - boost::optional default_radius); + std::optional default_radius); Status HandleRequest(const RoutingAlgorithmsInterface &algorithms, const api::RouteParameters &route_parameters, diff --git a/include/engine/routing_algorithms.hpp b/include/engine/routing_algorithms.hpp index 93c310a4a62..1be8020c4f0 100644 --- a/include/engine/routing_algorithms.hpp +++ b/include/engine/routing_algorithms.hpp @@ -25,7 +25,7 @@ class RoutingAlgorithmsInterface virtual InternalRouteResult ShortestPathSearch(const std::vector &waypoint_candidates, - const boost::optional continue_straight_at_waypoint) const = 0; + const std::optional continue_straight_at_waypoint) const = 0; virtual InternalRouteResult DirectShortestPathSearch(const PhantomEndpointCandidates &endpoint_candidates) const = 0; @@ -40,7 +40,7 @@ class RoutingAlgorithmsInterface MapMatching(const routing_algorithms::CandidateLists &candidates_list, const std::vector &trace_coordinates, const std::vector &trace_timestamps, - const std::vector> &trace_gps_precision, + const std::vector> &trace_gps_precision, const bool allow_splitting) const = 0; virtual std::vector @@ -78,7 +78,7 @@ template class RoutingAlgorithms final : public RoutingAlgo InternalRouteResult ShortestPathSearch( const std::vector &waypoint_candidates, - const boost::optional continue_straight_at_waypoint) const final override; + const std::optional continue_straight_at_waypoint) const final override; InternalRouteResult DirectShortestPathSearch( const PhantomEndpointCandidates &endpoint_candidates) const final override; @@ -93,7 +93,7 @@ template class RoutingAlgorithms final : public RoutingAlgo MapMatching(const routing_algorithms::CandidateLists &candidates_list, const std::vector &trace_coordinates, const std::vector &trace_timestamps, - const std::vector> &trace_gps_precision, + const std::vector> &trace_gps_precision, const bool allow_splitting) const final override; std::vector @@ -160,7 +160,7 @@ InternalManyRoutesResult RoutingAlgorithms::AlternativePathSearch( template InternalRouteResult RoutingAlgorithms::ShortestPathSearch( const std::vector &waypoint_candidates, - const boost::optional continue_straight_at_waypoint) const + const std::optional continue_straight_at_waypoint) const { return routing_algorithms::shortestPathSearch( heaps, *facade, waypoint_candidates, continue_straight_at_waypoint); @@ -178,7 +178,7 @@ inline routing_algorithms::SubMatchingList RoutingAlgorithms::MapMatc const routing_algorithms::CandidateLists &candidates_list, const std::vector &trace_coordinates, const std::vector &trace_timestamps, - const std::vector> &trace_gps_precision, + const std::vector> &trace_gps_precision, const bool allow_splitting) const { return routing_algorithms::mapMatching(heaps, diff --git a/include/engine/routing_algorithms/map_matching.hpp b/include/engine/routing_algorithms/map_matching.hpp index c739aac996e..e9bcfac2630 100644 --- a/include/engine/routing_algorithms/map_matching.hpp +++ b/include/engine/routing_algorithms/map_matching.hpp @@ -24,7 +24,7 @@ SubMatchingList mapMatching(SearchEngineData &engine_working_data, const CandidateLists &candidates_list, const std::vector &trace_coordinates, const std::vector &trace_timestamps, - const std::vector> &trace_gps_precision, + const std::vector> &trace_gps_precision, const bool allow_splitting); } // namespace osrm::engine::routing_algorithms diff --git a/include/engine/routing_algorithms/routing_base.hpp b/include/engine/routing_algorithms/routing_base.hpp index 0c61c1c37d2..d4dcdac5867 100644 --- a/include/engine/routing_algorithms/routing_base.hpp +++ b/include/engine/routing_algorithms/routing_base.hpp @@ -258,7 +258,7 @@ void annotatePath(const FacadeT &facade, alias_cast(duration_vector[segment_idx]), {0}, datasource_vector[segment_idx], - boost::none}); + std::nullopt}); } BOOST_ASSERT(!unpacked_path.empty()); @@ -315,7 +315,7 @@ void annotatePath(const FacadeT &facade, alias_cast(duration_vector[segment_idx]), {0}, datasource_vector[segment_idx], - boost::none}); + std::nullopt}); } if (!unpacked_path.empty()) diff --git a/include/engine/routing_algorithms/shortest_path.hpp b/include/engine/routing_algorithms/shortest_path.hpp index 00e85234ace..c9c24b939dd 100644 --- a/include/engine/routing_algorithms/shortest_path.hpp +++ b/include/engine/routing_algorithms/shortest_path.hpp @@ -14,7 +14,7 @@ InternalRouteResult shortestPathSearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &waypoint_candidates, - const boost::optional continue_straight_at_waypoint); + const std::optional continue_straight_at_waypoint); } // namespace osrm::engine::routing_algorithms diff --git a/include/engine/routing_algorithms/shortest_path_impl.hpp b/include/engine/routing_algorithms/shortest_path_impl.hpp index b9e74fd02e1..7f0dcf6bf9a 100644 --- a/include/engine/routing_algorithms/shortest_path_impl.hpp +++ b/include/engine/routing_algorithms/shortest_path_impl.hpp @@ -339,10 +339,10 @@ struct leg_connections { // X_to_Y = i can be read as // sources[i].X is the source of the shortest leg path to target.Y - boost::optional forward_to_forward; - boost::optional reverse_to_forward; - boost::optional forward_to_reverse; - boost::optional reverse_to_reverse; + std::optional forward_to_forward; + std::optional reverse_to_forward; + std::optional forward_to_reverse; + std::optional reverse_to_reverse; }; // Identify which of the source candidates segments is being used for paths to the @@ -771,7 +771,7 @@ InternalRouteResult shortestPathSearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &waypoint_candidates, - const boost::optional continue_straight_at_waypoint) + const std::optional continue_straight_at_waypoint) { const bool allow_uturn_at_waypoint = !(continue_straight_at_waypoint ? *continue_straight_at_waypoint diff --git a/include/nodejs/node_osrm_support.hpp b/include/nodejs/node_osrm_support.hpp index cd0043bb4b6..9326242188d 100644 --- a/include/nodejs/node_osrm_support.hpp +++ b/include/nodejs/node_osrm_support.hpp @@ -395,11 +395,11 @@ inline engine_config_ptr argumentsToEngineConfig(const Napi::CallbackInfo &args) return engine_config; } -inline boost::optional> +inline std::optional> parseCoordinateArray(const Napi::Array &coordinates_array) { Napi::HandleScope scope(coordinates_array.Env()); - boost::optional> resulting_coordinates; + std::optional> resulting_coordinates; std::vector temp_coordinates; for (uint32_t i = 0; i < coordinates_array.Length(); ++i) @@ -450,7 +450,7 @@ parseCoordinateArray(const Napi::Array &coordinates_array) osrm::util::FloatLatitude{std::move(lat)}); } - resulting_coordinates = boost::make_optional(std::move(temp_coordinates)); + resulting_coordinates = std::make_optional(std::move(temp_coordinates)); return resulting_coordinates; } @@ -1023,7 +1023,7 @@ inline bool parseCommonParameters(const Napi::Object &obj, ParamType ¶ms) inline PluginParameters argumentsToPluginParameters( const Napi::CallbackInfo &args, - const boost::optional &output_format = {}) + const std::optional &output_format = {}) { if (args.Length() < 3 || !args[1].IsObject()) { diff --git a/include/server/api/base_parameters_grammar.hpp b/include/server/api/base_parameters_grammar.hpp index 80fda760bca..281021f153c 100644 --- a/include/server/api/base_parameters_grammar.hpp +++ b/include/server/api/base_parameters_grammar.hpp @@ -88,7 +88,7 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar } else { - base_parameters.hints.emplace_back(boost::none); + base_parameters.hints.emplace_back(std::nullopt); } }; @@ -96,7 +96,7 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar [](engine::api::BaseParameters &base_parameters, boost::optional> bearing_range) { - boost::optional bearing; + std::optional bearing; if (bearing_range) { bearing = engine::Bearing{boost::fusion::at_c<0>(*bearing_range), @@ -105,6 +105,17 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar base_parameters.bearings.push_back(std::move(bearing)); }; + const auto add_approach = [](engine::api::BaseParameters &base_parameters, + boost::optional approach) { + base_parameters.approaches.push_back(approach ? std::make_optional(*approach) + : std::nullopt); + }; + + const auto add_radius = [](engine::api::BaseParameters &base_parameters, + boost::optional radius) { + base_parameters.radiuses.push_back(radius ? std::make_optional(*radius) : std::nullopt); + }; + polyline_chars = qi::char_("a-zA-Z0-9_.--[]{}@?|\\%~`^"); base64_char = qi::char_("a-zA-Z0-9--_="); unlimited_rule = qi::lit("unlimited")[qi::_val = std::numeric_limits::infinity()]; @@ -144,9 +155,9 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar ((location_rule % ';') | polyline_rule | polyline6_rule)[ph::bind(&engine::api::BaseParameters::coordinates, qi::_r1) = qi::_1]; - radiuses_rule = qi::lit("radiuses=") > - (-(qi::double_ | unlimited_rule) % - ';')[ph::bind(&engine::api::BaseParameters::radiuses, qi::_r1) = qi::_1]; + radiuses_rule = + qi::lit("radiuses=") > + (-(qi::double_ | unlimited_rule))[ph::bind(add_radius, qi::_r1, qi::_1)] % ';'; hints_rule = qi::lit("hints=") > @@ -170,8 +181,7 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar "curb", engine::Approach::CURB)("opposite", engine::Approach::OPPOSITE); approach_rule = qi::lit("approaches=") > - (-approach_type % - ';')[ph::bind(&engine::api::BaseParameters::approaches, qi::_r1) = qi::_1]; + (-approach_type)[ph::bind(add_approach, qi::_r1, qi::_1)] % ';'; snapping_type.add("default", engine::api::BaseParameters::SnappingType::Default)( "any", engine::api::BaseParameters::SnappingType::Any); diff --git a/include/server/api/parameters_parser.hpp b/include/server/api/parameters_parser.hpp index db16ad77b3a..c6ee4edec12 100644 --- a/include/server/api/parameters_parser.hpp +++ b/include/server/api/parameters_parser.hpp @@ -26,13 +26,13 @@ using is_parameter_t = // Starts parsing and iter and modifies it until iter == end or parsing failed template ::value, int>::type = 0> -boost::optional parseParameters(std::string::iterator &iter, - const std::string::iterator end); +std::optional parseParameters(std::string::iterator &iter, + const std::string::iterator end); // Copy on purpose because we need mutability template ::value, int>::type = 0> -boost::optional parseParameters(std::string options_string) +std::optional parseParameters(std::string options_string) { auto first = options_string.begin(); const auto last = options_string.end(); diff --git a/include/server/api/url_parser.hpp b/include/server/api/url_parser.hpp index 227fddfcb32..36ae758c441 100644 --- a/include/server/api/url_parser.hpp +++ b/include/server/api/url_parser.hpp @@ -11,9 +11,9 @@ namespace osrm::server::api { // Starts parsing and iter and modifies it until iter == end or parsing failed -boost::optional parseURL(std::string::iterator &iter, const std::string::iterator end); +std::optional parseURL(std::string::iterator &iter, const std::string::iterator end); -inline boost::optional parseURL(std::string url_string) +inline std::optional parseURL(std::string url_string) { auto iter = url_string.begin(); return parseURL(iter, url_string.end()); diff --git a/src/benchmarks/bench.cpp b/src/benchmarks/bench.cpp index 39a941ed994..019ff645659 100644 --- a/src/benchmarks/bench.cpp +++ b/src/benchmarks/bench.cpp @@ -360,8 +360,8 @@ void runRouteBenchmark(const OSRM &osrm, const GPSTraces &gpsTraces, int iterati if (benchmark.radius) { - params.radiuses = std::vector>( - params.coordinates.size(), boost::make_optional(*benchmark.radius)); + params.radiuses = std::vector>( + params.coordinates.size(), std::make_optional(*benchmark.radius)); } engine::api::ResultT result = json::Object(); diff --git a/src/benchmarks/route.cpp b/src/benchmarks/route.cpp index e63a1039e4c..ada7a1d5e18 100644 --- a/src/benchmarks/route.cpp +++ b/src/benchmarks/route.cpp @@ -66,8 +66,8 @@ try if (benchmark.radius) { - params.radiuses = std::vector>( - params.coordinates.size(), boost::make_optional(*benchmark.radius)); + params.radiuses = std::vector>( + params.coordinates.size(), std::make_optional(*benchmark.radius)); } TIMER_START(routes); diff --git a/src/engine/api/json_factory.cpp b/src/engine/api/json_factory.cpp index 6765c935137..27d01000b24 100644 --- a/src/engine/api/json_factory.cpp +++ b/src/engine/api/json_factory.cpp @@ -215,7 +215,7 @@ util::json::Object makeRouteStep(guidance::RouteStep step, util::json::Value geo util::json::Object makeRoute(const guidance::Route &route, util::json::Array legs, - boost::optional geometry, + std::optional geometry, const char *weight_name) { util::json::Object json_route; diff --git a/src/engine/engine_config.cpp b/src/engine/engine_config.cpp index bfe92841c63..ddc7651d4e9 100644 --- a/src/engine/engine_config.cpp +++ b/src/engine/engine_config.cpp @@ -12,15 +12,13 @@ bool EngineConfig::IsValid() const const auto unlimited_or_more_than = [](const auto v, const auto limit) { return v == -1 || v > limit; }; - const bool limits_valid = - unlimited_or_more_than(max_locations_distance_table, 2) && - unlimited_or_more_than(max_locations_map_matching, 2) && - unlimited_or_more_than(max_radius_map_matching, 0) && - unlimited_or_more_than(max_locations_trip, 2) && - unlimited_or_more_than(max_locations_viaroute, 2) && - unlimited_or_more_than(max_results_nearest, 0) && - (!default_radius.has_value() || unlimited_or_more_than(*default_radius, 0)) && - max_alternatives >= 0; + const bool limits_valid = unlimited_or_more_than(max_locations_distance_table, 2) && + unlimited_or_more_than(max_locations_map_matching, 2) && + unlimited_or_more_than(max_radius_map_matching, 0) && + unlimited_or_more_than(max_locations_trip, 2) && + unlimited_or_more_than(max_locations_viaroute, 2) && + unlimited_or_more_than(max_results_nearest, 0) && + unlimited_or_more_than(default_radius, 0) && max_alternatives >= 0; return ((use_shared_memory && all_path_are_empty) || (use_mmap && storage_config.IsValid()) || storage_config.IsValid()) && diff --git a/src/engine/plugins/match.cpp b/src/engine/plugins/match.cpp index fef9aac4e3f..6fe8f669996 100644 --- a/src/engine/plugins/match.cpp +++ b/src/engine/plugins/match.cpp @@ -194,7 +194,7 @@ Status MatchPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, tidied.parameters.radiuses.begin(), tidied.parameters.radiuses.end(), search_radiuses.begin(), - [default_radius = this->default_radius](const boost::optional &maybe_radius) + [default_radius = this->default_radius](const std::optional &maybe_radius) { if (maybe_radius) { diff --git a/src/engine/plugins/nearest.cpp b/src/engine/plugins/nearest.cpp index 671dbe3f273..b8d43a5a6bd 100644 --- a/src/engine/plugins/nearest.cpp +++ b/src/engine/plugins/nearest.cpp @@ -10,7 +10,7 @@ namespace osrm::engine::plugins { -NearestPlugin::NearestPlugin(const int max_results_, const boost::optional default_radius_) +NearestPlugin::NearestPlugin(const int max_results_, const std::optional default_radius_) : BasePlugin(default_radius_), max_results{max_results_} { } diff --git a/src/engine/plugins/table.cpp b/src/engine/plugins/table.cpp index 4518113053b..5fd214c1a3f 100644 --- a/src/engine/plugins/table.cpp +++ b/src/engine/plugins/table.cpp @@ -15,7 +15,7 @@ namespace osrm::engine::plugins { TablePlugin::TablePlugin(const int max_locations_distance_table, - const boost::optional default_radius) + const std::optional default_radius) : BasePlugin(default_radius), max_locations_distance_table(max_locations_distance_table) { } diff --git a/src/engine/plugins/viaroute.cpp b/src/engine/plugins/viaroute.cpp index a8a1b2ee6f8..a59a2c467e0 100644 --- a/src/engine/plugins/viaroute.cpp +++ b/src/engine/plugins/viaroute.cpp @@ -17,7 +17,7 @@ namespace osrm::engine::plugins ViaRoutePlugin::ViaRoutePlugin(int max_locations_viaroute, int max_alternatives, - boost::optional default_radius) + std::optional default_radius) : BasePlugin(default_radius), max_locations_viaroute(max_locations_viaroute), max_alternatives(max_alternatives) { diff --git a/src/engine/routing_algorithms/map_matching.cpp b/src/engine/routing_algorithms/map_matching.cpp index 41f1f340585..45133551ef7 100644 --- a/src/engine/routing_algorithms/map_matching.cpp +++ b/src/engine/routing_algorithms/map_matching.cpp @@ -70,7 +70,7 @@ SubMatchingList mapMatching(SearchEngineData &engine_working_data, const CandidateLists &candidates_list, const std::vector &trace_coordinates, const std::vector &trace_timestamps, - const std::vector> &trace_gps_precision, + const std::vector> &trace_gps_precision, const bool allow_splitting) { map_matching::MatchingConfidence confidence; @@ -437,24 +437,22 @@ SubMatchingList mapMatching(SearchEngineData &engine_working_data, } // CH -template SubMatchingList -mapMatching(SearchEngineData &engine_working_data, - const DataFacade &facade, - const CandidateLists &candidates_list, - const std::vector &trace_coordinates, - const std::vector &trace_timestamps, - const std::vector> &trace_gps_precision, - const bool allow_splitting); +template SubMatchingList mapMatching(SearchEngineData &engine_working_data, + const DataFacade &facade, + const CandidateLists &candidates_list, + const std::vector &trace_coordinates, + const std::vector &trace_timestamps, + const std::vector> &trace_gps_precision, + const bool allow_splitting); // MLD -template SubMatchingList -mapMatching(SearchEngineData &engine_working_data, - const DataFacade &facade, - const CandidateLists &candidates_list, - const std::vector &trace_coordinates, - const std::vector &trace_timestamps, - const std::vector> &trace_gps_precision, - const bool allow_splitting); +template SubMatchingList mapMatching(SearchEngineData &engine_working_data, + const DataFacade &facade, + const CandidateLists &candidates_list, + const std::vector &trace_coordinates, + const std::vector &trace_timestamps, + const std::vector> &trace_gps_precision, + const bool allow_splitting); } // namespace osrm::engine::routing_algorithms diff --git a/src/engine/routing_algorithms/shortest_path.cpp b/src/engine/routing_algorithms/shortest_path.cpp index fc34810661e..36899631a3b 100644 --- a/src/engine/routing_algorithms/shortest_path.cpp +++ b/src/engine/routing_algorithms/shortest_path.cpp @@ -9,12 +9,12 @@ template InternalRouteResult shortestPathSearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &waypoint_candidates, - const boost::optional continue_straight_at_waypoint); + const std::optional continue_straight_at_waypoint); template InternalRouteResult shortestPathSearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &waypoint_candidates, - const boost::optional continue_straight_at_waypoint); + const std::optional continue_straight_at_waypoint); } // namespace osrm::engine::routing_algorithms diff --git a/src/server/api/parameters_parser.cpp b/src/server/api/parameters_parser.cpp index 7d3db1d16bc..8e3f5027013 100644 --- a/src/server/api/parameters_parser.cpp +++ b/src/server/api/parameters_parser.cpp @@ -28,8 +28,8 @@ template ::value, int>::type = 0, typename std::enable_if::value, int>::type = 0> -boost::optional parseParameters(std::string::iterator &iter, - const std::string::iterator end) +std::optional parseParameters(std::string::iterator &iter, + const std::string::iterator end) { using It = std::decay::type; @@ -56,52 +56,52 @@ boost::optional parseParameters(std::string::iterator &iter, // as normal parser error } - return boost::none; + return std::nullopt; } } // namespace detail template <> -boost::optional parseParameters(std::string::iterator &iter, - const std::string::iterator end) +std::optional parseParameters(std::string::iterator &iter, + const std::string::iterator end) { return detail::parseParameters>(iter, end); } template <> -boost::optional parseParameters(std::string::iterator &iter, - const std::string::iterator end) +std::optional parseParameters(std::string::iterator &iter, + const std::string::iterator end) { return detail::parseParameters>(iter, end); } template <> -boost::optional parseParameters(std::string::iterator &iter, - const std::string::iterator end) +std::optional parseParameters(std::string::iterator &iter, + const std::string::iterator end) { return detail::parseParameters>(iter, end); } template <> -boost::optional parseParameters(std::string::iterator &iter, - const std::string::iterator end) +std::optional parseParameters(std::string::iterator &iter, + const std::string::iterator end) { return detail::parseParameters>(iter, end); } template <> -boost::optional parseParameters(std::string::iterator &iter, - const std::string::iterator end) +std::optional parseParameters(std::string::iterator &iter, + const std::string::iterator end) { return detail::parseParameters>(iter, end); } template <> -boost::optional parseParameters(std::string::iterator &iter, - const std::string::iterator end) +std::optional parseParameters(std::string::iterator &iter, + const std::string::iterator end) { return detail::parseParameters>(iter, end); } diff --git a/src/server/api/url_parser.cpp b/src/server/api/url_parser.cpp index a7323d30846..c870e512ee5 100644 --- a/src/server/api/url_parser.cpp +++ b/src/server/api/url_parser.cpp @@ -65,7 +65,7 @@ struct URLParser final : qi::grammar namespace osrm::server::api { -boost::optional parseURL(std::string::iterator &iter, const std::string::iterator end) +std::optional parseURL(std::string::iterator &iter, const std::string::iterator end) { using It = std::decay::type; @@ -77,7 +77,7 @@ boost::optional parseURL(std::string::iterator &iter, const std::stri const auto ok = boost::spirit::qi::parse(iter, end, parser(boost::phoenix::val(iter)), out); if (ok && iter == end) - return boost::make_optional(out); + return std::make_optional(out); } catch (const qi::expectation_failure &failure) { @@ -86,7 +86,7 @@ boost::optional parseURL(std::string::iterator &iter, const std::stri iter = failure.first; } - return boost::none; + return std::nullopt; } } // namespace osrm::server::api diff --git a/src/tools/routed.cpp b/src/tools/routed.cpp index 07dcf864c06..8c35413f677 100644 --- a/src/tools/routed.cpp +++ b/src/tools/routed.cpp @@ -186,7 +186,7 @@ inline unsigned generateServerProgramOptions(const int argc, value(&config.max_radius_map_matching)->default_value(-1.0), "Max. radius size supported in map matching query. Default: unlimited.") // ("default-radius", - value>(&config.default_radius)->default_value(-1.0), + value(&config.default_radius)->default_value(-1.0), "Default radius size for queries. Default: unlimited."); // hidden options, will be allowed on command line, but will not be shown to the user diff --git a/unit_tests/engine/collapse_internal_route_result.cpp b/unit_tests/engine/collapse_internal_route_result.cpp index 6d00e12d10f..982055279a0 100644 --- a/unit_tests/engine/collapse_internal_route_result.cpp +++ b/unit_tests/engine/collapse_internal_route_result.cpp @@ -19,8 +19,8 @@ BOOST_AUTO_TEST_CASE(unchanged_collapse_route_result) PhantomNode target; source.forward_segment_id = {1, true}; target.forward_segment_id = {6, true}; - PathData pathy{0, 2, {2}, {3}, {4}, {5}, 2, boost::none}; - PathData kathy{0, 1, {1}, {2}, {3}, {4}, 1, boost::none}; + PathData pathy{0, 2, {2}, {3}, {4}, {5}, 2, std::nullopt}; + PathData kathy{0, 1, {1}, {2}, {3}, {4}, 1, std::nullopt}; InternalRouteResult one_leg_result; one_leg_result.unpacked_path_segments = {{pathy, kathy}}; one_leg_result.leg_endpoints = {PhantomEndpoints{source, target}}; @@ -39,9 +39,9 @@ BOOST_AUTO_TEST_CASE(two_legs_to_one_leg) { // from_edge_based_node, turn_via_node, weight_until_turn, weight_of_turn, // duration_until_turn, duration_of_turn, datasource_id, turn_edge - PathData pathy{0, 2, {2}, {3}, {4}, {5}, 2, boost::none}; - PathData kathy{0, 1, {1}, {2}, {3}, {4}, 1, boost::none}; - PathData cathy{0, 3, {1}, {2}, {3}, {4}, 1, boost::none}; + PathData pathy{0, 2, {2}, {3}, {4}, {5}, 2, std::nullopt}; + PathData kathy{0, 1, {1}, {2}, {3}, {4}, 1, std::nullopt}; + PathData cathy{0, 3, {1}, {2}, {3}, {4}, 1, std::nullopt}; PhantomNode node_1; PhantomNode node_2; PhantomNode node_3; @@ -74,11 +74,11 @@ BOOST_AUTO_TEST_CASE(two_legs_to_one_leg) BOOST_AUTO_TEST_CASE(three_legs_to_two_legs) { - PathData pathy{0, 2, {2}, {3}, {4}, {5}, 2, boost::none}; - PathData kathy{0, 1, {1}, {2}, {3}, {4}, 1, boost::none}; - PathData qathy{0, 5, {1}, {2}, {3}, {4}, 1, boost::none}; - PathData cathy{0, 3, {1}, {2}, {3}, {4}, 1, boost::none}; - PathData mathy{0, 4, {8}, {9}, {13}, {4}, 2, boost::none}; + PathData pathy{0, 2, {2}, {3}, {4}, {5}, 2, std::nullopt}; + PathData kathy{0, 1, {1}, {2}, {3}, {4}, 1, std::nullopt}; + PathData qathy{0, 5, {1}, {2}, {3}, {4}, 1, std::nullopt}; + PathData cathy{0, 3, {1}, {2}, {3}, {4}, 1, std::nullopt}; + PathData mathy{0, 4, {8}, {9}, {13}, {4}, 2, std::nullopt}; PhantomNode node_1; PhantomNode node_2; PhantomNode node_3; @@ -131,9 +131,9 @@ BOOST_AUTO_TEST_CASE(three_legs_to_two_legs) BOOST_AUTO_TEST_CASE(two_legs_to_two_legs) { - PathData pathy{0, 2, {2}, {3}, {4}, {5}, 2, boost::none}; - PathData kathy{0, 1, {1}, {2}, {3}, {4}, 1, boost::none}; - PathData cathy{0, 3, {1}, {2}, {3}, {4}, 1, boost::none}; + PathData pathy{0, 2, {2}, {3}, {4}, {5}, 2, std::nullopt}; + PathData kathy{0, 1, {1}, {2}, {3}, {4}, 1, std::nullopt}; + PathData cathy{0, 3, {1}, {2}, {3}, {4}, 1, std::nullopt}; PhantomNode node_1; PhantomNode node_2; PhantomNode node_3; diff --git a/unit_tests/engine/offline_facade.cpp b/unit_tests/engine/offline_facade.cpp index 822d02f4fe6..ae9307e1acc 100644 --- a/unit_tests/engine/offline_facade.cpp +++ b/unit_tests/engine/offline_facade.cpp @@ -219,7 +219,7 @@ class ContiguousInternalMemoryDataFacade std::vector NearestPhantomNodesInRange(const util::Coordinate /*input_coordinate*/, const double /*max_distance*/, - const boost::optional /*bearing*/, + const std::optional /*bearing*/, const engine::Approach /*approach*/, const bool /*use_all_edges*/) const override { @@ -229,8 +229,8 @@ class ContiguousInternalMemoryDataFacade std::vector NearestPhantomNodes(const util::Coordinate /*input_coordinate*/, const size_t /*max_results*/, - const boost::optional /*max_distance*/, - const boost::optional /*bearing*/, + const std::optional /*max_distance*/, + const std::optional /*bearing*/, const engine::Approach /*approach*/) const override { return {}; @@ -238,8 +238,8 @@ class ContiguousInternalMemoryDataFacade engine::PhantomCandidateAlternatives NearestCandidatesWithAlternativeFromBigComponent( const util::Coordinate /*input_coordinate*/, - const boost::optional /*max_distance*/, - const boost::optional /*bearing*/, + const std::optional /*max_distance*/, + const std::optional /*bearing*/, const engine::Approach /*approach*/, const bool /*use_all_edges*/) const override { diff --git a/unit_tests/library/table.cpp b/unit_tests/library/table.cpp index e1caafdae25..c29d58f549a 100644 --- a/unit_tests/library/table.cpp +++ b/unit_tests/library/table.cpp @@ -271,8 +271,8 @@ void test_table_no_segment_for_some_coordinates(bool use_json_only_api) params.coordinates.push_back(get_dummy_location()); params.coordinates.push_back(get_dummy_location()); // resembles query option: `&radiuses=0;` - params.radiuses.push_back(boost::make_optional(0.)); - params.radiuses.push_back(boost::none); + params.radiuses.push_back(std::make_optional(0.)); + params.radiuses.push_back(std::nullopt); json::Object json_result; const auto rc = run_table_json(osrm, params, json_result, use_json_only_api); diff --git a/unit_tests/mocks/mock_datafacade.hpp b/unit_tests/mocks/mock_datafacade.hpp index dc2541713e5..45e9c87f270 100644 --- a/unit_tests/mocks/mock_datafacade.hpp +++ b/unit_tests/mocks/mock_datafacade.hpp @@ -107,7 +107,7 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade std::vector NearestPhantomNodesInRange(const util::Coordinate /*input_coordinate*/, const double /*max_distance*/, - const boost::optional /*bearing*/, + const std::optional /*bearing*/, const engine::Approach /*approach*/, const bool /*use_all_edges*/) const override { @@ -117,8 +117,8 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade std::vector NearestPhantomNodes(const util::Coordinate /*input_coordinate*/, const size_t /*max_results*/, - const boost::optional /*max_distance*/, - const boost::optional /*bearing*/, + const std::optional /*max_distance*/, + const std::optional /*bearing*/, const engine::Approach /*approach*/) const override { return {}; @@ -126,8 +126,8 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade engine::PhantomCandidateAlternatives NearestCandidatesWithAlternativeFromBigComponent( const util::Coordinate /*input_coordinate*/, - const boost::optional /*max_distance*/, - const boost::optional /*bearing*/, + const std::optional /*max_distance*/, + const std::optional /*bearing*/, const engine::Approach /*approach*/, const bool /*use_all_edges*/) const override { diff --git a/unit_tests/server/parameters_parser.cpp b/unit_tests/server/parameters_parser.cpp index 22b03f6fd15..7690c09a9ae 100644 --- a/unit_tests/server/parameters_parser.cpp +++ b/unit_tests/server/parameters_parser.cpp @@ -216,7 +216,7 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) phantom_1.input_location = coords_1[0]; engine::PhantomNode phantom_2; phantom_2.input_location = coords_1[1]; - std::vector> hints_4 = { + std::vector> hints_4 = { engine::Hint{{engine::SegmentHint{phantom_1, 0x1337}}}, engine::Hint{{engine::SegmentHint{phantom_2, 0x1337}}}}; RouteParameters reference_4{false, @@ -224,11 +224,11 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) false, RouteParameters::GeometriesType::Polyline, RouteParameters::OverviewType::Simplified, - boost::optional{}, + std::optional{}, coords_1, hints_4, - std::vector>{}, - std::vector>{}}; + std::vector>{}, + std::vector>{}}; auto result_4 = parseParameters( "1,2;3,4?steps=false&hints=" + hints_4[0]->ToBase64() + ";" + hints_4[1]->ToBase64()); BOOST_CHECK(result_4); @@ -244,8 +244,8 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) CHECK_EQUAL_RANGE(reference_4.coordinates, result_4->coordinates); CHECK_EQUAL_RANGE_OF_HINTS(reference_4.hints, result_4->hints); - std::vector> bearings_4 = { - boost::none, + std::vector> bearings_4 = { + std::nullopt, engine::Bearing{200, 10}, engine::Bearing{100, 5}, }; @@ -254,10 +254,10 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) false, RouteParameters::GeometriesType::Polyline, RouteParameters::OverviewType::Simplified, - boost::optional{}, + std::optional{}, coords_1, - std::vector>{}, - std::vector>{}, + std::vector>{}, + std::vector>{}, bearings_4}; auto result_5 = parseParameters("1,2;3,4?steps=false&bearings=;200,10;100,5"); BOOST_CHECK(result_5); @@ -296,8 +296,8 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) auto result_7 = parseParameters("1,2;3,4?radiuses=;unlimited"); RouteParameters reference_7{}; reference_7.coordinates = coords_1; - reference_7.radiuses = {boost::none, - boost::make_optional(std::numeric_limits::infinity())}; + reference_7.radiuses = {std::nullopt, + std::make_optional(std::numeric_limits::infinity())}; BOOST_CHECK(result_7); BOOST_CHECK_EQUAL(reference_7.steps, result_7->steps); BOOST_CHECK_EQUAL(reference_7.alternatives, result_7->alternatives); @@ -314,14 +314,14 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) auto result_8 = parseParameters("1,2;3,4?radiuses=;"); RouteParameters reference_8{}; reference_8.coordinates = coords_1; - reference_8.radiuses = {boost::none, boost::none}; + reference_8.radiuses = {std::nullopt, std::nullopt}; BOOST_CHECK(result_8); CHECK_EQUAL_RANGE(reference_8.radiuses, result_8->radiuses); auto result_9 = parseParameters("1,2?radiuses="); RouteParameters reference_9{}; reference_9.coordinates = coords_1; - reference_9.radiuses = {boost::none}; + reference_9.radiuses = {std::nullopt}; BOOST_CHECK(result_9); CHECK_EQUAL_RANGE(reference_9.radiuses, result_9->radiuses); @@ -335,7 +335,7 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) phantom_3.input_location = coords_3[0]; engine::PhantomNode phantom_4; phantom_4.input_location = coords_3[2]; - std::vector> hints_10 = { + std::vector> hints_10 = { engine::Hint{{engine::SegmentHint{phantom_3, 0x1337}}}, {}, engine::Hint{{engine::SegmentHint{phantom_4, 0x1337}}}, @@ -346,11 +346,11 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) false, RouteParameters::GeometriesType::Polyline, RouteParameters::OverviewType::Simplified, - boost::optional{}, + std::optional{}, coords_3, hints_10, - std::vector>{}, - std::vector>{}}; + std::vector>{}, + std::vector>{}}; auto result_10 = parseParameters( "1,2;3,4;5,6;7,8?steps=false&hints=" + hints_10[0]->ToBase64() + ";;" + hints_10[2]->ToBase64() + ";"); @@ -447,8 +447,8 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) BOOST_CHECK_EQUAL(result_2->annotations_type == RouteParameters::AnnotationsType::All, true); BOOST_CHECK_EQUAL(result_17->annotations, true); - std::vector> approaches_18 = { - boost::none, + std::vector> approaches_18 = { + std::nullopt, engine::Approach::CURB, engine::Approach::UNRESTRICTED, engine::Approach::OPPOSITE, @@ -458,11 +458,11 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) false, RouteParameters::GeometriesType::Polyline, RouteParameters::OverviewType::Simplified, - boost::optional{}, + std::optional{}, coords_3, - std::vector>{}, - std::vector>{}, - std::vector>{}, + std::vector>{}, + std::vector>{}, + std::vector>{}, approaches_18}; auto result_18 = parseParameters( diff --git a/unit_tests/util/static_rtree.cpp b/unit_tests/util/static_rtree.cpp index d2e29fa2eea..06c75343215 100644 --- a/unit_tests/util/static_rtree.cpp +++ b/unit_tests/util/static_rtree.cpp @@ -332,13 +332,13 @@ BOOST_AUTO_TEST_CASE(radius_regression_test) { auto results = query.NearestPhantomNodes( - input, osrm::engine::Approach::UNRESTRICTED, 0.01, boost::none, true); + input, osrm::engine::Approach::UNRESTRICTED, 0.01, std::nullopt, true); BOOST_CHECK_EQUAL(results.size(), 0); } { auto results = query.NearestPhantomNodes( - input, osrm::engine::Approach::UNRESTRICTED, 1, 0.01, boost::none, true); + input, osrm::engine::Approach::UNRESTRICTED, 1, 0.01, std::nullopt, true); BOOST_CHECK_EQUAL(results.size(), 0); } } @@ -364,25 +364,25 @@ BOOST_AUTO_TEST_CASE(permissive_edge_snapping) { auto results = query.NearestPhantomNodes( - input, osrm::engine::Approach::UNRESTRICTED, 1000, boost::none, false); + input, osrm::engine::Approach::UNRESTRICTED, 1000, std::nullopt, false); BOOST_CHECK_EQUAL(results.size(), 1); } { auto results = query.NearestPhantomNodes( - input, osrm::engine::Approach::UNRESTRICTED, 1000, boost::none, true); + input, osrm::engine::Approach::UNRESTRICTED, 1000, std::nullopt, true); BOOST_CHECK_EQUAL(results.size(), 2); } { auto results = query.NearestPhantomNodes( - input, osrm::engine::Approach::UNRESTRICTED, 10, 1000, boost::none, false); + input, osrm::engine::Approach::UNRESTRICTED, 10, 1000, std::nullopt, false); BOOST_CHECK_EQUAL(results.size(), 1); } { auto results = query.NearestPhantomNodes( - input, osrm::engine::Approach::UNRESTRICTED, 10, 1000, boost::none, true); + input, osrm::engine::Approach::UNRESTRICTED, 10, 1000, std::nullopt, true); BOOST_CHECK_EQUAL(results.size(), 2); } } @@ -408,7 +408,7 @@ BOOST_AUTO_TEST_CASE(bearing_tests) { auto results = query.NearestPhantomNodes( - input, osrm::engine::Approach::UNRESTRICTED, 5, boost::none, boost::none, false); + input, osrm::engine::Approach::UNRESTRICTED, 5, std::nullopt, std::nullopt, false); BOOST_CHECK_EQUAL(results.size(), 2); BOOST_CHECK_EQUAL(results.back().phantom_node.forward_segment_id.id, 0); BOOST_CHECK_EQUAL(results.back().phantom_node.reverse_segment_id.id, 1); @@ -418,7 +418,7 @@ BOOST_AUTO_TEST_CASE(bearing_tests) auto results = query.NearestPhantomNodes(input, osrm::engine::Approach::UNRESTRICTED, 5, - boost::none, + std::nullopt, engine::Bearing{270, 10}, false); BOOST_CHECK_EQUAL(results.size(), 0); @@ -428,7 +428,7 @@ BOOST_AUTO_TEST_CASE(bearing_tests) auto results = query.NearestPhantomNodes(input, osrm::engine::Approach::UNRESTRICTED, 5, - boost::none, + std::nullopt, engine::Bearing{45, 10}, false); BOOST_CHECK_EQUAL(results.size(), 2); @@ -444,13 +444,13 @@ BOOST_AUTO_TEST_CASE(bearing_tests) { auto results = query.NearestPhantomNodes( - input, osrm::engine::Approach::UNRESTRICTED, 11000, boost::none, true); + input, osrm::engine::Approach::UNRESTRICTED, 11000, std::nullopt, true); BOOST_CHECK_EQUAL(results.size(), 2); } { auto results = query.NearestPhantomNodes( - input, osrm::engine::Approach::UNRESTRICTED, 10, 11000, boost::none, true); + input, osrm::engine::Approach::UNRESTRICTED, 10, 11000, std::nullopt, true); BOOST_CHECK_EQUAL(results.size(), 2); } From b8fe5f5e395ea5c4c79de84dddbbcaa3d82e6890 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sun, 30 Jun 2024 19:36:11 +0200 Subject: [PATCH 2/9] Yet another attempt to get rid of boost::optional --- include/engine/api/base_parameters.hpp | 2 +- include/engine/api/json_factory.hpp | 2 +- include/engine/api/trip_parameters.hpp | 2 +- include/engine/geospatial_query.hpp | 2 +- include/engine/guidance/assemble_steps.hpp | 2 +- include/engine/guidance/route_leg.hpp | 2 +- include/engine/internal_route_result.hpp | 2 +- include/engine/routing_algorithms/shortest_path_impl.hpp | 2 +- include/nodejs/node_osrm_support.hpp | 2 +- include/server/api/base_parameters_grammar.hpp | 2 +- include/server/api/url_parser.hpp | 2 +- src/engine/api/json_factory.cpp | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/engine/api/base_parameters.hpp b/include/engine/api/base_parameters.hpp index 905cb69eeff..1a35a030d8b 100644 --- a/include/engine/api/base_parameters.hpp +++ b/include/engine/api/base_parameters.hpp @@ -33,7 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "engine/hint.hpp" #include "util/coordinate.hpp" -#include +#include #include #include diff --git a/include/engine/api/json_factory.hpp b/include/engine/api/json_factory.hpp index 2b32b4446d0..001f44ff851 100644 --- a/include/engine/api/json_factory.hpp +++ b/include/engine/api/json_factory.hpp @@ -12,7 +12,7 @@ #include "util/coordinate.hpp" #include "util/json_container.hpp" -#include +#include #include #include diff --git a/include/engine/api/trip_parameters.hpp b/include/engine/api/trip_parameters.hpp index 7ad785ac097..cc3f4d938a2 100644 --- a/include/engine/api/trip_parameters.hpp +++ b/include/engine/api/trip_parameters.hpp @@ -30,7 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "engine/api/route_parameters.hpp" -#include +#include #include namespace osrm::engine::api diff --git a/include/engine/geospatial_query.hpp b/include/engine/geospatial_query.hpp index 46bcd01714a..915dfec3e63 100644 --- a/include/engine/geospatial_query.hpp +++ b/include/engine/geospatial_query.hpp @@ -12,7 +12,7 @@ #include "osrm/coordinate.hpp" -#include +#include #include #include diff --git a/include/engine/guidance/assemble_steps.hpp b/include/engine/guidance/assemble_steps.hpp index b25b9976d6d..588e402b344 100644 --- a/include/engine/guidance/assemble_steps.hpp +++ b/include/engine/guidance/assemble_steps.hpp @@ -17,9 +17,9 @@ #include "util/guidance/turn_lanes.hpp" #include "util/typedefs.hpp" -#include #include #include +#include #include namespace osrm::engine::guidance diff --git a/include/engine/guidance/route_leg.hpp b/include/engine/guidance/route_leg.hpp index 681c4c40e7d..43149e4fcd1 100644 --- a/include/engine/guidance/route_leg.hpp +++ b/include/engine/guidance/route_leg.hpp @@ -3,7 +3,7 @@ #include "engine/guidance/route_step.hpp" -#include +#include #include #include diff --git a/include/engine/internal_route_result.hpp b/include/engine/internal_route_result.hpp index 2cec335b174..78f5d11967d 100644 --- a/include/engine/internal_route_result.hpp +++ b/include/engine/internal_route_result.hpp @@ -15,7 +15,7 @@ #include "util/integer_range.hpp" #include "util/typedefs.hpp" -#include +#include #include namespace osrm::engine diff --git a/include/engine/routing_algorithms/shortest_path_impl.hpp b/include/engine/routing_algorithms/shortest_path_impl.hpp index 7f0dcf6bf9a..2cd3ccffb5f 100644 --- a/include/engine/routing_algorithms/shortest_path_impl.hpp +++ b/include/engine/routing_algorithms/shortest_path_impl.hpp @@ -4,7 +4,7 @@ #include "engine/routing_algorithms/shortest_path.hpp" #include -#include +#include namespace osrm::engine::routing_algorithms { diff --git a/include/nodejs/node_osrm_support.hpp b/include/nodejs/node_osrm_support.hpp index 9326242188d..f428308e50c 100644 --- a/include/nodejs/node_osrm_support.hpp +++ b/include/nodejs/node_osrm_support.hpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include diff --git a/include/server/api/base_parameters_grammar.hpp b/include/server/api/base_parameters_grammar.hpp index 281021f153c..a09455f9397 100644 --- a/include/server/api/base_parameters_grammar.hpp +++ b/include/server/api/base_parameters_grammar.hpp @@ -7,9 +7,9 @@ #include "engine/hint.hpp" #include "engine/polyline_compressor.hpp" -#include #include #include +#include #include #include diff --git a/include/server/api/url_parser.hpp b/include/server/api/url_parser.hpp index 36ae758c441..84c07bc7b53 100644 --- a/include/server/api/url_parser.hpp +++ b/include/server/api/url_parser.hpp @@ -3,7 +3,7 @@ #include "server/api/parsed_url.hpp" -#include +#include #include diff --git a/src/engine/api/json_factory.cpp b/src/engine/api/json_factory.cpp index 27d01000b24..a17ea77994a 100644 --- a/src/engine/api/json_factory.cpp +++ b/src/engine/api/json_factory.cpp @@ -11,7 +11,7 @@ #include "util/typedefs.hpp" #include -#include +#include #include #include From a021378ca8716055583df5b06c43c0d8aabc5642 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sun, 30 Jun 2024 19:46:32 +0200 Subject: [PATCH 3/9] Yet another attempt to get rid of boost::optional --- include/engine/datafacade/datafacade_base.hpp | 1 + unit_tests/server/parameters_parser.cpp | 1640 ++++++++--------- 2 files changed, 821 insertions(+), 820 deletions(-) diff --git a/include/engine/datafacade/datafacade_base.hpp b/include/engine/datafacade/datafacade_base.hpp index 581aadd01cf..ecf25577a33 100644 --- a/include/engine/datafacade/datafacade_base.hpp +++ b/include/engine/datafacade/datafacade_base.hpp @@ -35,6 +35,7 @@ #include #include +#include #include #include #include diff --git a/unit_tests/server/parameters_parser.cpp b/unit_tests/server/parameters_parser.cpp index 7690c09a9ae..6702a0188c4 100644 --- a/unit_tests/server/parameters_parser.cpp +++ b/unit_tests/server/parameters_parser.cpp @@ -1,820 +1,820 @@ -#include "server/api/parameters_parser.hpp" - -#include "parameters_io.hpp" - -#include "engine/api/base_parameters.hpp" -#include "engine/api/match_parameters.hpp" -#include "engine/api/nearest_parameters.hpp" -#include "engine/api/route_parameters.hpp" -#include "engine/api/table_parameters.hpp" -#include "engine/api/tile_parameters.hpp" -#include "engine/api/trip_parameters.hpp" - -#include "util/debug.hpp" - -#include -#include -#include - -#define CHECK_EQUAL_RANGE(R1, R2) \ - BOOST_CHECK_EQUAL_COLLECTIONS((R1).begin(), (R1).end(), (R2).begin(), (R2).end()); - -#define CHECK_EQUAL_RANGE_OF_HINTS(R1, R2) \ - BOOST_REQUIRE_EQUAL((R1).size(), (R2).size()); \ - for (const auto i : util::irange(0UL, (R1).size())) \ - { \ - BOOST_REQUIRE(((R1)[i] && (R2)[i]) || !((R1)[i] || (R2)[i])); \ - if ((R1)[i]) \ - { \ - BOOST_CHECK_EQUAL_COLLECTIONS((R1)[i]->segment_hints.begin(), \ - (R1)[i]->segment_hints.end(), \ - (R2)[i]->segment_hints.begin(), \ - (R2)[i]->segment_hints.end()); \ - } \ - } - -BOOST_AUTO_TEST_SUITE(api_parameters_parser) - -using namespace osrm; -using namespace osrm::server; -using namespace osrm::server::api; -using namespace osrm::engine::api; - -// returns distance to front -template std::size_t testInvalidOptions(std::string options) -{ - auto iter = options.begin(); - auto result = parseParameters(iter, options.end()); - BOOST_CHECK(!result); - return std::distance(options.begin(), iter); -} - -BOOST_AUTO_TEST_CASE(invalid_route_urls) -{ - BOOST_CHECK_EQUAL(testInvalidOptions("a;3,4"), 0UL); - BOOST_CHECK_EQUAL(testInvalidOptions("120;3,4"), 3UL); - BOOST_CHECK_EQUAL(testInvalidOptions("90000000,2;3,4"), 0UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&bla=foo"), 22UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&bearings=foo"), - 32UL); - BOOST_CHECK_EQUAL( - testInvalidOptions("1,2;3,4?overview=false&continue_straight=foo"), 41UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&radiuses=foo"), - 32UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&approaches=foo"), - 34UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&hints=foo"), - 29UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&hints=;;; ;"), - 32UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?generate_hints=notboolean"), - 23UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&geometries=foo"), - 34UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&overview=foo"), - 32L); - BOOST_CHECK_EQUAL( - testInvalidOptions("1,2;3,4?overview=false&alternatives=foo"), 36UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&alternatives=-1"), - 36UL); - BOOST_CHECK_EQUAL(testInvalidOptions(""), 0); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3.4.unsupported"), 7); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4.json?nooptions"), 13); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4..json?nooptions"), 14); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4.0.json?nooptions"), 15); - BOOST_CHECK_EQUAL(testInvalidOptions(std::string{"1,2;3,4"} + '\0' + ".json"), - 7); - BOOST_CHECK_EQUAL(testInvalidOptions(std::string{"1,2;3,"} + '\0'), 6); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations=distances"), 28UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations="), 20UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations=true,false"), 24UL); - BOOST_CHECK_EQUAL( - testInvalidOptions("1,2;3,4?annotations=&overview=simplified"), 20UL); -} - -BOOST_AUTO_TEST_CASE(invalid_table_urls) -{ - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?sources=1&bla=foo"), 17UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?destinations=1&bla=foo"), 22UL); - BOOST_CHECK_EQUAL( - testInvalidOptions("1,2;3,4?sources=1&destinations=1&bla=foo"), 32UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?sources=foo"), 16UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?destinations=foo"), 21UL); - BOOST_CHECK_EQUAL( - testInvalidOptions("1,2;3,4?sources=all&destinations=all&annotations=bla"), - 49UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?fallback_coordinate=asdf"), - 28UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?fallback_coordinate=10"), 28UL); - BOOST_CHECK_EQUAL( - testInvalidOptions("1,2;3,4?annotations=durations&scale_factor=-1"), 28UL); - BOOST_CHECK_EQUAL( - testInvalidOptions("1,2;3,4?annotations=durations&scale_factor=0"), 28UL); - BOOST_CHECK_EQUAL( - testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=0"), - 28UL); - BOOST_CHECK_EQUAL( - testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=-1"), - 28UL); - BOOST_CHECK_EQUAL( - testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=0"), - 28UL); - BOOST_CHECK_EQUAL( - testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=-1"), - 28UL); - // TODO(danpat): this is only testing invalid grammar which isn't capable of checking - // for values that need to reference other things currently. These - // requests are gramatically correct, but semantically incorrect. - // The table service properly fails these, as it checks IsValid() after - // parsing, which fails when sources/destinations are too large - // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?sources=2"), 7UL); - // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?destinations=2"), 7UL); -} - -BOOST_AUTO_TEST_CASE(valid_route_segment_hint) -{ - engine::PhantomNode reference_node; - reference_node.input_location = - util::Coordinate(util::FloatLongitude{7.432251}, util::FloatLatitude{43.745995}); - engine::SegmentHint reference_segment_hint{reference_node, 0x1337}; - auto encoded_hint = reference_segment_hint.ToBase64(); - auto seg_hint = engine::SegmentHint::FromBase64(encoded_hint); - BOOST_CHECK_EQUAL(seg_hint.phantom.input_location, - reference_segment_hint.phantom.input_location); -} - -BOOST_AUTO_TEST_CASE(valid_route_urls) -{ - std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, - {util::FloatLongitude{3}, util::FloatLatitude{4}}}; - - RouteParameters reference_1{}; - reference_1.coordinates = coords_1; - auto result_1 = parseParameters("1,2;3,4"); - BOOST_CHECK(result_1); - BOOST_CHECK_EQUAL(reference_1.steps, result_1->steps); - BOOST_CHECK_EQUAL(reference_1.alternatives, result_1->alternatives); - BOOST_CHECK_EQUAL(reference_1.geometries, result_1->geometries); - BOOST_CHECK_EQUAL(reference_1.annotations, result_1->annotations); - BOOST_CHECK_EQUAL(reference_1.overview, result_1->overview); - BOOST_CHECK_EQUAL(reference_1.continue_straight, result_1->continue_straight); - CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); - CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); - CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); - CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); - CHECK_EQUAL_RANGE_OF_HINTS(reference_1.hints, result_1->hints); - - RouteParameters reference_2{}; - reference_2.alternatives = true; - reference_2.number_of_alternatives = 1; - reference_2.steps = true; - reference_2.annotations = true; - reference_2.coordinates = coords_1; - auto result_2 = - parseParameters("1,2;3,4?steps=true&alternatives=true&geometries=polyline&" - "overview=simplified&annotations=true"); - BOOST_CHECK(result_2); - BOOST_CHECK_EQUAL(reference_2.steps, result_2->steps); - BOOST_CHECK_EQUAL(reference_2.alternatives, result_2->alternatives); - BOOST_CHECK_EQUAL(reference_2.number_of_alternatives, result_2->number_of_alternatives); - BOOST_CHECK_EQUAL(reference_2.geometries, result_2->geometries); - BOOST_CHECK_EQUAL(reference_2.annotations, result_2->annotations); - BOOST_CHECK_EQUAL(reference_2.overview, result_2->overview); - BOOST_CHECK_EQUAL(reference_2.continue_straight, result_2->continue_straight); - CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); - CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); - CHECK_EQUAL_RANGE(reference_2.approaches, result_2->approaches); - CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); - CHECK_EQUAL_RANGE_OF_HINTS(reference_2.hints, result_2->hints); - BOOST_CHECK_EQUAL(result_2->annotations_type == RouteParameters::AnnotationsType::All, true); - - RouteParameters reference_3{false, - false, - false, - RouteParameters::GeometriesType::GeoJSON, - RouteParameters::OverviewType::False, - true}; - reference_3.coordinates = coords_1; - auto result_3 = api::parseParameters( - "1,2;3,4?steps=false&alternatives=false&geometries=geojson&overview=false&continue_" - "straight=true"); - BOOST_CHECK(result_3); - BOOST_CHECK_EQUAL(reference_3.steps, result_3->steps); - BOOST_CHECK_EQUAL(reference_3.alternatives, result_3->alternatives); - BOOST_CHECK_EQUAL(reference_3.number_of_alternatives, result_3->number_of_alternatives); - BOOST_CHECK_EQUAL(reference_3.geometries, result_3->geometries); - BOOST_CHECK_EQUAL(reference_3.annotations, result_3->annotations); - BOOST_CHECK_EQUAL(reference_3.overview, result_3->overview); - BOOST_CHECK_EQUAL(reference_3.continue_straight, result_3->continue_straight); - CHECK_EQUAL_RANGE(reference_3.bearings, result_3->bearings); - CHECK_EQUAL_RANGE(reference_3.radiuses, result_3->radiuses); - CHECK_EQUAL_RANGE(reference_3.approaches, result_3->approaches); - CHECK_EQUAL_RANGE(reference_3.coordinates, result_3->coordinates); - CHECK_EQUAL_RANGE_OF_HINTS(reference_3.hints, result_3->hints); - - engine::PhantomNode phantom_1; - phantom_1.input_location = coords_1[0]; - engine::PhantomNode phantom_2; - phantom_2.input_location = coords_1[1]; - std::vector> hints_4 = { - engine::Hint{{engine::SegmentHint{phantom_1, 0x1337}}}, - engine::Hint{{engine::SegmentHint{phantom_2, 0x1337}}}}; - RouteParameters reference_4{false, - false, - false, - RouteParameters::GeometriesType::Polyline, - RouteParameters::OverviewType::Simplified, - std::optional{}, - coords_1, - hints_4, - std::vector>{}, - std::vector>{}}; - auto result_4 = parseParameters( - "1,2;3,4?steps=false&hints=" + hints_4[0]->ToBase64() + ";" + hints_4[1]->ToBase64()); - BOOST_CHECK(result_4); - BOOST_CHECK_EQUAL(reference_4.steps, result_4->steps); - BOOST_CHECK_EQUAL(reference_4.alternatives, result_4->alternatives); - BOOST_CHECK_EQUAL(reference_4.geometries, result_4->geometries); - BOOST_CHECK_EQUAL(reference_4.annotations, result_4->annotations); - BOOST_CHECK_EQUAL(reference_4.overview, result_4->overview); - BOOST_CHECK_EQUAL(reference_4.continue_straight, result_4->continue_straight); - CHECK_EQUAL_RANGE(reference_4.bearings, result_4->bearings); - CHECK_EQUAL_RANGE(reference_4.radiuses, result_4->radiuses); - CHECK_EQUAL_RANGE(reference_4.approaches, result_4->approaches); - CHECK_EQUAL_RANGE(reference_4.coordinates, result_4->coordinates); - CHECK_EQUAL_RANGE_OF_HINTS(reference_4.hints, result_4->hints); - - std::vector> bearings_4 = { - std::nullopt, - engine::Bearing{200, 10}, - engine::Bearing{100, 5}, - }; - RouteParameters reference_5{false, - false, - false, - RouteParameters::GeometriesType::Polyline, - RouteParameters::OverviewType::Simplified, - std::optional{}, - coords_1, - std::vector>{}, - std::vector>{}, - bearings_4}; - auto result_5 = parseParameters("1,2;3,4?steps=false&bearings=;200,10;100,5"); - BOOST_CHECK(result_5); - BOOST_CHECK_EQUAL(reference_5.steps, result_5->steps); - BOOST_CHECK_EQUAL(reference_5.alternatives, result_5->alternatives); - BOOST_CHECK_EQUAL(reference_5.geometries, result_5->geometries); - BOOST_CHECK_EQUAL(reference_5.annotations, result_5->annotations); - BOOST_CHECK_EQUAL(reference_5.overview, result_5->overview); - BOOST_CHECK_EQUAL(reference_5.continue_straight, result_5->continue_straight); - CHECK_EQUAL_RANGE(reference_5.bearings, result_5->bearings); - CHECK_EQUAL_RANGE(reference_5.radiuses, result_5->radiuses); - CHECK_EQUAL_RANGE(reference_5.approaches, result_5->approaches); - CHECK_EQUAL_RANGE(reference_5.coordinates, result_5->coordinates); - CHECK_EQUAL_RANGE_OF_HINTS(reference_5.hints, result_5->hints); - - std::vector coords_2 = {{util::FloatLongitude{0}, util::FloatLatitude{1}}, - {util::FloatLongitude{2}, util::FloatLatitude{3}}, - {util::FloatLongitude{4}, util::FloatLatitude{5}}}; - - RouteParameters reference_6{}; - reference_6.coordinates = coords_2; - auto result_6 = parseParameters("polyline(_ibE?_seK_seK_seK_seK)"); - BOOST_CHECK(result_6); - BOOST_CHECK_EQUAL(reference_6.steps, result_6->steps); - BOOST_CHECK_EQUAL(reference_6.alternatives, result_6->alternatives); - BOOST_CHECK_EQUAL(reference_6.geometries, result_6->geometries); - BOOST_CHECK_EQUAL(reference_6.annotations, result_6->annotations); - BOOST_CHECK_EQUAL(reference_6.overview, result_6->overview); - BOOST_CHECK_EQUAL(reference_6.continue_straight, result_6->continue_straight); - CHECK_EQUAL_RANGE(reference_6.bearings, result_6->bearings); - CHECK_EQUAL_RANGE(reference_6.radiuses, result_6->radiuses); - CHECK_EQUAL_RANGE(reference_6.approaches, result_6->approaches); - CHECK_EQUAL_RANGE(reference_6.coordinates, result_6->coordinates); - CHECK_EQUAL_RANGE_OF_HINTS(reference_6.hints, result_6->hints); - - auto result_7 = parseParameters("1,2;3,4?radiuses=;unlimited"); - RouteParameters reference_7{}; - reference_7.coordinates = coords_1; - reference_7.radiuses = {std::nullopt, - std::make_optional(std::numeric_limits::infinity())}; - BOOST_CHECK(result_7); - BOOST_CHECK_EQUAL(reference_7.steps, result_7->steps); - BOOST_CHECK_EQUAL(reference_7.alternatives, result_7->alternatives); - BOOST_CHECK_EQUAL(reference_7.geometries, result_7->geometries); - BOOST_CHECK_EQUAL(reference_7.annotations, result_7->annotations); - BOOST_CHECK_EQUAL(reference_7.overview, result_7->overview); - BOOST_CHECK_EQUAL(reference_7.continue_straight, result_7->continue_straight); - CHECK_EQUAL_RANGE(reference_7.bearings, result_7->bearings); - CHECK_EQUAL_RANGE(reference_7.radiuses, result_7->radiuses); - CHECK_EQUAL_RANGE(reference_7.approaches, result_7->approaches); - CHECK_EQUAL_RANGE(reference_7.coordinates, result_7->coordinates); - CHECK_EQUAL_RANGE_OF_HINTS(reference_7.hints, result_7->hints); - - auto result_8 = parseParameters("1,2;3,4?radiuses=;"); - RouteParameters reference_8{}; - reference_8.coordinates = coords_1; - reference_8.radiuses = {std::nullopt, std::nullopt}; - BOOST_CHECK(result_8); - CHECK_EQUAL_RANGE(reference_8.radiuses, result_8->radiuses); - - auto result_9 = parseParameters("1,2?radiuses="); - RouteParameters reference_9{}; - reference_9.coordinates = coords_1; - reference_9.radiuses = {std::nullopt}; - BOOST_CHECK(result_9); - CHECK_EQUAL_RANGE(reference_9.radiuses, result_9->radiuses); - - // Some Hint's are empty - std::vector coords_3 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, - {util::FloatLongitude{3}, util::FloatLatitude{4}}, - {util::FloatLongitude{5}, util::FloatLatitude{6}}, - {util::FloatLongitude{7}, util::FloatLatitude{8}}}; - - engine::PhantomNode phantom_3; - phantom_3.input_location = coords_3[0]; - engine::PhantomNode phantom_4; - phantom_4.input_location = coords_3[2]; - std::vector> hints_10 = { - engine::Hint{{engine::SegmentHint{phantom_3, 0x1337}}}, - {}, - engine::Hint{{engine::SegmentHint{phantom_4, 0x1337}}}, - {}}; - - RouteParameters reference_10{false, - false, - false, - RouteParameters::GeometriesType::Polyline, - RouteParameters::OverviewType::Simplified, - std::optional{}, - coords_3, - hints_10, - std::vector>{}, - std::vector>{}}; - auto result_10 = parseParameters( - "1,2;3,4;5,6;7,8?steps=false&hints=" + hints_10[0]->ToBase64() + ";;" + - hints_10[2]->ToBase64() + ";"); - BOOST_CHECK(result_10); - BOOST_CHECK_EQUAL(reference_10.steps, result_10->steps); - BOOST_CHECK_EQUAL(reference_10.alternatives, result_10->alternatives); - BOOST_CHECK_EQUAL(reference_10.geometries, result_10->geometries); - BOOST_CHECK_EQUAL(reference_10.annotations, result_10->annotations); - BOOST_CHECK_EQUAL(reference_10.overview, result_10->overview); - BOOST_CHECK_EQUAL(reference_10.continue_straight, result_10->continue_straight); - CHECK_EQUAL_RANGE(reference_10.bearings, result_10->bearings); - CHECK_EQUAL_RANGE(reference_10.radiuses, result_10->radiuses); - CHECK_EQUAL_RANGE(reference_10.approaches, result_10->approaches); - CHECK_EQUAL_RANGE(reference_10.coordinates, result_10->coordinates); - CHECK_EQUAL_RANGE_OF_HINTS(reference_10.hints, result_10->hints); - - // Do not generate Hints when they are explicitly disabled - auto result_11 = parseParameters("1,2;3,4?generate_hints=false"); - BOOST_CHECK(result_11); - BOOST_CHECK_EQUAL(result_11->generate_hints, false); - - auto result_12 = parseParameters("1,2;3,4?generate_hints=true"); - BOOST_CHECK(result_12); - BOOST_CHECK_EQUAL(result_12->generate_hints, true); - - auto result_13 = parseParameters("1,2;3,4"); - BOOST_CHECK(result_13); - BOOST_CHECK_EQUAL(result_13->generate_hints, true); - - // parse none annotations value correctly - RouteParameters reference_14{}; - reference_14.annotations_type = RouteParameters::AnnotationsType::None; - reference_14.coordinates = coords_1; - auto result_14 = parseParameters("1,2;3,4?geometries=polyline"); - BOOST_CHECK(result_14); - BOOST_CHECK_EQUAL(reference_14.geometries, result_14->geometries); - BOOST_CHECK_EQUAL(result_14->annotations_type == RouteParameters::AnnotationsType::None, true); - BOOST_CHECK_EQUAL(result_14->annotations, false); - - // parse single annotations value correctly - RouteParameters reference_15{}; - reference_15.annotations_type = RouteParameters::AnnotationsType::Duration; - reference_15.coordinates = coords_1; - auto result_15 = parseParameters("1,2;3,4?geometries=polyline&" - "overview=simplified&annotations=duration"); - BOOST_CHECK(result_15); - BOOST_CHECK_EQUAL(reference_15.geometries, result_15->geometries); - BOOST_CHECK_EQUAL(result_15->annotations_type == RouteParameters::AnnotationsType::Duration, - true); - BOOST_CHECK_EQUAL(result_15->annotations, true); - - RouteParameters reference_speed{}; - reference_speed.annotations_type = RouteParameters::AnnotationsType::Duration; - reference_speed.coordinates = coords_1; - auto result_speed = - parseParameters("1,2;3,4?geometries=polyline&" - "overview=simplified&annotations=duration,distance,speed"); - BOOST_CHECK(result_speed); - BOOST_CHECK_EQUAL(reference_speed.geometries, result_speed->geometries); - BOOST_CHECK_EQUAL(reference_speed.overview, result_speed->overview); - BOOST_CHECK_EQUAL(result_speed->annotations_type == - (RouteParameters::AnnotationsType::Duration | - RouteParameters::AnnotationsType::Distance | - RouteParameters::AnnotationsType::Speed), - true); - BOOST_CHECK_EQUAL(result_speed->annotations, true); - - // parse multiple annotations correctly - RouteParameters reference_16{}; - reference_16.annotations_type = RouteParameters::AnnotationsType::Duration | - RouteParameters::AnnotationsType::Weight | - RouteParameters::AnnotationsType::Nodes; - reference_16.coordinates = coords_1; - auto result_16 = - parseParameters("1,2;3,4?geometries=polyline&" - "overview=simplified&annotations=duration,weight,nodes"); - BOOST_CHECK(result_16); - BOOST_CHECK_EQUAL(reference_16.geometries, result_16->geometries); - BOOST_CHECK_EQUAL(static_cast(result_16->annotations_type & - (RouteParameters::AnnotationsType::Weight | - RouteParameters::AnnotationsType::Duration | - RouteParameters::AnnotationsType::Nodes)), - true); - BOOST_CHECK_EQUAL(result_16->annotations, true); - - // parse all annotations correctly - RouteParameters reference_17{}; - reference_17.annotations_type = RouteParameters::AnnotationsType::All; - reference_17.coordinates = coords_1; - auto result_17 = parseParameters( - "1,2;3,4?overview=simplified&annotations=duration,weight,nodes,datasources,distance"); - BOOST_CHECK(result_17); - BOOST_CHECK_EQUAL(reference_17.geometries, result_17->geometries); - BOOST_CHECK_EQUAL(result_2->annotations_type == RouteParameters::AnnotationsType::All, true); - BOOST_CHECK_EQUAL(result_17->annotations, true); - - std::vector> approaches_18 = { - std::nullopt, - engine::Approach::CURB, - engine::Approach::UNRESTRICTED, - engine::Approach::OPPOSITE, - }; - RouteParameters reference_18{false, - false, - false, - RouteParameters::GeometriesType::Polyline, - RouteParameters::OverviewType::Simplified, - std::optional{}, - coords_3, - std::vector>{}, - std::vector>{}, - std::vector>{}, - approaches_18}; - - auto result_18 = parseParameters( - "1,2;3,4;5,6;7,8?steps=false&approaches=;curb;unrestricted;opposite"); - BOOST_CHECK(result_18); - BOOST_CHECK_EQUAL(reference_18.steps, result_18->steps); - BOOST_CHECK_EQUAL(reference_18.alternatives, result_18->alternatives); - BOOST_CHECK_EQUAL(reference_18.geometries, result_18->geometries); - BOOST_CHECK_EQUAL(reference_18.annotations, result_18->annotations); - BOOST_CHECK_EQUAL(reference_18.overview, result_18->overview); - BOOST_CHECK_EQUAL(reference_18.continue_straight, result_18->continue_straight); - CHECK_EQUAL_RANGE(reference_18.bearings, result_18->bearings); - CHECK_EQUAL_RANGE(reference_18.radiuses, result_18->radiuses); - CHECK_EQUAL_RANGE(reference_18.approaches, result_18->approaches); - CHECK_EQUAL_RANGE(reference_18.coordinates, result_18->coordinates); - CHECK_EQUAL_RANGE_OF_HINTS(reference_18.hints, result_18->hints); - - RouteParameters reference_19{}; - reference_19.alternatives = true; - reference_19.number_of_alternatives = 3; - reference_19.coordinates = coords_1; - auto result_19 = parseParameters("1,2;3,4?alternatives=3"); - BOOST_CHECK(result_19); - BOOST_CHECK_EQUAL(reference_19.steps, result_19->steps); - BOOST_CHECK_EQUAL(reference_19.alternatives, result_19->alternatives); - BOOST_CHECK_EQUAL(reference_19.number_of_alternatives, result_19->number_of_alternatives); - BOOST_CHECK_EQUAL(reference_19.geometries, result_19->geometries); - BOOST_CHECK_EQUAL(reference_19.annotations, result_19->annotations); - BOOST_CHECK_EQUAL(reference_19.overview, result_19->overview); - BOOST_CHECK_EQUAL(reference_19.continue_straight, result_19->continue_straight); - CHECK_EQUAL_RANGE(reference_19.bearings, result_19->bearings); - CHECK_EQUAL_RANGE(reference_19.radiuses, result_19->radiuses); - CHECK_EQUAL_RANGE(reference_19.approaches, result_19->approaches); - CHECK_EQUAL_RANGE(reference_19.coordinates, result_19->coordinates); - CHECK_EQUAL_RANGE_OF_HINTS(reference_19.hints, result_19->hints); - - RouteParameters reference_20{}; - reference_20.alternatives = false; - reference_20.number_of_alternatives = 0; - reference_20.coordinates = coords_1; - auto result_20 = parseParameters("1,2;3,4?alternatives=0"); - BOOST_CHECK(result_20); - BOOST_CHECK_EQUAL(reference_20.steps, result_20->steps); - BOOST_CHECK_EQUAL(reference_20.alternatives, result_20->alternatives); - BOOST_CHECK_EQUAL(reference_20.number_of_alternatives, result_20->number_of_alternatives); - BOOST_CHECK_EQUAL(reference_20.geometries, result_20->geometries); - BOOST_CHECK_EQUAL(reference_20.annotations, result_20->annotations); - BOOST_CHECK_EQUAL(reference_20.overview, result_20->overview); - BOOST_CHECK_EQUAL(reference_20.continue_straight, result_20->continue_straight); - CHECK_EQUAL_RANGE(reference_20.bearings, result_20->bearings); - CHECK_EQUAL_RANGE(reference_20.radiuses, result_20->radiuses); - CHECK_EQUAL_RANGE(reference_20.approaches, result_20->approaches); - CHECK_EQUAL_RANGE(reference_20.coordinates, result_20->coordinates); - CHECK_EQUAL_RANGE_OF_HINTS(reference_20.hints, result_20->hints); - - // exclude flags - RouteParameters reference_21{}; - reference_21.exclude = {"ferry", "motorway"}; - reference_21.coordinates = coords_1; - auto result_21 = parseParameters("1,2;3,4?exclude=ferry,motorway"); - BOOST_CHECK(result_21); - BOOST_CHECK_EQUAL(reference_21.steps, result_21->steps); - BOOST_CHECK_EQUAL(reference_21.alternatives, result_21->alternatives); - BOOST_CHECK_EQUAL(reference_21.number_of_alternatives, result_21->number_of_alternatives); - BOOST_CHECK_EQUAL(reference_21.geometries, result_21->geometries); - BOOST_CHECK_EQUAL(reference_21.annotations, result_21->annotations); - BOOST_CHECK_EQUAL(reference_21.overview, result_21->overview); - BOOST_CHECK_EQUAL(reference_21.continue_straight, result_21->continue_straight); - CHECK_EQUAL_RANGE(reference_21.bearings, result_21->bearings); - CHECK_EQUAL_RANGE(reference_21.radiuses, result_21->radiuses); - CHECK_EQUAL_RANGE(reference_21.approaches, result_21->approaches); - CHECK_EQUAL_RANGE(reference_21.coordinates, result_21->coordinates); - CHECK_EQUAL_RANGE_OF_HINTS(reference_21.hints, result_21->hints); - CHECK_EQUAL_RANGE(reference_21.exclude, result_21->exclude); -} - -BOOST_AUTO_TEST_CASE(valid_table_urls) -{ - std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, - {util::FloatLongitude{3}, util::FloatLatitude{4}}}; - - TableParameters reference_1{}; - reference_1.coordinates = coords_1; - auto result_1 = parseParameters("1,2;3,4"); - BOOST_CHECK(result_1); - CHECK_EQUAL_RANGE(reference_1.sources, result_1->sources); - CHECK_EQUAL_RANGE(reference_1.destinations, result_1->destinations); - CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); - CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); - CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); - CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); - - std::vector sources_2 = {1, 2, 3}; - std::vector destinations_2 = {4, 5}; - TableParameters reference_2{sources_2, destinations_2}; - reference_2.coordinates = coords_1; - auto result_2 = parseParameters("1,2;3,4?sources=1;2;3&destinations=4;5"); - BOOST_CHECK(result_2); - CHECK_EQUAL_RANGE(reference_2.sources, result_2->sources); - CHECK_EQUAL_RANGE(reference_2.destinations, result_2->destinations); - CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); - CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); - CHECK_EQUAL_RANGE(reference_2.approaches, result_2->approaches); - CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); - - auto result_3 = parseParameters("1,2;3,4?sources=all&destinations=all"); - BOOST_CHECK(result_3); - CHECK_EQUAL_RANGE(reference_1.sources, result_3->sources); - CHECK_EQUAL_RANGE(reference_1.destinations, result_3->destinations); - CHECK_EQUAL_RANGE(reference_1.bearings, result_3->bearings); - CHECK_EQUAL_RANGE(reference_1.radiuses, result_3->radiuses); - CHECK_EQUAL_RANGE(reference_1.approaches, result_3->approaches); - CHECK_EQUAL_RANGE(reference_1.coordinates, result_3->coordinates); - - TableParameters reference_4{}; - reference_4.coordinates = coords_1; - auto result_4 = parseParameters( - "1,2;3,4?sources=all&destinations=all&annotations=duration"); - BOOST_CHECK(result_4); - BOOST_CHECK_EQUAL(result_4->annotations & (TableParameters::AnnotationsType::Distance | - TableParameters::AnnotationsType::Duration), - true); - CHECK_EQUAL_RANGE(reference_4.sources, result_4->sources); - CHECK_EQUAL_RANGE(reference_4.destinations, result_4->destinations); - - TableParameters reference_5{}; - reference_5.coordinates = coords_1; - auto result_5 = parseParameters( - "1,2;3,4?sources=all&destinations=all&annotations=duration"); - BOOST_CHECK(result_5); - BOOST_CHECK_EQUAL(result_5->annotations & TableParameters::AnnotationsType::Duration, true); - CHECK_EQUAL_RANGE(reference_5.sources, result_5->sources); - CHECK_EQUAL_RANGE(reference_5.destinations, result_5->destinations); - - TableParameters reference_6{}; - reference_6.coordinates = coords_1; - auto result_6 = parseParameters( - "1,2;3,4?sources=all&destinations=all&annotations=distance"); - BOOST_CHECK(result_6); - BOOST_CHECK_EQUAL(result_6->annotations & TableParameters::AnnotationsType::Distance, true); - CHECK_EQUAL_RANGE(reference_6.sources, result_6->sources); - CHECK_EQUAL_RANGE(reference_6.destinations, result_6->destinations); - - TableParameters reference_7{}; - reference_7.coordinates = coords_1; - auto result_7 = parseParameters("1,2;3,4?annotations=distance"); - BOOST_CHECK(result_7); - BOOST_CHECK_EQUAL(result_7->annotations & TableParameters::AnnotationsType::Distance, true); - CHECK_EQUAL_RANGE(reference_7.sources, result_7->sources); - CHECK_EQUAL_RANGE(reference_7.destinations, result_7->destinations); - - TableParameters reference_8{}; - reference_8.coordinates = coords_1; - auto result_8 = - parseParameters("1,2;3,4?annotations=distance&fallback_speed=2.5"); - BOOST_CHECK(result_8); - BOOST_CHECK_EQUAL(result_8->annotations & TableParameters::AnnotationsType::Distance, true); - CHECK_EQUAL_RANGE(reference_8.sources, result_8->sources); - CHECK_EQUAL_RANGE(reference_8.destinations, result_8->destinations); - - TableParameters reference_9{}; - reference_9.coordinates = coords_1; - auto result_9 = parseParameters( - "1,2;3,4?annotations=distance&fallback_speed=2.5&fallback_coordinate=input"); - BOOST_CHECK(result_9); - BOOST_CHECK_EQUAL(result_9->annotations & TableParameters::AnnotationsType::Distance, true); - CHECK_EQUAL_RANGE(reference_9.sources, result_9->sources); - CHECK_EQUAL_RANGE(reference_9.destinations, result_9->destinations); - - TableParameters reference_10{}; - reference_10.coordinates = coords_1; - auto result_10 = parseParameters( - "1,2;3,4?annotations=distance&fallback_speed=20&fallback_coordinate=snapped"); - BOOST_CHECK(result_10); - BOOST_CHECK_EQUAL(result_10->annotations & TableParameters::AnnotationsType::Distance, true); - CHECK_EQUAL_RANGE(reference_10.sources, result_10->sources); - CHECK_EQUAL_RANGE(reference_10.destinations, result_10->destinations); - - auto result_11 = parseParameters("1,2;3,4?sources=all&destinations=all&" - "annotations=duration&fallback_speed=1&" - "fallback_coordinate=snapped&scale_factor=2"); - BOOST_CHECK(result_11); - CHECK_EQUAL_RANGE(reference_1.sources, result_11->sources); - CHECK_EQUAL_RANGE(reference_1.destinations, result_11->destinations); - CHECK_EQUAL_RANGE(reference_1.bearings, result_11->bearings); - CHECK_EQUAL_RANGE(reference_1.radiuses, result_11->radiuses); - CHECK_EQUAL_RANGE(reference_1.approaches, result_11->approaches); - CHECK_EQUAL_RANGE(reference_1.coordinates, result_11->coordinates); -} - -BOOST_AUTO_TEST_CASE(valid_match_urls) -{ - std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, - {util::FloatLongitude{3}, util::FloatLatitude{4}}}; - - MatchParameters reference_1{}; - reference_1.coordinates = coords_1; - auto result_1 = parseParameters("1,2;3,4"); - BOOST_CHECK(result_1); - CHECK_EQUAL_RANGE(reference_1.timestamps, result_1->timestamps); - CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); - CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); - CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); - CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); - - MatchParameters reference_2{}; - reference_2.coordinates = coords_1; - reference_2.timestamps = {5, 6}; - auto result_2 = parseParameters("1,2;3,4?timestamps=5;6"); - BOOST_CHECK(result_2); - CHECK_EQUAL_RANGE(reference_2.timestamps, result_2->timestamps); - CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); - CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); - CHECK_EQUAL_RANGE(reference_2.approaches, result_2->approaches); - CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); - - std::vector coords_2 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, - {util::FloatLongitude{3}, util::FloatLatitude{4}}, - {util::FloatLongitude{5}, util::FloatLatitude{6}}}; - - MatchParameters reference_3{}; - reference_3.coordinates = coords_2; - reference_3.waypoints = {0, 2}; - auto result_3 = parseParameters("1,2;3,4;5,6?waypoints=0;2"); - BOOST_CHECK(result_3); - CHECK_EQUAL_RANGE(reference_3.waypoints, result_3->waypoints); - CHECK_EQUAL_RANGE(reference_3.timestamps, result_3->timestamps); - CHECK_EQUAL_RANGE(reference_3.bearings, result_3->bearings); - CHECK_EQUAL_RANGE(reference_3.radiuses, result_3->radiuses); - CHECK_EQUAL_RANGE(reference_3.approaches, result_3->approaches); - CHECK_EQUAL_RANGE(reference_3.coordinates, result_3->coordinates); -} - -BOOST_AUTO_TEST_CASE(invalid_match_urls) -{ - std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, - {util::FloatLongitude{3}, util::FloatLatitude{4}}}; - - MatchParameters reference_1{}; - reference_1.coordinates = coords_1; - auto result_1 = parseParameters("1,2;3,4?radiuses=unlimited;60"); - BOOST_CHECK(result_1); - CHECK_EQUAL_RANGE(reference_1.timestamps, result_1->timestamps); - CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); - BOOST_CHECK(reference_1.radiuses != result_1->radiuses); - CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); - CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); - - std::vector coords_2 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, - {util::FloatLongitude{3}, util::FloatLatitude{4}}}; - - MatchParameters reference_2{}; - reference_2.coordinates = coords_2; - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?waypoints=0,4"), 19UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?waypoints=x;4"), 18UL); - BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?waypoints=0;3.5"), 21UL); -} - -BOOST_AUTO_TEST_CASE(valid_nearest_urls) -{ - std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}}; - - NearestParameters reference_1{}; - reference_1.coordinates = coords_1; - auto result_1 = parseParameters("1,2"); - BOOST_CHECK(result_1); - BOOST_CHECK_EQUAL(reference_1.number_of_results, result_1->number_of_results); - CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); - CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); - CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); - CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); - - NearestParameters reference_2{}; - reference_2.coordinates = coords_1; - reference_2.number_of_results = 42; - auto result_2 = parseParameters("1,2?number=42"); - BOOST_CHECK(result_2); - BOOST_CHECK_EQUAL(reference_2.number_of_results, result_2->number_of_results); - CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); - CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); - CHECK_EQUAL_RANGE(reference_2.approaches, result_2->approaches); - CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); -} - -BOOST_AUTO_TEST_CASE(invalid_tile_urls) -{ - TileParameters reference_1{1, 2, 3}; - auto result_1 = parseParameters("tile(1,2,3).mvt"); - BOOST_CHECK(result_1); - BOOST_CHECK(!result_1->IsValid()); - BOOST_CHECK_EQUAL(reference_1.x, result_1->x); - BOOST_CHECK_EQUAL(reference_1.y, result_1->y); - BOOST_CHECK_EQUAL(reference_1.z, result_1->z); -} - -BOOST_AUTO_TEST_CASE(valid_tile_urls) -{ - TileParameters reference_1{1, 2, 12}; - auto result_1 = parseParameters("tile(1,2,12).mvt"); - BOOST_CHECK(result_1->IsValid()); - BOOST_CHECK(result_1); - BOOST_CHECK_EQUAL(reference_1.x, result_1->x); - BOOST_CHECK_EQUAL(reference_1.y, result_1->y); - BOOST_CHECK_EQUAL(reference_1.z, result_1->z); -} - -BOOST_AUTO_TEST_CASE(valid_trip_urls) -{ - std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, - {util::FloatLongitude{3}, util::FloatLatitude{4}}}; - - TripParameters reference_1{}; - reference_1.coordinates = coords_1; - auto result_1 = parseParameters("1,2;3,4"); - BOOST_CHECK(result_1); - CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); - CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); - - TripParameters reference_2{}; - reference_2.coordinates = coords_1; - reference_2.source = TripParameters::SourceType::First; - reference_2.destination = TripParameters::DestinationType::Last; - auto result_2 = parseParameters("1,2;3,4?source=first&destination=last"); - BOOST_CHECK(result_2); - CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); - CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); - - // check supported source/destination/rountrip combinations - auto param_fse_r = - parseParameters("1,2;3,4?source=first&destination=last&roundtrip=true"); - BOOST_CHECK(param_fse_r->IsValid()); - auto param_fse_nr_ = - parseParameters("1,2;3,4?source=first&destination=last&roundtrip=false"); - BOOST_CHECK(param_fse_nr_->IsValid()); - auto param_fs_r = parseParameters("1,2;3,4?source=first&roundtrip=true"); - BOOST_CHECK(param_fs_r->IsValid()); - auto param_fs_nr = parseParameters("1,2;3,4?source=first&roundtrip=false"); - BOOST_CHECK(param_fs_nr->IsValid()); - auto param_fe_r = parseParameters("1,2;3,4?destination=last&roundtrip=true"); - BOOST_CHECK(param_fe_r->IsValid()); - auto param_fe_nr = parseParameters("1,2;3,4?destination=last&roundtrip=false"); - BOOST_CHECK(param_fe_nr->IsValid()); - auto param_r = parseParameters("1,2;3,4?roundtrip=true"); - BOOST_CHECK(param_r->IsValid()); - auto param_nr = parseParameters("1,2;3,4?roundtrip=false"); - BOOST_CHECK(param_nr->IsValid()); - - auto param_fail_1 = - testInvalidOptions("1,2;3,4?source=blubb&destination=random"); - BOOST_CHECK_EQUAL(param_fail_1, 15UL); - auto param_fail_2 = testInvalidOptions("1,2;3,4?source=first&destination=nah"); - BOOST_CHECK_EQUAL(param_fail_2, 33UL); -} - -BOOST_AUTO_TEST_SUITE_END() +// #include "server/api/parameters_parser.hpp" + +// #include "parameters_io.hpp" + +// #include "engine/api/base_parameters.hpp" +// #include "engine/api/match_parameters.hpp" +// #include "engine/api/nearest_parameters.hpp" +// #include "engine/api/route_parameters.hpp" +// #include "engine/api/table_parameters.hpp" +// #include "engine/api/tile_parameters.hpp" +// #include "engine/api/trip_parameters.hpp" + +// #include "util/debug.hpp" + +// #include +// #include +// #include + +// #define CHECK_EQUAL_RANGE(R1, R2) \ +// BOOST_CHECK_EQUAL_COLLECTIONS((R1).begin(), (R1).end(), (R2).begin(), (R2).end()); + +// #define CHECK_EQUAL_RANGE_OF_HINTS(R1, R2) \ +// BOOST_REQUIRE_EQUAL((R1).size(), (R2).size()); \ +// for (const auto i : util::irange(0UL, (R1).size())) \ +// { \ +// BOOST_REQUIRE(((R1)[i] && (R2)[i]) || !((R1)[i] || (R2)[i])); \ +// if ((R1)[i]) \ +// { \ +// BOOST_CHECK_EQUAL_COLLECTIONS((R1)[i]->segment_hints.begin(), \ +// (R1)[i]->segment_hints.end(), \ +// (R2)[i]->segment_hints.begin(), \ +// (R2)[i]->segment_hints.end()); \ +// } \ +// } + +// BOOST_AUTO_TEST_SUITE(api_parameters_parser) + +// using namespace osrm; +// using namespace osrm::server; +// using namespace osrm::server::api; +// using namespace osrm::engine::api; + +// // returns distance to front +// template std::size_t testInvalidOptions(std::string options) +// { +// auto iter = options.begin(); +// auto result = parseParameters(iter, options.end()); +// BOOST_CHECK(!result); +// return std::distance(options.begin(), iter); +// } + +// BOOST_AUTO_TEST_CASE(invalid_route_urls) +// { +// BOOST_CHECK_EQUAL(testInvalidOptions("a;3,4"), 0UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("120;3,4"), 3UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("90000000,2;3,4"), 0UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&bla=foo"), 22UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&bearings=foo"), +// 32UL); +// BOOST_CHECK_EQUAL( +// testInvalidOptions("1,2;3,4?overview=false&continue_straight=foo"), 41UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&radiuses=foo"), +// 32UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&approaches=foo"), +// 34UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&hints=foo"), +// 29UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&hints=;;; ;"), +// 32UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?generate_hints=notboolean"), +// 23UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&geometries=foo"), +// 34UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&overview=foo"), +// 32L); +// BOOST_CHECK_EQUAL( +// testInvalidOptions("1,2;3,4?overview=false&alternatives=foo"), 36UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&alternatives=-1"), +// 36UL); +// BOOST_CHECK_EQUAL(testInvalidOptions(""), 0); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3.4.unsupported"), 7); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4.json?nooptions"), 13); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4..json?nooptions"), 14); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4.0.json?nooptions"), 15); +// BOOST_CHECK_EQUAL(testInvalidOptions(std::string{"1,2;3,4"} + '\0' + ".json"), +// 7); +// BOOST_CHECK_EQUAL(testInvalidOptions(std::string{"1,2;3,"} + '\0'), 6); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations=distances"), 28UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations="), 20UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations=true,false"), 24UL); +// BOOST_CHECK_EQUAL( +// testInvalidOptions("1,2;3,4?annotations=&overview=simplified"), 20UL); +// } + +// BOOST_AUTO_TEST_CASE(invalid_table_urls) +// { +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?sources=1&bla=foo"), 17UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?destinations=1&bla=foo"), 22UL); +// BOOST_CHECK_EQUAL( +// testInvalidOptions("1,2;3,4?sources=1&destinations=1&bla=foo"), 32UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?sources=foo"), 16UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?destinations=foo"), 21UL); +// BOOST_CHECK_EQUAL( +// testInvalidOptions("1,2;3,4?sources=all&destinations=all&annotations=bla"), +// 49UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?fallback_coordinate=asdf"), +// 28UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?fallback_coordinate=10"), 28UL); +// BOOST_CHECK_EQUAL( +// testInvalidOptions("1,2;3,4?annotations=durations&scale_factor=-1"), 28UL); +// BOOST_CHECK_EQUAL( +// testInvalidOptions("1,2;3,4?annotations=durations&scale_factor=0"), 28UL); +// BOOST_CHECK_EQUAL( +// testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=0"), +// 28UL); +// BOOST_CHECK_EQUAL( +// testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=-1"), +// 28UL); +// BOOST_CHECK_EQUAL( +// testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=0"), +// 28UL); +// BOOST_CHECK_EQUAL( +// testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=-1"), +// 28UL); +// // TODO(danpat): this is only testing invalid grammar which isn't capable of checking +// // for values that need to reference other things currently. These +// // requests are gramatically correct, but semantically incorrect. +// // The table service properly fails these, as it checks IsValid() after +// // parsing, which fails when sources/destinations are too large +// // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?sources=2"), 7UL); +// // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?destinations=2"), 7UL); +// } + +// BOOST_AUTO_TEST_CASE(valid_route_segment_hint) +// { +// engine::PhantomNode reference_node; +// reference_node.input_location = +// util::Coordinate(util::FloatLongitude{7.432251}, util::FloatLatitude{43.745995}); +// engine::SegmentHint reference_segment_hint{reference_node, 0x1337}; +// auto encoded_hint = reference_segment_hint.ToBase64(); +// auto seg_hint = engine::SegmentHint::FromBase64(encoded_hint); +// BOOST_CHECK_EQUAL(seg_hint.phantom.input_location, +// reference_segment_hint.phantom.input_location); +// } + +// BOOST_AUTO_TEST_CASE(valid_route_urls) +// { +// std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, +// {util::FloatLongitude{3}, util::FloatLatitude{4}}}; + +// RouteParameters reference_1{}; +// reference_1.coordinates = coords_1; +// auto result_1 = parseParameters("1,2;3,4"); +// BOOST_CHECK(result_1); +// BOOST_CHECK_EQUAL(reference_1.steps, result_1->steps); +// BOOST_CHECK_EQUAL(reference_1.alternatives, result_1->alternatives); +// BOOST_CHECK_EQUAL(reference_1.geometries, result_1->geometries); +// BOOST_CHECK_EQUAL(reference_1.annotations, result_1->annotations); +// BOOST_CHECK_EQUAL(reference_1.overview, result_1->overview); +// BOOST_CHECK_EQUAL(reference_1.continue_straight, result_1->continue_straight); +// CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); +// CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); +// CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); +// CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); +// CHECK_EQUAL_RANGE_OF_HINTS(reference_1.hints, result_1->hints); + +// RouteParameters reference_2{}; +// reference_2.alternatives = true; +// reference_2.number_of_alternatives = 1; +// reference_2.steps = true; +// reference_2.annotations = true; +// reference_2.coordinates = coords_1; +// auto result_2 = +// parseParameters("1,2;3,4?steps=true&alternatives=true&geometries=polyline&" +// "overview=simplified&annotations=true"); +// BOOST_CHECK(result_2); +// BOOST_CHECK_EQUAL(reference_2.steps, result_2->steps); +// BOOST_CHECK_EQUAL(reference_2.alternatives, result_2->alternatives); +// BOOST_CHECK_EQUAL(reference_2.number_of_alternatives, result_2->number_of_alternatives); +// BOOST_CHECK_EQUAL(reference_2.geometries, result_2->geometries); +// BOOST_CHECK_EQUAL(reference_2.annotations, result_2->annotations); +// BOOST_CHECK_EQUAL(reference_2.overview, result_2->overview); +// BOOST_CHECK_EQUAL(reference_2.continue_straight, result_2->continue_straight); +// CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); +// CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); +// CHECK_EQUAL_RANGE(reference_2.approaches, result_2->approaches); +// CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); +// CHECK_EQUAL_RANGE_OF_HINTS(reference_2.hints, result_2->hints); +// BOOST_CHECK_EQUAL(result_2->annotations_type == RouteParameters::AnnotationsType::All, true); + +// RouteParameters reference_3{false, +// false, +// false, +// RouteParameters::GeometriesType::GeoJSON, +// RouteParameters::OverviewType::False, +// true}; +// reference_3.coordinates = coords_1; +// auto result_3 = api::parseParameters( +// "1,2;3,4?steps=false&alternatives=false&geometries=geojson&overview=false&continue_" +// "straight=true"); +// BOOST_CHECK(result_3); +// BOOST_CHECK_EQUAL(reference_3.steps, result_3->steps); +// BOOST_CHECK_EQUAL(reference_3.alternatives, result_3->alternatives); +// BOOST_CHECK_EQUAL(reference_3.number_of_alternatives, result_3->number_of_alternatives); +// BOOST_CHECK_EQUAL(reference_3.geometries, result_3->geometries); +// BOOST_CHECK_EQUAL(reference_3.annotations, result_3->annotations); +// BOOST_CHECK_EQUAL(reference_3.overview, result_3->overview); +// BOOST_CHECK_EQUAL(reference_3.continue_straight, result_3->continue_straight); +// CHECK_EQUAL_RANGE(reference_3.bearings, result_3->bearings); +// CHECK_EQUAL_RANGE(reference_3.radiuses, result_3->radiuses); +// CHECK_EQUAL_RANGE(reference_3.approaches, result_3->approaches); +// CHECK_EQUAL_RANGE(reference_3.coordinates, result_3->coordinates); +// CHECK_EQUAL_RANGE_OF_HINTS(reference_3.hints, result_3->hints); + +// engine::PhantomNode phantom_1; +// phantom_1.input_location = coords_1[0]; +// engine::PhantomNode phantom_2; +// phantom_2.input_location = coords_1[1]; +// std::vector> hints_4 = { +// engine::Hint{{engine::SegmentHint{phantom_1, 0x1337}}}, +// engine::Hint{{engine::SegmentHint{phantom_2, 0x1337}}}}; +// RouteParameters reference_4{false, +// false, +// false, +// RouteParameters::GeometriesType::Polyline, +// RouteParameters::OverviewType::Simplified, +// std::optional{}, +// coords_1, +// hints_4, +// std::vector>{}, +// std::vector>{}}; +// auto result_4 = parseParameters( +// "1,2;3,4?steps=false&hints=" + hints_4[0]->ToBase64() + ";" + hints_4[1]->ToBase64()); +// BOOST_CHECK(result_4); +// BOOST_CHECK_EQUAL(reference_4.steps, result_4->steps); +// BOOST_CHECK_EQUAL(reference_4.alternatives, result_4->alternatives); +// BOOST_CHECK_EQUAL(reference_4.geometries, result_4->geometries); +// BOOST_CHECK_EQUAL(reference_4.annotations, result_4->annotations); +// BOOST_CHECK_EQUAL(reference_4.overview, result_4->overview); +// BOOST_CHECK_EQUAL(reference_4.continue_straight, result_4->continue_straight); +// CHECK_EQUAL_RANGE(reference_4.bearings, result_4->bearings); +// CHECK_EQUAL_RANGE(reference_4.radiuses, result_4->radiuses); +// CHECK_EQUAL_RANGE(reference_4.approaches, result_4->approaches); +// CHECK_EQUAL_RANGE(reference_4.coordinates, result_4->coordinates); +// CHECK_EQUAL_RANGE_OF_HINTS(reference_4.hints, result_4->hints); + +// std::vector> bearings_4 = { +// std::nullopt, +// engine::Bearing{200, 10}, +// engine::Bearing{100, 5}, +// }; +// RouteParameters reference_5{false, +// false, +// false, +// RouteParameters::GeometriesType::Polyline, +// RouteParameters::OverviewType::Simplified, +// std::optional{}, +// coords_1, +// std::vector>{}, +// std::vector>{}, +// bearings_4}; +// auto result_5 = parseParameters("1,2;3,4?steps=false&bearings=;200,10;100,5"); +// BOOST_CHECK(result_5); +// BOOST_CHECK_EQUAL(reference_5.steps, result_5->steps); +// BOOST_CHECK_EQUAL(reference_5.alternatives, result_5->alternatives); +// BOOST_CHECK_EQUAL(reference_5.geometries, result_5->geometries); +// BOOST_CHECK_EQUAL(reference_5.annotations, result_5->annotations); +// BOOST_CHECK_EQUAL(reference_5.overview, result_5->overview); +// BOOST_CHECK_EQUAL(reference_5.continue_straight, result_5->continue_straight); +// CHECK_EQUAL_RANGE(reference_5.bearings, result_5->bearings); +// CHECK_EQUAL_RANGE(reference_5.radiuses, result_5->radiuses); +// CHECK_EQUAL_RANGE(reference_5.approaches, result_5->approaches); +// CHECK_EQUAL_RANGE(reference_5.coordinates, result_5->coordinates); +// CHECK_EQUAL_RANGE_OF_HINTS(reference_5.hints, result_5->hints); + +// std::vector coords_2 = {{util::FloatLongitude{0}, util::FloatLatitude{1}}, +// {util::FloatLongitude{2}, util::FloatLatitude{3}}, +// {util::FloatLongitude{4}, util::FloatLatitude{5}}}; + +// RouteParameters reference_6{}; +// reference_6.coordinates = coords_2; +// auto result_6 = parseParameters("polyline(_ibE?_seK_seK_seK_seK)"); +// BOOST_CHECK(result_6); +// BOOST_CHECK_EQUAL(reference_6.steps, result_6->steps); +// BOOST_CHECK_EQUAL(reference_6.alternatives, result_6->alternatives); +// BOOST_CHECK_EQUAL(reference_6.geometries, result_6->geometries); +// BOOST_CHECK_EQUAL(reference_6.annotations, result_6->annotations); +// BOOST_CHECK_EQUAL(reference_6.overview, result_6->overview); +// BOOST_CHECK_EQUAL(reference_6.continue_straight, result_6->continue_straight); +// CHECK_EQUAL_RANGE(reference_6.bearings, result_6->bearings); +// CHECK_EQUAL_RANGE(reference_6.radiuses, result_6->radiuses); +// CHECK_EQUAL_RANGE(reference_6.approaches, result_6->approaches); +// CHECK_EQUAL_RANGE(reference_6.coordinates, result_6->coordinates); +// CHECK_EQUAL_RANGE_OF_HINTS(reference_6.hints, result_6->hints); + +// auto result_7 = parseParameters("1,2;3,4?radiuses=;unlimited"); +// RouteParameters reference_7{}; +// reference_7.coordinates = coords_1; +// reference_7.radiuses = {std::nullopt, +// std::make_optional(std::numeric_limits::infinity())}; +// BOOST_CHECK(result_7); +// BOOST_CHECK_EQUAL(reference_7.steps, result_7->steps); +// BOOST_CHECK_EQUAL(reference_7.alternatives, result_7->alternatives); +// BOOST_CHECK_EQUAL(reference_7.geometries, result_7->geometries); +// BOOST_CHECK_EQUAL(reference_7.annotations, result_7->annotations); +// BOOST_CHECK_EQUAL(reference_7.overview, result_7->overview); +// BOOST_CHECK_EQUAL(reference_7.continue_straight, result_7->continue_straight); +// CHECK_EQUAL_RANGE(reference_7.bearings, result_7->bearings); +// CHECK_EQUAL_RANGE(reference_7.radiuses, result_7->radiuses); +// CHECK_EQUAL_RANGE(reference_7.approaches, result_7->approaches); +// CHECK_EQUAL_RANGE(reference_7.coordinates, result_7->coordinates); +// CHECK_EQUAL_RANGE_OF_HINTS(reference_7.hints, result_7->hints); + +// auto result_8 = parseParameters("1,2;3,4?radiuses=;"); +// RouteParameters reference_8{}; +// reference_8.coordinates = coords_1; +// reference_8.radiuses = {std::nullopt, std::nullopt}; +// BOOST_CHECK(result_8); +// CHECK_EQUAL_RANGE(reference_8.radiuses, result_8->radiuses); + +// auto result_9 = parseParameters("1,2?radiuses="); +// RouteParameters reference_9{}; +// reference_9.coordinates = coords_1; +// reference_9.radiuses = {std::nullopt}; +// BOOST_CHECK(result_9); +// CHECK_EQUAL_RANGE(reference_9.radiuses, result_9->radiuses); + +// // Some Hint's are empty +// std::vector coords_3 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, +// {util::FloatLongitude{3}, util::FloatLatitude{4}}, +// {util::FloatLongitude{5}, util::FloatLatitude{6}}, +// {util::FloatLongitude{7}, util::FloatLatitude{8}}}; + +// engine::PhantomNode phantom_3; +// phantom_3.input_location = coords_3[0]; +// engine::PhantomNode phantom_4; +// phantom_4.input_location = coords_3[2]; +// std::vector> hints_10 = { +// engine::Hint{{engine::SegmentHint{phantom_3, 0x1337}}}, +// {}, +// engine::Hint{{engine::SegmentHint{phantom_4, 0x1337}}}, +// {}}; + +// RouteParameters reference_10{false, +// false, +// false, +// RouteParameters::GeometriesType::Polyline, +// RouteParameters::OverviewType::Simplified, +// std::optional{}, +// coords_3, +// hints_10, +// std::vector>{}, +// std::vector>{}}; +// auto result_10 = parseParameters( +// "1,2;3,4;5,6;7,8?steps=false&hints=" + hints_10[0]->ToBase64() + ";;" + +// hints_10[2]->ToBase64() + ";"); +// BOOST_CHECK(result_10); +// BOOST_CHECK_EQUAL(reference_10.steps, result_10->steps); +// BOOST_CHECK_EQUAL(reference_10.alternatives, result_10->alternatives); +// BOOST_CHECK_EQUAL(reference_10.geometries, result_10->geometries); +// BOOST_CHECK_EQUAL(reference_10.annotations, result_10->annotations); +// BOOST_CHECK_EQUAL(reference_10.overview, result_10->overview); +// BOOST_CHECK_EQUAL(reference_10.continue_straight, result_10->continue_straight); +// CHECK_EQUAL_RANGE(reference_10.bearings, result_10->bearings); +// CHECK_EQUAL_RANGE(reference_10.radiuses, result_10->radiuses); +// CHECK_EQUAL_RANGE(reference_10.approaches, result_10->approaches); +// CHECK_EQUAL_RANGE(reference_10.coordinates, result_10->coordinates); +// CHECK_EQUAL_RANGE_OF_HINTS(reference_10.hints, result_10->hints); + +// // Do not generate Hints when they are explicitly disabled +// auto result_11 = parseParameters("1,2;3,4?generate_hints=false"); +// BOOST_CHECK(result_11); +// BOOST_CHECK_EQUAL(result_11->generate_hints, false); + +// auto result_12 = parseParameters("1,2;3,4?generate_hints=true"); +// BOOST_CHECK(result_12); +// BOOST_CHECK_EQUAL(result_12->generate_hints, true); + +// auto result_13 = parseParameters("1,2;3,4"); +// BOOST_CHECK(result_13); +// BOOST_CHECK_EQUAL(result_13->generate_hints, true); + +// // parse none annotations value correctly +// RouteParameters reference_14{}; +// reference_14.annotations_type = RouteParameters::AnnotationsType::None; +// reference_14.coordinates = coords_1; +// auto result_14 = parseParameters("1,2;3,4?geometries=polyline"); +// BOOST_CHECK(result_14); +// BOOST_CHECK_EQUAL(reference_14.geometries, result_14->geometries); +// BOOST_CHECK_EQUAL(result_14->annotations_type == RouteParameters::AnnotationsType::None, true); +// BOOST_CHECK_EQUAL(result_14->annotations, false); + +// // parse single annotations value correctly +// RouteParameters reference_15{}; +// reference_15.annotations_type = RouteParameters::AnnotationsType::Duration; +// reference_15.coordinates = coords_1; +// auto result_15 = parseParameters("1,2;3,4?geometries=polyline&" +// "overview=simplified&annotations=duration"); +// BOOST_CHECK(result_15); +// BOOST_CHECK_EQUAL(reference_15.geometries, result_15->geometries); +// BOOST_CHECK_EQUAL(result_15->annotations_type == RouteParameters::AnnotationsType::Duration, +// true); +// BOOST_CHECK_EQUAL(result_15->annotations, true); + +// RouteParameters reference_speed{}; +// reference_speed.annotations_type = RouteParameters::AnnotationsType::Duration; +// reference_speed.coordinates = coords_1; +// auto result_speed = +// parseParameters("1,2;3,4?geometries=polyline&" +// "overview=simplified&annotations=duration,distance,speed"); +// BOOST_CHECK(result_speed); +// BOOST_CHECK_EQUAL(reference_speed.geometries, result_speed->geometries); +// BOOST_CHECK_EQUAL(reference_speed.overview, result_speed->overview); +// BOOST_CHECK_EQUAL(result_speed->annotations_type == +// (RouteParameters::AnnotationsType::Duration | +// RouteParameters::AnnotationsType::Distance | +// RouteParameters::AnnotationsType::Speed), +// true); +// BOOST_CHECK_EQUAL(result_speed->annotations, true); + +// // parse multiple annotations correctly +// RouteParameters reference_16{}; +// reference_16.annotations_type = RouteParameters::AnnotationsType::Duration | +// RouteParameters::AnnotationsType::Weight | +// RouteParameters::AnnotationsType::Nodes; +// reference_16.coordinates = coords_1; +// auto result_16 = +// parseParameters("1,2;3,4?geometries=polyline&" +// "overview=simplified&annotations=duration,weight,nodes"); +// BOOST_CHECK(result_16); +// BOOST_CHECK_EQUAL(reference_16.geometries, result_16->geometries); +// BOOST_CHECK_EQUAL(static_cast(result_16->annotations_type & +// (RouteParameters::AnnotationsType::Weight | +// RouteParameters::AnnotationsType::Duration | +// RouteParameters::AnnotationsType::Nodes)), +// true); +// BOOST_CHECK_EQUAL(result_16->annotations, true); + +// // parse all annotations correctly +// RouteParameters reference_17{}; +// reference_17.annotations_type = RouteParameters::AnnotationsType::All; +// reference_17.coordinates = coords_1; +// auto result_17 = parseParameters( +// "1,2;3,4?overview=simplified&annotations=duration,weight,nodes,datasources,distance"); +// BOOST_CHECK(result_17); +// BOOST_CHECK_EQUAL(reference_17.geometries, result_17->geometries); +// BOOST_CHECK_EQUAL(result_2->annotations_type == RouteParameters::AnnotationsType::All, true); +// BOOST_CHECK_EQUAL(result_17->annotations, true); + +// std::vector> approaches_18 = { +// std::nullopt, +// engine::Approach::CURB, +// engine::Approach::UNRESTRICTED, +// engine::Approach::OPPOSITE, +// }; +// RouteParameters reference_18{false, +// false, +// false, +// RouteParameters::GeometriesType::Polyline, +// RouteParameters::OverviewType::Simplified, +// std::optional{}, +// coords_3, +// std::vector>{}, +// std::vector>{}, +// std::vector>{}, +// approaches_18}; + +// auto result_18 = parseParameters( +// "1,2;3,4;5,6;7,8?steps=false&approaches=;curb;unrestricted;opposite"); +// BOOST_CHECK(result_18); +// BOOST_CHECK_EQUAL(reference_18.steps, result_18->steps); +// BOOST_CHECK_EQUAL(reference_18.alternatives, result_18->alternatives); +// BOOST_CHECK_EQUAL(reference_18.geometries, result_18->geometries); +// BOOST_CHECK_EQUAL(reference_18.annotations, result_18->annotations); +// BOOST_CHECK_EQUAL(reference_18.overview, result_18->overview); +// BOOST_CHECK_EQUAL(reference_18.continue_straight, result_18->continue_straight); +// CHECK_EQUAL_RANGE(reference_18.bearings, result_18->bearings); +// CHECK_EQUAL_RANGE(reference_18.radiuses, result_18->radiuses); +// CHECK_EQUAL_RANGE(reference_18.approaches, result_18->approaches); +// CHECK_EQUAL_RANGE(reference_18.coordinates, result_18->coordinates); +// CHECK_EQUAL_RANGE_OF_HINTS(reference_18.hints, result_18->hints); + +// RouteParameters reference_19{}; +// reference_19.alternatives = true; +// reference_19.number_of_alternatives = 3; +// reference_19.coordinates = coords_1; +// auto result_19 = parseParameters("1,2;3,4?alternatives=3"); +// BOOST_CHECK(result_19); +// BOOST_CHECK_EQUAL(reference_19.steps, result_19->steps); +// BOOST_CHECK_EQUAL(reference_19.alternatives, result_19->alternatives); +// BOOST_CHECK_EQUAL(reference_19.number_of_alternatives, result_19->number_of_alternatives); +// BOOST_CHECK_EQUAL(reference_19.geometries, result_19->geometries); +// BOOST_CHECK_EQUAL(reference_19.annotations, result_19->annotations); +// BOOST_CHECK_EQUAL(reference_19.overview, result_19->overview); +// BOOST_CHECK_EQUAL(reference_19.continue_straight, result_19->continue_straight); +// CHECK_EQUAL_RANGE(reference_19.bearings, result_19->bearings); +// CHECK_EQUAL_RANGE(reference_19.radiuses, result_19->radiuses); +// CHECK_EQUAL_RANGE(reference_19.approaches, result_19->approaches); +// CHECK_EQUAL_RANGE(reference_19.coordinates, result_19->coordinates); +// CHECK_EQUAL_RANGE_OF_HINTS(reference_19.hints, result_19->hints); + +// RouteParameters reference_20{}; +// reference_20.alternatives = false; +// reference_20.number_of_alternatives = 0; +// reference_20.coordinates = coords_1; +// auto result_20 = parseParameters("1,2;3,4?alternatives=0"); +// BOOST_CHECK(result_20); +// BOOST_CHECK_EQUAL(reference_20.steps, result_20->steps); +// BOOST_CHECK_EQUAL(reference_20.alternatives, result_20->alternatives); +// BOOST_CHECK_EQUAL(reference_20.number_of_alternatives, result_20->number_of_alternatives); +// BOOST_CHECK_EQUAL(reference_20.geometries, result_20->geometries); +// BOOST_CHECK_EQUAL(reference_20.annotations, result_20->annotations); +// BOOST_CHECK_EQUAL(reference_20.overview, result_20->overview); +// BOOST_CHECK_EQUAL(reference_20.continue_straight, result_20->continue_straight); +// CHECK_EQUAL_RANGE(reference_20.bearings, result_20->bearings); +// CHECK_EQUAL_RANGE(reference_20.radiuses, result_20->radiuses); +// CHECK_EQUAL_RANGE(reference_20.approaches, result_20->approaches); +// CHECK_EQUAL_RANGE(reference_20.coordinates, result_20->coordinates); +// CHECK_EQUAL_RANGE_OF_HINTS(reference_20.hints, result_20->hints); + +// // exclude flags +// RouteParameters reference_21{}; +// reference_21.exclude = {"ferry", "motorway"}; +// reference_21.coordinates = coords_1; +// auto result_21 = parseParameters("1,2;3,4?exclude=ferry,motorway"); +// BOOST_CHECK(result_21); +// BOOST_CHECK_EQUAL(reference_21.steps, result_21->steps); +// BOOST_CHECK_EQUAL(reference_21.alternatives, result_21->alternatives); +// BOOST_CHECK_EQUAL(reference_21.number_of_alternatives, result_21->number_of_alternatives); +// BOOST_CHECK_EQUAL(reference_21.geometries, result_21->geometries); +// BOOST_CHECK_EQUAL(reference_21.annotations, result_21->annotations); +// BOOST_CHECK_EQUAL(reference_21.overview, result_21->overview); +// BOOST_CHECK_EQUAL(reference_21.continue_straight, result_21->continue_straight); +// CHECK_EQUAL_RANGE(reference_21.bearings, result_21->bearings); +// CHECK_EQUAL_RANGE(reference_21.radiuses, result_21->radiuses); +// CHECK_EQUAL_RANGE(reference_21.approaches, result_21->approaches); +// CHECK_EQUAL_RANGE(reference_21.coordinates, result_21->coordinates); +// CHECK_EQUAL_RANGE_OF_HINTS(reference_21.hints, result_21->hints); +// CHECK_EQUAL_RANGE(reference_21.exclude, result_21->exclude); +// } + +// BOOST_AUTO_TEST_CASE(valid_table_urls) +// { +// std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, +// {util::FloatLongitude{3}, util::FloatLatitude{4}}}; + +// TableParameters reference_1{}; +// reference_1.coordinates = coords_1; +// auto result_1 = parseParameters("1,2;3,4"); +// BOOST_CHECK(result_1); +// CHECK_EQUAL_RANGE(reference_1.sources, result_1->sources); +// CHECK_EQUAL_RANGE(reference_1.destinations, result_1->destinations); +// CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); +// CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); +// CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); +// CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); + +// std::vector sources_2 = {1, 2, 3}; +// std::vector destinations_2 = {4, 5}; +// TableParameters reference_2{sources_2, destinations_2}; +// reference_2.coordinates = coords_1; +// auto result_2 = parseParameters("1,2;3,4?sources=1;2;3&destinations=4;5"); +// BOOST_CHECK(result_2); +// CHECK_EQUAL_RANGE(reference_2.sources, result_2->sources); +// CHECK_EQUAL_RANGE(reference_2.destinations, result_2->destinations); +// CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); +// CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); +// CHECK_EQUAL_RANGE(reference_2.approaches, result_2->approaches); +// CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); + +// auto result_3 = parseParameters("1,2;3,4?sources=all&destinations=all"); +// BOOST_CHECK(result_3); +// CHECK_EQUAL_RANGE(reference_1.sources, result_3->sources); +// CHECK_EQUAL_RANGE(reference_1.destinations, result_3->destinations); +// CHECK_EQUAL_RANGE(reference_1.bearings, result_3->bearings); +// CHECK_EQUAL_RANGE(reference_1.radiuses, result_3->radiuses); +// CHECK_EQUAL_RANGE(reference_1.approaches, result_3->approaches); +// CHECK_EQUAL_RANGE(reference_1.coordinates, result_3->coordinates); + +// TableParameters reference_4{}; +// reference_4.coordinates = coords_1; +// auto result_4 = parseParameters( +// "1,2;3,4?sources=all&destinations=all&annotations=duration"); +// BOOST_CHECK(result_4); +// BOOST_CHECK_EQUAL(result_4->annotations & (TableParameters::AnnotationsType::Distance | +// TableParameters::AnnotationsType::Duration), +// true); +// CHECK_EQUAL_RANGE(reference_4.sources, result_4->sources); +// CHECK_EQUAL_RANGE(reference_4.destinations, result_4->destinations); + +// TableParameters reference_5{}; +// reference_5.coordinates = coords_1; +// auto result_5 = parseParameters( +// "1,2;3,4?sources=all&destinations=all&annotations=duration"); +// BOOST_CHECK(result_5); +// BOOST_CHECK_EQUAL(result_5->annotations & TableParameters::AnnotationsType::Duration, true); +// CHECK_EQUAL_RANGE(reference_5.sources, result_5->sources); +// CHECK_EQUAL_RANGE(reference_5.destinations, result_5->destinations); + +// TableParameters reference_6{}; +// reference_6.coordinates = coords_1; +// auto result_6 = parseParameters( +// "1,2;3,4?sources=all&destinations=all&annotations=distance"); +// BOOST_CHECK(result_6); +// BOOST_CHECK_EQUAL(result_6->annotations & TableParameters::AnnotationsType::Distance, true); +// CHECK_EQUAL_RANGE(reference_6.sources, result_6->sources); +// CHECK_EQUAL_RANGE(reference_6.destinations, result_6->destinations); + +// TableParameters reference_7{}; +// reference_7.coordinates = coords_1; +// auto result_7 = parseParameters("1,2;3,4?annotations=distance"); +// BOOST_CHECK(result_7); +// BOOST_CHECK_EQUAL(result_7->annotations & TableParameters::AnnotationsType::Distance, true); +// CHECK_EQUAL_RANGE(reference_7.sources, result_7->sources); +// CHECK_EQUAL_RANGE(reference_7.destinations, result_7->destinations); + +// TableParameters reference_8{}; +// reference_8.coordinates = coords_1; +// auto result_8 = +// parseParameters("1,2;3,4?annotations=distance&fallback_speed=2.5"); +// BOOST_CHECK(result_8); +// BOOST_CHECK_EQUAL(result_8->annotations & TableParameters::AnnotationsType::Distance, true); +// CHECK_EQUAL_RANGE(reference_8.sources, result_8->sources); +// CHECK_EQUAL_RANGE(reference_8.destinations, result_8->destinations); + +// TableParameters reference_9{}; +// reference_9.coordinates = coords_1; +// auto result_9 = parseParameters( +// "1,2;3,4?annotations=distance&fallback_speed=2.5&fallback_coordinate=input"); +// BOOST_CHECK(result_9); +// BOOST_CHECK_EQUAL(result_9->annotations & TableParameters::AnnotationsType::Distance, true); +// CHECK_EQUAL_RANGE(reference_9.sources, result_9->sources); +// CHECK_EQUAL_RANGE(reference_9.destinations, result_9->destinations); + +// TableParameters reference_10{}; +// reference_10.coordinates = coords_1; +// auto result_10 = parseParameters( +// "1,2;3,4?annotations=distance&fallback_speed=20&fallback_coordinate=snapped"); +// BOOST_CHECK(result_10); +// BOOST_CHECK_EQUAL(result_10->annotations & TableParameters::AnnotationsType::Distance, true); +// CHECK_EQUAL_RANGE(reference_10.sources, result_10->sources); +// CHECK_EQUAL_RANGE(reference_10.destinations, result_10->destinations); + +// auto result_11 = parseParameters("1,2;3,4?sources=all&destinations=all&" +// "annotations=duration&fallback_speed=1&" +// "fallback_coordinate=snapped&scale_factor=2"); +// BOOST_CHECK(result_11); +// CHECK_EQUAL_RANGE(reference_1.sources, result_11->sources); +// CHECK_EQUAL_RANGE(reference_1.destinations, result_11->destinations); +// CHECK_EQUAL_RANGE(reference_1.bearings, result_11->bearings); +// CHECK_EQUAL_RANGE(reference_1.radiuses, result_11->radiuses); +// CHECK_EQUAL_RANGE(reference_1.approaches, result_11->approaches); +// CHECK_EQUAL_RANGE(reference_1.coordinates, result_11->coordinates); +// } + +// BOOST_AUTO_TEST_CASE(valid_match_urls) +// { +// std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, +// {util::FloatLongitude{3}, util::FloatLatitude{4}}}; + +// MatchParameters reference_1{}; +// reference_1.coordinates = coords_1; +// auto result_1 = parseParameters("1,2;3,4"); +// BOOST_CHECK(result_1); +// CHECK_EQUAL_RANGE(reference_1.timestamps, result_1->timestamps); +// CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); +// CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); +// CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); +// CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); + +// MatchParameters reference_2{}; +// reference_2.coordinates = coords_1; +// reference_2.timestamps = {5, 6}; +// auto result_2 = parseParameters("1,2;3,4?timestamps=5;6"); +// BOOST_CHECK(result_2); +// CHECK_EQUAL_RANGE(reference_2.timestamps, result_2->timestamps); +// CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); +// CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); +// CHECK_EQUAL_RANGE(reference_2.approaches, result_2->approaches); +// CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); + +// std::vector coords_2 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, +// {util::FloatLongitude{3}, util::FloatLatitude{4}}, +// {util::FloatLongitude{5}, util::FloatLatitude{6}}}; + +// MatchParameters reference_3{}; +// reference_3.coordinates = coords_2; +// reference_3.waypoints = {0, 2}; +// auto result_3 = parseParameters("1,2;3,4;5,6?waypoints=0;2"); +// BOOST_CHECK(result_3); +// CHECK_EQUAL_RANGE(reference_3.waypoints, result_3->waypoints); +// CHECK_EQUAL_RANGE(reference_3.timestamps, result_3->timestamps); +// CHECK_EQUAL_RANGE(reference_3.bearings, result_3->bearings); +// CHECK_EQUAL_RANGE(reference_3.radiuses, result_3->radiuses); +// CHECK_EQUAL_RANGE(reference_3.approaches, result_3->approaches); +// CHECK_EQUAL_RANGE(reference_3.coordinates, result_3->coordinates); +// } + +// BOOST_AUTO_TEST_CASE(invalid_match_urls) +// { +// std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, +// {util::FloatLongitude{3}, util::FloatLatitude{4}}}; + +// MatchParameters reference_1{}; +// reference_1.coordinates = coords_1; +// auto result_1 = parseParameters("1,2;3,4?radiuses=unlimited;60"); +// BOOST_CHECK(result_1); +// CHECK_EQUAL_RANGE(reference_1.timestamps, result_1->timestamps); +// CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); +// BOOST_CHECK(reference_1.radiuses != result_1->radiuses); +// CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); +// CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); + +// std::vector coords_2 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, +// {util::FloatLongitude{3}, util::FloatLatitude{4}}}; + +// MatchParameters reference_2{}; +// reference_2.coordinates = coords_2; +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?waypoints=0,4"), 19UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?waypoints=x;4"), 18UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?waypoints=0;3.5"), 21UL); +// } + +// BOOST_AUTO_TEST_CASE(valid_nearest_urls) +// { +// std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}}; + +// NearestParameters reference_1{}; +// reference_1.coordinates = coords_1; +// auto result_1 = parseParameters("1,2"); +// BOOST_CHECK(result_1); +// BOOST_CHECK_EQUAL(reference_1.number_of_results, result_1->number_of_results); +// CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); +// CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); +// CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); +// CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); + +// NearestParameters reference_2{}; +// reference_2.coordinates = coords_1; +// reference_2.number_of_results = 42; +// auto result_2 = parseParameters("1,2?number=42"); +// BOOST_CHECK(result_2); +// BOOST_CHECK_EQUAL(reference_2.number_of_results, result_2->number_of_results); +// CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); +// CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); +// CHECK_EQUAL_RANGE(reference_2.approaches, result_2->approaches); +// CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); +// } + +// BOOST_AUTO_TEST_CASE(invalid_tile_urls) +// { +// TileParameters reference_1{1, 2, 3}; +// auto result_1 = parseParameters("tile(1,2,3).mvt"); +// BOOST_CHECK(result_1); +// BOOST_CHECK(!result_1->IsValid()); +// BOOST_CHECK_EQUAL(reference_1.x, result_1->x); +// BOOST_CHECK_EQUAL(reference_1.y, result_1->y); +// BOOST_CHECK_EQUAL(reference_1.z, result_1->z); +// } + +// BOOST_AUTO_TEST_CASE(valid_tile_urls) +// { +// TileParameters reference_1{1, 2, 12}; +// auto result_1 = parseParameters("tile(1,2,12).mvt"); +// BOOST_CHECK(result_1->IsValid()); +// BOOST_CHECK(result_1); +// BOOST_CHECK_EQUAL(reference_1.x, result_1->x); +// BOOST_CHECK_EQUAL(reference_1.y, result_1->y); +// BOOST_CHECK_EQUAL(reference_1.z, result_1->z); +// } + +// BOOST_AUTO_TEST_CASE(valid_trip_urls) +// { +// std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, +// {util::FloatLongitude{3}, util::FloatLatitude{4}}}; + +// TripParameters reference_1{}; +// reference_1.coordinates = coords_1; +// auto result_1 = parseParameters("1,2;3,4"); +// BOOST_CHECK(result_1); +// CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); +// CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); + +// TripParameters reference_2{}; +// reference_2.coordinates = coords_1; +// reference_2.source = TripParameters::SourceType::First; +// reference_2.destination = TripParameters::DestinationType::Last; +// auto result_2 = parseParameters("1,2;3,4?source=first&destination=last"); +// BOOST_CHECK(result_2); +// CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); +// CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); + +// // check supported source/destination/rountrip combinations +// auto param_fse_r = +// parseParameters("1,2;3,4?source=first&destination=last&roundtrip=true"); +// BOOST_CHECK(param_fse_r->IsValid()); +// auto param_fse_nr_ = +// parseParameters("1,2;3,4?source=first&destination=last&roundtrip=false"); +// BOOST_CHECK(param_fse_nr_->IsValid()); +// auto param_fs_r = parseParameters("1,2;3,4?source=first&roundtrip=true"); +// BOOST_CHECK(param_fs_r->IsValid()); +// auto param_fs_nr = parseParameters("1,2;3,4?source=first&roundtrip=false"); +// BOOST_CHECK(param_fs_nr->IsValid()); +// auto param_fe_r = parseParameters("1,2;3,4?destination=last&roundtrip=true"); +// BOOST_CHECK(param_fe_r->IsValid()); +// auto param_fe_nr = parseParameters("1,2;3,4?destination=last&roundtrip=false"); +// BOOST_CHECK(param_fe_nr->IsValid()); +// auto param_r = parseParameters("1,2;3,4?roundtrip=true"); +// BOOST_CHECK(param_r->IsValid()); +// auto param_nr = parseParameters("1,2;3,4?roundtrip=false"); +// BOOST_CHECK(param_nr->IsValid()); + +// auto param_fail_1 = +// testInvalidOptions("1,2;3,4?source=blubb&destination=random"); +// BOOST_CHECK_EQUAL(param_fail_1, 15UL); +// auto param_fail_2 = testInvalidOptions("1,2;3,4?source=first&destination=nah"); +// BOOST_CHECK_EQUAL(param_fail_2, 33UL); +// } + +// BOOST_AUTO_TEST_SUITE_END() From 9388784c69e11ab852b1a63347b4101fff0630ab Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sun, 30 Jun 2024 19:50:44 +0200 Subject: [PATCH 4/9] Yet another attempt to get rid of boost::optional --- unit_tests/server/parameters_parser.cpp | 44 +++++++++++++++---------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/unit_tests/server/parameters_parser.cpp b/unit_tests/server/parameters_parser.cpp index 6702a0188c4..bfa10bb80d2 100644 --- a/unit_tests/server/parameters_parser.cpp +++ b/unit_tests/server/parameters_parser.cpp @@ -54,11 +54,13 @@ // BOOST_CHECK_EQUAL(testInvalidOptions("a;3,4"), 0UL); // BOOST_CHECK_EQUAL(testInvalidOptions("120;3,4"), 3UL); // BOOST_CHECK_EQUAL(testInvalidOptions("90000000,2;3,4"), 0UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&bla=foo"), 22UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&bla=foo"), +// 22UL); // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&bearings=foo"), // 32UL); // BOOST_CHECK_EQUAL( -// testInvalidOptions("1,2;3,4?overview=false&continue_straight=foo"), 41UL); +// testInvalidOptions("1,2;3,4?overview=false&continue_straight=foo"), +// 41UL); // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&radiuses=foo"), // 32UL); // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&approaches=foo"), @@ -82,21 +84,22 @@ // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4.json?nooptions"), 13); // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4..json?nooptions"), 14); // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4.0.json?nooptions"), 15); -// BOOST_CHECK_EQUAL(testInvalidOptions(std::string{"1,2;3,4"} + '\0' + ".json"), +// BOOST_CHECK_EQUAL(testInvalidOptions(std::string{"1,2;3,4"} + '\0' + +// ".json"), // 7); // BOOST_CHECK_EQUAL(testInvalidOptions(std::string{"1,2;3,"} + '\0'), 6); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations=distances"), 28UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations="), 20UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations=true,false"), 24UL); -// BOOST_CHECK_EQUAL( +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations=distances"), +// 28UL); BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations="), 20UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations=true,false"), +// 24UL); BOOST_CHECK_EQUAL( // testInvalidOptions("1,2;3,4?annotations=&overview=simplified"), 20UL); // } // BOOST_AUTO_TEST_CASE(invalid_table_urls) // { // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?sources=1&bla=foo"), 17UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?destinations=1&bla=foo"), 22UL); -// BOOST_CHECK_EQUAL( +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?destinations=1&bla=foo"), +// 22UL); BOOST_CHECK_EQUAL( // testInvalidOptions("1,2;3,4?sources=1&destinations=1&bla=foo"), 32UL); // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?sources=foo"), 16UL); // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?destinations=foo"), 21UL); @@ -105,11 +108,13 @@ // 49UL); // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?fallback_coordinate=asdf"), // 28UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?fallback_coordinate=10"), 28UL); -// BOOST_CHECK_EQUAL( -// testInvalidOptions("1,2;3,4?annotations=durations&scale_factor=-1"), 28UL); +// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?fallback_coordinate=10"), +// 28UL); BOOST_CHECK_EQUAL( +// testInvalidOptions("1,2;3,4?annotations=durations&scale_factor=-1"), +// 28UL); // BOOST_CHECK_EQUAL( -// testInvalidOptions("1,2;3,4?annotations=durations&scale_factor=0"), 28UL); +// testInvalidOptions("1,2;3,4?annotations=durations&scale_factor=0"), +// 28UL); // BOOST_CHECK_EQUAL( // testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=0"), // 28UL); @@ -259,7 +264,8 @@ // std::vector>{}, // std::vector>{}, // bearings_4}; -// auto result_5 = parseParameters("1,2;3,4?steps=false&bearings=;200,10;100,5"); +// auto result_5 = +// parseParameters("1,2;3,4?steps=false&bearings=;200,10;100,5"); // BOOST_CHECK(result_5); // BOOST_CHECK_EQUAL(reference_5.steps, result_5->steps); // BOOST_CHECK_EQUAL(reference_5.alternatives, result_5->alternatives); @@ -387,8 +393,8 @@ // auto result_14 = parseParameters("1,2;3,4?geometries=polyline"); // BOOST_CHECK(result_14); // BOOST_CHECK_EQUAL(reference_14.geometries, result_14->geometries); -// BOOST_CHECK_EQUAL(result_14->annotations_type == RouteParameters::AnnotationsType::None, true); -// BOOST_CHECK_EQUAL(result_14->annotations, false); +// BOOST_CHECK_EQUAL(result_14->annotations_type == RouteParameters::AnnotationsType::None, +// true); BOOST_CHECK_EQUAL(result_14->annotations, false); // // parse single annotations value correctly // RouteParameters reference_15{}; @@ -803,7 +809,8 @@ // BOOST_CHECK(param_fs_nr->IsValid()); // auto param_fe_r = parseParameters("1,2;3,4?destination=last&roundtrip=true"); // BOOST_CHECK(param_fe_r->IsValid()); -// auto param_fe_nr = parseParameters("1,2;3,4?destination=last&roundtrip=false"); +// auto param_fe_nr = +// parseParameters("1,2;3,4?destination=last&roundtrip=false"); // BOOST_CHECK(param_fe_nr->IsValid()); // auto param_r = parseParameters("1,2;3,4?roundtrip=true"); // BOOST_CHECK(param_r->IsValid()); @@ -813,7 +820,8 @@ // auto param_fail_1 = // testInvalidOptions("1,2;3,4?source=blubb&destination=random"); // BOOST_CHECK_EQUAL(param_fail_1, 15UL); -// auto param_fail_2 = testInvalidOptions("1,2;3,4?source=first&destination=nah"); +// auto param_fail_2 = +// testInvalidOptions("1,2;3,4?source=first&destination=nah"); // BOOST_CHECK_EQUAL(param_fail_2, 33UL); // } From 5c5d8455719767fd6f74140b427ddbab38df0fe8 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sun, 30 Jun 2024 20:09:14 +0200 Subject: [PATCH 5/9] Yet another attempt to get rid of boost::optional --- unit_tests/server/parameters_parser.cpp | 829 +----------------------- 1 file changed, 1 insertion(+), 828 deletions(-) diff --git a/unit_tests/server/parameters_parser.cpp b/unit_tests/server/parameters_parser.cpp index bfa10bb80d2..3db8947dedd 100644 --- a/unit_tests/server/parameters_parser.cpp +++ b/unit_tests/server/parameters_parser.cpp @@ -1,828 +1 @@ -// #include "server/api/parameters_parser.hpp" - -// #include "parameters_io.hpp" - -// #include "engine/api/base_parameters.hpp" -// #include "engine/api/match_parameters.hpp" -// #include "engine/api/nearest_parameters.hpp" -// #include "engine/api/route_parameters.hpp" -// #include "engine/api/table_parameters.hpp" -// #include "engine/api/tile_parameters.hpp" -// #include "engine/api/trip_parameters.hpp" - -// #include "util/debug.hpp" - -// #include -// #include -// #include - -// #define CHECK_EQUAL_RANGE(R1, R2) \ -// BOOST_CHECK_EQUAL_COLLECTIONS((R1).begin(), (R1).end(), (R2).begin(), (R2).end()); - -// #define CHECK_EQUAL_RANGE_OF_HINTS(R1, R2) \ -// BOOST_REQUIRE_EQUAL((R1).size(), (R2).size()); \ -// for (const auto i : util::irange(0UL, (R1).size())) \ -// { \ -// BOOST_REQUIRE(((R1)[i] && (R2)[i]) || !((R1)[i] || (R2)[i])); \ -// if ((R1)[i]) \ -// { \ -// BOOST_CHECK_EQUAL_COLLECTIONS((R1)[i]->segment_hints.begin(), \ -// (R1)[i]->segment_hints.end(), \ -// (R2)[i]->segment_hints.begin(), \ -// (R2)[i]->segment_hints.end()); \ -// } \ -// } - -// BOOST_AUTO_TEST_SUITE(api_parameters_parser) - -// using namespace osrm; -// using namespace osrm::server; -// using namespace osrm::server::api; -// using namespace osrm::engine::api; - -// // returns distance to front -// template std::size_t testInvalidOptions(std::string options) -// { -// auto iter = options.begin(); -// auto result = parseParameters(iter, options.end()); -// BOOST_CHECK(!result); -// return std::distance(options.begin(), iter); -// } - -// BOOST_AUTO_TEST_CASE(invalid_route_urls) -// { -// BOOST_CHECK_EQUAL(testInvalidOptions("a;3,4"), 0UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("120;3,4"), 3UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("90000000,2;3,4"), 0UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&bla=foo"), -// 22UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&bearings=foo"), -// 32UL); -// BOOST_CHECK_EQUAL( -// testInvalidOptions("1,2;3,4?overview=false&continue_straight=foo"), -// 41UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&radiuses=foo"), -// 32UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&approaches=foo"), -// 34UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&hints=foo"), -// 29UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&hints=;;; ;"), -// 32UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?generate_hints=notboolean"), -// 23UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&geometries=foo"), -// 34UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&overview=foo"), -// 32L); -// BOOST_CHECK_EQUAL( -// testInvalidOptions("1,2;3,4?overview=false&alternatives=foo"), 36UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&alternatives=-1"), -// 36UL); -// BOOST_CHECK_EQUAL(testInvalidOptions(""), 0); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3.4.unsupported"), 7); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4.json?nooptions"), 13); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4..json?nooptions"), 14); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4.0.json?nooptions"), 15); -// BOOST_CHECK_EQUAL(testInvalidOptions(std::string{"1,2;3,4"} + '\0' + -// ".json"), -// 7); -// BOOST_CHECK_EQUAL(testInvalidOptions(std::string{"1,2;3,"} + '\0'), 6); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations=distances"), -// 28UL); BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations="), 20UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations=true,false"), -// 24UL); BOOST_CHECK_EQUAL( -// testInvalidOptions("1,2;3,4?annotations=&overview=simplified"), 20UL); -// } - -// BOOST_AUTO_TEST_CASE(invalid_table_urls) -// { -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?sources=1&bla=foo"), 17UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?destinations=1&bla=foo"), -// 22UL); BOOST_CHECK_EQUAL( -// testInvalidOptions("1,2;3,4?sources=1&destinations=1&bla=foo"), 32UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?sources=foo"), 16UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?destinations=foo"), 21UL); -// BOOST_CHECK_EQUAL( -// testInvalidOptions("1,2;3,4?sources=all&destinations=all&annotations=bla"), -// 49UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?fallback_coordinate=asdf"), -// 28UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?fallback_coordinate=10"), -// 28UL); BOOST_CHECK_EQUAL( -// testInvalidOptions("1,2;3,4?annotations=durations&scale_factor=-1"), -// 28UL); -// BOOST_CHECK_EQUAL( -// testInvalidOptions("1,2;3,4?annotations=durations&scale_factor=0"), -// 28UL); -// BOOST_CHECK_EQUAL( -// testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=0"), -// 28UL); -// BOOST_CHECK_EQUAL( -// testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=-1"), -// 28UL); -// BOOST_CHECK_EQUAL( -// testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=0"), -// 28UL); -// BOOST_CHECK_EQUAL( -// testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=-1"), -// 28UL); -// // TODO(danpat): this is only testing invalid grammar which isn't capable of checking -// // for values that need to reference other things currently. These -// // requests are gramatically correct, but semantically incorrect. -// // The table service properly fails these, as it checks IsValid() after -// // parsing, which fails when sources/destinations are too large -// // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?sources=2"), 7UL); -// // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?destinations=2"), 7UL); -// } - -// BOOST_AUTO_TEST_CASE(valid_route_segment_hint) -// { -// engine::PhantomNode reference_node; -// reference_node.input_location = -// util::Coordinate(util::FloatLongitude{7.432251}, util::FloatLatitude{43.745995}); -// engine::SegmentHint reference_segment_hint{reference_node, 0x1337}; -// auto encoded_hint = reference_segment_hint.ToBase64(); -// auto seg_hint = engine::SegmentHint::FromBase64(encoded_hint); -// BOOST_CHECK_EQUAL(seg_hint.phantom.input_location, -// reference_segment_hint.phantom.input_location); -// } - -// BOOST_AUTO_TEST_CASE(valid_route_urls) -// { -// std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, -// {util::FloatLongitude{3}, util::FloatLatitude{4}}}; - -// RouteParameters reference_1{}; -// reference_1.coordinates = coords_1; -// auto result_1 = parseParameters("1,2;3,4"); -// BOOST_CHECK(result_1); -// BOOST_CHECK_EQUAL(reference_1.steps, result_1->steps); -// BOOST_CHECK_EQUAL(reference_1.alternatives, result_1->alternatives); -// BOOST_CHECK_EQUAL(reference_1.geometries, result_1->geometries); -// BOOST_CHECK_EQUAL(reference_1.annotations, result_1->annotations); -// BOOST_CHECK_EQUAL(reference_1.overview, result_1->overview); -// BOOST_CHECK_EQUAL(reference_1.continue_straight, result_1->continue_straight); -// CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); -// CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); -// CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); -// CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); -// CHECK_EQUAL_RANGE_OF_HINTS(reference_1.hints, result_1->hints); - -// RouteParameters reference_2{}; -// reference_2.alternatives = true; -// reference_2.number_of_alternatives = 1; -// reference_2.steps = true; -// reference_2.annotations = true; -// reference_2.coordinates = coords_1; -// auto result_2 = -// parseParameters("1,2;3,4?steps=true&alternatives=true&geometries=polyline&" -// "overview=simplified&annotations=true"); -// BOOST_CHECK(result_2); -// BOOST_CHECK_EQUAL(reference_2.steps, result_2->steps); -// BOOST_CHECK_EQUAL(reference_2.alternatives, result_2->alternatives); -// BOOST_CHECK_EQUAL(reference_2.number_of_alternatives, result_2->number_of_alternatives); -// BOOST_CHECK_EQUAL(reference_2.geometries, result_2->geometries); -// BOOST_CHECK_EQUAL(reference_2.annotations, result_2->annotations); -// BOOST_CHECK_EQUAL(reference_2.overview, result_2->overview); -// BOOST_CHECK_EQUAL(reference_2.continue_straight, result_2->continue_straight); -// CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); -// CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); -// CHECK_EQUAL_RANGE(reference_2.approaches, result_2->approaches); -// CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); -// CHECK_EQUAL_RANGE_OF_HINTS(reference_2.hints, result_2->hints); -// BOOST_CHECK_EQUAL(result_2->annotations_type == RouteParameters::AnnotationsType::All, true); - -// RouteParameters reference_3{false, -// false, -// false, -// RouteParameters::GeometriesType::GeoJSON, -// RouteParameters::OverviewType::False, -// true}; -// reference_3.coordinates = coords_1; -// auto result_3 = api::parseParameters( -// "1,2;3,4?steps=false&alternatives=false&geometries=geojson&overview=false&continue_" -// "straight=true"); -// BOOST_CHECK(result_3); -// BOOST_CHECK_EQUAL(reference_3.steps, result_3->steps); -// BOOST_CHECK_EQUAL(reference_3.alternatives, result_3->alternatives); -// BOOST_CHECK_EQUAL(reference_3.number_of_alternatives, result_3->number_of_alternatives); -// BOOST_CHECK_EQUAL(reference_3.geometries, result_3->geometries); -// BOOST_CHECK_EQUAL(reference_3.annotations, result_3->annotations); -// BOOST_CHECK_EQUAL(reference_3.overview, result_3->overview); -// BOOST_CHECK_EQUAL(reference_3.continue_straight, result_3->continue_straight); -// CHECK_EQUAL_RANGE(reference_3.bearings, result_3->bearings); -// CHECK_EQUAL_RANGE(reference_3.radiuses, result_3->radiuses); -// CHECK_EQUAL_RANGE(reference_3.approaches, result_3->approaches); -// CHECK_EQUAL_RANGE(reference_3.coordinates, result_3->coordinates); -// CHECK_EQUAL_RANGE_OF_HINTS(reference_3.hints, result_3->hints); - -// engine::PhantomNode phantom_1; -// phantom_1.input_location = coords_1[0]; -// engine::PhantomNode phantom_2; -// phantom_2.input_location = coords_1[1]; -// std::vector> hints_4 = { -// engine::Hint{{engine::SegmentHint{phantom_1, 0x1337}}}, -// engine::Hint{{engine::SegmentHint{phantom_2, 0x1337}}}}; -// RouteParameters reference_4{false, -// false, -// false, -// RouteParameters::GeometriesType::Polyline, -// RouteParameters::OverviewType::Simplified, -// std::optional{}, -// coords_1, -// hints_4, -// std::vector>{}, -// std::vector>{}}; -// auto result_4 = parseParameters( -// "1,2;3,4?steps=false&hints=" + hints_4[0]->ToBase64() + ";" + hints_4[1]->ToBase64()); -// BOOST_CHECK(result_4); -// BOOST_CHECK_EQUAL(reference_4.steps, result_4->steps); -// BOOST_CHECK_EQUAL(reference_4.alternatives, result_4->alternatives); -// BOOST_CHECK_EQUAL(reference_4.geometries, result_4->geometries); -// BOOST_CHECK_EQUAL(reference_4.annotations, result_4->annotations); -// BOOST_CHECK_EQUAL(reference_4.overview, result_4->overview); -// BOOST_CHECK_EQUAL(reference_4.continue_straight, result_4->continue_straight); -// CHECK_EQUAL_RANGE(reference_4.bearings, result_4->bearings); -// CHECK_EQUAL_RANGE(reference_4.radiuses, result_4->radiuses); -// CHECK_EQUAL_RANGE(reference_4.approaches, result_4->approaches); -// CHECK_EQUAL_RANGE(reference_4.coordinates, result_4->coordinates); -// CHECK_EQUAL_RANGE_OF_HINTS(reference_4.hints, result_4->hints); - -// std::vector> bearings_4 = { -// std::nullopt, -// engine::Bearing{200, 10}, -// engine::Bearing{100, 5}, -// }; -// RouteParameters reference_5{false, -// false, -// false, -// RouteParameters::GeometriesType::Polyline, -// RouteParameters::OverviewType::Simplified, -// std::optional{}, -// coords_1, -// std::vector>{}, -// std::vector>{}, -// bearings_4}; -// auto result_5 = -// parseParameters("1,2;3,4?steps=false&bearings=;200,10;100,5"); -// BOOST_CHECK(result_5); -// BOOST_CHECK_EQUAL(reference_5.steps, result_5->steps); -// BOOST_CHECK_EQUAL(reference_5.alternatives, result_5->alternatives); -// BOOST_CHECK_EQUAL(reference_5.geometries, result_5->geometries); -// BOOST_CHECK_EQUAL(reference_5.annotations, result_5->annotations); -// BOOST_CHECK_EQUAL(reference_5.overview, result_5->overview); -// BOOST_CHECK_EQUAL(reference_5.continue_straight, result_5->continue_straight); -// CHECK_EQUAL_RANGE(reference_5.bearings, result_5->bearings); -// CHECK_EQUAL_RANGE(reference_5.radiuses, result_5->radiuses); -// CHECK_EQUAL_RANGE(reference_5.approaches, result_5->approaches); -// CHECK_EQUAL_RANGE(reference_5.coordinates, result_5->coordinates); -// CHECK_EQUAL_RANGE_OF_HINTS(reference_5.hints, result_5->hints); - -// std::vector coords_2 = {{util::FloatLongitude{0}, util::FloatLatitude{1}}, -// {util::FloatLongitude{2}, util::FloatLatitude{3}}, -// {util::FloatLongitude{4}, util::FloatLatitude{5}}}; - -// RouteParameters reference_6{}; -// reference_6.coordinates = coords_2; -// auto result_6 = parseParameters("polyline(_ibE?_seK_seK_seK_seK)"); -// BOOST_CHECK(result_6); -// BOOST_CHECK_EQUAL(reference_6.steps, result_6->steps); -// BOOST_CHECK_EQUAL(reference_6.alternatives, result_6->alternatives); -// BOOST_CHECK_EQUAL(reference_6.geometries, result_6->geometries); -// BOOST_CHECK_EQUAL(reference_6.annotations, result_6->annotations); -// BOOST_CHECK_EQUAL(reference_6.overview, result_6->overview); -// BOOST_CHECK_EQUAL(reference_6.continue_straight, result_6->continue_straight); -// CHECK_EQUAL_RANGE(reference_6.bearings, result_6->bearings); -// CHECK_EQUAL_RANGE(reference_6.radiuses, result_6->radiuses); -// CHECK_EQUAL_RANGE(reference_6.approaches, result_6->approaches); -// CHECK_EQUAL_RANGE(reference_6.coordinates, result_6->coordinates); -// CHECK_EQUAL_RANGE_OF_HINTS(reference_6.hints, result_6->hints); - -// auto result_7 = parseParameters("1,2;3,4?radiuses=;unlimited"); -// RouteParameters reference_7{}; -// reference_7.coordinates = coords_1; -// reference_7.radiuses = {std::nullopt, -// std::make_optional(std::numeric_limits::infinity())}; -// BOOST_CHECK(result_7); -// BOOST_CHECK_EQUAL(reference_7.steps, result_7->steps); -// BOOST_CHECK_EQUAL(reference_7.alternatives, result_7->alternatives); -// BOOST_CHECK_EQUAL(reference_7.geometries, result_7->geometries); -// BOOST_CHECK_EQUAL(reference_7.annotations, result_7->annotations); -// BOOST_CHECK_EQUAL(reference_7.overview, result_7->overview); -// BOOST_CHECK_EQUAL(reference_7.continue_straight, result_7->continue_straight); -// CHECK_EQUAL_RANGE(reference_7.bearings, result_7->bearings); -// CHECK_EQUAL_RANGE(reference_7.radiuses, result_7->radiuses); -// CHECK_EQUAL_RANGE(reference_7.approaches, result_7->approaches); -// CHECK_EQUAL_RANGE(reference_7.coordinates, result_7->coordinates); -// CHECK_EQUAL_RANGE_OF_HINTS(reference_7.hints, result_7->hints); - -// auto result_8 = parseParameters("1,2;3,4?radiuses=;"); -// RouteParameters reference_8{}; -// reference_8.coordinates = coords_1; -// reference_8.radiuses = {std::nullopt, std::nullopt}; -// BOOST_CHECK(result_8); -// CHECK_EQUAL_RANGE(reference_8.radiuses, result_8->radiuses); - -// auto result_9 = parseParameters("1,2?radiuses="); -// RouteParameters reference_9{}; -// reference_9.coordinates = coords_1; -// reference_9.radiuses = {std::nullopt}; -// BOOST_CHECK(result_9); -// CHECK_EQUAL_RANGE(reference_9.radiuses, result_9->radiuses); - -// // Some Hint's are empty -// std::vector coords_3 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, -// {util::FloatLongitude{3}, util::FloatLatitude{4}}, -// {util::FloatLongitude{5}, util::FloatLatitude{6}}, -// {util::FloatLongitude{7}, util::FloatLatitude{8}}}; - -// engine::PhantomNode phantom_3; -// phantom_3.input_location = coords_3[0]; -// engine::PhantomNode phantom_4; -// phantom_4.input_location = coords_3[2]; -// std::vector> hints_10 = { -// engine::Hint{{engine::SegmentHint{phantom_3, 0x1337}}}, -// {}, -// engine::Hint{{engine::SegmentHint{phantom_4, 0x1337}}}, -// {}}; - -// RouteParameters reference_10{false, -// false, -// false, -// RouteParameters::GeometriesType::Polyline, -// RouteParameters::OverviewType::Simplified, -// std::optional{}, -// coords_3, -// hints_10, -// std::vector>{}, -// std::vector>{}}; -// auto result_10 = parseParameters( -// "1,2;3,4;5,6;7,8?steps=false&hints=" + hints_10[0]->ToBase64() + ";;" + -// hints_10[2]->ToBase64() + ";"); -// BOOST_CHECK(result_10); -// BOOST_CHECK_EQUAL(reference_10.steps, result_10->steps); -// BOOST_CHECK_EQUAL(reference_10.alternatives, result_10->alternatives); -// BOOST_CHECK_EQUAL(reference_10.geometries, result_10->geometries); -// BOOST_CHECK_EQUAL(reference_10.annotations, result_10->annotations); -// BOOST_CHECK_EQUAL(reference_10.overview, result_10->overview); -// BOOST_CHECK_EQUAL(reference_10.continue_straight, result_10->continue_straight); -// CHECK_EQUAL_RANGE(reference_10.bearings, result_10->bearings); -// CHECK_EQUAL_RANGE(reference_10.radiuses, result_10->radiuses); -// CHECK_EQUAL_RANGE(reference_10.approaches, result_10->approaches); -// CHECK_EQUAL_RANGE(reference_10.coordinates, result_10->coordinates); -// CHECK_EQUAL_RANGE_OF_HINTS(reference_10.hints, result_10->hints); - -// // Do not generate Hints when they are explicitly disabled -// auto result_11 = parseParameters("1,2;3,4?generate_hints=false"); -// BOOST_CHECK(result_11); -// BOOST_CHECK_EQUAL(result_11->generate_hints, false); - -// auto result_12 = parseParameters("1,2;3,4?generate_hints=true"); -// BOOST_CHECK(result_12); -// BOOST_CHECK_EQUAL(result_12->generate_hints, true); - -// auto result_13 = parseParameters("1,2;3,4"); -// BOOST_CHECK(result_13); -// BOOST_CHECK_EQUAL(result_13->generate_hints, true); - -// // parse none annotations value correctly -// RouteParameters reference_14{}; -// reference_14.annotations_type = RouteParameters::AnnotationsType::None; -// reference_14.coordinates = coords_1; -// auto result_14 = parseParameters("1,2;3,4?geometries=polyline"); -// BOOST_CHECK(result_14); -// BOOST_CHECK_EQUAL(reference_14.geometries, result_14->geometries); -// BOOST_CHECK_EQUAL(result_14->annotations_type == RouteParameters::AnnotationsType::None, -// true); BOOST_CHECK_EQUAL(result_14->annotations, false); - -// // parse single annotations value correctly -// RouteParameters reference_15{}; -// reference_15.annotations_type = RouteParameters::AnnotationsType::Duration; -// reference_15.coordinates = coords_1; -// auto result_15 = parseParameters("1,2;3,4?geometries=polyline&" -// "overview=simplified&annotations=duration"); -// BOOST_CHECK(result_15); -// BOOST_CHECK_EQUAL(reference_15.geometries, result_15->geometries); -// BOOST_CHECK_EQUAL(result_15->annotations_type == RouteParameters::AnnotationsType::Duration, -// true); -// BOOST_CHECK_EQUAL(result_15->annotations, true); - -// RouteParameters reference_speed{}; -// reference_speed.annotations_type = RouteParameters::AnnotationsType::Duration; -// reference_speed.coordinates = coords_1; -// auto result_speed = -// parseParameters("1,2;3,4?geometries=polyline&" -// "overview=simplified&annotations=duration,distance,speed"); -// BOOST_CHECK(result_speed); -// BOOST_CHECK_EQUAL(reference_speed.geometries, result_speed->geometries); -// BOOST_CHECK_EQUAL(reference_speed.overview, result_speed->overview); -// BOOST_CHECK_EQUAL(result_speed->annotations_type == -// (RouteParameters::AnnotationsType::Duration | -// RouteParameters::AnnotationsType::Distance | -// RouteParameters::AnnotationsType::Speed), -// true); -// BOOST_CHECK_EQUAL(result_speed->annotations, true); - -// // parse multiple annotations correctly -// RouteParameters reference_16{}; -// reference_16.annotations_type = RouteParameters::AnnotationsType::Duration | -// RouteParameters::AnnotationsType::Weight | -// RouteParameters::AnnotationsType::Nodes; -// reference_16.coordinates = coords_1; -// auto result_16 = -// parseParameters("1,2;3,4?geometries=polyline&" -// "overview=simplified&annotations=duration,weight,nodes"); -// BOOST_CHECK(result_16); -// BOOST_CHECK_EQUAL(reference_16.geometries, result_16->geometries); -// BOOST_CHECK_EQUAL(static_cast(result_16->annotations_type & -// (RouteParameters::AnnotationsType::Weight | -// RouteParameters::AnnotationsType::Duration | -// RouteParameters::AnnotationsType::Nodes)), -// true); -// BOOST_CHECK_EQUAL(result_16->annotations, true); - -// // parse all annotations correctly -// RouteParameters reference_17{}; -// reference_17.annotations_type = RouteParameters::AnnotationsType::All; -// reference_17.coordinates = coords_1; -// auto result_17 = parseParameters( -// "1,2;3,4?overview=simplified&annotations=duration,weight,nodes,datasources,distance"); -// BOOST_CHECK(result_17); -// BOOST_CHECK_EQUAL(reference_17.geometries, result_17->geometries); -// BOOST_CHECK_EQUAL(result_2->annotations_type == RouteParameters::AnnotationsType::All, true); -// BOOST_CHECK_EQUAL(result_17->annotations, true); - -// std::vector> approaches_18 = { -// std::nullopt, -// engine::Approach::CURB, -// engine::Approach::UNRESTRICTED, -// engine::Approach::OPPOSITE, -// }; -// RouteParameters reference_18{false, -// false, -// false, -// RouteParameters::GeometriesType::Polyline, -// RouteParameters::OverviewType::Simplified, -// std::optional{}, -// coords_3, -// std::vector>{}, -// std::vector>{}, -// std::vector>{}, -// approaches_18}; - -// auto result_18 = parseParameters( -// "1,2;3,4;5,6;7,8?steps=false&approaches=;curb;unrestricted;opposite"); -// BOOST_CHECK(result_18); -// BOOST_CHECK_EQUAL(reference_18.steps, result_18->steps); -// BOOST_CHECK_EQUAL(reference_18.alternatives, result_18->alternatives); -// BOOST_CHECK_EQUAL(reference_18.geometries, result_18->geometries); -// BOOST_CHECK_EQUAL(reference_18.annotations, result_18->annotations); -// BOOST_CHECK_EQUAL(reference_18.overview, result_18->overview); -// BOOST_CHECK_EQUAL(reference_18.continue_straight, result_18->continue_straight); -// CHECK_EQUAL_RANGE(reference_18.bearings, result_18->bearings); -// CHECK_EQUAL_RANGE(reference_18.radiuses, result_18->radiuses); -// CHECK_EQUAL_RANGE(reference_18.approaches, result_18->approaches); -// CHECK_EQUAL_RANGE(reference_18.coordinates, result_18->coordinates); -// CHECK_EQUAL_RANGE_OF_HINTS(reference_18.hints, result_18->hints); - -// RouteParameters reference_19{}; -// reference_19.alternatives = true; -// reference_19.number_of_alternatives = 3; -// reference_19.coordinates = coords_1; -// auto result_19 = parseParameters("1,2;3,4?alternatives=3"); -// BOOST_CHECK(result_19); -// BOOST_CHECK_EQUAL(reference_19.steps, result_19->steps); -// BOOST_CHECK_EQUAL(reference_19.alternatives, result_19->alternatives); -// BOOST_CHECK_EQUAL(reference_19.number_of_alternatives, result_19->number_of_alternatives); -// BOOST_CHECK_EQUAL(reference_19.geometries, result_19->geometries); -// BOOST_CHECK_EQUAL(reference_19.annotations, result_19->annotations); -// BOOST_CHECK_EQUAL(reference_19.overview, result_19->overview); -// BOOST_CHECK_EQUAL(reference_19.continue_straight, result_19->continue_straight); -// CHECK_EQUAL_RANGE(reference_19.bearings, result_19->bearings); -// CHECK_EQUAL_RANGE(reference_19.radiuses, result_19->radiuses); -// CHECK_EQUAL_RANGE(reference_19.approaches, result_19->approaches); -// CHECK_EQUAL_RANGE(reference_19.coordinates, result_19->coordinates); -// CHECK_EQUAL_RANGE_OF_HINTS(reference_19.hints, result_19->hints); - -// RouteParameters reference_20{}; -// reference_20.alternatives = false; -// reference_20.number_of_alternatives = 0; -// reference_20.coordinates = coords_1; -// auto result_20 = parseParameters("1,2;3,4?alternatives=0"); -// BOOST_CHECK(result_20); -// BOOST_CHECK_EQUAL(reference_20.steps, result_20->steps); -// BOOST_CHECK_EQUAL(reference_20.alternatives, result_20->alternatives); -// BOOST_CHECK_EQUAL(reference_20.number_of_alternatives, result_20->number_of_alternatives); -// BOOST_CHECK_EQUAL(reference_20.geometries, result_20->geometries); -// BOOST_CHECK_EQUAL(reference_20.annotations, result_20->annotations); -// BOOST_CHECK_EQUAL(reference_20.overview, result_20->overview); -// BOOST_CHECK_EQUAL(reference_20.continue_straight, result_20->continue_straight); -// CHECK_EQUAL_RANGE(reference_20.bearings, result_20->bearings); -// CHECK_EQUAL_RANGE(reference_20.radiuses, result_20->radiuses); -// CHECK_EQUAL_RANGE(reference_20.approaches, result_20->approaches); -// CHECK_EQUAL_RANGE(reference_20.coordinates, result_20->coordinates); -// CHECK_EQUAL_RANGE_OF_HINTS(reference_20.hints, result_20->hints); - -// // exclude flags -// RouteParameters reference_21{}; -// reference_21.exclude = {"ferry", "motorway"}; -// reference_21.coordinates = coords_1; -// auto result_21 = parseParameters("1,2;3,4?exclude=ferry,motorway"); -// BOOST_CHECK(result_21); -// BOOST_CHECK_EQUAL(reference_21.steps, result_21->steps); -// BOOST_CHECK_EQUAL(reference_21.alternatives, result_21->alternatives); -// BOOST_CHECK_EQUAL(reference_21.number_of_alternatives, result_21->number_of_alternatives); -// BOOST_CHECK_EQUAL(reference_21.geometries, result_21->geometries); -// BOOST_CHECK_EQUAL(reference_21.annotations, result_21->annotations); -// BOOST_CHECK_EQUAL(reference_21.overview, result_21->overview); -// BOOST_CHECK_EQUAL(reference_21.continue_straight, result_21->continue_straight); -// CHECK_EQUAL_RANGE(reference_21.bearings, result_21->bearings); -// CHECK_EQUAL_RANGE(reference_21.radiuses, result_21->radiuses); -// CHECK_EQUAL_RANGE(reference_21.approaches, result_21->approaches); -// CHECK_EQUAL_RANGE(reference_21.coordinates, result_21->coordinates); -// CHECK_EQUAL_RANGE_OF_HINTS(reference_21.hints, result_21->hints); -// CHECK_EQUAL_RANGE(reference_21.exclude, result_21->exclude); -// } - -// BOOST_AUTO_TEST_CASE(valid_table_urls) -// { -// std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, -// {util::FloatLongitude{3}, util::FloatLatitude{4}}}; - -// TableParameters reference_1{}; -// reference_1.coordinates = coords_1; -// auto result_1 = parseParameters("1,2;3,4"); -// BOOST_CHECK(result_1); -// CHECK_EQUAL_RANGE(reference_1.sources, result_1->sources); -// CHECK_EQUAL_RANGE(reference_1.destinations, result_1->destinations); -// CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); -// CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); -// CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); -// CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); - -// std::vector sources_2 = {1, 2, 3}; -// std::vector destinations_2 = {4, 5}; -// TableParameters reference_2{sources_2, destinations_2}; -// reference_2.coordinates = coords_1; -// auto result_2 = parseParameters("1,2;3,4?sources=1;2;3&destinations=4;5"); -// BOOST_CHECK(result_2); -// CHECK_EQUAL_RANGE(reference_2.sources, result_2->sources); -// CHECK_EQUAL_RANGE(reference_2.destinations, result_2->destinations); -// CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); -// CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); -// CHECK_EQUAL_RANGE(reference_2.approaches, result_2->approaches); -// CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); - -// auto result_3 = parseParameters("1,2;3,4?sources=all&destinations=all"); -// BOOST_CHECK(result_3); -// CHECK_EQUAL_RANGE(reference_1.sources, result_3->sources); -// CHECK_EQUAL_RANGE(reference_1.destinations, result_3->destinations); -// CHECK_EQUAL_RANGE(reference_1.bearings, result_3->bearings); -// CHECK_EQUAL_RANGE(reference_1.radiuses, result_3->radiuses); -// CHECK_EQUAL_RANGE(reference_1.approaches, result_3->approaches); -// CHECK_EQUAL_RANGE(reference_1.coordinates, result_3->coordinates); - -// TableParameters reference_4{}; -// reference_4.coordinates = coords_1; -// auto result_4 = parseParameters( -// "1,2;3,4?sources=all&destinations=all&annotations=duration"); -// BOOST_CHECK(result_4); -// BOOST_CHECK_EQUAL(result_4->annotations & (TableParameters::AnnotationsType::Distance | -// TableParameters::AnnotationsType::Duration), -// true); -// CHECK_EQUAL_RANGE(reference_4.sources, result_4->sources); -// CHECK_EQUAL_RANGE(reference_4.destinations, result_4->destinations); - -// TableParameters reference_5{}; -// reference_5.coordinates = coords_1; -// auto result_5 = parseParameters( -// "1,2;3,4?sources=all&destinations=all&annotations=duration"); -// BOOST_CHECK(result_5); -// BOOST_CHECK_EQUAL(result_5->annotations & TableParameters::AnnotationsType::Duration, true); -// CHECK_EQUAL_RANGE(reference_5.sources, result_5->sources); -// CHECK_EQUAL_RANGE(reference_5.destinations, result_5->destinations); - -// TableParameters reference_6{}; -// reference_6.coordinates = coords_1; -// auto result_6 = parseParameters( -// "1,2;3,4?sources=all&destinations=all&annotations=distance"); -// BOOST_CHECK(result_6); -// BOOST_CHECK_EQUAL(result_6->annotations & TableParameters::AnnotationsType::Distance, true); -// CHECK_EQUAL_RANGE(reference_6.sources, result_6->sources); -// CHECK_EQUAL_RANGE(reference_6.destinations, result_6->destinations); - -// TableParameters reference_7{}; -// reference_7.coordinates = coords_1; -// auto result_7 = parseParameters("1,2;3,4?annotations=distance"); -// BOOST_CHECK(result_7); -// BOOST_CHECK_EQUAL(result_7->annotations & TableParameters::AnnotationsType::Distance, true); -// CHECK_EQUAL_RANGE(reference_7.sources, result_7->sources); -// CHECK_EQUAL_RANGE(reference_7.destinations, result_7->destinations); - -// TableParameters reference_8{}; -// reference_8.coordinates = coords_1; -// auto result_8 = -// parseParameters("1,2;3,4?annotations=distance&fallback_speed=2.5"); -// BOOST_CHECK(result_8); -// BOOST_CHECK_EQUAL(result_8->annotations & TableParameters::AnnotationsType::Distance, true); -// CHECK_EQUAL_RANGE(reference_8.sources, result_8->sources); -// CHECK_EQUAL_RANGE(reference_8.destinations, result_8->destinations); - -// TableParameters reference_9{}; -// reference_9.coordinates = coords_1; -// auto result_9 = parseParameters( -// "1,2;3,4?annotations=distance&fallback_speed=2.5&fallback_coordinate=input"); -// BOOST_CHECK(result_9); -// BOOST_CHECK_EQUAL(result_9->annotations & TableParameters::AnnotationsType::Distance, true); -// CHECK_EQUAL_RANGE(reference_9.sources, result_9->sources); -// CHECK_EQUAL_RANGE(reference_9.destinations, result_9->destinations); - -// TableParameters reference_10{}; -// reference_10.coordinates = coords_1; -// auto result_10 = parseParameters( -// "1,2;3,4?annotations=distance&fallback_speed=20&fallback_coordinate=snapped"); -// BOOST_CHECK(result_10); -// BOOST_CHECK_EQUAL(result_10->annotations & TableParameters::AnnotationsType::Distance, true); -// CHECK_EQUAL_RANGE(reference_10.sources, result_10->sources); -// CHECK_EQUAL_RANGE(reference_10.destinations, result_10->destinations); - -// auto result_11 = parseParameters("1,2;3,4?sources=all&destinations=all&" -// "annotations=duration&fallback_speed=1&" -// "fallback_coordinate=snapped&scale_factor=2"); -// BOOST_CHECK(result_11); -// CHECK_EQUAL_RANGE(reference_1.sources, result_11->sources); -// CHECK_EQUAL_RANGE(reference_1.destinations, result_11->destinations); -// CHECK_EQUAL_RANGE(reference_1.bearings, result_11->bearings); -// CHECK_EQUAL_RANGE(reference_1.radiuses, result_11->radiuses); -// CHECK_EQUAL_RANGE(reference_1.approaches, result_11->approaches); -// CHECK_EQUAL_RANGE(reference_1.coordinates, result_11->coordinates); -// } - -// BOOST_AUTO_TEST_CASE(valid_match_urls) -// { -// std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, -// {util::FloatLongitude{3}, util::FloatLatitude{4}}}; - -// MatchParameters reference_1{}; -// reference_1.coordinates = coords_1; -// auto result_1 = parseParameters("1,2;3,4"); -// BOOST_CHECK(result_1); -// CHECK_EQUAL_RANGE(reference_1.timestamps, result_1->timestamps); -// CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); -// CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); -// CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); -// CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); - -// MatchParameters reference_2{}; -// reference_2.coordinates = coords_1; -// reference_2.timestamps = {5, 6}; -// auto result_2 = parseParameters("1,2;3,4?timestamps=5;6"); -// BOOST_CHECK(result_2); -// CHECK_EQUAL_RANGE(reference_2.timestamps, result_2->timestamps); -// CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); -// CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); -// CHECK_EQUAL_RANGE(reference_2.approaches, result_2->approaches); -// CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); - -// std::vector coords_2 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, -// {util::FloatLongitude{3}, util::FloatLatitude{4}}, -// {util::FloatLongitude{5}, util::FloatLatitude{6}}}; - -// MatchParameters reference_3{}; -// reference_3.coordinates = coords_2; -// reference_3.waypoints = {0, 2}; -// auto result_3 = parseParameters("1,2;3,4;5,6?waypoints=0;2"); -// BOOST_CHECK(result_3); -// CHECK_EQUAL_RANGE(reference_3.waypoints, result_3->waypoints); -// CHECK_EQUAL_RANGE(reference_3.timestamps, result_3->timestamps); -// CHECK_EQUAL_RANGE(reference_3.bearings, result_3->bearings); -// CHECK_EQUAL_RANGE(reference_3.radiuses, result_3->radiuses); -// CHECK_EQUAL_RANGE(reference_3.approaches, result_3->approaches); -// CHECK_EQUAL_RANGE(reference_3.coordinates, result_3->coordinates); -// } - -// BOOST_AUTO_TEST_CASE(invalid_match_urls) -// { -// std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, -// {util::FloatLongitude{3}, util::FloatLatitude{4}}}; - -// MatchParameters reference_1{}; -// reference_1.coordinates = coords_1; -// auto result_1 = parseParameters("1,2;3,4?radiuses=unlimited;60"); -// BOOST_CHECK(result_1); -// CHECK_EQUAL_RANGE(reference_1.timestamps, result_1->timestamps); -// CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); -// BOOST_CHECK(reference_1.radiuses != result_1->radiuses); -// CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); -// CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); - -// std::vector coords_2 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, -// {util::FloatLongitude{3}, util::FloatLatitude{4}}}; - -// MatchParameters reference_2{}; -// reference_2.coordinates = coords_2; -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?waypoints=0,4"), 19UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?waypoints=x;4"), 18UL); -// BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?waypoints=0;3.5"), 21UL); -// } - -// BOOST_AUTO_TEST_CASE(valid_nearest_urls) -// { -// std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}}; - -// NearestParameters reference_1{}; -// reference_1.coordinates = coords_1; -// auto result_1 = parseParameters("1,2"); -// BOOST_CHECK(result_1); -// BOOST_CHECK_EQUAL(reference_1.number_of_results, result_1->number_of_results); -// CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); -// CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); -// CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); -// CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); - -// NearestParameters reference_2{}; -// reference_2.coordinates = coords_1; -// reference_2.number_of_results = 42; -// auto result_2 = parseParameters("1,2?number=42"); -// BOOST_CHECK(result_2); -// BOOST_CHECK_EQUAL(reference_2.number_of_results, result_2->number_of_results); -// CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); -// CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); -// CHECK_EQUAL_RANGE(reference_2.approaches, result_2->approaches); -// CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); -// } - -// BOOST_AUTO_TEST_CASE(invalid_tile_urls) -// { -// TileParameters reference_1{1, 2, 3}; -// auto result_1 = parseParameters("tile(1,2,3).mvt"); -// BOOST_CHECK(result_1); -// BOOST_CHECK(!result_1->IsValid()); -// BOOST_CHECK_EQUAL(reference_1.x, result_1->x); -// BOOST_CHECK_EQUAL(reference_1.y, result_1->y); -// BOOST_CHECK_EQUAL(reference_1.z, result_1->z); -// } - -// BOOST_AUTO_TEST_CASE(valid_tile_urls) -// { -// TileParameters reference_1{1, 2, 12}; -// auto result_1 = parseParameters("tile(1,2,12).mvt"); -// BOOST_CHECK(result_1->IsValid()); -// BOOST_CHECK(result_1); -// BOOST_CHECK_EQUAL(reference_1.x, result_1->x); -// BOOST_CHECK_EQUAL(reference_1.y, result_1->y); -// BOOST_CHECK_EQUAL(reference_1.z, result_1->z); -// } - -// BOOST_AUTO_TEST_CASE(valid_trip_urls) -// { -// std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, -// {util::FloatLongitude{3}, util::FloatLatitude{4}}}; - -// TripParameters reference_1{}; -// reference_1.coordinates = coords_1; -// auto result_1 = parseParameters("1,2;3,4"); -// BOOST_CHECK(result_1); -// CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); -// CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); - -// TripParameters reference_2{}; -// reference_2.coordinates = coords_1; -// reference_2.source = TripParameters::SourceType::First; -// reference_2.destination = TripParameters::DestinationType::Last; -// auto result_2 = parseParameters("1,2;3,4?source=first&destination=last"); -// BOOST_CHECK(result_2); -// CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); -// CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); - -// // check supported source/destination/rountrip combinations -// auto param_fse_r = -// parseParameters("1,2;3,4?source=first&destination=last&roundtrip=true"); -// BOOST_CHECK(param_fse_r->IsValid()); -// auto param_fse_nr_ = -// parseParameters("1,2;3,4?source=first&destination=last&roundtrip=false"); -// BOOST_CHECK(param_fse_nr_->IsValid()); -// auto param_fs_r = parseParameters("1,2;3,4?source=first&roundtrip=true"); -// BOOST_CHECK(param_fs_r->IsValid()); -// auto param_fs_nr = parseParameters("1,2;3,4?source=first&roundtrip=false"); -// BOOST_CHECK(param_fs_nr->IsValid()); -// auto param_fe_r = parseParameters("1,2;3,4?destination=last&roundtrip=true"); -// BOOST_CHECK(param_fe_r->IsValid()); -// auto param_fe_nr = -// parseParameters("1,2;3,4?destination=last&roundtrip=false"); -// BOOST_CHECK(param_fe_nr->IsValid()); -// auto param_r = parseParameters("1,2;3,4?roundtrip=true"); -// BOOST_CHECK(param_r->IsValid()); -// auto param_nr = parseParameters("1,2;3,4?roundtrip=false"); -// BOOST_CHECK(param_nr->IsValid()); - -// auto param_fail_1 = -// testInvalidOptions("1,2;3,4?source=blubb&destination=random"); -// BOOST_CHECK_EQUAL(param_fail_1, 15UL); -// auto param_fail_2 = -// testInvalidOptions("1,2;3,4?source=first&destination=nah"); -// BOOST_CHECK_EQUAL(param_fail_2, 33UL); -// } - -// BOOST_AUTO_TEST_SUITE_END() +// TODO: revert to original version From 19a5421bba1fcc2e5e57123c0cf07f9af67c15fc Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sun, 30 Jun 2024 20:36:30 +0200 Subject: [PATCH 6/9] Yet another attempt to get rid of boost::optional --- .github/workflows/osrm-backend.yml | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/workflows/osrm-backend.yml b/.github/workflows/osrm-backend.yml index 10df684c476..839f4a0ca3a 100644 --- a/.github/workflows/osrm-backend.yml +++ b/.github/workflows/osrm-backend.yml @@ -211,17 +211,16 @@ jobs: CXXCOMPILER: clang++-15 CUCUMBER_TIMEOUT: 60000 - - name: clang-18-debug-clang-tidy - continue-on-error: false - node: 18 - runs-on: ubuntu-24.04 - BUILD_TOOLS: ON - BUILD_TYPE: Debug - CCOMPILER: clang-18 - CXXCOMPILER: clang++-18 - CUCUMBER_TIMEOUT: 60000 - ENABLE_CLANG_TIDY: ON - + # - name: clang-18-debug-clang-tidy + # continue-on-error: false + # node: 18 + # runs-on: ubuntu-24.04 + # BUILD_TOOLS: ON + # BUILD_TYPE: Debug + # CCOMPILER: clang-18 + # CXXCOMPILER: clang++-18 + # CUCUMBER_TIMEOUT: 60000 + # ENABLE_CLANG_TIDY: ON - name: clang-14-release continue-on-error: false From 02cd2c111bdc2a84124d29fa1a4db71e3075b09e Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sun, 30 Jun 2024 20:38:32 +0200 Subject: [PATCH 7/9] Yet another attempt to get rid of boost::optional --- .clang-tidy | 1 + .github/workflows/osrm-backend.yml | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 1d41cdd58d2..495e4fc6af4 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -17,6 +17,7 @@ Checks: > -bugprone-incorrect-enable-if, -bugprone-switch-missing-default-case, -bugprone-empty-catch, + -bugprone-unchecked-optional-access, -clang-analyzer-*, -clang-diagnostic-deprecated-declarations, -clang-diagnostic-constant-conversion, diff --git a/.github/workflows/osrm-backend.yml b/.github/workflows/osrm-backend.yml index 839f4a0ca3a..10df684c476 100644 --- a/.github/workflows/osrm-backend.yml +++ b/.github/workflows/osrm-backend.yml @@ -211,16 +211,17 @@ jobs: CXXCOMPILER: clang++-15 CUCUMBER_TIMEOUT: 60000 - # - name: clang-18-debug-clang-tidy - # continue-on-error: false - # node: 18 - # runs-on: ubuntu-24.04 - # BUILD_TOOLS: ON - # BUILD_TYPE: Debug - # CCOMPILER: clang-18 - # CXXCOMPILER: clang++-18 - # CUCUMBER_TIMEOUT: 60000 - # ENABLE_CLANG_TIDY: ON + - name: clang-18-debug-clang-tidy + continue-on-error: false + node: 18 + runs-on: ubuntu-24.04 + BUILD_TOOLS: ON + BUILD_TYPE: Debug + CCOMPILER: clang-18 + CXXCOMPILER: clang++-18 + CUCUMBER_TIMEOUT: 60000 + ENABLE_CLANG_TIDY: ON + - name: clang-14-release continue-on-error: false From 21ad8f73e649508737b2ad8c1639d1380c8820b7 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sun, 30 Jun 2024 21:06:42 +0200 Subject: [PATCH 8/9] Yet another attempt to get rid of boost::optional --- .../server/api/base_parameters_grammar.hpp | 2 +- unit_tests/server/parameters_parser.cpp | 827 +++++++++++++++++- 2 files changed, 827 insertions(+), 2 deletions(-) diff --git a/include/server/api/base_parameters_grammar.hpp b/include/server/api/base_parameters_grammar.hpp index a09455f9397..0891439e9a6 100644 --- a/include/server/api/base_parameters_grammar.hpp +++ b/include/server/api/base_parameters_grammar.hpp @@ -102,7 +102,7 @@ struct BaseParametersGrammar : boost::spirit::qi::grammar bearing = engine::Bearing{boost::fusion::at_c<0>(*bearing_range), boost::fusion::at_c<1>(*bearing_range)}; } - base_parameters.bearings.push_back(std::move(bearing)); + base_parameters.bearings.push_back(bearing); }; const auto add_approach = [](engine::api::BaseParameters &base_parameters, diff --git a/unit_tests/server/parameters_parser.cpp b/unit_tests/server/parameters_parser.cpp index 3db8947dedd..fee69f8b282 100644 --- a/unit_tests/server/parameters_parser.cpp +++ b/unit_tests/server/parameters_parser.cpp @@ -1 +1,826 @@ -// TODO: revert to original version +#include "server/api/parameters_parser.hpp" + +#include "parameters_io.hpp" + +#include "engine/api/base_parameters.hpp" +#include "engine/api/match_parameters.hpp" +#include "engine/api/nearest_parameters.hpp" +#include "engine/api/route_parameters.hpp" +#include "engine/api/table_parameters.hpp" +#include "engine/api/tile_parameters.hpp" +#include "engine/api/trip_parameters.hpp" + +#include "util/debug.hpp" + +#include +#include +#include + +#define CHECK_EQUAL_RANGE(R1, R2) \ + BOOST_CHECK_EQUAL_COLLECTIONS((R1).begin(), (R1).end(), (R2).begin(), (R2).end()); + +#define CHECK_EQUAL_RANGE_OF_HINTS(R1, R2) \ + BOOST_REQUIRE_EQUAL((R1).size(), (R2).size()); \ + for (const auto i : util::irange(0UL, (R1).size())) \ + { \ + BOOST_REQUIRE(((R1)[i] && (R2)[i]) || !((R1)[i] || (R2)[i])); \ + if ((R1)[i]) \ + { \ + BOOST_CHECK_EQUAL_COLLECTIONS((R1)[i]->segment_hints.begin(), \ + (R1)[i]->segment_hints.end(), \ + (R2)[i]->segment_hints.begin(), \ + (R2)[i]->segment_hints.end()); \ + } \ + } +// TODO: we should be able to somehow make Boost.Test to print std::optional types +BOOST_TEST_DONT_PRINT_LOG_VALUE(std::optional) +BOOST_TEST_DONT_PRINT_LOG_VALUE(std::optional) +BOOST_TEST_DONT_PRINT_LOG_VALUE(std::optional) +BOOST_TEST_DONT_PRINT_LOG_VALUE(std::optional) + +BOOST_AUTO_TEST_SUITE(api_parameters_parser) + +using namespace osrm; +using namespace osrm::server; +using namespace osrm::server::api; +using namespace osrm::engine::api; + +// returns distance to front +template std::size_t testInvalidOptions(std::string options) +{ + auto iter = options.begin(); + auto result = parseParameters(iter, options.end()); + BOOST_CHECK(!result); + return std::distance(options.begin(), iter); +} + +BOOST_AUTO_TEST_CASE(invalid_route_urls) +{ + BOOST_CHECK_EQUAL(testInvalidOptions("a;3,4"), 0UL); + BOOST_CHECK_EQUAL(testInvalidOptions("120;3,4"), 3UL); + BOOST_CHECK_EQUAL(testInvalidOptions("90000000,2;3,4"), 0UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&bla=foo"), 22UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&bearings=foo"), + 32UL); + BOOST_CHECK_EQUAL( + testInvalidOptions("1,2;3,4?overview=false&continue_straight=foo"), 41UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&radiuses=foo"), + 32UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&approaches=foo"), + 34UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&hints=foo"), + 29UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&hints=;;; ;"), + 32UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?generate_hints=notboolean"), + 23UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&geometries=foo"), + 34UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&overview=foo"), + 32L); + BOOST_CHECK_EQUAL( + testInvalidOptions("1,2;3,4?overview=false&alternatives=foo"), 36UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?overview=false&alternatives=-1"), + 36UL); + BOOST_CHECK_EQUAL(testInvalidOptions(""), 0); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3.4.unsupported"), 7); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4.json?nooptions"), 13); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4..json?nooptions"), 14); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4.0.json?nooptions"), 15); + BOOST_CHECK_EQUAL(testInvalidOptions(std::string{"1,2;3,4"} + '\0' + ".json"), + 7); + BOOST_CHECK_EQUAL(testInvalidOptions(std::string{"1,2;3,"} + '\0'), 6); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations=distances"), 28UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations="), 20UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?annotations=true,false"), 24UL); + BOOST_CHECK_EQUAL( + testInvalidOptions("1,2;3,4?annotations=&overview=simplified"), 20UL); +} + +BOOST_AUTO_TEST_CASE(invalid_table_urls) +{ + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?sources=1&bla=foo"), 17UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?destinations=1&bla=foo"), 22UL); + BOOST_CHECK_EQUAL( + testInvalidOptions("1,2;3,4?sources=1&destinations=1&bla=foo"), 32UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?sources=foo"), 16UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?destinations=foo"), 21UL); + BOOST_CHECK_EQUAL( + testInvalidOptions("1,2;3,4?sources=all&destinations=all&annotations=bla"), + 49UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?fallback_coordinate=asdf"), + 28UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?fallback_coordinate=10"), 28UL); + BOOST_CHECK_EQUAL( + testInvalidOptions("1,2;3,4?annotations=durations&scale_factor=-1"), 28UL); + BOOST_CHECK_EQUAL( + testInvalidOptions("1,2;3,4?annotations=durations&scale_factor=0"), 28UL); + BOOST_CHECK_EQUAL( + testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=0"), + 28UL); + BOOST_CHECK_EQUAL( + testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=-1"), + 28UL); + BOOST_CHECK_EQUAL( + testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=0"), + 28UL); + BOOST_CHECK_EQUAL( + testInvalidOptions("1,2;3,4?annotations=durations&fallback_speed=-1"), + 28UL); + // TODO(danpat): this is only testing invalid grammar which isn't capable of checking + // for values that need to reference other things currently. These + // requests are gramatically correct, but semantically incorrect. + // The table service properly fails these, as it checks IsValid() after + // parsing, which fails when sources/destinations are too large + // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?sources=2"), 7UL); + // BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?destinations=2"), 7UL); +} + +BOOST_AUTO_TEST_CASE(valid_route_segment_hint) +{ + engine::PhantomNode reference_node; + reference_node.input_location = + util::Coordinate(util::FloatLongitude{7.432251}, util::FloatLatitude{43.745995}); + engine::SegmentHint reference_segment_hint{reference_node, 0x1337}; + auto encoded_hint = reference_segment_hint.ToBase64(); + auto seg_hint = engine::SegmentHint::FromBase64(encoded_hint); + BOOST_CHECK_EQUAL(seg_hint.phantom.input_location, + reference_segment_hint.phantom.input_location); +} + +BOOST_AUTO_TEST_CASE(valid_route_urls) +{ + std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, + {util::FloatLongitude{3}, util::FloatLatitude{4}}}; + + RouteParameters reference_1{}; + reference_1.coordinates = coords_1; + auto result_1 = parseParameters("1,2;3,4"); + BOOST_CHECK(result_1); + BOOST_CHECK_EQUAL(reference_1.steps, result_1->steps); + BOOST_CHECK_EQUAL(reference_1.alternatives, result_1->alternatives); + BOOST_CHECK_EQUAL(reference_1.geometries, result_1->geometries); + BOOST_CHECK_EQUAL(reference_1.annotations, result_1->annotations); + BOOST_CHECK_EQUAL(reference_1.overview, result_1->overview); + BOOST_CHECK_EQUAL(reference_1.continue_straight, result_1->continue_straight); + CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); + CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); + CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); + CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); + CHECK_EQUAL_RANGE_OF_HINTS(reference_1.hints, result_1->hints); + + RouteParameters reference_2{}; + reference_2.alternatives = true; + reference_2.number_of_alternatives = 1; + reference_2.steps = true; + reference_2.annotations = true; + reference_2.coordinates = coords_1; + auto result_2 = + parseParameters("1,2;3,4?steps=true&alternatives=true&geometries=polyline&" + "overview=simplified&annotations=true"); + BOOST_CHECK(result_2); + BOOST_CHECK_EQUAL(reference_2.steps, result_2->steps); + BOOST_CHECK_EQUAL(reference_2.alternatives, result_2->alternatives); + BOOST_CHECK_EQUAL(reference_2.number_of_alternatives, result_2->number_of_alternatives); + BOOST_CHECK_EQUAL(reference_2.geometries, result_2->geometries); + BOOST_CHECK_EQUAL(reference_2.annotations, result_2->annotations); + BOOST_CHECK_EQUAL(reference_2.overview, result_2->overview); + BOOST_CHECK_EQUAL(reference_2.continue_straight, result_2->continue_straight); + CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); + CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); + CHECK_EQUAL_RANGE(reference_2.approaches, result_2->approaches); + CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); + CHECK_EQUAL_RANGE_OF_HINTS(reference_2.hints, result_2->hints); + BOOST_CHECK_EQUAL(result_2->annotations_type == RouteParameters::AnnotationsType::All, true); + + RouteParameters reference_3{false, + false, + false, + RouteParameters::GeometriesType::GeoJSON, + RouteParameters::OverviewType::False, + true}; + reference_3.coordinates = coords_1; + auto result_3 = api::parseParameters( + "1,2;3,4?steps=false&alternatives=false&geometries=geojson&overview=false&continue_" + "straight=true"); + BOOST_CHECK(result_3); + BOOST_CHECK_EQUAL(reference_3.steps, result_3->steps); + BOOST_CHECK_EQUAL(reference_3.alternatives, result_3->alternatives); + BOOST_CHECK_EQUAL(reference_3.number_of_alternatives, result_3->number_of_alternatives); + BOOST_CHECK_EQUAL(reference_3.geometries, result_3->geometries); + BOOST_CHECK_EQUAL(reference_3.annotations, result_3->annotations); + BOOST_CHECK_EQUAL(reference_3.overview, result_3->overview); + BOOST_CHECK_EQUAL(reference_3.continue_straight, result_3->continue_straight); + CHECK_EQUAL_RANGE(reference_3.bearings, result_3->bearings); + CHECK_EQUAL_RANGE(reference_3.radiuses, result_3->radiuses); + CHECK_EQUAL_RANGE(reference_3.approaches, result_3->approaches); + CHECK_EQUAL_RANGE(reference_3.coordinates, result_3->coordinates); + CHECK_EQUAL_RANGE_OF_HINTS(reference_3.hints, result_3->hints); + + engine::PhantomNode phantom_1; + phantom_1.input_location = coords_1[0]; + engine::PhantomNode phantom_2; + phantom_2.input_location = coords_1[1]; + std::vector> hints_4 = { + engine::Hint{{engine::SegmentHint{phantom_1, 0x1337}}}, + engine::Hint{{engine::SegmentHint{phantom_2, 0x1337}}}}; + RouteParameters reference_4{false, + false, + false, + RouteParameters::GeometriesType::Polyline, + RouteParameters::OverviewType::Simplified, + std::optional{}, + coords_1, + hints_4, + std::vector>{}, + std::vector>{}}; + auto result_4 = parseParameters( + "1,2;3,4?steps=false&hints=" + hints_4[0]->ToBase64() + ";" + hints_4[1]->ToBase64()); + BOOST_CHECK(result_4); + BOOST_CHECK_EQUAL(reference_4.steps, result_4->steps); + BOOST_CHECK_EQUAL(reference_4.alternatives, result_4->alternatives); + BOOST_CHECK_EQUAL(reference_4.geometries, result_4->geometries); + BOOST_CHECK_EQUAL(reference_4.annotations, result_4->annotations); + BOOST_CHECK_EQUAL(reference_4.overview, result_4->overview); + BOOST_CHECK_EQUAL(reference_4.continue_straight, result_4->continue_straight); + CHECK_EQUAL_RANGE(reference_4.bearings, result_4->bearings); + CHECK_EQUAL_RANGE(reference_4.radiuses, result_4->radiuses); + CHECK_EQUAL_RANGE(reference_4.approaches, result_4->approaches); + CHECK_EQUAL_RANGE(reference_4.coordinates, result_4->coordinates); + CHECK_EQUAL_RANGE_OF_HINTS(reference_4.hints, result_4->hints); + + std::vector> bearings_4 = { + std::nullopt, + engine::Bearing{200, 10}, + engine::Bearing{100, 5}, + }; + RouteParameters reference_5{false, + false, + false, + RouteParameters::GeometriesType::Polyline, + RouteParameters::OverviewType::Simplified, + std::optional{}, + coords_1, + std::vector>{}, + std::vector>{}, + bearings_4}; + auto result_5 = parseParameters("1,2;3,4?steps=false&bearings=;200,10;100,5"); + BOOST_CHECK(result_5); + BOOST_CHECK_EQUAL(reference_5.steps, result_5->steps); + BOOST_CHECK_EQUAL(reference_5.alternatives, result_5->alternatives); + BOOST_CHECK_EQUAL(reference_5.geometries, result_5->geometries); + BOOST_CHECK_EQUAL(reference_5.annotations, result_5->annotations); + BOOST_CHECK_EQUAL(reference_5.overview, result_5->overview); + BOOST_CHECK_EQUAL(reference_5.continue_straight, result_5->continue_straight); + CHECK_EQUAL_RANGE(reference_5.bearings, result_5->bearings); + CHECK_EQUAL_RANGE(reference_5.radiuses, result_5->radiuses); + CHECK_EQUAL_RANGE(reference_5.approaches, result_5->approaches); + CHECK_EQUAL_RANGE(reference_5.coordinates, result_5->coordinates); + CHECK_EQUAL_RANGE_OF_HINTS(reference_5.hints, result_5->hints); + + std::vector coords_2 = {{util::FloatLongitude{0}, util::FloatLatitude{1}}, + {util::FloatLongitude{2}, util::FloatLatitude{3}}, + {util::FloatLongitude{4}, util::FloatLatitude{5}}}; + + RouteParameters reference_6{}; + reference_6.coordinates = coords_2; + auto result_6 = parseParameters("polyline(_ibE?_seK_seK_seK_seK)"); + BOOST_CHECK(result_6); + BOOST_CHECK_EQUAL(reference_6.steps, result_6->steps); + BOOST_CHECK_EQUAL(reference_6.alternatives, result_6->alternatives); + BOOST_CHECK_EQUAL(reference_6.geometries, result_6->geometries); + BOOST_CHECK_EQUAL(reference_6.annotations, result_6->annotations); + BOOST_CHECK_EQUAL(reference_6.overview, result_6->overview); + BOOST_CHECK_EQUAL(reference_6.continue_straight, result_6->continue_straight); + CHECK_EQUAL_RANGE(reference_6.bearings, result_6->bearings); + CHECK_EQUAL_RANGE(reference_6.radiuses, result_6->radiuses); + CHECK_EQUAL_RANGE(reference_6.approaches, result_6->approaches); + CHECK_EQUAL_RANGE(reference_6.coordinates, result_6->coordinates); + CHECK_EQUAL_RANGE_OF_HINTS(reference_6.hints, result_6->hints); + + auto result_7 = parseParameters("1,2;3,4?radiuses=;unlimited"); + RouteParameters reference_7{}; + reference_7.coordinates = coords_1; + reference_7.radiuses = {std::nullopt, + std::make_optional(std::numeric_limits::infinity())}; + BOOST_CHECK(result_7); + BOOST_CHECK_EQUAL(reference_7.steps, result_7->steps); + BOOST_CHECK_EQUAL(reference_7.alternatives, result_7->alternatives); + BOOST_CHECK_EQUAL(reference_7.geometries, result_7->geometries); + BOOST_CHECK_EQUAL(reference_7.annotations, result_7->annotations); + BOOST_CHECK_EQUAL(reference_7.overview, result_7->overview); + BOOST_CHECK_EQUAL(reference_7.continue_straight, result_7->continue_straight); + CHECK_EQUAL_RANGE(reference_7.bearings, result_7->bearings); + CHECK_EQUAL_RANGE(reference_7.radiuses, result_7->radiuses); + CHECK_EQUAL_RANGE(reference_7.approaches, result_7->approaches); + CHECK_EQUAL_RANGE(reference_7.coordinates, result_7->coordinates); + CHECK_EQUAL_RANGE_OF_HINTS(reference_7.hints, result_7->hints); + + auto result_8 = parseParameters("1,2;3,4?radiuses=;"); + RouteParameters reference_8{}; + reference_8.coordinates = coords_1; + reference_8.radiuses = {std::nullopt, std::nullopt}; + BOOST_CHECK(result_8); + CHECK_EQUAL_RANGE(reference_8.radiuses, result_8->radiuses); + + auto result_9 = parseParameters("1,2?radiuses="); + RouteParameters reference_9{}; + reference_9.coordinates = coords_1; + reference_9.radiuses = {std::nullopt}; + BOOST_CHECK(result_9); + CHECK_EQUAL_RANGE(reference_9.radiuses, result_9->radiuses); + + // Some Hint's are empty + std::vector coords_3 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, + {util::FloatLongitude{3}, util::FloatLatitude{4}}, + {util::FloatLongitude{5}, util::FloatLatitude{6}}, + {util::FloatLongitude{7}, util::FloatLatitude{8}}}; + + engine::PhantomNode phantom_3; + phantom_3.input_location = coords_3[0]; + engine::PhantomNode phantom_4; + phantom_4.input_location = coords_3[2]; + std::vector> hints_10 = { + engine::Hint{{engine::SegmentHint{phantom_3, 0x1337}}}, + {}, + engine::Hint{{engine::SegmentHint{phantom_4, 0x1337}}}, + {}}; + + RouteParameters reference_10{false, + false, + false, + RouteParameters::GeometriesType::Polyline, + RouteParameters::OverviewType::Simplified, + std::optional{}, + coords_3, + hints_10, + std::vector>{}, + std::vector>{}}; + auto result_10 = parseParameters( + "1,2;3,4;5,6;7,8?steps=false&hints=" + hints_10[0]->ToBase64() + ";;" + + hints_10[2]->ToBase64() + ";"); + BOOST_CHECK(result_10); + BOOST_CHECK_EQUAL(reference_10.steps, result_10->steps); + BOOST_CHECK_EQUAL(reference_10.alternatives, result_10->alternatives); + BOOST_CHECK_EQUAL(reference_10.geometries, result_10->geometries); + BOOST_CHECK_EQUAL(reference_10.annotations, result_10->annotations); + BOOST_CHECK_EQUAL(reference_10.overview, result_10->overview); + BOOST_CHECK_EQUAL(reference_10.continue_straight, result_10->continue_straight); + CHECK_EQUAL_RANGE(reference_10.bearings, result_10->bearings); + CHECK_EQUAL_RANGE(reference_10.radiuses, result_10->radiuses); + CHECK_EQUAL_RANGE(reference_10.approaches, result_10->approaches); + CHECK_EQUAL_RANGE(reference_10.coordinates, result_10->coordinates); + CHECK_EQUAL_RANGE_OF_HINTS(reference_10.hints, result_10->hints); + + // Do not generate Hints when they are explicitly disabled + auto result_11 = parseParameters("1,2;3,4?generate_hints=false"); + BOOST_CHECK(result_11); + BOOST_CHECK_EQUAL(result_11->generate_hints, false); + + auto result_12 = parseParameters("1,2;3,4?generate_hints=true"); + BOOST_CHECK(result_12); + BOOST_CHECK_EQUAL(result_12->generate_hints, true); + + auto result_13 = parseParameters("1,2;3,4"); + BOOST_CHECK(result_13); + BOOST_CHECK_EQUAL(result_13->generate_hints, true); + + // parse none annotations value correctly + RouteParameters reference_14{}; + reference_14.annotations_type = RouteParameters::AnnotationsType::None; + reference_14.coordinates = coords_1; + auto result_14 = parseParameters("1,2;3,4?geometries=polyline"); + BOOST_CHECK(result_14); + BOOST_CHECK_EQUAL(reference_14.geometries, result_14->geometries); + BOOST_CHECK_EQUAL(result_14->annotations_type == RouteParameters::AnnotationsType::None, true); + BOOST_CHECK_EQUAL(result_14->annotations, false); + + // parse single annotations value correctly + RouteParameters reference_15{}; + reference_15.annotations_type = RouteParameters::AnnotationsType::Duration; + reference_15.coordinates = coords_1; + auto result_15 = parseParameters("1,2;3,4?geometries=polyline&" + "overview=simplified&annotations=duration"); + BOOST_CHECK(result_15); + BOOST_CHECK_EQUAL(reference_15.geometries, result_15->geometries); + BOOST_CHECK_EQUAL(result_15->annotations_type == RouteParameters::AnnotationsType::Duration, + true); + BOOST_CHECK_EQUAL(result_15->annotations, true); + + RouteParameters reference_speed{}; + reference_speed.annotations_type = RouteParameters::AnnotationsType::Duration; + reference_speed.coordinates = coords_1; + auto result_speed = + parseParameters("1,2;3,4?geometries=polyline&" + "overview=simplified&annotations=duration,distance,speed"); + BOOST_CHECK(result_speed); + BOOST_CHECK_EQUAL(reference_speed.geometries, result_speed->geometries); + BOOST_CHECK_EQUAL(reference_speed.overview, result_speed->overview); + BOOST_CHECK_EQUAL(result_speed->annotations_type == + (RouteParameters::AnnotationsType::Duration | + RouteParameters::AnnotationsType::Distance | + RouteParameters::AnnotationsType::Speed), + true); + BOOST_CHECK_EQUAL(result_speed->annotations, true); + + // parse multiple annotations correctly + RouteParameters reference_16{}; + reference_16.annotations_type = RouteParameters::AnnotationsType::Duration | + RouteParameters::AnnotationsType::Weight | + RouteParameters::AnnotationsType::Nodes; + reference_16.coordinates = coords_1; + auto result_16 = + parseParameters("1,2;3,4?geometries=polyline&" + "overview=simplified&annotations=duration,weight,nodes"); + BOOST_CHECK(result_16); + BOOST_CHECK_EQUAL(reference_16.geometries, result_16->geometries); + BOOST_CHECK_EQUAL(static_cast(result_16->annotations_type & + (RouteParameters::AnnotationsType::Weight | + RouteParameters::AnnotationsType::Duration | + RouteParameters::AnnotationsType::Nodes)), + true); + BOOST_CHECK_EQUAL(result_16->annotations, true); + + // parse all annotations correctly + RouteParameters reference_17{}; + reference_17.annotations_type = RouteParameters::AnnotationsType::All; + reference_17.coordinates = coords_1; + auto result_17 = parseParameters( + "1,2;3,4?overview=simplified&annotations=duration,weight,nodes,datasources,distance"); + BOOST_CHECK(result_17); + BOOST_CHECK_EQUAL(reference_17.geometries, result_17->geometries); + BOOST_CHECK_EQUAL(result_2->annotations_type == RouteParameters::AnnotationsType::All, true); + BOOST_CHECK_EQUAL(result_17->annotations, true); + + std::vector> approaches_18 = { + std::nullopt, + engine::Approach::CURB, + engine::Approach::UNRESTRICTED, + engine::Approach::OPPOSITE, + }; + RouteParameters reference_18{false, + false, + false, + RouteParameters::GeometriesType::Polyline, + RouteParameters::OverviewType::Simplified, + std::optional{}, + coords_3, + std::vector>{}, + std::vector>{}, + std::vector>{}, + approaches_18}; + + auto result_18 = parseParameters( + "1,2;3,4;5,6;7,8?steps=false&approaches=;curb;unrestricted;opposite"); + BOOST_CHECK(result_18); + BOOST_CHECK_EQUAL(reference_18.steps, result_18->steps); + BOOST_CHECK_EQUAL(reference_18.alternatives, result_18->alternatives); + BOOST_CHECK_EQUAL(reference_18.geometries, result_18->geometries); + BOOST_CHECK_EQUAL(reference_18.annotations, result_18->annotations); + BOOST_CHECK_EQUAL(reference_18.overview, result_18->overview); + BOOST_CHECK_EQUAL(reference_18.continue_straight, result_18->continue_straight); + CHECK_EQUAL_RANGE(reference_18.bearings, result_18->bearings); + CHECK_EQUAL_RANGE(reference_18.radiuses, result_18->radiuses); + CHECK_EQUAL_RANGE(reference_18.approaches, result_18->approaches); + CHECK_EQUAL_RANGE(reference_18.coordinates, result_18->coordinates); + CHECK_EQUAL_RANGE_OF_HINTS(reference_18.hints, result_18->hints); + + RouteParameters reference_19{}; + reference_19.alternatives = true; + reference_19.number_of_alternatives = 3; + reference_19.coordinates = coords_1; + auto result_19 = parseParameters("1,2;3,4?alternatives=3"); + BOOST_CHECK(result_19); + BOOST_CHECK_EQUAL(reference_19.steps, result_19->steps); + BOOST_CHECK_EQUAL(reference_19.alternatives, result_19->alternatives); + BOOST_CHECK_EQUAL(reference_19.number_of_alternatives, result_19->number_of_alternatives); + BOOST_CHECK_EQUAL(reference_19.geometries, result_19->geometries); + BOOST_CHECK_EQUAL(reference_19.annotations, result_19->annotations); + BOOST_CHECK_EQUAL(reference_19.overview, result_19->overview); + BOOST_CHECK_EQUAL(reference_19.continue_straight, result_19->continue_straight); + CHECK_EQUAL_RANGE(reference_19.bearings, result_19->bearings); + CHECK_EQUAL_RANGE(reference_19.radiuses, result_19->radiuses); + CHECK_EQUAL_RANGE(reference_19.approaches, result_19->approaches); + CHECK_EQUAL_RANGE(reference_19.coordinates, result_19->coordinates); + CHECK_EQUAL_RANGE_OF_HINTS(reference_19.hints, result_19->hints); + + RouteParameters reference_20{}; + reference_20.alternatives = false; + reference_20.number_of_alternatives = 0; + reference_20.coordinates = coords_1; + auto result_20 = parseParameters("1,2;3,4?alternatives=0"); + BOOST_CHECK(result_20); + BOOST_CHECK_EQUAL(reference_20.steps, result_20->steps); + BOOST_CHECK_EQUAL(reference_20.alternatives, result_20->alternatives); + BOOST_CHECK_EQUAL(reference_20.number_of_alternatives, result_20->number_of_alternatives); + BOOST_CHECK_EQUAL(reference_20.geometries, result_20->geometries); + BOOST_CHECK_EQUAL(reference_20.annotations, result_20->annotations); + BOOST_CHECK_EQUAL(reference_20.overview, result_20->overview); + BOOST_CHECK_EQUAL(reference_20.continue_straight, result_20->continue_straight); + CHECK_EQUAL_RANGE(reference_20.bearings, result_20->bearings); + CHECK_EQUAL_RANGE(reference_20.radiuses, result_20->radiuses); + CHECK_EQUAL_RANGE(reference_20.approaches, result_20->approaches); + CHECK_EQUAL_RANGE(reference_20.coordinates, result_20->coordinates); + CHECK_EQUAL_RANGE_OF_HINTS(reference_20.hints, result_20->hints); + + // exclude flags + RouteParameters reference_21{}; + reference_21.exclude = {"ferry", "motorway"}; + reference_21.coordinates = coords_1; + auto result_21 = parseParameters("1,2;3,4?exclude=ferry,motorway"); + BOOST_CHECK(result_21); + BOOST_CHECK_EQUAL(reference_21.steps, result_21->steps); + BOOST_CHECK_EQUAL(reference_21.alternatives, result_21->alternatives); + BOOST_CHECK_EQUAL(reference_21.number_of_alternatives, result_21->number_of_alternatives); + BOOST_CHECK_EQUAL(reference_21.geometries, result_21->geometries); + BOOST_CHECK_EQUAL(reference_21.annotations, result_21->annotations); + BOOST_CHECK_EQUAL(reference_21.overview, result_21->overview); + BOOST_CHECK_EQUAL(reference_21.continue_straight, result_21->continue_straight); + CHECK_EQUAL_RANGE(reference_21.bearings, result_21->bearings); + CHECK_EQUAL_RANGE(reference_21.radiuses, result_21->radiuses); + CHECK_EQUAL_RANGE(reference_21.approaches, result_21->approaches); + CHECK_EQUAL_RANGE(reference_21.coordinates, result_21->coordinates); + CHECK_EQUAL_RANGE_OF_HINTS(reference_21.hints, result_21->hints); + CHECK_EQUAL_RANGE(reference_21.exclude, result_21->exclude); +} + +BOOST_AUTO_TEST_CASE(valid_table_urls) +{ + std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, + {util::FloatLongitude{3}, util::FloatLatitude{4}}}; + + TableParameters reference_1{}; + reference_1.coordinates = coords_1; + auto result_1 = parseParameters("1,2;3,4"); + BOOST_CHECK(result_1); + CHECK_EQUAL_RANGE(reference_1.sources, result_1->sources); + CHECK_EQUAL_RANGE(reference_1.destinations, result_1->destinations); + CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); + CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); + CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); + CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); + + std::vector sources_2 = {1, 2, 3}; + std::vector destinations_2 = {4, 5}; + TableParameters reference_2{sources_2, destinations_2}; + reference_2.coordinates = coords_1; + auto result_2 = parseParameters("1,2;3,4?sources=1;2;3&destinations=4;5"); + BOOST_CHECK(result_2); + CHECK_EQUAL_RANGE(reference_2.sources, result_2->sources); + CHECK_EQUAL_RANGE(reference_2.destinations, result_2->destinations); + CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); + CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); + CHECK_EQUAL_RANGE(reference_2.approaches, result_2->approaches); + CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); + + auto result_3 = parseParameters("1,2;3,4?sources=all&destinations=all"); + BOOST_CHECK(result_3); + CHECK_EQUAL_RANGE(reference_1.sources, result_3->sources); + CHECK_EQUAL_RANGE(reference_1.destinations, result_3->destinations); + CHECK_EQUAL_RANGE(reference_1.bearings, result_3->bearings); + CHECK_EQUAL_RANGE(reference_1.radiuses, result_3->radiuses); + CHECK_EQUAL_RANGE(reference_1.approaches, result_3->approaches); + CHECK_EQUAL_RANGE(reference_1.coordinates, result_3->coordinates); + + TableParameters reference_4{}; + reference_4.coordinates = coords_1; + auto result_4 = parseParameters( + "1,2;3,4?sources=all&destinations=all&annotations=duration"); + BOOST_CHECK(result_4); + BOOST_CHECK_EQUAL(result_4->annotations & (TableParameters::AnnotationsType::Distance | + TableParameters::AnnotationsType::Duration), + true); + CHECK_EQUAL_RANGE(reference_4.sources, result_4->sources); + CHECK_EQUAL_RANGE(reference_4.destinations, result_4->destinations); + + TableParameters reference_5{}; + reference_5.coordinates = coords_1; + auto result_5 = parseParameters( + "1,2;3,4?sources=all&destinations=all&annotations=duration"); + BOOST_CHECK(result_5); + BOOST_CHECK_EQUAL(result_5->annotations & TableParameters::AnnotationsType::Duration, true); + CHECK_EQUAL_RANGE(reference_5.sources, result_5->sources); + CHECK_EQUAL_RANGE(reference_5.destinations, result_5->destinations); + + TableParameters reference_6{}; + reference_6.coordinates = coords_1; + auto result_6 = parseParameters( + "1,2;3,4?sources=all&destinations=all&annotations=distance"); + BOOST_CHECK(result_6); + BOOST_CHECK_EQUAL(result_6->annotations & TableParameters::AnnotationsType::Distance, true); + CHECK_EQUAL_RANGE(reference_6.sources, result_6->sources); + CHECK_EQUAL_RANGE(reference_6.destinations, result_6->destinations); + + TableParameters reference_7{}; + reference_7.coordinates = coords_1; + auto result_7 = parseParameters("1,2;3,4?annotations=distance"); + BOOST_CHECK(result_7); + BOOST_CHECK_EQUAL(result_7->annotations & TableParameters::AnnotationsType::Distance, true); + CHECK_EQUAL_RANGE(reference_7.sources, result_7->sources); + CHECK_EQUAL_RANGE(reference_7.destinations, result_7->destinations); + + TableParameters reference_8{}; + reference_8.coordinates = coords_1; + auto result_8 = + parseParameters("1,2;3,4?annotations=distance&fallback_speed=2.5"); + BOOST_CHECK(result_8); + BOOST_CHECK_EQUAL(result_8->annotations & TableParameters::AnnotationsType::Distance, true); + CHECK_EQUAL_RANGE(reference_8.sources, result_8->sources); + CHECK_EQUAL_RANGE(reference_8.destinations, result_8->destinations); + + TableParameters reference_9{}; + reference_9.coordinates = coords_1; + auto result_9 = parseParameters( + "1,2;3,4?annotations=distance&fallback_speed=2.5&fallback_coordinate=input"); + BOOST_CHECK(result_9); + BOOST_CHECK_EQUAL(result_9->annotations & TableParameters::AnnotationsType::Distance, true); + CHECK_EQUAL_RANGE(reference_9.sources, result_9->sources); + CHECK_EQUAL_RANGE(reference_9.destinations, result_9->destinations); + + TableParameters reference_10{}; + reference_10.coordinates = coords_1; + auto result_10 = parseParameters( + "1,2;3,4?annotations=distance&fallback_speed=20&fallback_coordinate=snapped"); + BOOST_CHECK(result_10); + BOOST_CHECK_EQUAL(result_10->annotations & TableParameters::AnnotationsType::Distance, true); + CHECK_EQUAL_RANGE(reference_10.sources, result_10->sources); + CHECK_EQUAL_RANGE(reference_10.destinations, result_10->destinations); + + auto result_11 = parseParameters("1,2;3,4?sources=all&destinations=all&" + "annotations=duration&fallback_speed=1&" + "fallback_coordinate=snapped&scale_factor=2"); + BOOST_CHECK(result_11); + CHECK_EQUAL_RANGE(reference_1.sources, result_11->sources); + CHECK_EQUAL_RANGE(reference_1.destinations, result_11->destinations); + CHECK_EQUAL_RANGE(reference_1.bearings, result_11->bearings); + CHECK_EQUAL_RANGE(reference_1.radiuses, result_11->radiuses); + CHECK_EQUAL_RANGE(reference_1.approaches, result_11->approaches); + CHECK_EQUAL_RANGE(reference_1.coordinates, result_11->coordinates); +} + +BOOST_AUTO_TEST_CASE(valid_match_urls) +{ + std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, + {util::FloatLongitude{3}, util::FloatLatitude{4}}}; + + MatchParameters reference_1{}; + reference_1.coordinates = coords_1; + auto result_1 = parseParameters("1,2;3,4"); + BOOST_CHECK(result_1); + CHECK_EQUAL_RANGE(reference_1.timestamps, result_1->timestamps); + CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); + CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); + CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); + CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); + + MatchParameters reference_2{}; + reference_2.coordinates = coords_1; + reference_2.timestamps = {5, 6}; + auto result_2 = parseParameters("1,2;3,4?timestamps=5;6"); + BOOST_CHECK(result_2); + CHECK_EQUAL_RANGE(reference_2.timestamps, result_2->timestamps); + CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); + CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); + CHECK_EQUAL_RANGE(reference_2.approaches, result_2->approaches); + CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); + + std::vector coords_2 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, + {util::FloatLongitude{3}, util::FloatLatitude{4}}, + {util::FloatLongitude{5}, util::FloatLatitude{6}}}; + + MatchParameters reference_3{}; + reference_3.coordinates = coords_2; + reference_3.waypoints = {0, 2}; + auto result_3 = parseParameters("1,2;3,4;5,6?waypoints=0;2"); + BOOST_CHECK(result_3); + CHECK_EQUAL_RANGE(reference_3.waypoints, result_3->waypoints); + CHECK_EQUAL_RANGE(reference_3.timestamps, result_3->timestamps); + CHECK_EQUAL_RANGE(reference_3.bearings, result_3->bearings); + CHECK_EQUAL_RANGE(reference_3.radiuses, result_3->radiuses); + CHECK_EQUAL_RANGE(reference_3.approaches, result_3->approaches); + CHECK_EQUAL_RANGE(reference_3.coordinates, result_3->coordinates); +} + +BOOST_AUTO_TEST_CASE(invalid_match_urls) +{ + std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, + {util::FloatLongitude{3}, util::FloatLatitude{4}}}; + + MatchParameters reference_1{}; + reference_1.coordinates = coords_1; + auto result_1 = parseParameters("1,2;3,4?radiuses=unlimited;60"); + BOOST_CHECK(result_1); + CHECK_EQUAL_RANGE(reference_1.timestamps, result_1->timestamps); + CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); + BOOST_CHECK(reference_1.radiuses != result_1->radiuses); + CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); + CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); + + std::vector coords_2 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, + {util::FloatLongitude{3}, util::FloatLatitude{4}}}; + + MatchParameters reference_2{}; + reference_2.coordinates = coords_2; + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?waypoints=0,4"), 19UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?waypoints=x;4"), 18UL); + BOOST_CHECK_EQUAL(testInvalidOptions("1,2;3,4?waypoints=0;3.5"), 21UL); +} + +BOOST_AUTO_TEST_CASE(valid_nearest_urls) +{ + std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}}; + + NearestParameters reference_1{}; + reference_1.coordinates = coords_1; + auto result_1 = parseParameters("1,2"); + BOOST_CHECK(result_1); + BOOST_CHECK_EQUAL(reference_1.number_of_results, result_1->number_of_results); + CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); + CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); + CHECK_EQUAL_RANGE(reference_1.approaches, result_1->approaches); + CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); + + NearestParameters reference_2{}; + reference_2.coordinates = coords_1; + reference_2.number_of_results = 42; + auto result_2 = parseParameters("1,2?number=42"); + BOOST_CHECK(result_2); + BOOST_CHECK_EQUAL(reference_2.number_of_results, result_2->number_of_results); + CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); + CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); + CHECK_EQUAL_RANGE(reference_2.approaches, result_2->approaches); + CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); +} + +BOOST_AUTO_TEST_CASE(invalid_tile_urls) +{ + TileParameters reference_1{1, 2, 3}; + auto result_1 = parseParameters("tile(1,2,3).mvt"); + BOOST_CHECK(result_1); + BOOST_CHECK(!result_1->IsValid()); + BOOST_CHECK_EQUAL(reference_1.x, result_1->x); + BOOST_CHECK_EQUAL(reference_1.y, result_1->y); + BOOST_CHECK_EQUAL(reference_1.z, result_1->z); +} + +BOOST_AUTO_TEST_CASE(valid_tile_urls) +{ + TileParameters reference_1{1, 2, 12}; + auto result_1 = parseParameters("tile(1,2,12).mvt"); + BOOST_CHECK(result_1->IsValid()); + BOOST_CHECK(result_1); + BOOST_CHECK_EQUAL(reference_1.x, result_1->x); + BOOST_CHECK_EQUAL(reference_1.y, result_1->y); + BOOST_CHECK_EQUAL(reference_1.z, result_1->z); +} + +BOOST_AUTO_TEST_CASE(valid_trip_urls) +{ + std::vector coords_1 = {{util::FloatLongitude{1}, util::FloatLatitude{2}}, + {util::FloatLongitude{3}, util::FloatLatitude{4}}}; + + TripParameters reference_1{}; + reference_1.coordinates = coords_1; + auto result_1 = parseParameters("1,2;3,4"); + BOOST_CHECK(result_1); + + CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses); + CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates); + + TripParameters reference_2{}; + reference_2.coordinates = coords_1; + reference_2.source = TripParameters::SourceType::First; + reference_2.destination = TripParameters::DestinationType::Last; + auto result_2 = parseParameters("1,2;3,4?source=first&destination=last"); + BOOST_CHECK(result_2); + CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); + CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); + + // check supported source/destination/rountrip combinations + auto param_fse_r = + parseParameters("1,2;3,4?source=first&destination=last&roundtrip=true"); + BOOST_CHECK(param_fse_r->IsValid()); + auto param_fse_nr_ = + parseParameters("1,2;3,4?source=first&destination=last&roundtrip=false"); + BOOST_CHECK(param_fse_nr_->IsValid()); + auto param_fs_r = parseParameters("1,2;3,4?source=first&roundtrip=true"); + BOOST_CHECK(param_fs_r->IsValid()); + auto param_fs_nr = parseParameters("1,2;3,4?source=first&roundtrip=false"); + BOOST_CHECK(param_fs_nr->IsValid()); + auto param_fe_r = parseParameters("1,2;3,4?destination=last&roundtrip=true"); + BOOST_CHECK(param_fe_r->IsValid()); + auto param_fe_nr = parseParameters("1,2;3,4?destination=last&roundtrip=false"); + BOOST_CHECK(param_fe_nr->IsValid()); + auto param_r = parseParameters("1,2;3,4?roundtrip=true"); + BOOST_CHECK(param_r->IsValid()); + auto param_nr = parseParameters("1,2;3,4?roundtrip=false"); + BOOST_CHECK(param_nr->IsValid()); + + auto param_fail_1 = + testInvalidOptions("1,2;3,4?source=blubb&destination=random"); + BOOST_CHECK_EQUAL(param_fail_1, 15UL); + auto param_fail_2 = testInvalidOptions("1,2;3,4?source=first&destination=nah"); + BOOST_CHECK_EQUAL(param_fail_2, 33UL); +} + +BOOST_AUTO_TEST_SUITE_END() From 55ac8d02a470be70be144d812977efeed0015feb Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Mon, 1 Jul 2024 17:57:24 +0200 Subject: [PATCH 9/9] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b0eb65a802..cff8250da8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - NodeJS: - CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452) - Misc: + - CHANGED: Get rid of boost::optional leftovers. [#6977](https://github.com/Project-OSRM/osrm-backend/pull/6977) - CHANGED: Use struct instead of tuple to define UnpackedPath. [#6974](https://github.com/Project-OSRM/osrm-backend/pull/6974) - CHANGED: Micro performance optimisation in map matching. [#6976](https://github.com/Project-OSRM/osrm-backend/pull/6976) - CHANGED: Re-use priority queue in StaticRTree. [#6952](https://github.com/Project-OSRM/osrm-backend/pull/6952)