use container_probe::{Confidence, Detail, PartitionKind, Probe};
use std::fmt::Write;
use std::fs;
fn fixture(rel: &str) -> Vec<u8> {
fs::read(format!("{}/../{}", env!("CARGO_MANIFEST_DIR"), rel))
.unwrap_or_else(|e| panic!("failed to read fixture {rel}: {e}"))
}
#[test]
fn confidence_has_named_tiers() {
let tiers = [
(Confidence::CERTAIN, "CERTAIN"),
(Confidence::STRONG, "STRONG"),
(Confidence::STRUCTURAL, "STRUCTURAL"),
(Confidence::LATTICE_STRONG, "LATTICE_STRONG"),
(Confidence::LATTICE_WEAK, "LATTICE_WEAK"),
(Confidence::HEURISTIC, "HEURISTIC"),
];
for (c, name) in tiers {
assert_eq!(c.name(), name);
assert_eq!(c.to_string(), name, "Display must equal name()");
}
}
#[test]
fn detail_display_is_lossless() {
let data = fixture("fixtures/container-probe/m2ts_192.m2ts");
let detail = match container_probe::probe(&data) {
Probe::Identified { detail, .. } => detail,
other => panic!("m2ts_192.m2ts must identify, got {other:?}"),
};
let rendered = detail.to_string();
assert!(
rendered.contains("Ts") && rendered.contains("192") && rendered.contains("4"),
"Detail::Ts Display dropped data: {rendered:?}"
);
assert!(
rendered != "Ts",
"Detail::Ts must not collapse to its name only"
);
}
#[test]
fn major_brand_str_returns_the_brand() {
let data = fixture("fixtures/mp4/h264_high.mp4");
match container_probe::probe(&data) {
Probe::Identified { detail, .. } => {
assert_eq!(detail.major_brand_str(), Some("isom"));
}
other => panic!("h264_high.mp4 must identify, got {other:?}"),
}
}
#[test]
fn major_brand_str_is_none_for_ts() {
let data = fixture("fixtures/ts/h264_aac.ts");
match container_probe::probe(&data) {
Probe::Identified { detail, .. } => {
assert_eq!(detail.major_brand_str(), None);
}
other => panic!("h264_aac.ts must identify, got {other:?}"),
}
}
#[test]
fn detail_names() {
assert_eq!(Detail::None.name(), "None");
let mut s = String::new();
write!(&mut s, "{}", Detail::None).expect("fmt");
assert_eq!(s, "None");
}
#[test]
fn flv_mxf_mpegps_report_detail() {
let flv = container_probe::probe(&fixture("fixtures/flv/av.flv"));
match flv {
Probe::Identified { detail, .. } => match detail {
Detail::Flv {
has_audio,
has_video,
data_offset,
..
} => {
assert!(has_video, "av.flv carries video tags");
assert!(has_audio, "av.flv carries audio tags");
assert!(data_offset >= 9);
}
other => panic!("FLV must report Detail::Flv, got {other:?}"),
},
other => panic!("av.flv must identify, got {other:?}"),
}
let mxf = container_probe::probe(&fixture("fixtures/mxf/op1a_mpeg2_pcm.mxf"));
match mxf {
Probe::Identified { detail, .. } => match detail {
Detail::Mxf { partition_kind, .. } => {
assert!(
matches!(
partition_kind,
PartitionKind::Header | PartitionKind::Body | PartitionKind::Footer
),
"a real MXF fixture must decode to a named partition kind, got \
{partition_kind:?}"
);
assert_eq!(partition_kind.name(), "Header");
assert_eq!(partition_kind.to_string(), "Header");
}
other => panic!("MXF must report Detail::Mxf, got {other:?}"),
},
other => panic!("mxf must identify, got {other:?}"),
}
let ps = container_probe::probe(&fixture("fixtures/ps/h264_ac3.ps"));
match ps {
Probe::Identified { detail, .. } => match detail {
Detail::MpegPs {
structurally_valid, ..
} => assert!(structurally_valid, "h264_ac3.ps markers validate"),
other => panic!("MPEG-PS must report Detail::MpegPs, got {other:?}"),
},
other => panic!("h264_ac3.ps must identify, got {other:?}"),
}
}