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 ...@@ -131,6 +131,10 @@ TrajectoryRef ConvertScenarioTrajectoryRef(const std::shared_ptr<mantle_api::IEn
{ {
return detail::ConvertClothoidShape(follow_trajectory_action_trajectory); 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; return std::nullopt;
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <openScenarioLib/generated/v1_3/api/ApiClassInterfacesV1_3.h> #include <openScenarioLib/generated/v1_3/api/ApiClassInterfacesV1_3.h>
#include <openScenarioLib/generated/v1_3/impl/ApiClassImplV1_3.h> #include <openScenarioLib/generated/v1_3/impl/ApiClassImplV1_3.h>
#include <functional>
#include <optional> #include <optional>
#include <stdexcept> #include <stdexcept>
#include <tuple> #include <tuple>
...@@ -29,6 +30,13 @@ using namespace units::literals; ...@@ -29,6 +30,13 @@ using namespace units::literals;
class ConvertScenarioTrajectoryRefTest : public ::testing::Test class ConvertScenarioTrajectoryRefTest : public ::testing::Test
{ {
protected: protected:
void SetTrajectoryShapeAndName()
{
trajectory->SetShape(trajectory_shape);
trajectory->SetName("Trajectory1");
trajectory_ref->SetTrajectory(trajectory);
}
void SetTrajectoryWithClothoidSpline() void SetTrajectoryWithClothoidSpline()
{ {
expected_clothoid_spline.segments.push_back({ expected_clothoid_spline.segments.push_back({
...@@ -54,10 +62,7 @@ protected: ...@@ -54,10 +62,7 @@ protected:
clothoid_spline->SetSegments(clothoid_spline_segments); clothoid_spline->SetSegments(clothoid_spline_segments);
trajectory_shape->SetClothoidSpline(clothoid_spline); trajectory_shape->SetClothoidSpline(clothoid_spline);
trajectory->SetShape(trajectory_shape); SetTrajectoryShapeAndName();
trajectory->SetName("Trajectory1");
trajectory_ref->SetTrajectory(trajectory);
} }
std::shared_ptr<NET_ASAM_OPENSCENARIO::v1_3::PositionImpl> SetWorldPosition(double x, double y, double z, double h, double p, double r) 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 ...@@ -119,10 +124,7 @@ TEST_F(ConvertScenarioTrajectoryRefTest, GivenPolyLine_ReturnMantleAPITrajectory
polyline->SetVertices(vertices); polyline->SetVertices(vertices);
trajectory_shape->SetPolyline(polyline); trajectory_shape->SetPolyline(polyline);
trajectory->SetShape(trajectory_shape); SetTrajectoryShapeAndName();
trajectory->SetName("Trajectory1");
trajectory_ref->SetTrajectory(trajectory);
auto converted_trajectory_ref = OpenScenarioEngine::v1_3::ConvertScenarioTrajectoryRef(mockEnvironment, trajectory_ref, nullptr); auto converted_trajectory_ref = OpenScenarioEngine::v1_3::ConvertScenarioTrajectoryRef(mockEnvironment, trajectory_ref, nullptr);
...@@ -193,14 +195,29 @@ TEST_F(ConvertScenarioTrajectoryRefTest, GivenTrajectoryWithClothoidSpline_WhenI ...@@ -193,14 +195,29 @@ TEST_F(ConvertScenarioTrajectoryRefTest, GivenTrajectoryWithClothoidSpline_WhenI
EXPECT_THROW(OpenScenarioEngine::v1_3::ConvertScenarioTrajectoryRef(mockEnvironment, trajectory_ref, nullptr), std::runtime_error); 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); SetTrajectoryShapeAndName();
trajectory->SetName("Trajectory1");
trajectory_ref->SetTrajectory(trajectory);
auto converted_trajectory_ref = OpenScenarioEngine::v1_3::ConvertScenarioTrajectoryRef(mockEnvironment, trajectory_ref, nullptr); auto converted_trajectory_ref = OpenScenarioEngine::v1_3::ConvertScenarioTrajectoryRef(mockEnvironment, trajectory_ref, nullptr);
EXPECT_EQ(std::nullopt, converted_trajectory_ref); 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 } // 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