2021-04-07 00:57:30 +00:00
|
|
|
#![cfg(feature = "default")]
|
2021-05-16 03:43:31 +00:00
|
|
|
use lofty::{MimeType, Picture, PictureType, Tag};
|
2020-10-26 20:43:11 +00:00
|
|
|
|
2021-04-14 03:29:13 +00:00
|
|
|
macro_rules! full_test {
|
|
|
|
($function:ident, $file:expr) => {
|
2021-04-03 00:47:44 +00:00
|
|
|
#[test]
|
|
|
|
fn $function() {
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("-- Adding tags --");
|
2021-04-14 03:29:13 +00:00
|
|
|
add_tags!($file);
|
2021-04-22 17:56:51 +00:00
|
|
|
println!("-- Verifying tags --");
|
|
|
|
verify_write!($file);
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("-- Removing tags --");
|
2021-04-14 03:29:13 +00:00
|
|
|
remove_tags!($file);
|
2021-04-03 00:47:44 +00:00
|
|
|
}
|
|
|
|
};
|
2020-10-26 20:43:11 +00:00
|
|
|
}
|
|
|
|
|
2021-04-14 03:29:13 +00:00
|
|
|
macro_rules! add_tags {
|
|
|
|
($file:expr) => {
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Reading file");
|
2021-04-22 22:01:09 +00:00
|
|
|
let mut tag = Tag::default().read_from_path_signature($file).unwrap();
|
2021-04-14 03:29:13 +00:00
|
|
|
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Setting title");
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.set_title("foo title");
|
|
|
|
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Setting artist");
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.set_artist("foo artist");
|
|
|
|
|
2021-04-17 19:42:06 +00:00
|
|
|
println!("Setting year");
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.set_year(2020);
|
|
|
|
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Setting album title");
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.set_album_title("foo album title");
|
|
|
|
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Setting album artists");
|
2021-04-18 19:32:59 +00:00
|
|
|
tag.set_album_artist("foo album artist");
|
2021-04-14 03:29:13 +00:00
|
|
|
|
2021-05-16 17:16:57 +00:00
|
|
|
let covers = (
|
|
|
|
Picture {
|
|
|
|
pic_type: PictureType::CoverFront,
|
|
|
|
mime_type: MimeType::Jpeg,
|
2021-05-17 01:12:38 +00:00
|
|
|
data: vec![0, 74, 80, 69, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
2021-05-16 17:16:57 +00:00
|
|
|
},
|
|
|
|
Picture {
|
|
|
|
pic_type: PictureType::CoverBack,
|
|
|
|
mime_type: MimeType::Jpeg,
|
2021-05-17 01:12:38 +00:00
|
|
|
data: vec![0, 74, 80, 69, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
2021-05-16 17:16:57 +00:00
|
|
|
},
|
|
|
|
);
|
2021-04-24 01:15:33 +00:00
|
|
|
|
2021-05-17 01:12:38 +00:00
|
|
|
let file = stringify!($file);
|
2021-05-16 03:43:31 +00:00
|
|
|
|
2021-05-17 01:12:38 +00:00
|
|
|
// Skip this since RIFF INFO doesn't store images
|
|
|
|
if file != stringify!("tests/assets/a.wav") {
|
2021-05-16 17:16:57 +00:00
|
|
|
println!("Setting front cover");
|
|
|
|
tag.set_front_cover(covers.0.clone());
|
|
|
|
assert_eq!(tag.front_cover(), Some(covers.0));
|
|
|
|
|
|
|
|
println!("Setting back cover");
|
|
|
|
tag.set_back_cover(covers.1.clone());
|
|
|
|
assert_eq!(tag.back_cover(), Some(covers.1));
|
2021-05-16 03:43:31 +00:00
|
|
|
}
|
2021-04-14 03:29:13 +00:00
|
|
|
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Writing");
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.write_to_path($file).unwrap();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-22 17:56:51 +00:00
|
|
|
macro_rules! verify_write {
|
2021-04-14 03:29:13 +00:00
|
|
|
($file:expr) => {
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Reading file");
|
2021-04-22 22:01:09 +00:00
|
|
|
let tag = Tag::default().read_from_path_signature($file).unwrap();
|
2021-04-14 15:14:08 +00:00
|
|
|
|
2021-04-22 17:56:51 +00:00
|
|
|
let file_name = stringify!($file);
|
|
|
|
|
|
|
|
println!("Verifying title");
|
2021-04-14 03:29:13 +00:00
|
|
|
assert_eq!(tag.title(), Some("foo title"));
|
|
|
|
|
2021-04-22 17:56:51 +00:00
|
|
|
println!("Verifying artist");
|
|
|
|
assert_eq!(tag.artist_str(), Some("foo artist"));
|
|
|
|
|
|
|
|
// Skip this since RIFF INFO doesn't support year
|
|
|
|
if file_name != stringify!("tests/assets/a.wav") {
|
|
|
|
println!("Verifying year");
|
|
|
|
assert_eq!(tag.year(), Some(2020));
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("Verifying album title");
|
|
|
|
assert_eq!(tag.album_title(), Some("foo album title"));
|
|
|
|
|
|
|
|
// Skip this since RIFF INFO doesn't guarantee album artist
|
|
|
|
if file_name != stringify!("tests/assets/a.wav") {
|
|
|
|
println!("Verifying album artist");
|
|
|
|
assert_eq!(tag.album_artists_vec(), Some(vec!["foo album artist"]));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! remove_tags {
|
|
|
|
($file:expr) => {
|
|
|
|
println!("Reading file");
|
2021-04-22 22:01:09 +00:00
|
|
|
let mut tag = Tag::default().read_from_path_signature($file).unwrap();
|
2021-04-22 17:56:51 +00:00
|
|
|
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Removing title");
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.remove_title();
|
|
|
|
assert!(tag.title().is_none());
|
|
|
|
tag.remove_title(); // should not panic
|
|
|
|
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Removing artist");
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.remove_artist();
|
2021-04-18 19:32:59 +00:00
|
|
|
assert!(tag.artist_str().is_none());
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.remove_artist();
|
|
|
|
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Removing year");
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.remove_year();
|
|
|
|
assert!(tag.year().is_none());
|
|
|
|
tag.remove_year();
|
|
|
|
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Removing album title");
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.remove_album_title();
|
|
|
|
assert!(tag.album_title().is_none());
|
|
|
|
tag.remove_album_title();
|
|
|
|
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Removing album artists");
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.remove_album_artists();
|
2021-04-18 19:32:59 +00:00
|
|
|
assert!(tag.album_artists_vec().is_none());
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.remove_album_artists();
|
|
|
|
|
2021-05-16 17:16:57 +00:00
|
|
|
tag.remove_album_covers();
|
|
|
|
assert_eq!(tag.album_covers(), (None, None));
|
|
|
|
tag.remove_album_covers();
|
2021-04-14 03:29:13 +00:00
|
|
|
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Writing");
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.write_to_path($file).unwrap();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-22 15:15:19 +00:00
|
|
|
// APEv2
|
2021-04-14 03:29:13 +00:00
|
|
|
full_test!(test_ape, "tests/assets/a.ape");
|
2021-04-22 15:15:19 +00:00
|
|
|
|
|
|
|
// ID3v2
|
2021-04-14 03:29:13 +00:00
|
|
|
full_test!(test_mp3, "tests/assets/a.mp3");
|
2021-04-22 16:57:20 +00:00
|
|
|
full_test!(test_aiff, "tests/assets/a.aiff");
|
2021-04-22 15:15:19 +00:00
|
|
|
full_test!(test_wav_id3, "tests/assets/a-id3.wav");
|
|
|
|
|
|
|
|
// RIFF INFO
|
|
|
|
full_test!(test_wav_riff_info, "tests/assets/a.wav");
|
2021-04-07 00:57:30 +00:00
|
|
|
|
|
|
|
// Vorbis comments
|
2021-04-14 03:29:13 +00:00
|
|
|
full_test!(test_flac, "tests/assets/a.flac");
|
2021-04-22 15:15:19 +00:00
|
|
|
full_test!(test_m4a, "tests/assets/a.m4a");
|
2021-04-14 03:29:13 +00:00
|
|
|
full_test!(test_ogg, "tests/assets/a.ogg");
|
|
|
|
full_test!(test_opus, "tests/assets/a.opus");
|