add unit test for annotations=true returning all annotations

This commit is contained in:
karenzshea 2017-02-13 12:53:05 +01:00 committed by Patrick Niklaus
parent a31f401995
commit e75278f9c2
4 changed files with 47 additions and 19 deletions

View File

@ -228,21 +228,23 @@ class RouteAPI : public BaseAPI
std::vector<util::json::Object> 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<std::size_t>(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(

View File

@ -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",

View File

@ -4,9 +4,9 @@
#include "util/log.hpp"
#include <boost/filesystem.hpp>
#include <iostream>
#include <iostream>
#include <string>
#include <vector>
#include <iostream>
inline std::vector<std::string> get_args()
{
@ -26,11 +26,6 @@ inline std::vector<std::string> 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};
}

View File

@ -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<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
auto annotations = result.values["routes"]
.get<json::Array>()
.values[0]
.get<json::Object>()
.values["legs"]
.get<json::Array>()
.values[0]
.get<json::Object>()
.values["annotation"]
.get<json::Object>()
.values;
BOOST_CHECK_EQUAL(annotations.size(), 5);
}
BOOST_AUTO_TEST_SUITE_END()