Skip to content

Commit

Permalink
Implement new functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
abeltrano committed Jan 26, 2024
1 parent b499dff commit 9b42cb3
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 17 deletions.
23 changes: 17 additions & 6 deletions tests/unit/wifi/helpers/AccessPointControllerTest.cxx
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@

#include <stdexcept>

#include <microsoft/net/wifi/test/AccessPointControllerTest.hxx>
#include <microsoft/net/wifi/test/AccessPointTest.hxx>

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<IAccessPointController>
AccessPointControllerFactoryTest::Create(std::string_view interfaceName)
{
return std::make_unique<AccessPointControllerTest>(interfaceName);
if (AccessPoint != nullptr && interfaceName != AccessPoint->InterfaceName) {
throw std::runtime_error("AccessPointControllerFactoryTest::Create called with unexpected interface name");
}

return std::make_unique<AccessPointControllerTest>(AccessPoint);
}
4 changes: 2 additions & 2 deletions tests/unit/wifi/helpers/AccessPointTest.cxx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#include <microsoft/net/wifi/test/AccessPointTest.hxx>
#include <microsoft/net/wifi/test/AccessPointControllerTest.hxx>
#include <microsoft/net/wifi/test/AccessPointTest.hxx>

using namespace Microsoft::Net::Wifi;
using namespace Microsoft::Net::Wifi::Test;
Expand All @@ -23,7 +23,7 @@ AccessPointTest::GetInterfaceName() const noexcept
std::unique_ptr<IAccessPointController>
AccessPointTest::CreateController()
{
return std::make_unique<AccessPointControllerTest>(InterfaceName);
return std::make_unique<AccessPointControllerTest>(this);
}

std::shared_ptr<IAccessPoint>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Microsoft::Net::Wifi::IAccessPointController>
*/
std::unique_ptr<Microsoft::Net::Wifi::IAccessPointController>
Create(std::string_view interfaceName) override;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -28,9 +54,6 @@ struct AccessPointTest final :
*/
virtual std::unique_ptr<IAccessPointController>
CreateController() override;

std::string InterfaceName;
Microsoft::Net::Wifi::Ieee80211AccessPointCapabilities Capabilities;
};

/**
Expand Down Expand Up @@ -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<IAccessPoint>
*/
Expand Down

0 comments on commit 9b42cb3

Please sign in to comment.