mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2025-03-04 14:57:17 +00:00
Reorganize file tests
This commit is contained in:
parent
c72857c3d7
commit
afdfc09873
21 changed files with 67 additions and 64 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -11,5 +11,5 @@
|
|||
**/Cargo.lock
|
||||
|
||||
# Test assets
|
||||
/tests/assets/
|
||||
/tests/files/assets/
|
||||
/tests/picture/assets/
|
||||
|
|
|
@ -9,14 +9,14 @@ macro_rules! test_read {
|
|||
};
|
||||
}
|
||||
|
||||
test_read!(read_aiff, "tests/assets/a_text.aiff");
|
||||
test_read!(read_ape, "tests/assets/a.ape");
|
||||
test_read!(read_flac, "tests/assets/a.flac");
|
||||
test_read!(read_m4a, "tests/assets/a.m4a");
|
||||
test_read!(read_mp3, "tests/assets/a.mp3");
|
||||
test_read!(read_vorbis, "tests/assets/a.ogg");
|
||||
test_read!(read_opus, "tests/assets/a.opus");
|
||||
test_read!(read_riff, "tests/assets/a.wav");
|
||||
test_read!(read_aiff, "tests/files/assets/a_text.aiff");
|
||||
test_read!(read_ape, "tests/files/assets/a.ape");
|
||||
test_read!(read_flac, "tests/files/assets/a.flac");
|
||||
test_read!(read_m4a, "tests/files/assets/a.m4a");
|
||||
test_read!(read_mp3, "tests/files/assets/a.mp3");
|
||||
test_read!(read_vorbis, "tests/files/assets/a.ogg");
|
||||
test_read!(read_opus, "tests/files/assets/a.opus");
|
||||
test_read!(read_riff, "tests/files/assets/a.wav");
|
||||
|
||||
fn bench_sig(c: &mut Criterion) {
|
||||
let mut g = c.benchmark_group("File reading");
|
||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -12,7 +12,7 @@
|
|||
//! | AIFF | `aiff`, `aif` |**X** |**X** |`ID3v2`, `Text Chunks` |
|
||||
//! | FLAC | `flac` |**X** |**X** |`Vorbis Comments` |
|
||||
//! | MP3 | `mp3` |**X** |**X** |`ID3v2`, `ID3v1`, `APEv2`, `APEv1` |
|
||||
//! | MP4 | `mp4`, `m4a`, `m4b`, `m4p`, `m4r`, `m4v`, `3gp` |**X** |**X** |`Atoms` |
|
||||
//! | MP4 | `mp4`, `m4a`, `m4b`, `m4p`, `m4r`, `m4v`, `3gp` |**X** |**X** |`iTunes-style ilst` |
|
||||
//! | Opus | `opus` |**X** |**X** |`Vorbis Comments` |
|
||||
//! | Ogg Vorbis | `ogg` |**X** |**X** |`Vorbis Comments` |
|
||||
//! | WAV | `wav`, `wave` |**X** |**X** |`ID3v2`, `RIFF INFO` |
|
||||
|
@ -28,7 +28,7 @@
|
|||
//! ```
|
||||
//! use lofty::{Probe, FileType};
|
||||
//!
|
||||
//! let file_type = Probe::new().file_type_from_extension("tests/assets/a.mp3").unwrap();
|
||||
//! let file_type = Probe::new().file_type_from_extension("tests/files/assets/a.mp3").unwrap();
|
||||
//!
|
||||
//! assert_eq!(file_type, FileType::MP3)
|
||||
//! ```
|
||||
|
@ -38,7 +38,7 @@
|
|||
//! use lofty::{Probe, FileType};
|
||||
//!
|
||||
//! // Probe::file_type also exists for generic readers
|
||||
//! let file_type = Probe::new().file_type_from_path("tests/assets/a.mp3").unwrap();
|
||||
//! let file_type = Probe::new().file_type_from_path("tests/files/assets/a.mp3").unwrap();
|
||||
//!
|
||||
//! assert_eq!(file_type, FileType::MP3)
|
||||
//! ```
|
||||
|
@ -50,7 +50,7 @@
|
|||
//! use lofty::TagType;
|
||||
//! use std::fs::File;
|
||||
//!
|
||||
//! let mut file_content = File::open("tests/assets/a.mp3").unwrap();
|
||||
//! let mut file_content = File::open("tests/files/assets/a.mp3").unwrap();
|
||||
//!
|
||||
//! let mpeg_file = Mp3File::read_from(&mut file_content).unwrap();
|
||||
//!
|
||||
|
@ -70,7 +70,7 @@
|
|||
//! use lofty::{Probe, FileType};
|
||||
//!
|
||||
//! // Probe::read_from also exists for generic readers
|
||||
//! let tagged_file = Probe::new().read_from_path("tests/assets/a.mp3").unwrap();
|
||||
//! let tagged_file = Probe::new().read_from_path("tests/files/assets/a.mp3").unwrap();
|
||||
//!
|
||||
//! assert_eq!(tagged_file.file_type(), &FileType::MP3);
|
||||
//! assert_eq!(tagged_file.properties().channels(), Some(2));
|
||||
|
@ -80,7 +80,7 @@
|
|||
//! ```
|
||||
//! use lofty::Probe;
|
||||
//!
|
||||
//! let tagged_file = Probe::new().read_from_path("tests/assets/a.mp3").unwrap();
|
||||
//! let tagged_file = Probe::new().read_from_path("tests/files/assets/a.mp3").unwrap();
|
||||
//!
|
||||
//! // Get the primary tag (ID3v2 in this case)
|
||||
//! let id3v2 = tagged_file.primary_tag().unwrap();
|
||||
|
|
1
tests/files/main.rs
Normal file
1
tests/files/main.rs
Normal file
|
@ -0,0 +1 @@
|
|||
mod tagged_file;
|
|
@ -1,12 +1,12 @@
|
|||
mod util;
|
||||
|
||||
use lofty::{FileType, ItemKey, ItemValue, Probe, TagItem, TagType};
|
||||
use std::io::{Seek, Write};
|
||||
use crate::set_artist;
|
||||
use crate::verify_artist;
|
||||
|
||||
#[test]
|
||||
fn read() {
|
||||
// Here we have an AIFF file with both an ID3v2 chunk and text chunks
|
||||
let file = Probe::new().read_from_path("tests/assets/a.aiff").unwrap();
|
||||
let file = Probe::new().read_from_path("tests/files/assets/a.aiff").unwrap();
|
||||
|
||||
assert_eq!(file.file_type(), &FileType::AIFF);
|
||||
|
||||
|
@ -20,7 +20,7 @@ fn read() {
|
|||
#[test]
|
||||
fn write() {
|
||||
let mut file = tempfile::tempfile().unwrap();
|
||||
file.write_all(&std::fs::read("tests/assets/a.aiff").unwrap())
|
||||
file.write_all(&std::fs::read("tests/files/assets/a.aiff").unwrap())
|
||||
.unwrap();
|
||||
|
||||
let mut tagged_file = Probe::new().read_from(&mut file).unwrap();
|
||||
|
@ -45,10 +45,10 @@ fn write() {
|
|||
|
||||
#[test]
|
||||
fn remove_text_chunks() {
|
||||
crate::remove_tag!("tests/assets/a.aiff", TagType::AiffText);
|
||||
crate::remove_tag!("tests/files/assets/a.aiff", TagType::AiffText);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_id3v2() {
|
||||
crate::remove_tag!("tests/assets/a.aiff", TagType::Id3v2);
|
||||
crate::remove_tag!("tests/files/assets/a.aiff", TagType::Id3v2);
|
||||
}
|
|
@ -1,12 +1,11 @@
|
|||
mod util;
|
||||
|
||||
use lofty::{FileType, ItemKey, ItemValue, Probe, TagItem, TagType};
|
||||
use std::io::{Seek, Write};
|
||||
use crate::{verify_artist, set_artist};
|
||||
|
||||
#[test]
|
||||
fn read() {
|
||||
// Here we have an APE file with an ID3v2, ID3v1, and an APEv2 tag
|
||||
let file = Probe::new().read_from_path("tests/assets/a.ape").unwrap();
|
||||
let file = Probe::new().read_from_path("tests/files/assets/a.ape").unwrap();
|
||||
|
||||
assert_eq!(file.file_type(), &FileType::APE);
|
||||
|
||||
|
@ -24,7 +23,7 @@ fn read() {
|
|||
fn write() {
|
||||
// We don't write an ID3v2 tag here since it's against the spec
|
||||
let mut file = tempfile::tempfile().unwrap();
|
||||
file.write_all(&std::fs::read("tests/assets/a.ape").unwrap())
|
||||
file.write_all(&std::fs::read("tests/files/assets/a.ape").unwrap())
|
||||
.unwrap();
|
||||
|
||||
let mut tagged_file = Probe::new().read_from(&mut file).unwrap();
|
||||
|
@ -47,10 +46,10 @@ fn write() {
|
|||
|
||||
#[test]
|
||||
fn remove_ape() {
|
||||
crate::remove_tag!("tests/assets/a.ape", TagType::Ape);
|
||||
crate::remove_tag!("tests/files/assets/a.ape", TagType::Ape);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_id3v1() {
|
||||
crate::remove_tag!("tests/assets/a.ape", TagType::Id3v1);
|
||||
crate::remove_tag!("tests/files/assets/a.ape", TagType::Id3v1);
|
||||
}
|
7
tests/files/tagged_file/mod.rs
Normal file
7
tests/files/tagged_file/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
mod aiff;
|
||||
mod ape;
|
||||
mod mp4;
|
||||
mod mpeg;
|
||||
mod ogg;
|
||||
mod wav;
|
||||
pub(crate) mod util;
|
|
@ -1,12 +1,11 @@
|
|||
mod util;
|
||||
|
||||
use lofty::{FileType, ItemKey, ItemValue, Probe, TagItem, TagType};
|
||||
use std::io::{Seek, Write};
|
||||
use crate::{verify_artist, set_artist};
|
||||
|
||||
#[test]
|
||||
fn read() {
|
||||
// This file contains an ilst atom
|
||||
let file = Probe::new().read_from_path("tests/assets/a.m4a").unwrap();
|
||||
let file = Probe::new().read_from_path("tests/files/assets/a.m4a").unwrap();
|
||||
|
||||
assert_eq!(file.file_type(), &FileType::MP4);
|
||||
|
||||
|
@ -17,7 +16,7 @@ fn read() {
|
|||
#[test]
|
||||
fn write() {
|
||||
let mut file = tempfile::tempfile().unwrap();
|
||||
file.write_all(&std::fs::read("tests/assets/a.m4a").unwrap())
|
||||
file.write_all(&std::fs::read("tests/files/assets/a.m4a").unwrap())
|
||||
.unwrap();
|
||||
|
||||
let mut tagged_file = Probe::new().read_from(&mut file).unwrap();
|
||||
|
@ -35,5 +34,5 @@ fn write() {
|
|||
|
||||
#[test]
|
||||
fn remove() {
|
||||
crate::remove_tag!("tests/assets/a.m4a", TagType::Mp4Atom);
|
||||
crate::remove_tag!("tests/files/assets/a.m4a", TagType::Mp4Atom);
|
||||
}
|
|
@ -1,12 +1,11 @@
|
|||
mod util;
|
||||
|
||||
use lofty::{FileType, ItemKey, ItemValue, Probe, TagItem, TagType};
|
||||
use std::io::{Seek, Write};
|
||||
use crate::{verify_artist, set_artist};
|
||||
|
||||
#[test]
|
||||
fn read() {
|
||||
// Here we have an MP3 file with an ID3v2, ID3v1, and an APEv2 tag
|
||||
let file = Probe::new().read_from_path("tests/assets/a.mp3").unwrap();
|
||||
let file = Probe::new().read_from_path("tests/files/assets/a.mp3").unwrap();
|
||||
|
||||
assert_eq!(file.file_type(), &FileType::MP3);
|
||||
|
||||
|
@ -23,7 +22,7 @@ fn read() {
|
|||
#[test]
|
||||
fn write() {
|
||||
let mut file = tempfile::tempfile().unwrap();
|
||||
file.write_all(&std::fs::read("tests/assets/a.mp3").unwrap())
|
||||
file.write_all(&std::fs::read("tests/files/assets/a.mp3").unwrap())
|
||||
.unwrap();
|
||||
|
||||
let mut tagged_file = Probe::new().read_from(&mut file).unwrap();
|
||||
|
@ -51,15 +50,15 @@ fn write() {
|
|||
|
||||
#[test]
|
||||
fn remove_id3v2() {
|
||||
crate::remove_tag!("tests/assets/a.mp3", TagType::Id3v2);
|
||||
crate::remove_tag!("tests/files/assets/a.mp3", TagType::Id3v2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_id3v1() {
|
||||
crate::remove_tag!("tests/assets/a.mp3", TagType::Id3v1);
|
||||
crate::remove_tag!("tests/files/assets/a.mp3", TagType::Id3v1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_ape() {
|
||||
crate::remove_tag!("tests/assets/a.mp3", TagType::Ape);
|
||||
crate::remove_tag!("tests/files/assets/a.mp3", TagType::Ape);
|
||||
}
|
|
@ -1,55 +1,54 @@
|
|||
mod util;
|
||||
|
||||
use lofty::{FileType, ItemKey, ItemValue, Probe, TagItem, TagType};
|
||||
use std::io::{Seek, Write};
|
||||
use crate::{verify_artist, set_artist};
|
||||
|
||||
// The tests for OGG Opus/Vorbis are nearly identical
|
||||
// We have the vendor string and a title stored in the tag
|
||||
|
||||
#[test]
|
||||
fn opus_read() {
|
||||
read("tests/assets/a.opus", &FileType::Opus)
|
||||
read("tests/files/assets/a.opus", &FileType::Opus)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opus_write() {
|
||||
write("tests/assets/a.opus", &FileType::Opus)
|
||||
write("tests/files/assets/a.opus", &FileType::Opus)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opus_remove() {
|
||||
remove("tests/assets/a.opus", TagType::VorbisComments)
|
||||
remove("tests/files/assets/a.opus", TagType::VorbisComments)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flac_read() {
|
||||
// FLAC does **not** require a Vorbis comment block be present, this file has one
|
||||
read("tests/assets/a.flac", &FileType::FLAC)
|
||||
read("tests/files/assets/a.flac", &FileType::FLAC)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flac_write() {
|
||||
write("tests/assets/a.flac", &FileType::FLAC)
|
||||
write("tests/files/assets/a.flac", &FileType::FLAC)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flac_remove() {
|
||||
crate::remove_tag!("tests/assets/a.flac", TagType::VorbisComments);
|
||||
crate::remove_tag!("tests/files/assets/a.flac", TagType::VorbisComments);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vorbis_read() {
|
||||
read("tests/assets/a.ogg", &FileType::Vorbis)
|
||||
read("tests/files/assets/a.ogg", &FileType::Vorbis)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vorbis_write() {
|
||||
write("tests/assets/a.ogg", &FileType::Vorbis)
|
||||
write("tests/files/assets/a.ogg", &FileType::Vorbis)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vorbis_remove() {
|
||||
remove("tests/assets/a.ogg", TagType::VorbisComments)
|
||||
remove("tests/files/assets/a.ogg", TagType::VorbisComments)
|
||||
}
|
||||
|
||||
fn read(path: &str, file_type: &FileType) {
|
|
@ -1,12 +1,11 @@
|
|||
mod util;
|
||||
|
||||
use lofty::{FileType, ItemKey, ItemValue, Probe, TagItem, TagType};
|
||||
use std::io::{Seek, Write};
|
||||
use crate::{verify_artist, set_artist};
|
||||
|
||||
#[test]
|
||||
fn read() {
|
||||
// Here we have a WAV file with both an ID3v2 chunk and a RIFF INFO chunk
|
||||
let file = Probe::new().read_from_path("tests/assets/a.wav").unwrap();
|
||||
let file = Probe::new().read_from_path("tests/files/assets/a.wav").unwrap();
|
||||
|
||||
assert_eq!(file.file_type(), &FileType::WAV);
|
||||
|
||||
|
@ -20,7 +19,7 @@ fn read() {
|
|||
#[test]
|
||||
fn write() {
|
||||
let mut file = tempfile::tempfile().unwrap();
|
||||
file.write_all(&std::fs::read("tests/assets/a.wav").unwrap())
|
||||
file.write_all(&std::fs::read("tests/files/assets/a.wav").unwrap())
|
||||
.unwrap();
|
||||
|
||||
let mut tagged_file = Probe::new().read_from(&mut file).unwrap();
|
||||
|
@ -45,10 +44,10 @@ fn write() {
|
|||
|
||||
#[test]
|
||||
fn remove_id3v2() {
|
||||
crate::remove_tag!("tests/assets/a.wav", TagType::Id3v2);
|
||||
crate::remove_tag!("tests/files/assets/a.wav", TagType::Id3v2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_riff_info() {
|
||||
crate::remove_tag!("tests/assets/a.wav", TagType::RiffInfo);
|
||||
crate::remove_tag!("tests/files/assets/a.wav", TagType::RiffInfo);
|
||||
}
|
|
@ -86,7 +86,7 @@ where
|
|||
#[test]
|
||||
fn aiff_properties() {
|
||||
assert_eq!(
|
||||
get_properties::<AiffFile>("tests/assets/a.aiff"),
|
||||
get_properties::<AiffFile>("tests/files/assets/a.aiff"),
|
||||
AIFF_PROPERTIES
|
||||
);
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ fn aiff_properties() {
|
|||
#[test]
|
||||
fn ape_properties() {
|
||||
assert_eq!(
|
||||
get_properties::<ApeFile>("tests/assets/a.ape"),
|
||||
get_properties::<ApeFile>("tests/files/assets/a.ape"),
|
||||
APE_PROPERTIES
|
||||
);
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ fn ape_properties() {
|
|||
#[test]
|
||||
fn flac_properties() {
|
||||
assert_eq!(
|
||||
get_properties::<FlacFile>("tests/assets/a.flac"),
|
||||
get_properties::<FlacFile>("tests/files/assets/a.flac"),
|
||||
FLAC_PROPERTIES
|
||||
)
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ fn flac_properties() {
|
|||
#[test]
|
||||
fn mp3_properties() {
|
||||
assert_eq!(
|
||||
get_properties::<Mp3File>("tests/assets/a.mp3"),
|
||||
get_properties::<Mp3File>("tests/files/assets/a.mp3"),
|
||||
MP3_PROPERTIES
|
||||
)
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ fn mp3_properties() {
|
|||
#[test]
|
||||
fn mp4_properties() {
|
||||
assert_eq!(
|
||||
get_properties::<Mp4File>("tests/assets/a.m4a"),
|
||||
get_properties::<Mp4File>("tests/files/assets/a.m4a"),
|
||||
MP4_PROPERTIES
|
||||
)
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ fn mp4_properties() {
|
|||
#[test]
|
||||
fn opus_properties() {
|
||||
assert_eq!(
|
||||
get_properties::<OpusFile>("tests/assets/a.opus"),
|
||||
get_properties::<OpusFile>("tests/files/assets/a.opus"),
|
||||
OPUS_PROPERTIES
|
||||
)
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ fn opus_properties() {
|
|||
#[test]
|
||||
fn vorbis_properties() {
|
||||
assert_eq!(
|
||||
get_properties::<VorbisFile>("tests/assets/a.ogg"),
|
||||
get_properties::<VorbisFile>("tests/files/assets/a.ogg"),
|
||||
VORBIS_PROPERTIES
|
||||
)
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ fn vorbis_properties() {
|
|||
#[test]
|
||||
fn wav_properties() {
|
||||
assert_eq!(
|
||||
get_properties::<WavFile>("tests/assets/a.wav"),
|
||||
get_properties::<WavFile>("tests/files/assets/a.wav"),
|
||||
WAV_PROPERTIES
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue