diff --git a/src/common/net/wifi/core/include/microsoft/net/wifi/AccessPointAttributes.hxx b/src/common/net/wifi/core/include/microsoft/net/wifi/AccessPointAttributes.hxx index e8197c46..062d5376 100644 --- a/src/common/net/wifi/core/include/microsoft/net/wifi/AccessPointAttributes.hxx +++ b/src/common/net/wifi/core/include/microsoft/net/wifi/AccessPointAttributes.hxx @@ -14,8 +14,6 @@ namespace Microsoft::Net::Wifi */ struct AccessPointAttributes { - AccessPointAttributes() = default; - /** * @brief Attempt to deserialize a JSON string into a map of access point attributes. * diff --git a/tests/unit/net/wifi/core/CMakeLists.txt b/tests/unit/net/wifi/core/CMakeLists.txt index dbcbc8bf..abdf53e4 100644 --- a/tests/unit/net/wifi/core/CMakeLists.txt +++ b/tests/unit/net/wifi/core/CMakeLists.txt @@ -5,6 +5,7 @@ target_sources(wifi-core-test-unit PRIVATE Main.cxx TestAccessPoint.cxx + TestAccessPointAttributes.cxx TestAccessPointOperationStatus.cxx TestIeee80211.cxx ) @@ -18,6 +19,7 @@ target_link_libraries(wifi-core-test-unit PRIVATE Catch2::Catch2 magic_enum::magic_enum + nlohmann_json::nlohmann_json plog::plog strings wifi-core diff --git a/tests/unit/net/wifi/core/TestAccessPointAttributes.cxx b/tests/unit/net/wifi/core/TestAccessPointAttributes.cxx new file mode 100644 index 00000000..082f3605 --- /dev/null +++ b/tests/unit/net/wifi/core/TestAccessPointAttributes.cxx @@ -0,0 +1,75 @@ + +#include +#include + +#include +#include +#include + +TEST_CASE("AccessPointAttributes JSON Serialization and Deserialization", "[wifi][core][ap][serialization]") +{ + using namespace Microsoft::Net::Wifi; + + auto accessPointAttributesJson = R"( + { + "wlan0": { + "Properties": { + "key1": "value1", + "key2": "value2" + } + }, + "wlan1": { + "Properties": { + "key1": "value1", + "key2": "value2" + } + } + } + )"; + + // clang-format off + std::unordered_map AccessPointAttributesMap{ + { + "wlan0", + AccessPointAttributes{ + { + { "key1", "value1" }, + { "key2", "value2" } + } + }, + }, + { + "wlan1", + AccessPointAttributes{ + { + { "key1", "value1" }, + { "key2", "value2" } + } + } + } + }; + // clang-format on + + SECTION("Deserialization (direct) doesn't cause a crash") + { + REQUIRE_NOTHROW(nlohmann::json::parse(accessPointAttributesJson)); + } + + SECTION("Deserialization (wrapped) doesn't cause a crash") + { + REQUIRE_NOTHROW(AccessPointAttributes::TryParseJson(accessPointAttributesJson)); + } + + SECTION("Deserialization (wrapped) populates the access point attributes") + { + auto deserializedAccessPointAttributesOpt = AccessPointAttributes::TryParseJson(accessPointAttributesJson); + REQUIRE(deserializedAccessPointAttributesOpt.has_value()); + auto& deserializedAccessPointAttributes = deserializedAccessPointAttributesOpt.value(); + REQUIRE(std::size(deserializedAccessPointAttributes) == std::size(AccessPointAttributesMap)); + + for (const auto& [interfaceName, accessPointAttributes] : AccessPointAttributesMap) { + REQUIRE(deserializedAccessPointAttributes.contains(interfaceName)); + REQUIRE(deserializedAccessPointAttributes[interfaceName].Properties == accessPointAttributes.Properties); + } + } +}