2016-05-27 15:05:04 -04:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2016-03-16 06:58:39 -04:00
|
|
|
|
2016-04-01 18:39:45 -04:00
|
|
|
#include "coordinates.hpp"
|
2016-05-27 15:05:04 -04:00
|
|
|
#include "fixture.hpp"
|
2016-04-13 17:07:24 -04:00
|
|
|
#include "waypoint_check.hpp"
|
2016-03-16 07:42:26 -04:00
|
|
|
|
|
|
|
#include "osrm/match_parameters.hpp"
|
|
|
|
|
|
|
|
#include "osrm/coordinate.hpp"
|
|
|
|
#include "osrm/json_container.hpp"
|
|
|
|
#include "osrm/osrm.hpp"
|
2016-05-27 15:05:04 -04:00
|
|
|
#include "osrm/status.hpp"
|
2016-03-16 07:42:26 -04:00
|
|
|
|
2021-01-27 12:14:44 -05:00
|
|
|
osrm::Status run_match_json(const osrm::OSRM &osrm,
|
2022-06-30 09:32:12 -04:00
|
|
|
const osrm::MatchParameters ¶ms,
|
|
|
|
osrm::json::Object &json_result,
|
2021-01-27 12:14:44 -05:00
|
|
|
bool use_json_only_api)
|
|
|
|
{
|
2022-06-30 09:32:12 -04:00
|
|
|
using namespace osrm;
|
|
|
|
|
2021-01-27 12:14:44 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-03-16 06:58:39 -04:00
|
|
|
BOOST_AUTO_TEST_SUITE(match)
|
|
|
|
|
2021-01-27 12:14:44 -05:00
|
|
|
void test_match(bool use_json_only_api)
|
2016-03-16 07:42:26 -04:00
|
|
|
{
|
|
|
|
using namespace osrm;
|
|
|
|
|
2017-03-21 06:27:15 -04:00
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
2016-03-16 07:42:26 -04:00
|
|
|
|
|
|
|
MatchParameters params;
|
2016-04-01 18:39:45 -04:00
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
2016-03-16 07:42:26 -04:00
|
|
|
|
2021-01-27 12:14:44 -05:00
|
|
|
json::Object json_result;
|
|
|
|
const auto rc = run_match_json(osrm, params, json_result, use_json_only_api);
|
2016-03-16 07:42:26 -04:00
|
|
|
|
|
|
|
BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
|
2019-08-13 04:17:15 -04:00
|
|
|
const auto code = json_result.values.at("code").get<json::String>().value;
|
2016-04-01 18:39:45 -04:00
|
|
|
BOOST_CHECK_EQUAL(code, "Ok");
|
|
|
|
|
2019-08-13 04:17:15 -04:00
|
|
|
const auto &tracepoints = json_result.values.at("tracepoints").get<json::Array>().values;
|
2016-04-01 18:39:45 -04:00
|
|
|
BOOST_CHECK_EQUAL(tracepoints.size(), params.coordinates.size());
|
|
|
|
|
2019-08-13 04:17:15 -04:00
|
|
|
const auto &matchings = json_result.values.at("matchings").get<json::Array>().values;
|
2016-04-06 15:54:00 -04:00
|
|
|
const auto &number_of_matchings = matchings.size();
|
2016-04-01 18:39:45 -04:00
|
|
|
for (const auto &waypoint : tracepoints)
|
|
|
|
{
|
|
|
|
if (waypoint.is<mapbox::util::recursive_wrapper<util::json::Object>>())
|
2018-01-15 12:38:14 -05:00
|
|
|
{
|
|
|
|
BOOST_CHECK(waypoint_check(waypoint));
|
|
|
|
const auto &waypoint_object = waypoint.get<json::Object>();
|
|
|
|
const auto matchings_index =
|
|
|
|
waypoint_object.values.at("matchings_index").get<json::Number>().value;
|
|
|
|
const auto waypoint_index =
|
|
|
|
waypoint_object.values.at("waypoint_index").get<json::Number>().value;
|
|
|
|
const auto &route_legs = matchings[matchings_index]
|
|
|
|
.get<json::Object>()
|
|
|
|
.values.at("legs")
|
|
|
|
.get<json::Array>()
|
|
|
|
.values;
|
|
|
|
BOOST_CHECK_LT(waypoint_index, route_legs.size() + 1);
|
|
|
|
BOOST_CHECK_LT(matchings_index, number_of_matchings);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BOOST_CHECK(waypoint.is<json::Null>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-27 12:14:44 -05:00
|
|
|
BOOST_AUTO_TEST_CASE(test_match_new_api) { test_match(false); }
|
|
|
|
BOOST_AUTO_TEST_CASE(test_match_old_api) { test_match(true); }
|
2018-01-15 12:38:14 -05:00
|
|
|
|
2021-01-27 12:14:44 -05:00
|
|
|
void test_match_skip_waypoints(bool use_json_only_api)
|
2019-09-16 10:07:45 -04:00
|
|
|
{
|
|
|
|
using namespace osrm;
|
|
|
|
|
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
|
|
|
|
|
|
|
MatchParameters params;
|
|
|
|
params.skip_waypoints = true;
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
|
2021-01-27 12:14:44 -05:00
|
|
|
json::Object json_result;
|
|
|
|
const auto rc = run_match_json(osrm, params, json_result, use_json_only_api);
|
2019-09-16 10:07:45 -04:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
2021-01-27 12:14:44 -05:00
|
|
|
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); }
|
2019-09-16 10:07:45 -04:00
|
|
|
|
2021-01-27 12:14:44 -05:00
|
|
|
void test_match_split(bool use_json_only_api)
|
2018-01-15 12:38:14 -05:00
|
|
|
{
|
|
|
|
using namespace osrm;
|
|
|
|
|
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
|
|
|
|
|
|
|
MatchParameters params;
|
|
|
|
params.coordinates = get_split_trace_locations();
|
2018-01-19 05:22:23 -05:00
|
|
|
params.timestamps = {1, 2, 1700, 1800};
|
2018-01-15 12:38:14 -05:00
|
|
|
|
2021-01-27 12:14:44 -05:00
|
|
|
json::Object json_result;
|
|
|
|
const auto rc = run_match_json(osrm, params, json_result, use_json_only_api);
|
2018-01-15 12:38:14 -05:00
|
|
|
|
|
|
|
BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
|
2019-08-13 04:17:15 -04:00
|
|
|
const auto code = json_result.values.at("code").get<json::String>().value;
|
2018-01-15 12:38:14 -05:00
|
|
|
BOOST_CHECK_EQUAL(code, "Ok");
|
|
|
|
|
2019-08-13 04:17:15 -04:00
|
|
|
const auto &tracepoints = json_result.values.at("tracepoints").get<json::Array>().values;
|
2018-01-15 12:38:14 -05:00
|
|
|
BOOST_CHECK_EQUAL(tracepoints.size(), params.coordinates.size());
|
|
|
|
|
2019-08-13 04:17:15 -04:00
|
|
|
const auto &matchings = json_result.values.at("matchings").get<json::Array>().values;
|
2018-01-15 12:38:14 -05:00
|
|
|
const auto &number_of_matchings = matchings.size();
|
|
|
|
BOOST_CHECK_EQUAL(number_of_matchings, 2);
|
2018-01-19 05:22:23 -05:00
|
|
|
std::size_t current_matchings_index = 0, expected_waypoint_index = 0;
|
2018-01-15 12:38:14 -05:00
|
|
|
for (const auto &waypoint : tracepoints)
|
|
|
|
{
|
|
|
|
if (waypoint.is<mapbox::util::recursive_wrapper<util::json::Object>>())
|
2016-04-01 18:39:45 -04:00
|
|
|
{
|
2016-04-13 17:07:24 -04:00
|
|
|
BOOST_CHECK(waypoint_check(waypoint));
|
2016-04-01 18:39:45 -04:00
|
|
|
const auto &waypoint_object = waypoint.get<json::Object>();
|
2016-05-27 15:05:04 -04:00
|
|
|
const auto matchings_index =
|
|
|
|
waypoint_object.values.at("matchings_index").get<json::Number>().value;
|
|
|
|
const auto waypoint_index =
|
|
|
|
waypoint_object.values.at("waypoint_index").get<json::Number>().value;
|
2018-01-19 05:22:23 -05:00
|
|
|
|
2016-04-06 15:54:00 -04:00
|
|
|
BOOST_CHECK_LT(matchings_index, number_of_matchings);
|
2018-01-19 05:22:23 -05:00
|
|
|
|
|
|
|
expected_waypoint_index =
|
|
|
|
(current_matchings_index != matchings_index) ? 0 : expected_waypoint_index;
|
|
|
|
BOOST_CHECK_EQUAL(waypoint_index, expected_waypoint_index);
|
|
|
|
|
|
|
|
current_matchings_index = matchings_index;
|
|
|
|
++expected_waypoint_index;
|
2016-05-27 15:05:04 -04:00
|
|
|
}
|
|
|
|
else
|
2016-04-01 18:39:45 -04:00
|
|
|
{
|
2016-05-27 15:05:04 -04:00
|
|
|
BOOST_CHECK(waypoint.is<json::Null>());
|
2016-04-01 18:39:45 -04:00
|
|
|
}
|
|
|
|
}
|
2016-03-16 07:42:26 -04:00
|
|
|
}
|
2021-01-27 12:14:44 -05:00
|
|
|
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); }
|
2016-03-16 06:58:39 -04:00
|
|
|
|
2019-09-16 09:39:09 -04:00
|
|
|
BOOST_AUTO_TEST_CASE(test_match_fb_serialization)
|
|
|
|
{
|
|
|
|
using namespace osrm;
|
|
|
|
|
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
|
|
|
|
|
|
|
MatchParameters params;
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
|
|
|
|
engine::api::ResultT result = flatbuffers::FlatBufferBuilder();
|
|
|
|
|
|
|
|
const auto rc = osrm.Match(params, result);
|
|
|
|
BOOST_CHECK(rc == Status::Ok);
|
|
|
|
|
|
|
|
auto &fb_result = result.get<flatbuffers::FlatBufferBuilder>();
|
|
|
|
auto fb = engine::api::fbresult::GetFBResult(fb_result.GetBufferPointer());
|
|
|
|
|
|
|
|
BOOST_CHECK(!fb->error());
|
|
|
|
|
|
|
|
BOOST_CHECK(fb->waypoints() != nullptr);
|
|
|
|
const auto waypoints = fb->waypoints();
|
|
|
|
BOOST_CHECK(waypoints->size() == params.coordinates.size());
|
|
|
|
|
|
|
|
BOOST_CHECK(fb->routes() != nullptr);
|
|
|
|
const auto matchings = fb->routes();
|
|
|
|
const auto &number_of_matchings = matchings->size();
|
|
|
|
|
2021-06-24 13:59:15 -04:00
|
|
|
for (const auto waypoint : *waypoints)
|
2019-09-16 09:39:09 -04:00
|
|
|
{
|
|
|
|
BOOST_CHECK(waypoint_check(waypoint));
|
|
|
|
const auto matchings_index = waypoint->matchings_index();
|
|
|
|
const auto waypoint_index = waypoint->waypoint_index();
|
|
|
|
const auto &route_legs = matchings->operator[](matchings_index)->legs();
|
|
|
|
|
|
|
|
BOOST_CHECK_LT(waypoint_index, route_legs->size() + 1);
|
|
|
|
BOOST_CHECK_LT(matchings_index, number_of_matchings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 10:07:45 -04:00
|
|
|
BOOST_AUTO_TEST_CASE(test_match_fb_serialization_skip_waypoints)
|
|
|
|
{
|
|
|
|
using namespace osrm;
|
|
|
|
|
|
|
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
|
|
|
|
|
|
|
MatchParameters params;
|
|
|
|
params.skip_waypoints = true;
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
params.coordinates.push_back(get_dummy_location());
|
|
|
|
|
|
|
|
engine::api::ResultT result = flatbuffers::FlatBufferBuilder();
|
|
|
|
|
|
|
|
const auto rc = osrm.Match(params, result);
|
|
|
|
BOOST_CHECK(rc == Status::Ok);
|
|
|
|
|
|
|
|
auto &fb_result = result.get<flatbuffers::FlatBufferBuilder>();
|
|
|
|
auto fb = engine::api::fbresult::GetFBResult(fb_result.GetBufferPointer());
|
|
|
|
|
|
|
|
BOOST_CHECK(!fb->error());
|
|
|
|
|
|
|
|
BOOST_CHECK(fb->waypoints() == nullptr);
|
|
|
|
}
|
|
|
|
|
2016-03-16 06:58:39 -04:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|