Skip to content

Commit

Permalink
Add ManualCode unit tests for OnboardingPayloadParser (#29036)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored and pull[bot] committed Feb 26, 2024
1 parent 98bad05 commit 173f8cb
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
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
75 changes: 75 additions & 0 deletions src/controller/java/tests/chip/onboardingpayload/ManualCodeTest.kt
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")
}
}

0 comments on commit 173f8cb

Please sign in to comment.