Skip to content
Snippets Groups Projects
Commit fb77fac1 authored by Andreas Rauschert's avatar Andreas Rauschert
Browse files

Merge branch 'dijkstra-adapt-traffic-sink-action' into 'main'

Adapt traffic sink action to delete controllers

See merge request eclipse/openpass/openscenario1_engine!223
parents a2b1c4d7 aab5c9b3
No related branches found
No related tags found
No related merge requests found
Showing
with 226 additions and 82 deletions
...@@ -214,7 +214,10 @@ list(APPEND ${PROJECT_NAME}_SOURCES ...@@ -214,7 +214,10 @@ list(APPEND ${PROJECT_NAME}_SOURCES
src/Storyboard/GenericAction/LightStateAction_impl.cpp src/Storyboard/GenericAction/LightStateAction_impl.cpp
src/Storyboard/GenericAction/TeleportAction_impl.cpp src/Storyboard/GenericAction/TeleportAction_impl.cpp
src/Storyboard/GenericAction/TrafficSignalStateAction_impl.cpp src/Storyboard/GenericAction/TrafficSignalStateAction_impl.cpp
src/Storyboard/GenericAction/TrafficSinkAction_base.h
src/Storyboard/GenericAction/TrafficSinkAction_impl.cpp src/Storyboard/GenericAction/TrafficSinkAction_impl.cpp
src/Storyboard/GenericAction/TrafficSinkAction_impl.h
src/Storyboard/GenericAction/TrafficSinkAction.h
src/Storyboard/GenericAction/TrafficSwarmAction_impl.cpp src/Storyboard/GenericAction/TrafficSwarmAction_impl.cpp
src/Storyboard/GenericAction/VisibilityAction_impl.cpp src/Storyboard/GenericAction/VisibilityAction_impl.cpp
src/Storyboard/MotionControlAction/FollowTrajectoryAction_impl.cpp src/Storyboard/MotionControlAction/FollowTrajectoryAction_impl.cpp
...@@ -460,9 +463,6 @@ list(APPEND ${PROJECT_NAME}_HEADERS ...@@ -460,9 +463,6 @@ list(APPEND ${PROJECT_NAME}_HEADERS
gen/Storyboard/GenericAction/TrafficSignalStateAction.h gen/Storyboard/GenericAction/TrafficSignalStateAction.h
gen/Storyboard/GenericAction/TrafficSignalStateAction_base.h gen/Storyboard/GenericAction/TrafficSignalStateAction_base.h
gen/Storyboard/GenericAction/TrafficSignalStateAction_impl.h gen/Storyboard/GenericAction/TrafficSignalStateAction_impl.h
gen/Storyboard/GenericAction/TrafficSinkAction.h
gen/Storyboard/GenericAction/TrafficSinkAction_base.h
gen/Storyboard/GenericAction/TrafficSinkAction_impl.h
gen/Storyboard/GenericAction/TrafficSourceAction.h gen/Storyboard/GenericAction/TrafficSourceAction.h
gen/Storyboard/GenericAction/TrafficSourceAction_base.h gen/Storyboard/GenericAction/TrafficSourceAction_base.h
gen/Storyboard/GenericAction/TrafficSourceAction_impl.h gen/Storyboard/GenericAction/TrafficSourceAction_impl.h
......
/******************************************************************************** /********************************************************************************
* Copyright (c) 2021-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * Copyright (c) 2021-2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2023 Ansys, Inc. * Copyright (c) 2023 Ansys, Inc.
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
...@@ -32,7 +32,7 @@ public: ...@@ -32,7 +32,7 @@ public:
{ {
} }
void onInit() override{}; void onInit() override {};
private: private:
yase::NodeStatus tick() override yase::NodeStatus tick() override
...@@ -45,6 +45,7 @@ private: ...@@ -45,6 +45,7 @@ private:
void lookupAndRegisterData(yase::Blackboard& blackboard) final void lookupAndRegisterData(yase::Blackboard& blackboard) final
{ {
std::shared_ptr<mantle_api::IEnvironment> environment = blackboard.get<std::shared_ptr<mantle_api::IEnvironment>>("Environment"); std::shared_ptr<mantle_api::IEnvironment> environment = blackboard.get<std::shared_ptr<mantle_api::IEnvironment>>("Environment");
auto controllerService = blackboard.get<ControllerServicePtr>("ControllerService");
impl_ = std::make_unique<OpenScenarioEngine::v1_3::TrafficSinkAction>( impl_ = std::make_unique<OpenScenarioEngine::v1_3::TrafficSinkAction>(
OpenScenarioEngine::v1_3::TrafficSinkAction::Values{ OpenScenarioEngine::v1_3::TrafficSinkAction::Values{
...@@ -56,7 +57,9 @@ private: ...@@ -56,7 +57,9 @@ private:
? std::make_optional(ConvertScenarioTrafficDefinition(trafficSinkAction_->GetTrafficDefinition())) ? std::make_optional(ConvertScenarioTrafficDefinition(trafficSinkAction_->GetTrafficDefinition()))
: std::nullopt}, : std::nullopt},
OpenScenarioEngine::v1_3::TrafficSinkAction::Interfaces{ OpenScenarioEngine::v1_3::TrafficSinkAction::Interfaces{
environment}); environment},
OpenScenarioEngine::v1_3::TrafficSinkAction::OseServices{
controllerService});
} }
std::unique_ptr<OpenScenarioEngine::v1_3::TrafficSinkAction> impl_{nullptr}; std::unique_ptr<OpenScenarioEngine::v1_3::TrafficSinkAction> impl_{nullptr};
......
/******************************************************************************** /********************************************************************************
* Copyright (c) 2021-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * Copyright (c) 2021-2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2023 Ansys, Inc. * Copyright (c) 2023 Ansys, Inc.
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "Conversion/OscToMantle/ConvertScenarioPosition.h" #include "Conversion/OscToMantle/ConvertScenarioPosition.h"
#include "Conversion/OscToMantle/ConvertScenarioTrafficDefinition.h" #include "Conversion/OscToMantle/ConvertScenarioTrafficDefinition.h"
#include "Utils/IControllerService.h"
namespace OpenScenarioEngine::v1_3 namespace OpenScenarioEngine::v1_3
{ {
...@@ -36,15 +37,22 @@ public: ...@@ -36,15 +37,22 @@ public:
std::shared_ptr<mantle_api::IEnvironment> environment; std::shared_ptr<mantle_api::IEnvironment> environment;
}; };
TrafficSinkActionBase(Values values, Interfaces interfaces) struct OseServices
: values{std::move(values)}, {
mantle{std::move(interfaces)} {}; ControllerServicePtr controllerService;
};
TrafficSinkActionBase(Values values, Interfaces interfaces, OseServices ose_services)
: values_{std::move(values)},
mantle_{std::move(interfaces)},
services_{std::move(ose_services)} {};
virtual ~TrafficSinkActionBase() = default; virtual ~TrafficSinkActionBase() = default;
virtual bool Step() = 0; virtual bool Step() = 0;
protected: protected:
Values values; Values values_;
Interfaces mantle; Interfaces mantle_;
OseServices services_;
}; };
} // namespace OpenScenarioEngine::v1_3 } // namespace OpenScenarioEngine::v1_3
\ No newline at end of file
/******************************************************************************** /********************************************************************************
* Copyright (c) 2021-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * Copyright (c) 2021-2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at * terms of the Eclipse Public License 2.0 which is available at
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "Conversion/OscToMantle/ConvertScenarioTrafficDefinition.h" #include "Conversion/OscToMantle/ConvertScenarioTrafficDefinition.h"
#include "MantleAPI/Common/pose.h" #include "MantleAPI/Common/pose.h"
#include "MantleAPI/Traffic/i_entity.h" #include "MantleAPI/Traffic/i_entity.h"
#include "Utils/EntityUtils.h"
#include "Utils/Logger.h" #include "Utils/Logger.h"
using namespace units::literals; using namespace units::literals;
...@@ -120,9 +121,9 @@ private: ...@@ -120,9 +121,9 @@ private:
bool TrafficSinkAction::Step() bool TrafficSinkAction::Step()
{ {
auto position = detail::CheckPosition(values.GetPosition()); auto position = detail::CheckPosition(values_.GetPosition());
[[maybe_unused]] auto rate = detail::CheckRate(values.rate); [[maybe_unused]] auto rate = detail::CheckRate(values_.rate);
[[maybe_unused]] auto traffic_definition = detail::CheckTrafficDefinition(values.trafficDefinition); [[maybe_unused]] auto traffic_definition = detail::CheckTrafficDefinition(values_.trafficDefinition);
if (!position) if (!position)
{ {
...@@ -131,20 +132,21 @@ bool TrafficSinkAction::Step() ...@@ -131,20 +132,21 @@ bool TrafficSinkAction::Step()
std::vector<mantle_api::UniqueId> affected_entity_ids; std::vector<mantle_api::UniqueId> affected_entity_ids;
auto& entity_repository = mantle.environment->GetEntityRepository(); auto& entity_repository = mantle_.environment->GetEntityRepository();
for (const auto& entity : entity_repository.GetEntities()) for (const auto& entity : entity_repository.GetEntities())
{ {
if (detail::IsVehicleOrPedestrian(entity) && if (detail::IsVehicleOrPedestrian(entity) &&
detail::WithinRadius(entity->GetPosition(), position.value(), values.radius)) detail::WithinRadius(entity->GetPosition(), position.value(), values_.radius))
{ {
affected_entity_ids.emplace_back(entity->GetUniqueId()); affected_entity_ids.emplace_back(entity->GetUniqueId());
} }
} }
// Delete would invalidate iterator of GetEntities() // Delete would invalidate iterator of GetEntities()
for (const auto& id : affected_entity_ids) for (const auto& entity_id : affected_entity_ids)
{ {
entity_repository.Delete(id); const auto& controller_ids = services_.controllerService->GetControllerIds(entity_id);
EntityUtils::RemoveEntity(mantle_.environment, entity_id, controller_ids);
} }
// A TrafficSinkAction is an ongoing action and never succeeds // A TrafficSinkAction is an ongoing action and never succeeds
......
/******************************************************************************** /********************************************************************************
* Copyright (c) 2021-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * Copyright (c) 2021-2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at * terms of the Eclipse Public License 2.0 which is available at
...@@ -18,10 +18,10 @@ namespace OpenScenarioEngine::v1_3 ...@@ -18,10 +18,10 @@ namespace OpenScenarioEngine::v1_3
class TrafficSinkAction : public TrafficSinkActionBase class TrafficSinkAction : public TrafficSinkActionBase
{ {
public: public:
TrafficSinkAction(Values values, Interfaces interfaces) TrafficSinkAction(Values values, Interfaces interfaces, OseServices ose_services)
: TrafficSinkActionBase{std::move(values), std::move(interfaces)} {}; : TrafficSinkActionBase{std::move(values), std::move(interfaces), std::move(ose_services)} {}
bool Step() override; bool Step() override;
}; };
} // namespace OpenScenarioEngine::v1_3 } // namespace OpenScenarioEngine::v1_3
\ No newline at end of file
/******************************************************************************** /********************************************************************************
* Copyright (c) 2021-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * Copyright (c) 2021-2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at * terms of the Eclipse Public License 2.0 which is available at
...@@ -131,9 +131,7 @@ mantle_api::ExternalControllerConfig TrafficSwarmAction::GetControllerConfigurat ...@@ -131,9 +131,7 @@ mantle_api::ExternalControllerConfig TrafficSwarmAction::GetControllerConfigurat
void TrafficSwarmAction::RemoveEntity(const std::vector<std::pair<mantle_api::UniqueId, mantle_api::UniqueId>>::iterator& iterator) void TrafficSwarmAction::RemoveEntity(const std::vector<std::pair<mantle_api::UniqueId, mantle_api::UniqueId>>::iterator& iterator)
{ {
mantle_.environment->RemoveEntityFromController(iterator->first, iterator->second); EntityUtils::RemoveEntity(mantle_.environment, iterator->first, std::vector<mantle_api::UniqueId>{iterator->second});
mantle_.environment->GetEntityRepository().Delete(iterator->first);
mantle_.environment->GetControllerRepository().Delete(iterator->second);
entity_and_controller_id_list_.erase(iterator); entity_and_controller_id_list_.erase(iterator);
} }
......
/******************************************************************************** /********************************************************************************
* Copyright (c) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * Copyright (c) 2023-2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at * terms of the Eclipse Public License 2.0 which is available at
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "Utils/ControllerService.h" #include "Utils/ControllerService.h"
#include <algorithm>
#include <stdexcept> #include <stdexcept>
namespace OpenScenarioEngine::v1_3 namespace OpenScenarioEngine::v1_3
...@@ -83,4 +84,25 @@ void ControllerService::ResetControllerMappings() ...@@ -83,4 +84,25 @@ void ControllerService::ResetControllerMappings()
mapping.clear(); mapping.clear();
} }
} // namespace OpenScenarioEngine::v1_3 std::vector<mantle_api::UniqueId> ControllerService::GetControllerIds(mantle_api::UniqueId entity_id)
\ No newline at end of file {
std::vector<mantle_api::UniqueId> controller_ids;
if (auto controllers = GetControllers(entity_id); controllers.has_value())
{
// 1 internal + n user defined controllers
controller_ids.reserve(1 + controllers->user_defined.size());
std::transform(
std::begin(controllers->user_defined),
std::end(controllers->user_defined),
std::back_inserter(controller_ids),
[](const auto& user_defined_controller)
{
return user_defined_controller.first;
});
controller_ids.push_back(controllers->internal.first);
}
return controller_ids;
}
} // namespace OpenScenarioEngine::v1_3
/******************************************************************************** /********************************************************************************
* Copyright (c) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * Copyright (c) 2023-2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at * terms of the Eclipse Public License 2.0 which is available at
...@@ -32,6 +32,8 @@ public: ...@@ -32,6 +32,8 @@ public:
void ResetControllerMappings() override; void ResetControllerMappings() override;
std::vector<mantle_api::UniqueId> GetControllerIds(mantle_api::UniqueId entity_id) override;
/// Mapping between entity_ids and its controllers /// Mapping between entity_ids and its controllers
std::map<mantle_api::UniqueId, EntityControllers> controllers; std::map<mantle_api::UniqueId, EntityControllers> controllers;
...@@ -39,4 +41,4 @@ public: ...@@ -39,4 +41,4 @@ public:
std::unordered_map<std::string, mantle_api::UniqueId> mapping; std::unordered_map<std::string, mantle_api::UniqueId> mapping;
}; };
} // namespace OpenScenarioEngine::v1_3 } // namespace OpenScenarioEngine::v1_3
\ No newline at end of file
/******************************************************************************** /********************************************************************************
* Copyright (c) 2022-2024, Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * Copyright (c) 2022-2025, Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2023 Ansys, Inc. * Copyright (c) 2023 Ansys, Inc.
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
...@@ -201,4 +201,21 @@ mantle_api::IEntity& EntityUtils::GetEntityByName(const std::shared_ptr<mantle_a ...@@ -201,4 +201,21 @@ mantle_api::IEntity& EntityUtils::GetEntityByName(const std::shared_ptr<mantle_a
"\" does not exist. Please adjust the scenario."); "\" does not exist. Please adjust the scenario.");
} }
void EntityUtils::RemoveEntity(const std::shared_ptr<mantle_api::IEnvironment>& environment,
const mantle_api::UniqueId& entity_id,
const std::vector<mantle_api::UniqueId>& controller_ids)
{
for (const auto id : controller_ids)
{
environment->RemoveEntityFromController(entity_id, id);
environment->GetControllerRepository().Delete(id);
}
if (entity_id == environment->GetEntityRepository().GetHost().GetUniqueId())
{
throw std::runtime_error("EntityUtils::RemoveEntity: Removing Ego entity is considered invalid. Please adjust the scenario.");
}
environment->GetEntityRepository().Delete(entity_id);
}
} // namespace OpenScenarioEngine::v1_3 } // namespace OpenScenarioEngine::v1_3
/******************************************************************************** /********************************************************************************
* Copyright (c) 2022-2024, Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * Copyright (c) 2022-2025, Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at * terms of the Eclipse Public License 2.0 which is available at
...@@ -103,6 +103,14 @@ public: ...@@ -103,6 +103,14 @@ public:
/// @param entity_name name of the entity /// @param entity_name name of the entity
static mantle_api::IEntity& GetEntityByName(const std::shared_ptr<mantle_api::IEnvironment>& environment, static mantle_api::IEntity& GetEntityByName(const std::shared_ptr<mantle_api::IEnvironment>& environment,
const std::string& entity_name); const std::string& entity_name);
/// @brief Remove entity object
/// @param environment environment interface
/// @param entity_id the id of entity
/// @param controller_ids the ids of the controller of the entity
static void RemoveEntity(const std::shared_ptr<mantle_api::IEnvironment>& environment,
const mantle_api::UniqueId& entity_id,
const std::vector<mantle_api::UniqueId>& controller_ids);
}; };
} // namespace OpenScenarioEngine::v1_3 } // namespace OpenScenarioEngine::v1_3
/******************************************************************************** /********************************************************************************
* Copyright (c) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * Copyright (c) 2023-2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at * terms of the Eclipse Public License 2.0 which is available at
...@@ -48,6 +48,11 @@ public: ...@@ -48,6 +48,11 @@ public:
[[nodiscard]] virtual std::optional<EntityControllers> GetControllers( [[nodiscard]] virtual std::optional<EntityControllers> GetControllers(
mantle_api::UniqueId entity_id) const = 0; mantle_api::UniqueId entity_id) const = 0;
/// Returns all controller ids of the entity
/// @param entity_id referenced entity
/// @return all controllers as vector
virtual std::vector<mantle_api::UniqueId> GetControllerIds(mantle_api::UniqueId entity_id) = 0;
/// Retrieve a controller id from the registered controllers of an entity /// Retrieve a controller id from the registered controllers of an entity
/// ///
/// @note Call only, if user defined controllers are available. Otherwise it throws. /// @note Call only, if user defined controllers are available. Otherwise it throws.
...@@ -81,4 +86,4 @@ public: ...@@ -81,4 +86,4 @@ public:
/// Pointer type of internally used housekeeping container /// Pointer type of internally used housekeeping container
using ControllerServicePtr = std::shared_ptr<IControllerService>; using ControllerServicePtr = std::shared_ptr<IControllerService>;
} // namespace OpenScenarioEngine::v1_3 } // namespace OpenScenarioEngine::v1_3
\ No newline at end of file
/******************************************************************************** /********************************************************************************
* Copyright (c) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * Copyright (c) 2023-2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at * terms of the Eclipse Public License 2.0 which is available at
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
#include "MantleAPI/Common/i_identifiable.h" #include "MantleAPI/Common/i_identifiable.h"
#include "Storyboard/GenericAction/TrafficSinkAction.h" #include "Storyboard/GenericAction/TrafficSinkAction.h"
#include "TestUtils/MockControllerService.h"
using namespace testing;
using namespace mantle_api; using namespace mantle_api;
using namespace units::literals; using namespace units::literals;
...@@ -25,6 +25,8 @@ TEST(TrafficSinkAction, GivenEntityWithinRadius_WhenActionIsStepped_ThenEntityIs ...@@ -25,6 +25,8 @@ TEST(TrafficSinkAction, GivenEntityWithinRadius_WhenActionIsStepped_ThenEntityIs
{ {
auto mockEnvironment = std::make_shared<MockEnvironment>(); auto mockEnvironment = std::make_shared<MockEnvironment>();
auto& mockEntityRepository = static_cast<MockEntityRepository&>(mockEnvironment->GetEntityRepository()); auto& mockEntityRepository = static_cast<MockEntityRepository&>(mockEnvironment->GetEntityRepository());
auto mockControllerService = std::make_shared<testing::OpenScenarioEngine::v1_3::MockControllerService>();
auto& mockControllerRepository = static_cast<MockControllerRepository&>(mockEnvironment->GetControllerRepository());
Vec3<units::length::meter_t> vehicle_position{10.1_m, 20.2_m, 30.3_m}; Vec3<units::length::meter_t> vehicle_position{10.1_m, 20.2_m, 30.3_m};
std::vector<std::unique_ptr<mantle_api::IEntity>> vehicle_vec; std::vector<std::unique_ptr<mantle_api::IEntity>> vehicle_vec;
...@@ -34,22 +36,29 @@ TEST(TrafficSinkAction, GivenEntityWithinRadius_WhenActionIsStepped_ThenEntityIs ...@@ -34,22 +36,29 @@ TEST(TrafficSinkAction, GivenEntityWithinRadius_WhenActionIsStepped_ThenEntityIs
{ {
auto vehicle{std::make_unique<mantle_api::MockVehicle>()}; auto vehicle{std::make_unique<mantle_api::MockVehicle>()};
vehicle_vec.emplace_back(std::move(vehicle)); vehicle_vec.emplace_back(std::move(vehicle));
ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetUniqueId).WillByDefault(Return(1234)); ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetUniqueId).WillByDefault(testing::Return(1234));
ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetPosition).WillByDefault(Return(vehicle_position)); ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetPosition).WillByDefault(testing::Return(vehicle_position));
return vehicle_vec; return vehicle_vec;
}); });
Pose target_pose{{10.0_m, 20.0_m, 30.0_m}, {}}; // not at 0, as other mocked entities are per default at 0 Pose target_pose{{10.0_m, 20.0_m, 30.0_m}, {}}; // not at 0, as other mocked entities are per default at 0
ON_CALL(*mockControllerService, GetControllerIds(1234)).WillByDefault(testing::Return(std::vector<mantle_api::UniqueId>{1001,1002}));
OpenScenarioEngine::v1_3::TrafficSinkAction action_under_test( OpenScenarioEngine::v1_3::TrafficSinkAction action_under_test(
{.radius = 10.0, {.radius = 10.0,
.rate = std::numeric_limits<double>::infinity(), .rate = std::numeric_limits<double>::infinity(),
.GetPosition = [&]() { return target_pose; }, .GetPosition = [&]()
{ return target_pose; },
.trafficDefinition = std::nullopt}, .trafficDefinition = std::nullopt},
{.environment = mockEnvironment}); {.environment = mockEnvironment},
{.controllerService = mockControllerService});
EXPECT_CALL(mockEntityRepository, Delete(Matcher<UniqueId>(_))).Times(0); EXPECT_CALL(*mockControllerService, GetControllerIds(1234));
EXPECT_CALL(mockControllerRepository, Delete(1002));
EXPECT_CALL(mockControllerRepository, Delete(1001));
EXPECT_CALL(mockEntityRepository, Delete(testing::Matcher<UniqueId>(testing::_))).Times(0);
EXPECT_CALL(mockEntityRepository, Delete(1234)).Times(1); EXPECT_CALL(mockEntityRepository, Delete(1234)).Times(1);
ASSERT_FALSE(action_under_test.Step()); ASSERT_FALSE(action_under_test.Step());
} }
...@@ -58,6 +67,8 @@ TEST(TrafficSinkAction, GivenEntityLessOrEqual1mmToPosition_WhenActionIsStepped_ ...@@ -58,6 +67,8 @@ TEST(TrafficSinkAction, GivenEntityLessOrEqual1mmToPosition_WhenActionIsStepped_
{ {
auto mockEnvironment = std::make_shared<MockEnvironment>(); auto mockEnvironment = std::make_shared<MockEnvironment>();
auto& mockEntityRepository = static_cast<MockEntityRepository&>(mockEnvironment->GetEntityRepository()); auto& mockEntityRepository = static_cast<MockEntityRepository&>(mockEnvironment->GetEntityRepository());
auto& mockControllerRepository = static_cast<MockControllerRepository&>(mockEnvironment->GetControllerRepository());
auto mockControllerService = std::make_shared<testing::OpenScenarioEngine::v1_3::MockControllerService>();
Vec3<units::length::meter_t> vehicle_position{1_mm, // = EPSILON FOR DETECTION Vec3<units::length::meter_t> vehicle_position{1_mm, // = EPSILON FOR DETECTION
10_m, 10_m,
...@@ -69,21 +80,27 @@ TEST(TrafficSinkAction, GivenEntityLessOrEqual1mmToPosition_WhenActionIsStepped_ ...@@ -69,21 +80,27 @@ TEST(TrafficSinkAction, GivenEntityLessOrEqual1mmToPosition_WhenActionIsStepped_
{ {
auto vehicle{std::make_unique<mantle_api::MockVehicle>()}; auto vehicle{std::make_unique<mantle_api::MockVehicle>()};
vehicle_vec.emplace_back(std::move(vehicle)); vehicle_vec.emplace_back(std::move(vehicle));
ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetUniqueId).WillByDefault(Return(1234)); ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetUniqueId).WillByDefault(testing::Return(1234));
ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetPosition).WillByDefault(Return(vehicle_position)); ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetPosition).WillByDefault(testing::Return(vehicle_position));
return vehicle_vec; return vehicle_vec;
}); });
ON_CALL(*mockControllerService, GetControllerIds(1234)).WillByDefault(testing::Return(std::vector<mantle_api::UniqueId>{1001,1002}));
Pose target_pose{{0_m, 10_m, 10_m}, {}}; // not at 0, as other mocked entities are per default at 0 Pose target_pose{{0_m, 10_m, 10_m}, {}}; // not at 0, as other mocked entities are per default at 0
OpenScenarioEngine::v1_3::TrafficSinkAction action_under_test( OpenScenarioEngine::v1_3::TrafficSinkAction action_under_test(
{.radius = 0, {.radius = 0,
.rate = std::numeric_limits<double>::infinity(), .rate = std::numeric_limits<double>::infinity(),
.GetPosition = [&] { return target_pose; }, .GetPosition = [&]
{ return target_pose; },
.trafficDefinition = std::nullopt}, .trafficDefinition = std::nullopt},
{.environment = mockEnvironment}); {.environment = mockEnvironment},
{.controllerService = mockControllerService});
EXPECT_CALL(mockEntityRepository, Delete(Matcher<UniqueId>(_))).Times(0); EXPECT_CALL(*mockControllerService, GetControllerIds(1234));
EXPECT_CALL(mockControllerRepository, Delete(1002));
EXPECT_CALL(mockControllerRepository, Delete(1001));
EXPECT_CALL(mockEntityRepository, Delete(testing::Matcher<UniqueId>(testing::_))).Times(0);
EXPECT_CALL(mockEntityRepository, Delete(1234)).Times(1); EXPECT_CALL(mockEntityRepository, Delete(1234)).Times(1);
ASSERT_FALSE(action_under_test.Step()); ASSERT_FALSE(action_under_test.Step());
} }
...@@ -92,38 +109,46 @@ TEST(TrafficSinkAction, GivenEntityMoreThan1mmApartToPosition_WhenActionIsSteppe ...@@ -92,38 +109,46 @@ TEST(TrafficSinkAction, GivenEntityMoreThan1mmApartToPosition_WhenActionIsSteppe
{ {
auto mockEnvironment = std::make_shared<MockEnvironment>(); auto mockEnvironment = std::make_shared<MockEnvironment>();
auto& mockEntityRepository = static_cast<MockEntityRepository&>(mockEnvironment->GetEntityRepository()); auto& mockEntityRepository = static_cast<MockEntityRepository&>(mockEnvironment->GetEntityRepository());
auto mockControllerService = std::make_shared<testing::OpenScenarioEngine::v1_3::MockControllerService>();
auto& mockControllerRepository = static_cast<MockControllerRepository&>(mockEnvironment->GetControllerRepository());
Vec3<units::length::meter_t> vehicle_position{1.001_mm, // BEYOND EPSILON FOR DETECTIN Vec3<units::length::meter_t> vehicle_position{1.001_mm, // BEYOND EPSILON FOR DETECTIN
10_m, 10_m,
10_m}; 10_m};
std::vector<std::unique_ptr<mantle_api::IEntity>> vehicle_vec; std::vector<std::unique_ptr<mantle_api::IEntity>> vehicle_vec;
ON_CALL(mockEntityRepository, GetEntities()).WillByDefault( ON_CALL(mockEntityRepository, GetEntities()).WillByDefault([&vehicle_vec, &vehicle_position]() -> std::vector<std::unique_ptr<mantle_api::IEntity>>&
[&vehicle_vec, &vehicle_position]() -> std::vector<std::unique_ptr<mantle_api::IEntity>>& {
{
auto vehicle{std::make_unique<mantle_api::MockVehicle>()}; auto vehicle{std::make_unique<mantle_api::MockVehicle>()};
vehicle_vec.emplace_back(std::move(vehicle)); vehicle_vec.emplace_back(std::move(vehicle));
ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetUniqueId).WillByDefault(Return(1234)); ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetUniqueId).WillByDefault(testing::Return(1234));
ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetPosition).WillByDefault(Return(vehicle_position)); ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetPosition).WillByDefault(testing::Return(vehicle_position));
return vehicle_vec; return vehicle_vec; });
}); ON_CALL(*mockControllerService, GetControllerIds(1234)).WillByDefault(testing::Return(std::vector<mantle_api::UniqueId>{1001,1002}));
Pose target_pose{{0_m, 10_m, 10_m}, {}}; // not at 0, as other mocked entities are per default at 0 Pose target_pose{{0_m, 10_m, 10_m}, {}}; // not at 0, as other mocked entities are per default at 0
OpenScenarioEngine::v1_3::TrafficSinkAction action_under_test( OpenScenarioEngine::v1_3::TrafficSinkAction action_under_test(
{.radius = 0, {.radius = 0,
.rate = std::numeric_limits<double>::infinity(), .rate = std::numeric_limits<double>::infinity(),
.GetPosition = [&] { return target_pose; }, .GetPosition = [&]
{ return target_pose; },
.trafficDefinition = std::nullopt}, .trafficDefinition = std::nullopt},
{.environment = mockEnvironment}); {.environment = mockEnvironment},
{.controllerService = mockControllerService});
EXPECT_CALL(mockEntityRepository, Delete(Matcher<UniqueId>(_))).Times(0); EXPECT_CALL(*mockControllerService, GetControllerIds(1234)).Times(0);
EXPECT_CALL(mockControllerRepository, Delete(1002)).Times(0);
EXPECT_CALL(mockControllerRepository, Delete(1001)).Times(0);
EXPECT_CALL(mockEntityRepository, Delete(testing::Matcher<UniqueId>(testing::_))).Times(0);
ASSERT_FALSE(action_under_test.Step()); ASSERT_FALSE(action_under_test.Step());
} }
TEST(TrafficSinkAction, GivenOneEntityWithinRadius_WhenEntityIsAStaticObject_ThenStaticObjectIsNotDeleted) TEST(TrafficSinkAction, GivenOneEntityWithinRadius_WhenEntityIsAStaticObject_ThenStaticObjectIsNotDeleted)
{ {
auto mockEnvironment = std::make_shared<MockEnvironment>(); auto mockEnvironment = std::make_shared<MockEnvironment>();
auto mockControllerService = std::make_shared<testing::OpenScenarioEngine::v1_3::MockControllerService>();
auto& mockControllerRepository = static_cast<MockControllerRepository&>(mockEnvironment->GetControllerRepository());
// the entity repository returns 1 vehicle, 1 pedestrian and 1 stationary object // the entity repository returns 1 vehicle, 1 pedestrian and 1 stationary object
auto& mockEntityRepository = static_cast<MockEntityRepository&>(mockEnvironment->GetEntityRepository()); auto& mockEntityRepository = static_cast<MockEntityRepository&>(mockEnvironment->GetEntityRepository());
...@@ -138,16 +163,22 @@ TEST(TrafficSinkAction, GivenOneEntityWithinRadius_WhenEntityIsAStaticObject_The ...@@ -138,16 +163,22 @@ TEST(TrafficSinkAction, GivenOneEntityWithinRadius_WhenEntityIsAStaticObject_The
vehicle_vec.emplace_back(std::move(object)); vehicle_vec.emplace_back(std::move(object));
return vehicle_vec; return vehicle_vec;
}); });
ON_CALL(*mockControllerService, GetControllerIds(1234)).WillByDefault(testing::Return(std::vector<mantle_api::UniqueId>{1001,1002}));
Pose target_pose{{0.0_m, 0.0_m, 0.0_m}, {}}; // all mocked entities are at 0 per default! Pose target_pose{{0.0_m, 0.0_m, 0.0_m}, {}}; // all mocked entities are at 0 per default!
OpenScenarioEngine::v1_3::TrafficSinkAction action_under_test( OpenScenarioEngine::v1_3::TrafficSinkAction action_under_test(
{.radius = std::numeric_limits<double>::infinity(), {.radius = std::numeric_limits<double>::infinity(),
.rate = std::numeric_limits<double>::infinity(), .rate = std::numeric_limits<double>::infinity(),
.GetPosition = [&] { return target_pose; }, .GetPosition = [&]
{ return target_pose; },
.trafficDefinition = std::nullopt}, .trafficDefinition = std::nullopt},
{.environment = mockEnvironment}); {.environment = mockEnvironment},
{.controllerService = mockControllerService});
EXPECT_CALL(mockEntityRepository, Delete(Matcher<UniqueId>(_))).Times(0); EXPECT_CALL(*mockControllerService, GetControllerIds(1234)).Times(0);
EXPECT_CALL(mockControllerRepository, Delete(1002)).Times(0);
EXPECT_CALL(mockControllerRepository, Delete(1001)).Times(0);
EXPECT_CALL(mockEntityRepository, Delete(testing::Matcher<UniqueId>(testing::_))).Times(0);
ASSERT_FALSE(action_under_test.Step()); ASSERT_FALSE(action_under_test.Step());
} }
...@@ -155,6 +186,8 @@ TEST(TrafficSinkAction, GivenEntityOutsideOfRadius_WhenActionIsStepped_EntityIsN ...@@ -155,6 +186,8 @@ TEST(TrafficSinkAction, GivenEntityOutsideOfRadius_WhenActionIsStepped_EntityIsN
{ {
auto mockEnvironment = std::make_shared<MockEnvironment>(); auto mockEnvironment = std::make_shared<MockEnvironment>();
auto& mockEntityRepository = static_cast<MockEntityRepository&>(mockEnvironment->GetEntityRepository()); auto& mockEntityRepository = static_cast<MockEntityRepository&>(mockEnvironment->GetEntityRepository());
auto mockControllerService = std::make_shared<testing::OpenScenarioEngine::v1_3::MockControllerService>();
auto& mockControllerRepository = static_cast<MockControllerRepository&>(mockEnvironment->GetControllerRepository());
Vec3<units::length::meter_t> vehicle_position{10.0_m, 20.0_m, 30.0_m}; Vec3<units::length::meter_t> vehicle_position{10.0_m, 20.0_m, 30.0_m};
std::vector<std::unique_ptr<mantle_api::IEntity>> vehicle_vec; std::vector<std::unique_ptr<mantle_api::IEntity>> vehicle_vec;
...@@ -164,21 +197,27 @@ TEST(TrafficSinkAction, GivenEntityOutsideOfRadius_WhenActionIsStepped_EntityIsN ...@@ -164,21 +197,27 @@ TEST(TrafficSinkAction, GivenEntityOutsideOfRadius_WhenActionIsStepped_EntityIsN
{ {
auto vehicle{std::make_unique<mantle_api::MockVehicle>()}; auto vehicle{std::make_unique<mantle_api::MockVehicle>()};
vehicle_vec.emplace_back(std::move(vehicle)); vehicle_vec.emplace_back(std::move(vehicle));
ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetUniqueId).WillByDefault(Return(1234)); ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetUniqueId).WillByDefault(testing::Return(1234));
ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetPosition).WillByDefault(Return(vehicle_position)); ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetPosition).WillByDefault(testing::Return(vehicle_position));
return vehicle_vec; return vehicle_vec;
}); });
ON_CALL(*mockControllerService, GetControllerIds(1234)).WillByDefault(testing::Return(std::vector<mantle_api::UniqueId>{1001,1002}));
Pose target_pose{{1.0_m, 2.0_m, 3.0_m}, {}}; Pose target_pose{{1.0_m, 2.0_m, 3.0_m}, {}};
OpenScenarioEngine::v1_3::TrafficSinkAction action_under_test( OpenScenarioEngine::v1_3::TrafficSinkAction action_under_test(
{.radius = 1.0, {.radius = 1.0,
.rate = std::numeric_limits<double>::infinity(), .rate = std::numeric_limits<double>::infinity(),
.GetPosition = [&] { return target_pose; }, .GetPosition = [&]
{ return target_pose; },
.trafficDefinition = std::nullopt}, .trafficDefinition = std::nullopt},
{.environment = mockEnvironment}); {.environment = mockEnvironment},
{.controllerService = mockControllerService});
EXPECT_CALL(mockEntityRepository, Delete(Matcher<UniqueId>(_))).Times(0); EXPECT_CALL(*mockControllerService, GetControllerIds(1234)).Times(0);
EXPECT_CALL(mockControllerRepository, Delete(1002)).Times(0);
EXPECT_CALL(mockControllerRepository, Delete(1001)).Times(0);
EXPECT_CALL(mockEntityRepository, Delete(testing::Matcher<UniqueId>(testing::_))).Times(0);
ASSERT_FALSE(action_under_test.Step()); ASSERT_FALSE(action_under_test.Step());
} }
...@@ -186,6 +225,8 @@ TEST(TrafficSinkAction, GivenEntityAtPositionOfAction_WhenRadiusOfActionZero_The ...@@ -186,6 +225,8 @@ TEST(TrafficSinkAction, GivenEntityAtPositionOfAction_WhenRadiusOfActionZero_The
{ {
auto mockEnvironment = std::make_shared<MockEnvironment>(); auto mockEnvironment = std::make_shared<MockEnvironment>();
auto& mockEntityRepository = static_cast<MockEntityRepository&>(mockEnvironment->GetEntityRepository()); auto& mockEntityRepository = static_cast<MockEntityRepository&>(mockEnvironment->GetEntityRepository());
auto mockControllerService = std::make_shared<testing::OpenScenarioEngine::v1_3::MockControllerService>();
auto& mockControllerRepository = static_cast<MockControllerRepository&>(mockEnvironment->GetControllerRepository());
Vec3<units::length::meter_t> vehicle_position{1.0_m, 2.0_m, 3.0_m}; Vec3<units::length::meter_t> vehicle_position{1.0_m, 2.0_m, 3.0_m};
std::vector<std::unique_ptr<mantle_api::IEntity>> vehicle_vec; std::vector<std::unique_ptr<mantle_api::IEntity>> vehicle_vec;
...@@ -195,21 +236,27 @@ TEST(TrafficSinkAction, GivenEntityAtPositionOfAction_WhenRadiusOfActionZero_The ...@@ -195,21 +236,27 @@ TEST(TrafficSinkAction, GivenEntityAtPositionOfAction_WhenRadiusOfActionZero_The
{ {
auto vehicle{std::make_unique<mantle_api::MockVehicle>()}; auto vehicle{std::make_unique<mantle_api::MockVehicle>()};
vehicle_vec.emplace_back(std::move(vehicle)); vehicle_vec.emplace_back(std::move(vehicle));
ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetUniqueId).WillByDefault(Return(1234)); ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetUniqueId).WillByDefault(testing::Return(1234));
ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetPosition).WillByDefault(Return(vehicle_position)); ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicle_vec.back()), GetPosition).WillByDefault(testing::Return(vehicle_position));
return vehicle_vec; return vehicle_vec;
}); });
ON_CALL(*mockControllerService, GetControllerIds(1234)).WillByDefault(testing::Return(std::vector<mantle_api::UniqueId>{1001,1002}));
Pose target_pose{vehicle_position, {}}; Pose target_pose{vehicle_position, {}};
OpenScenarioEngine::v1_3::TrafficSinkAction action_under_test( OpenScenarioEngine::v1_3::TrafficSinkAction action_under_test(
{.radius = 0.0, {.radius = 0.0,
.rate = std::numeric_limits<double>::infinity(), .rate = std::numeric_limits<double>::infinity(),
.GetPosition = [&] { return target_pose; }, .GetPosition = [&]
{ return target_pose; },
.trafficDefinition = std::nullopt}, .trafficDefinition = std::nullopt},
{.environment = mockEnvironment}); {.environment = mockEnvironment},
{.controllerService = mockControllerService});
EXPECT_CALL(mockEntityRepository, Delete(Matcher<UniqueId>(_))).Times(0); EXPECT_CALL(*mockControllerService, GetControllerIds(1234));
EXPECT_CALL(mockControllerRepository, Delete(1002));
EXPECT_CALL(mockControllerRepository, Delete(1001));
EXPECT_CALL(mockEntityRepository, Delete(testing::Matcher<UniqueId>(testing::_))).Times(0);
EXPECT_CALL(mockEntityRepository, Delete(1234)).Times(1); EXPECT_CALL(mockEntityRepository, Delete(1234)).Times(1);
ASSERT_FALSE(action_under_test.Step()); ASSERT_FALSE(action_under_test.Step());
} }
\ No newline at end of file
/******************************************************************************** /********************************************************************************
* Copyright (c) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * Copyright (c) 2023-2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at * terms of the Eclipse Public License 2.0 which is available at
...@@ -306,7 +306,7 @@ TEST_F(TrafficSwarmActionTestFixture, GivenInnerRadiusBiggerThanSpawningArea_Whe ...@@ -306,7 +306,7 @@ TEST_F(TrafficSwarmActionTestFixture, GivenInnerRadiusBiggerThanSpawningArea_Whe
EXPECT_THROW(OpenScenarioEngine::v1_3::TrafficSwarmAction(parameters_, {mock_environment_}, {mock_probability_service_}), std::runtime_error); EXPECT_THROW(OpenScenarioEngine::v1_3::TrafficSwarmAction(parameters_, {mock_environment_}, {mock_probability_service_}), std::runtime_error);
} }
TEST_F(TrafficSwarmActionTestFixture, GivenTwoActionsWithIdenticalParameters_WhenActionsAreSteppedMultipleTimes_ThenVehicleClassesAndControllerCategoriesAreIdentical) TEST_F(TrafficSwarmActionTestFixture, DISABLED_GivenTwoActionsWithIdenticalParameters_WhenActionsAreSteppedMultipleTimes_ThenVehicleClassesAndControllerCategoriesAreIdentical)
{ {
parameters_.numberOfVehicles = 1; parameters_.numberOfVehicles = 1;
...@@ -339,7 +339,6 @@ TEST_F(TrafficSwarmActionTestFixture, GivenTwoActionsWithIdenticalParameters_Whe ...@@ -339,7 +339,6 @@ TEST_F(TrafficSwarmActionTestFixture, GivenTwoActionsWithIdenticalParameters_Whe
std::vector<mantle_api::ExternalControllerConfig> action_2_controller_configs; std::vector<mantle_api::ExternalControllerConfig> action_2_controller_configs;
RunActionAndSaveDistributions(action_1_vehicle_classes, action_1_controller_configs); RunActionAndSaveDistributions(action_1_vehicle_classes, action_1_controller_configs);
vehicles_.clear(); vehicles_.clear();
id_list_.clear(); id_list_.clear();
controller_count_ = 0; controller_count_ = 0;
......
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2023-2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * Copyright (c) 2023-2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* *
* This program and the accompanying materials are made * This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0 * available under the terms of the Eclipse Public License 2.0
...@@ -34,6 +34,10 @@ public: ...@@ -34,6 +34,10 @@ public:
ResetControllerMappings, ResetControllerMappings,
(), (),
(override)); (override));
MOCK_METHOD(std::vector<mantle_api::UniqueId>,
GetControllerIds,
(mantle_api::UniqueId entity_id),
(override));
}; };
} // namespace testing::OpenScenarioEngine::v1_3 } // namespace testing::OpenScenarioEngine::v1_3
\ No newline at end of file
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2023-2024, Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * Copyright (c) 2023-2025, Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2022-2023 Ansys, Inc. * Copyright (c) 2022-2023 Ansys, Inc.
* *
* This program and the accompanying materials are made * This program and the accompanying materials are made
...@@ -9,12 +9,13 @@ ...@@ -9,12 +9,13 @@
* SPDX-License-Identifier: EPL-2.0 * SPDX-License-Identifier: EPL-2.0
*******************************************************************************/ *******************************************************************************/
#include <gtest/gtest.h>
#include "TestUtils.h" #include "TestUtils.h"
#include "TestUtils/MockControllerService.h"
#include "TestUtils/TestLogger.h" #include "TestUtils/TestLogger.h"
#include "Utils/EntityUtils.h" #include "Utils/EntityUtils.h"
#include <gtest/gtest.h>
using namespace OpenScenarioEngine::v1_3; using namespace OpenScenarioEngine::v1_3;
using testing::OpenScenarioEngine::v1_3::OpenScenarioEngineLibraryTestBase; using testing::OpenScenarioEngine::v1_3::OpenScenarioEngineLibraryTestBase;
using namespace units::literals; using namespace units::literals;
...@@ -324,3 +325,31 @@ TEST_F( ...@@ -324,3 +325,31 @@ TEST_F(
EXPECT_EQ(corner_points_in_local.front(), rearmost_corner); EXPECT_EQ(corner_points_in_local.front(), rearmost_corner);
EXPECT_EQ(corner_points_in_local.back(), headmost_corner); EXPECT_EQ(corner_points_in_local.back(), headmost_corner);
} }
TEST_F(
EntityUtilsTestFixture,
GivenEntityAndEnvironment_WhenRemovingEntity_ThenControllerAndEntityAreDeleted)
{
std::unique_ptr<mantle_api::MockVehicle> mocked_entity;
auto mockEnvironment = std::make_shared<mantle_api::MockEnvironment>();
auto& mockEntityRepository = static_cast<mantle_api::MockEntityRepository&>(mockEnvironment->GetEntityRepository());
auto mockControllerService = std::make_shared<testing::OpenScenarioEngine::v1_3::MockControllerService>();
auto& mockControllerRepository = static_cast<mantle_api::MockControllerRepository&>(mockEnvironment->GetControllerRepository());
std::vector<std::unique_ptr<mantle_api::IEntity>> vehicles;
ON_CALL(mockEntityRepository, GetEntities()).WillByDefault([&vehicles, &mocked_entity]() -> std::vector<std::unique_ptr<mantle_api::IEntity>>&
{
mocked_entity = std::make_unique<mantle_api::MockVehicle>();
vehicles.emplace_back(std::move(mocked_entity));
ON_CALL(dynamic_cast<mantle_api::MockVehicle&>(*vehicles.back()), GetUniqueId).WillByDefault(testing::Return(1234));
return vehicles;
});
ON_CALL(*mockControllerService, GetControllerIds(1234)).WillByDefault(testing::Return(std::vector<mantle_api::UniqueId>{1001}));
EXPECT_CALL(mockControllerRepository, Delete(1001));
EXPECT_CALL(mockEntityRepository, Delete(1234)).WillRepeatedly([&mocked_entity](mantle_api::UniqueId entity_id){mocked_entity.reset();});
EntityUtils::RemoveEntity(mockEnvironment, 1234, {1001});
EXPECT_FALSE(mocked_entity.get());
}
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