Skip to content

Commit

Permalink
Restyled by clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits authored and su-shanka committed Apr 24, 2024
1 parent 18c5de5 commit a632edb
Showing 1 changed file with 54 additions and 56 deletions.
110 changes: 54 additions & 56 deletions src/lib/dnssd/tests/TestTxtFields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,10 @@ TEST(TestTxtFields, TestGetCommissionerPasscode)
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)
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)
{
return false;
}
Expand Down Expand Up @@ -461,55 +459,55 @@ void DiscoveredTxtFieldSessionIdleInterval()
strcpy(key, "SII");
strcpy(val, "1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().HasValue());
EXPECT_TRUE( nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().Value() == 1_ms32);
EXPECT_TRUE(nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().HasValue());
EXPECT_TRUE(nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().Value() == 1_ms32);

// Maximum
strcpy(key, "SII");
strcpy(val, "3600000");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().HasValue());
EXPECT_TRUE( nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().Value() == 3600000_ms32);
EXPECT_TRUE(nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().HasValue());
EXPECT_TRUE(nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().Value() == 3600000_ms32);

// Test no other fields were populated
ResetRetryIntervalIdle(nodeData);
EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get<NodeData>()));
EXPECT_TRUE(NodeDataIsEmpty(nodeData.Get<NodeData>()));

// Invalid SII - negative value
strcpy(key, "SII");
strcpy(val, "-1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().HasValue());

// Invalid SII - greater than maximum
strcpy(key, "SII");
strcpy(val, "3600001");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().HasValue());

// 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<NodeData>().GetMrpRetryIntervalIdle().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().HasValue());

// Invalid SII - hexadecimal value
strcpy(key, "SII");
strcpy(val, "0x20");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().HasValue());

// Invalid SII - leading zeros
strcpy(key, "SII");
strcpy(val, "0700");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().HasValue());

// Invalid SII - text at the end
strcpy(key, "SII");
strcpy(val, "123abc");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryIntervalIdle().HasValue());
}

// Test SAI (formerly CRA)
Expand All @@ -526,55 +524,55 @@ void DiscoveredTxtFieldSessionActiveInterval()
strcpy(key, "SAI");
strcpy(val, "1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( nodeData.Get<NodeData>().GetMrpRetryIntervalActive().HasValue());
EXPECT_TRUE( nodeData.Get<NodeData>().GetMrpRetryIntervalActive().Value() == 1_ms32);
EXPECT_TRUE(nodeData.Get<NodeData>().GetMrpRetryIntervalActive().HasValue());
EXPECT_TRUE(nodeData.Get<NodeData>().GetMrpRetryIntervalActive().Value() == 1_ms32);

// Maximum
strcpy(key, "SAI");
strcpy(val, "3600000");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( nodeData.Get<NodeData>().GetMrpRetryIntervalActive().HasValue());
EXPECT_TRUE( nodeData.Get<NodeData>().GetMrpRetryIntervalActive().Value() == 3600000_ms32);
EXPECT_TRUE(nodeData.Get<NodeData>().GetMrpRetryIntervalActive().HasValue());
EXPECT_TRUE(nodeData.Get<NodeData>().GetMrpRetryIntervalActive().Value() == 3600000_ms32);

// Test no other fields were populated
ResetRetryIntervalActive(nodeData);
EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get<NodeData>()));
EXPECT_TRUE(NodeDataIsEmpty(nodeData.Get<NodeData>()));

// Invalid SAI - negative value
strcpy(key, "SAI");
strcpy(val, "-1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().GetMrpRetryIntervalActive().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryIntervalActive().HasValue());

// Invalid SAI - greater than maximum
strcpy(key, "SAI");
strcpy(val, "3600001");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().GetMrpRetryIntervalActive().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryIntervalActive().HasValue());

// 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<NodeData>().GetMrpRetryIntervalActive().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryIntervalActive().HasValue());

// Invalid SAI - hexadecimal value
strcpy(key, "SAI");
strcpy(val, "0x20");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().GetMrpRetryIntervalActive().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryIntervalActive().HasValue());

