73 lines
2.0 KiB
Rust
73 lines
2.0 KiB
Rust
use fader_core::{
|
|
AdapterCommand, BackendEpoch, ChannelGains, Gain, Mute, OperationId, StreamHandle,
|
|
};
|
|
use volume_lib::{AdapterQueue, Enqueue};
|
|
|
|
fn stream(id: u64) -> StreamHandle {
|
|
StreamHandle::new(BackendEpoch::new(1), id, 1)
|
|
}
|
|
fn volume(operation: u64, stream: StreamHandle, value: f64) -> AdapterCommand {
|
|
AdapterCommand::SetVolume {
|
|
operation: OperationId::new(operation),
|
|
stream,
|
|
channels: ChannelGains::new(vec![Gain::new(value).unwrap()]).unwrap(),
|
|
}
|
|
}
|
|
fn mute(operation: u64, muted: Mute) -> AdapterCommand {
|
|
AdapterCommand::SetMute {
|
|
operation: OperationId::new(operation),
|
|
stream: stream(1),
|
|
muted,
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn volume_burst_stays_bounded_and_ends_at_latest_value() {
|
|
let mut queue = AdapterQueue::new(2);
|
|
assert_eq!(queue.push(volume(1, stream(1), 0.1)), Enqueue::Queued);
|
|
for operation in 2_u32..=100 {
|
|
assert!(matches!(
|
|
queue.push(volume(
|
|
u64::from(operation),
|
|
stream(1),
|
|
f64::from(operation) / 100.0
|
|
)),
|
|
Enqueue::Coalesced { .. }
|
|
));
|
|
}
|
|
assert_eq!(queue.len(), 1);
|
|
let AdapterCommand::SetVolume {
|
|
operation,
|
|
channels,
|
|
..
|
|
} = queue.pop().unwrap()
|
|
else {
|
|
panic!("volume command");
|
|
};
|
|
assert_eq!(operation, OperationId::new(100));
|
|
assert_eq!(channels.maximum(), Gain::UNITY);
|
|
}
|
|
|
|
#[test]
|
|
fn mute_edges_are_ordered_and_never_silently_coalesced() {
|
|
let mut queue = AdapterQueue::new(2);
|
|
assert_eq!(queue.push(mute(1, Mute::Muted)), Enqueue::Queued);
|
|
assert_eq!(queue.push(mute(2, Mute::Unmuted)), Enqueue::Queued);
|
|
assert_eq!(queue.push(mute(3, Mute::Muted)), Enqueue::Overflow);
|
|
assert!(queue.faulted());
|
|
assert!(matches!(
|
|
queue.pop(),
|
|
Some(AdapterCommand::SetMute {
|
|
muted: Mute::Muted,
|
|
..
|
|
})
|
|
));
|
|
assert!(matches!(
|
|
queue.pop(),
|
|
Some(AdapterCommand::SetMute {
|
|
muted: Mute::Unmuted,
|
|
..
|
|
})
|
|
));
|
|
}
|