From a44a75b211b7b94f99be8d606ef794509989fca1 Mon Sep 17 00:00:00 2001 From: Denis Chaplygin Date: Tue, 13 Aug 2019 11:17:15 +0300 Subject: [PATCH] Unit tests are compatible with new plugin API. --- src/benchmarks/match.cpp | 5 +-- unit_tests/library/limits.cpp | 30 +++++++++++------- unit_tests/library/match.cpp | 18 ++++++----- unit_tests/library/nearest.cpp | 24 ++++++++------ unit_tests/library/route.cpp | 54 ++++++++++++++++++-------------- unit_tests/library/table.cpp | 40 +++++++++++++----------- unit_tests/library/tile.cpp | 29 ++++++++++------- unit_tests/library/trip.cpp | 57 ++++++++++++++++++++-------------- 8 files changed, 148 insertions(+), 109 deletions(-) diff --git a/src/benchmarks/match.cpp b/src/benchmarks/match.cpp index 788ab2f0b..91d96b016 100644 --- a/src/benchmarks/match.cpp +++ b/src/benchmarks/match.cpp @@ -214,9 +214,10 @@ int main(int argc, const char *argv[]) try auto NUM = 100; for (int i = 0; i < NUM; ++i) { - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Match(params, result); - if (rc != Status::Ok || result.values.at("matchings").get().values.size() != 1) + auto& json_result=result.get(); + if (rc != Status::Ok || json_result.values.at("matchings").get().values.size() != 1) { return EXIT_FAILURE; } diff --git a/unit_tests/library/limits.cpp b/unit_tests/library/limits.cpp index a48a7f983..5b1816638 100644 --- a/unit_tests/library/limits.cpp +++ b/unit_tests/library/limits.cpp @@ -39,14 +39,15 @@ BOOST_AUTO_TEST_CASE(test_trip_limits) params.coordinates.emplace_back(getZeroCoordinate()); params.coordinates.emplace_back(getZeroCoordinate()); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Trip(params, result); BOOST_CHECK(rc == Status::Error); // Make sure we're not accidentally hitting a guard code path before - const auto code = result.values["code"].get().value; + auto& json_result=result.get(); + const auto code = json_result.values["code"].get().value; BOOST_CHECK(code == "TooBig"); // per the New-Server API spec } @@ -66,14 +67,15 @@ BOOST_AUTO_TEST_CASE(test_route_limits) params.coordinates.emplace_back(getZeroCoordinate()); params.coordinates.emplace_back(getZeroCoordinate()); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Route(params, result); BOOST_CHECK(rc == Status::Error); // Make sure we're not accidentally hitting a guard code path before - const auto code = result.values["code"].get().value; + auto& json_result=result.get(); + const auto code = json_result.values["code"].get().value; BOOST_CHECK(code == "TooBig"); // per the New-Server API spec } @@ -93,14 +95,15 @@ BOOST_AUTO_TEST_CASE(test_table_limits) params.coordinates.emplace_back(getZeroCoordinate()); params.coordinates.emplace_back(getZeroCoordinate()); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Table(params, result); BOOST_CHECK(rc == Status::Error); // Make sure we're not accidentally hitting a guard code path before - const auto code = result.values["code"].get().value; + auto& json_result=result.get(); + const auto code = json_result.values["code"].get().value; BOOST_CHECK(code == "TooBig"); // per the New-Server API spec } @@ -120,14 +123,15 @@ BOOST_AUTO_TEST_CASE(test_match_coordinate_limits) params.coordinates.emplace_back(getZeroCoordinate()); params.coordinates.emplace_back(getZeroCoordinate()); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Match(params, result); BOOST_CHECK(rc == Status::Error); // Make sure we're not accidentally hitting a guard code path before - const auto code = result.values["code"].get().value; + auto& json_result=result.get(); + const auto code = json_result.values["code"].get().value; BOOST_CHECK(code == "TooBig"); // per the New-Server API spec } @@ -152,14 +156,15 @@ BOOST_AUTO_TEST_CASE(test_match_radiuses_limits) params.radiuses.emplace_back(3.0); params.radiuses.emplace_back(2.0); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Match(params, result); BOOST_CHECK(rc == Status::Error); // Make sure we're not accidentally hitting a guard code path before - const auto code = result.values["code"].get().value; + auto& json_result=result.get(); + const auto code = json_result.values["code"].get().value; BOOST_CHECK(code == "TooBig"); // per the New-Server API spec } @@ -178,14 +183,15 @@ BOOST_AUTO_TEST_CASE(test_nearest_limits) params.coordinates.emplace_back(getZeroCoordinate()); params.number_of_results = 10000; - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Nearest(params, result); BOOST_CHECK(rc == Status::Error); // Make sure we're not accidentally hitting a guard code path before - const auto code = result.values["code"].get().value; + auto& json_result=result.get(); + const auto code = json_result.values["code"].get().value; BOOST_CHECK(code == "TooBig"); // per the New-Server API spec } diff --git a/unit_tests/library/match.cpp b/unit_tests/library/match.cpp index 1a398b3c2..b98947245 100644 --- a/unit_tests/library/match.cpp +++ b/unit_tests/library/match.cpp @@ -26,18 +26,19 @@ BOOST_AUTO_TEST_CASE(test_match) params.coordinates.push_back(get_dummy_location()); params.coordinates.push_back(get_dummy_location()); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Match(params, result); + auto& json_result=result.get(); BOOST_CHECK(rc == Status::Ok || rc == Status::Error); - const auto code = result.values.at("code").get().value; + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); - const auto &tracepoints = result.values.at("tracepoints").get().values; + const auto &tracepoints = json_result.values.at("tracepoints").get().values; BOOST_CHECK_EQUAL(tracepoints.size(), params.coordinates.size()); - const auto &matchings = result.values.at("matchings").get().values; + const auto &matchings = json_result.values.at("matchings").get().values; const auto &number_of_matchings = matchings.size(); for (const auto &waypoint : tracepoints) { @@ -74,18 +75,19 @@ BOOST_AUTO_TEST_CASE(test_match_split) params.coordinates = get_split_trace_locations(); params.timestamps = {1, 2, 1700, 1800}; - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Match(params, result); + auto& json_result=result.get(); BOOST_CHECK(rc == Status::Ok || rc == Status::Error); - const auto code = result.values.at("code").get().value; + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); - const auto &tracepoints = result.values.at("tracepoints").get().values; + const auto &tracepoints = json_result.values.at("tracepoints").get().values; BOOST_CHECK_EQUAL(tracepoints.size(), params.coordinates.size()); - const auto &matchings = result.values.at("matchings").get().values; + const auto &matchings = json_result.values.at("matchings").get().values; const auto &number_of_matchings = matchings.size(); BOOST_CHECK_EQUAL(number_of_matchings, 2); std::size_t current_matchings_index = 0, expected_waypoint_index = 0; diff --git a/unit_tests/library/nearest.cpp b/unit_tests/library/nearest.cpp index 013ece216..4fd6451a1 100644 --- a/unit_tests/library/nearest.cpp +++ b/unit_tests/library/nearest.cpp @@ -23,14 +23,15 @@ BOOST_AUTO_TEST_CASE(test_nearest_response) NearestParameters params; params.coordinates.push_back(get_dummy_location()); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Nearest(params, result); BOOST_REQUIRE(rc == Status::Ok); - const auto code = result.values.at("code").get().value; + auto& json_result=result.get(); + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); - const auto &waypoints = result.values.at("waypoints").get().values; + const auto &waypoints = json_result.values.at("waypoints").get().values; BOOST_CHECK(!waypoints.empty()); // the dataset has at least one nearest coordinate for (const auto &waypoint : waypoints) @@ -49,11 +50,12 @@ BOOST_AUTO_TEST_CASE(test_nearest_response_no_coordinates) NearestParameters params; - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Nearest(params, result); BOOST_REQUIRE(rc == Status::Error); - const auto code = result.values.at("code").get().value; + auto& json_result=result.get(); + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "InvalidOptions"); } @@ -67,11 +69,12 @@ BOOST_AUTO_TEST_CASE(test_nearest_response_multiple_coordinates) params.coordinates.push_back(get_dummy_location()); params.coordinates.push_back(get_dummy_location()); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Nearest(params, result); BOOST_REQUIRE(rc == Status::Error); - const auto code = result.values.at("code").get().value; + auto& json_result=result.get(); + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "InvalidOptions"); } @@ -87,14 +90,15 @@ BOOST_AUTO_TEST_CASE(test_nearest_response_for_location_in_small_component) params.coordinates.push_back(locations.at(0)); params.number_of_results = 3; - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Nearest(params, result); BOOST_REQUIRE(rc == Status::Ok); - const auto code = result.values.at("code").get().value; + auto& json_result=result.get(); + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); - const auto &waypoints = result.values.at("waypoints").get().values; + const auto &waypoints = json_result.values.at("waypoints").get().values; BOOST_CHECK(!waypoints.empty()); for (const auto &waypoint : waypoints) diff --git a/unit_tests/library/route.cpp b/unit_tests/library/route.cpp index 6a6faad96..f61bcbc9d 100644 --- a/unit_tests/library/route.cpp +++ b/unit_tests/library/route.cpp @@ -28,12 +28,13 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates_fixture) params.coordinates.push_back(get_dummy_location()); params.coordinates.push_back(get_dummy_location()); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Route(params, result); BOOST_CHECK(rc == Status::Ok); + auto& json_result=result.get(); // unset snapping dependent hint - for (auto &itr : result.values["waypoints"].get().values) + for (auto &itr : json_result.values["waypoints"].get().values) { // Hint values aren't stable, so blank it out itr.get().values["hint"] = ""; @@ -112,7 +113,7 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates_fixture) }}}}}}}}}}}}}}}}}; - CHECK_EQUAL_JSON(reference, result); + CHECK_EQUAL_JSON(reference, json_result); } BOOST_AUTO_TEST_CASE(test_route_same_coordinates) @@ -127,14 +128,15 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates) params.coordinates.push_back(get_dummy_location()); params.coordinates.push_back(get_dummy_location()); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Route(params, result); BOOST_CHECK(rc == Status::Ok); - const auto code = result.values.at("code").get().value; + auto& json_result=result.get(); + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); - const auto &waypoints = result.values.at("waypoints").get().values; + const auto &waypoints = json_result.values.at("waypoints").get().values; BOOST_CHECK(waypoints.size() == params.coordinates.size()); for (const auto &waypoint : waypoints) @@ -155,7 +157,7 @@ BOOST_AUTO_TEST_CASE(test_route_same_coordinates) BOOST_CHECK(!hint.empty()); } - const auto &routes = result.values.at("routes").get().values; + const auto &routes = json_result.values.at("routes").get().values; BOOST_REQUIRE_GT(routes.size(), 0); for (const auto &route : routes) @@ -280,14 +282,15 @@ BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_small_component) params.coordinates.push_back(locations.at(1)); params.coordinates.push_back(locations.at(2)); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Route(params, result); BOOST_CHECK(rc == Status::Ok); - const auto code = result.values.at("code").get().value; + auto& json_result=result.get(); + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); - const auto &waypoints = result.values.at("waypoints").get().values; + const auto &waypoints = json_result.values.at("waypoints").get().values; BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); for (const auto &waypoint : waypoints) @@ -315,14 +318,15 @@ BOOST_AUTO_TEST_CASE(test_route_response_for_locations_in_big_component) params.coordinates.push_back(locations.at(1)); params.coordinates.push_back(locations.at(2)); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Route(params, result); BOOST_CHECK(rc == Status::Ok); - const auto code = result.values.at("code").get().value; + auto& json_result=result.get(); + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); - const auto &waypoints = result.values.at("waypoints").get().values; + const auto &waypoints = json_result.values.at("waypoints").get().values; BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); for (const auto &waypoint : waypoints) @@ -352,14 +356,15 @@ BOOST_AUTO_TEST_CASE(test_route_response_for_locations_across_components) params.coordinates.push_back(small_component.at(1)); params.coordinates.push_back(big_component.at(1)); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Route(params, result); BOOST_CHECK(rc == Status::Ok); - const auto code = result.values.at("code").get().value; + auto& json_result=result.get(); + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); - const auto &waypoints = result.values.at("waypoints").get().values; + const auto &waypoints = json_result.values.at("waypoints").get().values; BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); for (const auto &waypoint : waypoints) @@ -386,11 +391,12 @@ BOOST_AUTO_TEST_CASE(test_route_user_disables_generating_hints) params.coordinates.push_back(get_dummy_location()); params.generate_hints = false; - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Route(params, result); BOOST_CHECK(rc == Status::Ok); - for (auto waypoint : result.values["waypoints"].get().values) + auto& json_result=result.get(); + for (auto waypoint : json_result.values["waypoints"].get().values) BOOST_CHECK_EQUAL(waypoint.get().values.count("hint"), 0); } @@ -407,11 +413,12 @@ BOOST_AUTO_TEST_CASE(speed_annotation_matches_duration_and_distance) params.coordinates.push_back(get_dummy_location()); params.coordinates.push_back(get_dummy_location()); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Route(params, result); BOOST_CHECK(rc == Status::Ok); - const auto &routes = result.values["routes"].get().values; + auto& json_result=result.get(); + const auto &routes = json_result.values["routes"].get().values; const auto &legs = routes[0].get().values.at("legs").get().values; const auto &annotation = legs[0].get().values.at("annotation").get(); @@ -447,14 +454,15 @@ BOOST_AUTO_TEST_CASE(test_manual_setting_of_annotations_property) params.coordinates.push_back(get_dummy_location()); params.coordinates.push_back(get_dummy_location()); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Route(params, result); BOOST_CHECK(rc == Status::Ok); - const auto code = result.values.at("code").get().value; + auto& json_result=result.get(); + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); - auto annotations = result.values["routes"] + auto annotations = json_result.values["routes"] .get() .values[0] .get() diff --git a/unit_tests/library/table.cpp b/unit_tests/library/table.cpp index f0b7528ae..fba6c5394 100644 --- a/unit_tests/library/table.cpp +++ b/unit_tests/library/table.cpp @@ -29,17 +29,18 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix) params.destinations.push_back(2); params.annotations = TableParameters::AnnotationsType::All; - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Table(params, result); + auto& json_result=result.get(); BOOST_CHECK(rc == Status::Ok || rc == Status::Error); - const auto code = result.values.at("code").get().value; + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); // check that returned durations error is expected size and proportions // this test expects a 1x1 matrix - const auto &durations_array = result.values.at("durations").get().values; + const auto &durations_array = json_result.values.at("durations").get().values; BOOST_CHECK_EQUAL(durations_array.size(), params.sources.size()); for (unsigned int i = 0; i < durations_array.size(); i++) { @@ -50,7 +51,7 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix) // check that returned distances error is expected size and proportions // this test expects a 1x1 matrix - const auto &distances_array = result.values.at("distances").get().values; + const auto &distances_array = json_result.values.at("distances").get().values; BOOST_CHECK_EQUAL(distances_array.size(), params.sources.size()); for (unsigned int i = 0; i < distances_array.size(); i++) { @@ -60,14 +61,14 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_one_dest_matrix) } // check destinations array of waypoint objects - const auto &destinations_array = result.values.at("destinations").get().values; + const auto &destinations_array = json_result.values.at("destinations").get().values; BOOST_CHECK_EQUAL(destinations_array.size(), params.destinations.size()); for (const auto &destination : destinations_array) { BOOST_CHECK(waypoint_check(destination)); } // check sources array of waypoint objects - const auto &sources_array = result.values.at("sources").get().values; + const auto &sources_array = json_result.values.at("sources").get().values; BOOST_CHECK_EQUAL(sources_array.size(), params.sources.size()); for (const auto &source : sources_array) { @@ -86,17 +87,18 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_matrix) params.coordinates.push_back(get_dummy_location()); params.coordinates.push_back(get_dummy_location()); params.sources.push_back(0); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Table(params, result); + auto& json_result=result.get(); BOOST_CHECK(rc == Status::Ok || rc == Status::Error); - const auto code = result.values.at("code").get().value; + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); // check that returned durations error is expected size and proportions // this test expects a 1x3 matrix - const auto &durations_array = result.values.at("durations").get().values; + const auto &durations_array = json_result.values.at("durations").get().values; BOOST_CHECK_EQUAL(durations_array.size(), params.sources.size()); for (unsigned int i = 0; i < durations_array.size(); i++) { @@ -106,14 +108,14 @@ BOOST_AUTO_TEST_CASE(test_table_three_coords_one_source_matrix) params.sources.size() * params.coordinates.size()); } // check destinations array of waypoint objects - const auto &destinations_array = result.values.at("destinations").get().values; + const auto &destinations_array = json_result.values.at("destinations").get().values; BOOST_CHECK_EQUAL(destinations_array.size(), params.coordinates.size()); for (const auto &destination : destinations_array) { BOOST_CHECK(waypoint_check(destination)); } // check sources array of waypoint objects - const auto &sources_array = result.values.at("sources").get().values; + const auto &sources_array = json_result.values.at("sources").get().values; BOOST_CHECK_EQUAL(sources_array.size(), params.sources.size()); for (const auto &source : sources_array) { @@ -133,17 +135,18 @@ BOOST_AUTO_TEST_CASE(test_table_three_coordinates_matrix) params.coordinates.push_back(get_dummy_location()); params.annotations = TableParameters::AnnotationsType::Duration; - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Table(params, result); + auto& json_result=result.get(); BOOST_CHECK(rc == Status::Ok || rc == Status::Error); - const auto code = result.values.at("code").get().value; + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); // check that returned durations error is expected size and proportions // this test expects a 3x3 matrix - const auto &durations_array = result.values.at("durations").get().values; + const auto &durations_array = json_result.values.at("durations").get().values; BOOST_CHECK_EQUAL(durations_array.size(), params.coordinates.size()); for (unsigned int i = 0; i < durations_array.size(); i++) { @@ -151,12 +154,12 @@ BOOST_AUTO_TEST_CASE(test_table_three_coordinates_matrix) BOOST_CHECK_EQUAL(durations_matrix[i].get().value, 0); BOOST_CHECK_EQUAL(durations_matrix.size(), params.coordinates.size()); } - const auto &destinations_array = result.values.at("destinations").get().values; + const auto &destinations_array = json_result.values.at("destinations").get().values; for (const auto &destination : destinations_array) { BOOST_CHECK(waypoint_check(destination)); } - const auto &sources_array = result.values.at("sources").get().values; + const auto &sources_array = json_result.values.at("sources").get().values; BOOST_CHECK_EQUAL(sources_array.size(), params.coordinates.size()); for (const auto &source : sources_array) { @@ -178,12 +181,13 @@ BOOST_AUTO_TEST_CASE(test_table_no_segment_for_some_coordinates) params.radiuses.push_back(boost::make_optional(0.)); params.radiuses.push_back(boost::none); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Table(params, result); + auto& json_result=result.get(); BOOST_CHECK(rc == Status::Error); - const auto code = result.values.at("code").get().value; + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "NoSegment"); } diff --git a/unit_tests/library/tile.cpp b/unit_tests/library/tile.cpp index 39bb26b02..1e9195bd2 100644 --- a/unit_tests/library/tile.cpp +++ b/unit_tests/library/tile.cpp @@ -161,13 +161,15 @@ void validate_tile(const osrm::OSRM &osrm) // This tile should contain most of monaco TileParameters params{17059, 11948, 15}; - std::string result; + engine::api::ResultT result = std::string(); + const auto rc = osrm.Tile(params, result); BOOST_CHECK(rc == Status::Ok); - BOOST_CHECK(result.size() > 114000); + auto& str_result = result.get(); + BOOST_CHECK(str_result.size() > 114000); - vtzero::vector_tile tile{result}; + vtzero::vector_tile tile{str_result}; validate_feature_layer(tile.next_layer()); validate_turn_layer(tile.next_layer()); @@ -206,13 +208,14 @@ void test_tile_turns(const osrm::OSRM &osrm) // Small tile where we can test all the values TileParameters params{272953, 191177, 19}; - std::string result; + engine::api::ResultT result = std::string(); const auto rc = osrm.Tile(params, result); BOOST_CHECK(rc == Status::Ok); - BOOST_CHECK_GT(result.size(), 128); + auto& str_result = result.get(); + BOOST_CHECK_GT(str_result.size(), 128); - vtzero::vector_tile tile{result}; + vtzero::vector_tile tile{str_result}; tile.next_layer(); auto layer = tile.next_layer(); @@ -347,13 +350,14 @@ void test_tile_speeds(const osrm::OSRM &osrm) // TileParameters params{272953, 191177, 19}; TileParameters params{136477, 95580, 18}; - std::string result; + engine::api::ResultT result = std::string(); const auto rc = osrm.Tile(params, result); BOOST_CHECK(rc == Status::Ok); - BOOST_CHECK_GT(result.size(), 128); + auto& str_result = result.get(); + BOOST_CHECK_GT(str_result.size(), 128); - vtzero::vector_tile tile{result}; + vtzero::vector_tile tile{str_result}; auto layer = tile.next_layer(); BOOST_CHECK_EQUAL(to_string(layer.name()), "speeds"); @@ -427,13 +431,14 @@ void test_tile_nodes(const osrm::OSRM &osrm) // Small tile where we can test all the values TileParameters params{272953, 191177, 19}; - std::string result; + engine::api::ResultT result = std::string(); const auto rc = osrm.Tile(params, result); BOOST_CHECK(rc == Status::Ok); - BOOST_CHECK_GT(result.size(), 128); + auto& str_result = result.get(); + BOOST_CHECK_GT(str_result.size(), 128); - vtzero::vector_tile tile{result}; + vtzero::vector_tile tile{str_result}; tile.next_layer(); tile.next_layer(); diff --git a/unit_tests/library/trip.cpp b/unit_tests/library/trip.cpp index 5161e832e..789acc495 100644 --- a/unit_tests/library/trip.cpp +++ b/unit_tests/library/trip.cpp @@ -26,17 +26,18 @@ BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_small_component) params.coordinates.push_back(locations.at(1)); params.coordinates.push_back(locations.at(2)); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Trip(params, result); BOOST_CHECK(rc == Status::Ok); - const auto code = result.values.at("code").get().value; + auto& json_result=result.get(); + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); - const auto &waypoints = result.values.at("waypoints").get().values; + const auto &waypoints = json_result.values.at("waypoints").get().values; BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); - const auto &trips = result.values.at("trips").get().values; + const auto &trips = json_result.values.at("trips").get().values; BOOST_CHECK_EQUAL(trips.size(), 1); for (const auto &waypoint : waypoints) @@ -68,17 +69,18 @@ BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_in_big_component) params.coordinates.push_back(locations.at(1)); params.coordinates.push_back(locations.at(2)); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Trip(params, result); BOOST_CHECK(rc == Status::Ok); - const auto code = result.values.at("code").get().value; + auto& json_result=result.get(); + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); - const auto &waypoints = result.values.at("waypoints").get().values; + const auto &waypoints = json_result.values.at("waypoints").get().values; BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); - const auto &trips = result.values.at("trips").get().values; + const auto &trips = json_result.values.at("trips").get().values; BOOST_CHECK_EQUAL(trips.size(), 1); for (const auto &waypoint : waypoints) @@ -112,17 +114,18 @@ BOOST_AUTO_TEST_CASE(test_roundtrip_response_for_locations_across_components) params.coordinates.push_back(small.at(1)); params.coordinates.push_back(big.at(1)); - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Trip(params, result); BOOST_CHECK(rc == Status::Ok); - const auto code = result.values.at("code").get().value; + auto& json_result=result.get(); + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); - const auto &waypoints = result.values.at("waypoints").get().values; + const auto &waypoints = json_result.values.at("waypoints").get().values; BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); - const auto &trips = result.values.at("trips").get().values; + const auto &trips = json_result.values.at("trips").get().values; BOOST_CHECK_EQUAL(trips.size(), 1); // ^ First snapping, then SCC decomposition (see plugins/trip.cpp). Therefore only a single // trip. @@ -160,17 +163,18 @@ BOOST_AUTO_TEST_CASE(test_tfse_1) params.destination = TripParameters::DestinationType::Last; params.roundtrip = false; - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Trip(params, result); BOOST_CHECK(rc == Status::Ok); - const auto code = result.values.at("code").get().value; + auto& json_result=result.get(); + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); - const auto &waypoints = result.values.at("waypoints").get().values; + const auto &waypoints = json_result.values.at("waypoints").get().values; BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); - const auto &trips = result.values.at("trips").get().values; + const auto &trips = json_result.values.at("trips").get().values; BOOST_CHECK_EQUAL(trips.size(), 1); for (const auto &waypoint : waypoints) @@ -206,17 +210,18 @@ BOOST_AUTO_TEST_CASE(test_tfse_2) params.destination = TripParameters::DestinationType::Last; params.roundtrip = false; - json::Object result; + engine::api::ResultT result = json::Object(); const auto rc = osrm.Trip(params, result); BOOST_CHECK(rc == Status::Ok); - const auto code = result.values.at("code").get().value; + auto& json_result=result.get(); + const auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); - const auto &waypoints = result.values.at("waypoints").get().values; + const auto &waypoints = json_result.values.at("waypoints").get().values; BOOST_CHECK_EQUAL(waypoints.size(), params.coordinates.size()); - const auto &trips = result.values.at("trips").get().values; + const auto &trips = json_result.values.at("trips").get().values; BOOST_CHECK_EQUAL(trips.size(), 1); for (const auto &waypoint : waypoints) @@ -245,19 +250,23 @@ void ResetParams(const Locations &locations, osrm::TripParameters ¶ms) } void CheckNotImplemented(const osrm::OSRM &osrm, osrm::TripParameters ¶ms) { - osrm::json::Object result; + using namespace osrm; + engine::api::ResultT result = json::Object(); auto rc = osrm.Trip(params, result); BOOST_REQUIRE(rc == osrm::Status::Error); - auto code = result.values.at("code").get().value; + auto& json_result=result.get(); + auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "NotImplemented"); } void CheckOk(const osrm::OSRM &osrm, osrm::TripParameters ¶ms) { - osrm::json::Object result; + using namespace osrm; + engine::api::ResultT result = json::Object(); auto rc = osrm.Trip(params, result); BOOST_REQUIRE(rc == osrm::Status::Ok); - auto code = result.values.at("code").get().value; + auto& json_result=result.get(); + auto code = json_result.values.at("code").get().value; BOOST_CHECK_EQUAL(code, "Ok"); }