implements PLN-0140
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
use crate::VirtualMachineRuntime;
|
||||
use crate::fs::{FsState, VirtualFS};
|
||||
use crate::os::{FsFacade, LifecycleFacade, SessionsFacade, VmFacade, WindowFacade};
|
||||
use crate::os::{
|
||||
FsFacade, GameLifecycleEvent, LifecycleFacade, SessionsFacade, VmFacade, WindowFacade,
|
||||
};
|
||||
use crate::process::ProcessManager;
|
||||
use crate::services::foreground::ForegroundStack;
|
||||
use crate::services::memcard::MemcardService;
|
||||
@@ -16,6 +18,7 @@ pub struct SystemOS {
|
||||
pub(super) process_manager: ProcessManager,
|
||||
pub(super) task_manager: TaskManager,
|
||||
pub(super) foreground_stack: ForegroundStack,
|
||||
pub(super) game_lifecycle_events: Vec<GameLifecycleEvent>,
|
||||
pub(super) window_manager: WindowManager,
|
||||
pub(super) log_service: LogService,
|
||||
pub(super) fs: VirtualFS,
|
||||
@@ -36,6 +39,7 @@ impl SystemOS {
|
||||
process_manager: ProcessManager::new(),
|
||||
task_manager: TaskManager::new(),
|
||||
foreground_stack: ForegroundStack::new(),
|
||||
game_lifecycle_events: Vec::new(),
|
||||
window_manager: WindowManager::new(),
|
||||
log_service,
|
||||
fs: VirtualFS::new(),
|
||||
@@ -136,7 +140,7 @@ impl SystemOS {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::os::{LifecycleError, LifecycleOperation};
|
||||
use crate::os::{GameLifecycleEventKind, LifecycleError, LifecycleOperation};
|
||||
use crate::process::ProcessState;
|
||||
use crate::services::foreground::{ForegroundOwner, ResidentGame, ResidentGameState};
|
||||
use crate::task::{TaskId, TaskState};
|
||||
@@ -195,12 +199,30 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn home_request_moves_game_to_resident_suspended_and_hub_foreground() {
|
||||
fn home_request_notifies_game_before_budget_suspends_it() {
|
||||
let mut os = SystemOS::new(None);
|
||||
let task_id = os.sessions().create_vm_game_task(42, "Sector Crawl");
|
||||
|
||||
os.lifecycle().request_home_from_game(task_id).expect("home request should succeed");
|
||||
|
||||
assert_eq!(os.lifecycle().foreground_owner(), ForegroundOwner::Game(task_id));
|
||||
assert_eq!(
|
||||
os.lifecycle().resident_game(),
|
||||
Some(ResidentGame {
|
||||
task_id,
|
||||
state: ResidentGameState::PauseRequested { remaining_ticks: 1 },
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
os.lifecycle().pending_game_lifecycle_events()[0].kind,
|
||||
GameLifecycleEventKind::Pause
|
||||
);
|
||||
assert_eq!(
|
||||
os.task_manager.get(task_id).expect("task should exist").state,
|
||||
TaskState::Foreground
|
||||
);
|
||||
|
||||
assert!(os.lifecycle().advance_game_pause_budget(task_id).expect("budget should advance"));
|
||||
assert_eq!(os.lifecycle().foreground_owner(), ForegroundOwner::Hub);
|
||||
assert_eq!(
|
||||
os.lifecycle().resident_game(),
|
||||
@@ -218,6 +240,7 @@ mod tests {
|
||||
let mut os = SystemOS::new(None);
|
||||
let game = os.sessions().create_vm_game_task(42, "Sector Crawl");
|
||||
os.lifecycle().request_home_from_game(game).expect("home request should succeed");
|
||||
os.lifecycle().advance_game_pause_budget(game).expect("budget should expire");
|
||||
let shell = os.sessions().create_vm_shell_task(7, "Settings");
|
||||
|
||||
assert_eq!(os.lifecycle().foreground_owner(), ForegroundOwner::Shell(shell));
|
||||
@@ -284,6 +307,10 @@ mod tests {
|
||||
TaskState::Foreground
|
||||
);
|
||||
assert_eq!(process_state_for_task(&os, task_id), ProcessState::Running);
|
||||
assert_eq!(
|
||||
os.lifecycle().pending_game_lifecycle_events().last().map(|event| event.kind),
|
||||
Some(GameLifecycleEventKind::ResumeForeground)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user