Skip to content

Commit

Permalink
Use EncodableToTLV in TestCommandInteraction (project-chip#33694)
Browse files Browse the repository at this point in the history
* An initial conversion. however we FAIL right now....

* ifdef to compare ok/fail

* Fix usage of internal calls ... we want the re-shuffling of responses to happen

* Restyle

* Update src/app/tests/TestCommandInteraction.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

---------

Co-authored-by: Andrei Litvin <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
3 people authored Jun 3, 2024
1 parent 9a06cfc commit 8a64366
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/app/tests/TestCommandInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ constexpr CommandId kTestCommandIdFillResponseMessage = 7;
constexpr CommandId kTestNonExistCommandId = 0;

const app::CommandSender::TestOnlyMarker kCommandSenderTestOnlyMarker;

class SimpleTLVPayload : public app::DataModel::EncodableToTLV
{
public:
CHIP_ERROR EncodeTo(TLV::TLVWriter & writer, TLV::Tag tag) const override
{
TLV::TLVType outerType;
ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outerType));
ReturnErrorOnFailure(writer.PutBoolean(chip::TLV::ContextTag(1), true));
return writer.EndContainer(outerType);
}
};

} // namespace

namespace app {
Expand Down Expand Up @@ -199,12 +212,8 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aRequestCommandPat
}
else
{
const CommandHandler::InvokeResponseParameters prepareParams(aRequestCommandPath);
const ConcreteCommandPath responseCommandPath = aRequestCommandPath;
apCommandObj->PrepareInvokeResponseCommand(responseCommandPath, prepareParams);
chip::TLV::TLVWriter * writer = apCommandObj->GetCommandDataIBTLVWriter();
writer->PutBoolean(chip::TLV::ContextTag(1), true);
apCommandObj->FinishCommand();
SimpleTLVPayload payloadWriter;
apCommandObj->AddResponse(aRequestCommandPath, aRequestCommandPath.mCommandId, payloadWriter);
}
}

Expand Down Expand Up @@ -597,8 +606,6 @@ void TestCommandInteraction::AddInvalidInvokeRequestData(nlTestSuite * apSuite,
void TestCommandInteraction::AddInvokeResponseData(nlTestSuite * apSuite, void * apContext, CommandHandler * apCommandHandler,
bool aNeedStatusCode, CommandId aResponseCommandId, CommandId aRequestCommandId)
{
CHIP_ERROR err = CHIP_NO_ERROR;

constexpr EndpointId kTestEndpointId = 1;
constexpr ClusterId kTestClusterId = 3;
ConcreteCommandPath requestCommandPath = { kTestEndpointId, kTestClusterId, aRequestCommandId };
Expand All @@ -608,17 +615,8 @@ void TestCommandInteraction::AddInvokeResponseData(nlTestSuite * apSuite, void *
}
else
{
const CommandHandler::InvokeResponseParameters prepareParams(requestCommandPath);
ConcreteCommandPath responseCommandPath = { kTestEndpointId, kTestClusterId, aResponseCommandId };
err = apCommandHandler->PrepareInvokeResponseCommand(responseCommandPath, prepareParams);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

chip::TLV::TLVWriter * writer = apCommandHandler->GetCommandDataIBTLVWriter();

err = writer->PutBoolean(chip::TLV::ContextTag(1), true);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);

err = apCommandHandler->FinishCommand();
SimpleTLVPayload payloadWriter;
CHIP_ERROR err = apCommandHandler->AddResponseData(requestCommandPath, aResponseCommandId, payloadWriter);
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
}
}
Expand Down

0 comments on commit 8a64366

Please sign in to comment.