From 16f32e1a0691377f46ec8d7b1515370defd1d13a Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Fri, 24 Mar 2023 18:08:26 -0400 Subject: [PATCH] Tests: Add TagLib Opus tests --- tests/taglib/main.rs | 1 + tests/taglib/test_opus.rs | 59 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/taglib/test_opus.rs diff --git a/tests/taglib/main.rs b/tests/taglib/main.rs index b431252ba..521f552b5 100644 --- a/tests/taglib/main.rs +++ b/tests/taglib/main.rs @@ -15,3 +15,4 @@ mod test_speex; mod test_wav; mod test_wavpack; mod test_xiphcomment; +mod test_opus; diff --git a/tests/taglib/test_opus.rs b/tests/taglib/test_opus.rs new file mode 100644 index 000000000..3253c786d --- /dev/null +++ b/tests/taglib/test_opus.rs @@ -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 +}