Skip to content

Commit

Permalink
Allow empty events in report
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google committed May 11, 2022
1 parent d2de7c1 commit fb4669d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
14 changes: 1 addition & 13 deletions src/app/MessageDef/EventReportIBs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace app {
CHIP_ERROR EventReportIBs::Parser::CheckSchemaValidity() const
{
CHIP_ERROR err = CHIP_NO_ERROR;
size_t numEventReports = 0;
TLV::TLVReader reader;

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

++numEventReports;
}

PRETTY_PRINT("],");
Expand All @@ -65,16 +62,7 @@ CHIP_ERROR EventReportIBs::Parser::CheckSchemaValidity() const
// if we have exhausted this container
if (CHIP_END_OF_TLV == err)
{
// if we have at least one event report
if (numEventReports > 0)
{
err = CHIP_NO_ERROR;
}
else
{
ChipLogError(DataManagement, "PROTOCOL ERROR: Empty event reports");
err = CHIP_NO_ERROR;
}
err = CHIP_NO_ERROR;
}
ReturnErrorOnFailure(err);
ReturnErrorOnFailure(reader.ExitContainer(mOuterContainerType));
Expand Down
33 changes: 29 additions & 4 deletions src/app/tests/TestMessageDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,15 @@ void ParseEventReportIB(nlTestSuite * apSuite, EventReportIB::Parser & aEventRep
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
}

void BuildEventReports(nlTestSuite * apSuite, EventReportIBs::Builder & aEventReportsBuilder)
void BuildEventReports(nlTestSuite * apSuite, EventReportIBs::Builder & aEventReportsBuilder, bool aIsEmptyEvents)
{
EventReportIB::Builder & eventReportIBBuilder = aEventReportsBuilder.CreateEventReport();
NL_TEST_ASSERT(apSuite, aEventReportsBuilder.GetError() == CHIP_NO_ERROR);
BuildEventReportIB(apSuite, eventReportIBBuilder);

if (!aIsEmptyEvents)
{
BuildEventReportIB(apSuite, eventReportIBBuilder);
}
aEventReportsBuilder.EndOfEventReports();
NL_TEST_ASSERT(apSuite, aEventReportsBuilder.GetError() == CHIP_NO_ERROR);
}
Expand Down Expand Up @@ -1038,7 +1041,7 @@ void BuildReportDataMessage(nlTestSuite * apSuite, chip::TLV::TLVWriter & aWrite

EventReportIBs::Builder & eventReportIBs = reportDataMessageBuilder.CreateEventReports();
NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR);
BuildEventReports(apSuite, eventReportIBs);
BuildEventReports(apSuite, eventReportIBs, false /*aIsEmptyEvents*/);

reportDataMessageBuilder.MoreChunkedMessages(true).SuppressResponse(true);
NL_TEST_ASSERT(apSuite, reportDataMessageBuilder.GetError() == CHIP_NO_ERROR);
Expand Down Expand Up @@ -1695,7 +1698,28 @@ void EventReportsTest(nlTestSuite * apSuite, void * apContext)
EventReportIBs::Builder eventReportsBuilder;
writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize));
eventReportsBuilder.Init(&writer);
BuildEventReports(apSuite, eventReportsBuilder);
BuildEventReports(apSuite, eventReportsBuilder, false /*aIsEmptyEvents*/);
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);
ParseEventReports(apSuite, reader);
}

void EmptyEventReportsTest(nlTestSuite * apSuite, void * apContext)
{
CHIP_ERROR err = CHIP_NO_ERROR;
chip::System::PacketBufferTLVWriter writer;
chip::System::PacketBufferTLVReader reader;
EventReportIBs::Builder eventReportsBuilder;
writer.Init(chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSize));
eventReportsBuilder.Init(&writer);
BuildEventReports(apSuite, eventReportsBuilder, true /*aIsEmptyEvents*/);
chip::System::PacketBufferHandle buf;
err = writer.Finalize(&buf);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
Expand Down Expand Up @@ -2285,6 +2309,7 @@ const nlTest sTests[] =
NL_TEST_DEF("EventDataIBTest", EventDataIBTest),
NL_TEST_DEF("EventReportIBTest", EventReportIBTest),
NL_TEST_DEF("EventReportsTest", EventReportsTest),
NL_TEST_DEF("EmptyEventReportsTest", EmptyEventReportsTest),
NL_TEST_DEF("StatusIBTest", StatusIBTest),
NL_TEST_DEF("EventStatusIBTest", EventStatusIBTest),
NL_TEST_DEF("CommandPathIBTest", CommandPathIBTest),
Expand Down

0 comments on commit fb4669d

Please sign in to comment.