Tests: the damaged-sound test now reaches the check it is named for (its corrupted pages failed their checksums, so the container rejected the file first and the error was thrown away), the directory-permission test checks the mode, a test that returned early without a sound server is ignored instead of passing having tested nothing, and two assert what they set up
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
+5
-3
@@ -1177,16 +1177,18 @@ mod tests {
|
||||
assert!(!devices[1].is_default);
|
||||
}
|
||||
|
||||
/// Ignored by default: with no sound server there is nothing to resolve,
|
||||
/// and a test that returned early there passed having tested nothing.
|
||||
/// cargo test -- --ignored the_system_default
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn the_system_default_is_a_destination_rather_than_an_absence() {
|
||||
// Choosing "system default" has to actively move the stream. The sound
|
||||
// server puts an application back on the device it was last moved to,
|
||||
// so treating the default as "do not route" silently means "keep
|
||||
// whatever was chosen before" - which is how audio ends up playing
|
||||
// into a device nobody is listening to.
|
||||
let Ok(output) = default_device(Stream::Output) else {
|
||||
return; // no sound server here; nothing to assert against
|
||||
};
|
||||
let output = default_device(Stream::Output).expect("a sound server to ask");
|
||||
assert!(!output.is_empty(), "the default sink resolved to nothing");
|
||||
let input = default_device(Stream::Input).expect("a server with a sink should name a source");
|
||||
assert!(!input.is_empty(), "the default source resolved to nothing");
|
||||
|
||||
@@ -391,11 +391,26 @@ mod opus_guard_tests {
|
||||
assert!((1.9..=2.1).contains(&seconds), "decoded {seconds:.2}s of a 2s sound");
|
||||
}
|
||||
|
||||
/// Ogg's page checksum: CRC-32 with polynomial 0x04c11db7, not reflected,
|
||||
/// starting from zero, over the whole page with its own field zeroed.
|
||||
fn ogg_crc(page: &[u8]) -> u32 {
|
||||
let mut crc = 0u32;
|
||||
for &byte in page {
|
||||
crc ^= (byte as u32) << 24;
|
||||
for _ in 0..8 {
|
||||
crc = if crc & 0x8000_0000 != 0 { (crc << 1) ^ 0x04c1_1db7 } else { crc << 1 };
|
||||
}
|
||||
}
|
||||
crc
|
||||
}
|
||||
|
||||
/// Packets that are not Opus are left out rather than handed over.
|
||||
#[test]
|
||||
fn a_damaged_ogg_opus_sound_does_not_reach_the_decoder_whole() {
|
||||
let samples: Vec<f32> = (0..48_000).map(|i| (i as f32 * 0.03).sin() * 0.5).collect();
|
||||
let mut file = crate::oggopus::encode(&samples).unwrap();
|
||||
let whole = super::decode(&file).expect("the undamaged sound decodes");
|
||||
assert!(!whole.is_empty(), "the undamaged sound has audio in it");
|
||||
// Corrupt the audio pages (after the two header pages) without
|
||||
// touching the Ogg framing: each packet's first byte becomes a code 3
|
||||
// header claiming 63 frames, which no valid packet can.
|
||||
@@ -414,10 +429,18 @@ mod opus_guard_tests {
|
||||
file[body + 1] = 63;
|
||||
}
|
||||
let len: usize = file[i + 27..i + 27 + segments].iter().map(|&b| b as usize).sum();
|
||||
// The page's checksum covers what was just changed. Left as it was
|
||||
// the container rejects the whole file before any packet is read,
|
||||
// and this would be testing that and not the check it is named for.
|
||||
file[i + 22..i + 26].copy_from_slice(&[0; 4]);
|
||||
let crc = ogg_crc(&file[i..body + len]);
|
||||
file[i + 22..i + 26].copy_from_slice(&crc.to_le_bytes());
|
||||
i = body + len;
|
||||
}
|
||||
// Still a file symphonia can read, and the check keeps the bad
|
||||
// packets out; it must not panic or error the whole sound.
|
||||
let _ = super::decode(&file);
|
||||
// packets out; it must not panic or error the whole sound, and what
|
||||
// comes back is what was left of it - less than there was.
|
||||
let damaged = super::decode(&file).expect("a damaged sound is decoded as far as it goes");
|
||||
assert!(damaged.len() < whole.len(), "{} of {} samples came through", damaged.len(), whole.len());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -883,6 +883,7 @@ mod tests {
|
||||
fn closing_a_channel_forgets_who_was_talking_in_it() {
|
||||
let mut w = watching_odablock();
|
||||
w.heard("odablock", Speaker { nick: "someone".into(), user_id: None, badge: None });
|
||||
assert_eq!(w.roster("odablock").len(), 1, "somebody was heard to begin with");
|
||||
w.remove("odablock");
|
||||
assert!(w.roster("odablock").is_empty());
|
||||
}
|
||||
|
||||
@@ -125,6 +125,13 @@ mod tests {
|
||||
// Still ours to write into, which is the point - a directory nobody
|
||||
// can enter would be secure and useless.
|
||||
std::fs::write(dir.join("inside"), b"x").unwrap();
|
||||
// And closed to everybody else.
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let mode = std::fs::metadata(&dir).unwrap().permissions().mode() & 0o777;
|
||||
assert_eq!(mode, 0o700, "mode {mode:o}");
|
||||
}
|
||||
std::fs::remove_dir_all(&dir).ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,6 +367,7 @@ mod tests {
|
||||
assert_eq!(card.url.as_deref(), Some(watch));
|
||||
assert!(parse(&serde_json::json!({ "title": " ", "author_name": "x" }), watch).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_card_from_the_page_when_oembed_is_refused() {
|
||||
let watch = "https://www.youtube.com/watch?v=_-agl0pOQfs";
|
||||
|
||||
Reference in New Issue
Block a user