Skip to content

Commit 98458eb

Browse files
committed
Test global attribute read via AAI
1 parent ae58110 commit 98458eb

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/app/codegen-interaction-model/tests/TestCodegenModelViaMocks.cpp

+56
Original file line numberDiff line numberDiff line change
@@ -1172,3 +1172,59 @@ TEST(TestCodegenModelViaMocks, AttributeAccessInterfaceListIncrementalRead)
11721172
ASSERT_TRUE(actual.e.data_equal("thisislongertofillupfaster"_span));
11731173
}
11741174
}
1175+
1176+
TEST(TestCodegenModelViaMocks, ReadGlobalAttributeAttributeList)
1177+
{
1178+
UseMockNodeConfig config(gTestNodeConfig);
1179+
chip::app::CodegenDataModel model;
1180+
ScopedMockAccessControl accessControl;
1181+
1182+
TestReadRequest testRequest(kAdminSubjectDescriptor,
1183+
ConcreteAttributePath(kMockEndpoint2, MockClusterId(3), AttributeList::Id));
1184+
1185+
// Data read via the encoder
1186+
std::unique_ptr<AttributeValueEncoder> encoder = testRequest.StartEncoding(&model);
1187+
ASSERT_EQ(model.ReadAttribute(testRequest.request, *encoder), CHIP_NO_ERROR);
1188+
ASSERT_EQ(testRequest.FinishEncoding(), CHIP_NO_ERROR);
1189+
1190+
// Validate after read
1191+
std::vector<DecodedAttributeData> attribute_data;
1192+
ASSERT_EQ(testRequest.encodedIBs.Decode(attribute_data), CHIP_NO_ERROR);
1193+
ASSERT_EQ(attribute_data.size(), 1u);
1194+
1195+
DecodedAttributeData & encodedData = attribute_data[0];
1196+
ASSERT_EQ(encodedData.attributePath, testRequest.request.path);
1197+
1198+
ASSERT_EQ(encodedData.dataReader.GetType(), TLV::kTLVType_Array);
1199+
1200+
std::vector<AttributeId> items;
1201+
ASSERT_EQ(DecodeList(encodedData.dataReader, items), CHIP_NO_ERROR);
1202+
1203+
// Mock data contains ClusterRevision and FeatureMap.
1204+
// After this, Global attributes are auto-added
1205+
std::vector<AttributeId> expected;
1206+
1207+
// Encoding in global-attribute-access-interface has a logic of:
1208+
// - Append global attributes in front of the first specified
1209+
// large number global attribute.
1210+
// Since ClusterRevision and FeatureMap are
1211+
// global attributes, the order here is reversed for them
1212+
for (AttributeId id : GlobalAttributesNotInMetadata)
1213+
{
1214+
expected.push_back(id);
1215+
}
1216+
expected.push_back(ClusterRevision::Id);
1217+
expected.push_back(FeatureMap::Id);
1218+
expected.push_back(MockAttributeId(1));
1219+
expected.push_back(MockAttributeId(2));
1220+
expected.push_back(MockAttributeId(3));
1221+
1222+
ASSERT_EQ(items.size(), expected.size());
1223+
1224+
// Since we have no std::vector formatter, comparing element by element is somewhat
1225+
// more readable in case of failure.
1226+
for (unsigned i = 0; i < items.size(); i++)
1227+
{
1228+
EXPECT_EQ(items[i], expected[i]);
1229+
}
1230+
}

0 commit comments

Comments
 (0)