Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ManualCode unit tests for OnboardingPayloadParser #29036

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,22 @@ class OnboardingPayload(
setupPinCode == other.setupPinCode
}

override fun toString(): String {
return "OnboardingPayload(" +
"version=$version, " +
"vendorId=$vendorId, " +
"productId=$productId, " +
"commissioningFlow=$commissioningFlow, " +
"discoveryCapabilities=$discoveryCapabilities, " +
"discriminator=$discriminator, " +
"hasShortDiscriminator=$hasShortDiscriminator, " +
"setupPinCode=$setupPinCode, " +
"optionalQRCodeInfo=$optionalQRCodeInfo, " +
"optionalVendorData=$optionalVendorData, " +
"optionalExtensionData=$optionalExtensionData" +
")"
}

fun addOptionalQRCodeInfo(info: OptionalQRCodeInfo) {
optionalQRCodeInfo[info.tag] = info
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,4 +683,79 @@ class ManualCodeTest {
productId = payload.productId
)
}

/*
* Test Parse Short Manual PairingCode to Expected Payload
*/
@Test
fun testParseShortManualPairingCodeToExpectedPayload() {
// Payload: MT:W0GU2OTB00KA0648G00
// Setup Pin Code: 20202021
// Setup Discriminator: 15

val parser = OnboardingPayloadParser()
assertThat(parser.parseManualPairingCode("34970112332"))
.isEqualTo(
OnboardingPayload(
discriminator = 15,
setupPinCode = 20202021,
version = 0,
vendorId = 0,
productId = 0,
hasShortDiscriminator = true,
commissioningFlow = CommissioningFlow.STANDARD.value,
discoveryCapabilities = mutableSetOf(),
)
)
}

/*
* Test Parse Long Manual PairingCode to Expected Payload
*/
@Test
fun testParseLongManualPairingCodeToExpectedPayload() {
// Payload: MT:W0GU2OTB00KA0648G00
// Vendor Id: 9050 (0x235A)
// Product Id: 17729 (0x4541)
// Setup Pin Code: 20202021
// Setup Discriminator: 15

val parser = OnboardingPayloadParser()
assertThat(parser.parseManualPairingCode("749701123309050177298"))
.isEqualTo(
OnboardingPayload(
discriminator = 15,
setupPinCode = 20202021,
version = 0,
vendorId = 0x235A,
productId = 0x4541,
hasShortDiscriminator = true,
commissioningFlow = CommissioningFlow.CUSTOM.value,
discoveryCapabilities = mutableSetOf(),
)
)
}

/*
* Test Generate Manual PairingCode to Expected Payload
*/
@Test
fun testGenerateManualPairingCodetoExpectedPayload() {
val parser = OnboardingPayloadParser()
assertThat(
parser.getManualPairingCodeFromPayload(
OnboardingPayload(
discriminator = 15,
setupPinCode = 20202021,
version = 0,
vendorId = 0x235A,
productId = 0x4541,
hasShortDiscriminator = true,
commissioningFlow = CommissioningFlow.CUSTOM.value,
discoveryCapabilities = mutableSetOf(),
)
)
)
.isEqualTo("749701123309050177298")
}
}
Loading