Struct race_test::prelude::TestHandler
source · pub struct TestHandler<H>where
H: GameHandler,{ /* private fields */ }Expand description
A wrapped handler for testing This handler includes the general event handling, which is necessary for integration test.
Implementations§
source§impl<H: GameHandler> TestHandler<H>
impl<H: GameHandler> TestHandler<H>
pub fn init_state( context: &mut GameContext, game_account: &GameAccount ) -> Result<Self>
pub fn handle_event( &mut self, context: &mut GameContext, event: &Event ) -> Result<()>
sourcepub fn handle_dispatch_event(&mut self, context: &mut GameContext) -> Result<()>
pub fn handle_dispatch_event(&mut self, context: &mut GameContext) -> Result<()>
Find the event which is going to be disptached in the context, then process it. In real cases, the disptached event will be handled by an event loop. We use this function to simulate such cases, since we don’t have an event loop in tests.
sourcepub fn handle_until_no_events(
&mut self,
context: &mut GameContext,
event: &Event,
clients: Vec<&mut TestClient>
) -> Result<()>
pub fn handle_until_no_events( &mut self, context: &mut GameContext, event: &Event, clients: Vec<&mut TestClient> ) -> Result<()>
This fn keeps handling events of the following two types, until there is none:
- Event dispatched from within the (updated) context: context.dispatch
- Event dispatched by clients after they see the updated context
pub fn get_state(&self) -> &H
pub fn get_mut_state(&mut self) -> &mut H
Auto Trait Implementations§
impl<H> RefUnwindSafe for TestHandler<H>where H: RefUnwindSafe,
impl<H> Send for TestHandler<H>where H: Send,
impl<H> Sync for TestHandler<H>where H: Sync,
impl<H> Unpin for TestHandler<H>where H: Unpin,
impl<H> UnwindSafe for TestHandler<H>where H: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more