From 2740d3dd45500ac2d304c47c229a7859a32fe65f Mon Sep 17 00:00:00 2001 From: mnovak Date: Wed, 25 Nov 2026 13:08:24 +0100 Subject: [PATCH] [domistream] Tests: first compile, clippy clean Temporaries borrowed past their statement (control, media), clippy's is_multiple_of, needless index loop and type complexity. input.rs: the MOUSE_MOVE_ABS builder dropped the y field; the PROTOCOL.md cross-check would have caught it at runtime. --- crates/domistream/tests/alloc_caps.rs | 11 ++++++++--- crates/domistream/tests/audio.rs | 6 +++--- crates/domistream/tests/common/mod.rs | 2 +- crates/domistream/tests/control.rs | 3 ++- crates/domistream/tests/input.rs | 2 +- crates/domistream/tests/media.rs | 3 ++- crates/domistream/tests/pairing.rs | 4 ++-- 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/crates/domistream/tests/alloc_caps.rs b/crates/domistream/tests/alloc_caps.rs index 316c592..be4eafe 100644 --- a/crates/domistream/tests/alloc_caps.rs +++ b/crates/domistream/tests/alloc_caps.rs @@ -42,8 +42,13 @@ fn check(what: &str, input: &[u8], f: impl FnOnce(&[u8])) { ); } -fn lying_inputs() -> Vec<(&'static str, Vec, fn(&[u8]))> { - let mut v: Vec<(&'static str, Vec, fn(&[u8]))> = Vec::new(); +/// A parser under test: a name and a call that consumes the input. +type Parser = (&'static str, fn(&[u8])); +/// A parser and the hostile input for it. +type Case = (&'static str, Vec, fn(&[u8])); + +fn lying_inputs() -> Vec { + let mut v: Vec = Vec::new(); // RTSP: Content-Length claims 4 GiB. let rtsp = b"RTSP/1.0 200 OK\r\nCSeq: 1\r\nContent-Length: 4294967295\r\n\r\nabc".to_vec(); @@ -220,7 +225,7 @@ fn parsers_never_allocate_past_their_caps() { // Arbitrary inputs to every stateless parser. let mut runner = TestRunner::new(Config { cases: 400, ..Config::default() }); - let parsers: Vec<(&str, fn(&[u8]))> = vec![ + let parsers: Vec = vec![ ("xml", |b| { let _ = domistream::http::xml::parse(b); }), diff --git a/crates/domistream/tests/audio.rs b/crates/domistream/tests/audio.rs index 1547216..655676b 100644 --- a/crates/domistream/tests/audio.rs +++ b/crates/domistream/tests/audio.rs @@ -204,7 +204,7 @@ fn random_losses_over_many_blocks() { fn sequence_wraps() { // Blocks from 0xFFF0 through 0x000F: data sequence 0xFFFF -> 0, base sequence wrap, rikeyid + seq wrap. let h = host(true, audio_test_matrix()); - let (expect, want, dg) = scenario(&h, 20, 0xFFF0, 8, true, |b, i| (b + i) % 5 == 0); + let (expect, want, dg) = scenario(&h, 20, 0xFFF0, 8, true, |b, i| (b + i).is_multiple_of(5)); assert!(expect.iter().any(|e| e.sequence == 0xFFFF) && expect.iter().any(|e| e.sequence == 0)); check(&expect, &want, &run(config(true, AudioFec::ParityMatrix(h.matrix)), &dg)); } @@ -212,7 +212,7 @@ fn sequence_wraps() { #[test] fn duplicates_are_dropped() { let h = host(true, audio_test_matrix()); - let (expect, want, dg) = scenario(&h, 21, 0, 10, true, |b, i| (b * 7 + i) % 6 == 0); + let (expect, want, dg) = scenario(&h, 21, 0, 10, true, |b, i| (b * 7 + i).is_multiple_of(6)); let doubled: Vec> = dg.iter().flat_map(|g| [g.clone(), g.clone()]).collect(); let r = run(config(true, AudioFec::ParityMatrix(h.matrix)), &doubled); check(&expect, &want, &r); @@ -223,7 +223,7 @@ fn duplicates_are_dropped() { fn reordered_within_and_across_blocks() { let h = host(true, audio_test_matrix()); for seed in 30..36u64 { - let (expect, want, mut dg) = scenario(&h, seed, 0, 12, true, |b, i| (b + i + seed as usize) % 7 == 0); + let (expect, want, mut dg) = scenario(&h, seed, 0, 12, true, |b, i| (b + i + seed as usize).is_multiple_of(7)); let mut rng = SeqRng::new(seed); let mut i = 6; // the first block stays first, so the stream has a known start while i < dg.len() { diff --git a/crates/domistream/tests/common/mod.rs b/crates/domistream/tests/common/mod.rs index 1fc3d07..914ced6 100644 --- a/crates/domistream/tests/common/mod.rs +++ b/crates/domistream/tests/common/mod.rs @@ -139,7 +139,7 @@ pub fn hex(s: &str) -> Vec { if s == "-" { return Vec::new(); } - assert!(s.len() % 2 == 0, "odd hex length"); + assert!(s.len().is_multiple_of(2), "odd hex length"); (0..s.len()).step_by(2).map(|i| u8::from_str_radix(&s[i..i + 2], 16).expect("hex digit")).collect() } diff --git a/crates/domistream/tests/control.rs b/crates/domistream/tests/control.rs index 775d9fc..2967d3d 100644 --- a/crates/domistream/tests/control.rs +++ b/crates/domistream/tests/control.rs @@ -225,7 +225,8 @@ fn msg(ty: u16, body: &[u8]) -> Vec { #[test] fn message_split() { - let r = parse_message(&msg(0x010b, &[1, 2, 3])).unwrap(); + let m = msg(0x010b, &[1, 2, 3]); + let r = parse_message(&m).unwrap(); assert_eq!(r.message_type, 0x010b); assert_eq!(r.body, &[1, 2, 3]); assert_eq!(parse_message(&msg(0x7777, &[])).unwrap().body, &[] as &[u8]); diff --git a/crates/domistream/tests/input.rs b/crates/domistream/tests/input.rs index 4bbf2ef..fa669a4 100644 --- a/crates/domistream/tests/input.rs +++ b/crates/domistream/tests/input.rs @@ -33,7 +33,7 @@ fn rel(dx: i16, dy: i16) -> Vec { } fn abs(x: i16, y: i16, w: u16, h: u16) -> Vec { - input_message(0x05, &[&be16(x)[..], &[0, 0], &w.to_be_bytes(), &h.to_be_bytes()].concat()) + input_message(0x05, &[&be16(x)[..], &be16(y), &[0, 0], &w.to_be_bytes(), &h.to_be_bytes()].concat()) } fn button(down: bool, b: u8) -> Vec { diff --git a/crates/domistream/tests/media.rs b/crates/domistream/tests/media.rs index 43fdd6c..e1d60a2 100644 --- a/crates/domistream/tests/media.rs +++ b/crates/domistream/tests/media.rs @@ -60,7 +60,8 @@ fn video_packet_fields() { // Parity shard 5 of 4 + 2 is in range. assert!(parse_video_packet(&video_packet_bytes(1, 0, 0, 0, 0, fec_info(50, 5, 4), &payload)).is_ok()); // Bits 0-3 of fecInfo are not part of any field. - let v = parse_video_packet(&video_packet_bytes(1, 0, 0, 1, 0, fec_info(50, 0, 4) | 0xF, &payload)).unwrap(); + let p = video_packet_bytes(1, 0, 0, 1, 0, fec_info(50, 0, 4) | 0xF, &payload); + let v = parse_video_packet(&p).unwrap(); assert_eq!((v.nv.fec.shard_index, v.nv.fec.data_shards, v.nv.fec.fec_percentage), (0, 4, 50)); } diff --git a/crates/domistream/tests/pairing.rs b/crates/domistream/tests/pairing.rs index 64dbc66..5ef0f10 100644 --- a/crates/domistream/tests/pairing.rs +++ b/crates/domistream/tests/pairing.rs @@ -248,9 +248,9 @@ fn paired_needs_exactly_five_answers() { #[test] fn a_bare_paired_answer_cannot_skip_any_step() { // `1` is all steps 4 and 5 need. Fed early, it must fail, never jump ahead. - for steps in 0..3 { + for (steps, state) in STATES.iter().enumerate().take(3) { let (mut s, mut rng, id) = session_after(steps); - assert_eq!(s.state(), STATES[steps]); + assert_eq!(s.state(), *state); expect_failure(&mut s, &id, &mut rng, 200, &resp_ok(), PairingFailure::MalformedAnswer); } }