// Invalid SAI - leading zeros
strcpy(key, "SAI");
strcpy(val, "0700");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().GetMrpRetryIntervalActive().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryIntervalActive().HasValue());

// Invalid SAI - text at the end
strcpy(key, "SAI");
strcpy(val, "123abc");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().GetMrpRetryIntervalActive().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryIntervalActive().HasValue());
}

// Test SAT (Session Active Threshold)
Expand All @@ -591,55 +589,55 @@ void DiscoveredTxtFieldSessionActiveThreshold()
strcpy(key, "SAT");
strcpy(val, "1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().HasValue());
EXPECT_TRUE( nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().Value() == 1_ms16);
EXPECT_TRUE(nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().HasValue());
EXPECT_TRUE(nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().Value() == 1_ms16);

// Maximum
strcpy(key, "SAT");
strcpy(val, "65535");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().HasValue());
EXPECT_TRUE( nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().Value() == 65535_ms16);
EXPECT_TRUE(nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().HasValue());
EXPECT_TRUE(nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().Value() == 65535_ms16);

// Test no other fields were populated
ResetRetryActiveThreshold(nodeData);
EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get<NodeData>()));
EXPECT_TRUE(NodeDataIsEmpty(nodeData.Get<NodeData>()));

// Invalid SAI - negative value
strcpy(key, "SAT");
strcpy(val, "-1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().HasValue());

// Invalid SAI - greater than maximum
strcpy(key, "SAT");
strcpy(val, "65536");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().HasValue());

// 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<NodeData>().GetMrpRetryActiveThreshold().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().HasValue());

// Invalid SAT - hexadecimal value
strcpy(key, "SAT");
strcpy(val, "0x20");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().HasValue());

// Invalid SAT - leading zeros
strcpy(key, "SAT");
strcpy(val, "0700");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().HasValue());

// Invalid SAT - text at the end
strcpy(key, "SAT");
strcpy(val, "123abc");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().HasValue());
EXPECT_TRUE(!nodeData.Get<NodeData>().GetMrpRetryActiveThreshold().HasValue());
}

// Test T (TCP support)
Expand All @@ -656,23 +654,23 @@ void DiscoveredTxtFieldTcpSupport()
strcpy(key, "T");
strcpy(val, "1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( nodeData.Get<NodeData>().supportsTcp);
EXPECT_TRUE(nodeData.Get<NodeData>().supportsTcp);

// Test no other fields were populated
nodeData.Get<NodeData>().supportsTcp = false;
EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get<NodeData>()));
EXPECT_TRUE(NodeDataIsEmpty(nodeData.Get<NodeData>()));

// False
strcpy(key, "T");
strcpy(val, "0");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( nodeData.Get<NodeData>().supportsTcp == false);
EXPECT_TRUE(nodeData.Get<NodeData>().supportsTcp == false);

// Invalid value, stil false
strcpy(key, "T");
strcpy(val, "asdf");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( nodeData.Get<NodeData>().supportsTcp == false);
EXPECT_TRUE(nodeData.Get<NodeData>().supportsTcp == false);
}

// Test ICD (ICD operation Mode)
Expand All @@ -689,27 +687,27 @@ void DiscoveredTxtFieldICDoperatesAsLIT()
strcpy(key, "ICD");
strcpy(val, "1");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( nodeData.Get<NodeData>().isICDOperatingAsLIT.HasValue());
EXPECT_TRUE( nodeData.Get<NodeData>().isICDOperatingAsLIT.Value());
EXPECT_TRUE(nodeData.Get<NodeData>().isICDOperatingAsLIT.HasValue());
EXPECT_TRUE(nodeData.Get<NodeData>().isICDOperatingAsLIT.Value());

// Test no other fields were populated
nodeData.Get<NodeData>().isICDOperatingAsLIT.ClearValue();
EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get<NodeData>()));
EXPECT_TRUE(NodeDataIsEmpty(nodeData.Get<NodeData>()));

