diff --git a/src/app/tests/TestCommandInteraction.cpp b/src/app/tests/TestCommandInteraction.cpp index 195580ce8702a5..dc6b6132341a63 100644 --- a/src/app/tests/TestCommandInteraction.cpp +++ b/src/app/tests/TestCommandInteraction.cpp @@ -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 { @@ -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); } } @@ -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 }; @@ -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); } }