@@ -70,8 +70,6 @@ constexpr AttributeId kTestBadAttribute =
70
70
71
71
constexpr int kListAttributeItems = 5 ;
72
72
73
- using TestReadChunking = chip::Test::AppContext;
74
-
75
73
// clang-format off
76
74
DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN (testClusterAttrs)
77
75
DECLARE_DYNAMIC_ATTRIBUTE (0x00000001 , INT8U, 1 , 0 ), DECLARE_DYNAMIC_ATTRIBUTE(0x00000002 , INT8U, 1 , 0 ),
@@ -456,6 +454,15 @@ void TestMutableReadCallback::OnAttributeData(const app::ConcreteDataAttributePa
456
454
// Ignore all other attributes, we don't care above the global attributes.
457
455
}
458
456
457
+ class TestReadChunking : public chip ::Test::AppContext
458
+ {
459
+ protected:
460
+ struct Instruction ;
461
+ void DoTest (TestMutableReadCallback * callback, Instruction instruction);
462
+ void DriveIOUntilSubscriptionEstablished (TestMutableReadCallback * callback);
463
+ void DriveIOUntilEndOfReport (TestMutableReadCallback * callback);
464
+ };
465
+
459
466
/*
460
467
* This validates all the various corner cases encountered during chunking by
461
468
* artificially reducing the size of a packet buffer used to encode attribute data
@@ -809,57 +816,59 @@ enum AttrIds
809
816
using AttributeWithValue = std::pair<AttributeIdWithEndpointId, uint8_t >;
810
817
using AttributesList = std::vector<AttributeIdWithEndpointId>;
811
818
812
- struct Instruction
819
+ void CheckValues (TestMutableReadCallback * callback, std::vector<AttributeWithValue> expectedValues = {})
820
+ {
821
+ for (const auto & vals : expectedValues)
822
+ {
823
+ EXPECT_EQ (callback->mValues [vals.first ], vals.second );
824
+ }
825
+ }
826
+
827
+ void ExpectSameDataVersions (TestMutableReadCallback * callback, AttributesList attrList)
828
+ {
829
+ if (attrList.size () == 0 )
830
+ {
831
+ return ;
832
+ }
833
+ DataVersion expectedVersion = callback->mDataVersions [attrList[0 ]];
834
+ for (const auto & attr : attrList)
835
+ {
836
+ EXPECT_EQ (callback->mDataVersions [attr], expectedVersion);
837
+ }
838
+ }
839
+
840
+ }; // namespace TestSetDirtyBetweenChunksUtil
841
+
842
+ struct TestReadChunking ::Instruction
813
843
{
814
844
// The maximum number of attributes should be iterated in a single report chunk.
815
845
uint32_t chunksize;
816
846
// A list of functions that will be executed before driving the main loop.
817
847
std::vector<std::function<void ()>> preworks;
818
848
// A list of pair for attributes and their expected values in the report.
819
- std::vector<AttributeWithValue> expectedValues;
849
+ std::vector<TestSetDirtyBetweenChunksUtil:: AttributeWithValue> expectedValues;
820
850
// A list of list of various attributes which should have the same data version in the report.
821
- std::vector<AttributesList> attributesWithSameDataVersion;
851
+ std::vector<TestSetDirtyBetweenChunksUtil:: AttributesList> attributesWithSameDataVersion;
822
852
};
823
853
824
- void DriveIOUntilSubscriptionEstablished (TestReadChunking * pContext, TestMutableReadCallback * callback)
854
+ void TestReadChunking:: DriveIOUntilSubscriptionEstablished (TestMutableReadCallback * callback)
825
855
{
826
856
callback->mOnReportEnd = false ;
827
- pContext-> GetIOContext ().DriveIOUntil (System::Clock::Seconds16 (5 ), [&]() { return callback->mOnSubscriptionEstablished ; });
857
+ GetIOContext ().DriveIOUntil (System::Clock::Seconds16 (5 ), [&]() { return callback->mOnSubscriptionEstablished ; });
828
858
EXPECT_TRUE (callback->mOnReportEnd );
829
859
EXPECT_TRUE (callback->mOnSubscriptionEstablished );
830
860
callback->mActionOn .clear ();
831
861
}
832
862
833
- void DriveIOUntilEndOfReport (TestReadChunking * pContext, TestMutableReadCallback * callback)
863
+ void TestReadChunking:: DriveIOUntilEndOfReport (TestMutableReadCallback * callback)
834
864
{
835
865
callback->mOnReportEnd = false ;
836
- pContext-> GetIOContext ().DriveIOUntil (System::Clock::Seconds16 (5 ), [&]() { return callback->mOnReportEnd ; });
866
+ GetIOContext ().DriveIOUntil (System::Clock::Seconds16 (5 ), [&]() { return callback->mOnReportEnd ; });
837
867
EXPECT_TRUE (callback->mOnReportEnd );
838
868
callback->mActionOn .clear ();
839
869
}
840
870
841
- void CheckValues (TestMutableReadCallback * callback, std::vector<AttributeWithValue> expectedValues = {})
842
- {
843
- for (const auto & vals : expectedValues)
844
- {
845
- EXPECT_EQ (callback->mValues [vals.first ], vals.second );
846
- }
847
- }
848
-
849
- void ExpectSameDataVersions (TestMutableReadCallback * callback, AttributesList attrList)
850
- {
851
- if (attrList.size () == 0 )
852
- {
853
- return ;
854
- }
855
- DataVersion expectedVersion = callback->mDataVersions [attrList[0 ]];
856
- for (const auto & attr : attrList)
857
- {
858
- EXPECT_EQ (callback->mDataVersions [attr], expectedVersion);
859
- }
860
- }
861
-
862
- void DoTest (TestReadChunking * pContext, TestMutableReadCallback * callback, Instruction instruction)
871
+ void TestReadChunking::DoTest (TestMutableReadCallback * callback, Instruction instruction)
863
872
{
864
873
app::InteractionModelEngine::GetInstance ()->GetReportingEngine ().SetMaxAttributesPerChunk (instruction.chunksize );
865
874
@@ -868,18 +877,16 @@ void DoTest(TestReadChunking * pContext, TestMutableReadCallback * callback, Ins
868
877
act ();
869
878
}
870
879
871
- DriveIOUntilEndOfReport (pContext, callback);
880
+ DriveIOUntilEndOfReport (callback);
872
881
873
- CheckValues (callback, instruction.expectedValues );
882
+ TestSetDirtyBetweenChunksUtil:: CheckValues (callback, instruction.expectedValues );
874
883
875
884
for (const auto & attrList : instruction.attributesWithSameDataVersion )
876
885
{
877
- ExpectSameDataVersions (callback, attrList);
886
+ TestSetDirtyBetweenChunksUtil:: ExpectSameDataVersions (callback, attrList);
878
887
}
879
888
}
880
889
881
- }; // namespace TestSetDirtyBetweenChunksUtil
882
-
883
890
TEST_F (TestReadChunking, TestSetDirtyBetweenChunks)
884
891
{
885
892
using namespace TestSetDirtyBetweenChunksUtil ;
@@ -929,19 +936,19 @@ TEST_F(TestReadChunking, TestSetDirtyBetweenChunks)
929
936
// We are expected to miss attributes on kTestEndpointId during initial reports.
930
937
ChipLogProgress (DataManagement, " Case 1-1: Set dirty during priming report." );
931
938
readCallback.mActionOn [AttrOnEp5<Attr1>] = TouchAttrOp (AttrOnEp1<Attr1>);
932
- DriveIOUntilSubscriptionEstablished (this , &readCallback);
939
+ DriveIOUntilSubscriptionEstablished (&readCallback);
933
940
CheckValues (&readCallback, { { AttrOnEp1<Attr1>, 1 } });
934
941
935
942
ChipLogProgress (DataManagement, " Case 1-2: Check for attributes missed last report." );
936
- DoTest (this , &readCallback, Instruction{ .chunksize = 2 , .expectedValues = { { AttrOnEp1<Attr1>, 2 } } });
943
+ DoTest (&readCallback, Instruction{ .chunksize = 2 , .expectedValues = { { AttrOnEp1<Attr1>, 2 } } });
937
944
}
938
945
939
946
// CASE 2 -- Set dirty during chunked report, the attribute is already dirty.
940
947
{
941
948
ChipLogProgress (DataManagement, " Case 2: Set dirty during chunked report by wildcard path." );
942
949
readCallback.mActionOn [AttrOnEp5<Attr2>] = WriteAttrOp (AttrOnEp5<Attr3>, 3 );
943
950
DoTest (
944
- this , &readCallback,
951
+ &readCallback,
945
952
Instruction{ .chunksize = 2 ,
946
953
.preworks = { WriteAttrOp (AttrOnEp5<Attr1>, 2 ), WriteAttrOp (AttrOnEp5<Attr2>, 2 ),
947
954
WriteAttrOp (AttrOnEp5<Attr3>, 2 ) },
@@ -955,7 +962,7 @@ TEST_F(TestReadChunking, TestSetDirtyBetweenChunks)
955
962
" Case 3-1: Set dirty during chunked report by wildcard path -- new dirty attribute." );
956
963
readCallback.mActionOn [AttrOnEp5<Attr2>] = WriteAttrOp (AttrOnEp5<Attr3>, 4 );
957
964
DoTest (
958
- this , &readCallback,
965
+ &readCallback,
959
966
Instruction{ .chunksize = 1 ,
960
967
.preworks = { WriteAttrOp (AttrOnEp5<Attr1>, 4 ), WriteAttrOp (AttrOnEp5<Attr2>, 4 ) },
961
968
.expectedValues = { { AttrOnEp5<Attr1>, 4 }, { AttrOnEp5<Attr2>, 4 }, { AttrOnEp5<Attr3>, 4 } },
@@ -966,7 +973,7 @@ TEST_F(TestReadChunking, TestSetDirtyBetweenChunks)
966
973
app::InteractionModelEngine::GetInstance ()->GetReportingEngine ().SetMaxAttributesPerChunk (1 );
967
974
readCallback.mActionOn [AttrOnEp5<Attr2>] = WriteAttrOp (AttrOnEp5<Attr1>, 5 );
968
975
DoTest (
969
- this , &readCallback,
976
+ &readCallback,
970
977
Instruction{ .chunksize = 1 ,
971
978
.preworks = { WriteAttrOp (AttrOnEp5<Attr2>, 5 ), WriteAttrOp (AttrOnEp5<Attr3>, 5 ) },
972
979
.expectedValues = { { AttrOnEp5<Attr1>, 5 }, { AttrOnEp5<Attr2>, 5 }, { AttrOnEp5<Attr3>, 5 } },
@@ -1001,21 +1008,21 @@ TEST_F(TestReadChunking, TestSetDirtyBetweenChunks)
1001
1008
1002
1009
EXPECT_EQ (readClient.SendRequest (readParams), CHIP_NO_ERROR);
1003
1010
1004
- DriveIOUntilSubscriptionEstablished (this , &readCallback);
1011
+ DriveIOUntilSubscriptionEstablished (&readCallback);
1005
1012
1006
1013
// Note, although the two attributes comes from the same cluster, they are generated by different interested paths.
1007
1014
// In this case, we won't reset the path iterator.
1008
1015
ChipLogProgress (DataManagement, " Case 1-1: Test set dirty during reports generated by concrete paths." );
1009
1016
readCallback.mActionOn [AttrOnEp5<Attr2>] = WriteAttrOp (AttrOnEp5<Attr3>, 4 );
1010
- DoTest (this , &readCallback,
1017
+ DoTest (&readCallback,
1011
1018
Instruction{ .chunksize = 1 ,
1012
1019
.preworks = { WriteAttrOp (AttrOnEp5<Attr1>, 3 ), WriteAttrOp (AttrOnEp5<Attr2>, 3 ),
1013
1020
WriteAttrOp (AttrOnEp5<Attr3>, 3 ) },
1014
1021
.expectedValues = { { AttrOnEp5<Attr1>, 3 }, { AttrOnEp5<Attr2>, 3 }, { AttrOnEp5<Attr3>, 3 } } });
1015
1022
1016
1023
// The attribute failed to catch last report will be picked by this report.
1017
1024
ChipLogProgress (DataManagement, " Case 1-2: Check for attributes missed last report." );
1018
- DoTest (this , &readCallback, { .chunksize = 1 , .expectedValues = { { AttrOnEp5<Attr3>, 4 } } });
1025
+ DoTest (&readCallback, { .chunksize = 1 , .expectedValues = { { AttrOnEp5<Attr3>, 4 } } });
1019
1026
}
1020
1027
}
1021
1028
0 commit comments