@@ -286,6 +286,7 @@ class TestReadInteraction
286
286
{
287
287
public:
288
288
static void TestReadClient (nlTestSuite * apSuite, void * apContext);
289
+ static void TestReadUnexpectedSubscriptionId (nlTestSuite * apSuite, void * apContext);
289
290
static void TestReadHandler (nlTestSuite * apSuite, void * apContext);
290
291
static void TestReadClientGenerateAttributePathList (nlTestSuite * apSuite, void * apContext);
291
292
static void TestReadClientGenerateInvalidAttributePathList (nlTestSuite * apSuite, void * apContext);
@@ -331,11 +332,11 @@ class TestReadInteraction
331
332
332
333
private:
333
334
static void GenerateReportData (nlTestSuite * apSuite, void * apContext, System::PacketBufferHandle & aPayload,
334
- bool aNeedInvalidReport, bool aSuppressResponse);
335
+ bool aNeedInvalidReport, bool aSuppressResponse, bool aHasSubscriptionId );
335
336
};
336
337
337
338
void TestReadInteraction::GenerateReportData (nlTestSuite * apSuite, void * apContext, System::PacketBufferHandle & aPayload,
338
- bool aNeedInvalidReport, bool aSuppressResponse)
339
+ bool aNeedInvalidReport, bool aSuppressResponse, bool aHasSubscriptionId = false )
339
340
{
340
341
CHIP_ERROR err = CHIP_NO_ERROR;
341
342
System::PacketBufferTLVWriter writer;
@@ -346,6 +347,12 @@ void TestReadInteraction::GenerateReportData(nlTestSuite * apSuite, void * apCon
346
347
err = reportDataMessageBuilder.Init (&writer);
347
348
NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
348
349
350
+ if (aHasSubscriptionId)
351
+ {
352
+ reportDataMessageBuilder.SubscriptionId (1 );
353
+ NL_TEST_ASSERT (apSuite, reportDataMessageBuilder.GetError () == CHIP_NO_ERROR);
354
+ }
355
+
349
356
AttributeReportIBs::Builder & attributeReportIBsBuilder = reportDataMessageBuilder.CreateAttributeReportIBs ();
350
357
NL_TEST_ASSERT (apSuite, reportDataMessageBuilder.GetError () == CHIP_NO_ERROR);
351
358
@@ -435,6 +442,32 @@ void TestReadInteraction::TestReadClient(nlTestSuite * apSuite, void * apContext
435
442
NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
436
443
}
437
444
445
+ void TestReadInteraction::TestReadUnexpectedSubscriptionId (nlTestSuite * apSuite, void * apContext)
446
+ {
447
+ CHIP_ERROR err = CHIP_NO_ERROR;
448
+ TestContext & ctx = *static_cast <TestContext *>(apContext);
449
+ MockInteractionModelApp delegate;
450
+ app::ReadClient readClient (chip::app::InteractionModelEngine::GetInstance (), &ctx.GetExchangeManager (), delegate,
451
+ chip::app::ReadClient::InteractionType::Read);
452
+ System::PacketBufferHandle buf = System::PacketBufferHandle::New (System::PacketBuffer::kMaxSize );
453
+
454
+ ReadPrepareParams readPrepareParams (ctx.GetSessionBobToAlice ());
455
+ err = readClient.SendRequest (readPrepareParams);
456
+ NL_TEST_ASSERT (apSuite, err == CHIP_NO_ERROR);
457
+
458
+ // We don't actually want to deliver that message, because we want to
459
+ // synthesize the read response. But we don't want it hanging around
460
+ // forever either.
461
+ ctx.GetLoopback ().mNumMessagesToDrop = 1 ;
462
+ ctx.DrainAndServiceIO ();
463
+
464
+ // For read, we don't expect there is subscription id in report data.
465
+ GenerateReportData (apSuite, apContext, buf, false /* aNeedInvalidReport*/ , true /* aSuppressResponse*/ ,
466
+ true /* aHasSubscriptionId*/ );
467
+ err = readClient.ProcessReportData (std::move (buf));
468
+ NL_TEST_ASSERT (apSuite, err == CHIP_ERROR_INVALID_ARGUMENT);
469
+ }
470
+
438
471
void TestReadInteraction::TestReadHandler (nlTestSuite * apSuite, void * apContext)
439
472
{
440
473
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -3350,6 +3383,7 @@ const nlTest sTests[] =
3350
3383
NL_TEST_DEF (" TestReadChunking" , chip::app::TestReadInteraction::TestReadChunking),
3351
3384
NL_TEST_DEF (" TestSetDirtyBetweenChunks" , chip::app::TestReadInteraction::TestSetDirtyBetweenChunks),
3352
3385
NL_TEST_DEF (" CheckReadClient" , chip::app::TestReadInteraction::TestReadClient),
3386
+ NL_TEST_DEF (" TestReadUnexpectedSubscriptionId" , chip::app::TestReadInteraction::TestReadUnexpectedSubscriptionId),
3353
3387
NL_TEST_DEF (" CheckReadHandler" , chip::app::TestReadInteraction::TestReadHandler),
3354
3388
NL_TEST_DEF (" TestReadClientGenerateAttributePathList" , chip::app::TestReadInteraction::TestReadClientGenerateAttributePathList),
3355
3389
NL_TEST_DEF (" TestReadClientGenerateInvalidAttributePathList" , chip::app::TestReadInteraction::TestReadClientGenerateInvalidAttributePathList),
0 commit comments