Skip to content

Commit

Permalink
Tests: Update TagLib tests for latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Serial-ATA committed Apr 14, 2024
1 parent 1cf473c commit d1743c2
Show file tree
Hide file tree
Showing 17 changed files with 173 additions and 147 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions tests/taglib/test_aiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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));
}

Expand All @@ -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();
Expand Down
24 changes: 18 additions & 6 deletions tests/taglib/test_ape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<ApeFile>(path);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions tests/taglib/test_apetag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
Expand Down
112 changes: 58 additions & 54 deletions tests/taglib/test_fileref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
{
Expand All @@ -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();
{
Expand Down Expand Up @@ -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<TaggedFile> 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<R>(_: &mut R, _: ParseOptions) -> lofty::Result<Self>
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<TaggedFile> 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<R>(_: &mut R, _: ParseOptions) -> lofty::Result<Self>
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<FileType> {
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<FileType> {
Some(FileType::Vorbis)
}
}
}

lofty::resolve::register_custom_resolver::<DummyResolver>("Dummy");
lofty::resolve::register_custom_resolver::<DummyResolver>("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);
}
}
}
Loading

0 comments on commit d1743c2

Please sign in to comment.