Merge branch 'master' into danpat_cleanup_node_deps

This commit is contained in:
Daniel Patterson 2021-01-27 09:16:11 -08:00
commit f7b74470d2
No known key found for this signature in database
GPG Key ID: 19C12BE1725A028B
10 changed files with 578 additions and 248 deletions

View File

@ -16,7 +16,8 @@
- Windows:
- FIXED: Fix bit-shift overflow in MLD partition step. [#5878](https://github.com/Project-OSRM/osrm-backend/pull/5878)
- FIXED: Fix vector bool permutation in graph contraction step [#5882](https://github.com/Project-OSRM/osrm-backend/pull/5882)
- API:
- FIXED: Undo libosrm API break by adding old interface as method overload [#5861](https://github.com/Project-OSRM/osrm-backend/pull/5861)
# 5.23.0
- Changes from 5.22.0

View File

@ -84,7 +84,8 @@ class OSRM final
* \return Status indicating success for the query or failure
* \see Status, RouteParameters and json::Object
*/
Status Route(const RouteParameters &parameters, osrm::engine::api::ResultT &result) const;
Status Route(const RouteParameters &parameters, json::Object &result) const;
Status Route(const RouteParameters &parameters, engine::api::ResultT &result) const;
/**
* Distance tables for coordinates.
@ -93,7 +94,8 @@ class OSRM final
* \return Status indicating success for the query or failure
* \see Status, TableParameters and json::Object
*/
Status Table(const TableParameters &parameters, osrm::engine::api::ResultT &result) const;
Status Table(const TableParameters &parameters, json::Object &result) const;
Status Table(const TableParameters &parameters, engine::api::ResultT &result) const;
/**
* Nearest street segment for coordinate.
@ -102,7 +104,8 @@ class OSRM final
* \return Status indicating success for the query or failure
* \see Status, NearestParameters and json::Object
*/
Status Nearest(const NearestParameters &parameters, osrm::engine::api::ResultT &result) const;
Status Nearest(const NearestParameters &parameters, json::Object &result) const;
Status Nearest(const NearestParameters &parameters, engine::api::ResultT &result) const;
/**
* Trip: shortest round trip between coordinates.
@ -111,7 +114,8 @@ class OSRM final
* \return Status indicating success for the query or failure
* \see Status, TripParameters and json::Object
*/
Status Trip(const TripParameters &parameters, osrm::engine::api::ResultT &result) const;
Status Trip(const TripParameters &parameters, json::Object &result) const;
Status Trip(const TripParameters &parameters, engine::api::ResultT &result) const;
/**
* Match: snaps noisy coordinate traces to the road network
@ -120,7 +124,8 @@ class OSRM final
* \return Status indicating success for the query or failure
* \see Status, MatchParameters and json::Object
*/
Status Match(const MatchParameters &parameters, osrm::engine::api::ResultT &result) const;
Status Match(const MatchParameters &parameters, json::Object &result) const;
Status Match(const MatchParameters &parameters, engine::api::ResultT &result) const;
/**
* Tile: vector tiles with internal graph representation
@ -129,7 +134,8 @@ class OSRM final
* \return Status indicating success for the query or failure
* \see Status, TileParameters and json::Object
*/
Status Tile(const TileParameters &parameters, osrm::engine::api::ResultT &result) const;
Status Tile(const TileParameters &parameters, std::string &result) const;
Status Tile(const TileParameters &parameters, engine::api::ResultT &result) const;
private:
std::unique_ptr<engine::EngineInterface> engine_;

View File

@ -306,7 +306,10 @@ inline void asyncForTiles(const Nan::FunctionCallbackInfo<v8::Value> &info,
// clang-format on
NAN_METHOD(Engine::route) //
{
async(info, &argumentsToRouteParameter, &osrm::OSRM::Route, true);
osrm::Status (osrm::OSRM::*route_fn)(const osrm::RouteParameters &params,
osrm::engine::api::ResultT &result) const =
&osrm::OSRM::Route;
async(info, &argumentsToRouteParameter, route_fn, true);
}
// clang-format off
@ -346,7 +349,10 @@ NAN_METHOD(Engine::route) //
// clang-format on
NAN_METHOD(Engine::nearest) //
{
async(info, &argumentsToNearestParameter, &osrm::OSRM::Nearest, false);
osrm::Status (osrm::OSRM::*nearest_fn)(const osrm::NearestParameters &params,
osrm::engine::api::ResultT &result) const =
&osrm::OSRM::Nearest;
async(info, &argumentsToNearestParameter, nearest_fn, false);
}
// clang-format off
@ -398,7 +404,10 @@ NAN_METHOD(Engine::nearest) //
// clang-format on
NAN_METHOD(Engine::table) //
{
async(info, &argumentsToTableParameter, &osrm::OSRM::Table, true);
osrm::Status (osrm::OSRM::*table_fn)(const osrm::TableParameters &params,
osrm::engine::api::ResultT &result) const =
&osrm::OSRM::Table;
async(info, &argumentsToTableParameter, table_fn, true);
}
// clang-format off
@ -429,7 +438,10 @@ NAN_METHOD(Engine::table) //
// clang-format on
NAN_METHOD(Engine::tile)
{
asyncForTiles(info, &argumentsToTileParameters, &osrm::OSRM::Tile, {/*unused*/});
osrm::Status (osrm::OSRM::*tile_fn)(const osrm::TileParameters &params,
osrm::engine::api::ResultT &result) const =
&osrm::OSRM::Tile;
asyncForTiles(info, &argumentsToTileParameters, tile_fn, {/*unused*/});
}
// clang-format off
@ -483,7 +495,10 @@ NAN_METHOD(Engine::tile)
// clang-format on
NAN_METHOD(Engine::match) //
{
async(info, &argumentsToMatchParameter, &osrm::OSRM::Match, true);
osrm::Status (osrm::OSRM::*match_fn)(const osrm::MatchParameters &params,
osrm::engine::api::ResultT &result) const =
&osrm::OSRM::Match;
async(info, &argumentsToMatchParameter, match_fn, true);
}
// clang-format off
@ -553,7 +568,10 @@ NAN_METHOD(Engine::match) //
// clang-format on
NAN_METHOD(Engine::trip) //
{
async(info, &argumentsToTripParameter, &osrm::OSRM::Trip, true);
osrm::Status (osrm::OSRM::*trip_fn)(const osrm::TripParameters &params,
osrm::engine::api::ResultT &result) const =
&osrm::OSRM::Trip;
async(info, &argumentsToTripParameter, trip_fn, true);
}
/**

View File

@ -56,38 +56,81 @@ OSRM &OSRM::operator=(OSRM &&) noexcept = default;
// Forward to implementation
engine::Status OSRM::Route(const engine::api::RouteParameters &params,
osrm::engine::api::ResultT &result) const
Status OSRM::Route(const engine::api::RouteParameters &params, json::Object &json_result) const
{
osrm::engine::api::ResultT result = json::Object();
auto status = engine_->Route(params, result);
json_result = std::move(result.get<json::Object>());
return status;
}
Status OSRM::Route(const RouteParameters &params, engine::api::ResultT &result) const
{
return engine_->Route(params, result);
}
engine::Status OSRM::Table(const engine::api::TableParameters &params,
osrm::engine::api::ResultT &result) const
Status OSRM::Table(const engine::api::TableParameters &params, json::Object &json_result) const
{
osrm::engine::api::ResultT result = json::Object();
auto status = engine_->Table(params, result);
json_result = std::move(result.get<json::Object>());
return status;
}
Status OSRM::Table(const TableParameters &params, engine::api::ResultT &result) const
{
return engine_->Table(params, result);
}
engine::Status OSRM::Nearest(const engine::api::NearestParameters &params,
osrm::engine::api::ResultT &result) const
Status OSRM::Nearest(const engine::api::NearestParameters &params, json::Object &json_result) const
{
osrm::engine::api::ResultT result = json::Object();
auto status = engine_->Nearest(params, result);
json_result = std::move(result.get<json::Object>());
return status;
}
Status OSRM::Nearest(const NearestParameters &params, engine::api::ResultT &result) const
{
return engine_->Nearest(params, result);
}
Status OSRM::Trip(const engine::api::TripParameters &params, json::Object &json_result) const
{
osrm::engine::api::ResultT result = json::Object();
auto status = engine_->Trip(params, result);
json_result = std::move(result.get<json::Object>());
return status;
}
engine::Status OSRM::Trip(const engine::api::TripParameters &params,
osrm::engine::api::ResultT &result) const
engine::api::ResultT &result) const
{
return engine_->Trip(params, result);
}
engine::Status OSRM::Match(const engine::api::MatchParameters &params,
osrm::engine::api::ResultT &result) const
Status OSRM::Match(const engine::api::MatchParameters &params, json::Object &json_result) const
{
osrm::engine::api::ResultT result = json::Object();
auto status = engine_->Match(params, result);
json_result = std::move(result.get<json::Object>());
return status;
}
Status OSRM::Match(const MatchParameters &params, engine::api::ResultT &result) const
{
return engine_->Match(params, result);
}
engine::Status OSRM::Tile(const engine::api::TileParameters &params,
osrm::engine::api::ResultT &result) const
Status OSRM::Tile(const engine::api::TileParameters &params, std::string &str_result) const
{
osrm::engine::api::ResultT result = std::string();
auto status = engine_->Tile(params, result);
str_result = std::move(result.get<std::string>());
return status;
}
Status OSRM::Tile(const engine::api::TileParameters &params, engine::api::ResultT &result) const
{
return engine_->Tile(params, result);
}

View File

@ -7,14 +7,28 @@
#include "osrm/match_parameters.hpp"
#include "osrm/coordinate.hpp"
#include "osrm/engine_config.hpp"
#include "osrm/json_container.hpp"
#include "osrm/osrm.hpp"
#include "osrm/status.hpp"
osrm::Status run_match_json(const osrm::OSRM &osrm,
const MatchParameters &params,
json::Object &json_result,
bool use_json_only_api)
{
if (use_json_only_api)
{
return osrm.Match(params, json_result);
}
engine::api::ResultT result = json::Object();
auto rc = osrm.Match(params, result);
json_result = result.get<json::Object>();
return rc;
}
BOOST_AUTO_TEST_SUITE(match)
BOOST_AUTO_TEST_CASE(test_match)
void test_match(bool use_json_only_api)
{
using namespace osrm;
@ -25,11 +39,9 @@ BOOST_AUTO_TEST_CASE(test_match)
params.coordinates.push_back(get_dummy_location());
params.coordinates.push_back(get_dummy_location());
engine::api::ResultT result = json::Object();
json::Object json_result;
const auto rc = run_match_json(osrm, params, json_result, use_json_only_api);
const auto rc = osrm.Match(params, result);
auto &json_result = result.get<json::Object>();
BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -63,8 +75,10 @@ BOOST_AUTO_TEST_CASE(test_match)
}
}
}
BOOST_AUTO_TEST_CASE(test_match_new_api) { test_match(false); }
BOOST_AUTO_TEST_CASE(test_match_old_api) { test_match(true); }
BOOST_AUTO_TEST_CASE(test_match_skip_waypoints)
void test_match_skip_waypoints(bool use_json_only_api)
{
using namespace osrm;
@ -76,19 +90,19 @@ BOOST_AUTO_TEST_CASE(test_match_skip_waypoints)
params.coordinates.push_back(get_dummy_location());
params.coordinates.push_back(get_dummy_location());
engine::api::ResultT result = json::Object();
json::Object json_result;
const auto rc = run_match_json(osrm, params, json_result, use_json_only_api);
const auto rc = osrm.Match(params, result);
auto &json_result = result.get<json::Object>();
BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
BOOST_CHECK(json_result.values.find("tracepoints") == json_result.values.end());
}
BOOST_AUTO_TEST_CASE(test_match_skip_waypoints_old_api) { test_match_skip_waypoints(true); }
BOOST_AUTO_TEST_CASE(test_match_skip_waypoints_new_api) { test_match_skip_waypoints(false); }
BOOST_AUTO_TEST_CASE(test_match_split)
void test_match_split(bool use_json_only_api)
{
using namespace osrm;
@ -98,11 +112,9 @@ BOOST_AUTO_TEST_CASE(test_match_split)
params.coordinates = get_split_trace_locations();
params.timestamps = {1, 2, 1700, 1800};
engine::api::ResultT result = json::Object();
json::Object json_result;
const auto rc = run_match_json(osrm, params, json_result, use_json_only_api);
const auto rc = osrm.Match(params, result);
auto &json_result = result.get<json::Object>();
BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -140,6 +152,8 @@ BOOST_AUTO_TEST_CASE(test_match_split)
}
}
}
BOOST_AUTO_TEST_CASE(test_match_split_old_api) { test_match_split(true); }
BOOST_AUTO_TEST_CASE(test_match_split_new_api) { test_match_split(false); }
BOOST_AUTO_TEST_CASE(test_match_fb_serialization)
{

View File

@ -7,14 +7,28 @@
#include "osrm/nearest_parameters.hpp"
#include "osrm/coordinate.hpp"
#include "osrm/engine_config.hpp"
#include "osrm/json_container.hpp"
#include "osrm/osrm.hpp"
#include "osrm/status.hpp"
osrm::Status run_nearest_json(const osrm::OSRM &osrm,
const osrm::NearestParameters &params,
osrm::json::Object &json_result,
bool use_json_only_api)
{
if (use_json_only_api)
{
return osrm.Nearest(params, json_result);
}
osrm::engine::api::ResultT result = osrm::json::Object();
auto rc = osrm.Nearest(params, result);
json_result = result.get<osrm::json::Object>();
return rc;
}
BOOST_AUTO_TEST_SUITE(nearest)
BOOST_AUTO_TEST_CASE(test_nearest_response)
void test_nearest_response(bool use_json_only_api)
{
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
@ -23,11 +37,10 @@ BOOST_AUTO_TEST_CASE(test_nearest_response)
NearestParameters params;
params.coordinates.push_back(get_dummy_location());
engine::api::ResultT result = json::Object();
const auto rc = osrm.Nearest(params, result);
json::Object json_result;
const auto rc = run_nearest_json(osrm, params, json_result, use_json_only_api);
BOOST_REQUIRE(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -41,8 +54,10 @@ BOOST_AUTO_TEST_CASE(test_nearest_response)
BOOST_CHECK(distance >= 0);
}
}
BOOST_AUTO_TEST_CASE(test_nearest_response_old_api) { test_nearest_response(true); }
BOOST_AUTO_TEST_CASE(test_nearest_response_new_api) { test_nearest_response(false); }
BOOST_AUTO_TEST_CASE(test_nearest_response_skip_waypoints)
void test_nearest_response_skip_waypoints(bool use_json_only_api)
{
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
@ -52,18 +67,25 @@ BOOST_AUTO_TEST_CASE(test_nearest_response_skip_waypoints)
params.skip_waypoints = true;
params.coordinates.push_back(get_dummy_location());
engine::api::ResultT result = json::Object();
const auto rc = osrm.Nearest(params, result);
json::Object json_result;
const auto rc = run_nearest_json(osrm, params, json_result, use_json_only_api);
BOOST_REQUIRE(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
BOOST_CHECK(json_result.values.find("waypoints") == json_result.values.end());
}
BOOST_AUTO_TEST_CASE(test_nearest_response_skip_waypoints_old_api)
{
test_nearest_response_skip_waypoints(true);
}
BOOST_AUTO_TEST_CASE(test_nearest_response_skip_waypoints_new_api)
{
test_nearest_response_skip_waypoints(false);
}
BOOST_AUTO_TEST_CASE(test_nearest_response_no_coordinates)
void test_nearest_response_no_coordinates(bool use_json_only_api)
{
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
@ -71,16 +93,23 @@ BOOST_AUTO_TEST_CASE(test_nearest_response_no_coordinates)
NearestParameters params;
engine::api::ResultT result = json::Object();
const auto rc = osrm.Nearest(params, result);
json::Object json_result;
const auto rc = run_nearest_json(osrm, params, json_result, use_json_only_api);
BOOST_REQUIRE(rc == Status::Error);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "InvalidOptions");
}
BOOST_AUTO_TEST_CASE(test_nearest_response_no_coordinates_old_api)
{
test_nearest_response_no_coordinates(true);
}
BOOST_AUTO_TEST_CASE(test_nearest_response_no_coordinates_new_api)
{
test_nearest_response_no_coordinates(false);
}
BOOST_AUTO_TEST_CASE(test_nearest_response_multiple_coordinates)
void test_nearest_response_multiple_coordinates(bool use_json_only_api)
{
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
@ -90,16 +119,23 @@ BOOST_AUTO_TEST_CASE(test_nearest_response_multiple_coordinates)
params.coordinates.push_back(get_dummy_location());
params.coordinates.push_back(get_dummy_location());
engine::api::ResultT result = json::Object();
const auto rc = osrm.Nearest(params, result);
json::Object json_result;
const auto rc = run_nearest_json(osrm, params, json_result, use_json_only_api);
BOOST_REQUIRE(rc == Status::Error);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "InvalidOptions");
}
BOOST_AUTO_TEST_CASE(test_nearest_response_multiple_coordinates_old_api)
{
test_nearest_response_multiple_coordinates(true);
}
BOOST_AUTO_TEST_CASE(test_nearest_response_multiple_coordinates_new_api)
{
test_nearest_response_multiple_coordinates(false);
}
BOOST_AUTO_TEST_CASE(test_nearest_response_for_location_in_small_component)
void test_nearest_response_for_location_in_small_component(bool use_json_only_api)
{
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
@ -111,11 +147,10 @@ BOOST_AUTO_TEST_CASE(test_nearest_response_for_location_in_small_component)
params.coordinates.push_back(locations.at(0));
params.number_of_results = 3;
engine::api::ResultT result = json::Object();
const auto rc = osrm.Nearest(params, result);
json::Object json_result;
const auto rc = run_nearest_json(osrm, params, json_result, use_json_only_api);
BOOST_REQUIRE(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -137,6 +172,14 @@ BOOST_AUTO_TEST_CASE(test_nearest_response_for_location_in_small_component)
BOOST_CHECK(nodes[1].get<util::json::Number>().value != 0);
}
}
BOOST_AUTO_TEST_CASE(test_nearest_response_for_location_in_small_component_old_api)
{
test_nearest_response_for_location_in_small_component(true);
}
BOOST_AUTO_TEST_CASE(test_nearest_response_for_location_in_small_component_new_api)
{
test_nearest_response_for_location_in_small_component(false);
}
BOOST_AUTO_TEST_CASE(test_nearest_fb_serialization)
{

View File

@ -15,9 +15,24 @@
#include "osrm/route_parameters.hpp"
#include "osrm/status.hpp"
osrm::Status run_route_json(const osrm::OSRM &osrm,
const osrm::RouteParameters &params,
osrm::json::Object &json_result,
bool use_json_only_api)
{
if (use_json_only_api)
{
return osrm.Route(params, json_result);
}
osrm::engine::api::ResultT result = osrm::json::Object();
auto rc = osrm.Route(params, result);
json_result = result.get<osrm::json::Object>();
return rc;
}
BOOST_AUTO_TEST_SUITE(route)
BOOST_AUTO_TEST_CASE(test_route_same_coordinates_fixture)
void test_route_same_coordinates_fixture(bool use_json_only_api)
{
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
@ -28,11 +43,10 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates_fixture)
params.coordinates.push_back(get_dummy_location());
params.coordinates.push_back(get_dummy_location());
engine::api::ResultT result = json::Object();
const auto rc = osrm.Route(params, result);
json::Object json_result;
const auto rc = run_route_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
// unset snapping dependent hint
for (auto &itr : json_result.values["waypoints"].get<json::Array>().values)
{
@ -115,8 +129,16 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates_fixture)
CHECK_EQUAL_JSON(reference, json_result);
}
BOOST_AUTO_TEST_CASE(test_route_same_coordinates_fixture_old_api)
{
test_route_same_coordinates_fixture(true);
}
BOOST_AUTO_TEST_CASE(test_route_same_coordinates_fixture_new_api)
{
test_route_same_coordinates_fixture(false);
}
BOOST_AUTO_TEST_CASE(test_route_same_coordinates)
void test_route_same_coordinates(bool use_json_only_api)
{
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
@ -128,11 +150,10 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates)
params.coordinates.push_back(get_dummy_location());
params.coordinates.push_back(get_dummy_location());
engine::api::ResultT result = json::Object();
const auto rc = osrm.Route(params, result);
json::Object json_result;
const auto rc = run_route_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -268,8 +289,10 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates)
}
}
}
BOOST_AUTO_TEST_CASE(test_route_same_coordinates_old_api) { test_route_same_coordinates(true); }
BOOST_AUTO_TEST_CASE(test_route_same_coordinates_new_api) { test_route_same_coordinates(false); }
BOOST_AUTO_TEST_CASE(test_route_same_coordinates_no_waypoints)
void test_route_same_coordinates_no_waypoints(bool use_json_only_api)
{
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
@ -282,11 +305,10 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates_no_waypoints)
params.coordinates.push_back(get_dummy_location());
params.coordinates.push_back(get_dummy_location());
engine::api::ResultT result = json::Object();
const auto rc = osrm.Route(params, result);
json::Object json_result;
const auto rc = run_route_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -315,8 +337,16 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates_no_waypoints)
// The rest of legs contents is verified by test_route_same_coordinates
}
}
BOOST_AUTO_TEST_CASE(test_route_same_coordinates_no_waypoints_old_api)
{
test_route_same_coordinates_no_waypoints(true);
}
BOOST_AUTO_TEST_CASE(test_route_same_coordinates_no_waypoints_new_api)
{
test_route_same_coordinates_no_waypoints(false);
}
BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_small_component)
void test_route_response_for_locations_in_small_component(bool use_json_only_api)
{
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
@ -329,11 +359,10 @@ BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_small_component)
params.coordinates.push_back(locations.at(1));
params.coordinates.push_back(locations.at(2));
engine::api::ResultT result = json::Object();
const auto rc = osrm.Route(params, result);
json::Object json_result;
const auto rc = run_route_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -351,8 +380,16 @@ BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_small_component)
BOOST_CHECK(latitude >= -90. && latitude <= 90.);
}
}
BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_small_component_old_api)
{
test_route_response_for_locations_in_small_component(true);
}
BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_small_component_new_api)
{
test_route_response_for_locations_in_small_component(false);
}
BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_big_component)
void test_route_response_for_locations_in_big_component(bool use_json_only_api)
{
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
@ -365,11 +402,10 @@ BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_big_component)
params.coordinates.push_back(locations.at(1));
params.coordinates.push_back(locations.at(2));
engine::api::ResultT result = json::Object();
const auto rc = osrm.Route(params, result);
json::Object json_result;
const auto rc = run_route_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -387,8 +423,16 @@ BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_big_component)
BOOST_CHECK(latitude >= -90. && latitude <= 90.);
}
}
BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_big_component_old_api)
{
test_route_response_for_locations_in_big_component(true);
}
BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_big_component_new_api)
{
test_route_response_for_locations_in_big_component(false);
}
BOOST_AUTO_TEST_CASE(test_route_response_for_locations_across_components)
void test_route_response_for_locations_across_components(bool use_json_only_api)
{
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
@ -403,11 +447,10 @@ BOOST_AUTO_TEST_CASE(test_route_response_for_locations_across_components)
params.coordinates.push_back(small_component.at(1));
params.coordinates.push_back(big_component.at(1));
engine::api::ResultT result = json::Object();
const auto rc = osrm.Route(params, result);
json::Object json_result;
const auto rc = run_route_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -425,8 +468,16 @@ BOOST_AUTO_TEST_CASE(test_route_response_for_locations_across_components)
BOOST_CHECK(latitude >= -90. && latitude <= 90.);
}
}
BOOST_AUTO_TEST_CASE(test_route_response_for_locations_across_components_old_api)
{
test_route_response_for_locations_across_components(true);
}
BOOST_AUTO_TEST_CASE(test_route_response_for_locations_across_components_new_api)
{
test_route_response_for_locations_across_components(false);
}
BOOST_AUTO_TEST_CASE(test_route_user_disables_generating_hints)
void test_route_user_disables_generating_hints(bool use_json_only_api)
{
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
@ -438,16 +489,23 @@ BOOST_AUTO_TEST_CASE(test_route_user_disables_generating_hints)
params.coordinates.push_back(get_dummy_location());
params.generate_hints = false;
engine::api::ResultT result = json::Object();
const auto rc = osrm.Route(params, result);
json::Object json_result;
const auto rc = run_route_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
for (auto waypoint : json_result.values["waypoints"].get<json::Array>().values)
BOOST_CHECK_EQUAL(waypoint.get<json::Object>().values.count("hint"), 0);
}
BOOST_AUTO_TEST_CASE(test_route_user_disables_generating_hints_old_api)
{
test_route_user_disables_generating_hints(true);
}
BOOST_AUTO_TEST_CASE(test_route_user_disables_generating_hints_new_api)
{
test_route_user_disables_generating_hints(false);
}
BOOST_AUTO_TEST_CASE(speed_annotation_matches_duration_and_distance)
void speed_annotation_matches_duration_and_distance(bool use_json_only_api)
{
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
@ -460,11 +518,10 @@ BOOST_AUTO_TEST_CASE(speed_annotation_matches_duration_and_distance)
params.coordinates.push_back(get_dummy_location());
params.coordinates.push_back(get_dummy_location());
engine::api::ResultT result = json::Object();
const auto rc = osrm.Route(params, result);
json::Object json_result;
const auto rc = run_route_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
const auto &routes = json_result.values["routes"].get<json::Array>().values;
const auto &legs = routes[0].get<json::Object>().values.at("legs").get<json::Array>().values;
const auto &annotation =
@ -489,8 +546,16 @@ BOOST_AUTO_TEST_CASE(speed_annotation_matches_duration_and_distance)
BOOST_CHECK_EQUAL(duration, 0);
}
}
BOOST_AUTO_TEST_CASE(speed_annotation_matches_duration_and_distance_old_api)
{
speed_annotation_matches_duration_and_distance(true);
}
BOOST_AUTO_TEST_CASE(speed_annotation_matches_duration_and_distance_new_api)
{
speed_annotation_matches_duration_and_distance(false);
}
BOOST_AUTO_TEST_CASE(test_manual_setting_of_annotations_property)
void test_manual_setting_of_annotations_property(bool use_json_only_api)
{
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
@ -501,11 +566,10 @@ BOOST_AUTO_TEST_CASE(test_manual_setting_of_annotations_property)
params.coordinates.push_back(get_dummy_location());
params.coordinates.push_back(get_dummy_location());
engine::api::ResultT result = json::Object();
const auto rc = osrm.Route(params, result);
json::Object json_result;
const auto rc = run_route_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -522,6 +586,14 @@ BOOST_AUTO_TEST_CASE(test_manual_setting_of_annotations_property)
.values;
BOOST_CHECK_EQUAL(annotations.size(), 6);
}
BOOST_AUTO_TEST_CASE(test_manual_setting_of_annotations_property_old_api)
{
test_manual_setting_of_annotations_property(true);
}
BOOST_AUTO_TEST_CASE(test_manual_setting_of_annotations_property_new_api)
{
test_manual_setting_of_annotations_property(false);
}
BOOST_AUTO_TEST_CASE(test_route_serialize_fb)
{

View File

@ -7,14 +7,28 @@
#include "osrm/table_parameters.hpp"
#include "osrm/coordinate.hpp"
#include "osrm/engine_config.hpp"
#include "osrm/json_container.hpp"
#include "osrm/osrm.hpp"
#include "osrm/status.hpp"
osrm::Status run_table_json(const osrm::OSRM &osrm,
const osrm::TableParameters &params,
osrm::json::Object &json_result,
bool use_json_only_api)
{
if (use_json_only_api)
{
return osrm.Table(params, json_result);
}
osrm::engine::api::ResultT result = osrm::json::Object();
auto rc = osrm.Table(params, result);
json_result = result.get<osrm::json::Object>();
return rc;
}
BOOST_AUTO_TEST_SUITE(table)
BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix)
void test_table_three_coords_one_source_one_dest_matrix(bool use_json_only_api)
{
using namespace osrm;
@ -28,11 +42,9 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix)
params.destinations.push_back(2);
params.annotations = TableParameters::AnnotationsType::All;
engine::api::ResultT result = json::Object();
json::Object json_result;
const auto rc = run_table_json(osrm, params, json_result, use_json_only_api);
const auto rc = osrm.Table(params, result);
auto &json_result = result.get<json::Object>();
BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -75,8 +87,16 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix)
BOOST_CHECK(waypoint_check(source));
}
}
BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix_old_api)
{
test_table_three_coords_one_source_one_dest_matrix(true);
}
BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix_new_api)
{
test_table_three_coords_one_source_one_dest_matrix(false);
}
BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix_no_waypoints)
void test_table_three_coords_one_source_one_dest_matrix_no_waypoints(bool use_json_only_api)
{
using namespace osrm;
@ -91,11 +111,9 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix_no_waypo
params.destinations.push_back(2);
params.annotations = TableParameters::AnnotationsType::All;
engine::api::ResultT result = json::Object();
json::Object json_result;
const auto rc = run_table_json(osrm, params, json_result, use_json_only_api);
const auto rc = osrm.Table(params, result);
auto &json_result = result.get<json::Object>();
BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -126,8 +144,16 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix_no_waypo
BOOST_CHECK(json_result.values.find("destinations") == json_result.values.end());
BOOST_CHECK(json_result.values.find("sources") == json_result.values.end());
}
BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix_no_waypoints_old_api)
{
test_table_three_coords_one_source_one_dest_matrix_no_waypoints(true);
}
BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix_no_waypoints_new_api)
{
test_table_three_coords_one_source_one_dest_matrix_no_waypoints(false);
}
BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_matrix)
void test_table_three_coords_one_source_matrix(bool use_json_only_api)
{
using namespace osrm;
@ -140,9 +166,9 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_matrix)
params.sources.push_back(0);
engine::api::ResultT result = json::Object();
const auto rc = osrm.Table(params, result);
json::Object json_result;
const auto rc = run_table_json(osrm, params, json_result, use_json_only_api);
auto &json_result = result.get<json::Object>();
BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -174,8 +200,16 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_matrix)
BOOST_CHECK(waypoint_check(source));
}
}
BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_matrix_old_api)
{
test_table_three_coords_one_source_matrix(true);
}
BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_matrix_new_api)
{
test_table_three_coords_one_source_matrix(false);
}
BOOST_AUTO_TEST_CASE(test_table_three_coordinates_matrix)
void test_table_three_coordinates_matrix(bool use_json_only_api)
{
using namespace osrm;
@ -187,11 +221,9 @@ BOOST_AUTO_TEST_CASE(test_table_three_coordinates_matrix)
params.coordinates.push_back(get_dummy_location());
params.annotations = TableParameters::AnnotationsType::Duration;
engine::api::ResultT result = json::Object();
json::Object json_result;
const auto rc = run_table_json(osrm, params, json_result, use_json_only_api);
const auto rc = osrm.Table(params, result);
auto &json_result = result.get<json::Object>();
BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -219,9 +251,17 @@ BOOST_AUTO_TEST_CASE(test_table_three_coordinates_matrix)
BOOST_CHECK(waypoint_check(source));
}
}
BOOST_AUTO_TEST_CASE(test_table_three_coordinates_matrix_old_api)
{
test_table_three_coordinates_matrix(true);
}
BOOST_AUTO_TEST_CASE(test_table_three_coordinates_matrix_new_api)
{
test_table_three_coordinates_matrix(false);
}
// See https://github.com/Project-OSRM/osrm-backend/pull/3992
BOOST_AUTO_TEST_CASE(test_table_no_segment_for_some_coordinates)
void test_table_no_segment_for_some_coordinates(bool use_json_only_api)
{
using namespace osrm;
@ -234,17 +274,23 @@ BOOST_AUTO_TEST_CASE(test_table_no_segment_for_some_coordinates)
params.radiuses.push_back(boost::make_optional(0.));
params.radiuses.push_back(boost::none);
engine::api::ResultT result = json::Object();
json::Object json_result;
const auto rc = run_table_json(osrm, params, json_result, use_json_only_api);
const auto rc = osrm.Table(params, result);
auto &json_result = result.get<json::Object>();
BOOST_CHECK(rc == Status::Error);
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "NoSegment");
const auto message = json_result.values.at("message").get<json::String>().value;
BOOST_CHECK_EQUAL(message, "Could not find a matching segment for coordinate 0");
}
BOOST_AUTO_TEST_CASE(test_table_no_segment_for_some_coordinates_old_api)
{
test_table_no_segment_for_some_coordinates(true);
}
BOOST_AUTO_TEST_CASE(test_table_no_segment_for_some_coordinates_new_api)
{
test_table_no_segment_for_some_coordinates(false);
}
BOOST_AUTO_TEST_CASE(test_table_serialiaze_fb)
{

View File

@ -18,6 +18,21 @@
#include <map>
osrm::Status run_tile(const osrm::OSRM &osrm,
const osrm::TileParameters &params,
std::string &string_result,
bool use_string_only_api)
{
if (use_string_only_api)
{
return osrm.Tile(params, string_result);
}
osrm::engine::api::ResultT result = std::string();
auto rc = osrm.Tile(params, result);
string_result = result.get<std::string>();
return rc;
}
#define CHECK_EQUAL_RANGE(R1, R2) \
BOOST_CHECK_EQUAL_COLLECTIONS(R1.begin(), R1.end(), R2.begin(), R2.end());
@ -153,19 +168,17 @@ void validate_internal_nodes_layer(vtzero::layer layer)
}
}
void validate_tile(const osrm::OSRM &osrm)
void validate_tile(const osrm::OSRM &osrm, bool use_string_only_api)
{
using namespace osrm;
// This tile should contain most of monaco
TileParameters params{17059, 11948, 15};
engine::api::ResultT result = std::string();
const auto rc = osrm.Tile(params, result);
std::string str_result;
const auto rc = run_tile(osrm, params, str_result, use_string_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &str_result = result.get<std::string>();
BOOST_CHECK(str_result.size() > 114000);
vtzero::vector_tile tile{str_result};
@ -176,42 +189,47 @@ void validate_tile(const osrm::OSRM &osrm)
validate_internal_nodes_layer(tile.next_layer());
}
BOOST_AUTO_TEST_CASE(test_tile_ch)
void test_tile_ch(bool use_string_only_api)
{
using namespace osrm;
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", osrm::EngineConfig::Algorithm::CH);
validate_tile(osrm);
validate_tile(osrm, use_string_only_api);
}
BOOST_AUTO_TEST_CASE(test_tile_ch_old_api) { test_tile_ch(true); }
BOOST_AUTO_TEST_CASE(test_tile_ch_new_api) { test_tile_ch(false); }
BOOST_AUTO_TEST_CASE(test_tile_corech)
void test_tile_corech(bool use_string_only_api)
{
// Note: this tests that given the CoreCH algorithm config option, configuration falls back to
// CH and is compatible with CH data
using namespace osrm;
auto osrm =
getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", osrm::EngineConfig::Algorithm::CoreCH);
validate_tile(osrm);
validate_tile(osrm, use_string_only_api);
}
BOOST_AUTO_TEST_CASE(test_tile_corech_old_api) { test_tile_corech(true); }
BOOST_AUTO_TEST_CASE(test_tile_corech_new_api) { test_tile_corech(false); }
BOOST_AUTO_TEST_CASE(test_tile_mld)
void test_tile_mld(bool use_string_only_api)
{
using namespace osrm;
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/mld/monaco.osrm", osrm::EngineConfig::Algorithm::MLD);
validate_tile(osrm);
validate_tile(osrm, use_string_only_api);
}
BOOST_AUTO_TEST_CASE(test_tile_mld_old_api) { test_tile_mld(true); }
BOOST_AUTO_TEST_CASE(test_tile_mld_new_api) { test_tile_mld(false); }
void test_tile_turns(const osrm::OSRM &osrm)
void test_tile_turns(const osrm::OSRM &osrm, bool use_string_only_api)
{
using namespace osrm;
// Small tile where we can test all the values
TileParameters params{272953, 191177, 19};
engine::api::ResultT result = std::string();
const auto rc = osrm.Tile(params, result);
std::string str_result;
const auto rc = run_tile(osrm, params, str_result, use_string_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &str_result = result.get<std::string>();
BOOST_CHECK_GT(str_result.size(), 128);
vtzero::vector_tile tile{str_result};
@ -314,34 +332,41 @@ void test_tile_turns(const osrm::OSRM &osrm)
CHECK_EQUAL_RANGE(actual_turn_bearings, expected_turn_bearings);
}
BOOST_AUTO_TEST_CASE(test_tile_turns_ch)
void test_tile_turns_ch(osrm::EngineConfig::Algorithm algorithm, bool use_string_only_api)
{
using namespace osrm;
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", osrm::EngineConfig::Algorithm::CH);
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", algorithm);
test_tile_turns(osrm);
test_tile_turns(osrm, use_string_only_api);
}
BOOST_AUTO_TEST_CASE(test_tile_turns_corech)
BOOST_AUTO_TEST_CASE(test_tile_turns_ch_old_api)
{
// Note: this tests that given the CoreCH algorithm config option, configuration falls back to
// CH and is compatible with CH data
using namespace osrm;
auto osrm =
getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", osrm::EngineConfig::Algorithm::CoreCH);
test_tile_turns(osrm);
test_tile_turns_ch(osrm::EngineConfig::Algorithm::CH, true);
}
BOOST_AUTO_TEST_CASE(test_tile_turns_ch_new_api)
{
test_tile_turns_ch(osrm::EngineConfig::Algorithm::CH, false);
}
BOOST_AUTO_TEST_CASE(test_tile_turns_corech_old_api)
{
test_tile_turns_ch(osrm::EngineConfig::Algorithm::CoreCH, true);
}
BOOST_AUTO_TEST_CASE(test_tile_turns_corech_new_api)
{
test_tile_turns_ch(osrm::EngineConfig::Algorithm::CoreCH, false);
}
BOOST_AUTO_TEST_CASE(test_tile_turns_mld)
void test_tile_turns_mld(bool use_string_only_api)
{
using namespace osrm;
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/mld/monaco.osrm", osrm::EngineConfig::Algorithm::MLD);
test_tile_turns(osrm);
test_tile_turns(osrm, use_string_only_api);
}
BOOST_AUTO_TEST_CASE(test_tile_turns_mld_old_api) { test_tile_turns_mld(true); }
BOOST_AUTO_TEST_CASE(test_tile_turns_mld_new_api) { test_tile_turns_mld(false); }
void test_tile_speeds(const osrm::OSRM &osrm)
void test_tile_speeds(const osrm::OSRM &osrm, bool use_string_only_api)
{
using namespace osrm;
@ -349,11 +374,10 @@ void test_tile_speeds(const osrm::OSRM &osrm)
// TileParameters params{272953, 191177, 19};
TileParameters params{136477, 95580, 18};
engine::api::ResultT result = std::string();
const auto rc = osrm.Tile(params, result);
std::string str_result;
const auto rc = run_tile(osrm, params, str_result, use_string_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &str_result = result.get<std::string>();
BOOST_CHECK_GT(str_result.size(), 128);
vtzero::vector_tile tile{str_result};
@ -393,34 +417,41 @@ void test_tile_speeds(const osrm::OSRM &osrm)
BOOST_CHECK(actual_names == expected_names);
}
BOOST_AUTO_TEST_CASE(test_tile_speeds_ch)
void test_tile_speeds_ch(osrm::EngineConfig::Algorithm algorithm, bool use_string_only_api)
{
using namespace osrm;
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", osrm::EngineConfig::Algorithm::CH);
test_tile_speeds(osrm);
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", algorithm);
test_tile_speeds(osrm, use_string_only_api);
}
BOOST_AUTO_TEST_CASE(test_tile_speeds_corech)
BOOST_AUTO_TEST_CASE(test_tile_speeds_ch_old_api)
{
// Note: this tests that given the CoreCH algorithm config option, configuration falls back to
// CH and is compatible with CH data
using namespace osrm;
auto osrm =
getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", osrm::EngineConfig::Algorithm::CoreCH);
test_tile_speeds(osrm);
test_tile_speeds_ch(osrm::EngineConfig::Algorithm::CH, true);
}
BOOST_AUTO_TEST_CASE(test_tile_speeds_ch_new_api)
{
test_tile_speeds_ch(osrm::EngineConfig::Algorithm::CH, false);
}
BOOST_AUTO_TEST_CASE(test_tile_speeds_corech_old_api)
{
test_tile_speeds_ch(osrm::EngineConfig::Algorithm::CoreCH, true);
}
BOOST_AUTO_TEST_CASE(test_tile_speeds_corech_new_api)
{
test_tile_speeds_ch(osrm::EngineConfig::Algorithm::CoreCH, false);
}
BOOST_AUTO_TEST_CASE(test_tile_speeds_mld)
void test_tile_speeds_mld(bool use_string_only_api)
{
using namespace osrm;
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/mld/monaco.osrm", osrm::EngineConfig::Algorithm::MLD);
test_tile_speeds(osrm);
test_tile_speeds(osrm, use_string_only_api);
}
BOOST_AUTO_TEST_CASE(test_tile_speeds_mld_old_api) { test_tile_speeds_mld(true); }
BOOST_AUTO_TEST_CASE(test_tile_speeds_mld_new_api) { test_tile_speeds_mld(false); }
void test_tile_nodes(const osrm::OSRM &osrm)
void test_tile_nodes(const osrm::OSRM &osrm, bool use_string_only_api)
{
using namespace osrm;
@ -430,11 +461,10 @@ void test_tile_nodes(const osrm::OSRM &osrm)
// Small tile where we can test all the values
TileParameters params{272953, 191177, 19};
engine::api::ResultT result = std::string();
const auto rc = osrm.Tile(params, result);
std::string str_result;
const auto rc = run_tile(osrm, params, str_result, use_string_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &str_result = result.get<std::string>();
BOOST_CHECK_GT(str_result.size(), 128);
vtzero::vector_tile tile{str_result};
@ -456,31 +486,38 @@ void test_tile_nodes(const osrm::OSRM &osrm)
BOOST_CHECK(found_node_ids == expected_node_ids);
}
BOOST_AUTO_TEST_CASE(test_tile_nodes_ch)
void test_tile_nodes_ch(osrm::EngineConfig::Algorithm algorithm, bool use_string_only_api)
{
using namespace osrm;
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", osrm::EngineConfig::Algorithm::CH);
test_tile_nodes(osrm);
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", algorithm);
test_tile_nodes(osrm, use_string_only_api);
}
BOOST_AUTO_TEST_CASE(test_tile_nodes_corech)
BOOST_AUTO_TEST_CASE(test_tile_node_ch_old_api)
{
// Note: this tests that given the CoreCH algorithm config option, configuration falls back to
// CH and is compatible with CH data
using namespace osrm;
auto osrm =
getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm", osrm::EngineConfig::Algorithm::CoreCH);
test_tile_nodes(osrm);
test_tile_nodes_ch(osrm::EngineConfig::Algorithm::CH, true);
}
BOOST_AUTO_TEST_CASE(test_tile_node_ch_new_api)
{
test_tile_nodes_ch(osrm::EngineConfig::Algorithm::CH, false);
}
BOOST_AUTO_TEST_CASE(test_tile_node_corech_old_api)
{
test_tile_nodes_ch(osrm::EngineConfig::Algorithm::CoreCH, true);
}
BOOST_AUTO_TEST_CASE(test_tile_node_corech_new_api)
{
test_tile_nodes_ch(osrm::EngineConfig::Algorithm::CoreCH, false);
}
BOOST_AUTO_TEST_CASE(test_tile_nodes_mld)
void test_tile_nodes_mld(bool use_string_only_api)
{
using namespace osrm;
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/mld/monaco.osrm", osrm::EngineConfig::Algorithm::MLD);
test_tile_nodes(osrm);
test_tile_nodes(osrm, use_string_only_api);
}
BOOST_AUTO_TEST_CASE(test_tile_node_mld_old_api) { test_tile_nodes_mld(true); }
BOOST_AUTO_TEST_CASE(test_tile_node_mld_new_api) { test_tile_nodes_mld(false); }
BOOST_AUTO_TEST_SUITE_END()

View File

@ -7,14 +7,28 @@
#include <engine/api/flatbuffers/fbresult_generated.h>
#include "osrm/coordinate.hpp"
#include "osrm/engine_config.hpp"
#include "osrm/json_container.hpp"
#include "osrm/osrm.hpp"
#include "osrm/status.hpp"
osrm::Status run_trip_json(const osrm::OSRM &osrm,
const osrm::TripParameters &params,
osrm::json::Object &json_result,
bool use_json_only_api)
{
if (use_json_only_api)
{
return osrm.Trip(params, json_result);
}
osrm::engine::api::ResultT result = osrm::json::Object();
auto rc = osrm.Trip(params, result);
json_result = result.get<osrm::json::Object>();
return rc;
}
BOOST_AUTO_TEST_SUITE(trip)
BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_small_component)
void test_roundtrip_response_for_locations_in_small_component(bool use_json_only_api)
{
using namespace osrm;
@ -26,11 +40,10 @@ BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_small_component)
params.coordinates.push_back(locations.at(1));
params.coordinates.push_back(locations.at(2));
engine::api::ResultT result = json::Object();
const auto rc = osrm.Trip(params, result);
json::Object json_result;
const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -56,8 +69,16 @@ BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_small_component)
BOOST_CHECK(pos >= 0 && pos < waypoints.size());
}
}
BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_small_component_old_api)
{
test_roundtrip_response_for_locations_in_small_component(true);
}
BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_small_component_new_api)
{
test_roundtrip_response_for_locations_in_small_component(false);
}
BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_small_component_skip_waypoints)
void test_roundtrip_response_for_locations_in_small_component_skip_waypoints(bool use_json_only_api)
{
using namespace osrm;
@ -70,18 +91,27 @@ BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_small_component_sk
params.coordinates.push_back(locations.at(1));
params.coordinates.push_back(locations.at(2));
engine::api::ResultT result = json::Object();
const auto rc = osrm.Trip(params, result);
json::Object json_result;
const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
BOOST_CHECK(json_result.values.find("waypoints") == json_result.values.end());
}
BOOST_AUTO_TEST_CASE(
test_roundtrip_response_for_locations_in_small_component_skip_waypoints_old_api)
{
test_roundtrip_response_for_locations_in_small_component_skip_waypoints(true);
}
BOOST_AUTO_TEST_CASE(
test_roundtrip_response_for_locations_in_small_component_skip_waypoints_new_api)
{
test_roundtrip_response_for_locations_in_small_component_skip_waypoints(false);
}
BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_big_component)
void test_roundtrip_response_for_locations_in_big_component(bool use_json_only_api)
{
using namespace osrm;
@ -93,11 +123,10 @@ BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_big_component)
params.coordinates.push_back(locations.at(1));
params.coordinates.push_back(locations.at(2));
engine::api::ResultT result = json::Object();
const auto rc = osrm.Trip(params, result);
json::Object json_result;
const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -123,8 +152,16 @@ BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_big_component)
BOOST_CHECK(pos >= 0 && pos < waypoints.size());
}
}
BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_big_component_old_api)
{
test_roundtrip_response_for_locations_in_big_component(true);
}
BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_big_component_new_api)
{
test_roundtrip_response_for_locations_in_big_component(false);
}
BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_across_components)
void test_roundtrip_response_for_locations_across_components(bool use_json_only_api)
{
using namespace osrm;
@ -138,11 +175,10 @@ BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_across_components)
params.coordinates.push_back(small.at(1));
params.coordinates.push_back(big.at(1));
engine::api::ResultT result = json::Object();
const auto rc = osrm.Trip(params, result);
json::Object json_result;
const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -170,8 +206,16 @@ BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_across_components)
BOOST_CHECK(pos >= 0 && pos < waypoints.size());
}
}
BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_across_components_old_api)
{
test_roundtrip_response_for_locations_across_components(true);
}
BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_across_components_new_api)
{
test_roundtrip_response_for_locations_across_components(false);
}
BOOST_AUTO_TEST_CASE(test_tfse_1)
void test_tfse_1(bool use_json_only_api)
{
using namespace osrm;
@ -187,11 +231,10 @@ BOOST_AUTO_TEST_CASE(test_tfse_1)
params.destination = TripParameters::DestinationType::Last;
params.roundtrip = false;
engine::api::ResultT result = json::Object();
const auto rc = osrm.Trip(params, result);
json::Object json_result;
const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -217,8 +260,10 @@ BOOST_AUTO_TEST_CASE(test_tfse_1)
BOOST_CHECK(pos >= 0 && pos < waypoints.size());
}
}
BOOST_AUTO_TEST_CASE(test_tfse_1_old_api) { test_tfse_1(true); }
BOOST_AUTO_TEST_CASE(test_tfse_1_new_api) { test_tfse_1(false); }
BOOST_AUTO_TEST_CASE(test_tfse_2)
void test_tfse_2(bool use_json_only_api)
{
using namespace osrm;
@ -234,11 +279,10 @@ BOOST_AUTO_TEST_CASE(test_tfse_2)
params.destination = TripParameters::DestinationType::Last;
params.roundtrip = false;
engine::api::ResultT result = json::Object();
const auto rc = osrm.Trip(params, result);
json::Object json_result;
const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Ok);
auto &json_result = result.get<json::Object>();
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
@ -264,6 +308,8 @@ BOOST_AUTO_TEST_CASE(test_tfse_2)
BOOST_CHECK(pos >= 0 && pos < waypoints.size());
}
}
BOOST_AUTO_TEST_CASE(test_tfse_2_old_api) { test_tfse_2(true); }
BOOST_AUTO_TEST_CASE(test_tfse_2_new_api) { test_tfse_2(false); }
void ResetParams(const Locations &locations, osrm::TripParameters &params)
{
@ -272,29 +318,29 @@ void ResetParams(const Locations &locations, osrm::TripParameters &params)
params.coordinates.push_back(locations.at(1));
params.coordinates.push_back(locations.at(2));
}
void CheckNotImplemented(const osrm::OSRM &osrm, osrm::TripParameters &params)
void CheckNotImplemented(const osrm::OSRM &osrm,
osrm::TripParameters &params,
bool use_json_only_api)
{
using namespace osrm;
engine::api::ResultT result = json::Object();
auto rc = osrm.Trip(params, result);
json::Object json_result;
const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api);
BOOST_REQUIRE(rc == osrm::Status::Error);
auto &json_result = result.get<json::Object>();
auto code = json_result.values.at("code").get<osrm::json::String>().value;
BOOST_CHECK_EQUAL(code, "NotImplemented");
}
void CheckOk(const osrm::OSRM &osrm, osrm::TripParameters &params)
void CheckOk(const osrm::OSRM &osrm, osrm::TripParameters &params, bool use_json_only_api)
{
using namespace osrm;
engine::api::ResultT result = json::Object();
auto rc = osrm.Trip(params, result);
json::Object json_result;
const auto rc = run_trip_json(osrm, params, json_result, use_json_only_api);
BOOST_REQUIRE(rc == osrm::Status::Ok);
auto &json_result = result.get<json::Object>();
auto code = json_result.values.at("code").get<osrm::json::String>().value;
BOOST_CHECK_EQUAL(code, "Ok");
}
BOOST_AUTO_TEST_CASE(test_tfse_illegal_parameters)
void test_tfse_illegal_parameters(bool use_json_only_api)
{
using namespace osrm;
@ -305,47 +351,49 @@ BOOST_AUTO_TEST_CASE(test_tfse_illegal_parameters)
// one parameter set
ResetParams(locations, params);
params.roundtrip = false;
CheckNotImplemented(osrm, params);
CheckNotImplemented(osrm, params, use_json_only_api);
// two parameter set
ResetParams(locations, params);
params.source = TripParameters::SourceType::Any;
params.roundtrip = false;
CheckNotImplemented(osrm, params);
CheckNotImplemented(osrm, params, use_json_only_api);
ResetParams(locations, params);
params.source = TripParameters::SourceType::First;
params.roundtrip = false;
CheckNotImplemented(osrm, params);
CheckNotImplemented(osrm, params, use_json_only_api);
ResetParams(locations, params);
params.destination = TripParameters::DestinationType::Any;
params.roundtrip = false;
CheckNotImplemented(osrm, params);
CheckNotImplemented(osrm, params, use_json_only_api);
ResetParams(locations, params);
params.destination = TripParameters::DestinationType::Last;
params.roundtrip = false;
CheckNotImplemented(osrm, params);
CheckNotImplemented(osrm, params, use_json_only_api);
// three parameters set
params.source = TripParameters::SourceType::Any;
params.destination = TripParameters::DestinationType::Any;
params.roundtrip = false;
CheckNotImplemented(osrm, params);
CheckNotImplemented(osrm, params, use_json_only_api);
params.source = TripParameters::SourceType::Any;
params.destination = TripParameters::DestinationType::Last;
params.roundtrip = false;
CheckNotImplemented(osrm, params);
CheckNotImplemented(osrm, params, use_json_only_api);
params.source = TripParameters::SourceType::First;
params.destination = TripParameters::DestinationType::Any;
params.roundtrip = false;
CheckNotImplemented(osrm, params);
CheckNotImplemented(osrm, params, use_json_only_api);
}
BOOST_AUTO_TEST_CASE(test_tfse_illegal_parameters_old_api) { test_tfse_illegal_parameters(true); }
BOOST_AUTO_TEST_CASE(test_tfse_illegal_parameters_new_api) { test_tfse_illegal_parameters(false); }
BOOST_AUTO_TEST_CASE(test_tfse_legal_parameters)
void test_tfse_legal_parameters(bool use_json_only_api)
{
using namespace osrm;
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
@ -355,96 +403,98 @@ BOOST_AUTO_TEST_CASE(test_tfse_legal_parameters)
// no parameter set
ResetParams(locations, params);
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
// one parameter set
ResetParams(locations, params);
params.roundtrip = true;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
ResetParams(locations, params);
params.source = TripParameters::SourceType::First;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
ResetParams(locations, params);
params.source = TripParameters::SourceType::Any;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
ResetParams(locations, params);
params.destination = TripParameters::DestinationType::Any;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
ResetParams(locations, params);
params.destination = TripParameters::DestinationType::Last;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
// two parameter set
ResetParams(locations, params);
params.destination = TripParameters::DestinationType::Last;
params.roundtrip = true;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
ResetParams(locations, params);
params.source = TripParameters::SourceType::First;
params.roundtrip = true;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
ResetParams(locations, params);
params.source = TripParameters::SourceType::First;
params.destination = TripParameters::DestinationType::Any;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
ResetParams(locations, params);
params.source = TripParameters::SourceType::Any;
params.destination = TripParameters::DestinationType::Last;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
ResetParams(locations, params);
params.source = TripParameters::SourceType::First;
params.destination = TripParameters::DestinationType::Last;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
ResetParams(locations, params);
params.source = TripParameters::SourceType::Any;
params.roundtrip = true;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
ResetParams(locations, params);
params.destination = TripParameters::DestinationType::Any;
params.roundtrip = true;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
ResetParams(locations, params);
params.source = TripParameters::SourceType::Any;
params.destination = TripParameters::DestinationType::Any;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
// three parameter set
params.source = TripParameters::SourceType::Any;
params.destination = TripParameters::DestinationType::Any;
params.roundtrip = true;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
params.source = TripParameters::SourceType::First;
params.destination = TripParameters::DestinationType::Last;
params.roundtrip = false;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
params.source = TripParameters::SourceType::Any;
params.destination = TripParameters::DestinationType::Last;
params.roundtrip = true;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
params.source = TripParameters::SourceType::First;
params.destination = TripParameters::DestinationType::Any;
params.roundtrip = true;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
params.source = TripParameters::SourceType::First;
params.destination = TripParameters::DestinationType::Last;
params.roundtrip = true;
CheckOk(osrm, params);
CheckOk(osrm, params, use_json_only_api);
}
BOOST_AUTO_TEST_CASE(test_tfse_legal_parameters_old_api) { test_tfse_legal_parameters(true); }
BOOST_AUTO_TEST_CASE(test_tfse_legal_parameters_new_api) { test_tfse_legal_parameters(false); }
BOOST_AUTO_TEST_CASE(test_roundtrip_response_fb_serialization)
{