Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
snendev committed Aug 22, 2024
1 parent 5b388d1 commit efc0013
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion tests/input_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use bevy::prelude::*;

use bevy::window::WindowPlugin;
use leafwing_input_playback::frame_counting::FrameCount;
use leafwing_input_playback::input_capture::BeginInputCapture;
use leafwing_input_playback::input_capture::{InputCapturePlugin, InputModesCaptured};
use leafwing_input_playback::timestamped_input::{
InputEvent, TimestampedInputEvent, TimestampedInputs,
Expand Down Expand Up @@ -41,7 +42,7 @@ fn capture_app() -> App {
InputPlugin,
InputCapturePlugin,
));

app.world_mut().send_event(BeginInputCapture::default());
app
}

Expand Down
20 changes: 13 additions & 7 deletions tests/input_playback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use bevy::window::WindowPlugin;
use leafwing_input_playback::frame_counting::FrameCount;
use leafwing_input_playback::input_capture::InputCapturePlugin;
use leafwing_input_playback::input_capture::InputModesCaptured;
use leafwing_input_playback::input_playback::BeginInputPlayback;
use leafwing_input_playback::input_playback::InputPlaybackPlugin;
use leafwing_input_playback::input_playback::PlaybackStrategy;
use leafwing_input_playback::timestamped_input::TimestampedInputs;
Expand Down Expand Up @@ -44,7 +45,10 @@ fn playback_app(strategy: PlaybackStrategy) -> App {
let mut registry = app.world_mut().resource_mut::<EventRegistry>();
registry.should_update = ShouldUpdateEvents::Always;

*app.world_mut().resource_mut::<PlaybackStrategy>() = strategy;
app.world_mut().send_event(BeginInputPlayback {
playback_strategy: strategy,
..Default::default()
});

app
}
Expand Down Expand Up @@ -74,7 +78,7 @@ fn minimal_playback() {
let input_events = app.world().resource::<Events<KeyboardInput>>();
assert_eq!(input_events.len(), 0);

*app.world_mut().resource_mut::<TimestampedInputs>() = simple_timestamped_input();
app.insert_resource(simple_timestamped_input());

app.update();

Expand All @@ -97,6 +101,7 @@ fn capture_and_playback() {
let mut app = playback_app(PlaybackStrategy::default());
app.add_plugins(InputCapturePlugin);
app.insert_resource(PlaybackStrategy::Paused);
app.insert_resource(TimestampedInputs::default());

let mut input_events = app.world_mut().resource_mut::<Events<KeyboardInput>>();
input_events.send(TEST_PRESS);
Expand Down Expand Up @@ -133,7 +138,8 @@ fn repeated_playback() {
let input_events = app.world().resource::<Events<KeyboardInput>>();
assert_eq!(input_events.len(), 0);

*app.world_mut().resource_mut::<TimestampedInputs>() = simple_timestamped_input();
app.insert_resource(simple_timestamped_input());

for _ in 1..10 {
app.update();
}
Expand All @@ -156,7 +162,7 @@ fn repeated_playback() {
#[test]
fn playback_strategy_paused() {
let mut app = playback_app(PlaybackStrategy::Paused);
*app.world_mut().resource_mut::<TimestampedInputs>() = complex_timestamped_input();
app.insert_resource(complex_timestamped_input());

let timestamped_input = app.world().resource::<TimestampedInputs>();
assert_eq!(timestamped_input.cursor, 0);
Expand All @@ -172,7 +178,7 @@ fn playback_strategy_paused() {
#[test]
fn playback_strategy_frame() {
let mut app = playback_app(PlaybackStrategy::FrameCount);
*app.world_mut().resource_mut::<TimestampedInputs>() = complex_timestamped_input();
app.insert_resource(complex_timestamped_input());

let timestamped_input = app.world().resource::<TimestampedInputs>();
assert_eq!(timestamped_input.cursor, 0);
Expand All @@ -195,7 +201,7 @@ fn playback_strategy_frame() {
fn playback_strategy_frame_range_once() {
let strategy = PlaybackStrategy::FrameRangeOnce(FrameCount(2), FrameCount(5));
let mut app = playback_app(strategy);
*app.world_mut().resource_mut::<TimestampedInputs>() = complex_timestamped_input();
app.insert_resource(complex_timestamped_input());

let timestamped_input = app.world().resource::<TimestampedInputs>();
assert_eq!(timestamped_input.cursor, 0);
Expand Down Expand Up @@ -234,7 +240,7 @@ fn playback_strategy_frame_range_once() {
fn playback_strategy_frame_range_loop() {
let strategy = PlaybackStrategy::FrameRangeLoop(FrameCount(2), FrameCount(5));
let mut app = playback_app(strategy);
*app.world_mut().resource_mut::<TimestampedInputs>() = complex_timestamped_input();
app.insert_resource(complex_timestamped_input());

let timestamped_input = app.world().resource::<TimestampedInputs>();
assert_eq!(timestamped_input.cursor, 0);
Expand Down

0 comments on commit efc0013

Please sign in to comment.