Skip to content

Commit

Permalink
Stronger tests for session reset for AttributePathExpandIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
andy31415 committed Dec 18, 2024
1 parent 68ec79c commit 0c36454
Showing 1 changed file with 147 additions and 50 deletions.
197 changes: 147 additions & 50 deletions src/app/tests/TestAttributePathExpandIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,39 @@ TEST(TestAttributePathExpandIterator, TestAllWildcard)
{ kMockEndpoint3, MockClusterId(4), Clusters::Globals::Attributes::AttributeList::Id },
};

size_t index = 0;
app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo);
auto session = iter.PrepareSearch();
{
size_t index = 0;
app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo);
auto session = iter.PrepareSearch();

for (; iter.Get(session, path); iter.Next(session))
{
ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId));
EXPECT_LT(index, ArraySize(paths));
EXPECT_EQ(paths[index], path);
index++;
}
EXPECT_EQ(index, ArraySize(paths));
}

for (; iter.Get(session, path); iter.Next(session))
// same test with session reset in each
{
ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId));
EXPECT_LT(index, ArraySize(paths));
EXPECT_EQ(paths[index], path);
index++;
size_t index = 0;
app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo);
auto session = iter.PrepareSearch();

for (; iter.Get(session, path); iter.Next(session))
{
ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId));
EXPECT_LT(index, ArraySize(paths));
EXPECT_EQ(paths[index], path);
index++;
session = iter.PrepareSearch();
}
EXPECT_EQ(index, ArraySize(paths));
}
EXPECT_EQ(index, ArraySize(paths));
}

TEST(TestAttributePathExpandIterator, TestWildcardEndpoint)
Expand Down Expand Up @@ -159,18 +179,36 @@ TEST(TestAttributePathExpandIterator, TestWildcardCluster)
{ kMockEndpoint3, MockClusterId(4), Clusters::Globals::Attributes::ClusterRevision::Id },
};

size_t index = 0;
app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo);
auto session = iter.PrepareSearch();
for (; iter.Get(session, path); iter.Next(session))
{
ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId));
EXPECT_LT(index, ArraySize(paths));
EXPECT_EQ(paths[index], path);
index++;
size_t index = 0;
app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo);
auto session = iter.PrepareSearch();
for (; iter.Get(session, path); iter.Next(session))
{
ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId));
EXPECT_LT(index, ArraySize(paths));
EXPECT_EQ(paths[index], path);
index++;
}
EXPECT_EQ(index, ArraySize(paths));
}

{
size_t index = 0;
app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo);
auto session = iter.PrepareSearch();
for (; iter.Get(session, path); iter.Next(session))
{
ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId));
EXPECT_LT(index, ArraySize(paths));
EXPECT_EQ(paths[index], path);
index++;
session = iter.PrepareSearch();
}
EXPECT_EQ(index, ArraySize(paths));
}
EXPECT_EQ(index, ArraySize(paths));
}

TEST(TestAttributePathExpandIterator, TestWildcardClusterGlobalAttributeNotInMetadata)
Expand All @@ -187,19 +225,38 @@ TEST(TestAttributePathExpandIterator, TestWildcardClusterGlobalAttributeNotInMet
{ kMockEndpoint3, MockClusterId(4), Clusters::Globals::Attributes::AttributeList::Id },
};

size_t index = 0;
app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo);
auto session = iter.PrepareSearch();
{
size_t index = 0;
app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo);
auto session = iter.PrepareSearch();

for (; iter.Get(session, path); iter.Next(session))
{
ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId));
EXPECT_LT(index, ArraySize(paths));
EXPECT_EQ(paths[index], path);
index++;
}
EXPECT_EQ(index, ArraySize(paths));
}

for (; iter.Get(session, path); iter.Next(session))
{
ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId));
EXPECT_LT(index, ArraySize(paths));
EXPECT_EQ(paths[index], path);
index++;
size_t index = 0;
app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo);
auto session = iter.PrepareSearch();

for (; iter.Get(session, path); iter.Next(session))
{
ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId));
EXPECT_LT(index, ArraySize(paths));
EXPECT_EQ(paths[index], path);
index++;
session = iter.PrepareSearch();
}
EXPECT_EQ(index, ArraySize(paths));
}
EXPECT_EQ(index, ArraySize(paths));
}

TEST(TestAttributePathExpandIterator, TestWildcardAttribute)
Expand All @@ -220,19 +277,39 @@ TEST(TestAttributePathExpandIterator, TestWildcardAttribute)
{ kMockEndpoint2, MockClusterId(3), Clusters::Globals::Attributes::AttributeList::Id },
};

size_t index = 0;
app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo);
auto session = iter.PrepareSearch();
{
size_t index = 0;
app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo);
auto session = iter.PrepareSearch();

for (; iter.Get(session, path); iter.Next(session))
{
ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId));
EXPECT_LT(index, ArraySize(paths));
EXPECT_EQ(paths[index], path);
index++;
}
EXPECT_EQ(index, ArraySize(paths));
}

for (; iter.Get(session, path); iter.Next(session))
// same test, with session reset
{
ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId));
EXPECT_LT(index, ArraySize(paths));
EXPECT_EQ(paths[index], path);
index++;
size_t index = 0;
app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo);
auto session = iter.PrepareSearch();

for (; iter.Get(session, path); iter.Next(session))
{
ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId));
EXPECT_LT(index, ArraySize(paths));
EXPECT_EQ(paths[index], path);
index++;
session = iter.PrepareSearch();
}
EXPECT_EQ(index, ArraySize(paths));
}
EXPECT_EQ(index, ArraySize(paths));
}

TEST(TestAttributePathExpandIterator, TestNoWildcard)
Expand Down Expand Up @@ -363,19 +440,39 @@ TEST(TestAttributePathExpandIterator, TestMultipleClusInfo)
{ kMockEndpoint2, MockClusterId(3), MockAttributeId(3) },
};

size_t index = 0;
app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo1);
auto session = iter.PrepareSearch();
{
size_t index = 0;
app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo1);
auto session = iter.PrepareSearch();

for (; iter.Get(session, path); iter.Next(session))
{
ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId));
EXPECT_LT(index, ArraySize(paths));
EXPECT_EQ(paths[index], path);
index++;
}
EXPECT_EQ(index, ArraySize(paths));
}

for (; iter.Get(session, path); iter.Next(session))
{
ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId));
EXPECT_LT(index, ArraySize(paths));
EXPECT_EQ(paths[index], path);
index++;
// test the SAME operation, however attempt to reset the sesssion each time
size_t index = 0;
app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo1);
auto session = iter.PrepareSearch();

for (; iter.Get(session, path); iter.Next(session))
{
ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId));
EXPECT_LT(index, ArraySize(paths));
EXPECT_EQ(paths[index], path);
index++;
session = iter.PrepareSearch(); // reset the session
}
EXPECT_EQ(index, ArraySize(paths));
}
EXPECT_EQ(index, ArraySize(paths));
}

} // namespace

0 comments on commit 0c36454

Please sign in to comment.