mirror of
https://github.com/smyalygames/checklist-tester.git
synced 2025-07-08 00:11:00 +02:00
feat(connector): add tests and run via XPC
This commit is contained in:
parent
515c06e46a
commit
452756e3d3
@ -1,37 +1,50 @@
|
|||||||
package tab.test
|
package tab.test
|
||||||
|
|
||||||
import androidx.compose.foundation.VerticalScrollbar
|
import androidx.compose.foundation.VerticalScrollbar
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.fillMaxHeight
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.rememberScrollbarAdapter
|
import androidx.compose.foundation.rememberScrollbarAdapter
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.outlined.Check
|
||||||
import androidx.compose.material.icons.outlined.Info
|
import androidx.compose.material.icons.outlined.Info
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material.icons.outlined.Warning
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.material3.ListItem
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import cafe.adriel.voyager.core.screen.Screen
|
import cafe.adriel.voyager.core.screen.Screen
|
||||||
import io.anthonyberg.connector.shared.entity.Action
|
import io.anthonyberg.connector.shared.entity.Action
|
||||||
|
import io.anthonyberg.connector.shared.xpc.XPC
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class TestRun (
|
class TestRun (
|
||||||
private val actions: List<Action>
|
private val actions: List<Action>
|
||||||
) : Screen {
|
) : Screen {
|
||||||
|
|
||||||
|
private var tested = mutableStateListOf<Boolean>()
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
override fun Content() {
|
override fun Content() {
|
||||||
val lazyState = rememberLazyListState(0)
|
val lazyState = rememberLazyListState(0)
|
||||||
|
var running by remember { mutableStateOf(false) }
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
) {
|
) {
|
||||||
|
// Progress Indicator
|
||||||
|
if (running) {
|
||||||
|
LinearProgressIndicator(
|
||||||
|
progress = { tested.size / actions.size.toFloat() },
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier.fillMaxWidth(0.7F)
|
modifier = Modifier.fillMaxWidth(0.7F)
|
||||||
) {
|
) {
|
||||||
@ -51,6 +64,14 @@ class TestRun (
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!running and (tested.size == 0)) {
|
||||||
|
scope.launch {
|
||||||
|
running = true
|
||||||
|
runSteps()
|
||||||
|
running = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -58,9 +79,48 @@ class TestRun (
|
|||||||
ListItem(
|
ListItem(
|
||||||
headlineContent = { Text(action.type) },
|
headlineContent = { Text(action.type) },
|
||||||
supportingContent = { Text("Goal: ${action.goal}") },
|
supportingContent = { Text("Goal: ${action.goal}") },
|
||||||
leadingContent = { Icon(Icons.Outlined.Info, null) }
|
leadingContent = {
|
||||||
|
if (action.step > tested.size) {
|
||||||
|
Icon(Icons.Outlined.Info, "Waiting")
|
||||||
|
} else if (action.step == tested.size) {
|
||||||
|
CircularProgressIndicator(
|
||||||
|
modifier = Modifier.size(24.dp)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
when (tested[action.step]) {
|
||||||
|
true -> Icon(Icons.Outlined.Check, "Passed")
|
||||||
|
false -> Icon(
|
||||||
|
imageVector = Icons.Outlined.Warning,
|
||||||
|
contentDescription = "Failed",
|
||||||
|
tint = MaterialTheme.colorScheme.error
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
HorizontalDivider()
|
HorizontalDivider()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
// TODO add try catch
|
||||||
|
val result = xpc.runChecklist(action.type, action.goal.toInt())
|
||||||
|
|
||||||
|
// TODO add more detailed results
|
||||||
|
tested.add(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,4 +26,21 @@ class XPC {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a dataref in X-Plane to the set goal
|
||||||
|
*
|
||||||
|
* @param dref Dataref name in X-Plane to change the value for
|
||||||
|
* @param goal The value that should be set for the dataref in X-Plane
|
||||||
|
*
|
||||||
|
* @return `true` if successfully set, `false` otherwise
|
||||||
|
*/
|
||||||
|
@Throws(SocketException::class, IOException::class)
|
||||||
|
fun runChecklist(dref: String, goal: Int) : Boolean {
|
||||||
|
xpc.sendDREF(dref, goal.toFloat())
|
||||||
|
|
||||||
|
val result = xpc.getDREF(dref)
|
||||||
|
|
||||||
|
return goal.toFloat() == result[0]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user