diff --git a/tests/unit/wifi/helpers/AccessPointControllerTest.cxx b/tests/unit/wifi/helpers/AccessPointControllerTest.cxx index 1442a12f..fc99be10 100644 --- a/tests/unit/wifi/helpers/AccessPointControllerTest.cxx +++ b/tests/unit/wifi/helpers/AccessPointControllerTest.cxx @@ -1,33 +1,44 @@ +#include + #include +#include using namespace Microsoft::Net::Wifi; using namespace Microsoft::Net::Wifi::Test; -AccessPointControllerTest::AccessPointControllerTest(std::string_view interfaceName) : - InterfaceName(interfaceName) +AccessPointControllerTest::AccessPointControllerTest(AccessPointTest *accessPoint) : + AccessPoint(accessPoint) {} std::string_view AccessPointControllerTest::GetInterfaceName() const noexcept { - return InterfaceName; + return AccessPoint->InterfaceName; } bool AccessPointControllerTest::GetIsEnabled() { - return IsEnabled; + return AccessPoint->IsEnabled; } Ieee80211AccessPointCapabilities AccessPointControllerTest::GetCapabilities() { - return {}; // TODO: return something + return AccessPoint->Capabilities; } +AccessPointControllerFactoryTest::AccessPointControllerFactoryTest(AccessPointTest *accessPoint) : + AccessPoint(accessPoint) +{} + std::unique_ptr AccessPointControllerFactoryTest::Create(std::string_view interfaceName) { - return std::make_unique(interfaceName); + if (AccessPoint != nullptr && interfaceName != AccessPoint->InterfaceName) { + throw std::runtime_error("AccessPointControllerFactoryTest::Create called with unexpected interface name"); + } + + return std::make_unique(AccessPoint); } diff --git a/tests/unit/wifi/helpers/AccessPointTest.cxx b/tests/unit/wifi/helpers/AccessPointTest.cxx index 9236eef3..0caeafd7 100644 --- a/tests/unit/wifi/helpers/AccessPointTest.cxx +++ b/tests/unit/wifi/helpers/AccessPointTest.cxx @@ -1,6 +1,6 @@ -#include #include +#include using namespace Microsoft::Net::Wifi; using namespace Microsoft::Net::Wifi::Test; @@ -23,7 +23,7 @@ AccessPointTest::GetInterfaceName() const noexcept std::unique_ptr AccessPointTest::CreateController() { - return std::make_unique(InterfaceName); + return std::make_unique(this); } std::shared_ptr diff --git a/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointControllerTest.hxx b/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointControllerTest.hxx index 51e70233..251e980e 100644 --- a/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointControllerTest.hxx +++ b/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointControllerTest.hxx @@ -9,27 +9,84 @@ namespace Microsoft::Net::Wifi::Test { +struct AccessPointTest; + +/** + * @brief IAccessPointController implementation for testing purposes. + * + * This implementation takes an AccessPointTest object which it uses to implement the IAccessPointController interface. + * The owner of this class must ensure that the passes AccessPointTest* remains valid for the lifetime of this object. + */ struct AccessPointControllerTest final : - public IAccessPointController + public Microsoft::Net::Wifi::IAccessPointController { - AccessPointControllerTest(std::string_view interfaceName); + AccessPointTest *AccessPoint{ nullptr }; + + /** + * @brief Construct a new AccessPointControllerTest object that uses the specified AccessPointTest to implement the + * IAccessPointController interface. + * + * @param accessPoint The access point to use. + */ + AccessPointControllerTest(AccessPointTest *accessPoint); + /** + * @brief Get the interface name associated with this controller. + * + * @return std::string_view + */ virtual std::string_view GetInterfaceName() const noexcept override; + /** + * @brief Get whether the access point is enabled. + * + * @return true + * @return false + */ virtual bool GetIsEnabled() override; + /** + * @brief Get the capabilities of the access point. + * + * @return Ieee80211AccessPointCapabilities + */ virtual Ieee80211AccessPointCapabilities GetCapabilities() override; - - std::string InterfaceName; - bool IsEnabled{ false }; }; +/** + * @brief IAccessPointControllerFactory implementation for testing purposes. + */ struct AccessPointControllerFactoryTest final : public Microsoft::Net::Wifi::IAccessPointControllerFactory { + AccessPointTest *AccessPoint{ nullptr }; + + /** + * @brief Construct a new AccessPointControllerFactoryTest object with no AccessPointTest parent/owner. This may + * only be used for cases where the constructed object won't actually be used (eg. unit tests for other components + * that require an IAccessPointControllerFactory, but the test doesn't trigger any functionality to use it). + * + * This should be contrained to testing creation/destruction of other objects that use this only. + */ + AccessPointControllerFactoryTest() = default; + + /** + * @brief Construct a new AccessPointControllerFactoryTest object. The owner of this object must ensure that the passed AccessPointTest remains valid for the lifetime of this object. + * + * @param accessPoint The access point to create controllers for. + */ + AccessPointControllerFactoryTest(AccessPointTest *accessPoint); + + /** + * @brief Create a new instance that can control the access point. + * + * @param interfaceName The name of the interface. If this factory was created with an AccessPointTest, this must + * match the interface name of the AccessPoint the object or else a std::runtime_error will be thrown. was created + * @return std::unique_ptr + */ std::unique_ptr Create(std::string_view interfaceName) override; }; diff --git a/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointTest.hxx b/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointTest.hxx index 1e038dca..41f6bbfa 100644 --- a/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointTest.hxx +++ b/tests/unit/wifi/helpers/include/microsoft/net/wifi/test/AccessPointTest.hxx @@ -11,13 +11,39 @@ namespace Microsoft::Net::Wifi::Test { +/** + * @brief IAccessPoint implementation for testing purposes. + * + * This implementation has public members for each configurable setting, allowing consumers to read and change them at + * will. This is intended to be used by test code only. + */ struct AccessPointTest final : public IAccessPoint { + std::string InterfaceName; + Microsoft::Net::Wifi::Ieee80211AccessPointCapabilities Capabilities; + bool IsEnabled{ false }; + + /** + * @brief Construct a new AccessPointTest object with the given interface name and default capabilities. + * + * @param interfaceName The interface name to use for the access point. + */ AccessPointTest(std::string_view interfaceName); + /** + * @brief Construct a new AccessPointTest object with the given interface name and capabilities. + * + * @param interfaceName The interface name to use for the access point. + * @param capabilities The capabilities to use for the access point. + */ AccessPointTest(std::string_view interfaceName, Microsoft::Net::Wifi::Ieee80211AccessPointCapabilities capabilities); + /** + * @brief Get the interface name of the access point. + * + * @return std::string_view + */ virtual std::string_view GetInterfaceName() const noexcept override; @@ -28,9 +54,6 @@ struct AccessPointTest final : */ virtual std::unique_ptr CreateController() override; - - std::string InterfaceName; - Microsoft::Net::Wifi::Ieee80211AccessPointCapabilities Capabilities; }; /** @@ -59,7 +82,7 @@ struct AccessPointFactoryTest : * * @param interface The interface to create the AccessPoint for. This can be * any string and does not have to correspond to a real device interface. - * @param createArgs + * @param createArgs Arguments to be passed to the access point during creation. * * @return std::shared_ptr */