Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
f30f3d5
Add `CommandTesting` infrastructure
LyudmilaKostanyan Oct 21, 2025
c1d6aee
Restyled by whitespace
restyled-commits Oct 21, 2025
9770887
Add status storage to `MockCommandHandler` for testing
LyudmilaKostanyan Oct 22, 2025
c855f9f
Restyled by clang-format
restyled-commits Oct 22, 2025
d8f0b34
Refactor `TestPushAVStreamTransportCluster`
LyudmilaKostanyan Oct 22, 2025
2731890
Replace single response with response array in `MockCommandHandler`
LyudmilaKostanyan Oct 22, 2025
6976e34
Update src/app/clusters/testing/CommandTesting.h
LyudmilaKostanyan Oct 22, 2025
17aabad
Update src/app/clusters/testing/CommandTesting.h
LyudmilaKostanyan Oct 22, 2025
5ccf691
Restyled by clang-format
restyled-commits Oct 22, 2025
cd5b281
Merge branch 'master' into CommandTesting
LyudmilaKostanyan Oct 23, 2025
bb1dee4
Merge branch 'master' into CommandTesting
LyudmilaKostanyan Oct 23, 2025
f35396f
Restyled by gn
restyled-commits Oct 23, 2025
eda168d
Merge branch 'master' into CommandTesting
LyudmilaKostanyan Oct 27, 2025
131b81e
Remove unused header file TestReadWriteAttribute.h from testing sourc…
LyudmilaKostanyan Oct 27, 2025
2276381
Update src/app/clusters/testing/CommandTesting.cpp
LyudmilaKostanyan Oct 27, 2025
12855fe
Remove unnecessary comments.
LyudmilaKostanyan Oct 27, 2025
6fecf03
Refactor `InvokeOperation::Invoke` to use generated request structs
LyudmilaKostanyan Oct 27, 2025
7298a14
Restyled by clang-format
restyled-commits Oct 27, 2025
51f37c2
Refactor `InvokeOperation` class in `CommandTesting.h`
LyudmilaKostanyan Oct 27, 2025
80d56de
Update src/app/clusters/diagnostic-logs-server/tests/TestDiagnosticLo…
LyudmilaKostanyan Oct 27, 2025
234a4e0
Update src/app/clusters/diagnostic-logs-server/tests/TestDiagnosticLo…
LyudmilaKostanyan Oct 27, 2025
353466d
Update src/app/clusters/diagnostic-logs-server/tests/TestDiagnosticLo…
LyudmilaKostanyan Oct 27, 2025
460bc34
Update src/app/clusters/diagnostic-logs-server/tests/TestDiagnosticLo…
LyudmilaKostanyan Oct 27, 2025
8511eae
Update src/app/clusters/diagnostic-logs-server/tests/TestDiagnosticLo…
LyudmilaKostanyan Oct 27, 2025
3f6e8f9
Update src/app/clusters/diagnostic-logs-server/tests/TestDiagnosticLo…
LyudmilaKostanyan Oct 27, 2025
045dfc1
Merge branch 'master' into CommandTesting
LyudmilaKostanyan Oct 27, 2025
cb0261d
Refactor `CommandTesting.h`
LyudmilaKostanyan Oct 27, 2025
0e39b9b
Update src/app/clusters/testing/CommandTesting.h
LyudmilaKostanyan Oct 27, 2025
1e9f140
Merge branch 'master' into CommandTesting
LyudmilaKostanyan Oct 29, 2025
a15010c
Refactor `ClusterTester` class to enhance command invocation capabili…
LyudmilaKostanyan Oct 29, 2025
60edc5a
Restyled by clang-format
restyled-commits Oct 29, 2025
b8fc040
Return helper function `InvokeCommand` to `ClusterTester`
LyudmilaKostanyan Oct 29, 2025
95e5b52
Restyled by clang-format
restyled-commits Oct 29, 2025
0eb0c33
Update src/app/clusters/testing/CommandTesting.h
LyudmilaKostanyan Oct 29, 2025
0287040
Refactoring of the `InvokeCommand` helper method:
LyudmilaKostanyan Oct 29, 2025
fef8b77
Restyled by clang-format
restyled-commits Oct 29, 2025
ea3e147
Refactor `TestGroupcastCluster` to use `MockCommandHandler` from `Com…
LyudmilaKostanyan Oct 29, 2025
7ab0d90
Merge branch 'master' into CommandTesting
LyudmilaKostanyan Oct 29, 2025
ba9cc8f
Merge branch 'master' into CommandTesting
LyudmilaKostanyan Oct 30, 2025
c2ce933
Updated comments in `CommandTesting.h` and removed `InvokeCommand` me…
LyudmilaKostanyan Oct 30, 2025
c9325cb
Restyled by clang-format
restyled-commits Oct 30, 2025
9faa42a
Refactor `ClusterTester` class to enhance command invocation.
LyudmilaKostanyan Oct 30, 2025
f6e375e
Update `ClusterTester` to use member buffer for TLV operations.
LyudmilaKostanyan Oct 30, 2025
a603bc1
Restyled by clang-format
restyled-commits Oct 30, 2025
6c81616
Updated comments in `ClusterTester.h`
LyudmilaKostanyan Oct 30, 2025
b2cb0a8
Enhance `ClusterTester` constructor to initialize `mHandler` and clea…
LyudmilaKostanyan Oct 30, 2025
f633116
Remove unused `mSubjectDescriptor` member from `TestPushAVStreamTrans…
LyudmilaKostanyan Oct 30, 2025
e2a435e
Restyled by clang-format
restyled-commits Oct 30, 2025
562b141
Enhance `Invoke` methods in `ClusterTester` to include `[[nodiscard]]…
LyudmilaKostanyan Oct 30, 2025
cc5eba3
Restyled by clang-format
restyled-commits Oct 30, 2025
8f58c46
Make `mHandler` a value in `ClusterTester` remove `unique_ptr` overloads
LyudmilaKostanyan Oct 30, 2025
a9864ac
Update `PacketBufferHandle` initialization to use maximum size constant
LyudmilaKostanyan Oct 30, 2025
7ca5ef8
Refactor `Invoke` method in `ClusterTester` to use `ReturnErrorOnFail…
LyudmilaKostanyan Oct 30, 2025
b767a42
Restyled by clang-format
restyled-commits Oct 30, 2025
3d503df
Simplify `ClusterTester` `InvokeOperation` API and clarify intent
LyudmilaKostanyan Oct 30, 2025
83a2327
Restyled by clang-format
restyled-commits Oct 30, 2025
d73ccfc
Merge branch 'master' into CommandTesting
LyudmilaKostanyan Oct 31, 2025
56a5c72
Update `MockCommandHandler::AddResponseData` to use a fixed buffer si…
LyudmilaKostanyan Oct 31, 2025
4a1d16d
Update `MockCommandHandler::AddResponseData` to use `kMaxAppMessageLe…
LyudmilaKostanyan Oct 31, 2025
098d4d9
Refactor `ClusterTester` to simplify command invocation methods and u…
LyudmilaKostanyan Oct 31, 2025
41d4647
Restyled by clang-format
restyled-commits Oct 31, 2025
31a5ed7
Remove unused `ClusterTester` methods `GetHandler()` and `DecodeRespo…
LyudmilaKostanyan Oct 31, 2025
b05e64f
Refactor to remove namespace for types
LyudmilaKostanyan Oct 31, 2025
0af66dd
Restyled by clang-format
restyled-commits Oct 31, 2025
1d5a243
Merge branch 'master' into CommandTesting
LyudmilaKostanyan Nov 3, 2025
48e0227
Remove unused `GetRequest()` method from `ClusterTester`
LyudmilaKostanyan Nov 3, 2025
c177b55
Restyled by clang-format
restyled-commits Nov 3, 2025
aae7d67
Remove `Invoke` useless methods and Refactor `JoinGroup` command test…
LyudmilaKostanyan Nov 3, 2025
846e90f
Restyled by clang-format
restyled-commits Nov 3, 2025
79814c9
Change `ReturnErrorOnFailure` to `VerifyOrReturnValue`
LyudmilaKostanyan Nov 3, 2025
a48de07
Refactor `ClusterTester` to simplify command invocation and update `T…
LyudmilaKostanyan Nov 3, 2025
a68b53a
Restyled by clang-format
restyled-commits Nov 3, 2025
7602cee
Merge branch 'master' into CommandTesting
LyudmilaKostanyan Nov 4, 2025
2bda6d5
Update src/app/clusters/testing/CommandTesting.cpp
LyudmilaKostanyan Nov 4, 2025
aa9e1b1
Remove unused member variables from `ClusterTester.h`
LyudmilaKostanyan Nov 4, 2025
ef56cab
Replace `push_back` to `emplace_back`
LyudmilaKostanyan Nov 4, 2025
106c462
Rename `CommandTesting` to `MockCommandHandler`
LyudmilaKostanyan Nov 4, 2025
f2659b1
Update `BUILD.gn`
LyudmilaKostanyan Nov 4, 2025
c0ac816
Restyled by clang-format
restyled-commits Nov 4, 2025
3322d4c
Update src/app/clusters/testing/ClusterTester.h
LyudmilaKostanyan Nov 4, 2025
e61dd2d
Update src/app/clusters/diagnostic-logs-server/tests/TestDiagnosticLo…
LyudmilaKostanyan Nov 4, 2025
d66109a
Update src/app/clusters/groupcast/tests/TestGroupcastCluster.cpp
LyudmilaKostanyan Nov 4, 2025
4fe4623
Update src/app/clusters/push-av-stream-transport-server/tests/TestPus…
LyudmilaKostanyan Nov 4, 2025
2a337bd
Update src/app/clusters/testing/MockCommandHandler.cpp
LyudmilaKostanyan Nov 4, 2025
87d9d71
Refactor `MockCommandHandler`
LyudmilaKostanyan Nov 4, 2025
a6c6a2e
Fix android compile error (#41761)
yufengwangca Nov 4, 2025
74e2465
Refactor `MockCommandHandler` - updating fabric index initialization …
LyudmilaKostanyan Nov 4, 2025
7baa51c
Refactoring of the code
restyled-commits Nov 4, 2025
a98afd9
Merge branch 'master' into CommandTesting
LyudmilaKostanyan Nov 5, 2025
53bb9b1
Enhance `ClusterTester` and `JoinGroupCommand` test
LyudmilaKostanyan Nov 5, 2025
e206c61
Restyled by clang-format
restyled-commits Nov 5, 2025
0d2beff
Merge branch 'master' into CommandTesting
LyudmilaKostanyan Nov 5, 2025
9bc8b56
Restyled by clang-format
restyled-commits Nov 5, 2025
aee693f
Enhance documentation in `ClusterTester.h` to clarify usage of Invoke…
LyudmilaKostanyan Nov 5, 2025
048e741
Update src/app/clusters/testing/ClusterTester.h
LyudmilaKostanyan Nov 5, 2025
46e400c
Restyled by clang-format
restyled-commits Nov 5, 2025
fe6cd84
Handle decode failure in `ClusterTester` Invoke by setting status and…
LyudmilaKostanyan Nov 6, 2025
92823ff
Merge branch 'master' into CommandTesting
LyudmilaKostanyan Nov 6, 2025
2ad2ac9
Refactor `ClusterTester` to improve command invocation and response h…
LyudmilaKostanyan Nov 6, 2025
397dc02
Restyled by clang-format
restyled-commits Nov 6, 2025
ecc49a4
Fix `IsSuccess()` to handle `NullObjectType` response correctly
LyudmilaKostanyan Nov 6, 2025
36d48e0
Merge branch 'master' into CommandTesting
LyudmilaKostanyan Nov 6, 2025
73b82a1
Restyled by whitespace
restyled-commits Nov 6, 2025
a5d1988
Restyled by clang-format
restyled-commits Nov 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/clusters/diagnostic-logs-server/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ chip_test_suite("tests") {

public_deps = [
"${chip_root}/src/app/clusters/diagnostic-logs-server",
"${chip_root}/src/app/clusters/testing:testing",
"${chip_root}/src/lib/support",
"${chip_root}/src/protocols/bdx",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <app/MessageDef/CommandDataIB.h>
#include <app/clusters/diagnostic-logs-server/DiagnosticLogsCluster.h>
#include <app/clusters/diagnostic-logs-server/DiagnosticLogsProviderDelegate.h>
#include <app/clusters/testing/MockCommandHandler.h>
#include <lib/support/Span.h>
#include <protocols/bdx/DiagnosticLogs.h>

Expand All @@ -36,72 +37,6 @@ using chip::Protocols::InteractionModel::Status;

static constexpr EndpointId kRootEndpoint = 0;

class MockCommandHandler : public CommandHandler
{
public:
~MockCommandHandler() override {}

struct ResponseRecord
{
ConcreteCommandPath path;
CommandId commandId;
chip::System::PacketBufferHandle encodedData;
};

CHIP_ERROR FallibleAddStatus(const ConcreteCommandPath & aRequestCommandPath,
const Protocols::InteractionModel::ClusterStatusCode & aStatus,
const char * context = nullptr) override
{
return CHIP_NO_ERROR;
}

void AddStatus(const ConcreteCommandPath & aRequestCommandPath, const Protocols::InteractionModel::ClusterStatusCode & aStatus,
const char * context = nullptr) override
{
CHIP_ERROR err = FallibleAddStatus(aRequestCommandPath, aStatus, context);
VerifyOrDie(err == CHIP_NO_ERROR);
}

FabricIndex GetAccessingFabricIndex() const override { return mFabricIndex; }

CHIP_ERROR AddResponseData(const ConcreteCommandPath & aRequestCommandPath, CommandId aResponseCommandId,
const DataModel::EncodableToTLV & aEncodable) override
{
chip::System::PacketBufferHandle handle = chip::MessagePacketBuffer::New(1024);
VerifyOrReturnError(!handle.IsNull(), CHIP_ERROR_NO_MEMORY);
TLV::TLVWriter baseWriter;
baseWriter.Init(handle->Start(), handle->MaxDataLength());
DataModel::FabricAwareTLVWriter writer(baseWriter, /*fabricIndex*/ 1);
TLV::TLVType ct;
ReturnErrorOnFailure(
static_cast<TLV::TLVWriter &>(writer).StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, ct));
ReturnErrorOnFailure(aEncodable.EncodeTo(writer, TLV::ContextTag(app::CommandDataIB::Tag::kFields)));
ReturnErrorOnFailure(static_cast<TLV::TLVWriter &>(writer).EndContainer(ct));
handle->SetDataLength(static_cast<TLV::TLVWriter &>(writer).GetLengthWritten());
mResponse.path = aRequestCommandPath;
mResponse.commandId = aResponseCommandId;
mResponse.encodedData = std::move(handle);
return CHIP_NO_ERROR;
}

void AddResponse(const ConcreteCommandPath & aRequestCommandPath, CommandId aResponseCommandId,
const DataModel::EncodableToTLV & aEncodable) override
{
(void) AddResponseData(aRequestCommandPath, aResponseCommandId, aEncodable);
}

bool IsTimedInvoke() const override { return false; }
void FlushAcksRightAwayOnSlowCommand() override {}
Access::SubjectDescriptor GetSubjectDescriptor() const override { return Access::SubjectDescriptor{}; }
Messaging::ExchangeContext * GetExchangeContext() const override { return nullptr; }

const ResponseRecord & GetResponse() const { return mResponse; }

private:
ResponseRecord mResponse;
FabricIndex mFabricIndex = 0;
};

class MockDelegate : public DiagnosticLogs::DiagnosticLogsProviderDelegate
{
public:
Expand Down Expand Up @@ -150,25 +85,11 @@ class MockDelegate : public DiagnosticLogs::DiagnosticLogsProviderDelegate
uint16_t bufferSize = 0;
};

static Commands::RetrieveLogsResponse::DecodableType DecodeRetrieveLogsResponse(const MockCommandHandler::ResponseRecord & rec)
static Commands::RetrieveLogsResponse::DecodableType DecodeRetrieveLogsResponse(const Testing::MockCommandHandler & handler)
{
TLV::TLVReader reader;
reader.Init(rec.encodedData->Start(), static_cast<uint32_t>(rec.encodedData->DataLength()));

CHIP_ERROR err = reader.Next();
EXPECT_EQ(err, CHIP_NO_ERROR);

TLV::TLVReader outer;
err = reader.OpenContainer(outer);
EXPECT_EQ(err, CHIP_NO_ERROR);

err = outer.Next();
EXPECT_EQ(err, CHIP_NO_ERROR);
EXPECT_TRUE(IsContextTag(outer.GetTag()));
EXPECT_EQ(TagNumFromTag(outer.GetTag()), chip::to_underlying(CommandDataIB::Tag::kFields));

Commands::RetrieveLogsResponse::DecodableType decoded;
EXPECT_EQ(decoded.Decode(outer), CHIP_NO_ERROR);
CHIP_ERROR err = handler.DecodeResponse(decoded);
EXPECT_EQ(err, CHIP_NO_ERROR);
return decoded;
}

Expand All @@ -188,10 +109,13 @@ TEST_F(TestDiagnosticLogsCluster, ResponsePayload_WithDelegate_Success)
diagnosticLogsCluster.SetDelegate(&delegate);

const ConcreteCommandPath kPath{ kRootEndpoint, DiagnosticLogs::Id, DiagnosticLogs::Commands::RetrieveLogsRequest::Id };
MockCommandHandler handler;
Testing::MockCommandHandler handler;
diagnosticLogsCluster.HandleLogRequestForResponsePayload(&handler, kPath, DiagnosticLogs::IntentEnum::kEndUserSupport);
EXPECT_EQ(handler.GetResponse().commandId, DiagnosticLogs::Commands::RetrieveLogsResponse::Id);
auto decoded = DecodeRetrieveLogsResponse(handler.GetResponse());

// Verify we have exactly one response
EXPECT_EQ(handler.GetResponseCount(), static_cast<size_t>(1));
EXPECT_EQ(handler.GetResponseCommandId(), DiagnosticLogs::Commands::RetrieveLogsResponse::Id);
auto decoded = DecodeRetrieveLogsResponse(handler);
EXPECT_EQ(decoded.status, DiagnosticLogs::StatusEnum::kSuccess);
size_t logContentSize = decoded.logContent.size();
EXPECT_EQ(logContentSize, sizeof(buffer));
Expand All @@ -208,11 +132,14 @@ TEST_F(TestDiagnosticLogsCluster, Bdx_WithDelegate_kExhausted)
diagnosticLogsCluster.SetDelegate(&delegate);

const ConcreteCommandPath kPath{ kRootEndpoint, DiagnosticLogs::Id, DiagnosticLogs::Commands::RetrieveLogsRequest::Id };
MockCommandHandler handler;
Testing::MockCommandHandler handler;
diagnosticLogsCluster.HandleLogRequestForBdx(&handler, kPath, DiagnosticLogs::IntentEnum::kEndUserSupport,
MakeOptional(CharSpan::fromCharString("enduser.log")));
EXPECT_EQ(handler.GetResponse().commandId, DiagnosticLogs::Commands::RetrieveLogsResponse::Id);
auto decoded = DecodeRetrieveLogsResponse(handler.GetResponse());

// Verify we have exactly one response
EXPECT_EQ(handler.GetResponseCount(), static_cast<size_t>(1));
EXPECT_EQ(handler.GetResponseCommandId(), DiagnosticLogs::Commands::RetrieveLogsResponse::Id);
auto decoded = DecodeRetrieveLogsResponse(handler);
EXPECT_EQ(decoded.status, DiagnosticLogs::StatusEnum::kExhausted);
size_t logContentSize = decoded.logContent.size();
EXPECT_EQ(logContentSize, sizeof(buffer));
Expand All @@ -228,11 +155,14 @@ TEST_F(TestDiagnosticLogsCluster, Bdx_WithDelegate_kExhausted_with_buffer_greate
diagnosticLogsCluster.SetDelegate(&delegate);

const ConcreteCommandPath kPath{ kRootEndpoint, DiagnosticLogs::Id, DiagnosticLogs::Commands::RetrieveLogsRequest::Id };
MockCommandHandler handler;
Testing::MockCommandHandler handler;
diagnosticLogsCluster.HandleLogRequestForBdx(&handler, kPath, DiagnosticLogs::IntentEnum::kEndUserSupport,
MakeOptional(CharSpan::fromCharString("enduser.log")));
EXPECT_EQ(handler.GetResponse().commandId, DiagnosticLogs::Commands::RetrieveLogsResponse::Id);
auto decoded = DecodeRetrieveLogsResponse(handler.GetResponse());

// Verify we have exactly one response
EXPECT_EQ(handler.GetResponseCount(), static_cast<size_t>(1));
EXPECT_EQ(handler.GetResponseCommandId(), DiagnosticLogs::Commands::RetrieveLogsResponse::Id);
auto decoded = DecodeRetrieveLogsResponse(handler);
EXPECT_EQ(decoded.status, DiagnosticLogs::StatusEnum::kExhausted);
size_t logContentSize = decoded.logContent.size();

Expand All @@ -245,10 +175,13 @@ TEST_F(TestDiagnosticLogsCluster, ResponsePayload_NoDelegate_NoLogs)
DiagnosticLogsCluster diagnosticLogsCluster;

const ConcreteCommandPath kPath{ kRootEndpoint, DiagnosticLogs::Id, DiagnosticLogs::Commands::RetrieveLogsRequest::Id };
MockCommandHandler handler;
Testing::MockCommandHandler handler;
diagnosticLogsCluster.HandleLogRequestForResponsePayload(&handler, kPath, DiagnosticLogs::IntentEnum::kEndUserSupport);
EXPECT_EQ(handler.GetResponse().commandId, DiagnosticLogs::Commands::RetrieveLogsResponse::Id);
auto decoded = DecodeRetrieveLogsResponse(handler.GetResponse());

// Verify we have exactly one response
EXPECT_EQ(handler.GetResponseCount(), static_cast<size_t>(1));
EXPECT_EQ(handler.GetResponseCommandId(), DiagnosticLogs::Commands::RetrieveLogsResponse::Id);
auto decoded = DecodeRetrieveLogsResponse(handler);
EXPECT_EQ(decoded.status, DiagnosticLogs::StatusEnum::kNoLogs);
}

Expand All @@ -262,10 +195,13 @@ TEST_F(TestDiagnosticLogsCluster, ResponsePayload_ZeroBufferSize_NoLogs)
diagnosticLogsCluster.SetDelegate(&delegate);

const ConcreteCommandPath kPath{ kRootEndpoint, DiagnosticLogs::Id, DiagnosticLogs::Commands::RetrieveLogsRequest::Id };
MockCommandHandler handler;
Testing::MockCommandHandler handler;
diagnosticLogsCluster.HandleLogRequestForResponsePayload(&handler, kPath, DiagnosticLogs::IntentEnum::kEndUserSupport);
EXPECT_EQ(handler.GetResponse().commandId, DiagnosticLogs::Commands::RetrieveLogsResponse::Id);
auto decoded = DecodeRetrieveLogsResponse(handler.GetResponse());

// Verify we have exactly one response
EXPECT_EQ(handler.GetResponseCount(), static_cast<size_t>(1));
EXPECT_EQ(handler.GetResponseCommandId(), DiagnosticLogs::Commands::RetrieveLogsResponse::Id);
auto decoded = DecodeRetrieveLogsResponse(handler);
EXPECT_EQ(decoded.status, DiagnosticLogs::StatusEnum::kNoLogs);
}

Expand All @@ -274,11 +210,14 @@ TEST_F(TestDiagnosticLogsCluster, Bdx_NoDelegate_NoLogs)
DiagnosticLogsCluster diagnosticLogsCluster;

const ConcreteCommandPath kPath{ kRootEndpoint, DiagnosticLogs::Id, DiagnosticLogs::Commands::RetrieveLogsRequest::Id };
MockCommandHandler handler;
Testing::MockCommandHandler handler;
diagnosticLogsCluster.HandleLogRequestForBdx(&handler, kPath, DiagnosticLogs::IntentEnum::kEndUserSupport,
MakeOptional(CharSpan::fromCharString("enduser.log")));
EXPECT_EQ(handler.GetResponse().commandId, DiagnosticLogs::Commands::RetrieveLogsResponse::Id);
auto decoded = DecodeRetrieveLogsResponse(handler.GetResponse());

// Verify we have exactly one response
EXPECT_EQ(handler.GetResponseCount(), static_cast<size_t>(1));
EXPECT_EQ(handler.GetResponseCommandId(), DiagnosticLogs::Commands::RetrieveLogsResponse::Id);
auto decoded = DecodeRetrieveLogsResponse(handler);
EXPECT_EQ(decoded.status, DiagnosticLogs::StatusEnum::kNoLogs);
}

Expand Down
83 changes: 8 additions & 75 deletions src/app/clusters/groupcast/tests/TestGroupcastCluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <app/clusters/groupcast/GroupcastCluster.h>
#include <app/clusters/testing/AttributeTesting.h>
#include <app/clusters/testing/ClusterTester.h>
#include <app/clusters/testing/MockCommandHandler.h>
#include <app/data-model-provider/MetadataTypes.h>
#include <app/server-cluster/DefaultServerCluster.h>
#include <app/server-cluster/testing/TestServerClusterContext.h>
Expand All @@ -39,75 +40,6 @@ using namespace chip::app::Clusters::Groupcast;
using chip::app::DataModel::AcceptedCommandEntry;
using chip::app::DataModel::AttributeEntry;

class MockCommandHandler : public app::CommandHandler
{
public:
~MockCommandHandler() override {}

struct ResponseRecord
{
app::ConcreteCommandPath path;
CommandId commandId;
System::PacketBufferHandle encodedData;
};

CHIP_ERROR FallibleAddStatus(const app::ConcreteCommandPath & aRequestCommandPath,
const Protocols::InteractionModel::ClusterStatusCode & aStatus,
const char * context = nullptr) override
{
return CHIP_NO_ERROR;
}

void AddStatus(const app::ConcreteCommandPath & aRequestCommandPath,
const Protocols::InteractionModel::ClusterStatusCode & aStatus, const char * context = nullptr) override
{
CHIP_ERROR err = FallibleAddStatus(aRequestCommandPath, aStatus, context);
VerifyOrDie(err == CHIP_NO_ERROR);
}

FabricIndex GetAccessingFabricIndex() const override { return mFabricIndex; }

CHIP_ERROR AddResponseData(const app::ConcreteCommandPath & aRequestCommandPath, CommandId aResponseCommandId,
const app::DataModel::EncodableToTLV & aEncodable) override
{
System::PacketBufferHandle handle = MessagePacketBuffer::New(1024);
VerifyOrReturnError(!handle.IsNull(), CHIP_ERROR_NO_MEMORY);
TLV::TLVWriter baseWriter;
baseWriter.Init(handle->Start(), handle->MaxDataLength());
app::DataModel::FabricAwareTLVWriter writer(baseWriter, mFabricIndex);
TLV::TLVType ct;
ReturnErrorOnFailure(
static_cast<TLV::TLVWriter &>(writer).StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, ct));
ReturnErrorOnFailure(aEncodable.EncodeTo(writer, TLV::ContextTag(app::CommandDataIB::Tag::kFields)));
ReturnErrorOnFailure(static_cast<TLV::TLVWriter &>(writer).EndContainer(ct));
handle->SetDataLength(static_cast<TLV::TLVWriter &>(writer).GetLengthWritten());
mResponse.path = aRequestCommandPath;
mResponse.commandId = aResponseCommandId;
mResponse.encodedData = std::move(handle);
return CHIP_NO_ERROR;
}

void AddResponse(const app::ConcreteCommandPath & aRequestCommandPath, CommandId aResponseCommandId,
const app::DataModel::EncodableToTLV & aEncodable) override
{
(void) AddResponseData(aRequestCommandPath, aResponseCommandId, aEncodable);
}

bool IsTimedInvoke() const override { return false; }
void FlushAcksRightAwayOnSlowCommand() override {}
Access::SubjectDescriptor GetSubjectDescriptor() const override { return Access::SubjectDescriptor{}; }
Messaging::ExchangeContext * GetExchangeContext() const override { return nullptr; }

const ResponseRecord & GetResponse() const { return mResponse; }

// Optional for test configuration
void SetFabricIndex(FabricIndex index) { mFabricIndex = index; }

private:
ResponseRecord mResponse;
FabricIndex mFabricIndex = 0;
};

// initialize memory as ReadOnlyBufferBuilder may allocate
struct TestGroupcastCluster : public ::testing::Test
{
Expand Down Expand Up @@ -183,12 +115,13 @@ TEST_F(TestGroupcastCluster, TestJoinGroupCommand)
cmdData.gracePeriod = MakeOptional(0U);
cmdData.useAuxiliaryACL = MakeOptional(true);

MockCommandHandler cmdHandler;
chip::app::Testing::MockCommandHandler cmdHandler;
chip::Test::ClusterTester tester(cluster);
auto result = tester.InvokeCommand(Commands::JoinGroup::Id, cmdData, &cmdHandler);
ASSERT_TRUE(result.has_value());
EXPECT_EQ(result.value().GetStatusCode().GetStatus(), // NOLINT(bugprone-unchecked-optional-access)
Protocols::InteractionModel::Status::Failure); // Currently expect Failure as JoinGroup command returns
// CHIP_ERROR_NOT_IMPLEMENTED
auto result =
tester.Invoke<Commands::JoinGroup::Type::ResponseType, Commands::JoinGroup::Type>(Commands::JoinGroup::Id, cmdData);
ASSERT_TRUE(result.status.has_value());
EXPECT_EQ(result.status.value().GetStatusCode().GetStatus(), // NOLINT(bugprone-unchecked-optional-access)
Protocols::InteractionModel::Status::Failure); // Currently expect Failure as JoinGroup command returns
// CHIP_ERROR_NOT_IMPLEMENTED
}
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ chip_test_suite("tests") {

public_deps = [
"${chip_root}/src/app/clusters/push-av-stream-transport-server",
"${chip_root}/src/app/clusters/testing",
"${chip_root}/src/app/clusters/testing:testing",
"${chip_root}/src/app/clusters/tls-client-management-server",
"${chip_root}/src/app/tests:helpers",
"${chip_root}/src/lib/core:string-builder-adapters",
Expand Down
Loading
Loading