2021-04-07 00:57:30 +00:00
|
|
|
#![cfg(feature = "default")]
|
2021-04-03 00:47:44 +00:00
|
|
|
use lofty::{MimeType, Picture, 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-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-14 03:29:13 +00:00
|
|
|
let mut tag = Tag::default().read_from_path($file).unwrap();
|
|
|
|
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Setting title");
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.set_title("foo title");
|
|
|
|
assert_eq!(tag.title(), Some("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");
|
|
|
|
assert_eq!(tag.artist(), Some("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);
|
|
|
|
assert_eq!(tag.year(), Some(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");
|
|
|
|
assert_eq!(tag.album_title(), Some("foo album title"));
|
|
|
|
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Setting album artists");
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.set_album_artists("foo album artist".to_string());
|
|
|
|
assert_eq!(tag.album_artists(), Some(vec!["foo album artist"]));
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// let cover = Picture {
|
|
|
|
// mime_type: MimeType::Jpeg,
|
|
|
|
// data: &vec![0u8; 10],
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// tags.set_album_cover(cover.clone());
|
|
|
|
// assert_eq!(tags.album_cover(), Some(cover));
|
|
|
|
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Writing");
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.write_to_path($file).unwrap();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! remove_tags {
|
|
|
|
($file:expr) => {
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Reading file");
|
2021-04-14 03:29:13 +00:00
|
|
|
let mut tag = Tag::default().read_from_path($file).unwrap();
|
2021-04-14 15:14:08 +00:00
|
|
|
|
|
|
|
println!("Checking title");
|
2021-04-14 03:29:13 +00:00
|
|
|
assert_eq!(tag.title(), Some("foo title"));
|
|
|
|
|
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();
|
|
|
|
assert!(tag.artist().is_none());
|
|
|
|
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();
|
|
|
|
assert!(tag.album_artists().is_none());
|
|
|
|
tag.remove_album_artists();
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// tags.remove_album_cover();
|
|
|
|
// assert!(tags.album_cover().is_none());
|
|
|
|
// tags.remove_album_cover();
|
|
|
|
|
2021-04-14 15:14:08 +00:00
|
|
|
println!("Writing");
|
2021-04-14 03:29:13 +00:00
|
|
|
tag.write_to_path($file).unwrap();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
full_test!(test_ape, "tests/assets/a.ape");
|
|
|
|
full_test!(test_m4a, "tests/assets/a.m4a");
|
|
|
|
full_test!(test_mp3, "tests/assets/a.mp3");
|
|
|
|
full_test!(test_wav, "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");
|
|
|
|
full_test!(test_ogg, "tests/assets/a.ogg");
|
|
|
|
full_test!(test_opus, "tests/assets/a.opus");
|