implements PLN-0103
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
use crate::hardware::Hardware;
|
||||
use crate::memory_banks::MemoryBanks;
|
||||
use prometeu_hal::{
|
||||
AssetStoragePlatform, AudioPlatform, Game2DFrameComposer, InputPlatform, RenderBackend,
|
||||
RenderSubmissionSink, RuntimePlatform, TelemetryPlatform,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct TestPlatform {
|
||||
hardware: Hardware,
|
||||
}
|
||||
|
||||
impl Default for TestPlatform {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl TestPlatform {
|
||||
pub fn new() -> Self {
|
||||
Self { hardware: Hardware::new() }
|
||||
}
|
||||
|
||||
pub fn new_with_memory_banks(memory_banks: Arc<MemoryBanks>) -> Self {
|
||||
Self { hardware: Hardware::new_with_memory_banks(memory_banks) }
|
||||
}
|
||||
|
||||
pub fn local_hardware(&self) -> &Hardware {
|
||||
&self.hardware
|
||||
}
|
||||
|
||||
pub fn local_hardware_mut(&mut self) -> &mut Hardware {
|
||||
&mut self.hardware
|
||||
}
|
||||
}
|
||||
|
||||
impl RuntimePlatform for TestPlatform {
|
||||
fn render_submission_sink(&mut self) -> &mut dyn RenderSubmissionSink {
|
||||
self.hardware.render_submission_sink()
|
||||
}
|
||||
|
||||
fn render_backend(&mut self) -> &mut dyn RenderBackend {
|
||||
self.hardware.render_backend()
|
||||
}
|
||||
|
||||
fn game2d_frame_composer(&mut self) -> &mut dyn Game2DFrameComposer {
|
||||
self.hardware.game2d_frame_composer()
|
||||
}
|
||||
|
||||
fn audio(&self) -> &dyn AudioPlatform {
|
||||
self.hardware.audio()
|
||||
}
|
||||
|
||||
fn audio_mut(&mut self) -> &mut dyn AudioPlatform {
|
||||
self.hardware.audio_mut()
|
||||
}
|
||||
|
||||
fn input(&self) -> &dyn InputPlatform {
|
||||
self.hardware.input()
|
||||
}
|
||||
|
||||
fn input_mut(&mut self) -> &mut dyn InputPlatform {
|
||||
self.hardware.input_mut()
|
||||
}
|
||||
|
||||
fn assets(&self) -> &dyn AssetStoragePlatform {
|
||||
self.hardware.assets()
|
||||
}
|
||||
|
||||
fn assets_mut(&mut self) -> &mut dyn AssetStoragePlatform {
|
||||
self.hardware.assets_mut()
|
||||
}
|
||||
|
||||
fn telemetry(&self) -> &dyn TelemetryPlatform {
|
||||
self.hardware.telemetry()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use prometeu_hal::{FrameId, Game2DFramePacket, RenderSubmission};
|
||||
|
||||
#[test]
|
||||
fn test_platform_initializes_required_facades() {
|
||||
let mut platform = TestPlatform::new();
|
||||
|
||||
platform.game2d_frame_composer().begin_frame();
|
||||
platform
|
||||
.render_submission_sink()
|
||||
.submit_render_submission(RenderSubmission::game2d(
|
||||
FrameId::ZERO,
|
||||
Game2DFramePacket::default(),
|
||||
))
|
||||
.expect("test platform render sink should accept local submission");
|
||||
assert!(!platform.audio().is_playing(0));
|
||||
assert!(!platform.input().pad().any());
|
||||
assert!(platform.telemetry().telemetry_snapshot().is_none());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user