Skip to content

Commit

Permalink
allow empty attribute reports as well
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google committed May 11, 2022
1 parent 93a029f commit e795320
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/app/MessageDef/AttributeReportIBs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ namespace app {
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
CHIP_ERROR AttributeReportIBs::Parser::CheckSchemaValidity() const
{
CHIP_ERROR err = CHIP_NO_ERROR;
size_t numAttributeReportIBs = 0;
CHIP_ERROR err = CHIP_NO_ERROR;
TLV::TLVReader reader;

PRETTY_PRINT("AttributeReportIBs =");
Expand All @@ -55,8 +54,6 @@ CHIP_ERROR AttributeReportIBs::Parser::CheckSchemaValidity() const
ReturnErrorOnFailure(AttributeReport.CheckSchemaValidity());
PRETTY_PRINT_DECDEPTH();
}

++numAttributeReportIBs;
}

PRETTY_PRINT("],");
Expand All @@ -65,16 +62,7 @@ CHIP_ERROR AttributeReportIBs::Parser::CheckSchemaValidity() const
// if we have exhausted this container
if (CHIP_END_OF_TLV == err)
{
// if we have at least one Attribute report
if (numAttributeReportIBs > 0)
{
err = CHIP_NO_ERROR;
}
else
{
ChipLogError(DataManagement, "PROTOCOL ERROR: Empty Attribute reports");
err = CHIP_NO_ERROR;
}
err = CHIP_NO_ERROR;
}
ReturnErrorOnFailure(err);
ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType));
Expand Down
23 changes: 23 additions & 0 deletions src/app/tests/TestMessageDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,28 @@ void AttributeReportIBsTest(nlTestSuite * apSuite, void * apContext)
ParseAttributeReportIBs(apSuite, reader);
}

void EmptyAttributeReportIBsTest(nlTestSuite * apSuite, void * apContext)
{
CHIP_ERROR err = CHIP_NO_ERROR;
chip::System::PacketBufferTLVWriter writer;
chip::System::PacketBufferTLVReader reader;
AttributeReportIBs::Builder attributeReportIBsBuilder;
writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize));
attributeReportIBsBuilder.Init(&writer);
attributeReportIBsBuilder.EndOfAttributeReportIBs();
NL_TEST_ASSERT(apSuite, attributeReportIBsBuilder.GetError() == CHIP_NO_ERROR);
chip::System::PacketBufferHandle buf;
err = writer.Finalize(&buf);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

DebugPrettyPrint(buf);

reader.Init(std::move(buf));
err = reader.Next();
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
ParseAttributeReportIBs(apSuite, reader);
}

void StatusIBTest(nlTestSuite * apSuite, void * apContext)
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down Expand Up @@ -2301,6 +2323,7 @@ const nlTest sTests[] =
NL_TEST_DEF("AttributeDataIBsTest", AttributeDataIBsTest),
NL_TEST_DEF("AttributeReportIBTest", AttributeReportIBTest),
NL_TEST_DEF("AttributeReportIBsTest", AttributeReportIBsTest),
NL_TEST_DEF("EmptyAttributeReportIBsTest", EmptyAttributeReportIBsTest),
NL_TEST_DEF("EventPathTest", EventPathTest),
NL_TEST_DEF("EventPathsTest", EventPathsTest),
NL_TEST_DEF("EventDataIBTest", EventDataIBTest),
Expand Down

0 comments on commit e795320

Please sign in to comment.