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