// ICD is operating as a SIT device
strcpy(key, "ICD");
strcpy(val, "0");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( nodeData.Get<NodeData>().isICDOperatingAsLIT.HasValue());
EXPECT_TRUE( nodeData.Get<NodeData>().isICDOperatingAsLIT.Value() == false);
EXPECT_TRUE(nodeData.Get<NodeData>().isICDOperatingAsLIT.HasValue());
EXPECT_TRUE(nodeData.Get<NodeData>().isICDOperatingAsLIT.Value() == false);

nodeData.Get<NodeData>().isICDOperatingAsLIT.ClearValue();
EXPECT_TRUE( NodeDataIsEmpty(nodeData.Get<NodeData>()));
EXPECT_TRUE(NodeDataIsEmpty(nodeData.Get<NodeData>()));
// Invalid value, No key set
strcpy(key, "ICD");
strcpy(val, "asdf");
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( nodeData.Get<NodeData>().isICDOperatingAsLIT.HasValue() == false);
EXPECT_TRUE(nodeData.Get<NodeData>().isICDOperatingAsLIT.HasValue() == false);
}

// Test IsDeviceTreatedAsSleepy() with CRI
Expand All @@ -725,19 +723,19 @@ void DiscoveredTestIsDeviceSessionIdle()
CommonResolutionData & resolutionData = nodeData.Get<NodeData>();

// No key/val set, so the device can't be sleepy
EXPECT_TRUE( !nodeData.Get<NodeData>().IsDeviceTreatedAsSleepy(&defaultMRPConfig));
EXPECT_TRUE(!nodeData.Get<NodeData>().IsDeviceTreatedAsSleepy(&defaultMRPConfig));

// If the interval is the default value, the device is not sleepy
strcpy(key, "SII");
sprintf(val, "%d", static_cast<int>(CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL.count()));
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().IsDeviceTreatedAsSleepy(&defaultMRPConfig));
EXPECT_TRUE(!nodeData.Get<NodeData>().IsDeviceTreatedAsSleepy(&defaultMRPConfig));

// If the interval is greater than the default value, the device is sleepy
sprintf(key, "SII");
sprintf(val, "%d", static_cast<int>(CHIP_CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL.count() + 1));
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( nodeData.Get<NodeData>().IsDeviceTreatedAsSleepy(&defaultMRPConfig));
EXPECT_TRUE(nodeData.Get<NodeData>().IsDeviceTreatedAsSleepy(&defaultMRPConfig));
}

// Test IsDeviceTreatedAsSleepy() with CRA
Expand All @@ -753,19 +751,19 @@ void DiscoveredTestIsDeviceSessionActive()
CommonResolutionData & resolutionData = nodeData.Get<NodeData>();

// No key/val set, so the device can't be sleepy
EXPECT_TRUE( !nodeData.Get<NodeData>().IsDeviceTreatedAsSleepy(&defaultMRPConfig));
EXPECT_TRUE(!nodeData.Get<NodeData>().IsDeviceTreatedAsSleepy(&defaultMRPConfig));

// If the interval is the default value, the device is not sleepy
sprintf(key, "SAI");
sprintf(val, "%d", static_cast<int>(CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL.count()));
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( !nodeData.Get<NodeData>().IsDeviceTreatedAsSleepy(&defaultMRPConfig));
EXPECT_TRUE(!nodeData.Get<NodeData>().IsDeviceTreatedAsSleepy(&defaultMRPConfig));

// If the interval is greater than the default value, the device is sleepy
strcpy(key, "SAI");
sprintf(val, "%d", static_cast<int>(CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL.count() + 1));
FillNodeDataFromTxt(GetSpan(key), GetSpan(val), resolutionData);
EXPECT_TRUE( nodeData.Get<NodeData>().IsDeviceTreatedAsSleepy(&defaultMRPConfig));
EXPECT_TRUE(nodeData.Get<NodeData>().IsDeviceTreatedAsSleepy(&defaultMRPConfig));
}

// Test SAI (formally CRI)
Expand Down

0 comments on commit a632edb

Please sign in to comment.