Skip to content

Commit a3dee0c

Browse files
committed
Replaced nlunit-test with pw_unit_test in src/lib/format/
1 parent 80b2f61 commit a3dee0c

File tree

4 files changed

+112
-170
lines changed

4 files changed

+112
-170
lines changed

src/lib/format/tests/BUILD.gn

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414

1515
import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
17-
import("//build_overrides/nlunit_test.gni")
1817

1918
import("${chip_root}/build/chip/chip_test_suite.gni")
2019
import("${chip_root}/build/chip/fuzz_test.gni")
2120

22-
chip_test_suite_using_nltest("tests") {
21+
chip_test_suite("tests") {
2322
output_name = "libFormatTests"
2423

2524
test_sources = [
@@ -40,8 +39,6 @@ chip_test_suite_using_nltest("tests") {
4039
"${chip_root}/src/lib/format:flat-tree",
4140
"${chip_root}/src/lib/format:protocol-decoder",
4241
"${chip_root}/src/lib/format:protocol-tlv-metadata",
43-
"${chip_root}/src/lib/support:testing_nlunit",
44-
"${nlunit_test_root}:nlunit-test",
4542
]
4643
}
4744

src/lib/format/tests/TestDecoding.cpp

+51-74
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
#include <lib/core/TLVWriter.h>
1818
#include <lib/format/protocol_decoder.h>
1919
#include <lib/support/StringBuilder.h>
20-
#include <lib/support/UnitTestRegistration.h>
20+
2121

2222
#include <tlv/meta/clusters_meta.h>
2323
#include <tlv/meta/protocols_meta.h>
2424

25-
#include <nlunit-test.h>
25+
#include <gtest/gtest.h>
2626

2727
#include "sample_data.h"
2828

@@ -57,7 +57,7 @@ const std::array<const Node<ItemInfo>, 53 + 2> fake_protocols_meta = { {
5757
{ 2, _FakeProtocolData },
5858
} };
5959

60-
void TestSampleData(nlTestSuite * inSuite, const PayloadDecoderInitParams & params, const SamplePayload & data,
60+
void TestSampleData(const PayloadDecoderInitParams & params, const SamplePayload & data,
6161
const char * expectation)
6262
{
6363
chip::Decoders::PayloadDecoder<64, 128> decoder(
@@ -130,48 +130,48 @@ void TestSampleData(nlTestSuite * inSuite, const PayloadDecoderInitParams & para
130130
printf("ACTUAL: '%s'\n", partial.Reset().Add(output_builder.c_str() + idx).AddMarkerIfOverflow().c_str());
131131
}
132132

133-
NL_TEST_ASSERT(inSuite, strcmp(output_builder.c_str(), expectation) == 0);
133+
EXPECT_EQ(strcmp(output_builder.c_str(), expectation), 0);
134134
}
135135

136-
void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
136+
TEST(TestDecoding, TestFullDataDecoding)
137137
{
138138
PayloadDecoderInitParams params;
139139

140140
params.SetProtocolDecodeTree(chip::TLVMeta::protocols_meta).SetClusterDecodeTree(chip::TLVMeta::clusters_meta);
141141

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,
144144
"pbkdf_param_request\n"
145145
" initiator_random: hex:7C8698755B8E9866BB4FFDC27B733F3B6EF7F83D43FBE0CA6AD2B8C52C8F4236\n"
146146
" initiator_session_id: 37677\n"
147147
" passcode_id: 0\n"
148148
" has_pbkdf_parameters: false\n");
149-
TestSampleData(inSuite, params, secure_channel_pkbdf_param_response,
149+
TestSampleData(params, secure_channel_pkbdf_param_response,
150150
"pbkdf_param_response\n"
151151
" initiator_random: hex:7C8698755B8E9866BB4FFDC27B733F3B6EF7F83D43FBE0CA6AD2B8C52C8F4236\n"
152152
" responder_random: hex:A44EB3E1A751A88A32BAB59EF16EB9764C20E1A9DDBEF6EFE3F588C943C58424\n"
153153
" responder_session_id: 40168\n"
154154
" pbkdf_parameters\n"
155155
" iterations: 1000\n"
156156
" salt: hex:E8FC1E6FD0023422B3CA7ECEDD344444551C814D3D0B0EB9C096F00E8A8051B2\n");
157-
TestSampleData(inSuite, params, secure_channel_pase_pake1,
157+
TestSampleData(params, secure_channel_pase_pake1,
158158
// clang-format off
159159
"pase_pake1\n"
160160
" pA: hex:0422ABC7A84352850456BD4A510905FE6BB782A0863A9382550E1228020801B22EEC4102C60F80082842B9739705FCD37F134651442A41E3723DFFE0...\n"
161161
// clang-format on
162162
);
163-
TestSampleData(inSuite, params, secure_channel_pase_pake2,
163+
TestSampleData(params, secure_channel_pase_pake2,
164164
// clang-format off
165165
"pase_pake2\n"
166166
" pB: hex:04B6A44A3347C6B77900A3674CA19F40F25F056F8CB344EC1B4FA7888B9E6B570B7010431C5D0BE4021FE74A96C40721765FDA6802BE8DFDF5624332...\n"
167167
" cB: hex:40E7452275E38AEBAF0E0F6FAB33A1B0CB5AEB5E824230DD40D0071DC7E55C87\n"
168168
// clang-format on
169169
);
170-
TestSampleData(inSuite, params, secure_channel_pase_pake3,
170+
TestSampleData(params, secure_channel_pase_pake3,
171171
"pase_pake3\n"
172172
" 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,
175175
"read_request\n"
176176
" attribute_requests\n"
177177
" Anonymous<>\n"
@@ -206,7 +206,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
206206
" attribute_id: 3 == 'connectMaxTimeSeconds'\n"
207207
" fabric_filtered: false\n"
208208
" interaction_model_revison: 1\n");
209-
TestSampleData(inSuite, params, im_protocol_report_data,
209+
TestSampleData(params, im_protocol_report_data,
210210
"report_data\n"
211211
" attribute_reports\n"
212212
" Anonymous<>\n"
@@ -279,7 +279,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
279279
" interaction_model_revison: 1\n");
280280

281281
// Different content
282-
TestSampleData(inSuite, params, im_protocol_report_data_acl,
282+
TestSampleData(params, im_protocol_report_data_acl,
283283
"report_data\n"
284284
" attribute_reports\n"
285285
" Anonymous<>\n"
@@ -301,7 +301,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
301301
" interaction_model_revison: 1\n");
302302

303303
TestSampleData(
304-
inSuite, params, im_protocol_report_data_window_covering,
304+
params, im_protocol_report_data_window_covering,
305305
"report_data\n"
306306
" attribute_reports\n"
307307
" Anonymous<>\n"
@@ -315,7 +315,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
315315
" suppress_response: true\n"
316316
" interaction_model_revison: 1\n");
317317

318-
TestSampleData(inSuite, params, im_protocol_invoke_request,
318+
TestSampleData(params, im_protocol_invoke_request,
319319
"invoke_request\n"
320320
" suppress_response: false\n"
321321
" timed_request: false\n"
@@ -328,7 +328,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
328328
" OnOff::Toggle\n"
329329
" interaction_model_revison: 1\n");
330330

331-
TestSampleData(inSuite, params, im_protocol_invoke_response,
331+
TestSampleData(params, im_protocol_invoke_response,
332332
"invoke_response\n"
333333
" suppress_response: false\n"
334334
" invoke_responses\n"
@@ -342,7 +342,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
342342
" status: 0 == kSuccess\n"
343343
" interaction_model_revison: 1\n");
344344

345-
TestSampleData(inSuite, params, im_protocol_invoke_request_change_channel,
345+
TestSampleData(params, im_protocol_invoke_request_change_channel,
346346
"invoke_request\n"
347347
" suppress_response: false\n"
348348
" timed_request: false\n"
@@ -356,7 +356,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
356356
" match: \"channel name\"\n"
357357
" interaction_model_revison: 1\n");
358358

359-
TestSampleData(inSuite, params, im_protocol_event_software_fault,
359+
TestSampleData(params, im_protocol_event_software_fault,
360360
"report_data\n"
361361
" event_reports\n"
362362
" Anonymous<>\n"
@@ -375,7 +375,7 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
375375
" suppress_response: true\n"
376376
" interaction_model_revison: 1\n");
377377

378-
TestSampleData(inSuite, params, im_protocol_event_multipress,
378+
TestSampleData(params, im_protocol_event_multipress,
379379
"report_data\n"
380380
" event_reports\n"
381381
" Anonymous<>\n"
@@ -394,22 +394,22 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
394394
" interaction_model_revison: 1\n");
395395
}
396396

397-
void TestMetaDataOnlyDecoding(nlTestSuite * inSuite, void * inContext)
397+
TEST(TestDecoding, TestMetaDataOnlyDecoding)
398398
{
399399
PayloadDecoderInitParams params;
400400

401401
// NO CLUSTER DECODE TREE
402402
params.SetProtocolDecodeTree(chip::TLVMeta::protocols_meta);
403403

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,
406406
"pbkdf_param_request\n"
407407
" initiator_random: hex:7C8698755B8E9866BB4FFDC27B733F3B6EF7F83D43FBE0CA6AD2B8C52C8F4236\n"
408408
" initiator_session_id: 37677\n"
409409
" passcode_id: 0\n"
410410
" has_pbkdf_parameters: false\n");
411411

412-
TestSampleData(inSuite, params, im_protocol_read_request,
412+
TestSampleData(params, im_protocol_read_request,
413413
"read_request\n"
414414
" attribute_requests\n"
415415
" Anonymous<>\n"
@@ -444,7 +444,7 @@ void TestMetaDataOnlyDecoding(nlTestSuite * inSuite, void * inContext)
444444
" attribute_id: 3\n"
445445
" fabric_filtered: false\n"
446446
" interaction_model_revison: 1\n");
447-
TestSampleData(inSuite, params, im_protocol_report_data,
447+
TestSampleData(params, im_protocol_report_data,
448448
"report_data\n"
449449
" attribute_reports\n"
450450
" Anonymous<>\n"
@@ -515,7 +515,7 @@ void TestMetaDataOnlyDecoding(nlTestSuite * inSuite, void * inContext)
515515
" interaction_model_revison: 1\n");
516516

517517
// Different content
518-
TestSampleData(inSuite, params, im_protocol_report_data_acl,
518+
TestSampleData(params, im_protocol_report_data_acl,
519519
"report_data\n"
520520
" attribute_reports\n"
521521
" Anonymous<>\n"
@@ -530,14 +530,14 @@ void TestMetaDataOnlyDecoding(nlTestSuite * inSuite, void * inContext)
530530
" interaction_model_revison: 1\n");
531531
}
532532

533-
void TestEmptyClusterMetaDataDecode(nlTestSuite * inSuite, void * inContext)
533+
TEST(TestDecoding, TestEmptyClusterMetaDataDecode)
534534
{
535535
PayloadDecoderInitParams params;
536536

537537
params.SetProtocolDecodeTree(chip::TLVMeta::protocols_meta).SetClusterDecodeTree(empty_meta);
538538

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,
541541
"report_data\n"
542542
" attribute_reports\n"
543543
" Anonymous<>\n"
@@ -559,24 +559,24 @@ void TestEmptyClusterMetaDataDecode(nlTestSuite * inSuite, void * inContext)
559559
" interaction_model_revison: 1\n");
560560
}
561561

562-
void TestMissingDecodeData(nlTestSuite * inSuite, void * inContext)
562+
TEST(TestDecoding, TestMissingDecodeData)
563563
{
564564
PayloadDecoderInitParams params;
565565

566566
params.SetProtocolDecodeTree(empty_meta).SetClusterDecodeTree(empty_meta);
567567

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");
570570
}
571571

572-
void TestWrongDecodeData(nlTestSuite * inSuite, void * inContext)
572+
TEST(TestDecoding, TestWrongDecodeData)
573573
{
574574
PayloadDecoderInitParams params;
575575

576576
params.SetProtocolDecodeTree(fake_protocols_meta).SetClusterDecodeTree(empty_meta);
577577

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,
580580
"proto5\n"
581581
" ContextTag(0x1)\n"
582582
" AnonymousTag()\n"
@@ -598,7 +598,7 @@ void TestWrongDecodeData(nlTestSuite * inSuite, void * inContext)
598598
" ContextTag(0xFF): 1\n");
599599
}
600600

601-
void TestNestingOverflow(nlTestSuite * inSuite, void * inContext)
601+
TEST(TestDecoding, TestNestingOverflow)
602602
{
603603
PayloadDecoderInitParams params;
604604
params.SetProtocolDecodeTree(fake_protocols_meta).SetClusterDecodeTree(empty_meta);
@@ -611,65 +611,62 @@ void TestNestingOverflow(nlTestSuite * inSuite, void * inContext)
611611
chip::TLV::TLVType unusedType;
612612

613613
// 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);
615615

616616
// nesting overflow here
617617
for (uint8_t i = 0; i < 32; i++)
618618
{
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);
620620
}
621621
// Go back to 24 (still too much nesting)
622622
for (uint8_t i = 0; i < 8; i++)
623623
{
624-
NL_TEST_ASSERT(inSuite, writer.EndContainer(kTLVType_List) == CHIP_NO_ERROR);
624+
EXPECT_EQ(writer.EndContainer(kTLVType_List), CHIP_NO_ERROR);
625625
}
626626
for (uint8_t i = 0; i < 4; i++)
627627
{
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);
630629
}
631630
for (uint8_t i = 0; i < 4; i++)
632631
{
633-
NL_TEST_ASSERT(inSuite, writer.EndContainer(kTLVType_List) == CHIP_NO_ERROR);
632+
EXPECT_EQ(writer.EndContainer(kTLVType_List), CHIP_NO_ERROR);
634633
}
635634
// Go back to 8
636635
for (uint8_t i = 0; i < 16; i++)
637636
{
638-
NL_TEST_ASSERT(inSuite, writer.EndContainer(kTLVType_List) == CHIP_NO_ERROR);
637+
EXPECT_EQ(writer.EndContainer(kTLVType_List), CHIP_NO_ERROR);
639638
}
640639
for (uint8_t i = 0; i < 4; i++)
641640
{
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);
644642
}
645643
for (uint8_t i = 0; i < 4; i++)
646644
{
647-
NL_TEST_ASSERT(inSuite, writer.EndContainer(kTLVType_List) == CHIP_NO_ERROR);
645+
EXPECT_EQ(writer.EndContainer(kTLVType_List), CHIP_NO_ERROR);
648646
}
649647
// Go back to 4
650648
for (uint8_t i = 0; i < 4; i++)
651649
{
652-
NL_TEST_ASSERT(inSuite, writer.EndContainer(kTLVType_List) == CHIP_NO_ERROR);
650+
EXPECT_EQ(writer.EndContainer(kTLVType_List), CHIP_NO_ERROR);
653651
}
654652
for (uint8_t i = 0; i < 4; i++)
655653
{
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);
658655
}
659656
for (uint8_t i = 0; i < 4; i++)
660657
{
661-
NL_TEST_ASSERT(inSuite, writer.EndContainer(kTLVType_List) == CHIP_NO_ERROR);
658+
EXPECT_EQ(writer.EndContainer(kTLVType_List), CHIP_NO_ERROR);
662659
}
663660
// close everything
664661
for (uint8_t i = 0; i < 4; i++)
665662
{
666-
NL_TEST_ASSERT(inSuite, writer.EndContainer(kTLVType_List) == CHIP_NO_ERROR);
663+
EXPECT_EQ(writer.EndContainer(kTLVType_List), CHIP_NO_ERROR);
667664
}
668-
NL_TEST_ASSERT(inSuite, writer.EndContainer(kTLVType_Structure) == CHIP_NO_ERROR);
665+
EXPECT_EQ(writer.EndContainer(kTLVType_Structure), CHIP_NO_ERROR);
669666

670667
SamplePayload fake_payload{ chip::Protocols::InteractionModel::Id, 5, chip::ByteSpan(data_buffer, writer.GetLengthWritten()) };
671668

672-
TestSampleData(inSuite, params, fake_payload,
669+
TestSampleData(params, fake_payload,
673670
"proto5\n"
674671
" ContextTag(0x0)\n"
675672
" ContextTag(0x1)\n"
@@ -696,24 +693,4 @@ void TestNestingOverflow(nlTestSuite * inSuite, void * inContext)
696693
" ContextTag(0x32)\n"
697694
" ContextTag(0x33)\n");
698695
}
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-
710696
} // 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

Comments
 (0)