Skip to content

Commit a2ff69c

Browse files
committed
Check bearings, radiuses size in TablePlugin
1 parent aa1f97d commit a2ff69c

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

features/car/startpoint.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Feature: Car - Allowed start/end modes
7070
Given the query options
7171
| snapping | any |
7272
| bearings | 90,180; |
73+
| radiuses | unlimited; |
7374

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

116118
And the ways
117119
| nodes | highway | access |

src/engine/plugins/table.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
4242
return Error(
4343
"InvalidOptions", "Number of bearings does not match number of coordinates", result);
4444
}
45+
46+
if (!params.bearings.empty() && params.radiuses.size() != params.bearings.size())
47+
{
48+
return Error(
49+
"InvalidOptions", "Number of radiuses does not match number of bearings", result);
50+
}
4551

4652
// Empty sources or destinations means the user wants all of them included, respectively
4753
// The ManyToMany routing algorithm we dispatch to below already handles this perfectly.

unit_tests/library/table.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,4 +387,34 @@ BOOST_AUTO_TEST_CASE(test_table_serialiaze_fb_no_waypoints)
387387
BOOST_CHECK(fb->waypoints() == nullptr);
388388
}
389389

390+
void test_table_bearings_without_radius(bool use_json_only_api)
391+
{
392+
using namespace osrm;
393+
394+
auto osrm = getOSRM(OSRM_TEST_DATA_DIR "/ch/monaco.osrm");
395+
396+
TableParameters params;
397+
params.coordinates.push_back(get_dummy_location());
398+
params.coordinates.push_back(get_dummy_location());
399+
params.bearings.push_back(engine::Bearing{100, 100});
400+
params.bearings.push_back(engine::Bearing{100, 100});
401+
402+
json::Object json_result;
403+
const auto rc = run_table_json(osrm, params, json_result, use_json_only_api);
404+
405+
BOOST_CHECK(rc == Status::Error);
406+
const auto code = json_result.values.at("code").get<json::String>().value;
407+
BOOST_CHECK_EQUAL(code, "InvalidOptions");
408+
const auto message = json_result.values.at("message").get<json::String>().value;
409+
BOOST_CHECK_EQUAL(message, "Number of radiuses does not match number of bearings");
410+
}
411+
BOOST_AUTO_TEST_CASE(test_table_bearings_without_radius_old_api)
412+
{
413+
test_table_bearings_without_radius(true);
414+
}
415+
BOOST_AUTO_TEST_CASE(test_table_bearings_without_radius_new_api)
416+
{
417+
test_table_bearings_without_radius(false);
418+
}
419+
390420
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)