From 5f456bb89884ff64c21c0e374ae0bcb1b90b6ad2 Mon Sep 17 00:00:00 2001 From: Anthony Berg Date: Thu, 2 May 2024 12:49:25 +0100 Subject: [PATCH] feat(connector): track initial state in test runs --- .../desktopMain/kotlin/tab/test/TestRun.kt | 39 +++++++++++++------ .../anthonyberg/connector/shared/xpc/XPC.kt | 18 +++++++++ 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/connector/composeApp/src/desktopMain/kotlin/tab/test/TestRun.kt b/connector/composeApp/src/desktopMain/kotlin/tab/test/TestRun.kt index 102ec43..45f2f8a 100644 --- a/connector/composeApp/src/desktopMain/kotlin/tab/test/TestRun.kt +++ b/connector/composeApp/src/desktopMain/kotlin/tab/test/TestRun.kt @@ -25,7 +25,11 @@ class TestRun ( private val actions: List ) : Screen { + private val xpc = XPC() + private val xpcConnected = xpc.connected() + private var tested = mutableStateListOf() + private val initState = getInitState() @Composable override fun Content() { @@ -37,6 +41,11 @@ class TestRun ( modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally, ) { + if (!xpcConnected) { + Text("Could not connect to the simulator!") + return + } + // Progress Indicator if (running) { LinearProgressIndicator( @@ -50,7 +59,7 @@ class TestRun ( ) { LazyColumn { items(actions) { action -> - ActionItem(action) + ActionItem(action, initState[action.step]) } } @@ -75,8 +84,9 @@ class TestRun ( } @Composable - private fun ActionItem(action: Action) { + private fun ActionItem(action: Action, initState: FloatArray) { ListItem( + overlineContent = { Text("Initial State: ${initState[0]}") }, headlineContent = { Text(action.type) }, supportingContent = { Text("Goal: ${action.goal}") }, leadingContent = { @@ -103,16 +113,6 @@ class TestRun ( } private suspend fun runSteps() { - val xpc = XPC() - - // Checks if the simulator is running before running the other tests - if (!xpc.connected()) { - for (action in actions) { - tested.add(false) - } - return - } - for (action in actions) { delay(1000L) @@ -123,4 +123,19 @@ class TestRun ( tested.add(result) } } + + private fun getInitState(): Array { + if (!xpc.connected()) { + return Array(actions.size) { FloatArray(0) } + } + + var initDrefs = arrayOf() + for (action in actions) { + initDrefs += action.type + } + + val result = xpc.getStates(initDrefs) + + return result + } } diff --git a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/xpc/XPC.kt b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/xpc/XPC.kt index 9d41d6c..2193c7f 100644 --- a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/xpc/XPC.kt +++ b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/xpc/XPC.kt @@ -27,6 +27,24 @@ class XPC { } } + /** + * Gets the state of all Datarefs + * + * @param drefs Array of Datarefs (maximum list size = 255) + * + * @return List of all the values for each Dataref + */ + @Throws(IllegalArgumentException::class) + fun getStates(drefs: Array): Array { + if (drefs.size > 255) { + throw IllegalArgumentException("The drefs cannot contain more than 255 elements") + } + + val result = xpc.getDREFs(drefs) + + return result + } + /** * Sets a dataref in X-Plane to the set goal *