2016-03-16 06:58:39 -04:00
|
|
|
#include <boost/test/test_case_template.hpp>
|
2016-05-27 15:05:04 -04:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2016-03-16 06:58:39 -04:00
|
|
|
|
2016-03-16 09:53:14 -04:00
|
|
|
#include "args.hpp"
|
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/engine_config.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
|
|
|
|
2016-03-16 06:58:39 -04:00
|
|
|
BOOST_AUTO_TEST_SUITE(match)
|
|
|
|
|
2016-03-16 07:42:26 -04:00
|
|
|
BOOST_AUTO_TEST_CASE(test_match)
|
|
|
|
{
|
|
|
|
const auto args = get_args();
|
|
|
|
BOOST_REQUIRE_EQUAL(args.size(), 1);
|
|
|
|
|
|
|
|
using namespace osrm;
|
|
|
|
|
2016-03-24 12:45:14 -04:00
|
|
|
auto osrm = getOSRM(args[0]);
|
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
|
|
|
|
|
|
|
json::Object result;
|
|
|
|
|
|
|
|
const auto rc = osrm.Match(params, result);
|
|
|
|
|
|
|
|
BOOST_CHECK(rc == Status::Ok || rc == Status::Error);
|
2016-04-01 18:39:45 -04:00
|
|
|
const auto code = result.values.at("code").get<json::String>().value;
|
|
|
|
BOOST_CHECK_EQUAL(code, "Ok");
|
|
|
|
|
|
|
|
const auto &tracepoints = result.values.at("tracepoints").get<json::Array>().values;
|
|
|
|
BOOST_CHECK_EQUAL(tracepoints.size(), params.coordinates.size());
|
|
|
|
|
2016-04-06 15:54:00 -04:00
|
|
|
const auto &matchings = result.values.at("matchings").get<json::Array>().values;
|
|
|
|
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>>())
|
|
|
|
{
|
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;
|
|
|
|
const auto &route_legs = matchings[matchings_index]
|
|
|
|
.get<json::Object>()
|
|
|
|
.values.at("legs")
|
|
|
|
.get<json::Array>()
|
|
|
|
.values;
|
2016-04-06 15:54:00 -04:00
|
|
|
BOOST_CHECK_LT(waypoint_index, route_legs.size() + 1);
|
|
|
|
BOOST_CHECK_LT(matchings_index, number_of_matchings);
|
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
|
|
|
}
|
2016-03-16 06:58:39 -04:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|