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

Fix kotlin tests, remove unused code #32880

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -183,7 +183,5 @@ class ManualOnboardingPayloadGenerator(private val payloadContents: OnboardingPa
if (offset + len > buffer.size) {
throw OnboardingPayloadException("The outBuffer has insufficient size")
}

String.format("%0${len}d", number).toCharArray(buffer, offset, 0, len)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ fun payloadBase38RepresentationWithTLV(

// Copy the subBuffer back to the outBuffer
subBuffer.copyInto(outBuffer, prefixLen)

// Reduce output buffer size to be the size of written data
outBuffer.copyOf(prefixLen + subBuffer.size)
yufengwangca marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import kotlin.math.ceil
import kotlin.math.log10
import kotlin.math.pow
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
Expand Down Expand Up @@ -444,7 +445,7 @@ class ManualCodeTest {
// Override the discriminator in the input payload with the short version,
// since that's what we will produce.
inPayload.setShortDiscriminatorValue(inPayload.getShortDiscriminatorValue())
assertThat(inPayload == outPayload)
assertEquals(inPayload, outPayload)
}

/*
Expand All @@ -464,7 +465,7 @@ class ManualCodeTest {
// Override the discriminator in the input payload with the short version,
// since that's what we will produce.
inPayload.setShortDiscriminatorValue(inPayload.getShortDiscriminatorValue())
assertThat(inPayload == outPayload)
assertEquals(inPayload, outPayload)
}

/*
Expand All @@ -479,15 +480,15 @@ class ManualCodeTest {

try {
ManualOnboardingPayloadParser.checkDecimalStringValidity(representationWithoutCheckDigit)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}

representationWithoutCheckDigit = "1"
try {
ManualOnboardingPayloadParser.checkDecimalStringValidity(representationWithoutCheckDigit)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}
Expand Down Expand Up @@ -516,28 +517,28 @@ class ManualCodeTest {

try {
ManualOnboardingPayloadParser.checkCodeLengthValidity("01234567891", false)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}

try {
ManualOnboardingPayloadParser.checkCodeLengthValidity("012345678", false)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}

try {
ManualOnboardingPayloadParser.checkCodeLengthValidity("012345678901234567891", true)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}

try {
ManualOnboardingPayloadParser.checkCodeLengthValidity("0123456789012345678", true)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}
Expand All @@ -562,14 +563,14 @@ class ManualCodeTest {

try {
ManualOnboardingPayloadParser.toNumber("012345.123456789")
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}

try {
ManualOnboardingPayloadParser.toNumber("/")
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}
Expand Down Expand Up @@ -631,22 +632,22 @@ class ManualCodeTest {
try {
index.set(1)
ManualOnboardingPayloadParser.readDigitsFromDecimalString("12345", index, 5)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}

try {
ManualOnboardingPayloadParser.readDigitsFromDecimalString("12", index, 5)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}

try {
index.set(200)
ManualOnboardingPayloadParser.readDigitsFromDecimalString("6256276377282", index, 1)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}
Expand Down
29 changes: 15 additions & 14 deletions src/controller/java/tests/matter/onboardingpayload/QRCodeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package matter.onboardingpayload

import com.google.common.truth.Truth.assertThat
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
Expand Down Expand Up @@ -224,7 +225,7 @@ class QRCodeTest {

try {
QRCodeOnboardingPayloadParser(invalidString).populatePayload()
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}
Expand All @@ -240,7 +241,7 @@ class QRCodeTest {

try {
QRCodeOnboardingPayloadParser(invalidString).populatePayload()
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}
Expand Down Expand Up @@ -396,21 +397,21 @@ class QRCodeTest {
// verify we can grab just the serial number as well
assertThat(parsedQrCode.getSerialNumber()).isEqualTo("123456789")

// Test 2nd optional field
optionalQRCodeInfo = OptionalQRCodeInfoExtension()
optionalQRCodeInfo.tag = 130
optionalQRCodeInfo.type = OptionalQRCodeInfoType.TYPE_STRING
optionalQRCodeInfo.data = "myData"
val optionalQRCodeInfo1 = OptionalQRCodeInfoExtension()
optionalQRCodeInfo1.tag = 130
optionalQRCodeInfo1.type = OptionalQRCodeInfoType.TYPE_STRING
optionalQRCodeInfo1.data = "myData"

assertThat(parsedQrCode.getAllOptionalVendorData()[0]).isEqualTo(optionalQRCodeInfo)
val optionalQRCodeInfo2 = OptionalQRCodeInfoExtension()
optionalQRCodeInfo2.tag = 131
optionalQRCodeInfo2.type = OptionalQRCodeInfoType.TYPE_INT32
optionalQRCodeInfo2.int32 = 12

// Test 3rd optional field
optionalQRCodeInfo = OptionalQRCodeInfoExtension()
optionalQRCodeInfo.tag = 131
optionalQRCodeInfo.type = OptionalQRCodeInfoType.TYPE_INT32
optionalQRCodeInfo.int32 = 12
val vendor1 = parsedQrCode.getAllOptionalVendorData()[0]
val vendor2 = parsedQrCode.getAllOptionalVendorData()[1]

assertThat(parsedQrCode.getAllOptionalVendorData()[1]).isEqualTo(optionalQRCodeInfo)
assertTrue(vendor1 == optionalQRCodeInfo1 || vendor1 == optionalQRCodeInfo2)
assertTrue(vendor2 == optionalQRCodeInfo1 || vendor2 == optionalQRCodeInfo2)
}

companion object {
Expand Down
Loading