implements PLN-0156
This commit is contained in:
@@ -143,17 +143,33 @@ impl SystemOS {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::os::{GameLifecycleEventKind, LifecycleError, LifecycleOperation};
|
||||
use crate::process::{ProcessKind, ProcessState};
|
||||
use crate::os::{GameLifecycleEventKind, LifecycleError, LifecycleOperation, SessionError};
|
||||
use crate::process::{ProcessId, ProcessKind, ProcessState};
|
||||
use crate::services::foreground::{ForegroundOwner, ResidentGame, ResidentGameState};
|
||||
use crate::task::{TaskId, TaskState};
|
||||
use prometeu_hal::app_mode::AppMode;
|
||||
use prometeu_hal::cartridge::{AssetsPayloadSource, Cartridge};
|
||||
use prometeu_hal::syscalls::caps;
|
||||
|
||||
fn process_state_for_task(os: &SystemOS, task_id: TaskId) -> ProcessState {
|
||||
let task = os.task_manager.get(task_id).expect("task should exist");
|
||||
os.process_manager.get(task.process_id).expect("process should exist").state
|
||||
}
|
||||
|
||||
fn session_test_cartridge(app_mode: AppMode, app_id: u32, title: &str) -> Cartridge {
|
||||
Cartridge {
|
||||
app_id,
|
||||
title: title.to_string(),
|
||||
app_version: "1.0.0".to_string(),
|
||||
app_mode,
|
||||
capabilities: caps::NONE,
|
||||
program: vec![],
|
||||
assets: AssetsPayloadSource::empty(),
|
||||
asset_table: vec![],
|
||||
preload: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_foreground_task_marks_task_and_process_running() {
|
||||
let mut os = SystemOS::new(None);
|
||||
@@ -453,6 +469,60 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vm_shell_load_returns_typed_error_when_foreground_shell_exists() {
|
||||
let mut os = SystemOS::new(None);
|
||||
let first = os.sessions().create_vm_shell_task(7, "Settings");
|
||||
let cartridge = session_test_cartridge(AppMode::Shell, 8, "Files");
|
||||
|
||||
let error = os.sessions().load_vm_cartridge(&cartridge).expect_err("load should fail");
|
||||
|
||||
match error {
|
||||
SessionError::Lifecycle(LifecycleError::ForegroundShellAlreadyExists {
|
||||
existing,
|
||||
requested,
|
||||
}) => {
|
||||
assert_eq!(existing, first);
|
||||
assert_ne!(requested, first);
|
||||
}
|
||||
other => panic!("expected foreground shell lifecycle error, got {:?}", other),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vm_session_creation_returns_typed_error_for_missing_task() {
|
||||
let mut os = SystemOS::new(None);
|
||||
|
||||
assert_eq!(
|
||||
os.sessions().try_create_vm_session_for_task(TaskId(999)),
|
||||
Err(SessionError::TaskNotFound(TaskId(999)))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vm_session_creation_returns_typed_error_for_missing_process() {
|
||||
let mut os = SystemOS::new(None);
|
||||
let task_id = os.task_manager.create_game_task(ProcessId(999), 42, "Broken");
|
||||
|
||||
assert_eq!(
|
||||
os.sessions().try_create_vm_session_for_task(task_id),
|
||||
Err(SessionError::ProcessNotFound(ProcessId(999)))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn session_cartridge_initialization_returns_typed_error_for_missing_session() {
|
||||
let mut os = SystemOS::new(None);
|
||||
let process_id = os.process_manager.spawn_vm_game(42, "Sector Crawl");
|
||||
let task_id = os.task_manager.create_game_task(process_id, 42, "Sector Crawl");
|
||||
let cartridge = session_test_cartridge(AppMode::Game, 42, "Sector Crawl");
|
||||
|
||||
assert_eq!(
|
||||
os.sessions().try_initialize_session_cartridge(task_id, &cartridge),
|
||||
Err(SessionError::MissingVmSession(task_id))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closing_foreground_shell_returns_to_hub() {
|
||||
let mut os = SystemOS::new(None);
|
||||
|
||||
Reference in New Issue
Block a user