From 26b0b013a70b9707a6ab3a99f47b236bf8e4d152 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Fri, 18 Mar 2022 13:54:55 -0400 Subject: [PATCH] Add more `Probe` tests --- src/probe.rs | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/src/probe.rs b/src/probe.rs index 2157843d..92cc7e04 100644 --- a/src/probe.rs +++ b/src/probe.rs @@ -264,7 +264,9 @@ where #[cfg(test)] mod tests { - use crate::Probe; + use crate::{FileType, Probe}; + + use std::fs::File; #[test] fn mp3_id3v2_trailing_junk() { @@ -291,4 +293,78 @@ mod tests { let probe = Probe::new(data).guess_file_type().unwrap(); assert_eq!(probe.file_type(), Some(crate::FileType::MP3)); } + + fn test_probe(path: &str, expected_file_type_guess: FileType) { + test_probe_file(path, expected_file_type_guess); + test_probe_path(path, expected_file_type_guess); + } + + // Test from file contents + fn test_probe_file(path: &str, expected_file_type_guess: FileType) { + let mut f = File::open(path).unwrap(); + let probe = Probe::new(&mut f).guess_file_type().unwrap(); + assert_eq!(probe.file_type(), Some(expected_file_type_guess)); + } + + // Test from file extension + fn test_probe_path(path: &str, expected_file_type_guess: FileType) { + let probe = Probe::open(path).unwrap(); + assert_eq!(probe.file_type(), Some(expected_file_type_guess)); + } + + #[test] + fn probe_aiff() { + test_probe("tests/files/assets/minimal/full_test.aiff", FileType::AIFF); + } + + #[test] + fn probe_ape_with_id3v2() { + test_probe("tests/files/assets/minimal/full_test.ape", FileType::APE); + } + + #[test] + fn probe_flac() { + test_probe("tests/files/assets/minimal/full_test.flac", FileType::FLAC); + } + + #[test] + fn probe_flac_with_id3v2() { + test_probe("tests/files/assets/flac_with_id3v2.flac", FileType::FLAC); + } + + #[test] + fn probe_mp3_with_id3v2() { + test_probe("tests/files/assets/minimal/full_test.mp3", FileType::MP3); + } + + #[test] + fn probe_vorbis() { + test_probe("tests/files/assets/minimal/full_test.ogg", FileType::Vorbis); + } + + #[test] + fn probe_opus() { + test_probe("tests/files/assets/minimal/full_test.opus", FileType::Opus); + } + + #[test] + fn probe_speex() { + test_probe("tests/files/assets/minimal/full_test.spx", FileType::Speex); + } + + #[test] + fn probe_mp4() { + test_probe( + "tests/files/assets/minimal/m4a_codec_aac.m4a", + FileType::MP4, + ); + } + + #[test] + fn probe_wav() { + test_probe( + "tests/files/assets/minimal/wav_format_pcm.wav", + FileType::WAV, + ); + } }