33
33
#include < protocols/interaction_model/Constants.h>
34
34
#include < pw_unit_test/framework.h>
35
35
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
-
41
36
namespace chip {
42
37
namespace app {
43
38
44
39
using namespace Clusters ::Actions;
45
40
using namespace chip ::Protocols::InteractionModel;
46
41
47
- class TestActionsDelegateImpl ;
48
-
49
42
class TestActionsDelegateImpl : public Clusters ::Actions::Delegate
50
43
{
51
44
public:
@@ -170,8 +163,8 @@ class TestActionsDelegateImpl : public Clusters::Actions::Delegate
170
163
}
171
164
};
172
165
173
- static TestActionsDelegateImpl * sActionsDelegateImpl ;
174
- static ActionsServer * sActionsServer ;
166
+ static TestActionsDelegateImpl * sActionsDelegateImpl = nullptr ;
167
+ static ActionsServer * sActionsServer = nullptr ;
175
168
176
169
class TestActionsCluster : public ::testing::Test
177
170
{
@@ -180,26 +173,29 @@ class TestActionsCluster : public ::testing::Test
180
173
{
181
174
ASSERT_EQ (chip::Platform::MemoryInit (), CHIP_NO_ERROR);
182
175
sActionsDelegateImpl = new TestActionsDelegateImpl;
183
- sActionsServer = new ActionsServer (0 , sActionsDelegateImpl );
176
+ sActionsServer = new ActionsServer (1 , sActionsDelegateImpl );
184
177
sActionsServer ->Init ();
185
178
}
186
179
static void TearDownTestSuite ()
187
180
{
188
181
sActionsServer ->Shutdown ();
182
+ delete sActionsDelegateImpl ;
183
+ delete sActionsServer ;
189
184
chip::Platform::MemoryShutdown ();
190
185
}
191
186
};
192
187
193
188
TEST_F (TestActionsCluster, TestActionListConstraints)
194
189
{
195
190
// Test 1: Action name length constraint
191
+ TestActionsDelegateImpl delegate = *sActionsDelegateImpl ;
192
+ delegate.mNumActions = 0 ;
196
193
char longName[kActionNameMaxSize + 10 ];
197
194
memset (longName, ' A' , sizeof (longName));
198
195
longName[sizeof (longName) - 1 ] = ' \0 ' ;
199
196
200
197
ActionStructStorage actionWithLongName (1 , CharSpan::fromCharString (longName), ActionTypeEnum::kScene , 0 , BitMask<CommandBits>(),
201
198
ActionStateEnum::kInactive );
202
- TestActionsDelegateImpl delegate = *sActionsDelegateImpl ;
203
199
204
200
// Add action and verify it was added successfully
205
201
EXPECT_EQ (delegate.AddTestAction (actionWithLongName), CHIP_NO_ERROR);
@@ -227,6 +223,8 @@ TEST_F(TestActionsCluster, TestActionListConstraints)
227
223
TEST_F (TestActionsCluster, TestEndpointListConstraints)
228
224
{
229
225
// Test 1: Endpoint list name length constraint
226
+ TestActionsDelegateImpl delegate = *sActionsDelegateImpl ;
227
+ delegate.mNumEndpointLists = 0 ;
230
228
char longName[kEndpointListNameMaxSize + 10 ];
231
229
memset (longName, ' B' , sizeof (longName));
232
230
longName[sizeof (longName) - 1 ] = ' \0 ' ;
@@ -235,7 +233,6 @@ TEST_F(TestActionsCluster, TestEndpointListConstraints)
235
233
EndpointListStorage epListWithLongName (1 , CharSpan::fromCharString (longName), EndpointListTypeEnum::kOther ,
236
234
DataModel::List<const EndpointId>(endpoints));
237
235
238
- TestActionsDelegateImpl delegate = *sActionsDelegateImpl ;
239
236
// Add endpoint list and verify it was added successfully
240
237
EXPECT_EQ (delegate.AddTestEndpointList (epListWithLongName), CHIP_NO_ERROR);
241
238
@@ -279,17 +276,17 @@ TEST_F(TestActionsCluster, TestEndpointListConstraints)
279
276
280
277
TEST_F (TestActionsCluster, TestActionListAttributeAccess)
281
278
{
282
- TestActionsDelegateImpl delegate = * sActionsDelegateImpl ;
283
- delegate. mNumActions = 0 ;
279
+ TestActionsDelegateImpl * delegate = sActionsDelegateImpl ;
280
+ delegate-> mNumActions = 0 ;
284
281
285
282
// Add test actions
286
283
ActionStructStorage action1 (1 , CharSpan::fromCharString (" FirstAction" ), ActionTypeEnum::kScene , 0 , BitMask<CommandBits>(),
287
284
ActionStateEnum::kInactive );
288
285
ActionStructStorage action2 (2 , CharSpan::fromCharString (" SecondAction" ), ActionTypeEnum::kScene , 1 , BitMask<CommandBits>(),
289
286
ActionStateEnum::kActive );
290
287
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);
293
290
294
291
// Test reading actions through attribute reader
295
292
uint8_t buf[1024 ];
@@ -301,7 +298,7 @@ TEST_F(TestActionsCluster, TestActionListAttributeAccess)
301
298
AttributeReportIBs::Builder builder;
302
299
builder.Init (&tlvWriter);
303
300
304
- ConcreteAttributePath path (0 , Clusters::Actions::Id, Clusters::Actions::Attributes::ActionList::Id);
301
+ ConcreteAttributePath path (1 , Clusters::Actions::Id, Clusters::Actions::Attributes::ActionList::Id);
305
302
ConcreteReadAttributePath readPath (path);
306
303
chip::DataVersion dataVersion (0 );
307
304
Access::SubjectDescriptor subjectDescriptor;
@@ -361,8 +358,8 @@ TEST_F(TestActionsCluster, TestActionListAttributeAccess)
361
358
362
359
TEST_F (TestActionsCluster, TestEndpointListAttributeAccess)
363
360
{
364
- TestActionsDelegateImpl delegate = * sActionsDelegateImpl ;
365
- delegate. mNumEndpointLists = 0 ;
361
+ TestActionsDelegateImpl * delegate = sActionsDelegateImpl ;
362
+ delegate-> mNumEndpointLists = 0 ;
366
363
367
364
// Add test endpoint lists
368
365
const EndpointId endpoints1[] = { 1 , 2 };
@@ -373,8 +370,8 @@ TEST_F(TestActionsCluster, TestEndpointListAttributeAccess)
373
370
EndpointListStorage epList2 (2 , CharSpan::fromCharString (" SecondList" ), EndpointListTypeEnum::kOther ,
374
371
DataModel::List<const EndpointId>(endpoints2, 3 ));
375
372
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);
378
375
379
376
// Test reading endpoint lists through attribute reader
380
377
TLV::TLVWriter writer;
@@ -388,7 +385,7 @@ TEST_F(TestActionsCluster, TestEndpointListAttributeAccess)
388
385
AttributeReportIBs::Builder builder;
389
386
builder.Init (&tlvWriter);
390
387
391
- ConcreteAttributePath path (0 , Clusters::Actions::Id, Clusters::Actions::Attributes::EndpointLists::Id);
388
+ ConcreteAttributePath path (1 , Clusters::Actions::Id, Clusters::Actions::Attributes::EndpointLists::Id);
392
389
ConcreteReadAttributePath readPath (path);
393
390
chip::DataVersion dataVersion (0 );
394
391
Access::SubjectDescriptor subjectDescriptor;
0 commit comments