Skip to content

Commit 65bd815

Browse files
committed
Tests: Update TagLib tests for latest changes
1 parent 2ee29f2 commit 65bd815

17 files changed

+173
-147
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ id3v2_compression_support = ["dep:flate2"]
3333
[dev-dependencies]
3434
# WAV properties validity tests
3535
hound = { git = "https://github.com/ruuda/hound.git", rev = "02e66effb33683dd6acb92df792683ee46ad6a59" }
36+
rusty-fork = "0.3.0"
3637
# tag_writer example
3738
structopt = { version = "0.3.26", default-features = false }
3839
tempfile = "3.9.0"

tests/taglib/test_aiff.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::io::Seek;
55

66
use lofty::id3::v2::Id3v2Tag;
77
use lofty::iff::aiff::{AiffCompressionType, AiffFile};
8-
use lofty::{Accessor, AudioFile, FileType, ParseOptions, Probe};
8+
use lofty::{Accessor, AudioFile, FileType, ParseOptions, Probe, WriteOptions};
99

1010
#[test]
1111
fn test_aiff_properties() {
@@ -65,7 +65,7 @@ fn test_save_id3v2() {
6565
id3v2.set_title("TitleXXX".to_string());
6666
tfile.set_id3v2(id3v2);
6767
file.rewind().unwrap();
68-
tfile.save_to(&mut file).unwrap();
68+
tfile.save_to(&mut file, WriteOptions::default()).unwrap();
6969
assert!(tfile.contains_tag_type(lofty::TagType::Id3v2));
7070
}
7171

@@ -81,7 +81,7 @@ fn test_save_id3v2() {
8181
id3v2.remove_title();
8282
tfile.set_id3v2(id3v2);
8383
file.rewind().unwrap();
84-
tfile.save_to(&mut file).unwrap();
84+
tfile.save_to(&mut file, WriteOptions::default()).unwrap();
8585
}
8686

8787
file.rewind().unwrap();

tests/taglib/test_ape.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::time::Duration;
66

77
use lofty::ape::{ApeFile, ApeItem, ApeTag};
88
use lofty::id3::v1::Id3v1Tag;
9-
use lofty::{Accessor, AudioFile, FileType, ItemValue, ParseOptions, Probe, TagExt};
9+
use lofty::{Accessor, AudioFile, FileType, ItemValue, ParseOptions, Probe, TagExt, WriteOptions};
1010

1111
fn test_399(path: &str) {
1212
let f = get_file::<ApeFile>(path);
@@ -106,7 +106,9 @@ fn test_strip_and_properties() {
106106
ape_file.set_id3v1(id3v1_tag);
107107

108108
file.rewind().unwrap();
109-
ape_file.save_to(&mut file).unwrap();
109+
ape_file
110+
.save_to(&mut file, WriteOptions::default())
111+
.unwrap();
110112
}
111113
{
112114
file.rewind().unwrap();
@@ -337,7 +339,11 @@ fn test_properties() {
337339
ape_file.set_ape(tag.clone());
338340

339341
file.rewind().unwrap();
340-
ape_file.ape().unwrap().save_to(&mut file).unwrap();
342+
ape_file
343+
.ape()
344+
.unwrap()
345+
.save_to(&mut file, WriteOptions::default())
346+
.unwrap();
341347
}
342348
{
343349
file.rewind().unwrap();
@@ -358,11 +364,15 @@ fn test_repeated_save() {
358364
let mut ape_tag = ApeTag::default();
359365
ape_tag.set_title(String::from("01234 56789 ABCDE FGHIJ"));
360366
ape_file.set_ape(ape_tag);
361-
ape_file.save_to(&mut file).unwrap();
367+
ape_file
368+
.save_to(&mut file, WriteOptions::default())
369+
.unwrap();
362370
file.rewind().unwrap();
363371

364372
ape_file.ape_mut().unwrap().set_title(String::from("0"));
365-
ape_file.save_to(&mut file).unwrap();
373+
ape_file
374+
.save_to(&mut file, WriteOptions::default())
375+
.unwrap();
366376
file.rewind().unwrap();
367377

368378
let mut id3v1_tag = Id3v1Tag::default();
@@ -371,7 +381,9 @@ fn test_repeated_save() {
371381
ape_file.ape_mut().unwrap().set_title(String::from(
372382
"01234 56789 ABCDE FGHIJ 01234 56789 ABCDE FGHIJ 01234 56789",
373383
));
374-
ape_file.save_to(&mut file).unwrap();
384+
ape_file
385+
.save_to(&mut file, WriteOptions::default())
386+
.unwrap();
375387
}
376388
{
377389
file.rewind().unwrap();

tests/taglib/test_apetag.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::io::Seek;
44

55
use lofty::ape::{ApeItem, ApeTag};
66
use lofty::musepack::MpcFile;
7-
use lofty::{Accessor, AudioFile, ItemValue, ParseOptions, TagExt};
7+
use lofty::{Accessor, AudioFile, ItemValue, ParseOptions, TagExt, WriteOptions};
88

99
#[test]
1010
fn test_is_empty() {
@@ -104,7 +104,9 @@ fn test_id3v1_collision() {
104104
ape_tag.set_artist(String::from("Filltointersect "));
105105
ape_tag.set_title(String::from("Filltointersect "));
106106
mpc_file.set_ape(ape_tag);
107-
mpc_file.save_to(&mut file).unwrap();
107+
mpc_file
108+
.save_to(&mut file, WriteOptions::default())
109+
.unwrap();
108110
}
109111
{
110112
file.rewind().unwrap();

tests/taglib/test_fileref.rs

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use std::io::{Read, Seek};
66
use lofty::error::ErrorKind;
77
use lofty::resolve::FileResolver;
88
use lofty::{
9-
Accessor, AudioFile, FileProperties, FileType, ParseOptions, Tag, TagExt, TagType, TaggedFile,
10-
TaggedFileExt,
9+
Accessor, AudioFile, FileProperties, FileType, GlobalOptions, ParseOptions, Tag, TagExt,
10+
TagType, TaggedFile, TaggedFileExt, WriteOptions,
1111
};
1212

1313
fn file_ref_save(path: &str, expected_file_type: FileType) {
@@ -33,7 +33,7 @@ fn file_ref_save(path: &str, expected_file_type: FileType) {
3333
tag.set_comment(String::from("a comment"));
3434
tag.set_track(5);
3535
tag.set_year(2020);
36-
tag.save_to(&mut file).unwrap();
36+
tag.save_to(&mut file, WriteOptions::default()).unwrap();
3737
}
3838
file.rewind().unwrap();
3939
{
@@ -55,7 +55,7 @@ fn file_ref_save(path: &str, expected_file_type: FileType) {
5555
tag.set_comment(String::from("another comment"));
5656
tag.set_track(7);
5757
tag.set_year(2080);
58-
tag.save_to(&mut file).unwrap();
58+
tag.save_to(&mut file, WriteOptions::default()).unwrap();
5959
}
6060
file.rewind().unwrap();
6161
{
@@ -214,72 +214,76 @@ fn test_default_file_extensions() {
214214
// Marker test, Lofty does not replicate this API
215215
}
216216

217-
// TODO: We need to check resolvers *first* and then resort to our default implementations
218-
#[test]
219-
#[ignore]
220-
fn test_file_resolver() {
221-
{
222-
let file = lofty::read_from_path("tests/taglib/data/xing.mp3").unwrap();
223-
assert_eq!(file.file_type(), FileType::Mpeg);
224-
}
225-
226-
struct DummyResolver;
227-
impl Into<TaggedFile> for DummyResolver {
228-
fn into(self) -> TaggedFile {
229-
TaggedFile::new(FileType::Vorbis, FileProperties::default(), Vec::new())
230-
}
231-
}
217+
use rusty_fork::rusty_fork_test;
232218

233-
impl AudioFile for DummyResolver {
234-
type Properties = ();
219+
rusty_fork_test! {
220+
#[test]
221+
fn test_file_resolver() {
222+
lofty::apply_global_options(GlobalOptions::new().use_custom_resolvers(true));
235223

236-
fn read_from<R>(_: &mut R, _: ParseOptions) -> lofty::Result<Self>
237-
where
238-
R: Read + Seek,
239-
Self: Sized,
240224
{
241-
Ok(Self)
225+
let file = lofty::read_from_path("tests/taglib/data/xing.mp3").unwrap();
226+
assert_eq!(file.file_type(), FileType::Mpeg);
242227
}
243228

244-
fn save_to(&self, _: &mut File) -> lofty::Result<()> {
245-
unimplemented!()
229+
struct DummyResolver;
230+
impl Into<TaggedFile> for DummyResolver {
231+
fn into(self) -> TaggedFile {
232+
TaggedFile::new(FileType::Vorbis, FileProperties::default(), Vec::new())
233+
}
246234
}
247235

248-
fn properties(&self) -> &Self::Properties {
249-
unimplemented!()
250-
}
236+
impl AudioFile for DummyResolver {
237+
type Properties = ();
251238

252-
fn contains_tag(&self) -> bool {
253-
unimplemented!()
254-
}
239+
fn read_from<R>(_: &mut R, _: ParseOptions) -> lofty::Result<Self>
240+
where
241+
R: Read + Seek,
242+
Self: Sized,
243+
{
244+
Ok(Self)
245+
}
255246

256-
fn contains_tag_type(&self, _: TagType) -> bool {
257-
unimplemented!()
258-
}
259-
}
247+
fn save_to(&self, _: &mut File, _: WriteOptions) -> lofty::Result<()> {
248+
unimplemented!()
249+
}
260250

261-
impl FileResolver for DummyResolver {
262-
fn extension() -> Option<&'static str> {
263-
Some("mp3")
264-
}
251+
fn properties(&self) -> &Self::Properties {
252+
unimplemented!()
253+
}
265254

266-
fn primary_tag_type() -> TagType {
267-
unimplemented!()
268-
}
255+
fn contains_tag(&self) -> bool {
256+
unimplemented!()
257+
}
269258

270-
fn supported_tag_types() -> &'static [TagType] {
271-
unimplemented!()
259+
fn contains_tag_type(&self, _: TagType) -> bool {
260+
unimplemented!()
261+
}
272262
}
273263

274-
fn guess(_: &[u8]) -> Option<FileType> {
275-
Some(FileType::Vorbis)
264+
impl FileResolver for DummyResolver {
265+
fn extension() -> Option<&'static str> {
266+
Some("mp3")
267+
}
268+
269+
fn primary_tag_type() -> TagType {
270+
unimplemented!()
271+
}
272+
273+
fn supported_tag_types() -> &'static [TagType] {
274+
unimplemented!()
275+
}
276+
277+
fn guess(_: &[u8]) -> Option<FileType> {
278+
Some(FileType::Vorbis)
279+
}
276280
}
277-
}
278281

279-
lofty::resolve::register_custom_resolver::<DummyResolver>("Dummy");
282+
lofty::resolve::register_custom_resolver::<DummyResolver>("Dummy");
280283

281-
{
282-
let file = lofty::read_from_path("tests/taglib/data/xing.mp3").unwrap();
283-
assert_eq!(file.file_type(), FileType::Vorbis);
284+
{
285+
let file = lofty::read_from_path("tests/taglib/data/xing.mp3").unwrap();
286+
assert_eq!(file.file_type(), FileType::Vorbis);
287+
}
284288
}
285289
}

0 commit comments

Comments
 (0)