diff --git a/Cargo.toml b/Cargo.toml index bc04b052d..327c9517c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ id3v2_compression_support = ["dep:flate2"] [dev-dependencies] # WAV properties validity tests hound = { git = "https://github.com/ruuda/hound.git", rev = "02e66effb33683dd6acb92df792683ee46ad6a59" } +rusty-fork = "0.3.0" # tag_writer example structopt = { version = "0.3.26", default-features = false } tempfile = "3.9.0" diff --git a/tests/taglib/test_aiff.rs b/tests/taglib/test_aiff.rs index d30a3096b..d0854d25b 100644 --- a/tests/taglib/test_aiff.rs +++ b/tests/taglib/test_aiff.rs @@ -5,7 +5,7 @@ use std::io::Seek; use lofty::id3::v2::Id3v2Tag; use lofty::iff::aiff::{AiffCompressionType, AiffFile}; -use lofty::{Accessor, AudioFile, FileType, ParseOptions, Probe}; +use lofty::{Accessor, AudioFile, FileType, ParseOptions, Probe, WriteOptions}; #[test] fn test_aiff_properties() { @@ -65,7 +65,7 @@ fn test_save_id3v2() { id3v2.set_title("TitleXXX".to_string()); tfile.set_id3v2(id3v2); file.rewind().unwrap(); - tfile.save_to(&mut file).unwrap(); + tfile.save_to(&mut file, WriteOptions::default()).unwrap(); assert!(tfile.contains_tag_type(lofty::TagType::Id3v2)); } @@ -81,7 +81,7 @@ fn test_save_id3v2() { id3v2.remove_title(); tfile.set_id3v2(id3v2); file.rewind().unwrap(); - tfile.save_to(&mut file).unwrap(); + tfile.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); diff --git a/tests/taglib/test_ape.rs b/tests/taglib/test_ape.rs index 09c74d8a0..dc2487333 100644 --- a/tests/taglib/test_ape.rs +++ b/tests/taglib/test_ape.rs @@ -6,7 +6,7 @@ use std::time::Duration; use lofty::ape::{ApeFile, ApeItem, ApeTag}; use lofty::id3::v1::Id3v1Tag; -use lofty::{Accessor, AudioFile, FileType, ItemValue, ParseOptions, Probe, TagExt}; +use lofty::{Accessor, AudioFile, FileType, ItemValue, ParseOptions, Probe, TagExt, WriteOptions}; fn test_399(path: &str) { let f = get_file::(path); @@ -106,7 +106,9 @@ fn test_strip_and_properties() { ape_file.set_id3v1(id3v1_tag); file.rewind().unwrap(); - ape_file.save_to(&mut file).unwrap(); + ape_file + .save_to(&mut file, WriteOptions::default()) + .unwrap(); } { file.rewind().unwrap(); @@ -337,7 +339,11 @@ fn test_properties() { ape_file.set_ape(tag.clone()); file.rewind().unwrap(); - ape_file.ape().unwrap().save_to(&mut file).unwrap(); + ape_file + .ape() + .unwrap() + .save_to(&mut file, WriteOptions::default()) + .unwrap(); } { file.rewind().unwrap(); @@ -358,11 +364,15 @@ fn test_repeated_save() { let mut ape_tag = ApeTag::default(); ape_tag.set_title(String::from("01234 56789 ABCDE FGHIJ")); ape_file.set_ape(ape_tag); - ape_file.save_to(&mut file).unwrap(); + ape_file + .save_to(&mut file, WriteOptions::default()) + .unwrap(); file.rewind().unwrap(); ape_file.ape_mut().unwrap().set_title(String::from("0")); - ape_file.save_to(&mut file).unwrap(); + ape_file + .save_to(&mut file, WriteOptions::default()) + .unwrap(); file.rewind().unwrap(); let mut id3v1_tag = Id3v1Tag::default(); @@ -371,7 +381,9 @@ fn test_repeated_save() { ape_file.ape_mut().unwrap().set_title(String::from( "01234 56789 ABCDE FGHIJ 01234 56789 ABCDE FGHIJ 01234 56789", )); - ape_file.save_to(&mut file).unwrap(); + ape_file + .save_to(&mut file, WriteOptions::default()) + .unwrap(); } { file.rewind().unwrap(); diff --git a/tests/taglib/test_apetag.rs b/tests/taglib/test_apetag.rs index 2bc591abb..077e838e6 100644 --- a/tests/taglib/test_apetag.rs +++ b/tests/taglib/test_apetag.rs @@ -4,7 +4,7 @@ use std::io::Seek; use lofty::ape::{ApeItem, ApeTag}; use lofty::musepack::MpcFile; -use lofty::{Accessor, AudioFile, ItemValue, ParseOptions, TagExt}; +use lofty::{Accessor, AudioFile, ItemValue, ParseOptions, TagExt, WriteOptions}; #[test] fn test_is_empty() { @@ -104,7 +104,9 @@ fn test_id3v1_collision() { ape_tag.set_artist(String::from("Filltointersect ")); ape_tag.set_title(String::from("Filltointersect ")); mpc_file.set_ape(ape_tag); - mpc_file.save_to(&mut file).unwrap(); + mpc_file + .save_to(&mut file, WriteOptions::default()) + .unwrap(); } { file.rewind().unwrap(); diff --git a/tests/taglib/test_fileref.rs b/tests/taglib/test_fileref.rs index 4eaff6d22..d11db9b6b 100644 --- a/tests/taglib/test_fileref.rs +++ b/tests/taglib/test_fileref.rs @@ -6,8 +6,8 @@ use std::io::{Read, Seek}; use lofty::error::ErrorKind; use lofty::resolve::FileResolver; use lofty::{ - Accessor, AudioFile, FileProperties, FileType, ParseOptions, Tag, TagExt, TagType, TaggedFile, - TaggedFileExt, + Accessor, AudioFile, FileProperties, FileType, GlobalOptions, ParseOptions, Tag, TagExt, + TagType, TaggedFile, TaggedFileExt, WriteOptions, }; fn file_ref_save(path: &str, expected_file_type: FileType) { @@ -33,7 +33,7 @@ fn file_ref_save(path: &str, expected_file_type: FileType) { tag.set_comment(String::from("a comment")); tag.set_track(5); tag.set_year(2020); - tag.save_to(&mut file).unwrap(); + tag.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -55,7 +55,7 @@ fn file_ref_save(path: &str, expected_file_type: FileType) { tag.set_comment(String::from("another comment")); tag.set_track(7); tag.set_year(2080); - tag.save_to(&mut file).unwrap(); + tag.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -214,72 +214,76 @@ fn test_default_file_extensions() { // Marker test, Lofty does not replicate this API } -// TODO: We need to check resolvers *first* and then resort to our default implementations -#[test] -#[ignore] -fn test_file_resolver() { - { - let file = lofty::read_from_path("tests/taglib/data/xing.mp3").unwrap(); - assert_eq!(file.file_type(), FileType::Mpeg); - } - - struct DummyResolver; - impl Into for DummyResolver { - fn into(self) -> TaggedFile { - TaggedFile::new(FileType::Vorbis, FileProperties::default(), Vec::new()) - } - } +use rusty_fork::rusty_fork_test; - impl AudioFile for DummyResolver { - type Properties = (); +rusty_fork_test! { + #[test] + fn test_file_resolver() { + lofty::apply_global_options(GlobalOptions::new().use_custom_resolvers(true)); - fn read_from(_: &mut R, _: ParseOptions) -> lofty::Result - where - R: Read + Seek, - Self: Sized, { - Ok(Self) + let file = lofty::read_from_path("tests/taglib/data/xing.mp3").unwrap(); + assert_eq!(file.file_type(), FileType::Mpeg); } - fn save_to(&self, _: &mut File) -> lofty::Result<()> { - unimplemented!() + struct DummyResolver; + impl Into for DummyResolver { + fn into(self) -> TaggedFile { + TaggedFile::new(FileType::Vorbis, FileProperties::default(), Vec::new()) + } } - fn properties(&self) -> &Self::Properties { - unimplemented!() - } + impl AudioFile for DummyResolver { + type Properties = (); - fn contains_tag(&self) -> bool { - unimplemented!() - } + fn read_from(_: &mut R, _: ParseOptions) -> lofty::Result + where + R: Read + Seek, + Self: Sized, + { + Ok(Self) + } - fn contains_tag_type(&self, _: TagType) -> bool { - unimplemented!() - } - } + fn save_to(&self, _: &mut File, _: WriteOptions) -> lofty::Result<()> { + unimplemented!() + } - impl FileResolver for DummyResolver { - fn extension() -> Option<&'static str> { - Some("mp3") - } + fn properties(&self) -> &Self::Properties { + unimplemented!() + } - fn primary_tag_type() -> TagType { - unimplemented!() - } + fn contains_tag(&self) -> bool { + unimplemented!() + } - fn supported_tag_types() -> &'static [TagType] { - unimplemented!() + fn contains_tag_type(&self, _: TagType) -> bool { + unimplemented!() + } } - fn guess(_: &[u8]) -> Option { - Some(FileType::Vorbis) + impl FileResolver for DummyResolver { + fn extension() -> Option<&'static str> { + Some("mp3") + } + + fn primary_tag_type() -> TagType { + unimplemented!() + } + + fn supported_tag_types() -> &'static [TagType] { + unimplemented!() + } + + fn guess(_: &[u8]) -> Option { + Some(FileType::Vorbis) + } } - } - lofty::resolve::register_custom_resolver::("Dummy"); + lofty::resolve::register_custom_resolver::("Dummy"); - { - let file = lofty::read_from_path("tests/taglib/data/xing.mp3").unwrap(); - assert_eq!(file.file_type(), FileType::Vorbis); + { + let file = lofty::read_from_path("tests/taglib/data/xing.mp3").unwrap(); + assert_eq!(file.file_type(), FileType::Vorbis); + } } } diff --git a/tests/taglib/test_flac.rs b/tests/taglib/test_flac.rs index cdccbf12b..8af0805cf 100644 --- a/tests/taglib/test_flac.rs +++ b/tests/taglib/test_flac.rs @@ -8,6 +8,7 @@ use lofty::id3::v2::Id3v2Tag; use lofty::ogg::{OggPictureStorage, VorbisComments}; use lofty::{ Accessor, AudioFile, MimeType, ParseOptions, Picture, PictureInformation, PictureType, TagExt, + WriteOptions, }; #[test] @@ -69,7 +70,7 @@ fn test_add_picture() { }; f.insert_picture(new_pic, Some(new_pic_info)).unwrap(); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -126,7 +127,7 @@ fn test_replace_picture() { f.remove_pictures(); f.insert_picture(new_pic, Some(new_pic_info)).unwrap(); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -159,7 +160,7 @@ fn test_remove_all_pictures() { assert_eq!(lst.len(), 1); f.remove_pictures(); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -185,7 +186,7 @@ fn test_repeated_save_1() { f.vorbis_comments_mut() .unwrap() .set_title(String::from("NEW TITLE")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); file.rewind().unwrap(); assert_eq!( @@ -195,7 +196,7 @@ fn test_repeated_save_1() { f.vorbis_comments_mut() .unwrap() .set_title(String::from("NEW TITLE 2")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); assert_eq!( f.vorbis_comments().unwrap().title().as_deref(), @@ -232,10 +233,10 @@ fn test_repeated_save_3() { tag.set_title(String::from_utf8(vec![b'X'; 8 * 1024]).unwrap()); f.set_vorbis_comments(tag); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); file.rewind().unwrap(); assert_eq!(file.metadata().unwrap().len(), 12862); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); assert_eq!(file.metadata().unwrap().len(), 12862); } @@ -252,7 +253,7 @@ fn test_save_multiple_values() { f.vorbis_comments_mut() .unwrap() .push(String::from("ARTIST"), String::from("artist 2")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -347,7 +348,10 @@ fn test_properties() { f.set_vorbis_comments(tag.clone()); file.rewind().unwrap(); - f.vorbis_comments().unwrap().save_to(&mut file).unwrap(); + f.vorbis_comments() + .unwrap() + .save_to(&mut file, WriteOptions::default()) + .unwrap(); } file.rewind().unwrap(); { @@ -405,7 +409,7 @@ fn test_zero_sized_padding_2() { f.vorbis_comments_mut() .unwrap() .set_title(String::from("ABC")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -415,7 +419,7 @@ fn test_zero_sized_padding_2() { f.vorbis_comments_mut() .unwrap() .set_title(String::from_utf8(vec![b'X'; 3067]).unwrap()); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -435,7 +439,7 @@ fn test_shrink_padding() { f.vorbis_comments_mut() .unwrap() .set_title(String::from_utf8(vec![b'X'; 128 * 1024]).unwrap()); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); assert!(file.metadata().unwrap().len() > 128 * 1024); } file.rewind().unwrap(); @@ -446,7 +450,7 @@ fn test_shrink_padding() { f.vorbis_comments_mut() .unwrap() .set_title(String::from("0123456789")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); assert!(file.metadata().unwrap().len() < 8 * 1024); } } @@ -471,7 +475,7 @@ fn test_empty_id3v2() { file.rewind().unwrap(); f.set_id3v2(Id3v2Tag::default()); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -494,7 +498,7 @@ fn test_strip_tags() { f.vorbis_comments_mut() .unwrap() .set_title(String::from("XiphComment Title")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -507,7 +511,7 @@ fn test_strip_tags() { Some("XiphComment Title") ); f.remove_vorbis_comments(); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -533,7 +537,7 @@ fn test_remove_xiph_field() { f.vorbis_comments_mut() .unwrap() .set_title(String::from("XiphComment Title")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -545,7 +549,7 @@ fn test_remove_xiph_field() { Some("XiphComment Title") ); let _ = f.vorbis_comments_mut().unwrap().remove("TITLE"); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -566,7 +570,7 @@ fn test_empty_seek_table() { let mut tag = VorbisComments::default(); tag.set_title(String::from("XiphComment Title")); f.set_vorbis_comments(tag); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -620,7 +624,7 @@ fn test_picture_stored_after_comment() { let mut tag = VorbisComments::default(); tag.set_title(String::from("Title")); f.set_vorbis_comments(tag); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { diff --git a/tests/taglib/test_id3v2.rs b/tests/taglib/test_id3v2.rs index f37854020..ad2ea51c4 100644 --- a/tests/taglib/test_id3v2.rs +++ b/tests/taglib/test_id3v2.rs @@ -15,7 +15,7 @@ use lofty::id3::v2::{ use lofty::mpeg::MpegFile; use lofty::{ Accessor, AudioFile, MimeType, ParseOptions, ParsingMode, Picture, PictureType, TagExt, - TextEncoding, + TextEncoding, WriteOptions, }; #[test] @@ -317,7 +317,7 @@ fn test_popm_from_file() { Frame::new("POPM", FrameValue::Popularimeter(f), FrameFlags::default()).unwrap(), ); foo.set_id3v2(tag); - foo.save_to(&mut file).unwrap(); + foo.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -839,7 +839,7 @@ fn test_save_utf16_comment() { .unwrap(), ); foo.set_id3v2(tag); - foo.save_to(&mut file).unwrap(); + foo.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -995,7 +995,7 @@ fn test_delete_frame() { let t = f.id3v2_mut().unwrap(); let _ = t.remove(&FrameId::Valid(Cow::Borrowed("TCON"))); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -1016,7 +1016,7 @@ fn test_save_and_strip_id3v1_should_not_add_frame_from_id3v1_to_id3v2() { let mut tag = Id3v2Tag::new(); tag.set_artist(String::from("Artist")); foo.set_id3v2(tag); - foo.save_to(&mut file).unwrap(); + foo.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -1028,7 +1028,7 @@ fn test_save_and_strip_id3v1_should_not_add_frame_from_id3v1_to_id3v2() { .unwrap() .remove(&FrameId::Valid(Cow::Borrowed("TPE1"))); - bar.save_to(&mut file).unwrap(); + bar.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); diff --git a/tests/taglib/test_mp4.rs b/tests/taglib/test_mp4.rs index eceec7aa0..adc844c68 100644 --- a/tests/taglib/test_mp4.rs +++ b/tests/taglib/test_mp4.rs @@ -5,7 +5,10 @@ use std::borrow::Cow; use std::io::{Read, Seek}; use lofty::mp4::{Atom, AtomData, AtomIdent, Ilst, Mp4Codec, Mp4File}; -use lofty::{Accessor, AudioFile, MimeType, ParseOptions, Picture, PictureType, TagExt, TagType}; +use lofty::{ + Accessor, AudioFile, MimeType, ParseOptions, Picture, PictureType, TagExt, TagType, + WriteOptions, +}; #[test] fn test_properties_aac() { @@ -119,7 +122,7 @@ fn test_has_tag() { let mut tag = Ilst::default(); tag.set_title(String::from("TITLE")); f.set_ilst(tag); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -151,7 +154,7 @@ fn test_update_stco() { // Find and collect all `stco` offsets - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -181,7 +184,7 @@ fn test_freeform() { }, AtomData::UTF8(String::from("Bar")), )); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -203,7 +206,7 @@ fn test_freeform() { .next(), Some(&AtomData::UTF8(String::from("Bar"))) ); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } } @@ -229,7 +232,7 @@ fn test_save_existing_when_ilst_is_last() { ); assert_eq!(ilst.artist().as_deref(), Some("Pearl Jam")); ilst.set_comment(String::from("foo")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -300,7 +303,7 @@ fn test_covr_write() { None, b"foo".to_vec(), )); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -382,9 +385,9 @@ fn test_repeated_save() { tag.set_title(String::from("0123456789")); f.set_ilst(tag); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); file.rewind().unwrap(); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); file.rewind().unwrap(); let mut file_bytes = Vec::new(); @@ -425,7 +428,7 @@ fn test_remove_metadata() { assert!(tag.is_empty()); tag.set_title(String::from("TITLE")); f.set_ilst(tag); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { diff --git a/tests/taglib/test_mpc.rs b/tests/taglib/test_mpc.rs index 6aa10022b..145e5361e 100644 --- a/tests/taglib/test_mpc.rs +++ b/tests/taglib/test_mpc.rs @@ -6,7 +6,7 @@ use std::io::Seek; use lofty::ape::ApeTag; use lofty::id3::v1::Id3v1Tag; use lofty::musepack::{MpcFile, MpcProperties}; -use lofty::{Accessor, AudioFile, ParseOptions, Probe, TagExt}; +use lofty::{Accessor, AudioFile, ParseOptions, Probe, TagExt, WriteOptions}; #[test] fn test_properties_sv8() { @@ -131,7 +131,7 @@ fn test_strip_and_properties() { let mut id3v1 = Id3v1Tag::new(); id3v1.set_title(String::from("ID3v1")); f.set_id3v1(id3v1); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -142,7 +142,7 @@ fn test_strip_and_properties() { f.ape_mut().unwrap().clear(); assert_eq!(f.id3v1().unwrap().title().as_deref(), Some("ID3v1")); f.id3v1_mut().unwrap().clear(); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -168,12 +168,12 @@ fn test_repeated_save() { ape.set_title(String::from("01234 56789 ABCDE FGHIJ")); f.set_ape(ape); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); file.rewind().unwrap(); f.ape_mut().unwrap().set_title(String::from("0")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); file.rewind().unwrap(); let mut id3v1 = Id3v1Tag::new(); @@ -182,7 +182,7 @@ fn test_repeated_save() { f.ape_mut().unwrap().set_title(String::from( "01234 56789 ABCDE FGHIJ 01234 56789 ABCDE FGHIJ 01234 56789", )); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { diff --git a/tests/taglib/test_mpeg.rs b/tests/taglib/test_mpeg.rs index d3dda2868..23173ba13 100644 --- a/tests/taglib/test_mpeg.rs +++ b/tests/taglib/test_mpeg.rs @@ -8,7 +8,7 @@ use lofty::ape::ApeTag; use lofty::id3::v1::Id3v1Tag; use lofty::id3::v2::{Id3v2Tag, Id3v2Version}; use lofty::mpeg::MpegFile; -use lofty::{Accessor, AudioFile, ParseOptions}; +use lofty::{Accessor, AudioFile, ParseOptions, WriteOptions}; #[test] fn test_audio_properties_xing_header_cbr() { @@ -117,7 +117,7 @@ fn test_save_id3v24() { tag.set_title(xxx.clone()); tag.set_artist(String::from("Artist A")); f.set_id3v2(tag); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -150,7 +150,7 @@ fn test_save_id3v23() { tag.set_title(xxx.clone()); tag.set_artist(String::from("Artist A")); f.set_id3v2(tag); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -196,7 +196,7 @@ fn test_strip_and_properties() { let mut id3v1 = Id3v1Tag::default(); id3v1.set_title(String::from("ID3v1")); f.set_id3v1(id3v1); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -240,12 +240,12 @@ fn test_repeated_save_3() { let mut ape = ApeTag::default(); ape.set_title(String::from("01234 56789 ABCDE FGHIJ")); f.set_ape(ape); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { f.ape_mut().unwrap().set_title(String::from("0")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } { let mut id3v1 = Id3v1Tag::default(); @@ -257,7 +257,7 @@ fn test_repeated_save_3() { f.ape_mut().unwrap().set_title(String::from( "01234 56789 ABCDE FGHIJ 01234 56789 ABCDE FGHIJ 01234 56789", )); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } } file.rewind().unwrap(); @@ -286,7 +286,6 @@ fn test_empty_ape() { // Marker test, Lofty accepts empty strings as valid values } -// TODO: We can't find an ID3v2 tag after saving with garbage #[test] fn test_ignore_garbage() { let mut file = temp_file!("tests/taglib/data/garbage.mp3"); @@ -298,7 +297,7 @@ fn test_ignore_garbage() { assert_eq!(f.id3v2().unwrap().title().as_deref(), Some("Title A")); f.id3v2_mut().unwrap().set_title(String::from("Title B")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { diff --git a/tests/taglib/test_ogaflac.rs b/tests/taglib/test_ogaflac.rs index fd404bc34..ad7492066 100644 --- a/tests/taglib/test_ogaflac.rs +++ b/tests/taglib/test_ogaflac.rs @@ -4,7 +4,7 @@ use std::io::{Seek, SeekFrom}; use lofty::flac::FlacFile; use lofty::ogg::VorbisComments; -use lofty::{Accessor, AudioFile, ParseOptions}; +use lofty::{Accessor, AudioFile, ParseOptions, WriteOptions}; // TODO: We don't support FLAC in OGA (#172) #[test] @@ -19,7 +19,7 @@ fn test_framing_bit() { let mut vorbis_comments = VorbisComments::new(); vorbis_comments.set_artist(String::from("The Artist")); f.set_vorbis_comments(vorbis_comments); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { diff --git a/tests/taglib/test_ogg.rs b/tests/taglib/test_ogg.rs index b590ea9bd..9111343e9 100644 --- a/tests/taglib/test_ogg.rs +++ b/tests/taglib/test_ogg.rs @@ -5,7 +5,7 @@ use std::io::{Read, Seek, SeekFrom}; use byteorder::{LittleEndian, ReadBytesExt}; use lofty::ogg::VorbisFile; -use lofty::{Accessor, AudioFile, ParseOptions}; +use lofty::{Accessor, AudioFile, ParseOptions, WriteOptions}; #[test] fn test_simple() { @@ -17,7 +17,7 @@ fn test_simple() { f.vorbis_comments_mut() .set_artist(String::from("The Artist")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -42,7 +42,7 @@ fn test_split_packets2() { file.rewind().unwrap(); f.vorbis_comments_mut().set_title(text.clone()); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -52,7 +52,7 @@ fn test_split_packets2() { assert_eq!(f.vorbis_comments().title().as_deref(), Some(&*text)); f.vorbis_comments_mut().set_title(String::from("ABCDE")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -99,7 +99,7 @@ fn test_page_checksum() { f.vorbis_comments_mut() .set_title(String::from("The Artist")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); file.seek(SeekFrom::Start(0x50)).unwrap(); assert_eq!(file.read_u32::().unwrap(), 0x3D3BD92D); @@ -111,7 +111,7 @@ fn test_page_checksum() { f.vorbis_comments_mut() .set_title(String::from("The Artist 2")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); file.seek(SeekFrom::Start(0x50)).unwrap(); assert_eq!(file.read_u32::().unwrap(), 0xD985291C); @@ -130,7 +130,7 @@ fn test_page_granule_position() { // check if the granule position is -1 indicating that no packets // finish on this page. f.vorbis_comments_mut().set_comment("A".repeat(70000)); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); file.seek(SeekFrom::Start(0x3A)).unwrap(); let mut buf = [0; 6]; @@ -147,7 +147,7 @@ fn test_page_granule_position() { // check if the granule position is zero. f.vorbis_comments_mut() .set_comment(String::from("A small comment")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); file.seek(SeekFrom::Start(0x3A)).unwrap(); let mut buf = [0; 6]; diff --git a/tests/taglib/test_opus.rs b/tests/taglib/test_opus.rs index ec55612eb..71771ee81 100644 --- a/tests/taglib/test_opus.rs +++ b/tests/taglib/test_opus.rs @@ -4,7 +4,7 @@ use crate::util::get_file; use std::io::Seek; use lofty::ogg::OpusFile; -use lofty::{Accessor, AudioFile, ParseOptions}; +use lofty::{Accessor, AudioFile, ParseOptions, WriteOptions}; #[test] fn test_audio_properties() { @@ -38,7 +38,7 @@ fn test_write_comments() { file.rewind().unwrap(); f.vorbis_comments_mut() .set_artist(String::from("Your Tester")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { diff --git a/tests/taglib/test_speex.rs b/tests/taglib/test_speex.rs index afc436bf8..1c914c43b 100644 --- a/tests/taglib/test_speex.rs +++ b/tests/taglib/test_speex.rs @@ -4,7 +4,7 @@ use crate::util::get_file; use std::io::Seek; use lofty::ogg::{SpeexFile, VorbisComments}; -use lofty::{Accessor, AudioFile, ParseOptions}; +use lofty::{Accessor, AudioFile, ParseOptions, WriteOptions}; #[test] fn test_audio_properties() { @@ -34,7 +34,7 @@ fn test_split_packets() { let mut tag = VorbisComments::default(); tag.set_title(text.clone()); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -56,7 +56,7 @@ fn test_split_packets() { f.vorbis_comments_mut().set_title(String::from("ABCDE")); file.rewind().unwrap(); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { diff --git a/tests/taglib/test_wav.rs b/tests/taglib/test_wav.rs index 361ae86e2..e909ae205 100644 --- a/tests/taglib/test_wav.rs +++ b/tests/taglib/test_wav.rs @@ -2,7 +2,7 @@ use crate::temp_file; use crate::util::get_file; use lofty::id3::v2::Id3v2Tag; use lofty::iff::wav::{RIFFInfoList, WavFile, WavFormat}; -use lofty::{Accessor, AudioFile, ParseOptions, TagType}; +use lofty::{Accessor, AudioFile, ParseOptions, TagType, WriteOptions}; use std::io::{Cursor, Read, Seek, SeekFrom}; #[test] @@ -82,7 +82,7 @@ fn test_id3v2_tag() { id3v2.set_title(String::from("Title")); id3v2.set_artist(String::from("Artist")); f.set_id3v2(id3v2); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); assert!(f.id3v2().is_some()); } file.rewind().unwrap(); @@ -96,7 +96,7 @@ fn test_id3v2_tag() { f.id3v2_mut().unwrap().remove_title(); f.id3v2_mut().unwrap().remove_artist(); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -145,7 +145,7 @@ fn test_info_tag() { riff_info.set_artist(String::from("Artist")); f.set_riff_info(riff_info); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -158,7 +158,7 @@ fn test_info_tag() { f.riff_info_mut().unwrap().remove_title(); f.riff_info_mut().unwrap().remove_artist(); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -183,7 +183,7 @@ fn test_strip_tags() { riff_info.set_title(String::from("test title")); f.set_riff_info(riff_info); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -205,7 +205,7 @@ fn test_strip_tags() { riff_info.set_title(String::from("test title")); f.set_riff_info(riff_info); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -241,7 +241,7 @@ fn test_duplicate_tags() { assert!(f.riff_info().is_some()); assert_eq!(f.riff_info().unwrap().title().as_deref(), Some("Title1")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); assert_eq!(file.seek(SeekFrom::End(0)).unwrap(), 15898); let mut file_bytes = Vec::new(); diff --git a/tests/taglib/test_wavpack.rs b/tests/taglib/test_wavpack.rs index aab501754..b0288a77e 100644 --- a/tests/taglib/test_wavpack.rs +++ b/tests/taglib/test_wavpack.rs @@ -7,7 +7,7 @@ use std::io::Seek; use lofty::ape::ApeTag; use lofty::id3::v1::Id3v1Tag; use lofty::wavpack::WavPackFile; -use lofty::{Accessor, AudioFile, ParseOptions}; +use lofty::{Accessor, AudioFile, ParseOptions, WriteOptions}; #[test] fn test_no_length_properties() { @@ -96,7 +96,7 @@ fn test_strip_and_properties() { id3v1.set_title(String::from("ID3v1")); f.set_id3v1(id3v1); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -124,11 +124,11 @@ fn test_repeated_save() { let mut ape = ApeTag::default(); ape.set_title(String::from("01234 56789 ABCDE FGHIJ")); f.set_ape(ape); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); file.rewind().unwrap(); f.ape_mut().unwrap().set_title(String::from("0")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); file.rewind().unwrap(); let mut id3v1 = Id3v1Tag::default(); @@ -137,7 +137,7 @@ fn test_repeated_save() { f.ape_mut().unwrap().set_title(String::from( "01234 56789 ABCDE FGHIJ 01234 56789 ABCDE FGHIJ 01234 56789", )); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { diff --git a/tests/taglib/test_xiphcomment.rs b/tests/taglib/test_xiphcomment.rs index a100fc23c..af46839f7 100644 --- a/tests/taglib/test_xiphcomment.rs +++ b/tests/taglib/test_xiphcomment.rs @@ -5,6 +5,7 @@ use std::io::Seek; use lofty::ogg::{OggPictureStorage, VorbisComments, VorbisFile}; use lofty::{ Accessor, AudioFile, MimeType, ParseOptions, Picture, PictureInformation, PictureType, TagExt, + WriteOptions, }; #[test] @@ -80,7 +81,7 @@ fn test_clear_comment() { f.vorbis_comments_mut() .push(String::from("COMMENT"), String::from("Comment1")); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -129,7 +130,7 @@ fn test_picture() { f.vorbis_comments_mut() .insert_picture(picture, Some(info)) .unwrap(); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); { @@ -157,7 +158,7 @@ fn test_lowercase_fields() { assert_eq!(f.vorbis_comments().title().as_deref(), Some("TEST TITLE")); assert_eq!(f.vorbis_comments().artist().as_deref(), Some("TEST ARTIST")); assert_eq!(f.vorbis_comments().pictures().len(), 1); - f.save_to(&mut file).unwrap(); + f.save_to(&mut file, WriteOptions::default()).unwrap(); } file.rewind().unwrap(); {