From 43d02a25e45bfc89f133c4393b98b4994cea3675 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Sat, 3 Jun 2023 12:59:37 +0100 Subject: [PATCH] feat: squawk assignment menu --- docs/TAG_FUNCTIONS.md | 1 + src/plugin/squawk/SquawkAssignment.cpp | 2 +- src/plugin/squawk/SquawkAssignment.h | 3 +- src/plugin/squawk/SquawkAssignmentMenu.cpp | 92 ++++++++++++++++++++ src/plugin/squawk/SquawkAssignmentMenu.h | 65 ++++++++++++++ src/plugin/squawk/SquawkGenerator.cpp | 19 ++-- src/plugin/squawk/SquawkGenerator.h | 21 ++--- src/plugin/squawk/SquawkGeneratorInterface.h | 27 ++++++ src/plugin/squawk/SquawkModule.cpp | 31 +++++++ test/plugin/squawk/SquawkAssignmentTest.cpp | 16 ++-- test/plugin/squawk/SquawkGeneratorTest.cpp | 26 +++--- test/plugin/squawk/SquawkModuleTest.cpp | 15 +++- 12 files changed, 275 insertions(+), 43 deletions(-) create mode 100644 src/plugin/squawk/SquawkAssignmentMenu.cpp create mode 100644 src/plugin/squawk/SquawkAssignmentMenu.h create mode 100644 src/plugin/squawk/SquawkGeneratorInterface.h diff --git a/docs/TAG_FUNCTIONS.md b/docs/TAG_FUNCTIONS.md index 5acd5b075..4b3922e2e 100644 --- a/docs/TAG_FUNCTIONS.md +++ b/docs/TAG_FUNCTIONS.md @@ -22,3 +22,4 @@ 9019 - Acknowledge Prenote Message 9020 - Trigger Missed Approach 9021 - Acknowledge Missed Approach +9022 - Open Squawk Assignment Menu diff --git a/src/plugin/squawk/SquawkAssignment.cpp b/src/plugin/squawk/SquawkAssignment.cpp index 4c279640e..918e31924 100644 --- a/src/plugin/squawk/SquawkAssignment.cpp +++ b/src/plugin/squawk/SquawkAssignment.cpp @@ -45,7 +45,7 @@ namespace UKControllerPlugin::Squawk { this->GeneralAssignmentNeeded(flightplan, radarTarget); } - bool SquawkAssignment::AssignConspicuityAllowed(EuroScopeCFlightPlanInterface& flightplan) const + bool SquawkAssignment::DeleteApiSquawkAllowed(EuroScopeCFlightPlanInterface& flightplan) const { return this->activeCallsigns.UserHasCallsign() && (flightplan.IsTrackedByUser() || !flightplan.IsTracked()); } diff --git a/src/plugin/squawk/SquawkAssignment.h b/src/plugin/squawk/SquawkAssignment.h index 4f8cdca0a..752fd5435 100644 --- a/src/plugin/squawk/SquawkAssignment.h +++ b/src/plugin/squawk/SquawkAssignment.h @@ -35,8 +35,7 @@ namespace UKControllerPlugin { bool CircuitAssignmentNeeded( UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& flightplan, UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& radarTarget) const; - bool - AssignConspicuityAllowed(UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& flightplan) const; + bool DeleteApiSquawkAllowed(UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& flightplan) const; bool ForceAssignmentAllowed(UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& flightplan) const; bool ForceAssignmentNeeded(UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& flightplan) const; bool ForceAssignmentOrNoSquawkAssigned( diff --git a/src/plugin/squawk/SquawkAssignmentMenu.cpp b/src/plugin/squawk/SquawkAssignmentMenu.cpp new file mode 100644 index 000000000..ccd998c33 --- /dev/null +++ b/src/plugin/squawk/SquawkAssignmentMenu.cpp @@ -0,0 +1,92 @@ +#include "SquawkAssignmentMenu.h" +#include "SquawkGeneratorInterface.h" +#include "controller/ActiveCallsign.h" +#include "controller/ActiveCallsignCollection.h" +#include "euroscope/EuroScopeCFlightPlanInterface.h" +#include "euroscope/EuroscopePluginLoopbackInterface.h" +#include "euroscope/EuroscopeRadarLoopbackInterface.h" + +namespace UKControllerPlugin::Squawk { + + SquawkAssignmentMenu::SquawkAssignmentMenu( + int callbackId, + SquawkGeneratorInterface& squawkGenerator, + Controller::ActiveCallsignCollection& activeCallsigns, + Euroscope::EuroscopePluginLoopbackInterface& plugin) + : callbackId(callbackId), squawkGenerator(squawkGenerator), activeCallsigns(activeCallsigns), plugin(plugin) + { + } + + void SquawkAssignmentMenu::DisplaySquawkAssignmentMenu( + Euroscope::EuroScopeCFlightPlanInterface& flightplan, const POINT& mousePos) + { + // If the user doesn't have a callsign or the callsign isn't active, don't show the menu + if (!this->activeCallsigns.UserHasCallsign()) { + return; + } + + // Trigger the menu + plugin.TriggerPopupList( + {mousePos.x, mousePos.y, mousePos.x + MENU_WIDTH, mousePos.y + MENU_HEIGHT}, "Assign Squawk", 1); + + // Add the options + this->AddMenuOptions(); + } + + void SquawkAssignmentMenu::AddMenuOptions() + { + Plugin::PopupMenuItem item; + item.firstValue = ""; + item.secondValue = ""; + item.callbackFunctionId = this->callbackId; + item.checked = EuroScopePlugIn::POPUP_ELEMENT_NO_CHECKBOX; + item.disabled = false; + item.fixedPosition = false; + this->plugin.AddItemToPopupList(item); + + for (const auto& menuItem : this->squawkOptions) { + item.firstValue = menuItem; + this->plugin.AddItemToPopupList(item); + } + } + + void SquawkAssignmentMenu::MenuOptionSelected( + Euroscope::EuroscopeRadarLoopbackInterface& radarScreen, + const std::string& option, + const POINT& mousePos, + const RECT& tagItemArea) + { + auto flightplan = this->plugin.GetSelectedFlightplan(); + auto radarTarget = this->plugin.GetSelectedRadarTarget(); + if (!flightplan || !radarTarget) { + LogWarning("No flightplan selected, cant action squawk menu selection"); + return; + } + + if (option == GENERAL_SQUAWK) { + this->squawkGenerator.ForceGeneralSquawkForAircraft(*flightplan, *radarTarget); + return; + } + + if (option == LOCAL_SQUAWK) { + this->squawkGenerator.ForceLocalSquawkForAircraft(*flightplan, *radarTarget); + return; + } + + if (option == CONSPICUITY) { + this->squawkGenerator.DeleteApiSquawkAndSetTo("7000", *flightplan); + return; + } + + if (option == CIRCUIT) { + this->squawkGenerator.DeleteApiSquawkAndSetTo("7010", *flightplan); + return; + } + + if (option == EUROSCOPE) { + radarScreen.ToggleEuroscopeTagFunction( + EuroScopePlugIn::TAG_ITEM_FUNCTION_SQUAWK_POPUP, flightplan->GetCallsign(), mousePos, tagItemArea); + return; + } + } +} // namespace UKControllerPlugin::Squawk diff --git a/src/plugin/squawk/SquawkAssignmentMenu.h b/src/plugin/squawk/SquawkAssignmentMenu.h new file mode 100644 index 000000000..60d888a44 --- /dev/null +++ b/src/plugin/squawk/SquawkAssignmentMenu.h @@ -0,0 +1,65 @@ +#pragma once + +namespace UKControllerPlugin { + namespace Controller { + class ActiveCallsignCollection; + } // namespace Controller + namespace Euroscope { + class EuroscopePluginLoopbackInterface; + class EuroScopeCFlightPlanInterface; + class EuroscopeRadarLoopbackInterface; + } // namespace Euroscope +} // namespace UKControllerPlugin + +namespace UKControllerPlugin::Squawk { + + class SquawkGeneratorInterface; + + /** + * A popup menu for choosing a squawk code to assign to a flight. + */ + class SquawkAssignmentMenu + { + public: + SquawkAssignmentMenu( + int callbackId, + SquawkGeneratorInterface& squawkGenerator, + Controller::ActiveCallsignCollection& activeCallsigns, + Euroscope::EuroscopePluginLoopbackInterface& plugin); + void DisplaySquawkAssignmentMenu(Euroscope::EuroScopeCFlightPlanInterface& flightplan, const POINT& mousePos); + void MenuOptionSelected( + Euroscope::EuroscopeRadarLoopbackInterface& radarScreen, + const std::string& option, + const POINT& mousePos, + const RECT& tagItemArea); + + private: + void AddMenuOptions(); + + // Menu options + const char* GENERAL_SQUAWK = "General"; + const char* LOCAL_SQUAWK = "Local"; + const char* CONSPICUITY = "Conspicuity (7000)"; + const char* CIRCUIT = "Circuit (7010)"; + const char* EUROSCOPE = "Euroscope"; + + std::list squawkOptions = {GENERAL_SQUAWK, LOCAL_SQUAWK, CONSPICUITY, CIRCUIT, EUROSCOPE}; + + // Menu sizes + static const int MENU_WIDTH = 200; + static const int MENU_HEIGHT = 200; + + // The callback id to use for when a menu item is clicked + const int callbackId; + + // The squawk generator + SquawkGeneratorInterface& squawkGenerator; + + // Who's active as a controller + Controller::ActiveCallsignCollection& activeCallsigns; + + // The plugin instance, lets us make menus + Euroscope::EuroscopePluginLoopbackInterface& plugin; + }; + +} // namespace UKControllerPlugin::Squawk diff --git a/src/plugin/squawk/SquawkGenerator.cpp b/src/plugin/squawk/SquawkGenerator.cpp index 41936ebf9..4052e8a88 100644 --- a/src/plugin/squawk/SquawkGenerator.cpp +++ b/src/plugin/squawk/SquawkGenerator.cpp @@ -60,23 +60,24 @@ namespace UKControllerPlugin::Squawk { } /** - * Removes the API squawk assignment and deletes the local + * Removes the API squawk assignment and changes the EuroScope callotion to the provided squawk. */ - auto SquawkGenerator::AssignConspicuitySquawkForAircraft(EuroScopeCFlightPlanInterface& flightplan) -> bool + auto SquawkGenerator::DeleteApiSquawkAndSetTo(const std::string& squawk, EuroScopeCFlightPlanInterface& flightplan) + -> bool { - if (!this->assignmentRules.AssignConspicuityAllowed(flightplan)) { - LogWarning("Cannot assign conspicuity squawk to " + flightplan.GetCallsign() + " - not allowed"); + if (!this->assignmentRules.DeleteApiSquawkAllowed(flightplan)) { + LogWarning("Cannot delete api squawk " + flightplan.GetCallsign() + " - not allowed"); return false; } const auto currentSquawk = flightplan.GetAssignedSquawk(); - if (!this->StartSquawkUpdate(flightplan)) { + if (!this->StartSquawkUpdate(flightplan, squawk)) { return false; } const auto callsign = flightplan.GetCallsign(); if (storedFlightplans.HasFlightplanForCallsign(callsign)) { - storedFlightplans.GetFlightplanForCallsign(callsign).SetPreviouslyAssignedSquawk("7000"); + storedFlightplans.GetFlightplanForCallsign(callsign).SetPreviouslyAssignedSquawk(squawk); } this->taskRunner->QueueAsynchronousTask([this, callsign, currentSquawk]() { @@ -306,14 +307,16 @@ namespace UKControllerPlugin::Squawk { /* Places a request in progress to prevent duplicate requests */ - auto SquawkGenerator::StartSquawkUpdate(EuroScopeCFlightPlanInterface& flightplan) -> bool + auto SquawkGenerator::StartSquawkUpdate(EuroScopeCFlightPlanInterface& flightplan, const std::string& processSquawk) + -> bool { // Lock the requests queue and mark the request as in progress. Set a holding squawk. if (!this->squawkRequests.Start(flightplan.GetCallsign())) { return false; } - flightplan.SetSquawk(this->PROCESS_SQUAWK); + flightplan.SetSquawk(processSquawk); + return true; } diff --git a/src/plugin/squawk/SquawkGenerator.h b/src/plugin/squawk/SquawkGenerator.h index 867445ca7..665815239 100644 --- a/src/plugin/squawk/SquawkGenerator.h +++ b/src/plugin/squawk/SquawkGenerator.h @@ -1,5 +1,7 @@ #pragma once +#include "SquawkGeneratorInterface.h" #include "SquawkRequest.h" +#include "squawk/SquawkGeneratorInterface.h" #include "task/TaskRunnerInterface.h" namespace UKControllerPlugin { @@ -28,7 +30,7 @@ namespace UKControllerPlugin::Squawk { /* Makes the relevant API calls to generate a squawk for an aircraft. */ - class SquawkGenerator + class SquawkGenerator : public SquawkGeneratorInterface { public: SquawkGenerator( @@ -38,18 +40,18 @@ namespace UKControllerPlugin::Squawk { const UKControllerPlugin::Controller::ActiveCallsignCollection& callsigns, const UKControllerPlugin::Flightplan::StoredFlightplanCollection& storedFlightplans, const std::shared_ptr& allocations); - auto - AssignConspicuitySquawkForAircraft(UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& flightplan) - -> bool; auto AssignCircuitSquawkForAircraft( UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& flightplan, UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& radarTarget) const -> bool; + auto DeleteApiSquawkAndSetTo( + const std::string& squawk, UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& flightplan) + -> bool override; auto ForceGeneralSquawkForAircraft( UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& flightplan, - UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool; + UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool override; auto ForceLocalSquawkForAircraft( UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& flightplan, - UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool; + UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool override; auto ReassignPreviousSquawkToAircraft( UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& flightplan, UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& radarTarget) const -> bool; @@ -69,7 +71,9 @@ namespace UKControllerPlugin::Squawk { CreateLocalSquawkAssignment(const std::string& callsign, std::string unit, std::string flightRules) const -> bool; void EndSquawkUpdate(std::string callsign); - auto StartSquawkUpdate(UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& flightplan) -> bool; + auto StartSquawkUpdate( + UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& flightplan, + const std::string& processSquawk = "7000") -> bool; // Callsigns of logged in controllers const UKControllerPlugin::Controller::ActiveCallsignCollection& activeCallsigns; @@ -91,8 +95,5 @@ namespace UKControllerPlugin::Squawk { // Receives API squawk allocations, so that they may be assigned to flightplans on the main thread const std::shared_ptr allocations; - - // The squawk we set when a squawk is being generated - const std::string PROCESS_SQUAWK = "7000"; }; } // namespace UKControllerPlugin::Squawk diff --git a/src/plugin/squawk/SquawkGeneratorInterface.h b/src/plugin/squawk/SquawkGeneratorInterface.h new file mode 100644 index 000000000..0f6f986f0 --- /dev/null +++ b/src/plugin/squawk/SquawkGeneratorInterface.h @@ -0,0 +1,27 @@ +#pragma once + +namespace UKControllerPlugin::Euroscope { + class EuroScopeCFlightPlanInterface; + class EuroScopeCRadarTargetInterface; +} // namespace UKControllerPlugin::Euroscope + +namespace UKControllerPlugin::Squawk { + + /* + Makes the relevant API calls to generate a squawk for an aircraft. + */ + class SquawkGeneratorInterface + { + public: + virtual ~SquawkGeneratorInterface() = default; + virtual auto DeleteApiSquawkAndSetTo( + const std::string& squawk, UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& flightplan) + -> bool = 0; + virtual auto ForceGeneralSquawkForAircraft( + UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& flightplan, + UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool = 0; + virtual auto ForceLocalSquawkForAircraft( + UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& flightplan, + UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool = 0; + }; +} // namespace UKControllerPlugin::Squawk diff --git a/src/plugin/squawk/SquawkModule.cpp b/src/plugin/squawk/SquawkModule.cpp index 3acf94bd7..af1a096dd 100644 --- a/src/plugin/squawk/SquawkModule.cpp +++ b/src/plugin/squawk/SquawkModule.cpp @@ -2,12 +2,15 @@ #include "ResetSquawkOnFailedDelete.h" #include "SquawkAssignment.h" #include "SquawkAssignmentDeleteForConspicuityFailedEvent.h" +#include "SquawkAssignmentMenu.h" #include "SquawkEventHandler.h" #include "SquawkGenerator.h" #include "SquawkModule.h" #include "bootstrap/PersistenceContainer.h" #include "controller/ActiveCallsignCollection.h" #include "controller/ControllerStatusEventHandlerCollection.h" +#include "euroscope/EuroscopeRadarLoopbackInterface.h" +#include "euroscope/RadarScreenCallbackFunction.h" #include "euroscope/UserSettingAwareCollection.h" #include "eventhandler/EventBus.h" #include "eventhandler/EventHandlerFlags.h" @@ -90,6 +93,34 @@ namespace UKControllerPlugin::Squawk { container.pluginFunctionHandlers->RegisterFunctionCall(forceSquawkCallbackLocal); + // Squawk assignment menu + int squawkMenuCallbackId = container.pluginFunctionHandlers->ReserveNextDynamicFunctionId(); + std::shared_ptr squawkMenu = std::make_shared( + squawkMenuCallbackId, *container.squawkGenerator, *container.activeCallsigns, *container.plugin); + + // Register a callback function for when the option is selected + Euroscope::RadarScreenCallbackFunction menuCallbackFunction( + squawkMenuCallbackId, + "Squawk Assignment Menu Callback", + [squawkMenu]( + int, + UKControllerPlugin::Euroscope::EuroscopeRadarLoopbackInterface& radarScreen, + const std::string& context, + const POINT& mousePos, + const RECT& area) { squawkMenu->MenuOptionSelected(radarScreen, context, mousePos, area); }); + container.pluginFunctionHandlers->RegisterFunctionCall(menuCallbackFunction); + + // Register the tag function + TagFunction squawkMenuTagFunction( + 9022, + "Open Squawk Assignment Menu", + [squawkMenu]( + UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& fp, + UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& rt, + const std::string& context, + const POINT& mousePos) { squawkMenu->DisplaySquawkAssignmentMenu(fp, mousePos); }); + container.pluginFunctionHandlers->RegisterFunctionCall(squawkMenuTagFunction); + // Handler to reset squawks if delete fails UKControllerPluginUtils::EventHandler::EventBus::Bus() .AddHandler( diff --git a/test/plugin/squawk/SquawkAssignmentTest.cpp b/test/plugin/squawk/SquawkAssignmentTest.cpp index d8fb64dea..a937429c2 100644 --- a/test/plugin/squawk/SquawkAssignmentTest.cpp +++ b/test/plugin/squawk/SquawkAssignmentTest.cpp @@ -886,30 +886,30 @@ namespace UKControllerPluginTest { EXPECT_FALSE(this->assignment.CircuitAssignmentNeeded(*this->mockFlightplan, *this->mockRadarTarget)); } - TEST_F(SquawkAssignmentTest, AssignConspicuityAllowedReturnsFalseIfUserHasNoCallsign) + TEST_F(SquawkAssignmentTest, DeleteApiSquawkAllowedReturnsFalseIfUserHasNoCallsign) { this->activeCallsigns.Flush(); - EXPECT_FALSE(this->assignment.AssignConspicuityAllowed(*this->mockFlightplan)); + EXPECT_FALSE(this->assignment.DeleteApiSquawkAllowed(*this->mockFlightplan)); } - TEST_F(SquawkAssignmentTest, AssignConspicuityAllowedReturnsFalseIfFlightplanTrackedBySomeoneElse) + TEST_F(SquawkAssignmentTest, DeleteApiSquawkAllowedReturnsFalseIfFlightplanTrackedBySomeoneElse) { ON_CALL(*this->mockFlightplan, IsTrackedByUser()).WillByDefault(Return(false)); ON_CALL(*this->mockFlightplan, IsTracked()).WillByDefault(Return(true)); - EXPECT_FALSE(this->assignment.AssignConspicuityAllowed(*this->mockFlightplan)); + EXPECT_FALSE(this->assignment.DeleteApiSquawkAllowed(*this->mockFlightplan)); } - TEST_F(SquawkAssignmentTest, AssignConspicuityAllowedReturnsTrueIfFlightplanTrackedByUser) + TEST_F(SquawkAssignmentTest, DeleteApiSquawkAllowedReturnsTrueIfFlightplanTrackedByUser) { ON_CALL(*this->mockFlightplan, IsTrackedByUser()).WillByDefault(Return(true)); ON_CALL(*this->mockFlightplan, IsTracked()).WillByDefault(Return(true)); - EXPECT_TRUE(this->assignment.AssignConspicuityAllowed(*this->mockFlightplan)); + EXPECT_TRUE(this->assignment.DeleteApiSquawkAllowed(*this->mockFlightplan)); } - TEST_F(SquawkAssignmentTest, AssignConspicuityAllowedReturnsTrueIfFlightplanNotTracked) + TEST_F(SquawkAssignmentTest, DeleteApiSquawkAllowedReturnsTrueIfFlightplanNotTracked) { ON_CALL(*this->mockFlightplan, IsTracked()).WillByDefault(Return(false)); - EXPECT_TRUE(this->assignment.AssignConspicuityAllowed(*this->mockFlightplan)); + EXPECT_TRUE(this->assignment.DeleteApiSquawkAllowed(*this->mockFlightplan)); } } // namespace Squawk } // namespace UKControllerPluginTest diff --git a/test/plugin/squawk/SquawkGeneratorTest.cpp b/test/plugin/squawk/SquawkGeneratorTest.cpp index f1e4a87ed..3f8921a40 100644 --- a/test/plugin/squawk/SquawkGeneratorTest.cpp +++ b/test/plugin/squawk/SquawkGeneratorTest.cpp @@ -555,14 +555,14 @@ namespace UKControllerPluginTest { EXPECT_TRUE(this->generator->AssignCircuitSquawkForAircraft(*this->mockFlightplan, *this->mockRadarTarget)); } - TEST_F(SquawkGeneratorTest, ConspicuityReturnsFalseOnNoAction) + TEST_F(SquawkGeneratorTest, DeleteApiSquawkAndSetToReturnsFalseOnNoAction) { this->activeCallsigns.Flush(); EXPECT_CALL(*this->mockFlightplan, SetSquawk).Times(0); - EXPECT_FALSE(this->generator->AssignConspicuitySquawkForAircraft(*this->mockFlightplan)); + EXPECT_FALSE(this->generator->DeleteApiSquawkAndSetTo("7000", *this->mockFlightplan)); } - TEST_F(SquawkGeneratorTest, ConspicuityReturnsFalseOnNoActionRequestAlreadyHappening) + TEST_F(SquawkGeneratorTest, DeleteApiSquawkAndSetToReturnsFalseOnNoActionRequestAlreadyHappening) { MockTaskRunnerInterface mockRunnerNoExecute(false); SquawkGenerator newGenerator( @@ -578,11 +578,11 @@ namespace UKControllerPluginTest { ON_CALL(*this->mockFlightplan, GetAssignedSquawk()).WillByDefault(Return("1234")); EXPECT_CALL(*this->mockFlightplan, SetSquawk("7000")).Times(1); - EXPECT_TRUE(newGenerator.AssignConspicuitySquawkForAircraft(*this->mockFlightplan)); - EXPECT_FALSE(newGenerator.AssignConspicuitySquawkForAircraft(*this->mockFlightplan)); + EXPECT_TRUE(newGenerator.DeleteApiSquawkAndSetTo("7000", *this->mockFlightplan)); + EXPECT_FALSE(newGenerator.DeleteApiSquawkAndSetTo("7000", *this->mockFlightplan)); } - TEST_F(SquawkGeneratorTest, ConspicuityDeletesSquawk) + TEST_F(SquawkGeneratorTest, DeleteApiSquawkAndSetToDeletesSquawk) { StoredFlightplan storedPlan("BAW1252", "EGKK", "EGPH"); storedPlan.SetPreviouslyAssignedSquawk("1234"); @@ -591,14 +591,14 @@ namespace UKControllerPluginTest { ON_CALL(*this->mockFlightplan, IsTrackedByUser()).WillByDefault(Return(true)); ON_CALL(*this->mockFlightplan, GetCallsign()).WillByDefault(Return("BAW1252")); ON_CALL(*this->mockFlightplan, GetAssignedSquawk()).WillByDefault(Return("1234")); - EXPECT_CALL(*this->mockFlightplan, SetSquawk("7000")).Times(1); + EXPECT_CALL(*this->mockFlightplan, SetSquawk("7010")).Times(1); EXPECT_CALL(this->api, DeleteSquawkAssignment("BAW1252")).Times(1); - EXPECT_TRUE(this->generator->AssignConspicuitySquawkForAircraft(*this->mockFlightplan)); - EXPECT_EQ("7000", this->flightplans.GetFlightplanForCallsign("BAW1252").GetPreviouslyAssignedSquawk()); + EXPECT_TRUE(this->generator->DeleteApiSquawkAndSetTo("7010", *this->mockFlightplan)); + EXPECT_EQ("7010", this->flightplans.GetFlightplanForCallsign("BAW1252").GetPreviouslyAssignedSquawk()); } - TEST_F(SquawkGeneratorTest, ConspicuityDeletesSquawkAndTriggersFailedEventIfDeleteFails) + TEST_F(SquawkGeneratorTest, DeleteApiSquawkAndSetToDeletesSquawkAndTriggersFailedEventIfDeleteFails) { StoredFlightplan storedPlan("BAW1252", "EGKK", "EGPH"); storedPlan.SetPreviouslyAssignedSquawk("1234"); @@ -607,12 +607,12 @@ namespace UKControllerPluginTest { ON_CALL(*this->mockFlightplan, IsTrackedByUser()).WillByDefault(Return(true)); ON_CALL(*this->mockFlightplan, GetCallsign()).WillByDefault(Return("BAW1252")); ON_CALL(*this->mockFlightplan, GetAssignedSquawk()).WillByDefault(Return("1234")); - EXPECT_CALL(*this->mockFlightplan, SetSquawk("7000")).Times(1); + EXPECT_CALL(*this->mockFlightplan, SetSquawk("2831")).Times(1); EXPECT_CALL(this->api, DeleteSquawkAssignment("BAW1252")) .WillOnce(Throw(ApiNotFoundException("Not found"))); - EXPECT_TRUE(this->generator->AssignConspicuitySquawkForAircraft(*this->mockFlightplan)); - EXPECT_EQ("7000", this->flightplans.GetFlightplanForCallsign("BAW1252").GetPreviouslyAssignedSquawk()); + EXPECT_TRUE(this->generator->DeleteApiSquawkAndSetTo("2831", *this->mockFlightplan)); + EXPECT_EQ("2831", this->flightplans.GetFlightplanForCallsign("BAW1252").GetPreviouslyAssignedSquawk()); AssertSingleEventDispatched(); AssertFirstEventDispatched( diff --git a/test/plugin/squawk/SquawkModuleTest.cpp b/test/plugin/squawk/SquawkModuleTest.cpp index 181f25535..f5a588732 100644 --- a/test/plugin/squawk/SquawkModuleTest.cpp +++ b/test/plugin/squawk/SquawkModuleTest.cpp @@ -65,7 +65,7 @@ namespace UKControllerPluginTest::Squawk { TEST_F(SquawkModuleTest, BootstrapPluginRegistersFunctionCallbacks) { SquawkModule::BootstrapPlugin(container, false); - EXPECT_EQ(2, this->container.pluginFunctionHandlers->CountTagFunctions()); + EXPECT_EQ(3, this->container.pluginFunctionHandlers->CountTagFunctions()); EXPECT_EQ(0, this->container.pluginFunctionHandlers->CountCallbacks()); } @@ -91,4 +91,17 @@ namespace UKControllerPluginTest::Squawk { UKControllerPlugin::Squawk ::SquawkAssignmentDeleteForConspicuityFailedEvent>( UKControllerPluginUtils::EventHandler::EventHandlerFlags::EuroscopeThread); } + + TEST_F(SquawkModuleTest, BootstrapPluginRegistersSquawkAssignmentMenuTagFunction) + { + SquawkModule::BootstrapPlugin(container, true); + EXPECT_TRUE(this->container.pluginFunctionHandlers->HasTagFunction(9022)); + } + + TEST_F(SquawkModuleTest, BootstrapPluginRegistersSquawkAssignmentMenuCallbackFunction) + { + SquawkModule::BootstrapPlugin(container, true); + EXPECT_TRUE(this->container.pluginFunctionHandlers->HasRadarScreenCallbackByDescription( + "Squawk Assignment Menu Callback")); + } } // namespace UKControllerPluginTest::Squawk