mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-12 21:52:33 +00:00
Add tests for zero-size files
This commit is contained in:
parent
cc2f806839
commit
f0c2252eec
11 changed files with 59 additions and 17 deletions
|
@ -31,3 +31,13 @@ where
|
|||
|
||||
Ok(tag)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_size_id3v2() {
|
||||
use crate::id3::v2::read_id3v2_header;
|
||||
use std::io::Cursor;
|
||||
|
||||
let mut f = Cursor::new(std::fs::read("tests/tags/assets/id3v2/zero.id3v2").unwrap());
|
||||
let header = read_id3v2_header(&mut f).unwrap();
|
||||
assert!(parse_id3v2(&mut f, header).is_ok());
|
||||
}
|
||||
|
|
|
@ -172,20 +172,3 @@ where
|
|||
|
||||
Ok(file)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::file::AudioFile;
|
||||
use crate::mp3::Mp3File;
|
||||
use std::fs::File;
|
||||
|
||||
#[test]
|
||||
fn issue_39() {
|
||||
// MP3 file that only consists of an ID3v2 tag
|
||||
assert!(Mp3File::read_from(
|
||||
&mut File::open("tests/files/assets/issue_39.mp3").unwrap(),
|
||||
true,
|
||||
)
|
||||
.is_err());
|
||||
}
|
||||
}
|
||||
|
|
BIN
tests/files/assets/zero/zero.aiff
Normal file
BIN
tests/files/assets/zero/zero.aiff
Normal file
Binary file not shown.
BIN
tests/files/assets/zero/zero.ape
Normal file
BIN
tests/files/assets/zero/zero.ape
Normal file
Binary file not shown.
BIN
tests/files/assets/zero/zero.flac
Normal file
BIN
tests/files/assets/zero/zero.flac
Normal file
Binary file not shown.
BIN
tests/files/assets/zero/zero.mp4
Normal file
BIN
tests/files/assets/zero/zero.mp4
Normal file
Binary file not shown.
BIN
tests/files/assets/zero/zero.wav
Normal file
BIN
tests/files/assets/zero/zero.wav
Normal file
Binary file not shown.
|
@ -5,3 +5,4 @@ mod mpeg;
|
|||
mod ogg;
|
||||
pub(crate) mod util;
|
||||
mod wav;
|
||||
mod zero_sized;
|
||||
|
|
48
tests/files/zero_sized.rs
Normal file
48
tests/files/zero_sized.rs
Normal file
|
@ -0,0 +1,48 @@
|
|||
use lofty::ape::ApeFile;
|
||||
use lofty::flac::FlacFile;
|
||||
use lofty::iff::{AiffFile, WavFile};
|
||||
use lofty::mp3::Mp3File;
|
||||
use lofty::mp4::Mp4File;
|
||||
use lofty::AudioFile;
|
||||
|
||||
fn read_file<A: AudioFile + std::fmt::Debug>(path: &str) -> bool {
|
||||
let res = <A as AudioFile>::read_from(&mut std::fs::File::open(path).unwrap(), true);
|
||||
res.is_ok()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_audio_aiff() {
|
||||
// An AIFF files with a zero-size SSND chunk will error when attempting to read properties
|
||||
assert!(!read_file::<AiffFile>("tests/files/assets/zero/zero.aiff"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_audio_ape() {
|
||||
// An APE file with total_frames = 0 will error when attempting to read properties
|
||||
assert!(!read_file::<ApeFile>("tests/files/assets/zero/zero.ape"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_audio_flac() {
|
||||
assert!(read_file::<FlacFile>("tests/files/assets/zero/zero.flac"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_audio_mp3() {
|
||||
// A zero-size MP3 will error, since we need MPEG frames to extract audio properties
|
||||
assert!(!read_file::<Mp3File>("tests/files/assets/zero/zero.mp3"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_audio_mp4() {
|
||||
// A zero-size MP4 will error, since we need an audio track to extract audio properties
|
||||
assert!(!read_file::<Mp4File>("tests/files/assets/zero/zero.mp4"));
|
||||
}
|
||||
|
||||
// zero-size Vorbis, Opus, and Speex files are invalid
|
||||
|
||||
#[test]
|
||||
fn zero_audio_wav() {
|
||||
// An empty "data" chunk is an error
|
||||
assert!(!read_file::<WavFile>("tests/files/assets/zero/zero.wav"));
|
||||
}
|
BIN
tests/tags/assets/id3v2/zero.id3v2
Normal file
BIN
tests/tags/assets/id3v2/zero.id3v2
Normal file
Binary file not shown.
Loading…
Reference in a new issue