Skip to content

Commit 8a64366

Browse files
andy31415andreilitvinbzbarsky-apple
authored
Use EncodableToTLV in TestCommandInteraction (#33694)
* 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 <bzbarsky@apple.com> --------- Co-authored-by: Andrei Litvin <andreilitvin@google.com> Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent 9a06cfc commit 8a64366

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

src/app/tests/TestCommandInteraction.cpp

+17-19
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ constexpr CommandId kTestCommandIdFillResponseMessage = 7;
8787
constexpr CommandId kTestNonExistCommandId = 0;
8888

8989
const app::CommandSender::TestOnlyMarker kCommandSenderTestOnlyMarker;
90+
91+
class SimpleTLVPayload : public app::DataModel::EncodableToTLV
92+
{
93+
public:
94+
CHIP_ERROR EncodeTo(TLV::TLVWriter & writer, TLV::Tag tag) const override
95+
{
96+
TLV::TLVType outerType;
97+
ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outerType));
98+
ReturnErrorOnFailure(writer.PutBoolean(chip::TLV::ContextTag(1), true));
99+
return writer.EndContainer(outerType);
100+
}
101+
};
102+
90103
} // namespace
91104

92105
namespace app {
@@ -199,12 +212,8 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aRequestCommandPat
199212
}
200213
else
201214
{
202-
const CommandHandler::InvokeResponseParameters prepareParams(aRequestCommandPath);
203-
const ConcreteCommandPath responseCommandPath = aRequestCommandPath;
204-
apCommandObj->PrepareInvokeResponseCommand(responseCommandPath, prepareParams);
205-
chip::TLV::TLVWriter * writer = apCommandObj->GetCommandDataIBTLVWriter();
206-
writer->PutBoolean(chip::TLV::ContextTag(1), true);
207-
apCommandObj->FinishCommand();
215+
SimpleTLVPayload payloadWriter;
216+
apCommandObj->AddResponse(aRequestCommandPath, aRequestCommandPath.mCommandId, payloadWriter);
208217
}
209218
}
210219

@@ -597,8 +606,6 @@ void TestCommandInteraction::AddInvalidInvokeRequestData(nlTestSuite * apSuite,
597606
void TestCommandInteraction::AddInvokeResponseData(nlTestSuite * apSuite, void * apContext, CommandHandler * apCommandHandler,
598607
bool aNeedStatusCode, CommandId aResponseCommandId, CommandId aRequestCommandId)
599608
{
600-
CHIP_ERROR err = CHIP_NO_ERROR;
601-
602609
constexpr EndpointId kTestEndpointId = 1;
603610
constexpr ClusterId kTestClusterId = 3;
604611
ConcreteCommandPath requestCommandPath = { kTestEndpointId, kTestClusterId, aRequestCommandId };
@@ -608,17 +615,8 @@ void TestCommandInteraction::AddInvokeResponseData(nlTestSuite * apSuite, void *
608615
}
609616
else
610617
{
611-
const CommandHandler::InvokeResponseParameters prepareParams(requestCommandPath);
612-
ConcreteCommandPath responseCommandPath = { kTestEndpointId, kTestClusterId, aResponseCommandId };
613-
err = apCommandHandler->PrepareInvokeResponseCommand(responseCommandPath, prepareParams);
614-
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
615-
616-
chip::TLV::TLVWriter * writer = apCommandHandler->GetCommandDataIBTLVWriter();
617-
618-
err = writer->PutBoolean(chip::TLV::ContextTag(1), true);
619-
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
620-
621-
err = apCommandHandler->FinishCommand();
618+
SimpleTLVPayload payloadWriter;
619+
CHIP_ERROR err = apCommandHandler->AddResponseData(requestCommandPath, aResponseCommandId, payloadWriter);
622620
NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR);
623621
}
624622
}

0 commit comments

Comments
 (0)