lofty-rs/tests/ogg_read_write.rs

65 lines
1.5 KiB
Rust
Raw Normal View History

2021-09-06 14:41:24 +00:00
mod util;
2021-09-05 01:18:11 +00:00
use lofty::{FileType, ItemKey, ItemValue, Probe, TagItem};
2021-09-03 19:37:37 +00:00
// The tests for OGG Opus/Vorbis are nearly identical
2021-09-06 14:41:24 +00:00
// We have the vendor string and a title stored in the tag
2021-09-03 19:37:37 +00:00
#[test]
fn ogg_opus_read() {
2021-09-06 14:41:24 +00:00
read("tests/assets/a.opus", &FileType::Opus)
2021-09-03 19:37:37 +00:00
}
#[test]
fn ogg_opus_write() {
2021-09-06 14:41:24 +00:00
write("tests/assets/a.opus", &FileType::Opus)
}
2021-09-03 19:37:37 +00:00
2021-09-06 14:41:24 +00:00
#[test]
fn ogg_flac_read() {
// FLAC does **not** require a Vorbis comment block be present, this file has one
read("tests/assets/a.flac", &FileType::FLAC)
}
2021-09-03 19:37:37 +00:00
2021-09-06 14:41:24 +00:00
#[test]
fn ogg_flac_write() {
write("tests/assets/a.flac", &FileType::FLAC)
2021-09-03 19:37:37 +00:00
}
#[test]
fn ogg_vorbis_read() {
2021-09-06 14:41:24 +00:00
read("tests/assets/a.ogg", &FileType::Vorbis)
}
2021-09-03 19:37:37 +00:00
2021-09-06 14:41:24 +00:00
#[test]
fn ogg_vorbis_write() {
write("tests/assets/a.ogg", &FileType::Vorbis)
}
2021-09-03 19:37:37 +00:00
2021-09-06 14:41:24 +00:00
fn read(path: &str, file_type: &FileType) {
let file = Probe::new().read_from_path(path).unwrap();
2021-09-03 19:37:37 +00:00
2021-09-06 14:41:24 +00:00
assert_eq!(file.file_type(), file_type);
2021-09-03 19:37:37 +00:00
2021-09-06 14:41:24 +00:00
crate::verify_artist!(file, primary_tag, "Foo artist", 2);
2021-09-03 19:37:37 +00:00
}
2021-09-06 14:41:24 +00:00
fn write(path: &str, file_type: &FileType) {
2021-09-03 19:37:37 +00:00
let mut file = std::fs::OpenOptions::new()
.read(true)
.write(true)
2021-09-06 14:41:24 +00:00
.open(path)
2021-09-03 19:37:37 +00:00
.unwrap();
let mut tagged_file = Probe::new().read_from(&mut file).unwrap();
2021-09-06 14:41:24 +00:00
assert_eq!(tagged_file.file_type(), file_type);
2021-09-03 19:37:37 +00:00
2021-09-06 14:41:24 +00:00
crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 2 => file, "Bar artist");
2021-09-03 19:37:37 +00:00
// Now reread the file
let mut tagged_file = Probe::new().read_from(&mut file).unwrap();
2021-09-06 14:41:24 +00:00
crate::set_artist!(tagged_file, primary_tag_mut, "Bar artist", 2 => file, "Foo artist");
2021-09-03 19:37:37 +00:00
}