Skip to content
Snippets Groups Projects

Integrate MantleAPI v17

Merged Andreas Rauschert requested to merge integrate_mantle_api_v12 into main
Compare and
102 files
+ 2323
2101
Compare changes
  • Side-by-side
  • Inline
Files
102
+ 23
21
/********************************************************************************
* 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
* terms of the Eclipse Public License 2.0 which is available at
@@ -9,8 +9,6 @@
********************************************************************************/
#include <MantleAPI/Common/i_logger.h>
#include <MantleAPI/Common/log_utils.h>
#include <MantleAPI/Test/test_utils.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -19,6 +17,7 @@
#include <string>
#include "OpenScenarioEngine/OpenScenarioEngine.h"
#include "tests/TestUtils.h"
using namespace units::literals;
@@ -62,42 +61,45 @@ int main(int argc, char* argv[])
return -1;
}
auto mockEnvironment = std::make_shared<mantle_api::MockEnvironment>();
auto fake_environment = std::make_shared<testing::OpenScenarioEngine::v1_3::FakeEnvironment>();
auto& mockEntityRepository = static_cast<mantle_api::MockEntityRepository&>(mockEnvironment->GetEntityRepository());
auto& mockEntityRepository = static_cast<mantle_api::MockEntityRepository&>(fake_environment->GetEntityRepository());
mantle_api::MockVehicle mockVehicle1;
ON_CALL(mockEntityRepository, Create("Vehicle1", A<const mantle_api::VehicleProperties&>())).WillByDefault(ReturnRef(mockVehicle1));
auto mock_vehicle_1 = std::make_shared<mantle_api::MockVehicle>();
ON_CALL(mockEntityRepository, Create("Vehicle1", A<const mantle_api::VehicleProperties&>())).WillByDefault(Return(mock_vehicle_1));
mantle_api::MockVehicle mockVehicle2;
ON_CALL(mockEntityRepository, Create("Vehicle2", A<const mantle_api::VehicleProperties&>())).WillByDefault(ReturnRef(mockVehicle2));
auto mock_vehicle_2 = std::make_shared<mantle_api::MockVehicle>();
ON_CALL(mockEntityRepository, Create("Vehicle2", A<const mantle_api::VehicleProperties&>())).WillByDefault(Return(mock_vehicle_2));
auto& mockControllerRepository = mockEnvironment->GetControllerRepository();
auto& mockControllerRepository = fake_environment->GetControllerRepository();
mantle_api::MockController mockController;
auto mockController = std::make_shared<mantle_api::MockController>();
auto controller_name("demo_controller"s);
ON_CALL(mockControllerRepository, Create(_)).WillByDefault(ReturnRef(mockController));
ON_CALL(mockController, GetName()).WillByDefault(ReturnRef(controller_name));
ON_CALL(mockController, GetUniqueId()).WillByDefault(Return(1234));
ON_CALL(mockControllerRepository, Create(_)).WillByDefault(Return(mockController));
ON_CALL(*mockController, GetName()).WillByDefault(ReturnRef(controller_name));
ON_CALL(*mockController, GetUniqueId()).WillByDefault(Return(mantle_api::UniqueId(1234)));
OpenScenarioEngine::v1_3::OpenScenarioEngine openScenarioEngine(scenario_file.string(), mockEnvironment, consoleLogger);
OpenScenarioEngine::v1_3::OpenScenarioEngine openScenarioEngine(scenario_file.string(), fake_environment, consoleLogger);
mantle_api::Time current_time{0_s};
ON_CALL(*mockEnvironment, GetSimulationTime())
.WillByDefault(Invoke([&current_time]() { return current_time; }));
ON_CALL(*mockEnvironment, HasControlStrategyGoalBeenReached(_, mantle_api::ControlStrategyType::kFollowVelocitySpline))
.WillByDefault(Invoke([&current_time]() -> bool { return current_time > 5.5_s; }));
ON_CALL(*fake_environment, GetSimulationTime())
.WillByDefault(Invoke([&current_time]()
{ return current_time; }));
ON_CALL(*fake_environment, HasControlStrategyGoalBeenReached(_, mantle_api::ControlStrategyType::kFollowVelocitySpline))
.WillByDefault(Invoke([&current_time]() -> bool
{ return current_time > 5.5_s; }));
try
{
openScenarioEngine.Init();
openScenarioEngine.Step(0_ms);
while (!openScenarioEngine.IsFinished())
{
openScenarioEngine.Step();
openScenarioEngine.Step(500_ms);
current_time += 500_ms;
}
}
catch(const std::runtime_error& e)
catch (const std::runtime_error& e)
{
consoleLogger->Log(mantle_api::LogLevel::kError, e.what());
}
Loading