dash ble: add tests for StringLengthPrefixEncodingTest

We tested this part with a real pod and confirmed that it's working
This commit is contained in:
Andrei Vereha 2021-03-14 12:38:53 +01:00
parent 5f71e1b27f
commit eda52857e5
3 changed files with 28 additions and 1 deletions

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message
import org.junit.Assert.*
class MessagePacketTest

View file

@ -7,8 +7,8 @@ import org.junit.Test
import java.util.*
class PayloadSplitJoinTest {
private val random = Random(42)
val random = Random(42)
@Test fun testSplitAndJoinBack() {
for (s in 0..250) {
val payload = ByteArray(s)

View file

@ -0,0 +1,22 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message
import com.google.crypto.tink.subtle.Hex
import info.nightscout.androidaps.utils.extensions.toHex
import org.junit.Assert.*
import org.junit.Test
class StringLengthPrefixEncodingTest {
private val p0Payload = Hex.decode("50,30,3d,00,01,a5".replace(",","")) // from logs
private val p0Content = Hex.decode("a5")
@Test fun testFormatKeysP0() {
val payload = StringLengthPrefixEncoding.formatKeys(arrayOf("P0="), arrayOf(p0Content))
assertEquals(p0Payload.toHex(), payload.toHex())
}
@Test fun testParseKeysP0() {
val parsed = StringLengthPrefixEncoding.parseKeys(arrayOf("P0="), p0Payload)
assertEquals(parsed.size, 1)
assertEquals(parsed[0].toHex(), p0Content.toHex())
}
}