diff --git a/src/BUILD.gn b/src/BUILD.gn index 25f0a57211766b..d283c7ec4defad 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -86,6 +86,7 @@ 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 4ed7033417352e..0f672c274fc941 100644 --- a/src/setup_payload/tests/BUILD.gn +++ b/src/setup_payload/tests/BUILD.gn @@ -15,16 +15,33 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") import("//build_overrides/nlunit_test.gni") +import("//build_overrides/pigweed.gni") import("${chip_root}/build/chip/chip_test_suite.gni") -chip_test_suite_using_nltest("tests") { +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", ] diff --git a/src/setup_payload/tests/TestManualCode.cpp b/src/setup_payload/tests/TestManualCode.cpp index cfe7c59c06e8b8..0b9be9a906011e 100644 --- a/src/setup_payload/tests/TestManualCode.cpp +++ b/src/setup_payload/tests/TestManualCode.cpp @@ -22,15 +22,13 @@ * */ -#include +#include #include #include #include #include -#include -#include #include #include @@ -79,26 +77,26 @@ PayloadContents GetDefaultPayload() return payload; } -void TestDecimalRepresentation_PartialPayload(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestDecimalRepresentation_PartialPayload) { PayloadContents payload = GetDefaultPayload(); std::string expectedResult = "2412950753"; - NL_TEST_ASSERT(inSuite, CheckGenerator(payload, expectedResult)); + EXPECT_TRUE(CheckGenerator(payload, expectedResult)); } -void TestDecimalRepresentation_PartialPayload_RequiresCustomFlow(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestDecimalRepresentation_PartialPayload_RequiresCustomFlow) { PayloadContents payload = GetDefaultPayload(); payload.commissioningFlow = CommissioningFlow::kCustom; std::string expectedResult = "64129507530000000000"; - NL_TEST_ASSERT(inSuite, CheckGenerator(payload, expectedResult)); + EXPECT_TRUE(CheckGenerator(payload, expectedResult)); } -void TestDecimalRepresentation_FullPayloadWithZeros(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestDecimalRepresentation_FullPayloadWithZeros) { PayloadContents payload = GetDefaultPayload(); payload.commissioningFlow = CommissioningFlow::kCustom; @@ -107,10 +105,10 @@ void TestDecimalRepresentation_FullPayloadWithZeros(nlTestSuite * inSuite, void std::string expectedResult = "64129507530000100001"; - NL_TEST_ASSERT(inSuite, CheckGenerator(payload, expectedResult)); + EXPECT_TRUE(CheckGenerator(payload, expectedResult)); } -void TestDecimalRepresentation_FullPayloadWithoutZeros_DoesNotRequireCustomFlow(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestDecimalRepresentation_FullPayloadWithoutZeros_DoesNotRequireCustomFlow) { PayloadContents payload = GetDefaultPayload(); payload.vendorID = 45367; @@ -118,10 +116,10 @@ void TestDecimalRepresentation_FullPayloadWithoutZeros_DoesNotRequireCustomFlow( std::string expectedResult = "2412950753"; - NL_TEST_ASSERT(inSuite, CheckGenerator(payload, expectedResult)); + EXPECT_TRUE(CheckGenerator(payload, expectedResult)); } -void TestDecimalRepresentation_FullPayloadWithoutZeros(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestDecimalRepresentation_FullPayloadWithoutZeros) { PayloadContents payload = GetDefaultPayload(); payload.commissioningFlow = CommissioningFlow::kCustom; @@ -130,20 +128,20 @@ void TestDecimalRepresentation_FullPayloadWithoutZeros(nlTestSuite * inSuite, vo std::string expectedResult = "64129507534536714526"; - NL_TEST_ASSERT(inSuite, CheckGenerator(payload, expectedResult)); + EXPECT_TRUE(CheckGenerator(payload, expectedResult)); } -void assertPayloadValues(nlTestSuite * inSuite, CHIP_ERROR actualError, CHIP_ERROR expectedError, const PayloadContents & payload, - uint32_t pinCode, const SetupDiscriminator & discriminator, uint16_t vendorID, uint16_t productID) +void assertPayloadValues(CHIP_ERROR actualError, CHIP_ERROR expectedError, const PayloadContents & payload, uint32_t pinCode, + const SetupDiscriminator & discriminator, uint16_t vendorID, uint16_t productID) { - NL_TEST_ASSERT(inSuite, actualError == expectedError); - NL_TEST_ASSERT(inSuite, payload.setUpPINCode == pinCode); - NL_TEST_ASSERT(inSuite, payload.discriminator == discriminator); - NL_TEST_ASSERT(inSuite, payload.vendorID == vendorID); - NL_TEST_ASSERT(inSuite, payload.productID == productID); + EXPECT_EQ(actualError, expectedError); + EXPECT_EQ(payload.setUpPINCode, pinCode); + EXPECT_EQ(payload.discriminator, discriminator); + EXPECT_EQ(payload.vendorID, vendorID); + EXPECT_EQ(payload.productID, productID); } -void TestGenerateAndParser_ManualSetupCodeWithLongDiscriminator(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestGenerateAndParser_ManualSetupCodeWithLongDiscriminator) { PayloadContents payload = GetDefaultPayload(); payload.discriminator.SetLongValue(0xa1f); @@ -152,15 +150,15 @@ void TestGenerateAndParser_ManualSetupCodeWithLongDiscriminator(nlTestSuite * in // Test short 11 digit code ManualSetupPayloadGenerator generator(payload); std::string result; - NL_TEST_ASSERT(inSuite, generator.payloadDecimalStringRepresentation(result) == CHIP_NO_ERROR); + EXPECT_EQ(generator.payloadDecimalStringRepresentation(result), CHIP_NO_ERROR); SetupPayload outPayload; CHIP_ERROR err = ManualSetupPayloadParser(result).populatePayload(outPayload); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); SetupDiscriminator discriminator; discriminator.SetShortValue(0xa); - assertPayloadValues(inSuite, err, CHIP_NO_ERROR, outPayload, payload.setUpPINCode, discriminator, payload.vendorID, + assertPayloadValues(err, CHIP_NO_ERROR, outPayload, payload.setUpPINCode, discriminator, payload.vendorID, payload.productID); } @@ -173,20 +171,20 @@ void TestGenerateAndParser_ManualSetupCodeWithLongDiscriminator(nlTestSuite * in // Test long 21 digit code ManualSetupPayloadGenerator generator(payload); std::string result; - NL_TEST_ASSERT(inSuite, generator.payloadDecimalStringRepresentation(result) == CHIP_NO_ERROR); + EXPECT_EQ(generator.payloadDecimalStringRepresentation(result), CHIP_NO_ERROR); SetupPayload outPayload; CHIP_ERROR err = ManualSetupPayloadParser(result).populatePayload(outPayload); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); SetupDiscriminator discriminator; discriminator.SetShortValue(0xb); - assertPayloadValues(inSuite, err, CHIP_NO_ERROR, outPayload, payload.setUpPINCode, discriminator, payload.vendorID, + assertPayloadValues(err, CHIP_NO_ERROR, outPayload, payload.setUpPINCode, discriminator, payload.vendorID, payload.productID); } } -void TestDecimalRepresentation_AllZeros(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestDecimalRepresentation_AllZeros) { PayloadContents payload; payload.setUpPINCode = 0; @@ -194,10 +192,10 @@ void TestDecimalRepresentation_AllZeros(nlTestSuite * inSuite, void * inContext) std::string expectedResult; - NL_TEST_ASSERT(inSuite, CheckGenerator(payload, expectedResult) == false); + EXPECT_EQ(CheckGenerator(payload, expectedResult), false); } -void TestDecimalRepresentation_AllOnes(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestDecimalRepresentation_AllOnes) { PayloadContents payload; payload.setUpPINCode = 0x7FFFFFF; @@ -208,7 +206,7 @@ void TestDecimalRepresentation_AllOnes(nlTestSuite * inSuite, void * inContext) std::string expectedResult = "76553581916553565535"; - NL_TEST_ASSERT(inSuite, CheckGenerator(payload, expectedResult, /*allowInvalidPayload*/ true)); + EXPECT_TRUE(CheckGenerator(payload, expectedResult, /*allowInvalidPayload*/ true)); } char ComputeCheckChar(const std::string & str) @@ -219,7 +217,7 @@ char ComputeCheckChar(const std::string & str) return Verhoeff10::ComputeCheckChar(copy.c_str()); } -void TestPayloadParser_FullPayload(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestPayloadParser_FullPayload) { SetupPayload payload; std::string decimalString; @@ -227,39 +225,39 @@ void TestPayloadParser_FullPayload(nlTestSuite * inSuite, void * inContext) decimalString = "63610875354536714526"; decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str()); CHIP_ERROR err = ManualSetupPayloadParser(decimalString).populatePayload(payload); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); SetupDiscriminator discriminator; discriminator.SetShortValue(0xa); - assertPayloadValues(inSuite, err, CHIP_NO_ERROR, payload, 123456780, discriminator, 45367, 14526); + assertPayloadValues(err, CHIP_NO_ERROR, payload, 123456780, discriminator, 45367, 14526); // The same thing, but with dashes separating digit groups. decimalString = "6361-0875-3545-3671-4526"; decimalString += ComputeCheckChar(decimalString); err = ManualSetupPayloadParser(decimalString).populatePayload(payload); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); discriminator.SetShortValue(0xa); - assertPayloadValues(inSuite, err, CHIP_NO_ERROR, payload, 123456780, discriminator, 45367, 14526); + assertPayloadValues(err, CHIP_NO_ERROR, payload, 123456780, discriminator, 45367, 14526); decimalString = "52927623630456200032"; decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str()); err = ManualSetupPayloadParser(decimalString).populatePayload(payload); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); discriminator.SetShortValue(0x5); - assertPayloadValues(inSuite, err, CHIP_NO_ERROR, payload, 38728284, discriminator, 4562, 32); + assertPayloadValues(err, CHIP_NO_ERROR, payload, 38728284, discriminator, 4562, 32); decimalString = "40000100000000100001"; decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str()); err = ManualSetupPayloadParser(decimalString).populatePayload(payload); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); discriminator.SetShortValue(0); - assertPayloadValues(inSuite, err, CHIP_NO_ERROR, payload, 1, discriminator, 1, 1); + assertPayloadValues(err, CHIP_NO_ERROR, payload, 1, discriminator, 1, 1); } -void TestGenerateAndParser_FullPayload(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestGenerateAndParser_FullPayload) { PayloadContents payload = GetDefaultPayload(); payload.vendorID = 1; @@ -268,37 +266,35 @@ void TestGenerateAndParser_FullPayload(nlTestSuite * inSuite, void * inContext) ManualSetupPayloadGenerator generator(payload); std::string result; - NL_TEST_ASSERT(inSuite, generator.payloadDecimalStringRepresentation(result) == CHIP_NO_ERROR); + EXPECT_EQ(generator.payloadDecimalStringRepresentation(result), CHIP_NO_ERROR); SetupPayload outPayload; CHIP_ERROR err = ManualSetupPayloadParser(result).populatePayload(outPayload); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); SetupDiscriminator discriminator; discriminator.SetShortValue(payload.discriminator.GetShortValue()); - assertPayloadValues(inSuite, err, CHIP_NO_ERROR, outPayload, payload.setUpPINCode, discriminator, payload.vendorID, - payload.productID); + assertPayloadValues(err, CHIP_NO_ERROR, outPayload, payload.setUpPINCode, discriminator, payload.vendorID, payload.productID); } -void TestGenerateAndParser_PartialPayload(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestGenerateAndParser_PartialPayload) { PayloadContents payload = GetDefaultPayload(); ManualSetupPayloadGenerator generator(payload); std::string result; - NL_TEST_ASSERT(inSuite, generator.payloadDecimalStringRepresentation(result) == CHIP_NO_ERROR); + EXPECT_EQ(generator.payloadDecimalStringRepresentation(result), CHIP_NO_ERROR); SetupPayload outPayload; CHIP_ERROR err = ManualSetupPayloadParser(result).populatePayload(outPayload); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); SetupDiscriminator discriminator; discriminator.SetShortValue(payload.discriminator.GetShortValue()); - assertPayloadValues(inSuite, err, CHIP_NO_ERROR, outPayload, payload.setUpPINCode, discriminator, payload.vendorID, - payload.productID); + assertPayloadValues(err, CHIP_NO_ERROR, outPayload, payload.setUpPINCode, discriminator, payload.vendorID, payload.productID); } -void TestPayloadParser_PartialPayload(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestPayloadParser_PartialPayload) { CHIP_ERROR err; SetupPayload payload; @@ -306,65 +302,65 @@ void TestPayloadParser_PartialPayload(nlTestSuite * inSuite, void * inContext) decimalString = "2361087535"; decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str()); - NL_TEST_ASSERT(inSuite, decimalString.length() == 11); + EXPECT_EQ(decimalString.length(), 11u); err = ManualSetupPayloadParser(decimalString).populatePayload(payload); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); SetupDiscriminator discriminator; discriminator.SetShortValue(0xa); - assertPayloadValues(inSuite, err, CHIP_NO_ERROR, payload, 123456780, discriminator, 0, 0); + assertPayloadValues(err, CHIP_NO_ERROR, payload, 123456780, discriminator, 0, 0); // The same thing, but with dashes separating digit groups. decimalString = "236-108753-5"; decimalString += ComputeCheckChar(decimalString); - NL_TEST_ASSERT(inSuite, decimalString.length() == 13); + EXPECT_EQ(decimalString.length(), 13u); err = ManualSetupPayloadParser(decimalString).populatePayload(payload); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); discriminator.SetShortValue(0xa); - assertPayloadValues(inSuite, err, CHIP_NO_ERROR, payload, 123456780, discriminator, 0, 0); + assertPayloadValues(err, CHIP_NO_ERROR, payload, 123456780, discriminator, 0, 0); decimalString = "0000010000"; decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str()); - NL_TEST_ASSERT(inSuite, decimalString.length() == 11); + EXPECT_EQ(decimalString.length(), 11u); err = ManualSetupPayloadParser(decimalString).populatePayload(payload); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); discriminator.SetShortValue(0); - assertPayloadValues(inSuite, err, CHIP_NO_ERROR, payload, 1, discriminator, 0, 0); + assertPayloadValues(err, CHIP_NO_ERROR, payload, 1, discriminator, 0, 0); decimalString = "63610875350000000000"; decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str()); - NL_TEST_ASSERT(inSuite, decimalString.length() == 21); + EXPECT_EQ(decimalString.length(), 21u); err = ManualSetupPayloadParser(decimalString).populatePayload(payload); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); discriminator.SetShortValue(0xa); - assertPayloadValues(inSuite, err, CHIP_NO_ERROR, payload, 123456780, discriminator, 0, 0); + assertPayloadValues(err, CHIP_NO_ERROR, payload, 123456780, discriminator, 0, 0); // no discriminator (= 0) decimalString = "0033407535"; decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str()); - NL_TEST_ASSERT(inSuite, decimalString.length() == 11); + EXPECT_EQ(decimalString.length(), 11u); err = ManualSetupPayloadParser(decimalString).populatePayload(payload); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // no vid (= 0) decimalString = "63610875350000014526"; decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str()); - NL_TEST_ASSERT(inSuite, decimalString.length() == 21); + EXPECT_EQ(decimalString.length(), 21u); err = ManualSetupPayloadParser(decimalString).populatePayload(payload); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); // no pid (= 0) decimalString = "63610875354536700000"; decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str()); - NL_TEST_ASSERT(inSuite, decimalString.length() == 21); + EXPECT_EQ(decimalString.length(), 21u); err = ManualSetupPayloadParser(decimalString).populatePayload(payload); - NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + EXPECT_EQ(err, CHIP_NO_ERROR); } -void TestShortCodeReadWrite(nlTestSuite * inSuite, void * context) +TEST(TestManualCode, TestShortCodeReadWrite) { PayloadContents inPayload = GetDefaultPayload(); @@ -378,10 +374,10 @@ void TestShortCodeReadWrite(nlTestSuite * inSuite, void * context) // Override the discriminator in the input payload with the short version, // since that's what we will produce. inPayload.discriminator.SetShortValue(inPayload.discriminator.GetShortValue()); - NL_TEST_ASSERT(inSuite, inPayload == outPayload); + EXPECT_TRUE(inPayload == outPayload); } -void TestLongCodeReadWrite(nlTestSuite * inSuite, void * context) +TEST(TestManualCode, TestLongCodeReadWrite) { PayloadContents inPayload = GetDefaultPayload(); inPayload.commissioningFlow = CommissioningFlow::kCustom; @@ -398,19 +394,17 @@ void TestLongCodeReadWrite(nlTestSuite * inSuite, void * context) // Override the discriminator in the input payload with the short version, // since that's what we will produce. inPayload.discriminator.SetShortValue(inPayload.discriminator.GetShortValue()); - NL_TEST_ASSERT(inSuite, inPayload == outPayload); + EXPECT_TRUE(inPayload == outPayload); } -void assertEmptyPayloadWithError(nlTestSuite * inSuite, CHIP_ERROR actualError, CHIP_ERROR expectedError, - const SetupPayload & payload) +void assertEmptyPayloadWithError(CHIP_ERROR actualError, CHIP_ERROR expectedError, const SetupPayload & payload) { - NL_TEST_ASSERT(inSuite, actualError == expectedError); - NL_TEST_ASSERT(inSuite, - payload.setUpPINCode == 0 && payload.discriminator.GetLongValue() == 0 && payload.productID == 0 && - payload.vendorID == 0); + EXPECT_EQ(actualError, expectedError); + EXPECT_TRUE(payload.setUpPINCode == 0 && payload.discriminator.GetLongValue() == 0 && payload.productID == 0 && + payload.vendorID == 0); } -void TestPayloadParser_InvalidEntry(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestPayloadParser_InvalidEntry) { SetupPayload payload; std::string decimalString; @@ -418,50 +412,50 @@ void TestPayloadParser_InvalidEntry(nlTestSuite * inSuite, void * inContext) // Empty input decimalString = ""; decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str()); - assertEmptyPayloadWithError(inSuite, ManualSetupPayloadParser(decimalString).populatePayload(payload), - CHIP_ERROR_INVALID_STRING_LENGTH, payload); + assertEmptyPayloadWithError(ManualSetupPayloadParser(decimalString).populatePayload(payload), CHIP_ERROR_INVALID_STRING_LENGTH, + payload); // Invalid character decimalString = "24184.2196"; decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str()); - assertEmptyPayloadWithError(inSuite, ManualSetupPayloadParser(decimalString).populatePayload(payload), - CHIP_ERROR_INVALID_INTEGER_VALUE, payload); + assertEmptyPayloadWithError(ManualSetupPayloadParser(decimalString).populatePayload(payload), CHIP_ERROR_INVALID_INTEGER_VALUE, + payload); // too short decimalString = "2456"; decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str()); - assertEmptyPayloadWithError(inSuite, ManualSetupPayloadParser(decimalString).populatePayload(payload), - CHIP_ERROR_INVALID_STRING_LENGTH, payload); + assertEmptyPayloadWithError(ManualSetupPayloadParser(decimalString).populatePayload(payload), CHIP_ERROR_INVALID_STRING_LENGTH, + payload); // too long for long code decimalString = "123456789123456785671"; decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str()); - assertEmptyPayloadWithError(inSuite, ManualSetupPayloadParser(decimalString).populatePayload(payload), - CHIP_ERROR_INVALID_STRING_LENGTH, payload); + assertEmptyPayloadWithError(ManualSetupPayloadParser(decimalString).populatePayload(payload), CHIP_ERROR_INVALID_STRING_LENGTH, + payload); // too long for short code decimalString = "12749875380"; decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str()); - assertEmptyPayloadWithError(inSuite, ManualSetupPayloadParser(decimalString).populatePayload(payload), - CHIP_ERROR_INVALID_STRING_LENGTH, payload); + assertEmptyPayloadWithError(ManualSetupPayloadParser(decimalString).populatePayload(payload), CHIP_ERROR_INVALID_STRING_LENGTH, + payload); // bit to indicate short code but long code length decimalString = "23456789123456785610"; decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str()); - assertEmptyPayloadWithError(inSuite, ManualSetupPayloadParser(decimalString).populatePayload(payload), - CHIP_ERROR_INVALID_STRING_LENGTH, payload); + assertEmptyPayloadWithError(ManualSetupPayloadParser(decimalString).populatePayload(payload), CHIP_ERROR_INVALID_STRING_LENGTH, + payload); // no pin code (= 0) decimalString = "2327680000"; decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str()); - assertEmptyPayloadWithError(inSuite, ManualSetupPayloadParser(decimalString).populatePayload(payload), - CHIP_ERROR_INVALID_ARGUMENT, payload); + assertEmptyPayloadWithError(ManualSetupPayloadParser(decimalString).populatePayload(payload), CHIP_ERROR_INVALID_ARGUMENT, + payload); // wrong check digit decimalString = "02684354589"; - assertEmptyPayloadWithError(inSuite, ManualSetupPayloadParser(decimalString).populatePayload(payload), - CHIP_ERROR_INTEGRITY_CHECK_FAILED, payload); + assertEmptyPayloadWithError(ManualSetupPayloadParser(decimalString).populatePayload(payload), CHIP_ERROR_INTEGRITY_CHECK_FAILED, + payload); } -void TestCheckDecimalStringValidity(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestCheckDecimalStringValidity) { std::string outReprensation; char checkDigit; @@ -469,172 +463,106 @@ void TestCheckDecimalStringValidity(nlTestSuite * inSuite, void * inContext) std::string decimalString; representationWithoutCheckDigit = ""; - NL_TEST_ASSERT(inSuite, - ManualSetupPayloadParser::CheckDecimalStringValidity(representationWithoutCheckDigit, outReprensation) == - CHIP_ERROR_INVALID_STRING_LENGTH); + EXPECT_EQ(ManualSetupPayloadParser::CheckDecimalStringValidity(representationWithoutCheckDigit, outReprensation), + CHIP_ERROR_INVALID_STRING_LENGTH); representationWithoutCheckDigit = "1"; - NL_TEST_ASSERT(inSuite, - ManualSetupPayloadParser::CheckDecimalStringValidity(representationWithoutCheckDigit, outReprensation) == - CHIP_ERROR_INVALID_STRING_LENGTH); + EXPECT_EQ(ManualSetupPayloadParser::CheckDecimalStringValidity(representationWithoutCheckDigit, outReprensation), + CHIP_ERROR_INVALID_STRING_LENGTH); representationWithoutCheckDigit = "10109"; checkDigit = Verhoeff10::ComputeCheckChar(representationWithoutCheckDigit.c_str()); decimalString = representationWithoutCheckDigit + checkDigit; - NL_TEST_ASSERT(inSuite, ManualSetupPayloadParser::CheckDecimalStringValidity(decimalString, outReprensation) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, outReprensation == representationWithoutCheckDigit); + EXPECT_EQ(ManualSetupPayloadParser::CheckDecimalStringValidity(decimalString, outReprensation), CHIP_NO_ERROR); + EXPECT_EQ(outReprensation, representationWithoutCheckDigit); representationWithoutCheckDigit = "0000"; checkDigit = Verhoeff10::ComputeCheckChar(representationWithoutCheckDigit.c_str()); decimalString = representationWithoutCheckDigit + checkDigit; - NL_TEST_ASSERT(inSuite, ManualSetupPayloadParser::CheckDecimalStringValidity(decimalString, outReprensation) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, outReprensation == representationWithoutCheckDigit); + EXPECT_EQ(ManualSetupPayloadParser::CheckDecimalStringValidity(decimalString, outReprensation), CHIP_NO_ERROR); + EXPECT_EQ(outReprensation, representationWithoutCheckDigit); } -void TestCheckCodeLengthValidity(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestCheckCodeLengthValidity) { - NL_TEST_ASSERT(inSuite, ManualSetupPayloadParser::CheckCodeLengthValidity("01234567890123456789", true) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, ManualSetupPayloadParser::CheckCodeLengthValidity("0123456789", false) == CHIP_NO_ERROR); - - NL_TEST_ASSERT(inSuite, - ManualSetupPayloadParser::CheckCodeLengthValidity("01234567891", false) == CHIP_ERROR_INVALID_STRING_LENGTH); - NL_TEST_ASSERT(inSuite, - ManualSetupPayloadParser::CheckCodeLengthValidity("012345678", false) == CHIP_ERROR_INVALID_STRING_LENGTH); - NL_TEST_ASSERT(inSuite, - ManualSetupPayloadParser::CheckCodeLengthValidity("012345678901234567891", true) == - CHIP_ERROR_INVALID_STRING_LENGTH); - NL_TEST_ASSERT(inSuite, - ManualSetupPayloadParser::CheckCodeLengthValidity("0123456789012345678", true) == - CHIP_ERROR_INVALID_STRING_LENGTH); + EXPECT_EQ(ManualSetupPayloadParser::CheckCodeLengthValidity("01234567890123456789", true), CHIP_NO_ERROR); + EXPECT_EQ(ManualSetupPayloadParser::CheckCodeLengthValidity("0123456789", false), CHIP_NO_ERROR); + + EXPECT_EQ(ManualSetupPayloadParser::CheckCodeLengthValidity("01234567891", false), CHIP_ERROR_INVALID_STRING_LENGTH); + EXPECT_EQ(ManualSetupPayloadParser::CheckCodeLengthValidity("012345678", false), CHIP_ERROR_INVALID_STRING_LENGTH); + EXPECT_EQ(ManualSetupPayloadParser::CheckCodeLengthValidity("012345678901234567891", true), CHIP_ERROR_INVALID_STRING_LENGTH); + EXPECT_EQ(ManualSetupPayloadParser::CheckCodeLengthValidity("0123456789012345678", true), CHIP_ERROR_INVALID_STRING_LENGTH); } -void TestDecimalStringToNumber(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestDecimalStringToNumber) { uint32_t number; - NL_TEST_ASSERT(inSuite, ManualSetupPayloadParser::ToNumber("12345", number) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, number == 12345); + EXPECT_EQ(ManualSetupPayloadParser::ToNumber("12345", number), CHIP_NO_ERROR); + EXPECT_EQ(number, 12345u); - NL_TEST_ASSERT(inSuite, ManualSetupPayloadParser::ToNumber("01234567890", number) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, number == 1234567890); + EXPECT_EQ(ManualSetupPayloadParser::ToNumber("01234567890", number), CHIP_NO_ERROR); + EXPECT_EQ(number, 1234567890u); - NL_TEST_ASSERT(inSuite, ManualSetupPayloadParser::ToNumber("00000001", number) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, number == 1); + EXPECT_EQ(ManualSetupPayloadParser::ToNumber("00000001", number), CHIP_NO_ERROR); + EXPECT_TRUE(number); - NL_TEST_ASSERT(inSuite, ManualSetupPayloadParser::ToNumber("0", number) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, number == 0); + EXPECT_EQ(ManualSetupPayloadParser::ToNumber("0", number), CHIP_NO_ERROR); + EXPECT_FALSE(number); - NL_TEST_ASSERT(inSuite, ManualSetupPayloadParser::ToNumber("012345.123456789", number) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, ManualSetupPayloadParser::ToNumber("/", number) == CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(ManualSetupPayloadParser::ToNumber("012345.123456789", number), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(ManualSetupPayloadParser::ToNumber("/", number), CHIP_ERROR_INVALID_INTEGER_VALUE); } -void TestReadCharsFromDecimalString(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestReadCharsFromDecimalString) { uint32_t number; size_t index = 3; - NL_TEST_ASSERT(inSuite, ManualSetupPayloadParser::ReadDigitsFromDecimalString("12345", index, number, 2) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, number == 45); + EXPECT_EQ(ManualSetupPayloadParser::ReadDigitsFromDecimalString("12345", index, number, 2), CHIP_NO_ERROR); + EXPECT_EQ(number, 45u); index = 2; - NL_TEST_ASSERT(inSuite, - ManualSetupPayloadParser::ReadDigitsFromDecimalString("6256276377282", index, number, 7) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, number == 5627637); + EXPECT_EQ(ManualSetupPayloadParser::ReadDigitsFromDecimalString("6256276377282", index, number, 7), CHIP_NO_ERROR); + EXPECT_EQ(number, 5627637u); index = 0; - NL_TEST_ASSERT(inSuite, ManualSetupPayloadParser::ReadDigitsFromDecimalString("10", index, number, 2) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, number == 10); + EXPECT_EQ(ManualSetupPayloadParser::ReadDigitsFromDecimalString("10", index, number, 2), CHIP_NO_ERROR); + EXPECT_EQ(number, 10u); index = 0; - NL_TEST_ASSERT(inSuite, ManualSetupPayloadParser::ReadDigitsFromDecimalString("01", index, number, 2) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, number == 1); + EXPECT_EQ(ManualSetupPayloadParser::ReadDigitsFromDecimalString("01", index, number, 2), CHIP_NO_ERROR); + EXPECT_TRUE(number); index = 1; - NL_TEST_ASSERT(inSuite, ManualSetupPayloadParser::ReadDigitsFromDecimalString("11", index, number, 1) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, number == 1); + EXPECT_EQ(ManualSetupPayloadParser::ReadDigitsFromDecimalString("11", index, number, 1), CHIP_NO_ERROR); + EXPECT_TRUE(number); index = 2; - NL_TEST_ASSERT(inSuite, ManualSetupPayloadParser::ReadDigitsFromDecimalString("100001", index, number, 3) == CHIP_NO_ERROR); + EXPECT_EQ(ManualSetupPayloadParser::ReadDigitsFromDecimalString("100001", index, number, 3), CHIP_NO_ERROR); index = 1; - NL_TEST_ASSERT(inSuite, - ManualSetupPayloadParser::ReadDigitsFromDecimalString("12345", index, number, 5) == - CHIP_ERROR_INVALID_STRING_LENGTH); - NL_TEST_ASSERT( - inSuite, ManualSetupPayloadParser::ReadDigitsFromDecimalString("12", index, number, 5) == CHIP_ERROR_INVALID_STRING_LENGTH); + EXPECT_EQ(ManualSetupPayloadParser::ReadDigitsFromDecimalString("12345", index, number, 5), CHIP_ERROR_INVALID_STRING_LENGTH); + EXPECT_EQ(ManualSetupPayloadParser::ReadDigitsFromDecimalString("12", index, number, 5), CHIP_ERROR_INVALID_STRING_LENGTH); index = 200; - NL_TEST_ASSERT(inSuite, - ManualSetupPayloadParser::ReadDigitsFromDecimalString("6256276377282", index, number, 1) == - CHIP_ERROR_INVALID_STRING_LENGTH); + EXPECT_EQ(ManualSetupPayloadParser::ReadDigitsFromDecimalString("6256276377282", index, number, 1), + CHIP_ERROR_INVALID_STRING_LENGTH); } -void TestShortCodeCharLengths(nlTestSuite * inSuite, void * inContext) +TEST(TestManualCode, TestShortCodeCharLengths) { size_t numBits = 1 + kSetupPINCodeFieldLengthInBits + kManualSetupDiscriminatorFieldLengthInBits; size_t manualSetupShortCodeCharLength = static_cast(ceil(log10(pow(2, numBits)))); - NL_TEST_ASSERT(inSuite, manualSetupShortCodeCharLength == kManualSetupShortCodeCharLength); + EXPECT_EQ(manualSetupShortCodeCharLength, size_t(kManualSetupShortCodeCharLength)); size_t manualSetupVendorIdCharLength = static_cast(ceil(log10(pow(2, kVendorIDFieldLengthInBits)))); - NL_TEST_ASSERT(inSuite, manualSetupVendorIdCharLength == kManualSetupVendorIdCharLength); + EXPECT_EQ(manualSetupVendorIdCharLength, size_t(kManualSetupVendorIdCharLength)); size_t manualSetupProductIdCharLength = static_cast(ceil(log10(pow(2, kProductIDFieldLengthInBits)))); - NL_TEST_ASSERT(inSuite, manualSetupProductIdCharLength == kManualSetupProductIdCharLength); + EXPECT_EQ(manualSetupProductIdCharLength, size_t(kManualSetupProductIdCharLength)); size_t manualSetupLongCodeCharLength = kManualSetupShortCodeCharLength + kManualSetupVendorIdCharLength + kManualSetupProductIdCharLength; - NL_TEST_ASSERT(inSuite, manualSetupLongCodeCharLength == kManualSetupLongCodeCharLength); + EXPECT_EQ(manualSetupLongCodeCharLength, size_t(kManualSetupLongCodeCharLength)); } -/** - * Test Suite that lists all the Test functions. - */ -// clang-format off -const nlTest sTests[] = -{ - NL_TEST_DEF("Generate Decimal Representation from Partial Payload", TestDecimalRepresentation_PartialPayload), - NL_TEST_DEF("Generate Decimal Representation from Partial Payload (Custom Flow)", TestDecimalRepresentation_PartialPayload_RequiresCustomFlow), - NL_TEST_DEF("Generate Decimal Representation from Full Payload with Zeros", TestDecimalRepresentation_FullPayloadWithZeros), - NL_TEST_DEF("Decimal Representation from Full Payload without Zeros", TestDecimalRepresentation_FullPayloadWithoutZeros_DoesNotRequireCustomFlow), - NL_TEST_DEF("Decimal Representation from Full Payload without Zeros (Custom Flow)", TestDecimalRepresentation_FullPayloadWithoutZeros), - NL_TEST_DEF("Test 12 bit discriminator for manual setup code", TestGenerateAndParser_ManualSetupCodeWithLongDiscriminator), - NL_TEST_DEF("Test Decimal Representation - All Zeros", TestDecimalRepresentation_AllZeros), - NL_TEST_DEF("Test Decimal Representation - All Ones", TestDecimalRepresentation_AllOnes), - NL_TEST_DEF("Parse from Partial Payload", TestPayloadParser_PartialPayload), - NL_TEST_DEF("Parse from Full Payload", TestPayloadParser_FullPayload), - NL_TEST_DEF("Test Invalid Entry To QR Code Parser", TestPayloadParser_InvalidEntry), - NL_TEST_DEF("Test Short Read Write", TestShortCodeReadWrite), - NL_TEST_DEF("Test Long Read Write", TestLongCodeReadWrite), - NL_TEST_DEF("Check Decimal String Validity", TestCheckDecimalStringValidity), - NL_TEST_DEF("Check QR Code Length Validity", TestCheckCodeLengthValidity), - NL_TEST_DEF("Test Decimal String to Number", TestDecimalStringToNumber), - NL_TEST_DEF("Test Short Code Character Lengths", TestShortCodeCharLengths), - NL_TEST_DEF("Test Read Characters from Decimal String", TestReadCharsFromDecimalString), - NL_TEST_DEF("Generate Full Payload and Parse it", TestGenerateAndParser_FullPayload), - NL_TEST_DEF("Generate Partial Payload and Parse it", TestGenerateAndParser_PartialPayload), - - NL_TEST_SENTINEL() -}; -// clang-format on - } // namespace - -/** - * Main - */ -int TestManualSetupCode() -{ - // clang-format off - nlTestSuite theSuite = - { - "chip-manual-code-general-Tests", - &sTests[0], - nullptr, - nullptr - }; - // 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(TestManualSetupCode); diff --git a/src/setup_payload/tests/TestQRCode.cpp b/src/setup_payload/tests/TestQRCode.cpp index 7bedf282ec82e0..1ec508578dec30 100644 --- a/src/setup_payload/tests/TestQRCode.cpp +++ b/src/setup_payload/tests/TestQRCode.cpp @@ -25,62 +25,60 @@ #include "TestHelpers.h" #include -#include +#include #include -#include -#include using namespace chip; using namespace std; namespace { -void TestRendezvousFlags(nlTestSuite * inSuite, void * inContext) +TEST(TestQRCode, TestRendezvousFlags) { SetupPayload inPayload = GetDefaultPayload(); // Not having a value in rendezvousInformation is not allowed for a QR code. inPayload.rendezvousInformation.SetValue(RendezvousInformationFlag::kNone); - NL_TEST_ASSERT(inSuite, CheckWriteRead(inPayload)); + EXPECT_TRUE(CheckWriteRead(inPayload)); inPayload.rendezvousInformation.SetValue(RendezvousInformationFlag::kSoftAP); - NL_TEST_ASSERT(inSuite, CheckWriteRead(inPayload)); + EXPECT_TRUE(CheckWriteRead(inPayload)); inPayload.rendezvousInformation.SetValue(RendezvousInformationFlag::kBLE); - NL_TEST_ASSERT(inSuite, CheckWriteRead(inPayload)); + EXPECT_TRUE(CheckWriteRead(inPayload)); inPayload.rendezvousInformation.SetValue(RendezvousInformationFlag::kOnNetwork); - NL_TEST_ASSERT(inSuite, CheckWriteRead(inPayload)); + EXPECT_TRUE(CheckWriteRead(inPayload)); inPayload.rendezvousInformation.SetValue( RendezvousInformationFlags(RendezvousInformationFlag::kSoftAP, RendezvousInformationFlag::kOnNetwork)); - NL_TEST_ASSERT(inSuite, CheckWriteRead(inPayload)); + EXPECT_TRUE(CheckWriteRead(inPayload)); inPayload.rendezvousInformation.SetValue( RendezvousInformationFlags(RendezvousInformationFlag::kBLE, RendezvousInformationFlag::kOnNetwork)); - NL_TEST_ASSERT(inSuite, CheckWriteRead(inPayload)); + EXPECT_TRUE(CheckWriteRead(inPayload)); inPayload.rendezvousInformation.SetValue(RendezvousInformationFlags( RendezvousInformationFlag::kBLE, RendezvousInformationFlag::kSoftAP, RendezvousInformationFlag::kOnNetwork)); - NL_TEST_ASSERT(inSuite, CheckWriteRead(inPayload)); + EXPECT_TRUE(CheckWriteRead(inPayload)); } -void TestCommissioningFlow(nlTestSuite * inSuite, void * inContext) +TEST(TestQRCode, TestCommissioningFlow) { SetupPayload inPayload = GetDefaultPayload(); inPayload.commissioningFlow = CommissioningFlow::kStandard; - NL_TEST_ASSERT(inSuite, CheckWriteRead(inPayload)); + EXPECT_TRUE(CheckWriteRead(inPayload)); inPayload.commissioningFlow = CommissioningFlow::kUserActionRequired; - NL_TEST_ASSERT(inSuite, CheckWriteRead(inPayload)); + EXPECT_TRUE(CheckWriteRead(inPayload)); inPayload.commissioningFlow = CommissioningFlow::kCustom; - NL_TEST_ASSERT(inSuite, CheckWriteRead(inPayload)); + EXPECT_TRUE(CheckWriteRead(inPayload)); } -void TestMaximumValues(nlTestSuite * inSuite, void * inContext) +TEST(TestQRCode, TestMaximumValues) { SetupPayload inPayload = GetDefaultPayload(); @@ -93,18 +91,18 @@ void TestMaximumValues(nlTestSuite * inSuite, void * inContext) inPayload.discriminator.SetLongValue(static_cast((1 << kPayloadDiscriminatorFieldLengthInBits) - 1)); inPayload.setUpPINCode = static_cast((1 << kSetupPINCodeFieldLengthInBits) - 1); - NL_TEST_ASSERT(inSuite, CheckWriteRead(inPayload, /* allowInvalidPayload */ true)); + EXPECT_TRUE(CheckWriteRead(inPayload, /* allowInvalidPayload */ true)); } -void TestPayloadByteArrayRep(nlTestSuite * inSuite, void * inContext) +TEST(TestQRCode, TestPayloadByteArrayRep) { SetupPayload payload = GetDefaultPayload(); string expected = " 0000 000000000000000100000000000 000010000000 00000001 00 0000000000000001 0000000000001100 000"; - NL_TEST_ASSERT(inSuite, CompareBinary(payload, expected)); + EXPECT_TRUE(CompareBinary(payload, expected)); } -void TestPayloadBase38Rep(nlTestSuite * inSuite, void * inContext) +TEST(TestQRCode, TestPayloadBase38Rep) { SetupPayload payload = GetDefaultPayload(); @@ -112,12 +110,12 @@ void TestPayloadBase38Rep(nlTestSuite * inSuite, void * inContext) string result; CHIP_ERROR err = generator.payloadBase38Representation(result); bool didSucceed = err == CHIP_NO_ERROR; - NL_TEST_ASSERT(inSuite, didSucceed == true); + EXPECT_EQ(didSucceed, true); - NL_TEST_ASSERT(inSuite, result == kDefaultPayloadQRCode); + EXPECT_EQ(result, kDefaultPayloadQRCode); } -void TestBase38(nlTestSuite * inSuite, void * inContext) +TEST(TestQRCode, TestBase38) { uint8_t input[3] = { 10, 10, 10 }; char encodedBuf[64]; @@ -126,181 +124,181 @@ void TestBase38(nlTestSuite * inSuite, void * inContext) // basic stuff base38Encode(inputSpan.SubSpan(0, 0), encodedSpan); - NL_TEST_ASSERT(inSuite, strlen(encodedBuf) == 0); + EXPECT_EQ(strlen(encodedBuf), 0u); encodedSpan = MutableCharSpan(encodedBuf); base38Encode(inputSpan.SubSpan(0, 1), encodedSpan); - NL_TEST_ASSERT(inSuite, strcmp(encodedBuf, "A0") == 0); + EXPECT_STREQ(encodedBuf, "A0"); encodedSpan = MutableCharSpan(encodedBuf); base38Encode(inputSpan.SubSpan(0, 2), encodedSpan); - NL_TEST_ASSERT(inSuite, strcmp(encodedBuf, "OT10") == 0); + EXPECT_STREQ(encodedBuf, "OT10"); encodedSpan = MutableCharSpan(encodedBuf); base38Encode(inputSpan, encodedSpan); - NL_TEST_ASSERT(inSuite, strcmp(encodedBuf, "-N.B0") == 0); + EXPECT_STREQ(encodedBuf, "-N.B0"); // test null termination of output buffer encodedSpan = MutableCharSpan(encodedBuf); MutableCharSpan subSpan = encodedSpan.SubSpan(0, 2); - NL_TEST_ASSERT(inSuite, base38Encode(inputSpan.SubSpan(0, 1), subSpan) == CHIP_ERROR_BUFFER_TOO_SMALL); + EXPECT_EQ(base38Encode(inputSpan.SubSpan(0, 1), subSpan), CHIP_ERROR_BUFFER_TOO_SMALL); // Force no nulls in output buffer memset(encodedSpan.data(), '?', encodedSpan.size()); subSpan = encodedSpan.SubSpan(0, 3); base38Encode(inputSpan.SubSpan(0, 1), subSpan); size_t encodedLen = strnlen(encodedSpan.data(), ArraySize(encodedBuf)); - NL_TEST_ASSERT(inSuite, encodedLen == strlen("A0")); - NL_TEST_ASSERT(inSuite, strcmp(encodedBuf, "A0") == 0); + EXPECT_EQ(encodedLen, strlen("A0")); + EXPECT_STREQ(encodedBuf, "A0"); // passing empty parameters MutableCharSpan emptySpan; encodedSpan = MutableCharSpan(encodedBuf); - NL_TEST_ASSERT(inSuite, base38Encode(inputSpan, emptySpan) == CHIP_ERROR_BUFFER_TOO_SMALL); + EXPECT_EQ(base38Encode(inputSpan, emptySpan), CHIP_ERROR_BUFFER_TOO_SMALL); base38Encode(MutableByteSpan(), encodedSpan); - NL_TEST_ASSERT(inSuite, strcmp(encodedBuf, "") == 0); - NL_TEST_ASSERT(inSuite, base38Encode(MutableByteSpan(), emptySpan) == CHIP_ERROR_BUFFER_TOO_SMALL); + EXPECT_STREQ(encodedBuf, ""); + EXPECT_EQ(base38Encode(MutableByteSpan(), emptySpan), CHIP_ERROR_BUFFER_TOO_SMALL); // test single odd byte corner conditions encodedSpan = MutableCharSpan(encodedBuf); input[2] = 0; base38Encode(inputSpan, encodedSpan); - NL_TEST_ASSERT(inSuite, strcmp(encodedBuf, "OT100") == 0); + EXPECT_STREQ(encodedBuf, "OT100"); input[2] = 40; encodedSpan = MutableCharSpan(encodedBuf); base38Encode(inputSpan, encodedSpan); - NL_TEST_ASSERT(inSuite, strcmp(encodedBuf, "Y6V91") == 0); + EXPECT_STREQ(encodedBuf, "Y6V91"); input[2] = 41; encodedSpan = MutableCharSpan(encodedBuf); base38Encode(inputSpan, encodedSpan); - NL_TEST_ASSERT(inSuite, strcmp(encodedBuf, "KL0B1") == 0); + EXPECT_STREQ(encodedBuf, "KL0B1"); input[2] = 255; encodedSpan = MutableCharSpan(encodedBuf); base38Encode(inputSpan, encodedSpan); - NL_TEST_ASSERT(inSuite, strcmp(encodedBuf, "Q-M08") == 0); + EXPECT_STREQ(encodedBuf, "Q-M08"); // verify chunks of 1,2 and 3 bytes result in fixed-length strings padded with '0' // for 1 byte we need always 2 characters input[0] = 35; encodedSpan = MutableCharSpan(encodedBuf); base38Encode(inputSpan.SubSpan(0, 1), encodedSpan); - NL_TEST_ASSERT(inSuite, strcmp(encodedBuf, "Z0") == 0); + EXPECT_STREQ(encodedBuf, "Z0"); // for 2 bytes we need always 4 characters input[0] = 255; input[1] = 0; encodedSpan = MutableCharSpan(encodedBuf); base38Encode(inputSpan.SubSpan(0, 2), encodedSpan); - NL_TEST_ASSERT(inSuite, strcmp(encodedBuf, "R600") == 0); + EXPECT_STREQ(encodedBuf, "R600"); // for 3 bytes we need always 5 characters input[0] = 46; input[1] = 0; input[2] = 0; encodedSpan = MutableCharSpan(encodedBuf); base38Encode(inputSpan, encodedSpan); - NL_TEST_ASSERT(inSuite, strcmp(encodedBuf, "81000") == 0); + EXPECT_STREQ(encodedBuf, "81000"); // verify maximum available values for each chunk size to check selecting proper characters number // for 1 byte we need 2 characters input[0] = 255; encodedSpan = MutableCharSpan(encodedBuf); base38Encode(inputSpan.SubSpan(0, 1), encodedSpan); - NL_TEST_ASSERT(inSuite, strcmp(encodedBuf, "R6") == 0); + EXPECT_STREQ(encodedBuf, "R6"); // for 2 bytes we need 4 characters input[0] = 255; input[1] = 255; encodedSpan = MutableCharSpan(encodedBuf); base38Encode(inputSpan.SubSpan(0, 2), encodedSpan); - NL_TEST_ASSERT(inSuite, strcmp(encodedBuf, "NE71") == 0); + EXPECT_STREQ(encodedBuf, "NE71"); // for 3 bytes we need 5 characters input[0] = 255; input[1] = 255; input[2] = 255; encodedSpan = MutableCharSpan(encodedBuf); base38Encode(inputSpan, encodedSpan); - NL_TEST_ASSERT(inSuite, strcmp(encodedBuf, "PLS18") == 0); + EXPECT_STREQ(encodedBuf, "PLS18"); // fun with strings encodedSpan = MutableCharSpan(encodedBuf); base38Encode(ByteSpan((uint8_t *) "Hello World!", sizeof("Hello World!") - 1), encodedSpan); - NL_TEST_ASSERT(inSuite, strcmp(encodedBuf, "KKHF3W2S013OPM3EJX11") == 0); + EXPECT_STREQ(encodedBuf, "KKHF3W2S013OPM3EJX11"); vector decoded = vector(); - NL_TEST_ASSERT(inSuite, base38Decode("KKHF3W2S013OPM3EJX11", decoded) == CHIP_NO_ERROR); + EXPECT_EQ(base38Decode("KKHF3W2S013OPM3EJX11", decoded), CHIP_NO_ERROR); string hello_world; for (uint8_t b : decoded) { hello_world += static_cast(b); } - NL_TEST_ASSERT(inSuite, hello_world == "Hello World!"); + EXPECT_EQ(hello_world, "Hello World!"); // short input - NL_TEST_ASSERT(inSuite, base38Decode("A0", decoded) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, decoded.size() == 1); - NL_TEST_ASSERT(inSuite, decoded[0] == 10); + EXPECT_EQ(base38Decode("A0", decoded), CHIP_NO_ERROR); + EXPECT_TRUE(decoded.size()); + EXPECT_EQ(decoded[0], 10u); // empty == empty - NL_TEST_ASSERT(inSuite, base38Decode("", decoded) == CHIP_NO_ERROR); - NL_TEST_ASSERT(inSuite, decoded.empty()); + EXPECT_EQ(base38Decode("", decoded), CHIP_NO_ERROR); + EXPECT_TRUE(decoded.empty()); // test invalid characters - NL_TEST_ASSERT(inSuite, base38Decode("0\001", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode("\0010", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode("[0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode("0[", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode(" 0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode("!0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode("\"0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode("#0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode("$0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode("%0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode("&0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode("'0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode("(0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode(")0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode("*0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode("+0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode(",0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode(";0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode("<0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode("=0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode(">0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); - NL_TEST_ASSERT(inSuite, base38Decode("@0", decoded) == CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("0\001", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("\0010", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("[0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("0[", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode(" 0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("!0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("\"0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("#0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("$0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("%0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("&0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("'0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("(0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode(")0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("*0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("+0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode(",0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode(";0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("<0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("=0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode(">0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); + EXPECT_EQ(base38Decode("@0", decoded), CHIP_ERROR_INVALID_INTEGER_VALUE); // test strings that encode maximum values - NL_TEST_ASSERT(inSuite, base38Decode("R6", decoded) == CHIP_NO_ERROR); // this is 0xFF - NL_TEST_ASSERT(inSuite, decoded == std::vector({ 255 })); - NL_TEST_ASSERT(inSuite, base38Decode("S6", decoded) == CHIP_ERROR_INVALID_ARGUMENT); // trying to encode 0xFF + 1 in 2 chars - NL_TEST_ASSERT(inSuite, base38Decode("S600", decoded) == CHIP_NO_ERROR); // this is 0xFF + 1, needs 4 chars - NL_TEST_ASSERT(inSuite, decoded == std::vector({ 0, 1 })); - NL_TEST_ASSERT(inSuite, base38Decode("NE71", decoded) == CHIP_NO_ERROR); // this is 0xFFFF - NL_TEST_ASSERT(inSuite, decoded == std::vector({ 255, 255 })); - NL_TEST_ASSERT(inSuite, base38Decode("OE71", decoded) == CHIP_ERROR_INVALID_ARGUMENT); // trying to encode 0xFFFF + 1 in 4 chars - NL_TEST_ASSERT(inSuite, base38Decode("OE710", decoded) == CHIP_NO_ERROR); // this is 0xFFFF + 1, needs 5 chars - NL_TEST_ASSERT(inSuite, decoded == std::vector({ 0, 0, 1 })); - NL_TEST_ASSERT(inSuite, base38Decode("PLS18", decoded) == CHIP_NO_ERROR); // this is 0xFFFFFF - NL_TEST_ASSERT(inSuite, decoded == std::vector({ 255, 255, 255 })); - NL_TEST_ASSERT(inSuite, base38Decode("QLS18", decoded) == CHIP_ERROR_INVALID_ARGUMENT); // trying to encode 0xFFFFFF + 1 + EXPECT_EQ(base38Decode("R6", decoded), CHIP_NO_ERROR); // this is 0xFF + EXPECT_EQ(decoded, std::vector({ 255 })); + EXPECT_EQ(base38Decode("S6", decoded), CHIP_ERROR_INVALID_ARGUMENT); // trying to encode 0xFF + 1 in 2 chars + EXPECT_EQ(base38Decode("S600", decoded), CHIP_NO_ERROR); // this is 0xFF + 1, needs 4 chars + EXPECT_EQ(decoded, std::vector({ 0, 1 })); + EXPECT_EQ(base38Decode("NE71", decoded), CHIP_NO_ERROR); // this is 0xFFFF + EXPECT_EQ(decoded, std::vector({ 255, 255 })); + EXPECT_EQ(base38Decode("OE71", decoded), CHIP_ERROR_INVALID_ARGUMENT); // trying to encode 0xFFFF + 1 in 4 chars + EXPECT_EQ(base38Decode("OE710", decoded), CHIP_NO_ERROR); // this is 0xFFFF + 1, needs 5 chars + EXPECT_EQ(decoded, std::vector({ 0, 0, 1 })); + EXPECT_EQ(base38Decode("PLS18", decoded), CHIP_NO_ERROR); // this is 0xFFFFFF + EXPECT_EQ(decoded, std::vector({ 255, 255, 255 })); + EXPECT_EQ(base38Decode("QLS18", decoded), CHIP_ERROR_INVALID_ARGUMENT); // trying to encode 0xFFFFFF + 1 } -void TestBitsetLen(nlTestSuite * inSuite, void * inContext) +TEST(TestQRCode, TestBitsetLen) { - NL_TEST_ASSERT(inSuite, kTotalPayloadDataSizeInBits % 8 == 0); + EXPECT_FALSE(kTotalPayloadDataSizeInBits % 8); } -void TestSetupPayloadVerify(nlTestSuite * inSuite, void * inContext) +TEST(TestQRCode, TestSetupPayloadVerify) { SetupPayload payload = GetDefaultPayload(); - NL_TEST_ASSERT(inSuite, payload.isValidQRCodePayload() == true); + EXPECT_EQ(payload.isValidQRCodePayload(), true); // test invalid commissioning flow SetupPayload test_payload = payload; test_payload.commissioningFlow = CommissioningFlow::kCustom; - NL_TEST_ASSERT(inSuite, test_payload.isValidQRCodePayload()); + EXPECT_TRUE(test_payload.isValidQRCodePayload()); test_payload.commissioningFlow = static_cast(1 << kCommissioningFlowFieldLengthInBits); - NL_TEST_ASSERT(inSuite, test_payload.isValidQRCodePayload() == false); + EXPECT_EQ(test_payload.isValidQRCodePayload(), false); // test invalid version test_payload = payload; test_payload.version = 1 << kVersionFieldLengthInBits; - NL_TEST_ASSERT(inSuite, test_payload.isValidQRCodePayload() == false); + EXPECT_EQ(test_payload.isValidQRCodePayload(), false); // test invalid rendezvousInformation test_payload = payload; @@ -308,15 +306,15 @@ void TestSetupPayloadVerify(nlTestSuite * inSuite, void * inContext) RendezvousInformationFlag::kBLE, RendezvousInformationFlag::kSoftAP, RendezvousInformationFlag::kOnNetwork); invalid.SetRaw(static_cast(invalid.Raw() + 1)); test_payload.rendezvousInformation.SetValue(invalid); - NL_TEST_ASSERT(inSuite, test_payload.isValidQRCodePayload() == false); + EXPECT_EQ(test_payload.isValidQRCodePayload(), false); // test invalid setup PIN test_payload = payload; test_payload.setUpPINCode = 1 << kSetupPINCodeFieldLengthInBits; - NL_TEST_ASSERT(inSuite, test_payload.isValidQRCodePayload() == false); + EXPECT_EQ(test_payload.isValidQRCodePayload(), false); } -void TestInvalidQRCodePayload_WrongCharacterSet(nlTestSuite * inSuite, void * inContext) +TEST(TestQRCode, TestInvalidQRCodePayload_WrongCharacterSet) { string invalidString = kDefaultPayloadQRCode; invalidString.back() = ' '; // space is not contained in the base38 alphabet @@ -325,11 +323,11 @@ void TestInvalidQRCodePayload_WrongCharacterSet(nlTestSuite * inSuite, void * in SetupPayload payload; CHIP_ERROR err = parser.populatePayload(payload); bool didFail = err != CHIP_NO_ERROR; - NL_TEST_ASSERT(inSuite, didFail == true); - NL_TEST_ASSERT(inSuite, payload.isValidQRCodePayload() == false); + EXPECT_EQ(didFail, true); + EXPECT_EQ(payload.isValidQRCodePayload(), false); } -void TestInvalidQRCodePayload_WrongLength(nlTestSuite * inSuite, void * inContext) +TEST(TestQRCode, TestInvalidQRCodePayload_WrongLength) { string invalidString = kDefaultPayloadQRCode; invalidString.pop_back(); @@ -338,19 +336,19 @@ void TestInvalidQRCodePayload_WrongLength(nlTestSuite * inSuite, void * inContex SetupPayload payload; CHIP_ERROR err = parser.populatePayload(payload); bool didFail = err != CHIP_NO_ERROR; - NL_TEST_ASSERT(inSuite, didFail == true); - NL_TEST_ASSERT(inSuite, payload.isValidQRCodePayload() == false); + EXPECT_EQ(didFail, true); + EXPECT_EQ(payload.isValidQRCodePayload(), false); } -void TestPayloadEquality(nlTestSuite * inSuite, void * inContext) +TEST(TestQRCode, TestPayloadEquality) { SetupPayload payload = GetDefaultPayload(); SetupPayload equalPayload = GetDefaultPayload(); - NL_TEST_ASSERT(inSuite, payload == equalPayload); + EXPECT_TRUE(payload == equalPayload); } -void TestPayloadInEquality(nlTestSuite * inSuite, void * inContext) +TEST(TestQRCode, TestPayloadInEquality) { SetupPayload payload = GetDefaultPayload(); @@ -358,10 +356,10 @@ void TestPayloadInEquality(nlTestSuite * inSuite, void * inContext) unequalPayload.discriminator.SetLongValue(28); unequalPayload.setUpPINCode = 121233; - NL_TEST_ASSERT(inSuite, !(payload == unequalPayload)); + EXPECT_FALSE(payload == unequalPayload); } -void TestQRCodeToPayloadGeneration(nlTestSuite * inSuite, void * inContext) +TEST(TestQRCode, TestQRCodeToPayloadGeneration) { SetupPayload payload = GetDefaultPayload(); @@ -369,89 +367,39 @@ void TestQRCodeToPayloadGeneration(nlTestSuite * inSuite, void * inContext) string base38Rep; CHIP_ERROR err = generator.payloadBase38Representation(base38Rep); bool didSucceed = err == CHIP_NO_ERROR; - NL_TEST_ASSERT(inSuite, didSucceed == true); + EXPECT_EQ(didSucceed, true); SetupPayload resultingPayload; QRCodeSetupPayloadParser parser(base38Rep); err = parser.populatePayload(resultingPayload); didSucceed = err == CHIP_NO_ERROR; - NL_TEST_ASSERT(inSuite, didSucceed == true); - NL_TEST_ASSERT(inSuite, resultingPayload.isValidQRCodePayload() == true); + EXPECT_EQ(didSucceed, true); + EXPECT_EQ(resultingPayload.isValidQRCodePayload(), true); bool result = payload == resultingPayload; - NL_TEST_ASSERT(inSuite, result == true); + EXPECT_EQ(result, true); } -void TestExtractPayload(nlTestSuite * inSuite, void * inContext) +TEST(TestQRCode, TestExtractPayload) { - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("MT:ABC")) == string("ABC")); - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("MT:")) == string("")); - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("H:")) == string("")); - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("ASMT:")) == string("")); - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("Z%MT:ABC%")) == string("ABC")); - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("Z%MT:ABC")) == string("ABC")); - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("%Z%MT:ABC")) == string("ABC")); - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("%Z%MT:ABC%")) == string("ABC")); - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("%Z%MT:ABC%DDD")) == string("ABC")); - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("MT:ABC%DDD")) == string("ABC")); - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("MT:ABC%")) == string("ABC")); - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("%MT:")) == string("")); - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("%MT:%")) == string("")); - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("A%")) == string("")); - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("MT:%")) == string("")); - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("%MT:ABC")) == string("ABC")); - NL_TEST_ASSERT(inSuite, QRCodeSetupPayloadParser::ExtractPayload(string("ABC")) == string("")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("MT:ABC")), string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("MT:")), string("")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("H:")), string("")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("ASMT:")), string("")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("Z%MT:ABC%")), string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("Z%MT:ABC")), string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("%Z%MT:ABC")), string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("%Z%MT:ABC%")), string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("%Z%MT:ABC%DDD")), string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("MT:ABC%DDD")), string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("MT:ABC%")), string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("%MT:")), string("")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("%MT:%")), string("")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("A%")), string("")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("MT:%")), string("")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("%MT:ABC")), string("ABC")); + EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("ABC")), string("")); } -// Test Suite - -/** - * Test Suite that lists all the test functions. - */ -// clang-format off -const nlTest sTests[] = -{ - NL_TEST_DEF("Test Rendezvous Flags", TestRendezvousFlags), - NL_TEST_DEF("Test Commissioning Flow", TestCommissioningFlow), - NL_TEST_DEF("Test Maximum Values", TestMaximumValues), - NL_TEST_DEF("Test Base 38", TestBase38), - NL_TEST_DEF("Test Bitset Length", TestBitsetLen), - NL_TEST_DEF("Test Payload Byte Array Representation", TestPayloadByteArrayRep), - NL_TEST_DEF("Test Payload Base 38 Representation", TestPayloadBase38Rep), - NL_TEST_DEF("Test Setup Payload Verify", TestSetupPayloadVerify), - NL_TEST_DEF("Test Payload Equality", TestPayloadEquality), - NL_TEST_DEF("Test Payload Inequality", TestPayloadInEquality), - NL_TEST_DEF("Test QRCode to Payload Generation", TestQRCodeToPayloadGeneration), - NL_TEST_DEF("Test Invalid QR Code Payload - Wrong Character Set", TestInvalidQRCodePayload_WrongCharacterSet), - NL_TEST_DEF("Test Invalid QR Code Payload - Wrong Length", TestInvalidQRCodePayload_WrongLength), - NL_TEST_DEF("Test Extract Payload", TestExtractPayload), - - NL_TEST_SENTINEL() -}; -// clang-format on - } // namespace - -/** - * Main - */ -int TestQuickResponseCode() -{ - // clang-format off - nlTestSuite theSuite = - { - "chip-qrcode-general-tests", - &sTests[0], - nullptr, - nullptr - }; - // 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(TestQuickResponseCode); diff --git a/src/test_driver/openiotsdk/unit-tests/test_components.txt b/src/test_driver/openiotsdk/unit-tests/test_components.txt index 9cf879e9fb5125..8504c28313f998 100644 --- a/src/test_driver/openiotsdk/unit-tests/test_components.txt +++ b/src/test_driver/openiotsdk/unit-tests/test_components.txt @@ -6,3 +6,4 @@ MinimalMdnsRespondersTests CoreTests PlatformTests TestShell +SetupPayloadTests \ No newline at end of file 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 7f86f2604e2f84..3da7f5bdfb608f 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,7 @@ MinimalMdnsCoreTests RawTransportTests RetransmitTests SecureChannelTests -SetupPayloadTests +SetupPayloadTestsNL SupportTests TransportLayerTests UserDirectedCommissioningTests