Skip to content

Commit

Permalink
Tests: Add TagLib Speex tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Serial-ATA committed Jan 21, 2023
1 parent a8972c6 commit 2c54dfc
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/taglib/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ mod test_flac;
mod test_flacpicture;
mod test_id3v1;
mod test_info;
mod test_speex;
75 changes: 75 additions & 0 deletions tests/taglib/test_speex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use crate::temp_file;

use std::io::Seek;

use lofty::ogg::{SpeexFile, VorbisComments};
use lofty::{Accessor, AudioFile, ParseOptions};

#[test]
#[ignore]
fn test_audio_properties() {
let mut file = temp_file!("tests/taglib/data/empty.spx");
let f = SpeexFile::read_from(&mut file, ParseOptions::new()).unwrap();

assert_eq!(f.properties().duration().as_secs(), 3);
// TODO: We report 3684, we're off by one
assert_eq!(f.properties().duration().as_millis(), 3685);
// TODO: We report zero, we aren't properly calculating bitrates for Speex
assert_eq!(f.properties().audio_bitrate(), 53);
assert_eq!(f.properties().nominal_bitrate(), -1);
assert_eq!(f.properties().channels(), 2);
assert_eq!(f.properties().sample_rate(), 44100);
}

#[test]
#[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.
fn test_split_packets() {
let mut file = temp_file!("tests/taglib/data/empty.spx");

let text = String::from_utf8(vec![b'X'; 128 * 1024]).unwrap();

{
let f = SpeexFile::read_from(&mut file, ParseOptions::new()).unwrap();
file.rewind().unwrap();

let mut tag = VorbisComments::default();
tag.set_title(text.clone());
f.save_to(&mut file).unwrap();
}
file.rewind().unwrap();
{
let mut f = SpeexFile::read_from(&mut file, ParseOptions::new()).unwrap();
file.rewind().unwrap();

assert_eq!(file.metadata().unwrap().len(), 156330);
assert_eq!(f.vorbis_comments().title().as_deref(), Some(text.as_str()));

// NOTE: TagLib exposes the packets and page headers through `Speex::File`.
// Lofty does not keep this information around, so we just double check with `ogg_pager`.
let packets = ogg_pager::Packets::read(&mut file).unwrap();
assert_eq!(packets.get(0).unwrap().len(), 80);
assert_eq!(packets.get(1).unwrap().len(), 131116);
assert_eq!(packets.get(2).unwrap().len(), 93);
assert_eq!(packets.get(3).unwrap().len(), 93);

assert_eq!(f.properties().duration().as_millis(), 3685);

f.vorbis_comments_mut().set_title(String::from("ABCDE"));
file.rewind().unwrap();
f.save_to(&mut file).unwrap();
}
file.rewind().unwrap();
{
let f = SpeexFile::read_from(&mut file, ParseOptions::new()).unwrap();
assert_eq!(file.metadata().unwrap().len(), 24317);
assert_eq!(f.vorbis_comments().title().as_deref(), Some("ABCDE"));

let packets = ogg_pager::Packets::read(&mut file).unwrap();
assert_eq!(packets.get(0).unwrap().len(), 80);
assert_eq!(packets.get(1).unwrap().len(), 49);
assert_eq!(packets.get(2).unwrap().len(), 93);
assert_eq!(packets.get(3).unwrap().len(), 93);

assert_eq!(f.properties().duration().as_millis(), 3685);
}
}

0 comments on commit 2c54dfc

Please sign in to comment.