Skip to content

Commit

Permalink
Merge pull request #548 from AndyTWF/ecfmp-flow-measure-crash
Browse files Browse the repository at this point in the history
fix: ecfmp throws exception when flow measure has no aircraft
  • Loading branch information
AndyTWF authored Nov 12, 2023
2 parents c433072 + fc6b238 commit a35a410
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/plugin/ecfmp/AircraftFlowMeasureMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ namespace UKControllerPlugin::ECFMP {
// Add the flow measure to the map by id
flowMeasureIdMap.emplace(measure->Id(), measure);

// Initialise the flow measure's callsign map
flowMeasureCallsignMap.emplace(measure, std::unordered_set<std::string>());

// Check each of the flightplans and see if it applies to them
plugin.ApplyFunctionToAllFlightplans([&measure, this](
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
Expand Down
48 changes: 48 additions & 0 deletions test/plugin/ecfmp/AircraftFlowMeasureMapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,30 @@ namespace UKControllerPluginTest::ECFMP {
EXPECT_EQ(0, map.GetFlowMeasuresForCallsign("BAW456").size());
}

TEST_F(AircraftFlowMeasureMapTest, FlowMeasuresWithdrawingHandlesNoCallsignsAssociatedWithMeasure)
{
// Flightplan 1 will be applicable to the measure, flightplan 2, not so
EXPECT_CALL(*mockFlowMeasure1, ApplicableToAircraft(testing::_, testing::_))
.WillRepeatedly(testing::Return(false));

EXPECT_CALL(*mockFlowMeasure2, ApplicableToAircraft(testing::_, testing::_))
.WillRepeatedly(testing::Return(false));

map.OnEvent(::ECFMP::Plugin::FlowMeasureActivatedEvent{mockFlowMeasure1});
map.OnEvent(::ECFMP::Plugin::FlowMeasureActivatedEvent{mockFlowMeasure2});

EXPECT_EQ(0, map.GetFlowMeasuresForCallsign("BAW123").size());
EXPECT_EQ(0, map.GetFlowMeasuresForCallsign("BAW456").size());

// Withdraw the measures
EXPECT_NO_THROW(map.OnEvent(::ECFMP::Plugin::FlowMeasureWithdrawnEvent{mockFlowMeasure1}));
EXPECT_NO_THROW(map.OnEvent(::ECFMP::Plugin::FlowMeasureWithdrawnEvent{mockFlowMeasure2}));

// Check that flightplan 1 now has just the second measure, but flightplan 2 has only the second
EXPECT_EQ(0, map.GetFlowMeasuresForCallsign("BAW123").size());
EXPECT_EQ(0, map.GetFlowMeasuresForCallsign("BAW456").size());
}

TEST_F(AircraftFlowMeasureMapTest, FlowMeasuresExpiringRemoveThemFromAircraftsActiveFlowMeasures)
{
// Flightplan 1 will be applicable to the measure, flightplan 2, not so
Expand Down Expand Up @@ -186,6 +210,30 @@ namespace UKControllerPluginTest::ECFMP {
EXPECT_EQ(0, map.GetFlowMeasuresForCallsign("BAW456").size());
}

TEST_F(AircraftFlowMeasureMapTest, FlowMeasuresExpiringHandlesNoCallsignsAssociatedWithMeasure)
{
// Flightplan 1 will be applicable to the measure, flightplan 2, not so
EXPECT_CALL(*mockFlowMeasure1, ApplicableToAircraft(testing::_, testing::_))
.WillRepeatedly(testing::Return(false));

EXPECT_CALL(*mockFlowMeasure2, ApplicableToAircraft(testing::_, testing::_))
.WillRepeatedly(testing::Return(false));

map.OnEvent(::ECFMP::Plugin::FlowMeasureActivatedEvent{mockFlowMeasure1});
map.OnEvent(::ECFMP::Plugin::FlowMeasureActivatedEvent{mockFlowMeasure2});

EXPECT_EQ(0, map.GetFlowMeasuresForCallsign("BAW123").size());
EXPECT_EQ(0, map.GetFlowMeasuresForCallsign("BAW456").size());

// Withdraw the measures
EXPECT_NO_THROW(map.OnEvent(::ECFMP::Plugin::FlowMeasureExpiredEvent{mockFlowMeasure1}));
EXPECT_NO_THROW(map.OnEvent(::ECFMP::Plugin::FlowMeasureExpiredEvent{mockFlowMeasure2}));

// Check that flightplan 1 now has just the second measure, but flightplan 2 has only the second
EXPECT_EQ(0, map.GetFlowMeasuresForCallsign("BAW123").size());
EXPECT_EQ(0, map.GetFlowMeasuresForCallsign("BAW456").size());
}

TEST_F(AircraftFlowMeasureMapTest, FlightplansDisconnectingRemoveTheirActiveFlowMeasures)
{
// Flightplan 1 will be applicable to the measure, flightplan 2, not so
Expand Down

0 comments on commit a35a410

Please sign in to comment.