Skip to content

Commit c29a463

Browse files
committed
Tests: Cleanup Taglib APE and AIFF tests
1 parent 0b7ff7d commit c29a463

File tree

3 files changed

+38
-44
lines changed

3 files changed

+38
-44
lines changed

tests/taglib/test_aiff.rs

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
use lofty::{Accessor, AudioFile, FileType, ParseOptions, TaggedFileExt};
1+
use lofty::{Accessor, AudioFile, FileType, ParseOptions, Probe};
22

3+
use lofty::id3::v2::Id3v2Tag;
34
use lofty::iff::aiff::AiffFile;
4-
use std::io::{Read, Seek};
5+
use std::io::Seek;
56

6-
use crate::util::get_filetype;
7+
use crate::util::get_file;
78
use crate::{assert_delta, temp_file};
89

910
#[test]
1011
#[ignore]
1112
fn test_aiff_properties() {
12-
let file = lofty::read_from_path("tests/taglib/data/empty.aiff").unwrap();
13-
14-
assert_eq!(file.file_type(), FileType::Aiff);
13+
let file = get_file::<AiffFile>("tests/taglib/data/empty.aiff");
1514

1615
let properties = file.properties();
1716
assert_eq!(properties.duration().as_secs(), 0);
@@ -28,9 +27,7 @@ fn test_aiff_properties() {
2827
#[test]
2928
#[ignore]
3029
fn test_aifc_properties() {
31-
let file = lofty::read_from_path("tests/taglib/data/alaw.aifc").unwrap();
32-
33-
assert_eq!(file.file_type(), FileType::Aiff);
30+
let file = get_file::<AiffFile>("tests/taglib/data/alaw.aifc");
3431

3532
let properties = file.properties();
3633
assert_eq!(properties.duration().as_secs(), 0);
@@ -52,15 +49,13 @@ fn test_save_id3v2() {
5249
let mut file = temp_file!("tests/taglib/data/empty.aiff");
5350

5451
{
55-
let mut tfile = lofty::read_from(&mut file).unwrap();
52+
let mut tfile = AiffFile::read_from(&mut file, ParseOptions::new()).unwrap();
5653

57-
assert_eq!(tfile.file_type(), FileType::Aiff);
54+
assert!(tfile.id3v2().is_none());
5855

59-
assert!(tfile.tag(lofty::TagType::Id3v2).is_none());
60-
61-
let mut tag = lofty::Tag::new(lofty::TagType::Id3v2);
62-
tag.set_title("TitleXXX".to_string());
63-
tfile.insert_tag(tag);
56+
let mut id3v2 = Id3v2Tag::new();
57+
id3v2.set_title("TitleXXX".to_string());
58+
tfile.set_id3v2(id3v2);
6459
file.rewind().unwrap();
6560
tfile.save_to(&mut file).unwrap();
6661
assert!(tfile.contains_tag_type(lofty::TagType::Id3v2));
@@ -69,14 +64,12 @@ fn test_save_id3v2() {
6964
file.rewind().unwrap();
7065

7166
{
72-
let mut tfile = lofty::read_from(&mut file).unwrap();
73-
74-
assert_eq!(tfile.file_type(), FileType::Aiff);
67+
let mut tfile = AiffFile::read_from(&mut file, ParseOptions::new()).unwrap();
7568

76-
let mut tag = tfile.tag(lofty::TagType::Id3v2).unwrap().to_owned();
77-
assert_eq!(tag.title().as_deref(), Some("TitleXXX"));
78-
tag.set_title(String::new());
79-
tfile.insert_tag(tag);
69+
let mut id3v2 = tfile.id3v2().unwrap().to_owned();
70+
assert_eq!(id3v2.title().as_deref(), Some("TitleXXX"));
71+
id3v2.set_title(String::new());
72+
tfile.set_id3v2(id3v2);
8073
file.rewind().unwrap();
8174
tfile.save_to(&mut file).unwrap();
8275
assert!(!tfile.contains_tag_type(lofty::TagType::Id3v2));
@@ -85,10 +78,7 @@ fn test_save_id3v2() {
8578
file.rewind().unwrap();
8679

8780
{
88-
let tfile = lofty::read_from(&mut file).unwrap();
89-
90-
assert_eq!(tfile.file_type(), FileType::Aiff);
91-
81+
let tfile = AiffFile::read_from(&mut file, ParseOptions::new()).unwrap();
9282
assert!(!tfile.contains_tag_type(lofty::TagType::Id3v2));
9383
}
9484
}
@@ -104,11 +94,14 @@ fn test_duplicate_id3v2() {
10494
}
10595

10696
#[test]
107-
#[ignore]
10897
fn test_fuzzed_file1() {
10998
assert_eq!(
110-
get_filetype("tests/taglib/data/segfault.aif"),
111-
FileType::Aiff
99+
Probe::open("tests/taglib/data/segfault.aif")
100+
.unwrap()
101+
.guess_file_type()
102+
.unwrap()
103+
.file_type(),
104+
Some(FileType::Aiff)
112105
);
113106
}
114107

tests/taglib/test_ape.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use crate::temp_file;
2-
use crate::util::get_filetype;
32

43
use std::fs::File;
54
use std::io::Seek;
65
use std::time::Duration;
76

87
use lofty::ape::{ApeFile, ApeItem, ApeTag};
98
use lofty::id3::v1::Id3v1Tag;
10-
use lofty::{Accessor, AudioFile, FileType, ItemValue, ParseOptions, TagExt};
9+
use lofty::{Accessor, AudioFile, FileType, ItemValue, ParseOptions, Probe, TagExt};
1110

1211
fn test_399(path: &str) {
1312
let mut file = File::open(path).unwrap();
@@ -79,14 +78,25 @@ fn test_properties_390() {
7978
#[test]
8079
fn test_fuzzed_file_1() {
8180
assert_eq!(
82-
get_filetype("tests/taglib/data/longloop.ape"),
83-
FileType::Ape
81+
Probe::open("tests/taglib/data/longloop.ape")
82+
.unwrap()
83+
.guess_file_type()
84+
.unwrap()
85+
.file_type(),
86+
Some(FileType::Ape)
8487
);
8588
}
8689

8790
#[test]
8891
fn test_fuzzed_file_2() {
89-
assert_eq!(get_filetype("tests/taglib/data/zerodiv.ape"), FileType::Ape);
92+
assert_eq!(
93+
Probe::open("tests/taglib/data/zerodiv.ape")
94+
.unwrap()
95+
.guess_file_type()
96+
.unwrap()
97+
.file_type(),
98+
Some(FileType::Ape)
99+
);
90100
}
91101

92102
#[test]

tests/taglib/util/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
use lofty::{AudioFile, ParseOptions};
22
use std::fs::File;
33

4-
/// This function tries to simulate TagLibs isValid function
5-
// https://github.com/Serial-ATA/lofty-rs/pull/51#discussion_r873171570
6-
pub fn get_filetype<P: AsRef<std::path::Path>>(path: P) -> lofty::FileType {
7-
let mut file = std::fs::File::open(path).unwrap();
8-
let mut buf = [0; 12];
9-
std::io::Read::read_exact(&mut file, &mut buf).unwrap();
10-
lofty::FileType::from_buffer(&buf).unwrap()
11-
}
12-
134
pub fn get_file<F: AudioFile>(path: &str) -> F {
145
let mut file = File::open(path).unwrap();
156
F::read_from(&mut file, ParseOptions::new()).unwrap()

0 commit comments

Comments
 (0)