Skip to content

Commit 823afd6

Browse files
committed
Tests: Add TagLib APE tests
1 parent 2382183 commit 823afd6

File tree

9 files changed

+382
-0
lines changed

9 files changed

+382
-0
lines changed

tests/taglib/data/longloop.ape

184 Bytes
Binary file not shown.

tests/taglib/data/mac-390-hdr.ape

128 Bytes
Binary file not shown.

tests/taglib/data/mac-396.ape

104 Bytes
Binary file not shown.

tests/taglib/data/mac-399-id3v2.ape

87.1 KB
Binary file not shown.

tests/taglib/data/mac-399-tagged.ape

89.4 KB
Binary file not shown.

tests/taglib/data/mac-399.ape

83.2 KB
Binary file not shown.

tests/taglib/data/zerodiv.ape

946 Bytes
Binary file not shown.

tests/taglib/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub(crate) mod util;
22

33
mod test_aiff;
4+
mod test_ape;

tests/taglib/test_ape.rs

Lines changed: 381 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,381 @@
1+
use crate::temp_file;
2+
use crate::util::get_filetype;
3+
4+
use std::fs::File;
5+
use std::io::Seek;
6+
use std::time::Duration;
7+
8+
use lofty::ape::{ApeFile, ApeItem, ApeTag};
9+
use lofty::id3::v1::ID3v1Tag;
10+
use lofty::{Accessor, AudioFile, FileType, ItemValue, ParseOptions, TagExt};
11+
12+
fn test_399(path: &str) {
13+
let mut file = File::open(path).unwrap();
14+
let file = ApeFile::read_from(&mut file, ParseOptions::new()).unwrap();
15+
let properties = file.properties();
16+
17+
assert_eq!(properties.duration(), Duration::from_millis(3550));
18+
assert_eq!(properties.bitrate(), 192);
19+
assert_eq!(properties.channels(), 2);
20+
assert_eq!(properties.sample_rate(), 44100);
21+
assert_eq!(properties.bit_depth(), 16);
22+
// TODO
23+
// assert_eq!(properties.sample_frames(), 156556);
24+
assert_eq!(properties.version(), 3990)
25+
}
26+
27+
#[test]
28+
#[ignore]
29+
fn test_properties_399() {
30+
test_399("tests/taglib/data/mac-399.ape")
31+
}
32+
33+
#[test]
34+
#[ignore]
35+
fn test_properties_399_tagged() {
36+
test_399("tests/taglib/data/mac-399-tagged.ape")
37+
}
38+
39+
#[test]
40+
#[ignore]
41+
fn test_properties_399_id3v2() {
42+
test_399("tests/taglib/data/mac-399-id3v2.ape")
43+
}
44+
45+
#[test]
46+
#[ignore]
47+
fn test_properties_396() {
48+
let mut file = File::open("tests/taglib/data/mac-396.ape").unwrap();
49+
let file = ApeFile::read_from(&mut file, ParseOptions::new()).unwrap();
50+
let properties = file.properties();
51+
52+
assert_eq!(properties.duration(), Duration::from_millis(3685));
53+
assert_eq!(properties.bitrate(), 0);
54+
assert_eq!(properties.channels(), 2);
55+
assert_eq!(properties.sample_rate(), 44100);
56+
assert_eq!(properties.bit_depth(), 16);
57+
// TODO
58+
// assert_eq!(properties.sample_frames(), 162496);
59+
assert_eq!(properties.version(), 3960)
60+
}
61+
62+
#[test]
63+
#[ignore]
64+
fn test_properties_390() {
65+
let mut file = File::open("tests/taglib/data/mac-390-hdr.ape").unwrap();
66+
let file = ApeFile::read_from(&mut file, ParseOptions::new()).unwrap();
67+
let properties = file.properties();
68+
69+
assert_eq!(properties.duration(), Duration::from_millis(15630));
70+
assert_eq!(properties.bitrate(), 0);
71+
assert_eq!(properties.channels(), 2);
72+
assert_eq!(properties.sample_rate(), 44100);
73+
assert_eq!(properties.bit_depth(), 16);
74+
// TODO
75+
// assert_eq!(properties.sample_frames(), 689262);
76+
assert_eq!(properties.version(), 3900)
77+
}
78+
79+
#[test]
80+
fn test_fuzzed_file_1() {
81+
assert_eq!(
82+
get_filetype("tests/taglib/data/longloop.ape"),
83+
FileType::APE
84+
);
85+
}
86+
87+
#[test]
88+
fn test_fuzzed_file_2() {
89+
assert_eq!(get_filetype("tests/taglib/data/zerodiv.ape"), FileType::APE);
90+
}
91+
92+
#[test]
93+
fn test_strip_and_properties() {
94+
let mut file = temp_file!("tests/taglib/data/mac-399.ape");
95+
{
96+
let mut ape_file = ApeFile::read_from(&mut file, ParseOptions::new()).unwrap();
97+
98+
let mut ape_tag = ApeTag::default();
99+
ape_tag.set_title(String::from("APE"));
100+
ape_file.set_ape(ape_tag);
101+
102+
let mut id3v1_tag = ID3v1Tag::default();
103+
id3v1_tag.set_title(String::from("ID3v1"));
104+
ape_file.set_id3v1(id3v1_tag);
105+
106+
file.rewind().unwrap();
107+
ape_file.save_to(&mut file).unwrap();
108+
}
109+
{
110+
file.rewind().unwrap();
111+
let mut ape_file = ApeFile::read_from(&mut file, ParseOptions::new()).unwrap();
112+
113+
assert_eq!(ape_file.ape().unwrap().title().as_deref(), Some("APE"));
114+
ape_file.remove_ape();
115+
116+
assert_eq!(ape_file.id3v1().unwrap().title().as_deref(), Some("ID3v1"));
117+
ape_file.remove_id3v1();
118+
119+
assert!(!ape_file.contains_tag());
120+
}
121+
}
122+
123+
#[test]
124+
fn test_properties() {
125+
let mut tag = ApeTag::default();
126+
tag.insert(
127+
ApeItem::new(
128+
String::from("ALBUM"),
129+
ItemValue::Text(String::from("Album")),
130+
)
131+
.unwrap(),
132+
);
133+
tag.insert(
134+
ApeItem::new(
135+
String::from("ALBUMARTIST"),
136+
ItemValue::Text(String::from("Album Artist")),
137+
)
138+
.unwrap(),
139+
);
140+
tag.insert(
141+
ApeItem::new(
142+
String::from("ALBUMARTISTSORT"),
143+
ItemValue::Text(String::from("Album Artist Sort")),
144+
)
145+
.unwrap(),
146+
);
147+
tag.insert(
148+
ApeItem::new(
149+
String::from("ALBUMSORT"),
150+
ItemValue::Text(String::from("Album Sort")),
151+
)
152+
.unwrap(),
153+
);
154+
tag.insert(
155+
ApeItem::new(
156+
String::from("ARTIST"),
157+
ItemValue::Text(String::from("Artist")),
158+
)
159+
.unwrap(),
160+
);
161+
tag.insert(
162+
ApeItem::new(
163+
String::from("ARTISTS"),
164+
ItemValue::Text(String::from("Artists")),
165+
)
166+
.unwrap(),
167+
);
168+
tag.insert(
169+
ApeItem::new(
170+
String::from("ARTISTSORT"),
171+
ItemValue::Text(String::from("Artist Sort")),
172+
)
173+
.unwrap(),
174+
);
175+
tag.insert(ApeItem::new(String::from("ASIN"), ItemValue::Text(String::from("ASIN"))).unwrap());
176+
tag.insert(
177+
ApeItem::new(
178+
String::from("BARCODE"),
179+
ItemValue::Text(String::from("Barcode")),
180+
)
181+
.unwrap(),
182+
);
183+
tag.insert(
184+
ApeItem::new(
185+
String::from("CATALOGNUMBER"),
186+
ItemValue::Text(String::from("Catalog Number 1")),
187+
)
188+
.unwrap(),
189+
);
190+
tag.insert(
191+
ApeItem::new(
192+
String::from("COMMENT"),
193+
ItemValue::Text(String::from("Comment")),
194+
)
195+
.unwrap(),
196+
);
197+
tag.insert(
198+
ApeItem::new(
199+
String::from("DATE"),
200+
ItemValue::Text(String::from("2021-01-10")),
201+
)
202+
.unwrap(),
203+
);
204+
tag.insert(
205+
ApeItem::new(
206+
String::from("DISCNUMBER"),
207+
ItemValue::Text(String::from("3/5")),
208+
)
209+
.unwrap(),
210+
);
211+
tag.insert(
212+
ApeItem::new(
213+
String::from("GENRE"),
214+
ItemValue::Text(String::from("Genre")),
215+
)
216+
.unwrap(),
217+
);
218+
tag.insert(
219+
ApeItem::new(
220+
String::from("ISRC"),
221+
ItemValue::Text(String::from("UKAAA0500001")),
222+
)
223+
.unwrap(),
224+
);
225+
tag.insert(
226+
ApeItem::new(
227+
String::from("LABEL"),
228+
ItemValue::Text(String::from("Label 1")),
229+
)
230+
.unwrap(),
231+
);
232+
tag.insert(
233+
ApeItem::new(
234+
String::from("MEDIA"),
235+
ItemValue::Text(String::from("Media")),
236+
)
237+
.unwrap(),
238+
);
239+
tag.insert(
240+
ApeItem::new(
241+
String::from("MUSICBRAINZ_ALBUMARTISTID"),
242+
ItemValue::Text(String::from("MusicBrainz_AlbumartistID")),
243+
)
244+
.unwrap(),
245+
);
246+
tag.insert(
247+
ApeItem::new(
248+
String::from("MUSICBRAINZ_ALBUMID"),
249+
ItemValue::Text(String::from("MusicBrainz_AlbumID")),
250+
)
251+
.unwrap(),
252+
);
253+
tag.insert(
254+
ApeItem::new(
255+
String::from("MUSICBRAINZ_ARTISTID"),
256+
ItemValue::Text(String::from("MusicBrainz_ArtistID")),
257+
)
258+
.unwrap(),
259+
);
260+
tag.insert(
261+
ApeItem::new(
262+
String::from("MUSICBRAINZ_RELEASEGROUPID"),
263+
ItemValue::Text(String::from("MusicBrainz_ReleasegroupID")),
264+
)
265+
.unwrap(),
266+
);
267+
tag.insert(
268+
ApeItem::new(
269+
String::from("MUSICBRAINZ_RELEASETRACKID"),
270+
ItemValue::Text(String::from("MusicBrainz_ReleasetrackID")),
271+
)
272+
.unwrap(),
273+
);
274+
tag.insert(
275+
ApeItem::new(
276+
String::from("MUSICBRAINZ_TRACKID"),
277+
ItemValue::Text(String::from("MusicBrainz_TrackID")),
278+
)
279+
.unwrap(),
280+
);
281+
tag.insert(
282+
ApeItem::new(
283+
String::from("ORIGINALDATE"),
284+
ItemValue::Text(String::from("2021-01-09")),
285+
)
286+
.unwrap(),
287+
);
288+
tag.insert(
289+
ApeItem::new(
290+
String::from("RELEASECOUNTRY"),
291+
ItemValue::Text(String::from("Release Country")),
292+
)
293+
.unwrap(),
294+
);
295+
tag.insert(
296+
ApeItem::new(
297+
String::from("RELEASESTATUS"),
298+
ItemValue::Text(String::from("Release Status")),
299+
)
300+
.unwrap(),
301+
);
302+
tag.insert(
303+
ApeItem::new(
304+
String::from("RELEASETYPE"),
305+
ItemValue::Text(String::from("Release Type")),
306+
)
307+
.unwrap(),
308+
);
309+
tag.insert(
310+
ApeItem::new(
311+
String::from("SCRIPT"),
312+
ItemValue::Text(String::from("Script")),
313+
)
314+
.unwrap(),
315+
);
316+
tag.insert(
317+
ApeItem::new(
318+
String::from("TITLE"),
319+
ItemValue::Text(String::from("Title")),
320+
)
321+
.unwrap(),
322+
);
323+
tag.insert(
324+
ApeItem::new(
325+
String::from("TRACKNUMBER"),
326+
ItemValue::Text(String::from("2/3")),
327+
)
328+
.unwrap(),
329+
);
330+
331+
let mut file = temp_file!("tests/taglib/data/mac-399.ape");
332+
{
333+
let mut ape_file = ApeFile::read_from(&mut file, ParseOptions::new()).unwrap();
334+
335+
ape_file.set_ape(tag.clone());
336+
337+
file.rewind().unwrap();
338+
ape_file.ape().unwrap().save_to(&mut file).unwrap();
339+
}
340+
{
341+
file.rewind().unwrap();
342+
let ape_file = ApeFile::read_from(&mut file, ParseOptions::new()).unwrap();
343+
344+
assert_eq!(ape_file.ape(), Some(&tag));
345+
}
346+
}
347+
348+
#[test]
349+
fn test_repeated_save() {
350+
let mut file = temp_file!("tests/taglib/data/mac-399.ape");
351+
{
352+
let mut ape_file = ApeFile::read_from(&mut file, ParseOptions::new()).unwrap();
353+
assert!(ape_file.ape().is_none());
354+
assert!(ape_file.id3v1().is_none());
355+
356+
let mut ape_tag = ApeTag::default();
357+
ape_tag.set_title(String::from("01234 56789 ABCDE FGHIJ"));
358+
ape_file.set_ape(ape_tag);
359+
ape_file.save_to(&mut file).unwrap();
360+
file.rewind().unwrap();
361+
362+
ape_file.ape_mut().unwrap().set_title(String::from("0"));
363+
ape_file.save_to(&mut file).unwrap();
364+
file.rewind().unwrap();
365+
366+
let mut id3v1_tag = ID3v1Tag::default();
367+
id3v1_tag.set_title(String::from("01234 56789 ABCDE FGHIJ"));
368+
ape_file.set_id3v1(id3v1_tag);
369+
ape_file.ape_mut().unwrap().set_title(String::from(
370+
"01234 56789 ABCDE FGHIJ 01234 56789 ABCDE FGHIJ 01234 56789",
371+
));
372+
ape_file.save_to(&mut file).unwrap();
373+
}
374+
{
375+
file.rewind().unwrap();
376+
let ape_file = ApeFile::read_from(&mut file, ParseOptions::new()).unwrap();
377+
378+
assert!(ape_file.ape().is_some());
379+
assert!(ape_file.id3v1().is_some());
380+
}
381+
}

0 commit comments

Comments
 (0)