Add extra check to tag_reader example; Reorganize test assets

This commit is contained in:
Serial 2022-02-13 13:15:27 -05:00
parent 3cb1cf7aed
commit d73173fb84
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
22 changed files with 112 additions and 70 deletions

View file

@ -18,15 +18,15 @@ fn path_infer_read(c: &mut Criterion) {
test_read_path!(
c,
[
("AIFF", "tests/files/assets/full_test.aiff"),
("APE", "tests/files/assets/full_test.ape"),
("FLAC", "tests/files/assets/full_test.flac"),
("MP4", "tests/files/assets/m4a_codec_aac.m4a"),
("MP3", "tests/files/assets/full_test.mp3"),
("OPUS", "tests/files/assets/full_test.opus"),
("RIFF", "tests/files/assets/wav_format_pcm.wav"),
("SPEEX", "tests/files/assets/full_test.spx"),
("VORBIS", "tests/files/assets/full_test.ogg")
("AIFF", "tests/files/assets/minimal/full_test.aiff"),
("APE", "tests/files/assets/minimal/full_test.ape"),
("FLAC", "tests/files/assets/minimal/full_test.flac"),
("MP4", "tests/files/assets/minimal/m4a_codec_aac.m4a"),
("MP3", "tests/files/assets/minimal/full_test.mp3"),
("OPUS", "tests/files/assets/minimal/full_test.opus"),
("RIFF", "tests/files/assets/minimal/wav_format_pcm.wav"),
("SPEEX", "tests/files/assets/minimal/full_test.spx"),
("VORBIS", "tests/files/assets/minimal/full_test.ogg")
]
);
}
@ -56,15 +56,15 @@ fn content_infer_read(c: &mut Criterion) {
test_read_file!(
c,
[
(AIFF, "../tests/files/assets/full_test.aiff"),
(APE, "../tests/files/assets/full_test.ape"),
(FLAC, "../tests/files/assets/full_test.flac"),
(MP4, "../tests/files/assets/m4a_codec_aac.m4a"),
(MP3, "../tests/files/assets/full_test.mp3"),
(OPUS, "../tests/files/assets/full_test.opus"),
(RIFF, "../tests/files/assets/wav_format_pcm.wav"),
(SPEEX, "../tests/files/assets/full_test.spx"),
(VORBIS, "../tests/files/assets/full_test.ogg")
(AIFF, "../tests/files/assets/minimal/full_test.aiff"),
(APE, "../tests/files/assets/minimal/full_test.ape"),
(FLAC, "../tests/files/assets/minimal/full_test.flac"),
(MP4, "../tests/files/assets/minimal/m4a_codec_aac.m4a"),
(MP3, "../tests/files/assets/minimal/full_test.mp3"),
(OPUS, "../tests/files/assets/minimal/full_test.opus"),
(RIFF, "../tests/files/assets/minimal/wav_format_pcm.wav"),
(SPEEX, "../tests/files/assets/minimal/full_test.spx"),
(VORBIS, "../tests/files/assets/minimal/full_test.ogg")
]
);
}

View file

@ -1,7 +1,13 @@
use lofty::{Accessor, Probe};
use std::path::Path;
fn main() {
let path = std::env::args().nth(1).expect("Error: No path specified!");
let path_str = std::env::args().nth(1).expect("Error: No path specified!");
let path = Path::new(&path_str);
if !path.is_file() {
panic!("Error: Path is not a file!");
}
let tagged_file = Probe::open(path)
.expect("Error: Bad path provided!")

View file

@ -100,7 +100,9 @@ mod tests {
file_name: Some(String::from("a.mp3")),
descriptor: Some(String::from("Test Asset")),
},
data: crate::tag_utils::test_utils::read_path("tests/files/assets/full_test.mp3"),
data: crate::tag_utils::test_utils::read_path(
"tests/files/assets/minimal/full_test.mp3",
),
};
let cont = crate::tag_utils::test_utils::read_path("tests/tags/assets/id3v2/test.geob");
@ -119,7 +121,9 @@ mod tests {
file_name: Some(String::from("a.mp3")),
descriptor: Some(String::from("Test Asset")),
},
data: crate::tag_utils::test_utils::read_path("tests/files/assets/full_test.mp3"),
data: crate::tag_utils::test_utils::read_path(
"tests/files/assets/minimal/full_test.mp3",
),
};
let encoded = to_encode.as_bytes();

