Added unit test for flatbuffers serialization of Match/Trip responses.
This commit is contained in:
parent
a5127539eb
commit
a9d4e28e38
@ -118,4 +118,45 @@ BOOST_AUTO_TEST_CASE(test_match_split)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
for (const auto &waypoint : *waypoints)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "coordinates.hpp"
|
#include "coordinates.hpp"
|
||||||
#include "fixture.hpp"
|
#include "fixture.hpp"
|
||||||
|
|
||||||
|
#include <engine/api/flatbuffers/fbresult_generated.h>
|
||||||
#include "osrm/trip_parameters.hpp"
|
#include "osrm/trip_parameters.hpp"
|
||||||
|
|
||||||
#include "osrm/coordinate.hpp"
|
#include "osrm/coordinate.hpp"
|
||||||
@ -422,4 +423,47 @@ BOOST_AUTO_TEST_CASE(test_tfse_legal_parameters)
|
|||||||
CheckOk(osrm, params);
|
CheckOk(osrm, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test_roundtrip_response_fb_serialization)
|
||||||
|
{
|
||||||
|
using namespace osrm;
|
||||||
|
|
||||||
|
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
|
||||||
|
const auto locations = get_locations_in_small_component();
|
||||||
|
|
||||||
|
TripParameters params;
|
||||||
|
params.coordinates.push_back(locations.at(0));
|
||||||
|
params.coordinates.push_back(locations.at(1));
|
||||||
|
params.coordinates.push_back(locations.at(2));
|
||||||
|
|
||||||
|
engine::api::ResultT result = flatbuffers::FlatBufferBuilder();
|
||||||
|
const auto rc = osrm.Trip(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 trips = fb->routes();
|
||||||
|
BOOST_CHECK_EQUAL(trips->size(), 1);
|
||||||
|
|
||||||
|
for (const auto &waypoint : *waypoints)
|
||||||
|
{
|
||||||
|
const auto longitude = waypoint->location()->longitude();
|
||||||
|
const auto latitude = waypoint->location()->latitude();
|
||||||
|
BOOST_CHECK(longitude >= -180. && longitude <= 180.);
|
||||||
|
BOOST_CHECK(latitude >= -90. && latitude <= 90.);
|
||||||
|
|
||||||
|
const auto trip = waypoint->trips_index();
|
||||||
|
const auto pos = waypoint->waypoint_index();
|
||||||
|
BOOST_CHECK(trip < trips->size());
|
||||||
|
BOOST_CHECK(pos < waypoints->size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
Loading…
Reference in New Issue
Block a user