mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
test(data): Add Kotest property-based tests for PacketHandler
This commit is contained in:
parent
438d018260
commit
7d56c3fefd
2 changed files with 22 additions and 2 deletions
|
|
@ -71,6 +71,8 @@ kotlin {
|
||||||
commonTest.dependencies {
|
commonTest.dependencies {
|
||||||
implementation(kotlin("test"))
|
implementation(kotlin("test"))
|
||||||
implementation(libs.kotlinx.coroutines.test)
|
implementation(libs.kotlinx.coroutines.test)
|
||||||
|
implementation(libs.kotest.assertions)
|
||||||
|
implementation(libs.kotest.property)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,9 @@ import dev.mokkery.every
|
||||||
import dev.mokkery.matcher.any
|
import dev.mokkery.matcher.any
|
||||||
import dev.mokkery.mock
|
import dev.mokkery.mock
|
||||||
import dev.mokkery.verifySuspend
|
import dev.mokkery.verifySuspend
|
||||||
|
import io.kotest.property.Arb
|
||||||
|
import io.kotest.property.arbitrary.int
|
||||||
|
import io.kotest.property.checkAll
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.test.StandardTestDispatcher
|
import kotlinx.coroutines.test.StandardTestDispatcher
|
||||||
import kotlinx.coroutines.test.TestScope
|
import kotlinx.coroutines.test.TestScope
|
||||||
|
|
@ -39,6 +42,7 @@ import org.meshtastic.proto.QueueStatus
|
||||||
import org.meshtastic.proto.ToRadio
|
import org.meshtastic.proto.ToRadio
|
||||||
import kotlin.test.BeforeTest
|
import kotlin.test.BeforeTest
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertNotNull
|
||||||
|
|
||||||
class PacketHandlerImplTest {
|
class PacketHandlerImplTest {
|
||||||
|
|
||||||
|
|
@ -70,13 +74,16 @@ class PacketHandlerImplTest {
|
||||||
handler.start(testScope)
|
handler.start(testScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testInitialization() {
|
||||||
|
assertNotNull(handler)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `sendToRadio with ToRadio sends immediately`() {
|
fun `sendToRadio with ToRadio sends immediately`() {
|
||||||
val toRadio = ToRadio(packet = MeshPacket(id = 123))
|
val toRadio = ToRadio(packet = MeshPacket(id = 123))
|
||||||
|
|
||||||
handler.sendToRadio(toRadio)
|
handler.sendToRadio(toRadio)
|
||||||
|
|
||||||
// No explicit assertion here in original test, but we could verify call
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -107,6 +114,17 @@ class PacketHandlerImplTest {
|
||||||
testScheduler.runCurrent()
|
testScheduler.runCurrent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `handleQueueStatus property test`() = runTest(testDispatcher) {
|
||||||
|
checkAll(Arb.int(0, 10), Arb.int(0, 32), Arb.int(0, 100000)) { res, free, packetId ->
|
||||||
|
val status = QueueStatus(res = res, free = free, mesh_packet_id = packetId)
|
||||||
|
|
||||||
|
// Ensure it doesn't crash on any input
|
||||||
|
handler.handleQueueStatus(status)
|
||||||
|
testScheduler.runCurrent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `outgoing packets are logged with NODE_NUM_LOCAL`() = runTest(testDispatcher) {
|
fun `outgoing packets are logged with NODE_NUM_LOCAL`() = runTest(testDispatcher) {
|
||||||
val packet = MeshPacket(id = 123, decoded = Data(portnum = PortNum.TEXT_MESSAGE_APP))
|
val packet = MeshPacket(id = 123, decoded = Data(portnum = PortNum.TEXT_MESSAGE_APP))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue