Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bmisiak committed Feb 26, 2024
1 parent dc3a302 commit aa6e8fa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/amx_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ pub(crate) struct VariadicAmxArguments {
}

impl VariadicAmxArguments {
#[cfg(test)]
pub fn empty() -> Self {
Self { inner: vec![] }
}

fn get_type_letters(
args: &mut samp::args::Args,
skipped_args: usize,
Expand Down
42 changes: 37 additions & 5 deletions src/scheduling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ fn deschedule_next_due(next_due: &NextDue) -> Result<(), TriggeringError> {
Ok(())
}

fn change_next_trigger(
key: usize,
next_trigger: Instant,
) -> Result<(), TriggeringError> {
fn change_next_trigger(key: usize, next_trigger: Instant) -> Result<(), TriggeringError> {
QUEUE.with(|q| {
q.try_borrow_mut()
.context(ReschedulingBorrowSnafu)?
Expand Down Expand Up @@ -165,7 +162,7 @@ impl NextDue {
change_next_trigger(self.key, next_trigger)?;

TIMERS.with_borrow_mut(|t| {
let timer = t.get_mut(self.key).context(ExpectedInSlabSnafu)?;
let timer: &mut Timer = t.get_mut(self.key).context(ExpectedInSlabSnafu)?;
prep(timer).context(StackPushSnafu)
})
} else {
Expand All @@ -188,3 +185,38 @@ pub(crate) fn next_timer_due_for_triggering(now: Instant) -> Option<NextDue> {
_ => None,
})
}

#[cfg(test)]
mod test {
use std::ptr::null_mut;

use samp::raw::types::AMX;

use crate::Timer;
use crate::{amx_arguments::VariadicAmxArguments, scheduling::next_timer_due_for_triggering};

use super::{insert_and_schedule_timer, TimerScheduling};

fn mock_no_arg_timer() -> Timer {
let amx_pointer: *mut AMX = null_mut();
Timer {
passed_arguments: VariadicAmxArguments::empty(),
amx_callback_index: samp::consts::AmxExecIdx::Continue,
amx_identifier: amx_pointer.into(),
}
}

#[test]
fn hello() {
insert_and_schedule_timer(
mock_no_arg_timer(),
TimerScheduling {
next_trigger: std::time::Instant::now(),
repeat: super::Repeat::DontRepeat,
},
);
let next_due = next_timer_due_for_triggering(std::time::Instant::now());

assert!(next_due.is_some());
}
}

0 comments on commit aa6e8fa

Please sign in to comment.