Skip to content

Commit 96bcc60

Browse files
committed
Tests: Add TagLib WavPack tests
1 parent 0d132b6 commit 96bcc60

File tree

8 files changed

+157
-0
lines changed

8 files changed

+157
-0
lines changed

tests/taglib/data/dsd_stereo.wv

51.4 KB
Binary file not shown.

tests/taglib/data/four_channels.wv

52.3 KB
Binary file not shown.

tests/taglib/data/infloop.wv

2.4 KB
Binary file not shown.

tests/taglib/data/no_length.wv

532 Bytes
Binary file not shown.
132 Bytes
Binary file not shown.

tests/taglib/data/tagged.wv

74.8 KB
Binary file not shown.

tests/taglib/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ mod test_info;
1111
mod test_mp4;
1212
mod test_mpeg;
1313
mod test_speex;
14+
mod test_wavpack;

tests/taglib/test_wavpack.rs

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
use crate::temp_file;
2+
3+
use std::io::Seek;
4+
5+
use lofty::ape::ApeTag;
6+
use lofty::id3::v1::ID3v1Tag;
7+
use lofty::wavpack::WavPackFile;
8+
use lofty::{Accessor, AudioFile, ParseOptions};
9+
10+
#[test]
11+
fn test_no_length_properties() {
12+
let mut file = temp_file!("tests/taglib/data/no_length.wv");
13+
let f = WavPackFile::read_from(&mut file, ParseOptions::new()).unwrap();
14+
assert_eq!(f.properties().duration().as_secs(), 3);
15+
assert_eq!(f.properties().duration().as_millis(), 3705);
16+
assert_eq!(f.properties().audio_bitrate(), 1);
17+
assert_eq!(f.properties().channels(), 2);
18+
assert_eq!(f.properties().bit_depth(), 16);
19+
assert_eq!(f.properties().is_lossless(), true);
20+
assert_eq!(f.properties().sample_rate(), 44100);
21+
// TODO: CPPUNIT_ASSERT_EQUAL(163392U, f.audioProperties()->sampleFrames());
22+
assert_eq!(f.properties().version(), 1031);
23+
}
24+
25+
#[test]
26+
fn test_multi_channel_properties() {
27+
let mut file = temp_file!("tests/taglib/data/four_channels.wv");
28+
let f = WavPackFile::read_from(&mut file, ParseOptions::new()).unwrap();
29+
assert_eq!(f.properties().duration().as_secs(), 3);
30+
assert_eq!(f.properties().duration().as_millis(), 3833);
31+
assert_eq!(f.properties().audio_bitrate(), 112);
32+
assert_eq!(f.properties().channels(), 4);
33+
assert_eq!(f.properties().bit_depth(), 16);
34+
assert_eq!(f.properties().is_lossless(), false);
35+
assert_eq!(f.properties().sample_rate(), 44100);
36+
// TODO: CPPUNIT_ASSERT_EQUAL(169031U, f.audioProperties()->sampleFrames());
37+
assert_eq!(f.properties().version(), 1031);
38+
}
39+
40+
#[test]
41+
fn test_dsd_stereo_properties() {
42+
let mut file = temp_file!("tests/taglib/data/dsd_stereo.wv");
43+
let f = WavPackFile::read_from(&mut file, ParseOptions::new()).unwrap();
44+
assert_eq!(f.properties().duration().as_secs(), 0);
45+
assert_eq!(f.properties().duration().as_millis(), 200);
46+
assert_eq!(f.properties().audio_bitrate(), 2096);
47+
assert_eq!(f.properties().channels(), 2);
48+
assert_eq!(f.properties().bit_depth(), 8);
49+
assert_eq!(f.properties().is_lossless(), true);
50+
assert_eq!(f.properties().sample_rate(), 352800);
51+
// TODO: CPPUNIT_ASSERT_EQUAL(70560U, f.audioProperties()->sampleFrames());
52+
assert_eq!(f.properties().version(), 1040);
53+
}
54+
55+
#[test]
56+
fn test_non_standard_rate_properties() {
57+
let mut file = temp_file!("tests/taglib/data/non_standard_rate.wv");
58+
let f = WavPackFile::read_from(&mut file, ParseOptions::new()).unwrap();
59+
assert_eq!(f.properties().duration().as_secs(), 3);
60+
assert_eq!(f.properties().duration().as_millis(), 3675);
61+
assert_eq!(f.properties().audio_bitrate(), 0);
62+
assert_eq!(f.properties().channels(), 2);
63+
assert_eq!(f.properties().bit_depth(), 16);
64+
assert_eq!(f.properties().is_lossless(), true);
65+
assert_eq!(f.properties().sample_rate(), 1000);
66+
// TODO: CPPUNIT_ASSERT_EQUAL(3675U, f.audioProperties()->sampleFrames());
67+
assert_eq!(f.properties().version(), 1040);
68+
}
69+
70+
#[test]
71+
fn test_tagged_properties() {
72+
let mut file = temp_file!("tests/taglib/data/tagged.wv");
73+
let f = WavPackFile::read_from(&mut file, ParseOptions::new()).unwrap();
74+
assert_eq!(f.properties().duration().as_secs(), 3);
75+
assert_eq!(f.properties().duration().as_millis(), 3550);
76+
assert_eq!(f.properties().audio_bitrate(), 172);
77+
assert_eq!(f.properties().channels(), 2);
78+
assert_eq!(f.properties().bit_depth(), 16);
79+
assert_eq!(f.properties().is_lossless(), false);
80+
assert_eq!(f.properties().sample_rate(), 44100);
81+
// TODO: CPPUNIT_ASSERT_EQUAL(156556U, f.audioProperties()->sampleFrames());
82+
assert_eq!(f.properties().version(), 1031);
83+
}
84+
85+
#[test]
86+
fn test_fuzzed_file() {
87+
let mut file = temp_file!("tests/taglib/data/infloop.wv");
88+
let _ = WavPackFile::read_from(&mut file, ParseOptions::new()).unwrap();
89+
}
90+
91+
#[test]
92+
fn test_strip_and_properties() {
93+
let mut file = temp_file!("tests/taglib/data/click.wv");
94+
95+
{
96+
let mut f = WavPackFile::read_from(&mut file, ParseOptions::new()).unwrap();
97+
file.rewind().unwrap();
98+
99+
let mut ape = ApeTag::default();
100+
ape.set_title(String::from("APE"));
101+
f.set_ape(ape);
102+
103+
let mut id3v1 = ID3v1Tag::default();
104+
id3v1.set_title(String::from("ID3v1"));
105+
f.set_id3v1(id3v1);
106+
107+
f.save_to(&mut file).unwrap();
108+
}
109+
file.rewind().unwrap();
110+
{
111+
// NOTE: This is not the same as the TagLib test.
112+
// Their test checks the first "TITLE" which changes when tags are stripped.
113+
let mut f = WavPackFile::read_from(&mut file, ParseOptions::new()).unwrap();
114+
assert_eq!(f.ape().unwrap().title().as_deref(), Some("APE"));
115+
f.remove_ape();
116+
assert_eq!(f.id3v1().unwrap().title.as_deref(), Some("ID3v1"));
117+
f.remove_id3v1();
118+
assert!(!f.contains_tag());
119+
}
120+
}
121+
122+
#[test]
123+
fn test_repeated_save() {
124+
let mut file = temp_file!("tests/taglib/data/click.wv");
125+
126+
{
127+
let mut f = WavPackFile::read_from(&mut file, ParseOptions::new()).unwrap();
128+
file.rewind().unwrap();
129+
assert!(f.ape().is_none());
130+
assert!(f.id3v1().is_none());
131+
132+
let mut ape = ApeTag::default();
133+
ape.set_title(String::from("01234 56789 ABCDE FGHIJ"));
134+
f.set_ape(ape);
135+
f.save_to(&mut file).unwrap();
136+
file.rewind().unwrap();
137+
138+
f.ape_mut().unwrap().set_title(String::from("0"));
139+
f.save_to(&mut file).unwrap();
140+
file.rewind().unwrap();
141+
142+
let mut id3v1 = ID3v1Tag::default();
143+
id3v1.set_title(String::from("01234 56789 ABCDE FGHIJ"));
144+
f.set_id3v1(id3v1);
145+
f.ape_mut().unwrap().set_title(String::from(
146+
"01234 56789 ABCDE FGHIJ 01234 56789 ABCDE FGHIJ 01234 56789",
147+
));
148+
f.save_to(&mut file).unwrap();
149+
}
150+
file.rewind().unwrap();
151+
{
152+
let f = WavPackFile::read_from(&mut file, ParseOptions::new()).unwrap();
153+
assert!(f.ape().is_some());
154+
assert!(f.id3v1().is_some());
155+
}
156+
}

0 commit comments

Comments
 (0)