From 210da11fbb657c6680b6a8d19249d54a516cdb82 Mon Sep 17 00:00:00 2001 From: "Daniel J. Hofmann" Date: Fri, 18 Mar 2016 13:48:17 +0100 Subject: [PATCH] Unit test for Route service; some failing where v5 spec is unclear --- unit_tests/library/route.cpp | 117 +++++++++++++++++++++++++++++++++-- 1 file changed, 113 insertions(+), 4 deletions(-) diff --git a/unit_tests/library/route.cpp b/unit_tests/library/route.cpp index 4cab3db26..10d347156 100644 --- a/unit_tests/library/route.cpp +++ b/unit_tests/library/route.cpp @@ -14,7 +14,7 @@ BOOST_AUTO_TEST_SUITE(route) -BOOST_AUTO_TEST_CASE(test_route) +BOOST_AUTO_TEST_CASE(test_route_same_coordinates) { const auto args = get_args(); auto osrm = get_osrm(args.at(0)); @@ -22,15 +22,124 @@ BOOST_AUTO_TEST_CASE(test_route) using namespace osrm; RouteParameters params; - + params.coordinates.emplace_back(util::FloatLongitude{}, util::FloatLatitude{}); params.coordinates.emplace_back(util::FloatLongitude{}, util::FloatLatitude{}); params.coordinates.emplace_back(util::FloatLongitude{}, util::FloatLatitude{}); json::Object result; - const auto rc = osrm.Route(params, result); + BOOST_CHECK(rc == Status::Ok); - BOOST_CHECK(rc == Status::Ok || rc == Status::Error); + const auto code = result.values.at("code").get().value; + BOOST_CHECK_EQUAL(code, "ok"); + + const auto &waypoints = result.values.at("waypoints").get().values; + BOOST_CHECK(!waypoints.empty()); + + for (const auto &waypoint : waypoints) + { + const auto &waypoint_object = waypoint.get(); + + // nothing can be said about name, empty or contains name of the street + const auto name = waypoint_object.values.at("name").get().value; + BOOST_CHECK(((void)name, true)); + + const auto location = waypoint_object.values.at("location").get().values; + const auto longitude = location[0].get().value; + const auto latitude = location[1].get().value; + BOOST_CHECK(longitude >= 180. && longitude <= -180.); + BOOST_CHECK(latitude >= -90. && latitude <= 90.); + + const auto hint = waypoint_object.values.at("hint").get().value; + BOOST_CHECK(!hint.empty()); + } + + // alternative=true by default + const auto &routes = result.values.at("routes").get().values; + BOOST_CHECK(!routes.empty()); + BOOST_CHECK(routes.size() > 1); + + for (const auto &route : routes) + { + const auto &route_object = route.get(); + + const auto distance = route_object.values.at("distance").get().value; + BOOST_CHECK(distance == 0); + + const auto duration = route_object.values.at("duration").get().value; + BOOST_CHECK(duration == 0); + + // geometries=polyline by default + const auto geometry = route_object.values.at("geometry").get().value; + BOOST_CHECK(!geometry.empty()); + + const auto &legs = route_object.values.at("legs").get().values; + BOOST_CHECK(!legs.empty()); + + for (const auto &leg : legs) + { + const auto &leg_object = leg.get(); + + const auto distance = leg_object.values.at("distance").get().value; + BOOST_CHECK(distance == 0); + + const auto duration = leg_object.values.at("duration").get().value; + BOOST_CHECK(duration == 0); + + // nothing can be said about summary, empty or contains human readable summary + const auto summary = leg_object.values.at("summary").get().value; + BOOST_CHECK(((void)summary, true)); + + // steps=true by default + const auto &steps = leg_object.values.at("steps").get().values; + BOOST_CHECK(!steps.empty()); + + for (const auto &step : steps) + { + const auto &step_object = step.get(); + + const auto distance = step_object.values.at("distance").get().value; + BOOST_CHECK(distance == 0); + + const auto duration = step_object.values.at("duration").get().value; + BOOST_CHECK(duration == 0); + + // geometries=polyline by default + const auto geometry = step_object.values.at("geometry").get().value; + BOOST_CHECK(!geometry.empty()); + + // nothing can be said about name, empty or contains way name + const auto name = step_object.values.at("name").get().value; + BOOST_CHECK(((void)name, true)); + + // nothing can be said about mode, contains mode of transportation + const auto mode = step_object.values.at("mode").get().value; + BOOST_CHECK(!name.empty()); + + const auto &maneuver = step_object.values.at("maneuver").get().values; + + const auto location = maneuver.at("location").get().values; + const auto longitude = location[0].get().value; + const auto latitude = location[1].get().value; + BOOST_CHECK(longitude >= 180. && longitude <= -180.); + BOOST_CHECK(latitude >= -90. && latitude <= 90.); + + const auto bearing_before = maneuver.at("bearing_before").get().value; + const auto bearing_after = maneuver.at("bearing_after").get().value; + BOOST_CHECK(bearing_before >= 0. && bearing_before <= 360.); + BOOST_CHECK(bearing_after >= 0. && bearing_after <= 360.); + + const auto type = maneuver.at("type").get().value; + BOOST_CHECK(!type.empty()); + + // modifier is optional + // TODO(daniel-j-h): + + // exit is optional + // TODO(daniel-j-h): + } + } + } } BOOST_AUTO_TEST_SUITE_END()