tests: Move TestLogBackend to backends/log.rs

This commit is contained in:
Nathan Adams 2023-11-09 13:00:53 +01:00
parent 6a413e28f7
commit 8a85a24213
4 changed files with 33 additions and 31 deletions

View File

@ -1,5 +1,7 @@
mod audio; mod audio;
mod log;
mod navigator; mod navigator;
pub use audio::TestAudioBackend; pub use audio::TestAudioBackend;
pub use log::TestLogBackend;
pub use navigator::TestNavigatorBackend; pub use navigator::TestNavigatorBackend;

View File

@ -0,0 +1,29 @@
use ruffle_core::backend::log::LogBackend;
use std::cell::RefCell;
use std::rc::Rc;
#[derive(Clone)]
pub struct TestLogBackend {
trace_output: Rc<RefCell<String>>,
}
impl Default for TestLogBackend {
fn default() -> Self {
Self {
trace_output: Rc::new(RefCell::new(String::new())),
}
}
}
impl TestLogBackend {
pub fn trace_output(self) -> String {
self.trace_output.take()
}
}
impl LogBackend for TestLogBackend {
fn avm_trace(&self, message: &str) {
self.trace_output.borrow_mut().push_str(message);
self.trace_output.borrow_mut().push('\n');
}
}

View File

@ -1,4 +1,4 @@
use crate::runner::TestLogBackend; use crate::backends::TestLogBackend;
use async_channel::Receiver; use async_channel::Receiver;
use ruffle_core::backend::log::LogBackend; use ruffle_core::backend::log::LogBackend;
use ruffle_core::backend::navigator::{ use ruffle_core::backend::navigator::{

View File

@ -1,11 +1,10 @@
use crate::backends::TestNavigatorBackend; use crate::backends::{TestLogBackend, TestNavigatorBackend};
use crate::fs_commands::{FsCommand, TestFsCommandProvider}; use crate::fs_commands::{FsCommand, TestFsCommandProvider};
use crate::image_trigger::ImageTrigger; use crate::image_trigger::ImageTrigger;
use crate::options::ImageComparison; use crate::options::ImageComparison;
use crate::test::Test; use crate::test::Test;
use crate::test_ui::TestUiBackend; use crate::test_ui::TestUiBackend;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use ruffle_core::backend::log::LogBackend;
use ruffle_core::backend::navigator::NullExecutor; use ruffle_core::backend::navigator::NullExecutor;
use ruffle_core::events::MouseButton as RuffleMouseButton; use ruffle_core::events::MouseButton as RuffleMouseButton;
use ruffle_core::events::{KeyCode, TextControlCode as RuffleTextControlCode}; use ruffle_core::events::{KeyCode, TextControlCode as RuffleTextControlCode};
@ -18,38 +17,10 @@ use ruffle_input_format::{
}; };
use ruffle_render_wgpu::descriptors::Descriptors; use ruffle_render_wgpu::descriptors::Descriptors;
use ruffle_socket_format::SocketEvent; use ruffle_socket_format::SocketEvent;
use std::cell::RefCell;
use std::path::Path; use std::path::Path;
use std::rc::Rc;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::time::Duration; use std::time::Duration;
#[derive(Clone)]
pub struct TestLogBackend {
trace_output: Rc<RefCell<String>>,
}
impl Default for TestLogBackend {
fn default() -> Self {
Self {
trace_output: Rc::new(RefCell::new(String::new())),
}
}
}
impl TestLogBackend {
pub fn trace_output(self) -> String {
self.trace_output.take()
}
}
impl LogBackend for TestLogBackend {
fn avm_trace(&self, message: &str) {
self.trace_output.borrow_mut().push_str(message);
self.trace_output.borrow_mut().push('\n');
}
}
/// Loads an SWF and runs it through the Ruffle core for a number of frames. /// Loads an SWF and runs it through the Ruffle core for a number of frames.
/// Tests that the trace output matches the given expected output. /// Tests that the trace output matches the given expected output.
pub fn run_swf( pub fn run_swf(