use broadcast_common::Parse;
use dvb_ci::Error;
use dvb_ci::objects::host_control::{Replace, Tune};
fn is_trailing(e: &Error) -> bool {
matches!(
e,
Error::InvalidObject { reason, .. } if *reason == "trailing bytes after the fixed body"
)
}
#[test]
fn tune_rejects_a_trailing_byte() {
let exact = [
0x9F, 0x84, 0x00, 0x08, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
];
let t = Tune::parse(&exact).unwrap();
assert_eq!(
(
t.network_id,
t.original_network_id,
t.transport_stream_id,
t.service_id
),
(0x1122, 0x3344, 0x5566, 0x7788)
);
let padded = [
0x9F, 0x84, 0x00, 0x09, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0xEE,
];
assert!(is_trailing(&Tune::parse(&padded).unwrap_err()));
}
#[test]
fn replace_rejects_a_trailing_byte() {
let exact = [0x9F, 0x84, 0x01, 0x05, 0x07, 0xE0, 0x64, 0xE0, 0x65];
let r = Replace::parse(&exact).unwrap();
assert_eq!(
(r.replacement_ref, r.replaced_pid, r.replacement_pid),
(0x07, 0x0064, 0x0065)
);
let padded = [0x9F, 0x84, 0x01, 0x06, 0x07, 0xE0, 0x64, 0xE0, 0x65, 0xEE];
assert!(is_trailing(&Replace::parse(&padded).unwrap_err()));
}