[domistream] Tests: rustfmt

This commit is contained in:
2026-11-25 12:52:38 +01:00
parent 948f446a13
commit da1f3afd52
16 changed files with 1015 additions and 293 deletions
+37 -9
View File
@@ -84,9 +84,11 @@ fn check(expect: &[AExpect], want: &[Want], r: &Run) {
let mut prev: Option<usize> = None;
for e in &r.events {
let (seq, i) = match e {
AudioEvent::Packet { sequence, .. } | AudioEvent::Lost { sequence } => {
(*sequence, *pos.get(sequence).unwrap_or_else(|| panic!("event for sequence {sequence} that was never a data packet")))
}
AudioEvent::Packet { sequence, .. } | AudioEvent::Lost { sequence } => (
*sequence,
*pos.get(sequence)
.unwrap_or_else(|| panic!("event for sequence {sequence} that was never a data packet")),
),
};
assert!(!seen[i], "two events for sequence {seq}");
assert!(prev.is_none_or(|p| i > p), "sequence {seq} out of order");
@@ -120,7 +122,14 @@ fn block_want(arrived: &[bool; 6], fec: bool) -> [Want; 4] {
}
/// Blocks `1..blocks-1` lose what `lose(block, index)` says; the first and last blocks arrive whole.
fn scenario(h: &AudioHost, seed: u64, first_seq: u16, blocks: usize, fec: bool, lose: impl Fn(usize, usize) -> bool) -> (Vec<AExpect>, Vec<Want>, Vec<Vec<u8>>) {
fn scenario(
h: &AudioHost,
seed: u64,
first_seq: u16,
blocks: usize,
fec: bool,
lose: impl Fn(usize, usize) -> bool,
) -> (Vec<AExpect>, Vec<Want>, Vec<Vec<u8>>) {
let mut rng = SeqRng::new(seed);
let (packets, expect) = h.blocks(&mut rng, first_seq, 0x7000_0000, blocks);
let mut want = Vec::new();
@@ -248,7 +257,9 @@ fn far_past_and_far_future() {
for e in &r.events {
if let AudioEvent::Packet { sequence, opus, .. } = e {
assert!(!(600..604).contains(sequence), "far-past sequence {sequence} played");
let want = by_seq.get(sequence).unwrap_or_else(|| panic!("a packet for sequence {sequence} that only strays carried"));
let want = by_seq
.get(sequence)
.unwrap_or_else(|| panic!("a packet for sequence {sequence} that only strays carried"));
assert_eq!(opus, &want.opus);
if (1000..1012).contains(sequence) {
first_blocks += 1;
@@ -322,11 +333,18 @@ fn undecryptable_data_is_dropped_and_rebuilt() {
#[test]
fn config_refusals() {
assert_err!(AudioDepacketizer::new(AudioConfig { packet_duration_ms: 0, ..config(true, AudioFec::Disabled) }), Error::Malformed { .. });
assert_err!(
AudioDepacketizer::new(AudioConfig { packet_duration_ms: 0, ..config(true, AudioFec::Disabled) }),
Error::Malformed { .. }
);
let mut zero = audio_test_matrix();
zero[5] = 0;
for bad in [zero, [1; 8], [1, 2, 3, 4, 2, 4, 6, 8], [0; 8]] {
assert_err!(AudioDepacketizer::new(config(true, AudioFec::ParityMatrix(bad))), Error::Malformed { .. }, "{bad:?} is not MDS");
assert_err!(
AudioDepacketizer::new(config(true, AudioFec::ParityMatrix(bad))),
Error::Malformed { .. },
"{bad:?} is not MDS"
);
}
assert!(AudioDepacketizer::new(config(false, AudioFec::ParityMatrix(audio_test_matrix()))).is_ok());
}
@@ -334,9 +352,19 @@ fn config_refusals() {
#[test]
fn push_sizes() {
let mut d = AudioDepacketizer::new(config(true, AudioFec::Disabled)).unwrap();
assert_too_large!(d.push(Instant::ZERO, &vec![0x80; MAX_AUDIO_PACKET_BYTES + 1]), MAX_AUDIO_PACKET_BYTES, MAX_AUDIO_PACKET_BYTES + 1);
assert_too_large!(
d.push(Instant::ZERO, &vec![0x80; MAX_AUDIO_PACKET_BYTES + 1]),
MAX_AUDIO_PACKET_BYTES,
MAX_AUDIO_PACKET_BYTES + 1
);
assert_too_large!(d.push(Instant::ZERO, &vec![0x80; 1 << 20]), MAX_AUDIO_PACKET_BYTES, 1 << 20);
for g in [vec![], vec![0x80], vec![0x80, 97, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], vec![0xFF; 40], vec![0x80; MAX_AUDIO_PACKET_BYTES]] {
for g in [
vec![],
vec![0x80],
vec![0x80, 97, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
vec![0xFF; 40],
vec![0x80; MAX_AUDIO_PACKET_BYTES],
] {
assert_eq!(d.push(Instant::ZERO, &g), Ok(()));
}
assert_eq!(d.stats().packets_dropped, 5);