forge
Explore
Log in

Don't you dare go Hollow

U18: ec-riff rf64 tests trimmed to the RIFF/RF64 round trip and the manual 4 GiB test (synthetic per-field checks removed, no ffmpeg oracle touched)

Browse files at this commit

8cbf7363bf93a5a500d5f9eb4cb0e7f13164c7d9Ahmet Kaan GümüşParent: ae1754b
crates/ec-riff/tests/it/rf64.rsmodified+0 -86
@@ -22,10 +22,6 @@ fn le64(bytes: &[u8], at: usize) -> u64 {
22 u64::from_le_bytes(bytes[at..at + 8].try_into().unwrap())22 u64::from_le_bytes(bytes[at..at + 8].try_into().unwrap())
23 }23 }
24 24
25-fn le32(bytes: &[u8], at: usize) -> u32 {
26- u32::from_le_bytes(bytes[at..at + 4].try_into().unwrap())
27-}
28-
29 /// Write `frames` frames of a ramp and return the finished file.25 /// Write `frames` frames of a ramp and return the finished file.
30 fn write_file(s: WavSpec, frames: usize, options: WavOptions) -> Vec<u8> {26 fn write_file(s: WavSpec, frames: usize, options: WavOptions) -> Vec<u8> {
31 let mut w = WavWriter::with_options(Cursor::new(Vec::new()), s, options).unwrap();27 let mut w = WavWriter::with_options(Cursor::new(Vec::new()), s, options).unwrap();
@@ -44,42 +40,6 @@ fn opts(frames: u64, threshold: u64) -> WavOptions {
44 }40 }
45 }41 }
46 42
47-#[test]
48-fn over_threshold_writes_rf64_with_exact_ds64_sizes() {
49- let s = spec(2, 16);
50- let frames = 1000;
51- let bytes = write_file(s, frames, opts(frames as u64, 64));
52-
53- assert_eq!(&bytes[0..4], b"RF64");
54- assert_eq!(le32(&bytes, 4), u32::MAX, "RIFF size is ds64's to hold");
55- assert_eq!(&bytes[8..12], b"WAVE");
56- assert_eq!(&bytes[12..16], b"ds64");
57- assert_eq!(le32(&bytes, 16), 28, "ds64 body without a table");
58-
59- let data_bytes = (frames * 4) as u64;
60- assert_eq!(le64(&bytes, 20), bytes.len() as u64 - 8, "riffSize");
61- assert_eq!(le64(&bytes, 28), data_bytes, "dataSize");
62- assert_eq!(le64(&bytes, 36), frames as u64, "sampleCount");
63- assert_eq!(le32(&bytes, 44), 0, "tableLength");
64-
65- // Stereo 16-bit is a plain PCM fmt with no fact chunk, then data with the sentinel.
66- let fmt = 48;
67- assert_eq!(&bytes[fmt..fmt + 4], b"fmt ");
68- // The `data` id sits right before its payload, at a fixed distance from the end.
69- let data = bytes.len() - 8 - data_bytes as usize;
70- assert_eq!(&bytes[data..data + 4], b"data");
71- assert_eq!(
72- le32(&bytes, data + 4),
73- u32::MAX,
74- "data size is ds64's to hold"
75- );
76-
77- let mut r = WavReader::new(Cursor::new(&bytes[..])).unwrap();
78- assert_eq!(r.spec(), s);
79- assert_eq!(r.duration(), Some(frames as u64));
80- assert_eq!(r.read_all_i32().unwrap().len(), frames * 2);
81-}
82-
83 #[test]43 #[test]
84 fn rf64_samples_match_the_riff_file_for_the_same_input() {44 fn rf64_samples_match_the_riff_file_for_the_same_input() {
85 for (channels, bits) in [(1u16, 8u16), (6, 24), (2, 16), (8, 32)] {45 for (channels, bits) in [(1u16, 8u16), (6, 24), (2, 16), (8, 32)] {
@@ -101,52 +61,6 @@ fn rf64_samples_match_the_riff_file_for_the_same_input() {
101 }61 }
102 }62 }
103 63
104-#[test]
105-fn odd_rf64_data_gets_a_pad_byte_outside_its_size() {
106- let s = spec(1, 8);
107- let frames = 5;
108- let bytes = write_file(s, frames, opts(frames as u64, 1));
109- // 5 data bytes: one pad byte follows, counted by riffSize but not dataSize.
110- assert_eq!(bytes.len() % 2, 0);
111- assert_eq!(le64(&bytes, 20), bytes.len() as u64 - 8);
112- assert_eq!(le64(&bytes, 28), 5);
113- let r = WavReader::new(Cursor::new(&bytes[..])).unwrap();
114- assert_eq!(r.duration(), Some(5));
115-}
116-
117-#[test]
118-fn extensible_rf64_keeps_fact_and_its_saturating_count() {
119- let s = spec(6, 24);
120- let frames = 50;
121- let bytes = write_file(s, frames, opts(frames as u64, 1));
122- assert_eq!(&bytes[0..4], b"RF64");
123- // Extensible fmt is 40 bytes, so `fact` follows it at 48 + 8 + 40.
124- let fact = 48 + 8 + 40;
125- assert_eq!(&bytes[fact..fact + 4], b"fact");
126- assert_eq!(le32(&bytes, fact + 8), frames as u32);
127- let r = WavReader::new(Cursor::new(&bytes[..])).unwrap();
128- assert_eq!(r.spec(), s);
129- assert_eq!(r.duration(), Some(frames as u64));
130-}
131-
132-#[test]
133-fn under_threshold_stays_riff_byte_for_byte() {
134- let s = spec(2, 16);
135- let riff = write_file(s, 100, WavOptions::default());
136- let below = write_file(s, 100, opts(100, 400 + 1));
137- assert_eq!(riff, below);
138- assert_eq!(&riff[0..4], b"RIFF");
139- assert_eq!(le32(&riff, 4) as usize, riff.len() - 8);
140-}
141-
142-#[test]
143-fn unknown_length_is_riff_and_oversize_riff_is_refused() {
144- let s = spec(2, 16);
145- let bytes = write_file(s, 10, WavOptions::default());
146- assert_eq!(&bytes[0..4], b"RIFF");
147- assert_eq!(le32(&bytes, 4) as usize, bytes.len() - 8);
148-}
149-
150 /// Manual: writes 4.1 GiB of 16-bit stereo and reads its header back. Run with64 /// Manual: writes 4.1 GiB of 16-bit stereo and reads its header back. Run with
151 /// `cargo test -p ec-riff --test it rf64:: -- --ignored --nocapture`.65 /// `cargo test -p ec-riff --test it rf64:: -- --ignored --nocapture`.
152 #[test]66 #[test]