Skip to content

Commit 7cee1f4

Browse files
Fix unit tests.
1 parent 880d2f2 commit 7cee1f4

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ using namespace chip::app::Clusters::Actions;
2424
using namespace chip::app::Clusters::Actions::Attributes;
2525
using namespace chip::Protocols::InteractionModel;
2626

27+
namespace {
2728
Clusters::Actions::ActionsDelegateImpl * sActionsDelegateImpl = nullptr;
2829
Clusters::Actions::ActionsServer * sActionsServer = nullptr;
30+
} // namespace
2931

3032
CHIP_ERROR ActionsDelegateImpl::ReadActionAtIndex(uint16_t index, ActionStructStorage & action)
3133
{

src/app/clusters/actions-server/actions-server.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ void ActionsServer::Shutdown()
4545

4646
CHIP_ERROR ActionsServer::Init()
4747
{
48-
// Check if the cluster has been selected in zap
49-
VerifyOrDie(emberAfContainsServer(mEndpointId, Actions::Id) == true);
50-
5148
ReturnErrorOnFailure(CommandHandlerInterfaceRegistry::Instance().RegisterCommandHandler(this));
5249
VerifyOrReturnError(AttributeAccessInterfaceRegistry::Instance().Register(this), CHIP_ERROR_INCORRECT_STATE);
5350
return CHIP_NO_ERROR;
@@ -111,7 +108,6 @@ CHIP_ERROR ActionsServer::ReadActionListAttribute(const ConcreteReadAttributePat
111108
{
112109
ActionStructStorage action;
113110
CHIP_ERROR err = mDelegate->ReadActionAtIndex(i, action);
114-
115111
if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED)
116112
{
117113
return CHIP_NO_ERROR;
@@ -128,7 +124,6 @@ CHIP_ERROR ActionsServer::ReadEndpointListAttribute(const ConcreteReadAttributeP
128124
for (uint16_t i = 0; i < kMaxEndpointListLength; i++)
129125
{
130126
EndpointListStorage epList;
131-
132127
CHIP_ERROR err = mDelegate->ReadEndpointListAtIndex(i, epList);
133128
if (err == CHIP_ERROR_PROVIDER_LIST_EXHAUSTED)
134129
{

src/app/tests/TestActionsCluster.cpp

+19-22
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,12 @@
3333
#include <protocols/interaction_model/Constants.h>
3434
#include <pw_unit_test/framework.h>
3535

36-
#ifdef CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT
37-
#undef CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT
38-
#define CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT 1
39-
#endif
40-
4136
namespace chip {
4237
namespace app {
4338

4439
using namespace Clusters::Actions;
4540
using namespace chip::Protocols::InteractionModel;
4641

47-
class TestActionsDelegateImpl;
48-
4942
class TestActionsDelegateImpl : public Clusters::Actions::Delegate
5043
{
5144
public:
@@ -170,8 +163,8 @@ class TestActionsDelegateImpl : public Clusters::Actions::Delegate
170163
}
171164
};
172165

173-
static TestActionsDelegateImpl * sActionsDelegateImpl;
174-
static ActionsServer * sActionsServer;
166+
static TestActionsDelegateImpl * sActionsDelegateImpl = nullptr;
167+
static ActionsServer * sActionsServer = nullptr;
175168

176169
class TestActionsCluster : public ::testing::Test
177170
{
@@ -180,26 +173,29 @@ class TestActionsCluster : public ::testing::Test
180173
{
181174
ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR);
182175
sActionsDelegateImpl = new TestActionsDelegateImpl;
183-
sActionsServer = new ActionsServer(0, sActionsDelegateImpl);
176+
sActionsServer = new ActionsServer(1, sActionsDelegateImpl);
184177
sActionsServer->Init();
185178
}
186179
static void TearDownTestSuite()
187180
{
188181
sActionsServer->Shutdown();
182+
delete sActionsDelegateImpl;
183+
delete sActionsServer;
189184
chip::Platform::MemoryShutdown();
190185
}
191186
};
192187

193188
TEST_F(TestActionsCluster, TestActionListConstraints)
194189
{
195190
// Test 1: Action name length constraint
191+
TestActionsDelegateImpl delegate = *sActionsDelegateImpl;
192+
delegate.mNumActions = 0;
196193
char longName[kActionNameMaxSize + 10];
197194
memset(longName, 'A', sizeof(longName));
198195
longName[sizeof(longName) - 1] = '\0';
199196

200197
ActionStructStorage actionWithLongName(1, CharSpan::fromCharString(longName), ActionTypeEnum::kScene, 0, BitMask<CommandBits>(),
201198
ActionStateEnum::kInactive);
202-
TestActionsDelegateImpl delegate = *sActionsDelegateImpl;
203199

204200
// Add action and verify it was added successfully
205201
EXPECT_EQ(delegate.AddTestAction(actionWithLongName), CHIP_NO_ERROR);
@@ -227,6 +223,8 @@ TEST_F(TestActionsCluster, TestActionListConstraints)
227223
TEST_F(TestActionsCluster, TestEndpointListConstraints)
228224
{
229225
// Test 1: Endpoint list name length constraint
226+
TestActionsDelegateImpl delegate = *sActionsDelegateImpl;
227+
delegate.mNumEndpointLists = 0;
230228
char longName[kEndpointListNameMaxSize + 10];
231229
memset(longName, 'B', sizeof(longName));
232230
longName[sizeof(longName) - 1] = '\0';
@@ -235,7 +233,6 @@ TEST_F(TestActionsCluster, TestEndpointListConstraints)
235233
EndpointListStorage epListWithLongName(1, CharSpan::fromCharString(longName), EndpointListTypeEnum::kOther,
236234
DataModel::List<const EndpointId>(endpoints));
237235

238-
TestActionsDelegateImpl delegate = *sActionsDelegateImpl;
239236
// Add endpoint list and verify it was added successfully
240237
EXPECT_EQ(delegate.AddTestEndpointList(epListWithLongName), CHIP_NO_ERROR);
241238

@@ -279,17 +276,17 @@ TEST_F(TestActionsCluster, TestEndpointListConstraints)
279276

280277
TEST_F(TestActionsCluster, TestActionListAttributeAccess)
281278
{
282-
TestActionsDelegateImpl delegate = *sActionsDelegateImpl;
283-
delegate.mNumActions = 0;
279+
TestActionsDelegateImpl * delegate = sActionsDelegateImpl;
280+
delegate->mNumActions = 0;
284281

285282
// Add test actions
286283
ActionStructStorage action1(1, CharSpan::fromCharString("FirstAction"), ActionTypeEnum::kScene, 0, BitMask<CommandBits>(),
287284
ActionStateEnum::kInactive);
288285
ActionStructStorage action2(2, CharSpan::fromCharString("SecondAction"), ActionTypeEnum::kScene, 1, BitMask<CommandBits>(),
289286
ActionStateEnum::kActive);
290287

291-
EXPECT_EQ(delegate.AddTestAction(action1), CHIP_NO_ERROR);
292-
EXPECT_EQ(delegate.AddTestAction(action2), CHIP_NO_ERROR);
288+
EXPECT_EQ(delegate->AddTestAction(action1), CHIP_NO_ERROR);
289+
EXPECT_EQ(delegate->AddTestAction(action2), CHIP_NO_ERROR);
293290

294291
// Test reading actions through attribute reader
295292
uint8_t buf[1024];
@@ -301,7 +298,7 @@ TEST_F(TestActionsCluster, TestActionListAttributeAccess)
301298
AttributeReportIBs::Builder builder;
302299
builder.Init(&tlvWriter);
303300

304-
ConcreteAttributePath path(0, Clusters::Actions::Id, Clusters::Actions::Attributes::ActionList::Id);
301+
ConcreteAttributePath path(1, Clusters::Actions::Id, Clusters::Actions::Attributes::ActionList::Id);
305302
ConcreteReadAttributePath readPath(path);
306303
chip::DataVersion dataVersion(0);
307304
Access::SubjectDescriptor subjectDescriptor;
@@ -361,8 +358,8 @@ TEST_F(TestActionsCluster, TestActionListAttributeAccess)
361358

362359
TEST_F(TestActionsCluster, TestEndpointListAttributeAccess)
363360
{
364-
TestActionsDelegateImpl delegate = *sActionsDelegateImpl;
365-
delegate.mNumEndpointLists = 0;
361+
TestActionsDelegateImpl * delegate = sActionsDelegateImpl;
362+
delegate->mNumEndpointLists = 0;
366363

367364
// Add test endpoint lists
368365
const EndpointId endpoints1[] = { 1, 2 };
@@ -373,8 +370,8 @@ TEST_F(TestActionsCluster, TestEndpointListAttributeAccess)
373370
EndpointListStorage epList2(2, CharSpan::fromCharString("SecondList"), EndpointListTypeEnum::kOther,
374371
DataModel::List<const EndpointId>(endpoints2, 3));
375372

376-
EXPECT_EQ(delegate.AddTestEndpointList(epList1), CHIP_NO_ERROR);
377-
EXPECT_EQ(delegate.AddTestEndpointList(epList2), CHIP_NO_ERROR);
373+
EXPECT_EQ(delegate->AddTestEndpointList(epList1), CHIP_NO_ERROR);
374+
EXPECT_EQ(delegate->AddTestEndpointList(epList2), CHIP_NO_ERROR);
378375

379376
// Test reading endpoint lists through attribute reader
380377
TLV::TLVWriter writer;
@@ -388,7 +385,7 @@ TEST_F(TestActionsCluster, TestEndpointListAttributeAccess)
388385
AttributeReportIBs::Builder builder;
389386
builder.Init(&tlvWriter);
390387

391-
ConcreteAttributePath path(0, Clusters::Actions::Id, Clusters::Actions::Attributes::EndpointLists::Id);
388+
ConcreteAttributePath path(1, Clusters::Actions::Id, Clusters::Actions::Attributes::EndpointLists::Id);
392389
ConcreteReadAttributePath readPath(path);
393390
chip::DataVersion dataVersion(0);
394391
Access::SubjectDescriptor subjectDescriptor;

0 commit comments

Comments
 (0)