mirror of
https://github.com/RustAudio/rodio
synced 2024-12-13 13:42:34 +00:00
Fix periodic test module
Add a simple test of periodic_access.
This commit is contained in:
parent
dba627a1b4
commit
011090034f
1 changed files with 31 additions and 0 deletions
|
@ -116,3 +116,34 @@ where
|
||||||
self.input.total_duration()
|
self.input.total_duration()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use buffer::SamplesBuffer;
|
||||||
|
use std::time::Duration;
|
||||||
|
use source::Source;
|
||||||
|
use std::cell::RefCell;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn stereo_access() {
|
||||||
|
// Stereo, 1Hz audio buffer
|
||||||
|
let inner = SamplesBuffer::new(2, 1, vec![10i16, -10, 10, -10, 20, -20]);
|
||||||
|
|
||||||
|
let cnt = RefCell::new(0);
|
||||||
|
|
||||||
|
let mut source = inner.periodic_access(Duration::from_millis(1000), |_src| {
|
||||||
|
*cnt.borrow_mut() += 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_eq!(*cnt.borrow(), 0);
|
||||||
|
// Always called on first access!
|
||||||
|
assert_eq!(source.next(), Some(10)); assert_eq!(*cnt.borrow(), 1);
|
||||||
|
// Called every 1 second afterwards
|
||||||
|
assert_eq!(source.next(), Some(-10)); assert_eq!(*cnt.borrow(), 1);
|
||||||
|
assert_eq!(source.next(), Some(10)); assert_eq!(*cnt.borrow(), 2);
|
||||||
|
assert_eq!(source.next(), Some(-10)); assert_eq!(*cnt.borrow(), 2);
|
||||||
|
assert_eq!(source.next(), Some(20)); assert_eq!(*cnt.borrow(), 3);
|
||||||
|
assert_eq!(source.next(), Some(-20)); assert_eq!(*cnt.borrow(), 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue