17
17
#include < lib/core/TLVWriter.h>
18
18
#include < lib/format/protocol_decoder.h>
19
19
#include < lib/support/StringBuilder.h>
20
- # include < lib/support/UnitTestRegistration.h >
20
+
21
21
22
22
#include < tlv/meta/clusters_meta.h>
23
23
#include < tlv/meta/protocols_meta.h>
24
24
25
- #include < nlunit-test .h>
25
+ #include < gtest/gtest .h>
26
26
27
27
#include " sample_data.h"
28
28
@@ -57,7 +57,7 @@ const std::array<const Node<ItemInfo>, 53 + 2> fake_protocols_meta = { {
57
57
{ 2 , _FakeProtocolData },
58
58
} };
59
59
60
- void TestSampleData (nlTestSuite * inSuite, const PayloadDecoderInitParams & params, const SamplePayload & data,
60
+ void TestSampleData (const PayloadDecoderInitParams & params, const SamplePayload & data,
61
61
const char * expectation)
62
62
{
63
63
chip::Decoders::PayloadDecoder<64 , 128 > decoder (
@@ -130,48 +130,48 @@ void TestSampleData(nlTestSuite * inSuite, const PayloadDecoderInitParams & para
130
130
printf (" ACTUAL: '%s'\n " , partial.Reset ().Add (output_builder.c_str () + idx).AddMarkerIfOverflow ().c_str ());
131
131
}
132
132
133
- NL_TEST_ASSERT (inSuite, strcmp (output_builder.c_str (), expectation) == 0 );
133
+ EXPECT_EQ ( strcmp (output_builder.c_str (), expectation), 0 );
134
134
}
135
135
136
- void TestFullDataDecoding (nlTestSuite * inSuite, void * inContext )
136
+ TEST (TestDecoding, TestFullDataDecoding )
137
137
{
138
138
PayloadDecoderInitParams params;
139
139
140
140
params.SetProtocolDecodeTree (chip::TLVMeta::protocols_meta).SetClusterDecodeTree (chip::TLVMeta::clusters_meta);
141
141
142
- TestSampleData (inSuite, params, secure_channel_mrp_ack, " mrp_ack: EMPTY\n " );
143
- TestSampleData (inSuite, params, secure_channel_pkbdf_param_request,
142
+ TestSampleData (params, secure_channel_mrp_ack, " mrp_ack: EMPTY\n " );
143
+ TestSampleData (params, secure_channel_pkbdf_param_request,
144
144
" pbkdf_param_request\n "
145
145
" initiator_random: hex:7C8698755B8E9866BB4FFDC27B733F3B6EF7F83D43FBE0CA6AD2B8C52C8F4236\n "
146
146
" initiator_session_id: 37677\n "
147
147
" passcode_id: 0\n "
148
148
" has_pbkdf_parameters: false\n " );
149
- TestSampleData (inSuite, params, secure_channel_pkbdf_param_response,
149
+ TestSampleData (params, secure_channel_pkbdf_param_response,
150
150
" pbkdf_param_response\n "
151
151
" initiator_random: hex:7C8698755B8E9866BB4FFDC27B733F3B6EF7F83D43FBE0CA6AD2B8C52C8F4236\n "
152
152
" responder_random: hex:A44EB3E1A751A88A32BAB59EF16EB9764C20E1A9DDBEF6EFE3F588C943C58424\n "
153
153
" responder_session_id: 40168\n "
154
154
" pbkdf_parameters\n "
155
155
" iterations: 1000\n "
156
156
" salt: hex:E8FC1E6FD0023422B3CA7ECEDD344444551C814D3D0B0EB9C096F00E8A8051B2\n " );
157
- TestSampleData (inSuite, params, secure_channel_pase_pake1,
157
+ TestSampleData (params, secure_channel_pase_pake1,
158
158
// clang-format off
159
159
" pase_pake1\n "
160
160
" pA: hex:0422ABC7A84352850456BD4A510905FE6BB782A0863A9382550E1228020801B22EEC4102C60F80082842B9739705FCD37F134651442A41E3723DFFE0...\n "
161
161
// clang-format on
162
162
);
163
- TestSampleData (inSuite, params, secure_channel_pase_pake2,
163
+ TestSampleData (params, secure_channel_pase_pake2,
164
164
// clang-format off
165
165
" pase_pake2\n "
166
166
" pB: hex:04B6A44A3347C6B77900A3674CA19F40F25F056F8CB344EC1B4FA7888B9E6B570B7010431C5D0BE4021FE74A96C40721765FDA6802BE8DFDF5624332...\n "
167
167
" cB: hex:40E7452275E38AEBAF0E0F6FAB33A1B0CB5AEB5E824230DD40D0071DC7E55C87\n "
168
168
// clang-format on
169
169
);
170
- TestSampleData (inSuite, params, secure_channel_pase_pake3,
170
+ TestSampleData (params, secure_channel_pase_pake3,
171
171
" pase_pake3\n "
172
172
" cA: hex:6008C72EDEC9D25D4A36522F0BF23058F9378EFE38CBBCCE8C6853900169BC38\n " );
173
- TestSampleData (inSuite, params, secure_channel_status_report, " status_report: BINARY DATA\n " );
174
- TestSampleData (inSuite, params, im_protocol_read_request,
173
+ TestSampleData (params, secure_channel_status_report, " status_report: BINARY DATA\n " );
174
+ TestSampleData (params, im_protocol_read_request,
175
175
" read_request\n "
176
176
" attribute_requests\n "
177
177
" Anonymous<>\n "
@@ -206,7 +206,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
206
206
" attribute_id: 3 == 'connectMaxTimeSeconds'\n "
207
207
" fabric_filtered: false\n "
208
208
" interaction_model_revison: 1\n " );
209
- TestSampleData (inSuite, params, im_protocol_report_data,
209
+ TestSampleData (params, im_protocol_report_data,
210
210
" report_data\n "
211
211
" attribute_reports\n "
212
212
" Anonymous<>\n "
@@ -279,7 +279,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
279
279
" interaction_model_revison: 1\n " );
280
280
281
281
// Different content
282
- TestSampleData (inSuite, params, im_protocol_report_data_acl,
282
+ TestSampleData (params, im_protocol_report_data_acl,
283
283
" report_data\n "
284
284
" attribute_reports\n "
285
285
" Anonymous<>\n "
@@ -301,7 +301,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
301
301
" interaction_model_revison: 1\n " );
302
302
303
303
TestSampleData (
304
- inSuite, params, im_protocol_report_data_window_covering,
304
+ params, im_protocol_report_data_window_covering,
305
305
" report_data\n "
306
306
" attribute_reports\n "
307
307
" Anonymous<>\n "
@@ -315,7 +315,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
315
315
" suppress_response: true\n "
316
316
" interaction_model_revison: 1\n " );
317
317
318
- TestSampleData (inSuite, params, im_protocol_invoke_request,
318
+ TestSampleData (params, im_protocol_invoke_request,
319
319
" invoke_request\n "
320
320
" suppress_response: false\n "
321
321
" timed_request: false\n "
@@ -328,7 +328,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
328
328
" OnOff::Toggle\n "
329
329
" interaction_model_revison: 1\n " );
330
330
331
- TestSampleData (inSuite, params, im_protocol_invoke_response,
331
+ TestSampleData (params, im_protocol_invoke_response,
332
332
" invoke_response\n "
333
333
" suppress_response: false\n "
334
334
" invoke_responses\n "
@@ -342,7 +342,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
342
342
" status: 0 == kSuccess\n "
343
343
" interaction_model_revison: 1\n " );
344
344
345
- TestSampleData (inSuite, params, im_protocol_invoke_request_change_channel,
345
+ TestSampleData (params, im_protocol_invoke_request_change_channel,
346
346
" invoke_request\n "
347
347
" suppress_response: false\n "
348
348
" timed_request: false\n "
@@ -356,7 +356,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
356
356
" match: \" channel name\"\n "
357
357
" interaction_model_revison: 1\n " );
358
358
359
- TestSampleData (inSuite, params, im_protocol_event_software_fault,
359
+ TestSampleData (params, im_protocol_event_software_fault,
360
360
" report_data\n "
361
361
" event_reports\n "
362
362
" Anonymous<>\n "
@@ -375,7 +375,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
375
375
" suppress_response: true\n "
376
376
" interaction_model_revison: 1\n " );
377
377
378
- TestSampleData (inSuite, params, im_protocol_event_multipress,
378
+ TestSampleData (params, im_protocol_event_multipress,
379
379
" report_data\n "
380
380
" event_reports\n "
381
381
" Anonymous<>\n "
@@ -394,22 +394,22 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
394
394
" interaction_model_revison: 1\n " );
395
395
}
396
396
397
- void TestMetaDataOnlyDecoding (nlTestSuite * inSuite, void * inContext )
397
+ TEST (TestDecoding, TestMetaDataOnlyDecoding )
398
398
{
399
399
PayloadDecoderInitParams params;
400
400
401
401
// NO CLUSTER DECODE TREE
402
402
params.SetProtocolDecodeTree (chip::TLVMeta::protocols_meta);
403
403
404
- TestSampleData (inSuite, params, secure_channel_mrp_ack, " mrp_ack: EMPTY\n " );
405
- TestSampleData (inSuite, params, secure_channel_pkbdf_param_request,
404
+ TestSampleData (params, secure_channel_mrp_ack, " mrp_ack: EMPTY\n " );
405
+ TestSampleData (params, secure_channel_pkbdf_param_request,
406
406
" pbkdf_param_request\n "
407
407
" initiator_random: hex:7C8698755B8E9866BB4FFDC27B733F3B6EF7F83D43FBE0CA6AD2B8C52C8F4236\n "
408
408
" initiator_session_id: 37677\n "
409
409
" passcode_id: 0\n "
410
410
" has_pbkdf_parameters: false\n " );
411
411
412
- TestSampleData (inSuite, params, im_protocol_read_request,
412
+ TestSampleData (params, im_protocol_read_request,
413
413
" read_request\n "
414
414
" attribute_requests\n "
415
415
" Anonymous<>\n "
@@ -444,7 +444,7 @@ void TestMetaDataOnlyDecoding(nlTestSuite * inSuite, void * inContext)
444
444
" attribute_id: 3\n "
445
445
" fabric_filtered: false\n "
446
446
" interaction_model_revison: 1\n " );
447
- TestSampleData (inSuite, params, im_protocol_report_data,
447
+ TestSampleData (params, im_protocol_report_data,
448
448
" report_data\n "
449
449
" attribute_reports\n "
450
450
" Anonymous<>\n "
@@ -515,7 +515,7 @@ void TestMetaDataOnlyDecoding(nlTestSuite * inSuite, void * inContext)
515
515
" interaction_model_revison: 1\n " );
516
516
517
517
// Different content
518
- TestSampleData (inSuite, params, im_protocol_report_data_acl,
518
+ TestSampleData (params, im_protocol_report_data_acl,
519
519
" report_data\n "
520
520
" attribute_reports\n "
521
521
" Anonymous<>\n "
@@ -530,14 +530,14 @@ void TestMetaDataOnlyDecoding(nlTestSuite * inSuite, void * inContext)
530
530
" interaction_model_revison: 1\n " );
531
531
}
532
532
533
- void TestEmptyClusterMetaDataDecode (nlTestSuite * inSuite, void * inContext )
533
+ TEST (TestDecoding, TestEmptyClusterMetaDataDecode )
534
534
{
535
535
PayloadDecoderInitParams params;
536
536
537
537
params.SetProtocolDecodeTree (chip::TLVMeta::protocols_meta).SetClusterDecodeTree (empty_meta);
538
538
539
- TestSampleData (inSuite, params, secure_channel_mrp_ack, " mrp_ack: EMPTY\n " );
540
- TestSampleData (inSuite, params, im_protocol_report_data_acl,
539
+ TestSampleData (params, secure_channel_mrp_ack, " mrp_ack: EMPTY\n " );
540
+ TestSampleData (params, im_protocol_report_data_acl,
541
541
" report_data\n "
542
542
" attribute_reports\n "
543
543
" Anonymous<>\n "
@@ -559,24 +559,24 @@ void TestEmptyClusterMetaDataDecode(nlTestSuite * inSuite, void * inContext)
559
559
" interaction_model_revison: 1\n " );
560
560
}
561
561
562
- void TestMissingDecodeData (nlTestSuite * inSuite, void * inContext )
562
+ TEST (TestDecoding, TestMissingDecodeData )
563
563
{
564
564
PayloadDecoderInitParams params;
565
565
566
566
params.SetProtocolDecodeTree (empty_meta).SetClusterDecodeTree (empty_meta);
567
567
568
- TestSampleData (inSuite, params, secure_channel_mrp_ack, " PROTO(0x0, 0x10): UNKNOWN\n " );
569
- TestSampleData (inSuite, params, im_protocol_report_data_acl, " PROTO(0x1, 0x5): UNKNOWN\n " );
568
+ TestSampleData (params, secure_channel_mrp_ack, " PROTO(0x0, 0x10): UNKNOWN\n " );
569
+ TestSampleData (params, im_protocol_report_data_acl, " PROTO(0x1, 0x5): UNKNOWN\n " );
570
570
}
571
571
572
- void TestWrongDecodeData (nlTestSuite * inSuite, void * inContext )
572
+ TEST (TestDecoding, TestWrongDecodeData )
573
573
{
574
574
PayloadDecoderInitParams params;
575
575
576
576
params.SetProtocolDecodeTree (fake_protocols_meta).SetClusterDecodeTree (empty_meta);
577
577
578
- TestSampleData (inSuite, params, secure_channel_mrp_ack, " proto16: EMPTY\n " );
579
- TestSampleData (inSuite, params, im_protocol_report_data_acl,
578
+ TestSampleData (params, secure_channel_mrp_ack, " proto16: EMPTY\n " );
579
+ TestSampleData (params, im_protocol_report_data_acl,
580
580
" proto5\n "
581
581
" ContextTag(0x1)\n "
582
582
" AnonymousTag()\n "
@@ -598,7 +598,7 @@ void TestWrongDecodeData(nlTestSuite * inSuite, void * inContext)
598
598
" ContextTag(0xFF): 1\n " );
599
599
}
600
600
601
- void TestNestingOverflow (nlTestSuite * inSuite, void * inContext )
601
+ TEST (TestDecoding, TestNestingOverflow )
602
602
{
603
603
PayloadDecoderInitParams params;
604
604
params.SetProtocolDecodeTree (fake_protocols_meta).SetClusterDecodeTree (empty_meta);
@@ -611,65 +611,62 @@ void TestNestingOverflow(nlTestSuite * inSuite, void * inContext)
611
611
chip::TLV::TLVType unusedType;
612
612
613
613
// Protocols start with an anonymous tagged structure, after which lists can be of any tags
614
- NL_TEST_ASSERT (inSuite, writer.StartContainer (AnonymousTag (), kTLVType_Structure , unusedType) == CHIP_NO_ERROR);
614
+ EXPECT_EQ ( writer.StartContainer (AnonymousTag (), kTLVType_Structure , unusedType), CHIP_NO_ERROR);
615
615
616
616
// nesting overflow here
617
617
for (uint8_t i = 0 ; i < 32 ; i++)
618
618
{
619
- NL_TEST_ASSERT (inSuite, writer.StartContainer (ContextTag (i), kTLVType_List , unusedType) == CHIP_NO_ERROR);
619
+ EXPECT_EQ ( writer.StartContainer (ContextTag (i), kTLVType_List , unusedType), CHIP_NO_ERROR);
620
620
}
621
621
// Go back to 24 (still too much nesting)
622
622
for (uint8_t i = 0 ; i < 8 ; i++)
623
623
{
624
- NL_TEST_ASSERT (inSuite, writer.EndContainer (kTLVType_List ) == CHIP_NO_ERROR);
624
+ EXPECT_EQ ( writer.EndContainer (kTLVType_List ), CHIP_NO_ERROR);
625
625
}
626
626
for (uint8_t i = 0 ; i < 4 ; i++)
627
627
{
628
- NL_TEST_ASSERT (
629
- inSuite, writer.StartContainer (ContextTag (static_cast <uint8_t >(i + 0x10 )), kTLVType_List , unusedType) == CHIP_NO_ERROR);
628
+ EXPECT_EQ (writer.StartContainer (ContextTag (static_cast <uint8_t >(i + 0x10 )), kTLVType_List , unusedType), CHIP_NO_ERROR);
630
629
}
631
630
for (uint8_t i = 0 ; i < 4 ; i++)
632
631
{
633
- NL_TEST_ASSERT (inSuite, writer.EndContainer (kTLVType_List ) == CHIP_NO_ERROR);
632
+ EXPECT_EQ ( writer.EndContainer (kTLVType_List ), CHIP_NO_ERROR);
634
633
}
635
634
// Go back to 8
636
635
for (uint8_t i = 0 ; i < 16 ; i++)
637
636
{
638
- NL_TEST_ASSERT (inSuite, writer.EndContainer (kTLVType_List ) == CHIP_NO_ERROR);
637
+ EXPECT_EQ ( writer.EndContainer (kTLVType_List ), CHIP_NO_ERROR);
639
638
}
640
639
for (uint8_t i = 0 ; i < 4 ; i++)
641
640
{
642
- NL_TEST_ASSERT (
643
- inSuite, writer.StartContainer (ContextTag (static_cast <uint8_t >(i + 0x20 )), kTLVType_List , unusedType) == CHIP_NO_ERROR);
641
+ EXPECT_EQ (writer.StartContainer (ContextTag (static_cast <uint8_t >(i + 0x20 )), kTLVType_List , unusedType), CHIP_NO_ERROR);
644
642
}
645
643
for (uint8_t i = 0 ; i < 4 ; i++)
646
644
{
647
- NL_TEST_ASSERT (inSuite, writer.EndContainer (kTLVType_List ) == CHIP_NO_ERROR);
645
+ EXPECT_EQ ( writer.EndContainer (kTLVType_List ), CHIP_NO_ERROR);
648
646
}
649
647
// Go back to 4
650
648
for (uint8_t i = 0 ; i < 4 ; i++)
651
649
{
652
- NL_TEST_ASSERT (inSuite, writer.EndContainer (kTLVType_List ) == CHIP_NO_ERROR);
650
+ EXPECT_EQ ( writer.EndContainer (kTLVType_List ), CHIP_NO_ERROR);
653
651
}
654
652
for (uint8_t i = 0 ; i < 4 ; i++)
655
653
{
656
- NL_TEST_ASSERT (
657
- inSuite, writer.StartContainer (ContextTag (static_cast <uint8_t >(i + 0x30 )), kTLVType_List , unusedType) == CHIP_NO_ERROR);
654
+ EXPECT_EQ (writer.StartContainer (ContextTag (static_cast <uint8_t >(i + 0x30 )), kTLVType_List , unusedType), CHIP_NO_ERROR);
658
655
}
659
656
for (uint8_t i = 0 ; i < 4 ; i++)
660
657
{
661
- NL_TEST_ASSERT (inSuite, writer.EndContainer (kTLVType_List ) == CHIP_NO_ERROR);
658
+ EXPECT_EQ ( writer.EndContainer (kTLVType_List ), CHIP_NO_ERROR);
662
659
}
663
660
// close everything
664
661
for (uint8_t i = 0 ; i < 4 ; i++)
665
662
{
666
- NL_TEST_ASSERT (inSuite, writer.EndContainer (kTLVType_List ) == CHIP_NO_ERROR);
663
+ EXPECT_EQ ( writer.EndContainer (kTLVType_List ), CHIP_NO_ERROR);
667
664
}
668
- NL_TEST_ASSERT (inSuite, writer.EndContainer (kTLVType_Structure ) == CHIP_NO_ERROR);
665
+ EXPECT_EQ ( writer.EndContainer (kTLVType_Structure ), CHIP_NO_ERROR);
669
666
670
667
SamplePayload fake_payload{ chip::Protocols::InteractionModel::Id, 5 , chip::ByteSpan (data_buffer, writer.GetLengthWritten ()) };
671
668
672
- TestSampleData (inSuite, params, fake_payload,
669
+ TestSampleData (params, fake_payload,
673
670
" proto5\n "
674
671
" ContextTag(0x0)\n "
675
672
" ContextTag(0x1)\n "
@@ -696,24 +693,4 @@ void TestNestingOverflow(nlTestSuite * inSuite, void * inContext)
696
693
" ContextTag(0x32)\n "
697
694
" ContextTag(0x33)\n " );
698
695
}
699
-
700
- const nlTest sTests [] = {
701
- NL_TEST_DEF (" TestFullDataDecoding" , TestFullDataDecoding), //
702
- NL_TEST_DEF (" TestMetaDataOnlyDecoding" , TestMetaDataOnlyDecoding), //
703
- NL_TEST_DEF (" TestEmptyClusterMetaDataDecode" , TestEmptyClusterMetaDataDecode), //
704
- NL_TEST_DEF (" TestMissingDecodeData" , TestMissingDecodeData), //
705
- NL_TEST_DEF (" TestWrongDecodeData" , TestWrongDecodeData), //
706
- NL_TEST_DEF (" TestNestingOverflow" , TestNestingOverflow), //
707
- NL_TEST_SENTINEL () //
708
- };
709
-
710
696
} // namespace
711
-
712
- int TestDecode ()
713
- {
714
- nlTestSuite theSuite = { " TestDecode" , sTests , nullptr , nullptr };
715
- nlTestRunner (&theSuite, nullptr );
716
- return nlTestRunnerStats (&theSuite);
717
- }
718
-
719
- CHIP_REGISTER_TEST_SUITE (TestDecode)
0 commit comments