use super::*;
#[test]
fn a_family_demuxer_walks_every_word_it_handles() {
let format = ContainerFormat::new(Utf8Bytes::from("mov,mp4,m4a,3gp,3g2,mj2"), None);
assert_eq!(format.name(), "mov,mp4,m4a,3gp,3g2,mj2");
assert_eq!(
format.names().collect::<Vec<_>>(),
["mov", "mp4", "m4a", "3gp", "3g2", "mj2"],
);
}
#[test]
fn a_single_format_demuxer_walks_one_word() {
let format = ContainerFormat::new(Utf8Bytes::from("flac"), Some(Utf8Bytes::from("raw FLAC")));
assert_eq!(format.names().collect::<Vec<_>>(), ["flac"]);
assert_eq!(format.long_name(), Some("raw FLAC"));
}
#[test]
fn a_format_without_a_description_is_still_a_format() {
let format = ContainerFormat::new(Utf8Bytes::from("matroska,webm"), None);
assert_eq!(format.long_name(), None);
assert_eq!(format.names().collect::<Vec<_>>(), ["matroska", "webm"]);
}
#[test]
fn empty_words_are_not_names() {
let format = ContainerFormat::new(Utf8Bytes::from("mp4,,mov,"), None);
assert_eq!(format.names().collect::<Vec<_>>(), ["mp4", "mov"]);
}
#[test]
fn the_words_are_what_a_typed_vocabulary_parses() {
let format = ContainerFormat::new(Utf8Bytes::from("mov,mp4,m4a,3gp,3g2,mj2"), None);
let recognised: Vec<_> = format
.names()
.filter(|word| matches!(*word, "mov" | "mp4" | "mkv" | "webm"))
.collect();
assert_eq!(
recognised,
["mov", "mp4"],
"a family demuxer can offer several words a vocabulary knows, and choosing between them \
is the consumer's call rather than this crate's",
);
}
#[test]
fn a_null_context_has_no_format() {
assert_eq!(
unsafe { ContainerFormat::from_context(std::ptr::null()) },
None,
);
}
#[test]
fn a_name_no_registered_demuxer_goes_by_is_refused_by_name() {
let mov = DemuxerName::registered("mov,mp4,m4a,3gp,3g2,mj2").expect("the ISOBMFF demuxer");
assert_eq!(mov.as_str(), "mov,mp4,m4a,3gp,3g2,mj2");
assert_eq!(mov.to_string(), "mov,mp4,m4a,3gp,3g2,mj2");
let h264 = "h264"
.parse::<DemuxerName>()
.expect("the raw H.264 demuxer");
assert_eq!(h264.as_str(), "h264");
let format = ContainerFormat::new(Utf8Bytes::from("mov,mp4,m4a,3gp,3g2,mj2"), None);
assert!(format.is(mov), "a session's format is its demuxer");
assert!(!format.is(h264), "and no other");
let word = DemuxerName::registered("mov").expect_err("refused by name: a word of a comma list");
assert_eq!(word.name(), "mov");
assert_eq!(word.word_of(), Some(mov), "the whole name to give");
assert_eq!(
word.to_string(),
"no demuxer the linked FFmpeg registers is named \"mov\": it is a word of \
\"mov,mp4,m4a,3gp,3g2,mj2\", the demuxer's whole name"
);
for name in ["not a demuxer", "MOV,MP4,M4A,3GP,3G2,MJ2", "mov,mp4", ""] {
let refused = name.parse::<DemuxerName>().expect_err("refused by name");
assert_eq!(refused.name(), name, "refused by name");
assert_eq!(
refused.word_of(),
None,
"{name:?}: a word of no demuxer's name"
);
}
}