@@ -65,6 +65,8 @@ void DispatchSingleClusterCommand(chip::ClusterId aClusterId, chip::CommandId aC
65
65
class TestCommandInteraction
66
66
{
67
67
public:
68
+ static void TestCommandSenderWithWrongState (nlTestSuite * apSuite, void * apContext);
69
+ static void TestCommandHandlerWithWrongState (nlTestSuite * apSuite, void * apContext);
68
70
static void TestCommandSenderWithSendCommand (nlTestSuite * apSuite, void * apContext);
69
71
static void TestCommandHandlerWithSendEmptyCommand (nlTestSuite * apSuite, void * apContext);
70
72
static void TestCommandSenderWithProcessReceivedMsg (nlTestSuite * apSuite, void * apContext);
@@ -172,6 +174,53 @@ void TestCommandInteraction::AddCommandDataElement(nlTestSuite * apSuite, void *
172
174
}
173
175
}
174
176
177
+ void TestCommandInteraction::TestCommandSenderWithWrongState (nlTestSuite * apSuite, void * apContext)
178
+ {
179
+ CHIP_ERROR err = CHIP_NO_ERROR;
180
+ chip::app::CommandPathParams commandPathParams = { 1 , // Endpoint
181
+ 2 , // GroupId
182
+ 3 , // ClusterId
183
+ 4 , // CommandId
184
+ (chip::app::CommandPathFlags::kEndpointIdValid ) };
185
+ app::CommandSender commandSender;
186
+
187
+ err = commandSender.PrepareCommand (&commandPathParams);
188
+ NL_TEST_ASSERT (apSuite, err == CHIP_ERROR_INCORRECT_STATE);
189
+
190
+ commandSender.Shutdown ();
191
+
192
+ System::PacketBufferHandle buf = System::PacketBufferHandle::New (System::PacketBuffer::kMaxSize );
193
+ err = commandSender.Init (&gExchangeManager , nullptr );
194
+ NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
195
+
196
+ err = commandSender.SendCommandRequest (kTestDeviceNodeId , gAdminId );
197
+ NL_TEST_ASSERT (apSuite, err == CHIP_ERROR_INCORRECT_STATE);
198
+ }
199
+
200
+ void TestCommandInteraction::TestCommandHandlerWithWrongState (nlTestSuite * apSuite, void * apContext)
201
+ {
202
+ CHIP_ERROR err = CHIP_NO_ERROR;
203
+ chip::app::CommandPathParams commandPathParams = { 1 , // Endpoint
204
+ 2 , // GroupId
205
+ 3 , // ClusterId
206
+ 4 , // CommandId
207
+ (chip::app::CommandPathFlags::kEndpointIdValid ) };
208
+ app::CommandHandler commandHandler;
209
+
210
+ err = commandHandler.PrepareCommand (&commandPathParams);
211
+ NL_TEST_ASSERT (apSuite, err == CHIP_ERROR_INCORRECT_STATE);
212
+ commandHandler.Shutdown ();
213
+
214
+ err = commandHandler.Init (&chip::gExchangeManager , nullptr );
215
+ NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
216
+ commandHandler.mpExchangeCtx = gExchangeManager .NewContext ({ 0 , 0 , 0 }, nullptr );
217
+ TestExchangeDelegate delegate;
218
+ commandHandler.mpExchangeCtx ->SetDelegate (&delegate);
219
+ err = commandHandler.SendCommandResponse ();
220
+ NL_TEST_ASSERT (apSuite, err == CHIP_ERROR_INCORRECT_STATE);
221
+ commandHandler.Shutdown ();
222
+ }
223
+
175
224
void TestCommandInteraction::TestCommandSenderWithSendCommand (nlTestSuite * apSuite, void * apContext)
176
225
{
177
226
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -330,6 +379,8 @@ void InitializeChip(nlTestSuite * apSuite)
330
379
// clang-format off
331
380
const nlTest sTests [] =
332
381
{
382
+ NL_TEST_DEF (" TestCommandSenderWithWrongState" , chip::app::TestCommandInteraction::TestCommandSenderWithWrongState),
383
+ NL_TEST_DEF (" TestCommandHandlerWithWrongState" , chip::app::TestCommandInteraction::TestCommandHandlerWithWrongState),
333
384
NL_TEST_DEF (" TestCommandSenderWithSendCommand" , chip::app::TestCommandInteraction::TestCommandSenderWithSendCommand),
334
385
NL_TEST_DEF (" TestCommandHandlerWithSendEmptyCommand" , chip::app::TestCommandInteraction::TestCommandHandlerWithSendEmptyCommand),
335
386
NL_TEST_DEF (" TestCommandSenderWithProcessReceivedMsg" , chip::app::TestCommandInteraction::TestCommandSenderWithProcessReceivedMsg),
0 commit comments