Skip to content
Snippets Groups Projects
Commit 9a34cefa authored by Luis Gressenbuch's avatar Luis Gressenbuch
Browse files

fix: Throw exception on unsupported trajectory shape

parent 0fd84b95
No related branches found
No related tags found
1 merge request!235fix: Error message unsupported trajectory shape
Pipeline #66100 passed
......@@ -131,6 +131,10 @@ TrajectoryRef ConvertScenarioTrajectoryRef(const std::shared_ptr<mantle_api::IEn
{
return detail::ConvertClothoidShape(follow_trajectory_action_trajectory);
}
else if(follow_trajectory_action_trajectory_shape->IsSetClothoid() || follow_trajectory_action_trajectory_shape->IsSetNurbs())
{
throw std::runtime_error("ConvertScenarioTrajectoryRef: Unsupported trajectory shape for trajectory '" + follow_trajectory_action_trajectory->GetName() + "'. Only Polyline and ClothoidSpline are supported!");
}
return std::nullopt;
}
......
......@@ -13,6 +13,7 @@
#include <openScenarioLib/generated/v1_3/api/ApiClassInterfacesV1_3.h>
#include <openScenarioLib/generated/v1_3/impl/ApiClassImplV1_3.h>
#include <functional>
#include <optional>
#include <stdexcept>
#include <tuple>
......@@ -29,6 +30,13 @@ using namespace units::literals;
class ConvertScenarioTrajectoryRefTest : public ::testing::Test
{
protected:
void SetTrajectoryShapeAndName()
{
trajectory->SetShape(trajectory_shape);
trajectory->SetName("Trajectory1");
trajectory_ref->SetTrajectory(trajectory);
}
void SetTrajectoryWithClothoidSpline()
{
expected_clothoid_spline.segments.push_back({
......@@ -54,10 +62,7 @@ protected:
clothoid_spline->SetSegments(clothoid_spline_segments);
trajectory_shape->SetClothoidSpline(clothoid_spline);
trajectory->SetShape(trajectory_shape);
trajectory->SetName("Trajectory1");
trajectory_ref->SetTrajectory(trajectory);
SetTrajectoryShapeAndName();
}
std::shared_ptr<NET_ASAM_OPENSCENARIO::v1_3::PositionImpl> SetWorldPosition(double x, double y, double z, double h, double p, double r)
......@@ -119,10 +124,7 @@ TEST_F(ConvertScenarioTrajectoryRefTest, GivenPolyLine_ReturnMantleAPITrajectory
polyline->SetVertices(vertices);
trajectory_shape->SetPolyline(polyline);
trajectory->SetShape(trajectory_shape);
trajectory->SetName("Trajectory1");
trajectory_ref->SetTrajectory(trajectory);
SetTrajectoryShapeAndName();
auto converted_trajectory_ref = OpenScenarioEngine::v1_3::ConvertScenarioTrajectoryRef(mockEnvironment, trajectory_ref, nullptr);
......@@ -193,14 +195,29 @@ TEST_F(ConvertScenarioTrajectoryRefTest, GivenTrajectoryWithClothoidSpline_WhenI
EXPECT_THROW(OpenScenarioEngine::v1_3::ConvertScenarioTrajectoryRef(mockEnvironment, trajectory_ref, nullptr), std::runtime_error);
}
TEST_F(ConvertScenarioTrajectoryRefTest, GivenNoPolyLineAndNoClothoidSpline_ReturnNullPtr)
TEST_F(ConvertScenarioTrajectoryRefTest, GivenNoShape_ReturnNullopt)
{
trajectory->SetShape(trajectory_shape);
trajectory->SetName("Trajectory1");
trajectory_ref->SetTrajectory(trajectory);
SetTrajectoryShapeAndName();
auto converted_trajectory_ref = OpenScenarioEngine::v1_3::ConvertScenarioTrajectoryRef(mockEnvironment, trajectory_ref, nullptr);
EXPECT_EQ(std::nullopt, converted_trajectory_ref);
}
using SetShapeFunction = std::function<void(std::shared_ptr<NET_ASAM_OPENSCENARIO::v1_3::ShapeImpl>)>;
class ConvertScenarioTrajectoryRefTestShapeParam : public ConvertScenarioTrajectoryRefTest, public ::testing::WithParamInterface<SetShapeFunction>
{
};
INSTANTIATE_TEST_CASE_P(
ConvertScenarioTrajectoryRefTestShapeInstParam,
ConvertScenarioTrajectoryRefTestShapeParam,
::testing::Values([](std::shared_ptr<NET_ASAM_OPENSCENARIO::v1_3::ShapeImpl> shape){shape->SetClothoid(std::make_shared<NET_ASAM_OPENSCENARIO::v1_3::ClothoidImpl>());},
[](std::shared_ptr<NET_ASAM_OPENSCENARIO::v1_3::ShapeImpl> shape){shape->SetNurbs(std::make_shared<NET_ASAM_OPENSCENARIO::v1_3::NurbsImpl>());}));
TEST_P(ConvertScenarioTrajectoryRefTestShapeParam, GivenUnsupportedShape_ThenException)
{
GetParam()(trajectory_shape);
SetTrajectoryShapeAndName();
EXPECT_THROW(OpenScenarioEngine::v1_3::ConvertScenarioTrajectoryRef(mockEnvironment, trajectory_ref, nullptr), std::runtime_error);
}
} // namespace
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment