diff --git a/um_audio/src/__fixtures__/mp3_with_id3v2.bin b/um_audio/src/__fixtures__/mp3_with_id3v2.bin new file mode 100644 index 0000000..d3b47e6 Binary files /dev/null and b/um_audio/src/__fixtures__/mp3_with_id3v2.bin differ diff --git a/um_audio/src/lib.rs b/um_audio/src/lib.rs index 883d45b..9a44b30 100644 --- a/um_audio/src/lib.rs +++ b/um_audio/src/lib.rs @@ -129,3 +129,15 @@ pub fn detect_audio_type(buffer: &[u8]) -> Result { Ok(AudioType::Unknown) } + +#[cfg(test)] +mod tests { + use crate::{detect_audio_type, AudioType}; + + #[test] + fn test_mp3() { + let mp3_data = include_bytes!("__fixtures__/mp3_with_id3v2.bin"); + let result = detect_audio_type(mp3_data).expect("failed to parse mp3"); + assert_eq!(result, AudioType::MP3); + } +} diff --git a/um_audio/src/metadata.rs b/um_audio/src/metadata.rs index 0a3a6a9..17afd46 100644 --- a/um_audio/src/metadata.rs +++ b/um_audio/src/metadata.rs @@ -67,7 +67,7 @@ fn get_ape_v2_size(buffer: &[u8], offset: usize) -> Result { pub fn get_header_metadata_size(buffer: &[u8], offset: usize) -> Result { let len = get_id3_header_size(buffer, offset)?; - if len == 0 { + if len != 0 { Ok(len) } else { get_ape_v2_size(buffer, offset)