add unit test for annotations=true returning all annotations
This commit is contained in:
parent
a31f401995
commit
e75278f9c2
@ -228,21 +228,23 @@ class RouteAPI : public BaseAPI
|
|||||||
|
|
||||||
std::vector<util::json::Object> annotations;
|
std::vector<util::json::Object> annotations;
|
||||||
|
|
||||||
if (parameters.annotations_type != RouteParameters::AnnotationsType::None ||
|
// To maintain support for uses of the old default constructors, we check
|
||||||
parameters.annotations == true)
|
// 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;
|
requested_annotations = RouteParameters::AnnotationsType::All;
|
||||||
if ((parameters.annotations == true) &&
|
}
|
||||||
(parameters.annotations_type == RouteParameters::AnnotationsType::None))
|
|
||||||
{
|
|
||||||
requested_annotations = RouteParameters::AnnotationsType::All;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (requested_annotations != RouteParameters::AnnotationsType::None)
|
||||||
|
{
|
||||||
for (const auto idx : util::irange<std::size_t>(0UL, leg_geometries.size()))
|
for (const auto idx : util::irange<std::size_t>(0UL, leg_geometries.size()))
|
||||||
{
|
{
|
||||||
auto &leg_geometry = leg_geometries[idx];
|
auto &leg_geometry = leg_geometries[idx];
|
||||||
util::json::Object annotation;
|
util::json::Object annotation;
|
||||||
|
|
||||||
|
// AnnotationsType uses bit flags, & operator checks if a property is set
|
||||||
if (parameters.annotations_type & RouteParameters::AnnotationsType::Speed)
|
if (parameters.annotations_type & RouteParameters::AnnotationsType::Speed)
|
||||||
{
|
{
|
||||||
annotation.values["speed"] = GetAnnotations(
|
annotation.values["speed"] = GetAnnotations(
|
||||||
@ -251,15 +253,13 @@ class RouteAPI : public BaseAPI
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// AnnotationsType uses bit flags, & operator checks if a property is set
|
if (requested_annotations & RouteParameters::AnnotationsType::Duration)
|
||||||
if (ReqAnnotations & RouteParameters::AnnotationsType::Duration)
|
|
||||||
{
|
{
|
||||||
annotation.values["duration"] = GetAnnotations(
|
annotation.values["duration"] = GetAnnotations(
|
||||||
leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
|
leg_geometry, [](const guidance::LegGeometry::Annotation &anno) {
|
||||||
return anno.duration;
|
return anno.duration;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requested_annotations & RouteParameters::AnnotationsType::Distance)
|
if (requested_annotations & RouteParameters::AnnotationsType::Distance)
|
||||||
{
|
{
|
||||||
annotation.values["distance"] = GetAnnotations(
|
annotation.values["distance"] = GetAnnotations(
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"name": "osrm-backend-test-suite",
|
"name": "osrm-backend-test-suite",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"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": {
|
"dependencies": {
|
||||||
"chalk": "^1.1.3",
|
"chalk": "^1.1.3",
|
||||||
"cucumber": "^1.2.1",
|
"cucumber": "^1.2.1",
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
#include "util/log.hpp"
|
#include "util/log.hpp"
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
inline std::vector<std::string> get_args()
|
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 argc = boost::unit_test::framework::master_test_suite().argc - 1;
|
||||||
const auto argv = boost::unit_test::framework::master_test_suite().argv + 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};
|
return {argv, argv + argc};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,7 +394,7 @@ BOOST_AUTO_TEST_CASE(speed_annotation_matches_duration_and_distance)
|
|||||||
|
|
||||||
using namespace osrm;
|
using namespace osrm;
|
||||||
|
|
||||||
RouteParameters params{};
|
RouteParameters params;
|
||||||
params.annotations_type = RouteParameters::AnnotationsType::Duration |
|
params.annotations_type = RouteParameters::AnnotationsType::Duration |
|
||||||
RouteParameters::AnnotationsType::Distance |
|
RouteParameters::AnnotationsType::Distance |
|
||||||
RouteParameters::AnnotationsType::Speed;
|
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()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
Loading…
Reference in New Issue
Block a user