Skip to content

Commit fd45d14

Browse files
committed
Tests: Add TagLib Speex tests
1 parent 1e5c0ca commit fd45d14

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

tests/taglib/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ mod test_flac;
88
mod test_flacpicture;
99
mod test_id3v1;
1010
mod test_info;
11+
mod test_speex;

tests/taglib/test_speex.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
use crate::temp_file;
2+
3+
use std::io::Seek;
4+
5+
use lofty::ogg::{SpeexFile, VorbisComments};
6+
use lofty::{Accessor, AudioFile, ParseOptions};
7+
8+
#[test]
9+
#[ignore]
10+
fn test_audio_properties() {
11+
let mut file = temp_file!("tests/taglib/data/empty.spx");
12+
let f = SpeexFile::read_from(&mut file, ParseOptions::new()).unwrap();
13+
14+
assert_eq!(f.properties().duration().as_secs(), 3);
15+
// TODO: We report 3684, we're off by one
16+
assert_eq!(f.properties().duration().as_millis(), 3685);
17+
// TODO: We report zero, we aren't properly calculating bitrates for Speex
18+
assert_eq!(f.properties().audio_bitrate(), 53);
19+
assert_eq!(f.properties().nominal_bitrate(), -1);
20+
assert_eq!(f.properties().channels(), 2);
21+
assert_eq!(f.properties().sample_rate(), 44100);
22+
}
23+
24+
#[test]
25+
#[ignore] // TODO: This test doesn't work, it's very specific with file/packet sizes. Have to determine whether or not to even keep this one.
26+
fn test_split_packets() {
27+
let mut file = temp_file!("tests/taglib/data/empty.spx");
28+
29+
let text = String::from_utf8(vec![b'X'; 128 * 1024]).unwrap();
30+
31+
{
32+
let f = SpeexFile::read_from(&mut file, ParseOptions::new()).unwrap();
33+
file.rewind().unwrap();
34+
35+
let mut tag = VorbisComments::default();
36+
tag.set_title(text.clone());
37+
f.save_to(&mut file).unwrap();
38+
}
39+
file.rewind().unwrap();
40+
{
41+
let mut f = SpeexFile::read_from(&mut file, ParseOptions::new()).unwrap();
42+
file.rewind().unwrap();
43+
44+
assert_eq!(file.metadata().unwrap().len(), 156330);
45+
assert_eq!(f.vorbis_comments().title().as_deref(), Some(text.as_str()));
46+
47+
// NOTE: TagLib exposes the packets and page headers through `Speex::File`.
48+
// Lofty does not keep this information around, so we just double check with `ogg_pager`.
49+
let packets = ogg_pager::Packets::read(&mut file).unwrap();
50+
assert_eq!(packets.get(0).unwrap().len(), 80);
51+
assert_eq!(packets.get(1).unwrap().len(), 131116);
52+
assert_eq!(packets.get(2).unwrap().len(), 93);
53+
assert_eq!(packets.get(3).unwrap().len(), 93);
54+
55+
assert_eq!(f.properties().duration().as_millis(), 3685);
56+
57+
f.vorbis_comments_mut().set_title(String::from("ABCDE"));
58+
file.rewind().unwrap();
59+
f.save_to(&mut file).unwrap();
60+
}
61+
file.rewind().unwrap();
62+
{
63+
let f = SpeexFile::read_from(&mut file, ParseOptions::new()).unwrap();
64+
assert_eq!(file.metadata().unwrap().len(), 24317);
65+
assert_eq!(f.vorbis_comments().title().as_deref(), Some("ABCDE"));
66+
67+
let packets = ogg_pager::Packets::read(&mut file).unwrap();
68+
assert_eq!(packets.get(0).unwrap().len(), 80);
69+
assert_eq!(packets.get(1).unwrap().len(), 49);
70+
assert_eq!(packets.get(2).unwrap().len(), 93);
71+
assert_eq!(packets.get(3).unwrap().len(), 93);
72+
73+
assert_eq!(f.properties().duration().as_millis(), 3685);
74+
}
75+
}

0 commit comments

Comments
 (0)