From d298199a07bb82d5e7be4436b2130c181433e611 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Mon, 11 Jul 2022 17:04:40 -0400 Subject: [PATCH] Vorbis Comments: Add zero-sized test --- src/ogg/tag.rs | 18 +++++++++++------- tests/files/zero_sized.rs | 2 -- tests/tags/assets/zero.vorbis | Bin 0 -> 8 bytes 3 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 tests/tags/assets/zero.vorbis diff --git a/src/ogg/tag.rs b/src/ogg/tag.rs index 5ec116e2..2e572f3b 100644 --- a/src/ogg/tag.rs +++ b/src/ogg/tag.rs @@ -549,8 +549,6 @@ mod tests { use crate::ogg::VorbisComments; use crate::{Tag, TagExt, TagType}; - use std::io::Read; - fn read_tag(tag: &[u8]) -> VorbisComments { let mut reader = std::io::Cursor::new(tag); let mut parsed_tag = VorbisComments::default(); @@ -597,11 +595,7 @@ mod tests { #[test] fn vorbis_comments_to_tag() { - let mut tag_bytes = Vec::new(); - std::fs::File::open("tests/tags/assets/test.vorbis") - .unwrap() - .read_to_end(&mut tag_bytes) - .unwrap(); + let tag_bytes = std::fs::read("tests/tags/assets/test.vorbis").unwrap(); let mut reader = std::io::Cursor::new(&tag_bytes[..]); let mut vorbis_comments = VorbisComments::default(); @@ -626,4 +620,14 @@ mod tests { assert_eq!(vorbis_comments.get("TRACKNUMBER"), Some("1")); assert_eq!(vorbis_comments.get("GENRE"), Some("Classical")); } + + #[test] + fn zero_sized_vorbis_comments() { + let tag_bytes = std::fs::read("tests/tags/assets/zero.vorbis").unwrap(); + + let mut reader = std::io::Cursor::new(&tag_bytes[..]); + let mut vorbis_comments = VorbisComments::default(); + + crate::ogg::read::read_comments(&mut reader, &mut vorbis_comments).unwrap(); + } } diff --git a/tests/files/zero_sized.rs b/tests/files/zero_sized.rs index 2727b6a3..e4aef37b 100644 --- a/tests/files/zero_sized.rs +++ b/tests/files/zero_sized.rs @@ -5,8 +5,6 @@ use lofty::mp3::Mp3File; use lofty::mp4::Mp4File; use lofty::AudioFile; -// TODO: zero-size vorbis comments - fn read_file_with_properties(path: &str) -> bool { let res = ::read_from(&mut std::fs::File::open(path).unwrap(), true); res.is_ok() diff --git a/tests/tags/assets/zero.vorbis b/tests/tags/assets/zero.vorbis new file mode 100644 index 0000000000000000000000000000000000000000..1b1cb4d44c57c2d7a5122870fa6ac3e62ff7e94e GIT binary patch literal 8 KcmZQzfB*mh2mk>9 literal 0 HcmV?d00001