From 6004917a5c757838e210c1679ecf6d15e86119e6 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Fri, 26 Apr 2024 12:18:42 -0400 Subject: [PATCH] [Chore] Convert chip::Optional to std::optional for dnssd/types.h (#33179) * Replace some chip Optional with std::optional * Restyle * a few more updates * Also fix RemoteDataLogger.cpp * Code review feedback: added some bracketing * Re-do the bracketing * Fix some of the unchecked optional access warnings * Also fix TestIncrementalResolve * Fix Commissionable script binding * Fix more files * Restyle --------- Co-authored-by: Andrei Litvin --- .../commands/common/RemoteDataModelLogger.cpp | 16 +- src/controller/SetUpCodePairer.cpp | 8 +- ...issionableNodeController-ScriptBinding.cpp | 16 +- .../python/ChipDeviceController-Discovery.cpp | 39 ++-- .../AddressResolve_DefaultImpl.cpp | 4 +- src/lib/dnssd/TxtFields.cpp | 18 +- src/lib/dnssd/Types.h | 50 +++--- .../dnssd/tests/TestIncrementalResolve.cpp | 10 +- src/lib/dnssd/tests/TestTxtFields.cpp | 166 ++++++++---------- src/lib/shell/commands/Dns.cpp | 20 +-- 10 files changed, 173 insertions(+), 174 deletions(-) diff --git a/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp b/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp index 9a996051957ccf..9e4f29c5534757 100644 --- a/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp +++ b/examples/chip-tool/commands/common/RemoteDataModelLogger.cpp @@ -245,24 +245,24 @@ CHIP_ERROR LogDiscoveredNodeData(const chip::Dnssd::CommissionNodeData & nodeDat value["port"] = resolutionData.port; value["numIPs"] = static_cast(resolutionData.numIPs); - if (resolutionData.mrpRetryIntervalIdle.HasValue()) + if (resolutionData.mrpRetryIntervalIdle.has_value()) { - value["mrpRetryIntervalIdle"] = resolutionData.mrpRetryIntervalIdle.Value().count(); + value["mrpRetryIntervalIdle"] = resolutionData.mrpRetryIntervalIdle->count(); } - if (resolutionData.mrpRetryIntervalActive.HasValue()) + if (resolutionData.mrpRetryIntervalActive.has_value()) { - value["mrpRetryIntervalActive"] = resolutionData.mrpRetryIntervalActive.Value().count(); + value["mrpRetryIntervalActive"] = resolutionData.mrpRetryIntervalActive->count(); } - if (resolutionData.mrpRetryActiveThreshold.HasValue()) + if (resolutionData.mrpRetryActiveThreshold.has_value()) { - value["mrpRetryActiveThreshold"] = resolutionData.mrpRetryActiveThreshold.Value().count(); + value["mrpRetryActiveThreshold"] = resolutionData.mrpRetryActiveThreshold->count(); } - if (resolutionData.isICDOperatingAsLIT.HasValue()) + if (resolutionData.isICDOperatingAsLIT.has_value()) { - value["isICDOperatingAsLIT"] = resolutionData.isICDOperatingAsLIT.Value(); + value["isICDOperatingAsLIT"] = *(resolutionData.isICDOperatingAsLIT); } Json::Value rootValue; diff --git a/src/controller/SetUpCodePairer.cpp b/src/controller/SetUpCodePairer.cpp index c3aecbfdd36f66..cf7ba2abd43d89 100644 --- a/src/controller/SetUpCodePairer.cpp +++ b/src/controller/SetUpCodePairer.cpp @@ -620,14 +620,14 @@ SetUpCodePairerParameters::SetUpCodePairerParameters(const Dnssd::CommonResoluti auto & ip = data.ipAddress[index]; SetPeerAddress(Transport::PeerAddress::UDP(ip, data.port, ip.IsIPv6LinkLocal() ? data.interfaceId : Inet::InterfaceId::Null())); - if (data.mrpRetryIntervalIdle.HasValue()) + if (data.mrpRetryIntervalIdle.has_value()) { - SetIdleInterval(data.mrpRetryIntervalIdle.Value()); + SetIdleInterval(*data.mrpRetryIntervalIdle); } - if (data.mrpRetryIntervalActive.HasValue()) + if (data.mrpRetryIntervalActive.has_value()) { - SetActiveInterval(data.mrpRetryIntervalActive.Value()); + SetActiveInterval(*data.mrpRetryIntervalActive); } } diff --git a/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp b/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp index 6df32c6940667a..157789f5d64136 100644 --- a/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp +++ b/src/controller/python/ChipCommissionableNodeController-ScriptBinding.cpp @@ -97,17 +97,21 @@ void pychip_CommissionableNodeController_PrintDiscoveredCommissioners( ChipLogProgress(Discovery, "\tRotating Id\t\t%s", rotatingId); ChipLogProgress(Discovery, "\tPairing Instruction\t%s", dnsSdInfo->pairingInstruction); ChipLogProgress(Discovery, "\tPairing Hint\t\t%u", dnsSdInfo->pairingHint); - if (dnsSdInfo->GetMrpRetryIntervalIdle().HasValue()) + + auto idleInterval = dnsSdInfo->GetMrpRetryIntervalIdle(); + if (idleInterval.has_value()) { - ChipLogProgress(Discovery, "\tMrp Interval idle\t%u", dnsSdInfo->GetMrpRetryIntervalIdle().Value().count()); + ChipLogProgress(Discovery, "\tMrp Interval idle\t%u", idleInterval->count()); } else { ChipLogProgress(Discovery, "\tMrp Interval idle\tNot present"); } - if (dnsSdInfo->GetMrpRetryIntervalActive().HasValue()) + + auto activeInterval = dnsSdInfo->GetMrpRetryIntervalIdle(); + if (activeInterval.has_value()) { - ChipLogProgress(Discovery, "\tMrp Interval active\t%u", dnsSdInfo->GetMrpRetryIntervalActive().Value().count()); + ChipLogProgress(Discovery, "\tMrp Interval active\t%u", activeInterval->count()); } else { @@ -115,9 +119,9 @@ void pychip_CommissionableNodeController_PrintDiscoveredCommissioners( } ChipLogProgress(Discovery, "\tSupports TCP\t\t%d", dnsSdInfo->supportsTcp); - if (dnsSdInfo->isICDOperatingAsLIT.HasValue()) + if (dnsSdInfo->isICDOperatingAsLIT.has_value()) { - ChipLogProgress(Discovery, "\tICD is operating as a\t%s", dnsSdInfo->isICDOperatingAsLIT.Value() ? "LIT" : "SIT"); + ChipLogProgress(Discovery, "\tICD is operating as a\t%s", *(dnsSdInfo->isICDOperatingAsLIT) ? "LIT" : "SIT"); } for (unsigned j = 0; j < dnsSdInfo->numIPs; ++j) diff --git a/src/controller/python/ChipDeviceController-Discovery.cpp b/src/controller/python/ChipDeviceController-Discovery.cpp index b7589791b41eab..4ad6db56bf6739 100644 --- a/src/controller/python/ChipDeviceController-Discovery.cpp +++ b/src/controller/python/ChipDeviceController-Discovery.cpp @@ -124,17 +124,23 @@ void pychip_DeviceController_IterateDiscoveredCommissionableNodes(Controller::De jsonVal["deviceName"] = dnsSdInfo->deviceName; jsonVal["pairingInstruction"] = dnsSdInfo->pairingInstruction; jsonVal["pairingHint"] = dnsSdInfo->pairingHint; - if (dnsSdInfo->GetMrpRetryIntervalIdle().HasValue()) + + auto idleInterval = dnsSdInfo->GetMrpRetryIntervalIdle(); + if (idleInterval.has_value()) { - jsonVal["mrpRetryIntervalIdle"] = dnsSdInfo->GetMrpRetryIntervalIdle().Value().count(); + jsonVal["mrpRetryIntervalIdle"] = idleInterval->count(); } - if (dnsSdInfo->GetMrpRetryIntervalActive().HasValue()) + + auto activeInterval = dnsSdInfo->GetMrpRetryIntervalActive(); + if (activeInterval.has_value()) { - jsonVal["mrpRetryIntervalActive"] = dnsSdInfo->GetMrpRetryIntervalActive().Value().count(); + jsonVal["mrpRetryIntervalActive"] = activeInterval->count(); } - if (dnsSdInfo->GetMrpRetryActiveThreshold().HasValue()) + + auto activeThreshold = dnsSdInfo->GetMrpRetryActiveThreshold(); + if (activeThreshold.has_value()) { - jsonVal["mrpRetryActiveThreshold"] = dnsSdInfo->GetMrpRetryActiveThreshold().Value().count(); + jsonVal["mrpRetryActiveThreshold"] = activeThreshold->count(); } jsonVal["supportsTcp"] = dnsSdInfo->supportsTcp; { @@ -147,9 +153,9 @@ void pychip_DeviceController_IterateDiscoveredCommissionableNodes(Controller::De } jsonVal["addresses"] = addresses; } - if (dnsSdInfo->isICDOperatingAsLIT.HasValue()) + if (dnsSdInfo->isICDOperatingAsLIT.has_value()) { - jsonVal["isICDOperatingAsLIT"] = dnsSdInfo->isICDOperatingAsLIT.Value(); + jsonVal["isICDOperatingAsLIT"] = *(dnsSdInfo->isICDOperatingAsLIT); } if (dnsSdInfo->rotatingIdLen > 0) { @@ -188,26 +194,31 @@ void pychip_DeviceController_PrintDiscoveredDevices(Controller::DeviceCommission ChipLogProgress(Discovery, "\tRotating Id\t\t%s", rotatingId); ChipLogProgress(Discovery, "\tPairing Instruction\t%s", dnsSdInfo->pairingInstruction); ChipLogProgress(Discovery, "\tPairing Hint\t\t%u", dnsSdInfo->pairingHint); - if (dnsSdInfo->GetMrpRetryIntervalIdle().HasValue()) + + auto idleInterval = dnsSdInfo->GetMrpRetryIntervalIdle(); + if (idleInterval.has_value()) { - ChipLogProgress(Discovery, "\tMrp Interval idle\t%u", dnsSdInfo->GetMrpRetryIntervalIdle().Value().count()); + ChipLogProgress(Discovery, "\tMrp Interval idle\t%u", idleInterval->count()); } else { ChipLogProgress(Discovery, "\tMrp Interval idle\tNot present"); } - if (dnsSdInfo->GetMrpRetryIntervalActive().HasValue()) + + auto activeInterval = dnsSdInfo->GetMrpRetryIntervalActive(); + if (activeInterval.has_value()) { - ChipLogProgress(Discovery, "\tMrp Interval active\t%u", dnsSdInfo->GetMrpRetryIntervalActive().Value().count()); + ChipLogProgress(Discovery, "\tMrp Interval active\t%u", activeInterval->count()); } else { ChipLogProgress(Discovery, "\tMrp Interval active\tNot present"); } + ChipLogProgress(Discovery, "\tSupports TCP\t\t%d", dnsSdInfo->supportsTcp); - if (dnsSdInfo->isICDOperatingAsLIT.HasValue()) + if (dnsSdInfo->isICDOperatingAsLIT.has_value()) { - ChipLogProgress(Discovery, "\tICD is operating as a\t%s", dnsSdInfo->isICDOperatingAsLIT.Value() ? "LIT" : "SIT"); + ChipLogProgress(Discovery, "\tICD is operating as a\t%s", *(dnsSdInfo->isICDOperatingAsLIT) ? "LIT" : "SIT"); } for (unsigned j = 0; j < dnsSdInfo->numIPs; ++j) { diff --git a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp index 6e461a4b99c72d..5a9651ff76ba3d 100644 --- a/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp +++ b/src/lib/address_resolve/AddressResolve_DefaultImpl.cpp @@ -290,9 +290,9 @@ void Resolver::OnOperationalNodeResolved(const Dnssd::ResolvedNodeData & nodeDat result.mrpRemoteConfig = nodeData.resolutionData.GetRemoteMRPConfig(); result.supportsTcp = nodeData.resolutionData.supportsTcp; - if (nodeData.resolutionData.isICDOperatingAsLIT.HasValue()) + if (nodeData.resolutionData.isICDOperatingAsLIT.has_value()) { - result.isICDOperatingAsLIT = nodeData.resolutionData.isICDOperatingAsLIT.Value(); + result.isICDOperatingAsLIT = *(nodeData.resolutionData.isICDOperatingAsLIT); } for (size_t i = 0; i < nodeData.resolutionData.numIPs; i++) diff --git a/src/lib/dnssd/TxtFields.cpp b/src/lib/dnssd/TxtFields.cpp index 88a116871ca017..6ac2cfa19e8ece 100644 --- a/src/lib/dnssd/TxtFields.cpp +++ b/src/lib/dnssd/TxtFields.cpp @@ -105,14 +105,14 @@ bool MakeBoolFromAsciiDecimal(const ByteSpan & val) return val.size() == 1 && static_cast(*val.data()) == '1'; } -Optional MakeOptionalBoolFromAsciiDecimal(const ByteSpan & val) +std::optional MakeOptionalBoolFromAsciiDecimal(const ByteSpan & val) { char character = static_cast(*val.data()); if (val.size() == 1 && ((character == '1') || (character == '0'))) { - return MakeOptional(character == '1'); + return std::make_optional(character == '1'); } - return NullOptional; + return std::nullopt; } size_t GetPlusSignIdx(const ByteSpan & value) @@ -188,27 +188,27 @@ uint8_t GetCommissionerPasscode(const ByteSpan & value) return MakeBoolFromAsciiDecimal(value); } -Optional GetRetryInterval(const ByteSpan & value) +std::optional GetRetryInterval(const ByteSpan & value) { const auto undefined = std::numeric_limits::max(); const auto retryInterval = MakeU32FromAsciiDecimal(value, undefined); if (retryInterval != undefined && retryInterval <= kMaxRetryInterval.count()) - return MakeOptional(System::Clock::Milliseconds32(retryInterval)); + return std::make_optional(System::Clock::Milliseconds32(retryInterval)); - return NullOptional; + return std::nullopt; } -Optional GetRetryActiveThreshold(const ByteSpan & value) +std::optional GetRetryActiveThreshold(const ByteSpan & value) { const auto retryInterval = MakeU16FromAsciiDecimal(value); if (retryInterval == 0) { - return NullOptional; + return std::nullopt; } - return MakeOptional(System::Clock::Milliseconds16(retryInterval)); + return std::make_optional(System::Clock::Milliseconds16(retryInterval)); } TxtFieldKey GetTxtFieldKey(const ByteSpan & key) diff --git a/src/lib/dnssd/Types.h b/src/lib/dnssd/Types.h index e62c9a52418efe..c88dd0a9c73522 100644 --- a/src/lib/dnssd/Types.h +++ b/src/lib/dnssd/Types.h @@ -19,10 +19,10 @@ #include #include +#include #include #include -#include #include #include #include @@ -91,10 +91,10 @@ struct CommonResolutionData uint16_t port = 0; char hostName[kHostNameMaxLength + 1] = {}; bool supportsTcp = false; - Optional isICDOperatingAsLIT; - Optional mrpRetryIntervalIdle; - Optional mrpRetryIntervalActive; - Optional mrpRetryActiveThreshold; + std::optional isICDOperatingAsLIT; + std::optional mrpRetryIntervalIdle; + std::optional mrpRetryIntervalActive; + std::optional mrpRetryActiveThreshold; CommonResolutionData() { Reset(); } @@ -103,21 +103,21 @@ struct CommonResolutionData ReliableMessageProtocolConfig GetRemoteMRPConfig() const { const ReliableMessageProtocolConfig defaultConfig = GetDefaultMRPConfig(); - return ReliableMessageProtocolConfig(GetMrpRetryIntervalIdle().ValueOr(defaultConfig.mIdleRetransTimeout), - GetMrpRetryIntervalActive().ValueOr(defaultConfig.mActiveRetransTimeout), - GetMrpRetryActiveThreshold().ValueOr(defaultConfig.mActiveThresholdTime)); + return ReliableMessageProtocolConfig(GetMrpRetryIntervalIdle().value_or(defaultConfig.mIdleRetransTimeout), + GetMrpRetryIntervalActive().value_or(defaultConfig.mActiveRetransTimeout), + GetMrpRetryActiveThreshold().value_or(defaultConfig.mActiveThresholdTime)); } - Optional GetMrpRetryIntervalIdle() const { return mrpRetryIntervalIdle; } - Optional GetMrpRetryIntervalActive() const { return mrpRetryIntervalActive; } - Optional GetMrpRetryActiveThreshold() const { return mrpRetryActiveThreshold; } + std::optional GetMrpRetryIntervalIdle() const { return mrpRetryIntervalIdle; } + std::optional GetMrpRetryIntervalActive() const { return mrpRetryIntervalActive; } + std::optional GetMrpRetryActiveThreshold() const { return mrpRetryActiveThreshold; } bool IsDeviceTreatedAsSleepy(const ReliableMessageProtocolConfig * defaultMRPConfig) const { // If either session interval (Idle - SII, Active - SAI) has a value and that value is greater // than the value passed to this function, then the peer device will be treated as if it is // a Sleepy End Device (SED) - return (mrpRetryIntervalIdle.HasValue() && (mrpRetryIntervalIdle.Value() > defaultMRPConfig->mIdleRetransTimeout)) || - (mrpRetryIntervalActive.HasValue() && (mrpRetryIntervalActive.Value() > defaultMRPConfig->mActiveRetransTimeout)); + return (mrpRetryIntervalIdle.has_value() && (*mrpRetryIntervalIdle > defaultMRPConfig->mIdleRetransTimeout)) || + (mrpRetryIntervalActive.has_value() && (*mrpRetryIntervalActive > defaultMRPConfig->mActiveRetransTimeout)); } bool IsHost(const char * host) const { return strcmp(host, hostName) == 0; } @@ -125,10 +125,10 @@ struct CommonResolutionData void Reset() { memset(hostName, 0, sizeof(hostName)); - mrpRetryIntervalIdle = NullOptional; - mrpRetryIntervalActive = NullOptional; - mrpRetryActiveThreshold = NullOptional; - isICDOperatingAsLIT = NullOptional; + mrpRetryIntervalIdle = std::nullopt; + mrpRetryIntervalActive = std::nullopt; + mrpRetryActiveThreshold = std::nullopt; + isICDOperatingAsLIT = std::nullopt; numIPs = 0; port = 0; supportsTcp = false; @@ -157,34 +157,34 @@ struct CommonResolutionData { ChipLogDetail(Discovery, "\tPort: %u", port); } - if (mrpRetryIntervalIdle.HasValue()) + if (mrpRetryIntervalIdle.has_value()) { - ChipLogDetail(Discovery, "\tMrp Interval idle: %" PRIu32 " ms", mrpRetryIntervalIdle.Value().count()); + ChipLogDetail(Discovery, "\tMrp Interval idle: %" PRIu32 " ms", mrpRetryIntervalIdle->count()); } else { ChipLogDetail(Discovery, "\tMrp Interval idle: not present"); } - if (mrpRetryIntervalActive.HasValue()) + if (mrpRetryIntervalActive.has_value()) { - ChipLogDetail(Discovery, "\tMrp Interval active: %" PRIu32 " ms", mrpRetryIntervalActive.Value().count()); + ChipLogDetail(Discovery, "\tMrp Interval active: %" PRIu32 " ms", mrpRetryIntervalActive->count()); } else { ChipLogDetail(Discovery, "\tMrp Interval active: not present"); } - if (mrpRetryActiveThreshold.HasValue()) + if (mrpRetryActiveThreshold.has_value()) { - ChipLogDetail(Discovery, "\tMrp Active Threshold: %u ms", mrpRetryActiveThreshold.Value().count()); + ChipLogDetail(Discovery, "\tMrp Active Threshold: %u ms", mrpRetryActiveThreshold->count()); } else { ChipLogDetail(Discovery, "\tMrp Active Threshold: not present"); } ChipLogDetail(Discovery, "\tTCP Supported: %d", supportsTcp); - if (isICDOperatingAsLIT.HasValue()) + if (isICDOperatingAsLIT.has_value()) { - ChipLogDetail(Discovery, "\tThe ICD operates in %s", isICDOperatingAsLIT.Value() ? "LIT" : "SIT"); + ChipLogDetail(Discovery, "\tThe ICD operates in %s", *isICDOperatingAsLIT ? "LIT" : "SIT"); } else { diff --git a/src/lib/dnssd/tests/TestIncrementalResolve.cpp b/src/lib/dnssd/tests/TestIncrementalResolve.cpp index 5ed4191319e824..0b5f26abbcd405 100644 --- a/src/lib/dnssd/tests/TestIncrementalResolve.cpp +++ b/src/lib/dnssd/tests/TestIncrementalResolve.cpp @@ -307,9 +307,8 @@ TEST(TestIncrementalResolve, TestParseOperational) EXPECT_EQ(nodeData.resolutionData.numIPs, 1u); EXPECT_EQ(nodeData.resolutionData.port, 0x1234); EXPECT_FALSE(nodeData.resolutionData.supportsTcp); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue()); - EXPECT_TRUE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue()); - EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalIdle().Value(), chip::System::Clock::Milliseconds32(23)); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().has_value()); + EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalIdle(), std::make_optional(chip::System::Clock::Milliseconds32(23))); Inet::IPAddress addr; EXPECT_TRUE(Inet::IPAddress::FromString("fe80::abcd:ef11:2233:4455", addr)); @@ -396,9 +395,8 @@ TEST(TestIncrementalResolve, TestParseCommissionable) EXPECT_EQ(nodeData.numIPs, 2u); EXPECT_EQ(nodeData.port, 0x1234); EXPECT_FALSE(nodeData.supportsTcp); - EXPECT_TRUE(nodeData.GetMrpRetryIntervalActive().HasValue()); - EXPECT_EQ(nodeData.GetMrpRetryIntervalActive().Value(), chip::System::Clock::Milliseconds32(321)); - EXPECT_FALSE(nodeData.GetMrpRetryIntervalIdle().HasValue()); + EXPECT_EQ(nodeData.GetMrpRetryIntervalActive(), std::make_optional(chip::System::Clock::Milliseconds32(321))); + EXPECT_FALSE(nodeData.GetMrpRetryIntervalIdle().has_value()); Inet::IPAddress addr; EXPECT_TRUE(Inet::IPAddress::FromString("fe80::abcd:ef11:2233:4455", addr)); diff --git a/src/lib/dnssd/tests/TestTxtFields.cpp b/src/lib/dnssd/tests/TestTxtFields.cpp index ce206e34ae46aa..b80f1c0682ef32 100644 --- a/src/lib/dnssd/tests/TestTxtFields.cpp +++ b/src/lib/dnssd/tests/TestTxtFields.cpp @@ -304,9 +304,9 @@ bool NodeDataIsEmpty(const CommissionNodeData & node) { if (node.longDiscriminator != 0 || node.vendorId != 0 || node.productId != 0 || node.commissioningMode != 0 || - node.deviceType != 0 || node.rotatingIdLen != 0 || node.pairingHint != 0 || node.mrpRetryIntervalIdle.HasValue() || - node.mrpRetryIntervalActive.HasValue() || node.mrpRetryActiveThreshold.HasValue() || node.isICDOperatingAsLIT.HasValue() || - node.supportsTcp || node.supportsCommissionerGeneratedPasscode != 0) + node.deviceType != 0 || node.rotatingIdLen != 0 || node.pairingHint != 0 || node.mrpRetryIntervalIdle.has_value() || + node.mrpRetryIntervalActive.has_value() || node.mrpRetryActiveThreshold.has_value() || + node.isICDOperatingAsLIT.has_value() || node.supportsTcp || node.supportsCommissionerGeneratedPasscode != 0) { return false; } @@ -411,39 +411,39 @@ TEST(TestTxtFields, TestFillDiscoveredNodeDataFromTxt) bool NodeDataIsEmpty(const ResolvedNodeData & nodeData) { return nodeData.operationalData.peerId == PeerId{} && nodeData.resolutionData.numIPs == 0 && - nodeData.resolutionData.port == 0 && !nodeData.resolutionData.mrpRetryIntervalIdle.HasValue() && - !nodeData.resolutionData.mrpRetryIntervalActive.HasValue() && !nodeData.resolutionData.supportsTcp && - !nodeData.resolutionData.isICDOperatingAsLIT.HasValue(); + nodeData.resolutionData.port == 0 && !nodeData.resolutionData.mrpRetryIntervalIdle.has_value() && + !nodeData.resolutionData.mrpRetryIntervalActive.has_value() && !nodeData.resolutionData.supportsTcp && + !nodeData.resolutionData.isICDOperatingAsLIT.has_value(); } void ResetRetryIntervalIdle(DiscoveredNodeData & nodeData) { - nodeData.Get().mrpRetryIntervalIdle.ClearValue(); + nodeData.Get().mrpRetryIntervalIdle.reset(); } void ResetRetryIntervalIdle(ResolvedNodeData & nodeData) { - nodeData.resolutionData.mrpRetryIntervalIdle.ClearValue(); + nodeData.resolutionData.mrpRetryIntervalIdle.reset(); } void ResetRetryIntervalActive(DiscoveredNodeData & nodeData) { - nodeData.Get().mrpRetryIntervalActive.ClearValue(); + nodeData.Get().mrpRetryIntervalActive.reset(); } void ResetRetryIntervalActive(ResolvedNodeData & nodeData) { - nodeData.resolutionData.mrpRetryIntervalActive.ClearValue(); + nodeData.resolutionData.mrpRetryIntervalActive.reset(); } void ResetRetryActiveThreshold(DiscoveredNodeData & nodeData) { - nodeData.Get().mrpRetryActiveThreshold.ClearValue(); + nodeData.Get().mrpRetryActiveThreshold.reset(); } void ResetRetryActiveThreshold(ResolvedNodeData & nodeData) { - nodeData.resolutionData.mrpRetryActiveThreshold.ClearValue(); + nodeData.resolutionData.mrpRetryActiveThreshold.reset(); } template @@ -459,15 +459,13 @@ void DiscoveredTxtFieldSessionIdleInterval() strcpy(key, "SII"); strcpy(val, "1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); - EXPECT_TRUE(nodeData.Get().GetMrpRetryIntervalIdle().Value() == 1_ms32); + EXPECT_EQ(nodeData.Get().GetMrpRetryIntervalIdle(), std::make_optional(1_ms32)); // Maximum strcpy(key, "SII"); strcpy(val, "3600000"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); - EXPECT_TRUE(nodeData.Get().GetMrpRetryIntervalIdle().Value() == 3600000_ms32); + EXPECT_EQ(nodeData.Get().GetMrpRetryIntervalIdle(), std::make_optional(3600000_ms32)); // Test no other fields were populated ResetRetryIntervalIdle(nodeData); @@ -477,37 +475,37 @@ void DiscoveredTxtFieldSessionIdleInterval() strcpy(key, "SII"); strcpy(val, "-1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryIntervalIdle().has_value()); // Invalid SII - greater than maximum strcpy(key, "SII"); strcpy(val, "3600001"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryIntervalIdle().has_value()); // Invalid SII - much greater than maximum strcpy(key, "SII"); strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32) FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryIntervalIdle().has_value()); // Invalid SII - hexadecimal value strcpy(key, "SII"); strcpy(val, "0x20"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryIntervalIdle().has_value()); // Invalid SII - leading zeros strcpy(key, "SII"); strcpy(val, "0700"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryIntervalIdle().has_value()); // Invalid SII - text at the end strcpy(key, "SII"); strcpy(val, "123abc"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalIdle().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryIntervalIdle().has_value()); } // Test SAI (formerly CRA) @@ -524,15 +522,13 @@ void DiscoveredTxtFieldSessionActiveInterval() strcpy(key, "SAI"); strcpy(val, "1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(nodeData.Get().GetMrpRetryIntervalActive().HasValue()); - EXPECT_TRUE(nodeData.Get().GetMrpRetryIntervalActive().Value() == 1_ms32); + EXPECT_EQ(nodeData.Get().GetMrpRetryIntervalActive(), std::make_optional(1_ms32)); // Maximum strcpy(key, "SAI"); strcpy(val, "3600000"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(nodeData.Get().GetMrpRetryIntervalActive().HasValue()); - EXPECT_TRUE(nodeData.Get().GetMrpRetryIntervalActive().Value() == 3600000_ms32); + EXPECT_EQ(nodeData.Get().GetMrpRetryIntervalActive(), std::make_optional(3600000_ms32)); // Test no other fields were populated ResetRetryIntervalActive(nodeData); @@ -542,37 +538,37 @@ void DiscoveredTxtFieldSessionActiveInterval() strcpy(key, "SAI"); strcpy(val, "-1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryIntervalActive().has_value()); // Invalid SAI - greater than maximum strcpy(key, "SAI"); strcpy(val, "3600001"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryIntervalActive().has_value()); // Invalid SAI - much greater than maximum strcpy(key, "SAI"); strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32) FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryIntervalActive().has_value()); // Invalid SAI - hexadecimal value strcpy(key, "SAI"); strcpy(val, "0x20"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryIntervalActive().has_value()); // Invalid SAI - leading zeros strcpy(key, "SAI"); strcpy(val, "0700"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryIntervalActive().has_value()); // Invalid SAI - text at the end strcpy(key, "SAI"); strcpy(val, "123abc"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryIntervalActive().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryIntervalActive().has_value()); } // Test SAT (Session Active Threshold) @@ -589,15 +585,13 @@ void DiscoveredTxtFieldSessionActiveThreshold() strcpy(key, "SAT"); strcpy(val, "1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); - EXPECT_TRUE(nodeData.Get().GetMrpRetryActiveThreshold().Value() == 1_ms16); + EXPECT_EQ(nodeData.Get().GetMrpRetryActiveThreshold(), std::make_optional(1_ms16)); // Maximum strcpy(key, "SAT"); strcpy(val, "65535"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); - EXPECT_TRUE(nodeData.Get().GetMrpRetryActiveThreshold().Value() == 65535_ms16); + EXPECT_EQ(nodeData.Get().GetMrpRetryActiveThreshold(), std::make_optional(65535_ms16)); // Test no other fields were populated ResetRetryActiveThreshold(nodeData); @@ -607,37 +601,37 @@ void DiscoveredTxtFieldSessionActiveThreshold() strcpy(key, "SAT"); strcpy(val, "-1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryActiveThreshold().has_value()); // Invalid SAI - greater than maximum strcpy(key, "SAT"); strcpy(val, "65536"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryActiveThreshold().has_value()); // Invalid SAT - much greater than maximum strcpy(key, "SAT"); strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32) FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryActiveThreshold().has_value()); // Invalid SAT - hexadecimal value strcpy(key, "SAT"); strcpy(val, "0x20"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryActiveThreshold().has_value()); // Invalid SAT - leading zeros strcpy(key, "SAT"); strcpy(val, "0700"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryActiveThreshold().has_value()); // Invalid SAT - text at the end strcpy(key, "SAT"); strcpy(val, "123abc"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().GetMrpRetryActiveThreshold().HasValue()); + EXPECT_FALSE(nodeData.Get().GetMrpRetryActiveThreshold().has_value()); } // Test T (TCP support) @@ -687,27 +681,25 @@ void DiscoveredTxtFieldICDoperatesAsLIT() strcpy(key, "ICD"); strcpy(val, "1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(nodeData.Get().isICDOperatingAsLIT.HasValue()); - EXPECT_TRUE(nodeData.Get().isICDOperatingAsLIT.Value()); + EXPECT_EQ(nodeData.Get().isICDOperatingAsLIT, std::make_optional(true)); // Test no other fields were populated - nodeData.Get().isICDOperatingAsLIT.ClearValue(); + nodeData.Get().isICDOperatingAsLIT.reset(); EXPECT_TRUE(NodeDataIsEmpty(nodeData.Get())); // ICD is operating as a SIT device strcpy(key, "ICD"); strcpy(val, "0"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(nodeData.Get().isICDOperatingAsLIT.HasValue()); - EXPECT_TRUE(nodeData.Get().isICDOperatingAsLIT.Value() == false); + EXPECT_EQ(nodeData.Get().isICDOperatingAsLIT, std::make_optional(false)); - nodeData.Get().isICDOperatingAsLIT.ClearValue(); + nodeData.Get().isICDOperatingAsLIT.reset(); EXPECT_TRUE(NodeDataIsEmpty(nodeData.Get())); // Invalid value, No key set strcpy(key, "ICD"); strcpy(val, "asdf"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(nodeData.Get().isICDOperatingAsLIT.HasValue() == false); + EXPECT_FALSE(nodeData.Get().isICDOperatingAsLIT.has_value()); } // Test IsDeviceTreatedAsSleepy() with CRI @@ -723,13 +715,13 @@ void DiscoveredTestIsDeviceSessionIdle() CommonResolutionData & resolutionData = nodeData.Get(); // No key/val set, so the device can't be sleepy - EXPECT_TRUE(!nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); + EXPECT_FALSE(nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); // If the interval is the default value, the device is not sleepy strcpy(key, "SII"); sprintf(val, "%d", static_cast(CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL.count())); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); + EXPECT_FALSE(nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); // If the interval is greater than the default value, the device is sleepy sprintf(key, "SII"); @@ -751,13 +743,13 @@ void DiscoveredTestIsDeviceSessionActive() CommonResolutionData & resolutionData = nodeData.Get(); // No key/val set, so the device can't be sleepy - EXPECT_TRUE(!nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); + EXPECT_FALSE(nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); // If the interval is the default value, the device is not sleepy sprintf(key, "SAI"); sprintf(val, "%d", static_cast(CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL.count())); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData); - EXPECT_TRUE(!nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); + EXPECT_FALSE(nodeData.Get().IsDeviceTreatedAsSleepy(&defaultMRPConfig)); // If the interval is greater than the default value, the device is sleepy strcpy(key, "SAI"); @@ -778,15 +770,13 @@ void TxtFieldSessionIdleInterval() strcpy(key, "SII"); strcpy(val, "1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_TRUE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue()); - EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalIdle().Value(), 1_ms32); + EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalIdle(), std::make_optional(1_ms32)); // Maximum strcpy(key, "SII"); strcpy(val, "3600000"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_TRUE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue()); - EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalIdle().Value(), 3600000_ms32); + EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalIdle(), std::make_optional(3600000_ms32)); // Test no other fields were populated ResetRetryIntervalIdle(nodeData); @@ -796,37 +786,37 @@ void TxtFieldSessionIdleInterval() strcpy(key, "SII"); strcpy(val, "-1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().has_value()); // Invalid SII - greater than maximum strcpy(key, "SII"); strcpy(val, "3600001"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().has_value()); // Invalid SII - much greater than maximum strcpy(key, "SII"); strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32) FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().has_value()); // Invalid SII - hexadecimal value strcpy(key, "SII"); strcpy(val, "0x20"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().has_value()); // Invalid SII - leading zeros strcpy(key, "SII"); strcpy(val, "0700"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().has_value()); // Invalid SII - text at the end strcpy(key, "SII"); strcpy(val, "123abc"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalIdle().has_value()); } TEST(TestTxtFields, TxtDiscoveredFieldMrpRetryIntervalIdle) @@ -851,15 +841,13 @@ void TxtFieldSessionActiveInterval() strcpy(key, "SAI"); strcpy(val, "1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_TRUE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue()); - EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalActive().Value(), 1_ms32); + EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalActive(), std::make_optional(1_ms32)); // Maximum strcpy(key, "SAI"); strcpy(val, "3600000"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_TRUE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue()); - EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalActive().Value(), 3600000_ms32); + EXPECT_EQ(nodeData.resolutionData.GetMrpRetryIntervalActive(), std::make_optional(3600000_ms32)); // Test no other fields were populated ResetRetryIntervalActive(nodeData); @@ -869,37 +857,37 @@ void TxtFieldSessionActiveInterval() strcpy(key, "SAI"); strcpy(val, "-1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().has_value()); // Invalid SAI - greater than maximum strcpy(key, "SAI"); strcpy(val, "3600001"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().has_value()); // Invalid SAI - much greater than maximum strcpy(key, "SAI"); strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32) FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().has_value()); // Invalid SAI - hexadecimal value strcpy(key, "SAI"); strcpy(val, "0x20"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().has_value()); // Invalid SAI - leading zeros strcpy(key, "SAI"); strcpy(val, "0700"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().has_value()); // Invalid SAI - text at the end strcpy(key, "SAI"); strcpy(val, "123abc"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryIntervalActive().has_value()); } TEST(TestTxtFields, TxtDiscoveredFieldMrpRetryIntervalActive) @@ -924,15 +912,13 @@ void TxtFieldSessionActiveThreshold() strcpy(key, "SAT"); strcpy(val, "1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_TRUE(nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue()); - EXPECT_EQ(nodeData.resolutionData.GetMrpRetryActiveThreshold().Value(), 1_ms16); + EXPECT_EQ(nodeData.resolutionData.GetMrpRetryActiveThreshold(), std::make_optional(1_ms16)); // Maximum strcpy(key, "SAT"); strcpy(val, "65535"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_TRUE(nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue()); - EXPECT_EQ(nodeData.resolutionData.GetMrpRetryActiveThreshold().Value(), 65535_ms16); + EXPECT_EQ(nodeData.resolutionData.GetMrpRetryActiveThreshold(), std::make_optional(65535_ms16)); // Test no other fields were populated ResetRetryActiveThreshold(nodeData); @@ -942,37 +928,37 @@ void TxtFieldSessionActiveThreshold() strcpy(key, "SAT"); strcpy(val, "-1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().has_value()); // Invalid SAI - greater than maximum strcpy(key, "SAT"); strcpy(val, "65536"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().has_value()); // Invalid SAT - much greater than maximum strcpy(key, "SAT"); strcpy(val, "1095216660481"); // 0xFF00000001 == 1 (mod 2^32) FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().has_value()); // Invalid SAT - hexadecimal value strcpy(key, "SAT"); strcpy(val, "0x20"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().has_value()); // Invalid SAT - leading zeros strcpy(key, "SAT"); strcpy(val, "0700"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().has_value()); // Invalid SAT - text at the end strcpy(key, "SAT"); strcpy(val, "123abc"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().HasValue()); + EXPECT_FALSE(nodeData.resolutionData.GetMrpRetryActiveThreshold().has_value()); } TEST(TestTxtFields, TxtDiscoveredFieldMrpRetryActiveThreshold) @@ -1038,27 +1024,27 @@ void TxtFieldICDoperatesAsLIT() strcpy(key, "ICD"); strcpy(val, "1"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_TRUE(nodeData.resolutionData.isICDOperatingAsLIT.HasValue()); - EXPECT_TRUE(nodeData.resolutionData.isICDOperatingAsLIT.Value()); + EXPECT_TRUE(nodeData.resolutionData.isICDOperatingAsLIT.has_value()); + EXPECT_TRUE(nodeData.resolutionData.isICDOperatingAsLIT.value_or(false)); // Test no other fields were populated - nodeData.resolutionData.isICDOperatingAsLIT.ClearValue(); + nodeData.resolutionData.isICDOperatingAsLIT.reset(); EXPECT_TRUE(NodeDataIsEmpty(nodeData)); // ICD is operating as a SIT device strcpy(key, "ICD"); strcpy(val, "0"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_TRUE(nodeData.resolutionData.isICDOperatingAsLIT.HasValue()); - EXPECT_EQ(nodeData.resolutionData.isICDOperatingAsLIT.Value(), false); + EXPECT_TRUE(nodeData.resolutionData.isICDOperatingAsLIT.has_value()); + EXPECT_EQ(nodeData.resolutionData.isICDOperatingAsLIT.value_or(true), false); - nodeData.resolutionData.isICDOperatingAsLIT.ClearValue(); + nodeData.resolutionData.isICDOperatingAsLIT.reset(); EXPECT_TRUE(NodeDataIsEmpty(nodeData)); // Invalid value, No key set strcpy(key, "ICD"); strcpy(val, "asdf"); FillNodeDataFromTxt(GetSpan(key), GetSpan(val), nodeData.resolutionData); - EXPECT_EQ(nodeData.resolutionData.isICDOperatingAsLIT.HasValue(), false); + EXPECT_EQ(nodeData.resolutionData.isICDOperatingAsLIT.has_value(), false); } TEST(TestTxtFields, TxtDiscoveredIsICDoperatingAsLIT) diff --git a/src/lib/shell/commands/Dns.cpp b/src/lib/shell/commands/Dns.cpp index 04d82313d7d3d4..7fac0186da912f 100644 --- a/src/lib/shell/commands/Dns.cpp +++ b/src/lib/shell/commands/Dns.cpp @@ -115,25 +115,25 @@ class DnsShellResolverDelegate : public Dnssd::DiscoverNodeDelegate, public Addr auto retryInterval = nodeData.GetMrpRetryIntervalIdle(); - if (retryInterval.HasValue()) - streamer_printf(streamer_get(), " MRP retry interval (idle): %" PRIu32 "ms\r\n", retryInterval.Value()); + if (retryInterval.has_value()) + streamer_printf(streamer_get(), " MRP retry interval (idle): %" PRIu32 "ms\r\n", *retryInterval); retryInterval = nodeData.GetMrpRetryIntervalActive(); - if (retryInterval.HasValue()) - streamer_printf(streamer_get(), " MRP retry interval (active): %" PRIu32 "ms\r\n", retryInterval.Value()); + if (retryInterval.has_value()) + streamer_printf(streamer_get(), " MRP retry interval (active): %" PRIu32 "ms\r\n", *retryInterval); - if (nodeData.GetMrpRetryActiveThreshold().HasValue()) + auto activeThreshold = nodeData.GetMrpRetryActiveThreshold(); + + if (activeThreshold.has_value()) { - streamer_printf(streamer_get(), " MRP retry active threshold time: %" PRIu32 "ms\r\n", - nodeData.GetMrpRetryActiveThreshold().Value()); + streamer_printf(streamer_get(), " MRP retry active threshold time: %" PRIu32 "ms\r\n", *activeThreshold); } streamer_printf(streamer_get(), " Supports TCP: %s\r\n", nodeData.supportsTcp ? "yes" : "no"); - if (nodeData.isICDOperatingAsLIT.HasValue()) + if (nodeData.isICDOperatingAsLIT.has_value()) { - streamer_printf(streamer_get(), " ICD is operating as a: %s\r\n", - nodeData.isICDOperatingAsLIT.Value() ? "LIT" : "SIT"); + streamer_printf(streamer_get(), " ICD is operating as a: %s\r\n", *(nodeData.isICDOperatingAsLIT) ? "LIT" : "SIT"); } streamer_printf(streamer_get(), " IP addresses:\r\n"); for (size_t i = 0; i < nodeData.numIPs; i++)