Check bearings, radiuses size in TablePlugin

This commit is contained in:
whytro 2023-03-11 14:39:11 +09:00
parent aa1f97d25b
commit a2ff69c3aa
3 changed files with 38 additions and 0 deletions

View File

@ -70,6 +70,7 @@ Feature: Car - Allowed start/end modes
Given the query options
| snapping | any |
| bearings | 90,180; |
| radiuses | unlimited; |
And the ways
| nodes | highway | access |
@ -112,6 +113,7 @@ Feature: Car - Allowed start/end modes
Given the query options
| snapping | any |
| bearings | 90,180;0,180;; |
| radiuses | unlimited;;; |
And the ways
| nodes | highway | access |

View File

@ -42,6 +42,12 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
return Error(
"InvalidOptions", "Number of bearings does not match number of coordinates", result);
}
if (!params.bearings.empty() && params.radiuses.size() != params.bearings.size())
{
return Error(
"InvalidOptions", "Number of radiuses does not match number of bearings", result);
}
// Empty sources or destinations means the user wants all of them included, respectively
// The ManyToMany routing algorithm we dispatch to below already handles this perfectly.

View File

@ -387,4 +387,34 @@ BOOST_AUTO_TEST_CASE(test_table_serialiaze_fb_no_waypoints)
BOOST_CHECK(fb->waypoints() == nullptr);
}
void test_table_bearings_without_radius(bool use_json_only_api)
{
using namespace osrm;
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
TableParameters params;
params.coordinates.push_back(get_dummy_location());
params.coordinates.push_back(get_dummy_location());
params.bearings.push_back(engine::Bearing{100, 100});
params.bearings.push_back(engine::Bearing{100, 100});
json::Object json_result;
const auto rc = run_table_json(osrm, params, json_result, use_json_only_api);
BOOST_CHECK(rc == Status::Error);
const auto code = json_result.values.at("code").get<json::String>().value;
BOOST_CHECK_EQUAL(code, "InvalidOptions");
const auto message = json_result.values.at("message").get<json::String>().value;
BOOST_CHECK_EQUAL(message, "Number of radiuses does not match number of bearings");
}
BOOST_AUTO_TEST_CASE(test_table_bearings_without_radius_old_api)
{
test_table_bearings_without_radius(true);
}
BOOST_AUTO_TEST_CASE(test_table_bearings_without_radius_new_api)
{
test_table_bearings_without_radius(false);
}
BOOST_AUTO_TEST_SUITE_END()