View file

@ -34,11 +34,11 @@
//! // First, create a probe.
//! // This will guess the format from the extension
//! // ("mp3" in this case), but we can guess from the content if we want to.
//! let tagged_file = read_from_path("tests/files/assets/full_test.mp3", false)?;
//! let tagged_file = read_from_path("tests/files/assets/minimal/full_test.mp3", false)?;
//!
//! // Let's guess the format from the content just in case.
//! // This is not necessary in this case!
//! let tagged_file2 = Probe::open("tests/files/assets/full_test.mp3")?
//! let tagged_file2 = Probe::open("tests/files/assets/minimal/full_test.mp3")?
//! .guess_file_type()?
//! .read(false)?;
//! # Ok(())
@ -54,7 +54,7 @@
//! use std::fs::File;
//!
//! // Let's read from an open file
//! let mut file = File::open("tests/files/assets/full_test.mp3")?;
//! let mut file = File::open("tests/files/assets/minimal/full_test.mp3")?;
//!
//! // Here, we have to guess the file type prior to reading
//! let tagged_file = read_from(&mut file, false)?;
@ -69,7 +69,7 @@
//! # fn main() -> Result<(), LoftyError> {
//! use lofty::read_from_path;
//!
//! let tagged_file = read_from_path("tests/files/assets/full_test.mp3", false)?;
//! let tagged_file = read_from_path("tests/files/assets/minimal/full_test.mp3", false)?;
//!
//! // Get the primary tag (ID3v2 in this case)
//! let id3v2 = tagged_file.primary_tag().unwrap();
@ -90,7 +90,7 @@
//! use lofty::{AudioFile, TagType};
//! use std::fs::File;
//!
//! let mut file_content = File::open("tests/files/assets/full_test.mp3")?;
//! let mut file_content = File::open("tests/files/assets/minimal/full_test.mp3")?;
//!
//! // We are expecting an MP3 file
//! let mpeg_file = Mp3File::read_from(&mut file_content, true)?;

View file

@ -30,7 +30,7 @@ use std::path::Path;
/// # fn main() -> Result<(), LoftyError> {
/// use lofty::FileType;
///
/// let probe = Probe::open("tests/files/assets/full_test.mp3")?;
/// let probe = Probe::open("tests/files/assets/minimal/full_test.mp3")?;
///
/// // Inferred from the `mp3` extension
/// assert_eq!(probe.file_type(), Some(FileType::MP3));
@ -46,7 +46,7 @@ use std::path::Path;
/// use lofty::FileType;
///
/// // Our same path probe with a guessed file type
/// let probe = Probe::open("tests/files/assets/full_test.mp3")?.guess_file_type()?;
/// let probe = Probe::open("tests/files/assets/minimal/full_test.mp3")?.guess_file_type()?;
///
/// // Inferred from the file's content
/// assert_eq!(probe.file_type(), Some(FileType::MP3));

View file

