Skip to content

Commit

Permalink
add unit test for annotations=true returning all annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
karenzshea committed Feb 13, 2017
1 parent 9b12319 commit 6301e34
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 19 deletions.
22 changes: 11 additions & 11 deletions include/engine/api/route_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 1 addition & 6 deletions unit_tests/library/args.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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};
}

Expand Down
35 changes: 34 additions & 1 deletion unit_tests/library/route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()

0 comments on commit 6301e34

Please sign in to comment.