From e75278f9c2450a6a1487c73c6b24c2b6ae1aac30 Mon Sep 17 00:00:00 2001 From: karenzshea Date: Mon, 13 Feb 2017 12:53:05 +0100 Subject: [PATCH] add unit test for annotations=true returning all annotations --- include/engine/api/route_api.hpp | 22 ++++++++++---------- package.json | 2 +- unit_tests/library/args.hpp | 7 +------ unit_tests/library/route.cpp | 35 +++++++++++++++++++++++++++++++- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/include/engine/api/route_api.hpp b/include/engine/api/route_api.hpp index 499c59d99..cbb22fbcd 100644 --- a/include/engine/api/route_api.hpp +++ b/include/engine/api/route_api.hpp @@ -228,21 +228,23 @@ class RouteAPI : public BaseAPI std::vector annotations; - if (parameters.annotations_type != RouteParameters::AnnotationsType::None || - parameters.annotations == true) + // To maintain support for uses of the old default constructors, we check + // if annotations property was set manually after default construction + auto requested_annotations = parameters.annotations_type; + if ((parameters.annotations == true) && + (parameters.annotations_type == RouteParameters::AnnotationsType::None)) { - auto requested_annotations = parameters.annotations_type; - if ((parameters.annotations == true) && - (parameters.annotations_type == RouteParameters::AnnotationsType::None)) - { - requested_annotations = RouteParameters::AnnotationsType::All; - } + requested_annotations = RouteParameters::AnnotationsType::All; + } + if (requested_annotations != RouteParameters::AnnotationsType::None) + { for (const auto idx : util::irange(0UL, leg_geometries.size())) { auto &leg_geometry = leg_geometries[idx]; util::json::Object annotation; + // AnnotationsType uses bit flags, & operator checks if a property is set if (parameters.annotations_type & RouteParameters::AnnotationsType::Speed) { annotation.values["speed"] = GetAnnotations( @@ -251,15 +253,13 @@ class RouteAPI : public BaseAPI }); } - // AnnotationsType uses bit flags, & operator checks if a property is set - if (ReqAnnotations & RouteParameters::AnnotationsType::Duration) + if (requested_annotations & RouteParameters::AnnotationsType::Duration) { annotation.values["duration"] = GetAnnotations( leg_geometry, [](const guidance::LegGeometry::Annotation &anno) { return anno.duration; }); } - if (requested_annotations & RouteParameters::AnnotationsType::Distance) { annotation.values["distance"] = GetAnnotations( diff --git a/package.json b/package.json index 0aead113d..363a4dfe5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "osrm-backend-test-suite", "version": "0.0.0", "private": true, - "description": "The Open Source Routing Machine is a high performance routing engine written in C++11 designed to run on OpenStreetMap data.", + "description": "The Open Source Routing Machine is a high performance routing engine written in C++14 designed to run on OpenStreetMap data.", "dependencies": { "chalk": "^1.1.3", "cucumber": "^1.2.1", diff --git a/unit_tests/library/args.hpp b/unit_tests/library/args.hpp index f9b95b17c..5cf0d53fc 100644 --- a/unit_tests/library/args.hpp +++ b/unit_tests/library/args.hpp @@ -4,9 +4,9 @@ #include "util/log.hpp" #include #include +#include #include #include -#include inline std::vector get_args() { @@ -26,11 +26,6 @@ inline std::vector get_args() const auto argc = boost::unit_test::framework::master_test_suite().argc - 1; const auto argv = boost::unit_test::framework::master_test_suite().argv + 1; - if (argc == 0) - { - std::cout << "You must provide a path to the test data, please see the unit testing docs" << std::endl; - } - return {argv, argv + argc}; } diff --git a/unit_tests/library/route.cpp b/unit_tests/library/route.cpp index 574a6e0e4..ecf3bf3eb 100644 --- a/unit_tests/library/route.cpp +++ b/unit_tests/library/route.cpp @@ -394,7 +394,7 @@ BOOST_AUTO_TEST_CASE(speed_annotation_matches_duration_and_distance) using namespace osrm; - RouteParameters params{}; + RouteParameters params; params.annotations_type = RouteParameters::AnnotationsType::Duration | RouteParameters::AnnotationsType::Distance | RouteParameters::AnnotationsType::Speed; @@ -422,4 +422,37 @@ BOOST_AUTO_TEST_CASE(speed_annotation_matches_duration_and_distance) } } +BOOST_AUTO_TEST_CASE(test_manual_setting_of_annotations_property) +{ + const auto args = get_args(); + auto osrm = getOSRM(args.at(0)); + + using namespace osrm; + + RouteParameters params{}; + params.annotations = true; + params.coordinates.push_back(get_dummy_location()); + params.coordinates.push_back(get_dummy_location()); + + json::Object result; + const auto rc = osrm.Route(params, result); + BOOST_CHECK(rc == Status::Ok); + + const auto code = result.values.at("code").get().value; + BOOST_CHECK_EQUAL(code, "Ok"); + + auto annotations = result.values["routes"] + .get() + .values[0] + .get() + .values["legs"] + .get() + .values[0] + .get() + .values["annotation"] + .get() + .values; + BOOST_CHECK_EQUAL(annotations.size(), 5); +} + BOOST_AUTO_TEST_SUITE_END()