diff --git a/features/step_definitions/trip.js b/features/step_definitions/trip.js index 7e52c5d224e..699aa27b851 100644 --- a/features/step_definitions/trip.js +++ b/features/step_definitions/trip.js @@ -34,6 +34,8 @@ module.exports = function () { json = JSON.parse(res.body); } + console.log(json); + if (headers.has('status')) { got.status = json.status.toString(); } @@ -52,6 +54,15 @@ module.exports = function () { } } + if (headers.has('source') && headers.has('destination')) { + if (this.queryParams['source']) { + got.source = json.trips[0].source; + } + if (this.queryParams['destination']) { + got.source = json.trips[0].destination; + } + } + if (headers.has('#')) { // comment column got['#'] = row['#']; diff --git a/features/testbot/trip.feature b/features/testbot/trip.feature index 287a7618b06..29be31aca9a 100644 --- a/features/testbot/trip.feature +++ b/features/testbot/trip.feature @@ -24,6 +24,7 @@ Feature: Basic trip planning | a,b,c,d | abcda | 7.6 | | d,b,c,a | dbcad | 7.6 | + Scenario: Testbot - Trip planning with more than 10 nodes Given the node map """ @@ -48,14 +49,16 @@ Feature: Basic trip planning | kl | | la | - When I plan a trip I should get | waypoints | trips | | a,b,c,d,e,f,g,h,i,j,k,l | cbalkjihgfedc | Scenario: Testbot - Trip planning with less than 10 nodes with fixed start and end - Given the query parameters + Given the query options + | source | 1 | + | destination | 4 | + Given the node map """ a b @@ -71,11 +74,15 @@ Feature: Basic trip planning When I plan a trip I should get | waypoints | trips | durations | - | a,b,c,d | abcd | 7.6 | - | d,b,c,a | dbca | 7.6 | + | a,b,c,d | abcda | 7.6 | + | d,b,c,a | dbcaa | 7.6 | Scenario: Testbot - Trip planning with more than 10 nodes with fixed start and end + Given the query options + | source | 1 | + | destination | 12 | + Given the node map """ a b c d @@ -101,8 +108,9 @@ Feature: Basic trip planning When I plan a trip I should get - | waypoints | trips | - | a,b,c,d,e,f,g,h,i,j,k,l | cbalkjihgfed | + | waypoints | trips | + | a,b,c,d,e,f,g,h,i,j,k,l | cbalkjihgfedc | + Scenario: Testbot - Trip planning with multiple scc Given the node map @@ -141,6 +149,7 @@ Feature: Basic trip planning | waypoints | trips | | a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p | defghijklabcd,mnopm | + # Test single node in each component #1850 Scenario: Testbot - Trip planning with less than 10 nodes Given the node map @@ -196,6 +205,7 @@ Feature: Basic trip planning | a,b,c,d | abcda | 7.6 | 1,1,1.00009,1,1,0.99991,1.00009,1,1,1,1.00009,0.99991,1,1 | | d,b,c,a | dbcad | 7.6 | 1.00009,0.99991,1,1,1.00009,1,1,0.99991,1.00009,1,1,1,1.00009,0.99991 | + Scenario: Testbot - Trip with geometry details of polyline Given the query options | geometries | polyline | @@ -218,6 +228,7 @@ Feature: Basic trip planning | a,b,c,d | abcda | 7.6 | 1,1,1,1.00009,0.99991,1,1,1.00009,1,1,0.99991,1.00009,1,1 | | d,b,c,a | dbcad | 7.6 | 0.99991,1.00009,1,1,1,1.00009,0.99991,1,1,1.00009,1,1,0.99991,1.00009 | + Scenario: Testbot - Trip with geometry details of polyline6 Given the query options | geometries | polyline6 | diff --git a/include/engine/api/trip_parameters.hpp b/include/engine/api/trip_parameters.hpp index 53c9f42746d..507ad26b022 100644 --- a/include/engine/api/trip_parameters.hpp +++ b/include/engine/api/trip_parameters.hpp @@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "engine/api/route_parameters.hpp" +#include #include namespace osrm @@ -47,7 +48,30 @@ namespace api */ struct TripParameters : public RouteParameters { - // bool IsValid() const; Falls back to base class + TripParameters() + : RouteParameters(false, + false, + false, + RouteParameters::GeometriesType::Polyline, + RouteParameters::OverviewType::Simplified, + 0, + 0) + { + } + + template + TripParameters(int source_, int destination_, Args... args_) + : RouteParameters{std::forward(args_)...}, source{source_}, destination{destination_} + { + } + + int source; + int destination; + + bool IsValid() const + { + return RouteParameters::IsValid() && source > 0 && destination > 0; + } }; } } diff --git a/include/server/api/trip_parameter_grammar.hpp b/include/server/api/trip_parameter_grammar.hpp index 30809a398bd..26e6cafe32c 100644 --- a/include/server/api/trip_parameter_grammar.hpp +++ b/include/server/api/trip_parameter_grammar.hpp @@ -26,11 +26,20 @@ struct TripParametersGrammar final : public RouteParametersGrammar + qi::uint_)[ph::bind(&engine::api::TripParameters::source, qi::_r1) = qi::_1]; + + destination_rule = (qi::lit("destination=") > + qi::uint_)[ph::bind(&engine::api::TripParameters::destination, qi::_r1) = qi::_1]; + root_rule = BaseGrammar::query_rule(qi::_r1) > -qi::lit(".json") > -('?' > (BaseGrammar::base_rule(qi::_r1)) % '&'); } private: + qi::rule source_rule; + qi::rule destination_rule; qi::rule root_rule; }; } diff --git a/src/engine/plugins/trip.cpp b/src/engine/plugins/trip.cpp index 73f4980deae..945ac0faa29 100644 --- a/src/engine/plugins/trip.cpp +++ b/src/engine/plugins/trip.cpp @@ -148,6 +148,9 @@ Status TripPlugin::HandleRequest(const std::shared_ptr 0 && static_cast(parameters.coordinates.size()) > max_locations_trip) diff --git a/unit_tests/server/parameters_parser.cpp b/unit_tests/server/parameters_parser.cpp index bbd0e5298b7..cbf45620f44 100644 --- a/unit_tests/server/parameters_parser.cpp +++ b/unit_tests/server/parameters_parser.cpp @@ -432,6 +432,18 @@ BOOST_AUTO_TEST_CASE(valid_trip_urls) CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings); 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 = 1; + reference_2.destination = 2; + auto result_2 = parseParameters("1,2;3,4?source=1&destination=2"); + BOOST_CHECK(result_2); + BOOST_CHECK_EQUAL(reference_2.source, result_2->source); + BOOST_CHECK_EQUAL(reference_2.destination, result_2->destination); + CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings); + CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses); + CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates); } BOOST_AUTO_TEST_SUITE_END()