Skip to content

Commit

Permalink
Restyle
Browse files Browse the repository at this point in the history
  • Loading branch information
andreilitvin committed Apr 19, 2024
1 parent bcdef5e commit 3685bf9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
59 changes: 30 additions & 29 deletions src/setup_payload/tests/TestManualCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ TEST(TestManualCode, TestDecimalRepresentation_FullPayloadWithoutZeros)
EXPECT_TRUE(CheckGenerator(payload, expectedResult));
}

void assertPayloadValues(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)
{
EXPECT_EQ(actualError, expectedError);
EXPECT_EQ(payload.setUpPINCode, pinCode);
Expand Down Expand Up @@ -274,8 +274,7 @@ TEST(TestManualCode, TestGenerateAndParser_FullPayload)

SetupDiscriminator discriminator;
discriminator.SetShortValue(payload.discriminator.GetShortValue());
assertPayloadValues(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);
}

TEST(TestManualCode, TestGenerateAndParser_PartialPayload)
Expand All @@ -292,8 +291,7 @@ TEST(TestManualCode, TestGenerateAndParser_PartialPayload)

SetupDiscriminator discriminator;
discriminator.SetShortValue(payload.discriminator.GetShortValue());
assertPayloadValues(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);
}

TEST(TestManualCode, TestPayloadParser_PartialPayload)
Expand Down Expand Up @@ -399,11 +397,11 @@ TEST(TestManualCode, TestLongCodeReadWrite)
EXPECT_TRUE(inPayload == outPayload);
}

void assertEmptyPayloadWithError(CHIP_ERROR actualError, CHIP_ERROR expectedError,
const SetupPayload & payload)
void assertEmptyPayloadWithError(CHIP_ERROR actualError, CHIP_ERROR expectedError, const SetupPayload & payload)
{
EXPECT_EQ(actualError, expectedError);
EXPECT_TRUE(payload.setUpPINCode == 0 && payload.discriminator.GetLongValue() == 0 && payload.productID == 0 && payload.vendorID == 0);
EXPECT_TRUE(payload.setUpPINCode == 0 && payload.discriminator.GetLongValue() == 0 && payload.productID == 0 &&
payload.vendorID == 0);
}

TEST(TestManualCode, TestPayloadParser_InvalidEntry)
Expand All @@ -414,47 +412,47 @@ TEST(TestManualCode, TestPayloadParser_InvalidEntry)
// Empty input
decimalString = "";
decimalString += Verhoeff10::ComputeCheckChar(decimalString.c_str());
assertEmptyPayloadWithError(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(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(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(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(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(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(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(ManualSetupPayloadParser(decimalString).populatePayload(payload),
CHIP_ERROR_INTEGRITY_CHECK_FAILED, payload);
assertEmptyPayloadWithError(ManualSetupPayloadParser(decimalString).populatePayload(payload), CHIP_ERROR_INTEGRITY_CHECK_FAILED,
payload);
}

TEST(TestManualCode, TestCheckDecimalStringValidity)
Expand All @@ -465,10 +463,12 @@ TEST(TestManualCode, TestCheckDecimalStringValidity)
std::string decimalString;

representationWithoutCheckDigit = "";
EXPECT_EQ(ManualSetupPayloadParser::CheckDecimalStringValidity(representationWithoutCheckDigit, outReprensation), CHIP_ERROR_INVALID_STRING_LENGTH);
EXPECT_EQ(ManualSetupPayloadParser::CheckDecimalStringValidity(representationWithoutCheckDigit, outReprensation),
CHIP_ERROR_INVALID_STRING_LENGTH);

representationWithoutCheckDigit = "1";
EXPECT_EQ(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());
Expand Down Expand Up @@ -544,7 +544,8 @@ TEST(TestManualCode, TestReadCharsFromDecimalString)
EXPECT_EQ(ManualSetupPayloadParser::ReadDigitsFromDecimalString("12", index, number, 5), CHIP_ERROR_INVALID_STRING_LENGTH);

index = 200;
EXPECT_EQ(ManualSetupPayloadParser::ReadDigitsFromDecimalString("6256276377282", index, number, 1), CHIP_ERROR_INVALID_STRING_LENGTH);
EXPECT_EQ(ManualSetupPayloadParser::ReadDigitsFromDecimalString("6256276377282", index, number, 1),
CHIP_ERROR_INVALID_STRING_LENGTH);
}

TEST(TestManualCode, TestShortCodeCharLengths)
Expand All @@ -564,4 +565,4 @@ TEST(TestManualCode, TestShortCodeCharLengths)
EXPECT_EQ(manualSetupLongCodeCharLength, size_t(kManualSetupLongCodeCharLength));
}

} // namespace
} // namespace
3 changes: 1 addition & 2 deletions src/setup_payload/tests/TestQRCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <gtest/gtest.h>
#include <lib/support/Span.h>


using namespace chip;
using namespace std;

Expand Down Expand Up @@ -403,4 +402,4 @@ TEST(TestQRCode, TestExtractPayload)
EXPECT_EQ(QRCodeSetupPayloadParser::ExtractPayload(string("ABC")), string(""));
}

} // namespace
} // namespace

0 comments on commit 3685bf9

Please sign in to comment.