From 0ea7f4ff0e185ef74e788802b190bbd66e7404f2 Mon Sep 17 00:00:00 2001 From: AYA Date: Tue, 23 Apr 2024 17:36:24 +0200 Subject: [PATCH 1/5] pw_unit_test migration: setup_payload batch #2 (with fixtures) --- src/BUILD.gn | 1 - src/setup_payload/tests/BUILD.gn | 20 +- .../tests/TestAdditionalDataPayload.cpp | 181 +++++---------- src/setup_payload/tests/TestQRCodeTLV.cpp | 206 ++++++------------ .../unit-tests/test_components_nl.txt | 1 - 5 files changed, 126 insertions(+), 283 deletions(-) diff --git a/src/BUILD.gn b/src/BUILD.gn index d283c7ec4defad..25f0a57211766b 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -86,7 +86,6 @@ if (chip_build_tests) { chip_device_platform != "efr32") { tests += [ "${chip_root}/src/setup_payload/tests", - "${chip_root}/src/setup_payload/tests:tests_nltest", "${chip_root}/src/transport/raw/tests", ] } diff --git a/src/setup_payload/tests/BUILD.gn b/src/setup_payload/tests/BUILD.gn index 0f672c274fc941..b08d18a5a4fc15 100644 --- a/src/setup_payload/tests/BUILD.gn +++ b/src/setup_payload/tests/BUILD.gn @@ -23,25 +23,9 @@ chip_test_suite("tests") { output_name = "libSetupPayloadTests" test_sources = [ + "TestAdditionalDataPayload.cpp", "TestManualCode.cpp", "TestQRCode.cpp", - ] - - sources = [ "TestHelpers.h" ] - - cflags = [ "-Wconversion" ] - - public_deps = [ - "${chip_root}/src/platform", - "${chip_root}/src/setup_payload", - ] -} - -chip_test_suite_using_nltest("tests_nltest") { - output_name = "libSetupPayloadTestsNL" - - test_sources = [ - "TestAdditionalDataPayload.cpp", "TestQRCodeTLV.cpp", ] @@ -50,9 +34,7 @@ chip_test_suite_using_nltest("tests_nltest") { cflags = [ "-Wconversion" ] public_deps = [ - "${chip_root}/src/lib/support:testing_nlunit", "${chip_root}/src/platform", "${chip_root}/src/setup_payload", - "${nlunit_test_root}:nlunit-test", ] } diff --git a/src/setup_payload/tests/TestAdditionalDataPayload.cpp b/src/setup_payload/tests/TestAdditionalDataPayload.cpp index f64846222323e9..6c9854066dead0 100644 --- a/src/setup_payload/tests/TestAdditionalDataPayload.cpp +++ b/src/setup_payload/tests/TestAdditionalDataPayload.cpp @@ -22,22 +22,20 @@ * */ +#include #include #include -#include #include #include #include #include #include -#include #include #include #include #include -#include #include using namespace chip; @@ -59,7 +57,7 @@ constexpr uint16_t kLifetimeCounter constexpr uint16_t kShortRotatingIdLength = 5; #endif // CHIP_ENABLE_ROTATING_DEVICE_ID -CHIP_ERROR GenerateAdditionalDataPayload(nlTestSuite * inSuite, AdditionalDataPayloadGeneratorParams & additionalDataPayloadParams, +CHIP_ERROR GenerateAdditionalDataPayload(AdditionalDataPayloadGeneratorParams & additionalDataPayloadParams, BitFlags additionalDataFields, char * additionalDataPayloadOutput) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -69,7 +67,7 @@ CHIP_ERROR GenerateAdditionalDataPayload(nlTestSuite * inSuite, AdditionalDataPa additionalDataFields); if (err == CHIP_NO_ERROR) { - NL_TEST_ASSERT(inSuite, !bufferHandle.IsNull()); + EXPECT_FALSE(bufferHandle.IsNull()); } else { @@ -99,20 +97,25 @@ CHIP_ERROR ParseAdditionalDataPayload(const char * additionalDataPayload, size_t return AdditionalDataPayloadParser(additionalDataPayloadBytes.get(), bufferSize).populatePayload(outPayload); } -void TestGeneratingAdditionalDataPayloadWithoutRotatingDeviceId(nlTestSuite * inSuite, void * inContext) +class TestAdditionalDataPayload : public ::testing::Test +{ +public: + static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); } + static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); } +}; + +TEST_F(TestAdditionalDataPayload, TestGeneratingAdditionalDataPayloadWithoutRotatingDeviceId) { BitFlags additionalDataFields; char output[kAdditionalDataPayloadLength]; AdditionalDataPayloadGeneratorParams additionalDataPayloadParams; - NL_TEST_ASSERT(inSuite, - GenerateAdditionalDataPayload(inSuite, additionalDataPayloadParams, additionalDataFields, output) == - CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, strcmp(output, kAdditionalDataPayloadWithoutRotatingDeviceId) == 0); + EXPECT_EQ(GenerateAdditionalDataPayload(additionalDataPayloadParams, additionalDataFields, output), CHIP_NO_ERROR); + EXPECT_STREQ(output, kAdditionalDataPayloadWithoutRotatingDeviceId); } #if CHIP_ENABLE_ROTATING_DEVICE_ID -void TestGeneratingAdditionalDataPayloadWithRotatingDeviceId(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAdditionalDataPayload, TestGeneratingAdditionalDataPayloadWithRotatingDeviceId) { BitFlags additionalDataFields; additionalDataFields.Set(AdditionalDataFields::RotatingDeviceId); @@ -121,13 +124,11 @@ void TestGeneratingAdditionalDataPayloadWithRotatingDeviceId(nlTestSuite * inSui additionalDataPayloadParams.rotatingDeviceIdUniqueId = ByteSpan(kUniqueId); char output[kAdditionalDataPayloadLength]; - NL_TEST_ASSERT(inSuite, - GenerateAdditionalDataPayload(inSuite, additionalDataPayloadParams, additionalDataFields, output) == - CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, strcmp(output, kAdditionalDataPayloadWithRotatingDeviceId) == 0); + EXPECT_EQ(GenerateAdditionalDataPayload(additionalDataPayloadParams, additionalDataFields, output), CHIP_NO_ERROR); + EXPECT_STREQ(output, kAdditionalDataPayloadWithRotatingDeviceId); } -void TestGeneratingAdditionalDataPayloadWithRotatingDeviceIdAndMaxLifetimeCounter(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAdditionalDataPayload, TestGeneratingAdditionalDataPayloadWithRotatingDeviceIdAndMaxLifetimeCounter) { BitFlags additionalDataFields; additionalDataFields.Set(AdditionalDataFields::RotatingDeviceId); @@ -136,25 +137,22 @@ void TestGeneratingAdditionalDataPayloadWithRotatingDeviceIdAndMaxLifetimeCounte additionalDataPayloadParams.rotatingDeviceIdUniqueId = ByteSpan(kUniqueId); char output[kAdditionalDataPayloadLength]; - NL_TEST_ASSERT(inSuite, - GenerateAdditionalDataPayload(inSuite, additionalDataPayloadParams, additionalDataFields, output) == - CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, strcmp(output, kAdditionalDataPayloadWithRotatingDeviceIdAndMaxLifetimeCounter) == 0); + EXPECT_EQ(GenerateAdditionalDataPayload(additionalDataPayloadParams, additionalDataFields, output), CHIP_NO_ERROR); + EXPECT_STREQ(output, kAdditionalDataPayloadWithRotatingDeviceIdAndMaxLifetimeCounter); } -void TestGeneratingAdditionalDataPayloadWithRotatingDeviceIdWithNullInputs(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAdditionalDataPayload, TestGeneratingAdditionalDataPayloadWithRotatingDeviceIdWithNullInputs) { BitFlags additionalDataFields; additionalDataFields.Set(AdditionalDataFields::RotatingDeviceId); AdditionalDataPayloadGeneratorParams additionalDataPayloadParams; char output[kAdditionalDataPayloadLength]; - NL_TEST_ASSERT(inSuite, - GenerateAdditionalDataPayload(inSuite, additionalDataPayloadParams, additionalDataFields, output) == - CHIP_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(GenerateAdditionalDataPayload(additionalDataPayloadParams, additionalDataFields, output), + CHIP_ERROR_INVALID_ARGUMENT); } -void TestGeneratingRotatingDeviceIdAsString(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAdditionalDataPayload, TestGeneratingRotatingDeviceIdAsString) { CHIP_ERROR err = CHIP_NO_ERROR; char rotatingDeviceIdHexBuffer[RotatingDeviceId::kHexMaxLength]; @@ -165,8 +163,8 @@ void TestGeneratingRotatingDeviceIdAsString(nlTestSuite * inSuite, void * inCont err = AdditionalDataPayloadGenerator().generateRotatingDeviceIdAsHexString( additionalDataPayloadParams, rotatingDeviceIdHexBuffer, ArraySize(rotatingDeviceIdHexBuffer), rotatingDeviceIdValueOutputSize); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, strcmp(rotatingDeviceIdHexBuffer, kRotatingDeviceId) == 0); + EXPECT_EQ(err, CHIP_NO_ERROR); + EXPECT_STREQ(rotatingDeviceIdHexBuffer, kRotatingDeviceId); // Parsing out the lifetime counter value long lifetimeCounter; char lifetimeCounterStr[3]; @@ -174,10 +172,10 @@ void TestGeneratingRotatingDeviceIdAsString(nlTestSuite * inSuite, void * inCont char * parseEnd; lifetimeCounter = strtol(lifetimeCounterStr, &parseEnd, 16); - NL_TEST_ASSERT(inSuite, lifetimeCounter == kLifetimeCounter); + EXPECT_EQ(lifetimeCounter, kLifetimeCounter); } -void TestGeneratingRotatingDeviceIdAsStringWithNullInputs(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAdditionalDataPayload, TestGeneratingRotatingDeviceIdAsStringWithNullInputs) { CHIP_ERROR err = CHIP_NO_ERROR; char rotatingDeviceIdHexBuffer[RotatingDeviceId::kHexMaxLength]; @@ -188,10 +186,10 @@ void TestGeneratingRotatingDeviceIdAsStringWithNullInputs(nlTestSuite * inSuite, err = AdditionalDataPayloadGenerator().generateRotatingDeviceIdAsHexString( additionalDataPayloadParams, rotatingDeviceIdHexBuffer, ArraySize(rotatingDeviceIdHexBuffer), rotatingDeviceIdValueOutputSize); - NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(err, CHIP_ERROR_INVALID_ARGUMENT); } -void TestGeneratingRotatingDeviceIdWithSmallBuffer(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAdditionalDataPayload, TestGeneratingRotatingDeviceIdWithSmallBuffer) { CHIP_ERROR err = CHIP_NO_ERROR; char rotatingDeviceIdHexBuffer[kShortRotatingIdLength]; @@ -202,122 +200,51 @@ void TestGeneratingRotatingDeviceIdWithSmallBuffer(nlTestSuite * inSuite, void * err = AdditionalDataPayloadGenerator().generateRotatingDeviceIdAsHexString( additionalDataPayloadParams, rotatingDeviceIdHexBuffer, ArraySize(rotatingDeviceIdHexBuffer), rotatingDeviceIdValueOutputSize); - NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_BUFFER_TOO_SMALL); + EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL); } #endif // CHIP_ENABLE_ROTATING_DEVICE_ID -void TestParsingAdditionalDataPayloadWithRotatingDeviceId(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAdditionalDataPayload, TestParsingAdditionalDataPayloadWithRotatingDeviceId) { chip::SetupPayloadData::AdditionalDataPayload resultPayload; - NL_TEST_ASSERT(inSuite, - ParseAdditionalDataPayload(kAdditionalDataPayloadWithRotatingDeviceId, - strlen(kAdditionalDataPayloadWithRotatingDeviceId), resultPayload) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, strcmp(resultPayload.rotatingDeviceId.c_str(), kRotatingDeviceId) == 0); + EXPECT_EQ(ParseAdditionalDataPayload(kAdditionalDataPayloadWithRotatingDeviceId, + strlen(kAdditionalDataPayloadWithRotatingDeviceId), resultPayload), + CHIP_NO_ERROR); + EXPECT_STREQ(resultPayload.rotatingDeviceId.c_str(), kRotatingDeviceId); } -void TestParsingAdditionalDataPayloadWithoutRotatingDeviceId(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAdditionalDataPayload, TestParsingAdditionalDataPayloadWithoutRotatingDeviceId) { chip::SetupPayloadData::AdditionalDataPayload resultPayload; - NL_TEST_ASSERT(inSuite, - ParseAdditionalDataPayload(kAdditionalDataPayloadWithoutRotatingDeviceId, - strlen(kAdditionalDataPayloadWithoutRotatingDeviceId), - resultPayload) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, strcmp(resultPayload.rotatingDeviceId.c_str(), "") == 0); + EXPECT_EQ(ParseAdditionalDataPayload(kAdditionalDataPayloadWithoutRotatingDeviceId, + strlen(kAdditionalDataPayloadWithoutRotatingDeviceId), resultPayload), + CHIP_NO_ERROR); + EXPECT_STREQ(resultPayload.rotatingDeviceId.c_str(), ""); } -void TestParsingAdditionalDataPayloadWithInvalidRotatingDeviceIdLength(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAdditionalDataPayload, TestParsingAdditionalDataPayloadWithInvalidRotatingDeviceIdLength) { chip::SetupPayloadData::AdditionalDataPayload resultPayload; - NL_TEST_ASSERT(inSuite, - ParseAdditionalDataPayload(kAdditionalDataPayloadWithInvalidRotatingDeviceIdLength, - strlen(kAdditionalDataPayloadWithInvalidRotatingDeviceIdLength), - resultPayload) == CHIP_ERROR_TLV_UNDERRUN); + EXPECT_EQ(ParseAdditionalDataPayload(kAdditionalDataPayloadWithInvalidRotatingDeviceIdLength, + strlen(kAdditionalDataPayloadWithInvalidRotatingDeviceIdLength), resultPayload), + CHIP_ERROR_TLV_UNDERRUN); } -void TestParsingAdditionalDataPayloadWithLongRotatingDeviceId(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAdditionalDataPayload, TestParsingAdditionalDataPayloadWithLongRotatingDeviceId) { chip::SetupPayloadData::AdditionalDataPayload resultPayload; - NL_TEST_ASSERT(inSuite, - ParseAdditionalDataPayload(kAdditionalDataPayloadWithLongRotatingDeviceId, - strlen(kAdditionalDataPayloadWithLongRotatingDeviceId), - resultPayload) == CHIP_ERROR_INVALID_STRING_LENGTH); + EXPECT_EQ(ParseAdditionalDataPayload(kAdditionalDataPayloadWithLongRotatingDeviceId, + strlen(kAdditionalDataPayloadWithLongRotatingDeviceId), resultPayload), + CHIP_ERROR_INVALID_STRING_LENGTH); } -void TestParsingAdditionalDataPayloadWithShortRotatingDeviceId(nlTestSuite * inSuite, void * inContext) +TEST_F(TestAdditionalDataPayload, TestParsingAdditionalDataPayloadWithShortRotatingDeviceId) { chip::SetupPayloadData::AdditionalDataPayload resultPayload; - NL_TEST_ASSERT(inSuite, - ParseAdditionalDataPayload(kAdditionalDataPayloadWithShortRotatingDeviceId, - strlen(kAdditionalDataPayloadWithShortRotatingDeviceId), - resultPayload) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, strcmp(resultPayload.rotatingDeviceId.c_str(), kShortRotatingDeviceId) == 0); -} - -/** - * Test Suite that lists all the Test functions. - */ -// clang-format off -const nlTest sTests[] = -{ - NL_TEST_DEF("Test Generating Additional Data Payload without Rotatin gDevice Id", TestGeneratingAdditionalDataPayloadWithoutRotatingDeviceId), - #if CHIP_ENABLE_ROTATING_DEVICE_ID - NL_TEST_DEF("Test Generating Additional Data Payload with Rotating Device Id", TestGeneratingAdditionalDataPayloadWithRotatingDeviceId), - NL_TEST_DEF("Test Generating Additional Data Payload with Rotating Device Id + Max Lifetime Counter", TestGeneratingAdditionalDataPayloadWithRotatingDeviceIdAndMaxLifetimeCounter), - NL_TEST_DEF("Test Generating Additional Data Payload with Rotating Device Id + Null/Empty Inputs", TestGeneratingAdditionalDataPayloadWithRotatingDeviceIdWithNullInputs), - NL_TEST_DEF("Test Generating Rotating Device Id as string", TestGeneratingRotatingDeviceIdAsString), - NL_TEST_DEF("Test Generating Rotating Device Id as string with null/invalid inputs", TestGeneratingRotatingDeviceIdAsStringWithNullInputs), - NL_TEST_DEF("Test Generating Rotating Device Id as string with small buffer", TestGeneratingRotatingDeviceIdWithSmallBuffer), - #endif - NL_TEST_DEF("Test Parsing Additional Data Payload with Rotating Device Id", TestParsingAdditionalDataPayloadWithRotatingDeviceId), - NL_TEST_DEF("Test Parsing Additional Data Payload without Rotating Device Id", TestParsingAdditionalDataPayloadWithoutRotatingDeviceId), - NL_TEST_DEF("Test Parsing Additional Data Payload with Invalid Rotating Device Id Length", TestParsingAdditionalDataPayloadWithInvalidRotatingDeviceIdLength), - NL_TEST_DEF("Test Parsing Additional Data Payload with Long Rotating Device Id", TestParsingAdditionalDataPayloadWithLongRotatingDeviceId), - NL_TEST_DEF("Test Parsing Additional Data Payload with Short Rotating Device Id", TestParsingAdditionalDataPayloadWithShortRotatingDeviceId), - NL_TEST_SENTINEL() -}; -// clang-format on - -} // namespace - -/** - * Set up the test suite. - */ -int TestAdditionalDataPayload_Setup(void * inContext) -{ - CHIP_ERROR error = chip::Platform::MemoryInit(); - if (error != CHIP_NO_ERROR) - return FAILURE; - return SUCCESS; -} - -/** - * Tear down the test suite. - */ -int TestAdditionalDataPayload_Teardown(void * inContext) -{ - chip::Platform::MemoryShutdown(); - return SUCCESS; -} - -/** - * Main - */ -int TestAdditionalDataPayload() -{ - // clang-format off - nlTestSuite theSuite = - { - "chip-additional-data-payload-general-Tests", - &sTests[0], - TestAdditionalDataPayload_Setup, - TestAdditionalDataPayload_Teardown - }; - // clang-format on - - // Generate machine-readable, comma-separated value (CSV) output. - nl_test_set_output_style(OUTPUT_CSV); - - return chip::ExecuteTestsWithoutContext(&theSuite); + EXPECT_EQ(ParseAdditionalDataPayload(kAdditionalDataPayloadWithShortRotatingDeviceId, + strlen(kAdditionalDataPayloadWithShortRotatingDeviceId), resultPayload), + CHIP_NO_ERROR); + EXPECT_STREQ(resultPayload.rotatingDeviceId.c_str(), kShortRotatingDeviceId); } -CHIP_REGISTER_TEST_SUITE(TestAdditionalDataPayload); +} // namespace \ No newline at end of file diff --git a/src/setup_payload/tests/TestQRCodeTLV.cpp b/src/setup_payload/tests/TestQRCodeTLV.cpp index 739a074184b0ca..cdf6048a49b9a0 100644 --- a/src/setup_payload/tests/TestQRCodeTLV.cpp +++ b/src/setup_payload/tests/TestQRCodeTLV.cpp @@ -16,81 +16,86 @@ */ #include "TestHelpers.h" +#include #include -#include #include -#include -#include using namespace chip; using namespace std; namespace { -void TestOptionalDataAddRemove(nlTestSuite * inSuite, void * inContext) +class TestQRCodeTLV : public ::testing::Test +{ +public: + static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); } + static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); } +}; + +TEST_F(TestQRCodeTLV, TestOptionalDataAddRemove) { SetupPayload payload = GetDefaultPayload(); vector optionalData; CHIP_ERROR err; optionalData = payload.getAllOptionalVendorData(); - NL_TEST_ASSERT(inSuite, optionalData.empty()); + EXPECT_TRUE(optionalData.empty()); err = payload.addOptionalVendorData(kOptionalDefaultStringTag, kOptionalDefaultStringValue); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); optionalData = payload.getAllOptionalVendorData(); - NL_TEST_ASSERT(inSuite, optionalData.size() == 1); + EXPECT_TRUE(optionalData.size()); err = payload.addOptionalVendorData(kOptionalDefaultIntTag, kOptionalDefaultIntValue); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); optionalData = payload.getAllOptionalVendorData(); - NL_TEST_ASSERT(inSuite, optionalData.size() == 2); + EXPECT_EQ(optionalData.size(), 2u); err = payload.removeOptionalVendorData(kOptionalDefaultStringTag); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); optionalData = payload.getAllOptionalVendorData(); - NL_TEST_ASSERT(inSuite, optionalData.size() == 1); + EXPECT_EQ(optionalData.size(), 1u); payload.removeOptionalVendorData(kOptionalDefaultIntTag); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); optionalData = payload.getAllOptionalVendorData(); - NL_TEST_ASSERT(inSuite, optionalData.empty()); + EXPECT_TRUE(optionalData.empty()); err = payload.removeOptionalVendorData(kOptionalDefaultStringTag); - NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_KEY_NOT_FOUND); + EXPECT_EQ(err, CHIP_ERROR_KEY_NOT_FOUND); optionalData = payload.getAllOptionalVendorData(); - NL_TEST_ASSERT(inSuite, optionalData.empty()); + EXPECT_TRUE(optionalData.empty()); err = payload.removeOptionalVendorData(kOptionalDefaultIntTag); - NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_KEY_NOT_FOUND); + EXPECT_EQ(err, CHIP_ERROR_KEY_NOT_FOUND); optionalData = payload.getAllOptionalVendorData(); - NL_TEST_ASSERT(inSuite, optionalData.empty()); + EXPECT_TRUE(optionalData.empty()); } -void TestSimpleWrite(nlTestSuite * inSuite, void * inContext) +TEST_F(TestQRCodeTLV, TestSimpleWrite) { SetupPayload inPayload = GetDefaultPayload(); QRCodeSetupPayloadGenerator generator(inPayload); string result; CHIP_ERROR err = generator.payloadBase38Representation(result); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); string result2; err = generator.payloadBase38RepresentationWithAutoTLVBuffer(result2); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, result == result2); + EXPECT_EQ(result, result2); } -void TestSimpleRead(nlTestSuite * inSuite, void * inContext) +TEST_F(TestQRCodeTLV, TestSimpleRead) { SetupPayload inPayload = GetDefaultPayload(); SetupPayload outPayload; @@ -98,81 +103,81 @@ void TestSimpleRead(nlTestSuite * inSuite, void * inContext) QRCodeSetupPayloadGenerator generator(inPayload); string result; CHIP_ERROR err = generator.payloadBase38Representation(result); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); QRCodeSetupPayloadParser parser = QRCodeSetupPayloadParser(result); err = parser.populatePayload(outPayload); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, inPayload == outPayload); + EXPECT_TRUE(inPayload == outPayload); } -void TestOptionalTagValues(nlTestSuite * inSuite, void * inContext) +TEST_F(TestQRCodeTLV, TestOptionalTagValues) { SetupPayload payload = GetDefaultPayload(); CHIP_ERROR err; err = payload.addOptionalVendorData(kOptionalDefaultStringTag, kOptionalDefaultStringValue); // Vendor specific tag - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = payload.addOptionalVendorData(0x80, kOptionalDefaultStringValue); // Vendor specific tag - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = payload.addOptionalVendorData(0x82, kOptionalDefaultStringValue); // Vendor specific tag - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); err = payload.addOptionalVendorData(127, kOptionalDefaultStringValue); // Common tag - NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(err, CHIP_ERROR_INVALID_ARGUMENT); err = payload.addOptionalVendorData(0, kOptionalDefaultStringValue); // Common tag - NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INVALID_ARGUMENT); + EXPECT_EQ(err, CHIP_ERROR_INVALID_ARGUMENT); } -void TestSerialNumberAddRemove(nlTestSuite * inSuite, void * inContext) +TEST_F(TestQRCodeTLV, TestSerialNumberAddRemove) { SetupPayload inPayload = GetDefaultPayload(); string sn; - NL_TEST_ASSERT(inSuite, inPayload.getSerialNumber(sn) == CHIP_ERROR_KEY_NOT_FOUND); - NL_TEST_ASSERT(inSuite, inPayload.removeSerialNumber() == CHIP_ERROR_KEY_NOT_FOUND); + EXPECT_EQ(inPayload.getSerialNumber(sn), CHIP_ERROR_KEY_NOT_FOUND); + EXPECT_EQ(inPayload.removeSerialNumber(), CHIP_ERROR_KEY_NOT_FOUND); - NL_TEST_ASSERT(inSuite, inPayload.addSerialNumber(kSerialNumberDefaultStringValue) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, inPayload.getSerialNumber(sn) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, sn == kSerialNumberDefaultStringValue); + EXPECT_EQ(inPayload.addSerialNumber(kSerialNumberDefaultStringValue), CHIP_NO_ERROR); + EXPECT_EQ(inPayload.getSerialNumber(sn), CHIP_NO_ERROR); + EXPECT_EQ(sn, kSerialNumberDefaultStringValue); - NL_TEST_ASSERT(inSuite, inPayload.addSerialNumber(kSerialNumberDefaultUInt32Value) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, inPayload.getSerialNumber(sn) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, sn == to_string(kSerialNumberDefaultUInt32Value)); + EXPECT_EQ(inPayload.addSerialNumber(kSerialNumberDefaultUInt32Value), CHIP_NO_ERROR); + EXPECT_EQ(inPayload.getSerialNumber(sn), CHIP_NO_ERROR); + EXPECT_EQ(sn, to_string(kSerialNumberDefaultUInt32Value)); - NL_TEST_ASSERT(inSuite, inPayload.removeSerialNumber() == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, inPayload.getSerialNumber(sn) == CHIP_ERROR_KEY_NOT_FOUND); - NL_TEST_ASSERT(inSuite, inPayload.removeSerialNumber() == CHIP_ERROR_KEY_NOT_FOUND); + EXPECT_EQ(inPayload.removeSerialNumber(), CHIP_NO_ERROR); + EXPECT_EQ(inPayload.getSerialNumber(sn), CHIP_ERROR_KEY_NOT_FOUND); + EXPECT_EQ(inPayload.removeSerialNumber(), CHIP_ERROR_KEY_NOT_FOUND); } -void TestOptionalDataWriteSerial(nlTestSuite * inSuite, void * inContext) +TEST_F(TestQRCodeTLV, TestOptionalDataWriteSerial) { CHIP_ERROR err = CHIP_NO_ERROR; SetupPayload inPayload = GetDefaultPayload(); err = inPayload.addSerialNumber("1"); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); QRCodeSetupPayloadGenerator generator(inPayload); string result; err = generator.payloadBase38Representation(result); - NL_TEST_ASSERT(inSuite, err != CHIP_NO_ERROR); + EXPECT_NE(err, CHIP_NO_ERROR); uint8_t optionalInfo[kDefaultBufferSizeInBytes]; err = generator.payloadBase38Representation(result, optionalInfo, sizeof(optionalInfo)); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); string result2; err = generator.payloadBase38RepresentationWithAutoTLVBuffer(result2); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, result == result2); + EXPECT_EQ(result, result2); } -void TestOptionalDataWrite(nlTestSuite * inSuite, void * inContext) +TEST_F(TestQRCodeTLV, TestOptionalDataWrite) { SetupPayload inPayload = GetDefaultPayloadWithOptionalDefaults(); @@ -180,60 +185,60 @@ void TestOptionalDataWrite(nlTestSuite * inSuite, void * inContext) string result; uint8_t optionalInfo[kDefaultBufferSizeInBytes]; CHIP_ERROR err = generator.payloadBase38Representation(result, optionalInfo, sizeof(optionalInfo)); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); string result2; err = generator.payloadBase38RepresentationWithAutoTLVBuffer(result2); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, result == result2); + EXPECT_EQ(result, result2); } -void TestOptionalDataReadSerial(nlTestSuite * inSuite, void * inContext) +TEST_F(TestQRCodeTLV, TestOptionalDataReadSerial) { SetupPayload inPayload = GetDefaultPayload(); inPayload.addSerialNumber(kSerialNumberDefaultStringValue); - NL_TEST_ASSERT(inSuite, CheckWriteRead(inPayload)); + EXPECT_TRUE(CheckWriteRead(inPayload)); inPayload.addSerialNumber(kSerialNumberDefaultUInt32Value); - NL_TEST_ASSERT(inSuite, CheckWriteRead(inPayload)); + EXPECT_TRUE(CheckWriteRead(inPayload)); } -void TestOptionalDataReadVendorInt(nlTestSuite * inSuite, void * inContext) +TEST_F(TestQRCodeTLV, TestOptionalDataReadVendorInt) { SetupPayload inPayload = GetDefaultPayload(); inPayload.addOptionalVendorData(kOptionalDefaultIntTag, kOptionalDefaultIntValue); - NL_TEST_ASSERT(inSuite, CheckWriteRead(inPayload)); + EXPECT_TRUE(CheckWriteRead(inPayload)); } -void TestOptionalDataReadVendorString(nlTestSuite * inSuite, void * inContext) +TEST_F(TestQRCodeTLV, TestOptionalDataReadVendorString) { SetupPayload inPayload = GetDefaultPayload(); inPayload.addOptionalVendorData(kOptionalDefaultStringTag, kOptionalDefaultStringValue); - NL_TEST_ASSERT(inSuite, CheckWriteRead(inPayload)); + EXPECT_TRUE(CheckWriteRead(inPayload)); } -void TestOptionalDataRead(nlTestSuite * inSuite, void * inContext) +TEST_F(TestQRCodeTLV, TestOptionalDataRead) { SetupPayload inPayload = GetDefaultPayloadWithOptionalDefaults(); - NL_TEST_ASSERT(inSuite, CheckWriteRead(inPayload)); + EXPECT_TRUE(CheckWriteRead(inPayload)); } -void TestOptionalDataWriteNoBuffer(nlTestSuite * inSuite, void * inContext) +TEST_F(TestQRCodeTLV, TestOptionalDataWriteNoBuffer) { SetupPayload inPayload = GetDefaultPayloadWithOptionalDefaults(); QRCodeSetupPayloadGenerator generator(inPayload); string result; CHIP_ERROR err = generator.payloadBase38Representation(result); - NL_TEST_ASSERT(inSuite, err != CHIP_NO_ERROR); + EXPECT_NE(err, CHIP_NO_ERROR); } -void TestOptionalDataWriteSmallBuffer(nlTestSuite * inSuite, void * inContext) +TEST_F(TestQRCodeTLV, TestOptionalDataWriteSmallBuffer) { SetupPayload inPayload = GetDefaultPayloadWithOptionalDefaults(); @@ -241,76 +246,7 @@ void TestOptionalDataWriteSmallBuffer(nlTestSuite * inSuite, void * inContext) string result; uint8_t optionalInfo[kSmallBufferSizeInBytes]; CHIP_ERROR err = generator.payloadBase38Representation(result, optionalInfo, sizeof(optionalInfo)); - NL_TEST_ASSERT(inSuite, err != CHIP_NO_ERROR); -} - -// Test Suite - -/** - * Test Suite that lists all the test functions. - */ -// clang-format off -const nlTest sTests[] = -{ - NL_TEST_DEF("Test Simple Write", TestSimpleWrite), - NL_TEST_DEF("Test Simple Read", TestSimpleRead), - NL_TEST_DEF("Test Optional Add Remove", TestOptionalDataAddRemove), - NL_TEST_DEF("Test Serial Number Add Remove", TestSerialNumberAddRemove), - NL_TEST_DEF("Test Optional Write", TestOptionalDataWrite), - NL_TEST_DEF("Test Optional Write Serial", TestOptionalDataWriteSerial), - NL_TEST_DEF("Test Optional Write No Buffer", TestOptionalDataWriteNoBuffer), - NL_TEST_DEF("Test Optional Write Small Buffer", TestOptionalDataWriteSmallBuffer), - NL_TEST_DEF("Test Optional Read Serial", TestOptionalDataReadSerial), - NL_TEST_DEF("Test Optional Read Vendor String", TestOptionalDataReadVendorString), - NL_TEST_DEF("Test Optional Read Vendor Int", TestOptionalDataReadVendorInt), - NL_TEST_DEF("Test Optional Read", TestOptionalDataRead), - NL_TEST_DEF("Test Optional Tag Values", TestOptionalTagValues), - - NL_TEST_SENTINEL() -}; -// clang-format on - -/** - * Set up the test suite. - */ -int TestQRCodeTLV_Setup(void * inContext) -{ - CHIP_ERROR error = chip::Platform::MemoryInit(); - if (error != CHIP_NO_ERROR) - return FAILURE; - return SUCCESS; -} - -/** - * Tear down the test suite. - */ -int TestQRCodeTLV_Teardown(void * inContext) -{ - chip::Platform::MemoryShutdown(); - return SUCCESS; + EXPECT_NE(err, CHIP_NO_ERROR); } } // namespace - -/** - * Main - */ -int TestQRCodeTLV() -{ - // clang-format off - nlTestSuite theSuite = - { - "chip-qrcode-optional-info-tests", - &sTests[0], - TestQRCodeTLV_Setup, - TestQRCodeTLV_Teardown - }; - // clang-format on - - // Generate machine-readable, comma-separated value (CSV) output. - nl_test_set_output_style(OUTPUT_CSV); - - return chip::ExecuteTestsWithoutContext(&theSuite); -} - -CHIP_REGISTER_TEST_SUITE(TestQRCodeTLV); diff --git a/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt index 3da7f5bdfb608f..2c5858bf2c5acd 100644 --- a/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt +++ b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt @@ -10,7 +10,6 @@ MinimalMdnsCoreTests RawTransportTests RetransmitTests SecureChannelTests -SetupPayloadTestsNL SupportTests TransportLayerTests UserDirectedCommissioningTests From 0aee05a7d6c7971c1417e54c80b7afff36e69843 Mon Sep 17 00:00:00 2001 From: AYA Date: Tue, 23 Apr 2024 17:45:33 +0200 Subject: [PATCH 2/5] restyle fix --- src/setup_payload/tests/TestAdditionalDataPayload.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup_payload/tests/TestAdditionalDataPayload.cpp b/src/setup_payload/tests/TestAdditionalDataPayload.cpp index 6c9854066dead0..93b5bdf2fe1edc 100644 --- a/src/setup_payload/tests/TestAdditionalDataPayload.cpp +++ b/src/setup_payload/tests/TestAdditionalDataPayload.cpp @@ -247,4 +247,4 @@ TEST_F(TestAdditionalDataPayload, TestParsingAdditionalDataPayloadWithShortRotat EXPECT_STREQ(resultPayload.rotatingDeviceId.c_str(), kShortRotatingDeviceId); } -} // namespace \ No newline at end of file +} // namespace From fcbae6e77dc222add6c1464875f37778a452d1fa Mon Sep 17 00:00:00 2001 From: AYA Date: Wed, 24 Apr 2024 13:09:49 +0200 Subject: [PATCH 3/5] integrating comments --- src/setup_payload/tests/TestAdditionalDataPayload.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/setup_payload/tests/TestAdditionalDataPayload.cpp b/src/setup_payload/tests/TestAdditionalDataPayload.cpp index 93b5bdf2fe1edc..0dcd5f113339b9 100644 --- a/src/setup_payload/tests/TestAdditionalDataPayload.cpp +++ b/src/setup_payload/tests/TestAdditionalDataPayload.cpp @@ -22,22 +22,23 @@ * */ -#include + #include #include #include +#include + #include #include #include #include +#include #include #include #include #include -#include - using namespace chip; namespace { From 587ac681683076b89b0d1e9be6ed70c61bbb982a Mon Sep 17 00:00:00 2001 From: AYA Date: Wed, 24 Apr 2024 13:12:50 +0200 Subject: [PATCH 4/5] restyle --- src/setup_payload/tests/TestAdditionalDataPayload.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/setup_payload/tests/TestAdditionalDataPayload.cpp b/src/setup_payload/tests/TestAdditionalDataPayload.cpp index 0dcd5f113339b9..36ec0e6a970b90 100644 --- a/src/setup_payload/tests/TestAdditionalDataPayload.cpp +++ b/src/setup_payload/tests/TestAdditionalDataPayload.cpp @@ -22,7 +22,6 @@ * */ - #include #include #include From 43997be34089ed2c5763c8b8a14001bf9d83c49a Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 24 Apr 2024 08:08:34 -0400 Subject: [PATCH 5/5] Update test_components_nl.txt --- src/test_driver/openiotsdk/unit-tests/test_components_nl.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt index 809a36b167c817..95339685cf9a74 100644 --- a/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt +++ b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt @@ -8,7 +8,6 @@ MessagingLayerTests RawTransportTests RetransmitTests SecureChannelTests -SetupPayloadTestsNL SupportTestsNL TransportLayerTests UserDirectedCommissioningTests