|
| 1 | +use crate::temp_file; |
| 2 | +use lofty::ogg::OpusFile; |
| 3 | +use lofty::{Accessor, AudioFile, ParseOptions}; |
| 4 | +use std::io::Seek; |
| 5 | + |
| 6 | +#[test] |
| 7 | +fn test_audio_properties() { |
| 8 | + let mut file = temp_file!("tests/taglib/data/correctness_gain_silent_output.opus"); |
| 9 | + let f = OpusFile::read_from(&mut file, ParseOptions::new()).unwrap(); |
| 10 | + assert_eq!(f.properties().duration().as_secs(), 7); |
| 11 | + assert_eq!(f.properties().duration().as_millis(), 7737); |
| 12 | + assert_eq!(f.properties().audio_bitrate(), 36); |
| 13 | + assert_eq!(f.properties().channels(), 1); |
| 14 | + assert_eq!(f.properties().input_sample_rate(), 48000); |
| 15 | + assert_eq!(f.properties().version(), 1); |
| 16 | +} |
| 17 | + |
| 18 | +#[test] |
| 19 | +fn test_read_comments() { |
| 20 | + let mut file = temp_file!("tests/taglib/data/correctness_gain_silent_output.opus"); |
| 21 | + let f = OpusFile::read_from(&mut file, ParseOptions::new()).unwrap(); |
| 22 | + assert_eq!( |
| 23 | + f.vorbis_comments().get("ENCODER"), |
| 24 | + Some("Xiph.Org Opus testvectormaker") |
| 25 | + ); |
| 26 | + assert!(f.vorbis_comments().get("TESTDESCRIPTION").is_some()); |
| 27 | + assert!(f.vorbis_comments().artist().is_none()); |
| 28 | + assert_eq!(f.vorbis_comments().vendor(), "libopus 0.9.11-66-g64c2dd7"); |
| 29 | +} |
| 30 | + |
| 31 | +#[test] |
| 32 | +fn test_write_comments() { |
| 33 | + let mut file = temp_file!("tests/taglib/data/correctness_gain_silent_output.opus"); |
| 34 | + |
| 35 | + { |
| 36 | + let mut f = OpusFile::read_from(&mut file, ParseOptions::new()).unwrap(); |
| 37 | + file.rewind().unwrap(); |
| 38 | + f.vorbis_comments_mut() |
| 39 | + .set_artist(String::from("Your Tester")); |
| 40 | + f.save_to(&mut file).unwrap(); |
| 41 | + } |
| 42 | + file.rewind().unwrap(); |
| 43 | + { |
| 44 | + let f = OpusFile::read_from(&mut file, ParseOptions::new()).unwrap(); |
| 45 | + assert_eq!( |
| 46 | + f.vorbis_comments().get("ENCODER"), |
| 47 | + Some("Xiph.Org Opus testvectormaker") |
| 48 | + ); |
| 49 | + assert!(f.vorbis_comments().get("TESTDESCRIPTION").is_some()); |
| 50 | + assert_eq!(f.vorbis_comments().artist().as_deref(), Some("Your Tester")); |
| 51 | + assert_eq!(f.vorbis_comments().vendor(), "libopus 0.9.11-66-g64c2dd7"); |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +#[test] |
| 56 | +#[ignore] |
| 57 | +fn test_split_packets() { |
| 58 | + // Marker test, Lofty does not retain packet information |
| 59 | +} |
0 commit comments