From 464de37f4cecea93c8e0fda9eec3f87985fe7c86 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Sat, 3 Jul 2021 16:54:02 +0100 Subject: [PATCH] fix(squawks): assign squawks with C-Mode correlation when aircraft connect (#287) * fix(squawks): assign squawks when aircraft connect during C-Mode correlation When an aircraft connects with a flightplan in C-Mode correlation, the data ES presents to the plugin can sometimes be invalid - e.g. exactly 0ft at exactly 0.0nm from origin. This prevents squawks from assigning. This change adds a regular poll to squawks, initial altitudes and initial headings to check for required updates - which apparently works as during these polls ES returns us complete data. fix #284 #285 #286 * refactor(deferred-events): remove old deferred events code --- .../UKControllerPlugin.vcxproj | 8 - .../UKControllerPlugin.vcxproj.filters | 32 +--- .../UKControllerPluginTest.vcxproj | 6 - .../UKControllerPluginTest.vcxproj.filters | 20 +-- .../EventHandlerCollectionBootstrap.cpp | 4 - src/bootstrap/InitialisePlugin.cpp | 3 - src/bootstrap/PersistenceContainer.h | 4 +- .../InitialAltitudeEventHandler.cpp | 76 +++++----- .../InitialAltitudeEventHandler.h | 65 ++++---- src/initialaltitude/InitialAltitudeModule.cpp | 5 +- .../InitialHeadingEventHandler.cpp | 64 ++++---- .../InitialHeadingEventHandler.h | 23 +-- src/initialheading/InitialHeadingModule.cpp | 7 +- src/squawk/SquawkEventHandler.cpp | 115 ++++++-------- src/squawk/SquawkEventHandler.h | 17 +-- src/squawk/SquawkModule.cpp | 3 +- src/squawk/SquawkModule.h | 2 +- test/mock/MockDeferredEventRunner.h | 33 ---- .../MockEuroscopePluginLoopbackInterface.h | 11 ++ test/mock/MockInitialAltitudeEventHandler.h | 56 ------- test/mock/MockSquawkEventHandler.h | 3 - .../EventHandlerCollectionBootstrapTest.cpp | 11 -- .../controller/ActiveCallsignMonitorTest.cpp | 3 - .../DeferredFlightplanEventTest.cpp | 80 ---------- .../InitialAltitudeEventHandlerTest.cpp | 142 +++++++++++++----- .../InitialAltitudeModuleTest.cpp | 14 +- .../InitialHeadingEventHandlerTest.cpp | 134 +++++++++++------ .../InitialHeadingModuleTest.cpp | 10 ++ .../AirfieldOwnershipHandlerTest.cpp | 7 +- test/test/squawk/SquawkEventHandlerTest.cpp | 92 +++++++----- test/test/squawk/SquawkModuleTest.cpp | 2 +- .../timedevent/DeferredEventBootstrapTest.cpp | 22 --- .../timedevent/DeferredEventHandlerTest.cpp | 115 -------------- test/test/timedevent/DeferredEventTest.cpp | 29 ---- 34 files changed, 442 insertions(+), 776 deletions(-) delete mode 100644 test/mock/MockDeferredEventRunner.h delete mode 100644 test/mock/MockInitialAltitudeEventHandler.h delete mode 100644 test/test/flightplan/DeferredFlightplanEventTest.cpp delete mode 100644 test/test/timedevent/DeferredEventBootstrapTest.cpp delete mode 100644 test/test/timedevent/DeferredEventHandlerTest.cpp delete mode 100644 test/test/timedevent/DeferredEventTest.cpp diff --git a/msvc/UKControllerPlugin/UKControllerPlugin.vcxproj b/msvc/UKControllerPlugin/UKControllerPlugin.vcxproj index d7415cbc8..8f463576d 100644 --- a/msvc/UKControllerPlugin/UKControllerPlugin.vcxproj +++ b/msvc/UKControllerPlugin/UKControllerPlugin.vcxproj @@ -98,7 +98,6 @@ - @@ -317,8 +316,6 @@ - - @@ -396,7 +393,6 @@ - @@ -585,7 +581,6 @@ - @@ -593,9 +588,6 @@ - - - diff --git a/msvc/UKControllerPlugin/UKControllerPlugin.vcxproj.filters b/msvc/UKControllerPlugin/UKControllerPlugin.vcxproj.filters index c545c8237..2d6e0aa6a 100644 --- a/msvc/UKControllerPlugin/UKControllerPlugin.vcxproj.filters +++ b/msvc/UKControllerPlugin/UKControllerPlugin.vcxproj.filters @@ -549,21 +549,6 @@ src\offblock - - src\timedevent - - - src\timedevent - - - src\timedevent - - - src\timedevent - - - src\flightplan - resource @@ -1031,7 +1016,7 @@ src\timer - + src\push @@ -1067,7 +1052,7 @@ src\push - + src\releases @@ -1428,15 +1413,6 @@ src\euroscope - - src\timedevent - - - src\timedevent - - - src\flightplan - src\pch @@ -1857,7 +1833,7 @@ src\push - + src\releases @@ -1885,4 +1861,4 @@ src\releases - + \ No newline at end of file diff --git a/msvc/UKControllerPluginTest/UKControllerPluginTest.vcxproj b/msvc/UKControllerPluginTest/UKControllerPluginTest.vcxproj index db79eddae..847c85a70 100644 --- a/msvc/UKControllerPluginTest/UKControllerPluginTest.vcxproj +++ b/msvc/UKControllerPluginTest/UKControllerPluginTest.vcxproj @@ -82,7 +82,6 @@ - @@ -252,8 +251,6 @@ - - @@ -275,7 +272,6 @@ - @@ -292,7 +288,6 @@ - @@ -303,7 +298,6 @@ - diff --git a/msvc/UKControllerPluginTest/UKControllerPluginTest.vcxproj.filters b/msvc/UKControllerPluginTest/UKControllerPluginTest.vcxproj.filters index 59e588eae..81f3cbc07 100644 --- a/msvc/UKControllerPluginTest/UKControllerPluginTest.vcxproj.filters +++ b/msvc/UKControllerPluginTest/UKControllerPluginTest.vcxproj.filters @@ -419,18 +419,6 @@ test\offblock - - test\timedevent - - - test\timedevent - - - test\timedevent - - - test\flightplan - helper @@ -924,9 +912,6 @@ mock - - mock - mock @@ -949,9 +934,6 @@ mock - - mock - helper @@ -980,4 +962,4 @@ - + \ No newline at end of file diff --git a/src/bootstrap/EventHandlerCollectionBootstrap.cpp b/src/bootstrap/EventHandlerCollectionBootstrap.cpp index c9bc2c5ae..1c7776711 100644 --- a/src/bootstrap/EventHandlerCollectionBootstrap.cpp +++ b/src/bootstrap/EventHandlerCollectionBootstrap.cpp @@ -9,7 +9,6 @@ #include "timedevent/TimedEventCollection.h" #include "plugin/FunctionCallEventHandler.h" #include "metar/MetarEventHandlerCollection.h" -#include "timedevent/DeferredEventHandler.h" #include "euroscope/UserSettingAwareCollection.h" #include "plugin/UKPlugin.h" #include "command/CommandHandlerCollection.h" @@ -23,7 +22,6 @@ using UKControllerPlugin::Controller::ControllerStatusEventHandlerCollection; using UKControllerPlugin::TimedEvent::TimedEventCollection; using UKControllerPlugin::Plugin::FunctionCallEventHandler; using UKControllerPlugin::Metar::MetarEventHandlerCollection; -using UKControllerPlugin::TimedEvent::DeferredEventHandler; using UKControllerPlugin::Euroscope::UserSettingAwareCollection; using UKControllerPlugin::Command::CommandHandlerCollection; using UKControllerPlugin::Euroscope::RunwayDialogAwareCollection; @@ -44,11 +42,9 @@ namespace UKControllerPlugin { persistence.timedHandler.reset(new TimedEventCollection); persistence.pluginFunctionHandlers.reset(new FunctionCallEventHandler); persistence.metarEventHandler.reset(new MetarEventHandlerCollection); - persistence.deferredHandlers.reset(new DeferredEventHandler); persistence.userSettingHandlers.reset(new UserSettingAwareCollection); persistence.commandHandlers.reset(new CommandHandlerCollection); persistence.runwayDialogEventHandlers.reset(new RunwayDialogAwareCollection); - persistence.timedHandler->RegisterEvent(persistence.deferredHandlers, 3); persistence.controllerHandoffHandlers.reset(new HandoffEventHandlerCollection); } } // namespace Bootstrap diff --git a/src/bootstrap/InitialisePlugin.cpp b/src/bootstrap/InitialisePlugin.cpp index 390cf1b19..8906238b7 100644 --- a/src/bootstrap/InitialisePlugin.cpp +++ b/src/bootstrap/InitialisePlugin.cpp @@ -42,7 +42,6 @@ #include "squawk/SquawkModule.h" #include "srd/SrdModule.h" #include "stands/StandModule.h" -#include "timedevent/DeferredEventBootstrap.h" #include "update/PluginVersion.h" #include "wake/WakeModule.h" #include "push/PushEventBootstrap.h" @@ -76,7 +75,6 @@ using UKControllerPlugin::Prenote::PrenoteModule; using UKControllerPlugin::Message::UserMessagerBootstrap; using UKControllerPlugin::Euroscope::PluginUserSettingBootstrap; using UKControllerPlugin::Duplicate::DuplicatePlugin; -using UKControllerPlugin::TimedEvent::DeferredEventBootstrap; using UKControllerPlugin::Datablock::EstimatedDepartureTimeBootstrap; using UKControllerPlugin::Euroscope::GeneralSettingsConfigurationBootstrap; using UKControllerPlugin::Dependency::DependencyLoader; @@ -207,7 +205,6 @@ namespace UKControllerPlugin { Wake::BootstrapPlugin(*this->container, loader); LoginModule::BootstrapPlugin(*this->container); - DeferredEventBootstrap(*this->container->timedHandler); SectorFile::BootstrapPlugin(*this->container); // General settings config bootstrap diff --git a/src/bootstrap/PersistenceContainer.h b/src/bootstrap/PersistenceContainer.h index 214c596fa..36dffdbf2 100644 --- a/src/bootstrap/PersistenceContainer.h +++ b/src/bootstrap/PersistenceContainer.h @@ -32,7 +32,6 @@ #include "message/UserMessager.h" #include "euroscope/UserSetting.h" #include "command/CommandHandlerCollection.h" -#include "timedevent/DeferredEventHandler.h" #include "login/Login.h" #include "hold/HoldManager.h" #include "euroscope/UserSettingAwareCollection.h" @@ -87,8 +86,7 @@ namespace UKControllerPlugin { std::unique_ptr metarEventHandler; std::unique_ptr screenControls; std::unique_ptr commandHandlers; - std::shared_ptr deferredHandlers; - std::shared_ptr userSettingHandlers; + std::shared_ptr userSettingHandlers; std::unique_ptr runwayDialogEventHandlers; std::unique_ptr controllerHandoffHandlers; std::shared_ptr externalEventHandler; diff --git a/src/initialaltitude/InitialAltitudeEventHandler.cpp b/src/initialaltitude/InitialAltitudeEventHandler.cpp index 76a137b95..17f2054ec 100644 --- a/src/initialaltitude/InitialAltitudeEventHandler.cpp +++ b/src/initialaltitude/InitialAltitudeEventHandler.cpp @@ -4,9 +4,7 @@ #include "euroscope/EuroScopeCRadarTargetInterface.h" #include "ownership/AirfieldOwnershipManager.h" #include "controller/ActiveCallsignCollection.h" -#include "timedevent/DeferredEventHandler.h" #include "login/Login.h" -#include "flightplan/DeferredFlightplanEvent.h" #include "euroscope/EuroscopePluginLoopbackInterface.h" #include "euroscope/GeneralSettingsEntries.h" #include "sid/SidCollection.h" @@ -20,10 +18,7 @@ using UKControllerPlugin::Ownership::AirfieldOwnershipManager; using UKControllerPlugin::Controller::ActiveCallsignCollection; using UKControllerPlugin::Controller::ActiveCallsign; using UKControllerPlugin::Airfield::NormaliseSid; -using UKControllerPlugin::TimedEvent::DeferredEventHandler; using UKControllerPlugin::Controller::Login; -using UKControllerPlugin::Flightplan::DeferredFlightPlanEvent; -using UKControllerPlugin::Flightplan::StoredFlightplanCollection; using UKControllerPlugin::Euroscope::EuroscopePluginLoopbackInterface; using UKControllerPlugin::Euroscope::GeneralSettingsEntries; @@ -35,13 +30,10 @@ namespace UKControllerPlugin { const ActiveCallsignCollection & activeCallsigns, const AirfieldOwnershipManager & airfieldOwnership, const Login & login, - DeferredEventHandler & deferredEvents, - EuroscopePluginLoopbackInterface & plugin, - const StoredFlightplanCollection& storedFlightplans + EuroscopePluginLoopbackInterface& plugin ) : minimumLoginTimeBeforeAssignment(5), sids(sids), activeCallsigns(activeCallsigns), - airfieldOwnership(airfieldOwnership), deferredEvents(deferredEvents), login(login), - storedFlightplans(storedFlightplans), plugin(plugin) + airfieldOwnership(airfieldOwnership), login(login), plugin(plugin) { } @@ -60,11 +52,8 @@ namespace UKControllerPlugin { // If we've not been logged in for long, wait a bit if (this->login.GetSecondsLoggedIn() < this->minimumLoginTimeBeforeAssignment) { LogDebug( - "Deferring initial altitude assignment for " + flightPlan.GetCallsign() - ); - this->deferredEvents.DeferFor( - std::make_unique(*this, this->plugin, flightPlan.GetCallsign()), - this->minimumLoginTimeBeforeAssignment + "Deferring initial altitude assignment for " + flightPlan.GetCallsign() + + " for now, user has only recently logged in" ); return; } @@ -105,10 +94,6 @@ namespace UKControllerPlugin { this->alreadySetMap[flightPlan.GetCallsign()] = flightPlan.GetSidName(); } - InitialAltitudeEventHandler::~InitialAltitudeEventHandler(void) - { - } - /* Handle events regarding when a flightplan disconnects. */ @@ -228,24 +213,8 @@ namespace UKControllerPlugin { } - LogInfo("Mass assigning initial altitudes"); - - std::shared_ptr fp; - std::shared_ptr rt; - for ( - StoredFlightplanCollection::const_iterator it = this->storedFlightplans.cbegin(); - it != this->storedFlightplans.cend(); - ++it - ) { - fp = this->plugin.GetFlightplanForCallsign(it->second->GetCallsign()); - rt = this->plugin.GetRadarTargetForCallsign(it->second->GetCallsign()); - - if (!fp || !rt) { - continue; - } - - this->FlightPlanEvent(*fp, *rt); - } + LogInfo("User now active, mass assigning initial altitudes"); + this->CheckAllFlightplansForAssignment(); } /* @@ -264,12 +233,39 @@ namespace UKControllerPlugin { } + /* + * Periodically, check all flightplans to see if they need an initial altitude update. + */ + void InitialAltitudeEventHandler::TimedEventTrigger() + { + if (!this->activeCallsigns.UserHasCallsign()) { + return; + } + + this->CheckAllFlightplansForAssignment(); + } + + /* + * Loop all the flightplans and check if they need an assignment. + */ + void InitialAltitudeEventHandler::CheckAllFlightplansForAssignment() + { + this->plugin.ApplyFunctionToAllFlightplans( + [this] + ( + std::shared_ptr fp, + std::shared_ptr rt + ) + { + this->FlightPlanEvent(*fp, *rt); + } + ); + } + /* Called when user settings get updated. */ - void InitialAltitudeEventHandler::UserSettingsUpdated( - UKControllerPlugin::Euroscope::UserSetting & userSettings - ) + void InitialAltitudeEventHandler::UserSettingsUpdated(Euroscope::UserSetting& userSettings) { this->userAutomaticAssignmentsAllowed = userSettings.GetBooleanEntry( GeneralSettingsEntries::initialAltitudeToggleSettingsKey, diff --git a/src/initialaltitude/InitialAltitudeEventHandler.h b/src/initialaltitude/InitialAltitudeEventHandler.h index e28357199..b00e09b1e 100644 --- a/src/initialaltitude/InitialAltitudeEventHandler.h +++ b/src/initialaltitude/InitialAltitudeEventHandler.h @@ -1,10 +1,9 @@ #pragma once #include "flightplan/FlightPlanEventHandlerInterface.h" #include "airfield/NormaliseSid.h" -#include "timedevent/DeferredEventHandler.h" #include "euroscope/UserSettingAwareInterface.h" #include "controller/ActiveCallsignEventHandlerInterface.h" -#include "flightplan/StoredFlightplanCollection.h" +#include "timedevent/AbstractTimedEvent.h" // Forward declarations @@ -24,9 +23,6 @@ namespace UKControllerPlugin { class SidCollection; class StandardInstrumentDeparture; } // namespace Sid - namespace TimedEvent { - class DeferredEventHandler; - } // namespace TimedEvent namespace Euroscope { class EuroscopePluginLoopbackInterface; } // namespace Euroscope @@ -38,51 +34,51 @@ namespace UKControllerPlugin { /* Class that responds to events related to initial altitudes. */ - class InitialAltitudeEventHandler : public UKControllerPlugin::Flightplan::FlightPlanEventHandlerInterface, - public UKControllerPlugin::Euroscope::UserSettingAwareInterface, - public UKControllerPlugin::Controller::ActiveCallsignEventHandlerInterface + class InitialAltitudeEventHandler : public Flightplan::FlightPlanEventHandlerInterface, + public Euroscope::UserSettingAwareInterface, + public Controller::ActiveCallsignEventHandlerInterface, + public TimedEvent::AbstractTimedEvent { public: InitialAltitudeEventHandler( const Sid::SidCollection& sids, - const UKControllerPlugin::Controller::ActiveCallsignCollection & activeCallsigns, - const UKControllerPlugin::Ownership::AirfieldOwnershipManager & airfieldOwnership, - const UKControllerPlugin::Controller::Login & login, - UKControllerPlugin::TimedEvent::DeferredEventHandler & deferredEvents, - UKControllerPlugin::Euroscope::EuroscopePluginLoopbackInterface & plugin, - const UKControllerPlugin::Flightplan::StoredFlightplanCollection& storedFlightplans + const Controller::ActiveCallsignCollection& activeCallsigns, + const Ownership::AirfieldOwnershipManager& airfieldOwnership, + const Controller::Login& login, + Euroscope::EuroscopePluginLoopbackInterface& plugin ); void FlightPlanEvent( - UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface & flightPlan, - UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface & radarTarget + Euroscope::EuroScopeCFlightPlanInterface& flightPlan, + Euroscope::EuroScopeCRadarTargetInterface& radarTarget ) override; - ~InitialAltitudeEventHandler(void); + ~InitialAltitudeEventHandler() override = default; void FlightPlanDisconnectEvent( - UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface & flightPlan + Euroscope::EuroScopeCFlightPlanInterface& flightPlan ) override; void ControllerFlightPlanDataEvent( - UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface & flightPlan, + Euroscope::EuroScopeCFlightPlanInterface& flightPlan, int dataType ) override; void RecycleInitialAltitude( - UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface & flightPlan, - UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface & radarTarget, + Euroscope::EuroScopeCFlightPlanInterface& flightPlan, + Euroscope::EuroScopeCRadarTargetInterface& radarTarget, std::string context, const POINT & mousePos ); bool UserAutomaticAssignmentsAllowed(void) const; - void UserSettingsUpdated(UKControllerPlugin::Euroscope::UserSetting & userSettings) override; + void UserSettingsUpdated(Euroscope::UserSetting& userSettings) override; // Inherited via ActiveCallsignEventHandlerInterface void ActiveCallsignAdded( - const UKControllerPlugin::Controller::ActiveCallsign& callsign, + const Controller::ActiveCallsign& callsign, bool userCallsign ) override; void ActiveCallsignRemoved( - const UKControllerPlugin::Controller::ActiveCallsign& callsign, + const Controller::ActiveCallsign& callsign, bool userCallsign ) override; void CallsignsFlushed(void) override; + void TimedEventTrigger() override; // The maximum distance from the airfield that an aircraft can be untracked // to be considered for an altitude update. @@ -98,14 +94,15 @@ namespace UKControllerPlugin { const std::chrono::seconds minimumLoginTimeBeforeAssignment; private: + void CheckAllFlightplansForAssignment(); bool MeetsAssignmentConditions( Euroscope::EuroScopeCFlightPlanInterface& flightPlan, Euroscope::EuroScopeCRadarTargetInterface& radarTarget ) const; static bool MeetsForceAssignmentConditions( - UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface & flightplan, - UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface & radarTarget + Euroscope::EuroScopeCFlightPlanInterface& flightplan, + Euroscope::EuroScopeCRadarTargetInterface& radarTarget ); std::shared_ptr GetSidForFlight( @@ -116,25 +113,19 @@ namespace UKControllerPlugin { const Sid::SidCollection& sids; // Used to find out the users callsign. - const UKControllerPlugin::Controller::ActiveCallsignCollection & activeCallsigns; + const Controller::ActiveCallsignCollection& activeCallsigns; // Used to find out if the user owns a particular airfield. - const UKControllerPlugin::Ownership::AirfieldOwnershipManager & airfieldOwnership; - - // So we can defer loading IAs on first login - UKControllerPlugin::TimedEvent::DeferredEventHandler & deferredEvents; + const Ownership::AirfieldOwnershipManager& airfieldOwnership; // For checking how long we've been logged in - const UKControllerPlugin::Controller::Login & login; + const Controller::Login& login; // Class for parsing SIDs and removing deprecation warnings. - const UKControllerPlugin::Airfield::NormaliseSid normalise; - - // Stored flightplans - const UKControllerPlugin::Flightplan::StoredFlightplanCollection& storedFlightplans; + const Airfield::NormaliseSid normalise; // So we can get flightplans after deferred events - UKControllerPlugin::Euroscope::EuroscopePluginLoopbackInterface & plugin; + Euroscope::EuroscopePluginLoopbackInterface& plugin; // Has the user enabled automatic assignments bool userAutomaticAssignmentsAllowed = true; diff --git a/src/initialaltitude/InitialAltitudeModule.cpp b/src/initialaltitude/InitialAltitudeModule.cpp index 4e2054255..c95af51f2 100644 --- a/src/initialaltitude/InitialAltitudeModule.cpp +++ b/src/initialaltitude/InitialAltitudeModule.cpp @@ -25,9 +25,7 @@ namespace UKControllerPlugin { *persistence.activeCallsigns, *persistence.airfieldOwnership, *persistence.login, - *persistence.deferredHandlers, - *persistence.plugin, - *persistence.flightplans + *persistence.plugin ) ); @@ -35,6 +33,7 @@ namespace UKControllerPlugin { persistence.userSettingHandlers->RegisterHandler(initialAltitudeEventHandler); persistence.flightplanHandler->RegisterHandler(initialAltitudeEventHandler); persistence.activeCallsigns->AddHandler(initialAltitudeEventHandler); + persistence.timedHandler->RegisterEvent(initialAltitudeEventHandler, 10); TagFunction recycleFunction( diff --git a/src/initialheading/InitialHeadingEventHandler.cpp b/src/initialheading/InitialHeadingEventHandler.cpp index ee7890b0c..872998b18 100644 --- a/src/initialheading/InitialHeadingEventHandler.cpp +++ b/src/initialheading/InitialHeadingEventHandler.cpp @@ -4,9 +4,7 @@ #include "euroscope/EuroScopeCRadarTargetInterface.h" #include "ownership/AirfieldOwnershipManager.h" #include "controller/ActiveCallsignCollection.h" -#include "timedevent/DeferredEventHandler.h" #include "login/Login.h" -#include "flightplan/DeferredFlightplanEvent.h" #include "euroscope/EuroscopePluginLoopbackInterface.h" #include "euroscope/GeneralSettingsEntries.h" #include "sid/SidCollection.h" @@ -20,10 +18,7 @@ using UKControllerPlugin::Ownership::AirfieldOwnershipManager; using UKControllerPlugin::Controller::ActiveCallsignCollection; using UKControllerPlugin::Controller::ActiveCallsign; using UKControllerPlugin::Airfield::NormaliseSid; -using UKControllerPlugin::TimedEvent::DeferredEventHandler; using UKControllerPlugin::Controller::Login; -using UKControllerPlugin::Flightplan::DeferredFlightPlanEvent; -using UKControllerPlugin::Flightplan::StoredFlightplanCollection; using UKControllerPlugin::Euroscope::EuroscopePluginLoopbackInterface; using UKControllerPlugin::Euroscope::GeneralSettingsEntries; @@ -35,14 +30,10 @@ namespace UKControllerPlugin { const ActiveCallsignCollection& activeCallsigns, const AirfieldOwnershipManager& airfieldOwnership, const Login& login, - DeferredEventHandler& deferredEvents, - EuroscopePluginLoopbackInterface& plugin, - const StoredFlightplanCollection& storedFlightplans + EuroscopePluginLoopbackInterface& plugin ) : minimumLoginTimeBeforeAssignment(5), sids(sids), activeCallsigns(activeCallsigns), - airfieldOwnership(airfieldOwnership), deferredEvents(deferredEvents), login(login), - storedFlightplans(storedFlightplans), - plugin(plugin) + airfieldOwnership(airfieldOwnership), login(login), plugin(plugin) { } /* @@ -61,10 +52,7 @@ namespace UKControllerPlugin { if (this->login.GetSecondsLoggedIn() < this->minimumLoginTimeBeforeAssignment) { LogDebug( "Deferring initial heading assignment for " + flightPlan.GetCallsign() - ); - this->deferredEvents.DeferFor( - std::make_unique(*this, this->plugin, flightPlan.GetCallsign()), - this->minimumLoginTimeBeforeAssignment + + " for now, as user only just logged in" ); return; } @@ -101,9 +89,6 @@ namespace UKControllerPlugin { this->alreadySetMap[flightPlan.GetCallsign()] = flightPlan.GetSidName(); } - InitialHeadingEventHandler::~InitialHeadingEventHandler(void) - { } - /* Handle events regarding when a flightplan disconnects. */ @@ -160,6 +145,19 @@ namespace UKControllerPlugin { return this->userAutomaticAssignmentsAllowed; } + void InitialHeadingEventHandler::CheckAllFlightplansForAssignment() + { + this->plugin.ApplyFunctionToAllFlightplans( + [this] + ( + std::shared_ptr fp, + std::shared_ptr rt + ) + { + this->FlightPlanEvent(*fp, *rt); + } + ); + } /* Returns true if the aircraft meets the prerequisites for initial heading assignment. @@ -225,25 +223,8 @@ namespace UKControllerPlugin { return; } - - LogInfo("Mass assigning initial headings"); - - std::shared_ptr fp; - std::shared_ptr rt; - for ( - StoredFlightplanCollection::const_iterator it = this->storedFlightplans.cbegin(); - it != this->storedFlightplans.cend(); - ++it - ) { - fp = this->plugin.GetFlightplanForCallsign(it->second->GetCallsign()); - rt = this->plugin.GetRadarTargetForCallsign(it->second->GetCallsign()); - - if (!fp || !rt) { - continue; - } - - this->FlightPlanEvent(*fp, *rt); - } + LogInfo("User now active, mass assigning initial headings"); + this->CheckAllFlightplansForAssignment(); } /* @@ -258,6 +239,15 @@ namespace UKControllerPlugin { void InitialHeadingEventHandler::CallsignsFlushed(void) { } + void InitialHeadingEventHandler::TimedEventTrigger() + { + if (!this->activeCallsigns.UserHasCallsign()) { + return; + } + + this->CheckAllFlightplansForAssignment(); + } + /* Called when user settings get updated. */ diff --git a/src/initialheading/InitialHeadingEventHandler.h b/src/initialheading/InitialHeadingEventHandler.h index bba3d8846..4ae8578e8 100644 --- a/src/initialheading/InitialHeadingEventHandler.h +++ b/src/initialheading/InitialHeadingEventHandler.h @@ -1,10 +1,9 @@ #pragma once #include "flightplan/FlightPlanEventHandlerInterface.h" #include "airfield/NormaliseSid.h" -#include "timedevent/DeferredEventHandler.h" #include "euroscope/UserSettingAwareInterface.h" #include "controller/ActiveCallsignEventHandlerInterface.h" -#include "flightplan/StoredFlightplanCollection.h" +#include "timedevent/AbstractTimedEvent.h" // Forward declarations @@ -24,9 +23,6 @@ namespace UKControllerPlugin { class SidCollection; class StandardInstrumentDeparture; } // namespace Sid - namespace TimedEvent { - class DeferredEventHandler; - } // namespace TimedEvent namespace Euroscope { class EuroscopePluginLoopbackInterface; } // namespace Euroscope @@ -40,7 +36,8 @@ namespace UKControllerPlugin { */ class InitialHeadingEventHandler : public Flightplan::FlightPlanEventHandlerInterface, public Euroscope::UserSettingAwareInterface, - public Controller::ActiveCallsignEventHandlerInterface + public Controller::ActiveCallsignEventHandlerInterface, + public TimedEvent::AbstractTimedEvent { public: InitialHeadingEventHandler( @@ -48,15 +45,13 @@ namespace UKControllerPlugin { const Controller::ActiveCallsignCollection& activeCallsigns, const Ownership::AirfieldOwnershipManager& airfieldOwnership, const Controller::Login& login, - TimedEvent::DeferredEventHandler& deferredEvents, - Euroscope::EuroscopePluginLoopbackInterface& plugin, - const Flightplan::StoredFlightplanCollection& storedFlightplans + Euroscope::EuroscopePluginLoopbackInterface& plugin ); + ~InitialHeadingEventHandler() override = default; void FlightPlanEvent( Euroscope::EuroScopeCFlightPlanInterface& flightPlan, Euroscope::EuroScopeCRadarTargetInterface& radarTarget ) override; - ~InitialHeadingEventHandler(void); void FlightPlanDisconnectEvent( Euroscope::EuroScopeCFlightPlanInterface& flightPlan ) override; @@ -83,6 +78,7 @@ namespace UKControllerPlugin { bool userCallsign ) override; void CallsignsFlushed(void) override; + void TimedEventTrigger() override; // The maximum distance from the airfield that an aircraft can be untracked // to be considered for an heading update. @@ -98,6 +94,7 @@ namespace UKControllerPlugin { const std::chrono::seconds minimumLoginTimeBeforeAssignment; private: + void CheckAllFlightplansForAssignment(); bool MeetsAssignmentConditions( Euroscope::EuroScopeCFlightPlanInterface& flightPlan, Euroscope::EuroScopeCRadarTargetInterface& radarTarget @@ -121,18 +118,12 @@ namespace UKControllerPlugin { // Used to find out if the user owns a particular airfield. const Ownership::AirfieldOwnershipManager& airfieldOwnership; - // So we can defer loading IAs on first login - TimedEvent::DeferredEventHandler& deferredEvents; - // For checking how long we've been logged in const Controller::Login& login; // Class for parsing SIDs and removing deprecation warnings. const Airfield::NormaliseSid normalise; - // Stored flightplans - const Flightplan::StoredFlightplanCollection& storedFlightplans; - // So we can get flightplans after deferred events Euroscope::EuroscopePluginLoopbackInterface& plugin; diff --git a/src/initialheading/InitialHeadingModule.cpp b/src/initialheading/InitialHeadingModule.cpp index 002f01be2..3b211d1f1 100644 --- a/src/initialheading/InitialHeadingModule.cpp +++ b/src/initialheading/InitialHeadingModule.cpp @@ -16,7 +16,7 @@ namespace UKControllerPlugin { const int recycleFunctionId = 9011; /* - Initialises the initial altitude module. Gets the altitudes from the dependency cache + Initialises the initial heading module. Gets the headings from the dependency cache and registers the event handler to receive flightplan events. */ void BootstrapPlugin( @@ -28,14 +28,13 @@ namespace UKControllerPlugin { *persistence.activeCallsigns, *persistence.airfieldOwnership, *persistence.login, - *persistence.deferredHandlers, - *persistence.plugin, - *persistence.flightplans + *persistence.plugin ) ); persistence.userSettingHandlers->RegisterHandler(handler); persistence.flightplanHandler->RegisterHandler(handler); persistence.activeCallsigns->AddHandler(handler); + persistence.timedHandler->RegisterEvent(handler, 10); TagFunction recycleFunction( diff --git a/src/squawk/SquawkEventHandler.cpp b/src/squawk/SquawkEventHandler.cpp index d3f6a4c6d..834804d4e 100644 --- a/src/squawk/SquawkEventHandler.cpp +++ b/src/squawk/SquawkEventHandler.cpp @@ -1,6 +1,5 @@ #include "pch/stdafx.h" #include "squawk/SquawkEventHandler.h" -#include "controller/ControllerPosition.h" #include "euroscope/EuroScopeCFlightPlanInterface.h" #include "euroscope/EuroScopeCRadarTargetInterface.h" #include "euroscope/EuroscopePluginLoopbackInterface.h" @@ -9,8 +8,6 @@ #include "controller/ActiveCallsignCollection.h" #include "squawk/SquawkGenerator.h" #include "login/Login.h" -#include "timedevent/DeferredEventHandler.h" -#include "flightplan/DeferredFlightplanEvent.h" #include "euroscope/GeneralSettingsEntries.h" using UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface; @@ -24,8 +21,6 @@ using UKControllerPlugin::Controller::ActiveCallsign; using UKControllerPlugin::Squawk::SquawkAssignment; using UKControllerPlugin::Euroscope::EuroscopePluginLoopbackInterface; using UKControllerPlugin::Controller::Login; -using UKControllerPlugin::TimedEvent::DeferredEventHandler; -using UKControllerPlugin::Flightplan::DeferredFlightPlanEvent; using UKControllerPlugin::Euroscope::UserSetting; using UKControllerPlugin::Euroscope::GeneralSettingsEntries; @@ -38,17 +33,11 @@ namespace UKControllerPlugin { const StoredFlightplanCollection & storedFlightplans, EuroscopePluginLoopbackInterface & pluginLoopback, const Login & login, - DeferredEventHandler & deferredEvents, bool automaticAssignmentDisabled ) : generator(generator), activeCallsigns(activeCallsigns), storedFlightplans(storedFlightplans), - pluginLoopback(pluginLoopback), login(login), deferredEvents(deferredEvents), - automaticAssignmentDisabled(automaticAssignmentDisabled), minAutomaticAssignmentLoginTime(15) - { - - } - - SquawkEventHandler::~SquawkEventHandler() + pluginLoopback(pluginLoopback), login(login), automaticAssignmentDisabled(automaticAssignmentDisabled), + minAutomaticAssignmentLoginTime(15) { } @@ -65,25 +54,7 @@ namespace UKControllerPlugin { return; } - // If we haven't been logged in more than a certain time, defer squawk assignments - // to give EuroScope a chance to process controllers logged in / preexisting squawk assignments - // We defer by the wait time to space out the subsequent events. - if (this->login.GetSecondsLoggedIn() < this->minAutomaticAssignmentLoginTime) { - LogDebug( - "Deferring squawk assignment for " + flightplan.GetCallsign() + - " as only recently logged in" - ); - this->deferredEvents.DeferFor( - std::make_unique(*this, this->pluginLoopback, flightplan.GetCallsign()), - this->minAutomaticAssignmentLoginTime - ); - return; - } - - this->generator.AssignCircuitSquawkForAircraft(flightplan, radarTarget) || - this->generator.ReassignPreviousSquawkToAircraft(flightplan, radarTarget) || - this->generator.RequestLocalSquawkForAircraft(flightplan, radarTarget) || - this->generator.RequestGeneralSquawkForAircraft(flightplan, radarTarget); + this->AttemptAssignment(flightplan, radarTarget); } /* @@ -151,28 +122,7 @@ namespace UKControllerPlugin { return; } - std::shared_ptr fp; - std::shared_ptr rt; - for ( - StoredFlightplanCollection::const_iterator it = this->storedFlightplans.cbegin(); - it != this->storedFlightplans.cend(); - ++it - ) { - fp = this->pluginLoopback.GetFlightplanForCallsign(it->second->GetCallsign()); - rt = this->pluginLoopback.GetRadarTargetForCallsign(it->second->GetCallsign()); - - if (!fp || !rt) { - continue; - } - - if (fp->HasAssignedSquawk() || !fp->IsTrackedByUser()) { - continue; - } - - if (!this->generator.RequestLocalSquawkForAircraft(*fp, *rt)) { - this->generator.RequestGeneralSquawkForAircraft(*fp, *rt); - } - } + this->AttemptAssignSquawksToAllAircraft(); } /* @@ -204,24 +154,8 @@ namespace UKControllerPlugin { return; } - LogInfo("Mass assigning squawks"); - - std::shared_ptr fp; - std::shared_ptr rt; - for ( - StoredFlightplanCollection::const_iterator it = this->storedFlightplans.cbegin(); - it != this->storedFlightplans.cend(); - ++it - ) { - fp = this->pluginLoopback.GetFlightplanForCallsign(it->second->GetCallsign()); - rt = this->pluginLoopback.GetRadarTargetForCallsign(it->second->GetCallsign()); - - if (!fp || !rt) { - continue; - } - - this->FlightPlanEvent(*fp, *rt); - } + LogInfo("User is now an active callsign, mass assigning squawks"); + this->AttemptAssignSquawksToAllAircraft(); } /* @@ -238,5 +172,42 @@ namespace UKControllerPlugin { void SquawkEventHandler::CallsignsFlushed(void) { } + + void SquawkEventHandler::AttemptAssignment( + EuroScopeCFlightPlanInterface& flightplan, + EuroScopeCRadarTargetInterface& radarTarget + ) const + { + if (this->login.GetSecondsLoggedIn() < this->minAutomaticAssignmentLoginTime) { + LogDebug( + "Skipping squawk assignment for " + flightplan.GetCallsign() + + " for now, as only recently logged in" + ); + return; + } + + this->generator.AssignCircuitSquawkForAircraft(flightplan, radarTarget) || + this->generator.ReassignPreviousSquawkToAircraft(flightplan, radarTarget) || + this->generator.RequestLocalSquawkForAircraft(flightplan, radarTarget) || + this->generator.RequestGeneralSquawkForAircraft(flightplan, radarTarget); + } + + void SquawkEventHandler::AttemptAssignSquawksToAllAircraft() const + { + this->pluginLoopback.ApplyFunctionToAllFlightplans( + [this] + ( + std::shared_ptr fp, + std::shared_ptr rt + ) + { + if (fp->HasAssignedSquawk() || fp->IsTracked() && !fp->IsTrackedByUser()) { + return; + } + + this->AttemptAssignment(*fp, *rt); + } + ); + } } // namespace Squawk } // namespace UKControllerPlugin diff --git a/src/squawk/SquawkEventHandler.h b/src/squawk/SquawkEventHandler.h index ce45a5068..444a6a843 100644 --- a/src/squawk/SquawkEventHandler.h +++ b/src/squawk/SquawkEventHandler.h @@ -24,10 +24,7 @@ namespace UKControllerPlugin { namespace Squawk { class SquawkGenerator; } // namespace Squawk - namespace TimedEvent { - class DeferredEventHandler; - } // namespace TimedEvent -} // namespace UKControllerPlugin +} // namespace UKControllerPlugin namespace UKControllerPlugin { @@ -45,10 +42,9 @@ namespace UKControllerPlugin { const UKControllerPlugin::Flightplan::StoredFlightplanCollection & storedFlightplans, UKControllerPlugin::Euroscope::EuroscopePluginLoopbackInterface & pluginLoopback, const UKControllerPlugin::Controller::Login & login, - UKControllerPlugin::TimedEvent::DeferredEventHandler & deferredEvents, bool automaticAssignmentAllowed ); - ~SquawkEventHandler(); + ~SquawkEventHandler() override = default; void FlightPlanEvent( UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface & flightPlan, UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface & radarTarget @@ -97,6 +93,12 @@ namespace UKControllerPlugin { const bool automaticAssignmentDisabled = true; private: + void AttemptAssignment( + Euroscope::EuroScopeCFlightPlanInterface& flightplan, + Euroscope::EuroScopeCRadarTargetInterface& radarTarget + ) const; + + void AttemptAssignSquawksToAllAircraft() const; // Generates squawks UKControllerPlugin::Squawk::SquawkGenerator & generator; @@ -110,9 +112,6 @@ namespace UKControllerPlugin { // Handles requests to the plugin core. UKControllerPlugin::Euroscope::EuroscopePluginLoopbackInterface & pluginLoopback; - // If an event needs deferring, put it here. - UKControllerPlugin::TimedEvent::DeferredEventHandler & deferredEvents; - // Duration we have to be logged in to start doing automatic squawk assignments. const std::chrono::seconds minAutomaticAssignmentLoginTime; diff --git a/src/squawk/SquawkModule.cpp b/src/squawk/SquawkModule.cpp index 0474433cf..695afa26b 100644 --- a/src/squawk/SquawkModule.cpp +++ b/src/squawk/SquawkModule.cpp @@ -53,14 +53,13 @@ namespace UKControllerPlugin { *container.flightplans, *container.plugin, *container.login, - *container.deferredHandlers, automaticAssignmentDisabled ) ); container.squawkEvents = eventHandler; container.flightplanHandler->RegisterHandler(eventHandler); - container.timedHandler->RegisterEvent(eventHandler, SquawkModule::trackedAircraftCheckFrequency); + container.timedHandler->RegisterEvent(eventHandler, squawkAssignmentsCheckFrequency); container.userSettingHandlers->RegisterHandler(eventHandler); container.activeCallsigns->AddHandler(eventHandler); diff --git a/src/squawk/SquawkModule.h b/src/squawk/SquawkModule.h index 0d55e81d8..c64ed6b3c 100644 --- a/src/squawk/SquawkModule.h +++ b/src/squawk/SquawkModule.h @@ -21,7 +21,7 @@ namespace UKControllerPlugin { ); // How often to check for tracked aircraft that don't have squawks. - static const int trackedAircraftCheckFrequency = 5; + static const int squawkAssignmentsCheckFrequency = 5; // How often to check for new API allocations static const int allocationCheckFrequency = 3; diff --git a/test/mock/MockDeferredEventRunner.h b/test/mock/MockDeferredEventRunner.h deleted file mode 100644 index 991e948ee..000000000 --- a/test/mock/MockDeferredEventRunner.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once -#include "timedevent/DeferredEventRunnerInterface.h" - -namespace UKControllerPluginTest { - namespace TimedEvent { - - class MockDeferredEventRunner : public UKControllerPlugin::TimedEvent::DeferredEventRunnerInterface - { - public: - explicit MockDeferredEventRunner(int & timesRun) - : timesRun(timesRun) - { - - } - - void Run(void) override - { - timesRun++; - } - - int TimesRun(void) const - { - return this->timesRun; - } - - - protected: - - // How many times the deferred event has run - int & timesRun; - }; - } // namespace TimedEvent -} // namespace UKControllerPluginTest diff --git a/test/mock/MockEuroscopePluginLoopbackInterface.h b/test/mock/MockEuroscopePluginLoopbackInterface.h index 8e9868dd9..a04bf0c61 100644 --- a/test/mock/MockEuroscopePluginLoopbackInterface.h +++ b/test/mock/MockEuroscopePluginLoopbackInterface.h @@ -88,6 +88,10 @@ namespace UKControllerPluginTest { > function ) override { + if (this->expectFlightplanLoopNoFire) { + throw std::logic_error("Was not expecting the flightplan loop"); + } + for ( std::list::const_iterator it = this->allFpRtPairs.cbegin(); @@ -114,11 +118,18 @@ namespace UKControllerPluginTest { } }; + void ExpectNoFlightplanLoop() + { + this->expectFlightplanLoopNoFire = true; + } + private: std::list allFpRtPairs; std::list< std::shared_ptr > allControllers; + + bool expectFlightplanLoopNoFire = false; }; } // namespace Euroscope } // namespace UKControllerPluginTest diff --git a/test/mock/MockInitialAltitudeEventHandler.h b/test/mock/MockInitialAltitudeEventHandler.h deleted file mode 100644 index dc6ef63e9..000000000 --- a/test/mock/MockInitialAltitudeEventHandler.h +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once -#include "pch/pch.h" -#include "initialaltitude/InitialAltitudeEventHandler.h" -#include "initialaltitude/InitialAltitudeGenerator.h" -#include "controller/ActiveCallsignCollection.h" -#include "ownership/AirfieldOwnershipManager.h" -#include "euroscope/EuroScopeCFlightPlanInterface.h" -#include "euroscope/EuroScopeCRadarTargetInterface.h" -#include "euroscope/EuroscopePluginLoopbackInterface.h" -#include "login/Login.h" -#include "timedevent/DeferredEventRunnerInterface.h" -#include "flightplan/StoredFlightplanCollection.h" - -namespace UKControllerPluginTest { - namespace EventHandler { - - class MockInitialAltitudeEventHandler : public UKControllerPlugin::InitialAltitude::InitialAltitudeEventHandler - { - public: - MockInitialAltitudeEventHandler() : InitialAltitudeEventHandler( - *generator, - *activeCallsigns, - *airfieldOwnership, - *login, - *deferredEvents, - *plugin, - *storedFlightplans - ) {} - MOCK_METHOD2( - FlightPlanEvent, - void( - UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface & flightPlan, - UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface & target) - ); - MOCK_METHOD1( - FlightPlanDisconnectEvent, - void(UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface & flightPlan) - ); - MOCK_METHOD1( - ControllerFlightPlanDataEvent, - void(UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface & flightPlan) - ); - - private: - - // Some dummy things so we can build the mock. - std::unique_ptr generator; - std::unique_ptr activeCallsigns; - std::unique_ptr airfieldOwnership; - std::unique_ptr login; - std::unique_ptr deferredEvents; - std::unique_ptr plugin; - std::unique_ptr storedFlightplans; - }; - } // namespace EventHandler -} // namespace UKControllerPluginTest diff --git a/test/mock/MockSquawkEventHandler.h b/test/mock/MockSquawkEventHandler.h index 84e35f3ed..5a9fd6343 100644 --- a/test/mock/MockSquawkEventHandler.h +++ b/test/mock/MockSquawkEventHandler.h @@ -7,7 +7,6 @@ #include "squawk/SquawkAssignment.h" #include "flightplan/StoredFlightplanCollection.h" #include "login/Login.h" -#include "timedevent/DeferredEventHandler.h" namespace UKControllerPluginTest { namespace Squawk { @@ -21,7 +20,6 @@ namespace UKControllerPluginTest { *plans, *pluginLoopback, *login, - *deferred, false ) { } @@ -48,7 +46,6 @@ namespace UKControllerPluginTest { std::unique_ptr plans; std::unique_ptr pluginLoopback; std::unique_ptr login; - std::unique_ptr deferred; }; } // namespace Squawk } // namespace UKControllerPluginTest diff --git a/test/test/bootstrap/EventHandlerCollectionBootstrapTest.cpp b/test/test/bootstrap/EventHandlerCollectionBootstrapTest.cpp index 7d696d738..0ef8ea1ac 100644 --- a/test/test/bootstrap/EventHandlerCollectionBootstrapTest.cpp +++ b/test/test/bootstrap/EventHandlerCollectionBootstrapTest.cpp @@ -58,11 +58,6 @@ namespace UKControllerPluginTest { EXPECT_EQ(0, this->container.metarEventHandler->CountHandlers()); } - TEST_F(EventHandlerCollectionBootstrapTest, BootstrapPluginCreatesDefferedEventHandler) - { - EXPECT_EQ(0, this->container.deferredHandlers->Count()); - } - TEST_F(EventHandlerCollectionBootstrapTest, BootstrapPluginCreatesUserSettingAwareHandler) { EXPECT_EQ(0, this->container.userSettingHandlers->Count()); @@ -78,12 +73,6 @@ namespace UKControllerPluginTest { EXPECT_EQ(0, this->container.runwayDialogEventHandlers->CountHandlers()); } - TEST_F(EventHandlerCollectionBootstrapTest, BootstrapPluginRegistersDeferredHandlersForTimedEvents) - { - EXPECT_EQ(1, this->container.timedHandler->CountHandlers()); - EXPECT_EQ(1, this->container.timedHandler->CountHandlersForFrequency(3)); - } - TEST_F(EventHandlerCollectionBootstrapTest, BootstrapPluginCreatesHandoffHandlers) { EXPECT_EQ(0, this->container.controllerHandoffHandlers->CountHandlers()); diff --git a/test/test/controller/ActiveCallsignMonitorTest.cpp b/test/test/controller/ActiveCallsignMonitorTest.cpp index 936ebf64f..ce4f4d51c 100644 --- a/test/test/controller/ActiveCallsignMonitorTest.cpp +++ b/test/test/controller/ActiveCallsignMonitorTest.cpp @@ -10,7 +10,6 @@ #include "mock/MockEuroScopeCFlightplanInterface.h" #include "mock/MockEuroScopeCRadarTargetInterface.h" #include "flightplan/StoredFlightplan.h" -#include "timedevent/DeferredEventHandler.h" #include "login/Login.h" #include "controller/ControllerStatusEventHandlerCollection.h" @@ -26,7 +25,6 @@ using UKControllerPluginTest::Euroscope::MockEuroScopeCFlightPlanInterface; using UKControllerPluginTest::Euroscope::MockEuroScopeCRadarTargetInterface; using UKControllerPlugin::Flightplan::StoredFlightplan; using UKControllerPlugin::Controller::Login; -using UKControllerPlugin::TimedEvent::DeferredEventHandler; using UKControllerPlugin::Controller::ControllerStatusEventHandlerCollection; using ::testing::Test; @@ -125,7 +123,6 @@ namespace UKControllerPluginTest { StoredFlightplanCollection flightplans; NiceMock plugin; Login login; - DeferredEventHandler deferredEvents; ActiveCallsignCollection activeCallsigns; ActiveCallsignMonitor handler; diff --git a/test/test/flightplan/DeferredFlightplanEventTest.cpp b/test/test/flightplan/DeferredFlightplanEventTest.cpp deleted file mode 100644 index 51eae4ce2..000000000 --- a/test/test/flightplan/DeferredFlightplanEventTest.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#pragma once -#include "pch/pch.h" -#include "flightplan/DeferredFlightplanEvent.h" -#include "mock/MockFlightPlanEventHandlerInterface.h" -#include "mock/MockEuroscopePluginLoopbackInterface.h" -#include "mock/MockEuroScopeCFlightplanInterface.h" -#include "mock/MockEuroScopeCRadarTargetInterface.h" - -using UKControllerPlugin::Flightplan::DeferredFlightPlanEvent; -using UKControllerPluginTest::Euroscope::MockEuroscopePluginLoopbackInterface; -using UKControllerPluginTest::Flightplan::MockFlightPlanEventHandlerInterface; -using UKControllerPluginTest::Euroscope::MockEuroScopeCFlightPlanInterface; -using UKControllerPluginTest::Euroscope::MockEuroScopeCRadarTargetInterface; - -using ::testing::Test; -using ::testing::NiceMock; -using ::testing::Return; -using ::testing::Throw; -using ::testing::Ref; - -namespace UKControllerPluginTest { - namespace Flightplan { - - class DeferredFlightplanEventTest : public Test - { - public: - - DeferredFlightplanEventTest() - : event(mockHandler, mockPlugin, callsign) - { - this->mockFlightplan = std::make_shared>(); - this->mockRadarTarget = std::make_shared>(); - } - - const std::string callsign = "BAW123"; - NiceMock mockPlugin; - NiceMock mockHandler; - std::shared_ptr> mockFlightplan; - std::shared_ptr> mockRadarTarget; - DeferredFlightPlanEvent event; - }; - - TEST_F(DeferredFlightplanEventTest, ItCallsTheHandlerWhenRun) - { - ON_CALL(this->mockPlugin, GetFlightplanForCallsign(this->callsign)) - .WillByDefault(Return(this->mockFlightplan)); - - ON_CALL(this->mockPlugin, GetRadarTargetForCallsign(this->callsign)) - .WillByDefault(Return(this->mockRadarTarget)); - - EXPECT_CALL(this->mockHandler, FlightPlanEvent(Ref(*this->mockFlightplan), Ref(*this->mockRadarTarget))) - .Times(1); - - this->event.Run(); - } - - TEST_F(DeferredFlightplanEventTest, ItHandlesMissingFlightplansGracefully) - { - ON_CALL(this->mockPlugin, GetFlightplanForCallsign(this->callsign)) - .WillByDefault(Return(nullptr)); - - ON_CALL(this->mockPlugin, GetRadarTargetForCallsign(this->callsign)) - .WillByDefault(Return(this->mockRadarTarget)); - - EXPECT_NO_THROW(this->event.Run()); - } - - TEST_F(DeferredFlightplanEventTest, ItHandlesMissingRadarTargetsGracefully) - { - ON_CALL(this->mockPlugin, GetFlightplanForCallsign(this->callsign)) - .WillByDefault(Return(this->mockFlightplan)); - - ON_CALL(this->mockPlugin, GetRadarTargetForCallsign(this->callsign)) - .WillByDefault(Return(nullptr)); - - EXPECT_NO_THROW(this->event.Run()); - } - - } // namespace Flightplan -} // namespace UKControllerPluginTest diff --git a/test/test/initialaltitude/InitialAltitudeEventHandlerTest.cpp b/test/test/initialaltitude/InitialAltitudeEventHandlerTest.cpp index 518d41bbf..62d0967c9 100644 --- a/test/test/initialaltitude/InitialAltitudeEventHandlerTest.cpp +++ b/test/test/initialaltitude/InitialAltitudeEventHandlerTest.cpp @@ -10,13 +10,10 @@ #include "airfield/AirfieldModel.h" #include "login/Login.h" #include "mock/MockEuroscopePluginLoopbackInterface.h" -#include "timedevent/DeferredEventHandler.h" #include "controller/ControllerStatusEventHandlerCollection.h" #include "mock/MockUserSettingProviderInterface.h" #include "euroscope/UserSetting.h" #include "euroscope/GeneralSettingsEntries.h" -#include "flightplan/StoredFlightplanCollection.h" -#include "flightplan/StoredFlightplan.h" #include "sid/SidCollection.h" #include "sid/StandardInstrumentDeparture.h" @@ -33,13 +30,10 @@ using UKControllerPlugin::Controller::ControllerPosition; using UKControllerPlugin::Airfield::AirfieldModel; using UKControllerPluginTest::Euroscope::MockEuroscopePluginLoopbackInterface; using UKControllerPlugin::Controller::Login; -using UKControllerPlugin::TimedEvent::DeferredEventHandler; using UKControllerPlugin::Controller::ControllerStatusEventHandlerCollection; using UKControllerPlugin::Euroscope::UserSetting; using UKControllerPluginTest::Euroscope::MockUserSettingProviderInterface; using UKControllerPlugin::Euroscope::GeneralSettingsEntries; -using UKControllerPlugin::Flightplan::StoredFlightplanCollection; -using UKControllerPlugin::Flightplan::StoredFlightplan; using ::testing::Test; using ::testing::StrictMock; @@ -56,7 +50,7 @@ namespace UKControllerPluginTest { InitialAltitudeEventHandlerTest() : owners(airfields, callsigns), login(plugin, ControllerStatusEventHandlerCollection()), - handler(sids, callsigns, owners, login, deferredEvents, plugin, flightplans), + handler(sids, callsigns, owners, login, plugin), controller(1, "LON_S_CTR", 129.420, {"EGKK"}, true, false), userCallsign("LON_S_CTR", "Test", controller) { @@ -70,19 +64,24 @@ namespace UKControllerPluginTest { sids.AddSid(std::make_shared("EGKK", "ADMAG2X", 6000, 0)); sids.AddSid(std::make_shared("EGKK", "CLN3X", 5000, 0)); + this->mockFlightplanPointer.reset(new NiceMock); + this->mockRadarTargetPointer.reset(new NiceMock); ON_CALL(mockFlightPlan, GetCallsign()) .WillByDefault(Return("BAW123")); + + ON_CALL(*mockFlightplanPointer, GetCallsign()) + .WillByDefault(Return("BAW123")); } ControllerPosition controller; ActiveCallsign userCallsign; AirfieldCollection airfields; - DeferredEventHandler deferredEvents; + std::shared_ptr> mockFlightplanPointer; + std::shared_ptr> mockRadarTargetPointer; NiceMock mockFlightPlan; NiceMock mockRadarTarget; NiceMock plugin; Login login; - StoredFlightplanCollection flightplans; ActiveCallsignCollection callsigns; AirfieldOwnershipManager owners; SidCollection sids; @@ -152,15 +151,15 @@ namespace UKControllerPluginTest { TEST_F(InitialAltitudeEventHandlerTest, FlightPlanEventDefersIfNotLoggedInLongEnough) { + EXPECT_CALL(this->mockFlightPlan, GetCallsign) + .Times(1) + .WillOnce(Return("BAW123")); + + EXPECT_CALL(this->mockRadarTarget, GetFlightLevel) + .Times(0); + login.SetLoginTime(std::chrono::system_clock::now() + std::chrono::minutes(15)); handler.FlightPlanEvent(mockFlightPlan, mockRadarTarget); - EXPECT_EQ(1, deferredEvents.Count()); - int64_t seconds = std::chrono::duration_cast ( - this->deferredEvents.NextEventTime() - std::chrono::system_clock::now() - ) - .count(); - EXPECT_LE(seconds, 5); - EXPECT_GT(seconds, 3); } TEST_F(InitialAltitudeEventHandlerTest, FlightPlanEventDoesNotAssignIfTooHigh) @@ -830,60 +829,54 @@ namespace UKControllerPluginTest { airfields.AddAirfield(std::unique_ptr(new AirfieldModel("EGKK", { "LON_S_CTR" }))); owners.RefreshOwner("EGKK"); - this->flightplans.UpdatePlan(StoredFlightplan("BAW123", "EGKK", "EGPF")); - - std::shared_ptr> mockReturnFlightplan = - std::make_shared>(); - - std::shared_ptr> mockReturnRadarTarget = - std::make_shared>(); + this->plugin.AddAllFlightplansItem({this->mockFlightplanPointer, this->mockRadarTargetPointer}); ON_CALL(this->plugin, GetFlightplanForCallsign("BAW123")) - .WillByDefault(Return(mockReturnFlightplan)); + .WillByDefault(Return(mockFlightplanPointer)); ON_CALL(this->plugin, GetRadarTargetForCallsign("BAW123")) - .WillByDefault(Return(mockReturnRadarTarget)); + .WillByDefault(Return(mockRadarTargetPointer)); - EXPECT_CALL(*mockReturnFlightplan, GetDistanceFromOrigin()) + EXPECT_CALL(*mockFlightplanPointer, GetDistanceFromOrigin()) .Times(2) .WillRepeatedly(Return(handler.assignmentMaxDistanceFromOrigin)); - EXPECT_CALL(*mockReturnFlightplan, HasControllerClearedAltitude()) + EXPECT_CALL(*mockFlightplanPointer, HasControllerClearedAltitude()) .Times(1) .WillOnce(Return(false)); - EXPECT_CALL(*mockReturnFlightplan, IsTracked()) + EXPECT_CALL(*mockFlightplanPointer, IsTracked()) .Times(1) .WillOnce(Return(false)); - EXPECT_CALL(*mockReturnFlightplan, IsSimulated()) + EXPECT_CALL(*mockFlightplanPointer, IsSimulated()) .Times(1) .WillOnce(Return(false)); - EXPECT_CALL(*mockReturnFlightplan, GetSidName()) + EXPECT_CALL(*mockFlightplanPointer, GetSidName()) .Times(2) .WillRepeatedly(Return("ADMAG2X")); - EXPECT_CALL(*mockReturnFlightplan, GetOrigin()) + EXPECT_CALL(*mockFlightplanPointer, GetOrigin()) .Times(3) .WillRepeatedly(Return("EGKK")); - EXPECT_CALL(*mockReturnFlightplan, GetCallsign()) + EXPECT_CALL(*mockFlightplanPointer, GetCallsign()) .Times(3) .WillRepeatedly(Return("BAW123")); - EXPECT_CALL(*mockReturnFlightplan, GetCruiseLevel()) + EXPECT_CALL(*mockFlightplanPointer, GetCruiseLevel()) .Times(1) .WillOnce(Return(6000)); - EXPECT_CALL(*mockReturnFlightplan, SetClearedAltitude(6000)) + EXPECT_CALL(*mockFlightplanPointer, SetClearedAltitude(6000)) .Times(1); - EXPECT_CALL(*mockReturnRadarTarget, GetGroundSpeed()) + EXPECT_CALL(*mockRadarTargetPointer, GetGroundSpeed()) .Times(1) .WillOnce(Return(handler.assignmentMaxSpeed)); - EXPECT_CALL(*mockReturnRadarTarget, GetFlightLevel()) + EXPECT_CALL(*mockRadarTargetPointer, GetFlightLevel()) .Times(2) .WillRepeatedly(Return(handler.assignmentMaxSpeed)); @@ -895,12 +888,81 @@ namespace UKControllerPluginTest { callsigns.AddCallsign(userCallsign); airfields.AddAirfield(std::unique_ptr(new AirfieldModel("EGKK", { "LON_S_CTR" }))); owners.RefreshOwner("EGKK"); - this->flightplans.UpdatePlan(StoredFlightplan("BAW123", "EGKK", "EGPF")); - - EXPECT_CALL(mockFlightPlan, SetClearedAltitude(6000)) - .Times(0); + this->plugin.AddAllFlightplansItem({this->mockFlightplanPointer, this->mockRadarTargetPointer}); + this->plugin.ExpectNoFlightplanLoop(); handler.ActiveCallsignAdded(userCallsign, false); } + + TEST_F(InitialAltitudeEventHandlerTest, TimedEventAssignsIfUserCallsign) + { + callsigns.AddUserCallsign(userCallsign); + + airfields.AddAirfield(std::make_unique("EGKK", std::vector{"LON_S_CTR"})); + owners.RefreshOwner("EGKK"); + this->plugin.AddAllFlightplansItem({this->mockFlightplanPointer, this->mockRadarTargetPointer}); + + ON_CALL(this->plugin, GetFlightplanForCallsign("BAW123")) + .WillByDefault(Return(mockFlightplanPointer)); + + ON_CALL(this->plugin, GetRadarTargetForCallsign("BAW123")) + .WillByDefault(Return(mockRadarTargetPointer)); + + EXPECT_CALL(*mockFlightplanPointer, GetDistanceFromOrigin()) + .Times(2) + .WillRepeatedly(Return(handler.assignmentMaxDistanceFromOrigin)); + + EXPECT_CALL(*mockFlightplanPointer, HasControllerClearedAltitude()) + .Times(1) + .WillOnce(Return(false)); + + EXPECT_CALL(*mockFlightplanPointer, IsTracked()) + .Times(1) + .WillOnce(Return(false)); + + EXPECT_CALL(*mockFlightplanPointer, IsSimulated()) + .Times(1) + .WillOnce(Return(false)); + + EXPECT_CALL(*mockFlightplanPointer, GetSidName()) + .Times(2) + .WillRepeatedly(Return("ADMAG2X")); + + EXPECT_CALL(*mockFlightplanPointer, GetOrigin()) + .Times(3) + .WillRepeatedly(Return("EGKK")); + + EXPECT_CALL(*mockFlightplanPointer, GetCallsign()) + .Times(3) + .WillRepeatedly(Return("BAW123")); + + EXPECT_CALL(*mockFlightplanPointer, GetCruiseLevel()) + .Times(1) + .WillOnce(Return(6000)); + + EXPECT_CALL(*mockFlightplanPointer, SetClearedAltitude(6000)) + .Times(1); + + EXPECT_CALL(*mockRadarTargetPointer, GetGroundSpeed()) + .Times(1) + .WillOnce(Return(handler.assignmentMaxSpeed)); + + EXPECT_CALL(*mockRadarTargetPointer, GetFlightLevel()) + .Times(2) + .WillRepeatedly(Return(handler.assignmentMaxSpeed)); + + handler.TimedEventTrigger(); + } + + TEST_F(InitialAltitudeEventHandlerTest, TimedEventDoesNotAssignIfNoUserCallsign) + { + callsigns.AddCallsign(userCallsign); + airfields.AddAirfield(std::make_unique("EGKK", std::vector{"LON_S_CTR"})); + owners.RefreshOwner("EGKK"); + this->plugin.AddAllFlightplansItem({this->mockFlightplanPointer, this->mockRadarTargetPointer}); + this->plugin.ExpectNoFlightplanLoop(); + + handler.TimedEventTrigger(); + } } // namespace InitialAltitude } // namespace UKControllerPluginTest diff --git a/test/test/initialaltitude/InitialAltitudeModuleTest.cpp b/test/test/initialaltitude/InitialAltitudeModuleTest.cpp index 8543ef444..572081ca7 100644 --- a/test/test/initialaltitude/InitialAltitudeModuleTest.cpp +++ b/test/test/initialaltitude/InitialAltitudeModuleTest.cpp @@ -5,6 +5,7 @@ #include "euroscope/UserSettingAwareCollection.h" #include "plugin/FunctionCallEventHandler.h" #include "controller/ActiveCallsignCollection.h" +#include "timedevent/TimedEventCollection.h" using UKControllerPlugin::InitialAltitude::InitialAltitudeModule; using UKControllerPlugin::Bootstrap::PersistenceContainer; @@ -12,8 +13,9 @@ using UKControllerPlugin::Flightplan::FlightPlanEventHandlerCollection; using UKControllerPlugin::Euroscope::UserSettingAwareCollection; using UKControllerPlugin::Plugin::FunctionCallEventHandler; using UKControllerPlugin::Controller::ActiveCallsignCollection; -using ::testing::Test; -using ::testing::NiceMock; +using UKControllerPlugin::TimedEvent::TimedEventCollection; +using testing::Test; +using testing::NiceMock; namespace UKControllerPluginTest { namespace InitialAltitude { @@ -28,6 +30,7 @@ namespace UKControllerPluginTest { container.userSettingHandlers = std::make_unique(); container.pluginFunctionHandlers = std::make_unique(); container.activeCallsigns = std::make_unique(); + container.timedHandler = std::make_unique(); } PersistenceContainer container; @@ -57,5 +60,12 @@ namespace UKControllerPluginTest { InitialAltitudeModule::BootstrapPlugin(this->container); EXPECT_EQ(1, container.userSettingHandlers->Count()); } + + TEST_F(InitialAltitudeModuleTest, BootstrapPluginRegistersTimedEvents) + { + InitialAltitudeModule::BootstrapPlugin(this->container); + EXPECT_EQ(1, container.timedHandler->CountHandlers()); + EXPECT_EQ(1, container.timedHandler->CountHandlersForFrequency(10)); + } } // namespace InitialAltitude } // namespace UKControllerPluginTest diff --git a/test/test/initialheading/InitialHeadingEventHandlerTest.cpp b/test/test/initialheading/InitialHeadingEventHandlerTest.cpp index 06dcb8cb9..2cf58964f 100644 --- a/test/test/initialheading/InitialHeadingEventHandlerTest.cpp +++ b/test/test/initialheading/InitialHeadingEventHandlerTest.cpp @@ -10,13 +10,10 @@ #include "airfield/AirfieldModel.h" #include "login/Login.h" #include "mock/MockEuroscopePluginLoopbackInterface.h" -#include "timedevent/DeferredEventHandler.h" #include "controller/ControllerStatusEventHandlerCollection.h" #include "mock/MockUserSettingProviderInterface.h" #include "euroscope/UserSetting.h" #include "euroscope/GeneralSettingsEntries.h" -#include "flightplan/StoredFlightplanCollection.h" -#include "flightplan/StoredFlightplan.h" #include "sid/SidCollection.h" #include "sid/StandardInstrumentDeparture.h" @@ -33,13 +30,10 @@ using UKControllerPlugin::Controller::ControllerPosition; using UKControllerPlugin::Airfield::AirfieldModel; using UKControllerPluginTest::Euroscope::MockEuroscopePluginLoopbackInterface; using UKControllerPlugin::Controller::Login; -using UKControllerPlugin::TimedEvent::DeferredEventHandler; using UKControllerPlugin::Controller::ControllerStatusEventHandlerCollection; using UKControllerPlugin::Euroscope::UserSetting; using UKControllerPluginTest::Euroscope::MockUserSettingProviderInterface; using UKControllerPlugin::Euroscope::GeneralSettingsEntries; -using UKControllerPlugin::Flightplan::StoredFlightplanCollection; -using UKControllerPlugin::Flightplan::StoredFlightplan; using ::testing::Test; using ::testing::StrictMock; @@ -57,7 +51,7 @@ namespace UKControllerPluginTest { InitialHeadingEventHandlerTest() : owners(airfields, callsigns), login(plugin, ControllerStatusEventHandlerCollection()), - handler(sids, callsigns, owners, login, deferredEvents, plugin, flightplans), + handler(sids, callsigns, owners, login, plugin), controller(1, "LON_S_CTR", 129.420, {"EGKK"}, true, false), userCallsign("LON_S_CTR", "Test", controller) { @@ -72,20 +66,25 @@ namespace UKControllerPluginTest { sids.AddSid(std::make_shared("EGKK", "CLN3X", 5000, 200)); sids.AddSid(std::make_shared("EGKK", "DAGGA1X", 5000, 0)); + this->mockFlightplanPointer.reset(new NiceMock); + this->mockRadarTargetPointer.reset(new NiceMock); ON_CALL(mockFlightPlan, GetCallsign()) .WillByDefault(Return("BAW123")); + + ON_CALL(*mockFlightplanPointer, GetCallsign()) + .WillByDefault(Return("BAW123")); } ControllerPosition controller; ActiveCallsign userCallsign; AirfieldCollection airfields; - DeferredEventHandler deferredEvents; + std::shared_ptr> mockFlightplanPointer; + std::shared_ptr> mockRadarTargetPointer; NiceMock mockFlightPlan; NiceMock mockRadarTarget; NiceMock plugin; Login login; - StoredFlightplanCollection flightplans; ActiveCallsignCollection callsigns; AirfieldOwnershipManager owners; SidCollection sids; @@ -155,15 +154,15 @@ namespace UKControllerPluginTest { TEST_F(InitialHeadingEventHandlerTest, FlightPlanEventDefersIfNotLoggedInLongEnough) { + EXPECT_CALL(this->mockFlightPlan, GetCallsign) + .Times(1) + .WillOnce(Return("BAW123")); + + EXPECT_CALL(this->mockRadarTarget, GetFlightLevel) + .Times(0); + login.SetLoginTime(std::chrono::system_clock::now() + std::chrono::minutes(15)); handler.FlightPlanEvent(mockFlightPlan, mockRadarTarget); - EXPECT_EQ(1, deferredEvents.Count()); - int64_t seconds = std::chrono::duration_cast ( - this->deferredEvents.NextEventTime() - std::chrono::system_clock::now() - ) - .count(); - EXPECT_LE(seconds, 5); - EXPECT_GT(seconds, 3); } TEST_F(InitialHeadingEventHandlerTest, FlightPlanEventDoesNotAssignIfTooHigh) @@ -829,75 +828,122 @@ namespace UKControllerPluginTest { { callsigns.AddUserCallsign(userCallsign); - airfields.AddAirfield(std::unique_ptr(new AirfieldModel("EGKK", { "LON_S_CTR" }))); + airfields.AddAirfield(std::make_unique("EGKK", std::vector{"LON_S_CTR"})); owners.RefreshOwner("EGKK"); - this->flightplans.UpdatePlan(StoredFlightplan("BAW123", "EGKK", "EGPF")); + this->plugin.AddAllFlightplansItem({this->mockFlightplanPointer, this->mockRadarTargetPointer}); + + EXPECT_CALL(*mockFlightplanPointer, GetDistanceFromOrigin()) + .Times(2) + .WillRepeatedly(Return(handler.assignmentMaxDistanceFromOrigin)); + + EXPECT_CALL(*mockFlightplanPointer, HasControllerAssignedHeading()) + .Times(1) + .WillOnce(Return(false)); + + EXPECT_CALL(*mockFlightplanPointer, IsTracked()) + .Times(1) + .WillOnce(Return(false)); + + EXPECT_CALL(*mockFlightplanPointer, IsSimulated()) + .Times(1) + .WillOnce(Return(false)); + + EXPECT_CALL(*mockFlightplanPointer, GetSidName()) + .Times(2) + .WillRepeatedly(Return("ADMAG2X")); + + EXPECT_CALL(*mockFlightplanPointer, GetOrigin()) + .Times(3) + .WillRepeatedly(Return("EGKK")); + + EXPECT_CALL(*mockFlightplanPointer, GetCallsign()) + .Times(3) + .WillRepeatedly(Return("BAW123")); - std::shared_ptr> mockReturnFlightplan = - std::make_shared>(); + EXPECT_CALL(*mockFlightplanPointer, SetHeading(125)) + .Times(1); - std::shared_ptr> mockReturnRadarTarget = - std::make_shared>(); + EXPECT_CALL(*mockRadarTargetPointer, GetGroundSpeed()) + .Times(1) + .WillOnce(Return(handler.assignmentMaxSpeed)); + + EXPECT_CALL(*mockRadarTargetPointer, GetFlightLevel()) + .Times(2) + .WillRepeatedly(Return(handler.assignmentMaxSpeed)); - ON_CALL(this->plugin, GetFlightplanForCallsign("BAW123")) - .WillByDefault(Return(mockReturnFlightplan)); + handler.ActiveCallsignAdded(userCallsign, true); + } - ON_CALL(this->plugin, GetRadarTargetForCallsign("BAW123")) - .WillByDefault(Return(mockReturnRadarTarget)); + TEST_F(InitialHeadingEventHandlerTest, NewActiveCallsignDoesNotAssignIfNotUserCallsign) + { + callsigns.AddCallsign(userCallsign); + airfields.AddAirfield(std::make_unique("EGKK", std::vector{"LON_S_CTR"})); + owners.RefreshOwner("EGKK"); + this->plugin.AddAllFlightplansItem({this->mockFlightplanPointer, this->mockRadarTargetPointer}); + this->plugin.ExpectNoFlightplanLoop(); - EXPECT_CALL(*mockReturnFlightplan, GetDistanceFromOrigin()) + handler.ActiveCallsignAdded(userCallsign, false); + } + + TEST_F(InitialHeadingEventHandlerTest, TimedEventAssignsIfUserCallsign) + { + callsigns.AddUserCallsign(userCallsign); + + airfields.AddAirfield(std::make_unique("EGKK", std::vector{"LON_S_CTR"})); + owners.RefreshOwner("EGKK"); + this->plugin.AddAllFlightplansItem({this->mockFlightplanPointer, this->mockRadarTargetPointer}); + + EXPECT_CALL(*mockFlightplanPointer, GetDistanceFromOrigin()) .Times(2) .WillRepeatedly(Return(handler.assignmentMaxDistanceFromOrigin)); - EXPECT_CALL(*mockReturnFlightplan, HasControllerAssignedHeading()) + EXPECT_CALL(*mockFlightplanPointer, HasControllerAssignedHeading()) .Times(1) .WillOnce(Return(false)); - EXPECT_CALL(*mockReturnFlightplan, IsTracked()) + EXPECT_CALL(*mockFlightplanPointer, IsTracked()) .Times(1) .WillOnce(Return(false)); - EXPECT_CALL(*mockReturnFlightplan, IsSimulated()) + EXPECT_CALL(*mockFlightplanPointer, IsSimulated()) .Times(1) .WillOnce(Return(false)); - EXPECT_CALL(*mockReturnFlightplan, GetSidName()) + EXPECT_CALL(*mockFlightplanPointer, GetSidName()) .Times(2) .WillRepeatedly(Return("ADMAG2X")); - EXPECT_CALL(*mockReturnFlightplan, GetOrigin()) + EXPECT_CALL(*mockFlightplanPointer, GetOrigin()) .Times(3) .WillRepeatedly(Return("EGKK")); - EXPECT_CALL(*mockReturnFlightplan, GetCallsign()) + EXPECT_CALL(*mockFlightplanPointer, GetCallsign()) .Times(3) .WillRepeatedly(Return("BAW123")); - EXPECT_CALL(*mockReturnFlightplan, SetHeading(125)) + EXPECT_CALL(*mockFlightplanPointer, SetHeading(125)) .Times(1); - EXPECT_CALL(*mockReturnRadarTarget, GetGroundSpeed()) + EXPECT_CALL(*mockRadarTargetPointer, GetGroundSpeed()) .Times(1) .WillOnce(Return(handler.assignmentMaxSpeed)); - EXPECT_CALL(*mockReturnRadarTarget, GetFlightLevel()) + EXPECT_CALL(*mockRadarTargetPointer, GetFlightLevel()) .Times(2) .WillRepeatedly(Return(handler.assignmentMaxSpeed)); - handler.ActiveCallsignAdded(userCallsign, true); + handler.TimedEventTrigger(); } - TEST_F(InitialHeadingEventHandlerTest, NewActiveCallsignDoesNotAssignIfNotUserCallsign) + TEST_F(InitialHeadingEventHandlerTest, TimedEventDoesNotAssignIfNoUserCallsign) { callsigns.AddCallsign(userCallsign); - airfields.AddAirfield(std::unique_ptr(new AirfieldModel("EGKK", { "LON_S_CTR" }))); + airfields.AddAirfield(std::make_unique("EGKK", std::vector{"LON_S_CTR"})); owners.RefreshOwner("EGKK"); - this->flightplans.UpdatePlan(StoredFlightplan("BAW123", "EGKK", "EGPF")); + this->plugin.AddAllFlightplansItem({this->mockFlightplanPointer, this->mockRadarTargetPointer}); + this->plugin.ExpectNoFlightplanLoop(); - EXPECT_CALL(mockFlightPlan, SetHeading(6000)) - .Times(0); - - handler.ActiveCallsignAdded(userCallsign, false); + handler.TimedEventTrigger(); } } // namespace InitialHeading } // namespace UKControllerPluginTest diff --git a/test/test/initialheading/InitialHeadingModuleTest.cpp b/test/test/initialheading/InitialHeadingModuleTest.cpp index 984fa43aa..7a6ffda4d 100644 --- a/test/test/initialheading/InitialHeadingModuleTest.cpp +++ b/test/test/initialheading/InitialHeadingModuleTest.cpp @@ -5,6 +5,7 @@ #include "euroscope/UserSettingAwareCollection.h" #include "plugin/FunctionCallEventHandler.h" #include "controller/ActiveCallsignCollection.h" +#include "timedevent/TimedEventCollection.h" using UKControllerPlugin::InitialHeading::BootstrapPlugin; using UKControllerPlugin::Bootstrap::PersistenceContainer; @@ -12,6 +13,7 @@ using UKControllerPlugin::Flightplan::FlightPlanEventHandlerCollection; using UKControllerPlugin::Euroscope::UserSettingAwareCollection; using UKControllerPlugin::Plugin::FunctionCallEventHandler; using UKControllerPlugin::Controller::ActiveCallsignCollection; +using UKControllerPlugin::TimedEvent::TimedEventCollection; using ::testing::Test; using ::testing::NiceMock; @@ -28,6 +30,7 @@ namespace UKControllerPluginTest { container.userSettingHandlers = std::make_unique(); container.pluginFunctionHandlers = std::make_unique(); container.activeCallsigns = std::make_unique(); + container.timedHandler = std::make_unique(); } PersistenceContainer container; @@ -57,5 +60,12 @@ namespace UKControllerPluginTest { BootstrapPlugin(this->container); EXPECT_EQ(1, container.userSettingHandlers->Count()); } + + TEST_F(InitialHeadingModuleTest, BootstrapPluginRegistersForTimedEvents) + { + BootstrapPlugin(this->container); + EXPECT_EQ(1, container.timedHandler->CountHandlers()); + EXPECT_EQ(1, container.timedHandler->CountHandlersForFrequency(10)); + } } // namespace InitialHeading } // namespace UKControllerPluginTest diff --git a/test/test/ownership/AirfieldOwnershipHandlerTest.cpp b/test/test/ownership/AirfieldOwnershipHandlerTest.cpp index 063312c6d..17058ef2e 100644 --- a/test/test/ownership/AirfieldOwnershipHandlerTest.cpp +++ b/test/test/ownership/AirfieldOwnershipHandlerTest.cpp @@ -16,7 +16,6 @@ #include "mock/MockSquawkEventHandler.h" #include "flightplan/StoredFlightplan.h" #include "message/UserMessager.h" -#include "timedevent/DeferredEventHandler.h" #include "login/Login.h" #include "controller/ControllerStatusEventHandlerCollection.h" #include "sid/SidCollection.h" @@ -42,7 +41,6 @@ using UKControllerPluginTest::Squawk::MockSquawkEventHandler; using UKControllerPlugin::Flightplan::StoredFlightplan; using UKControllerPlugin::Message::UserMessager; using UKControllerPlugin::Controller::Login; -using UKControllerPlugin::TimedEvent::DeferredEventHandler; using UKControllerPlugin::Controller::ControllerStatusEventHandlerCollection; using ::testing::Test; @@ -65,9 +63,7 @@ namespace UKControllerPluginTest { this->activeCallsigns, this->ownership, this->login, - this->deferredEvents, - this->plugin, - this->flightplans + this->plugin ) ), userMessager(this->plugin), @@ -180,7 +176,6 @@ namespace UKControllerPluginTest { std::shared_ptr initialAltitudes; NiceMock plugin; Login login; - DeferredEventHandler deferredEvents; ActiveCallsignCollection activeCallsigns; UserMessager userMessager; AirfieldOwnershipHandler handler; diff --git a/test/test/squawk/SquawkEventHandlerTest.cpp b/test/test/squawk/SquawkEventHandlerTest.cpp index 9e390cdf9..dbd4149e9 100644 --- a/test/test/squawk/SquawkEventHandlerTest.cpp +++ b/test/test/squawk/SquawkEventHandlerTest.cpp @@ -21,7 +21,6 @@ #include "squawk/SquawkAssignment.h" #include "login/Login.h" #include "controller/ControllerStatusEventHandlerCollection.h" -#include "timedevent/DeferredEventHandler.h" #include "euroscope/UserSetting.h" #include "mock/MockUserSettingProviderInterface.h" #include "euroscope/GeneralSettingsEntries.h" @@ -53,7 +52,6 @@ using UKControllerPluginTest::Windows::MockWinApi; using UKControllerPluginTest::Api::MockApiInterface; using UKControllerPlugin::Controller::Login; using UKControllerPlugin::Controller::ControllerStatusEventHandlerCollection; -using UKControllerPlugin::TimedEvent::DeferredEventHandler; using UKControllerPlugin::Euroscope::UserSetting; using UKControllerPluginTest::Euroscope::MockUserSettingProviderInterface; using UKControllerPlugin::Euroscope::GeneralSettingsEntries; @@ -99,7 +97,6 @@ namespace UKControllerPluginTest { this->plans, this->pluginLoopback, this->login, - this->deferredEvents, false ), userCallsign("EGKK_APP", "Testy McTestface", this->controller) @@ -205,6 +202,12 @@ namespace UKControllerPluginTest { .WillByDefault(Return(mockFlightplan)); } + void ExpectNoAssignment() + { + EXPECT_CALL(*this->mockFlightplan, SetSquawk(_)) + .Times(0); + } + void AssertGeneralAssignment() { ApiSquawkAllocation allocation{ "BAW1252", "1423" }; @@ -219,7 +222,6 @@ namespace UKControllerPluginTest { EXPECT_TRUE(allocation == this->apiSquawkAllocations->First()); } - DeferredEventHandler deferredEvents; Login login; NiceMock pluginLoopback; std::shared_ptr> mockFlightplan; @@ -295,21 +297,14 @@ namespace UKControllerPluginTest { EXPECT_NO_THROW(this->handler.FlightPlanEvent(mockFp, mockRt)); } - TEST_F(SquawkEventHandlerTest, FlightplanEventDefersFor10SecondsIfNotLoggedInLongEnough) + TEST_F(SquawkEventHandlerTest, FlightplanEventDefersIfNotLoggedInLongEnough) { - ON_CALL(*this->mockFlightplan, GetCallsign()) - .WillByDefault(Return("BAW123")); + EXPECT_CALL(*this->mockFlightplan, GetCallsign()) + .Times(1) + .WillOnce(Return("BAW123")); this->login.SetLoginTime(std::chrono::system_clock::now()); this->handler.FlightPlanEvent(*this->mockFlightplan, *this->mockRadarTarget); - - EXPECT_EQ(1, this->deferredEvents.Count()); - int64_t seconds = std::chrono::duration_cast ( - this->deferredEvents.NextEventTime() - std::chrono::system_clock::now() - ) - .count(); - EXPECT_LE(seconds, 15); - EXPECT_GT(seconds, 13); } TEST_F(SquawkEventHandlerTest, FlightplanEventReassignsOldSquawk) @@ -455,16 +450,13 @@ namespace UKControllerPluginTest { TEST_F(SquawkEventHandlerTest, TimedEventTriggerDoesNothingIfUserNotActive) { - this->plans.UpdatePlan(StoredFlightplan("BAW1252", "EGKK", "EGPF")); - ON_CALL(this->pluginLoopback, GetFlightplanForCallsign(_)) - .WillByDefault(Throw(std::exception("test"))); + this->pluginLoopback.ExpectNoFlightplanLoop(); SquawkEventHandler handler( this->generator, ActiveCallsignCollection(), this->plans, this->pluginLoopback, this->login, - this->deferredEvents, true ); EXPECT_NO_THROW(handler.TimedEventTrigger()); @@ -472,16 +464,13 @@ namespace UKControllerPluginTest { TEST_F(SquawkEventHandlerTest, TimedEventTriggerDoesNothingIfAutoAssignDisabled) { - this->plans.UpdatePlan(StoredFlightplan("BAW1252", "EGKK", "EGPF")); - ON_CALL(this->pluginLoopback, GetFlightplanForCallsign(_)) - .WillByDefault(Throw(std::exception("test"))); + this->pluginLoopback.ExpectNoFlightplanLoop(); SquawkEventHandler handler( this->generator, this->activeCallsigns, this->plans, this->pluginLoopback, this->login, - this->deferredEvents, true ); EXPECT_NO_THROW(handler.TimedEventTrigger()); @@ -496,9 +485,7 @@ namespace UKControllerPluginTest { .Times(1) .WillOnce(Return("0")); - this->plans.UpdatePlan(StoredFlightplan("BAW1252", "EGKK", "EGPF")); - ON_CALL(this->pluginLoopback, GetFlightplanForCallsign(_)) - .WillByDefault(Throw(std::exception("test"))); + this->pluginLoopback.ExpectNoFlightplanLoop(); this->handler.UserSettingsUpdated(userSetting); EXPECT_NO_THROW(handler.TimedEventTrigger()); @@ -509,34 +496,56 @@ namespace UKControllerPluginTest { ON_CALL(*this->mockFlightplan, HasAssignedSquawk) .WillByDefault(Return(true)); - ON_CALL(this->pluginLoopback, GetFlightplanForCallsign) - .WillByDefault(Return(this->mockFlightplan)); + this->pluginLoopback.AddAllFlightplansItem({this->mockFlightplan, this->mockRadarTarget}); EXPECT_NO_THROW(handler.TimedEventTrigger()); } - TEST_F(SquawkEventHandlerTest, TimedEventTriggerDoesNothingIfFlightplanNotTrackedByUser) + TEST_F(SquawkEventHandlerTest, TimedEventTriggerDoesNothingIfAircraftTrackedByAnotherController) { - ON_CALL(*this->mockFlightplan, HasAssignedSquawk) + ON_CALL(*this->mockFlightplan, HasAssignedSquawk) .WillByDefault(Return(false)); - ON_CALL(*this->mockFlightplan, IsTrackedByUser) + ON_CALL(*this->mockFlightplan, IsTrackedByUser) .WillByDefault(Return(false)); - ON_CALL(this->pluginLoopback, GetFlightplanForCallsign) - .WillByDefault(Return(this->mockFlightplan)); + ON_CALL(*this->mockFlightplan, IsTracked) + .WillByDefault(Return(true)); + + this->pluginLoopback.AddAllFlightplansItem({this->mockFlightplan, this->mockRadarTarget}); - EXPECT_NO_THROW(handler.TimedEventTrigger()); + EXPECT_NO_THROW(handler.TimedEventTrigger()); } - TEST_F(SquawkEventHandlerTest, TimedEventTriggerDoesSquawkAssignmentWhereAppropriate) + TEST_F(SquawkEventHandlerTest, TimedEventTriggerDoesSquawkAssignmentForTrackedByUserAircraft) { - this->plans.UpdatePlan(StoredFlightplan("BAW1252", "EGKK", "EGPF")); + this->pluginLoopback.AddAllFlightplansItem({this->mockFlightplan, this->mockRadarTarget}); + + ON_CALL(*this->mockFlightplan, HasAssignedSquawk) + .WillByDefault(Return(false)); + + ON_CALL(*this->mockFlightplan, IsTrackedByUser) + .WillByDefault(Return(true)); + + ON_CALL(*this->mockFlightplan, IsTracked) + .WillByDefault(Return(true)); + + ON_CALL(*this->mockRadarTarget, GetFlightLevel()) + .WillByDefault(Return(999999)); + + this->expectGeneralAssignment(); + handler.TimedEventTrigger(); + this->AssertGeneralAssignment(); + } + + TEST_F(SquawkEventHandlerTest, TimedEventTriggerDoesSquawkAssignmentForUntrackedAircraft) + { + this->pluginLoopback.AddAllFlightplansItem({this->mockFlightplan, this->mockRadarTarget}); ON_CALL(*this->mockFlightplan, HasAssignedSquawk) .WillByDefault(Return(false)); - ON_CALL(*this->mockFlightplan, IsTrackedByUser) + ON_CALL(*this->mockFlightplan, IsTracked) .WillByDefault(Return(true)); ON_CALL(*this->mockRadarTarget, GetFlightLevel()) @@ -549,7 +558,7 @@ namespace UKControllerPluginTest { TEST_F(SquawkEventHandlerTest, ActiveCallsignAddedAssignsAllSquawksWhenUserLogsOn) { - this->plans.UpdatePlan(StoredFlightplan("BAW1252", "EGKK", "EGPF")); + this->pluginLoopback.AddAllFlightplansItem({this->mockFlightplan, this->mockRadarTarget}); ON_CALL(*this->mockFlightplan, HasAssignedSquawk) .WillByDefault(Return(false)); @@ -563,6 +572,9 @@ namespace UKControllerPluginTest { ON_CALL(*this->mockFlightplan, GetDistanceFromOrigin) .WillByDefault(Return(1.0)); + EXPECT_CALL(*this->mockFlightplan, SetSquawk(testing::_)) + .Times(0); + this->expectGeneralAssignment(); handler.ActiveCallsignAdded(this->userCallsign, true); this->AssertGeneralAssignment(); @@ -570,7 +582,7 @@ namespace UKControllerPluginTest { TEST_F(SquawkEventHandlerTest, ActiveCallsignAddedDoesntAssignSquawkIfNotUserLogsOn) { - this->plans.UpdatePlan(StoredFlightplan("BAW1252", "EGKK", "EGPF")); + this->pluginLoopback.AddAllFlightplansItem({this->mockFlightplan, this->mockRadarTarget}); ON_CALL(*this->mockFlightplan, HasAssignedSquawk) .WillByDefault(Return(false)); @@ -581,6 +593,8 @@ namespace UKControllerPluginTest { ON_CALL(*this->mockRadarTarget, GetFlightLevel()) .WillByDefault(Return(999999)); + this->ExpectNoAssignment(); + handler.ActiveCallsignAdded(this->userCallsign, false); } } // namespace Squawk diff --git a/test/test/squawk/SquawkModuleTest.cpp b/test/test/squawk/SquawkModuleTest.cpp index 7641b4249..f6256b5b1 100644 --- a/test/test/squawk/SquawkModuleTest.cpp +++ b/test/test/squawk/SquawkModuleTest.cpp @@ -55,7 +55,7 @@ namespace UKControllerPluginTest { SquawkModule::BootstrapPlugin(container, false); EXPECT_EQ( 1, - this->container.timedHandler->CountHandlersForFrequency(SquawkModule::trackedAircraftCheckFrequency) + this->container.timedHandler->CountHandlersForFrequency(SquawkModule::squawkAssignmentsCheckFrequency) ); } diff --git a/test/test/timedevent/DeferredEventBootstrapTest.cpp b/test/test/timedevent/DeferredEventBootstrapTest.cpp deleted file mode 100644 index d4bcb78c8..000000000 --- a/test/test/timedevent/DeferredEventBootstrapTest.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include "pch/pch.h" -#include "timedevent/DeferredEventBootstrap.h" -#include "timedevent/TimedEventCollection.h" - -using UKControllerPlugin::TimedEvent::DeferredEventBootstrap; -using UKControllerPlugin::TimedEvent::TimedEventCollection; - -namespace UKControllerPluginTest { - namespace TimedEvent { - - TEST(DeferredEventBootstrapTest, ItRegistersForTimedEvents) - { - TimedEventCollection collection; - EXPECT_EQ(0, collection.CountHandlers()); - DeferredEventBootstrap(collection); - EXPECT_EQ(1, collection.CountHandlers()); - EXPECT_EQ(1, collection.CountHandlersForFrequency(5)); - } - - } // namespace TimedEvent -} // namespace UKControllerPluginTest diff --git a/test/test/timedevent/DeferredEventHandlerTest.cpp b/test/test/timedevent/DeferredEventHandlerTest.cpp deleted file mode 100644 index 20683f192..000000000 --- a/test/test/timedevent/DeferredEventHandlerTest.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#pragma once -#include "pch/pch.h" -#include "timedevent/DeferredEventHandler.h" -#include "mock/MockDeferredEventRunner.h" -#include "timedevent/DeferredEventRunnerInterface.h" - -using UKControllerPlugin::TimedEvent::DeferredEventHandler; -using UKControllerPluginTest::TimedEvent::MockDeferredEventRunner; -using UKControllerPlugin::TimedEvent::DeferredEventRunnerInterface; -using ::testing::Test; - -namespace UKControllerPluginTest { - namespace TimedEvent { - - class DeferredEventHandlerTest : public Test - { - public: - DeferredEventHandler handler; - }; - - TEST_F(DeferredEventHandlerTest, ItStartsEmpty) - { - EXPECT_EQ(0, this->handler.Count()); - } - - TEST_F(DeferredEventHandlerTest, ItAddsADeferredEvent) - { - int timesRun = 0; - this->handler.DeferFor( - std::unique_ptr(new MockDeferredEventRunner(timesRun)), - std::chrono::seconds(10) - ); - EXPECT_EQ(1, this->handler.Count()); - } - - TEST_F(DeferredEventHandlerTest, GetNextEventTimeReturnsMaxTimeIfNoevent) - { - EXPECT_EQ((std::chrono::system_clock::time_point::max)(), this->handler.NextEventTime()); - } - - TEST_F(DeferredEventHandlerTest, GetNextEventTimeReturnsTime) - { - int timesRun = 0; - this->handler.DeferFor( - std::unique_ptr(new MockDeferredEventRunner(timesRun)), - std::chrono::seconds(50) - ); - - std::chrono::seconds secondsFromNow = std::chrono::duration_cast( - this->handler.NextEventTime() - std::chrono::system_clock::now() - ); - EXPECT_TRUE(secondsFromNow.count() <= 50); - EXPECT_TRUE(secondsFromNow.count() >= 48); - } - - TEST_F(DeferredEventHandlerTest, ItDoesntRunNonReadyEvents) - { - int timesRun = 0; - this->handler.DeferFor( - std::unique_ptr (new MockDeferredEventRunner(timesRun)), - std::chrono::seconds(45) - ); - handler.TimedEventTrigger(); - EXPECT_EQ(0, timesRun); - } - - TEST_F(DeferredEventHandlerTest, ItRunsReadyEvents) - { - int timesRun = 0; - this->handler.DeferFor( - std::unique_ptr (new MockDeferredEventRunner(timesRun)), - std::chrono::seconds(-60) - ); - handler.TimedEventTrigger(); - EXPECT_EQ(1, timesRun); - } - - TEST_F(DeferredEventHandlerTest, ItRemovesRunEventsFromQueue) - { - int timesRun = 0; - this->handler.DeferFor( - std::unique_ptr(new MockDeferredEventRunner(timesRun)), - std::chrono::seconds(-60) - ); - handler.TimedEventTrigger(); - EXPECT_EQ(0, this->handler.Count()); - } - - TEST_F(DeferredEventHandlerTest, ItRunsEventsRegardlessOfInsertionOrder) - { - int timesRunEvent1 = 0; - int timesRunEvent2 = 0; - int timesRunEvent3 = 0; - - this->handler.DeferFor( - std::unique_ptr(new MockDeferredEventRunner(timesRunEvent1)), - std::chrono::seconds(-60) - ); - this->handler.DeferFor( - std::unique_ptr(new MockDeferredEventRunner(timesRunEvent2)), - std::chrono::seconds(60) - ); - this->handler.DeferFor( - std::unique_ptr(new MockDeferredEventRunner(timesRunEvent3)), - std::chrono::seconds(-60) - ); - this->handler.TimedEventTrigger(); - - EXPECT_EQ(1, timesRunEvent1); - EXPECT_EQ(0, timesRunEvent2); - EXPECT_EQ(1, timesRunEvent3); - } - - } // namespace TimedEvent -} // namespace UKControllerPluginTest diff --git a/test/test/timedevent/DeferredEventTest.cpp b/test/test/timedevent/DeferredEventTest.cpp deleted file mode 100644 index 009a1e399..000000000 --- a/test/test/timedevent/DeferredEventTest.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include "pch/pch.h" -#include "timedevent/DeferredEvent.h" -#include "mock/MockDeferredEventRunner.h" - -using UKControllerPlugin::TimedEvent::DeferredEvent; -using UKControllerPluginTest::TimedEvent::MockDeferredEventRunner; - -namespace UKControllerPluginTest { - namespace TimedEvent { - - TEST(DeferredEventTest, LessThanMeansEarlierTimepoint) - { - int foo = 0; - DeferredEvent earlier { - std::chrono::system_clock::now() - std::chrono::seconds(15), - std::make_unique(foo), - }; - - DeferredEvent later { - std::chrono::system_clock::now(), - std::make_unique(foo), - }; - - EXPECT_LT(earlier, later); - } - - } // namespace TimedEvent -} // namespace UKControllerPluginTest