@ -5,7 +5,7 @@ use std::io::{Seek, SeekFrom, Write};
#[test]
fn read() {
// Here we have an AIFF file with both an ID3v2 chunk and text chunks
let file = lofty::read_from_path("tests/files/assets/full_test.aiff", false).unwrap();
let file = lofty::read_from_path("tests/files/assets/minimal/full_test.aiff", false).unwrap();
assert_eq!(file.file_type(), &FileType::AIFF);
@ -18,7 +18,7 @@ fn read() {
#[test]
fn write() {
let mut file = temp_file!("tests/files/assets/full_test.aiff");
let mut file = temp_file!("tests/files/assets/minimal/full_test.aiff");
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
@ -41,10 +41,13 @@ fn write() {
#[test]
fn remove_text_chunks() {
crate::remove_tag!("tests/files/assets/full_test.aiff", TagType::AiffText);
crate::remove_tag!(
"tests/files/assets/minimal/full_test.aiff",
TagType::AiffText
);
}
#[test]
fn remove_id3v2() {
crate::remove_tag!("tests/files/assets/full_test.aiff", TagType::Id3v2);
crate::remove_tag!("tests/files/assets/minimal/full_test.aiff", TagType::Id3v2);
}

View file

@ -5,7 +5,7 @@ use std::io::{Seek, SeekFrom, Write};
#[test]
fn read() {
// Here we have an APE file with an ID3v2, ID3v1, and an APEv2 tag
let file = lofty::read_from_path("tests/files/assets/full_test.ape", false).unwrap();
let file = lofty::read_from_path("tests/files/assets/minimal/full_test.ape", false).unwrap();
assert_eq!(file.file_type(), &FileType::APE);
@ -22,7 +22,7 @@ fn read() {
#[test]
fn write() {
// We don't write an ID3v2 tag here since it's against the spec
let mut file = temp_file!("tests/files/assets/full_test.ape");
let mut file = temp_file!("tests/files/assets/minimal/full_test.ape");
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
@ -45,10 +45,10 @@ fn write() {
#[test]
fn remove_ape() {
crate::remove_tag!("tests/files/assets/full_test.ape", TagType::Ape);
crate::remove_tag!("tests/files/assets/minimal/full_test.ape", TagType::Ape);
}
#[test]
fn remove_id3v1() {
crate::remove_tag!("tests/files/assets/full_test.ape", TagType::Id3v1);
crate::remove_tag!("tests/files/assets/minimal/full_test.ape", TagType::Id3v1);
}

View file

@ -5,7 +5,8 @@ use std::io::{Seek, SeekFrom, Write};
#[test]
fn read() {
// This file contains an ilst atom
let file = lofty::read_from_path("tests/files/assets/m4a_codec_aac.m4a", false).unwrap();
let file =
lofty::read_from_path("tests/files/assets/minimal/m4a_codec_aac.m4a", false).unwrap();
assert_eq!(file.file_type(), &FileType::MP4);
@ -15,7 +16,7 @@ fn read() {
#[test]
fn write() {
let mut file = temp_file!("tests/files/assets/m4a_codec_aac.m4a");
let mut file = temp_file!("tests/files/assets/minimal/m4a_codec_aac.m4a");
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
@ -33,5 +34,8 @@ fn write() {
#[test]
fn remove() {
crate::remove_tag!("tests/files/assets/m4a_codec_aac.m4a", TagType::Mp4Ilst);
crate::remove_tag!(
"tests/files/assets/minimal/m4a_codec_aac.m4a",
TagType::Mp4Ilst
);
}

View file

@ -5,7 +5,7 @@ use std::io::{Seek, SeekFrom, Write};
#[test]
fn read() {
// Here we have an MP3 file with an ID3v2, ID3v1, and an APEv2 tag
let file = lofty::read_from_path("tests/files/assets/full_test.mp3", false).unwrap();
let file = lofty::read_from_path("tests/files/assets/minimal/full_test.mp3", false).unwrap();
assert_eq!(file.file_type(), &FileType::MP3);
@ -45,7 +45,7 @@ fn read_with_junk_bytes_between_frames() {
#[test]
fn write() {
let mut file = temp_file!("tests/files/assets/full_test.mp3");
let mut file = temp_file!("tests/files/assets/minimal/full_test.mp3");
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
@ -73,15 +73,15 @@ fn write() {
#[test]
fn remove_id3v2() {
crate::remove_tag!("tests/files/assets/full_test.mp3", TagType::Id3v2);
crate::remove_tag!("tests/files/assets/minimal/full_test.mp3", TagType::Id3v2);
}
#[test]
fn remove_id3v1() {
crate::remove_tag!("tests/files/assets/full_test.mp3", TagType::Id3v1);
crate::remove_tag!("tests/files/assets/minimal/full_test.mp3", TagType::Id3v1);
}
#[test]
fn remove_ape() {
crate::remove_tag!("tests/files/assets/full_test.mp3", TagType::Ape);
crate::remove_tag!("tests/files/assets/minimal/full_test.mp3", TagType::Ape);
}

View file

@ -7,63 +7,81 @@ use std::io::{Seek, SeekFrom, Write};
#[test]
fn opus_read() {
read("tests/files/assets/full_test.opus", &FileType::Opus)
read("tests/files/assets/minimal/full_test.opus", &FileType::Opus)
}
#[test]
fn opus_write() {
write("tests/files/assets/full_test.opus", &FileType::Opus)
write("tests/files/assets/minimal/full_test.opus", &FileType::Opus)
}
#[test]
fn opus_remove() {
remove("tests/files/assets/full_test.opus", TagType::VorbisComments)
remove(
"tests/files/assets/minimal/full_test.opus",
TagType::VorbisComments,
)
}
#[test]
fn flac_read() {
// FLAC does **not** require a Vorbis comment block be present, this file has one
read("tests/files/assets/full_test.flac", &FileType::FLAC)
read("tests/files/assets/minimal/full_test.flac", &FileType::FLAC)
}
#[test]
fn flac_write() {
write("tests/files/assets/full_test.flac", &FileType::FLAC)
write("tests/files/assets/minimal/full_test.flac", &FileType::FLAC)
}
#[test]
fn flac_remove() {
crate::remove_tag!("tests/files/assets/full_test.flac", TagType::VorbisComments);
crate::remove_tag!(
"tests/files/assets/minimal/full_test.flac",
TagType::VorbisComments
);
}
#[test]
fn vorbis_read() {
read("tests/files/assets/full_test.ogg", &FileType::Vorbis)
read(
"tests/files/assets/minimal/full_test.ogg",
&FileType::Vorbis,
)
}
#[test]
fn vorbis_write() {
write("tests/files/assets/full_test.ogg", &FileType::Vorbis)
write(
"tests/files/assets/minimal/full_test.ogg",
&FileType::Vorbis,
)
}
#[test]
fn vorbis_remove() {
remove("tests/files/assets/full_test.ogg", TagType::VorbisComments)
remove(
"tests/files/assets/minimal/full_test.ogg",
TagType::VorbisComments,
)
}
#[test]
fn speex_read() {
read("tests/files/assets/full_test.spx", &FileType::Speex)
read("tests/files/assets/minimal/full_test.spx", &FileType::Speex)
}
#[test]
fn speex_write() {
write("tests/files/assets/full_test.spx", &FileType::Speex)
write("tests/files/assets/minimal/full_test.spx", &FileType::Speex)
}
#[test]
fn speex_remove() {
remove("tests/files/assets/full_test.spx", TagType::VorbisComments)
remove(
"tests/files/assets/minimal/full_test.spx",
TagType::VorbisComments,
)
}
fn read(path: &str, file_type: &FileType) {

View file

@ -5,7 +5,8 @@ use std::io::{Seek, SeekFrom, Write};
#[test]
fn read() {
// Here we have a WAV file with both an ID3v2 chunk and a RIFF INFO chunk
let file = lofty::read_from_path("tests/files/assets/wav_format_pcm.wav", false).unwrap();
let file =
lofty::read_from_path("tests/files/assets/minimal/wav_format_pcm.wav", false).unwrap();
assert_eq!(file.file_type(), &FileType::WAV);
@ -18,7 +19,7 @@ fn read() {
#[test]
fn write() {
let mut file = temp_file!("tests/files/assets/wav_format_pcm.wav");
let mut file = temp_file!("tests/files/assets/minimal/wav_format_pcm.wav");
let mut tagged_file = lofty::read_from(&mut file, false).unwrap();
@ -41,10 +42,16 @@ fn write() {
#[test]
fn remove_id3v2() {
crate::remove_tag!("tests/files/assets/wav_format_pcm.wav", TagType::Id3v2);
crate::remove_tag!(
"tests/files/assets/minimal/wav_format_pcm.wav",
TagType::Id3v2
);
}
#[test]
fn remove_riff_info() {
crate::remove_tag!("tests/files/assets/wav_format_pcm.wav", TagType::RiffInfo);
crate::remove_tag!(
"tests/files/assets/minimal/wav_format_pcm.wav",
TagType::RiffInfo
);
}

View file

@ -114,7 +114,7 @@ where
#[test]
fn aiff_properties() {
assert_eq!(
get_properties::<AiffFile>("tests/files/assets/full_test.aiff"),
get_properties::<AiffFile>("tests/files/assets/minimal/full_test.aiff"),
AIFF_PROPERTIES
);
}
@ -122,7 +122,7 @@ fn aiff_properties() {
#[test]
fn ape_properties() {
assert_eq!(
get_properties::<ApeFile>("tests/files/assets/full_test.ape"),
get_properties::<ApeFile>("tests/files/assets/minimal/full_test.ape"),
APE_PROPERTIES
);
}
@ -130,7 +130,7 @@ fn ape_properties() {
#[test]
fn flac_properties() {
assert_eq!(
get_properties::<FlacFile>("tests/files/assets/full_test.flac"),
get_properties::<FlacFile>("tests/files/assets/minimal/full_test.flac"),
FLAC_PROPERTIES
)
}
@ -138,7 +138,7 @@ fn flac_properties() {
#[test]
fn mp3_properties() {
assert_eq!(
get_properties::<Mp3File>("tests/files/assets/full_test.mp3"),
get_properties::<Mp3File>("tests/files/assets/minimal/full_test.mp3"),
MP3_PROPERTIES
)
}
@ -146,7 +146,7 @@ fn mp3_properties() {
#[test]
fn mp4_aac_properties() {
assert_eq!(
get_properties::<Mp4File>("tests/files/assets/m4a_codec_aac.m4a"),
get_properties::<Mp4File>("tests/files/assets/minimal/m4a_codec_aac.m4a"),
MP4_AAC_PROPERTIES
)
}
@ -154,7 +154,7 @@ fn mp4_aac_properties() {
#[test]
fn mp4_alac_properties() {
assert_eq!(
get_properties::<Mp4File>("tests/files/assets/m4a_codec_alac.m4a"),
get_properties::<Mp4File>("tests/files/assets/minimal/m4a_codec_alac.m4a"),
MP4_ALAC_PROPERTIES
)
}
@ -162,7 +162,7 @@ fn mp4_alac_properties() {
#[test]
fn opus_properties() {
assert_eq!(
get_properties::<OpusFile>("tests/files/assets/full_test.opus"),
get_properties::<OpusFile>("tests/files/assets/minimal/full_test.opus"),
OPUS_PROPERTIES
)
}
@ -170,7 +170,7 @@ fn opus_properties() {
#[test]
fn speex_properties() {
assert_eq!(
get_properties::<SpeexFile>("tests/files/assets/full_test.spx"),
get_properties::<SpeexFile>("tests/files/assets/minimal/full_test.spx"),
SPEEX_PROPERTIES
)
}
@ -178,7 +178,7 @@ fn speex_properties() {
#[test]
fn vorbis_properties() {
assert_eq!(
get_properties::<VorbisFile>("tests/files/assets/full_test.ogg"),
get_properties::<VorbisFile>("tests/files/assets/minimal/full_test.ogg"),
VORBIS_PROPERTIES
)
}
@ -186,7 +186,7 @@ fn vorbis_properties() {
#[test]
fn wav_properties() {
assert_eq!(
get_properties::<WavFile>("tests/files/assets/wav_format_pcm.wav"),
get_properties::<WavFile>("tests/files/assets/minimal/wav_format_pcm.wav"),
WAV_PROPERTIES
)
}