mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-14 18:26:11 -04:00
Add option to show fake devices
This commit is contained in:
@@ -1,24 +1,24 @@
|
||||
package eu.darken.capod.pods.core.apple
|
||||
|
||||
import android.bluetooth.BluetoothDevice
|
||||
import android.bluetooth.le.ScanRecord
|
||||
import android.bluetooth.le.ScanResult
|
||||
import eu.darken.capod.common.SystemClockWrap
|
||||
import eu.darken.capod.common.bluetooth.BleScanResult
|
||||
import eu.darken.capod.pods.core.PodDevice
|
||||
import eu.darken.capod.pods.core.apple.protocol.ContinuityProtocol
|
||||
import eu.darken.capod.pods.core.apple.protocol.ProximityPairing
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.every
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import io.mockk.mockkObject
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import testhelper.BaseTest
|
||||
|
||||
abstract class BaseAirPodsTest : BaseTest() {
|
||||
|
||||
@MockK lateinit var scanResult: ScanResult
|
||||
@MockK lateinit var scanRecord: ScanRecord
|
||||
@MockK lateinit var device: BluetoothDevice
|
||||
private val baseBleScanResult = BleScanResult(
|
||||
address = "77:49:4C:D8:25:0C",
|
||||
rssi = -66,
|
||||
generatedAtNanos = 136136027721826,
|
||||
manufacturerSpecificData = emptyMap()
|
||||
)
|
||||
|
||||
val factory = AppleFactory(
|
||||
proximityPairingDecoder = ProximityPairing.Decoder(),
|
||||
@@ -28,11 +28,6 @@ abstract class BaseAirPodsTest : BaseTest() {
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
MockKAnnotations.init(this)
|
||||
every { scanResult.scanRecord } returns scanRecord
|
||||
every { scanResult.rssi } returns -66
|
||||
every { scanResult.timestampNanos } returns 136136027721826
|
||||
every { scanResult.device } returns device
|
||||
every { device.address } returns "77:49:4C:D8:25:0C"
|
||||
|
||||
mockkObject(SystemClockWrap)
|
||||
every { SystemClockWrap.elapsedRealtimeNanos } returns 1000L
|
||||
@@ -45,11 +40,11 @@ abstract class BaseAirPodsTest : BaseTest() {
|
||||
.replace("<", "")
|
||||
require(trimmed.length % 2 == 0) { "Not a HEX string" }
|
||||
val bytes = trimmed.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
||||
mockData(bytes)
|
||||
block.invoke(factory.create(scanResult) as T)
|
||||
val result = mockData(bytes)
|
||||
block.invoke(factory.create(result) as T)
|
||||
}
|
||||
|
||||
fun mockData(hex: String) {
|
||||
fun mockData(hex: String): BleScanResult {
|
||||
val trimmed = hex
|
||||
.replace(" ", "")
|
||||
.replace(">", "")
|
||||
@@ -59,7 +54,9 @@ abstract class BaseAirPodsTest : BaseTest() {
|
||||
return mockData(bytes)
|
||||
}
|
||||
|
||||
fun mockData(data: ByteArray) {
|
||||
every { scanRecord.getManufacturerSpecificData(ContinuityProtocol.APPLE_COMPANY_IDENTIFIER) } returns data
|
||||
}
|
||||
fun mockData(data: ByteArray): BleScanResult = baseBleScanResult.copy(
|
||||
manufacturerSpecificData = mutableMapOf<Int, ByteArray>().apply {
|
||||
this[ContinuityProtocol.APPLE_COMPANY_IDENTIFIER] = data
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -26,11 +26,9 @@ class SingleApplePodsTest : BaseAirPodsTest() {
|
||||
create<AirPodsMax>("07 19 01 0A 20 02 05 80 04 0F 44 A7 60 9B F8 3C FD B1 D8 1C 61 EA 82 60 A3 2C 4E") {
|
||||
batteryHeadsetPercent shouldBe 0.5f
|
||||
|
||||
isCaseCharging shouldBe false
|
||||
isHeadsetBeingCharged shouldBe false
|
||||
|
||||
isHeadphonesBeingWorn shouldBe true
|
||||
batteryCasePercent shouldBe 0.0f
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,11 +22,9 @@ class AirPodsMaxTest : BaseAirPodsTest() {
|
||||
|
||||
batteryHeadsetPercent shouldBe 0.4f
|
||||
|
||||
isCaseCharging shouldBe false
|
||||
isHeadsetBeingCharged shouldBe false
|
||||
|
||||
isHeadphonesBeingWorn shouldBe true
|
||||
batteryCasePercent shouldBe 0.0f
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,11 +43,9 @@ class AirPodsMaxTest : BaseAirPodsTest() {
|
||||
|
||||
batteryHeadsetPercent shouldBe 0.5f
|
||||
|
||||
isCaseCharging shouldBe false
|
||||
isHeadsetBeingCharged shouldBe false
|
||||
|
||||
isHeadphonesBeingWorn shouldBe true
|
||||
batteryCasePercent shouldBe 0.0f
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,7 +171,7 @@ class AirPodsProTest : BaseAirPodsTest() {
|
||||
isCaseCharging shouldBe false
|
||||
isRightPodCharging shouldBe false
|
||||
isLeftPodCharging shouldBe false
|
||||
batteryCasePercent shouldBe null
|
||||
batteryCasePercent shouldBe 0.6f
|
||||
|
||||
deviceColor shouldBe DualApplePods.DeviceColor.WHITE
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user