lofty-rs/lofty/tests/hound.rs

61 lines
1.7 KiB
Rust
Raw Normal View History

use lofty::config::ParseOptions;
2024-04-10 18:08:28 +00:00
use lofty::error::Result;
use lofty::iff::wav::WavFile;
use lofty::prelude::*;
use hound::WavReader;
2022-01-23 12:37:13 +00:00
use std::fs;
use std::fs::File;
use std::path::Path;
2022-01-23 11:32:51 +00:00
fn get_properties(path: &Path) -> Result<<WavFile as AudioFile>::Properties> {
2022-01-23 11:32:51 +00:00
let mut f = File::open(path).unwrap();
2022-09-24 06:34:22 +00:00
let wav_file = WavFile::read_from(&mut f, ParseOptions::new())?;
2022-01-23 12:37:13 +00:00
Ok(*wav_file.properties())
2022-01-23 11:32:51 +00:00
}
#[test]
fn hound() {
let paths = fs::read_dir("tests/files/assets/hound").unwrap();
for path in paths {
let path = path.unwrap().path();
if path.is_file() && path.extension().unwrap() == "wav" {
println!("Name: {}", path.display());
let wav_reader = WavReader::open(&path).unwrap();
2022-01-23 12:37:13 +00:00
let lofty = get_properties(&path).unwrap();
2024-05-04 20:41:40 +00:00
assert_eq!(u16::from(lofty.channels()), wav_reader.spec().channels);
2022-01-23 12:37:13 +00:00
assert_eq!(lofty.sample_rate(), wav_reader.spec().sample_rate);
2024-05-04 20:41:40 +00:00
assert_eq!(
u16::from(lofty.bit_depth()),
wav_reader.spec().bits_per_sample
);
2022-01-23 12:37:13 +00:00
}
}
}
#[test]
fn hound_fuzz() {
let paths = fs::read_dir("tests/files/assets/hound/fuzz").unwrap();
for path in paths {
let path = path.unwrap().path();
if path.is_file() && path.extension().unwrap() == "wav" {
println!("Name: {}", path.display());
if let Ok(wav_reader) = WavReader::open(&path) {
let lofty = get_properties(&path).unwrap();
println!("{lofty:#?}");
2024-05-04 20:41:40 +00:00
assert_eq!(u16::from(lofty.channels()), wav_reader.spec().channels);
2022-01-23 12:37:13 +00:00
assert_eq!(lofty.sample_rate(), wav_reader.spec().sample_rate);
2024-05-04 20:41:40 +00:00
assert_eq!(
u16::from(lofty.bit_depth()),
wav_reader.spec().bits_per_sample
);
2022-01-23 12:37:13 +00:00
} else if get_properties(&path).is_ok() {
println!("We are even better for this file!");
}
2022-01-23 11:32:51 +00:00
}
}
}