diff --git a/server/core/src/test/java/dev/slimevr/TestServer.kt b/server/core/src/test/java/dev/slimevr/TestServer.kt index 8de6c05f6..d8f591162 100644 --- a/server/core/src/test/java/dev/slimevr/TestServer.kt +++ b/server/core/src/test/java/dev/slimevr/TestServer.kt @@ -1,9 +1,15 @@ package dev.slimevr import dev.llelievr.espflashkotlin.FlasherSerialInterface +import dev.slimevr.config.DefaultUserBehaviour +import dev.slimevr.config.UserConfig +import dev.slimevr.config.UserConfigData +import dev.slimevr.config.UserConfigState +import dev.slimevr.context.Context import dev.slimevr.serial.SerialPortHandle import dev.slimevr.serial.SerialServer import kotlinx.coroutines.CoroutineScope +import java.nio.file.Files fun buildTestSerialServer(scope: CoroutineScope) = SerialServer.create( openPort = { loc, _, _ -> SerialPortHandle(loc, "Fake $loc", {}, {}) }, @@ -25,3 +31,17 @@ fun buildTestSerialServer(scope: CoroutineScope) = SerialServer.create( ) fun buildTestVrServer(scope: CoroutineScope): VRServer = VRServer.create(scope) + +fun buildTestUserConfig(scope: CoroutineScope): UserConfig { + val tempDir = Files.createTempDirectory("slimevr-test").toFile() + tempDir.deleteOnExit() + val behaviours = listOf(DefaultUserBehaviour) + val context = Context.create( + initialState = UserConfigState(data = UserConfigData(), name = "test"), + scope = scope, + behaviours = behaviours, + ) + val userConfig = UserConfig(context, scope = scope, userConfigDir = tempDir) + behaviours.forEach { it.observe(userConfig) } + return userConfig +} diff --git a/server/core/src/test/java/dev/slimevr/heightcalibration/HeightCalibrationTest.kt b/server/core/src/test/java/dev/slimevr/heightcalibration/HeightCalibrationTest.kt index ba87b0867..810b1bcb0 100644 --- a/server/core/src/test/java/dev/slimevr/heightcalibration/HeightCalibrationTest.kt +++ b/server/core/src/test/java/dev/slimevr/heightcalibration/HeightCalibrationTest.kt @@ -2,6 +2,7 @@ package dev.slimevr.heightcalibration +import dev.slimevr.buildTestUserConfig import io.github.axisangles.ktmath.Quaternion import io.github.axisangles.ktmath.Vector3 import kotlinx.coroutines.Job @@ -51,8 +52,9 @@ private fun TestScope.launchSession( controllerFlow: MutableSharedFlow, ): Job { val scope = this + val userConfig = buildTestUserConfig(backgroundScope) return launch { - runCalibrationSession(context, hmdFlow, controllerFlow, clock = { scope.currentTime * 1_000_000L }) + runCalibrationSession(context, userConfig, hmdFlow, controllerFlow, clock = { scope.currentTime * 1_000_000L }) } } @@ -290,7 +292,7 @@ class HeightCalibrationSessionTest { val context = makeContext(this) val controllerFlow = MutableSharedFlow(extraBufferCapacity = 1) val hmdFlow = MutableSharedFlow(extraBufferCapacity = 1) - val job = launch { runCalibrationSession(context, hmdFlow, controllerFlow) } + val job = launch { runCalibrationSession(context, buildTestUserConfig(backgroundScope), hmdFlow, controllerFlow) } advanceTimeBy(TIMEOUT_MS + 1) diff --git a/server/core/src/test/java/dev/slimevr/solarxr/DataFeedTest.kt b/server/core/src/test/java/dev/slimevr/solarxr/DataFeedTest.kt index cd561cff4..c68b79f64 100644 --- a/server/core/src/test/java/dev/slimevr/solarxr/DataFeedTest.kt +++ b/server/core/src/test/java/dev/slimevr/solarxr/DataFeedTest.kt @@ -1,21 +1,31 @@ package dev.slimevr.solarxr +import dev.slimevr.buildTestUserConfig import dev.slimevr.buildTestVrServer +import dev.slimevr.skeleton.Skeleton import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.advanceTimeBy import kotlinx.coroutines.test.runTest +import solarxr_protocol.MessageBundle import solarxr_protocol.data_feed.DataFeedConfig import solarxr_protocol.data_feed.PollDataFeed import solarxr_protocol.data_feed.StartDataFeed import kotlin.test.Test import kotlin.test.assertEquals -private fun testConn(backgroundScope: kotlinx.coroutines.CoroutineScope, onSend: suspend (ByteArray) -> Unit) = SolarXRConnection.create( - buildTestVrServer(backgroundScope), - onSend = onSend, - scope = backgroundScope, - behaviours = listOf(DataFeedInitBehaviour), -) +private fun testConn(backgroundScope: kotlinx.coroutines.CoroutineScope, onSend: suspend (ByteArray) -> Unit): SolarXRBridge { + val server = buildTestVrServer(backgroundScope) + val userConfig = buildTestUserConfig(backgroundScope) + val skeleton = Skeleton.create(backgroundScope, userConfig) + val bridge = SolarXRBridge.create( + id = 1, + serverContext = server, + scope = backgroundScope, + behaviours = listOf(DataFeedInitBehaviour(server, skeleton)), + ) + bridge.outbound.on { _ -> onSend(ByteArray(0)) } + return bridge +} private fun config(intervalMs: Int) = DataFeedConfig(minimumTimeSinceLast = intervalMs.toUShort()) @@ -91,4 +101,4 @@ class DataFeedTest { } // TODO: need more tests for the content of a datafeed + check if the masks work -} +} \ No newline at end of file