Skip to content

Commit

Permalink
Add unit tests for OnboardingPayloadParser (#29030)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored and pull[bot] committed Dec 20, 2023
1 parent 23c26a1 commit 9524116
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/controller/java/tests/chip/onboardingpayload/QRCodeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,60 @@ class QRCodeTest {
assertEquals("ABC", QRCodeOnboardingPayloadParser.extractPayload("%MT:ABC"))
}

/*
* Test Parse QrCode to Expected Payload
*/
@Test
fun testParseQrCodeToExpectedPayload() {
// Payload: MT:W0GU2OTB00KA0648G00
// Vendor Id: 9050 (0x235A)
// Product Id: 20043 (0x4E4B)
// Setup Pin Code: 20202021
// Setup Discriminator: 3840 (0xF00)

val parser = OnboardingPayloadParser()
assertThat(parser.parseQrCode("MT:W0GU2OTB00KA0648G00"))
.isEqualTo(
OnboardingPayload(
discriminator = 0xF00,
setupPinCode = 20202021,
version = 0,
vendorId = 0x235A,
productId = 0x4E4B,
commissioningFlow = CommissioningFlow.STANDARD.value,
discoveryCapabilities = mutableSetOf(DiscoveryCapability.BLE),
)
)
}

/*
* Test Generate QrCode from Expected Value
*/
@Test
fun testGenerateQrCodeFromExpectedValue() {
// Payload: MT:W0GU2OTB00KA0648G00
// Vendor Id: 9050 (0x235A)
// Product Id: 20043 (0x4E4B)
// Setup Pin Code: 20202021
// Setup Discriminator: 3840 (0xF00)

val parser = OnboardingPayloadParser()
assertThat(
parser.getQrCodeFromPayload(
OnboardingPayload(
discriminator = 0xF00,
setupPinCode = 20202021,
version = 0,
vendorId = 0x235A,
productId = 0x4E4B,
commissioningFlow = CommissioningFlow.STANDARD.value,
discoveryCapabilities = mutableSetOf(DiscoveryCapability.BLE),
)
)
)
.isEqualTo("MT:W0GU2OTB00KA0648G00")
}

companion object {
const val kDefaultPayloadQRCode: String = "MT:M5L90MP500K64J00000"
}
Expand Down

0 comments on commit 9524116

Please sign in to comment.