#![allow(clippy::unwrap_used, reason = "allow in test files")]
#![allow(clippy::undocumented_unsafe_blocks, reason = "allow in test files")]
#![allow(clippy::indexing_slicing, reason = "allow in test files")]
use quickcheck::TestResult;
use quickcheck_macros::quickcheck;
use super::*;
use crate::util::PlaneSizeTuple;
#[allow(clippy::type_complexity)]
fn create_test_params() -> (
NonZeroUsize,
NonZeroUsize,
Subpel,
usize,
usize,
MVPlaneSet,
NonZeroU8,
NonZeroU8,
NonZeroU8,
SmallVec<[usize; 3]>,
PlaneSizeTuple,
) {
let width = NonZeroUsize::new(64).unwrap();
let height = NonZeroUsize::new(48).unwrap();
let pel = Subpel::Full;
let hpad = 8;
let vpad = 8;
let yuv_mode = MVPlaneSet::YUVPLANES;
let x_ratio_uv = NonZeroU8::new(2).unwrap();
let y_ratio_uv = NonZeroU8::new(2).unwrap();
let bits_per_sample = NonZeroU8::new(8).unwrap();
let plane_offsets = SmallVec::from([0, 1000, 2000]);
let pitch = (
NonZeroUsize::new(80).unwrap(),
Some(NonZeroUsize::new(40).unwrap()),
Some(NonZeroUsize::new(40).unwrap()),
);
(
width,
height,
pel,
hpad,
vpad,
yuv_mode,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
plane_offsets,
pitch,
)
}
fn create_test_mvframe() -> MVFrame {
let (
width,
height,
pel,
hpad,
vpad,
yuv_mode,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
plane_offsets,
pitch,
) = create_test_params();
MVFrame::new(
width,
height,
pel,
hpad,
vpad,
yuv_mode,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
&plane_offsets,
pitch,
)
.unwrap()
}
#[test]
fn mvframe_new_creates_correct_number_of_planes() {
let (
width,
height,
pel,
hpad,
vpad,
yuv_mode,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
plane_offsets,
pitch,
) = create_test_params();
let frame = MVFrame::new(
width,
height,
pel,
hpad,
vpad,
yuv_mode,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
&plane_offsets,
pitch,
)
.unwrap();
assert_eq!(frame.planes.len(), 3, "Should create 3 planes for YUV mode");
}
#[test]
fn mvframe_new_y_plane_only() {
let (
width,
height,
pel,
hpad,
vpad,
_,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
plane_offsets,
pitch,
) = create_test_params();
let frame = MVFrame::new(
width,
height,
pel,
hpad,
vpad,
MVPlaneSet::YPLANE,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
&plane_offsets,
pitch,
)
.unwrap();
assert_eq!(
frame.planes.len(),
1,
"Should create 1 plane for Y-only mode"
);
}
#[test]
fn mvframe_new_chroma_calculation() {
let width = NonZeroUsize::new(64).unwrap();
let height = NonZeroUsize::new(48).unwrap();
let pel = Subpel::Full;
let hpad = 8;
let vpad = 8;
let yuv_mode = MVPlaneSet::YUVPLANES;
let x_ratio_uv = NonZeroU8::new(2).unwrap();
let y_ratio_uv = NonZeroU8::new(2).unwrap();
let bits_per_sample = NonZeroU8::new(8).unwrap();
let plane_offsets = SmallVec::from([0, 1000, 2000]);
let pitch = (
NonZeroUsize::new(80).unwrap(),
Some(NonZeroUsize::new(40).unwrap()),
Some(NonZeroUsize::new(40).unwrap()),
);
let frame = MVFrame::new(
width,
height,
pel,
hpad,
vpad,
yuv_mode,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
&plane_offsets,
pitch,
)
.unwrap();
assert_eq!(frame.planes[0].width, width);
assert_eq!(frame.planes[0].height, height);
let expected_chroma_width = NonZeroUsize::new(32).unwrap();
let expected_chroma_height = NonZeroUsize::new(24).unwrap();
assert_eq!(frame.planes[1].width, expected_chroma_width);
assert_eq!(frame.planes[1].height, expected_chroma_height);
assert_eq!(frame.planes[2].width, expected_chroma_width);
assert_eq!(frame.planes[2].height, expected_chroma_height);
}
#[test]
fn mvframe_new_padding_calculation() {
let width = NonZeroUsize::new(64).unwrap();
let height = NonZeroUsize::new(48).unwrap();
let pel = Subpel::Full;
let hpad = 16;
let vpad = 12;
let yuv_mode = MVPlaneSet::YUVPLANES;
let x_ratio_uv = NonZeroU8::new(2).unwrap();
let y_ratio_uv = NonZeroU8::new(2).unwrap();
let bits_per_sample = NonZeroU8::new(8).unwrap();
let plane_offsets = SmallVec::from([0, 1000, 2000]);
let pitch = (
NonZeroUsize::new(96).unwrap(),
Some(NonZeroUsize::new(48).unwrap()),
Some(NonZeroUsize::new(48).unwrap()),
);
let frame = MVFrame::new(
width,
height,
pel,
hpad,
vpad,
yuv_mode,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
&plane_offsets,
pitch,
)
.unwrap();
assert_eq!(frame.planes[0].hpad, hpad);
assert_eq!(frame.planes[0].vpad, vpad);
assert_eq!(frame.planes[1].hpad, 8);
assert_eq!(frame.planes[1].vpad, 6);
assert_eq!(frame.planes[2].hpad, 8);
assert_eq!(frame.planes[2].vpad, 6);
}
#[test]
fn mvframe_new_different_pel_values() {
let (
width,
height,
_,
hpad,
vpad,
yuv_mode,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
plane_offsets,
pitch,
) = create_test_params();
for &pel in &[Subpel::Full, Subpel::Half, Subpel::Quarter] {
let frame = MVFrame::new(
width,
height,
pel,
hpad,
vpad,
yuv_mode,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
&plane_offsets,
pitch,
)
.unwrap();
for plane in &frame.planes {
assert_eq!(
plane.pel, pel,
"All planes should have the correct pel value"
);
}
}
}
#[test]
fn mvframe_new_edge_case_small_dimensions() {
let width = NonZeroUsize::new(4).unwrap(); let height = NonZeroUsize::new(4).unwrap(); let pel = Subpel::Full;
let hpad = 0;
let vpad = 0;
let yuv_mode = MVPlaneSet::YUVPLANES;
let x_ratio_uv = NonZeroU8::new(2).unwrap();
let y_ratio_uv = NonZeroU8::new(2).unwrap();
let bits_per_sample = NonZeroU8::new(8).unwrap();
let plane_offsets = SmallVec::from([0, 1000, 2000]);
let pitch = (
NonZeroUsize::new(4).unwrap(),
Some(NonZeroUsize::new(2).unwrap()),
Some(NonZeroUsize::new(2).unwrap()),
);
let result = MVFrame::new(
width,
height,
pel,
hpad,
vpad,
yuv_mode,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
&plane_offsets,
pitch,
);
assert!(result.is_ok(), "Should handle small valid dimensions");
let frame = result.unwrap();
assert_eq!(frame.planes[1].width.get(), 2);
assert_eq!(frame.planes[1].height.get(), 2);
}
#[test]
fn mvframe_new_plane_selection() {
let (
width,
height,
pel,
hpad,
vpad,
_,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
plane_offsets,
pitch,
) = create_test_params();
let test_cases = [
(MVPlaneSet::YPLANE, 1),
(MVPlaneSet::UPLANE, 1),
(MVPlaneSet::VPLANE, 1),
(MVPlaneSet::YUPLANES, 2),
(MVPlaneSet::YVPLANES, 2),
(MVPlaneSet::UVPLANES, 2),
(MVPlaneSet::YUVPLANES, 3),
];
for (yuv_mode, expected_count) in test_cases {
let frame = MVFrame::new(
width,
height,
pel,
hpad,
vpad,
yuv_mode,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
&plane_offsets,
pitch,
)
.unwrap();
assert_eq!(
frame.planes.len(),
expected_count,
"Mode {:?} should create {} planes",
yuv_mode,
expected_count
);
}
}
#[quickcheck]
fn mvframe_new_property_based(width: u16, height: u16, hpad: u8, vpad: u8, bits: u8) -> TestResult {
if width == 0 || height == 0 || bits == 0 || bits > 16 {
return TestResult::discard();
}
let width = NonZeroUsize::new(width as usize).unwrap();
let height = NonZeroUsize::new(height as usize).unwrap();
let pel = Subpel::Full;
let hpad = hpad as usize;
let vpad = vpad as usize;
let yuv_mode = MVPlaneSet::YPLANE; let x_ratio_uv = NonZeroU8::new(1).unwrap();
let y_ratio_uv = NonZeroU8::new(1).unwrap();
let bits_per_sample = NonZeroU8::new(bits).unwrap();
let plane_offsets = SmallVec::from([0, 1000, 2000]);
let pitch = (
NonZeroUsize::new(width.get() + hpad * 2).unwrap(),
Some(NonZeroUsize::new(width.get() + hpad * 2).unwrap()),
Some(NonZeroUsize::new(width.get() + hpad * 2).unwrap()),
);
match MVFrame::new(
width,
height,
pel,
hpad,
vpad,
yuv_mode,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
&plane_offsets,
pitch,
) {
Ok(frame) => {
assert!(!frame.planes.is_empty());
assert_eq!(frame.planes[0].width, width);
assert_eq!(frame.planes[0].height, height);
TestResult::passed()
}
Err(_) => TestResult::discard(), }
}
#[test]
fn mvframe_plane_access_patterns() {
let frame = create_test_mvframe();
for (i, plane) in frame.planes.iter().enumerate() {
assert!(i < 3, "Should not have more than 3 planes");
assert!(plane.width.get() > 0, "Plane width should be positive");
assert!(plane.height.get() > 0, "Plane height should be positive");
}
}
#[test]
fn mvframe_plane_dimensions_consistency() {
let frame = create_test_mvframe();
if frame.planes.len() >= 3 {
let y_plane = &frame.planes[0];
let u_plane = &frame.planes[1];
let v_plane = &frame.planes[2];
assert_eq!(y_plane.width.get() / 2, u_plane.width.get());
assert_eq!(y_plane.height.get() / 2, u_plane.height.get());
assert_eq!(u_plane.width, v_plane.width);
assert_eq!(u_plane.height, v_plane.height);
}
}
#[test]
fn mvframe_memory_layout_expectations() {
let frame = create_test_mvframe();
for plane in &frame.planes {
assert!(plane.padded_width.get() >= plane.width.get());
assert!(plane.padded_height.get() >= plane.height.get());
assert!(plane.stride.get() >= plane.padded_width.get());
assert_eq!(plane.padded_width.get(), plane.width.get() + 2 * plane.hpad);
assert_eq!(
plane.padded_height.get(),
plane.height.get() + 2 * plane.vpad
);
}
}
#[test]
fn mvframe_subpel_window_offsets() {
let (
width,
height,
_,
hpad,
vpad,
yuv_mode,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
plane_offsets,
pitch,
) = create_test_params();
for &pel in &[Subpel::Full, Subpel::Half, Subpel::Quarter] {
let frame = MVFrame::new(
width,
height,
pel,
hpad,
vpad,
yuv_mode,
x_ratio_uv,
y_ratio_uv,
bits_per_sample,
&plane_offsets,
pitch,
)
.unwrap();
let expected_windows = u8::from(pel) * u8::from(pel);
for plane in &frame.planes {
assert_eq!(
plane.subpel_window_offsets.len(),
expected_windows as usize,
"Pel {:?} should create {} subpel windows",
pel,
expected_windows
);
}
}
}