[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.
This commit is contained in:
@@ -42,8 +42,13 @@ fn check(what: &str, input: &[u8], f: impl FnOnce(&[u8])) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lying_inputs() -> Vec<(&'static str, Vec<u8>, fn(&[u8]))> {
|
/// A parser under test: a name and a call that consumes the input.
|
||||||
let mut v: Vec<(&'static str, Vec<u8>, fn(&[u8]))> = Vec::new();
|
type Parser = (&'static str, fn(&[u8]));
|
||||||
|
/// A parser and the hostile input for it.
|
||||||
|
type Case = (&'static str, Vec<u8>, fn(&[u8]));
|
||||||
|
|
||||||
|
fn lying_inputs() -> Vec<Case> {
|
||||||
|
let mut v: Vec<Case> = Vec::new();
|
||||||
|
|
||||||
// RTSP: Content-Length claims 4 GiB.
|
// 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();
|
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.
|
// Arbitrary inputs to every stateless parser.
|
||||||
let mut runner = TestRunner::new(Config { cases: 400, ..Config::default() });
|
let mut runner = TestRunner::new(Config { cases: 400, ..Config::default() });
|
||||||
let parsers: Vec<(&str, fn(&[u8]))> = vec![
|
let parsers: Vec<Parser> = vec![
|
||||||
("xml", |b| {
|
("xml", |b| {
|
||||||
let _ = domistream::http::xml::parse(b);
|
let _ = domistream::http::xml::parse(b);
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ fn random_losses_over_many_blocks() {
|
|||||||
fn sequence_wraps() {
|
fn sequence_wraps() {
|
||||||
// Blocks from 0xFFF0 through 0x000F: data sequence 0xFFFF -> 0, base sequence wrap, rikeyid + seq wrap.
|
// Blocks from 0xFFF0 through 0x000F: data sequence 0xFFFF -> 0, base sequence wrap, rikeyid + seq wrap.
|
||||||
let h = host(true, audio_test_matrix());
|
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));
|
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));
|
check(&expect, &want, &run(config(true, AudioFec::ParityMatrix(h.matrix)), &dg));
|
||||||
}
|
}
|
||||||
@@ -212,7 +212,7 @@ fn sequence_wraps() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn duplicates_are_dropped() {
|
fn duplicates_are_dropped() {
|
||||||
let h = host(true, audio_test_matrix());
|
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<Vec<u8>> = dg.iter().flat_map(|g| [g.clone(), g.clone()]).collect();
|
let doubled: Vec<Vec<u8>> = dg.iter().flat_map(|g| [g.clone(), g.clone()]).collect();
|
||||||
let r = run(config(true, AudioFec::ParityMatrix(h.matrix)), &doubled);
|
let r = run(config(true, AudioFec::ParityMatrix(h.matrix)), &doubled);
|
||||||
check(&expect, &want, &r);
|
check(&expect, &want, &r);
|
||||||
@@ -223,7 +223,7 @@ fn duplicates_are_dropped() {
|
|||||||
fn reordered_within_and_across_blocks() {
|
fn reordered_within_and_across_blocks() {
|
||||||
let h = host(true, audio_test_matrix());
|
let h = host(true, audio_test_matrix());
|
||||||
for seed in 30..36u64 {
|
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 rng = SeqRng::new(seed);
|
||||||
let mut i = 6; // the first block stays first, so the stream has a known start
|
let mut i = 6; // the first block stays first, so the stream has a known start
|
||||||
while i < dg.len() {
|
while i < dg.len() {
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ pub fn hex(s: &str) -> Vec<u8> {
|
|||||||
if s == "-" {
|
if s == "-" {
|
||||||
return Vec::new();
|
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()
|
(0..s.len()).step_by(2).map(|i| u8::from_str_radix(&s[i..i + 2], 16).expect("hex digit")).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -225,7 +225,8 @@ fn msg(ty: u16, body: &[u8]) -> Vec<u8> {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn message_split() {
|
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.message_type, 0x010b);
|
||||||
assert_eq!(r.body, &[1, 2, 3]);
|
assert_eq!(r.body, &[1, 2, 3]);
|
||||||
assert_eq!(parse_message(&msg(0x7777, &[])).unwrap().body, &[] as &[u8]);
|
assert_eq!(parse_message(&msg(0x7777, &[])).unwrap().body, &[] as &[u8]);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ fn rel(dx: i16, dy: i16) -> Vec<u8> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn abs(x: i16, y: i16, w: u16, h: u16) -> Vec<u8> {
|
fn abs(x: i16, y: i16, w: u16, h: u16) -> Vec<u8> {
|
||||||
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<u8> {
|
fn button(down: bool, b: u8) -> Vec<u8> {
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ fn video_packet_fields() {
|
|||||||
// Parity shard 5 of 4 + 2 is in range.
|
// 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());
|
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.
|
// 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));
|
assert_eq!((v.nv.fec.shard_index, v.nv.fec.data_shards, v.nv.fec.fec_percentage), (0, 4, 50));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -248,9 +248,9 @@ fn paired_needs_exactly_five_answers() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn a_bare_paired_answer_cannot_skip_any_step() {
|
fn a_bare_paired_answer_cannot_skip_any_step() {
|
||||||
// `<paired>1</paired>` is all steps 4 and 5 need. Fed early, it must fail, never jump ahead.
|
// `<paired>1</paired>` 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);
|
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);
|
expect_failure(&mut s, &id, &mut rng, 200, &resp_ok(), PairingFailure::MalformedAnswer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user