Skip to content

Commit

Permalink
Tests: Add TagLib Opus tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Serial-ATA committed Mar 24, 2023
1 parent e88a94a commit 16f32e1
Show file tree
Hide file tree
Showing 2 changed files with 60 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 @@ -15,3 +15,4 @@ mod test_speex;
mod test_wav;
mod test_wavpack;
mod test_xiphcomment;
mod test_opus;
59 changes: 59 additions & 0 deletions tests/taglib/test_opus.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use crate::temp_file;
use lofty::ogg::OpusFile;
use lofty::{Accessor, AudioFile, ParseOptions};
use std::io::Seek;

#[test]
fn test_audio_properties() {
let mut file = temp_file!("tests/taglib/data/correctness_gain_silent_output.opus");
let f = OpusFile::read_from(&mut file, ParseOptions::new()).unwrap();
assert_eq!(f.properties().duration().as_secs(), 7);
assert_eq!(f.properties().duration().as_millis(), 7737);
assert_eq!(f.properties().audio_bitrate(), 36);
assert_eq!(f.properties().channels(), 1);
assert_eq!(f.properties().input_sample_rate(), 48000);
assert_eq!(f.properties().version(), 1);
}

#[test]
fn test_read_comments() {
let mut file = temp_file!("tests/taglib/data/correctness_gain_silent_output.opus");
let f = OpusFile::read_from(&mut file, ParseOptions::new()).unwrap();
assert_eq!(
f.vorbis_comments().get("ENCODER"),
Some("Xiph.Org Opus testvectormaker")
);
assert!(f.vorbis_comments().get("TESTDESCRIPTION").is_some());
assert!(f.vorbis_comments().artist().is_none());
assert_eq!(f.vorbis_comments().vendor(), "libopus 0.9.11-66-g64c2dd7");
}

#[test]
fn test_write_comments() {
let mut file = temp_file!("tests/taglib/data/correctness_gain_silent_output.opus");

{
let mut f = OpusFile::read_from(&mut file, ParseOptions::new()).unwrap();
file.rewind().unwrap();
f.vorbis_comments_mut()
.set_artist(String::from("Your Tester"));
f.save_to(&mut file).unwrap();
}
file.rewind().unwrap();
{
let f = OpusFile::read_from(&mut file, ParseOptions::new()).unwrap();
assert_eq!(
f.vorbis_comments().get("ENCODER"),
Some("Xiph.Org Opus testvectormaker")
);
assert!(f.vorbis_comments().get("TESTDESCRIPTION").is_some());
assert_eq!(f.vorbis_comments().artist().as_deref(), Some("Your Tester"));
assert_eq!(f.vorbis_comments().vendor(), "libopus 0.9.11-66-g64c2dd7");
}
}

#[test]
#[ignore]
fn test_split_packets() {
// Marker test, Lofty does not retain packet information
}

0 comments on commit 16f32e1

Please sign in to comment.